Skip to content

Commit

Permalink
support br_table instruction (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
butterunderflow authored Oct 4, 2024
1 parent e5be572 commit 17303a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/scala/wasm/MiniWasm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ object Evaluator {
val I32V(cond) :: newStack = stack
if (cond != 0) trail(label)(newStack)
else eval(rest, newStack, frame, kont, trail, ret)
case BrTable(labels, default) =>
val I32V(cond) :: newStack = stack
val goto = if (cond < labels.length) labels(cond) else default
trail(goto)(newStack)
case Return => trail(ret)(stack)
case Call(f) if frame.module.funcs(f).isInstanceOf[FuncDef] =>
val FuncDef(_, FuncBodyDef(ty, _, locals, body)) = frame.module.funcs(f)
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/genwasym/TestEval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class TestEval extends FunSuite {
test("even-odd") { testFile("./benchmarks/wasm/even_odd.wat", None, Some(1)) }
test("return") { testFile("./benchmarks/wasm/return.wat", None, None) }

test("fib") { testFile("./benchmarks/wasm/fib.wat", None, None) }
test("fib") { testFile("./benchmarks/wasm/fib.wat", None, Some(144)) }

// Parser works, but the memory issue remains
// test("btree") { testFile("./benchmarks/wasm/btree/2o1u-no-label-for-real.wat") }
Expand Down

0 comments on commit 17303a7

Please sign in to comment.