mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-18 09:00:51 +00:00
feat(interface-types) Add new instructions.
This commit is contained in:
parent
6279b3e915
commit
bd3a888452
@ -37,6 +37,12 @@ pub enum Instruction<'input> {
|
||||
GetField(InterfaceType, u64),
|
||||
Const(InterfaceType, u64),
|
||||
FoldSeq(u64),
|
||||
Add(InterfaceType),
|
||||
MemToSeq(InterfaceType, &'input str),
|
||||
Load(InterfaceType, &'input str),
|
||||
SeqNew(InterfaceType),
|
||||
ListPush,
|
||||
RepeatWhile(u64, u64),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
|
@ -193,6 +193,36 @@ fn instructions<'input, E: ParseError<&'input [u8]>>(
|
||||
(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) = leb(input)?);
|
||||
consume!((input, argument_1) = leb(input)?);
|
||||
(input, Instruction::RepeatWhile(argument_0, argument_1))
|
||||
}
|
||||
|
||||
_ => return Err(Err::Error(make_error(input, ErrorKind::ParseTo))),
|
||||
})
|
||||
}
|
||||
@ -467,7 +497,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_instructions() {
|
||||
let input = &[
|
||||
0x0e, // list of 14 items
|
||||
0x14, // list of 20 items
|
||||
0x00, 0x01, // ArgumentGet(1)
|
||||
0x01, 0x01, // Call(1)
|
||||
0x02, 0x03, 0x61, 0x62, 0x63, // CallExport("abc")
|
||||
@ -482,6 +512,12 @@ mod tests {
|
||||
0x0c, 0xff, 0xff, 0x01, 0x02, // GetField(Int, 2)
|
||||
0x0d, 0x7f, 0x01, // Const(I32, 1)
|
||||
0x0e, 0x01, // FoldSeq(1)
|
||||
0x0f, 0x7f, // Add(I32)
|
||||
0x10, 0x7f, 0x03, 0x61, 0x62, 0x63, // MemToSeq(I32, "abc")
|
||||
0x11, 0x7f, 0x03, 0x61, 0x62, 0x63, // Load(I32, "abc")
|
||||
0x12, 0x7f, // SeqNew(I32)
|
||||
0x13, // ListPush
|
||||
0x14, 0x01, 0x02, // RepeatWhile(1, 2)
|
||||
0x0a,
|
||||
];
|
||||
let output = Ok((
|
||||
@ -501,6 +537,12 @@ mod tests {
|
||||
Instruction::GetField(InterfaceType::Int, 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::RepeatWhile(1, 2),
|
||||
],
|
||||
));
|
||||
|
||||
|
@ -44,6 +44,22 @@ impl<'input> From<&Instruction<'input>> for String {
|
||||
format!("const {} {}", String::from(interface_type), value)
|
||||
}
|
||||
Instruction::FoldSeq(import_index) => format!("fold-seq {}", import_index),
|
||||
Instruction::Add(interface_type) => format!("add {}", String::from(interface_type)),
|
||||
Instruction::MemToSeq(interface_type, memory) => format!(
|
||||
r#"mem-to-seq {} "{}""#,
|
||||
String::from(interface_type),
|
||||
memory
|
||||
),
|
||||
Instruction::Load(interface_type, memory) => {
|
||||
format!(r#"load {} "{}""#, String::from(interface_type), memory)
|
||||
}
|
||||
Instruction::SeqNew(interface_type) => {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -212,6 +228,12 @@ mod tests {
|
||||
(&Instruction::GetField(InterfaceType::Int, 7)).into(),
|
||||
(&Instruction::Const(InterfaceType::I32, 7)).into(),
|
||||
(&Instruction::FoldSeq(7)).into(),
|
||||
(&Instruction::Add(InterfaceType::Int)).into(),
|
||||
(&Instruction::MemToSeq(InterfaceType::Int, "foo")).into(),
|
||||
(&Instruction::Load(InterfaceType::Int, "foo")).into(),
|
||||
(&Instruction::SeqNew(InterfaceType::Int)).into(),
|
||||
(&Instruction::ListPush).into(),
|
||||
(&Instruction::RepeatWhile(1, 2)).into(),
|
||||
];
|
||||
let outputs = vec![
|
||||
"arg.get 7",
|
||||
@ -228,6 +250,12 @@ mod tests {
|
||||
"get-field Int 7",
|
||||
"const i32 7",
|
||||
"fold-seq 7",
|
||||
"add Int",
|
||||
r#"mem-to-seq Int "foo""#,
|
||||
r#"load Int "foo""#,
|
||||
"seq.new Int",
|
||||
"list.push",
|
||||
"repeat-while 1 2",
|
||||
];
|
||||
|
||||
assert_eq!(inputs, outputs);
|
||||
|
Loading…
x
Reference in New Issue
Block a user