feat(interface-types) Remove abandonned instructions.

This commit is contained in:
Ivan Enderlin
2020-02-26 15:48:00 +01:00
parent 350a30507f
commit f951b6aa53
6 changed files with 3 additions and 404 deletions

View File

@ -196,77 +196,6 @@ fn instruction<'input, E: ParseError<&'input [u8]>>(
) )
} }
0x05 => {
consume!((input, argument_0) = ty(input)?);
(input, Instruction::AsWasm(argument_0))
}
0x06 => {
consume!((input, argument_0) = ty(input)?);
(input, Instruction::AsInterface(argument_0))
}
0x07 => (input, Instruction::TableRefAdd),
0x08 => (input, Instruction::TableRefGet),
0x09 => {
consume!((input, argument_0) = uleb(input)?);
(input, Instruction::CallMethod(argument_0))
}
0x0a => {
consume!((input, argument_0) = ty(input)?);
(input, Instruction::MakeRecord(argument_0))
}
0x0c => {
consume!((input, argument_0) = ty(input)?);
consume!((input, argument_1) = uleb(input)?);
(input, Instruction::GetField(argument_0, argument_1))
}
0x0d => {
consume!((input, argument_0) = ty(input)?);
consume!((input, argument_1) = uleb(input)?);
(input, Instruction::Const(argument_0, argument_1))
}
0x0e => {
consume!((input, argument_0) = uleb(input)?);
(input, Instruction::FoldSeq(argument_0))
}
0x0f => {
consume!((input, argument_0) = ty(input)?);
(input, Instruction::Add(argument_0))
}
0x10 => {
consume!((input, argument_0) = ty(input)?);
consume!((input, argument_1) = string(input)?);
(input, Instruction::MemToSeq(argument_0, argument_1))
}
0x11 => {
consume!((input, argument_0) = ty(input)?);
consume!((input, argument_1) = string(input)?);
(input, Instruction::Load(argument_0, argument_1))
}
0x12 => {
consume!((input, argument_0) = ty(input)?);
(input, Instruction::SeqNew(argument_0))
}
0x13 => (input, Instruction::ListPush),
0x14 => {
consume!((input, argument_0) = uleb(input)?);
consume!((input, argument_1) = uleb(input)?);
(input, Instruction::RepeatUntil(argument_0, argument_1))
}
_ => return Err(Err::Error(make_error(input, ErrorKind::ParseTo))), _ => return Err(Err::Error(make_error(input, ErrorKind::ParseTo))),
}) })
} }
@ -670,27 +599,12 @@ mod tests {
#[test] #[test]
fn test_instructions() { fn test_instructions() {
let input = &[ let input = &[
0x14, // list of 20 items 0x05, // list of 5 items
0x00, 0x01, // ArgumentGet { index: 1 } 0x00, 0x01, // ArgumentGet { index: 1 }
0x01, 0x01, // Call { function_index: 1 } 0x01, 0x01, // Call { function_index: 1 }
0x02, 0x03, 0x61, 0x62, 0x63, // CallExport { export_name: "abc" } 0x02, 0x03, 0x61, 0x62, 0x63, // CallExport { export_name: "abc" }
0x03, // ReadUtf8 0x03, // ReadUtf8
0x04, 0x03, 0x61, 0x62, 0x63, // WriteUtf8 { allocator_name: "abc" } 0x04, 0x03, 0x61, 0x62, 0x63, // WriteUtf8 { allocator_name: "abc" }
0x05, 0x00, // AsWasm(S8)
0x06, 0x00, // AsInterface(S8)
0x07, // TableRefAdd
0x08, // TableRefGet
0x09, 0x01, // CallMethod(1)
0x0a, 0x0c, // MakeRecord(I32)
0x0c, 0x00, 0x02, // GetField(S8, 2)
0x0d, 0x0c, 0x01, // Const(I32, 1)
0x0e, 0x01, // FoldSeq(1)
0x0f, 0x00, // Add(I32)
0x10, 0x00, 0x03, 0x61, 0x62, 0x63, // MemToSeq(S8, "abc")
0x11, 0x00, 0x03, 0x61, 0x62, 0x63, // Load(S8, "abc")
0x12, 0x00, // SeqNew(S8)
0x13, // ListPush
0x14, 0x01, 0x02, // RepeatUntil(1, 2)
0x0a, 0x0a,
]; ];
let output = Ok(( let output = Ok((
@ -703,21 +617,6 @@ mod tests {
Instruction::WriteUtf8 { Instruction::WriteUtf8 {
allocator_name: "abc", allocator_name: "abc",
}, },
Instruction::AsWasm(InterfaceType::S8),
Instruction::AsInterface(InterfaceType::S8),
Instruction::TableRefAdd,
Instruction::TableRefGet,
Instruction::CallMethod(1),
Instruction::MakeRecord(InterfaceType::I32),
Instruction::GetField(InterfaceType::S8, 2),
Instruction::Const(InterfaceType::I32, 1),
Instruction::FoldSeq(1),
Instruction::Add(InterfaceType::S8),
Instruction::MemToSeq(InterfaceType::S8, "abc"),
Instruction::Load(InterfaceType::S8, "abc"),
Instruction::SeqNew(InterfaceType::S8),
Instruction::ListPush,
Instruction::RepeatUntil(1, 2),
], ],
)); ));

View File

@ -150,66 +150,6 @@ impl<'a> Parse<'a> for Instruction<'a> {
Ok(Instruction::WriteUtf8 { Ok(Instruction::WriteUtf8 {
allocator_name: parser.parse()?, allocator_name: parser.parse()?,
}) })
} else if lookahead.peek::<keyword::as_wasm>() {
parser.parse::<keyword::as_wasm>()?;
Ok(Instruction::AsWasm(parser.parse()?))
} else if lookahead.peek::<keyword::as_interface>() {
parser.parse::<keyword::as_interface>()?;
Ok(Instruction::AsInterface(parser.parse()?))
} else if lookahead.peek::<keyword::table_ref_add>() {
parser.parse::<keyword::table_ref_add>()?;
Ok(Instruction::TableRefAdd)
} else if lookahead.peek::<keyword::table_ref_get>() {
parser.parse::<keyword::table_ref_get>()?;
Ok(Instruction::TableRefGet)
} else if lookahead.peek::<keyword::call_method>() {
parser.parse::<keyword::call_method>()?;
Ok(Instruction::CallMethod(parser.parse()?))
} else if lookahead.peek::<keyword::make_record>() {
parser.parse::<keyword::make_record>()?;
Ok(Instruction::MakeRecord(parser.parse()?))
} else if lookahead.peek::<keyword::get_field>() {
parser.parse::<keyword::get_field>()?;
Ok(Instruction::GetField(parser.parse()?, parser.parse()?))
} else if lookahead.peek::<keyword::r#const>() {
parser.parse::<keyword::r#const>()?;
Ok(Instruction::Const(parser.parse()?, parser.parse()?))
} else if lookahead.peek::<keyword::fold_seq>() {
parser.parse::<keyword::fold_seq>()?;
Ok(Instruction::FoldSeq(parser.parse()?))
} else if lookahead.peek::<keyword::add>() {
parser.parse::<keyword::add>()?;
Ok(Instruction::Add(parser.parse()?))
} else if lookahead.peek::<keyword::mem_to_seq>() {
parser.parse::<keyword::mem_to_seq>()?;
Ok(Instruction::MemToSeq(parser.parse()?, parser.parse()?))
} else if lookahead.peek::<keyword::load>() {
parser.parse::<keyword::load>()?;
Ok(Instruction::Load(parser.parse()?, parser.parse()?))
} else if lookahead.peek::<keyword::seq_new>() {
parser.parse::<keyword::seq_new>()?;
Ok(Instruction::SeqNew(parser.parse()?))
} else if lookahead.peek::<keyword::list_push>() {
parser.parse::<keyword::list_push>()?;
Ok(Instruction::ListPush)
} else if lookahead.peek::<keyword::repeat_until>() {
parser.parse::<keyword::repeat_until>()?;
Ok(Instruction::RepeatUntil(parser.parse()?, parser.parse()?))
} else { } else {
Err(lookahead.error()) Err(lookahead.error())
} }
@ -562,21 +502,6 @@ mod tests {
r#"call-export "foo""#, r#"call-export "foo""#,
"read-utf8", "read-utf8",
r#"write-utf8 "foo""#, r#"write-utf8 "foo""#,
"as-wasm s8",
"as-interface anyref",
"table-ref-add",
"table-ref-get",
"call-method 7",
"make-record s8",
"get-field i32 7",
"const i32 7",
"fold-seq 7",
"add i32",
r#"mem-to-seq i32 "foo""#,
r#"load i32 "foo""#,
"seq.new i32",
"list.push",
"repeat-until 1 2",
]; ];
let outputs = vec![ let outputs = vec![
Instruction::ArgumentGet { index: 7 }, Instruction::ArgumentGet { index: 7 },
@ -586,21 +511,6 @@ mod tests {
Instruction::WriteUtf8 { Instruction::WriteUtf8 {
allocator_name: "foo", allocator_name: "foo",
}, },
Instruction::AsWasm(InterfaceType::S8),
Instruction::AsInterface(InterfaceType::Anyref),
Instruction::TableRefAdd,
Instruction::TableRefGet,
Instruction::CallMethod(7),
Instruction::MakeRecord(InterfaceType::S8),
Instruction::GetField(InterfaceType::I32, 7),
Instruction::Const(InterfaceType::I32, 7),
Instruction::FoldSeq(7),
Instruction::Add(InterfaceType::I32),
Instruction::MemToSeq(InterfaceType::I32, "foo"),
Instruction::Load(InterfaceType::I32, "foo"),
Instruction::SeqNew(InterfaceType::I32),
Instruction::ListPush,
Instruction::RepeatUntil(1, 2),
]; ];
assert_eq!(inputs.len(), outputs.len()); assert_eq!(inputs.len(), outputs.len());

View File

@ -271,77 +271,6 @@ where
0x04_u8.to_bytes(writer)?; 0x04_u8.to_bytes(writer)?;
allocator_name.to_bytes(writer)?; allocator_name.to_bytes(writer)?;
} }
Instruction::AsWasm(interface_type) => {
0x05_u8.to_bytes(writer)?;
interface_type.to_bytes(writer)?;
}
Instruction::AsInterface(interface_type) => {
0x06_u8.to_bytes(writer)?;
interface_type.to_bytes(writer)?;
}
Instruction::TableRefAdd => 0x07_u8.to_bytes(writer)?,
Instruction::TableRefGet => 0x08_u8.to_bytes(writer)?,
Instruction::CallMethod(function_index) => {
0x09_u8.to_bytes(writer)?;
function_index.to_bytes(writer)?;
}
Instruction::MakeRecord(interface_type) => {
0x0a_u8.to_bytes(writer)?;
interface_type.to_bytes(writer)?;
}
Instruction::GetField(interface_type, field_index) => {
0x0c_u8.to_bytes(writer)?;
interface_type.to_bytes(writer)?;
field_index.to_bytes(writer)?;
}
Instruction::Const(interface_type, index) => {
0x0d_u8.to_bytes(writer)?;
interface_type.to_bytes(writer)?;
index.to_bytes(writer)?;
}
Instruction::FoldSeq(index) => {
0x0e_u8.to_bytes(writer)?;
index.to_bytes(writer)?;
}
Instruction::Add(interface_type) => {
0x0f_u8.to_bytes(writer)?;
interface_type.to_bytes(writer)?;
}
Instruction::MemToSeq(interface_type, string) => {
0x10_u8.to_bytes(writer)?;
interface_type.to_bytes(writer)?;
string.to_bytes(writer)?;
}
Instruction::Load(interface_type, string) => {
0x11_u8.to_bytes(writer)?;
interface_type.to_bytes(writer)?;
string.to_bytes(writer)?;
}
Instruction::SeqNew(interface_type) => {
0x12_u8.to_bytes(writer)?;
interface_type.to_bytes(writer)?;
}
Instruction::ListPush => 0x13_u8.to_bytes(writer)?,
Instruction::RepeatUntil(index1, index2) => {
0x14_u8.to_bytes(writer)?;
index1.to_bytes(writer)?;
index2.to_bytes(writer)?;
}
} }
Ok(()) Ok(())
@ -591,44 +520,14 @@ mod tests {
Instruction::WriteUtf8 { Instruction::WriteUtf8 {
allocator_name: "abc", allocator_name: "abc",
}, },
Instruction::AsWasm(InterfaceType::I32),
Instruction::AsInterface(InterfaceType::I64),
Instruction::TableRefAdd,
Instruction::TableRefGet,
Instruction::CallMethod(1),
Instruction::MakeRecord(InterfaceType::I32),
Instruction::GetField(InterfaceType::I32, 2),
Instruction::Const(InterfaceType::I32, 1),
Instruction::FoldSeq(1),
Instruction::Add(InterfaceType::I32),
Instruction::MemToSeq(InterfaceType::I32, "abc"),
Instruction::Load(InterfaceType::I32, "abc"),
Instruction::SeqNew(InterfaceType::I32),
Instruction::ListPush,
Instruction::RepeatUntil(1, 2),
], ],
&[ &[
0x14, // list of 20 items 0x05, // list of 5 items
0x00, 0x01, // ArgumentGet { index: 1 } 0x00, 0x01, // ArgumentGet { index: 1 }
0x01, 0x01, // Call { function_index: 1 } 0x01, 0x01, // Call { function_index: 1 }
0x02, 0x03, 0x61, 0x62, 0x63, // CallExport { export_name: "abc" } 0x02, 0x03, 0x61, 0x62, 0x63, // CallExport { export_name: "abc" }
0x03, // ReadUtf8 0x03, // ReadUtf8
0x04, 0x03, 0x61, 0x62, 0x63, // WriteUtf8 { allocator_name: "abc" } 0x04, 0x03, 0x61, 0x62, 0x63, // WriteUtf8 { allocator_name: "abc" }
0x05, 0x0c, // AsWasm(Int)
0x06, 0x0d, // AsInterface(I64)
0x07, // TableRefAdd
0x08, // TableRefGet
0x09, 0x01, // CallMethod(1)
0x0a, 0x0c, // MakeRecord(I32)
0x0c, 0x0c, 0x02, // GetField(I32, 2)
0x0d, 0x0c, 0x01, // Const(I32, 1)
0x0e, 0x01, // FoldSeq(1)
0x0f, 0x0c, // Add(I32)
0x10, 0x0c, 0x03, 0x61, 0x62, 0x63, // MemToSeq(I32, "abc")
0x11, 0x0c, 0x03, 0x61, 0x62, 0x63, // Load(I32, "abc")
0x12, 0x0c, // SeqNew(I32)
0x13, // ListPush
0x14, 0x01, 0x02, // RepeatUntil(1, 2)
] ]
); );
} }

View File

@ -92,39 +92,6 @@ impl<'input> ToString for &Instruction<'input> {
Instruction::WriteUtf8 { allocator_name } => { Instruction::WriteUtf8 { allocator_name } => {
format!(r#"write-utf8 "{}""#, allocator_name) format!(r#"write-utf8 "{}""#, allocator_name)
} }
Instruction::AsWasm(interface_type) => {
format!("as-wasm {}", interface_type.to_string())
}
Instruction::AsInterface(interface_type) => {
format!("as-interface {}", interface_type.to_string())
}
Instruction::TableRefAdd => "table-ref-add".into(),
Instruction::TableRefGet => "table-ref-get".into(),
Instruction::CallMethod(index) => format!("call-method {}", index),
Instruction::MakeRecord(interface_type) => {
format!("make-record {}", interface_type.to_string())
}
Instruction::GetField(interface_type, field_index) => {
format!("get-field {} {}", interface_type.to_string(), field_index)
}
Instruction::Const(interface_type, value) => {
format!("const {} {}", interface_type.to_string(), value)
}
Instruction::FoldSeq(import_index) => format!("fold-seq {}", import_index),
Instruction::Add(interface_type) => format!("add {}", interface_type.to_string()),
Instruction::MemToSeq(interface_type, memory) => {
format!(r#"mem-to-seq {} "{}""#, interface_type.to_string(), memory)
}
Instruction::Load(interface_type, memory) => {
format!(r#"load {} "{}""#, interface_type.to_string(), memory)
}
Instruction::SeqNew(interface_type) => {
format!("seq.new {}", interface_type.to_string())
}
Instruction::ListPush => "list.push".into(),
Instruction::RepeatUntil(condition_index, step_index) => {
format!("repeat-until {} {}", condition_index, step_index)
}
} }
} }
} }
@ -364,21 +331,6 @@ mod tests {
allocator_name: "foo", allocator_name: "foo",
}) })
.to_string(), .to_string(),
(&Instruction::AsWasm(InterfaceType::I32)).to_string(),
(&Instruction::AsInterface(InterfaceType::I32)).to_string(),
(&Instruction::TableRefAdd).to_string(),
(&Instruction::TableRefGet).to_string(),
(&Instruction::CallMethod(7)).to_string(),
(&Instruction::MakeRecord(InterfaceType::I32)).to_string(),
(&Instruction::GetField(InterfaceType::I32, 7)).to_string(),
(&Instruction::Const(InterfaceType::I32, 7)).to_string(),
(&Instruction::FoldSeq(7)).to_string(),
(&Instruction::Add(InterfaceType::I32)).to_string(),
(&Instruction::MemToSeq(InterfaceType::I32, "foo")).to_string(),
(&Instruction::Load(InterfaceType::I32, "foo")).to_string(),
(&Instruction::SeqNew(InterfaceType::I32)).to_string(),
(&Instruction::ListPush).to_string(),
(&Instruction::RepeatUntil(1, 2)).to_string(),
]; ];
let outputs = vec![ let outputs = vec![
"arg.get 7", "arg.get 7",
@ -386,21 +338,6 @@ mod tests {
r#"call-export "foo""#, r#"call-export "foo""#,
"read-utf8", "read-utf8",
r#"write-utf8 "foo""#, r#"write-utf8 "foo""#,
"as-wasm i32",
"as-interface i32",
"table-ref-add",
"table-ref-get",
"call-method 7",
"make-record i32",
"get-field i32 7",
"const i32 7",
"fold-seq 7",
"add i32",
r#"mem-to-seq i32 "foo""#,
r#"load i32 "foo""#,
"seq.new i32",
"list.push",
"repeat-until 1 2",
]; ];
assert_eq!(inputs, outputs); assert_eq!(inputs, outputs);

View File

@ -1,4 +1,4 @@
use crate::ast::InterfaceType; //use crate::ast::InterfaceType;
/// Represents all the possible WIT instructions. /// Represents all the possible WIT instructions.
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
@ -29,49 +29,4 @@ pub enum Instruction<'input> {
/// The allocator function name. /// The allocator function name.
allocator_name: &'input str, allocator_name: &'input str,
}, },
/// The `as-wasm` instruction.
AsWasm(InterfaceType),
/// The `as-interface` instruction.
AsInterface(InterfaceType),
/// The `table-ref-add` instruction.
TableRefAdd,
/// The `table-ref-get` instruction.
TableRefGet,
/// The `call-method` instruction.
CallMethod(u64),
/// The `make-record` instruction.
MakeRecord(InterfaceType),
/// The `get-field` instruction.
GetField(InterfaceType, u64),
/// The `const` instruction.
Const(InterfaceType, u64),
/// The `fold-seq` instruction.
FoldSeq(u64),
/// The `add` instruction.
Add(InterfaceType),
/// The `mem-to-seq` instruction.
MemToSeq(InterfaceType, &'input str),
/// The `load` instruction.
Load(InterfaceType, &'input str),
/// The `seq.new` instruction.
SeqNew(InterfaceType),
/// The `list.push` instruction.
ListPush,
/// The `repeat-until` instruction.
RepeatUntil(u64, u64),
} }

View File

@ -208,7 +208,6 @@ where
Instruction::WriteUtf8 { allocator_name } => { Instruction::WriteUtf8 { allocator_name } => {
instructions::write_utf8((*allocator_name).to_owned(), instruction_name) instructions::write_utf8((*allocator_name).to_owned(), instruction_name)
} }
_ => unimplemented!(),
} }
}) })
.collect(); .collect();