@@ -22,6 +22,9 @@ impl FuncHandle {
2222 /// See <https://webassembly.github.io/spec/core/exec/modules.html#invocation>
2323 #[ inline]
2424 pub fn call ( & self , store : & mut Store , params : & [ WasmValue ] ) -> Result < Vec < WasmValue > > {
25+ // Comments are ordered by the steps in the spec
26+ // In this implementation, some steps are combined and ordered differently for performance reasons
27+
2528 // 3. Let func_ty be the function type
2629 let func_ty = & self . ty ;
2730
@@ -35,7 +38,7 @@ impl FuncHandle {
3538 }
3639
3740 // 5. For each value type and the corresponding value, check if types match
38- if !unlikely ( func_ty. params . iter ( ) . zip ( params) . enumerate ( ) . all ( |( i, ( ty, param) ) | {
41+ if !( func_ty. params . iter ( ) . zip ( params) . enumerate ( ) . all ( |( i, ( ty, param) ) | {
3942 if ty != & param. val_type ( ) {
4043 log:: error!( "param type mismatch at index {}: expected {:?}, got {:?}" , i, ty, param) ;
4144 false
@@ -57,8 +60,8 @@ impl FuncHandle {
5760 } ;
5861
5962 // 6. Let f be the dummy frame
60- let call_frame =
61- CallFrame :: new ( wasm_func. clone ( ) , func_inst. owner , params . iter ( ) . map ( |v| RawWasmValue :: from ( * v ) ) , 0 ) ;
63+ let call_frame_params = params . iter ( ) . map ( |v| RawWasmValue :: from ( * v ) ) ;
64+ let call_frame = CallFrame :: new ( wasm_func. clone ( ) , func_inst. owner , call_frame_params , 0 ) ;
6265
6366 // 7. Push the frame f to the call stack
6467 // & 8. Push the values to the stack (Not needed since the call frame owns the values)
@@ -113,6 +116,7 @@ impl<P: IntoWasmValueTuple, R: FromWasmValueTuple> FuncHandleTyped<P, R> {
113116 R :: from_wasm_value_tuple ( & result)
114117 }
115118}
119+
116120macro_rules! impl_into_wasm_value_tuple {
117121 ( $( $T: ident) ,* ) => {
118122 impl <$( $T) ,* > IntoWasmValueTuple for ( $( $T, ) * )
@@ -140,21 +144,6 @@ macro_rules! impl_into_wasm_value_tuple_single {
140144 } ;
141145}
142146
143- impl_into_wasm_value_tuple_single ! ( i32 ) ;
144- impl_into_wasm_value_tuple_single ! ( i64 ) ;
145- impl_into_wasm_value_tuple_single ! ( f32 ) ;
146- impl_into_wasm_value_tuple_single ! ( f64 ) ;
147-
148- impl_into_wasm_value_tuple ! ( ) ;
149- impl_into_wasm_value_tuple ! ( T1 ) ;
150- impl_into_wasm_value_tuple ! ( T1 , T2 ) ;
151- impl_into_wasm_value_tuple ! ( T1 , T2 , T3 ) ;
152- impl_into_wasm_value_tuple ! ( T1 , T2 , T3 , T4 ) ;
153- impl_into_wasm_value_tuple ! ( T1 , T2 , T3 , T4 , T5 ) ;
154- impl_into_wasm_value_tuple ! ( T1 , T2 , T3 , T4 , T5 , T6 ) ;
155- impl_into_wasm_value_tuple ! ( T1 , T2 , T3 , T4 , T5 , T6 , T7 ) ;
156- impl_into_wasm_value_tuple ! ( T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 ) ;
157-
158147macro_rules! impl_from_wasm_value_tuple {
159148 ( $( $T: ident) ,* ) => {
160149 impl <$( $T) ,* > FromWasmValueTuple for ( $( $T, ) * )
@@ -200,21 +189,6 @@ macro_rules! impl_from_wasm_value_tuple_single {
200189 } ;
201190}
202191
203- impl_from_wasm_value_tuple_single ! ( i32 ) ;
204- impl_from_wasm_value_tuple_single ! ( i64 ) ;
205- impl_from_wasm_value_tuple_single ! ( f32 ) ;
206- impl_from_wasm_value_tuple_single ! ( f64 ) ;
207-
208- impl_from_wasm_value_tuple ! ( ) ;
209- impl_from_wasm_value_tuple ! ( T1 ) ;
210- impl_from_wasm_value_tuple ! ( T1 , T2 ) ;
211- impl_from_wasm_value_tuple ! ( T1 , T2 , T3 ) ;
212- impl_from_wasm_value_tuple ! ( T1 , T2 , T3 , T4 ) ;
213- impl_from_wasm_value_tuple ! ( T1 , T2 , T3 , T4 , T5 ) ;
214- impl_from_wasm_value_tuple ! ( T1 , T2 , T3 , T4 , T5 , T6 ) ;
215- impl_from_wasm_value_tuple ! ( T1 , T2 , T3 , T4 , T5 , T6 , T7 ) ;
216- impl_from_wasm_value_tuple ! ( T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 ) ;
217-
218192pub trait ValTypesFromTuple {
219193 fn val_types ( ) -> Box < [ ValType ] > ;
220194}
@@ -268,19 +242,42 @@ impl ValTypesFromTuple for () {
268242 }
269243}
270244
271- impl < T1 > ValTypesFromTuple for T1
272- where
273- T1 : ToValType ,
274- {
245+ impl < T : ToValType > ValTypesFromTuple for T {
275246 #[ inline]
276247 fn val_types ( ) -> Box < [ ValType ] > {
277- Box :: new ( [ T1 :: to_val_type ( ) ] )
248+ Box :: new ( [ T :: to_val_type ( ) ] )
278249 }
279250}
280251
252+ impl_from_wasm_value_tuple_single ! ( i32 ) ;
253+ impl_from_wasm_value_tuple_single ! ( i64 ) ;
254+ impl_from_wasm_value_tuple_single ! ( f32 ) ;
255+ impl_from_wasm_value_tuple_single ! ( f64 ) ;
256+
257+ impl_into_wasm_value_tuple_single ! ( i32 ) ;
258+ impl_into_wasm_value_tuple_single ! ( i64 ) ;
259+ impl_into_wasm_value_tuple_single ! ( f32 ) ;
260+ impl_into_wasm_value_tuple_single ! ( f64 ) ;
261+
281262impl_val_types_from_tuple ! ( T1 ) ;
282263impl_val_types_from_tuple ! ( T1 , T2 ) ;
283264impl_val_types_from_tuple ! ( T1 , T2 , T3 ) ;
284265impl_val_types_from_tuple ! ( T1 , T2 , T3 , T4 ) ;
285266impl_val_types_from_tuple ! ( T1 , T2 , T3 , T4 , T5 ) ;
286267impl_val_types_from_tuple ! ( T1 , T2 , T3 , T4 , T5 , T6 ) ;
268+
269+ impl_from_wasm_value_tuple ! ( ) ;
270+ impl_from_wasm_value_tuple ! ( T1 ) ;
271+ impl_from_wasm_value_tuple ! ( T1 , T2 ) ;
272+ impl_from_wasm_value_tuple ! ( T1 , T2 , T3 ) ;
273+ impl_from_wasm_value_tuple ! ( T1 , T2 , T3 , T4 ) ;
274+ impl_from_wasm_value_tuple ! ( T1 , T2 , T3 , T4 , T5 ) ;
275+ impl_from_wasm_value_tuple ! ( T1 , T2 , T3 , T4 , T5 , T6 ) ;
276+
277+ impl_into_wasm_value_tuple ! ( ) ;
278+ impl_into_wasm_value_tuple ! ( T1 ) ;
279+ impl_into_wasm_value_tuple ! ( T1 , T2 ) ;
280+ impl_into_wasm_value_tuple ! ( T1 , T2 , T3 ) ;
281+ impl_into_wasm_value_tuple ! ( T1 , T2 , T3 , T4 ) ;
282+ impl_into_wasm_value_tuple ! ( T1 , T2 , T3 , T4 , T5 ) ;
283+ impl_into_wasm_value_tuple ! ( T1 , T2 , T3 , T4 , T5 , T6 ) ;
0 commit comments