From 09498ee286e75c44d472ac28d2965454afaf7dab Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 26 Feb 2020 15:42:29 +0100 Subject: [PATCH] fix(interface-types) `arg.get`'s index is of type `u32`. --- src/decoders/binary.rs | 7 ++++++- src/encoders/binary.rs | 2 +- src/interpreter/instruction.rs | 2 +- src/interpreter/instructions/argument_get.rs | 4 ++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/decoders/binary.rs b/src/decoders/binary.rs index 4466439..f6916c8 100644 --- a/src/decoders/binary.rs +++ b/src/decoders/binary.rs @@ -156,7 +156,12 @@ fn instruction<'input, E: ParseError<&'input [u8]>>( Ok(match opcode { 0x00 => { consume!((input, argument_0) = uleb(input)?); - (input, Instruction::ArgumentGet { index: argument_0 }) + ( + input, + Instruction::ArgumentGet { + index: argument_0 as u32, + }, + ) } 0x01 => { diff --git a/src/encoders/binary.rs b/src/encoders/binary.rs index c4f5b53..dbebee2 100644 --- a/src/encoders/binary.rs +++ b/src/encoders/binary.rs @@ -252,7 +252,7 @@ where match self { Instruction::ArgumentGet { index } => { 0x00_u8.to_bytes(writer)?; - index.to_bytes(writer)?; + (*index as u64).to_bytes(writer)?; } Instruction::Call { function_index } => { diff --git a/src/interpreter/instruction.rs b/src/interpreter/instruction.rs index 5364ac5..f20471a 100644 --- a/src/interpreter/instruction.rs +++ b/src/interpreter/instruction.rs @@ -6,7 +6,7 @@ pub enum Instruction<'input> { /// The `arg.get` instruction. ArgumentGet { /// The argument index. - index: u64, + index: u32, }, /// The `call` instruction. diff --git a/src/interpreter/instructions/argument_get.rs b/src/interpreter/instructions/argument_get.rs index 0a67909..e530d88 100644 --- a/src/interpreter/instructions/argument_get.rs +++ b/src/interpreter/instructions/argument_get.rs @@ -1,9 +1,9 @@ executable_instruction!( - argument_get(index: u64, instruction_name: String) -> _ { + argument_get(index: u32, instruction_name: String) -> _ { move |runtime| -> _ { let invocation_inputs = runtime.invocation_inputs; - if index >= (invocation_inputs.len() as u64) { + if index >= (invocation_inputs.len() as u32) { return Err(format!( "`{}` cannot access argument #{} because it doesn't exist.", instruction_name, index