From 95c52451a75d5a3f0b31eadb3fb69544ebd30419 Mon Sep 17 00:00:00 2001 From: Simon Heath Date: Wed, 17 Jan 2018 12:11:07 -0500 Subject: [PATCH] Replaced mysterous bool's in opcodes with u8 I suppose, looking at the code, a bool is always represented as u8, which is what we want anyway, but since these values are not bools but placeholder integers that must currently always be 0, having them be bools is kind of strange. Replaced the reading/writing of them with VarUint7, which is maybe almost as invalid, but works. Resolves issue #145. --- src/elements/ops.rs | 20 ++++++++++---------- src/interpreter/tests/wabt.rs | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/elements/ops.rs b/src/elements/ops.rs index 33527a7..5dd5ae1 100644 --- a/src/elements/ops.rs +++ b/src/elements/ops.rs @@ -1,7 +1,7 @@ use std::{io, fmt}; use super::{ Serialize, Deserialize, Error, VarUint7, - VarUint1, VarUint32, CountedList, BlockType, + VarUint32, CountedList, BlockType, Uint32, Uint64, CountedListWriter, VarInt32, VarInt64, }; @@ -117,7 +117,7 @@ pub enum Opcode { Return, Call(u32), - CallIndirect(u32, bool), + CallIndirect(u32, u8), Drop, Select, @@ -154,8 +154,8 @@ pub enum Opcode { I64Store16(u32, u32), I64Store32(u32, u32), - CurrentMemory(bool), - GrowMemory(bool), + CurrentMemory(u8), + GrowMemory(u8), I32Const(i32), I64Const(i64), @@ -346,7 +346,7 @@ impl Deserialize for Opcode { 0x10 => Call(VarUint32::deserialize(reader)?.into()), 0x11 => CallIndirect( VarUint32::deserialize(reader)?.into(), - VarUint1::deserialize(reader)?.into()), + VarUint7::deserialize(reader)?.into()), 0x1a => Drop, 0x1b => Select, @@ -449,8 +449,8 @@ impl Deserialize for Opcode { VarUint32::deserialize(reader)?.into()), - 0x3f => CurrentMemory(VarUint1::deserialize(reader)?.into()), - 0x40 => GrowMemory(VarUint1::deserialize(reader)?.into()), + 0x3f => CurrentMemory(VarUint7::deserialize(reader)?.into()), + 0x40 => GrowMemory(VarUint7::deserialize(reader)?.into()), 0x41 => I32Const(VarInt32::deserialize(reader)?.into()), 0x42 => I64Const(VarInt64::deserialize(reader)?.into()), @@ -644,7 +644,7 @@ impl Serialize for Opcode { }), CallIndirect(index, reserved) => op!(writer, 0x11, { VarUint32::from(index).serialize(writer)?; - VarUint1::from(reserved).serialize(writer)?; + VarUint7::from(reserved).serialize(writer)?; }), Drop => op!(writer, 0x1a), Select => op!(writer, 0x1b), @@ -756,10 +756,10 @@ impl Serialize for Opcode { VarUint32::from(offset).serialize(writer)?; }), CurrentMemory(flag) => op!(writer, 0x3f, { - VarUint1::from(flag).serialize(writer)?; + VarUint7::from(flag).serialize(writer)?; }), GrowMemory(flag) => op!(writer, 0x40, { - VarUint1::from(flag).serialize(writer)?; + VarUint7::from(flag).serialize(writer)?; }), I32Const(def) => op!(writer, 0x41, { VarInt32::from(def).serialize(writer)?; diff --git a/src/interpreter/tests/wabt.rs b/src/interpreter/tests/wabt.rs index 8bb5111..8780984 100644 --- a/src/interpreter/tests/wabt.rs +++ b/src/interpreter/tests/wabt.rs @@ -632,7 +632,7 @@ fn callindirect_1() { let body3 = Opcodes::new(vec![ Opcode::GetLocal(0), - Opcode::CallIndirect(0, false), + Opcode::CallIndirect(0, 0), Opcode::End, ]); @@ -691,7 +691,7 @@ fn callindirect_2() { Opcode::GetLocal(0), Opcode::GetLocal(1), Opcode::GetLocal(2), - Opcode::CallIndirect(0, false), + Opcode::CallIndirect(0, 0), Opcode::End, ]);