diff --git a/src/interpreter/instructions/call.rs b/src/interpreter/instructions/call.rs index d58368c..f6375c4 100644 --- a/src/interpreter/instructions/call.rs +++ b/src/interpreter/instructions/call.rs @@ -6,7 +6,7 @@ use crate::interpreter::wasm::{ executable_instruction!( call(function_index: usize, instruction_name: String) -> _ { move |runtime| -> _ { - let instance = runtime.wasm_instance; + let instance = &mut runtime.wasm_instance; let index = FunctionIndex::new(function_index); match instance.local_or_import(index) { diff --git a/src/interpreter/instructions/call_export.rs b/src/interpreter/instructions/call_export.rs index a1a4340..62e360a 100644 --- a/src/interpreter/instructions/call_export.rs +++ b/src/interpreter/instructions/call_export.rs @@ -3,7 +3,7 @@ use crate::interpreter::wasm::values::InterfaceType; executable_instruction!( call_export(export_name: String, instruction_name: String) -> _ { move |runtime| -> _ { - let instance = runtime.wasm_instance; + let instance = &mut runtime.wasm_instance; match instance.export(&export_name) { Some(export) => { diff --git a/src/interpreter/instructions/mod.rs b/src/interpreter/instructions/mod.rs index 183e0dc..d84d2b4 100644 --- a/src/interpreter/instructions/mod.rs +++ b/src/interpreter/instructions/mod.rs @@ -175,7 +175,7 @@ pub(crate) mod tests { } fn local_or_import( - &self, + &mut self, index: I, ) -> Option<&LocalImport> { self.locals_or_imports.get(&index.index()) diff --git a/src/interpreter/instructions/write_utf8.rs b/src/interpreter/instructions/write_utf8.rs index b0738f3..a1e2150 100644 --- a/src/interpreter/instructions/write_utf8.rs +++ b/src/interpreter/instructions/write_utf8.rs @@ -4,7 +4,7 @@ use std::convert::TryInto; executable_instruction!( write_utf8(allocator_name: String, instruction_name: String) -> _ { move |runtime| -> _ { - let instance = runtime.wasm_instance; + let instance = &mut runtime.wasm_instance; match instance.export(&allocator_name) { Some(allocator) => { @@ -17,7 +17,7 @@ executable_instruction!( )) } - match runtime.wasm_instance.memory(0) { + match instance.memory(0) { Some(memory) => match runtime.stack.pop1() { Some(string) => { let memory_view = memory.view(); diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 1b133a7..551311a 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -18,7 +18,7 @@ where { invocation_inputs: &'invocation [InterfaceValue], stack: Stack, - wasm_instance: &'instance Instance, + wasm_instance: &'instance mut Instance, _phantom: PhantomData<(Export, LocalImport, Memory, MemoryView)>, } @@ -58,7 +58,7 @@ where pub fn run( &self, invocation_inputs: &[InterfaceValue], - wasm_instance: &Instance, + wasm_instance: &mut Instance, ) -> Result, String> { let mut runtime = Runtime { invocation_inputs, diff --git a/src/interpreter/wasm/structures.rs b/src/interpreter/wasm/structures.rs index a38511c..7ec386f 100644 --- a/src/interpreter/wasm/structures.rs +++ b/src/interpreter/wasm/structures.rs @@ -70,7 +70,7 @@ where MV: MemoryView, { fn export(&self, export_name: &str) -> Option<&E>; - fn local_or_import(&self, index: I) -> Option<&LI>; + fn local_or_import(&mut self, index: I) -> Option<&LI>; fn memory(&self, index: usize) -> Option<&M>; } @@ -151,7 +151,7 @@ where None } - fn local_or_import(&self, _index: I) -> Option<&LI> { + fn local_or_import(&mut self, _index: I) -> Option<&LI> { None } } diff --git a/src/macros.rs b/src/macros.rs index aee8178..a0b9994 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -68,8 +68,8 @@ macro_rules! test_executable_instruction { (&vec![$($instructions),*]).try_into().unwrap(); let invocation_inputs = vec![$($invocation_inputs),*]; - let instance = $instance; - let run = interpreter.run(&invocation_inputs, &instance); + let mut instance = $instance; + let run = interpreter.run(&invocation_inputs, &mut instance); assert!(run.is_ok()); @@ -102,8 +102,8 @@ macro_rules! test_executable_instruction { (&vec![$($instructions),*]).try_into().unwrap(); let invocation_inputs = vec![$($invocation_inputs),*]; - let instance = $instance; - let run = interpreter.run(&invocation_inputs, &instance); + let mut instance = $instance; + let run = interpreter.run(&invocation_inputs, &mut instance); assert!(run.is_err());