Skip to content

Commit

Permalink
failing exmaple, k1 in suspend should not be forgotten
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuoguo committed Nov 27, 2024
1 parent 5c38f2d commit c20456c
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 4 deletions.
53 changes: 53 additions & 0 deletions benchmarks/wasm/wasmfx/diff_resume-strip.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
(module
(type (;0;) (func (param i32)))
(type (;1;) (cont 0))
(type (;2;) (func (result i32)))
(type (;3;) (func))
(import "spectest" "print_i32" (func (;0;) (type 0)))
(tag (;0;) (type 2) (result i32))
(export "_start" (func 2))
(start 2)
(elem (;0;) declare func 1)
(func (;1;) (type 0) (param i32)
local.get 0
call 0
suspend 0
call 0
)
(func (;2;) (type 3)
(local i32 (ref 1))
ref.func 1
cont.new 1
local.set 1
i32.const 10
local.set 0
block ;; label = @1
block (result (ref 1)) ;; label = @2
local.get 0
local.get 1
resume 1 (on 0 0 (;@2;))
i32.const -2
call 0
br 1 (;@1;)
end
local.set 1
local.get 0
i32.const 1
i32.add
local.set 0
block ;; label = @2
block (result (ref 1)) ;; label = @3
local.get 0
local.get 1
resume 1 (on 0 0 (;@3;))
i32.const 42
call 0
br 1 (;@2;)
end
i32.const 111
call 0
drop
end
end
)
)
52 changes: 52 additions & 0 deletions benchmarks/wasm/wasmfx/diff_resume.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
(module
(import "spectest" "print_i32" (func $print_i32 (param i32)))
(type $task (func (param i32)))
(type $cont (cont $task))

(tag $yield (result i32))

(func $task1 (param $x i32)
(call $print_i32 (local.get $x))
(suspend $yield) ;; DH: levaes a continuation on the stack, jump to the tag $yield
;; when come back, the stack should contains a i32 value, since the return type of $yield is i32
(call $print_i32)
)

(func $main (export "_start")
(local $i i32)
(local $k (ref $cont))
(local.set $k (cont.new $cont (ref.func $task1)))
(local.set $i (i32.const 10))
(block $h
(block $on_yield (result (ref $cont))
(resume $cont
(on $yield $on_yield)
(local.get $i)
(local.get $k)
)
(call $print_i32 (i32.const -2))
(br $h))
;; $on_yield lands here, with the continuation on the stack
(local.set $k)
(local.set $i (i32.add (local.get $i) (i32.const 1)))
(block $h
(block $on_yield2 (result (ref $cont))
(resume $cont
(on $yield $on_yield2)
(local.get $i)
(local.get $k)
)
(call $print_i32 (i32.const 42))
(br $h)
)
;; $on_yield2 lands here, with the continuation on the stack
(call $print_i32 (i32.const 111))
drop
)
)
)

(elem declare func $task1)

(start $main)
)
15 changes: 11 additions & 4 deletions src/test/scala/genwasym/TestFx.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,16 @@ class TestFx extends FunSuite {
// testWastFile("./benchmarks/wasm/wasmfx/cont_bind3.bin.wast")
// }

// test("cont") {
// // testFile("./benchmarks/wasm/wasmfx/callcont.wast", None, ExpInt(11))
// testWastFile("./benchmarks/wasm/wasmfx/callcont.bin.wast")
// }
test("cont") {
// testFile("./benchmarks/wasm/wasmfx/callcont.wast", None, ExpInt(11))
testWastFile("./benchmarks/wasm/wasmfx/callcont.bin.wast")
}

test("resume w/o suspend") {
testWastFile("./benchmarks/wasm/wasmfx/resume1.bin.wast")
}

// wasmfx sec 2.3 like example
test("test_cont") {
testFile("./benchmarks/wasm/wasmfx/test_cont-strip.wast")
}
Expand All @@ -164,14 +165,20 @@ class TestFx extends FunSuite {
testWastFile("./benchmarks/wasm/wasmfx/resume_chain1-strip.wast")
}

// printing 0 not 1
test("nested suspend") {
testFile("./benchmarks/wasm/wasmfx/nested_suspend-strip.wat")

// testFileOutput("./benchmarks/wasm/wasmfx/nested_suspend-strip.wat", List(0))
}

// going to print 100 to 1 and then print 42
test("gen") {
testFile("./benchmarks/wasm/wasmfx/gen-stripped.wast")
}

test("diff resume") {
testFileOutput("./benchmarks/wasm/wasmfx/diff_resume-strip.wat", List(10, 11, 42))
}

}

0 comments on commit c20456c

Please sign in to comment.