forked from bytecodealliance/wasm-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
alias.wast
284 lines (244 loc) · 6.66 KB
/
alias.wast
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
;; FIXME(#588) should be valid
(assert_invalid
(component
(import "i" (instance $i
(export "f1" (func $f1))
(export "f2" (func $f2 (param string)))
))
(export "run" (func $i "f1"))
)
"instance 0 is not a module instance")
;; FIXME(#588) should be valid
(assert_invalid
(component
(import "i" (component $c
(export "f1" (func $f1))
(export "f2" (func $f2 (param string)))
))
(instance $i (instantiate (component $c)))
(export "run" (func $i "f1"))
)
"instance 0 is not a module instance")
(component
(import "i" (module $m
(export "f1" (func $f1))
(export "f2" (func $f2 (param i32)))
))
(instance $i (instantiate (module $m)))
(module $m2 (import "" "" (func)))
(instance (instantiate (module $m2) (with "" (instance (export "" (func $i "f1"))))))
)
(component
(import "" (module $libc
(export "memory" (memory 1))
(export "table" (table 0 funcref))
(export "func" (func))
(export "global" (global i32))
(export "global mut" (global (mut i64)))
))
(instance $libc (instantiate (module $libc)))
(alias export $libc "memory" (memory $mem))
(alias export $libc "table" (table $tbl))
(alias export $libc "func" (func $func))
(alias export $libc "global" (global $global))
(alias export $libc "global mut" (global $global_mut))
(import "x" (module $needs_libc
(import "" "memory" (memory 1))
(import "" "table" (table 0 funcref))
(import "" "func" (func))
(import "" "global" (global i32))
(import "" "global mut" (global (mut i64)))
))
(instance (instantiate (module $needs_libc) (with "" (instance
(export "memory" (memory $mem))
(export "table" (table $tbl))
(export "func" (func $func))
(export "global" (global $global))
(export "global mut" (global $global_mut))
))))
)
;; FIXME(#588) should be valid
(assert_invalid
(component
(import "" (instance $i
(export "1" (func))
(export "2" (module))
(export "3" (instance))
))
(export "1" (func $i "1"))
(export "2" (module $i "2"))
(export "3" (instance $i "3"))
)
"instance 0 is not a module instance")
(component
(import "" (module $libc
(export "memory" (memory 1))
(export "table" (table 0 funcref))
(export "func" (func))
(export "global" (global i32))
(export "global mut" (global (mut i64)))
))
(import "x" (module $needs_libc
(import "" "memory" (memory 1))
(import "" "table" (table 0 funcref))
(import "" "func" (func))
(import "" "global" (global i32))
(import "" "global mut" (global (mut i64)))
))
(instance $libc (instantiate (module $libc)))
(instance (instantiate (module $needs_libc) (with "" (instance
(export "memory" (memory $libc "memory"))
(export "table" (table $libc "table"))
(export "func" (func $libc "func"))
(export "global" (global $libc "global"))
(export "global mut" (global $libc "global mut"))
))))
)
(assert_invalid
(component $outer
(import "" (instance $i (export "a" (func))))
(import "a" (component $m
(import "" (component (export "a" (func))))
))
(component $local
(alias outer $outer $i (instance))
)
(instance (instantiate (component $m) (with "" (component $local))))
)
"invalid leading byte (0xff) for outer alias")
(assert_invalid
(component
(import "" (instance (export "" (func))))
(export "" (module 0 ""))
)
"export `` for instance 0 is not a module")
(assert_invalid
(component
(component
(component (export ""))
)
(instance (instantiate (component 0)))
(export "" (module 0 ""))
)
"export `` for instance 0 is not a module")
(assert_invalid
(component
(import "" (module))
(instance (instantiate (module 0)))
(alias export 0 "" (func))
)
"instance 0 has no export named ``")
(assert_invalid
(component
(module)
(instance (instantiate (module 0)))
(alias export 0 "" (func))
)
"instance 0 has no export named ``")
;; FIXME(#588) should have a different error
(assert_invalid
(component
(import "" (component))
(instance (instantiate (component 0)))
(alias export 0 "" (func))
)
"instance 0 is not a module instance")
(; "instance 0 has no export named ``") ;)
(assert_invalid
(component
(import "a" (module $a (export "" (func))))
(import "b" (module $b (import "" "" (func (param i32)))))
(instance $a (instantiate (module $a)))
(instance $b (instantiate (module $b) (with "" (instance $a))))
)
"type mismatch")
;; aliasing various items works
(component $PARENT
(type $t (func (result string)))
(component
(import "" (func (type $t)))
)
(component
(alias outer $PARENT $t (type $my_type))
(alias outer 0 $my_type (type $my_type_again))
(import "" (func (type $my_type_again)))
)
)
(component
(type $a (func (result string)))
(component
(type $b (func (result u32)))
(component
(type $c (func (result s32)))
(component
(import "a" (func $a (type $a)))
(import "b" (func $b (type $b)))
(import "c" (func $c (type $c)))
(import "" (component $C
(import "a" (func (result string)))
(import "b" (func (result u32)))
(import "c" (func (result s32)))
))
(instance (instantiate (component $C)
(with "a" (func $a))
(with "b" (func $b))
(with "c" (func $c))
))
)
)
)
)
;; multiple projections in alias sugar
;; FIXME(#588) should be valid
(assert_invalid
(component $a
(import "" (instance $a
(export "b" (instance
(export "c" (instance
(export "d" (instance
(export "f" (func))
))
))
))
))
(import "b" (component $b (import "" (func))))
(instance (instantiate (component $b)
(with "" (func $a "b" "c" "d" "f"))
))
)
"instance 3 is not a module instance")
;; alias some constructs
(component
(import "" (instance $foo (export "v" (value s32))))
(export "v" (value $foo "v"))
)
(component
(import "" (instance $foo (export "v" (component))))
(export "v" (component $foo "v"))
)
(component
(import "" (instance $foo (export "v" (module))))
(export "v" (module $foo "v"))
)
(component $C
(module $m)
(alias outer $C $m (module $target))
(export "v" (module $target))
)
(component $C
(component $m)
(alias outer $C $m (component $target))
(export "v" (component $target))
)
(assert_invalid
(component (alias outer 100 0 (module)))
"invalid outer alias count of 100")
(assert_invalid
(component (alias outer 0 0 (module)))
"index out of bounds")
(assert_invalid
(component (alias outer 100 0 (component)))
"invalid outer alias count of 100")
(assert_invalid
(component (alias outer 0 0 (component)))
"index out of bounds")