@@ -80,7 +80,7 @@ enum ExecResult {
8080fn exec_one ( cf : & mut CallFrame , stack : & mut Stack , store : & mut Store , module : & ModuleInstance ) -> Result < ExecResult > {
8181 let instrs = & cf. func_instance . 0 . instructions ;
8282
83- if unlikely ( cf. instr_ptr >= instrs. len ( ) || instrs. is_empty ( ) ) {
83+ if unlikely ( cf. instr_ptr as usize >= instrs. len ( ) || instrs. is_empty ( ) ) {
8484 log:: error!( "instr_ptr out of bounds: {} >= {}" , cf. instr_ptr, instrs. len( ) ) ;
8585 return Err ( Error :: Other ( format ! ( "instr_ptr out of bounds: {} >= {}" , cf. instr_ptr, instrs. len( ) ) ) ) ;
8686 }
@@ -128,7 +128,7 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M
128128 } ;
129129
130130 let params = stack. values . pop_n_rev ( wasm_func. ty . params . len ( ) ) ?;
131- let call_frame = CallFrame :: new ( wasm_func, func_inst. owner , params, stack. blocks . len ( ) ) ;
131+ let call_frame = CallFrame :: new ( wasm_func, func_inst. owner , params, stack. blocks . len ( ) as u32 ) ;
132132
133133 // push the call frame
134134 cf. instr_ptr += 1 ; // skip the call instruction
@@ -181,7 +181,7 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M
181181 }
182182
183183 let params = stack. values . pop_n_rev ( wasm_func. ty . params . len ( ) ) ?;
184- let call_frame = CallFrame :: new ( wasm_func, func_inst. owner , params, stack. blocks . len ( ) ) ;
184+ let call_frame = CallFrame :: new ( wasm_func, func_inst. owner , params, stack. blocks . len ( ) as u32 ) ;
185185
186186 // push the call frame
187187 cf. instr_ptr += 1 ; // skip the call instruction
@@ -198,8 +198,8 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M
198198 cf. enter_block (
199199 BlockFrame :: new (
200200 cf. instr_ptr ,
201- cf. instr_ptr + * end_offset as usize ,
202- stack. values . len ( ) ,
201+ cf. instr_ptr + * end_offset,
202+ stack. values . len ( ) as u32 ,
203203 BlockType :: If ,
204204 & args. unpack ( ) ,
205205 module,
@@ -213,26 +213,26 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M
213213 // falsy value is on the top of the stack
214214 if * else_offset != 0 {
215215 let label = BlockFrame :: new (
216- cf. instr_ptr + * else_offset as usize ,
217- cf. instr_ptr + * end_offset as usize ,
218- stack. values . len ( ) ,
216+ cf. instr_ptr + * else_offset,
217+ cf. instr_ptr + * end_offset,
218+ stack. values . len ( ) as u32 ,
219219 BlockType :: Else ,
220220 & args. unpack ( ) ,
221221 module,
222222 ) ;
223- cf. instr_ptr += * else_offset as usize ;
223+ cf. instr_ptr += * else_offset;
224224 cf. enter_block ( label, & mut stack. values , & mut stack. blocks ) ;
225225 } else {
226- cf. instr_ptr += * end_offset as usize ;
226+ cf. instr_ptr += * end_offset;
227227 }
228228 }
229229
230230 Loop ( args, end_offset) => {
231231 cf. enter_block (
232232 BlockFrame :: new (
233233 cf. instr_ptr ,
234- cf. instr_ptr + * end_offset as usize ,
235- stack. values . len ( ) ,
234+ cf. instr_ptr + * end_offset,
235+ stack. values . len ( ) as u32 ,
236236 BlockType :: Loop ,
237237 args,
238238 module,
@@ -246,8 +246,8 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M
246246 cf. enter_block (
247247 BlockFrame :: new (
248248 cf. instr_ptr ,
249- cf. instr_ptr + * end_offset as usize ,
250- stack. values . len ( ) ,
249+ cf. instr_ptr + * end_offset,
250+ stack. values . len ( ) as u32 ,
251251 BlockType :: Block ,
252252 args,
253253 module,
@@ -258,7 +258,9 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M
258258 }
259259
260260 BrTable ( default, len) => {
261- let instr = cf. instructions ( ) [ cf. instr_ptr + 1 ..cf. instr_ptr + 1 + * len as usize ]
261+ let start = cf. instr_ptr + 1 ;
262+ let end = cf. instr_ptr + 1 + * len;
263+ let instr = cf. instructions ( ) [ start as usize ..end as usize ]
262264 . iter ( )
263265 . map ( |i| match i {
264266 BrLabel ( l) => Ok ( * l) ,
@@ -294,24 +296,13 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M
294296 false => return Ok ( ExecResult :: Call ) ,
295297 } ,
296298
297- EndFunc => {
298- if unlikely ( stack. blocks . len ( ) != cf. block_ptr ) {
299- panic ! ( "endfunc: block frames not empty, this should have been validated by the parser" ) ;
300- }
301-
302- match stack. call_stack . is_empty ( ) {
303- true => return Ok ( ExecResult :: Return ) ,
304- false => return Ok ( ExecResult :: Call ) ,
305- }
306- }
307-
308299 // We're essentially using else as a EndBlockFrame instruction for if blocks
309300 Else ( end_offset) => {
310301 let block =
311302 stack. blocks . pop ( ) . expect ( "else: no label to end, this should have been validated by the parser" ) ;
312303
313- stack. values . truncate_keep ( block. stack_ptr , block. results ) ;
314- cf. instr_ptr += * end_offset as usize ;
304+ stack. values . truncate_keep ( block. stack_ptr , block. results as u32 ) ;
305+ cf. instr_ptr += * end_offset;
315306 }
316307
317308 // remove the label from the label stack
@@ -321,7 +312,7 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M
321312 . pop ( )
322313 . expect ( "end blockframe: no label to end, this should have been validated by the parser" ) ;
323314
324- stack. values . truncate_keep ( block. stack_ptr , block. results ) ;
315+ stack. values . truncate_keep ( block. stack_ptr , block. results as u32 ) ;
325316 }
326317
327318 LocalGet ( local_index) => stack. values . push ( cf. get_local ( * local_index as usize ) ) ,
0 commit comments