Skip to content

Commit

Permalink
correct behavior for stack
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuoguo committed Nov 25, 2024
1 parent 7af3cf2 commit d57a91a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
31 changes: 31 additions & 0 deletions benchmarks/wasm/wasmfx/resume_chain1-strip.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(module
(type (;0;) (func (param i32) (result i32)))
(type (;1;) (cont 0))
(export "main" (func 2))
;; (elem (;0;) declare func 0 1)
(func (;0;) (type 0) (param i32) (result i32)
local.get 0
i32.const 10
i32.add
)
(func (;1;) (type 0) (param i32) (result i32)
local.get 0
i32.const 100
i32.add
ref.func 0
cont.new 1
resume 1
i32.const 1000
i32.add
)
(func (;2;) (type 0) (param i32) (result i32)
local.get 0
ref.func 1
cont.new 1
resume 1
)
)

(assert_return (invoke "main" (i32.const 4)) (i32.const 1114))
(assert_return (invoke "main" (i32.const 5)) (i32.const 1115))
(assert_return (invoke "main" (i32.const 9)) (i32.const 1119))
6 changes: 3 additions & 3 deletions src/main/scala/wasm/MiniWasmFX.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ case class EvaluatorFX(module: ModuleInstance) {
val rest = insts.tail

// TODO: uncommenting this will fail tests that uses `testFileOutput`
// println(s"inst: ${inst} \t | ${frame.locals} | ${stack.reverse}" )
println(s"inst: ${inst} \t | ${frame.locals} | ${stack.reverse}" )

inst match {
case Drop => eval(rest, stack.tail, frame, kont, mkont, trail, h)
Expand Down Expand Up @@ -276,7 +276,7 @@ case class EvaluatorFX(module: ModuleInstance) {
val (inputs, restStack) = newStack.splitAt(inps.size)

if (handler.length == 0) {
val k: Cont[Ans] = (s, m) => eval(rest, newStack, frame, kont, m, trail, h)
val k: Cont[Ans] = (s, m) => eval(rest, s, frame, kont, m, trail, h)
f.k(inputs, k, mkont, h)
} else {
// TODO: attempt single tag first
Expand All @@ -290,7 +290,7 @@ case class EvaluatorFX(module: ModuleInstance) {

// f might be handled by the default handler (namely kont), or by the
// handler specified by tags (newhandler, which has the same type as meta-continuation)
val k: Cont[Ans] = (s, m) => eval(rest, newStack, frame, kont, m, trail, h)
val k: Cont[Ans] = (s, m) => eval(rest, s, frame, kont, m, trail, h)
f.k(inputs, k, mkont, newHandler)

// throw new Exception("tags not supported")
Expand Down
4 changes: 4 additions & 0 deletions src/test/scala/genwasym/TestFx.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,8 @@ class TestFx extends FunSuite {
testFile("./benchmarks/wasm/wasmfx/test_cont-strip.wast")
}

test("resume_chain1") {
testWastFile("./benchmarks/wasm/wasmfx/resume_chain1-strip.wast")
}

}

0 comments on commit d57a91a

Please sign in to comment.