diff --git a/crates/wasm_interp/src/instance.rs b/crates/wasm_interp/src/instance.rs index 89209a7178..0eb85e1f85 100644 --- a/crates/wasm_interp/src/instance.rs +++ b/crates/wasm_interp/src/instance.rs @@ -10,7 +10,7 @@ use roc_wasm_module::{Value, ValueType}; use crate::call_stack::CallStack; use crate::value_stack::ValueStack; -use crate::{Error, ImportDispatcher}; +use crate::{pc_to_fn_index, Error, ImportDispatcher}; #[derive(Debug)] pub enum Action { @@ -459,7 +459,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> { } let mut action = Action::Continue; - // let mut implicit_return = false; + let mut implicit_return = false; match op_code { UNREACHABLE => { @@ -517,7 +517,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> { if self.blocks.len() == self.outermost_block as usize { // implicit RETURN at end of function action = self.do_return(); - // implicit_return = true; + implicit_return = true; } else { self.blocks.pop().unwrap(); } @@ -1518,17 +1518,17 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> { } } - // if let Some(debug_string) = &self.debug_string { - // let base = self.call_stack.value_stack_base(); - // let slice = self.value_stack.get_slice(base as usize); - // eprintln!("{:06x} {:17} {:?}", file_offset, debug_string, slice); - // if op_code == RETURN || (op_code == END && implicit_return) { - // let fn_index = pc_to_fn_index(self.program_counter, module); - // eprintln!("returning to function {}\n", fn_index); - // } else if op_code == CALL || op_code == CALLINDIRECT { - // eprintln!(); - // } - // } + if let Some(debug_string) = &self.debug_string { + let base = self.call_stack.value_stack_base(); + let slice = self.value_stack.get_slice(base as usize); + eprintln!("{:06x} {:17} {:?}", file_offset, debug_string, slice); + if op_code == RETURN || (op_code == END && implicit_return) { + let fn_index = pc_to_fn_index(self.program_counter, module); + eprintln!("returning to function {}\n", fn_index); + } else if op_code == CALL || op_code == CALLINDIRECT { + eprintln!(); + } + } Ok(action) } diff --git a/crates/wasm_interp/src/value_stack.rs b/crates/wasm_interp/src/value_stack.rs index fc70d95cdd..d45389b90c 100644 --- a/crates/wasm_interp/src/value_stack.rs +++ b/crates/wasm_interp/src/value_stack.rs @@ -94,6 +94,10 @@ impl<'a> ValueStack<'a> { pub(crate) fn truncate(&mut self, depth: usize) { self.values.truncate(depth) } + + pub(crate) fn get_slice(&mut self, from: usize) -> &[Value] { + &self.values[from..] + } } impl Debug for ValueStack<'_> {