From ddf6711045eb7619e1d5d970d0b4559fa915c6b7 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 12 Feb 2020 15:59:41 +0100 Subject: [PATCH] doc(interface-types) Improve documentation of the `instruction` module. Also, rename `RepeatWhile` to `RepeatUntil`. --- src/decoders/binary.rs | 6 ++--- src/encoders/wat.rs | 8 +++---- src/interpreter/instruction.rs | 42 +++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/decoders/binary.rs b/src/decoders/binary.rs index 2eb914b..afa549a 100644 --- a/src/decoders/binary.rs +++ b/src/decoders/binary.rs @@ -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), ], )); diff --git a/src/encoders/wat.rs b/src/encoders/wat.rs index fcdc916..0857329 100644 --- a/src/encoders/wat.rs +++ b/src/encoders/wat.rs @@ -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); diff --git a/src/interpreter/instruction.rs b/src/interpreter/instruction.rs index e474d2d..20fbd40 100644 --- a/src/interpreter/instruction.rs +++ b/src/interpreter/instruction.rs @@ -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), }