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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
|
/* Copyright 2021 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// ./test/core/func.wast
// ./test/core/func.wast:3
let $0 = instantiate(`(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))
(func (result) (result))
(func (result i32) (unreachable))
(func (result i32 f64 f32) (unreachable))
(func (result i32) (result f64) (unreachable))
(func (result i32 f32) (result i64) (result) (result i32 f64) (unreachable))
(type $$sig-1 (func))
(type $$sig-2 (func (result i32)))
(type $$sig-3 (func (param $$x i32)))
(type $$sig-4 (func (param i32 f64 i32) (result i32)))
(func (export "type-use-1") (type $$sig-1))
(func (export "type-use-2") (type $$sig-2) (i32.const 0))
(func (export "type-use-3") (type $$sig-3))
(func (export "type-use-4") (type $$sig-4) (i32.const 0))
(func (export "type-use-5") (type $$sig-2) (result i32) (i32.const 0))
(func (export "type-use-6") (type $$sig-3) (param i32))
(func (export "type-use-7")
(type $$sig-4) (param i32) (param f64 i32) (result i32) (i32.const 0)
)
(func (type $$sig))
(func (type $$forward)) ;; forward reference
(func $$complex
(param i32 f32) (param $$x i64) (param) (param i32)
(result) (result i32) (result) (result i64 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)
)
(type $$forward (func))
;; Typing of locals
(func (export "local-first-i32") (result i32) (local i32 i32) (local.get 0))
(func (export "local-first-i64") (result i64) (local i64 i64) (local.get 0))
(func (export "local-first-f32") (result f32) (local f32 f32) (local.get 0))
(func (export "local-first-f64") (result f64) (local f64 f64) (local.get 0))
(func (export "local-second-i32") (result i32) (local i32 i32) (local.get 1))
(func (export "local-second-i64") (result i64) (local i64 i64) (local.get 1))
(func (export "local-second-f32") (result f32) (local f32 f32) (local.get 1))
(func (export "local-second-f64") (result f64) (local f64 f64) (local.get 1))
(func (export "local-mixed") (result f64)
(local f32) (local $$x i32) (local i64 i32) (local) (local f64 i32)
(drop (f32.neg (local.get 0)))
(drop (i32.eqz (local.get 1)))
(drop (i64.eqz (local.get 2)))
(drop (i32.eqz (local.get 3)))
(drop (f64.neg (local.get 4)))
(drop (i32.eqz (local.get 5)))
(local.get 4)
)
;; Typing of parameters
(func (export "param-first-i32") (param i32 i32) (result i32) (local.get 0))
(func (export "param-first-i64") (param i64 i64) (result i64) (local.get 0))
(func (export "param-first-f32") (param f32 f32) (result f32) (local.get 0))
(func (export "param-first-f64") (param f64 f64) (result f64) (local.get 0))
(func (export "param-second-i32") (param i32 i32) (result i32) (local.get 1))
(func (export "param-second-i64") (param i64 i64) (result i64) (local.get 1))
(func (export "param-second-f32") (param f32 f32) (result f32) (local.get 1))
(func (export "param-second-f64") (param f64 f64) (result f64) (local.get 1))
(func (export "param-mixed") (param f32 i32) (param) (param $$x i64) (param i32 f64 i32)
(result f64)
(drop (f32.neg (local.get 0)))
(drop (i32.eqz (local.get 1)))
(drop (i64.eqz (local.get 2)))
(drop (i32.eqz (local.get 3)))
(drop (f64.neg (local.get 4)))
(drop (i32.eqz (local.get 5)))
(local.get 4)
)
;; Typing of results
(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-i32-f64") (result i32 f64) (i32.const 77) (f64.const 7))
(func (export "value-i32-i32-i32") (result i32 i32 i32)
(i32.const 1) (i32.const 2) (i32.const 3)
)
(func (export "value-block-void") (block (call $$dummy) (call $$dummy)))
(func (export "value-block-i32") (result i32)
(block (result i32) (call $$dummy) (i32.const 77))
)
(func (export "value-block-i32-i64") (result i32 i64)
(block (result i32 i64) (call $$dummy) (i32.const 1) (i64.const 2))
)
(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-i32-f64") (result i32 f64)
(return (i32.const 78) (f64.const 78.78))
)
(func (export "return-i32-i32-i32") (result i32 i32 i32)
(return (i32.const 1) (i32.const 2) (i32.const 3))
)
(func (export "return-block-i32") (result i32)
(return (block (result i32) (call $$dummy) (i32.const 77)))
)
(func (export "return-block-i32-i64") (result i32 i64)
(return (block (result i32 i64) (call $$dummy) (i32.const 1) (i64.const 2)))
)
(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-i32-f64") (result i32 f64)
(br 0 (i32.const 79) (f64.const 79.79))
)
(func (export "break-i32-i32-i32") (result i32 i32 i32)
(br 0 (i32.const 1) (i32.const 2) (i32.const 3))
)
(func (export "break-block-i32") (result i32)
(br 0 (block (result i32) (call $$dummy) (i32.const 77)))
)
(func (export "break-block-i32-i64") (result i32 i64)
(br 0 (block (result i32 i64) (call $$dummy) (i32.const 1) (i64.const 2)))
)
(func (export "break-br_if-empty") (param i32)
(br_if 0 (local.get 0))
)
(func (export "break-br_if-num") (param i32) (result i32)
(drop (br_if 0 (i32.const 50) (local.get 0))) (i32.const 51)
)
(func (export "break-br_if-num-num") (param i32) (result i32 i64)
(drop (drop (br_if 0 (i32.const 50) (i64.const 51) (local.get 0))))
(i32.const 51) (i64.const 52)
)
(func (export "break-br_table-empty") (param i32)
(br_table 0 0 0 (local.get 0))
)
(func (export "break-br_table-num") (param i32) (result i32)
(br_table 0 0 (i32.const 50) (local.get 0)) (i32.const 51)
)
(func (export "break-br_table-num-num") (param i32) (result f32 i64)
(br_table 0 0 (f32.const 50) (i64.const 51) (local.get 0))
(f32.const 51) (i64.const 52)
)
(func (export "break-br_table-nested-empty") (param i32)
(block (br_table 0 1 0 (local.get 0)))
)
(func (export "break-br_table-nested-num") (param i32) (result i32)
(i32.add
(block (result i32)
(br_table 0 1 0 (i32.const 50) (local.get 0)) (i32.const 51)
)
(i32.const 2)
)
)
(func (export "break-br_table-nested-num-num") (param i32) (result i32 i32)
(i32.add
(block (result i32 i32)
(br_table 0 1 0 (i32.const 50) (i32.const 51) (local.get 0))
(i32.const 51) (i32.const -3)
)
)
(i32.const 52)
)
;; Large signatures
(func (export "large-sig")
(param i32 i64 f32 f32 i32 f64 f32 i32 i32 i32 f32 f64 f64 f64 i32 i32 f32)
(result f64 f32 i32 i32 i32 i64 f32 i32 i32 f32 f64 f64 i32 f32 i32 f64)
(local.get 5)
(local.get 2)
(local.get 0)
(local.get 8)
(local.get 7)
(local.get 1)
(local.get 3)
(local.get 9)
(local.get 4)
(local.get 6)
(local.get 13)
(local.get 11)
(local.get 15)
(local.get 16)
(local.get 14)
(local.get 12)
)
;; Default initialization of locals
(func (export "init-local-i32") (result i32) (local i32) (local.get 0))
(func (export "init-local-i64") (result i64) (local i64) (local.get 0))
(func (export "init-local-f32") (result f32) (local f32) (local.get 0))
(func (export "init-local-f64") (result f64) (local f64) (local.get 0))
)`);
// ./test/core/func.wast:241
assert_return(() => invoke($0, `type-use-1`, []), []);
// ./test/core/func.wast:242
assert_return(() => invoke($0, `type-use-2`, []), [value("i32", 0)]);
// ./test/core/func.wast:243
assert_return(() => invoke($0, `type-use-3`, [1]), []);
// ./test/core/func.wast:244
assert_return(() => invoke($0, `type-use-4`, [1, value("f64", 1), 1]), [value("i32", 0)]);
// ./test/core/func.wast:248
assert_return(() => invoke($0, `type-use-5`, []), [value("i32", 0)]);
// ./test/core/func.wast:249
assert_return(() => invoke($0, `type-use-6`, [1]), []);
// ./test/core/func.wast:250
assert_return(() => invoke($0, `type-use-7`, [1, value("f64", 1), 1]), [value("i32", 0)]);
// ./test/core/func.wast:255
assert_return(() => invoke($0, `local-first-i32`, []), [value("i32", 0)]);
// ./test/core/func.wast:256
assert_return(() => invoke($0, `local-first-i64`, []), [value("i64", 0n)]);
// ./test/core/func.wast:257
assert_return(() => invoke($0, `local-first-f32`, []), [value("f32", 0)]);
// ./test/core/func.wast:258
assert_return(() => invoke($0, `local-first-f64`, []), [value("f64", 0)]);
// ./test/core/func.wast:259
assert_return(() => invoke($0, `local-second-i32`, []), [value("i32", 0)]);
// ./test/core/func.wast:260
assert_return(() => invoke($0, `local-second-i64`, []), [value("i64", 0n)]);
// ./test/core/func.wast:261
assert_return(() => invoke($0, `local-second-f32`, []), [value("f32", 0)]);
// ./test/core/func.wast:262
assert_return(() => invoke($0, `local-second-f64`, []), [value("f64", 0)]);
// ./test/core/func.wast:263
assert_return(() => invoke($0, `local-mixed`, []), [value("f64", 0)]);
// ./test/core/func.wast:265
assert_return(() => invoke($0, `param-first-i32`, [2, 3]), [value("i32", 2)]);
// ./test/core/func.wast:268
assert_return(() => invoke($0, `param-first-i64`, [2n, 3n]), [value("i64", 2n)]);
// ./test/core/func.wast:271
assert_return(
() => invoke($0, `param-first-f32`, [value("f32", 2), value("f32", 3)]),
[value("f32", 2)],
);
// ./test/core/func.wast:274
assert_return(
() => invoke($0, `param-first-f64`, [value("f64", 2), value("f64", 3)]),
[value("f64", 2)],
);
// ./test/core/func.wast:277
assert_return(() => invoke($0, `param-second-i32`, [2, 3]), [value("i32", 3)]);
// ./test/core/func.wast:280
assert_return(() => invoke($0, `param-second-i64`, [2n, 3n]), [value("i64", 3n)]);
// ./test/core/func.wast:283
assert_return(
() => invoke($0, `param-second-f32`, [value("f32", 2), value("f32", 3)]),
[value("f32", 3)],
);
// ./test/core/func.wast:286
assert_return(
() => invoke($0, `param-second-f64`, [value("f64", 2), value("f64", 3)]),
[value("f64", 3)],
);
// ./test/core/func.wast:290
assert_return(
() => invoke($0, `param-mixed`, [value("f32", 1), 2, 3n, 4, value("f64", 5.5), 6]),
[value("f64", 5.5)],
);
// ./test/core/func.wast:298
assert_return(() => invoke($0, `empty`, []), []);
// ./test/core/func.wast:299
assert_return(() => invoke($0, `value-void`, []), []);
// ./test/core/func.wast:300
assert_return(() => invoke($0, `value-i32`, []), [value("i32", 77)]);
// ./test/core/func.wast:301
assert_return(() => invoke($0, `value-i64`, []), [value("i64", 7777n)]);
// ./test/core/func.wast:302
assert_return(() => invoke($0, `value-f32`, []), [value("f32", 77.7)]);
// ./test/core/func.wast:303
assert_return(() => invoke($0, `value-f64`, []), [value("f64", 77.77)]);
// ./test/core/func.wast:304
assert_return(() => invoke($0, `value-i32-f64`, []), [value("i32", 77), value("f64", 7)]);
// ./test/core/func.wast:305
assert_return(
() => invoke($0, `value-i32-i32-i32`, []),
[value("i32", 1), value("i32", 2), value("i32", 3)],
);
// ./test/core/func.wast:308
assert_return(() => invoke($0, `value-block-void`, []), []);
// ./test/core/func.wast:309
assert_return(() => invoke($0, `value-block-i32`, []), [value("i32", 77)]);
// ./test/core/func.wast:310
assert_return(() => invoke($0, `value-block-i32-i64`, []), [value("i32", 1), value("i64", 2n)]);
// ./test/core/func.wast:312
assert_return(() => invoke($0, `return-empty`, []), []);
// ./test/core/func.wast:313
assert_return(() => invoke($0, `return-i32`, []), [value("i32", 78)]);
// ./test/core/func.wast:314
assert_return(() => invoke($0, `return-i64`, []), [value("i64", 7878n)]);
// ./test/core/func.wast:315
assert_return(() => invoke($0, `return-f32`, []), [value("f32", 78.7)]);
// ./test/core/func.wast:316
assert_return(() => invoke($0, `return-f64`, []), [value("f64", 78.78)]);
// ./test/core/func.wast:317
assert_return(() => invoke($0, `return-i32-f64`, []), [value("i32", 78), value("f64", 78.78)]);
// ./test/core/func.wast:318
assert_return(
() => invoke($0, `return-i32-i32-i32`, []),
[value("i32", 1), value("i32", 2), value("i32", 3)],
);
// ./test/core/func.wast:321
assert_return(() => invoke($0, `return-block-i32`, []), [value("i32", 77)]);
// ./test/core/func.wast:322
assert_return(() => invoke($0, `return-block-i32-i64`, []), [value("i32", 1), value("i64", 2n)]);
// ./test/core/func.wast:324
assert_return(() => invoke($0, `break-empty`, []), []);
// ./test/core/func.wast:325
assert_return(() => invoke($0, `break-i32`, []), [value("i32", 79)]);
// ./test/core/func.wast:326
assert_return(() => invoke($0, `break-i64`, []), [value("i64", 7979n)]);
// ./test/core/func.wast:327
assert_return(() => invoke($0, `break-f32`, []), [value("f32", 79.9)]);
// ./test/core/func.wast:328
assert_return(() => invoke($0, `break-f64`, []), [value("f64", 79.79)]);
// ./test/core/func.wast:329
assert_return(() => invoke($0, `break-i32-f64`, []), [value("i32", 79), value("f64", 79.79)]);
// ./test/core/func.wast:330
assert_return(
() => invoke($0, `break-i32-i32-i32`, []),
[value("i32", 1), value("i32", 2), value("i32", 3)],
);
// ./test/core/func.wast:333
assert_return(() => invoke($0, `break-block-i32`, []), [value("i32", 77)]);
// ./test/core/func.wast:334
assert_return(() => invoke($0, `break-block-i32-i64`, []), [value("i32", 1), value("i64", 2n)]);
// ./test/core/func.wast:336
assert_return(() => invoke($0, `break-br_if-empty`, [0]), []);
// ./test/core/func.wast:337
assert_return(() => invoke($0, `break-br_if-empty`, [2]), []);
// ./test/core/func.wast:338
assert_return(() => invoke($0, `break-br_if-num`, [0]), [value("i32", 51)]);
// ./test/core/func.wast:339
assert_return(() => invoke($0, `break-br_if-num`, [1]), [value("i32", 50)]);
// ./test/core/func.wast:340
assert_return(() => invoke($0, `break-br_if-num-num`, [0]), [value("i32", 51), value("i64", 52n)]);
// ./test/core/func.wast:343
assert_return(() => invoke($0, `break-br_if-num-num`, [1]), [value("i32", 50), value("i64", 51n)]);
// ./test/core/func.wast:347
assert_return(() => invoke($0, `break-br_table-empty`, [0]), []);
// ./test/core/func.wast:348
assert_return(() => invoke($0, `break-br_table-empty`, [1]), []);
// ./test/core/func.wast:349
assert_return(() => invoke($0, `break-br_table-empty`, [5]), []);
// ./test/core/func.wast:350
assert_return(() => invoke($0, `break-br_table-empty`, [-1]), []);
// ./test/core/func.wast:351
assert_return(() => invoke($0, `break-br_table-num`, [0]), [value("i32", 50)]);
// ./test/core/func.wast:352
assert_return(() => invoke($0, `break-br_table-num`, [1]), [value("i32", 50)]);
// ./test/core/func.wast:353
assert_return(() => invoke($0, `break-br_table-num`, [10]), [value("i32", 50)]);
// ./test/core/func.wast:354
assert_return(() => invoke($0, `break-br_table-num`, [-100]), [value("i32", 50)]);
// ./test/core/func.wast:355
assert_return(() => invoke($0, `break-br_table-num-num`, [0]), [value("f32", 50), value("i64", 51n)]);
// ./test/core/func.wast:358
assert_return(() => invoke($0, `break-br_table-num-num`, [1]), [value("f32", 50), value("i64", 51n)]);
// ./test/core/func.wast:361
assert_return(() => invoke($0, `break-br_table-num-num`, [10]), [value("f32", 50), value("i64", 51n)]);
// ./test/core/func.wast:364
assert_return(() => invoke($0, `break-br_table-num-num`, [-100]), [value("f32", 50), value("i64", 51n)]);
// ./test/core/func.wast:367
assert_return(() => invoke($0, `break-br_table-nested-empty`, [0]), []);
// ./test/core/func.wast:368
assert_return(() => invoke($0, `break-br_table-nested-empty`, [1]), []);
// ./test/core/func.wast:369
assert_return(() => invoke($0, `break-br_table-nested-empty`, [3]), []);
// ./test/core/func.wast:370
assert_return(() => invoke($0, `break-br_table-nested-empty`, [-2]), []);
// ./test/core/func.wast:371
assert_return(() => invoke($0, `break-br_table-nested-num`, [0]), [value("i32", 52)]);
// ./test/core/func.wast:374
assert_return(() => invoke($0, `break-br_table-nested-num`, [1]), [value("i32", 50)]);
// ./test/core/func.wast:377
assert_return(() => invoke($0, `break-br_table-nested-num`, [2]), [value("i32", 52)]);
// ./test/core/func.wast:380
assert_return(() => invoke($0, `break-br_table-nested-num`, [-3]), [value("i32", 52)]);
// ./test/core/func.wast:383
assert_return(
() => invoke($0, `break-br_table-nested-num-num`, [0]),
[value("i32", 101), value("i32", 52)],
);
// ./test/core/func.wast:387
assert_return(
() => invoke($0, `break-br_table-nested-num-num`, [1]),
[value("i32", 50), value("i32", 51)],
);
// ./test/core/func.wast:391
assert_return(
() => invoke($0, `break-br_table-nested-num-num`, [2]),
[value("i32", 101), value("i32", 52)],
);
// ./test/core/func.wast:395
assert_return(
() => invoke($0, `break-br_table-nested-num-num`, [-3]),
[value("i32", 101), value("i32", 52)],
);
// ./test/core/func.wast:400
assert_return(
() => invoke($0, `large-sig`, [
0,
1n,
value("f32", 2),
value("f32", 3),
4,
value("f64", 5),
value("f32", 6),
7,
8,
9,
value("f32", 10),
value("f64", 11),
value("f64", 12),
value("f64", 13),
14,
15,
value("f32", 16),
]),
[
value("f64", 5),
value("f32", 2),
value("i32", 0),
value("i32", 8),
value("i32", 7),
value("i64", 1n),
value("f32", 3),
value("i32", 9),
value("i32", 4),
value("f32", 6),
value("f64", 13),
value("f64", 11),
value("i32", 15),
value("f32", 16),
value("i32", 14),
value("f64", 12),
],
);
// ./test/core/func.wast:414
assert_return(() => invoke($0, `init-local-i32`, []), [value("i32", 0)]);
// ./test/core/func.wast:415
assert_return(() => invoke($0, `init-local-i64`, []), [value("i64", 0n)]);
// ./test/core/func.wast:416
assert_return(() => invoke($0, `init-local-f32`, []), [value("f32", 0)]);
// ./test/core/func.wast:417
assert_return(() => invoke($0, `init-local-f64`, []), [value("f64", 0)]);
// ./test/core/func.wast:422
let $1 = instantiate(`(module
(func $$f (result f64) (f64.const 0)) ;; adds implicit type definition
(func $$g (param i32)) ;; reuses explicit type definition
(type $$t (func (param i32)))
(func $$i32->void (type 0)) ;; (param i32)
(func $$void->f64 (type 1) (f64.const 0)) ;; (result f64)
(func $$check
(call $$i32->void (i32.const 0))
(drop (call $$void->f64))
)
)`);
// ./test/core/func.wast:435
assert_invalid(
() => instantiate(`(module
(func $$f (result f64) (f64.const 0)) ;; adds implicit type definition
(func $$g (param i32)) ;; reuses explicit type definition
(func $$h (result f64) (f64.const 1)) ;; reuses implicit type definition
(type $$t (func (param i32)))
(func (type 2)) ;; does not exist
)`),
`unknown type`,
);
// ./test/core/func.wast:447
assert_malformed(
() => instantiate(`(func $$f (result f64) (f64.const 0)) (func $$g (param i32)) (func $$h (result f64) (f64.const 1)) (type $$t (func (param i32))) (func (type 2) (param i32)) `),
`unknown type`,
);
// ./test/core/func.wast:459
let $2 = instantiate(`(module
(type $$proc (func (result i32)))
(type $$sig (func (param i32) (result i32)))
(func (export "f") (type $$sig)
(local $$var i32)
(local.get $$var)
)
(func $$g (type $$sig)
(local $$var i32)
(local.get $$var)
)
(func (export "g") (type $$sig)
(call $$g (local.get 0))
)
(func (export "p") (type $$proc)
(local $$var i32)
(local.set 0 (i32.const 42))
(local.get $$var)
)
)`);
// ./test/core/func.wast:483
assert_return(() => invoke($2, `f`, [42]), [value("i32", 0)]);
// ./test/core/func.wast:484
assert_return(() => invoke($2, `g`, [42]), [value("i32", 0)]);
// ./test/core/func.wast:485
assert_return(() => invoke($2, `p`, []), [value("i32", 42)]);
// ./test/core/func.wast:488
let $3 = instantiate(`(module
(type $$sig (func))
(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))
(func $$complex-sig-4 (param i64 i64 f64 i64 f64 i64 f32 i32))
(func $$complex-sig-5 (param i64 i64 f64 i64 f64 i64 f32 i32))
(type $$empty-sig-duplicate (func))
(type $$complex-sig-duplicate (func (param i64 i64 f64 i64 f64 i64 f32 i32)))
(table funcref
(elem
$$complex-sig-3 $$empty-sig-2 $$complex-sig-1 $$complex-sig-3 $$empty-sig-1
$$complex-sig-4 $$complex-sig-5
)
)
(func (export "signature-explicit-reused")
(call_indirect (type $$sig) (i32.const 1))
(call_indirect (type $$sig) (i32.const 4))
)
(func (export "signature-implicit-reused")
;; The implicit index 3 in this test depends on the function and
;; type definitions, and may need adapting if they change.
(call_indirect (type 3)
(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 (type 3)
(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 (type 3)
(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 (type $$empty-sig-duplicate) (i32.const 1))
)
(func (export "signature-implicit-duplicate")
(call_indirect (type $$complex-sig-duplicate)
(i64.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 5)
)
(call_indirect (type $$complex-sig-duplicate)
(i64.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 6)
)
)
)`);
// ./test/core/func.wast:551
assert_return(() => invoke($3, `signature-explicit-reused`, []), []);
// ./test/core/func.wast:552
assert_return(() => invoke($3, `signature-implicit-reused`, []), []);
// ./test/core/func.wast:553
assert_return(() => invoke($3, `signature-explicit-duplicate`, []), []);
// ./test/core/func.wast:554
assert_return(() => invoke($3, `signature-implicit-duplicate`, []), []);
// ./test/core/func.wast:559
assert_malformed(
() => instantiate(`(type $$sig (func (param i32) (result i32))) (func (type $$sig) (result i32) (param i32) (i32.const 0)) `),
`unexpected token`,
);
// ./test/core/func.wast:566
assert_malformed(
() => instantiate(`(type $$sig (func (param i32) (result i32))) (func (param i32) (type $$sig) (result i32) (i32.const 0)) `),
`unexpected token`,
);
// ./test/core/func.wast:573
assert_malformed(
() => instantiate(`(type $$sig (func (param i32) (result i32))) (func (param i32) (result i32) (type $$sig) (i32.const 0)) `),
`unexpected token`,
);
// ./test/core/func.wast:580
assert_malformed(
() => instantiate(`(type $$sig (func (param i32) (result i32))) (func (result i32) (type $$sig) (param i32) (i32.const 0)) `),
`unexpected token`,
);
// ./test/core/func.wast:587
assert_malformed(
() => instantiate(`(type $$sig (func (param i32) (result i32))) (func (result i32) (param i32) (type $$sig) (i32.const 0)) `),
`unexpected token`,
);
// ./test/core/func.wast:594
assert_malformed(
() => instantiate(`(func (result i32) (param i32) (i32.const 0)) `),
`unexpected token`,
);
// ./test/core/func.wast:601
assert_malformed(
() => instantiate(`(type $$sig (func)) (func (type $$sig) (result i32) (i32.const 0)) `),
`inline function type`,
);
// ./test/core/func.wast:608
assert_malformed(
() => instantiate(`(type $$sig (func (param i32) (result i32))) (func (type $$sig) (result i32) (i32.const 0)) `),
`inline function type`,
);
// ./test/core/func.wast:615
assert_malformed(
() => instantiate(`(type $$sig (func (param i32) (result i32))) (func (type $$sig) (param i32) (i32.const 0)) `),
`inline function type`,
);
// ./test/core/func.wast:622
assert_malformed(
() => instantiate(`(type $$sig (func (param i32 i32) (result i32))) (func (type $$sig) (param i32) (result i32) (unreachable)) `),
`inline function type`,
);
// ./test/core/func.wast:630
assert_invalid(() => instantiate(`(module (func $$g (type 4)))`), `unknown type`);
// ./test/core/func.wast:634
assert_invalid(
() => instantiate(`(module
(func $$f (drop (ref.func $$g)))
(func $$g (type 4))
(elem declare func $$g)
)`),
`unknown type`,
);
// ./test/core/func.wast:646
assert_invalid(
() => instantiate(`(module (func $$type-local-num-vs-num (result i64) (local i32) (local.get 0)))`),
`type mismatch`,
);
// ./test/core/func.wast:650
assert_invalid(
() => instantiate(`(module (func $$type-local-num-vs-num (local f32) (i32.eqz (local.get 0))))`),
`type mismatch`,
);
// ./test/core/func.wast:654
assert_invalid(
() => instantiate(`(module (func $$type-local-num-vs-num (local f64 i64) (f64.neg (local.get 1))))`),
`type mismatch`,
);
// ./test/core/func.wast:659
assert_invalid(
() => instantiate(`(module
(type $$t (func))
(func $$type-local-uninitialized (local $$x (ref $$t)) (drop (local.get $$x)))
)`),
`uninitialized local`,
);
// ./test/core/func.wast:670
assert_invalid(
() => instantiate(`(module (func $$type-param-num-vs-num (param i32) (result i64) (local.get 0)))`),
`type mismatch`,
);
// ./test/core/func.wast:674
assert_invalid(
() => instantiate(`(module (func $$type-param-num-vs-num (param f32) (i32.eqz (local.get 0))))`),
`type mismatch`,
);
// ./test/core/func.wast:678
assert_invalid(
() => instantiate(`(module (func $$type-param-num-vs-num (param f64 i64) (f64.neg (local.get 1))))`),
`type mismatch`,
);
// ./test/core/func.wast:686
assert_invalid(
() => instantiate(`(module (func $$type-empty-i32 (result i32)))`),
`type mismatch`,
);
// ./test/core/func.wast:690
assert_invalid(
() => instantiate(`(module (func $$type-empty-i64 (result i64)))`),
`type mismatch`,
);
// ./test/core/func.wast:694
assert_invalid(
() => instantiate(`(module (func $$type-empty-f32 (result f32)))`),
`type mismatch`,
);
// ./test/core/func.wast:698
assert_invalid(
() => instantiate(`(module (func $$type-empty-f64 (result f64)))`),
`type mismatch`,
);
// ./test/core/func.wast:702
assert_invalid(
() => instantiate(`(module (func $$type-empty-f64-i32 (result f64 i32)))`),
`type mismatch`,
);
// ./test/core/func.wast:707
assert_invalid(
() => instantiate(`(module (func $$type-value-void-vs-num (result i32)
(nop)
))`),
`type mismatch`,
);
// ./test/core/func.wast:713
assert_invalid(
() => instantiate(`(module (func $$type-value-void-vs-nums (result i32 i32)
(nop)
))`),
`type mismatch`,
);
// ./test/core/func.wast:719
assert_invalid(
() => instantiate(`(module (func $$type-value-num-vs-void
(i32.const 0)
))`),
`type mismatch`,
);
// ./test/core/func.wast:725
assert_invalid(
() => instantiate(`(module (func $$type-value-nums-vs-void
(i32.const 0) (i64.const 0)
))`),
`type mismatch`,
);
// ./test/core/func.wast:731
assert_invalid(
() => instantiate(`(module (func $$type-value-num-vs-num (result i32)
(f32.const 0)
))`),
`type mismatch`,
);
// ./test/core/func.wast:737
assert_invalid(
() => instantiate(`(module (func $$type-value-num-vs-nums (result f32 f32)
(f32.const 0)
))`),
`type mismatch`,
);
// ./test/core/func.wast:743
assert_invalid(
() => instantiate(`(module (func $$type-value-nums-vs-num (result f32)
(f32.const 0) (f32.const 0)
))`),
`type mismatch`,
);
// ./test/core/func.wast:750
assert_invalid(
() => instantiate(`(module (func $$type-return-last-empty-vs-num (result i32)
(return)
))`),
`type mismatch`,
);
// ./test/core/func.wast:756
assert_invalid(
() => instantiate(`(module (func $$type-return-last-empty-vs-nums (result i32 i32)
(return)
))`),
`type mismatch`,
);
// ./test/core/func.wast:762
assert_invalid(
() => instantiate(`(module (func $$type-return-last-void-vs-num (result i32)
(return (nop))
))`),
`type mismatch`,
);
// ./test/core/func.wast:768
assert_invalid(
() => instantiate(`(module (func $$type-return-last-void-vs-nums (result i32 i64)
(return (nop))
))`),
`type mismatch`,
);
// ./test/core/func.wast:774
assert_invalid(
() => instantiate(`(module (func $$type-return-last-num-vs-num (result i32)
(return (i64.const 0))
))`),
`type mismatch`,
);
// ./test/core/func.wast:780
assert_invalid(
() => instantiate(`(module (func $$type-return-last-num-vs-nums (result i64 i64)
(return (i64.const 0))
))`),
`type mismatch`,
);
// ./test/core/func.wast:787
assert_invalid(
() => instantiate(`(module (func $$type-return-empty-vs-num (result i32)
(return) (i32.const 1)
))`),
`type mismatch`,
);
// ./test/core/func.wast:793
assert_invalid(
() => instantiate(`(module (func $$type-return-empty-vs-nums (result i32 i32)
(return) (i32.const 1) (i32.const 2)
))`),
`type mismatch`,
);
// ./test/core/func.wast:799
assert_invalid(
() => instantiate(`(module (func $$type-return-partial-vs-nums (result i32 i32)
(i32.const 1) (return) (i32.const 2)
))`),
`type mismatch`,
);
// ./test/core/func.wast:805
assert_invalid(
() => instantiate(`(module (func $$type-return-void-vs-num (result i32)
(return (nop)) (i32.const 1)
))`),
`type mismatch`,
);
// ./test/core/func.wast:811
assert_invalid(
() => instantiate(`(module (func $$type-return-void-vs-nums (result i32 i32)
(return (nop)) (i32.const 1)
))`),
`type mismatch`,
);
// ./test/core/func.wast:817
assert_invalid(
() => instantiate(`(module (func $$type-return-num-vs-num (result i32)
(return (i64.const 1)) (i32.const 1)
))`),
`type mismatch`,
);
// ./test/core/func.wast:823
assert_invalid(
() => instantiate(`(module (func $$type-return-num-vs-nums (result i32 i32)
(return (i64.const 1)) (i32.const 1) (i32.const 2)
))`),
`type mismatch`,
);
// ./test/core/func.wast:829
assert_invalid(
() => instantiate(`(module (func $$type-return-first-num-vs-num (result i32)
(return (i64.const 1)) (return (i32.const 1))
))`),
`type mismatch`,
);
// ./test/core/func.wast:835
assert_invalid(
() => instantiate(`(module (func $$type-return-first-num-vs-nums (result i32 i32)
(return (i32.const 1)) (return (i32.const 1) (i32.const 2))
))`),
`type mismatch`,
);
// ./test/core/func.wast:842
assert_invalid(
() => instantiate(`(module (func $$type-break-last-void-vs-num (result i32)
(br 0)
))`),
`type mismatch`,
);
// ./test/core/func.wast:848
assert_invalid(
() => instantiate(`(module (func $$type-break-last-void-vs-nums (result i32 i32)
(br 0)
))`),
`type mismatch`,
);
// ./test/core/func.wast:854
assert_invalid(
() => instantiate(`(module (func $$type-break-last-num-vs-num (result i32)
(br 0 (f32.const 0))
))`),
`type mismatch`,
);
// ./test/core/func.wast:860
assert_invalid(
() => instantiate(`(module (func $$type-break-last-num-vs-nums (result i32 i32)
(br 0 (i32.const 0))
))`),
`type mismatch`,
);
// ./test/core/func.wast:866
assert_invalid(
() => instantiate(`(module (func $$type-break-void-vs-num (result i32)
(br 0) (i32.const 1)
))`),
`type mismatch`,
);
// ./test/core/func.wast:872
assert_invalid(
() => instantiate(`(module (func $$type-break-void-vs-nums (result i32 i32)
(br 0) (i32.const 1) (i32.const 2)
))`),
`type mismatch`,
);
// ./test/core/func.wast:878
assert_invalid(
() => instantiate(`(module (func $$type-break-num-vs-num (result i32)
(br 0 (i64.const 1)) (i32.const 1)
))`),
`type mismatch`,
);
// ./test/core/func.wast:884
assert_invalid(
() => instantiate(`(module (func $$type-break-num-vs-nums (result i32 i32)
(br 0 (i32.const 1)) (i32.const 1) (i32.const 2)
))`),
`type mismatch`,
);
// ./test/core/func.wast:890
assert_invalid(
() => instantiate(`(module (func $$type-break-first-num-vs-num (result i32)
(br 0 (i64.const 1)) (br 0 (i32.const 1))
))`),
`type mismatch`,
);
// ./test/core/func.wast:897
assert_invalid(
() => instantiate(`(module (func $$type-break-nested-empty-vs-num (result i32)
(block (br 1)) (br 0 (i32.const 1))
))`),
`type mismatch`,
);
// ./test/core/func.wast:903
assert_invalid(
() => instantiate(`(module (func $$type-break-nested-empty-vs-nums (result i32 i32)
(block (br 1)) (br 0 (i32.const 1) (i32.const 2))
))`),
`type mismatch`,
);
// ./test/core/func.wast:909
assert_invalid(
() => instantiate(`(module (func $$type-break-nested-void-vs-num (result i32)
(block (br 1 (nop))) (br 0 (i32.const 1))
))`),
`type mismatch`,
);
// ./test/core/func.wast:915
assert_invalid(
() => instantiate(`(module (func $$type-break-nested-void-vs-nums (result i32 i32)
(block (br 1 (nop))) (br 0 (i32.const 1) (i32.const 2))
))`),
`type mismatch`,
);
// ./test/core/func.wast:921
assert_invalid(
() => instantiate(`(module (func $$type-break-nested-num-vs-num (result i32)
(block (br 1 (i64.const 1))) (br 0 (i32.const 1))
))`),
`type mismatch`,
);
// ./test/core/func.wast:927
assert_invalid(
() => instantiate(`(module (func $$type-break-nested-num-vs-nums (result i32 i32)
(block (result i32) (br 1 (i32.const 1))) (br 0 (i32.const 1) (i32.const 2))
))`),
`type mismatch`,
);
// ./test/core/func.wast:937
assert_malformed(() => instantiate(`(func (nop) (local i32)) `), `unexpected token`);
// ./test/core/func.wast:941
assert_malformed(() => instantiate(`(func (nop) (param i32)) `), `unexpected token`);
// ./test/core/func.wast:945
assert_malformed(() => instantiate(`(func (nop) (result i32)) `), `unexpected token`);
// ./test/core/func.wast:949
assert_malformed(() => instantiate(`(func (local i32) (param i32)) `), `unexpected token`);
// ./test/core/func.wast:953
assert_malformed(
() => instantiate(`(func (local i32) (result i32) (local.get 0)) `),
`unexpected token`,
);
// ./test/core/func.wast:957
assert_malformed(
() => instantiate(`(func (result i32) (param i32) (local.get 0)) `),
`unexpected token`,
);
// ./test/core/func.wast:964
assert_malformed(() => instantiate(`(func $$foo) (func $$foo) `), `duplicate func`);
// ./test/core/func.wast:968
assert_malformed(
() => instantiate(`(import "" "" (func $$foo)) (func $$foo) `),
`duplicate func`,
);
// ./test/core/func.wast:972
assert_malformed(
() => instantiate(`(import "" "" (func $$foo)) (import "" "" (func $$foo)) `),
`duplicate func`,
);
// ./test/core/func.wast:977
assert_malformed(
() => instantiate(`(func (param $$foo i32) (param $$foo i32)) `),
`duplicate local`,
);
// ./test/core/func.wast:981
assert_malformed(
() => instantiate(`(func (param $$foo i32) (local $$foo i32)) `),
`duplicate local`,
);
// ./test/core/func.wast:985
assert_malformed(
() => instantiate(`(func (local $$foo i32) (local $$foo i32)) `),
`duplicate local`,
);
|