@@ -80,7 +80,7 @@ enum ExecResult {
80
80
fn exec_one ( cf : & mut CallFrame , stack : & mut Stack , store : & mut Store , module : & ModuleInstance ) -> Result < ExecResult > {
81
81
let instrs = & cf. func_instance . 0 . instructions ;
82
82
83
- if unlikely ( cf. instr_ptr >= instrs. len ( ) || instrs. is_empty ( ) ) {
83
+ if unlikely ( cf. instr_ptr as usize >= instrs. len ( ) || instrs. is_empty ( ) ) {
84
84
log:: error!( "instr_ptr out of bounds: {} >= {}" , cf. instr_ptr, instrs. len( ) ) ;
85
85
return Err ( Error :: Other ( format ! ( "instr_ptr out of bounds: {} >= {}" , cf. instr_ptr, instrs. len( ) ) ) ) ;
86
86
}
@@ -128,7 +128,7 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M
128
128
} ;
129
129
130
130
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 ) ;
132
132
133
133
// push the call frame
134
134
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
181
181
}
182
182
183
183
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 ) ;
185
185
186
186
// push the call frame
187
187
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
198
198
cf. enter_block (
199
199
BlockFrame :: new (
200
200
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 ,
203
203
BlockType :: If ,
204
204
& args. unpack ( ) ,
205
205
module,
@@ -213,26 +213,26 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M
213
213
// falsy value is on the top of the stack
214
214
if * else_offset != 0 {
215
215
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 ,
219
219
BlockType :: Else ,
220
220
& args. unpack ( ) ,
221
221
module,
222
222
) ;
223
- cf. instr_ptr += * else_offset as usize ;
223
+ cf. instr_ptr += * else_offset;
224
224
cf. enter_block ( label, & mut stack. values , & mut stack. blocks ) ;
225
225
} else {
226
- cf. instr_ptr += * end_offset as usize ;
226
+ cf. instr_ptr += * end_offset;
227
227
}
228
228
}
229
229
230
230
Loop ( args, end_offset) => {
231
231
cf. enter_block (
232
232
BlockFrame :: new (
233
233
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 ,
236
236
BlockType :: Loop ,
237
237
args,
238
238
module,
@@ -246,8 +246,8 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M
246
246
cf. enter_block (
247
247
BlockFrame :: new (
248
248
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 ,
251
251
BlockType :: Block ,
252
252
args,
253
253
module,
@@ -258,7 +258,9 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M
258
258
}
259
259
260
260
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 ]
262
264
. iter ( )
263
265
. map ( |i| match i {
264
266
BrLabel ( l) => Ok ( * l) ,
@@ -294,24 +296,13 @@ fn exec_one(cf: &mut CallFrame, stack: &mut Stack, store: &mut Store, module: &M
294
296
false => return Ok ( ExecResult :: Call ) ,
295
297
} ,
296
298
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
-
308
299
// We're essentially using else as a EndBlockFrame instruction for if blocks
309
300
Else ( end_offset) => {
310
301
let block =
311
302
stack. blocks . pop ( ) . expect ( "else: no label to end, this should have been validated by the parser" ) ;
312
303
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;
315
306
}
316
307
317
308
// 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
321
312
. pop ( )
322
313
. expect ( "end blockframe: no label to end, this should have been validated by the parser" ) ;
323
314
324
- stack. values . truncate_keep ( block. stack_ptr , block. results ) ;
315
+ stack. values . truncate_keep ( block. stack_ptr , block. results as u32 ) ;
325
316
}
326
317
327
318
LocalGet ( local_index) => stack. values . push ( cf. get_local ( * local_index as usize ) ) ,
0 commit comments