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