From 67adf21e642bd7a2e474829ae9a01a8f0ce5e1b4 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Tue, 5 Dec 2023 16:46:58 +0100 Subject: chore: refactor stack structs Signed-off-by: Henry Gressmann --- crates/types/src/lib.rs | 51 +++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 19 deletions(-) (limited to 'crates/types/src') diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index 9f37759..6430b03 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -23,16 +23,29 @@ pub struct TinyWasmModule { /// A WebAssembly value. /// See https://webassembly.github.io/spec/core/syntax/types.html#value-types -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Copy)] pub enum WasmValue { // Num types I32(i32), I64(i64), F32(f32), F64(f64), - // Vec types - V128(i128), + // V128(i128), +} + +impl WasmValue { + pub fn default_for(ty: ValType) -> Self { + match ty { + ValType::I32 => Self::I32(0), + ValType::I64 => Self::I64(0), + ValType::F32 => Self::F32(0.0), + ValType::F64 => Self::F64(0.0), + ValType::V128 => unimplemented!("V128 is not yet supported"), + ValType::FuncRef => unimplemented!("FuncRef is not yet supported"), + ValType::ExternRef => unimplemented!("ExternRef is not yet supported"), + } + } } impl From for WasmValue { @@ -59,11 +72,11 @@ impl From for WasmValue { } } -impl From for WasmValue { - fn from(i: i128) -> Self { - Self::V128(i) - } -} +// impl From for WasmValue { +// fn from(i: i128) -> Self { +// Self::V128(i) +// } +// } impl TryFrom for i32 { type Error = (); @@ -109,16 +122,16 @@ impl TryFrom for f64 { } } -impl TryFrom for i128 { - type Error = (); +// impl TryFrom for i128 { +// type Error = (); - fn try_from(value: WasmValue) -> Result { - match value { - WasmValue::V128(i) => Ok(i), - _ => Err(()), - } - } -} +// fn try_from(value: WasmValue) -> Result { +// match value { +// WasmValue::V128(i) => Ok(i), +// _ => Err(()), +// } +// } +// } impl Debug for WasmValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -127,7 +140,7 @@ impl Debug for WasmValue { WasmValue::I64(i) => write!(f, "i64({})", i), WasmValue::F32(i) => write!(f, "f32({})", i), WasmValue::F64(i) => write!(f, "f64({})", i), - WasmValue::V128(i) => write!(f, "v128({})", i), + // WasmValue::V128(i) => write!(f, "v128({})", i), } } } @@ -139,7 +152,7 @@ impl WasmValue { Self::I64(_) => ValType::I64, Self::F32(_) => ValType::F32, Self::F64(_) => ValType::F64, - Self::V128(_) => ValType::V128, + // Self::V128(_) => ValType::V128, } } } -- cgit v1.3.1