blob: a9c71db48096be1cc690dc06adf6eda2408ab32d (
plain)
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
|
;; Test `func` declarations, i.e. functions
(module
;; Auxiliary definition
(type $sig (func))
(func $dummy)
;; Syntax
(func)
(func (export "f"))
(func $f)
(func $h (export "g"))
(func (local))
(func (local) (local))
(func (local i32))
(func (local $x i32))
(func (local i32 f64 i64))
(func (local i32) (local f64))
(func (local i32 f32) (local $x i64) (local) (local i32 f64))
(func (param))
(func (param) (param))
(func (param i32))
(func (param $x i32))
(func (param i32 f64 i64))
(func (param i32) (param f64))
(func (param i32 f32) (param $x i64) (param) (param i32 f64))
(func (result i32) (unreachable))
(func (type $sig))
(func $complex
(param i32 f32) (param $x i64) (param) (param i32)
(result i32)
(local f32) (local $y i32) (local i64 i32) (local) (local f64 i32)
(unreachable) (unreachable)
)
(func $complex-sig
(type $sig)
(local f32) (local $y i32) (local i64 i32) (local) (local f64 i32)
(unreachable) (unreachable)
)
;; Typing of locals
(func (export "local-first-i32") (result i32) (local i32 i32) (get_local 0))
(func (export "local-first-i64") (result i64) (local i64 i64) (get_local 0))
(func (export "local-first-f32") (result f32) (local f32 f32) (get_local 0))
(func (export "local-first-f64") (result f64) (local f64 f64) (get_local 0))
(func (export "local-second-i32") (result i32) (local i32 i32) (get_local 1))
(func (export "local-second-i64") (result i64) (local i64 i64) (get_local 1))
(func (export "local-second-f32") (result f32) (local f32 f32) (get_local 1))
(func (export "local-second-f64") (result f64) (local f64 f64) (get_local 1))
(func (export "local-mixed") (result f64)
(local f32) (local $x i32) (local i64 i32) (local) (local f64 i32)
(drop (f32.neg (get_local 0)))
(drop (i32.eqz (get_local 1)))
(drop (i64.eqz (get_local 2)))
(drop (i32.eqz (get_local 3)))
(drop (f64.neg (get_local 4)))
(drop (i32.eqz (get_local 5)))
(get_local 4)
)
;; Typing of parameters
(func (export "param-first-i32") (param i32 i32) (result i32) (get_local 0))
(func (export "param-first-i64") (param i64 i64) (result i64) (get_local 0))
(func (export "param-first-f32") (param f32 f32) (result f32) (get_local 0))
(func (export "param-first-f64") (param f64 f64) (result f64) (get_local 0))
(func (export "param-second-i32") (param i32 i32) (result i32) (get_local 1))
(func (export "param-second-i64") (param i64 i64) (result i64) (get_local 1))
(func (export "param-second-f32") (param f32 f32) (result f32) (get_local 1))
(func (export "param-second-f64") (param f64 f64) (result f64) (get_local 1))
(func (export "param-mixed") (param f32 i32) (param) (param $x i64) (param i32 f64 i32)
(result f64)
(drop (f32.neg (get_local 0)))
(drop (i32.eqz (get_local 1)))
(drop (i64.eqz (get_local 2)))
(drop (i32.eqz (get_local 3)))
(drop (f64.neg (get_local 4)))
(drop (i32.eqz (get_local 5)))
(get_local 4)
)
;; Typing of result
(func (export "empty"))
(func (export "value-void") (call $dummy))
(func (export "value-i32") (result i32) (i32.const 77))
(func (export "value-i64") (result i64) (i64.const 7777))
(func (export "value-f32") (result f32) (f32.const 77.7))
(func (export "value-f64") (result f64) (f64.const 77.77))
(func (export "value-block-void") (block (call $dummy) (call $dummy)))
(func (export "value-block-i32") (result i32)
(block i32 (call $dummy) (i32.const 77))
)
(func (export "return-empty") (return))
(func (export "return-i32") (result i32) (return (i32.const 78)))
(func (export "return-i64") (result i64) (return (i64.const 7878)))
(func (export "return-f32") (result f32) (return (f32.const 78.7)))
(func (export "return-f64") (result f64) (return (f64.const 78.78)))
(func (export "return-block-i32") (result i32)
(return (block i32 (call $dummy) (i32.const 77)))
)
(func (export "break-empty") (br 0))
(func (export "break-i32") (result i32) (br 0 (i32.const 79)))
(func (export "break-i64") (result i64) (br 0 (i64.const 7979)))
(func (export "break-f32") (result f32) (br 0 (f32.const 79.9)))
(func (export "break-f64") (result f64) (br 0 (f64.const 79.79)))
(func (export "break-block-i32") (result i32)
(br 0 (block i32 (call $dummy) (i32.const 77)))
)
(func (export "break-br_if-empty") (param i32)
(br_if 0 (get_local 0))
)
(func (export "break-br_if-num") (param i32) (result i32)
(drop (br_if 0 (i32.const 50) (get_local 0))) (i32.const 51)
)
(func (export "break-br_table-empty") (param i32)
(br_table 0 0 0 (get_local 0))
)
(func (export "break-br_table-num") (param i32) (result i32)
(br_table 0 0 (i32.const 50) (get_local 0)) (i32.const 51)
)
(func (export "break-br_table-nested-empty") (param i32)
(block (br_table 0 1 0 (get_local 0)))
)
(func (export "break-br_table-nested-num") (param i32) (result i32)
(i32.add
(block i32 (br_table 0 1 0 (i32.const 50) (get_local 0)) (i32.const 51))
(i32.const 2)
)
)
;; Default initialization of locals
(func (export "init-local-i32") (result i32) (local i32) (get_local 0))
(func (export "init-local-i64") (result i64) (local i64) (get_local 0))
(func (export "init-local-f32") (result f32) (local f32) (get_local 0))
(func (export "init-local-f64") (result f64) (local f64) (get_local 0))
;; Desugaring of implicit type signature
(func $empty-sig-1) ;; should be assigned type $sig
(func $complex-sig-1 (param f64 i64 f64 i64 f64 i64 f32 i32))
(func $empty-sig-2) ;; should be assigned type $sig
(func $complex-sig-2 (param f64 i64 f64 i64 f64 i64 f32 i32))
(func $complex-sig-3 (param f64 i64 f64 i64 f64 i64 f32 i32))
(type $empty-sig-duplicate (func))
(type $complex-sig-duplicate (func (param f64 i64 f64 i64 f64 i64 f32 i32)))
(table anyfunc
(elem
$complex-sig-3 $empty-sig-2 $complex-sig-1 $complex-sig-3 $empty-sig-1
)
)
(func (export "signature-explicit-reused")
(call_indirect $sig (i32.const 1))
(call_indirect $sig (i32.const 4))
)
(func (export "signature-implicit-reused")
;; The implicit index 16 in this test depends on the function and
;; type definitions, and may need adapting if they change.
(call_indirect 16
(f64.const 0) (i64.const 0) (f64.const 0) (i64.const 0)
(f64.const 0) (i64.const 0) (f32.const 0) (i32.const 0)
(i32.const 0)
)
(call_indirect 16
(f64.const 0) (i64.const 0) (f64.const 0) (i64.const 0)
(f64.const 0) (i64.const 0) (f32.const 0) (i32.const 0)
(i32.const 2)
)
(call_indirect 16
(f64.const 0) (i64.const 0) (f64.const 0) (i64.const 0)
(f64.const 0) (i64.const 0) (f32.const 0) (i32.const 0)
(i32.const 3)
)
)
(func (export "signature-explicit-duplicate")
(call_indirect $empty-sig-duplicate (i32.const 1))
)
(func (export "signature-implicit-duplicate")
(call_indirect $complex-sig-duplicate
(f64.const 0) (i64.const 0) (f64.const 0) (i64.const 0)
(f64.const 0) (i64.const 0) (f32.const 0) (i32.const 0)
(i32.const 0)
)
)
)
(assert_return (invoke "local-first-i32") (i32.const 0))
(assert_return (invoke "local-first-i64") (i64.const 0))
(assert_return (invoke "local-first-f32") (f32.const 0))
(assert_return (invoke "local-first-f64") (f64.const 0))
(assert_return (invoke "local-second-i32") (i32.const 0))
(assert_return (invoke "local-second-i64") (i64.const 0))
(assert_return (invoke "local-second-f32") (f32.const 0))
(assert_return (invoke "local-second-f64") (f64.const 0))
(assert_return (invoke "local-mixed") (f64.const 0))
(assert_return
(invoke "param-first-i32" (i32.const 2) (i32.const 3)) (i32.const 2)
)
(assert_return
(invoke "param-first-i64" (i64.const 2) (i64.const 3)) (i64.const 2)
)
(assert_return
(invoke "param-first-f32" (f32.const 2) (f32.const 3)) (f32.const 2)
)
(assert_return
(invoke "param-first-f64" (f64.const 2) (f64.const 3)) (f64.const 2)
)
(assert_return
(invoke "param-second-i32" (i32.const 2) (i32.const 3)) (i32.const 3)
)
(assert_return
(invoke "param-second-i64" (i64.const 2) (i64.const 3)) (i64.const 3)
)
(assert_return
(invoke "param-second-f32" (f32.const 2) (f32.const 3)) (f32.const 3)
)
(assert_return
(invoke "param-second-f64" (f64.const 2) (f64.const 3)) (f64.const 3)
)
(assert_return
(invoke "param-mixed"
(f32.const 1) (i32.const 2) (i64.const 3)
(i32.const 4) (f64.const 5.5) (i32.const 6)
)
(f64.const 5.5)
)
(assert_return (invoke "empty"))
(assert_return (invoke "value-void"))
(assert_return (invoke "value-i32") (i32.const 77))
(assert_return (invoke "value-i64") (i64.const 7777))
(assert_return (invoke "value-f32") (f32.const 77.7))
(assert_return (invoke "value-f64") (f64.const 77.77))
(assert_return (invoke "value-block-void"))
(assert_return (invoke "value-block-i32") (i32.const 77))
(assert_return (invoke "return-empty"))
(assert_return (invoke "return-i32") (i32.const 78))
(assert_return (invoke "return-i64") (i64.const 7878))
(assert_return (invoke "return-f32") (f32.const 78.7))
(assert_return (invoke "return-f64") (f64.const 78.78))
(assert_return (invoke "return-block-i32") (i32.const 77))
(assert_return (invoke "break-empty"))
(assert_return (invoke "break-i32") (i32.const 79))
(assert_return (invoke "break-i64") (i64.const 7979))
(assert_return (invoke "break-f32") (f32.const 79.9))
(assert_return (invoke "break-f64") (f64.const 79.79))
(assert_return (invoke "break-block-i32") (i32.const 77))
(assert_return (invoke "break-br_if-empty" (i32.const 0)))
(assert_return (invoke "break-br_if-empty" (i32.const 2)))
(assert_return (invoke "break-br_if-num" (i32.const 0)) (i32.const 51))
(assert_return (invoke "break-br_if-num" (i32.const 1)) (i32.const 50))
(assert_return (invoke "break-br_table-empty" (i32.const 0)))
(assert_return (invoke "break-br_table-empty" (i32.const 1)))
(assert_return (invoke "break-br_table-empty" (i32.const 5)))
(assert_return (invoke "break-br_table-empty" (i32.const -1)))
(assert_return (invoke "break-br_table-num" (i32.const 0)) (i32.const 50))
(assert_return (invoke "break-br_table-num" (i32.const 1)) (i32.const 50))
(assert_return (invoke "break-br_table-num" (i32.const 10)) (i32.const 50))
(assert_return (invoke "break-br_table-num" (i32.const -100)) (i32.const 50))
(assert_return (invoke "break-br_table-nested-empty" (i32.const 0)))
(assert_return (invoke "break-br_table-nested-empty" (i32.const 1)))
(assert_return (invoke "break-br_table-nested-empty" (i32.const 3)))
(assert_return (invoke "break-br_table-nested-empty" (i32.const -2)))
(assert_return
(invoke "break-br_table-nested-num" (i32.const 0)) (i32.const 52)
)
(assert_return
(invoke "break-br_table-nested-num" (i32.const 1)) (i32.const 50)
)
(assert_return
(invoke "break-br_table-nested-num" (i32.const 2)) (i32.const 52)
)
(assert_return
(invoke "break-br_table-nested-num" (i32.const -3)) (i32.const 52)
)
(assert_return (invoke "init-local-i32") (i32.const 0))
(assert_return (invoke "init-local-i64") (i64.const 0))
(assert_return (invoke "init-local-f32") (f32.const 0))
(assert_return (invoke "init-local-f64") (f64.const 0))
(assert_return (invoke "signature-explicit-reused"))
(assert_return (invoke "signature-implicit-reused"))
(assert_return (invoke "signature-explicit-duplicate"))
(assert_return (invoke "signature-implicit-duplicate"))
;; Invalid typing of locals
(assert_invalid
(module (func $type-local-num-vs-num (result i64) (local i32) (get_local 0)))
"type mismatch"
)
(assert_invalid
(module (func $type-local-num-vs-num (local f32) (i32.eqz (get_local 0))))
"type mismatch"
)
(assert_invalid
(module (func $type-local-num-vs-num (local f64 i64) (f64.neg (get_local 1))))
"type mismatch"
)
;; Invalid typing of parameters
(assert_invalid
(module (func $type-param-num-vs-num (param i32) (result i64) (get_local 0)))
"type mismatch"
)
(assert_invalid
(module (func $type-param-num-vs-num (param f32) (i32.eqz (get_local 0))))
"type mismatch"
)
(assert_invalid
(module (func $type-param-num-vs-num (param f64 i64) (f64.neg (get_local 1))))
"type mismatch"
)
;; Invalid typing of result
(assert_invalid
(module (func $type-multiple-result (result i32 i32) (unreachable)))
"invalid result arity"
)
(assert_invalid
(module
(type (func (result i32 i32)))
(func $type-multiple-result (type 0) (unreachable))
)
"invalid result arity"
)
(assert_invalid
(module (func $type-empty-i32 (result i32)))
"type mismatch"
)
(assert_invalid
(module (func $type-empty-i64 (result i64)))
"type mismatch"
)
(assert_invalid
(module (func $type-empty-f32 (result f32)))
"type mismatch"
)
(assert_invalid
(module (func $type-empty-f64 (result f64)))
"type mismatch"
)
(assert_invalid
(module (func $type-value-void-vs-num (result i32)
(nop)
))
"type mismatch"
)
(assert_invalid
(module (func $type-value-num-vs-void
(i32.const 0)
))
"type mismatch"
)
(assert_invalid
(module (func $type-value-num-vs-num (result i32)
(f32.const 0)
))
"type mismatch"
)
(assert_invalid
(module (func $type-return-last-empty-vs-num (result i32)
(return)
))
"type mismatch"
)
(assert_invalid
(module (func $type-return-last-void-vs-num (result i32)
(return (nop))
))
"type mismatch"
)
(assert_invalid
(module (func $type-return-last-num-vs-num (result i32)
(return (i64.const 0))
))
"type mismatch"
)
(assert_invalid
(module (func $type-return-empty-vs-num (result i32)
(return) (i32.const 1)
))
"type mismatch"
)
(assert_invalid
(module (func $type-return-void-vs-num (result i32)
(return (nop)) (i32.const 1)
))
"type mismatch"
)
(assert_invalid
(module (func $type-return-num-vs-num (result i32)
(return (i64.const 1)) (i32.const 1)
))
"type mismatch"
)
(assert_invalid
(module (func $type-return-first-num-vs-num (result i32)
(return (i64.const 1)) (return (i32.const 1))
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-last-void-vs-num (result i32)
(br 0)
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-last-num-vs-num (result i32)
(br 0 (f32.const 0))
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-void-vs-num (result i32)
(br 0) (i32.const 1)
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-num-vs-num (result i32)
(br 0 (i64.const 1)) (i32.const 1)
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-first-num-vs-num (result i32)
(br 0 (i64.const 1)) (br 0 (i32.const 1))
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-nested-empty-vs-num (result i32)
(block (br 1)) (br 0 (i32.const 1))
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-nested-void-vs-num (result i32)
(block (br 1 (nop))) (br 0 (i32.const 1))
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-nested-num-vs-num (result i32)
(block (br 1 (i64.const 1))) (br 0 (i32.const 1))
))
"type mismatch"
)
|