(module $chain (type $func (;0;) (func)) (type $cont (;1;) (cont $func)) (type $i-func (;2;) (func (param i32))) (type $i-cont (;3;) (cont $i-func)) (type (;4;) (func (result i32))) (type (;5;) (func (param (ref $cont)) (result i32))) (type (;6;) (func (param i32 i32))) (import "actor" "self" (tag $self (;0;) (type 4) (result i32))) (import "actor" "spawn" (tag $spawn (;1;) (type 5) (param (ref $cont)) (result i32))) (import "actor" "send" (tag $send (;2;) (type 6) (param i32 i32))) (import "actor" "recv" (tag $recv (;3;) (type 4) (result i32))) (import "spectest" "print_i32" (func $log (;0;) (type $i-func))) (export "chain" (func $chain)) (elem (;0;) declare func $next) (func $next (;1;) (type $i-func) (param $p i32) (local $s i32) suspend $recv local.set $s i32.const -1 call $log local.get $s local.get $p suspend $send ) (func $chain (;2;) (type $i-func) (param $n i32) (local $p i32) suspend $self local.set $p loop $l local.get $n i32.eqz if ;; label = @2 i32.const 42 local.get $p suspend $send else local.get $p ref.func $next cont.new $i-cont cont.bind $i-cont $cont suspend $spawn local.set $p local.get $n i32.const 1 i32.sub local.set $n br $l end end suspend $recv call $log ) )