wasm/execution/interpreter_loop/
parametric.rs1use core::ops::ControlFlow;
2
3use crate::{
4 assert_validated::UnwrapValidatedExt,
5 core::reader::types::opcode,
6 execution::interpreter_loop::{define_instruction_fn, Args},
7 ValType,
8};
9
10define_instruction_fn! {
11 drop,
12 fuel_check = flat(opcode::DROP),
13 |Args { resumable, .. }| {
14 resumable.stack.pop_value();
15 trace!("Instruction: DROP");
16
17 Ok(ControlFlow::Continue(()))
18 }
19}
20
21define_instruction_fn! {
22 select,
23 fuel_check = flat(opcode::SELECT),
24 |Args { resumable, .. }| {
25 let test_val: i32 = resumable.stack.pop_value().try_into().unwrap_validated();
26 let val2 = resumable.stack.pop_value();
27 let val1 = resumable.stack.pop_value();
28 if test_val != 0 {
29 resumable.stack.push_value(val1)?;
30 } else {
31 resumable.stack.push_value(val2)?;
32 }
33 trace!("Instruction: SELECT");
34 Ok(ControlFlow::Continue(()))
35 }
36}
37
38define_instruction_fn! {
39 select_t,
40 fuel_check = flat(opcode::SELECT_T),
41 |Args {
42 resumable, wasm, ..
43 }| {
44 let _type_vec = wasm.read_vec(ValType::read).unwrap_validated();
45 let test_val: i32 = resumable.stack.pop_value().try_into().unwrap_validated();
46 let val2 = resumable.stack.pop_value();
47 let val1 = resumable.stack.pop_value();
48 if test_val != 0 {
49 resumable.stack.push_value(val1)?;
50 } else {
51 resumable.stack.push_value(val2)?;
52 }
53 trace!("Instruction: SELECT_T");
54 Ok(ControlFlow::Continue(()))
55 }
56}