summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/parser/src/conversion.rs60
-rw-r--r--crates/tinywasm/src/runtime/executor/mod.rs33
-rw-r--r--crates/tinywasm/src/runtime/stack/call_stack.rs7
-rw-r--r--crates/tinywasm/src/runtime/stack/value_stack.rs6
-rw-r--r--crates/tinywasm/tests/charts/progress.rs4
-rw-r--r--crates/tinywasm/tests/mvp.csv2
-rw-r--r--crates/tinywasm/tests/mvp.rs1
-rw-r--r--crates/tinywasm/tests/progress-mvp.svg56
-rw-r--r--crates/tinywasm/tests/testsuite/run.rs4
-rw-r--r--crates/types/src/instructions.rs3
10 files changed, 96 insertions, 80 deletions
diff --git a/crates/parser/src/conversion.rs b/crates/parser/src/conversion.rs
index 5e7be0e..d921e35 100644
--- a/crates/parser/src/conversion.rs
+++ b/crates/parser/src/conversion.rs
@@ -114,9 +114,9 @@ pub fn process_operators<'a>(
mut validator: FuncValidator<ValidatorResources>,
) -> Result<Box<[Instruction]>> {
let mut instructions = Vec::new();
- let mut labels_ptrs = Vec::new();
+ let mut labels_ptrs = Vec::new(); // indexes into the instructions array
- for (i, op) in ops.enumerate() {
+ for op in ops {
info!("op: {:?}", op);
let op = op?;
@@ -146,17 +146,42 @@ pub fn process_operators<'a>(
}
If { blockty } => {
labels_ptrs.push(instructions.len());
- Instruction::If(convert_blocktype(blockty), 0)
+ Instruction::If(convert_blocktype(blockty), None, 0)
+ }
+ Else => {
+ labels_ptrs.push(instructions.len());
+ Instruction::Else(0)
}
End => {
if let Some(label_pointer) = labels_ptrs.pop() {
+ info!("ending block: {:?}", instructions[label_pointer]);
+
+ let current_instr_ptr = instructions.len();
+
// last_label_pointer is Some if we're ending a block
match instructions[label_pointer] {
- Instruction::Block(_, ref mut end)
- | Instruction::Loop(_, ref mut end)
- | Instruction::Else(ref mut end)
- | Instruction::If(_, ref mut end) => {
- *end = i + 1; // Set the end position to be one after the End instruction
+ Instruction::Else(ref mut else_instr_end_offset) => {
+ *else_instr_end_offset = current_instr_ptr - label_pointer;
+
+ // since we're ending an else block, we need to end the if block as well
+ let if_label_pointer = labels_ptrs.pop().ok_or(crate::ParseError::UnsupportedOperator(
+ "Expected to end an if block, but the last label was not an if".to_string(),
+ ))?;
+
+ let if_instruction = &mut instructions[if_label_pointer];
+ let Instruction::If(_, ref mut else_offset, ref mut end_offset) = if_instruction else {
+ return Err(crate::ParseError::UnsupportedOperator(
+ "Expected to end an if block, but the last label was not an if".to_string(),
+ ));
+ };
+
+ *else_offset = Some(label_pointer - if_label_pointer);
+ *end_offset = current_instr_ptr - if_label_pointer;
+ }
+ Instruction::Block(_, ref mut end_offset)
+ | Instruction::Loop(_, ref mut end_offset)
+ | Instruction::If(_, _, ref mut end_offset) => {
+ *end_offset = current_instr_ptr - label_pointer;
}
_ => {
return Err(crate::ParseError::UnsupportedOperator(
@@ -171,26 +196,7 @@ pub fn process_operators<'a>(
Instruction::EndFunc
}
}
- Else => {
- let Some(label_pointer) = labels_ptrs.pop() else {
- return Err(crate::ParseError::UnsupportedOperator(
- "Expected to end an if block, but the last label was None".to_string(),
- ));
- };
-
- match instructions[label_pointer] {
- Instruction::If(_, ref mut end) => {
- *end = i + 1; // Set the end position to be one after the Else instruction
- }
- _ => {
- return Err(crate::ParseError::UnsupportedOperator(
- "Expected to end an if block, but the last label was not an if".to_string(),
- ));
- }
- }
- Instruction::Else(0)
- }
Br { relative_depth } => Instruction::Br(relative_depth),
BrIf { relative_depth } => Instruction::BrIf(relative_depth),
Return => Instruction::Return,
diff --git a/crates/tinywasm/src/runtime/executor/mod.rs b/crates/tinywasm/src/runtime/executor/mod.rs
index 7d8ead4..39788b5 100644
--- a/crates/tinywasm/src/runtime/executor/mod.rs
+++ b/crates/tinywasm/src/runtime/executor/mod.rs
@@ -84,7 +84,6 @@ fn exec_one(
Nop => { /* do nothing */ }
Unreachable => return Ok(ExecResult::Trap(crate::Trap::Unreachable)), // we don't need to include the call frame here because it's already on the stack
Drop => stack.values.pop().map(|_| ())?,
- Return => todo!("called function returned"),
Select => {
let cond: i32 = stack.values.pop()?.into();
let val2 = stack.values.pop()?;
@@ -117,6 +116,38 @@ fn exec_one(
return Ok(ExecResult::Call);
}
+ Return => todo!("called function returned"),
+
+ If(args, else_offset, end_offset) => {
+ let end_instr_ptr = cf.instr_ptr + *end_offset;
+
+ info!(
+ "if it's true, we'll jump to the next instruction (@{})",
+ cf.instr_ptr + 1
+ );
+
+ if let Some(else_offset) = else_offset {
+ info!(
+ "else: {:?} (@{})",
+ instrs[cf.instr_ptr + else_offset],
+ cf.instr_ptr + else_offset
+ );
+ };
+
+ info!("end: {:?} (@{})", instrs[end_instr_ptr], end_instr_ptr);
+
+ if stack.values.pop_t::<i32>()? != 0 {
+ cf.labels.push(LabelFrame {
+ instr_ptr: cf.instr_ptr,
+ end_instr_ptr: cf.instr_ptr + *end_offset,
+ stack_ptr: stack.values.len(),
+ args: *args,
+ ty: BlockType::If,
+ });
+ stack.values.push_block_args(*args)?;
+ }
+ }
+
Loop(args, end_offset) => {
cf.labels.push(LabelFrame {
instr_ptr: cf.instr_ptr,
diff --git a/crates/tinywasm/src/runtime/stack/call_stack.rs b/crates/tinywasm/src/runtime/stack/call_stack.rs
index 3005953..42fae54 100644
--- a/crates/tinywasm/src/runtime/stack/call_stack.rs
+++ b/crates/tinywasm/src/runtime/stack/call_stack.rs
@@ -105,15 +105,12 @@ impl CallFrame {
BlockType::Block => {
debug!("current instr_ptr: {}", self.instr_ptr);
- // this is a block, so we want to jump to the end of the block
- self.instr_ptr = break_to.end_instr_ptr;
+ // this is a block, so we want to jump to the next instruction after the block ends
+ self.instr_ptr = break_to.end_instr_ptr + 1;
value_stack.trim(break_to.stack_ptr);
// we also want to trim the label stack, including the block
self.labels.trim(self.labels.len() - break_to_relative as usize + 1);
-
- debug!("break_to.end_instr_ptr: {}", self.instr_ptr);
-
panic!()
}
_ => unimplemented!("break to block type: {:?}", current_label.ty),
diff --git a/crates/tinywasm/src/runtime/stack/value_stack.rs b/crates/tinywasm/src/runtime/stack/value_stack.rs
index 59be3d2..1962995 100644
--- a/crates/tinywasm/src/runtime/stack/value_stack.rs
+++ b/crates/tinywasm/src/runtime/stack/value_stack.rs
@@ -40,8 +40,8 @@ impl ValueStack {
pub(crate) fn push_block_args(&self, args: BlockArgs) -> Result<()> {
match args {
BlockArgs::Empty => Ok(()),
- BlockArgs::Type(_t) => todo!(),
- BlockArgs::FuncType(_t) => todo!(),
+ BlockArgs::Type(_t) => todo!("support block args (type)"),
+ BlockArgs::FuncType(_t) => todo!("support block args (func type)"),
}
}
@@ -65,7 +65,7 @@ impl ValueStack {
#[inline]
pub(crate) fn pop_t<T: From<RawWasmValue>>(&mut self) -> Result<T> {
self.top -= 1;
- Ok(self.pop()?.into())
+ Ok(self.stack.pop().ok_or(Error::StackUnderflow)?.into())
}
#[inline]
diff --git a/crates/tinywasm/tests/charts/progress.rs b/crates/tinywasm/tests/charts/progress.rs
index 6d18291..c5d6c6f 100644
--- a/crates/tinywasm/tests/charts/progress.rs
+++ b/crates/tinywasm/tests/charts/progress.rs
@@ -20,8 +20,8 @@ pub fn create_progress_chart(csv_path: &Path, output_path: &Path) -> Result<()>
if parts.len() > 3 {
let version = format!("v{}", parts[0]);
- let failed: u32 = parts[1].parse()?;
- let passed: u32 = parts[2].parse()?;
+ let passed: u32 = parts[1].parse()?;
+ let failed: u32 = parts[2].parse()?;
let total = failed + passed;
if total > max_tests {
diff --git a/crates/tinywasm/tests/mvp.csv b/crates/tinywasm/tests/mvp.csv
index 65a59d2..4c7715c 100644
--- a/crates/tinywasm/tests/mvp.csv
+++ b/crates/tinywasm/tests/mvp.csv
@@ -1,3 +1,3 @@
0.0.3,9258,7567,[{"name":"address.wast","passed":0,"failed":54},{"name":"align.wast","passed":0,"failed":109},{"name":"binary-leb128.wast","passed":66,"failed":25},{"name":"binary.wast","passed":104,"failed":8},{"name":"block.wast","passed":0,"failed":171},{"name":"br.wast","passed":0,"failed":21},{"name":"br_if.wast","passed":0,"failed":30},{"name":"br_table.wast","passed":0,"failed":25},{"name":"call.wast","passed":0,"failed":22},{"name":"call_indirect.wast","passed":0,"failed":56},{"name":"comments.wast","passed":4,"failed":4},{"name":"const.wast","passed":702,"failed":76},{"name":"conversions.wast","passed":0,"failed":93},{"name":"custom.wast","passed":10,"failed":1},{"name":"data.wast","passed":0,"failed":61},{"name":"elem.wast","passed":0,"failed":76},{"name":"endianness.wast","passed":0,"failed":1},{"name":"exports.wast","passed":21,"failed":73},{"name":"f32.wast","passed":1005,"failed":1509},{"name":"f32_bitwise.wast","passed":1,"failed":363},{"name":"f32_cmp.wast","passed":2401,"failed":6},{"name":"f64.wast","passed":1005,"failed":1509},{"name":"f64_bitwise.wast","passed":1,"failed":363},{"name":"f64_cmp.wast","passed":2401,"failed":6},{"name":"fac.wast","passed":0,"failed":2},{"name":"float_exprs.wast","passed":269,"failed":591},{"name":"float_literals.wast","passed":34,"failed":129},{"name":"float_memory.wast","passed":0,"failed":6},{"name":"float_misc.wast","passed":138,"failed":303},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":4,"failed":75},{"name":"func_ptrs.wast","passed":0,"failed":16},{"name":"global.wast","passed":4,"failed":49},{"name":"i32.wast","passed":0,"failed":96},{"name":"i64.wast","passed":0,"failed":42},{"name":"if.wast","passed":0,"failed":118},{"name":"imports.wast","passed":1,"failed":156},{"name":"inline-module.wast","passed":0,"failed":1},{"name":"int_exprs.wast","passed":38,"failed":70},{"name":"int_literals.wast","passed":5,"failed":46},{"name":"labels.wast","passed":1,"failed":28},{"name":"left-to-right.wast","passed":0,"failed":1},{"name":"linking.wast","passed":1,"failed":66},{"name":"load.wast","passed":0,"failed":60},{"name":"local_get.wast","passed":2,"failed":34},{"name":"local_set.wast","passed":5,"failed":48},{"name":"local_tee.wast","passed":0,"failed":42},{"name":"loop.wast","passed":0,"failed":43},{"name":"memory.wast","passed":0,"failed":34},{"name":"memory_grow.wast","passed":0,"failed":19},{"name":"memory_redundancy.wast","passed":0,"failed":1},{"name":"memory_size.wast","passed":0,"failed":6},{"name":"memory_trap.wast","passed":0,"failed":172},{"name":"names.wast","passed":484,"failed":1},{"name":"nop.wast","passed":0,"failed":5},{"name":"return.wast","passed":0,"failed":21},{"name":"select.wast","passed":0,"failed":32},{"name":"skip-stack-guard-page.wast","passed":0,"failed":11},{"name":"stack.wast","passed":0,"failed":2},{"name":"start.wast","passed":0,"failed":10},{"name":"store.wast","passed":0,"failed":59},{"name":"switch.wast","passed":1,"failed":27},{"name":"token.wast","passed":16,"failed":42},{"name":"traps.wast","passed":3,"failed":33},{"name":"type.wast","passed":1,"failed":2},{"name":"unreachable.wast","passed":0,"failed":59},{"name":"unreached-invalid.wast","passed":0,"failed":118},{"name":"unwind.wast","passed":1,"failed":49},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":0,"failed":176}]
0.0.4,9258,7567,[{"name":"address.wast","passed":0,"failed":54},{"name":"align.wast","passed":0,"failed":109},{"name":"binary-leb128.wast","passed":66,"failed":25},{"name":"binary.wast","passed":104,"failed":8},{"name":"block.wast","passed":0,"failed":171},{"name":"br.wast","passed":0,"failed":21},{"name":"br_if.wast","passed":0,"failed":30},{"name":"br_table.wast","passed":0,"failed":25},{"name":"call.wast","passed":0,"failed":22},{"name":"call_indirect.wast","passed":0,"failed":56},{"name":"comments.wast","passed":4,"failed":4},{"name":"const.wast","passed":702,"failed":76},{"name":"conversions.wast","passed":0,"failed":93},{"name":"custom.wast","passed":10,"failed":1},{"name":"data.wast","passed":0,"failed":61},{"name":"elem.wast","passed":0,"failed":76},{"name":"endianness.wast","passed":0,"failed":1},{"name":"exports.wast","passed":21,"failed":73},{"name":"f32.wast","passed":1005,"failed":1509},{"name":"f32_bitwise.wast","passed":1,"failed":363},{"name":"f32_cmp.wast","passed":2401,"failed":6},{"name":"f64.wast","passed":1005,"failed":1509},{"name":"f64_bitwise.wast","passed":1,"failed":363},{"name":"f64_cmp.wast","passed":2401,"failed":6},{"name":"fac.wast","passed":0,"failed":2},{"name":"float_exprs.wast","passed":269,"failed":591},{"name":"float_literals.wast","passed":34,"failed":129},{"name":"float_memory.wast","passed":0,"failed":6},{"name":"float_misc.wast","passed":138,"failed":303},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":4,"failed":75},{"name":"func_ptrs.wast","passed":0,"failed":16},{"name":"global.wast","passed":4,"failed":49},{"name":"i32.wast","passed":0,"failed":96},{"name":"i64.wast","passed":0,"failed":42},{"name":"if.wast","passed":0,"failed":118},{"name":"imports.wast","passed":1,"failed":156},{"name":"inline-module.wast","passed":0,"failed":1},{"name":"int_exprs.wast","passed":38,"failed":70},{"name":"int_literals.wast","passed":5,"failed":46},{"name":"labels.wast","passed":1,"failed":28},{"name":"left-to-right.wast","passed":0,"failed":1},{"name":"linking.wast","passed":1,"failed":66},{"name":"load.wast","passed":0,"failed":60},{"name":"local_get.wast","passed":2,"failed":34},{"name":"local_set.wast","passed":5,"failed":48},{"name":"local_tee.wast","passed":0,"failed":42},{"name":"loop.wast","passed":0,"failed":43},{"name":"memory.wast","passed":0,"failed":34},{"name":"memory_grow.wast","passed":0,"failed":19},{"name":"memory_redundancy.wast","passed":0,"failed":1},{"name":"memory_size.wast","passed":0,"failed":6},{"name":"memory_trap.wast","passed":0,"failed":172},{"name":"names.wast","passed":484,"failed":1},{"name":"nop.wast","passed":0,"failed":5},{"name":"return.wast","passed":0,"failed":21},{"name":"select.wast","passed":0,"failed":32},{"name":"skip-stack-guard-page.wast","passed":0,"failed":11},{"name":"stack.wast","passed":0,"failed":2},{"name":"start.wast","passed":0,"failed":10},{"name":"store.wast","passed":0,"failed":59},{"name":"switch.wast","passed":1,"failed":27},{"name":"token.wast","passed":16,"failed":42},{"name":"traps.wast","passed":3,"failed":33},{"name":"type.wast","passed":1,"failed":2},{"name":"unreachable.wast","passed":0,"failed":59},{"name":"unreached-invalid.wast","passed":0,"failed":118},{"name":"unwind.wast","passed":1,"failed":49},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":0,"failed":176}]
-0.0.5-alpha.0,9258,7567,[{"name":"address.wast","passed":0,"failed":54},{"name":"align.wast","passed":0,"failed":109},{"name":"binary-leb128.wast","passed":66,"failed":25},{"name":"binary.wast","passed":104,"failed":8},{"name":"block.wast","passed":0,"failed":171},{"name":"br.wast","passed":0,"failed":21},{"name":"br_if.wast","passed":0,"failed":30},{"name":"br_table.wast","passed":0,"failed":25},{"name":"call.wast","passed":0,"failed":22},{"name":"call_indirect.wast","passed":0,"failed":56},{"name":"comments.wast","passed":4,"failed":4},{"name":"const.wast","passed":702,"failed":76},{"name":"conversions.wast","passed":0,"failed":93},{"name":"custom.wast","passed":10,"failed":1},{"name":"data.wast","passed":0,"failed":61},{"name":"elem.wast","passed":0,"failed":76},{"name":"endianness.wast","passed":0,"failed":1},{"name":"exports.wast","passed":21,"failed":73},{"name":"f32.wast","passed":1005,"failed":1509},{"name":"f32_bitwise.wast","passed":1,"failed":363},{"name":"f32_cmp.wast","passed":2401,"failed":6},{"name":"f64.wast","passed":1005,"failed":1509},{"name":"f64_bitwise.wast","passed":1,"failed":363},{"name":"f64_cmp.wast","passed":2401,"failed":6},{"name":"fac.wast","passed":0,"failed":2},{"name":"float_exprs.wast","passed":269,"failed":591},{"name":"float_literals.wast","passed":34,"failed":129},{"name":"float_memory.wast","passed":0,"failed":6},{"name":"float_misc.wast","passed":138,"failed":303},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":4,"failed":75},{"name":"func_ptrs.wast","passed":0,"failed":16},{"name":"global.wast","passed":4,"failed":49},{"name":"i32.wast","passed":0,"failed":96},{"name":"i64.wast","passed":0,"failed":42},{"name":"if.wast","passed":0,"failed":118},{"name":"imports.wast","passed":1,"failed":156},{"name":"inline-module.wast","passed":0,"failed":1},{"name":"int_exprs.wast","passed":38,"failed":70},{"name":"int_literals.wast","passed":5,"failed":46},{"name":"labels.wast","passed":1,"failed":28},{"name":"left-to-right.wast","passed":0,"failed":1},{"name":"linking.wast","passed":1,"failed":66},{"name":"load.wast","passed":0,"failed":60},{"name":"local_get.wast","passed":2,"failed":34},{"name":"local_set.wast","passed":5,"failed":48},{"name":"local_tee.wast","passed":0,"failed":42},{"name":"loop.wast","passed":0,"failed":43},{"name":"memory.wast","passed":0,"failed":34},{"name":"memory_grow.wast","passed":0,"failed":19},{"name":"memory_redundancy.wast","passed":0,"failed":1},{"name":"memory_size.wast","passed":0,"failed":6},{"name":"memory_trap.wast","passed":0,"failed":172},{"name":"names.wast","passed":484,"failed":1},{"name":"nop.wast","passed":0,"failed":5},{"name":"return.wast","passed":0,"failed":21},{"name":"select.wast","passed":0,"failed":32},{"name":"skip-stack-guard-page.wast","passed":0,"failed":11},{"name":"stack.wast","passed":0,"failed":2},{"name":"start.wast","passed":0,"failed":10},{"name":"store.wast","passed":0,"failed":59},{"name":"switch.wast","passed":1,"failed":27},{"name":"token.wast","passed":16,"failed":42},{"name":"traps.wast","passed":3,"failed":33},{"name":"type.wast","passed":1,"failed":2},{"name":"unreachable.wast","passed":0,"failed":59},{"name":"unreached-invalid.wast","passed":0,"failed":118},{"name":"unwind.wast","passed":1,"failed":49},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":0,"failed":176}]
+0.0.5-alpha.0,9262,10924,[{"name":"address.wast","passed":0,"failed":260},{"name":"align.wast","passed":0,"failed":156},{"name":"binary-leb128.wast","passed":66,"failed":25},{"name":"binary.wast","passed":104,"failed":8},{"name":"block.wast","passed":0,"failed":223},{"name":"br.wast","passed":0,"failed":97},{"name":"br_if.wast","passed":0,"failed":118},{"name":"br_table.wast","passed":0,"failed":174},{"name":"call.wast","passed":0,"failed":91},{"name":"call_indirect.wast","passed":0,"failed":170},{"name":"comments.wast","passed":4,"failed":4},{"name":"const.wast","passed":702,"failed":76},{"name":"conversions.wast","passed":0,"failed":619},{"name":"custom.wast","passed":10,"failed":1},{"name":"data.wast","passed":0,"failed":61},{"name":"elem.wast","passed":0,"failed":99},{"name":"endianness.wast","passed":0,"failed":69},{"name":"exports.wast","passed":21,"failed":75},{"name":"f32.wast","passed":1005,"failed":1509},{"name":"f32_bitwise.wast","passed":1,"failed":363},{"name":"f32_cmp.wast","passed":2401,"failed":6},{"name":"f64.wast","passed":1005,"failed":1509},{"name":"f64_bitwise.wast","passed":1,"failed":363},{"name":"f64_cmp.wast","passed":2401,"failed":6},{"name":"fac.wast","passed":0,"failed":8},{"name":"float_exprs.wast","passed":273,"failed":617},{"name":"float_literals.wast","passed":34,"failed":129},{"name":"float_memory.wast","passed":0,"failed":66},{"name":"float_misc.wast","passed":138,"failed":303},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":4,"failed":168},{"name":"func_ptrs.wast","passed":0,"failed":35},{"name":"global.wast","passed":4,"failed":106},{"name":"i32.wast","passed":0,"failed":460},{"name":"i64.wast","passed":0,"failed":416},{"name":"if.wast","passed":0,"failed":241},{"name":"imports.wast","passed":1,"failed":182},{"name":"inline-module.wast","passed":0,"failed":1},{"name":"int_exprs.wast","passed":38,"failed":70},{"name":"int_literals.wast","passed":5,"failed":46},{"name":"labels.wast","passed":1,"failed":28},{"name":"left-to-right.wast","passed":0,"failed":96},{"name":"linking.wast","passed":1,"failed":131},{"name":"load.wast","passed":0,"failed":97},{"name":"local_get.wast","passed":2,"failed":34},{"name":"local_set.wast","passed":5,"failed":48},{"name":"local_tee.wast","passed":0,"failed":97},{"name":"loop.wast","passed":0,"failed":120},{"name":"memory.wast","passed":0,"failed":79},{"name":"memory_grow.wast","passed":0,"failed":96},{"name":"memory_redundancy.wast","passed":0,"failed":5},{"name":"memory_size.wast","passed":0,"failed":42},{"name":"memory_trap.wast","passed":0,"failed":182},{"name":"names.wast","passed":484,"failed":2},{"name":"nop.wast","passed":0,"failed":88},{"name":"return.wast","passed":0,"failed":84},{"name":"select.wast","passed":0,"failed":148},{"name":"skip-stack-guard-page.wast","passed":0,"failed":11},{"name":"stack.wast","passed":0,"failed":7},{"name":"start.wast","passed":0,"failed":16},{"name":"store.wast","passed":0,"failed":68},{"name":"switch.wast","passed":1,"failed":27},{"name":"token.wast","passed":16,"failed":42},{"name":"traps.wast","passed":3,"failed":33},{"name":"type.wast","passed":1,"failed":2},{"name":"unreachable.wast","passed":0,"failed":64},{"name":"unreached-invalid.wast","passed":0,"failed":118},{"name":"unwind.wast","passed":1,"failed":49},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":0,"failed":176}]
diff --git a/crates/tinywasm/tests/mvp.rs b/crates/tinywasm/tests/mvp.rs
index e81e946..6e6a104 100644
--- a/crates/tinywasm/tests/mvp.rs
+++ b/crates/tinywasm/tests/mvp.rs
@@ -27,7 +27,6 @@ fn generate_charts() -> Result<()> {
fn test_mvp() -> Result<()> {
let mut test_suite = TestSuite::new();
test_suite.run(wasm_testsuite::MVP_TESTS)?;
-
test_suite.save_csv("./tests/mvp.csv", env!("CARGO_PKG_VERSION"))?;
if test_suite.failed() {
diff --git a/crates/tinywasm/tests/progress-mvp.svg b/crates/tinywasm/tests/progress-mvp.svg
index 7851f0a..f5a23e6 100644
--- a/crates/tinywasm/tests/progress-mvp.svg
+++ b/crates/tinywasm/tests/progress-mvp.svg
@@ -10,51 +10,31 @@ Tests Passed
TinyWasm Version
</text>
<line opacity="0.3" stroke="#000000" stroke-width="1" x1="70" y1="354" x2="989" y2="354"/>
-<line opacity="0.3" stroke="#000000" stroke-width="1" x1="70" y1="318" x2="989" y2="318"/>
-<line opacity="0.3" stroke="#000000" stroke-width="1" x1="70" y1="281" x2="989" y2="281"/>
-<line opacity="0.3" stroke="#000000" stroke-width="1" x1="70" y1="244" x2="989" y2="244"/>
-<line opacity="0.3" stroke="#000000" stroke-width="1" x1="70" y1="207" x2="989" y2="207"/>
-<line opacity="0.3" stroke="#000000" stroke-width="1" x1="70" y1="170" x2="989" y2="170"/>
-<line opacity="0.3" stroke="#000000" stroke-width="1" x1="70" y1="133" x2="989" y2="133"/>
-<line opacity="0.3" stroke="#000000" stroke-width="1" x1="70" y1="97" x2="989" y2="97"/>
-<line opacity="0.3" stroke="#000000" stroke-width="1" x1="70" y1="60" x2="989" y2="60"/>
+<line opacity="0.3" stroke="#000000" stroke-width="1" x1="70" y1="278" x2="989" y2="278"/>
+<line opacity="0.3" stroke="#000000" stroke-width="1" x1="70" y1="201" x2="989" y2="201"/>
+<line opacity="0.3" stroke="#000000" stroke-width="1" x1="70" y1="124" x2="989" y2="124"/>
+<line opacity="0.3" stroke="#000000" stroke-width="1" x1="70" y1="47" x2="989" y2="47"/>
<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="69,44 69,354 "/>
<text x="60" y="354" dy="0.5ex" text-anchor="end" font-family="sans-serif" font-size="9.67741935483871" opacity="1" fill="#000000">
0
</text>
<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="64,354 69,354 "/>
-<text x="60" y="318" dy="0.5ex" text-anchor="end" font-family="sans-serif" font-size="9.67741935483871" opacity="1" fill="#000000">
-2000
+<text x="60" y="278" dy="0.5ex" text-anchor="end" font-family="sans-serif" font-size="9.67741935483871" opacity="1" fill="#000000">
+5000
</text>
-<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="64,318 69,318 "/>
-<text x="60" y="281" dy="0.5ex" text-anchor="end" font-family="sans-serif" font-size="9.67741935483871" opacity="1" fill="#000000">
-4000
-</text>
-<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="64,281 69,281 "/>
-<text x="60" y="244" dy="0.5ex" text-anchor="end" font-family="sans-serif" font-size="9.67741935483871" opacity="1" fill="#000000">
-6000
-</text>
-<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="64,244 69,244 "/>
-<text x="60" y="207" dy="0.5ex" text-anchor="end" font-family="sans-serif" font-size="9.67741935483871" opacity="1" fill="#000000">
-8000
-</text>
-<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="64,207 69,207 "/>
-<text x="60" y="170" dy="0.5ex" text-anchor="end" font-family="sans-serif" font-size="9.67741935483871" opacity="1" fill="#000000">
+<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="64,278 69,278 "/>
+<text x="60" y="201" dy="0.5ex" text-anchor="end" font-family="sans-serif" font-size="9.67741935483871" opacity="1" fill="#000000">
10000
</text>
-<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="64,170 69,170 "/>
-<text x="60" y="133" dy="0.5ex" text-anchor="end" font-family="sans-serif" font-size="9.67741935483871" opacity="1" fill="#000000">
-12000
-</text>
-<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="64,133 69,133 "/>
-<text x="60" y="97" dy="0.5ex" text-anchor="end" font-family="sans-serif" font-size="9.67741935483871" opacity="1" fill="#000000">
-14000
+<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="64,201 69,201 "/>
+<text x="60" y="124" dy="0.5ex" text-anchor="end" font-family="sans-serif" font-size="9.67741935483871" opacity="1" fill="#000000">
+15000
</text>
-<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="64,97 69,97 "/>
-<text x="60" y="60" dy="0.5ex" text-anchor="end" font-family="sans-serif" font-size="9.67741935483871" opacity="1" fill="#000000">
-16000
+<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="64,124 69,124 "/>
+<text x="60" y="47" dy="0.5ex" text-anchor="end" font-family="sans-serif" font-size="9.67741935483871" opacity="1" fill="#000000">
+20000
</text>
-<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="64,60 69,60 "/>
+<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="64,47 69,47 "/>
<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="70,355 989,355 "/>
<text x="223" y="365" dy="0.76em" text-anchor="middle" font-family="sans-serif" font-size="9.67741935483871" opacity="1" fill="#000000">
v0.0.3
@@ -68,7 +48,7 @@ v0.0.4
v0.0.5-alpha.0
</text>
<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="836,355 836,360 "/>
-<rect x="688" y="215" width="296" height="139" opacity="0.5" fill="#0000FF" stroke="none"/>
-<rect x="75" y="215" width="296" height="139" opacity="0.5" fill="#0000FF" stroke="none"/>
-<rect x="381" y="215" width="297" height="139" opacity="0.5" fill="#0000FF" stroke="none"/>
+<rect x="75" y="212" width="296" height="142" opacity="0.5" fill="#0000FF" stroke="none"/>
+<rect x="381" y="212" width="297" height="142" opacity="0.5" fill="#0000FF" stroke="none"/>
+<rect x="688" y="212" width="296" height="142" opacity="0.5" fill="#0000FF" stroke="none"/>
</svg>
diff --git a/crates/tinywasm/tests/testsuite/run.rs b/crates/tinywasm/tests/testsuite/run.rs
index 42dd825..56f3a44 100644
--- a/crates/tinywasm/tests/testsuite/run.rs
+++ b/crates/tinywasm/tests/testsuite/run.rs
@@ -34,6 +34,8 @@ impl TestSuite {
.map_err(|e| eyre!("failed to parse module: {:?}", e))
.and_then(|res| res);
+ println!("result: {:?}", result);
+
match &result {
Err(_) => last_module = None,
Ok(m) => last_module = Some(m.clone()),
@@ -61,8 +63,8 @@ impl TestSuite {
AssertReturn { span, exec, results } => {
let Some(module) = last_module.as_ref() else {
- // we skip tests for modules that failed to parse
println!("no module found for assert_return: {:?}", exec);
+ test_group.add_result(&format!("{}-return", name), span, Err(eyre!("no module found")));
continue;
};
diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs
index 6f11817..d8aff7b 100644
--- a/crates/types/src/instructions.rs
+++ b/crates/types/src/instructions.rs
@@ -17,6 +17,7 @@ pub struct MemArg {
type BrTableDefault = u32;
type BrTableLen = usize;
type EndOffset = usize;
+type ElseOffset = usize;
/// A WebAssembly Instruction
///
@@ -41,7 +42,7 @@ pub enum Instruction {
Nop,
Block(BlockArgs, EndOffset),
Loop(BlockArgs, EndOffset),
- If(BlockArgs, EndOffset),
+ If(BlockArgs, Option<ElseOffset>, EndOffset),
Else(EndOffset),
EndBlockFrame,
EndFunc,