diff options
| author | Mica White <botahamec@outlook.com> | 2026-10-31 20:43:04 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2026-10-31 20:43:04 -0400 |
| commit | 6bce3f0ff4abe8b5fac9d42f06f2b7e7964732d5 (patch) | |
| tree | 3849b3321c10f66b2089d8015bb4144fc8c4b674 | |
| parent | b45a98a85c776d956a797773acd2f198c06b40ed (diff) | |
Support unsigned typesunsigned-types
| -rw-r--r-- | crates/tinywasm/src/func/values.rs | 2 | ||||
| -rw-r--r-- | crates/tinywasm/src/reference/value.rs | 20 |
2 files changed, 17 insertions, 5 deletions
diff --git a/crates/tinywasm/src/func/values.rs b/crates/tinywasm/src/func/values.rs index 11d3b17..4f33083 100644 --- a/crates/tinywasm/src/func/values.rs +++ b/crates/tinywasm/src/func/values.rs @@ -109,6 +109,8 @@ macro_rules! impl_tuple_traits { } impl_scalar_wasm_traits!( + u32 => WasmType::I32, + u64 => WasmType::I64, i32 => WasmType::I32, i64 => WasmType::I64, f32 => WasmType::F32, diff --git a/crates/tinywasm/src/reference/value.rs b/crates/tinywasm/src/reference/value.rs index 7ef3dea..826d635 100644 --- a/crates/tinywasm/src/reference/value.rs +++ b/crates/tinywasm/src/reference/value.rs @@ -144,20 +144,22 @@ macro_rules! value_conversions { impl WasmValue { #[doc = concat!("Returns the contained `", stringify!($ty), "` value.")] pub fn $method(&self) -> Option<$ty> { - if let Self::$variant(value) = self { Some(value.clone()) } else { None } + if let Self::$variant(value) = self { Some(value.clone() as _) } else { None } } } - impl From<$ty> for WasmValue { fn from(value: $ty) -> Self { Self::$variant(value) } } + impl From<$ty> for WasmValue { fn from(value: $ty) -> Self { Self::$variant(value as _) } } impl TryFrom<WasmValue> for $ty { type Error = (); fn try_from(value: WasmValue) -> Result<Self, Self::Error> { - if let WasmValue::$variant(value) = value { Ok(value) } else { Err(()) } + if let WasmValue::$variant(value) = value { Ok(value as _) } else { Err(()) } } } )*}; } value_conversions! { + u32 => I32, as_u32; + u64 => I64, as_u64; i32 => I32, as_i32; i64 => I64, as_i64; f32 => F32, as_f32; @@ -168,7 +170,11 @@ value_conversions! { impl WasmValue { /// Returns the contained reference value. pub const fn as_ref(&self) -> Option<&RefValue> { - if let Self::Ref(value) = self { Some(value) } else { None } + if let Self::Ref(value) = self { + Some(value) + } else { + None + } } } @@ -182,7 +188,11 @@ impl TryFrom<WasmValue> for RefValue { type Error = (); fn try_from(value: WasmValue) -> Result<Self, Self::Error> { - if let WasmValue::Ref(value) = value { Ok(value) } else { Err(()) } + if let WasmValue::Ref(value) = value { + Ok(value) + } else { + Err(()) + } } } |
