Debian Codegraph @

tests/cli/component-model/instance-type.wast

raw
1 ;; RUN: wast --assert default --snapshot tests/snapshots %
2
3 ;; instances
4 (component
5 (type (instance))
6
7 (type $foo (func))
8
9 (type $t (func (result string)))
10
11 (core type (module
12 (type $local_type (func))
13 ;; functions
14 (export "a" (func))
15 (export "b" (func $foo))
16 (export "c" (func))
17 (export "d" (func $foo))
18 (export "e" (func (type $local_type)))
19 (export "f" (func (param i32)))
20 (export "g" (func (param i32) (result i32 i64)))
21 (export "h" (func (type $local_type) (result i32)))
22
23 ;; globals
24 (export "i" (global i32))
25 (export "j" (global $foo i32))
26 (export "k" (global (mut i32)))
27
28 ;; tables
29 (export "l" (table 1 funcref))
30 (export "m" (table $foo 1 funcref))
31
32 ;; memory
33 (export "n" (memory 1))
34 (export "o" (memory $foo 1))
35 (export "p" (memory 1 2))
36 (export "q" (memory 1 2 shared))
37 ))
38
39 (type $outer (instance
40 (type $local_type (func))
41 ;; functions
42 (export "a" (func))
43 (export "a2" (func (type $local_type)))
44 (export "b" (func))
45 (export "c" (func))
46 (export "d" (func))
47 (export "e" (func (type $t)))
48 (export "f" (func (param "f" string)))
49 (export "g" (func (param "g" s32) (result u32)))
50 (export "h" (func (type $t)))
51
52 ;; components
53 (type $component_type (component))
54 (export "c1" (component))
55 (export "c2" (component (import "i1" (func))))
56 (export "c3" (component (export "e1" (func))))
57 (export "c4" (component (type $component_type)))
58 (export "c5" (component
59 (type $nested_func_type (func))
60 (alias outer $outer $local_type (type $my_type))
61 (import "i1" (func (type $nested_func_type)))
62 (import "i2" (component))
63 (export "e1" (func (type $my_type)))
64 (export "e2" (component))
65 ))
66 ))
67 )
68
69 ;; expand inline types
70 (component
71 (type (instance (export "a" (instance))))
72 )
73
74 ;; reference outer types
75 (component
76 (type (instance
77 (type $t (instance))
78 (export "a" (instance (type $t)))
79 ))
80 (type $x (instance))
81 (type (instance (export "a" (instance (type $x)))))
82 )
83
84 ;; recursive
85 (component
86 (type (instance (export "a" (core module
87 (type $functype (func))
88
89 (export "a" (func))
90 (export "b" (func (type 0)))
91 (export "c" (func (param i32)))
92 (export "d" (func (type $functype)))
93
94 ;; globals
95 (export "e" (global i32))
96 (export "f" (global (mut i32)))
97
98 ;; tables
99 (export "g" (table 1 funcref))
100
101 ;; memory
102 (export "h" (memory 1))
103 (export "i" (memory 1 2))
104 (export "j" (memory 1 2 shared))
105 ))))
106 )
107
108 ;; modules
109 (component
110 (core type (module))
111
112 (core type $foo (module))
113
114 (type $empty (func))
115 (type $i (instance))
116
117 (core type (module
118 (type $empty (func))
119 (import "" "a" (func))
120 (import "" "b" (func (type $empty)))
121 (import "" "c" (func (param i32)))
122 (import "" "d" (func (param i32) (result i32)))
123
124 (import "" "e" (global i32))
125 (import "" "f" (memory 1))
126 (import "" "g" (table 1 funcref))
127
128 (export "a" (func))
129 (export "b" (global i32))
130 (export "c" (memory 1))
131 (export "d" (table 1 funcref))
132
133 (export "e" (func (type $empty)))
134 (export "f" (func (param i32)))
135 ))
136
137 (type (component
138 (import "a" (func))
139 (import "b" (func (type $empty)))
140 (import "c" (func (param "c" s32)))
141 (import "d" (func (param "d" s32) (result s32)))
142
143 (import "h" (instance))
144 (import "i" (instance (type $i)))
145 (import "j" (instance
146 (export "a" (func))
147 (export "b" (func (type $empty)))
148 (export "c" (func (param "c" s32)))
149 ))
150
151 (import "k" (core module))
152 (import "l" (core module
153 (type $empty (func))
154 (import "" "a" (func (type $empty)))
155 (import "" "b" (func (param i32)))
156 (export "a" (func (type $empty)))
157 (export "b" (func (param i32)))
158 ))
159
160 (export "m" (func))
161 (export "n" (func (type $empty)))
162 (export "o" (func (param "f" s32)))
163
164 (export "p" (instance
165 (export "a" (func))
166 (export "b" (func (type $empty)))
167 (export "c" (func (param "c" s32)))
168 ))
169
170 (export "q" (core module
171 (type $empty (func))
172 (import "" "a" (func (type $empty)))
173 (import "" "b" (func (param i32)))
174 (export "a" (func (type $empty)))
175 (export "b" (func (param i32)))
176 ))
177 ))
178 )
179
180 (assert_invalid
181 (component
182 (type (instance
183 (export "a" (func))
184 (export "a" (func)))))
185 "export name `a` conflicts with previous name `a`")
186
187 (assert_invalid
188 (component
189 (type $t (func))
190 (type (instance
191 (export "a" (instance (type $t)))
192 )))
193 "type index 0 is not an instance type")
194
195 (assert_invalid
196 (component
197 (core type $t (func))
198 (type (instance
199 (export "a" (core module (type $t)))
200 )))
201 "core type index 0 is not a module type")
202
203 (assert_malformed
204 (component quote
205 "(type $t (func))"
206 "(type (instance (export \"a\" (core module (type $t)))))"
207 )
208 "unknown core type")
209
210 (assert_invalid
211 (component
212 (type $t (record (field "a" string)))
213 (type (instance
214 (export "a" (func (type $t)))
215 )))
216 "type index 0 is not a function type")
217
218 (assert_invalid
219 (component
220 (type $t (instance))
221 (type (instance
222 (export "a" (func (type $t)))
223 )))
224 "type index 0 is not a function type")
225
226 (assert_invalid
227 (component
228 (type $t (instance))
229 (type (instance
230 (export "a" (instance
231 (export "a" (func (type $t)))
232 ))
233 )))
234 "type index 0 is not a function type")