(module $concurrent-generator (type $ghook (;0;) (func (param i64))) (type $proc (;1;) (func)) (type $pproc (;2;) (func (param i64 i64))) (type $cont (;3;) (cont $proc)) (type $pcont (;4;) (cont $pproc)) (type (;5;) (func (param (ref $cont)))) (type (;6;) (func (param i64 i64) (result i64))) (import "spectest" "print_i64" (func $log (;0;) (type $ghook))) (import "scheduler" "yield" (tag $syield (;0;) (type $proc))) (import "scheduler" "spawn" (tag $spawn (;1;) (type 5) (param (ref $cont)))) (import "scheduler" "scheduler" (func $scheduler (;1;) (type 5))) (import "generator" "sum" (func $gsum (;2;) (type 6))) (import "generator" "hook" (global $ghook (;0;) (mut (ref $ghook)))) (global $result (;1;) (mut i64) i64.const 0) (global $done (;2;) (mut i32) i32.const 0) (export "sum" (func 6)) (elem (;0;) declare func $main $bg-thread $syield) (func $syield (;3;) (type $ghook) (param $i i64) local.get $i call $log suspend $syield ) (func $bg-thread (;4;) (type $proc) i64.const -10 call $log loop $l i64.const -11 call $log suspend $syield global.get $done i32.eqz br_if $l end i64.const -12 call $log ) (func $main (;5;) (type $pproc) (param $i i64) (param $j i64) ref.func $bg-thread cont.new $cont suspend $spawn ref.func $syield global.set $ghook local.get $i local.get $j call $gsum global.set $result i32.const 1 global.set $done ) (func (;6;) (type 6) (param $i i64) (param $j i64) (result i64) i64.const -1 call $log local.get $i local.get $j ref.func $main cont.new $pcont cont.bind $pcont $cont call $scheduler i64.const -2 call $log global.get $result ) )