doc(interface-types) Improve documentation of the instruction module.

Also, rename `RepeatWhile` to `RepeatUntil`.
This commit is contained in:
Ivan Enderlin 2020-02-12 15:59:41 +01:00
parent 98c73099c3
commit b3c102da37
3 changed files with 48 additions and 8 deletions

View File

@ -246,7 +246,7 @@ fn instruction<'input, E: ParseError<&'input [u8]>>(
0x14 => {
consume!((input, argument_0) = leb(input)?);
consume!((input, argument_1) = leb(input)?);
(input, Instruction::RepeatWhile(argument_0, argument_1))
(input, Instruction::RepeatUntil(argument_0, argument_1))
}
_ => return Err(Err::Error(make_error(input, ErrorKind::ParseTo))),
@ -643,7 +643,7 @@ mod tests {
0x11, 0x7f, 0x03, 0x61, 0x62, 0x63, // Load(I32, "abc")
0x12, 0x7f, // SeqNew(I32)
0x13, // ListPush
0x14, 0x01, 0x02, // RepeatWhile(1, 2)
0x14, 0x01, 0x02, // RepeatUntil(1, 2)
0x0a,
];
let output = Ok((
@ -670,7 +670,7 @@ mod tests {
Instruction::Load(InterfaceType::I32, "abc"),
Instruction::SeqNew(InterfaceType::I32),
Instruction::ListPush,
Instruction::RepeatWhile(1, 2),
Instruction::RepeatUntil(1, 2),
],
));

View File

@ -154,8 +154,8 @@ impl<'input> From<&Instruction<'input>> for String {
format!("seq.new {}", String::from(interface_type))
}
Instruction::ListPush => "list.push".into(),
Instruction::RepeatWhile(condition_index, step_index) => {
format!("repeat-while {} {}", condition_index, step_index)
Instruction::RepeatUntil(condition_index, step_index) => {
format!("repeat-until {} {}", condition_index, step_index)
}
}
}
@ -420,7 +420,7 @@ mod tests {
(&Instruction::Load(InterfaceType::Int, "foo")).into(),
(&Instruction::SeqNew(InterfaceType::Int)).into(),
(&Instruction::ListPush).into(),
(&Instruction::RepeatWhile(1, 2)).into(),
(&Instruction::RepeatUntil(1, 2)).into(),
];
let outputs = vec![
"arg.get 7",
@ -442,7 +442,7 @@ mod tests {
r#"load Int "foo""#,
"seq.new Int",
"list.push",
"repeat-while 1 2",
"repeat-until 1 2",
];
assert_eq!(inputs, outputs);

View File

@ -1,25 +1,65 @@
use crate::ast::InterfaceType;
/// Represents all the possible WIT instructions.
#[derive(PartialEq, Debug)]
pub enum Instruction<'input> {
/// `arg.get`
ArgumentGet { index: u64 },
/// `call`
Call { function_index: usize },
/// `call-export`
CallExport { export_name: &'input str },
/// `read-utf8`
ReadUtf8,
/// `write-utf8`
WriteUtf8 { allocator_name: &'input str },
/// `as-wasm`
AsWasm(InterfaceType),
/// `as-interface`
AsInterface(InterfaceType),
/// `table-ref-add`
TableRefAdd,
/// `table-ref-get`
TableRefGet,
/// `call-method`
CallMethod(u64),
/// `make-record`
MakeRecord(InterfaceType),
/// `get-field`
GetField(InterfaceType, u64),
/// `const`
Const(InterfaceType, u64),
/// `fold-seq`
FoldSeq(u64),
/// `add`
Add(InterfaceType),
/// `mem-to-seq`
MemToSeq(InterfaceType, &'input str),
/// `load`
Load(InterfaceType, &'input str),
/// `seq.new`
SeqNew(InterfaceType),
/// `list.push`
ListPush,
RepeatWhile(u64, u64),
/// `repeat-until`
RepeatUntil(u64, u64),
}