11use super :: { InterpreterRuntime , Stack } ;
22use crate :: { cold, log, unlikely} ;
33use crate :: {
4- runtime:: { BlockType , CallFrame , LabelArgs , LabelFrame } ,
4+ runtime:: { BlockType , CallFrame , LabelFrame } ,
55 Error , FuncContext , ModuleInstance , Result , Store , Trap ,
66} ;
77use alloc:: format;
@@ -29,13 +29,12 @@ impl InterpreterRuntime {
2929 let mut cf = stack. call_stack . pop ( ) ?;
3030
3131 let mut func_inst = cf. func_instance . clone ( ) ;
32- let mut wasm_func = func_inst. assert_wasm ( ) . expect ( "exec expected wasm function" ) ;
32+ let mut wasm_func = func_inst. assert_wasm ( ) ? ;
3333
3434 // The function to execute, gets updated from ExecResult::Call
3535 let mut instrs = & wasm_func. instructions ;
3636 let mut instr_count = instrs. len ( ) ;
37-
38- let mut current_module = store. get_module_instance ( func_inst. owner ) . unwrap ( ) . clone ( ) ;
37+ let mut current_module = store. get_module_instance_raw ( func_inst. owner ) ;
3938
4039 loop {
4140 if unlikely ( cf. instr_ptr >= instr_count) {
@@ -164,8 +163,8 @@ fn exec_one(
164163 }
165164 } ;
166165
167- let params = stack. values . pop_n_rev ( ty. params . len ( ) ) ?. collect :: < Vec < _ > > ( ) ;
168- let call_frame = CallFrame :: new_raw ( func_inst, & params, locals) ;
166+ let params = stack. values . pop_n_rev ( ty. params . len ( ) ) ?;
167+ let call_frame = CallFrame :: new ( func_inst, params, locals) ;
169168
170169 // push the call frame
171170 cf. instr_ptr += 1 ; // skip the call instruction
@@ -213,8 +212,8 @@ fn exec_one(
213212 }
214213 } ;
215214
216- let params = stack. values . pop_n_rev ( func_ty. params . len ( ) ) ?. collect :: < Vec < _ > > ( ) ;
217- let call_frame = CallFrame :: new_raw ( func_inst, & params, locals) ;
215+ let params = stack. values . pop_n_rev ( func_ty. params . len ( ) ) ?;
216+ let call_frame = CallFrame :: new ( func_inst, params, locals) ;
218217
219218 // push the call frame
220219 cf. instr_ptr += 1 ; // skip the call instruction
@@ -229,13 +228,14 @@ fn exec_one(
229228 // truthy value is on the top of the stack, so enter the then block
230229 if stack. values . pop_t :: < i32 > ( ) ? != 0 {
231230 cf. enter_label (
232- LabelFrame {
233- instr_ptr : cf. instr_ptr ,
234- end_instr_ptr : cf. instr_ptr + * end_offset,
235- stack_ptr : stack. values . len ( ) , // - params,
236- args : LabelArgs :: new ( * args, module) ?,
237- ty : BlockType :: If ,
238- } ,
231+ LabelFrame :: new (
232+ cf. instr_ptr ,
233+ cf. instr_ptr + * end_offset,
234+ stack. values . len ( ) , // - params,
235+ BlockType :: If ,
236+ args,
237+ module,
238+ ) ,
239239 & mut stack. values ,
240240 ) ;
241241 return Ok ( ExecResult :: Ok ) ;
@@ -244,13 +244,14 @@ fn exec_one(
244244 // falsy value is on the top of the stack
245245 if let Some ( else_offset) = else_offset {
246246 cf. enter_label (
247- LabelFrame {
248- instr_ptr : cf. instr_ptr + * else_offset,
249- end_instr_ptr : cf. instr_ptr + * end_offset,
250- stack_ptr : stack. values . len ( ) , // - params,
251- args : LabelArgs :: new ( * args, module) ?,
252- ty : BlockType :: Else ,
253- } ,
247+ LabelFrame :: new (
248+ cf. instr_ptr + * else_offset,
249+ cf. instr_ptr + * end_offset,
250+ stack. values . len ( ) , // - params,
251+ BlockType :: Else ,
252+ args,
253+ module,
254+ ) ,
254255 & mut stack. values ,
255256 ) ;
256257 cf. instr_ptr += * else_offset;
@@ -261,26 +262,28 @@ fn exec_one(
261262
262263 Loop ( args, end_offset) => {
263264 cf. enter_label (
264- LabelFrame {
265- instr_ptr : cf. instr_ptr ,
266- end_instr_ptr : cf. instr_ptr + * end_offset,
267- stack_ptr : stack. values . len ( ) , // - params,
268- args : LabelArgs :: new ( * args, module) ?,
269- ty : BlockType :: Loop ,
270- } ,
265+ LabelFrame :: new (
266+ cf. instr_ptr ,
267+ cf. instr_ptr + * end_offset,
268+ stack. values . len ( ) , // - params,
269+ BlockType :: Loop ,
270+ args,
271+ module,
272+ ) ,
271273 & mut stack. values ,
272274 ) ;
273275 }
274276
275277 Block ( args, end_offset) => {
276278 cf. enter_label (
277- LabelFrame {
278- instr_ptr : cf. instr_ptr ,
279- end_instr_ptr : cf. instr_ptr + * end_offset,
280- stack_ptr : stack. values . len ( ) , //- params,
281- args : LabelArgs :: new ( * args, module) ?,
282- ty : BlockType :: Block ,
283- } ,
279+ LabelFrame :: new (
280+ cf. instr_ptr ,
281+ cf. instr_ptr + * end_offset,
282+ stack. values . len ( ) , // - params,
283+ BlockType :: Block ,
284+ args,
285+ module,
286+ ) ,
284287 & mut stack. values ,
285288 ) ;
286289 }
@@ -341,7 +344,7 @@ fn exec_one(
341344 panic ! ( "else: no label to end, this should have been validated by the parser" ) ;
342345 } ;
343346
344- let res_count = block. args . results ;
347+ let res_count = block. results ;
345348 stack. values . truncate_keep ( block. stack_ptr , res_count) ;
346349 cf. instr_ptr += * end_offset;
347350 }
@@ -352,7 +355,7 @@ fn exec_one(
352355 cold ( ) ;
353356 panic ! ( "end: no label to end, this should have been validated by the parser" ) ;
354357 } ;
355- stack. values . truncate_keep ( block. stack_ptr , block. args . results )
358+ stack. values . truncate_keep ( block. stack_ptr , block. results )
356359 }
357360
358361 LocalGet ( local_index) => stack. values . push ( cf. get_local ( * local_index as usize ) ) ,
0 commit comments