1- #![ allow( missing_docs) ]
21use crate :: Result ;
32use tinywasm_types:: { LocalAddr , ValType , WasmValue } ;
43
@@ -12,9 +11,13 @@ pub(crate) type ValueRef = Option<u32>;
1211#[ derive( Debug , Clone , Copy , PartialEq ) ]
1312/// A untyped WebAssembly value
1413pub enum TinyWasmValue {
14+ /// A 32-bit value
1515 Value32 ( Value32 ) ,
16+ /// A 64-bit value
1617 Value64 ( Value64 ) ,
18+ /// A 128-bit value
1719 Value128 ( Value128 ) ,
20+ /// A reference value
1821 ValueRef ( ValueRef ) ,
1922}
2023
@@ -64,34 +67,39 @@ impl From<&[ValType]> for StackHeight {
6467}
6568
6669impl TinyWasmValue {
70+ /// Asserts that the value is a 32-bit value and returns it (panics if the value is the wrong size)
6771 pub fn unwrap_32 ( & self ) -> Value32 {
6872 match self {
6973 TinyWasmValue :: Value32 ( v) => * v,
7074 _ => unreachable ! ( "Expected Value32" ) ,
7175 }
7276 }
7377
78+ /// Asserts that the value is a 64-bit value and returns it (panics if the value is the wrong size)
7479 pub fn unwrap_64 ( & self ) -> Value64 {
7580 match self {
7681 TinyWasmValue :: Value64 ( v) => * v,
7782 _ => unreachable ! ( "Expected Value64" ) ,
7883 }
7984 }
8085
86+ /// Asserts that the value is a 128-bit value and returns it (panics if the value is the wrong size)
8187 pub fn unwrap_128 ( & self ) -> Value128 {
8288 match self {
8389 TinyWasmValue :: Value128 ( v) => * v,
8490 _ => unreachable ! ( "Expected Value128" ) ,
8591 }
8692 }
8793
94+ /// Asserts that the value is a reference value and returns it (panics if the value is the wrong size)
8895 pub fn unwrap_ref ( & self ) -> ValueRef {
8996 match self {
9097 TinyWasmValue :: ValueRef ( v) => * v,
9198 _ => unreachable ! ( "Expected ValueRef" ) ,
9299 }
93100 }
94101
102+ /// Attaches a type to the value (panics if the size of the value is not the same as the type)
95103 pub fn attach_type ( & self , ty : ValType ) -> WasmValue {
96104 match ty {
97105 ValType :: I32 => WasmValue :: I32 ( self . unwrap_32 ( ) as i32 ) ,
0 commit comments