diff options
author | Ben Smith <binji@chromium.org> | 2016-04-12 12:42:09 -0700 |
---|---|---|
committer | Ben Smith <binji@chromium.org> | 2016-04-12 14:59:44 -0700 |
commit | fb0f7da9c1ba977aa68f5e01346306ae13b8f59a (patch) | |
tree | f1ff7855186033fcb491dd2120f326a9db834397 /src | |
parent | 04140042f96a68f3610b4a24fdf456b5fac9792e (diff) | |
download | wabt-fb0f7da9c1ba977aa68f5e01346306ae13b8f59a.tar.gz wabt-fb0f7da9c1ba977aa68f5e01346306ae13b8f59a.tar.bz2 wabt-fb0f7da9c1ba977aa68f5e01346306ae13b8f59a.zip |
share WasmFuncDeclaration with Func and Import
There was some duplicated code between WasmFunc and WasmImport; both
allow you to specify a function signature or a function type. This
change introduces a WasmFuncDeclaration which is shared by both.
This also allows us to remove WasmTypeBindings.
Diffstat (limited to 'src')
-rw-r--r-- | src/prebuilt/wasm-bison-parser.c | 2130 | ||||
-rw-r--r-- | src/wasm-ast-checker.c | 138 | ||||
-rw-r--r-- | src/wasm-ast-writer.c | 37 | ||||
-rw-r--r-- | src/wasm-ast.c | 66 | ||||
-rw-r--r-- | src/wasm-ast.h | 132 | ||||
-rw-r--r-- | src/wasm-binary-reader-ast.c | 40 | ||||
-rw-r--r-- | src/wasm-binary-writer-spec.c | 8 | ||||
-rw-r--r-- | src/wasm-binary-writer.c | 64 | ||||
-rw-r--r-- | src/wasm-bison-parser.y | 105 | ||||
-rw-r--r-- | src/wasm-parser-lexer-shared.h | 1 |
10 files changed, 981 insertions, 1740 deletions
diff --git a/src/prebuilt/wasm-bison-parser.c b/src/prebuilt/wasm-bison-parser.c index 48c614c1..30371fa1 100644 --- a/src/prebuilt/wasm-bison-parser.c +++ b/src/prebuilt/wasm-bison-parser.c @@ -120,6 +120,10 @@ #define USE_NATURAL_ALIGNMENT (~0) +static WasmFuncField* new_func_field(WasmAllocator* allocator) { + return wasm_alloc_zero(allocator, sizeof(WasmFuncField), WASM_DEFAULT_ALIGN); +} + static WasmFunc* new_func(WasmAllocator* allocator) { return wasm_alloc_zero(allocator, sizeof(WasmFunc), WASM_DEFAULT_ALIGN); } @@ -147,10 +151,14 @@ static WasmExpr* new_block_expr_with_list(WasmAllocator* allocator, WasmLabel* label, WasmExprPtrVector* exprs); +WasmResult copy_signature_from_func_type(WasmAllocator* allocator, + WasmModule* module, + WasmFuncDeclaration* decl); + #define wasm_parser_lex wasm_lexer_lex -#line 154 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:339 */ +#line 162 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:339 */ # ifndef YY_NULLPTR # if defined __cplusplus && 201103L <= __cplusplus @@ -280,7 +288,7 @@ int wasm_parser_parse (WasmLexer lexer, WasmParser* parser); /* Copy the second part of user declarations. */ -#line 284 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:358 */ +#line 292 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:358 */ #ifdef short # undef short @@ -524,16 +532,16 @@ union yyalloc /* YYFINAL -- State number of the termination state. */ #define YYFINAL 7 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 617 +#define YYLAST 321 /* YYNTOKENS -- Number of terminals. */ #define YYNTOKENS 57 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 44 +#define YYNNTS 42 /* YYNRULES -- Number of rules. */ -#define YYNRULES 177 +#define YYNRULES 114 /* YYNSTATES -- Number of states. */ -#define YYNSTATES 326 +#define YYNSTATES 264 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned by yylex, with out-of-bounds checking. */ @@ -585,24 +593,18 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 184, 184, 185, 191, 192, 196, 200, 207, 212, - 220, 232, 240, 241, 247, 251, 261, 268, 269, 273, - 274, 283, 284, 295, 298, 302, 306, 314, 323, 334, - 347, 353, 360, 367, 374, 382, 388, 393, 400, 406, - 412, 419, 424, 430, 438, 447, 460, 466, 473, 480, - 487, 493, 497, 501, 508, 509, 512, 516, 522, 523, - 529, 534, 543, 548, 559, 562, 567, 576, 581, 592, - 595, 599, 604, 610, 617, 625, 634, 644, 653, 661, - 670, 678, 685, 693, 702, 710, 717, 725, 732, 738, - 745, 751, 758, 766, 775, 783, 790, 798, 805, 811, - 818, 826, 833, 839, 844, 850, 857, 865, 874, 882, - 889, 897, 904, 910, 917, 925, 932, 938, 945, 951, - 956, 962, 969, 977, 984, 990, 997, 1003, 1008, 1014, - 1021, 1027, 1032, 1038, 1045, 1051, 1055, 1068, 1076, 1077, - 1084, 1096, 1108, 1114, 1123, 1127, 1134, 1138, 1145, 1153, - 1160, 1171, 1178, 1184, 1187, 1196, 1205, 1213, 1221, 1229, - 1237, 1245, 1255, 1362, 1368, 1375, 1382, 1390, 1397, 1407, - 1408, 1416, 1428, 1429, 1432, 1433, 1440, 1449 + 0, 191, 191, 192, 198, 199, 203, 207, 214, 219, + 227, 239, 247, 248, 254, 258, 268, 275, 276, 280, + 281, 290, 291, 302, 305, 309, 313, 321, 330, 341, + 354, 360, 367, 374, 381, 389, 395, 400, 407, 413, + 419, 426, 431, 437, 445, 454, 467, 473, 480, 487, + 494, 500, 504, 508, 515, 516, 519, 523, 529, 530, + 535, 542, 548, 556, 562, 568, 578, 581, 645, 651, + 658, 663, 674, 678, 691, 699, 700, 707, 719, 731, + 737, 746, 750, 757, 761, 768, 776, 783, 794, 801, + 807, 810, 819, 828, 836, 844, 852, 860, 868, 878, + 974, 980, 987, 994, 1002, 1009, 1019, 1020, 1028, 1040, + 1041, 1044, 1045, 1052, 1061 }; #endif @@ -622,12 +624,12 @@ static const char *const yytname[] = "ASSERT_RETURN_NAN", "ASSERT_TRAP", "INVOKE", "LOW", "$accept", "value_type_list", "func_type", "literal", "var", "var_list", "bind_var", "quoted_text", "string_contents", "labeling", "offset", "align", "expr", - "expr1", "expr_opt", "non_empty_expr_list", "expr_list", "param_list", - "result", "local_list", "type_use", "func_info", "func", "start", - "segment_address", "segment", "segment_list", "initial_pages", - "max_pages", "memory", "type_def", "table", "import", "export", - "export_memory", "module_fields", "module", "cmd", "cmd_list", "const", - "const_opt", "const_list", "script", "script_start", YY_NULLPTR + "expr1", "expr_opt", "non_empty_expr_list", "expr_list", "func_fields", + "type_use", "func_info", "func", "start", "segment_address", "segment", + "segment_list", "initial_pages", "max_pages", "memory", "type_def", + "table", "import", "export", "export_memory", "module_fields", "module", + "cmd", "cmd_list", "const", "const_opt", "const_list", "script", + "script_start", YY_NULLPTR }; #endif @@ -645,10 +647,10 @@ static const yytype_uint16 yytoknum[] = }; # endif -#define YYPACT_NINF -140 +#define YYPACT_NINF -130 #define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-140))) + (!!((Yystate) == (-130))) #define YYTABLE_NINF -1 @@ -659,39 +661,33 @@ static const yytype_uint16 yytoknum[] = STATE-NUM. */ static const yytype_int16 yypact[] = { - -140, 1, -140, 20, -9, -140, -140, -140, -140, 25, - 29, 31, 33, 42, 97, 17, 42, 8, 11, 23, - -140, -140, 201, -140, -140, -140, -140, -140, -140, -140, - -140, -140, 68, 42, 42, 42, 121, 0, 48, 27, - 69, 123, 42, -140, -140, -140, -140, -140, 50, -140, - -140, 348, -140, 90, -140, 94, 100, 103, 115, 119, - 104, -140, -140, 116, 91, 129, -140, 130, 42, 42, - 21, 105, 142, 150, 152, 162, -140, 141, 94, 141, - 19, 48, -140, 48, 48, 48, 94, 48, 48, 132, - 132, 162, 94, 94, 94, 94, 94, 48, 141, 134, - 141, -140, -140, 94, 158, 94, 100, 103, 115, 119, - 567, -140, 403, 94, 103, 115, 300, 94, 115, 485, - 94, 444, 94, 100, 103, 115, -140, -140, 161, 140, - -140, 169, -140, 42, 179, 183, 186, -140, -140, 192, - 195, 42, -140, -140, 196, -140, 94, 199, 141, 94, - 94, -140, -140, 94, 48, 94, 94, 94, -140, -140, - 94, -140, 174, 174, -140, -140, 94, 94, -140, 94, - 204, 43, 200, 208, 51, 209, -140, -140, 94, 103, - 115, 94, 115, 94, 94, 100, 103, 115, 141, 94, - 115, 94, 94, 141, 94, 103, 115, 94, 115, 94, - 135, 213, 161, 175, -140, -140, 176, 179, -26, 216, - 217, -140, -140, -140, 218, -140, 219, -140, 94, -140, - 526, 94, 94, -140, -140, 94, 94, -140, -140, 94, - -140, -140, 94, 94, -140, -140, 94, -140, -140, -140, - 220, -140, -140, 221, 94, 115, 94, 94, 94, 103, - 115, 94, 115, 94, 78, 227, 94, 80, 232, 94, - 115, 94, 94, -140, 233, 222, 225, 240, -140, 226, - 245, -140, -140, -140, -140, 141, -140, -140, -140, -140, - -140, -140, 94, -140, -140, -140, 94, 94, 115, 94, - 94, -140, 248, -140, 249, 94, 87, 250, -140, 251, - -140, 198, -140, -140, 94, -140, 94, -140, -140, 253, - -140, -140, -140, 255, 256, 228, -140, 254, 252, 262, - 258, 141, -140, 94, 263, -140 + -130, 4, -130, 9, 42, -130, -130, -130, -130, 12, + 31, 73, 80, 39, 28, 49, 39, 33, 45, 50, + -130, -130, 270, -130, -130, -130, -130, -130, -130, -130, + -130, -130, 104, 39, 39, 39, 115, 5, 46, 20, + 108, 116, 39, -130, -130, -130, -130, -130, 86, -130, + -130, 139, -130, 119, -130, 124, -130, -130, 128, 132, + -130, -130, 154, 146, 164, -130, 163, 39, 39, 13, + 82, 122, 126, 131, 134, -130, 167, 124, 167, 21, + 46, -130, 46, 46, 46, 124, 46, 46, 155, 155, + 134, 124, 124, 124, 124, 124, 46, 167, 175, 167, + -130, -130, 124, 181, 128, 182, 262, -130, 180, 189, + -130, -130, 191, 172, -130, 138, -130, 39, 196, 205, + 212, -130, -130, 214, 218, 39, -130, -130, 219, -130, + 124, 215, 167, 124, 124, -130, -130, 124, 46, 124, + 124, 124, -130, -130, 124, -130, 195, 195, -130, -130, + 124, 124, -130, 124, 222, 26, 216, 223, 43, 226, + -130, -130, 236, -130, -130, 107, 245, 191, 206, -130, + -130, 149, 196, 64, 253, 254, -130, -130, -130, 255, + -130, 256, -130, -130, 221, 124, 124, -130, -130, 124, + 124, -130, -130, 124, -130, -130, 124, 124, -130, -130, + 124, -130, 128, -130, 257, 128, 128, 258, -130, -130, + 259, 260, 261, 271, -130, 263, 277, -130, -130, -130, + -130, 167, -130, -130, -130, -130, -130, -130, 124, -130, + -130, 128, -130, -130, 128, 69, 286, -130, 287, -130, + 268, -130, -130, 124, -130, -130, -130, 295, -130, -130, + -130, 296, 297, 264, -130, 299, 290, 249, 301, 167, + -130, 124, 305, -130 }; /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. @@ -699,59 +695,53 @@ static const yytype_int16 yypact[] = means the default is an error. */ static const yytype_uint8 yydefact[] = { - 169, 176, 177, 0, 0, 163, 170, 1, 153, 0, + 106, 113, 114, 0, 0, 100, 107, 1, 90, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 15, 174, 0, 162, 154, 161, 160, 159, 158, 155, - 156, 157, 0, 0, 0, 0, 0, 70, 0, 0, - 0, 0, 0, 12, 165, 174, 174, 174, 0, 164, - 175, 0, 14, 71, 56, 133, 119, 127, 131, 103, - 0, 10, 11, 0, 0, 0, 140, 138, 0, 0, - 0, 0, 0, 0, 0, 0, 24, 17, 0, 17, - 54, 0, 12, 0, 0, 0, 54, 0, 0, 19, - 19, 0, 0, 0, 0, 0, 0, 0, 2, 0, - 2, 51, 52, 0, 0, 102, 90, 98, 88, 72, - 0, 57, 0, 126, 120, 124, 0, 130, 128, 0, - 132, 0, 118, 104, 112, 116, 134, 135, 4, 0, - 141, 0, 138, 0, 4, 0, 0, 146, 13, 172, - 0, 0, 8, 9, 0, 18, 58, 0, 18, 58, - 54, 55, 34, 0, 0, 58, 58, 0, 36, 41, - 0, 20, 21, 21, 45, 46, 0, 0, 50, 0, - 0, 0, 0, 0, 0, 0, 53, 23, 97, 91, - 95, 101, 99, 89, 87, 73, 81, 85, 2, 123, - 121, 125, 129, 2, 111, 105, 109, 115, 113, 117, - 0, 0, 4, 0, 143, 139, 0, 4, 0, 0, - 0, 152, 151, 173, 0, 167, 0, 171, 59, 25, - 0, 26, 58, 32, 35, 30, 13, 38, 39, 58, - 42, 22, 0, 0, 47, 49, 0, 69, 60, 3, - 0, 64, 65, 0, 94, 92, 96, 100, 80, 74, - 78, 84, 82, 86, 0, 0, 122, 0, 0, 108, - 106, 110, 114, 2, 0, 0, 0, 0, 142, 0, - 0, 149, 147, 166, 168, 17, 28, 33, 31, 37, - 40, 43, 0, 48, 61, 66, 93, 77, 75, 79, - 83, 62, 0, 67, 0, 107, 0, 0, 144, 0, - 136, 0, 150, 148, 58, 44, 76, 63, 68, 5, - 7, 145, 16, 0, 0, 0, 137, 27, 0, 0, - 0, 17, 6, 58, 0, 29 + 15, 111, 0, 99, 91, 98, 97, 96, 95, 92, + 93, 94, 0, 0, 0, 0, 0, 58, 0, 0, + 0, 0, 0, 12, 102, 111, 111, 111, 0, 101, + 112, 0, 14, 58, 56, 59, 60, 67, 58, 0, + 10, 11, 0, 0, 0, 77, 75, 0, 0, 0, + 0, 0, 0, 0, 0, 24, 17, 0, 17, 54, + 0, 12, 0, 0, 0, 54, 0, 0, 19, 19, + 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, + 51, 52, 0, 0, 58, 0, 0, 57, 0, 0, + 70, 72, 4, 0, 78, 0, 75, 0, 4, 0, + 0, 83, 13, 109, 0, 0, 8, 9, 0, 18, + 58, 0, 18, 58, 54, 55, 34, 0, 0, 58, + 58, 0, 36, 41, 0, 20, 21, 21, 45, 46, + 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, + 53, 23, 0, 71, 68, 0, 0, 4, 0, 80, + 76, 0, 4, 0, 0, 0, 89, 88, 110, 0, + 104, 0, 108, 25, 0, 26, 58, 32, 35, 30, + 13, 38, 39, 58, 42, 22, 0, 0, 47, 49, + 0, 66, 58, 3, 0, 58, 58, 0, 69, 2, + 0, 0, 0, 0, 79, 0, 0, 86, 84, 103, + 105, 17, 28, 33, 31, 37, 40, 43, 0, 48, + 61, 58, 63, 64, 58, 0, 0, 81, 0, 73, + 0, 87, 85, 58, 44, 62, 65, 5, 7, 82, + 16, 0, 0, 0, 74, 27, 0, 0, 0, 17, + 6, 58, 0, 29 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int16 yypgoto[] = { - -140, -94, -132, 178, 203, 188, 40, 117, -140, -78, - 187, 122, -55, -140, -77, 157, -139, -48, -2, -38, - -46, -140, -140, -140, -140, -140, 146, -140, -140, -140, - -140, -140, -140, -140, -140, -140, 270, -140, -140, 153, - -140, 70, -140, -140 + -130, -94, -112, 176, -21, 233, -25, 3, -130, -78, + 229, 156, -52, -130, -65, -130, -129, -125, -51, -36, + -130, -130, -130, -130, 203, -130, -130, -130, -130, -130, + -130, -130, -130, -130, 311, -130, -130, 198, -130, 65, + -130, -130 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int16 yydefgoto[] = { - -1, 171, 201, 144, 63, 71, 145, 21, 313, 146, - 162, 232, 54, 104, 152, 218, 219, 56, 57, 58, - 59, 60, 24, 25, 301, 205, 131, 67, 132, 26, - 27, 28, 29, 30, 31, 14, 5, 6, 1, 50, - 214, 36, 2, 3 + -1, 155, 166, 128, 62, 70, 129, 21, 251, 130, + 146, 196, 54, 103, 136, 55, 56, 57, 58, 59, + 24, 25, 240, 170, 115, 66, 116, 26, 27, 28, + 29, 30, 31, 14, 5, 6, 1, 50, 179, 36, + 2, 3 }; /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If @@ -759,173 +749,109 @@ static const yytype_int16 yydefgoto[] = number is the opposite. If YYTABLE_NINF, syntax error. */ static const yytype_uint16 yytable[] = { - 111, 149, 209, 51, 4, 106, 174, 109, 52, 158, - 223, 123, 97, 263, 264, 108, 227, 228, 115, 118, - 7, 125, 110, 147, 61, 151, 61, 62, 15, 62, - 64, 151, 17, 8, 18, 52, 19, 165, 166, 167, - 168, 169, 9, 10, 11, 12, 13, 238, 176, 20, - 111, 107, 239, 61, 114, 242, 62, 124, 111, 8, - 239, 185, 111, 33, 135, 111, 34, 111, 180, 182, - 266, 187, 44, 224, 66, 269, 190, 53, 35, 65, - 75, 68, 291, 277, 293, 196, 198, 239, 210, 239, - 280, 309, 221, 51, 254, 151, 239, 110, 225, 257, - 22, 23, 229, 112, 179, 230, 116, 186, 126, 137, - 61, 234, 235, 62, 236, 72, 73, 74, 119, 148, - 127, 195, 121, 111, 48, 49, 111, 128, 111, 111, - 20, 52, 129, 32, 111, 130, 111, 111, 172, 111, - 175, 245, 111, 173, 111, 48, 139, 250, 252, 52, - 45, 46, 47, 48, 140, 48, 141, 260, 69, 70, - 161, 270, 177, 111, 200, 314, 276, 142, 143, 296, - 278, 279, 203, 204, 263, 264, 202, 281, 282, 203, - 268, 283, 208, 249, 324, 133, 134, 211, 222, 111, - 212, 111, 111, 111, 55, 48, 111, 304, 111, 215, - 217, 111, 220, 231, 111, 312, 111, 111, 237, 240, - 105, 288, 241, 113, 117, 120, 122, 265, 243, 267, - 271, 272, 273, 274, 284, 285, 298, 305, 255, 299, - 302, 111, 111, 258, 111, 111, 292, 37, 38, 39, - 111, 294, 297, 323, 40, 300, 41, 42, 43, 303, - 207, 111, 307, 308, 310, 311, 315, 319, 216, 316, - 317, 320, 322, 178, 181, 183, 184, 325, 318, 164, - 154, 189, 191, 136, 138, 192, 321, 163, 206, 16, - 194, 197, 199, 150, 153, 233, 155, 156, 157, 0, - 159, 160, 213, 0, 0, 0, 0, 0, 0, 0, - 170, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 76, 77, 78, 0, 0, 79, 80, 81, 82, 0, - 83, 84, 85, 86, 87, 88, 89, 90, 0, 0, - 91, 92, 93, 94, 95, 96, 244, 246, 0, 247, - 0, 100, 248, 251, 253, 0, 0, 256, 101, 102, - 103, 0, 259, 261, 0, 262, 0, 226, 76, 77, - 78, 0, 0, 79, 80, 81, 82, 0, 83, 84, - 85, 86, 87, 88, 89, 90, 0, 0, 91, 92, - 93, 94, 95, 96, 0, 0, 97, 98, 99, 100, - 0, 0, 0, 0, 0, 0, 101, 102, 103, 0, - 0, 0, 286, 0, 0, 0, 287, 289, 0, 290, - 0, 0, 0, 76, 77, 78, 0, 295, 79, 80, - 81, 82, 0, 83, 84, 85, 86, 87, 88, 89, - 90, 0, 0, 91, 92, 93, 94, 95, 96, 0, - 0, 0, 188, 99, 100, 306, 0, 0, 0, 0, - 0, 101, 102, 103, 76, 77, 78, 0, 0, 79, - 80, 81, 82, 0, 83, 84, 85, 86, 87, 88, - 89, 90, 0, 0, 91, 92, 93, 94, 95, 96, - 0, 0, 0, 98, 99, 100, 0, 0, 0, 0, - 0, 0, 101, 102, 103, 76, 77, 78, 0, 0, - 79, 80, 81, 82, 0, 83, 84, 85, 86, 87, - 88, 89, 90, 0, 0, 91, 92, 93, 94, 95, - 96, 0, 0, 0, 0, 0, 193, 0, 0, 0, - 0, 0, 0, 101, 102, 103, 76, 77, 78, 275, - 0, 79, 80, 81, 82, 0, 83, 84, 85, 86, - 87, 88, 89, 90, 0, 0, 91, 92, 93, 94, - 95, 96, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 101, 102, 103, 76, 77, 78, - 0, 0, 79, 80, 81, 82, 0, 83, 84, 85, - 86, 87, 88, 89, 90, 0, 0, 91, 92, 93, - 94, 95, 96, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 101, 102, 103 + 133, 183, 104, 107, 187, 158, 174, 4, 51, 7, + 191, 192, 53, 52, 64, 15, 67, 105, 60, 32, + 142, 61, 109, 63, 106, 131, 60, 135, 52, 61, + 202, 22, 23, 135, 17, 203, 45, 46, 47, 149, + 150, 151, 152, 153, 68, 69, 20, 206, 120, 122, + 160, 60, 203, 132, 61, 212, 119, 223, 134, 137, + 215, 139, 140, 141, 226, 143, 144, 175, 162, 188, + 117, 118, 156, 247, 159, 154, 18, 230, 203, 185, + 232, 233, 135, 19, 8, 189, 121, 60, 33, 193, + 61, 8, 194, 9, 10, 11, 12, 13, 198, 199, + 34, 200, 96, 209, 210, 35, 245, 186, 44, 246, + 71, 72, 73, 65, 252, 235, 74, 190, 48, 49, + 172, 216, 51, 20, 52, 48, 123, 106, 181, 48, + 124, 108, 262, 222, 48, 125, 110, 224, 225, 126, + 127, 168, 169, 243, 227, 228, 209, 210, 229, 75, + 76, 77, 168, 214, 78, 79, 80, 81, 111, 82, + 83, 84, 85, 86, 87, 88, 89, 113, 114, 90, + 91, 92, 93, 94, 95, 52, 244, 96, 97, 98, + 99, 261, 112, 145, 157, 161, 163, 100, 101, 102, + 75, 76, 77, 164, 165, 78, 79, 80, 81, 173, + 82, 83, 84, 85, 86, 87, 88, 89, 167, 176, + 90, 91, 92, 93, 94, 95, 177, 48, 184, 97, + 98, 99, 180, 182, 195, 204, 201, 205, 100, 101, + 102, 75, 76, 77, 221, 207, 78, 79, 80, 81, + 208, 82, 83, 84, 85, 86, 87, 88, 89, 211, + 213, 90, 91, 92, 93, 94, 95, 217, 218, 219, + 220, 231, 234, 259, 237, 238, 148, 241, 236, 100, + 101, 102, 75, 76, 77, 250, 239, 78, 79, 80, + 81, 242, 82, 83, 84, 85, 86, 87, 88, 89, + 248, 249, 90, 91, 92, 93, 94, 95, 253, 258, + 254, 255, 257, 197, 256, 260, 37, 38, 39, 263, + 100, 101, 102, 40, 138, 41, 42, 43, 147, 171, + 16, 178 }; -static const yytype_int16 yycheck[] = +static const yytype_uint16 yycheck[] = { - 55, 79, 134, 3, 3, 53, 100, 53, 8, 86, - 149, 59, 38, 39, 40, 53, 155, 156, 56, 57, - 0, 59, 3, 78, 5, 80, 5, 8, 3, 8, - 3, 86, 3, 42, 3, 8, 3, 92, 93, 94, - 95, 96, 51, 52, 53, 54, 55, 4, 103, 7, - 105, 53, 9, 5, 56, 4, 8, 59, 113, 42, - 9, 109, 117, 55, 43, 120, 55, 122, 106, 107, - 202, 109, 4, 150, 5, 207, 114, 37, 55, 39, - 30, 41, 4, 222, 4, 123, 124, 9, 134, 9, - 229, 4, 147, 3, 188, 150, 9, 3, 153, 193, - 3, 4, 157, 3, 106, 160, 3, 109, 4, 4, - 5, 166, 167, 8, 169, 45, 46, 47, 3, 79, - 4, 123, 3, 178, 3, 4, 181, 36, 183, 184, - 7, 8, 3, 16, 189, 5, 191, 192, 98, 194, - 100, 179, 197, 9, 199, 3, 4, 185, 186, 8, - 33, 34, 35, 3, 4, 3, 4, 195, 41, 42, - 28, 207, 4, 218, 3, 304, 221, 5, 6, 263, - 225, 226, 3, 4, 39, 40, 36, 232, 233, 3, - 4, 236, 3, 185, 323, 68, 69, 4, 148, 244, - 4, 246, 247, 248, 37, 3, 251, 275, 253, 4, - 4, 256, 3, 29, 259, 7, 261, 262, 4, 9, - 53, 249, 4, 56, 57, 58, 59, 4, 9, 44, - 4, 4, 4, 4, 4, 4, 4, 282, 188, 4, - 4, 286, 287, 193, 289, 290, 9, 36, 37, 38, - 295, 9, 9, 321, 43, 5, 45, 46, 47, 4, - 133, 306, 4, 4, 4, 4, 3, 3, 141, 4, - 4, 9, 4, 106, 107, 108, 109, 4, 40, 91, - 82, 114, 115, 70, 71, 118, 14, 90, 132, 9, - 123, 124, 125, 80, 81, 163, 83, 84, 85, -1, - 87, 88, 139, -1, -1, -1, -1, -1, -1, -1, - 97, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 10, 11, 12, -1, -1, 15, 16, 17, 18, -1, - 20, 21, 22, 23, 24, 25, 26, 27, -1, -1, - 30, 31, 32, 33, 34, 35, 179, 180, -1, 182, - -1, 41, 185, 186, 187, -1, -1, 190, 48, 49, - 50, -1, 195, 196, -1, 198, -1, 154, 10, 11, - 12, -1, -1, 15, 16, 17, 18, -1, 20, 21, - 22, 23, 24, 25, 26, 27, -1, -1, 30, 31, - 32, 33, 34, 35, -1, -1, 38, 39, 40, 41, - -1, -1, -1, -1, -1, -1, 48, 49, 50, -1, - -1, -1, 245, -1, -1, -1, 249, 250, -1, 252, - -1, -1, -1, 10, 11, 12, -1, 260, 15, 16, - 17, 18, -1, 20, 21, 22, 23, 24, 25, 26, - 27, -1, -1, 30, 31, 32, 33, 34, 35, -1, - -1, -1, 39, 40, 41, 288, -1, -1, -1, -1, - -1, 48, 49, 50, 10, 11, 12, -1, -1, 15, - 16, 17, 18, -1, 20, 21, 22, 23, 24, 25, - 26, 27, -1, -1, 30, 31, 32, 33, 34, 35, - -1, -1, -1, 39, 40, 41, -1, -1, -1, -1, - -1, -1, 48, 49, 50, 10, 11, 12, -1, -1, - 15, 16, 17, 18, -1, 20, 21, 22, 23, 24, - 25, 26, 27, -1, -1, 30, 31, 32, 33, 34, - 35, -1, -1, -1, -1, -1, 41, -1, -1, -1, - -1, -1, -1, 48, 49, 50, 10, 11, 12, 13, - -1, 15, 16, 17, 18, -1, 20, 21, 22, 23, - 24, 25, 26, 27, -1, -1, 30, 31, 32, 33, - 34, 35, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 48, 49, 50, 10, 11, 12, - -1, -1, 15, 16, 17, 18, -1, 20, 21, 22, - 23, 24, 25, 26, 27, -1, -1, 30, 31, 32, - 33, 34, 35, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 48, 49, 50 + 78, 130, 53, 55, 133, 99, 118, 3, 3, 0, + 139, 140, 37, 8, 39, 3, 41, 53, 5, 16, + 85, 8, 58, 3, 3, 77, 5, 79, 8, 8, + 4, 3, 4, 85, 3, 9, 33, 34, 35, 91, + 92, 93, 94, 95, 41, 42, 7, 4, 69, 70, + 102, 5, 9, 78, 8, 167, 43, 186, 79, 80, + 172, 82, 83, 84, 193, 86, 87, 118, 104, 134, + 67, 68, 97, 4, 99, 96, 3, 202, 9, 131, + 205, 206, 134, 3, 42, 137, 4, 5, 55, 141, + 8, 42, 144, 51, 52, 53, 54, 55, 150, 151, + 55, 153, 38, 39, 40, 55, 231, 132, 4, 234, + 45, 46, 47, 5, 243, 209, 30, 138, 3, 4, + 117, 172, 3, 7, 8, 3, 4, 3, 125, 3, + 4, 3, 261, 185, 3, 4, 4, 189, 190, 5, + 6, 3, 4, 221, 196, 197, 39, 40, 200, 10, + 11, 12, 3, 4, 15, 16, 17, 18, 4, 20, + 21, 22, 23, 24, 25, 26, 27, 3, 5, 30, + 31, 32, 33, 34, 35, 8, 228, 38, 39, 40, + 41, 259, 36, 28, 9, 4, 4, 48, 49, 50, + 10, 11, 12, 4, 3, 15, 16, 17, 18, 3, + 20, 21, 22, 23, 24, 25, 26, 27, 36, 4, + 30, 31, 32, 33, 34, 35, 4, 3, 3, 39, + 40, 41, 4, 4, 29, 9, 4, 4, 48, 49, + 50, 10, 11, 12, 13, 9, 15, 16, 17, 18, + 4, 20, 21, 22, 23, 24, 25, 26, 27, 4, + 44, 30, 31, 32, 33, 34, 35, 4, 4, 4, + 4, 4, 4, 14, 4, 4, 90, 4, 9, 48, + 49, 50, 10, 11, 12, 7, 5, 15, 16, 17, + 18, 4, 20, 21, 22, 23, 24, 25, 26, 27, + 4, 4, 30, 31, 32, 33, 34, 35, 3, 9, + 4, 4, 3, 147, 40, 4, 36, 37, 38, 4, + 48, 49, 50, 43, 81, 45, 46, 47, 89, 116, + 9, 123 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ static const yytype_uint8 yystos[] = { - 0, 95, 99, 100, 3, 93, 94, 0, 42, 51, - 52, 53, 54, 55, 92, 3, 93, 3, 3, 3, - 7, 64, 3, 4, 79, 80, 86, 87, 88, 89, - 90, 91, 64, 55, 55, 55, 98, 36, 37, 38, + 0, 93, 97, 98, 3, 91, 92, 0, 42, 51, + 52, 53, 54, 55, 90, 3, 91, 3, 3, 3, + 7, 64, 3, 4, 77, 78, 84, 85, 86, 87, + 88, 89, 64, 55, 55, 55, 96, 36, 37, 38, 43, 45, 46, 47, 4, 64, 64, 64, 3, 4, - 96, 3, 8, 63, 69, 72, 74, 75, 76, 77, - 78, 5, 8, 61, 3, 63, 5, 84, 63, 64, - 64, 62, 98, 98, 98, 30, 10, 11, 12, 15, - 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, - 27, 30, 31, 32, 33, 34, 35, 38, 39, 40, - 41, 48, 49, 50, 70, 72, 74, 75, 76, 77, - 3, 69, 3, 72, 75, 76, 3, 72, 76, 3, - 72, 3, 72, 74, 75, 76, 4, 4, 36, 3, - 5, 83, 85, 64, 64, 43, 61, 4, 61, 4, - 4, 4, 5, 6, 60, 63, 66, 69, 63, 66, - 61, 69, 71, 61, 62, 61, 61, 61, 71, 61, - 61, 28, 67, 67, 60, 69, 69, 69, 69, 69, - 61, 58, 63, 9, 58, 63, 69, 4, 72, 75, - 76, 72, 76, 72, 72, 74, 75, 76, 39, 72, - 76, 72, 72, 41, 72, 75, 76, 72, 76, 72, - 3, 59, 36, 3, 4, 82, 83, 64, 3, 59, - 77, 4, 4, 96, 97, 4, 64, 4, 72, 73, - 3, 69, 63, 73, 71, 69, 61, 73, 73, 69, - 69, 29, 68, 68, 69, 69, 69, 4, 4, 9, - 9, 4, 4, 9, 72, 76, 72, 72, 72, 75, - 76, 72, 76, 72, 58, 63, 72, 58, 63, 72, - 76, 72, 72, 39, 40, 4, 59, 44, 4, 59, - 77, 4, 4, 4, 4, 13, 69, 73, 69, 69, - 73, 69, 69, 69, 4, 4, 72, 72, 76, 72, - 72, 4, 9, 4, 9, 72, 58, 9, 4, 4, - 5, 81, 4, 4, 66, 69, 72, 4, 4, 4, - 4, 4, 7, 65, 73, 3, 4, 4, 40, 3, - 9, 14, 4, 66, 73, 4 + 94, 3, 8, 63, 69, 72, 73, 74, 75, 76, + 5, 8, 61, 3, 63, 5, 82, 63, 64, 64, + 62, 96, 96, 96, 30, 10, 11, 12, 15, 16, + 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, + 30, 31, 32, 33, 34, 35, 38, 39, 40, 41, + 48, 49, 50, 70, 75, 76, 3, 69, 3, 76, + 4, 4, 36, 3, 5, 81, 83, 64, 64, 43, + 61, 4, 61, 4, 4, 4, 5, 6, 60, 63, + 66, 69, 63, 66, 61, 69, 71, 61, 62, 61, + 61, 61, 71, 61, 61, 28, 67, 67, 60, 69, + 69, 69, 69, 69, 61, 58, 63, 9, 58, 63, + 69, 4, 76, 4, 4, 3, 59, 36, 3, 4, + 80, 81, 64, 3, 59, 75, 4, 4, 94, 95, + 4, 64, 4, 73, 3, 69, 63, 73, 71, 69, + 61, 73, 73, 69, 69, 29, 68, 68, 69, 69, + 69, 4, 4, 9, 9, 4, 4, 9, 4, 39, + 40, 4, 59, 44, 4, 59, 75, 4, 4, 4, + 4, 13, 69, 73, 69, 69, 73, 69, 69, 69, + 74, 4, 74, 74, 4, 58, 9, 4, 4, 5, + 79, 4, 4, 66, 69, 74, 74, 4, 4, 4, + 7, 65, 73, 3, 4, 4, 40, 3, 9, 14, + 4, 66, 73, 4 }; /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ @@ -937,18 +863,12 @@ static const yytype_uint8 yyr1[] = 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 72, 72, 73, 73, - 74, 74, 74, 74, 75, 76, 76, 76, 76, 77, - 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, - 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, - 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, - 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, - 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, - 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, - 78, 78, 78, 78, 79, 80, 81, 82, 83, 83, - 84, 85, 86, 86, 87, 87, 88, 89, 89, 89, - 89, 90, 91, 92, 92, 92, 92, 92, 92, 92, - 92, 92, 93, 94, 94, 94, 94, 94, 94, 95, - 95, 96, 97, 97, 98, 98, 99, 100 + 74, 74, 74, 74, 74, 74, 75, 76, 77, 77, + 77, 77, 78, 79, 80, 81, 81, 82, 83, 84, + 84, 85, 85, 86, 87, 87, 87, 87, 88, 89, + 90, 90, 90, 90, 90, 90, 90, 90, 90, 91, + 92, 92, 92, 92, 92, 92, 93, 93, 94, 95, + 95, 96, 96, 97, 98 }; /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ @@ -960,18 +880,12 @@ static const yytype_uint8 yyr2[] = 3, 4, 3, 4, 2, 3, 2, 4, 3, 3, 4, 2, 3, 4, 5, 2, 2, 3, 4, 3, 2, 1, 1, 2, 0, 1, 1, 2, 0, 1, - 4, 5, 5, 6, 4, 4, 5, 5, 6, 4, - 0, 1, 2, 3, 4, 5, 6, 5, 4, 5, - 4, 3, 4, 5, 4, 3, 4, 3, 2, 3, - 2, 3, 4, 5, 4, 3, 4, 3, 2, 3, - 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, - 4, 3, 2, 3, 4, 3, 2, 3, 2, 1, - 2, 3, 4, 3, 2, 3, 2, 1, 2, 3, - 2, 1, 2, 1, 4, 4, 1, 5, 0, 2, - 1, 1, 6, 5, 7, 8, 4, 6, 7, 6, - 7, 5, 5, 0, 2, 2, 2, 2, 2, 2, - 2, 2, 4, 1, 5, 5, 9, 8, 9, 0, - 2, 4, 0, 1, 0, 2, 1, 1 + 1, 5, 6, 5, 5, 6, 4, 1, 5, 6, + 4, 5, 4, 1, 5, 0, 2, 1, 1, 6, + 5, 7, 8, 4, 6, 7, 6, 7, 5, 5, + 0, 2, 2, 2, 2, 2, 2, 2, 2, 4, + 1, 5, 5, 9, 8, 9, 0, 2, 4, 0, + 1, 0, 2, 1, 1 }; @@ -1468,189 +1382,183 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio switch (yytype) { case 58: /* value_type_list */ -#line 154 "src/wasm-bison-parser.y" /* yacc.c:1257 */ +#line 161 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_type_vector(parser->allocator, &((*yyvaluep).types)); } -#line 1474 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1388 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; case 59: /* func_type */ -#line 164 "src/wasm-bison-parser.y" /* yacc.c:1257 */ +#line 171 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_func_signature(parser->allocator, &((*yyvaluep).func_sig)); } -#line 1480 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1394 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; case 60: /* literal */ -#line 153 "src/wasm-bison-parser.y" /* yacc.c:1257 */ +#line 160 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).literal).text); } -#line 1486 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1400 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; case 61: /* var */ -#line 155 "src/wasm-bison-parser.y" /* yacc.c:1257 */ +#line 162 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_var(parser->allocator, &((*yyvaluep).var)); } -#line 1492 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1406 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; case 62: /* var_list */ -#line 156 "src/wasm-bison-parser.y" /* yacc.c:1257 */ +#line 163 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_var_vector_and_elements(parser->allocator, &((*yyvaluep).vars)); } -#line 1498 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1412 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; case 63: /* bind_var */ -#line 152 "src/wasm-bison-parser.y" /* yacc.c:1257 */ +#line 159 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } -#line 1504 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1418 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; case 64: /* quoted_text */ -#line 152 "src/wasm-bison-parser.y" /* yacc.c:1257 */ +#line 159 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } -#line 1510 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1424 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; case 65: /* string_contents */ -#line 161 "src/wasm-bison-parser.y" /* yacc.c:1257 */ +#line 168 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_segment(parser->allocator, &((*yyvaluep).segment)); } -#line 1516 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1430 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; case 66: /* labeling */ -#line 152 "src/wasm-bison-parser.y" /* yacc.c:1257 */ +#line 159 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } -#line 1522 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1436 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; case 69: /* expr */ -#line 157 "src/wasm-bison-parser.y" /* yacc.c:1257 */ +#line 164 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_expr_ptr(parser->allocator, &((*yyvaluep).expr)); } -#line 1528 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1442 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; case 70: /* expr1 */ -#line 157 "src/wasm-bison-parser.y" /* yacc.c:1257 */ +#line 164 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_expr_ptr(parser->allocator, &((*yyvaluep).expr)); } -#line 1534 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1448 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; case 71: /* expr_opt */ -#line 157 "src/wasm-bison-parser.y" /* yacc.c:1257 */ +#line 164 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_expr_ptr(parser->allocator, &((*yyvaluep).expr)); } -#line 1540 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1454 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; case 72: /* non_empty_expr_list */ -#line 158 "src/wasm-bison-parser.y" /* yacc.c:1257 */ +#line 165 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_expr_ptr_vector_and_elements(parser->allocator, &((*yyvaluep).exprs)); } -#line 1546 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1460 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; case 73: /* expr_list */ -#line 158 "src/wasm-bison-parser.y" /* yacc.c:1257 */ +#line 165 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_expr_ptr_vector_and_elements(parser->allocator, &((*yyvaluep).exprs)); } -#line 1552 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1466 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 74: /* param_list */ -#line 159 "src/wasm-bison-parser.y" /* yacc.c:1257 */ - { wasm_destroy_type_bindings(parser->allocator, &((*yyvaluep).type_bindings)); } -#line 1558 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ - break; - - case 76: /* local_list */ -#line 159 "src/wasm-bison-parser.y" /* yacc.c:1257 */ - { wasm_destroy_type_bindings(parser->allocator, &((*yyvaluep).type_bindings)); } -#line 1564 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ + case 74: /* func_fields */ +#line 166 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + { wasm_destroy_func_fields(parser->allocator, ((*yyvaluep).func_fields)); } +#line 1472 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 78: /* func_info */ -#line 160 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + case 76: /* func_info */ +#line 167 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_func(parser->allocator, ((*yyvaluep).func)); wasm_free(parser->allocator, ((*yyvaluep).func)); } -#line 1570 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1478 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 79: /* func */ -#line 160 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + case 77: /* func */ +#line 167 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_func(parser->allocator, ((*yyvaluep).func)); wasm_free(parser->allocator, ((*yyvaluep).func)); } -#line 1576 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1484 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 82: /* segment */ -#line 161 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + case 80: /* segment */ +#line 168 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_segment(parser->allocator, &((*yyvaluep).segment)); } -#line 1582 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1490 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 83: /* segment_list */ -#line 162 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + case 81: /* segment_list */ +#line 169 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_segment_vector_and_elements(parser->allocator, &((*yyvaluep).segments)); } -#line 1588 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1496 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 86: /* memory */ -#line 163 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + case 84: /* memory */ +#line 170 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_memory(parser->allocator, &((*yyvaluep).memory)); } -#line 1594 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1502 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 87: /* type_def */ -#line 165 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + case 85: /* type_def */ +#line 172 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_func_type(parser->allocator, &((*yyvaluep).func_type)); } -#line 1600 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1508 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 88: /* table */ -#line 156 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + case 86: /* table */ +#line 163 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_var_vector_and_elements(parser->allocator, &((*yyvaluep).vars)); } -#line 1606 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1514 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 89: /* import */ -#line 166 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + case 87: /* import */ +#line 173 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_import(parser->allocator, ((*yyvaluep).import)); wasm_free(parser->allocator, ((*yyvaluep).import)); } -#line 1612 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1520 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 90: /* export */ -#line 167 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + case 88: /* export */ +#line 174 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_export(parser->allocator, &((*yyvaluep).export_)); } -#line 1618 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1526 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 92: /* module_fields */ -#line 168 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + case 90: /* module_fields */ +#line 175 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_module(parser->allocator, ((*yyvaluep).module)); wasm_free(parser->allocator, ((*yyvaluep).module)); } -#line 1624 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1532 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 93: /* module */ -#line 168 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + case 91: /* module */ +#line 175 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_module(parser->allocator, ((*yyvaluep).module)); wasm_free(parser->allocator, ((*yyvaluep).module)); } -#line 1630 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1538 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 94: /* cmd */ -#line 170 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + case 92: /* cmd */ +#line 177 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_command(parser->allocator, ((*yyvaluep).command)); wasm_free(parser->allocator, ((*yyvaluep).command)); } -#line 1636 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1544 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 95: /* cmd_list */ -#line 171 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + case 93: /* cmd_list */ +#line 178 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_command_vector_and_elements(parser->allocator, &((*yyvaluep).commands)); } -#line 1642 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1550 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 98: /* const_list */ -#line 169 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + case 96: /* const_list */ +#line 176 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_const_vector(parser->allocator, &((*yyvaluep).consts)); } -#line 1648 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1556 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; - case 99: /* script */ -#line 172 "src/wasm-bison-parser.y" /* yacc.c:1257 */ + case 97: /* script */ +#line 179 "src/wasm-bison-parser.y" /* yacc.c:1257 */ { wasm_destroy_script(&((*yyvaluep).script)); } -#line 1654 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ +#line 1562 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1257 */ break; @@ -1942,72 +1850,72 @@ yyreduce: switch (yyn) { case 2: -#line 184 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 191 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.types)); } -#line 1948 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1856 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 3: -#line 185 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 192 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.types) = (yyvsp[-1].types); CHECK_ALLOC(wasm_append_type_value(parser->allocator, &(yyval.types), &(yyvsp[0].type))); } -#line 1957 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1865 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 4: -#line 191 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 198 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.func_sig)); } -#line 1963 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1871 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 5: -#line 192 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 199 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.func_sig).result_type = WASM_TYPE_VOID; (yyval.func_sig).param_types = (yyvsp[-1].types); } -#line 1972 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1880 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 6: -#line 196 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 203 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.func_sig).result_type = (yyvsp[-1].type); (yyval.func_sig).param_types = (yyvsp[-5].types); } -#line 1981 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1889 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 7: -#line 200 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 207 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.func_sig)); (yyval.func_sig).result_type = (yyvsp[-1].type); } -#line 1987 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1895 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 8: -#line 207 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 214 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.literal).type = (yyvsp[0].literal).type; DUPTEXT((yyval.literal).text, (yyvsp[0].literal).text); CHECK_ALLOC_STR((yyval.literal).text); } -#line 1997 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1905 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 9: -#line 212 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 219 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.literal).type = (yyvsp[0].literal).type; DUPTEXT((yyval.literal).text, (yyvsp[0].literal).text); CHECK_ALLOC_STR((yyval.literal).text); } -#line 2007 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1915 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 10: -#line 220 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 227 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.var).loc = (yylsp[0]); (yyval.var).type = WASM_VAR_TYPE_INDEX; @@ -2020,43 +1928,43 @@ yyreduce: } (yyval.var).index = index; } -#line 2024 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1932 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 11: -#line 232 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 239 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.var).loc = (yylsp[0]); (yyval.var).type = WASM_VAR_TYPE_NAME; DUPTEXT((yyval.var).name, (yyvsp[0].text)); CHECK_ALLOC_STR((yyval.var).name); } -#line 2035 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1943 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 12: -#line 240 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 247 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.vars)); } -#line 2041 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1949 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 13: -#line 241 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 248 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.vars) = (yyvsp[-1].vars); CHECK_ALLOC(wasm_append_var_value(parser->allocator, &(yyval.vars), &(yyvsp[0].var))); } -#line 2050 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1958 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 14: -#line 247 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 254 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { DUPTEXT((yyval.text), (yyvsp[0].text)); CHECK_ALLOC_STR((yyval.text)); } -#line 2056 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1964 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 15: -#line 251 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 258 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { void* data; size_t size; @@ -2064,38 +1972,38 @@ yyreduce: (yyval.text).start = data; (yyval.text).length = size; } -#line 2068 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1976 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 16: -#line 261 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 268 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { CHECK_ALLOC(dup_string_contents(parser->allocator, &(yyvsp[0].text), &(yyval.segment).data, &(yyval.segment).size)); } -#line 2077 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1985 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 17: -#line 268 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 275 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.text)); } -#line 2083 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1991 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 18: -#line 269 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 276 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.text) = (yyvsp[0].text); } -#line 2089 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 1997 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 19: -#line 273 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 280 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.u64) = 0; } -#line 2095 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2003 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 20: -#line 274 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 281 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { if (WASM_FAILED(wasm_parse_int64((yyvsp[0].text).start, (yyvsp[0].text).start + (yyvsp[0].text).length, &(yyval.u64)))) { wasm_parser_error(&(yylsp[0]), lexer, parser, @@ -2103,17 +2011,17 @@ yyreduce: WASM_PRINTF_STRING_SLICE_ARG((yyvsp[0].text))); } } -#line 2107 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2015 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 21: -#line 283 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 290 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.u32) = USE_NATURAL_ALIGNMENT; } -#line 2113 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2021 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 22: -#line 284 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 291 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { if (WASM_FAILED(wasm_parse_int32((yyvsp[0].text).start, (yyvsp[0].text).start + (yyvsp[0].text).length, &(yyval.u32), WASM_PARSE_UNSIGNED_ONLY))) { @@ -2122,35 +2030,35 @@ yyreduce: WASM_PRINTF_STRING_SLICE_ARG((yyvsp[0].text))); } } -#line 2126 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2034 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 23: -#line 295 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 302 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = (yyvsp[-1].expr); (yyval.expr)->loc = (yylsp[-2]); } -#line 2132 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2040 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 24: -#line 298 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 305 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_empty_expr(parser->allocator, WASM_EXPR_TYPE_NOP); CHECK_ALLOC_NULL((yyval.expr)); } -#line 2141 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2049 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 25: -#line 302 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 309 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = new_block_expr_with_list(parser->allocator, &(yyvsp[-1].text), &(yyvsp[0].exprs)); CHECK_ALLOC_NULL((yyval.expr)); } -#line 2150 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2058 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 26: -#line 306 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 313 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_if_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2159,11 +2067,11 @@ yyreduce: CHECK_ALLOC_NULL(true_block); (yyval.expr)->if_.true_ = true_block; } -#line 2163 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2071 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 27: -#line 314 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 321 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_if_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2173,11 +2081,11 @@ yyreduce: CHECK_ALLOC_NULL(true_block); (yyval.expr)->if_.true_ = true_block; } -#line 2177 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2085 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 28: -#line 323 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 330 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_if_else_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2189,11 +2097,11 @@ yyreduce: CHECK_ALLOC_NULL(false_block); (yyval.expr)->if_else.false_ = false_block; } -#line 2193 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2101 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 29: -#line 334 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 341 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_if_else_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2207,22 +2115,22 @@ yyreduce: CHECK_ALLOC_NULL(false_block); (yyval.expr)->if_else.false_ = false_block; } -#line 2211 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2119 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 30: -#line 347 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 354 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_br_if_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); (yyval.expr)->br_if.var = (yyvsp[-1].var); (yyval.expr)->br_if.cond = (yyvsp[0].expr); } -#line 2222 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2130 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 31: -#line 353 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 360 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_br_if_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2230,11 +2138,11 @@ yyreduce: (yyval.expr)->br_if.expr = (yyvsp[-1].expr); (yyval.expr)->br_if.cond = (yyvsp[0].expr); } -#line 2234 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2142 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 32: -#line 360 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 367 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_loop_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2242,11 +2150,11 @@ yyreduce: (yyval.expr)->loop.inner = (yyvsp[-1].text); (yyval.expr)->loop.exprs = (yyvsp[0].exprs); } -#line 2246 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2154 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 33: -#line 367 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 374 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_loop_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2254,11 +2162,11 @@ yyreduce: (yyval.expr)->loop.inner = (yyvsp[-1].text); (yyval.expr)->loop.exprs = (yyvsp[0].exprs); } -#line 2258 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2166 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 34: -#line 374 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 381 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_br_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2267,32 +2175,32 @@ yyreduce: (yyval.expr)->br.var.index = 0; (yyval.expr)->br.expr = (yyvsp[0].expr); } -#line 2271 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2179 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 35: -#line 382 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 389 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_br_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); (yyval.expr)->br.var = (yyvsp[-1].var); (yyval.expr)->br.expr = (yyvsp[0].expr); } -#line 2282 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2190 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 36: -#line 388 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 395 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_return_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); (yyval.expr)->return_.expr = (yyvsp[0].expr); } -#line 2292 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2200 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 37: -#line 393 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 400 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_br_table_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2300,33 +2208,33 @@ yyreduce: (yyval.expr)->br_table.targets = (yyvsp[-2].vars); (yyval.expr)->br_table.default_target = (yyvsp[-1].var); } -#line 2304 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2212 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 38: -#line 400 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 407 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_call_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); (yyval.expr)->call.var = (yyvsp[-1].var); (yyval.expr)->call.args = (yyvsp[0].exprs); } -#line 2315 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2223 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 39: -#line 406 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 413 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_call_import_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); (yyval.expr)->call.var = (yyvsp[-1].var); (yyval.expr)->call.args = (yyvsp[0].exprs); } -#line 2326 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2234 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 40: -#line 412 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 419 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_call_indirect_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2334,32 +2242,32 @@ yyreduce: (yyval.expr)->call_indirect.expr = (yyvsp[-1].expr); (yyval.expr)->call_indirect.args = (yyvsp[0].exprs); } -#line 2338 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2246 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 41: -#line 419 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 426 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_get_local_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); (yyval.expr)->get_local.var = (yyvsp[0].var); } -#line 2348 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2256 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 42: -#line 424 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 431 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_set_local_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); (yyval.expr)->set_local.var = (yyvsp[-1].var); (yyval.expr)->set_local.expr = (yyvsp[0].expr); } -#line 2359 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2267 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 43: -#line 430 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 437 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_load_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2368,11 +2276,11 @@ yyreduce: (yyval.expr)->load.align = (yyvsp[-1].u32); (yyval.expr)->load.addr = (yyvsp[0].expr); } -#line 2372 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2280 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 44: -#line 438 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 445 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_store_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2382,11 +2290,11 @@ yyreduce: (yyval.expr)->store.addr = (yyvsp[-1].expr); (yyval.expr)->store.value = (yyvsp[0].expr); } -#line 2386 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2294 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 45: -#line 447 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 454 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_const_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2400,22 +2308,22 @@ yyreduce: } wasm_free(parser->allocator, (char*)(yyvsp[0].literal).text.start); } -#line 2404 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2312 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 46: -#line 460 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 467 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_unary_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); (yyval.expr)->unary.opcode = (yyvsp[-1].opcode); (yyval.expr)->unary.expr = (yyvsp[0].expr); } -#line 2415 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2323 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 47: -#line 466 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 473 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_binary_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2423,11 +2331,11 @@ yyreduce: (yyval.expr)->binary.left = (yyvsp[-1].expr); (yyval.expr)->binary.right = (yyvsp[0].expr); } -#line 2427 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2335 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 48: -#line 473 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 480 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_select_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2435,11 +2343,11 @@ yyreduce: (yyval.expr)->select.false_ = (yyvsp[-1].expr); (yyval.expr)->select.cond = (yyvsp[0].expr); } -#line 2439 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2347 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 49: -#line 480 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 487 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_compare_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); @@ -2447,968 +2355,274 @@ yyreduce: (yyval.expr)->compare.left = (yyvsp[-1].expr); (yyval.expr)->compare.right = (yyvsp[0].expr); } -#line 2451 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2359 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 50: -#line 487 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 494 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_convert_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); (yyval.expr)->convert.opcode = (yyvsp[-1].opcode); (yyval.expr)->convert.expr = (yyvsp[0].expr); } -#line 2462 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2370 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 51: -#line 493 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 500 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_empty_expr(parser->allocator, WASM_EXPR_TYPE_UNREACHABLE); CHECK_ALLOC_NULL((yyval.expr)); } -#line 2471 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2379 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 52: -#line 497 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 504 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_empty_expr(parser->allocator, WASM_EXPR_TYPE_MEMORY_SIZE); CHECK_ALLOC_NULL((yyval.expr)); } -#line 2480 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2388 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 53: -#line 501 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 508 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_grow_memory_expr(parser->allocator); CHECK_ALLOC_NULL((yyval.expr)); (yyval.expr)->grow_memory.expr = (yyvsp[0].expr); } -#line 2490 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2398 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 54: -#line 508 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 515 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.expr) = NULL; } -#line 2496 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2404 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 56: -#line 512 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 519 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.exprs)); CHECK_ALLOC(wasm_append_expr_ptr_value(parser->allocator, &(yyval.exprs), &(yyvsp[0].expr))); } -#line 2505 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2413 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 57: -#line 516 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 523 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.exprs) = (yyvsp[-1].exprs); CHECK_ALLOC(wasm_append_expr_ptr_value(parser->allocator, &(yyval.exprs), &(yyvsp[0].expr))); } -#line 2514 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2422 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 58: -#line 522 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 529 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.exprs)); } -#line 2520 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2428 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 60: -#line 529 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 535 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { - WASM_ZERO_MEMORY((yyval.type_bindings)); - CHECK_ALLOC(wasm_extend_types(parser->allocator, &(yyval.type_bindings).types, &(yyvsp[-1].types))); - wasm_destroy_type_vector(parser->allocator, &(yyvsp[-1].types)); + (yyval.func_fields) = new_func_field(parser->allocator); + CHECK_ALLOC_NULL((yyval.func_fields)); + (yyval.func_fields)->type = WASM_FUNC_FIELD_TYPE_EXPRS; + (yyval.func_fields)->exprs = (yyvsp[0].exprs); + (yyval.func_fields)->next = NULL; } -#line 2530 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2440 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 61: -#line 534 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 542 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { - WASM_ZERO_MEMORY((yyval.type_bindings)); - WasmBinding* binding = - wasm_insert_binding(parser->allocator, &(yyval.type_bindings).bindings, &(yyvsp[-2].text)); - CHECK_ALLOC_NULL(binding); - binding->loc = (yylsp[-3]); - binding->index = (yyval.type_bindings).types.size; - CHECK_ALLOC(wasm_append_type_value(parser->allocator, &(yyval.type_bindings).types, &(yyvsp[-1].type))); + (yyval.func_fields) = new_func_field(parser->allocator); + (yyval.func_fields)->type = WASM_FUNC_FIELD_TYPE_PARAM_TYPES; + (yyval.func_fields)->types = (yyvsp[-2].types); + (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 2544 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2451 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 62: -#line 543 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 548 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { - (yyval.type_bindings) = (yyvsp[-4].type_bindings); - CHECK_ALLOC(wasm_extend_types(parser->allocator, &(yyval.type_bindings).types, &(yyvsp[-1].types))); - wasm_destroy_type_vector(parser->allocator, &(yyvsp[-1].types)); + (yyval.func_fields) = new_func_field(parser->allocator); + (yyval.func_fields)->type = WASM_FUNC_FIELD_TYPE_BOUND_PARAM; + (yyval.func_fields)->bound_type.loc = (yylsp[-4]); + (yyval.func_fields)->bound_type.name = (yyvsp[-3].text); + (yyval.func_fields)->bound_type.type = (yyvsp[-2].type); + (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 2554 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2464 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 63: -#line 548 "src/wasm-bison-parser.y" /* yacc.c:1646 */ +#line 556 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { - (yyval.type_bindings) = (yyvsp[-5].type_bindings); - WasmBinding* binding = - wasm_insert_binding(parser->allocator, &(yyval.type_bindings).bindings, &(yyvsp[-2].text)); - CHECK_ALLOC_NULL(binding); - binding->loc = (yylsp[-3]); - binding->index = (yyval.type_bindings).types.size; - CHECK_ALLOC(wasm_append_type_value(parser->allocator, &(yyval.type_bindings).types, &(yyvsp[-1].type))); + (yyval.func_fields) = new_func_field(parser->allocator); + (yyval.func_fields)->type = WASM_FUNC_FIELD_TYPE_RESULT_TYPE; + (yyval.func_fields)->result_type = (yyvsp[-2].type); + (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 2568 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2475 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; case 64: -#line 559 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { (yyval.type) = (yyvsp[-1].type); } -#line 2574 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 65: #line 562 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { - WASM_ZERO_MEMORY((yyval.type_bindings)); - CHECK_ALLOC(wasm_extend_types(parser->allocator, &(yyval.type_bindings).types, &(yyvsp[-1].types))); - wasm_destroy_type_vector(parser->allocator, &(yyvsp[-1].types)); + (yyval.func_fields) = new_func_field(parser->allocator); + (yyval.func_fields)->type = WASM_FUNC_FIELD_TYPE_LOCAL_TYPES; + (yyval.func_fields)->types = (yyvsp[-2].types); + (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 2584 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2486 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 66: -#line 567 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - WASM_ZERO_MEMORY((yyval.type_bindings)); - WasmBinding* binding = - wasm_insert_binding(parser->allocator, &(yyval.type_bindings).bindings, &(yyvsp[-2].text)); - CHECK_ALLOC_NULL(binding); - binding->loc = (yylsp[-3]); - binding->index = (yyval.type_bindings).types.size; - CHECK_ALLOC(wasm_append_type_value(parser->allocator, &(yyval.type_bindings).types, &(yyvsp[-1].type))); - } -#line 2598 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 67: -#line 576 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.type_bindings) = (yyvsp[-4].type_bindings); - CHECK_ALLOC(wasm_extend_types(parser->allocator, &(yyval.type_bindings).types, &(yyvsp[-1].types))); - wasm_destroy_type_vector(parser->allocator, &(yyvsp[-1].types)); - } -#line 2608 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 68: -#line 581 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 65: +#line 568 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { - (yyval.type_bindings) = (yyvsp[-5].type_bindings); - WasmBinding* binding = - wasm_insert_binding(parser->allocator, &(yyval.type_bindings).bindings, &(yyvsp[-2].text)); - CHECK_ALLOC_NULL(binding); - binding->loc = (yylsp[-3]); - binding->index = (yyval.type_bindings).types.size; - CHECK_ALLOC(wasm_append_type_value(parser->allocator, &(yyval.type_bindings).types, &(yyvsp[-1].type))); + (yyval.func_fields) = new_func_field(parser->allocator); + (yyval.func_fields)->type = WASM_FUNC_FIELD_TYPE_BOUND_LOCAL; + (yyval.func_fields)->bound_type.loc = (yylsp[-4]); + (yyval.func_fields)->bound_type.name = (yyvsp[-3].text); + (yyval.func_fields)->bound_type.type = (yyvsp[-2].type); + (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 2622 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2499 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 69: -#line 592 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 66: +#line 578 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.var) = (yyvsp[-1].var); } -#line 2628 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 70: -#line 595 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - } -#line 2637 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 71: -#line 599 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[0].text); - } -#line 2647 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 72: -#line 604 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE; - (yyval.func)->name = (yyvsp[-1].text); - (yyval.func)->type_var = (yyvsp[0].var); - } -#line 2658 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 73: -#line 610 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-2].text); - (yyval.func)->type_var = (yyvsp[-1].var); - (yyval.func)->params = (yyvsp[0].type_bindings); - } -#line 2670 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 74: -#line 617 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-3].text); - (yyval.func)->type_var = (yyvsp[-2].var); - (yyval.func)->params = (yyvsp[-1].type_bindings); - (yyval.func)->result_type = (yyvsp[0].type); - } -#line 2683 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 75: -#line 625 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-4].text); - (yyval.func)->type_var = (yyvsp[-3].var); - (yyval.func)->params = (yyvsp[-2].type_bindings); - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->locals = (yyvsp[0].type_bindings); - } -#line 2697 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 76: -#line 634 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-5].text); - (yyval.func)->type_var = (yyvsp[-4].var); - (yyval.func)->params = (yyvsp[-3].type_bindings); - (yyval.func)->result_type = (yyvsp[-2].type); - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 2712 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 77: -#line 644 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-4].text); - (yyval.func)->type_var = (yyvsp[-3].var); - (yyval.func)->params = (yyvsp[-2].type_bindings); - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 2726 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 78: -#line 653 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-3].text); - (yyval.func)->type_var = (yyvsp[-2].var); - (yyval.func)->params = (yyvsp[-1].type_bindings); - (yyval.func)->locals = (yyvsp[0].type_bindings); - } -#line 2739 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 79: -#line 661 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-4].text); - (yyval.func)->type_var = (yyvsp[-3].var); - (yyval.func)->params = (yyvsp[-2].type_bindings); - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 2753 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 80: -#line 670 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-3].text); - (yyval.func)->type_var = (yyvsp[-2].var); - (yyval.func)->params = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 2766 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 81: -#line 678 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-2].text); - (yyval.func)->type_var = (yyvsp[-1].var); - (yyval.func)->result_type = (yyvsp[0].type); - } -#line 2778 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 82: -#line 685 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-3].text); - (yyval.func)->type_var = (yyvsp[-2].var); - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->locals = (yyvsp[0].type_bindings); - } -#line 2791 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 83: -#line 693 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-4].text); - (yyval.func)->type_var = (yyvsp[-3].var); - (yyval.func)->result_type = (yyvsp[-2].type); - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 2805 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 84: -#line 702 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-3].text); - (yyval.func)->type_var = (yyvsp[-2].var); - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 2818 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 85: -#line 710 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE; - (yyval.func)->name = (yyvsp[-2].text); - (yyval.func)->type_var = (yyvsp[-1].var); - (yyval.func)->locals = (yyvsp[0].type_bindings); - } -#line 2830 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 86: -#line 717 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE; - (yyval.func)->name = (yyvsp[-3].text); - (yyval.func)->type_var = (yyvsp[-2].var); - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 2843 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2505 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 87: -#line 725 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 67: +#line 581 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE; - (yyval.func)->name = (yyvsp[-2].text); - (yyval.func)->type_var = (yyvsp[-1].var); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 2855 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; + CHECK_ALLOC_NULL((yyval.func)); + WasmFuncField* field = (yyvsp[0].func_fields); + while (field) { + WasmFuncField* next = field->next; - case 88: -#line 732 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-1].text); - (yyval.func)->locals = (yyvsp[0].type_bindings); - } -#line 2866 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; + if (field->type == WASM_FUNC_FIELD_TYPE_PARAM_TYPES || + field->type == WASM_FUNC_FIELD_TYPE_BOUND_PARAM || + field->type == WASM_FUNC_FIELD_TYPE_RESULT_TYPE) { + (yyval.func)->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE; + } - case 89: -#line 738 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-2].text); - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 2878 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; + switch (field->type) { + case WASM_FUNC_FIELD_TYPE_EXPRS: + (yyval.func)->exprs = field->exprs; + break; - case 90: -#line 745 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-1].text); - (yyval.func)->params = (yyvsp[0].type_bindings); - } -#line 2889 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; + case WASM_FUNC_FIELD_TYPE_PARAM_TYPES: + case WASM_FUNC_FIELD_TYPE_LOCAL_TYPES: { + WasmTypeVector* types = + field->type == WASM_FUNC_FIELD_TYPE_PARAM_TYPES + ? &(yyval.func)->decl.sig.param_types + : &(yyval.func)->local_types; + CHECK_ALLOC( + wasm_extend_types(parser->allocator, types, &field->types)); + wasm_destroy_type_vector(parser->allocator, &field->types); + break; + } - case 91: -#line 751 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-2].text); - (yyval.func)->params = (yyvsp[-1].type_bindings); - (yyval.func)->result_type = (yyvsp[0].type); - } -#line 2901 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; + case WASM_FUNC_FIELD_TYPE_BOUND_PARAM: + case WASM_FUNC_FIELD_TYPE_BOUND_LOCAL: { + WasmTypeVector* types; + WasmBindingHash* bindings; + if (field->type == WASM_FUNC_FIELD_TYPE_BOUND_PARAM) { + types = &(yyval.func)->decl.sig.param_types; + bindings = &(yyval.func)->param_bindings; + } else { + types = &(yyval.func)->local_types; + bindings = &(yyval.func)->local_bindings; + } - case 92: -#line 758 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-3].text); - (yyval.func)->params = (yyvsp[-2].type_bindings); - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->locals = (yyvsp[0].type_bindings); - } -#line 2914 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; + CHECK_ALLOC(wasm_append_type_value(parser->allocator, types, + &field->bound_type.type)); + WasmBinding* binding = wasm_insert_binding( + parser->allocator, bindings, &field->bound_type.name); + CHECK_ALLOC_NULL(binding); + binding->loc = field->bound_type.loc; + binding->index = types->size - 1; + break; + } - case 93: -#line 766 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-4].text); - (yyval.func)->params = (yyvsp[-3].type_bindings); - (yyval.func)->result_type = (yyvsp[-2].type); - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 2928 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; + case WASM_FUNC_FIELD_TYPE_RESULT_TYPE: + (yyval.func)->decl.sig.result_type = field->result_type; + break; + } - case 94: -#line 775 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-3].text); - (yyval.func)->params = (yyvsp[-2].type_bindings); - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->exprs = (yyvsp[0].exprs); + /* we steal memory from the func field, but not the linked list nodes */ + wasm_free(parser->allocator, field); + field = next; + } } -#line 2941 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2572 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 95: -#line 783 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 68: +#line 645 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-2].text); - (yyval.func)->params = (yyvsp[-1].type_bindings); - (yyval.func)->locals = (yyvsp[0].type_bindings); + (yyval.func) = (yyvsp[-1].func); + (yyval.func)->loc = (yylsp[-3]); + (yyval.func)->decl.flags |= WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + (yyval.func)->decl.type_var = (yyvsp[-2].var); } -#line 2953 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2583 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 96: -#line 790 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 69: +#line 651 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; + (yyval.func) = (yyvsp[-1].func); + (yyval.func)->loc = (yylsp[-4]); + (yyval.func)->decl.flags |= WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + (yyval.func)->decl.type_var = (yyvsp[-2].var); (yyval.func)->name = (yyvsp[-3].text); - (yyval.func)->params = (yyvsp[-2].type_bindings); - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); } -#line 2966 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2595 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 97: -#line 798 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-2].text); - (yyval.func)->params = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 2978 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 98: -#line 805 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-1].text); - (yyval.func)->result_type = (yyvsp[0].type); - } -#line 2989 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 99: -#line 811 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 70: +#line 658 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-2].text); - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->locals = (yyvsp[0].type_bindings); + (yyval.func) = (yyvsp[-1].func); + (yyval.func)->loc = (yylsp[-2]); + (yyval.func)->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE; } -#line 3001 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2605 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 100: -#line 818 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-3].text); - (yyval.func)->result_type = (yyvsp[-2].type); - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3014 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 101: -#line 826 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 71: +#line 663 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; + (yyval.func) = (yyvsp[-1].func); + (yyval.func)->loc = (yylsp[-3]); + (yyval.func)->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE; (yyval.func)->name = (yyvsp[-2].text); - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3026 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 102: -#line 833 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->name = (yyvsp[-1].text); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3037 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 103: -#line 839 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE; - (yyval.func)->type_var = (yyvsp[0].var); - } -#line 3047 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 104: -#line 844 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->type_var = (yyvsp[-1].var); - (yyval.func)->params = (yyvsp[0].type_bindings); - } -#line 3058 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 105: -#line 850 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->type_var = (yyvsp[-2].var); - (yyval.func)->params = (yyvsp[-1].type_bindings); - (yyval.func)->result_type = (yyvsp[0].type); - } -#line 3070 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 106: -#line 857 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->type_var = (yyvsp[-3].var); - (yyval.func)->params = (yyvsp[-2].type_bindings); - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->locals = (yyvsp[0].type_bindings); - } -#line 3083 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 107: -#line 865 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->type_var = (yyvsp[-4].var); - (yyval.func)->params = (yyvsp[-3].type_bindings); - (yyval.func)->result_type = (yyvsp[-2].type); - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3097 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 108: -#line 874 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->type_var = (yyvsp[-3].var); - (yyval.func)->params = (yyvsp[-2].type_bindings); - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3110 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 109: -#line 882 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->type_var = (yyvsp[-2].var); - (yyval.func)->params = (yyvsp[-1].type_bindings); - (yyval.func)->locals = (yyvsp[0].type_bindings); - } -#line 3122 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 110: -#line 889 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->type_var = (yyvsp[-3].var); - (yyval.func)->params = (yyvsp[-2].type_bindings); - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3135 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 111: -#line 897 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->type_var = (yyvsp[-2].var); - (yyval.func)->params = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3147 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 112: -#line 904 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->type_var = (yyvsp[-1].var); - (yyval.func)->result_type = (yyvsp[0].type); - } -#line 3158 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 113: -#line 910 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->type_var = (yyvsp[-2].var); - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->locals = (yyvsp[0].type_bindings); - } -#line 3170 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 114: -#line 917 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->type_var = (yyvsp[-3].var); - (yyval.func)->result_type = (yyvsp[-2].type); - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3183 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 115: -#line 925 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->type_var = (yyvsp[-2].var); - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3195 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 116: -#line 932 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE; - (yyval.func)->type_var = (yyvsp[-1].var); - (yyval.func)->locals = (yyvsp[0].type_bindings); - } -#line 3206 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 117: -#line 938 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE; - (yyval.func)->type_var = (yyvsp[-2].var); - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3218 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 118: -#line 945 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE; - (yyval.func)->type_var = (yyvsp[-1].var); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3229 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 119: -#line 951 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->params = (yyvsp[0].type_bindings); - } -#line 3239 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 120: -#line 956 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->params = (yyvsp[-1].type_bindings); - (yyval.func)->result_type = (yyvsp[0].type); } -#line 3250 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2616 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 121: -#line 962 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->params = (yyvsp[-2].type_bindings); - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->locals = (yyvsp[0].type_bindings); - } -#line 3262 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 122: -#line 969 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->params = (yyvsp[-3].type_bindings); - (yyval.func)->result_type = (yyvsp[-2].type); - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3275 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 123: -#line 977 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->params = (yyvsp[-2].type_bindings); - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3287 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 124: -#line 984 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->params = (yyvsp[-1].type_bindings); - (yyval.func)->locals = (yyvsp[0].type_bindings); - } -#line 3298 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 125: -#line 990 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->params = (yyvsp[-2].type_bindings); - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3310 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 126: -#line 997 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->params = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3321 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 127: -#line 1003 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->result_type = (yyvsp[0].type); - } -#line 3331 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 128: -#line 1008 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->locals = (yyvsp[0].type_bindings); - } -#line 3342 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 129: -#line 1014 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->result_type = (yyvsp[-2].type); - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3354 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 130: -#line 1021 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->result_type = (yyvsp[-1].type); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3365 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 131: -#line 1027 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->locals = (yyvsp[0].type_bindings); - } -#line 3375 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 132: -#line 1032 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->locals = (yyvsp[-1].type_bindings); - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3386 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 133: -#line 1038 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { - (yyval.func) = new_func(parser->allocator); - (yyval.func)->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - (yyval.func)->exprs = (yyvsp[0].exprs); - } -#line 3396 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 134: -#line 1045 "src/wasm-bison-parser.y" /* yacc.c:1646 */ - { (yyval.func) = (yyvsp[-1].func); (yyval.func)->loc = (yylsp[-2]); } -#line 3402 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ - break; - - case 135: -#line 1051 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 72: +#line 674 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.var) = (yyvsp[-1].var); } -#line 3408 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2622 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 136: -#line 1055 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 73: +#line 678 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { if (WASM_FAILED(wasm_parse_int32((yyvsp[0].literal).text.start, (yyvsp[0].literal).text.start + (yyvsp[0].literal).text.length, &(yyval.u32), @@ -3419,37 +2633,37 @@ yyreduce: WASM_PRINTF_STRING_SLICE_ARG((yyvsp[0].literal).text)); } } -#line 3423 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2637 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 137: -#line 1068 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 74: +#line 691 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.segment).loc = (yylsp[-3]); (yyval.segment).data = (yyvsp[-1].segment).data; (yyval.segment).size = (yyvsp[-1].segment).size; (yyval.segment).addr = (yyvsp[-2].u32); } -#line 3434 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2648 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 138: -#line 1076 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 75: +#line 699 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.segments)); } -#line 3440 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2654 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 139: -#line 1077 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 76: +#line 700 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.segments) = (yyvsp[-1].segments); CHECK_ALLOC(wasm_append_segment_value(parser->allocator, &(yyval.segments), &(yyvsp[0].segment))); } -#line 3449 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2663 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 140: -#line 1084 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 77: +#line 707 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { if (WASM_FAILED(wasm_parse_int32((yyvsp[0].literal).text.start, (yyvsp[0].literal).text.start + (yyvsp[0].literal).text.length, &(yyval.u32), @@ -3459,11 +2673,11 @@ yyreduce: WASM_PRINTF_STRING_SLICE_ARG((yyvsp[0].literal).text)); } } -#line 3463 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2677 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 141: -#line 1096 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 78: +#line 719 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { if (WASM_FAILED(wasm_parse_int32((yyvsp[0].literal).text.start, (yyvsp[0].literal).text.start + (yyvsp[0].literal).text.length, &(yyval.u32), @@ -3473,132 +2687,132 @@ yyreduce: WASM_PRINTF_STRING_SLICE_ARG((yyvsp[0].literal).text)); } } -#line 3477 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2691 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 142: -#line 1108 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 79: +#line 731 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.memory).loc = (yylsp[-4]); (yyval.memory).initial_pages = (yyvsp[-3].u32); (yyval.memory).max_pages = (yyvsp[-2].u32); (yyval.memory).segments = (yyvsp[-1].segments); } -#line 3488 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2702 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 143: -#line 1114 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 80: +#line 737 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.memory).loc = (yylsp[-3]); (yyval.memory).initial_pages = (yyvsp[-2].u32); (yyval.memory).max_pages = (yyval.memory).initial_pages; (yyval.memory).segments = (yyvsp[-1].segments); } -#line 3499 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2713 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 144: -#line 1123 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 81: +#line 746 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.func_type)); (yyval.func_type).sig = (yyvsp[-2].func_sig); } -#line 3508 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2722 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 145: -#line 1127 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 82: +#line 750 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.func_type).name = (yyvsp[-5].text); (yyval.func_type).sig = (yyvsp[-2].func_sig); } -#line 3517 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2731 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 146: -#line 1134 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 83: +#line 757 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.vars) = (yyvsp[-1].vars); } -#line 3523 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2737 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 147: -#line 1138 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 84: +#line 761 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.import) = new_import(parser->allocator); - (yyval.import)->import_type = WASM_IMPORT_HAS_TYPE; (yyval.import)->module_name = (yyvsp[-3].text); (yyval.import)->func_name = (yyvsp[-2].text); - (yyval.import)->type_var = (yyvsp[-1].var); + (yyval.import)->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + (yyval.import)->decl.type_var = (yyvsp[-1].var); } -#line 3535 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2749 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 148: -#line 1145 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 85: +#line 768 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.import) = new_import(parser->allocator); - (yyval.import)->import_type = WASM_IMPORT_HAS_TYPE; (yyval.import)->name = (yyvsp[-4].text); (yyval.import)->module_name = (yyvsp[-3].text); (yyval.import)->func_name = (yyvsp[-2].text); - (yyval.import)->type_var = (yyvsp[-1].var); + (yyval.import)->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + (yyval.import)->decl.type_var = (yyvsp[-1].var); } -#line 3548 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2762 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 149: -#line 1153 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 86: +#line 776 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.import) = new_import(parser->allocator); - (yyval.import)->import_type = WASM_IMPORT_HAS_FUNC_SIGNATURE; (yyval.import)->module_name = (yyvsp[-3].text); (yyval.import)->func_name = (yyvsp[-2].text); - (yyval.import)->func_sig = (yyvsp[-1].func_sig); + (yyval.import)->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE; + (yyval.import)->decl.sig = (yyvsp[-1].func_sig); } -#line 3560 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2774 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 150: -#line 1160 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 87: +#line 783 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.import) = new_import(parser->allocator); - (yyval.import)->import_type = WASM_IMPORT_HAS_FUNC_SIGNATURE; (yyval.import)->name = (yyvsp[-4].text); (yyval.import)->module_name = (yyvsp[-3].text); (yyval.import)->func_name = (yyvsp[-2].text); - (yyval.import)->func_sig = (yyvsp[-1].func_sig); + (yyval.import)->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE; + (yyval.import)->decl.sig = (yyvsp[-1].func_sig); } -#line 3573 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2787 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 151: -#line 1171 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 88: +#line 794 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.export_).name = (yyvsp[-2].text); (yyval.export_).var = (yyvsp[-1].var); } -#line 3582 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2796 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 152: -#line 1178 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 89: +#line 801 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.export_memory).name = (yyvsp[-2].text); } -#line 3590 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2804 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 153: -#line 1184 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 90: +#line 807 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.module) = new_module(parser->allocator); } -#line 3598 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2812 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 154: -#line 1187 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 91: +#line 810 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); @@ -3608,11 +2822,11 @@ yyreduce: field->func = *(yyvsp[0].func); wasm_free(parser->allocator, (yyvsp[0].func)); } -#line 3612 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2826 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 155: -#line 1196 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 92: +#line 819 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); @@ -3622,11 +2836,11 @@ yyreduce: field->import = *(yyvsp[0].import); wasm_free(parser->allocator, (yyvsp[0].import)); } -#line 3626 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2840 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 156: -#line 1205 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 93: +#line 828 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); @@ -3635,11 +2849,11 @@ yyreduce: field->type = WASM_MODULE_FIELD_TYPE_EXPORT; field->export_ = (yyvsp[0].export_); } -#line 3639 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2853 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 157: -#line 1213 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 94: +#line 836 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); @@ -3648,11 +2862,11 @@ yyreduce: field->type = WASM_MODULE_FIELD_TYPE_EXPORT_MEMORY; field->export_memory = (yyvsp[0].export_memory); } -#line 3652 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2866 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 158: -#line 1221 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 95: +#line 844 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); @@ -3661,11 +2875,11 @@ yyreduce: field->type = WASM_MODULE_FIELD_TYPE_TABLE; field->table = (yyvsp[0].vars); } -#line 3665 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2879 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 159: -#line 1229 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 96: +#line 852 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); @@ -3674,11 +2888,11 @@ yyreduce: field->type = WASM_MODULE_FIELD_TYPE_FUNC_TYPE; field->func_type = (yyvsp[0].func_type); } -#line 3678 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2892 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 160: -#line 1237 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 97: +#line 860 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); @@ -3687,11 +2901,11 @@ yyreduce: field->type = WASM_MODULE_FIELD_TYPE_MEMORY; field->memory = (yyvsp[0].memory); } -#line 3691 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2905 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 161: -#line 1245 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 98: +#line 868 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); @@ -3700,11 +2914,11 @@ yyreduce: field->type = WASM_MODULE_FIELD_TYPE_START; field->start = (yyvsp[0].var); } -#line 3704 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 2918 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 162: -#line 1255 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 99: +#line 878 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); (yyval.module)->loc = (yylsp[-2]); @@ -3782,46 +2996,35 @@ yyreduce: } } - /* if a function only defines a func type (and no explicit signature), - * copy the signature over for convenience */ size_t i; for (i = 0; i < (yyval.module)->funcs.size; ++i) { WasmFunc* func = (yyval.module)->funcs.data[i]; - if (func->flags == WASM_FUNC_FLAG_HAS_FUNC_TYPE) { - int index = wasm_get_func_type_index_by_var((yyval.module), &func->type_var); - if (index >= 0 && (size_t)index < (yyval.module)->func_types.size) { - WasmFuncType* func_type = (yyval.module)->func_types.data[index]; - func->result_type = func_type->sig.result_type; - CHECK_ALLOC(wasm_extend_types(parser->allocator, - &func->params.types, - &func_type->sig.param_types)); - } - } + CHECK_ALLOC( + copy_signature_from_func_type(parser->allocator, (yyval.module), &func->decl)); + } - /* now that func->params is set, we can easily create params_and_locals - * as well */ - CHECK_ALLOC(wasm_extend_type_bindings( - parser->allocator, &func->params_and_locals, &func->params)); - CHECK_ALLOC(wasm_extend_type_bindings( - parser->allocator, &func->params_and_locals, &func->locals)); + for (i = 0; i < (yyval.module)->imports.size; ++i) { + WasmImport* import = (yyval.module)->imports.data[i]; + CHECK_ALLOC(copy_signature_from_func_type(parser->allocator, (yyval.module), + &import->decl)); } } -#line 3810 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 3013 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 163: -#line 1362 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 100: +#line 974 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.command) = new_command(parser->allocator); (yyval.command)->type = WASM_COMMAND_TYPE_MODULE; (yyval.command)->module = *(yyvsp[0].module); wasm_free(parser->allocator, (yyvsp[0].module)); } -#line 3821 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 3024 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 164: -#line 1368 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 101: +#line 980 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.command) = new_command(parser->allocator); (yyval.command)->type = WASM_COMMAND_TYPE_INVOKE; @@ -3829,11 +3032,11 @@ yyreduce: (yyval.command)->invoke.name = (yyvsp[-2].text); (yyval.command)->invoke.args = (yyvsp[-1].consts); } -#line 3833 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 3036 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 165: -#line 1375 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 102: +#line 987 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.command) = new_command(parser->allocator); (yyval.command)->type = WASM_COMMAND_TYPE_ASSERT_INVALID; @@ -3841,11 +3044,11 @@ yyreduce: (yyval.command)->assert_invalid.text = (yyvsp[-1].text); wasm_free(parser->allocator, (yyvsp[-2].module)); } -#line 3845 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 3048 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 166: -#line 1382 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 103: +#line 994 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.command) = new_command(parser->allocator); (yyval.command)->type = WASM_COMMAND_TYPE_ASSERT_RETURN; @@ -3854,11 +3057,11 @@ yyreduce: (yyval.command)->assert_return.invoke.args = (yyvsp[-3].consts); (yyval.command)->assert_return.expected = (yyvsp[-1].const_); } -#line 3858 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 3061 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 167: -#line 1390 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 104: +#line 1002 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.command) = new_command(parser->allocator); (yyval.command)->type = WASM_COMMAND_TYPE_ASSERT_RETURN_NAN; @@ -3866,11 +3069,11 @@ yyreduce: (yyval.command)->assert_return_nan.invoke.name = (yyvsp[-3].text); (yyval.command)->assert_return_nan.invoke.args = (yyvsp[-2].consts); } -#line 3870 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 3073 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 168: -#line 1397 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 105: +#line 1009 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.command) = new_command(parser->allocator); (yyval.command)->type = WASM_COMMAND_TYPE_ASSERT_TRAP; @@ -3879,27 +3082,27 @@ yyreduce: (yyval.command)->assert_trap.invoke.args = (yyvsp[-3].consts); (yyval.command)->assert_trap.text = (yyvsp[-1].text); } -#line 3883 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 3086 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 169: -#line 1407 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 106: +#line 1019 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.commands)); } -#line 3889 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 3092 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 170: -#line 1408 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 107: +#line 1020 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.commands) = (yyvsp[-1].commands); CHECK_ALLOC(wasm_append_command_value(parser->allocator, &(yyval.commands), (yyvsp[0].command))); wasm_free(parser->allocator, (yyvsp[0].command)); } -#line 3899 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 3102 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 171: -#line 1416 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 108: +#line 1028 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.const_).loc = (yylsp[-2]); if (WASM_FAILED(parse_const((yyvsp[-2].type), (yyvsp[-1].literal).type, (yyvsp[-1].literal).text.start, @@ -3910,41 +3113,41 @@ yyreduce: } wasm_free(parser->allocator, (char*)(yyvsp[-1].literal).text.start); } -#line 3914 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 3117 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 172: -#line 1428 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 109: +#line 1040 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.const_).type = WASM_TYPE_VOID; } -#line 3920 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 3123 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 174: -#line 1432 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 111: +#line 1044 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.consts)); } -#line 3926 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 3129 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 175: -#line 1433 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 112: +#line 1045 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.consts) = (yyvsp[-1].consts); CHECK_ALLOC(wasm_append_const_value(parser->allocator, &(yyval.consts), &(yyvsp[0].const_))); } -#line 3935 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 3138 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; - case 176: -#line 1440 "src/wasm-bison-parser.y" /* yacc.c:1646 */ + case 113: +#line 1052 "src/wasm-bison-parser.y" /* yacc.c:1646 */ { (yyval.script).commands = (yyvsp[0].commands); parser->script = (yyval.script); } -#line 3944 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 3147 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ break; -#line 3948 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ +#line 3151 "src/prebuilt/wasm-bison-parser.c" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -4179,7 +3382,7 @@ yyreturn: #endif return yyresult; } -#line 1452 "src/wasm-bison-parser.y" /* yacc.c:1906 */ +#line 1064 "src/wasm-bison-parser.y" /* yacc.c:1906 */ void wasm_parser_error(WasmLocation* loc, @@ -4322,3 +3525,24 @@ WasmExpr* new_block_expr_with_list(WasmAllocator* allocator, block->block.exprs = *exprs; return block; } + +WasmResult copy_signature_from_func_type(WasmAllocator* allocator, + WasmModule* module, + WasmFuncDeclaration* decl) { + /* if a function or import only defines a func type (and no explicit + * signature), copy the signature over for convenience */ + if (wasm_decl_has_func_type(decl) && !wasm_decl_has_signature(decl)) { + int index = wasm_get_func_type_index_by_var(module, &decl->type_var); + if (index >= 0 && (size_t)index < module->func_types.size) { + WasmFuncType* func_type = module->func_types.data[index]; + decl->sig.result_type = func_type->sig.result_type; + return wasm_extend_types(allocator, &decl->sig.param_types, + &func_type->sig.param_types); + } else { + /* technically not OK, but we'll catch this error later in the AST + * checker */ + return WASM_OK; + } + } + return WASM_OK; +} diff --git a/src/wasm-ast-checker.c b/src/wasm-ast-checker.c index cc12f4c6..2b000680 100644 --- a/src/wasm-ast-checker.c +++ b/src/wasm-ast-checker.c @@ -223,11 +223,11 @@ static WasmResult check_local_var(WasmContext* ctx, int index = wasm_get_local_index_by_var(func, var); if (index >= 0 && index < max_index) { if (out_type) { - int num_params = func->params.types.size; + int num_params = wasm_get_num_params(func); if (index < num_params) { - *out_type = func->params.types.data[index]; + *out_type = wasm_get_param_type(func, index); } else { - *out_type = func->locals.types.data[index - num_params]; + *out_type = func->local_types.data[index - num_params]; } } return WASM_OK; @@ -411,21 +411,20 @@ static void check_call(WasmContext* ctx, const WasmLocation* loc, const WasmModule* module, const WasmFunc* func, - const WasmTypeVector* param_types, - WasmType result_type, + const WasmFuncSignature* sig, const WasmExprPtrVector* args, WasmType expected_type, const char* desc) { size_t actual_args = args->size; - size_t expected_args = param_types->size; + size_t expected_args = sig->param_types.size; if (expected_args == actual_args) { char buffer[100]; wasm_snprintf(buffer, 100, " of %s result", desc); - check_type(ctx, loc, result_type, expected_type, buffer); + check_type(ctx, loc, sig->result_type, expected_type, buffer); size_t i; for (i = 0; i < actual_args; ++i) { wasm_snprintf(buffer, 100, " of argument %" PRIzd " of %s", i, desc); - check_expr(ctx, module, func, args->data[i], param_types->data[i], + check_expr(ctx, module, func, args->data[i], sig->param_types.data[i], buffer); } } else { @@ -506,25 +505,11 @@ static void check_expr(WasmContext* ctx, const WasmFunc* callee; if (WASM_SUCCEEDED( check_func_var(ctx, module, &expr->call.var, &callee))) { - const WasmTypeVector* param_types = NULL; - WasmType result_type = WASM_TYPE_VOID; - if (callee->flags & WASM_FUNC_FLAG_HAS_FUNC_TYPE) { - const WasmFuncType* func_type; - if (WASM_SUCCEEDED(check_func_type_var(ctx, module, &callee->type_var, - &func_type))) { - param_types = &func_type->sig.param_types; - result_type = func_type->sig.result_type; - } - } else { - assert(callee->flags & WASM_FUNC_FLAG_HAS_SIGNATURE); - param_types = &callee->params.types; - result_type = callee->result_type; - } + if (wasm_decl_has_func_type(&callee->decl)) + check_func_type_var(ctx, module, &callee->decl.type_var, NULL); - if (param_types) { - check_call(ctx, &expr->loc, module, func, param_types, result_type, - &expr->call.args, expected_type, "call"); - } + check_call(ctx, &expr->loc, module, func, &callee->decl.sig, + &expr->call.args, expected_type, "call"); } break; } @@ -533,22 +518,11 @@ static void check_expr(WasmContext* ctx, const WasmImport* import; if (WASM_SUCCEEDED( check_import_var(ctx, module, &expr->call.var, &import))) { - const WasmFuncSignature* sig = NULL; - if (import->import_type == WASM_IMPORT_HAS_TYPE) { - const WasmFuncType* func_type; - if (WASM_SUCCEEDED(check_func_type_var(ctx, module, &import->type_var, - &func_type))) { - sig = &func_type->sig; - } - } else { - assert(import->import_type == WASM_IMPORT_HAS_FUNC_SIGNATURE); - sig = &import->func_sig; - } - if (sig) { - check_call(ctx, &expr->loc, module, func, &sig->param_types, - sig->result_type, &expr->call.args, expected_type, - "call_import"); - } + if (wasm_decl_has_func_type(&import->decl)) + check_func_type_var(ctx, module, &import->decl.type_var, NULL); + + check_call(ctx, &expr->loc, module, func, &import->decl.sig, + &expr->call.args, expected_type, "call_import"); } break; } @@ -559,10 +533,8 @@ static void check_expr(WasmContext* ctx, const WasmFuncType* func_type; if (WASM_SUCCEEDED(check_func_type_var( ctx, module, &expr->call_indirect.var, &func_type))) { - const WasmFuncSignature* sig = &func_type->sig; - check_call(ctx, &expr->loc, module, func, &sig->param_types, - sig->result_type, &expr->call_indirect.args, expected_type, - "call_indirect"); + check_call(ctx, &expr->loc, module, func, &func_type->sig, + &expr->call_indirect.args, expected_type, "call_indirect"); } break; } @@ -660,20 +632,22 @@ static void check_expr(WasmContext* ctx, check_type(ctx, &expr->loc, WASM_TYPE_VOID, expected_type, " in nop"); break; - case WASM_EXPR_TYPE_RETURN: + case WASM_EXPR_TYPE_RETURN: { + WasmType result_type = wasm_get_result_type(func); if (expr->return_.expr) { - if (func->result_type == WASM_TYPE_VOID) { + if (result_type == WASM_TYPE_VOID) { print_error(ctx, &expr->loc, "arity mismatch of return. function expects void, but " "return value is non-empty"); } else { - check_expr(ctx, module, func, expr->return_.expr, func->result_type, + check_expr(ctx, module, func, expr->return_.expr, result_type, " of return"); } } else { - check_type(ctx, &expr->loc, WASM_TYPE_VOID, func->result_type, desc); + check_type(ctx, &expr->loc, WASM_TYPE_VOID, result_type, desc); } break; + } case WASM_EXPR_TYPE_SELECT: check_expr(ctx, module, func, expr->select.cond, WASM_TYPE_I32, @@ -734,35 +708,42 @@ static void check_expr(WasmContext* ctx, } } +static void check_func_signature_matches_func_type( + WasmContext* ctx, + const WasmFunc* func, + const WasmFuncType* func_type) { + size_t num_params = wasm_get_num_params(func); + check_type_exact(ctx, &func->loc, wasm_get_result_type(func), + wasm_get_func_type_result_type(func_type), ""); + if (num_params == wasm_get_func_type_num_params(func_type)) { + size_t i; + for (i = 0; i < num_params; ++i) { + check_type_arg_exact(ctx, &func->loc, wasm_get_param_type(func, i), + wasm_get_func_type_param_type(func_type, i), + "function", i); + } + } else { + print_error(ctx, &func->loc, "expected %d parameters, got %d", + wasm_get_func_type_num_params(func_type), num_params); + } +} + static void check_func(WasmContext* ctx, const WasmModule* module, const WasmLocation* loc, const WasmFunc* func) { - if (func->flags & WASM_FUNC_FLAG_HAS_FUNC_TYPE) { + if (wasm_decl_has_func_type(&func->decl)) { const WasmFuncType* func_type; - if (WASM_SUCCEEDED( - check_func_type_var(ctx, module, &func->type_var, &func_type))) { - if (func->flags & WASM_FUNC_FLAG_HAS_SIGNATURE) { - check_type_exact(ctx, &func->loc, func->result_type, - func_type->sig.result_type, ""); - if (func->params.types.size == func_type->sig.param_types.size) { - size_t i; - for (i = 0; i < func->params.types.size; ++i) { - check_type_arg_exact(ctx, &func->loc, func->params.types.data[i], - func_type->sig.param_types.data[i], "function", - i); - } - } else { - print_error(ctx, &func->loc, "expected %d parameters, got %d", - func_type->sig.param_types.size, func->params.types.size); - } - } + if (WASM_SUCCEEDED(check_func_type_var(ctx, module, &func->decl.type_var, + &func_type))) { + if (wasm_decl_has_signature(&func->decl)) + check_func_signature_matches_func_type(ctx, func, func_type); } } - check_duplicate_bindings(ctx, &func->params.bindings, "parameter"); - check_duplicate_bindings(ctx, &func->locals.bindings, "local"); - check_exprs(ctx, module, func, &func->exprs, func->result_type, + check_duplicate_bindings(ctx, &func->param_bindings, "parameter"); + check_duplicate_bindings(ctx, &func->local_bindings, "local"); + check_exprs(ctx, module, func, &func->exprs, wasm_get_result_type(func), " of function result"); } @@ -770,8 +751,8 @@ static void check_import(WasmContext* ctx, const WasmModule* module, const WasmLocation* loc, const WasmImport* import) { - if (import->import_type == WASM_IMPORT_HAS_TYPE) - check_func_type_var(ctx, module, &import->type_var, NULL); + if (wasm_decl_has_func_type(&import->decl)) + check_func_type_var(ctx, module, &import->decl.type_var, NULL); } static void check_export(WasmContext* ctx, @@ -872,10 +853,10 @@ static void check_module(WasmContext* ctx, const WasmModule* module) { const WasmFunc* start_func = NULL; check_func_var(ctx, module, &field->start, &start_func); if (start_func) { - if (start_func->params.types.size != 0) + if (wasm_get_num_params(start_func) != 0) print_error(ctx, &field->loc, "start function must be nullary"); - if (start_func->result_type != WASM_TYPE_VOID) { + if (wasm_get_result_type(start_func) != WASM_TYPE_VOID) { print_error(ctx, &field->loc, "start function must not return anything"); } @@ -919,7 +900,7 @@ static void check_invoke(WasmContext* ctx, } size_t actual_args = invoke->args.size; - size_t expected_args = func->params.types.size; + size_t expected_args = wasm_get_num_params(func); if (expected_args != actual_args) { print_error(ctx, &invoke->loc, "too %s parameters to function. got %d, expected %d", @@ -927,12 +908,13 @@ static void check_invoke(WasmContext* ctx, expected_args); return; } - check_type_set(ctx, &invoke->loc, func->result_type, return_type, ""); + check_type_set(ctx, &invoke->loc, wasm_get_result_type(func), return_type, + ""); size_t i; for (i = 0; i < actual_args; ++i) { WasmConst* const_ = &invoke->args.data[i]; check_type_arg_exact(ctx, &const_->loc, const_->type, - func->params.types.data[i], "invoke", i); + wasm_get_param_type(func, i), "invoke", i); } } diff --git a/src/wasm-ast-writer.c b/src/wasm-ast-writer.c index 72899217..00c5d59b 100644 --- a/src/wasm-ast-writer.c +++ b/src/wasm-ast-writer.c @@ -614,9 +614,10 @@ static void write_exprs(WasmContext* ctx, const WasmExprPtrVector* exprs) { static void write_type_bindings(WasmContext* ctx, const char* prefix, const WasmFunc* func, - const WasmTypeBindings* type_bindings) { + const WasmTypeVector* types, + const WasmBindingHash* bindings) { CHECK_ALLOC(ctx, wasm_make_type_binding_reverse_mapping( - ctx->allocator, type_bindings, &ctx->index_to_name)); + ctx->allocator, types, bindings, &ctx->index_to_name)); /* named params/locals must be specified by themselves, but nameless * params/locals can be compressed, e.g.: @@ -625,7 +626,7 @@ static void write_type_bindings(WasmContext* ctx, */ WasmBool is_open = WASM_FALSE; size_t i; - for (i = 0; i < type_bindings->types.size; ++i) { + for (i = 0; i < types->size; ++i) { if (!is_open) { out_open_space(ctx, prefix); is_open = WASM_TRUE; @@ -635,7 +636,7 @@ static void write_type_bindings(WasmContext* ctx, WasmBool has_name = name->start != NULL; if (has_name) out_string_slice(ctx, name, WASM_NEXT_CHAR_SPACE); - out_type(ctx, type_bindings->types.data[i], WASM_NEXT_CHAR_SPACE); + out_type(ctx, types->data[i], WASM_NEXT_CHAR_SPACE); if (has_name) { out_close_space(ctx); is_open = WASM_FALSE; @@ -652,26 +653,24 @@ static void write_func(WasmContext* ctx, out_open_space(ctx, "func"); out_printf(ctx, "(; %d ;)", func_index); out_string_slice_opt(ctx, &func->name, WASM_NEXT_CHAR_SPACE); - uint32_t num_params = 0; - if (func->flags & WASM_FUNC_FLAG_HAS_FUNC_TYPE) { - num_params = - module->func_types.data[func->type_var.index]->sig.param_types.size; + if (wasm_decl_has_func_type(&func->decl)) { out_open_space(ctx, "type"); - out_var(ctx, &func->type_var, WASM_NEXT_CHAR_NONE); + out_var(ctx, &func->decl.type_var, WASM_NEXT_CHAR_NONE); out_close_space(ctx); } - if (func->flags & WASM_FUNC_FLAG_HAS_SIGNATURE) { - num_params = func->params.types.size; - write_type_bindings(ctx, "param", func, &func->params); - if (func->result_type != WASM_TYPE_VOID) { + if (wasm_decl_has_signature(&func->decl)) { + write_type_bindings(ctx, "param", func, &func->decl.sig.param_types, + &func->param_bindings); + if (wasm_get_result_type(func) != WASM_TYPE_VOID) { out_open_space(ctx, "result"); - out_type(ctx, func->result_type, WASM_NEXT_CHAR_NONE); + out_type(ctx, wasm_get_result_type(func), WASM_NEXT_CHAR_NONE); out_close_space(ctx); } } out_newline(ctx, NO_FORCE_NEWLINE); - if (func->locals.types.size) { - write_type_bindings(ctx, "local", func, &func->locals); + if (func->local_types.size) { + write_type_bindings(ctx, "local", func, &func->local_types, + &func->local_bindings); } out_newline(ctx, NO_FORCE_NEWLINE); write_exprs(ctx, &func->exprs); @@ -686,12 +685,12 @@ static void write_import(WasmContext* ctx, out_string_slice_opt(ctx, &import->name, WASM_NEXT_CHAR_SPACE); out_quoted_string_slice(ctx, &import->module_name, WASM_NEXT_CHAR_SPACE); out_quoted_string_slice(ctx, &import->func_name, WASM_NEXT_CHAR_SPACE); - if (import->import_type == WASM_IMPORT_HAS_TYPE) { + if (wasm_decl_has_func_type(&import->decl)) { out_open_space(ctx, "type"); - out_var(ctx, &import->type_var, WASM_NEXT_CHAR_NONE); + out_var(ctx, &import->decl.type_var, WASM_NEXT_CHAR_NONE); out_close_space(ctx); } else { - out_func_sig_space(ctx, &import->func_sig); + out_func_sig_space(ctx, &import->decl.sig); } out_close_newline(ctx); } diff --git a/src/wasm-ast.c b/src/wasm-ast.c index 917c4a06..e07b9c02 100644 --- a/src/wasm-ast.c +++ b/src/wasm-ast.c @@ -203,16 +203,12 @@ int wasm_get_local_index_by_var(const WasmFunc* func, const WasmVar* var) { if (var->type == WASM_VAR_TYPE_INDEX) return var->index; - int result = find_binding_index_by_name(&func->params.bindings, &var->name); + int result = find_binding_index_by_name(&func->param_bindings, &var->name); if (result != -1) return result; /* the locals start after all the params */ - return func->params.types.size + - find_binding_index_by_name(&func->locals.bindings, &var->name); -} - -size_t wasm_get_num_params_and_locals(const WasmFunc* func) { - return func->params.types.size + func->locals.types.size; + return func->decl.sig.param_types.size + + find_binding_index_by_name(&func->local_bindings, &var->name); } WasmFuncPtr wasm_get_func_by_var(const WasmModule* module, const WasmVar* var) { @@ -238,35 +234,12 @@ WasmImportPtr wasm_get_import_by_var(const WasmModule* module, return module->imports.data[index]; } -WasmResult wasm_extend_type_bindings(WasmAllocator* allocator, - WasmTypeBindings* dst, - WasmTypeBindings* src) { - size_t last_type = dst->types.size; - if (WASM_FAILED(wasm_extend_types(allocator, &dst->types, &src->types))) - return WASM_ERROR; - - size_t i; - for (i = 0; i < src->bindings.entries.capacity; ++i) { - WasmBindingHashEntry* src_entry = &src->bindings.entries.data[i]; - if (wasm_hash_entry_is_free(src_entry)) - continue; - - WasmBinding* dst_binding = wasm_insert_binding(allocator, &dst->bindings, - &src_entry->binding.name); - if (!dst_binding) - return WASM_ERROR; - - *dst_binding = src_entry->binding; - dst_binding->index += last_type; /* fixup the binding index */ - } - return WASM_OK; -} - WasmResult wasm_make_type_binding_reverse_mapping( struct WasmAllocator* allocator, - const WasmTypeBindings* type_bindings, + const WasmTypeVector* types, + const WasmBindingHash* bindings, WasmStringSliceVector* out_reverse_mapping) { - uint32_t num_names = type_bindings->types.size; + uint32_t num_names = types->size; if (WASM_FAILED(wasm_reserve_string_slices(allocator, out_reverse_mapping, num_names))) { return WASM_ERROR; @@ -276,9 +249,8 @@ WasmResult wasm_make_type_binding_reverse_mapping( /* map index to name */ size_t i; - for (i = 0; i < type_bindings->bindings.entries.capacity; ++i) { - const WasmBindingHashEntry* entry = - &type_bindings->bindings.entries.data[i]; + for (i = 0; i < bindings->entries.capacity; ++i) { + const WasmBindingHashEntry* entry = &bindings->entries.data[i]; if (wasm_hash_entry_is_free(entry)) continue; @@ -367,12 +339,6 @@ static void wasm_destroy_binding_hash(WasmAllocator* allocator, wasm_destroy_binding_hash_entry_vector(allocator, &hash->entries); } -void wasm_destroy_type_bindings(WasmAllocator* allocator, - WasmTypeBindings* type_bindings) { - wasm_destroy_type_vector(allocator, &type_bindings->types); - wasm_destroy_binding_hash(allocator, &type_bindings->bindings); -} - void wasm_destroy_var(WasmAllocator* allocator, WasmVar* var) { if (var->type == WASM_VAR_TYPE_NAME) wasm_destroy_string_slice(allocator, &var->name); @@ -496,11 +462,18 @@ void wasm_destroy_expr_ptr_vector_and_elements(WasmAllocator* allocator, WASM_DESTROY_VECTOR_AND_ELEMENTS(allocator, *exprs, expr_ptr); } +void wasm_destroy_func_declaration(WasmAllocator* allocator, + WasmFuncDeclaration* decl) { + wasm_destroy_var(allocator, &decl->type_var); + wasm_destroy_func_signature(allocator, &decl->sig); +} + void wasm_destroy_func(WasmAllocator* allocator, WasmFunc* func) { wasm_destroy_string_slice(allocator, &func->name); - wasm_destroy_var(allocator, &func->type_var); - wasm_destroy_type_bindings(allocator, &func->params); - wasm_destroy_type_bindings(allocator, &func->locals); + wasm_destroy_func_declaration(allocator, &func->decl); + wasm_destroy_type_vector(allocator, &func->local_types); + wasm_destroy_binding_hash(allocator, &func->param_bindings); + wasm_destroy_binding_hash(allocator, &func->local_bindings); WASM_DESTROY_VECTOR_AND_ELEMENTS(allocator, func->exprs, expr_ptr); } @@ -508,8 +481,7 @@ void wasm_destroy_import(WasmAllocator* allocator, WasmImport* import) { wasm_destroy_string_slice(allocator, &import->name); wasm_destroy_string_slice(allocator, &import->module_name); wasm_destroy_string_slice(allocator, &import->func_name); - wasm_destroy_var(allocator, &import->type_var); - wasm_destroy_func_signature(allocator, &import->func_sig); + wasm_destroy_func_declaration(allocator, &import->decl); } void wasm_destroy_export(WasmAllocator* allocator, WasmExport* export) { diff --git a/src/wasm-ast.h b/src/wasm-ast.h index 7adf5e5c..6217b7f8 100644 --- a/src/wasm-ast.h +++ b/src/wasm-ast.h @@ -17,6 +17,7 @@ #ifndef WASM_AST_H_ #define WASM_AST_H_ +#include <assert.h> #include <stddef.h> #include <stdint.h> @@ -167,11 +168,6 @@ typedef struct WasmBoundType { WasmType type; } WasmBoundType; -typedef struct WasmTypeBindings { - WasmTypeVector types; - WasmBindingHash bindings; -} WasmTypeBindings; - /* only used for parsing */ typedef enum WasmFuncFieldType { WASM_FUNC_FIELD_TYPE_EXPRS, @@ -193,25 +189,52 @@ typedef struct WasmFuncField { struct WasmFuncField* next; } WasmFuncField; +typedef struct WasmFuncSignature { + WasmType result_type; + WasmTypeVector param_types; +} WasmFuncSignature; + +typedef struct WasmFuncType { + WasmStringSlice name; + WasmFuncSignature sig; +} WasmFuncType; +typedef WasmFuncType* WasmFuncTypePtr; +WASM_DEFINE_VECTOR(func_type_ptr, WasmFuncTypePtr); + enum { - WASM_FUNC_FLAG_HAS_FUNC_TYPE = 1, - WASM_FUNC_FLAG_HAS_SIGNATURE = 2, + WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE = 1, + WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE = 2, }; -typedef uint32_t WasmFuncFlags; +typedef uint32_t WasmFuncDeclarationFlags; + +typedef struct WasmFuncDeclaration { + WasmFuncDeclarationFlags flags; + WasmVar type_var; + WasmFuncSignature sig; +} WasmFuncDeclaration; typedef struct WasmFunc { WasmLocation loc; - WasmFuncFlags flags; WasmStringSlice name; - WasmVar type_var; - WasmTypeBindings params; - WasmType result_type; - WasmTypeBindings locals; + WasmFuncDeclaration decl; + WasmTypeVector local_types; + WasmBindingHash param_bindings; + WasmBindingHash local_bindings; WasmExprPtrVector exprs; } WasmFunc; typedef WasmFunc* WasmFuncPtr; WASM_DEFINE_VECTOR(func_ptr, WasmFuncPtr); +typedef struct WasmImport { + WasmLocation loc; + WasmStringSlice name; + WasmStringSlice module_name; + WasmStringSlice func_name; + WasmFuncDeclaration decl; +} WasmImport; +typedef WasmImport* WasmImportPtr; +WASM_DEFINE_VECTOR(import_ptr, WasmImportPtr); + typedef struct WasmSegment { WasmLocation loc; uint32_t addr; @@ -227,35 +250,6 @@ typedef struct WasmMemory { WasmSegmentVector segments; } WasmMemory; -typedef struct WasmFuncSignature { - WasmType result_type; - WasmTypeVector param_types; -} WasmFuncSignature; - -typedef struct WasmFuncType { - WasmStringSlice name; - WasmFuncSignature sig; -} WasmFuncType; -typedef WasmFuncType* WasmFuncTypePtr; -WASM_DEFINE_VECTOR(func_type_ptr, WasmFuncTypePtr); - -typedef enum WasmImportType { - WASM_IMPORT_HAS_TYPE, - WASM_IMPORT_HAS_FUNC_SIGNATURE, -} WasmImportType; - -typedef struct WasmImport { - WasmLocation loc; - WasmImportType import_type; - WasmStringSlice name; - WasmStringSlice module_name; - WasmStringSlice func_name; - WasmVar type_var; - WasmFuncSignature func_sig; -} WasmImport; -typedef WasmImport* WasmImportPtr; -WASM_DEFINE_VECTOR(import_ptr, WasmImportPtr); - typedef struct WasmExport { WasmStringSlice name; WasmVar var; @@ -442,6 +436,7 @@ void wasm_destroy_export(struct WasmAllocator*, WasmExport*); void wasm_destroy_expr_ptr_vector_and_elements(struct WasmAllocator*, WasmExprPtrVector*); void wasm_destroy_expr_ptr(struct WasmAllocator*, WasmExprPtr*); +void wasm_destroy_func_declaration(WasmAllocator*, WasmFuncDeclaration*); void wasm_destroy_func_fields(struct WasmAllocator*, WasmFuncField*); void wasm_destroy_func_signature(struct WasmAllocator*, WasmFuncSignature*); void wasm_destroy_func_type(struct WasmAllocator*, WasmFuncType*); @@ -452,7 +447,6 @@ void wasm_destroy_module(struct WasmAllocator*, WasmModule*); void wasm_destroy_segment_vector_and_elements(struct WasmAllocator*, WasmSegmentVector*); void wasm_destroy_segment(struct WasmAllocator*, WasmSegment*); -void wasm_destroy_type_bindings(struct WasmAllocator*, WasmTypeBindings*); void wasm_destroy_var_vector_and_elements(struct WasmAllocator*, WasmVarVector*); void wasm_destroy_var(struct WasmAllocator*, WasmVar*); @@ -468,7 +462,6 @@ int wasm_get_func_type_index_by_var(const WasmModule* module, const WasmVar* var); int wasm_get_import_index_by_var(const WasmModule* module, const WasmVar* var); int wasm_get_local_index_by_var(const WasmFunc* func, const WasmVar* var); -size_t wasm_get_num_params_and_locals(const WasmFunc* func); WasmFuncPtr wasm_get_func_by_var(const WasmModule* module, const WasmVar* var); WasmFuncTypePtr wasm_get_func_type_by_var(const WasmModule* module, @@ -478,13 +471,56 @@ WasmImportPtr wasm_get_import_by_var(const WasmModule* module, WasmExportPtr wasm_get_export_by_name(const WasmModule* module, const WasmStringSlice* name); -WasmResult wasm_extend_type_bindings(struct WasmAllocator*, - WasmTypeBindings* dst, - WasmTypeBindings* src) WASM_WARN_UNUSED; WasmResult wasm_make_type_binding_reverse_mapping( struct WasmAllocator*, - const WasmTypeBindings*, + const WasmTypeVector*, + const WasmBindingHash*, WasmStringSliceVector* out_reverse_mapping); + +static WASM_INLINE WasmBool +wasm_decl_has_func_type(const WasmFuncDeclaration* decl) { + return decl->flags & WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; +} + +static WASM_INLINE WasmBool +wasm_decl_has_signature(const WasmFuncDeclaration* decl) { + return decl->flags & WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE; +} + + +static WASM_INLINE size_t wasm_get_num_params(const WasmFunc* func) { + return func->decl.sig.param_types.size; +} + +static WASM_INLINE size_t wasm_get_num_params_and_locals(const WasmFunc* func) { + return wasm_get_num_params(func) + func->local_types.size; +} + +static WASM_INLINE WasmType wasm_get_param_type(const WasmFunc* func, + int index) { + assert((size_t)index < wasm_get_num_params(func)); + return func->decl.sig.param_types.data[index]; +} + +static WASM_INLINE WasmType wasm_get_result_type(const WasmFunc* func) { + return func->decl.sig.result_type; +} + +static WASM_INLINE WasmType +wasm_get_func_type_result_type(const WasmFuncType* func_type) { + return func_type->sig.result_type; +} + +static WASM_INLINE WasmType +wasm_get_func_type_param_type(const WasmFuncType* func_type, int index) { + return func_type->sig.param_types.data[index]; +} + +static WASM_INLINE size_t +wasm_get_func_type_num_params(const WasmFuncType* func_type) { + return func_type->sig.param_types.size; +} + WASM_EXTERN_C_END #endif /* WASM_AST_H_ */ diff --git a/src/wasm-binary-reader-ast.c b/src/wasm-binary-reader-ast.c index feeab288..3e37f81e 100644 --- a/src/wasm-binary-reader-ast.c +++ b/src/wasm-binary-reader-ast.c @@ -54,7 +54,7 @@ #define CHECK_LOCAL(ctx, local_index) \ do { \ - assert((ctx)->current_func->flags& WASM_FUNC_FLAG_HAS_FUNC_TYPE); \ + assert(wasm_decl_has_func_type(&(ctx)->current_func->decl)); \ uint32_t max_local_index = \ wasm_get_num_params_and_locals((ctx)->current_func); \ if ((local_index) >= max_local_index) { \ @@ -268,14 +268,14 @@ static WasmResult on_import(uint32_t index, WasmImport* import = &field->import; WASM_ZERO_MEMORY(*import); - import->import_type = WASM_IMPORT_HAS_TYPE; + import->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; CHECK_ALLOC_NULL_STR(ctx, import->module_name = wasm_dup_string_slice( ctx->allocator, module_name)); CHECK_ALLOC_NULL_STR(ctx, import->func_name = wasm_dup_string_slice( ctx->allocator, function_name)); - import->type_var.type = WASM_VAR_TYPE_INDEX; + import->decl.type_var.type = WASM_VAR_TYPE_INDEX; assert(sig_index < ctx->module->func_types.size); - import->type_var.index = sig_index; + import->decl.type_var.index = sig_index; assert(index < ctx->module->imports.capacity); WasmImportPtr* import_ptr = @@ -303,19 +303,21 @@ static WasmResult on_function_signature(uint32_t index, WasmFunc* func = &field->func; WASM_ZERO_MEMORY(*func); - func->flags = WASM_FUNC_FLAG_HAS_FUNC_TYPE | WASM_FUNC_FLAG_HAS_SIGNATURE; - func->type_var.type = WASM_VAR_TYPE_INDEX; + func->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE | + WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE; + func->decl.type_var.type = WASM_VAR_TYPE_INDEX; assert(sig_index < ctx->module->func_types.size); - func->type_var.index = sig_index; + func->decl.type_var.index = sig_index; /* copy the signature from the function type */ WasmFuncSignature* sig = &ctx->module->func_types.data[sig_index]->sig; size_t i; for (i = 0; i < sig->param_types.size; ++i) { - CHECK_ALLOC(ctx, wasm_append_type_value(ctx->allocator, &func->params.types, - &sig->param_types.data[i])); + CHECK_ALLOC( + ctx, wasm_append_type_value(ctx->allocator, &func->decl.sig.param_types, + &sig->param_types.data[i])); } - func->result_type = sig->result_type; + func->decl.sig.result_type = sig->result_type; assert(index < ctx->module->funcs.capacity); WasmFuncPtr* func_ptr = @@ -359,13 +361,13 @@ static WasmResult on_local_decl(uint32_t decl_index, void* user_data) { WasmContext* ctx = user_data; assert(ctx->current_func); - size_t old_local_count = ctx->current_func->locals.types.size; + size_t old_local_count = ctx->current_func->local_types.size; size_t new_local_count = old_local_count + count; CHECK_ALLOC( - ctx, wasm_reserve_types(ctx->allocator, &ctx->current_func->locals.types, + ctx, wasm_reserve_types(ctx->allocator, &ctx->current_func->local_types, new_local_count)); WASM_STATIC_ASSERT(sizeof(WasmType) == sizeof(uint8_t)); - WasmTypeVector* types = &ctx->current_func->locals.types; + WasmTypeVector* types = &ctx->current_func->local_types; memset(&types->data[old_local_count], type, count); types->size = new_local_count; return WASM_OK; @@ -654,7 +656,7 @@ static WasmResult on_call_expr(uint32_t func_index, void* user_data) { assert(ctx->current_func); assert(func_index < ctx->module->funcs.size); WasmFunc* func = ctx->module->funcs.data[func_index]; - uint32_t sig_index = func->type_var.index; + uint32_t sig_index = func->decl.type_var.index; assert(sig_index < ctx->module->func_types.size); WasmFuncType* func_type = ctx->module->func_types.data[sig_index]; @@ -671,7 +673,7 @@ static WasmResult on_call_import_expr(uint32_t import_index, void* user_data) { assert(ctx->current_func); assert(import_index < ctx->module->imports.size); WasmImport* import = ctx->module->imports.data[import_index]; - uint32_t sig_index = import->type_var.index; + uint32_t sig_index = import->decl.type_var.index; assert(sig_index < ctx->module->func_types.size); WasmFuncType* func_type = ctx->module->func_types.data[sig_index]; @@ -850,7 +852,7 @@ static WasmResult on_return_expr(void* user_data) { WasmContext* ctx = user_data; assert(ctx->current_func); - uint32_t sig_index = ctx->current_func->type_var.index; + uint32_t sig_index = ctx->current_func->decl.type_var.index; assert(sig_index < ctx->module->func_types.size); WasmFuncType* func_type = ctx->module->func_types.data[sig_index]; @@ -1043,7 +1045,7 @@ static WasmResult on_local_name(uint32_t func_index, WasmContext* ctx = user_data; WasmModule* module = ctx->module; WasmFunc* func = module->funcs.data[func_index]; - uint32_t num_params = func->params.types.size; + uint32_t num_params = wasm_get_num_params(func); WasmStringSlice dup_name; CHECK_ALLOC_NULL_STR(ctx, dup_name = wasm_dup_string_slice(ctx->allocator, name)); @@ -1052,11 +1054,11 @@ static WasmResult on_local_name(uint32_t func_index, uint32_t index; if (local_index < num_params) { /* param name */ - bindings = &func->params.bindings; + bindings = &func->param_bindings; index = local_index; } else { /* local name */ - bindings = &func->locals.bindings; + bindings = &func->local_bindings; index = local_index - num_params; } binding = wasm_insert_binding(ctx->allocator, bindings, &dup_name); diff --git a/src/wasm-binary-writer-spec.c b/src/wasm-binary-writer-spec.c index 003decc7..4f00b3ad 100644 --- a/src/wasm-binary-writer-spec.c +++ b/src/wasm-binary-writer-spec.c @@ -302,8 +302,8 @@ static WasmFunc* append_nullary_func(WasmAllocator* allocator, if (!func_field) return NULL; WasmFunc* func = &func_field->func; - func->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; - func->result_type = result_type; + func->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE; + func->decl.sig.result_type = result_type; int func_index = module->funcs.size - 1; WasmModuleField* export_field = @@ -379,7 +379,7 @@ static void write_commands(WasmWriteSpecContext* ctx, WasmScript* script) { int func_index = wasm_get_func_index_by_var(last_module, &export->var); assert(func_index >= 0 && (size_t)func_index < last_module->funcs.size); WasmFunc* callee = last_module->funcs.data[func_index]; - WasmType result_type = callee->result_type; + WasmType result_type = wasm_get_result_type(callee); /* these pointers will be invalidated later, so we can't use them */ export = NULL; callee = NULL; @@ -469,7 +469,7 @@ static void write_commands(WasmWriteSpecContext* ctx, WasmScript* script) { WASM_TYPE_I32, name); CHECK_ALLOC_NULL(caller); CHECK_ALLOC(wasm_append_type_value( - script->allocator, &caller->locals.types, &result_type)); + script->allocator, &caller->local_types, &result_type)); expr_ptr = wasm_append_expr_ptr(script->allocator, &caller->exprs); CHECK_ALLOC_NULL(expr_ptr); *expr_ptr = create_set_local_expr( diff --git a/src/wasm-binary-writer.c b/src/wasm-binary-writer.c index 08326439..e3b3fc15 100644 --- a/src/wasm-binary-writer.c +++ b/src/wasm-binary-writer.c @@ -413,6 +413,22 @@ static void get_or_create_func_signature(WasmContext* ctx, *out_index = index; } +static int get_signature_index(WasmContext* ctx, + const WasmModule* module, + WasmFuncSignatureVector* sigs, + const WasmFuncDeclaration* decl) { + int index = -1; + if (wasm_decl_has_signature(decl)) { + get_or_create_func_signature(ctx, sigs, decl->sig.result_type, + &decl->sig.param_types, &index); + } else { + assert(wasm_decl_has_func_type(decl)); + index = wasm_get_func_type_index_by_var(module, &decl->type_var); + assert(index != -1); + } + return index; +} + static void get_func_signatures(WasmContext* ctx, const WasmModule* module, WasmFuncSignatureVector* sigs) { @@ -436,17 +452,8 @@ static void get_func_signatures(WasmContext* ctx, CHECK_ALLOC_NULL(ctx->import_sig_indexes); for (i = 0; i < module->imports.size; ++i) { const WasmImport* import = module->imports.data[i]; - int index; - if (import->import_type == WASM_IMPORT_HAS_FUNC_SIGNATURE) { - get_or_create_func_signature(ctx, sigs, import->func_sig.result_type, - &import->func_sig.param_types, &index); - } else { - assert(import->import_type == WASM_IMPORT_HAS_TYPE); - index = wasm_get_func_type_index_by_var(module, &import->type_var); - assert(index != -1); - } - - ctx->import_sig_indexes[i] = index; + ctx->import_sig_indexes[i] = + get_signature_index(ctx, module, sigs, &import->decl); } ctx->func_sig_indexes = @@ -456,24 +463,15 @@ static void get_func_signatures(WasmContext* ctx, CHECK_ALLOC_NULL(ctx->func_sig_indexes); for (i = 0; i < module->funcs.size; ++i) { const WasmFunc* func = module->funcs.data[i]; - int index; - if (func->flags & WASM_FUNC_FLAG_HAS_SIGNATURE) { - get_or_create_func_signature(ctx, sigs, func->result_type, - &func->params.types, &index); - } else { - assert(func->flags & WASM_FUNC_FLAG_HAS_FUNC_TYPE); - index = wasm_get_func_type_index_by_var(module, &func->type_var); - assert(index != -1); - } - - ctx->func_sig_indexes[i] = index; + ctx->func_sig_indexes[i] = + get_signature_index(ctx, module, sigs, &func->decl); } } static void remap_locals(WasmContext* ctx, const WasmFunc* func) { uint32_t i; - uint32_t num_params = func->params.types.size; - uint32_t num_locals = func->locals.types.size; + uint32_t num_params = wasm_get_num_params(func); + uint32_t num_locals = func->local_types.size; uint32_t num_params_and_locals = num_params + num_locals; ctx->remapped_locals = wasm_realloc(ctx->allocator, ctx->remapped_locals, num_params_and_locals * sizeof(uint32_t), @@ -499,7 +497,7 @@ static void remap_locals(WasmContext* ctx, const WasmFunc* func) { uint32_t max[WASM_NUM_TYPES]; WASM_ZERO_MEMORY(max); for (i = 0; i < num_locals; ++i) { - WasmType type = func->locals.types.data[i]; + WasmType type = func->local_types.data[i]; max[type]++; } @@ -518,7 +516,7 @@ static void remap_locals(WasmContext* ctx, const WasmFunc* func) { uint32_t seen[WASM_NUM_TYPES]; WASM_ZERO_MEMORY(seen); for (i = 0; i < num_locals; ++i) { - WasmType type = func->locals.types.data[i]; + WasmType type = func->local_types.data[i]; uint32_t unpacked_index = num_params + i; uint32_t packed_index = start[type] + seen[type]++; ctx->remapped_locals[unpacked_index] = packed_index; @@ -790,7 +788,7 @@ static void write_func_locals(WasmContext* ctx, return; } - uint32_t num_params = func->params.types.size; + uint32_t num_params = wasm_get_num_params(func); #define FIRST_LOCAL_INDEX (num_params) #define LAST_LOCAL_INDEX (num_params + local_types->size) @@ -830,7 +828,7 @@ static void write_func_locals(WasmContext* ctx, static void write_func(WasmContext* ctx, const WasmModule* module, const WasmFunc* func) { - write_func_locals(ctx, module, func, &func->locals.types); + write_func_locals(ctx, module, func, &func->local_types); write_expr_list(ctx, module, func, &func->exprs); } @@ -976,8 +974,8 @@ static void write_module(WasmContext* ctx, const WasmModule* module) { out_u32_leb128(ctx, module->funcs.size, "num functions"); for (i = 0; i < module->funcs.size; ++i) { const WasmFunc* func = module->funcs.data[i]; - uint32_t num_params = func->params.types.size; - uint32_t num_locals = func->locals.types.size; + uint32_t num_params = wasm_get_num_params(func); + uint32_t num_locals = func->local_types.size; uint32_t num_params_and_locals = wasm_get_num_params_and_locals(func); wasm_snprintf(desc, sizeof(desc), "func name %" PRIzd, i); @@ -988,7 +986,8 @@ static void write_module(WasmContext* ctx, const WasmModule* module) { remap_locals(ctx, func); CHECK_ALLOC(wasm_make_type_binding_reverse_mapping( - ctx->allocator, &func->params, &index_to_name)); + ctx->allocator, &func->decl.sig.param_types, &func->param_bindings, + &index_to_name)); size_t j; for (j = 0; j < num_params; ++j) { WasmStringSlice name = index_to_name.data[j]; @@ -997,7 +996,8 @@ static void write_module(WasmContext* ctx, const WasmModule* module) { } CHECK_ALLOC(wasm_make_type_binding_reverse_mapping( - ctx->allocator, &func->locals, &index_to_name)); + ctx->allocator, &func->local_types, &func->local_bindings, + &index_to_name)); for (j = 0; j < num_locals; ++j) { WasmStringSlice name = index_to_name.data[ctx->reverse_remapped_locals[num_params + j] - diff --git a/src/wasm-bison-parser.y b/src/wasm-bison-parser.y index c8d7ba46..dc5ad185 100644 --- a/src/wasm-bison-parser.y +++ b/src/wasm-bison-parser.y @@ -94,6 +94,10 @@ static WasmExpr* new_block_expr_with_list(WasmAllocator* allocator, WasmLabel* label, WasmExprPtrVector* exprs); +WasmResult copy_signature_from_func_type(WasmAllocator* allocator, + WasmModule* module, + WasmFuncDeclaration* decl); + #define wasm_parser_lex wasm_lexer_lex %} @@ -584,7 +588,7 @@ func_info : if (field->type == WASM_FUNC_FIELD_TYPE_PARAM_TYPES || field->type == WASM_FUNC_FIELD_TYPE_BOUND_PARAM || field->type == WASM_FUNC_FIELD_TYPE_RESULT_TYPE) { - $$->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; + $$->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE; } switch (field->type) { @@ -596,8 +600,8 @@ func_info : case WASM_FUNC_FIELD_TYPE_LOCAL_TYPES: { WasmTypeVector* types = field->type == WASM_FUNC_FIELD_TYPE_PARAM_TYPES - ? &$$->params.types - : &$$->locals.types; + ? &$$->decl.sig.param_types + : &$$->local_types; CHECK_ALLOC( wasm_extend_types(parser->allocator, types, &field->types)); wasm_destroy_type_vector(parser->allocator, &field->types); @@ -606,22 +610,28 @@ func_info : case WASM_FUNC_FIELD_TYPE_BOUND_PARAM: case WASM_FUNC_FIELD_TYPE_BOUND_LOCAL: { - WasmTypeBindings* bindings = - field->type == WASM_FUNC_FIELD_TYPE_BOUND_PARAM ? &$$->params - : &$$->locals; - CHECK_ALLOC(wasm_append_type_value( - parser->allocator, &bindings->types, &field->bound_type.type)); - WasmBinding* binding = - wasm_insert_binding(parser->allocator, &bindings->bindings, - &field->bound_type.name); + WasmTypeVector* types; + WasmBindingHash* bindings; + if (field->type == WASM_FUNC_FIELD_TYPE_BOUND_PARAM) { + types = &$$->decl.sig.param_types; + bindings = &$$->param_bindings; + } else { + types = &$$->local_types; + bindings = &$$->local_bindings; + } + + CHECK_ALLOC(wasm_append_type_value(parser->allocator, types, + &field->bound_type.type)); + WasmBinding* binding = wasm_insert_binding( + parser->allocator, bindings, &field->bound_type.name); CHECK_ALLOC_NULL(binding); binding->loc = field->bound_type.loc; - binding->index = bindings->types.size - 1; + binding->index = types->size - 1; break; } case WASM_FUNC_FIELD_TYPE_RESULT_TYPE: - $$->result_type = field->result_type; + $$->decl.sig.result_type = field->result_type; break; } @@ -635,25 +645,25 @@ func : LPAR FUNC type_use func_info RPAR { $$ = $4; $$->loc = @2; - $$->flags |= WASM_FUNC_FLAG_HAS_FUNC_TYPE; - $$->type_var = $3; + $$->decl.flags |= WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + $$->decl.type_var = $3; } | LPAR FUNC bind_var type_use func_info RPAR { $$ = $5; $$->loc = @2; - $$->flags |= WASM_FUNC_FLAG_HAS_FUNC_TYPE; + $$->decl.flags |= WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + $$->decl.type_var = $4; $$->name = $3; - $$->type_var = $4; } | LPAR FUNC func_info RPAR { $$ = $3; $$->loc = @2; - $$->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; + $$->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE; } | LPAR FUNC bind_var func_info RPAR { $$ = $4; $$->loc = @2; - $$->flags = WASM_FUNC_FLAG_HAS_SIGNATURE; + $$->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE; $$->name = $3; } ; @@ -750,33 +760,33 @@ table : import : LPAR IMPORT quoted_text quoted_text type_use RPAR { $$ = new_import(parser->allocator); - $$->import_type = WASM_IMPORT_HAS_TYPE; $$->module_name = $3; $$->func_name = $4; - $$->type_var = $5; + $$->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + $$->decl.type_var = $5; } | LPAR IMPORT bind_var quoted_text quoted_text type_use RPAR /* Sugar */ { $$ = new_import(parser->allocator); - $$->import_type = WASM_IMPORT_HAS_TYPE; $$->name = $3; $$->module_name = $4; $$->func_name = $5; - $$->type_var = $6; + $$->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + $$->decl.type_var = $6; } | LPAR IMPORT quoted_text quoted_text func_type RPAR /* Sugar */ { $$ = new_import(parser->allocator); - $$->import_type = WASM_IMPORT_HAS_FUNC_SIGNATURE; $$->module_name = $3; $$->func_name = $4; - $$->func_sig = $5; + $$->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE; + $$->decl.sig = $5; } | LPAR IMPORT bind_var quoted_text quoted_text func_type RPAR /* Sugar */ { $$ = new_import(parser->allocator); - $$->import_type = WASM_IMPORT_HAS_FUNC_SIGNATURE; $$->name = $3; $$->module_name = $4; $$->func_name = $5; - $$->func_sig = $6; + $$->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_SIGNATURE; + $$->decl.sig = $6; } ; @@ -942,21 +952,17 @@ module : } } - /* if a function only defines a func type (and no explicit signature), - * copy the signature over for convenience */ size_t i; for (i = 0; i < $$->funcs.size; ++i) { WasmFunc* func = $$->funcs.data[i]; - if (func->flags == WASM_FUNC_FLAG_HAS_FUNC_TYPE) { - int index = wasm_get_func_type_index_by_var($$, &func->type_var); - if (index >= 0 && (size_t)index < $$->func_types.size) { - WasmFuncType* func_type = $$->func_types.data[index]; - func->result_type = func_type->sig.result_type; - CHECK_ALLOC(wasm_extend_types(parser->allocator, - &func->params.types, - &func_type->sig.param_types)); - } - } + CHECK_ALLOC( + copy_signature_from_func_type(parser->allocator, $$, &func->decl)); + } + + for (i = 0; i < $$->imports.size; ++i) { + WasmImport* import = $$->imports.data[i]; + CHECK_ALLOC(copy_signature_from_func_type(parser->allocator, $$, + &import->decl)); } } ; @@ -1197,3 +1203,24 @@ WasmExpr* new_block_expr_with_list(WasmAllocator* allocator, block->block.exprs = *exprs; return block; } + +WasmResult copy_signature_from_func_type(WasmAllocator* allocator, + WasmModule* module, + WasmFuncDeclaration* decl) { + /* if a function or import only defines a func type (and no explicit + * signature), copy the signature over for convenience */ + if (wasm_decl_has_func_type(decl) && !wasm_decl_has_signature(decl)) { + int index = wasm_get_func_type_index_by_var(module, &decl->type_var); + if (index >= 0 && (size_t)index < module->func_types.size) { + WasmFuncType* func_type = module->func_types.data[index]; + decl->sig.result_type = func_type->sig.result_type; + return wasm_extend_types(allocator, &decl->sig.param_types, + &func_type->sig.param_types); + } else { + /* technically not OK, but we'll catch this error later in the AST + * checker */ + return WASM_OK; + } + } + return WASM_OK; +} diff --git a/src/wasm-parser-lexer-shared.h b/src/wasm-parser-lexer-shared.h index 83c05a72..12b0f885 100644 --- a/src/wasm-parser-lexer-shared.h +++ b/src/wasm-parser-lexer-shared.h @@ -50,7 +50,6 @@ typedef union WasmToken { WasmVarVector vars; WasmExprPtr expr; WasmExprPtrVector exprs; - WasmTypeBindings type_bindings; WasmFuncField* func_fields; WasmFunc* func; WasmSegment segment; |