From 63591a46640ec43199c91e6283d87a3c94074ace Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Mon, 4 Dec 2023 13:54:29 +0100 Subject: feat: add typed_func_handle, check for _start function Signed-off-by: Henry Gressmann --- crates/types/src/lib.rs | 87 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) (limited to 'crates/types/src') diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index a354203..9f37759 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -35,6 +35,91 @@ pub enum WasmValue { V128(i128), } +impl From for WasmValue { + fn from(i: i32) -> Self { + Self::I32(i) + } +} + +impl From for WasmValue { + fn from(i: i64) -> Self { + Self::I64(i) + } +} + +impl From for WasmValue { + fn from(i: f32) -> Self { + Self::F32(i) + } +} + +impl From for WasmValue { + fn from(i: f64) -> Self { + Self::F64(i) + } +} + +impl From for WasmValue { + fn from(i: i128) -> Self { + Self::V128(i) + } +} + +impl TryFrom for i32 { + type Error = (); + + fn try_from(value: WasmValue) -> Result { + match value { + WasmValue::I32(i) => Ok(i), + _ => Err(()), + } + } +} + +impl TryFrom for i64 { + type Error = (); + + fn try_from(value: WasmValue) -> Result { + match value { + WasmValue::I64(i) => Ok(i), + _ => Err(()), + } + } +} + +impl TryFrom for f32 { + type Error = (); + + fn try_from(value: WasmValue) -> Result { + match value { + WasmValue::F32(i) => Ok(i), + _ => Err(()), + } + } +} + +impl TryFrom for f64 { + type Error = (); + + fn try_from(value: WasmValue) -> Result { + match value { + WasmValue::F64(i) => Ok(i), + _ => Err(()), + } + } +} + +impl TryFrom for i128 { + type Error = (); + + 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 { match self { @@ -85,7 +170,6 @@ pub enum ExternalKind { /// These are indexes into the respective stores. /// See https://webassembly.github.io/spec/core/exec/runtime.html#addresses pub type Addr = u32; -pub type ModuleInstanceAddr = Addr; pub type FuncAddr = Addr; pub type TableAddr = Addr; pub type MemAddr = Addr; @@ -97,6 +181,7 @@ pub type ExternAddr = Addr; pub type TypeAddr = Addr; pub type LocalAddr = Addr; pub type LabelAddr = Addr; +pub type ModuleInstanceAddr = Addr; /// A WebAssembly Export Instance. /// https://webassembly.github.io/spec/core/exec/runtime.html#export-instances -- cgit v1.3.1