tests and bug fixed for i64store interpretation

This commit is contained in:
NikVolf 2017-05-16 14:42:58 +03:00
parent fa86543fbb
commit 3fb35f29b2
6 changed files with 28 additions and 5 deletions

BIN
res/cases/v1/offset.wasm Normal file

Binary file not shown.

11
res/cases/v1/offset.wast Normal file
View File

@ -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
)
)

View File

@ -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]);
}
}

View File

@ -67,6 +67,7 @@ impl MemoryInstance {
let mut mut_buffer = buffer.as_mut_slice();
mut_buffer[begin..end].copy_from_slice(value);
Ok(())
}

View File

@ -395,7 +395,7 @@ impl Interpreter {
.map(|_| InstructionOutcome::RunNextInstruction)
}
fn run_load<T>(context: &mut FunctionContext, offset: u32, _align: u32) -> Result<InstructionOutcome, Error>
fn run_load<T>(context: &mut FunctionContext, _align: u32, offset: u32) -> Result<InstructionOutcome, Error>
where RuntimeValue: From<T>, 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<T, U>(context: &mut FunctionContext, offset: u32, _align: u32) -> Result<InstructionOutcome, Error>
fn run_load_extend<T, U>(context: &mut FunctionContext, _align: u32, offset: u32) -> Result<InstructionOutcome, Error>
where T: ExtendInto<U>, RuntimeValue: From<U>, 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<T>(context: &mut FunctionContext, offset: u32, _align: u32) -> Result<InstructionOutcome, Error>
fn run_store<T>(context: &mut FunctionContext, _align: u32, offset: u32, ) -> Result<InstructionOutcome, Error>
where RuntimeValue: TryInto<T, Error>, T: LittleEndianConvert {
let stack_value = context
.value_stack_mut()
@ -433,7 +433,7 @@ impl Interpreter {
.map(|_| InstructionOutcome::RunNextInstruction)
}
fn run_store_wrap<T, U>(context: &mut FunctionContext, offset: u32, _align: u32) -> Result<InstructionOutcome, Error>
fn run_store_wrap<T, U>(context: &mut FunctionContext, _align: u32, offset: u32) -> Result<InstructionOutcome, Error>
where RuntimeValue: TryInto<T, Error>, T: WrapInto<U>, 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();

View File

@ -508,7 +508,7 @@ fn return_void() {
])),
Opcode::I32Const(0),
Opcode::I32Const(1),
Opcode::I32Store(0, 2),
Opcode::I32Store(2, 0),
Opcode::End,
]);