| 1 |
(module $concurrent-generator |
| 2 |
(type $ghook (;0;) (func (param i64))) |
| 3 |
(type $proc (;1;) (func)) |
| 4 |
(type $pproc (;2;) (func (param i64 i64))) |
| 5 |
(type $cont (;3;) (cont $proc)) |
| 6 |
(type $pcont (;4;) (cont $pproc)) |
| 7 |
(type (;5;) (func (param (ref $cont)))) |
| 8 |
(type (;6;) (func (param i64 i64) (result i64))) |
| 9 |
(import "spectest" "print_i64" (func $log (;0;) (type $ghook))) |
| 10 |
(import "scheduler" "yield" (tag $syield (;0;) (type $proc))) |
| 11 |
(import "scheduler" "spawn" (tag $spawn (;1;) (type 5) (param (ref $cont)))) |
| 12 |
(import "scheduler" "scheduler" (func $scheduler (;1;) (type 5))) |
| 13 |
(import "generator" "sum" (func $gsum (;2;) (type 6))) |
| 14 |
(import "generator" "hook" (global $ghook (;0;) (mut (ref $ghook)))) |
| 15 |
(global $result (;1;) (mut i64) i64.const 0) |
| 16 |
(global $done (;2;) (mut i32) i32.const 0) |
| 17 |
(export "sum" (func 6)) |
| 18 |
(elem (;0;) declare func $main $bg-thread $syield) |
| 19 |
(func $syield (;3;) (type $ghook) (param $i i64) |
| 20 |
local.get $i |
| 21 |
call $log |
| 22 |
suspend $syield |
| 23 |
) |
| 24 |
(func $bg-thread (;4;) (type $proc) |
| 25 |
i64.const -10 |
| 26 |
call $log |
| 27 |
loop $l |
| 28 |
i64.const -11 |
| 29 |
call $log |
| 30 |
suspend $syield |
| 31 |
global.get $done |
| 32 |
i32.eqz |
| 33 |
br_if $l |
| 34 |
end |
| 35 |
i64.const -12 |
| 36 |
call $log |
| 37 |
) |
| 38 |
(func $main (;5;) (type $pproc) (param $i i64) (param $j i64) |
| 39 |
ref.func $bg-thread |
| 40 |
cont.new $cont |
| 41 |
suspend $spawn |
| 42 |
ref.func $syield |
| 43 |
global.set $ghook |
| 44 |
local.get $i |
| 45 |
local.get $j |
| 46 |
call $gsum |
| 47 |
global.set $result |
| 48 |
i32.const 1 |
| 49 |
global.set $done |
| 50 |
) |
| 51 |
(func (;6;) (type 6) (param $i i64) (param $j i64) (result i64) |
| 52 |
i64.const -1 |
| 53 |
call $log |
| 54 |
local.get $i |
| 55 |
local.get $j |
| 56 |
ref.func $main |
| 57 |
cont.new $pcont |
| 58 |
cont.bind $pcont $cont |
| 59 |
call $scheduler |
| 60 |
i64.const -2 |
| 61 |
call $log |
| 62 |
global.get $result |
| 63 |
) |
| 64 |
) |