Skip to content

Commit

Permalink
lame fix (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuoguo authored Oct 3, 2024
1 parent 4cdb168 commit ddfe212
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
8 changes: 2 additions & 6 deletions benchmarks/wasm/even_odd.wat
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@
i32.add
call 0)
(func (;2;) (type 1) (result i32)
i32.const 0
i32.const 13
call 1)
(start 2)
(table (;0;) 1 1 funcref)
(memory (;0;) 16)
(export "memory" (memory 0))
(export "is_even" (func 0))
(export "is_odd" (func 1))
(export "real_main" (func 2)))
)
7 changes: 4 additions & 3 deletions src/main/scala/wasm/MiniWasm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ object Evaluator {
stack: List[Value],
frame: Frame,
trail: List[Cont],
kont: Cont): Unit = {
kont: Cont)
(implicit retKont: Cont): Unit = {
if (insts.isEmpty) return kont(stack)

val inst = insts.head
Expand Down Expand Up @@ -291,7 +292,7 @@ object Evaluator {
println(s"br if rest $rest")
eval(rest, newStack, frame, trail, kont)
}
case Return => kont(stack)
case Return => retKont(stack)
case Call(f) if frame.module.funcs(f).isInstanceOf[FuncDef] =>
val FuncDef(_, FuncBodyDef(ty, _, locals, body)) = frame.module.funcs(f)
println(s"calling $f")
Expand All @@ -303,7 +304,7 @@ object Evaluator {
eval(rest, retStack.take(ty.out.size) ++ newStack, frame, trail, kont)
// We push newK on the trail since function creates a new block to escape
// (more or less like `return`)
eval(body, List(), newFrame, newK :: trail, newK)
eval(body, List(), newFrame, newK :: trail, newK)(newK)
case Call(f) if frame.module.funcs(f).isInstanceOf[Import] =>
frame.module.funcs(f) match {
case Import("console", "log", _) =>
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/genwasym/TestEval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class TestEval extends FunSuite {
test("start") { testFile("./benchmarks/wasm/start.wat") }
test("fact") { testFile("./benchmarks/wasm/fact.wat", None, Some(120)) }
test("loop") { testFile("./benchmarks/wasm/loop.wat", None, Some(10)) }
// test("even-odd") { testFile("./benchmarks/wasm/even_odd.wat", None, Some(1)) }
// test("return") { testFile("./benchmarks/wasm/return.wat", None, None) }
test("even-odd") { testFile("./benchmarks/wasm/even_odd.wat", None, Some(1)) }
test("return") { testFile("./benchmarks/wasm/return.wat", None, None) }

// 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 ddfe212

Please sign in to comment.