From 6b5975ea472614b057f4b9a7f6b84f596f260113 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 23 Mar 2020 14:34:57 +0100 Subject: [PATCH] fix(interface-types) Use same stack order than Wasm invocation rule. --- src/interpreter/instructions/call_core.rs | 8 +++--- .../instructions/memory_to_string.rs | 26 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/interpreter/instructions/call_core.rs b/src/interpreter/instructions/call_core.rs index 7748649..5a3da21 100644 --- a/src/interpreter/instructions/call_core.rs +++ b/src/interpreter/instructions/call_core.rs @@ -70,8 +70,8 @@ mod tests { test_executable_instruction!( test_call_core = instructions: [ - Instruction::ArgumentGet { index: 1 }, Instruction::ArgumentGet { index: 0 }, + Instruction::ArgumentGet { index: 1 }, Instruction::CallCore { function_index: 42 }, ], invocation_inputs: [ @@ -113,8 +113,8 @@ mod tests { test_executable_instruction!( test_call_core__invalid_types_in_the_stack = instructions: [ - Instruction::ArgumentGet { index: 1 }, Instruction::ArgumentGet { index: 0 }, + Instruction::ArgumentGet { index: 1 }, Instruction::CallCore { function_index: 42 }, ], invocation_inputs: [ @@ -129,8 +129,8 @@ mod tests { test_executable_instruction!( test_call_core__failure_when_calling = instructions: [ - Instruction::ArgumentGet { index: 1 }, Instruction::ArgumentGet { index: 0 }, + Instruction::ArgumentGet { index: 1 }, Instruction::CallCore { function_index: 42 }, ], invocation_inputs: [ @@ -160,8 +160,8 @@ mod tests { test_executable_instruction!( test_call_core__void = instructions: [ - Instruction::ArgumentGet { index: 1 }, Instruction::ArgumentGet { index: 0 }, + Instruction::ArgumentGet { index: 1 }, Instruction::CallCore { function_index: 42 }, ], invocation_inputs: [ diff --git a/src/interpreter/instructions/memory_to_string.rs b/src/interpreter/instructions/memory_to_string.rs index e30b70c..8e9902c 100644 --- a/src/interpreter/instructions/memory_to_string.rs +++ b/src/interpreter/instructions/memory_to_string.rs @@ -27,8 +27,8 @@ executable_instruction!( ) })?; - let length = to_native::(&inputs[0], instruction)? as usize; - let pointer = to_native::(&inputs[1], instruction)? as usize; + let pointer = to_native::(&inputs[0], instruction)? as usize; + let length = to_native::(&inputs[1], instruction)? as usize; let memory_view = memory.view(); if length == 0 { @@ -67,15 +67,15 @@ mod tests { test_executable_instruction!( test_memory_to_string = instructions: [ - Instruction::ArgumentGet { index: 1 }, Instruction::ArgumentGet { index: 0 }, + Instruction::ArgumentGet { index: 1 }, Instruction::MemoryToString, ], invocation_inputs: [ - InterfaceValue::I32(13), - // ^^^^^^^ length InterfaceValue::I32(0), // ^^^^^^ pointer + InterfaceValue::I32(13), + // ^^^^^^^ length ], instance: Instance { memory: Memory::new("Hello, World!".as_bytes().iter().map(|u| Cell::new(*u)).collect()), @@ -87,8 +87,8 @@ mod tests { test_executable_instruction!( test_memory_to_string__empty_string = instructions: [ - Instruction::ArgumentGet { index: 1 }, Instruction::ArgumentGet { index: 0 }, + Instruction::ArgumentGet { index: 1 }, Instruction::MemoryToString, ], invocation_inputs: [ @@ -105,15 +105,15 @@ mod tests { test_executable_instruction!( test_memory_to_string__read_out_of_memory = instructions: [ - Instruction::ArgumentGet { index: 1 }, Instruction::ArgumentGet { index: 0 }, + Instruction::ArgumentGet { index: 1 }, Instruction::MemoryToString, ], invocation_inputs: [ - InterfaceValue::I32(13), - // ^^^^^^^ length is too long InterfaceValue::I32(0), // ^^^^^^ pointer + InterfaceValue::I32(13), + // ^^^^^^^ length is too long ], instance: Instance { memory: Memory::new("Hello!".as_bytes().iter().map(|u| Cell::new(*u)).collect()), @@ -125,15 +125,15 @@ mod tests { test_executable_instruction!( test_memory_to_string__invalid_encoding = instructions: [ - Instruction::ArgumentGet { index: 1 }, Instruction::ArgumentGet { index: 0 }, + Instruction::ArgumentGet { index: 1 }, Instruction::MemoryToString, ], invocation_inputs: [ - InterfaceValue::I32(4), - // ^^^^^^ length is too long InterfaceValue::I32(0), // ^^^^^^ pointer + InterfaceValue::I32(4), + // ^^^^^^ length is too long ], instance: Instance { memory: Memory::new(vec![0, 159, 146, 150].iter().map(|b| Cell::new(*b)).collect::>>()), @@ -150,8 +150,8 @@ mod tests { // ^^^^^^^^^^^^^^ `memory-to-string` expects 2 values on the stack, only one is present. ], invocation_inputs: [ - InterfaceValue::I32(13), InterfaceValue::I32(0), + InterfaceValue::I32(13), ], instance: Instance::new(), error: r#"`memory-to-string` needed to read `2` value(s) from the stack, but it doesn't contain enough data"#,