1*b242f5a6SAlex Crichton;;! component_model_async = true 2*b242f5a6SAlex Crichton;;! component_model_async_stackful = true 3*b242f5a6SAlex Crichton;;! reference_types = true 4*b242f5a6SAlex Crichton;;! gc_types = true 5*b242f5a6SAlex Crichton;;! multi_memory = true 6*b242f5a6SAlex Crichton 7*b242f5a6SAlex Crichton;; async lift; no callback 8*b242f5a6SAlex Crichton(component 9*b242f5a6SAlex Crichton (core module $m 10*b242f5a6SAlex Crichton (func (export "foo") (param i32) unreachable) 11*b242f5a6SAlex Crichton ) 12*b242f5a6SAlex Crichton (core instance $i (instantiate $m)) 13*b242f5a6SAlex Crichton 14*b242f5a6SAlex Crichton (func (export "foo") (param "p1" u32) (result u32) 15*b242f5a6SAlex Crichton (canon lift (core func $i "foo") async) 16*b242f5a6SAlex Crichton ) 17*b242f5a6SAlex Crichton) 18*b242f5a6SAlex Crichton 19*b242f5a6SAlex Crichton;; async lower -> async lift without callback 20*b242f5a6SAlex Crichton(component 21*b242f5a6SAlex Crichton (component $lifter 22*b242f5a6SAlex Crichton (core module $m 23*b242f5a6SAlex Crichton (import "" "task.return" (func $task-return (param i32))) 24*b242f5a6SAlex Crichton (func (export "foo") (param i32) (call $task-return (local.get 0))) 25*b242f5a6SAlex Crichton ) 26*b242f5a6SAlex Crichton (core func $task-return (canon task.return (result u32))) 27*b242f5a6SAlex Crichton (core instance $i (instantiate $m 28*b242f5a6SAlex Crichton (with "" (instance (export "task.return" (func $task-return)))) 29*b242f5a6SAlex Crichton )) 30*b242f5a6SAlex Crichton 31*b242f5a6SAlex Crichton (func (export "foo") (param "p1" u32) (result u32) 32*b242f5a6SAlex Crichton (canon lift (core func $i "foo") async) 33*b242f5a6SAlex Crichton ) 34*b242f5a6SAlex Crichton ) 35*b242f5a6SAlex Crichton 36*b242f5a6SAlex Crichton (component $lowerer 37*b242f5a6SAlex Crichton (import "a" (func $foo (param "p1" u32) (result u32))) 38*b242f5a6SAlex Crichton (core module $libc (memory (export "memory") 1)) 39*b242f5a6SAlex Crichton (core instance $libc (instantiate $libc)) 40*b242f5a6SAlex Crichton (core func $foo (canon lower (func $foo) async (memory $libc "memory"))) 41*b242f5a6SAlex Crichton (core module $m 42*b242f5a6SAlex Crichton (import "libc" "memory" (memory 1)) 43*b242f5a6SAlex Crichton (import "" "foo" (func $foo (param i32 i32) (result i32))) 44*b242f5a6SAlex Crichton (func (export "run") 45*b242f5a6SAlex Crichton block 46*b242f5a6SAlex Crichton (call $foo (i32.const 42) (i32.const 1204)) 47*b242f5a6SAlex Crichton (i32.eq (i32.load offset=0 (i32.const 1204)) (i32.const 42)) 48*b242f5a6SAlex Crichton br_if 0 49*b242f5a6SAlex Crichton unreachable 50*b242f5a6SAlex Crichton end 51*b242f5a6SAlex Crichton ) 52*b242f5a6SAlex Crichton ) 53*b242f5a6SAlex Crichton (core instance $i (instantiate $m 54*b242f5a6SAlex Crichton (with "libc" (instance $libc)) 55*b242f5a6SAlex Crichton (with "" (instance (export "foo" (func $foo)))) 56*b242f5a6SAlex Crichton )) 57*b242f5a6SAlex Crichton (func (export "run") (canon lift (core func $i "run"))) 58*b242f5a6SAlex Crichton ) 59*b242f5a6SAlex Crichton 60*b242f5a6SAlex Crichton (instance $lifter (instantiate $lifter)) 61*b242f5a6SAlex Crichton (instance $lowerer (instantiate $lowerer (with "a" (func $lifter "foo")))) 62*b242f5a6SAlex Crichton (func (export "run") (alias export $lowerer "run")) 63*b242f5a6SAlex Crichton) 64*b242f5a6SAlex Crichton 65*b242f5a6SAlex Crichton(assert_return (invoke "run")) 66*b242f5a6SAlex Crichton 67*b242f5a6SAlex Crichton;; sync lower -> async lift without callback 68*b242f5a6SAlex Crichton(component 69*b242f5a6SAlex Crichton (component $lifter 70*b242f5a6SAlex Crichton (core module $m 71*b242f5a6SAlex Crichton (import "" "task.return" (func $task-return (param i32))) 72*b242f5a6SAlex Crichton (func (export "foo") (param i32) (call $task-return (local.get 0))) 73*b242f5a6SAlex Crichton ) 74*b242f5a6SAlex Crichton (core func $task-return (canon task.return (result u32))) 75*b242f5a6SAlex Crichton (core instance $i (instantiate $m 76*b242f5a6SAlex Crichton (with "" (instance (export "task.return" (func $task-return)))) 77*b242f5a6SAlex Crichton )) 78*b242f5a6SAlex Crichton 79*b242f5a6SAlex Crichton (func (export "foo") (param "p1" u32) (result u32) 80*b242f5a6SAlex Crichton (canon lift (core func $i "foo") async) 81*b242f5a6SAlex Crichton ) 82*b242f5a6SAlex Crichton ) 83*b242f5a6SAlex Crichton 84*b242f5a6SAlex Crichton (component $lowerer 85*b242f5a6SAlex Crichton (import "a" (func $foo (param "p1" u32) (result u32))) 86*b242f5a6SAlex Crichton (core func $foo (canon lower (func $foo))) 87*b242f5a6SAlex Crichton (core module $m 88*b242f5a6SAlex Crichton (import "" "foo" (func $foo (param i32) (result i32))) 89*b242f5a6SAlex Crichton (func (export "run") 90*b242f5a6SAlex Crichton block 91*b242f5a6SAlex Crichton (i32.eq (call $foo (i32.const 42)) (i32.const 42)) 92*b242f5a6SAlex Crichton br_if 0 93*b242f5a6SAlex Crichton unreachable 94*b242f5a6SAlex Crichton end 95*b242f5a6SAlex Crichton ) 96*b242f5a6SAlex Crichton ) 97*b242f5a6SAlex Crichton (core instance $i (instantiate $m 98*b242f5a6SAlex Crichton (with "" (instance (export "foo" (func $foo)))) 99*b242f5a6SAlex Crichton )) 100*b242f5a6SAlex Crichton (func (export "run") (canon lift (core func $i "run"))) 101*b242f5a6SAlex Crichton ) 102*b242f5a6SAlex Crichton 103*b242f5a6SAlex Crichton (instance $lifter (instantiate $lifter)) 104*b242f5a6SAlex Crichton (instance $lowerer (instantiate $lowerer (with "a" (func $lifter "foo")))) 105*b242f5a6SAlex Crichton (func (export "run") (alias export $lowerer "run")) 106*b242f5a6SAlex Crichton) 107*b242f5a6SAlex Crichton 108*b242f5a6SAlex Crichton(assert_return (invoke "run")) 109*b242f5a6SAlex Crichton 110*b242f5a6SAlex Crichton;; waitable-set.wait 111*b242f5a6SAlex Crichton(component 112*b242f5a6SAlex Crichton (core module $libc (memory (export "memory") 1)) 113*b242f5a6SAlex Crichton (core instance $libc (instantiate $libc)) 114*b242f5a6SAlex Crichton (core module $m 115*b242f5a6SAlex Crichton (import "" "waitable-set.wait" (func $waitable-set-wait (param i32 i32) (result i32))) 116*b242f5a6SAlex Crichton ) 117*b242f5a6SAlex Crichton (core func $waitable-set-wait (canon waitable-set.wait cancellable (memory $libc "memory"))) 118*b242f5a6SAlex Crichton (core instance $i (instantiate $m (with "" (instance (export "waitable-set.wait" (func $waitable-set-wait)))))) 119*b242f5a6SAlex Crichton) 120*b242f5a6SAlex Crichton 121*b242f5a6SAlex Crichton;; waitable-set.poll 122*b242f5a6SAlex Crichton(component 123*b242f5a6SAlex Crichton (core module $libc (memory (export "memory") 1)) 124*b242f5a6SAlex Crichton (core instance $libc (instantiate $libc)) 125*b242f5a6SAlex Crichton (core module $m 126*b242f5a6SAlex Crichton (import "" "waitable-set.poll" (func $waitable-set-poll (param i32 i32) (result i32))) 127*b242f5a6SAlex Crichton ) 128*b242f5a6SAlex Crichton (core func $waitable-set-poll (canon waitable-set.poll cancellable (memory $libc "memory"))) 129*b242f5a6SAlex Crichton (core instance $i (instantiate $m (with "" (instance (export "waitable-set.poll" (func $waitable-set-poll)))))) 130*b242f5a6SAlex Crichton) 131*b242f5a6SAlex Crichton 132*b242f5a6SAlex Crichton;; yield 133*b242f5a6SAlex Crichton(component 134*b242f5a6SAlex Crichton (core module $m 135*b242f5a6SAlex Crichton (import "" "yield" (func $yield (result i32))) 136*b242f5a6SAlex Crichton ) 137*b242f5a6SAlex Crichton (core func $yield (canon thread.yield cancellable)) 138*b242f5a6SAlex Crichton (core instance $i (instantiate $m (with "" (instance (export "yield" (func $yield)))))) 139*b242f5a6SAlex Crichton) 140