diff --git a/res/cases/v1/offset.wasm b/res/cases/v1/offset.wasm new file mode 100644 index 0000000..fa0ae47 Binary files /dev/null and b/res/cases/v1/offset.wasm differ diff --git a/res/cases/v1/offset.wast b/res/cases/v1/offset.wast new file mode 100644 index 0000000..e22ce0c --- /dev/null +++ b/res/cases/v1/offset.wast @@ -0,0 +1,11 @@ +(module + (import "env" "memory" (memory (;0;) 256 256)) + (type (;0;) (func (result i32))) + (func (;0;) (type 0) (result i32) + (local i32) + get_local 0 + i64.const 72340172838076673 + i64.store offset=32 align=1 + i32.const 1 + ) +) \ No newline at end of file diff --git a/src/elements/module.rs b/src/elements/module.rs index 045fe92..057aab7 100644 --- a/src/elements/module.rs +++ b/src/elements/module.rs @@ -276,4 +276,15 @@ mod integration_tests { assert_eq!(I32Const(-16384), func.code().elements()[10]); assert_eq!(I32Const(-32768), func.code().elements()[11]); } + + #[test] + fn store() { + use super::super::Opcode::*; + + let module = deserialize_file("./res/cases/v1/offset.wasm").expect("Should be deserialized"); + let func = &module.code_section().expect("Code section to exist").bodies()[0]; + + assert_eq!(func.code().elements().len(), 5); + assert_eq!(I64Store(0, 32), func.code().elements()[2]); + } } \ No newline at end of file diff --git a/src/interpreter/memory.rs b/src/interpreter/memory.rs index 3a03790..1618bad 100644 --- a/src/interpreter/memory.rs +++ b/src/interpreter/memory.rs @@ -67,6 +67,7 @@ impl MemoryInstance { let mut mut_buffer = buffer.as_mut_slice(); mut_buffer[begin..end].copy_from_slice(value); + Ok(()) } diff --git a/src/interpreter/runner.rs b/src/interpreter/runner.rs index 1597f88..5069895 100644 --- a/src/interpreter/runner.rs +++ b/src/interpreter/runner.rs @@ -395,7 +395,7 @@ impl Interpreter { .map(|_| InstructionOutcome::RunNextInstruction) } - fn run_load(context: &mut FunctionContext, offset: u32, _align: u32) -> Result + fn run_load(context: &mut FunctionContext, _align: u32, offset: u32) -> Result where RuntimeValue: From, T: LittleEndianConvert { let address = effective_address(offset, context.value_stack_mut().pop_as()?)?; context.module() @@ -406,7 +406,7 @@ impl Interpreter { .map(|_| InstructionOutcome::RunNextInstruction) } - fn run_load_extend(context: &mut FunctionContext, offset: u32, _align: u32) -> Result + fn run_load_extend(context: &mut FunctionContext, _align: u32, offset: u32) -> Result where T: ExtendInto, RuntimeValue: From, T: LittleEndianConvert { let address = effective_address(offset, context.value_stack_mut().pop_as()?)?; let stack_value: U = context.module() @@ -420,7 +420,7 @@ impl Interpreter { .map(|_| InstructionOutcome::RunNextInstruction) } - fn run_store(context: &mut FunctionContext, offset: u32, _align: u32) -> Result + fn run_store(context: &mut FunctionContext, _align: u32, offset: u32, ) -> Result where RuntimeValue: TryInto, T: LittleEndianConvert { let stack_value = context .value_stack_mut() @@ -433,7 +433,7 @@ impl Interpreter { .map(|_| InstructionOutcome::RunNextInstruction) } - fn run_store_wrap(context: &mut FunctionContext, offset: u32, _align: u32) -> Result + fn run_store_wrap(context: &mut FunctionContext, _align: u32, offset: u32) -> Result where RuntimeValue: TryInto, T: WrapInto, U: LittleEndianConvert { let stack_value: T = context.value_stack_mut().pop().and_then(|v| v.try_into())?; let stack_value = stack_value.wrap_into().into_little_endian(); diff --git a/src/interpreter/tests/wabt.rs b/src/interpreter/tests/wabt.rs index 1f8fdff..d069392 100644 --- a/src/interpreter/tests/wabt.rs +++ b/src/interpreter/tests/wabt.rs @@ -508,7 +508,7 @@ fn return_void() { ])), Opcode::I32Const(0), Opcode::I32Const(1), - Opcode::I32Store(0, 2), + Opcode::I32Store(2, 0), Opcode::End, ]);