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.
This commit is contained in:
Simon Heath
2018-01-17 12:11:07 -05:00
parent a597cdb15d
commit 95c52451a7
2 changed files with 12 additions and 12 deletions

View File

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