diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/prebuilt/wasm-ast-parser-gen.c | 3210 | ||||
-rw-r--r-- | src/prebuilt/wasm-ast-parser-gen.h | 114 | ||||
-rw-r--r-- | src/wasm-ast-checker.c | 847 | ||||
-rw-r--r-- | src/wasm-ast-parser-lexer-shared.c | 29 | ||||
-rw-r--r-- | src/wasm-ast-parser-lexer-shared.h | 69 | ||||
-rw-r--r-- | src/wasm-ast-parser.y | 1313 | ||||
-rw-r--r-- | src/wasm-ast.c | 120 | ||||
-rw-r--r-- | src/wasm-ast.h | 215 |
9 files changed, 2959 insertions, 2960 deletions
@@ -142,7 +142,7 @@ update-bison: src/prebuilt/wasm-ast-parser-gen.c update-re2c: src/prebuilt/wasm-ast-lexer-gen.c src/prebuilt/wasm-ast-parser-gen.c: src/wasm-ast-parser.y - bison -o $@ $< --defines=src/prebuilt/wasm-ast-parser-gen.h + bison -o $@ $< --defines=src/prebuilt/wasm-ast-parser-gen.h --report=state src/prebuilt/wasm-ast-lexer-gen.c: src/wasm-ast-lexer.c re2c --no-generation-date -bc -o $@ $< diff --git a/src/prebuilt/wasm-ast-parser-gen.c b/src/prebuilt/wasm-ast-parser-gen.c index 4bd837ab..89026819 100644 --- a/src/prebuilt/wasm-ast-parser-gen.c +++ b/src/prebuilt/wasm-ast-parser-gen.c @@ -114,29 +114,54 @@ } \ while (0) +#define APPEND_FIELD_TO_LIST(module, field, KIND, kind, loc_, item) \ + do { \ + field = wasm_append_module_field(parser->allocator, module); \ + field->loc = loc_; \ + field->type = WASM_MODULE_FIELD_TYPE_##KIND; \ + field->kind = item; \ + } while (0) + +#define APPEND_ITEM_TO_VECTOR(module, Kind, kind, kinds, item_ptr) \ + do { \ + Wasm##Kind* dummy = item_ptr; \ + wasm_append_##kind##_ptr_value(parser->allocator, &(module)->kinds, \ + &dummy); \ + } while (0) + +#define INSERT_BINDING(module, kind, kinds, loc_, item) \ + do \ + if ((item).name.start) { \ + WasmBinding* binding = wasm_insert_binding( \ + parser->allocator, &(module)->kind##_bindings, &(item).name); \ + binding->loc = loc_; \ + binding->index = (module)->kinds.size - 1; \ + } \ + while (0) + +#define APPEND_INLINE_EXPORT(module, KIND, loc_, value, index_) \ + do \ + if ((value).export_.has_export) { \ + WasmModuleField* export_field; \ + APPEND_FIELD_TO_LIST(module, export_field, EXPORT, export_, loc_, \ + (value).export_.export_); \ + export_field->export_.kind = WASM_EXPORT_KIND_##KIND; \ + export_field->export_.var.index = index_; \ + APPEND_ITEM_TO_VECTOR(module, Export, export, exports, \ + &export_field->export_); \ + INSERT_BINDING(module, export, exports, export_field->loc, \ + export_field->export_); \ + } \ + while (0) + #define YYMALLOC(size) wasm_alloc(parser->allocator, size, WASM_DEFAULT_ALIGN) #define YYFREE(p) wasm_free(parser->allocator, p) #define USE_NATURAL_ALIGNMENT (~0) -#define PARSE_NAT(dst, s, s_loc, error_msg) \ - do { \ - if (WASM_FAILED(wasm_parse_uint64(s.text.start, \ - s.text.start + s.text.length, &dst))) { \ - wasm_ast_parser_error(&s_loc, lexer, parser, \ - error_msg PRIstringslice "\"", \ - WASM_PRINTF_STRING_SLICE_ARG(s.text)); \ - } \ - } while (0) - static WasmExprList join_exprs1(WasmLocation* loc, WasmExpr* expr1); static WasmExprList join_exprs2(WasmLocation* loc, WasmExprList* expr1, WasmExpr* expr2); -static WasmExprList join_exprs3(WasmLocation* loc, WasmExprList* expr1, - WasmExprList* expr2, WasmExpr* expr3); -static WasmExprList join_exprs4(WasmLocation* loc, WasmExprList* expr1, - WasmExprList* expr2, WasmExprList* expr3, - WasmExpr* expr4); static WasmFuncField* new_func_field(WasmAllocator* allocator) { return wasm_alloc_zero(allocator, sizeof(WasmFuncField), WASM_DEFAULT_ALIGN); @@ -185,7 +210,7 @@ static void on_read_binary_error(uint32_t offset, const char* error, #define wasm_ast_parser_lex wasm_ast_lexer_lex -#line 189 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:339 */ +#line 214 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:339 */ # ifndef YY_NULLPTR # if defined __cplusplus && 201103L <= __cplusplus @@ -238,60 +263,66 @@ extern int wasm_ast_parser_debug; WASM_TOKEN_TYPE_VAR = 264, WASM_TOKEN_TYPE_VALUE_TYPE = 265, WASM_TOKEN_TYPE_ANYFUNC = 266, - WASM_TOKEN_TYPE_NOP = 267, - WASM_TOKEN_TYPE_DROP = 268, - WASM_TOKEN_TYPE_BLOCK = 269, - WASM_TOKEN_TYPE_END = 270, - WASM_TOKEN_TYPE_IF = 271, - WASM_TOKEN_TYPE_THEN = 272, - WASM_TOKEN_TYPE_ELSE = 273, - WASM_TOKEN_TYPE_LOOP = 274, - WASM_TOKEN_TYPE_BR = 275, - WASM_TOKEN_TYPE_BR_IF = 276, - WASM_TOKEN_TYPE_BR_TABLE = 277, - WASM_TOKEN_TYPE_CALL = 278, - WASM_TOKEN_TYPE_CALL_IMPORT = 279, - WASM_TOKEN_TYPE_CALL_INDIRECT = 280, - WASM_TOKEN_TYPE_RETURN = 281, - WASM_TOKEN_TYPE_GET_LOCAL = 282, - WASM_TOKEN_TYPE_SET_LOCAL = 283, - WASM_TOKEN_TYPE_TEE_LOCAL = 284, - WASM_TOKEN_TYPE_GET_GLOBAL = 285, - WASM_TOKEN_TYPE_SET_GLOBAL = 286, - WASM_TOKEN_TYPE_LOAD = 287, - WASM_TOKEN_TYPE_STORE = 288, - WASM_TOKEN_TYPE_OFFSET_EQ_NAT = 289, - WASM_TOKEN_TYPE_ALIGN_EQ_NAT = 290, - WASM_TOKEN_TYPE_CONST = 291, - WASM_TOKEN_TYPE_UNARY = 292, - WASM_TOKEN_TYPE_BINARY = 293, - WASM_TOKEN_TYPE_COMPARE = 294, - WASM_TOKEN_TYPE_CONVERT = 295, - WASM_TOKEN_TYPE_SELECT = 296, - WASM_TOKEN_TYPE_UNREACHABLE = 297, - WASM_TOKEN_TYPE_CURRENT_MEMORY = 298, - WASM_TOKEN_TYPE_GROW_MEMORY = 299, - WASM_TOKEN_TYPE_FUNC = 300, - WASM_TOKEN_TYPE_START = 301, - WASM_TOKEN_TYPE_TYPE = 302, - WASM_TOKEN_TYPE_PARAM = 303, - WASM_TOKEN_TYPE_RESULT = 304, - WASM_TOKEN_TYPE_LOCAL = 305, - WASM_TOKEN_TYPE_GLOBAL = 306, - WASM_TOKEN_TYPE_MODULE = 307, - WASM_TOKEN_TYPE_TABLE = 308, - WASM_TOKEN_TYPE_ELEM = 309, - WASM_TOKEN_TYPE_MEMORY = 310, - WASM_TOKEN_TYPE_DATA = 311, - WASM_TOKEN_TYPE_OFFSET = 312, - WASM_TOKEN_TYPE_IMPORT = 313, - WASM_TOKEN_TYPE_EXPORT = 314, - WASM_TOKEN_TYPE_ASSERT_INVALID = 315, - WASM_TOKEN_TYPE_ASSERT_RETURN = 316, - WASM_TOKEN_TYPE_ASSERT_RETURN_NAN = 317, - WASM_TOKEN_TYPE_ASSERT_TRAP = 318, - WASM_TOKEN_TYPE_INVOKE = 319, - WASM_TOKEN_TYPE_LOW = 320 + WASM_TOKEN_TYPE_MUT = 267, + WASM_TOKEN_TYPE_NOP = 268, + WASM_TOKEN_TYPE_DROP = 269, + WASM_TOKEN_TYPE_BLOCK = 270, + WASM_TOKEN_TYPE_END = 271, + WASM_TOKEN_TYPE_IF = 272, + WASM_TOKEN_TYPE_THEN = 273, + WASM_TOKEN_TYPE_ELSE = 274, + WASM_TOKEN_TYPE_LOOP = 275, + WASM_TOKEN_TYPE_BR = 276, + WASM_TOKEN_TYPE_BR_IF = 277, + WASM_TOKEN_TYPE_BR_TABLE = 278, + WASM_TOKEN_TYPE_CALL = 279, + WASM_TOKEN_TYPE_CALL_IMPORT = 280, + WASM_TOKEN_TYPE_CALL_INDIRECT = 281, + WASM_TOKEN_TYPE_RETURN = 282, + WASM_TOKEN_TYPE_GET_LOCAL = 283, + WASM_TOKEN_TYPE_SET_LOCAL = 284, + WASM_TOKEN_TYPE_TEE_LOCAL = 285, + WASM_TOKEN_TYPE_GET_GLOBAL = 286, + WASM_TOKEN_TYPE_SET_GLOBAL = 287, + WASM_TOKEN_TYPE_LOAD = 288, + WASM_TOKEN_TYPE_STORE = 289, + WASM_TOKEN_TYPE_OFFSET_EQ_NAT = 290, + WASM_TOKEN_TYPE_ALIGN_EQ_NAT = 291, + WASM_TOKEN_TYPE_CONST = 292, + WASM_TOKEN_TYPE_UNARY = 293, + WASM_TOKEN_TYPE_BINARY = 294, + WASM_TOKEN_TYPE_COMPARE = 295, + WASM_TOKEN_TYPE_CONVERT = 296, + WASM_TOKEN_TYPE_SELECT = 297, + WASM_TOKEN_TYPE_UNREACHABLE = 298, + WASM_TOKEN_TYPE_CURRENT_MEMORY = 299, + WASM_TOKEN_TYPE_GROW_MEMORY = 300, + WASM_TOKEN_TYPE_FUNC = 301, + WASM_TOKEN_TYPE_START = 302, + WASM_TOKEN_TYPE_TYPE = 303, + WASM_TOKEN_TYPE_PARAM = 304, + WASM_TOKEN_TYPE_RESULT = 305, + WASM_TOKEN_TYPE_LOCAL = 306, + WASM_TOKEN_TYPE_GLOBAL = 307, + WASM_TOKEN_TYPE_MODULE = 308, + WASM_TOKEN_TYPE_TABLE = 309, + WASM_TOKEN_TYPE_ELEM = 310, + WASM_TOKEN_TYPE_MEMORY = 311, + WASM_TOKEN_TYPE_DATA = 312, + WASM_TOKEN_TYPE_OFFSET = 313, + WASM_TOKEN_TYPE_IMPORT = 314, + WASM_TOKEN_TYPE_EXPORT = 315, + WASM_TOKEN_TYPE_REGISTER = 316, + WASM_TOKEN_TYPE_INVOKE = 317, + WASM_TOKEN_TYPE_GET = 318, + WASM_TOKEN_TYPE_ASSERT_INVALID = 319, + WASM_TOKEN_TYPE_ASSERT_UNLINKABLE = 320, + WASM_TOKEN_TYPE_ASSERT_RETURN = 321, + WASM_TOKEN_TYPE_ASSERT_RETURN_NAN = 322, + WASM_TOKEN_TYPE_ASSERT_TRAP = 323, + WASM_TOKEN_TYPE_INPUT = 324, + WASM_TOKEN_TYPE_OUTPUT = 325, + WASM_TOKEN_TYPE_LOW = 326 }; #endif @@ -324,7 +355,7 @@ int wasm_ast_parser_parse (WasmAstLexer* lexer, WasmAstParser* parser); /* Copy the second part of user declarations. */ -#line 328 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:358 */ +#line 359 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:358 */ #ifdef short # undef short @@ -566,23 +597,23 @@ union yyalloc #endif /* !YYCOPY_NEEDED */ /* YYFINAL -- State number of the termination state. */ -#define YYFINAL 8 +#define YYFINAL 9 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 817 +#define YYLAST 750 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 66 +#define YYNTOKENS 72 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 54 +#define YYNNTS 62 /* YYNRULES -- Number of rules. */ -#define YYNRULES 173 +#define YYNRULES 166 /* YYNSTATES -- Number of states. */ -#define YYNSTATES 387 +#define YYNSTATES 380 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned by yylex, with out-of-bounds checking. */ #define YYUNDEFTOK 2 -#define YYMAXUTOK 320 +#define YYMAXUTOK 326 #define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) @@ -623,31 +654,30 @@ static const yytype_uint8 yytranslate[] = 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, - 65 + 65, 66, 67, 68, 69, 70, 71 }; #if WASM_AST_PARSER_DEBUG /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 228, 228, 234, 244, 245, 251, 252, 258, 261, - 262, 266, 270, 277, 288, 292, 296, 303, 315, 322, - 323, 329, 333, 349, 350, 352, 355, 356, 366, 367, - 378, 379, 382, 385, 388, 391, 396, 401, 410, 415, - 420, 427, 430, 435, 442, 445, 449, 453, 457, 461, - 465, 469, 473, 477, 483, 489, 501, 505, 509, 513, - 517, 520, 525, 528, 531, 534, 540, 546, 556, 562, - 568, 574, 580, 588, 596, 600, 604, 609, 615, 621, - 629, 635, 639, 644, 649, 654, 659, 664, 669, 674, - 679, 686, 693, 706, 711, 716, 721, 726, 730, 736, - 737, 745, 750, 751, 757, 763, 773, 779, 785, 795, - 798, 853, 861, 870, 876, 886, 887, 893, 896, 901, - 907, 910, 913, 918, 925, 929, 945, 951, 954, 957, - 962, 969, 973, 995, 999, 1004, 1014, 1018, 1025, 1032, - 1040, 1046, 1056, 1063, 1069, 1072, 1111, 1128, 1149, 1166, - 1174, 1195, 1206, 1224, 1245, 1256, 1267, 1301, 1310, 1334, - 1340, 1347, 1353, 1361, 1368, 1378, 1379, 1387, 1399, 1400, - 1403, 1404, 1411, 1420 + 0, 264, 264, 270, 280, 281, 285, 303, 304, 310, + 313, 318, 325, 328, 329, 333, 338, 345, 348, 351, + 356, 363, 369, 380, 384, 388, 395, 400, 407, 408, + 414, 415, 418, 422, 423, 427, 428, 438, 439, 450, + 451, 452, 455, 458, 461, 464, 467, 471, 475, 480, + 483, 487, 491, 495, 499, 503, 507, 511, 517, 523, + 535, 539, 543, 547, 551, 554, 559, 564, 569, 574, + 582, 590, 594, 597, 603, 609, 618, 624, 629, 635, + 640, 646, 654, 655, 663, 664, 672, 677, 678, 684, + 690, 700, 706, 712, 722, 777, 786, 793, 800, 810, + 813, 817, 822, 831, 837, 857, 862, 871, 878, 898, + 920, 927, 940, 947, 953, 959, 965, 973, 978, 985, + 991, 997, 1003, 1012, 1020, 1025, 1030, 1035, 1042, 1049, + 1053, 1056, 1067, 1071, 1078, 1082, 1085, 1093, 1101, 1118, + 1134, 1145, 1152, 1159, 1165, 1194, 1204, 1241, 1251, 1276, + 1277, 1281, 1289, 1299, 1305, 1310, 1316, 1322, 1328, 1333, + 1341, 1342, 1350, 1362, 1363, 1370, 1379 }; #endif @@ -657,26 +687,28 @@ static const yytype_uint16 yyrline[] = static const char *const yytname[] = { "\"EOF\"", "error", "$undefined", "\"(\"", "\")\"", "NAT", "INT", - "FLOAT", "TEXT", "VAR", "VALUE_TYPE", "ANYFUNC", "NOP", "DROP", "BLOCK", - "END", "IF", "THEN", "ELSE", "LOOP", "BR", "BR_IF", "BR_TABLE", "CALL", - "CALL_IMPORT", "CALL_INDIRECT", "RETURN", "GET_LOCAL", "SET_LOCAL", - "TEE_LOCAL", "GET_GLOBAL", "SET_GLOBAL", "LOAD", "STORE", + "FLOAT", "TEXT", "VAR", "VALUE_TYPE", "ANYFUNC", "MUT", "NOP", "DROP", + "BLOCK", "END", "IF", "THEN", "ELSE", "LOOP", "BR", "BR_IF", "BR_TABLE", + "CALL", "CALL_IMPORT", "CALL_INDIRECT", "RETURN", "GET_LOCAL", + "SET_LOCAL", "TEE_LOCAL", "GET_GLOBAL", "SET_GLOBAL", "LOAD", "STORE", "OFFSET_EQ_NAT", "ALIGN_EQ_NAT", "CONST", "UNARY", "BINARY", "COMPARE", "CONVERT", "SELECT", "UNREACHABLE", "CURRENT_MEMORY", "GROW_MEMORY", "FUNC", "START", "TYPE", "PARAM", "RESULT", "LOCAL", "GLOBAL", "MODULE", "TABLE", "ELEM", "MEMORY", "DATA", "OFFSET", "IMPORT", "EXPORT", - "ASSERT_INVALID", "ASSERT_RETURN", "ASSERT_RETURN_NAN", "ASSERT_TRAP", - "INVOKE", "LOW", "$accept", "non_empty_text_list", "text_list", - "value_type_list", "elem_type", "func_type", "nat", "literal", "var", - "var_list", "bind_var", "quoted_text", "labeling", "labeling1", - "offset_opt", "align_opt", "expr", "op", "expr1", "expr_list", - "const_expr", "func_fields", "func_body", "type_use", "func_info", - "func", "export_opt", "offset", "elem", "initial_elems", "max_elems", - "table_limits", "table", "data", "initial_pages", "max_pages", - "memory_limits", "memory", "start", "global", "type_def", "import", - "export", "export_memory", "module_fields", "raw_module", "module", - "cmd", "cmd_list", "const", "const_opt", "const_list", "script", - "script_start", YY_NULLPTR + "REGISTER", "INVOKE", "GET", "ASSERT_INVALID", "ASSERT_UNLINKABLE", + "ASSERT_RETURN", "ASSERT_RETURN_NAN", "ASSERT_TRAP", "INPUT", "OUTPUT", + "LOW", "$accept", "non_empty_text_list", "text_list", "quoted_text", + "value_type_list", "elem_type", "global_type", "func_type", "func_sig", + "table_sig", "memory_sig", "limits", "type_use", "nat", "literal", "var", + "var_list", "bind_var_opt", "bind_var", "labeling_opt", "offset_opt", + "align_opt", "instr", "plain_instr", "block_instr", "block", "expr", + "expr1", "if_", "instr_list", "expr_list", "const_expr", "func_fields", + "func_body", "func_info", "func", "offset", "elem", "table", "data", + "memory", "global", "import_kind", "import", "inline_import", + "export_kind", "export", "inline_export_opt", "inline_export", + "type_def", "start", "module_fields", "raw_module", "module", + "script_var_opt", "action", "cmd", "cmd_list", "const", "const_list", + "script", "script_start", YY_NULLPTR }; #endif @@ -691,16 +723,17 @@ static const yytype_uint16 yytoknum[] = 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320 + 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, + 325, 326 }; # endif -#define YYPACT_NINF -308 +#define YYPACT_NINF -261 #define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-308))) + (!!((Yystate) == (-261))) -#define YYTABLE_NINF -100 +#define YYTABLE_NINF -30 #define yytable_value_is_error(Yytable_value) \ 0 @@ -709,45 +742,44 @@ static const yytype_uint16 yytoknum[] = STATE-NUM. */ static const yytype_int16 yypact[] = { - -308, 14, -308, 41, 50, -308, -308, -308, -308, 45, - 75, 80, 83, 92, 93, -308, 46, 85, 67, 93, - 60, 64, 69, -308, -308, -308, -308, 76, -308, -308, - -308, -308, -308, -308, -308, -308, -308, -308, -308, -308, - 135, 93, 93, 93, 103, 93, 63, 21, 16, 22, - 141, 29, 141, 107, 93, -308, -308, -308, -308, 122, - -308, -308, -308, 340, -308, -308, 155, 116, -308, 159, - 426, 156, -308, -308, 164, 163, 166, 298, -308, 118, - -308, 173, 175, 45, 93, 93, 11, 138, 147, 149, - 70, 627, -308, -308, 176, 176, 176, 177, 177, 177, - 63, 63, 63, -308, 63, 63, 63, 63, 63, 150, - 150, 70, -308, -308, -308, -308, -308, -308, -308, -308, - 468, 426, -308, -308, -308, -308, 510, 182, -308, 184, - 143, 773, 187, 426, 139, -308, -308, 190, -308, 426, - 176, 426, 176, 63, 63, -308, 63, 63, 63, 426, - 63, 63, 63, 63, 63, 150, 150, 70, 426, 426, - 426, 426, 426, -308, -308, 426, 426, 191, 65, 45, - -308, -308, -308, 188, 193, 93, 196, 197, 198, 201, - 202, 93, -308, -308, -308, 203, 63, 176, 195, 176, - 204, -308, 426, -308, 426, 426, 176, -308, 63, 63, - -308, -308, -308, -308, -308, -308, -308, -308, -308, -308, - 165, 165, -308, 510, 205, -308, 666, 206, -308, 106, - 207, 184, -308, 208, -308, -308, -308, 426, 552, 209, - 426, 176, 426, 426, 63, 426, 426, 426, -308, -308, - 426, 426, -308, 426, 165, 165, -308, -308, 426, 426, - -308, 426, -308, -308, 210, -308, -308, -308, 211, -308, - 196, 89, 212, 216, -308, -308, -308, 222, -308, 224, - -308, 225, 25, 220, 228, 42, 223, -308, 219, 24, - 226, 426, -308, -308, 63, -308, -308, -308, 234, -308, - -308, -308, 230, 238, 239, -308, 94, -308, 740, 384, - 426, -308, 426, -308, 426, 426, -308, -308, 426, -308, - -308, -308, 426, 426, -308, -308, 426, -308, 242, 243, - 246, -308, -308, -308, -308, -308, 510, -308, 247, 594, - 594, 248, -308, -308, 176, -308, 240, 95, -308, 57, - 250, -308, 252, 253, 176, 384, -308, -308, -308, 426, - -308, -308, 426, -308, -308, -308, -308, -308, 510, 705, - -308, -308, 594, 426, -308, 255, -308, -308, -308, 426, - -308, -308, -308, -308, 251, 213, 268, -308, 263, 272, - 273, 258, -308, 176, 426, 274, -308 + -261, 45, -261, 60, 57, -261, -261, -261, -261, -261, + 44, 76, 44, 44, 89, 91, 91, 91, -261, 129, + -261, 44, 76, 143, 46, 76, 65, -261, 109, 76, + -261, 132, 222, 154, -261, 170, 172, 224, -261, 185, + -261, -261, 87, -261, -261, -261, -261, -261, -261, -261, + -261, -261, -261, -261, -261, 226, -261, -261, 196, -261, + -261, -261, 191, 176, 105, 191, 191, 98, 191, 98, + 76, 76, -261, 209, -261, 361, -261, -261, -261, -261, + 208, 197, 213, 242, 53, 243, 282, 245, -261, -261, + 246, 245, 129, 76, 249, -261, -261, -261, 240, 241, + -261, -261, 191, 191, 191, 176, 176, -261, 176, 176, + -261, 176, 176, 176, 176, 176, 225, 225, 209, -261, + -261, -261, -261, -261, -261, -261, -261, 394, 427, -261, + -261, -261, -261, -261, -261, 255, 263, 460, -261, 274, + -261, 283, 18, -261, 427, 56, 56, 180, 288, 111, + -261, 191, 191, 191, 427, 285, 290, -261, 175, 131, + 288, 288, 295, 129, 299, 313, 315, 50, 324, -261, + 176, 191, -261, 191, 76, 76, -261, -261, -261, -261, + -261, -261, 176, -261, -261, -261, -261, -261, -261, -261, + -261, 293, 293, -261, 565, 326, 705, -261, -261, 171, + 329, 330, 526, 394, 331, 192, 332, -261, 322, -261, + 333, 327, 340, 427, 342, 336, 288, -261, 350, 359, + -261, -261, -261, 373, 285, -261, -261, 178, -261, -261, + 129, 375, -261, 376, 339, 382, -261, 107, 406, 176, + 176, 176, 176, -261, 408, 156, 403, 158, 163, 409, + 76, 425, 328, 429, 96, 430, 198, -261, -261, -261, + -261, -261, -261, -261, -261, 439, -261, -261, 448, -261, + -261, 458, -261, -261, -261, 421, -261, -261, 69, -261, + -261, -261, -261, 474, -261, -261, 129, -261, 191, 191, + 191, 191, -261, 475, 481, 491, 505, -261, 394, -261, + 507, 493, 493, 508, 514, -261, -261, -261, -261, 427, + -261, 165, 167, -261, -261, -261, -261, 639, 525, -261, + 538, 540, 263, 56, 288, 288, -261, -261, -261, -261, + -261, 394, 604, -261, -261, 493, -261, 513, 542, -261, + 201, 427, 672, 285, -261, 547, 557, 558, 568, 569, + 577, -261, -261, -261, 533, 580, 586, 427, -261, -261, + -261, -261, -261, -261, -261, -261, -261, 597, 607, 168, + 582, 609, -261, 427, 594, 616, 427, -261, 618, -261 }; /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. @@ -755,67 +787,68 @@ static const yytype_int16 yypact[] = means the default is an error. */ static const yytype_uint8 yydefact[] = { - 165, 172, 173, 0, 0, 158, 159, 166, 1, 144, - 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, - 0, 0, 0, 22, 170, 157, 3, 0, 156, 145, - 151, 150, 154, 153, 155, 146, 152, 147, 148, 149, - 0, 0, 0, 0, 0, 115, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 161, 170, 170, 170, 0, - 160, 171, 116, 99, 17, 18, 0, 0, 21, 0, - 0, 0, 120, 8, 0, 122, 0, 0, 19, 0, - 127, 129, 0, 4, 0, 0, 0, 0, 0, 0, - 0, 0, 33, 34, 23, 23, 23, 0, 0, 0, - 0, 0, 0, 41, 0, 0, 0, 0, 0, 26, - 26, 0, 56, 57, 58, 59, 44, 32, 60, 61, - 99, 99, 30, 106, 110, 102, 99, 0, 133, 9, - 0, 0, 0, 0, 0, 121, 123, 0, 63, 0, - 23, 99, 23, 0, 0, 19, 0, 0, 0, 74, - 0, 0, 0, 0, 0, 26, 26, 0, 0, 0, - 0, 0, 0, 62, 97, 0, 99, 0, 0, 4, - 128, 130, 131, 5, 0, 0, 9, 0, 0, 168, - 0, 0, 14, 15, 16, 0, 0, 6, 0, 6, - 0, 25, 99, 24, 99, 99, 24, 13, 0, 0, - 19, 45, 46, 47, 48, 49, 50, 51, 52, 27, - 28, 28, 55, 99, 0, 100, 0, 0, 113, 0, - 0, 9, 134, 0, 19, 124, 64, 99, 99, 0, - 99, 24, 68, 0, 0, 99, 99, 0, 75, 85, - 0, 0, 88, 0, 28, 28, 92, 93, 0, 0, - 96, 0, 98, 101, 0, 118, 119, 20, 0, 126, - 9, 0, 0, 0, 143, 142, 169, 0, 163, 0, - 167, 0, 0, 0, 0, 0, 0, 31, 0, 0, - 0, 99, 38, 39, 0, 29, 53, 54, 0, 114, - 111, 6, 0, 0, 0, 135, 0, 65, 0, 76, - 99, 66, 99, 69, 70, 20, 82, 83, 99, 86, - 87, 89, 0, 0, 94, 95, 0, 117, 0, 0, - 0, 140, 138, 162, 164, 109, 99, 7, 0, 99, - 99, 0, 35, 42, 23, 36, 0, 40, 112, 0, - 0, 136, 0, 0, 23, 77, 80, 67, 71, 72, - 84, 90, 0, 81, 132, 141, 139, 104, 99, 0, - 103, 107, 99, 99, 37, 10, 12, 137, 125, 99, - 73, 91, 105, 108, 0, 0, 0, 43, 0, 78, - 0, 0, 11, 23, 99, 0, 79 + 160, 165, 166, 0, 0, 148, 153, 154, 161, 1, + 149, 0, 149, 149, 0, 0, 0, 0, 150, 135, + 6, 149, 0, 0, 0, 0, 0, 163, 0, 0, + 2, 0, 0, 0, 163, 0, 0, 0, 158, 0, + 147, 3, 0, 146, 140, 141, 138, 142, 139, 137, + 144, 145, 136, 143, 155, 0, 152, 156, 0, 157, + 164, 159, 30, 0, 0, 30, 30, 0, 30, 0, + 0, 0, 151, 0, 32, 82, 31, 22, 27, 26, + 0, 0, 0, 0, 0, 129, 0, 0, 100, 28, + 129, 0, 4, 0, 0, 23, 24, 25, 0, 0, + 43, 44, 33, 33, 33, 0, 0, 28, 0, 0, + 49, 0, 0, 0, 0, 0, 35, 35, 0, 60, + 61, 62, 63, 45, 42, 64, 65, 82, 82, 39, + 40, 41, 91, 94, 87, 0, 13, 82, 134, 13, + 132, 0, 0, 10, 82, 0, 0, 0, 0, 0, + 130, 33, 33, 33, 82, 84, 0, 28, 0, 0, + 0, 0, 130, 4, 5, 0, 0, 0, 0, 162, + 0, 7, 7, 7, 0, 0, 34, 7, 7, 7, + 46, 47, 0, 50, 51, 52, 53, 54, 55, 56, + 36, 37, 37, 59, 0, 0, 0, 83, 98, 0, + 0, 0, 0, 82, 0, 0, 0, 133, 0, 86, + 0, 0, 0, 82, 0, 0, 19, 9, 0, 0, + 7, 7, 7, 0, 84, 72, 71, 0, 102, 29, + 4, 0, 18, 0, 0, 0, 106, 0, 0, 0, + 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, + 0, 0, 82, 0, 0, 0, 48, 38, 57, 58, + 96, 7, 7, 119, 118, 0, 97, 12, 0, 111, + 122, 0, 120, 17, 20, 0, 103, 73, 0, 74, + 99, 85, 101, 0, 121, 107, 4, 105, 30, 30, + 30, 30, 117, 0, 0, 0, 0, 21, 82, 8, + 0, 82, 82, 0, 0, 131, 70, 66, 68, 82, + 67, 0, 0, 95, 11, 110, 28, 0, 0, 75, + 0, 0, 13, 0, 0, 0, 124, 127, 125, 126, + 89, 82, 0, 88, 92, 82, 123, 0, 14, 16, + 0, 82, 0, 81, 109, 0, 0, 0, 0, 0, + 0, 90, 93, 69, 0, 0, 0, 82, 80, 108, + 113, 112, 116, 114, 115, 7, 104, 77, 0, 0, + 0, 79, 15, 82, 0, 0, 82, 76, 0, 78 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int16 yypgoto[] = { - -308, 270, 44, -182, 214, -164, 58, -93, 117, -137, - -44, -5, -95, -91, -97, -201, -68, -308, 215, -110, - -308, -298, -307, -114, -105, -308, -308, 231, -308, -308, - -308, -308, -308, -308, -308, -308, -308, -308, -308, -308, - -308, -308, -308, -308, -308, 275, -308, -308, -308, 101, - -308, 91, -308, -308 + -261, 610, -141, -19, -164, 424, -119, 567, -128, -131, + -133, -126, -120, -116, 522, -44, -103, -53, -21, -66, + 506, 459, -261, -85, -261, -129, -67, -261, -261, -123, + 434, -118, -258, -260, -98, -261, -11, -261, -261, -261, + -261, -261, -261, -261, 64, -261, -261, 574, 80, -261, + -261, -261, 660, -261, 34, 207, -261, -261, -261, 641, + -261, -261 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int16 yydefgoto[] = { - -1, 173, 174, 272, 74, 220, 198, 185, 257, 168, - 191, 24, 192, 193, 210, 286, 121, 122, 190, 123, - 254, 124, 125, 126, 127, 29, 63, 78, 30, 75, - 136, 76, 31, 32, 81, 171, 82, 33, 34, 35, - 36, 37, 38, 39, 17, 5, 6, 7, 1, 61, - 267, 44, 2, 3 + -1, 164, 165, 21, 252, 218, 144, 82, 200, 214, + 231, 215, 127, 79, 98, 229, 158, 75, 76, 177, + 191, 258, 128, 129, 130, 253, 131, 156, 319, 132, + 225, 210, 133, 134, 135, 44, 89, 45, 46, 47, + 48, 49, 238, 50, 136, 168, 51, 149, 137, 52, + 53, 32, 5, 6, 19, 7, 8, 1, 60, 37, + 2, 3 }; /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If @@ -823,265 +856,250 @@ static const yytype_int16 yydefgoto[] = number is the opposite. If YYTABLE_NINF, syntax error. */ static const yytype_int16 yytable[] = { - 194, 195, 132, 69, 71, 196, 213, 275, 234, 84, - 287, 215, 262, 211, 40, 214, 64, 4, 212, 120, - 65, 217, 360, 361, 67, 68, 70, 72, 357, 326, - 68, 229, 79, 73, 80, 327, 56, 57, 58, 333, - 62, 8, 334, 312, 313, 227, 330, 230, 85, 86, - 25, 231, 327, 15, 26, 373, 253, 294, 244, 245, - 372, 365, 263, 284, 246, 223, 177, 327, 64, 256, - 64, 226, 65, 228, 65, 182, 183, 184, 18, 175, - 176, 238, 278, 20, 279, 280, 21, 296, 27, 28, - 247, 248, 249, 250, 251, 22, 319, 252, 343, 64, - -20, 23, 9, 65, -20, 281, 59, 60, 288, 339, - 10, 11, 12, 13, 14, 23, 68, 297, 215, 9, - 301, 45, 46, 47, 41, 306, 307, 48, 42, 49, - 50, 51, 52, 43, 53, 54, 186, 291, 292, 55, - 302, 59, 179, 273, 77, 276, 320, 87, 88, 89, - 59, 180, 59, 181, 291, 292, 199, 200, 90, 128, - 299, 129, 130, 66, 303, 304, 133, 134, 135, 308, - 260, 336, 309, 310, 169, 311, 269, 73, 170, 172, - 314, 315, 197, 316, 209, 68, 218, 219, 221, 215, - 346, 222, 347, 224, 225, 255, 26, 259, 350, 261, - 285, 264, 265, 178, 59, 274, 268, 270, 277, 289, - 290, 293, 295, 258, 317, 318, 321, 201, 202, 203, - 322, 204, 205, 206, 207, 208, 323, 300, 324, 325, - 328, 345, 329, 331, 332, 215, 348, 349, 338, 363, - 340, 335, 341, 342, 351, 352, 354, 355, 353, 369, - 356, 358, 362, 374, 366, 364, 367, 368, 375, 376, - 232, 233, 378, 235, 236, 237, 377, 239, 240, 241, - 242, 243, 379, 380, 385, 381, 383, 382, 386, 16, - 266, 370, 0, 83, 371, 19, 0, 0, 384, 0, - 137, 0, 167, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 271, 0, 0, 0, 0, 0, 0, - 138, 139, 140, 0, 141, 282, 283, 142, 143, 144, - 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 0, 0, 157, 158, 159, 160, 161, 162, - 163, 164, 165, 91, 0, 0, 0, 0, 0, 68, - 0, 305, 92, 93, 94, 166, 95, 0, 0, 96, - 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 0, 0, 111, 112, 113, 114, - 115, 116, 117, 118, 119, 0, 0, 131, 0, 0, - 0, 0, 0, 0, 0, 0, 92, 93, 94, 0, - 95, 337, -99, 96, 97, 98, 99, 100, 101, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 0, 0, - 111, 112, 113, 114, 115, 116, 117, 118, 119, 131, - 0, 0, 0, 0, 0, 0, 0, 0, 92, 93, - 94, 0, 95, 0, 0, 96, 97, 98, 99, 100, - 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, - 0, 0, 111, 112, 113, 114, 115, 116, 117, 118, - 119, 91, 0, 0, 0, 0, 0, 0, 0, 0, - 92, 93, 94, 0, 95, 0, 0, 96, 97, 98, - 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, - 109, 110, 0, 0, 111, 112, 113, 114, 115, 116, - 117, 118, 119, 216, 0, 0, 0, 0, 0, 0, - 0, 0, 92, 93, 94, 0, 95, 0, 0, 96, - 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 0, 0, 111, 112, 113, 114, - 115, 116, 117, 118, 119, 298, 0, 0, 0, 0, - 0, 0, 0, 0, 92, 93, 94, 0, 95, 0, - 0, 96, 97, 98, 99, 100, 101, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 0, 0, 111, 112, - 113, 114, 115, 116, 117, 118, 119, 359, 0, 0, - 0, 0, 0, 0, 0, 0, 92, 93, 94, 0, - 95, 0, 0, 96, 97, 98, 99, 100, 101, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 0, 0, - 111, 112, 113, 114, 115, 116, 117, 118, 119, 138, - 139, 140, 0, 141, 0, 0, 142, 143, 144, 145, - 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, - 156, 0, 0, 157, 158, 159, 160, 161, 162, 163, - 164, 165, 0, 0, 186, 187, 188, 189, 138, 139, - 140, 0, 141, 0, 0, 142, 143, 144, 145, 146, - 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 0, 0, 157, 158, 159, 160, 161, 162, 163, 164, - 165, 0, 0, 0, 187, 188, 189, 138, 139, 140, - 0, 141, 0, 0, 142, 143, 144, 145, 146, 147, - 148, 149, 150, 151, 152, 153, 154, 155, 156, 0, - 0, 157, 158, 159, 160, 161, 162, 163, 164, 165, - 0, 0, 138, 139, 140, 189, 141, 344, 0, 142, - 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 0, 0, 157, 158, 159, 160, - 161, 162, 163, 164, 165, 138, 139, 140, 0, 141, - 0, 0, 142, 143, 144, 145, 146, 147, 148, 149, - 150, 151, 152, 153, 154, 155, 156, 0, 0, 157, - 158, 159, 160, 161, 162, 163, 164, 165 + 88, 155, 88, 34, 182, 197, 36, 245, 247, 248, + 39, 206, 84, 85, 155, 90, 201, 203, 219, 80, + 88, 209, 235, 87, 88, 91, 212, 213, 233, 195, + 208, 209, 216, 216, 232, 232, 223, 178, 179, 204, + 330, 333, 334, 83, 216, 216, 22, 23, 4, 254, + 255, 93, 94, 18, 227, 33, 142, 278, 92, 211, + 9, 180, 181, 143, 183, 184, 143, 185, 186, 187, + 188, 189, 317, 351, 166, 352, 157, 174, 175, 299, + 163, 176, 176, 176, 20, 220, 221, 222, 224, 283, + 209, 277, 24, 279, 26, 271, 239, 311, 312, 10, + 274, 86, 240, 77, 241, 265, 242, 78, 81, 155, + 10, 155, 308, 38, 74, 309, 77, 155, 11, 12, + 13, 14, 217, 15, 16, 17, 244, 12, 13, 306, + 176, 176, 176, 62, 63, 64, 40, 30, 256, 65, + 41, 66, 67, 68, 69, 321, 70, 71, 145, 148, + 246, 35, 249, 288, 160, 250, 251, 224, 54, 289, + 298, 290, 301, 291, 146, 150, 299, 302, 299, 338, + 162, 339, 372, 299, 56, 299, 57, 299, 299, 228, + 77, 77, 282, 77, 78, 78, 337, 78, 230, 61, + 174, 175, 350, 349, 346, 293, 294, 295, 296, 232, + 74, 369, 347, -29, 348, 355, 77, -29, 216, 216, + 78, 318, 138, 340, 95, 96, 97, 140, 356, 170, + 261, 262, 27, 28, 29, 42, 43, 58, 59, 58, + 72, 304, 155, 73, 368, 322, 323, 324, 325, 174, + 175, 261, 262, 139, 169, 81, 147, 155, 86, 159, + 375, 343, 167, 378, 100, 101, 151, 155, 152, 198, + 190, 153, 105, 106, 107, 108, 199, 109, 110, 111, + 112, 113, 114, 115, 116, 117, 358, 205, 118, 119, + 120, 121, 122, 123, 124, 125, 126, 207, 196, 170, + 171, 172, 173, 77, 226, 100, 101, 151, 234, 152, + 174, 175, 153, 105, 106, 107, 108, 41, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 236, 237, 118, + 119, 120, 121, 122, 123, 124, 125, 126, 243, 257, + 260, 196, 268, 263, 264, 266, 267, 269, 299, 208, + 154, 100, 101, 102, 270, 103, 272, 217, 104, 105, + 106, 107, 108, 275, 109, 110, 111, 112, 113, 114, + 115, 116, 117, 276, 99, 118, 119, 120, 121, 122, + 123, 124, 125, 126, 100, 101, 102, 280, 103, 284, + 285, 104, 105, 106, 107, 108, 287, 109, 110, 111, + 112, 113, 114, 115, 116, 117, 286, 194, 118, 119, + 120, 121, 122, 123, 124, 125, 126, 100, 101, 102, + 292, 103, 297, 300, 104, 105, 106, 107, 108, 303, + 109, 110, 111, 112, 113, 114, 115, 116, 117, 305, + 196, 118, 119, 120, 121, 122, 123, 124, 125, 126, + 100, 101, 102, 313, 103, 307, 310, 104, 105, 106, + 107, 108, 314, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 315, 202, 118, 119, 120, 121, 122, 123, + 124, 125, 126, 100, 101, 102, 316, 103, 320, 326, + 104, 105, 106, 107, 108, 327, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 328, 332, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 100, 101, 102, 329, + 103, 331, 335, 104, 105, 106, 107, 108, 336, 109, + 110, 111, 112, 113, 114, 115, 116, 117, 342, 353, + 118, 119, 120, 121, 122, 123, 124, 125, 126, 100, + 101, 151, 344, 152, 345, 354, 153, 105, 106, 107, + 108, 359, 109, 110, 111, 112, 113, 114, 115, 116, + 117, 360, 361, 118, 119, 120, 121, 122, 123, 124, + 125, 126, 362, 363, 170, 171, 172, 173, 100, 101, + 151, 364, 152, 365, 366, 153, 105, 106, 107, 108, + 367, 109, 110, 111, 112, 113, 114, 115, 116, 117, + 370, 373, 118, 119, 120, 121, 122, 123, 124, 125, + 126, 371, 374, 376, 171, 172, 173, 100, 101, 151, + 377, 152, 379, 192, 153, 105, 106, 107, 108, 31, + 109, 110, 111, 112, 113, 114, 115, 116, 117, 273, + 193, 118, 119, 120, 121, 122, 123, 124, 125, 126, + 141, 259, 100, 101, 151, 173, 152, 341, 281, 153, + 105, 106, 107, 108, 161, 109, 110, 111, 112, 113, + 114, 115, 116, 117, 25, 55, 118, 119, 120, 121, + 122, 123, 124, 125, 126, 100, 101, 151, 0, 152, + 357, 0, 153, 105, 106, 107, 108, 0, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 0, 0, 118, + 119, 120, 121, 122, 123, 124, 125, 126, 100, 101, + 151, 0, 152, 0, 0, 153, 105, 106, 107, 108, + 0, 109, 110, 111, 112, 113, 114, 115, 116, 117, + 0, 0, 118, 119, 120, 121, 122, 123, 124, 125, + 126 }; static const yytype_int16 yycheck[] = { - 95, 96, 70, 47, 48, 96, 120, 189, 145, 53, - 211, 121, 176, 110, 19, 120, 5, 3, 111, 63, - 9, 126, 329, 330, 3, 9, 10, 5, 326, 4, - 9, 141, 3, 11, 5, 10, 41, 42, 43, 15, - 45, 0, 18, 244, 245, 140, 4, 142, 53, 54, - 4, 142, 10, 8, 8, 362, 166, 221, 155, 156, - 358, 4, 176, 200, 157, 133, 55, 10, 5, 4, - 5, 139, 9, 141, 9, 5, 6, 7, 3, 84, - 85, 149, 192, 3, 194, 195, 3, 224, 3, 4, - 158, 159, 160, 161, 162, 3, 260, 165, 4, 5, - 5, 8, 52, 9, 9, 196, 3, 4, 213, 291, - 60, 61, 62, 63, 64, 8, 9, 227, 228, 52, - 230, 45, 46, 47, 64, 235, 236, 51, 64, 53, - 54, 55, 56, 64, 58, 59, 47, 48, 49, 4, - 231, 3, 4, 187, 3, 189, 260, 56, 57, 58, - 3, 4, 3, 4, 48, 49, 98, 99, 36, 4, - 228, 45, 3, 46, 232, 233, 10, 3, 5, 237, - 175, 281, 240, 241, 56, 243, 181, 11, 5, 4, - 248, 249, 5, 251, 34, 9, 4, 3, 45, 299, - 300, 4, 302, 54, 4, 4, 8, 4, 308, 3, - 35, 4, 4, 86, 3, 10, 4, 4, 4, 4, - 4, 4, 4, 169, 4, 4, 4, 100, 101, 102, - 4, 104, 105, 106, 107, 108, 4, 18, 4, 4, - 10, 299, 4, 10, 15, 345, 304, 305, 4, 334, - 10, 15, 4, 4, 312, 313, 4, 4, 316, 344, - 4, 4, 4, 363, 4, 15, 4, 4, 3, 369, - 143, 144, 49, 146, 147, 148, 15, 150, 151, 152, - 153, 154, 4, 10, 384, 3, 18, 4, 4, 9, - 179, 349, -1, 52, 352, 10, -1, -1, 383, -1, - 76, -1, 77, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 186, -1, -1, -1, -1, -1, -1, - 12, 13, 14, -1, 16, 198, 199, 19, 20, 21, - 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, -1, -1, 36, 37, 38, 39, 40, 41, - 42, 43, 44, 3, -1, -1, -1, -1, -1, 9, - -1, 234, 12, 13, 14, 57, 16, -1, -1, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 32, 33, -1, -1, 36, 37, 38, 39, - 40, 41, 42, 43, 44, -1, -1, 3, -1, -1, - -1, -1, -1, -1, -1, -1, 12, 13, 14, -1, - 16, 284, 18, 19, 20, 21, 22, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32, 33, -1, -1, - 36, 37, 38, 39, 40, 41, 42, 43, 44, 3, - -1, -1, -1, -1, -1, -1, -1, -1, 12, 13, - 14, -1, 16, -1, -1, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, - -1, -1, 36, 37, 38, 39, 40, 41, 42, 43, - 44, 3, -1, -1, -1, -1, -1, -1, -1, -1, - 12, 13, 14, -1, 16, -1, -1, 19, 20, 21, - 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, -1, -1, 36, 37, 38, 39, 40, 41, - 42, 43, 44, 3, -1, -1, -1, -1, -1, -1, - -1, -1, 12, 13, 14, -1, 16, -1, -1, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 32, 33, -1, -1, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 3, -1, -1, -1, -1, - -1, -1, -1, -1, 12, 13, 14, -1, 16, -1, - -1, 19, 20, 21, 22, 23, 24, 25, 26, 27, - 28, 29, 30, 31, 32, 33, -1, -1, 36, 37, - 38, 39, 40, 41, 42, 43, 44, 3, -1, -1, - -1, -1, -1, -1, -1, -1, 12, 13, 14, -1, - 16, -1, -1, 19, 20, 21, 22, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32, 33, -1, -1, - 36, 37, 38, 39, 40, 41, 42, 43, 44, 12, - 13, 14, -1, 16, -1, -1, 19, 20, 21, 22, - 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - 33, -1, -1, 36, 37, 38, 39, 40, 41, 42, - 43, 44, -1, -1, 47, 48, 49, 50, 12, 13, - 14, -1, 16, -1, -1, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, - -1, -1, 36, 37, 38, 39, 40, 41, 42, 43, - 44, -1, -1, -1, 48, 49, 50, 12, 13, 14, - -1, 16, -1, -1, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, -1, - -1, 36, 37, 38, 39, 40, 41, 42, 43, 44, - -1, -1, 12, 13, 14, 50, 16, 17, -1, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 32, 33, -1, -1, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 12, 13, 14, -1, 16, - -1, -1, 19, 20, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 32, 33, -1, -1, 36, - 37, 38, 39, 40, 41, 42, 43, 44 + 67, 86, 69, 22, 107, 128, 25, 171, 172, 173, + 29, 139, 65, 66, 99, 68, 136, 137, 149, 63, + 87, 144, 163, 67, 91, 69, 145, 146, 161, 127, + 12, 154, 148, 149, 160, 161, 154, 103, 104, 137, + 298, 301, 302, 64, 160, 161, 12, 13, 3, 178, + 179, 70, 71, 9, 157, 21, 3, 221, 69, 3, + 0, 105, 106, 10, 108, 109, 10, 111, 112, 113, + 114, 115, 3, 331, 93, 335, 87, 59, 60, 10, + 91, 102, 103, 104, 8, 151, 152, 153, 155, 230, + 213, 220, 3, 222, 3, 213, 46, 261, 262, 53, + 216, 3, 52, 5, 54, 203, 56, 9, 3, 194, + 53, 196, 16, 4, 9, 19, 5, 202, 61, 62, + 63, 64, 11, 66, 67, 68, 170, 62, 63, 252, + 151, 152, 153, 46, 47, 48, 4, 8, 182, 52, + 8, 54, 55, 56, 57, 286, 59, 60, 84, 85, + 171, 8, 173, 46, 90, 174, 175, 224, 4, 52, + 4, 54, 4, 56, 84, 85, 10, 4, 10, 4, + 90, 4, 4, 10, 4, 10, 4, 10, 10, 4, + 5, 5, 4, 5, 9, 9, 309, 9, 57, 4, + 59, 60, 325, 324, 322, 239, 240, 241, 242, 325, + 9, 365, 322, 5, 323, 4, 5, 9, 324, 325, + 9, 278, 4, 316, 5, 6, 7, 4, 341, 48, + 49, 50, 15, 16, 17, 3, 4, 3, 4, 3, + 4, 250, 317, 37, 357, 288, 289, 290, 291, 59, + 60, 49, 50, 46, 4, 3, 3, 332, 3, 3, + 373, 318, 3, 376, 13, 14, 15, 342, 17, 4, + 35, 20, 21, 22, 23, 24, 3, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 343, 3, 37, 38, + 39, 40, 41, 42, 43, 44, 45, 4, 3, 48, + 49, 50, 51, 5, 4, 13, 14, 15, 3, 17, + 59, 60, 20, 21, 22, 23, 24, 8, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 4, 3, 37, + 38, 39, 40, 41, 42, 43, 44, 45, 4, 36, + 4, 3, 10, 4, 4, 4, 4, 4, 10, 12, + 58, 13, 14, 15, 4, 17, 4, 11, 20, 21, + 22, 23, 24, 3, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 4, 3, 37, 38, 39, 40, 41, + 42, 43, 44, 45, 13, 14, 15, 4, 17, 4, + 4, 20, 21, 22, 23, 24, 4, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 57, 3, 37, 38, + 39, 40, 41, 42, 43, 44, 45, 13, 14, 15, + 4, 17, 4, 10, 20, 21, 22, 23, 24, 10, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 4, + 3, 37, 38, 39, 40, 41, 42, 43, 44, 45, + 13, 14, 15, 4, 17, 16, 16, 20, 21, 22, + 23, 24, 4, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 4, 3, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 13, 14, 15, 55, 17, 4, 4, + 20, 21, 22, 23, 24, 4, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 4, 3, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 13, 14, 15, 4, + 17, 4, 4, 20, 21, 22, 23, 24, 4, 26, + 27, 28, 29, 30, 31, 32, 33, 34, 3, 16, + 37, 38, 39, 40, 41, 42, 43, 44, 45, 13, + 14, 15, 4, 17, 4, 3, 20, 21, 22, 23, + 24, 4, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 4, 4, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 4, 4, 48, 49, 50, 51, 13, 14, + 15, 4, 17, 50, 4, 20, 21, 22, 23, 24, + 4, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 3, 19, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 4, 3, 19, 49, 50, 51, 13, 14, 15, + 4, 17, 4, 117, 20, 21, 22, 23, 24, 19, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 215, + 118, 37, 38, 39, 40, 41, 42, 43, 44, 45, + 83, 192, 13, 14, 15, 51, 17, 18, 224, 20, + 21, 22, 23, 24, 90, 26, 27, 28, 29, 30, + 31, 32, 33, 34, 14, 34, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 13, 14, 15, -1, 17, + 18, -1, 20, 21, 22, 23, 24, -1, 26, 27, + 28, 29, 30, 31, 32, 33, 34, -1, -1, 37, + 38, 39, 40, 41, 42, 43, 44, 45, 13, 14, + 15, -1, 17, -1, -1, 20, 21, 22, 23, 24, + -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, + -1, -1, 37, 38, 39, 40, 41, 42, 43, 44, + 45 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ static const yytype_uint8 yystos[] = { - 0, 114, 118, 119, 3, 111, 112, 113, 0, 52, - 60, 61, 62, 63, 64, 8, 67, 110, 3, 111, - 3, 3, 3, 8, 77, 4, 8, 3, 4, 91, - 94, 98, 99, 103, 104, 105, 106, 107, 108, 109, - 77, 64, 64, 64, 117, 45, 46, 47, 51, 53, - 54, 55, 56, 58, 59, 4, 77, 77, 77, 3, - 4, 115, 77, 92, 5, 9, 74, 3, 9, 76, - 10, 76, 5, 11, 70, 95, 97, 3, 93, 3, - 5, 100, 102, 93, 76, 77, 77, 117, 117, 117, - 36, 3, 12, 13, 14, 16, 19, 20, 21, 22, - 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - 33, 36, 37, 38, 39, 40, 41, 42, 43, 44, - 76, 82, 83, 85, 87, 88, 89, 90, 4, 45, - 3, 3, 82, 10, 3, 5, 96, 70, 12, 13, - 14, 16, 19, 20, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 32, 33, 36, 37, 38, - 39, 40, 41, 42, 43, 44, 57, 84, 75, 56, - 5, 101, 4, 67, 68, 77, 77, 55, 74, 4, - 4, 4, 5, 6, 7, 73, 47, 48, 49, 50, - 84, 76, 78, 79, 78, 78, 79, 5, 72, 72, - 72, 74, 74, 74, 74, 74, 74, 74, 74, 34, - 80, 80, 73, 89, 90, 85, 3, 90, 4, 3, - 71, 45, 4, 82, 54, 4, 82, 78, 82, 85, - 78, 79, 74, 74, 75, 74, 74, 74, 82, 74, - 74, 74, 74, 74, 80, 80, 73, 82, 82, 82, - 82, 82, 82, 85, 86, 4, 4, 74, 68, 4, - 77, 3, 71, 89, 4, 4, 115, 116, 4, 77, - 4, 74, 69, 76, 10, 69, 76, 4, 85, 85, - 85, 79, 74, 74, 75, 35, 81, 81, 90, 4, - 4, 48, 49, 4, 71, 4, 75, 85, 3, 82, - 18, 85, 79, 82, 82, 74, 85, 85, 82, 82, - 82, 82, 81, 81, 82, 82, 82, 4, 4, 71, - 89, 4, 4, 4, 4, 4, 4, 10, 10, 4, - 4, 10, 15, 15, 18, 15, 85, 74, 4, 69, - 10, 4, 4, 4, 17, 82, 85, 85, 82, 82, - 85, 82, 82, 82, 4, 4, 4, 87, 4, 3, - 88, 88, 4, 78, 15, 4, 4, 4, 4, 78, - 82, 82, 87, 88, 85, 3, 85, 15, 49, 4, - 10, 3, 4, 18, 78, 85, 4 + 0, 129, 132, 133, 3, 124, 125, 127, 128, 0, + 53, 61, 62, 63, 64, 66, 67, 68, 9, 126, + 8, 75, 126, 126, 3, 124, 3, 127, 127, 127, + 8, 73, 123, 126, 75, 8, 75, 131, 4, 75, + 4, 8, 3, 4, 107, 109, 110, 111, 112, 113, + 115, 118, 121, 122, 4, 131, 4, 4, 3, 4, + 130, 4, 46, 47, 48, 52, 54, 55, 56, 57, + 59, 60, 4, 37, 9, 89, 90, 5, 9, 85, + 87, 3, 79, 90, 89, 89, 3, 87, 98, 108, + 89, 87, 108, 75, 75, 5, 6, 7, 86, 3, + 13, 14, 15, 17, 20, 21, 22, 23, 24, 26, + 27, 28, 29, 30, 31, 32, 33, 34, 37, 38, + 39, 40, 41, 42, 43, 44, 45, 84, 94, 95, + 96, 98, 101, 104, 105, 106, 116, 120, 4, 46, + 4, 79, 3, 10, 78, 116, 120, 3, 116, 119, + 120, 15, 17, 20, 58, 95, 99, 108, 88, 3, + 116, 119, 120, 108, 73, 74, 75, 3, 117, 4, + 48, 49, 50, 51, 59, 60, 90, 91, 91, 91, + 87, 87, 88, 87, 87, 87, 87, 87, 87, 87, + 35, 92, 92, 86, 3, 106, 3, 101, 4, 3, + 80, 84, 3, 84, 106, 3, 80, 4, 12, 101, + 103, 3, 78, 78, 81, 83, 85, 11, 77, 81, + 91, 91, 91, 103, 98, 102, 4, 88, 4, 87, + 57, 82, 83, 82, 3, 74, 4, 3, 114, 46, + 52, 54, 56, 4, 87, 76, 90, 76, 76, 90, + 75, 75, 76, 97, 97, 97, 87, 36, 93, 93, + 4, 49, 50, 4, 4, 106, 4, 4, 10, 4, + 4, 103, 4, 77, 85, 3, 4, 97, 76, 97, + 4, 102, 4, 74, 4, 4, 57, 4, 46, 52, + 54, 56, 4, 87, 87, 87, 87, 4, 4, 10, + 10, 4, 4, 10, 75, 4, 101, 16, 16, 19, + 16, 76, 76, 4, 4, 4, 55, 3, 98, 100, + 4, 74, 89, 89, 89, 89, 4, 4, 4, 4, + 104, 4, 3, 105, 105, 4, 4, 101, 4, 4, + 88, 18, 3, 98, 4, 4, 80, 84, 78, 81, + 82, 104, 105, 16, 3, 4, 101, 18, 98, 4, + 4, 4, 4, 4, 4, 50, 4, 4, 101, 76, + 3, 4, 4, 19, 3, 101, 19, 4, 101, 4 }; /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const yytype_uint8 yyr1[] = { - 0, 66, 67, 67, 68, 68, 69, 69, 70, 71, - 71, 71, 71, 72, 73, 73, 73, 74, 74, 75, - 75, 76, 77, 78, 78, 79, 80, 80, 81, 81, - 82, 82, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, - 83, 83, 84, 84, 84, 84, 84, 84, 84, 84, - 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, - 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, - 84, 84, 84, 84, 84, 84, 84, 84, 84, 85, - 85, 86, 87, 87, 87, 87, 88, 88, 88, 89, - 90, 91, 91, 91, 91, 92, 92, 93, 93, 94, - 95, 96, 97, 97, 98, 98, 99, 100, 101, 102, - 102, 103, 103, 104, 105, 105, 106, 106, 107, 107, - 107, 107, 108, 109, 110, 110, 110, 110, 110, 110, - 110, 110, 110, 110, 110, 110, 111, 111, 112, 113, - 113, 113, 113, 113, 113, 114, 114, 115, 116, 116, - 117, 117, 118, 119 + 0, 72, 73, 73, 74, 74, 75, 76, 76, 77, + 78, 78, 79, 80, 80, 80, 80, 81, 82, 83, + 83, 84, 85, 86, 86, 86, 87, 87, 88, 88, + 89, 89, 90, 91, 91, 92, 92, 93, 93, 94, + 94, 94, 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 96, 96, 96, 96, + 97, 98, 99, 99, 99, 99, 100, 100, 100, 100, + 100, 100, 101, 101, 102, 102, 103, 104, 104, 104, + 104, 105, 105, 105, 106, 107, 107, 107, 107, 108, + 108, 109, 109, 110, 110, 111, 111, 112, 112, 112, + 113, 113, 114, 114, 114, 114, 114, 115, 115, 115, + 115, 115, 115, 116, 117, 117, 117, 117, 118, 119, + 119, 120, 121, 121, 122, 123, 123, 123, 123, 123, + 123, 123, 123, 123, 123, 123, 124, 124, 125, 126, + 126, 127, 127, 128, 128, 128, 128, 128, 128, 128, + 129, 129, 130, 131, 131, 132, 133 }; /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ static const yytype_uint8 yyr2[] = { - 0, 2, 1, 2, 0, 1, 0, 2, 1, 0, - 4, 8, 4, 1, 1, 1, 1, 1, 1, 0, - 2, 1, 1, 0, 1, 1, 0, 1, 0, 1, - 1, 3, 1, 1, 1, 4, 4, 5, 3, 3, - 4, 1, 4, 7, 1, 2, 2, 2, 2, 2, - 2, 2, 2, 3, 3, 2, 1, 1, 1, 1, - 1, 1, 1, 1, 2, 3, 3, 4, 2, 3, - 3, 4, 4, 5, 1, 2, 3, 4, 7, 12, - 4, 4, 3, 3, 4, 2, 3, 3, 2, 3, - 4, 5, 2, 2, 3, 3, 2, 1, 2, 0, - 2, 1, 1, 5, 5, 6, 1, 5, 6, 4, - 1, 6, 7, 5, 6, 0, 1, 4, 3, 5, - 1, 1, 1, 2, 5, 8, 5, 1, 1, 1, - 2, 4, 7, 4, 5, 6, 7, 8, 6, 7, - 6, 7, 5, 5, 0, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 4, 4, 1, 1, - 5, 5, 9, 8, 9, 0, 2, 4, 0, 1, - 0, 2, 1, 1 + 0, 2, 1, 2, 0, 1, 1, 0, 2, 1, + 1, 4, 4, 0, 4, 8, 4, 2, 1, 1, + 2, 4, 1, 1, 1, 1, 1, 1, 0, 2, + 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, + 1, 1, 1, 1, 1, 1, 2, 2, 3, 1, + 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, + 1, 1, 1, 1, 1, 1, 4, 4, 4, 6, + 2, 3, 2, 3, 3, 4, 8, 4, 9, 5, + 3, 2, 0, 2, 0, 2, 1, 1, 5, 5, + 6, 1, 5, 6, 1, 7, 6, 6, 5, 4, + 1, 6, 5, 6, 10, 6, 5, 6, 9, 8, + 7, 6, 5, 5, 5, 5, 5, 6, 6, 6, + 6, 6, 6, 5, 4, 4, 4, 4, 5, 0, + 1, 4, 4, 5, 4, 0, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 5, 5, 1, 0, + 1, 6, 5, 1, 1, 5, 5, 5, 4, 5, + 0, 2, 4, 0, 2, 1, 1 }; @@ -1577,222 +1595,330 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN switch (yytype) { - case 67: /* non_empty_text_list */ -#line 214 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_text_list(parser->allocator, &((*yyvaluep).text_list)); } -#line 1584 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ - break; - - case 68: /* text_list */ -#line 214 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_text_list(parser->allocator, &((*yyvaluep).text_list)); } -#line 1590 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ - break; - - case 69: /* value_type_list */ -#line 215 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_type_vector(parser->allocator, &((*yyvaluep).types)); } -#line 1596 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ - break; - - case 71: /* func_type */ -#line 203 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_func_signature(parser->allocator, &((*yyvaluep).func_sig)); } + case 5: /* NAT */ +#line 245 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).literal).text); } #line 1602 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 73: /* literal */ -#line 210 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + case 6: /* INT */ +#line 245 "src/wasm-ast-parser.y" /* yacc.c:1257 */ { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).literal).text); } #line 1608 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 74: /* var */ -#line 217 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_var(parser->allocator, &((*yyvaluep).var)); } + case 7: /* FLOAT */ +#line 245 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).literal).text); } #line 1614 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 75: /* var_list */ -#line 216 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_var_vector_and_elements(parser->allocator, &((*yyvaluep).vars)); } + case 8: /* TEXT */ +#line 247 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } #line 1620 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 76: /* bind_var */ -#line 213 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + case 9: /* VAR */ +#line 247 "src/wasm-ast-parser.y" /* yacc.c:1257 */ { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } #line 1626 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 77: /* quoted_text */ -#line 213 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + case 35: /* OFFSET_EQ_NAT */ +#line 247 "src/wasm-ast-parser.y" /* yacc.c:1257 */ { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } #line 1632 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 78: /* labeling */ -#line 213 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + case 36: /* ALIGN_EQ_NAT */ +#line 247 "src/wasm-ast-parser.y" /* yacc.c:1257 */ { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } #line 1638 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 79: /* labeling1 */ -#line 213 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } + case 73: /* non_empty_text_list */ +#line 248 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_text_list(parser->allocator, &((*yyvaluep).text_list)); } #line 1644 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 82: /* expr */ -#line 200 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } + case 74: /* text_list */ +#line 248 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_text_list(parser->allocator, &((*yyvaluep).text_list)); } #line 1650 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 83: /* op */ -#line 199 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_expr(parser->allocator, ((*yyvaluep).expr)); } + case 75: /* quoted_text */ +#line 247 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } #line 1656 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 84: /* expr1 */ -#line 200 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } + case 76: /* value_type_list */ +#line 249 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_type_vector(parser->allocator, &((*yyvaluep).types)); } #line 1662 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 85: /* expr_list */ -#line 200 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } + case 79: /* func_type */ +#line 239 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_func_signature(parser->allocator, &((*yyvaluep).func_sig)); } #line 1668 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 86: /* const_expr */ -#line 200 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } + case 80: /* func_sig */ +#line 239 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_func_signature(parser->allocator, &((*yyvaluep).func_sig)); } #line 1674 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 87: /* func_fields */ -#line 201 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_func_fields(parser->allocator, ((*yyvaluep).func_fields)); } + case 84: /* type_use */ +#line 251 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_var(parser->allocator, &((*yyvaluep).var)); } #line 1680 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 88: /* func_body */ -#line 201 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_func_fields(parser->allocator, ((*yyvaluep).func_fields)); } + case 86: /* literal */ +#line 245 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).literal).text); } #line 1686 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 90: /* func_info */ -#line 202 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_func(parser->allocator, ((*yyvaluep).func)); wasm_free(parser->allocator, ((*yyvaluep).func)); } + case 87: /* var */ +#line 251 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_var(parser->allocator, &((*yyvaluep).var)); } #line 1692 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 91: /* func */ -#line 198 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_exported_func(parser->allocator, &((*yyvaluep).exported_func)); } + case 88: /* var_list */ +#line 250 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_var_vector_and_elements(parser->allocator, &((*yyvaluep).vars)); } #line 1698 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 92: /* export_opt */ -#line 213 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + case 89: /* bind_var_opt */ +#line 247 "src/wasm-ast-parser.y" /* yacc.c:1257 */ { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } #line 1704 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 93: /* offset */ -#line 200 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } + case 90: /* bind_var */ +#line 247 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } #line 1710 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 94: /* elem */ -#line 196 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_elem_segment(parser->allocator, &((*yyvaluep).elem_segment)); } + case 91: /* labeling_opt */ +#line 247 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } #line 1716 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 98: /* table */ -#line 212 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_table_elem_segment_pair(parser->allocator, &((*yyvaluep).table)); } + case 94: /* instr */ +#line 236 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } #line 1722 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 99: /* data */ -#line 207 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_data_segment(parser->allocator, &((*yyvaluep).data_segment)); } + case 95: /* plain_instr */ +#line 235 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_expr(parser->allocator, ((*yyvaluep).expr)); } #line 1728 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 103: /* memory */ -#line 206 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_memory_data_segment_pair(parser->allocator, &((*yyvaluep).memory)); } + case 96: /* block_instr */ +#line 235 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_expr(parser->allocator, ((*yyvaluep).expr)); } #line 1734 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 106: /* type_def */ -#line 204 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_func_type(parser->allocator, &((*yyvaluep).func_type)); } + case 97: /* block */ +#line 226 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_block(parser->allocator, &((*yyvaluep).block)); } #line 1740 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 107: /* import */ -#line 205 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_import(parser->allocator, ((*yyvaluep).import)); wasm_free(parser->allocator, ((*yyvaluep).import)); } + case 98: /* expr */ +#line 236 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } #line 1746 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 108: /* export */ -#line 197 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_export(parser->allocator, &((*yyvaluep).export_)); } + case 99: /* expr1 */ +#line 236 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } #line 1752 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 110: /* module_fields */ -#line 208 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_module(parser->allocator, ((*yyvaluep).module)); wasm_free(parser->allocator, ((*yyvaluep).module)); } + case 100: /* if_ */ +#line 236 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } #line 1758 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 111: /* raw_module */ -#line 209 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_raw_module(parser->allocator, &((*yyvaluep).raw_module)); } + case 101: /* instr_list */ +#line 236 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } #line 1764 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 112: /* module */ -#line 208 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_module(parser->allocator, ((*yyvaluep).module)); wasm_free(parser->allocator, ((*yyvaluep).module)); } + case 102: /* expr_list */ +#line 236 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } #line 1770 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 113: /* cmd */ -#line 193 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_command(parser->allocator, ((*yyvaluep).command)); wasm_free(parser->allocator, ((*yyvaluep).command)); } + case 103: /* const_expr */ +#line 236 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } #line 1776 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 114: /* cmd_list */ -#line 194 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_command_vector_and_elements(parser->allocator, &((*yyvaluep).commands)); } + case 104: /* func_fields */ +#line 237 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_func_fields(parser->allocator, ((*yyvaluep).func_fields)); } #line 1782 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 117: /* const_list */ -#line 195 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_const_vector(parser->allocator, &((*yyvaluep).consts)); } + case 105: /* func_body */ +#line 237 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_func_fields(parser->allocator, ((*yyvaluep).func_fields)); } #line 1788 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; - case 118: /* script */ -#line 211 "src/wasm-ast-parser.y" /* yacc.c:1257 */ - { wasm_destroy_script(&((*yyvaluep).script)); } + case 106: /* func_info */ +#line 238 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_func(parser->allocator, ((*yyvaluep).func)); wasm_free(parser->allocator, ((*yyvaluep).func)); } #line 1794 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ break; + case 107: /* func */ +#line 232 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_exported_func(parser->allocator, &((*yyvaluep).exported_func)); } +#line 1800 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 108: /* offset */ +#line 236 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_expr_list(parser->allocator, ((*yyvaluep).expr_list).first); } +#line 1806 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 109: /* elem */ +#line 230 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_elem_segment(parser->allocator, &((*yyvaluep).elem_segment)); } +#line 1812 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 110: /* table */ +#line 234 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_exported_table(parser->allocator, &((*yyvaluep).exported_table)); } +#line 1818 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 111: /* data */ +#line 242 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_data_segment(parser->allocator, &((*yyvaluep).data_segment)); } +#line 1824 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 112: /* memory */ +#line 233 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_exported_memory(parser->allocator, &((*yyvaluep).exported_memory)); } +#line 1830 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 114: /* import_kind */ +#line 241 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_import(parser->allocator, ((*yyvaluep).import)); wasm_free(parser->allocator, ((*yyvaluep).import)); } +#line 1836 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 115: /* import */ +#line 241 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_import(parser->allocator, ((*yyvaluep).import)); wasm_free(parser->allocator, ((*yyvaluep).import)); } +#line 1842 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 116: /* inline_import */ +#line 241 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_import(parser->allocator, ((*yyvaluep).import)); wasm_free(parser->allocator, ((*yyvaluep).import)); } +#line 1848 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 117: /* export_kind */ +#line 231 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_export(parser->allocator, &((*yyvaluep).export_)); } +#line 1854 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 118: /* export */ +#line 231 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_export(parser->allocator, &((*yyvaluep).export_)); } +#line 1860 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 121: /* type_def */ +#line 240 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_func_type(parser->allocator, &((*yyvaluep).func_type)); } +#line 1866 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 122: /* start */ +#line 251 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_var(parser->allocator, &((*yyvaluep).var)); } +#line 1872 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 123: /* module_fields */ +#line 243 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_module(parser->allocator, ((*yyvaluep).module)); wasm_free(parser->allocator, ((*yyvaluep).module)); } +#line 1878 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 124: /* raw_module */ +#line 244 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_raw_module(parser->allocator, &((*yyvaluep).raw_module)); } +#line 1884 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 125: /* module */ +#line 243 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_module(parser->allocator, ((*yyvaluep).module)); wasm_free(parser->allocator, ((*yyvaluep).module)); } +#line 1890 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 126: /* script_var_opt */ +#line 247 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_string_slice(parser->allocator, &((*yyvaluep).text)); } +#line 1896 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 128: /* cmd */ +#line 227 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_command(parser->allocator, ((*yyvaluep).command)); wasm_free(parser->allocator, ((*yyvaluep).command)); } +#line 1902 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 129: /* cmd_list */ +#line 228 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_command_vector_and_elements(parser->allocator, &((*yyvaluep).commands)); } +#line 1908 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 131: /* const_list */ +#line 229 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_const_vector(parser->allocator, &((*yyvaluep).consts)); } +#line 1914 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + + case 132: /* script */ +#line 246 "src/wasm-ast-parser.y" /* yacc.c:1257 */ + { wasm_destroy_script(&((*yyvaluep).script)); } +#line 1920 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1257 */ + break; + default: break; @@ -2082,18 +2208,18 @@ yyreduce: switch (yyn) { case 2: -#line 228 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 264 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { WasmTextListNode* node = new_text_list_node(parser->allocator); DUPTEXT(node->text, (yyvsp[0].text)); node->next = NULL; (yyval.text_list).first = (yyval.text_list).last = node; } -#line 2093 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2219 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 3: -#line 234 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 270 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.text_list) = (yyvsp[-1].text_list); WasmTextListNode* node = new_text_list_node(parser->allocator); @@ -2102,186 +2228,253 @@ yyreduce: (yyval.text_list).last->next = node; (yyval.text_list).last = node; } -#line 2106 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2232 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 4: -#line 244 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 280 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.text_list).first = (yyval.text_list).last = NULL; } -#line 2112 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2238 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 6: -#line 251 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { WASM_ZERO_MEMORY((yyval.types)); } -#line 2118 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 285 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + WasmTextListNode node; + node.text = (yyvsp[0].text); + node.next = NULL; + WasmTextList text_list; + text_list.first = &node; + text_list.last = &node; + void* data; + size_t size; + dup_text_list(parser->allocator, &text_list, &data, &size); + (yyval.text).start = data; + (yyval.text).length = size; + } +#line 2256 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 7: -#line 252 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 303 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { WASM_ZERO_MEMORY((yyval.types)); } +#line 2262 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 8: +#line 304 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.types) = (yyvsp[-1].types); wasm_append_type_value(parser->allocator, &(yyval.types), &(yyvsp[0].type)); } -#line 2127 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2271 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 8: -#line 258 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 9: +#line 310 "src/wasm-ast-parser.y" /* yacc.c:1646 */ {} -#line 2133 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2277 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 9: -#line 261 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 10: +#line 313 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + WASM_ZERO_MEMORY((yyval.global)); + (yyval.global).type = (yyvsp[0].type); + (yyval.global).mutable_ = WASM_FALSE; + } +#line 2287 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 11: +#line 318 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + WASM_ZERO_MEMORY((yyval.global)); + (yyval.global).type = (yyvsp[-1].type); + (yyval.global).mutable_ = WASM_TRUE; + } +#line 2297 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 12: +#line 325 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { (yyval.func_sig) = (yyvsp[-1].func_sig); } +#line 2303 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 13: +#line 328 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.func_sig)); } -#line 2139 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2309 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 10: -#line 262 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 14: +#line 329 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_sig).result_type = WASM_TYPE_VOID; + WASM_ZERO_MEMORY((yyval.func_sig)); (yyval.func_sig).param_types = (yyvsp[-1].types); } -#line 2148 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2318 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 11: -#line 266 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 15: +#line 333 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_sig).result_type = (yyvsp[-1].type); + WASM_ZERO_MEMORY((yyval.func_sig)); (yyval.func_sig).param_types = (yyvsp[-5].types); + (yyval.func_sig).result_types = (yyvsp[-1].types); } -#line 2157 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2328 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 12: -#line 270 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { WASM_ZERO_MEMORY((yyval.func_sig)); (yyval.func_sig).result_type = (yyvsp[-1].type); } -#line 2163 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + case 16: +#line 338 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + WASM_ZERO_MEMORY((yyval.func_sig)); + (yyval.func_sig).result_types = (yyvsp[-1].types); + } +#line 2337 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 13: -#line 277 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 17: +#line 345 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { (yyval.table).elem_limits = (yyvsp[-1].limits); } +#line 2343 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 18: +#line 348 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { (yyval.memory).page_limits = (yyvsp[0].limits); } +#line 2349 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 19: +#line 351 "src/wasm-ast-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), - WASM_PARSE_UNSIGNED_ONLY))) { - wasm_ast_parser_error(&(yylsp[0]), lexer, parser, "invalid int " PRIstringslice, + (yyval.limits).has_max = WASM_FALSE; + (yyval.limits).initial = (yyvsp[0].u64); + (yyval.limits).max = 0; + } +#line 2359 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 20: +#line 356 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + (yyval.limits).has_max = WASM_TRUE; + (yyval.limits).initial = (yyvsp[-1].u64); + (yyval.limits).max = (yyvsp[0].u64); + } +#line 2369 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 21: +#line 363 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { (yyval.var) = (yyvsp[-1].var); } +#line 2375 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 22: +#line 369 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + if (WASM_FAILED(wasm_parse_uint64((yyvsp[0].literal).text.start, + (yyvsp[0].literal).text.start + (yyvsp[0].literal).text.length, &(yyval.u64)))) { + wasm_ast_parser_error(&(yylsp[0]), lexer, parser, + "invalid int " PRIstringslice "\"", WASM_PRINTF_STRING_SLICE_ARG((yyvsp[0].literal).text)); } } -#line 2176 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2388 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 14: -#line 288 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 23: +#line 380 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.literal).type = (yyvsp[0].literal).type; DUPTEXT((yyval.literal).text, (yyvsp[0].literal).text); } -#line 2185 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2397 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 15: -#line 292 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 24: +#line 384 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.literal).type = (yyvsp[0].literal).type; DUPTEXT((yyval.literal).text, (yyvsp[0].literal).text); } -#line 2194 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2406 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 16: -#line 296 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 25: +#line 388 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.literal).type = (yyvsp[0].literal).type; DUPTEXT((yyval.literal).text, (yyvsp[0].literal).text); } -#line 2203 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2415 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 17: -#line 303 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 26: +#line 395 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.var).loc = (yylsp[0]); (yyval.var).type = WASM_VAR_TYPE_INDEX; - uint64_t index; - if (WASM_FAILED(wasm_parse_int64((yyvsp[0].literal).text.start, - (yyvsp[0].literal).text.start + (yyvsp[0].literal).text.length, &index, - WASM_PARSE_UNSIGNED_ONLY))) { - wasm_ast_parser_error(&(yylsp[0]), lexer, parser, "invalid int " PRIstringslice, - WASM_PRINTF_STRING_SLICE_ARG((yyvsp[0].literal).text)); - } - (yyval.var).index = index; + (yyval.var).index = (yyvsp[0].u64); } -#line 2220 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2425 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 18: -#line 315 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 27: +#line 400 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.var).loc = (yylsp[0]); (yyval.var).type = WASM_VAR_TYPE_NAME; DUPTEXT((yyval.var).name, (yyvsp[0].text)); } -#line 2230 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2435 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 19: -#line 322 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 28: +#line 407 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.vars)); } -#line 2236 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2441 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 20: -#line 323 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 29: +#line 408 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.vars) = (yyvsp[-1].vars); wasm_append_var_value(parser->allocator, &(yyval.vars), &(yyvsp[0].var)); } -#line 2245 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2450 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 21: -#line 329 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { DUPTEXT((yyval.text), (yyvsp[0].text)); } -#line 2251 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + case 30: +#line 414 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { WASM_ZERO_MEMORY((yyval.text)); } +#line 2456 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 22: -#line 333 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmTextListNode node; - node.text = (yyvsp[0].text); - node.next = NULL; - WasmTextList text_list; - text_list.first = &node; - text_list.last = &node; - void* data; - size_t size; - dup_text_list(parser->allocator, &text_list, &data, &size); - (yyval.text).start = data; - (yyval.text).length = size; - } -#line 2269 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + case 32: +#line 418 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { DUPTEXT((yyval.text), (yyvsp[0].text)); } +#line 2462 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 23: -#line 349 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 33: +#line 422 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.text)); } -#line 2275 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2468 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 26: -#line 355 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 35: +#line 427 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.u64) = 0; } -#line 2281 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2474 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 27: -#line 356 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 36: +#line 428 "src/wasm-ast-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_PARSE_SIGNED_AND_UNSIGNED))) { @@ -2290,17 +2483,17 @@ yyreduce: WASM_PRINTF_STRING_SLICE_ARG((yyvsp[0].text))); } } -#line 2294 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2487 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 28: -#line 366 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 37: +#line 438 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.u32) = USE_NATURAL_ALIGNMENT; } -#line 2300 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2493 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 29: -#line 367 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 38: +#line 439 "src/wasm-ast-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))) { @@ -2309,245 +2502,182 @@ yyreduce: WASM_PRINTF_STRING_SLICE_ARG((yyvsp[0].text))); } } -#line 2313 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2506 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 30: -#line 378 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 39: +#line 450 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = join_exprs1(&(yylsp[0]), (yyvsp[0].expr)); } -#line 2319 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2512 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 31: -#line 379 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { (yyval.expr_list) = (yyvsp[-1].expr_list); } -#line 2325 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + case 40: +#line 451 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { (yyval.expr_list) = join_exprs1(&(yylsp[0]), (yyvsp[0].expr)); } +#line 2518 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 32: -#line 382 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 41: +#line 452 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { (yyval.expr_list) = (yyvsp[0].expr_list); } +#line 2524 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 42: +#line 455 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_unreachable_expr(parser->allocator); } -#line 2333 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2532 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 33: -#line 385 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 43: +#line 458 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_nop_expr(parser->allocator); } -#line 2341 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2540 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 34: -#line 388 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 44: +#line 461 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_drop_expr(parser->allocator); } -#line 2349 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2548 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 35: -#line 391 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - (yyval.expr) = wasm_new_block_expr(parser->allocator); - (yyval.expr)->block.label = (yyvsp[-2].text); - (yyval.expr)->block.first = (yyvsp[-1].expr_list).first; - } -#line 2359 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 36: -#line 396 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - (yyval.expr) = wasm_new_loop_expr(parser->allocator); - (yyval.expr)->loop.label = (yyvsp[-2].text); - (yyval.expr)->loop.first = (yyvsp[-1].expr_list).first; - } -#line 2369 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 37: -#line 401 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 45: +#line 464 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr) = wasm_new_block_expr(parser->allocator); - (yyval.expr)->block.label = (yyvsp[-3].text); - WasmExpr* loop = wasm_new_loop_expr(parser->allocator); - loop->loc = (yylsp[-4]); - loop->loop.label = (yyvsp[-2].text); - loop->loop.first = (yyvsp[-1].expr_list).first; - (yyval.expr)->block.first = loop; + (yyval.expr) = wasm_new_select_expr(parser->allocator); } -#line 2383 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2556 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 38: -#line 410 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 46: +#line 467 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_br_expr(parser->allocator); - (yyval.expr)->br.arity = (yyvsp[-1].u32); (yyval.expr)->br.var = (yyvsp[0].var); } -#line 2393 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2565 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 39: -#line 415 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 47: +#line 471 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_br_if_expr(parser->allocator); - (yyval.expr)->br_if.arity = (yyvsp[-1].u32); (yyval.expr)->br_if.var = (yyvsp[0].var); } -#line 2403 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2574 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 40: -#line 420 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 48: +#line 475 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_br_table_expr(parser->allocator); - (yyval.expr)->br_table.arity = (yyvsp[-2].u32); (yyval.expr)->br_table.targets = (yyvsp[-1].vars); (yyval.expr)->br_table.default_target = (yyvsp[0].var); - // split_var_list_as_br_table_targets(&$$, $3); } -#line 2415 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2584 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 41: -#line 427 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 49: +#line 480 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_return_expr(parser->allocator); } -#line 2423 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2592 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 42: -#line 430 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - (yyval.expr) = wasm_new_if_expr(parser->allocator); - (yyval.expr)->if_.true_.label = (yyvsp[-2].text); - (yyval.expr)->if_.true_.first = (yyvsp[-1].expr_list).first; - } -#line 2433 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 43: -#line 435 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - (yyval.expr) = wasm_new_if_else_expr(parser->allocator); - (yyval.expr)->if_else.true_.label = (yyvsp[-5].text); - (yyval.expr)->if_else.true_.first = (yyvsp[-4].expr_list).first; - (yyval.expr)->if_else.false_.label = (yyvsp[-2].text); - (yyval.expr)->if_else.false_.first = (yyvsp[-1].expr_list).first; - } -#line 2445 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 44: -#line 442 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - (yyval.expr) = wasm_new_select_expr(parser->allocator); - } -#line 2453 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 45: -#line 445 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 50: +#line 483 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_call_expr(parser->allocator); (yyval.expr)->call.var = (yyvsp[0].var); } -#line 2462 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2601 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 46: -#line 449 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - (yyval.expr) = wasm_new_call_import_expr(parser->allocator); - (yyval.expr)->call_import.var = (yyvsp[0].var); - } -#line 2471 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 47: -#line 453 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 51: +#line 487 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_call_indirect_expr(parser->allocator); (yyval.expr)->call_indirect.var = (yyvsp[0].var); } -#line 2480 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2610 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 48: -#line 457 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 52: +#line 491 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_get_local_expr(parser->allocator); (yyval.expr)->get_local.var = (yyvsp[0].var); } -#line 2489 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2619 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 49: -#line 461 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 53: +#line 495 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_set_local_expr(parser->allocator); (yyval.expr)->set_local.var = (yyvsp[0].var); } -#line 2498 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2628 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 50: -#line 465 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 54: +#line 499 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_tee_local_expr(parser->allocator); (yyval.expr)->tee_local.var = (yyvsp[0].var); } -#line 2507 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2637 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 51: -#line 469 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 55: +#line 503 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_get_global_expr(parser->allocator); (yyval.expr)->get_global.var = (yyvsp[0].var); } -#line 2516 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2646 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 52: -#line 473 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 56: +#line 507 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_set_global_expr(parser->allocator); (yyval.expr)->set_global.var = (yyvsp[0].var); } -#line 2525 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2655 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 53: -#line 477 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 57: +#line 511 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_load_expr(parser->allocator); (yyval.expr)->load.opcode = (yyvsp[-2].opcode); (yyval.expr)->load.offset = (yyvsp[-1].u64); (yyval.expr)->load.align = (yyvsp[0].u32); } -#line 2536 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2666 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 54: -#line 483 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 58: +#line 517 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_store_expr(parser->allocator); (yyval.expr)->store.opcode = (yyvsp[-2].opcode); (yyval.expr)->store.offset = (yyvsp[-1].u64); (yyval.expr)->store.align = (yyvsp[0].u32); } -#line 2547 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2677 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 55: -#line 489 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 59: +#line 523 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_const_expr(parser->allocator); (yyval.expr)->const_.loc = (yylsp[-1]); @@ -2560,496 +2690,281 @@ yyreduce: } wasm_free(parser->allocator, (char*)(yyvsp[0].literal).text.start); } -#line 2564 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2694 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 56: -#line 501 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 60: +#line 535 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_unary_expr(parser->allocator); (yyval.expr)->unary.opcode = (yyvsp[0].opcode); } -#line 2573 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2703 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 57: -#line 505 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 61: +#line 539 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_binary_expr(parser->allocator); (yyval.expr)->binary.opcode = (yyvsp[0].opcode); } -#line 2582 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2712 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 58: -#line 509 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 62: +#line 543 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_compare_expr(parser->allocator); (yyval.expr)->compare.opcode = (yyvsp[0].opcode); } -#line 2591 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2721 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 59: -#line 513 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 63: +#line 547 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr) = wasm_new_convert_expr(parser->allocator); (yyval.expr)->convert.opcode = (yyvsp[0].opcode); } -#line 2600 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 60: -#line 517 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - (yyval.expr) = wasm_new_current_memory_expr(parser->allocator); - } -#line 2608 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 61: -#line 520 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - (yyval.expr) = wasm_new_grow_memory_expr(parser->allocator); - } -#line 2616 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 62: -#line 525 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - (yyval.expr_list) = join_exprs1(&(yylsp[0]), wasm_new_unreachable_expr(parser->allocator)); - } -#line 2624 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 63: -#line 528 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - (yyval.expr_list) = join_exprs1(&(yylsp[0]), wasm_new_nop_expr(parser->allocator)); - } -#line 2632 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2730 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 64: -#line 531 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 551 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr_list) = join_exprs2(&(yylsp[-1]), &(yyvsp[0].expr_list), wasm_new_drop_expr(parser->allocator)); + (yyval.expr) = wasm_new_current_memory_expr(parser->allocator); } -#line 2640 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2738 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 65: -#line 534 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 554 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* expr = wasm_new_block_expr(parser->allocator); - expr->block.label = (yyvsp[-1].text); - expr->block.first = (yyvsp[0].expr_list).first; - (yyval.expr_list) = join_exprs1(&(yylsp[-2]), expr); + (yyval.expr) = wasm_new_grow_memory_expr(parser->allocator); } -#line 2651 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2746 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 66: -#line 540 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 559 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* expr = wasm_new_loop_expr(parser->allocator); - expr->loop.label = (yyvsp[-1].text); - expr->loop.first = (yyvsp[0].expr_list).first; - (yyval.expr_list) = join_exprs1(&(yylsp[-2]), expr); + (yyval.expr) = wasm_new_block_expr(parser->allocator); + (yyval.expr)->block = (yyvsp[-1].block); + (yyval.expr)->block.label = (yyvsp[-2].text); } -#line 2662 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2756 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 67: -#line 546 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 564 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* block = wasm_new_block_expr(parser->allocator); - block->block.label = (yyvsp[-2].text); - WasmExpr* loop = wasm_new_loop_expr(parser->allocator); - loop->loc = (yylsp[-3]); - loop->loop.label = (yyvsp[-1].text); - loop->loop.first = (yyvsp[0].expr_list).first; - block->block.first = loop; - (yyval.expr_list) = join_exprs1(&(yylsp[-3]), block); + (yyval.expr) = wasm_new_loop_expr(parser->allocator); + (yyval.expr)->loop = (yyvsp[-1].block); + (yyval.expr)->loop.label = (yyvsp[-2].text); } -#line 2677 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2766 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 68: -#line 556 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 569 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* expr = wasm_new_br_expr(parser->allocator); - expr->br.arity = 0; - expr->br.var = (yyvsp[0].var); - (yyval.expr_list) = join_exprs1(&(yylsp[-1]), expr); + (yyval.expr) = wasm_new_if_expr(parser->allocator); + (yyval.expr)->if_.true_ = (yyvsp[-1].block); + (yyval.expr)->if_.true_.label = (yyvsp[-2].text); } -#line 2688 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2776 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 69: -#line 562 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 574 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* expr = wasm_new_br_expr(parser->allocator); - expr->br.arity = 1; - expr->br.var = (yyvsp[-1].var); - (yyval.expr_list) = join_exprs2(&(yylsp[-2]), &(yyvsp[0].expr_list), expr); + (yyval.expr) = wasm_new_if_expr(parser->allocator); + (yyval.expr)->if_.true_ = (yyvsp[-3].block); + (yyval.expr)->if_.true_.label = (yyvsp[-4].text); + (yyval.expr)->if_.false_ = (yyvsp[-1].expr_list).first; } -#line 2699 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2787 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 70: -#line 568 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 582 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* expr = wasm_new_br_if_expr(parser->allocator); - expr->br_if.arity = 0; - expr->br_if.var = (yyvsp[-1].var); - (yyval.expr_list) = join_exprs2(&(yylsp[-2]), &(yyvsp[0].expr_list), expr); + WASM_ZERO_MEMORY((yyval.block)); + (yyval.block).sig = (yyvsp[-1].types); + (yyval.block).first = (yyvsp[0].expr_list).first; } -#line 2710 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2797 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 71: -#line 574 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_br_if_expr(parser->allocator); - expr->br_if.arity = 1; - expr->br_if.var = (yyvsp[-2].var); - (yyval.expr_list) = join_exprs3(&(yylsp[-3]), &(yyvsp[-1].expr_list), &(yyvsp[0].expr_list), expr); - } -#line 2721 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 590 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { (yyval.expr_list) = (yyvsp[-1].expr_list); } +#line 2803 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 72: -#line 580 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 594 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* expr = wasm_new_br_table_expr(parser->allocator); - expr->br_table.arity = 0; - expr->br_table.targets = (yyvsp[-2].vars); - expr->br_table.default_target = (yyvsp[-1].var); - // split_var_list_as_br_table_targets(expr, $2); - (yyval.expr_list) = join_exprs2(&(yylsp[-3]), &(yyvsp[0].expr_list), expr); + (yyval.expr_list) = join_exprs2(&(yylsp[-1]), &(yyvsp[0].expr_list), (yyvsp[-1].expr)); } -#line 2734 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2811 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 73: -#line 588 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 597 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* expr = wasm_new_br_table_expr(parser->allocator); - expr->br_table.arity = 1; - expr->br_table.targets = (yyvsp[-3].vars); - expr->br_table.default_target = (yyvsp[-2].var); - // split_var_list_as_br_table_targets(expr, $2); - (yyval.expr_list) = join_exprs3(&(yylsp[-4]), &(yyvsp[-1].expr_list), &(yyvsp[0].expr_list), expr); + WasmExpr* expr = wasm_new_block_expr(parser->allocator); + expr->block = (yyvsp[0].block); + expr->block.label = (yyvsp[-1].text); + (yyval.expr_list) = join_exprs1(&(yylsp[-2]), expr); } -#line 2747 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2822 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 74: -#line 596 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 603 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* expr = wasm_new_return_expr(parser->allocator); - (yyval.expr_list) = join_exprs1(&(yylsp[0]), expr); + WasmExpr* expr = wasm_new_loop_expr(parser->allocator); + expr->loop = (yyvsp[0].block); + expr->loop.label = (yyvsp[-1].text); + (yyval.expr_list) = join_exprs1(&(yylsp[-2]), expr); } -#line 2756 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2833 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 75: -#line 600 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 609 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* expr = wasm_new_return_expr(parser->allocator); - (yyval.expr_list) = join_exprs2(&(yylsp[-1]), &(yyvsp[0].expr_list), expr); + (yyval.expr_list) = (yyvsp[0].expr_list); + WasmExpr* if_ = (yyvsp[0].expr_list).last; + assert(if_->type == WASM_EXPR_TYPE_IF); + if_->if_.true_.label = (yyvsp[-2].text); + if_->if_.true_.sig = (yyvsp[-1].types); } -#line 2765 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2845 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 76: -#line 604 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 618 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { WasmExpr* expr = wasm_new_if_expr(parser->allocator); - expr->if_.true_.first = (yyvsp[0].expr_list).first; - (yyval.expr_list) = join_exprs2(&(yylsp[-2]), &(yyvsp[-1].expr_list), expr); + expr->if_.true_.first = (yyvsp[-5].expr_list).first; + expr->if_.false_ = (yyvsp[-1].expr_list).first; + (yyval.expr_list) = join_exprs1(&(yylsp[-7]), expr); } -#line 2775 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2856 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 77: -#line 609 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 624 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* expr = wasm_new_if_else_expr(parser->allocator); - expr->if_else.true_.first = (yyvsp[-1].expr_list).first; - expr->if_else.false_.first = (yyvsp[0].expr_list).first; - (yyval.expr_list) = join_exprs2(&(yylsp[-3]), &(yyvsp[-2].expr_list), expr); + WasmExpr* expr = wasm_new_if_expr(parser->allocator); + expr->if_.true_.first = (yyvsp[-1].expr_list).first; + (yyval.expr_list) = join_exprs1(&(yylsp[-3]), expr); } -#line 2786 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2866 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 78: -#line 615 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 629 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { WasmExpr* expr = wasm_new_if_expr(parser->allocator); - expr->if_.true_.label = (yyvsp[-2].text); - expr->if_.true_.first = (yyvsp[-1].expr_list).first; - (yyval.expr_list) = join_exprs2(&(yylsp[-6]), &(yyvsp[-5].expr_list), expr); + expr->if_.true_.first = (yyvsp[-5].expr_list).first; + expr->if_.false_ = (yyvsp[-1].expr_list).first; + (yyval.expr_list) = join_exprs2(&(yylsp[-8]), &(yyvsp[-8].expr_list), expr); } -#line 2797 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2877 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 79: -#line 621 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 635 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* expr = wasm_new_if_else_expr(parser->allocator); - expr->if_else.true_.label = (yyvsp[-7].text); - expr->if_else.true_.first = (yyvsp[-6].expr_list).first; - expr->if_else.false_.label = (yyvsp[-2].text); - expr->if_else.false_.first = (yyvsp[-1].expr_list).first; - (yyval.expr_list) = join_exprs2(&(yylsp[-11]), &(yyvsp[-10].expr_list), expr); + WasmExpr* expr = wasm_new_if_expr(parser->allocator); + expr->if_.true_.first = (yyvsp[-1].expr_list).first; + (yyval.expr_list) = join_exprs2(&(yylsp[-4]), &(yyvsp[-4].expr_list), expr); } -#line 2810 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2887 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 80: -#line 629 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 640 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* expr = wasm_new_if_else_expr(parser->allocator); - expr->if_else.true_.first = (yyvsp[-2].expr_list).first; - expr->if_else.false_.first = (yyvsp[0].expr_list).first; - (yyval.expr_list) = join_exprs1(&(yylsp[-3]), expr); + WasmExpr* expr = wasm_new_if_expr(parser->allocator); + expr->if_.true_.first = (yyvsp[-1].expr_list).first; + expr->if_.false_ = (yyvsp[0].expr_list).first; + (yyval.expr_list) = join_exprs2(&(yylsp[-2]), &(yyvsp[-2].expr_list), expr); } -#line 2821 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2898 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 81: -#line 635 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 646 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr_list) = join_exprs4(&(yylsp[-3]), &(yyvsp[-2].expr_list), &(yyvsp[-1].expr_list), &(yyvsp[0].expr_list), - wasm_new_select_expr(parser->allocator)); + WasmExpr* expr = wasm_new_if_expr(parser->allocator); + expr->if_.true_.first = (yyvsp[0].expr_list).first; + (yyval.expr_list) = join_exprs2(&(yylsp[-1]), &(yyvsp[-1].expr_list), expr); } -#line 2830 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2908 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 82: -#line 639 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_call_expr(parser->allocator); - expr->call.var = (yyvsp[-1].var); - (yyval.expr_list) = join_exprs2(&(yylsp[-2]), &(yyvsp[0].expr_list), expr); - } -#line 2840 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 654 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { WASM_ZERO_MEMORY((yyval.expr_list)); } +#line 2914 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 83: -#line 644 "src/wasm-ast-parser.y" /* yacc.c:1646 */ +#line 655 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* expr = wasm_new_call_import_expr(parser->allocator); - expr->call_import.var = (yyvsp[-1].var); - (yyval.expr_list) = join_exprs2(&(yylsp[-2]), &(yyvsp[0].expr_list), expr); + (yyval.expr_list).first = (yyvsp[-1].expr_list).first; + (yyvsp[-1].expr_list).last->next = (yyvsp[0].expr_list).first; + (yyval.expr_list).last = (yyvsp[0].expr_list).last ? (yyvsp[0].expr_list).last : (yyvsp[-1].expr_list).last; + (yyval.expr_list).size = (yyvsp[-1].expr_list).size + (yyvsp[0].expr_list).size; } -#line 2850 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2925 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 84: -#line 649 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_call_indirect_expr(parser->allocator); - expr->call_indirect.var = (yyvsp[-2].var); - (yyval.expr_list) = join_exprs3(&(yylsp[-3]), &(yyvsp[-1].expr_list), &(yyvsp[0].expr_list), expr); - } -#line 2860 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 663 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { WASM_ZERO_MEMORY((yyval.expr_list)); } +#line 2931 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; case 85: -#line 654 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_get_local_expr(parser->allocator); - expr->get_local.var = (yyvsp[0].var); - (yyval.expr_list) = join_exprs1(&(yylsp[-1]), expr); - } -#line 2870 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 86: -#line 659 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_set_local_expr(parser->allocator); - expr->set_local.var = (yyvsp[-1].var); - (yyval.expr_list) = join_exprs2(&(yylsp[-2]), &(yyvsp[0].expr_list), expr); - } -#line 2880 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 87: #line 664 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* expr = wasm_new_tee_local_expr(parser->allocator); - expr->tee_local.var = (yyvsp[-1].var); - (yyval.expr_list) = join_exprs2(&(yylsp[-2]), &(yyvsp[0].expr_list), expr); - } -#line 2890 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 88: -#line 669 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_get_global_expr(parser->allocator); - expr->get_global.var = (yyvsp[0].var); - (yyval.expr_list) = join_exprs1(&(yylsp[-1]), expr); - } -#line 2900 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 89: -#line 674 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_set_global_expr(parser->allocator); - expr->set_global.var = (yyvsp[-1].var); - (yyval.expr_list) = join_exprs2(&(yylsp[-2]), &(yyvsp[0].expr_list), expr); - } -#line 2910 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 90: -#line 679 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_load_expr(parser->allocator); - expr->load.opcode = (yyvsp[-3].opcode); - expr->load.offset = (yyvsp[-2].u64); - expr->load.align = (yyvsp[-1].u32); - (yyval.expr_list) = join_exprs2(&(yylsp[-3]), &(yyvsp[0].expr_list), expr); - } -#line 2922 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 91: -#line 686 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_store_expr(parser->allocator); - expr->store.opcode = (yyvsp[-4].opcode); - expr->store.offset = (yyvsp[-3].u64); - expr->store.align = (yyvsp[-2].u32); - (yyval.expr_list) = join_exprs3(&(yylsp[-4]), &(yyvsp[-1].expr_list), &(yyvsp[0].expr_list), expr); - } -#line 2934 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 92: -#line 693 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_const_expr(parser->allocator); - expr->const_.loc = (yylsp[-1]); - if (WASM_FAILED(parse_const((yyvsp[-1].type), (yyvsp[0].literal).type, (yyvsp[0].literal).text.start, - (yyvsp[0].literal).text.start + (yyvsp[0].literal).text.length, - &expr->const_))) { - wasm_ast_parser_error(&(yylsp[0]), lexer, parser, - "invalid literal \"" PRIstringslice "\"", - WASM_PRINTF_STRING_SLICE_ARG((yyvsp[0].literal).text)); - } - wasm_free(parser->allocator, (char*)(yyvsp[0].literal).text.start); - (yyval.expr_list) = join_exprs1(&(yylsp[-1]), expr); - } -#line 2952 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 93: -#line 706 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_unary_expr(parser->allocator); - expr->unary.opcode = (yyvsp[-1].opcode); - (yyval.expr_list) = join_exprs2(&(yylsp[-1]), &(yyvsp[0].expr_list), expr); - } -#line 2962 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 94: -#line 711 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_binary_expr(parser->allocator); - expr->binary.opcode = (yyvsp[-2].opcode); - (yyval.expr_list) = join_exprs3(&(yylsp[-2]), &(yyvsp[-1].expr_list), &(yyvsp[0].expr_list), expr); - } -#line 2972 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 95: -#line 716 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_compare_expr(parser->allocator); - expr->compare.opcode = (yyvsp[-2].opcode); - (yyval.expr_list) = join_exprs3(&(yylsp[-2]), &(yyvsp[-1].expr_list), &(yyvsp[0].expr_list), expr); - } -#line 2982 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 96: -#line 721 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_convert_expr(parser->allocator); - expr->convert.opcode = (yyvsp[-1].opcode); - (yyval.expr_list) = join_exprs2(&(yylsp[-1]), &(yyvsp[0].expr_list), expr); - } -#line 2992 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 97: -#line 726 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_current_memory_expr(parser->allocator); - (yyval.expr_list) = join_exprs1(&(yylsp[0]), expr); - } -#line 3001 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 98: -#line 730 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { - WasmExpr* expr = wasm_new_grow_memory_expr(parser->allocator); - (yyval.expr_list) = join_exprs2(&(yylsp[-1]), &(yyvsp[0].expr_list), expr); - } -#line 3010 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 99: -#line 736 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { WASM_ZERO_MEMORY((yyval.expr_list)); } -#line 3016 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 100: -#line 737 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { (yyval.expr_list).first = (yyvsp[-1].expr_list).first; (yyvsp[-1].expr_list).last->next = (yyvsp[0].expr_list).first; (yyval.expr_list).last = (yyvsp[0].expr_list).last ? (yyvsp[0].expr_list).last : (yyvsp[-1].expr_list).last; (yyval.expr_list).size = (yyvsp[-1].expr_list).size + (yyvsp[0].expr_list).size; } -#line 3027 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2942 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 103: -#line 751 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 88: +#line 678 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (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)->type = WASM_FUNC_FIELD_TYPE_RESULT_TYPES; + (yyval.func_fields)->types = (yyvsp[-2].types); (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 3038 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2953 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 104: -#line 757 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 89: +#line 684 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (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 3049 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2964 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 105: -#line 763 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 90: +#line 690 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.func_fields) = new_func_field(parser->allocator); (yyval.func_fields)->type = WASM_FUNC_FIELD_TYPE_BOUND_PARAM; @@ -3058,33 +2973,33 @@ yyreduce: (yyval.func_fields)->bound_type.type = (yyvsp[-2].type); (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 3062 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2977 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 106: -#line 773 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 91: +#line 700 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.func_fields) = new_func_field(parser->allocator); (yyval.func_fields)->type = WASM_FUNC_FIELD_TYPE_EXPRS; (yyval.func_fields)->first_expr = (yyvsp[0].expr_list).first; (yyval.func_fields)->next = NULL; } -#line 3073 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2988 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 107: -#line 779 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 92: +#line 706 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (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 3084 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 2999 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 108: -#line 785 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 93: +#line 712 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.func_fields) = new_func_field(parser->allocator); (yyval.func_fields)->type = WASM_FUNC_FIELD_TYPE_BOUND_LOCAL; @@ -3093,17 +3008,11 @@ yyreduce: (yyval.func_fields)->bound_type.type = (yyvsp[-2].type); (yyval.func_fields)->next = (yyvsp[0].func_fields); } -#line 3097 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3012 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 109: -#line 795 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { (yyval.var) = (yyvsp[-1].var); } -#line 3103 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 110: -#line 798 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 94: +#line 722 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.func) = new_func(parser->allocator); WasmFuncField* field = (yyvsp[0].func_fields); @@ -3147,8 +3056,8 @@ yyreduce: break; } - case WASM_FUNC_FIELD_TYPE_RESULT_TYPE: - (yyval.func)->decl.sig.result_type = field->result_type; + case WASM_FUNC_FIELD_TYPE_RESULT_TYPES: + (yyval.func)->decl.sig.result_types = field->types; break; } @@ -3157,593 +3066,626 @@ yyreduce: field = next; } } -#line 3161 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3070 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 111: -#line 853 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 95: +#line 777 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { + WASM_ZERO_MEMORY((yyval.exported_func)); (yyval.exported_func).func = (yyvsp[-1].func); (yyval.exported_func).func->decl.flags |= WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; (yyval.exported_func).func->decl.type_var = (yyvsp[-2].var); - (yyval.exported_func).export_.name = (yyvsp[-3].text); - (yyval.exported_func).export_.var.type = WASM_VAR_TYPE_INDEX; - (yyval.exported_func).export_.var.index = -1; + (yyval.exported_func).func->name = (yyvsp[-4].text); + (yyval.exported_func).export_ = (yyvsp[-3].optional_export); } -#line 3174 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3083 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 112: -#line 861 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 96: +#line 786 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { + WASM_ZERO_MEMORY((yyval.exported_func)); (yyval.exported_func).func = (yyvsp[-1].func); (yyval.exported_func).func->decl.flags |= WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; (yyval.exported_func).func->decl.type_var = (yyvsp[-2].var); (yyval.exported_func).func->name = (yyvsp[-3].text); - (yyval.exported_func).export_.name = (yyvsp[-4].text); - (yyval.exported_func).export_.var.type = WASM_VAR_TYPE_INDEX; - (yyval.exported_func).export_.var.index = -1; } -#line 3188 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3095 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 113: -#line 870 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 97: +#line 793 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { + WASM_ZERO_MEMORY((yyval.exported_func)); (yyval.exported_func).func = (yyvsp[-1].func); - (yyval.exported_func).export_.name = (yyvsp[-2].text); - (yyval.exported_func).export_.var.type = WASM_VAR_TYPE_INDEX; - (yyval.exported_func).export_.var.index = -1; + (yyval.exported_func).func->name = (yyvsp[-3].text); + (yyval.exported_func).export_ = (yyvsp[-2].optional_export); } -#line 3199 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3106 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 114: -#line 876 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 98: +#line 800 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { + WASM_ZERO_MEMORY((yyval.exported_func)); (yyval.exported_func).func = (yyvsp[-1].func); (yyval.exported_func).func->name = (yyvsp[-2].text); - (yyval.exported_func).export_.name = (yyvsp[-3].text); - (yyval.exported_func).export_.var.type = WASM_VAR_TYPE_INDEX; - (yyval.exported_func).export_.var.index = -1; } -#line 3211 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3116 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 115: -#line 886 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { WASM_ZERO_MEMORY((yyval.text)); } -#line 3217 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 117: -#line 893 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 99: +#line 810 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.expr_list) = (yyvsp[-1].expr_list); } -#line 3225 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3124 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 118: -#line 896 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 101: +#line 817 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.expr_list) = (yyvsp[-1].expr_list); + (yyval.elem_segment).table_var = (yyvsp[-3].var); + (yyval.elem_segment).offset = (yyvsp[-2].expr_list).first; + (yyval.elem_segment).vars = (yyvsp[-1].vars); } -#line 3233 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3134 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 119: -#line 901 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 102: +#line 822 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { + (yyval.elem_segment).table_var.type = WASM_VAR_TYPE_INDEX; + (yyval.elem_segment).table_var.index = 0; (yyval.elem_segment).offset = (yyvsp[-2].expr_list).first; (yyval.elem_segment).vars = (yyvsp[-1].vars); } -#line 3242 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3145 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 120: -#line 907 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { PARSE_NAT((yyval.u64), (yyvsp[0].literal), (yylsp[0]), "invalid initial table elems"); } -#line 3248 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + case 103: +#line 831 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + (yyval.exported_table).table = (yyvsp[-1].table); + (yyval.exported_table).table.name = (yyvsp[-3].text); + (yyval.exported_table).has_elem_segment = WASM_FALSE; + (yyval.exported_table).export_ = (yyvsp[-2].optional_export); + } +#line 3156 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 121: -#line 910 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { PARSE_NAT((yyval.u64), (yyvsp[0].literal), (yylsp[0]), "invalid max table elems"); } -#line 3254 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + case 104: +#line 838 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + WasmExpr* expr = wasm_new_const_expr(parser->allocator); + expr->loc = (yylsp[-8]); + expr->const_.type = WASM_TYPE_I32; + expr->const_.u32 = 0; + + WASM_ZERO_MEMORY((yyval.exported_table)); + (yyval.exported_table).table.name = (yyvsp[-7].text); + (yyval.exported_table).table.elem_limits.initial = (yyvsp[-2].vars).size; + (yyval.exported_table).table.elem_limits.max = (yyvsp[-2].vars).size; + (yyval.exported_table).table.elem_limits.has_max = WASM_TRUE; + (yyval.exported_table).has_elem_segment = WASM_TRUE; + (yyval.exported_table).elem_segment.offset = expr; + (yyval.exported_table).elem_segment.vars = (yyvsp[-2].vars); + (yyval.exported_table).export_ = (yyvsp[-6].optional_export); + } +#line 3177 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 122: -#line 913 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 105: +#line 857 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.limits).initial = (yyvsp[0].u64); - (yyval.limits).max = 0; - (yyval.limits).has_max = WASM_FALSE; + (yyval.data_segment).memory_var = (yyvsp[-3].var); + (yyval.data_segment).offset = (yyvsp[-2].expr_list).first; + dup_text_list(parser->allocator, &(yyvsp[-1].text_list), &(yyval.data_segment).data, &(yyval.data_segment).size); } -#line 3264 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3187 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 123: -#line 918 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 106: +#line 862 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.limits).initial = (yyvsp[-1].u64); - (yyval.limits).max = (yyvsp[0].u64); - (yyval.limits).has_max = WASM_TRUE; + (yyval.data_segment).memory_var.type = WASM_VAR_TYPE_INDEX; + (yyval.data_segment).memory_var.index = 0; + (yyval.data_segment).offset = (yyvsp[-2].expr_list).first; + dup_text_list(parser->allocator, &(yyvsp[-1].text_list), &(yyval.data_segment).data, &(yyval.data_segment).size); } -#line 3274 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3198 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 124: -#line 925 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 107: +#line 871 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.table).table.elem_limits = (yyvsp[-2].limits); - (yyval.table).has_elem_segment = WASM_FALSE; + WASM_ZERO_MEMORY((yyval.exported_memory)); + (yyval.exported_memory).memory = (yyvsp[-1].memory); + (yyval.exported_memory).memory.name = (yyvsp[-3].text); + (yyval.exported_memory).has_data_segment = WASM_FALSE; + (yyval.exported_memory).export_ = (yyvsp[-2].optional_export); } -#line 3283 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3210 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 125: -#line 929 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 108: +#line 878 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + WasmExpr* expr = wasm_new_const_expr(parser->allocator); + expr->loc = (yylsp[-7]); + expr->const_.type = WASM_TYPE_I32; + expr->const_.u32 = 0; + + WASM_ZERO_MEMORY((yyval.exported_memory)); + (yyval.exported_memory).has_data_segment = WASM_TRUE; + (yyval.exported_memory).data_segment.offset = expr; + dup_text_list(parser->allocator, &(yyvsp[-2].text_list), &(yyval.exported_memory).data_segment.data, + &(yyval.exported_memory).data_segment.size); + uint32_t byte_size = WASM_ALIGN_UP_TO_PAGE((yyval.exported_memory).data_segment.size); + uint32_t page_size = WASM_BYTES_TO_PAGES(byte_size); + (yyval.exported_memory).memory.name = (yyvsp[-6].text); + (yyval.exported_memory).memory.page_limits.initial = page_size; + (yyval.exported_memory).memory.page_limits.max = page_size; + (yyval.exported_memory).memory.page_limits.has_max = WASM_TRUE; + (yyval.exported_memory).export_ = (yyvsp[-5].optional_export); + } +#line 3234 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 109: +#line 898 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { WasmExpr* expr = wasm_new_const_expr(parser->allocator); expr->loc = (yylsp[-6]); expr->const_.type = WASM_TYPE_I32; expr->const_.u32 = 0; - WASM_ZERO_MEMORY((yyval.table)); - (yyval.table).table.elem_limits.initial = (yyvsp[-2].vars).size; - (yyval.table).table.elem_limits.max = (yyvsp[-2].vars).size; - (yyval.table).table.elem_limits.has_max = WASM_TRUE; - (yyval.table).has_elem_segment = WASM_TRUE; - (yyval.table).elem_segment.offset = expr; - (yyval.table).elem_segment.vars = (yyvsp[-2].vars); + WASM_ZERO_MEMORY((yyval.exported_memory)); + (yyval.exported_memory).has_data_segment = WASM_TRUE; + (yyval.exported_memory).data_segment.offset = expr; + dup_text_list(parser->allocator, &(yyvsp[-2].text_list), &(yyval.exported_memory).data_segment.data, + &(yyval.exported_memory).data_segment.size); + uint32_t byte_size = WASM_ALIGN_UP_TO_PAGE((yyval.exported_memory).data_segment.size); + uint32_t page_size = WASM_BYTES_TO_PAGES(byte_size); + (yyval.exported_memory).memory.name = (yyvsp[-5].text); + (yyval.exported_memory).memory.page_limits.initial = page_size; + (yyval.exported_memory).memory.page_limits.max = page_size; + (yyval.exported_memory).memory.page_limits.has_max = WASM_TRUE; + (yyval.exported_memory).export_.has_export = WASM_FALSE; } -#line 3302 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3258 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 126: -#line 945 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 110: +#line 920 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.data_segment).offset = (yyvsp[-2].expr_list).first; - dup_text_list(parser->allocator, &(yyvsp[-1].text_list), &(yyval.data_segment).data, &(yyval.data_segment).size); + WASM_ZERO_MEMORY((yyval.exported_global)); + (yyval.exported_global).global = (yyvsp[-2].global); + (yyval.exported_global).global.name = (yyvsp[-4].text); + (yyval.exported_global).global.init_expr = (yyvsp[-1].expr_list).first; + (yyval.exported_global).export_ = (yyvsp[-3].optional_export); } -#line 3311 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3270 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 127: -#line 951 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { PARSE_NAT((yyval.u64), (yyvsp[0].literal), (yylsp[0]), "invalid initial memory pages"); } -#line 3317 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + case 111: +#line 927 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + WASM_ZERO_MEMORY((yyval.exported_global)); + (yyval.exported_global).global = (yyvsp[-2].global); + (yyval.exported_global).global.name = (yyvsp[-3].text); + (yyval.exported_global).global.init_expr = (yyvsp[-1].expr_list).first; + (yyval.exported_global).export_.has_export = WASM_FALSE; + } +#line 3282 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 128: -#line 954 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { PARSE_NAT((yyval.u64), (yyvsp[0].literal), (yylsp[0]), "invalid max memory pages"); } -#line 3323 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + case 112: +#line 940 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + (yyval.import) = new_import(parser->allocator); + (yyval.import)->name = (yyvsp[-2].text); + (yyval.import)->kind = WASM_IMPORT_KIND_FUNC; + (yyval.import)->func.decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + (yyval.import)->func.decl.type_var = (yyvsp[-1].var); + } +#line 3294 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 129: -#line 957 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 113: +#line 947 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.limits).initial = (yyvsp[0].u64); - (yyval.limits).max = 0; - (yyval.limits).has_max = WASM_FALSE; + (yyval.import) = new_import(parser->allocator); + (yyval.import)->name = (yyvsp[-2].text); + (yyval.import)->kind = WASM_IMPORT_KIND_FUNC; + (yyval.import)->func.decl.sig = (yyvsp[-1].func_sig); } -#line 3333 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3305 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 130: -#line 962 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 114: +#line 953 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.limits).initial = (yyvsp[-1].u64); - (yyval.limits).max = (yyvsp[0].u64); - (yyval.limits).has_max = WASM_TRUE; + (yyval.import) = new_import(parser->allocator); + (yyval.import)->name = (yyvsp[-2].text); + (yyval.import)->kind = WASM_IMPORT_KIND_TABLE; + (yyval.import)->table = (yyvsp[-1].table); } -#line 3343 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3316 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 131: -#line 969 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 115: +#line 959 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.memory).memory.page_limits = (yyvsp[-1].limits); - (yyval.memory).has_data_segment = WASM_FALSE; + (yyval.import) = new_import(parser->allocator); + (yyval.import)->name = (yyvsp[-2].text); + (yyval.import)->kind = WASM_IMPORT_KIND_MEMORY; + (yyval.import)->memory = (yyvsp[-1].memory); } -#line 3352 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3327 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 132: -#line 973 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 116: +#line 965 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WasmExpr* expr = wasm_new_const_expr(parser->allocator); - expr->loc = (yylsp[-5]); - expr->const_.type = WASM_TYPE_I32; - expr->const_.u32 = 0; + (yyval.import) = new_import(parser->allocator); + (yyval.import)->name = (yyvsp[-2].text); + (yyval.import)->kind = WASM_IMPORT_KIND_GLOBAL; + (yyval.import)->global = (yyvsp[-1].global); + } +#line 3338 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; - WASM_ZERO_MEMORY((yyval.memory)); - (yyval.memory).has_data_segment = WASM_TRUE; - (yyval.memory).data_segment.offset = expr; - dup_text_list(parser->allocator, &(yyvsp[-2].text_list), &(yyval.memory).data_segment.data, - &(yyval.memory).data_segment.size); - uint32_t byte_size = WASM_ALIGN_UP_TO_PAGE((yyval.memory).data_segment.size); - uint32_t page_size = WASM_BYTES_TO_PAGES(byte_size); - (yyval.memory).memory.page_limits.initial = page_size; - (yyval.memory).memory.page_limits.max = page_size; - (yyval.memory).memory.page_limits.has_max = WASM_TRUE; + case 117: +#line 973 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + (yyval.import) = (yyvsp[-1].import); + (yyval.import)->module_name = (yyvsp[-3].text); + (yyval.import)->item_name = (yyvsp[-2].text); } -#line 3374 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3348 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 133: -#line 995 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { (yyval.var) = (yyvsp[-1].var); } -#line 3380 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + case 118: +#line 978 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + (yyval.import) = (yyvsp[-2].import); + (yyval.import)->name = (yyvsp[-3].text); + (yyval.import)->kind = WASM_IMPORT_KIND_FUNC; + (yyval.import)->func.decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + (yyval.import)->func.decl.type_var = (yyvsp[-1].var); + } +#line 3360 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 134: -#line 999 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 119: +#line 985 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WASM_ZERO_MEMORY((yyval.global)); - (yyval.global).type = (yyvsp[-2].type); - (yyval.global).init_expr = (yyvsp[-1].expr_list).first; + (yyval.import) = (yyvsp[-2].import); + (yyval.import)->name = (yyvsp[-3].text); + (yyval.import)->kind = WASM_IMPORT_KIND_FUNC; + (yyval.import)->func.decl.sig = (yyvsp[-1].func_sig); } -#line 3390 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3371 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 135: -#line 1004 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 120: +#line 991 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WASM_ZERO_MEMORY((yyval.global)); - (yyval.global).name = (yyvsp[-3].text); - (yyval.global).type = (yyvsp[-2].type); - (yyval.global).init_expr = (yyvsp[-1].expr_list).first; + (yyval.import) = (yyvsp[-2].import); + (yyval.import)->name = (yyvsp[-3].text); + (yyval.import)->kind = WASM_IMPORT_KIND_TABLE; + (yyval.import)->table = (yyvsp[-1].table); } -#line 3401 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3382 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 136: -#line 1014 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 121: +#line 997 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - WASM_ZERO_MEMORY((yyval.func_type)); - (yyval.func_type).sig = (yyvsp[-2].func_sig); + (yyval.import) = (yyvsp[-2].import); + (yyval.import)->name = (yyvsp[-3].text); + (yyval.import)->kind = WASM_IMPORT_KIND_MEMORY; + (yyval.import)->memory = (yyvsp[-1].memory); } -#line 3410 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3393 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 137: -#line 1018 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 122: +#line 1003 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.func_type).name = (yyvsp[-5].text); - (yyval.func_type).sig = (yyvsp[-2].func_sig); + (yyval.import) = (yyvsp[-2].import); + (yyval.import)->name = (yyvsp[-3].text); + (yyval.import)->kind = WASM_IMPORT_KIND_GLOBAL; + (yyval.import)->global = (yyvsp[-1].global); } -#line 3419 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3404 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 138: -#line 1025 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 123: +#line 1012 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.import) = new_import(parser->allocator); - (yyval.import)->module_name = (yyvsp[-3].text); - (yyval.import)->func_name = (yyvsp[-2].text); - (yyval.import)->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; - (yyval.import)->decl.type_var = (yyvsp[-1].var); + (yyval.import)->module_name = (yyvsp[-2].text); + (yyval.import)->item_name = (yyvsp[-1].text); } -#line 3431 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3414 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 139: -#line 1032 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 124: +#line 1020 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.import) = new_import(parser->allocator); - (yyval.import)->name = (yyvsp[-4].text); - (yyval.import)->module_name = (yyvsp[-3].text); - (yyval.import)->func_name = (yyvsp[-2].text); - (yyval.import)->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; - (yyval.import)->decl.type_var = (yyvsp[-1].var); + WASM_ZERO_MEMORY((yyval.export_)); + (yyval.export_).kind = WASM_EXPORT_KIND_FUNC; + (yyval.export_).var = (yyvsp[-1].var); } -#line 3444 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3424 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 140: -#line 1040 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 125: +#line 1025 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.import) = new_import(parser->allocator); - (yyval.import)->module_name = (yyvsp[-3].text); - (yyval.import)->func_name = (yyvsp[-2].text); - (yyval.import)->decl.sig = (yyvsp[-1].func_sig); + WASM_ZERO_MEMORY((yyval.export_)); + (yyval.export_).kind = WASM_EXPORT_KIND_TABLE; + (yyval.export_).var = (yyvsp[-1].var); } -#line 3455 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3434 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 141: -#line 1046 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 126: +#line 1030 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.import) = new_import(parser->allocator); - (yyval.import)->name = (yyvsp[-4].text); - (yyval.import)->module_name = (yyvsp[-3].text); - (yyval.import)->func_name = (yyvsp[-2].text); - (yyval.import)->decl.sig = (yyvsp[-1].func_sig); + WASM_ZERO_MEMORY((yyval.export_)); + (yyval.export_).kind = WASM_EXPORT_KIND_MEMORY; + (yyval.export_).var = (yyvsp[-1].var); } -#line 3467 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3444 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 142: -#line 1056 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 127: +#line 1035 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.export_).name = (yyvsp[-2].text); + WASM_ZERO_MEMORY((yyval.export_)); + (yyval.export_).kind = WASM_EXPORT_KIND_GLOBAL; (yyval.export_).var = (yyvsp[-1].var); } -#line 3476 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3454 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 143: -#line 1063 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 128: +#line 1042 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.export_memory).name = (yyvsp[-2].text); + (yyval.export_) = (yyvsp[-1].export_); + (yyval.export_).name = (yyvsp[-2].text); } -#line 3484 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3463 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 144: -#line 1069 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 129: +#line 1049 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + WASM_ZERO_MEMORY((yyval.optional_export)); + (yyval.optional_export).has_export = WASM_FALSE; + } +#line 3472 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 131: +#line 1056 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.module) = new_module(parser->allocator); + WASM_ZERO_MEMORY((yyval.optional_export)); + (yyval.optional_export).has_export = WASM_TRUE; + (yyval.optional_export).export_.name = (yyvsp[-1].text); } -#line 3492 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3482 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 145: -#line 1072 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 132: +#line 1067 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { - (yyval.module) = (yyvsp[-1].module); - WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); - field->loc = (yylsp[0]); - field->type = WASM_MODULE_FIELD_TYPE_FUNC; - field->func = *(yyvsp[0].exported_func).func; - wasm_free(parser->allocator, (yyvsp[0].exported_func).func); + WASM_ZERO_MEMORY((yyval.func_type)); + (yyval.func_type).sig = (yyvsp[-1].func_sig); + } +#line 3491 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; - append_implicit_func_declaration(parser->allocator, &(yylsp[0]), (yyval.module), - &field->func.decl); + case 133: +#line 1071 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + (yyval.func_type).name = (yyvsp[-2].text); + (yyval.func_type).sig = (yyvsp[-1].func_sig); + } +#line 3500 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; - WasmFunc* func_ptr = &field->func; - wasm_append_func_ptr_value(parser->allocator, &(yyval.module)->funcs, &func_ptr); - if (field->func.name.start) { - WasmBinding* binding = wasm_insert_binding( - parser->allocator, &(yyval.module)->func_bindings, &field->func.name); - binding->loc = field->loc; - binding->index = (yyval.module)->funcs.size - 1; - } + case 134: +#line 1078 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { (yyval.var) = (yyvsp[-1].var); } +#line 3506 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; - /* is this function using the export syntactic sugar? */ - if ((yyvsp[0].exported_func).export_.name.start != NULL) { - WasmModuleField* export_field = - wasm_append_module_field(parser->allocator, (yyval.module)); - export_field->loc = (yylsp[0]); - export_field->type = WASM_MODULE_FIELD_TYPE_EXPORT; - export_field->export_ = (yyvsp[0].exported_func).export_; - export_field->export_.var.index = (yyval.module)->funcs.size - 1; - - WasmExport* export_ptr = &export_field->export_; - wasm_append_export_ptr_value(parser->allocator, &(yyval.module)->exports, - &export_ptr); - WasmBinding* binding = - wasm_insert_binding(parser->allocator, &(yyval.module)->export_bindings, - &export_field->export_.name); - binding->loc = export_field->loc; - binding->index = (yyval.module)->exports.size - 1; - } + case 135: +#line 1082 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + (yyval.module) = new_module(parser->allocator); } -#line 3536 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3514 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 146: -#line 1111 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 136: +#line 1085 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); - WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); - field->loc = (yylsp[0]); - field->type = WASM_MODULE_FIELD_TYPE_GLOBAL; - field->global = (yyvsp[0].global); - - WasmGlobal* global_ptr = &field->global; - wasm_append_global_ptr_value(parser->allocator, &(yyval.module)->globals, - &global_ptr); - if (field->global.name.start) { - WasmBinding* binding = wasm_insert_binding( - parser->allocator, &(yyval.module)->global_bindings, &field->global.name); - binding->loc = field->loc; - binding->index = (yyval.module)->globals.size - 1; - } + WasmModuleField* field; + APPEND_FIELD_TO_LIST((yyval.module), field, FUNC_TYPE, func_type, (yylsp[0]), (yyvsp[0].func_type)); + APPEND_ITEM_TO_VECTOR((yyval.module), FuncType, func_type, func_types, + &field->func_type); + INSERT_BINDING((yyval.module), func_type, func_types, (yylsp[0]), (yyvsp[0].func_type)); } -#line 3558 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3527 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 147: -#line 1128 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 137: +#line 1093 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); - WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); - field->loc = (yylsp[0]); - field->type = WASM_MODULE_FIELD_TYPE_IMPORT; - field->import = *(yyvsp[0].import); - wasm_free(parser->allocator, (yyvsp[0].import)); - - append_implicit_func_declaration(parser->allocator, &(yylsp[0]), (yyval.module), - &field->import.decl); - - WasmImport* import_ptr = &field->import; - wasm_append_import_ptr_value(parser->allocator, &(yyval.module)->imports, - &import_ptr); - if (field->import.name.start) { - WasmBinding* binding = wasm_insert_binding( - parser->allocator, &(yyval.module)->import_bindings, &field->import.name); - binding->loc = field->loc; - binding->index = (yyval.module)->imports.size - 1; - } + WasmModuleField* field; + APPEND_FIELD_TO_LIST((yyval.module), field, GLOBAL, global, (yylsp[0]), (yyvsp[0].exported_global).global); + APPEND_ITEM_TO_VECTOR((yyval.module), Global, global, globals, &field->global); + INSERT_BINDING((yyval.module), global, globals, (yylsp[0]), (yyvsp[0].exported_global).global); + APPEND_INLINE_EXPORT((yyval.module), GLOBAL, (yylsp[0]), (yyvsp[0].exported_global), (yyval.module)->globals.size - 1); } -#line 3584 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3540 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 148: -#line 1149 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 138: +#line 1101 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); - WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); - field->loc = (yylsp[0]); - field->type = WASM_MODULE_FIELD_TYPE_EXPORT; - field->export_ = (yyvsp[0].export_); - - WasmExport* export_ptr = &field->export_; - wasm_append_export_ptr_value(parser->allocator, &(yyval.module)->exports, - &export_ptr); - if (field->export_.name.start) { - WasmBinding* binding = wasm_insert_binding( - parser->allocator, &(yyval.module)->export_bindings, &field->export_.name); - binding->loc = field->loc; - binding->index = (yyval.module)->exports.size - 1; + WasmModuleField* field; + APPEND_FIELD_TO_LIST((yyval.module), field, TABLE, table, (yylsp[0]), (yyvsp[0].exported_table).table); + APPEND_ITEM_TO_VECTOR((yyval.module), Table, table, tables, &field->table); + INSERT_BINDING((yyval.module), table, tables, (yylsp[0]), (yyvsp[0].exported_table).table); + APPEND_INLINE_EXPORT((yyval.module), TABLE, (yylsp[0]), (yyvsp[0].exported_table), (yyval.module)->tables.size - 1); + + if ((yyvsp[0].exported_table).has_elem_segment) { + WasmModuleField* elem_segment_field; + APPEND_FIELD_TO_LIST((yyval.module), elem_segment_field, ELEM_SEGMENT, elem_segment, + (yylsp[0]), (yyvsp[0].exported_table).elem_segment); + APPEND_ITEM_TO_VECTOR((yyval.module), ElemSegment, elem_segment, elem_segments, + &elem_segment_field->elem_segment); } + } -#line 3606 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3562 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 149: -#line 1166 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 139: +#line 1118 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); - WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); - field->loc = (yylsp[0]); - field->type = WASM_MODULE_FIELD_TYPE_EXPORT_MEMORY; - field->export_memory = (yyvsp[0].export_memory); - (yyval.module)->export_memory = &field->export_memory; + WasmModuleField* field; + APPEND_FIELD_TO_LIST((yyval.module), field, MEMORY, memory, (yylsp[0]), (yyvsp[0].exported_memory).memory); + APPEND_ITEM_TO_VECTOR((yyval.module), Memory, memory, memories, &field->memory); + INSERT_BINDING((yyval.module), memory, memories, (yylsp[0]), (yyvsp[0].exported_memory).memory); + APPEND_INLINE_EXPORT((yyval.module), MEMORY, (yylsp[0]), (yyvsp[0].exported_memory), (yyval.module)->memories.size - 1); + + if ((yyvsp[0].exported_memory).has_data_segment) { + WasmModuleField* data_segment_field; + APPEND_FIELD_TO_LIST((yyval.module), data_segment_field, DATA_SEGMENT, data_segment, + (yylsp[0]), (yyvsp[0].exported_memory).data_segment); + APPEND_ITEM_TO_VECTOR((yyval.module), DataSegment, data_segment, data_segments, + &data_segment_field->data_segment); + } } -#line 3619 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3583 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 150: -#line 1174 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 140: +#line 1134 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); - WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); - field->loc = (yylsp[0]); - field->type = WASM_MODULE_FIELD_TYPE_TABLE; - field->table = (yyvsp[0].table).table; - (yyval.module)->table = &field->table; - - /* is this table using the elem_segment syntactic sugar? */ - if ((yyvsp[0].table).has_elem_segment) { - WasmModuleField* elem_segment_field = - wasm_append_module_field(parser->allocator, (yyval.module)); - elem_segment_field->loc = (yylsp[0]); - elem_segment_field->type = WASM_MODULE_FIELD_TYPE_ELEM_SEGMENT; - elem_segment_field->elem_segment = (yyvsp[0].table).elem_segment; - - WasmElemSegment* elem_segment_ptr = &elem_segment_field->elem_segment; - wasm_append_elem_segment_ptr_value( - parser->allocator, &(yyval.module)->elem_segments, &elem_segment_ptr); - } + WasmModuleField* field; + APPEND_FIELD_TO_LIST((yyval.module), field, FUNC, func, (yylsp[0]), *(yyvsp[0].exported_func).func); + wasm_free(parser->allocator, (yyvsp[0].exported_func).func); + append_implicit_func_declaration(parser->allocator, &(yylsp[0]), (yyval.module), + &field->func.decl); + APPEND_ITEM_TO_VECTOR((yyval.module), Func, func, funcs, &field->func); + INSERT_BINDING((yyval.module), func, funcs, (yylsp[0]), *(yyvsp[0].exported_func).func); + APPEND_INLINE_EXPORT((yyval.module), FUNC, (yylsp[0]), (yyvsp[0].exported_func), (yyval.module)->funcs.size - 1); } -#line 3645 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3599 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 151: -#line 1195 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 141: +#line 1145 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); - WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); - field->loc = (yylsp[0]); - field->type = WASM_MODULE_FIELD_TYPE_ELEM_SEGMENT; - field->elem_segment = (yyvsp[0].elem_segment); - - WasmElemSegment* elem_segment_ptr = &field->elem_segment; - wasm_append_elem_segment_ptr_value(parser->allocator, &(yyval.module)->elem_segments, - &elem_segment_ptr); + WasmModuleField* field; + APPEND_FIELD_TO_LIST((yyval.module), field, ELEM_SEGMENT, elem_segment, (yylsp[0]), (yyvsp[0].elem_segment)); + APPEND_ITEM_TO_VECTOR((yyval.module), ElemSegment, elem_segment, elem_segments, + &field->elem_segment); } -#line 3661 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3611 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 152: -#line 1206 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 142: +#line 1152 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); - WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); - field->loc = (yylsp[0]); - field->type = WASM_MODULE_FIELD_TYPE_FUNC_TYPE; - field->func_type = (yyvsp[0].func_type); - - WasmFuncType* func_type_ptr = &field->func_type; - wasm_append_func_type_ptr_value(parser->allocator, &(yyval.module)->func_types, - &func_type_ptr); - if (field->func_type.name.start) { - WasmBinding* binding = - wasm_insert_binding(parser->allocator, &(yyval.module)->func_type_bindings, - &field->func_type.name); - binding->loc = field->loc; - binding->index = (yyval.module)->func_types.size - 1; - } + WasmModuleField* field; + APPEND_FIELD_TO_LIST((yyval.module), field, DATA_SEGMENT, data_segment, (yylsp[0]), (yyvsp[0].data_segment)); + APPEND_ITEM_TO_VECTOR((yyval.module), DataSegment, data_segment, data_segments, + &field->data_segment); } -#line 3684 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3623 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 153: -#line 1224 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 143: +#line 1159 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); - WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); - field->loc = (yylsp[0]); - field->type = WASM_MODULE_FIELD_TYPE_MEMORY; - field->memory = (yyvsp[0].memory).memory; - (yyval.module)->memory = &field->memory; - - /* is this table using the memory data syntactic sugar? */ - if ((yyvsp[0].memory).has_data_segment) { - WasmModuleField* data_segment_field = - wasm_append_module_field(parser->allocator, (yyval.module)); - data_segment_field->loc = (yylsp[0]); - data_segment_field->type = WASM_MODULE_FIELD_TYPE_DATA_SEGMENT; - data_segment_field->data_segment = (yyvsp[0].memory).data_segment; - - WasmDataSegment* data_segment_ptr = &data_segment_field->data_segment; - wasm_append_data_segment_ptr_value( - parser->allocator, &(yyval.module)->data_segments, &data_segment_ptr); - } + WasmModuleField* field; + APPEND_FIELD_TO_LIST((yyval.module), field, START, start, (yylsp[0]), (yyvsp[0].var)); + (yyval.module)->start = &field->start; } -#line 3710 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3634 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 154: -#line 1245 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 144: +#line 1165 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); - WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); - field->loc = (yylsp[0]); - field->type = WASM_MODULE_FIELD_TYPE_DATA_SEGMENT; - field->data_segment = (yyvsp[0].data_segment); - - WasmDataSegment* data_segment_ptr = &field->data_segment; - wasm_append_data_segment_ptr_value(parser->allocator, &(yyval.module)->data_segments, - &data_segment_ptr); + WasmModuleField* field; + APPEND_FIELD_TO_LIST((yyval.module), field, IMPORT, import, (yylsp[0]), *(yyvsp[0].import)); + switch ((yyvsp[0].import)->kind) { + case WASM_IMPORT_KIND_FUNC: + append_implicit_func_declaration(parser->allocator, &(yylsp[0]), (yyval.module), + &(yyvsp[0].import)->func.decl); + APPEND_ITEM_TO_VECTOR((yyval.module), Func, func, funcs, &field->import.func); + INSERT_BINDING((yyval.module), func, funcs, (yylsp[0]), *(yyvsp[0].import)); + break; + case WASM_IMPORT_KIND_TABLE: + APPEND_ITEM_TO_VECTOR((yyval.module), Table, table, tables, &field->import.table); + INSERT_BINDING((yyval.module), table, tables, (yylsp[0]), *(yyvsp[0].import)); + break; + case WASM_IMPORT_KIND_MEMORY: + APPEND_ITEM_TO_VECTOR((yyval.module), Memory, memory, memories, + &field->import.memory); + INSERT_BINDING((yyval.module), memory, memories, (yylsp[0]), *(yyvsp[0].import)); + break; + case WASM_IMPORT_KIND_GLOBAL: + APPEND_ITEM_TO_VECTOR((yyval.module), Global, global, globals, + &field->import.global); + INSERT_BINDING((yyval.module), global, globals, (yylsp[0]), *(yyvsp[0].import)); + break; + } + wasm_free(parser->allocator, (yyvsp[0].import)); + APPEND_ITEM_TO_VECTOR((yyval.module), Import, import, imports, &field->import); } -#line 3726 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3668 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 155: -#line 1256 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 145: +#line 1194 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.module) = (yyvsp[-1].module); WasmModuleField* field = wasm_append_module_field(parser->allocator, (yyval.module)); - field->loc = (yylsp[0]); - field->type = WASM_MODULE_FIELD_TYPE_START; - field->start = (yyvsp[0].var); - (yyval.module)->start = &field->start; + APPEND_FIELD_TO_LIST((yyval.module), field, EXPORT, export_, (yylsp[0]), (yyvsp[0].export_)); + APPEND_ITEM_TO_VECTOR((yyval.module), Export, export, exports, &field->export_); + INSERT_BINDING((yyval.module), export, exports, (yylsp[0]), (yyvsp[0].export_)); } -#line 3739 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3680 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 156: -#line 1267 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 146: +#line 1204 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.raw_module).type = WASM_RAW_MODULE_TYPE_TEXT; (yyval.raw_module).text = (yyvsp[-1].module); - (yyval.raw_module).loc = (yylsp[-2]); + (yyval.raw_module).text->name = (yyvsp[-2].text); + (yyval.raw_module).loc = (yylsp[-3]); /* resolve func type variables where the signature was not specified * explicitly */ @@ -3763,33 +3705,36 @@ yyreduce: for (i = 0; i < (yyvsp[-1].module)->imports.size; ++i) { WasmImport* import = (yyvsp[-1].module)->imports.data[i]; - if (wasm_decl_has_func_type(&import->decl) && - is_empty_signature(&import->decl.sig)) { + if (import->kind == WASM_IMPORT_KIND_FUNC && + wasm_decl_has_func_type(&import->func.decl) && + is_empty_signature(&import->func.decl.sig)) { WasmFuncType* func_type = - wasm_get_func_type_by_var((yyvsp[-1].module), &import->decl.type_var); + wasm_get_func_type_by_var((yyvsp[-1].module), &import->func.decl.type_var); if (func_type) { - import->decl.sig = func_type->sig; - import->decl.flags |= WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE; + import->func.decl.sig = func_type->sig; + import->func.decl.flags |= + WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE; } } } } -#line 3778 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3722 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 157: -#line 1301 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 147: +#line 1241 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.raw_module).type = WASM_RAW_MODULE_TYPE_BINARY; - (yyval.raw_module).loc = (yylsp[-2]); + (yyval.raw_module).binary.name = (yyvsp[-2].text); + (yyval.raw_module).loc = (yylsp[-3]); dup_text_list(parser->allocator, &(yyvsp[-1].text_list), &(yyval.raw_module).binary.data, &(yyval.raw_module).binary.size); wasm_destroy_text_list(parser->allocator, &(yyvsp[-1].text_list)); } -#line 3789 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3734 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 158: -#line 1310 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 148: +#line 1251 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { if ((yyvsp[0].raw_module).type == WASM_RAW_MODULE_TYPE_TEXT) { (yyval.module) = (yyvsp[0].raw_module).text; @@ -3807,101 +3752,142 @@ yyreduce: wasm_read_binary_ast(parser->allocator, (yyvsp[0].raw_module).binary.data, (yyvsp[0].raw_module).binary.size, &options, &error_handler, (yyval.module)); wasm_free(parser->allocator, (yyvsp[0].raw_module).binary.data); + (yyval.module)->name = (yyvsp[0].raw_module).binary.name; } } -#line 3813 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3759 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 159: -#line 1334 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 149: +#line 1276 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { WASM_ZERO_MEMORY((yyval.text)); } +#line 3765 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 150: +#line 1277 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { DUPTEXT((yyval.text), (yyvsp[0].text)); } +#line 3771 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 151: +#line 1281 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + WASM_ZERO_MEMORY((yyval.action)); + (yyval.action).loc = (yylsp[-4]); + (yyval.action).module_var_name = (yyvsp[-3].text); + (yyval.action).type = WASM_ACTION_TYPE_INVOKE; + (yyval.action).invoke.name = (yyvsp[-2].text); + (yyval.action).invoke.args = (yyvsp[-1].consts); + } +#line 3784 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 152: +#line 1289 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + WASM_ZERO_MEMORY((yyval.action)); + (yyval.action).loc = (yylsp[-3]); + (yyval.action).module_var_name = (yyvsp[-2].text); + (yyval.action).type = WASM_ACTION_TYPE_GET; + (yyval.action).invoke.name = (yyvsp[-1].text); + } +#line 3796 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 153: +#line 1299 "src/wasm-ast-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 3824 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3807 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 160: -#line 1340 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 154: +#line 1305 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new_command(parser->allocator); - (yyval.command)->type = WASM_COMMAND_TYPE_INVOKE; - (yyval.command)->invoke.loc = (yylsp[-3]); - (yyval.command)->invoke.name = (yyvsp[-2].text); - (yyval.command)->invoke.args = (yyvsp[-1].consts); + (yyval.command)->type = WASM_COMMAND_TYPE_ACTION; + (yyval.command)->action = (yyvsp[0].action); } -#line 3836 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3817 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 161: -#line 1347 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 155: +#line 1310 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + { + (yyval.command) = new_command(parser->allocator); + (yyval.command)->type = WASM_COMMAND_TYPE_REGISTER; + (yyval.command)->register_.module_name = (yyvsp[-2].text); + (yyval.command)->register_.module_var_name = (yyvsp[-1].text); + } +#line 3828 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ + break; + + case 156: +#line 1316 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new_command(parser->allocator); (yyval.command)->type = WASM_COMMAND_TYPE_ASSERT_INVALID; (yyval.command)->assert_invalid.module = (yyvsp[-2].raw_module); (yyval.command)->assert_invalid.text = (yyvsp[-1].text); } -#line 3847 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3839 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 162: -#line 1353 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 157: +#line 1322 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new_command(parser->allocator); (yyval.command)->type = WASM_COMMAND_TYPE_ASSERT_RETURN; - (yyval.command)->assert_return.invoke.loc = (yylsp[-5]); - (yyval.command)->assert_return.invoke.name = (yyvsp[-4].text); - (yyval.command)->assert_return.invoke.args = (yyvsp[-3].consts); - (yyval.command)->assert_return.expected = (yyvsp[-1].const_); + (yyval.command)->assert_return.action = (yyvsp[-2].action); + (yyval.command)->assert_return.expected = (yyvsp[-1].consts); } -#line 3860 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3850 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 163: -#line 1361 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 158: +#line 1328 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new_command(parser->allocator); (yyval.command)->type = WASM_COMMAND_TYPE_ASSERT_RETURN_NAN; - (yyval.command)->assert_return_nan.invoke.loc = (yylsp[-4]); - (yyval.command)->assert_return_nan.invoke.name = (yyvsp[-3].text); - (yyval.command)->assert_return_nan.invoke.args = (yyvsp[-2].consts); + (yyval.command)->assert_return_nan.action = (yyvsp[-1].action); } -#line 3872 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3860 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 164: -#line 1368 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 159: +#line 1333 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.command) = new_command(parser->allocator); (yyval.command)->type = WASM_COMMAND_TYPE_ASSERT_TRAP; - (yyval.command)->assert_trap.invoke.loc = (yylsp[-5]); - (yyval.command)->assert_trap.invoke.name = (yyvsp[-4].text); - (yyval.command)->assert_trap.invoke.args = (yyvsp[-3].consts); + (yyval.command)->assert_trap.action = (yyvsp[-2].action); (yyval.command)->assert_trap.text = (yyvsp[-1].text); } -#line 3885 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3871 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 165: -#line 1378 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 160: +#line 1341 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.commands)); } -#line 3891 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3877 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 166: -#line 1379 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 161: +#line 1342 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.commands) = (yyvsp[-1].commands); wasm_append_command_value(parser->allocator, &(yyval.commands), (yyvsp[0].command)); wasm_free(parser->allocator, (yyvsp[0].command)); } -#line 3901 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3887 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 167: -#line 1387 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 162: +#line 1350 "src/wasm-ast-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, @@ -3912,41 +3898,35 @@ yyreduce: } wasm_free(parser->allocator, (char*)(yyvsp[-1].literal).text.start); } -#line 3916 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ - break; - - case 168: -#line 1399 "src/wasm-ast-parser.y" /* yacc.c:1646 */ - { (yyval.const_).type = WASM_TYPE_VOID; } -#line 3922 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3902 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 170: -#line 1403 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 163: +#line 1362 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { WASM_ZERO_MEMORY((yyval.consts)); } -#line 3928 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3908 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 171: -#line 1404 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 164: +#line 1363 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.consts) = (yyvsp[-1].consts); wasm_append_const_value(parser->allocator, &(yyval.consts), &(yyvsp[0].const_)); } -#line 3937 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3917 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; - case 172: -#line 1411 "src/wasm-ast-parser.y" /* yacc.c:1646 */ + case 165: +#line 1370 "src/wasm-ast-parser.y" /* yacc.c:1646 */ { (yyval.script).commands = (yyvsp[0].commands); parser->script = (yyval.script); } -#line 3946 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3926 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ break; -#line 3950 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ +#line 3930 "src/prebuilt/wasm-ast-parser-gen.c" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -4181,7 +4161,7 @@ yyreturn: #endif return yyresult; } -#line 1423 "src/wasm-ast-parser.y" /* yacc.c:1906 */ +#line 1382 "src/wasm-ast-parser.y" /* yacc.c:1906 */ static void append_expr_list(WasmExprList* expr_list, WasmExprList* expr) { @@ -4222,30 +4202,6 @@ static WasmExprList join_exprs2(WasmLocation* loc, WasmExprList* expr1, return result; } -static WasmExprList join_exprs3(WasmLocation* loc, WasmExprList* expr1, - WasmExprList* expr2, WasmExpr* expr3) { - WasmExprList result; - WASM_ZERO_MEMORY(result); - append_expr_list(&result, expr1); - append_expr_list(&result, expr2); - append_expr(&result, expr3); - expr3->loc = *loc; - return result; -} - -static WasmExprList join_exprs4(WasmLocation* loc, WasmExprList* expr1, - WasmExprList* expr2, WasmExprList* expr3, - WasmExpr* expr4) { - WasmExprList result; - WASM_ZERO_MEMORY(result); - append_expr_list(&result, expr1); - append_expr_list(&result, expr2); - append_expr_list(&result, expr3); - append_expr(&result, expr4); - expr4->loc = *loc; - return result; -} - static WasmResult parse_const(WasmType type, WasmLiteralType literal_type, const char* s, @@ -4346,7 +4302,7 @@ static void dup_text_list(WasmAllocator* allocator, } static WasmBool is_empty_signature(WasmFuncSignature* sig) { - return sig->result_type == WASM_TYPE_VOID && sig->param_types.size == 0; + return sig->result_types.size == 0 && sig->param_types.size == 0; } static void append_implicit_func_declaration(WasmAllocator* allocator, diff --git a/src/prebuilt/wasm-ast-parser-gen.h b/src/prebuilt/wasm-ast-parser-gen.h index 915daf50..df27e546 100644 --- a/src/prebuilt/wasm-ast-parser-gen.h +++ b/src/prebuilt/wasm-ast-parser-gen.h @@ -63,60 +63,66 @@ extern int wasm_ast_parser_debug; WASM_TOKEN_TYPE_VAR = 264, WASM_TOKEN_TYPE_VALUE_TYPE = 265, WASM_TOKEN_TYPE_ANYFUNC = 266, - WASM_TOKEN_TYPE_NOP = 267, - WASM_TOKEN_TYPE_DROP = 268, - WASM_TOKEN_TYPE_BLOCK = 269, - WASM_TOKEN_TYPE_END = 270, - WASM_TOKEN_TYPE_IF = 271, - WASM_TOKEN_TYPE_THEN = 272, - WASM_TOKEN_TYPE_ELSE = 273, - WASM_TOKEN_TYPE_LOOP = 274, - WASM_TOKEN_TYPE_BR = 275, - WASM_TOKEN_TYPE_BR_IF = 276, - WASM_TOKEN_TYPE_BR_TABLE = 277, - WASM_TOKEN_TYPE_CALL = 278, - WASM_TOKEN_TYPE_CALL_IMPORT = 279, - WASM_TOKEN_TYPE_CALL_INDIRECT = 280, - WASM_TOKEN_TYPE_RETURN = 281, - WASM_TOKEN_TYPE_GET_LOCAL = 282, - WASM_TOKEN_TYPE_SET_LOCAL = 283, - WASM_TOKEN_TYPE_TEE_LOCAL = 284, - WASM_TOKEN_TYPE_GET_GLOBAL = 285, - WASM_TOKEN_TYPE_SET_GLOBAL = 286, - WASM_TOKEN_TYPE_LOAD = 287, - WASM_TOKEN_TYPE_STORE = 288, - WASM_TOKEN_TYPE_OFFSET_EQ_NAT = 289, - WASM_TOKEN_TYPE_ALIGN_EQ_NAT = 290, - WASM_TOKEN_TYPE_CONST = 291, - WASM_TOKEN_TYPE_UNARY = 292, - WASM_TOKEN_TYPE_BINARY = 293, - WASM_TOKEN_TYPE_COMPARE = 294, - WASM_TOKEN_TYPE_CONVERT = 295, - WASM_TOKEN_TYPE_SELECT = 296, - WASM_TOKEN_TYPE_UNREACHABLE = 297, - WASM_TOKEN_TYPE_CURRENT_MEMORY = 298, - WASM_TOKEN_TYPE_GROW_MEMORY = 299, - WASM_TOKEN_TYPE_FUNC = 300, - WASM_TOKEN_TYPE_START = 301, - WASM_TOKEN_TYPE_TYPE = 302, - WASM_TOKEN_TYPE_PARAM = 303, - WASM_TOKEN_TYPE_RESULT = 304, - WASM_TOKEN_TYPE_LOCAL = 305, - WASM_TOKEN_TYPE_GLOBAL = 306, - WASM_TOKEN_TYPE_MODULE = 307, - WASM_TOKEN_TYPE_TABLE = 308, - WASM_TOKEN_TYPE_ELEM = 309, - WASM_TOKEN_TYPE_MEMORY = 310, - WASM_TOKEN_TYPE_DATA = 311, - WASM_TOKEN_TYPE_OFFSET = 312, - WASM_TOKEN_TYPE_IMPORT = 313, - WASM_TOKEN_TYPE_EXPORT = 314, - WASM_TOKEN_TYPE_ASSERT_INVALID = 315, - WASM_TOKEN_TYPE_ASSERT_RETURN = 316, - WASM_TOKEN_TYPE_ASSERT_RETURN_NAN = 317, - WASM_TOKEN_TYPE_ASSERT_TRAP = 318, - WASM_TOKEN_TYPE_INVOKE = 319, - WASM_TOKEN_TYPE_LOW = 320 + WASM_TOKEN_TYPE_MUT = 267, + WASM_TOKEN_TYPE_NOP = 268, + WASM_TOKEN_TYPE_DROP = 269, + WASM_TOKEN_TYPE_BLOCK = 270, + WASM_TOKEN_TYPE_END = 271, + WASM_TOKEN_TYPE_IF = 272, + WASM_TOKEN_TYPE_THEN = 273, + WASM_TOKEN_TYPE_ELSE = 274, + WASM_TOKEN_TYPE_LOOP = 275, + WASM_TOKEN_TYPE_BR = 276, + WASM_TOKEN_TYPE_BR_IF = 277, + WASM_TOKEN_TYPE_BR_TABLE = 278, + WASM_TOKEN_TYPE_CALL = 279, + WASM_TOKEN_TYPE_CALL_IMPORT = 280, + WASM_TOKEN_TYPE_CALL_INDIRECT = 281, + WASM_TOKEN_TYPE_RETURN = 282, + WASM_TOKEN_TYPE_GET_LOCAL = 283, + WASM_TOKEN_TYPE_SET_LOCAL = 284, + WASM_TOKEN_TYPE_TEE_LOCAL = 285, + WASM_TOKEN_TYPE_GET_GLOBAL = 286, + WASM_TOKEN_TYPE_SET_GLOBAL = 287, + WASM_TOKEN_TYPE_LOAD = 288, + WASM_TOKEN_TYPE_STORE = 289, + WASM_TOKEN_TYPE_OFFSET_EQ_NAT = 290, + WASM_TOKEN_TYPE_ALIGN_EQ_NAT = 291, + WASM_TOKEN_TYPE_CONST = 292, + WASM_TOKEN_TYPE_UNARY = 293, + WASM_TOKEN_TYPE_BINARY = 294, + WASM_TOKEN_TYPE_COMPARE = 295, + WASM_TOKEN_TYPE_CONVERT = 296, + WASM_TOKEN_TYPE_SELECT = 297, + WASM_TOKEN_TYPE_UNREACHABLE = 298, + WASM_TOKEN_TYPE_CURRENT_MEMORY = 299, + WASM_TOKEN_TYPE_GROW_MEMORY = 300, + WASM_TOKEN_TYPE_FUNC = 301, + WASM_TOKEN_TYPE_START = 302, + WASM_TOKEN_TYPE_TYPE = 303, + WASM_TOKEN_TYPE_PARAM = 304, + WASM_TOKEN_TYPE_RESULT = 305, + WASM_TOKEN_TYPE_LOCAL = 306, + WASM_TOKEN_TYPE_GLOBAL = 307, + WASM_TOKEN_TYPE_MODULE = 308, + WASM_TOKEN_TYPE_TABLE = 309, + WASM_TOKEN_TYPE_ELEM = 310, + WASM_TOKEN_TYPE_MEMORY = 311, + WASM_TOKEN_TYPE_DATA = 312, + WASM_TOKEN_TYPE_OFFSET = 313, + WASM_TOKEN_TYPE_IMPORT = 314, + WASM_TOKEN_TYPE_EXPORT = 315, + WASM_TOKEN_TYPE_REGISTER = 316, + WASM_TOKEN_TYPE_INVOKE = 317, + WASM_TOKEN_TYPE_GET = 318, + WASM_TOKEN_TYPE_ASSERT_INVALID = 319, + WASM_TOKEN_TYPE_ASSERT_UNLINKABLE = 320, + WASM_TOKEN_TYPE_ASSERT_RETURN = 321, + WASM_TOKEN_TYPE_ASSERT_RETURN_NAN = 322, + WASM_TOKEN_TYPE_ASSERT_TRAP = 323, + WASM_TOKEN_TYPE_INPUT = 324, + WASM_TOKEN_TYPE_OUTPUT = 325, + WASM_TOKEN_TYPE_LOW = 326 }; #endif diff --git a/src/wasm-ast-checker.c b/src/wasm-ast-checker.c index 999f556d..76790f08 100644 --- a/src/wasm-ast-checker.c +++ b/src/wasm-ast-checker.c @@ -28,34 +28,26 @@ #include "wasm-binary-reader-ast.h" #include "wasm-binary-reader.h" -typedef enum WasmCheckType { - WASM_CHECK_TYPE_VOID = WASM_TYPE_VOID, - WASM_CHECK_TYPE_I32 = WASM_TYPE_I32, - WASM_CHECK_TYPE_I64 = WASM_TYPE_I64, - WASM_CHECK_TYPE_F32 = WASM_TYPE_F32, - WASM_CHECK_TYPE_F64 = WASM_TYPE_F64, - WASM_CHECK_TYPE_ANY = WASM_NUM_TYPES, - WASM_NUM_CHECK_TYPES, - WASM_CHECK_TYPE____ = WASM_CHECK_TYPE_VOID, /* see table in wasm-common.h */ -} WasmCheckType; -WASM_DEFINE_VECTOR(check_type, WasmCheckType); - -static const char* s_type_names[] = {"void", "i32", "i64", "f32", "f64", "any"}; -WASM_STATIC_ASSERT(WASM_ARRAY_SIZE(s_type_names) == WASM_NUM_CHECK_TYPES); +#define WASM_TYPE_ANY WASM_NUM_TYPES + +static const char* s_type_names[] = { + "void", "i32", "i64", "f32", "f64", "any", +}; +WASM_STATIC_ASSERT(WASM_ARRAY_SIZE(s_type_names) == WASM_NUM_TYPES + 1); #define V(rtype, type1, type2, mem_size, code, NAME, text) \ - [code] = WASM_CHECK_TYPE_##rtype, -static WasmCheckType s_opcode_rtype[] = {WASM_FOREACH_OPCODE(V)}; + [code] = WASM_TYPE_##rtype, +static WasmType s_opcode_rtype[] = {WASM_FOREACH_OPCODE(V)}; #undef V #define V(rtype, type1, type2, mem_size, code, NAME, text) \ - [code] = WASM_CHECK_TYPE_##type1, -static WasmCheckType s_opcode_type1[] = {WASM_FOREACH_OPCODE(V)}; + [code] = WASM_TYPE_##type1, +static WasmType s_opcode_type1[] = {WASM_FOREACH_OPCODE(V)}; #undef V #define V(rtype, type1, type2, mem_size, code, NAME, text) \ - [code] = WASM_CHECK_TYPE_##type2, -static WasmCheckType s_opcode_type2[] = {WASM_FOREACH_OPCODE(V)}; + [code] = WASM_TYPE_##type2, +static WasmType s_opcode_type2[] = {WASM_FOREACH_OPCODE(V)}; #undef V #define V(rtype, type1, type2, mem_size, code, NAME, text) [code] = text, @@ -72,10 +64,23 @@ typedef enum CheckStyle { typedef struct LabelNode { const WasmLabel* label; - WasmCheckType type; + const WasmTypeVector* sig; struct LabelNode* next; } LabelNode; +typedef enum ActionResultKind { + ACTION_RESULT_KIND_TYPES, + ACTION_RESULT_KIND_TYPE, +} ActionResultKind; + +typedef struct ActionResult { + ActionResultKind kind; + union { + const WasmTypeVector* types; + WasmType type; + }; +} ActionResult; + typedef struct Context { CheckStyle check_style; WasmSourceErrorHandler* error_handler; @@ -83,8 +88,9 @@ typedef struct Context { WasmAstLexer* lexer; const WasmModule* current_module; const WasmFunc* current_func; + int current_global_index; WasmSizeTVector type_stack_limit; - WasmCheckTypeVector type_stack; + WasmTypeVector type_stack; LabelNode* top_label; int max_depth; WasmResult result; @@ -195,21 +201,6 @@ static WasmResult check_global_var(Context* ctx, return WASM_OK; } -static WasmResult check_import_var(Context* ctx, - const WasmVar* var, - const WasmImport** out_import) { - int index; - if (WASM_FAILED(check_var(ctx, &ctx->current_module->import_bindings, - ctx->current_module->imports.size, var, "import", - &index))) { - return WASM_ERROR; - } - - if (out_import) - *out_import = ctx->current_module->imports.data[index]; - return WASM_OK; -} - static WasmResult check_func_type_var(Context* ctx, const WasmVar* var, const WasmFuncType** out_func_type) { @@ -225,18 +216,47 @@ static WasmResult check_func_type_var(Context* ctx, return WASM_OK; } +static WasmResult check_table_var(Context* ctx, + const WasmVar* var, + const WasmTable** out_table) { + int index; + if (WASM_FAILED(check_var(ctx, &ctx->current_module->table_bindings, + ctx->current_module->tables.size, var, "table", + &index))) { + return WASM_ERROR; + } + + if (out_table) + *out_table = ctx->current_module->tables.data[index]; + return WASM_OK; +} + +static WasmResult check_memory_var(Context* ctx, + const WasmVar* var, + const WasmMemory** out_memory) { + int index; + if (WASM_FAILED(check_var(ctx, &ctx->current_module->memory_bindings, + ctx->current_module->memories.size, var, "memory", + &index))) { + return WASM_ERROR; + } + + if (out_memory) + *out_memory = ctx->current_module->memories.data[index]; + return WASM_OK; +} + static WasmResult check_local_var(Context* ctx, const WasmVar* var, - WasmCheckType* out_type) { - const WasmModule* module = ctx->current_module; + WasmType* out_type) { const WasmFunc* func = ctx->current_func; - int max_index = wasm_get_num_params_and_locals(module, func); + int max_index = wasm_get_num_params_and_locals(func); int index = wasm_get_local_index_by_var(func, var); if (index >= 0 && index < max_index) { if (out_type) { - int num_params = wasm_get_num_params(module, func); + int num_params = wasm_get_num_params(func); if (index < num_params) { - *out_type = wasm_get_param_type(module, func, index); + *out_type = wasm_get_param_type(func, index); } else { *out_type = ctx->current_func->local_types.data[index - num_params]; } @@ -322,10 +342,10 @@ static void push_label(Context* ctx, const WasmLocation* loc, LabelNode* node, const WasmLabel* label, - WasmCheckType type) { + const WasmTypeVector* sig) { node->label = label; node->next = ctx->top_label; - node->type = type; + node->sig = sig; ctx->top_label = node; ctx->max_depth++; } @@ -350,40 +370,71 @@ static void pop_type_stack_limit(Context* ctx) { ctx->type_stack_limit.size--; } -static void push_type(Context* ctx, WasmCheckType type) { - if (type != WASM_CHECK_TYPE_VOID) - wasm_append_check_type_value(ctx->allocator, &ctx->type_stack, &type); +static WasmResult check_type_stack_limit(Context* ctx, + const WasmLocation* loc, + size_t expected, + const char* desc) { + size_t limit = type_stack_limit(ctx); + size_t avail = ctx->type_stack.size - limit; + if (expected > avail) { + print_error(ctx, CHECK_STYLE_FULL, loc, + "type stack size too small at %s. got %" PRIzd + ", expected at least %" PRIzd, + desc, avail, expected); + return WASM_ERROR; + } + return WASM_OK; +} + +static void reset_type_stack_to_limit(Context* ctx) { + ctx->type_stack.size = type_stack_limit(ctx); } -static WasmCheckType peek_type(Context* ctx, size_t depth, int arity) { +static void push_type(Context* ctx, WasmType type) { + if (type != WASM_TYPE_VOID) + wasm_append_type_value(ctx->allocator, &ctx->type_stack, &type); +} + +static void push_types(Context* ctx, const WasmTypeVector* types) { + size_t i; + for (i = 0; i < types->size; ++i) + push_type(ctx, types->data[i]); +} + +static WasmType peek_type(Context* ctx, size_t depth, int arity) { if (arity > 0) { if (depth < ctx->type_stack.size - type_stack_limit(ctx)) { return ctx->type_stack.data[ctx->type_stack.size - depth - 1]; } else { /* return any type to allow type-checking to continue; the caller should * have already raised an error about the stack underflow. */ - return WASM_CHECK_TYPE_I32; + return WASM_TYPE_I32; } } else { - return WASM_CHECK_TYPE_VOID; + return WASM_TYPE_VOID; } } -static WasmCheckType top_type(Context* ctx) { +static WasmType top_type(Context* ctx) { return peek_type(ctx, 0, 1); } -static WasmCheckType pop_type(Context* ctx) { - WasmCheckType result = top_type(ctx); +static WasmType pop_type(Context* ctx) { + WasmType result = top_type(ctx); if (ctx->type_stack.size > type_stack_limit(ctx)) ctx->type_stack.size--; return result; } +static void drop_types(Context* ctx, size_t count) { + assert(ctx->type_stack.size >= type_stack_limit(ctx) + count); + ctx->type_stack.size -= count; +} + static void check_type(Context* ctx, const WasmLocation* loc, - WasmCheckType actual, - WasmCheckType expected, + WasmType actual, + WasmType expected, const char* desc) { if (actual != expected) { print_error(ctx, CHECK_STYLE_FULL, loc, @@ -392,110 +443,149 @@ static void check_type(Context* ctx, } } -static void check_type_arg(Context* ctx, - const WasmLocation* loc, - WasmCheckType actual, - WasmCheckType expected, - const char* desc, - int arg_index) { +static void check_type_index(Context* ctx, + const WasmLocation* loc, + WasmType actual, + WasmType expected, + const char* desc, + int index, + const char* index_kind) { if (actual != expected) { print_error(ctx, CHECK_STYLE_FULL, loc, - "type mismatch for argument %d of %s. got %s, expected %s", - arg_index, desc, s_type_names[actual], s_type_names[expected]); + "type mismatch for %s %d of %s. got %s, expected %s", + index_kind, index, desc, s_type_names[actual], + s_type_names[expected]); } } -static void check_assert_return_nan_type(Context* ctx, - const WasmLocation* loc, - WasmCheckType actual, - const char* desc) { - /* when using assert_return_nan, the result can be either a f32 or f64 type - * so we special case it here. */ - if (actual != WASM_CHECK_TYPE_F32 && actual != WASM_CHECK_TYPE_F64) { +static void check_types(Context* ctx, + const WasmLocation* loc, + const WasmTypeVector* actual, + const WasmTypeVector* expected, + const char* desc, + const char* index_kind) { + if (actual->size == expected->size) { + size_t i; + for (i = 0; i < actual->size; ++i) { + check_type_index(ctx, loc, actual->data[i], expected->data[i], desc, i, + index_kind); + } + } else { print_error(ctx, CHECK_STYLE_FULL, loc, - "type mismatch at %s. got %s, expected f32 or f64", desc, - s_type_names[actual]); + "expected %" PRIzd " %ss, got %" PRIzd, expected->size, + index_kind, actual->size); } } -static WasmCheckType join_type(Context* ctx, - const WasmLocation* loc, - WasmCheckType t1, - const char* t1_desc, - WasmCheckType t2, - const char* t2_desc) { - if (t1 == WASM_CHECK_TYPE_ANY) { - return t2; - } else if (t2 == WASM_CHECK_TYPE_ANY) { - return t1; - } else if (t1 == t2) { - return t1; +static void check_const_types(Context* ctx, + const WasmLocation* loc, + const WasmTypeVector* actual, + const WasmConstVector* expected, + const char* desc) { + if (actual->size == expected->size) { + size_t i; + for (i = 0; i < actual->size; ++i) { + check_type_index(ctx, loc, actual->data[i], expected->data[i].type, desc, + i, "result"); + } } else { print_error(ctx, CHECK_STYLE_FULL, loc, - "unable to join type %s (%s) with type %s (%s).", - s_type_names[t1], t1_desc, s_type_names[t2], t2_desc); - return t1; + "expected %" PRIzd " results, got %" PRIzd, expected->size, + actual->size); } } -static void unify_label_type(Context* ctx, +static void check_const_type(Context* ctx, const WasmLocation* loc, - LabelNode* node, - WasmCheckType type, + WasmType actual, + const WasmConstVector* expected, const char* desc) { - if (node->type == WASM_CHECK_TYPE_ANY) { - node->type = type; - } else if (type != WASM_CHECK_TYPE_ANY && node->type != type) { - print_error(ctx, CHECK_STYLE_FULL, loc, - "type mismatch at %s. got %s, expected %s", desc, - s_type_names[type], s_type_names[node->type]); + assert(actual != WASM_TYPE_ANY); + WasmTypeVector actual_types; + + WASM_ZERO_MEMORY(actual_types); + actual_types.size = actual == WASM_TYPE_VOID ? 0 : 1; + actual_types.data = &actual; + check_const_types(ctx, loc, &actual_types, expected, desc); +} + +static void pop_and_check_1_type(Context* ctx, + const WasmLocation* loc, + WasmType expected, + const char* desc) { + if (WASM_SUCCEEDED(check_type_stack_limit(ctx, loc, 1, desc))) { + WasmType actual = pop_type(ctx); + check_type(ctx, loc, actual, expected, desc); } } -static void transform_stack(Context* ctx, - const WasmLocation* loc, - const char* desc, - size_t before_size, - size_t after_size, - ...) { - size_t i; - va_list args; - va_start(args, after_size); - size_t limit = type_stack_limit(ctx); - size_t avail = ctx->type_stack.size - limit; - if (before_size <= avail) { - for (i = 0; i < before_size; ++i) { - WasmCheckType actual = - ctx->type_stack.data[ctx->type_stack.size - before_size + i]; - WasmCheckType expected = va_arg(args, WasmCheckType); - /* TODO(binji): could give a better location for the error by storing the - * location in the type stack; i.e. where this type was added to the - * stack */ - check_type(ctx, loc, actual, expected, desc); +static void pop_and_check_2_types(Context* ctx, + const WasmLocation* loc, + WasmType expected1, + WasmType expected2, + const char* desc) { + if (WASM_SUCCEEDED(check_type_stack_limit(ctx, loc, 2, desc))) { + WasmType actual2 = pop_type(ctx); + WasmType actual1 = pop_type(ctx); + check_type(ctx, loc, actual1, expected1, desc); + check_type(ctx, loc, actual2, expected2, desc); + } +} + +static void check_opcode1(Context* ctx, + const WasmLocation* loc, + WasmOpcode opcode) { + pop_and_check_1_type(ctx, loc, s_opcode_type1[opcode], s_opcode_name[opcode]); + push_type(ctx, s_opcode_rtype[opcode]); +} + +static void check_opcode2(Context* ctx, + const WasmLocation* loc, + WasmOpcode opcode) { + pop_and_check_2_types(ctx, loc, s_opcode_type1[opcode], + s_opcode_type2[opcode], s_opcode_name[opcode]); + push_type(ctx, s_opcode_rtype[opcode]); +} + +static void check_n_types(Context* ctx, + const WasmLocation* loc, + const WasmTypeVector* expected, + const char* desc) { + if (WASM_SUCCEEDED(check_type_stack_limit(ctx, loc, expected->size, desc))) { + size_t i; + for (i = 0; i < expected->size; ++i) { + WasmType actual = ctx->type_stack.data[i]; + check_type(ctx, loc, actual, expected->data[expected->size - i - 1], + desc); } - ctx->type_stack.size -= before_size; - } else { + } +} + +static void check_assert_return_nan_type(Context* ctx, + const WasmLocation* loc, + WasmType actual, + const char* desc) { + /* when using assert_return_nan, the result can be either a f32 or f64 type + * so we special case it here. */ + if (actual != WASM_TYPE_F32 && actual != WASM_TYPE_F64) { print_error(ctx, CHECK_STYLE_FULL, loc, - "type stack size too small at %s. got %" PRIzd - ", expected at least %" PRIzd, - desc, avail, before_size); - ctx->type_stack.size = limit; + "type mismatch at %s. got %s, expected f32 or f64", desc, + s_type_names[actual]); } - assert(after_size <= 1); - if (after_size > 0) - push_type(ctx, va_arg(args, WasmCheckType)); - va_end(args); } -static void check_br(Context* ctx, - const WasmLocation* loc, - const WasmVar* var, - WasmCheckType type, - const char* desc) { +static WasmResult check_br(Context* ctx, + const WasmLocation* loc, + const WasmVar* var, + const WasmBlockSignature** out_sig, + const char* desc) { LabelNode* node; - if (WASM_SUCCEEDED(check_label_var(ctx, ctx->top_label, var, &node))) { - unify_label_type(ctx, loc, node, type, desc); + WasmResult result = check_label_var(ctx, ctx->top_label, var, &node); + if (WASM_SUCCEEDED(result)) { + check_n_types(ctx, loc, node->sig, desc); + *out_sig = node->sig; } + return result; } static void check_call(Context* ctx, @@ -506,13 +596,13 @@ static void check_call(Context* ctx, size_t expected_args = sig->param_types.size; size_t limit = type_stack_limit(ctx); size_t avail = ctx->type_stack.size - limit; + size_t i; if (expected_args <= avail) { - size_t i; for (i = 0; i < sig->param_types.size; ++i) { - WasmCheckType actual = + WasmType actual = ctx->type_stack.data[ctx->type_stack.size - expected_args + i]; - WasmCheckType expected = sig->param_types.data[i]; - check_type_arg(ctx, loc, actual, expected, desc, i); + WasmType expected = sig->param_types.data[i]; + check_type_index(ctx, loc, actual, expected, desc, i, "argument"); } ctx->type_stack.size -= expected_args; } else { @@ -522,12 +612,13 @@ static void check_call(Context* ctx, desc, avail, expected_args); ctx->type_stack.size = limit; } - push_type(ctx, sig->result_type); + for (i = 0; i < sig->result_types.size; ++i) + push_type(ctx, sig->result_types.data[i]); } static void check_expr(Context* ctx, const WasmExpr* expr); -static WasmCheckType check_block(Context* ctx, +static WasmType check_block(Context* ctx, const WasmLocation* loc, const WasmExpr* first, const char* desc) { @@ -537,319 +628,224 @@ static WasmCheckType check_block(Context* ctx, for (expr = first; expr; expr = expr->next) { check_expr(ctx, expr); /* stop typechecking if we hit unreachable code */ - if (top_type(ctx) == WASM_CHECK_TYPE_ANY) + if (top_type(ctx) == WASM_TYPE_ANY) break; } - WasmCheckType result = top_type(ctx); - if (result != WASM_CHECK_TYPE_ANY) { + WasmType result = top_type(ctx); + if (result != WASM_TYPE_ANY) { size_t result_arity = ctx->type_stack.size - limit; if (result_arity > 1) { print_error(ctx, CHECK_STYLE_FULL, loc, "maximum arity for %s is 1, got %" PRIzd, desc, result_arity); } else if (result_arity == 0) { - result = WASM_CHECK_TYPE_VOID; + result = WASM_TYPE_VOID; } } ctx->type_stack.size = limit; pop_type_stack_limit(ctx); return result; } else { - return WASM_CHECK_TYPE_VOID; + return WASM_TYPE_VOID; } } static void check_expr(Context* ctx, const WasmExpr* expr) { switch (expr->type) { - case WASM_EXPR_TYPE_BINARY: { - WasmOpcode opcode = expr->binary.opcode; - WasmCheckType rtype = s_opcode_rtype[opcode]; - WasmCheckType type1 = s_opcode_type1[opcode]; - WasmCheckType type2 = s_opcode_type2[opcode]; - transform_stack(ctx, &expr->loc, s_opcode_name[opcode], 2, 1, type1, - type2, rtype); + case WASM_EXPR_TYPE_BINARY: + check_opcode2(ctx, &expr->loc, expr->binary.opcode); break; - } case WASM_EXPR_TYPE_BLOCK: { LabelNode node; push_label(ctx, &expr->loc, &node, &expr->block.label, - WASM_CHECK_TYPE_ANY); - WasmCheckType rtype = - check_block(ctx, &expr->loc, expr->block.first, "block"); - rtype = join_type(ctx, &expr->loc, node.type, - "joined type of block's br* targets", rtype, - "block's result type"); + &expr->block.sig); + check_block(ctx, &expr->loc, expr->block.first, "block"); pop_label(ctx); - push_type(ctx, rtype); + push_types(ctx, &expr->block.sig); break; } - case WASM_EXPR_TYPE_BR: { - WasmCheckType type = peek_type(ctx, 0, expr->br.arity); - check_br(ctx, &expr->loc, &expr->br.var, type, "br value"); - if (expr->br.arity > 0) { - transform_stack(ctx, &expr->loc, "br", 1, 1, type, WASM_CHECK_TYPE_ANY); - } else { - transform_stack(ctx, &expr->loc, "br", 0, 1, WASM_CHECK_TYPE_ANY); - } + case WASM_EXPR_TYPE_BR: + check_br(ctx, &expr->loc, &expr->br.var, NULL, "br value"); + reset_type_stack_to_limit(ctx); + push_type(ctx, WASM_TYPE_ANY); break; - } case WASM_EXPR_TYPE_BR_IF: { - WasmCheckType type = peek_type(ctx, 1, expr->br_if.arity); - check_br(ctx, &expr->loc, &expr->br_if.var, type, "br_if value"); - if (expr->br_if.arity > 0) { - transform_stack(ctx, &expr->loc, "br_if", 2, 1, type, - WASM_CHECK_TYPE_I32, WASM_CHECK_TYPE_VOID); - } else { - transform_stack(ctx, &expr->loc, "br_if", 1, 1, WASM_CHECK_TYPE_I32, - WASM_CHECK_TYPE_VOID); + const WasmBlockSignature* sig; + pop_and_check_1_type(ctx, &expr->loc, WASM_TYPE_I32, "br_if condition"); + if (WASM_SUCCEEDED(check_br(ctx, &expr->loc, &expr->br_if.var, &sig, + "br_if value"))) { + drop_types(ctx, sig->size); } break; } case WASM_EXPR_TYPE_BR_TABLE: { - WasmCheckType type = peek_type(ctx, 1, expr->br_table.arity); + pop_and_check_1_type(ctx, &expr->loc, WASM_TYPE_I32, "br_table key"); size_t i; for (i = 0; i < expr->br_table.targets.size; ++i) { - check_br(ctx, &expr->loc, &expr->br_table.targets.data[i], type, + check_br(ctx, &expr->loc, &expr->br_table.targets.data[i], NULL, "br_table target"); } - check_br(ctx, &expr->loc, &expr->br_table.default_target, type, + check_br(ctx, &expr->loc, &expr->br_table.default_target, NULL, "br_table default target"); - if (expr->br_table.arity > 0) { - transform_stack(ctx, &expr->loc, "br_table", 2, 1, type, - WASM_CHECK_TYPE_I32, WASM_CHECK_TYPE_ANY); - } else { - transform_stack(ctx, &expr->loc, "br_table", 1, 1, WASM_CHECK_TYPE_I32, - WASM_CHECK_TYPE_ANY); - } + reset_type_stack_to_limit(ctx); + push_type(ctx, WASM_TYPE_ANY); break; } case WASM_EXPR_TYPE_CALL: { const WasmFunc* callee; - if (WASM_SUCCEEDED(check_func_var(ctx, &expr->call.var, &callee))) { + if (WASM_SUCCEEDED(check_func_var(ctx, &expr->call.var, &callee))) check_call(ctx, &expr->loc, &callee->name, &callee->decl.sig, "call"); - } - break; - } - - case WASM_EXPR_TYPE_CALL_IMPORT: { - const WasmImport* import; - if (WASM_SUCCEEDED( - check_import_var(ctx, &expr->call_import.var, &import))) { - check_call(ctx, &expr->loc, &import->name, &import->decl.sig, - "call_import"); - } break; } case WASM_EXPR_TYPE_CALL_INDIRECT: { const WasmFuncType* func_type; - if (!ctx->current_module->table) { + if (ctx->current_module->tables.size == 0) { print_error(ctx, CHECK_STYLE_FULL, &expr->loc, "found call_indirect operator, but no table"); } if (WASM_SUCCEEDED( check_func_type_var(ctx, &expr->call_indirect.var, &func_type))) { - WasmCheckType type = pop_type(ctx); - check_type(ctx, &expr->loc, type, WASM_CHECK_TYPE_I32, + WasmType type = pop_type(ctx); + check_type(ctx, &expr->loc, type, WASM_TYPE_I32, "call_indirect function index"); check_call(ctx, &expr->loc, NULL, &func_type->sig, "call_indirect"); } break; } - case WASM_EXPR_TYPE_COMPARE: { - WasmOpcode opcode = expr->compare.opcode; - WasmCheckType rtype = s_opcode_rtype[opcode]; - WasmCheckType type1 = s_opcode_type1[opcode]; - WasmCheckType type2 = s_opcode_type2[opcode]; - transform_stack(ctx, &expr->loc, s_opcode_name[opcode], 2, 1, type1, - type2, rtype); + case WASM_EXPR_TYPE_COMPARE: + check_opcode2(ctx, &expr->loc, expr->compare.opcode); break; - } case WASM_EXPR_TYPE_CONST: push_type(ctx, expr->const_.type); break; - case WASM_EXPR_TYPE_CONVERT: { - WasmOpcode opcode = expr->convert.opcode; - WasmCheckType rtype = s_opcode_rtype[opcode]; - WasmCheckType type1 = s_opcode_type1[opcode]; - transform_stack(ctx, &expr->loc, s_opcode_name[opcode], 1, 1, type1, - rtype); + case WASM_EXPR_TYPE_CONVERT: + check_opcode1(ctx, &expr->loc, expr->convert.opcode); break; - } - case WASM_EXPR_TYPE_DROP: { - WasmCheckType type = top_type(ctx); - transform_stack(ctx, &expr->loc, "drop", 1, 0, type); + case WASM_EXPR_TYPE_DROP: + if (WASM_SUCCEEDED(check_type_stack_limit(ctx, &expr->loc, 1, "drop"))) + pop_type(ctx); break; - } case WASM_EXPR_TYPE_GET_GLOBAL: { const WasmGlobal* global; if (WASM_SUCCEEDED( - check_global_var(ctx, &expr->get_global.var, &global, NULL))) { + check_global_var(ctx, &expr->get_global.var, &global, NULL))) push_type(ctx, global->type); - } break; } case WASM_EXPR_TYPE_GET_LOCAL: { - WasmCheckType type; - if (WASM_SUCCEEDED(check_local_var(ctx, &expr->get_local.var, &type))) { + WasmType type; + if (WASM_SUCCEEDED(check_local_var(ctx, &expr->get_local.var, &type))) push_type(ctx, type); - } break; } case WASM_EXPR_TYPE_GROW_MEMORY: - transform_stack(ctx, &expr->loc, "grow_memory", 1, 1, WASM_CHECK_TYPE_I32, - WASM_CHECK_TYPE_I32); + check_opcode1(ctx, &expr->loc, WASM_OPCODE_GROW_MEMORY); break; case WASM_EXPR_TYPE_IF: { LabelNode node; push_label(ctx, &expr->loc, &node, &expr->if_.true_.label, - WASM_CHECK_TYPE_ANY); - WasmCheckType rtype = - check_block(ctx, &expr->loc, expr->if_.true_.first, "if"); - rtype = join_type(ctx, &expr->loc, rtype, "if true branch type", - WASM_CHECK_TYPE_VOID, "if false branch type"); + &expr->if_.true_.sig); + check_block(ctx, &expr->loc, expr->if_.true_.first, "if true branch"); + check_block(ctx, &expr->loc, expr->if_.false_, "if false branch"); pop_label(ctx); - transform_stack(ctx, &expr->loc, "if condition", 1, 1, - WASM_CHECK_TYPE_I32, rtype); + push_types(ctx, &expr->if_.true_.sig); break; } - case WASM_EXPR_TYPE_IF_ELSE: { - LabelNode node; - push_label(ctx, &expr->loc, &node, &expr->if_else.true_.label, - WASM_CHECK_TYPE_ANY); - WasmCheckType rtype_true = check_block( - ctx, &expr->loc, expr->if_else.true_.first, "if true branch"); - pop_label(ctx); - WasmCheckType true_type = - join_type(ctx, &expr->loc, node.type, - "joined type of if true branch's br* targets", rtype_true, - "if true branch last operation type"); - push_label(ctx, &expr->loc, &node, &expr->if_else.false_.label, - WASM_CHECK_TYPE_ANY); - WasmCheckType rtype_false = check_block( - ctx, &expr->loc, expr->if_else.false_.first, "if false branch"); - WasmCheckType false_type = - join_type(ctx, &expr->loc, node.type, - "joined type of if false branch's br* targets", rtype_false, - "if false branch last operation type"); - pop_label(ctx); - WasmCheckType rtype = - join_type(ctx, &expr->loc, true_type, "if true branch type", - false_type, "if false branch type"); - transform_stack(ctx, &expr->loc, "if condition", 1, 1, - WASM_CHECK_TYPE_I32, rtype); - break; - } - - case WASM_EXPR_TYPE_LOAD: { - WasmOpcode opcode = expr->load.opcode; - WasmCheckType rtype = s_opcode_rtype[opcode]; - WasmCheckType type1 = s_opcode_type1[opcode]; + case WASM_EXPR_TYPE_LOAD: check_align(ctx, &expr->loc, expr->load.align); check_offset(ctx, &expr->loc, expr->load.offset); - transform_stack(ctx, &expr->loc, s_opcode_name[opcode], 1, 1, type1, - rtype); + check_opcode1(ctx, &expr->loc, expr->load.opcode); break; - } case WASM_EXPR_TYPE_LOOP: { LabelNode node; - push_label(ctx, &expr->loc, &node, &expr->loop.label, - WASM_CHECK_TYPE_VOID); - WasmCheckType rtype = - check_block(ctx, &expr->loc, expr->loop.first, "loop"); + push_label(ctx, &expr->loc, &node, &expr->loop.label, &expr->loop.sig); + check_block(ctx, &expr->loc, expr->loop.first, "loop"); pop_label(ctx); - push_type(ctx, rtype); break; } case WASM_EXPR_TYPE_CURRENT_MEMORY: - push_type(ctx, WASM_CHECK_TYPE_I32); + push_type(ctx, WASM_TYPE_I32); break; case WASM_EXPR_TYPE_NOP: break; case WASM_EXPR_TYPE_RETURN: { - WasmCheckType result_type = - wasm_get_result_type(ctx->current_module, ctx->current_func); - if (result_type != WASM_TYPE_VOID) { - transform_stack(ctx, &expr->loc, "return", 1, 1, result_type, - WASM_CHECK_TYPE_ANY); - } else { - transform_stack(ctx, &expr->loc, "return", 0, 1, WASM_CHECK_TYPE_ANY); - } + check_n_types(ctx, &expr->loc, &ctx->current_func->decl.sig.result_types, + "return"); + reset_type_stack_to_limit(ctx); + push_type(ctx, WASM_TYPE_ANY); break; } case WASM_EXPR_TYPE_SELECT: { - WasmCheckType type = peek_type(ctx, 1, 1); - transform_stack(ctx, &expr->loc, "select", 3, 1, type, type, - WASM_CHECK_TYPE_I32, type); + pop_and_check_1_type(ctx, &expr->loc, WASM_TYPE_I32, "select"); + if (WASM_SUCCEEDED( + check_type_stack_limit(ctx, &expr->loc, 2, "select"))) { + WasmType type1 = pop_type(ctx); + WasmType type2 = pop_type(ctx); + check_type(ctx, &expr->loc, type2, type1, "select"); + push_type(ctx, type1); + } break; } case WASM_EXPR_TYPE_SET_GLOBAL: { - WasmCheckType type = WASM_TYPE_I32; + WasmType type = WASM_TYPE_I32; const WasmGlobal* global; if (WASM_SUCCEEDED( check_global_var(ctx, &expr->set_global.var, &global, NULL))) { type = global->type; } - transform_stack(ctx, &expr->loc, "set_global", 1, 0, type); + pop_and_check_1_type(ctx, &expr->loc, type, "set_global"); break; } case WASM_EXPR_TYPE_SET_LOCAL: { - WasmCheckType type = WASM_TYPE_I32; + WasmType type = WASM_TYPE_I32; check_local_var(ctx, &expr->set_local.var, &type); - transform_stack(ctx, &expr->loc, "set_local", 1, 0, type); + pop_and_check_1_type(ctx, &expr->loc, type, "set_local"); break; } - case WASM_EXPR_TYPE_STORE: { - WasmOpcode opcode = expr->store.opcode; - WasmCheckType type1 = s_opcode_type1[opcode]; - WasmCheckType type2 = s_opcode_type2[opcode]; + case WASM_EXPR_TYPE_STORE: check_align(ctx, &expr->loc, expr->store.align); check_offset(ctx, &expr->loc, expr->store.offset); - transform_stack(ctx, &expr->loc, s_opcode_name[opcode], 2, 0, type1, - type2); + check_opcode2(ctx, &expr->loc, expr->store.opcode); break; - } case WASM_EXPR_TYPE_TEE_LOCAL: { - WasmCheckType type = WASM_TYPE_I32; - check_local_var(ctx, &expr->tee_local.var, &type); - transform_stack(ctx, &expr->loc, "tee_local", 1, 1, type, type); + WasmType local_type = WASM_TYPE_I32; + check_local_var(ctx, &expr->tee_local.var, &local_type); + if (check_type_stack_limit(ctx, &expr->loc, 1, "tee_local")) + check_type(ctx, &expr->loc, top_type(ctx), local_type, "tee_local"); break; } - case WASM_EXPR_TYPE_UNARY: { - WasmOpcode opcode = expr->unary.opcode; - WasmCheckType rtype = s_opcode_rtype[opcode]; - WasmCheckType type1 = s_opcode_type1[opcode]; - transform_stack(ctx, &expr->loc, s_opcode_name[opcode], 1, 1, type1, - rtype); + case WASM_EXPR_TYPE_UNARY: + check_opcode1(ctx, &expr->loc, expr->unary.opcode); break; - } case WASM_EXPR_TYPE_UNREACHABLE: - push_type(ctx, WASM_CHECK_TYPE_ANY); + reset_type_stack_to_limit(ctx); + push_type(ctx, WASM_TYPE_ANY); break; } } @@ -859,36 +855,17 @@ static void check_func_signature_matches_func_type( const WasmLocation* loc, const WasmFuncSignature* sig, const WasmFuncType* func_type) { - size_t num_params = sig->param_types.size; - /* special case this check to give a better error message */ - WasmCheckType func_type_result_type = - wasm_get_func_type_result_type(func_type); - if (sig->result_type != func_type_result_type) { - print_error( - ctx, CHECK_STYLE_FULL, loc, - "type mismatch between function result type (%s) and function type " - "result type (%s)\n", - s_type_names[sig->result_type], s_type_names[func_type_result_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(ctx, loc, sig->param_types.data[i], - wasm_get_func_type_param_type(func_type, i), "function", - i); - } - } else { - print_error(ctx, CHECK_STYLE_FULL, loc, - "expected %" PRIzd " parameters, got %" PRIzd, - wasm_get_func_type_num_params(func_type), num_params); - } + check_types(ctx, loc, &sig->result_types, &func_type->sig.result_types, + "function", "result"); + check_types(ctx, loc, &sig->param_types, &func_type->sig.param_types, + "function", "argument"); } static void check_func(Context* ctx, const WasmLocation* loc, const WasmFunc* func) { ctx->current_func = func; - if (wasm_get_result_type(ctx->current_module, func) == WASM_TYPE_MULTIPLE) { + if (wasm_get_num_results(func) > 1) { print_error(ctx, CHECK_STYLE_FULL, loc, "multiple result values not currently supported."); /* don't run any other checks, the won't test the result_type properly */ @@ -909,11 +886,8 @@ static void check_func(Context* ctx, * returning from the function. */ LabelNode node; WasmLabel label = wasm_empty_string_slice(); - push_label(ctx, loc, &node, &label, func->decl.sig.result_type); - WasmCheckType rtype = - check_block(ctx, loc, func->first_expr, "function result"); - join_type(ctx, loc, rtype, "type of last operation", - func->decl.sig.result_type, "function signature result type"); + push_label(ctx, loc, &node, &label, &func->decl.sig.result_types); + check_block(ctx, loc, func->first_expr, "function result"); pop_label(ctx); ctx->current_func = NULL; } @@ -973,10 +947,9 @@ static WasmResult eval_const_expr_i32(Context* ctx, static void check_global(Context* ctx, const WasmLocation* loc, - const WasmGlobal* global, - int global_index) { + const WasmGlobal* global) { static const char s_desc[] = "global initializer expression"; - WasmCheckType type = WASM_CHECK_TYPE_VOID; + WasmType type = WASM_TYPE_VOID; WasmExpr* expr = global->init_expr; if (expr->next != NULL) { @@ -999,7 +972,7 @@ static void check_global(Context* ctx, type = ref_global->type; /* globals can only reference previously defined globals */ - if (ref_global_index >= global_index) { + if (ref_global_index >= ctx->current_global_index) { print_error(ctx, CHECK_STYLE_FULL, loc, "global can only be defined in terms of a previously " "defined global."); @@ -1015,17 +988,6 @@ static void check_global(Context* ctx, check_type(ctx, &expr->loc, type, global->type, s_desc); } -static void check_import(Context* ctx, - const WasmLocation* loc, - const WasmImport* import) { - if (wasm_decl_has_func_type(&import->decl)) - check_func_type_var(ctx, &import->decl.type_var, NULL); -} - -static void check_export(Context* ctx, const WasmExport* export) { - check_func_var(ctx, &export->var, NULL); -} - static void check_limits(Context* ctx, const WasmLocation* loc, const WasmLimits* limits, @@ -1059,21 +1021,18 @@ static void check_table(Context* ctx, } static void check_elem_segments(Context* ctx, const WasmModule* module) { - const WasmTable* table = module->table; - WasmModuleField* field; uint32_t last_end = 0; for (field = module->first_field; field; field = field->next) { if (field->type != WASM_MODULE_FIELD_TYPE_ELEM_SEGMENT) continue; - if (!table) { - print_error(ctx, CHECK_STYLE_FULL, &field->loc, - "elem segment cannot be specified without table section"); - break; - } - WasmElemSegment* elem_segment = &field->elem_segment; + const WasmTable* table; + if (!WASM_SUCCEEDED( + check_table_var(ctx, &elem_segment->table_var, &table))) + continue; + uint32_t offset = 0; if (WASM_SUCCEEDED(eval_const_expr_i32( ctx, elem_segment->offset, "elem segment expression", &offset))) { @@ -1105,21 +1064,18 @@ static void check_memory(Context* ctx, } static void check_data_segments(Context* ctx, const WasmModule* module) { - const WasmMemory* memory = module->memory; - WasmModuleField* field; uint32_t last_end = 0; for (field = module->first_field; field; field = field->next) { if (field->type != WASM_MODULE_FIELD_TYPE_DATA_SEGMENT) continue; - if (!memory) { - print_error(ctx, CHECK_STYLE_FULL, &field->loc, - "data segment cannot be specified without memory section"); - break; - } - WasmDataSegment* data_segment = &field->data_segment; + const WasmMemory* memory; + if (!WASM_SUCCEEDED( + check_memory_var(ctx, &data_segment->memory_var, &memory))) + continue; + uint32_t offset = 0; if (WASM_SUCCEEDED(eval_const_expr_i32( ctx, data_segment->offset, "data segment expression", &offset))) { @@ -1145,15 +1101,37 @@ static void check_data_segments(Context* ctx, const WasmModule* module) { } } +static void check_import(Context* ctx, + const WasmLocation* loc, + const WasmImport* import) { + switch (import->kind) { + case WASM_IMPORT_KIND_FUNC: + if (wasm_decl_has_func_type(&import->func.decl)) + check_func_type_var(ctx, &import->func.decl.type_var, NULL); + break; + case WASM_IMPORT_KIND_TABLE: + check_table(ctx, loc, &import->table); + break; + case WASM_IMPORT_KIND_MEMORY: + check_memory(ctx, loc, &import->memory); + break; + case WASM_IMPORT_KIND_GLOBAL: + check_global(ctx, loc, &import->global); + break; + } +} + +static void check_export(Context* ctx, const WasmExport* export) { + check_func_var(ctx, &export->var, NULL); +} + static void check_module(Context* ctx, const WasmModule* module) { - WasmLocation* export_memory_loc = NULL; WasmBool seen_memory = WASM_FALSE; - WasmBool seen_export_memory = WASM_FALSE; WasmBool seen_table = WASM_FALSE; WasmBool seen_start = WASM_FALSE; - int global_index = 0; ctx->current_module = module; + ctx->current_global_index = 0; WasmModuleField* field; for (field = module->first_field; field != NULL; field = field->next) { @@ -1163,7 +1141,8 @@ static void check_module(Context* ctx, const WasmModule* module) { break; case WASM_MODULE_FIELD_TYPE_GLOBAL: - check_global(ctx, &field->loc, &field->global, global_index++); + check_global(ctx, &field->loc, &field->global); + ctx->current_global_index++; break; case WASM_MODULE_FIELD_TYPE_IMPORT: @@ -1174,11 +1153,6 @@ static void check_module(Context* ctx, const WasmModule* module) { check_export(ctx, &field->export_); break; - case WASM_MODULE_FIELD_TYPE_EXPORT_MEMORY: - seen_export_memory = WASM_TRUE; - export_memory_loc = &field->loc; - break; - case WASM_MODULE_FIELD_TYPE_TABLE: if (seen_table) { print_error(ctx, CHECK_STYLE_FULL, &field->loc, @@ -1217,13 +1191,12 @@ static void check_module(Context* ctx, const WasmModule* module) { const WasmFunc* start_func = NULL; check_func_var(ctx, &field->start, &start_func); if (start_func) { - if (wasm_get_num_params(ctx->current_module, start_func) != 0) { + if (wasm_get_num_params(start_func) != 0) { print_error(ctx, CHECK_STYLE_FULL, &field->loc, "start function must be nullary"); } - if (wasm_get_result_type(ctx->current_module, start_func) != - WASM_TYPE_VOID) { + if (wasm_get_num_results(start_func) != 0) { print_error(ctx, CHECK_STYLE_FULL, &field->loc, "start function must not return anything"); } @@ -1237,15 +1210,12 @@ static void check_module(Context* ctx, const WasmModule* module) { check_elem_segments(ctx, module); check_data_segments(ctx, module); - if (seen_export_memory && !seen_memory) { - print_error(ctx, CHECK_STYLE_FULL, export_memory_loc, - "no memory to export"); - } - check_duplicate_bindings(ctx, &module->func_bindings, "function"); - check_duplicate_bindings(ctx, &module->import_bindings, "import"); + check_duplicate_bindings(ctx, &module->global_bindings, "global"); check_duplicate_bindings(ctx, &module->export_bindings, "export"); check_duplicate_bindings(ctx, &module->func_type_bindings, "function type"); + check_duplicate_bindings(ctx, &module->table_bindings, "table"); + check_duplicate_bindings(ctx, &module->memory_bindings, "memory"); } typedef struct BinaryErrorCallbackData { @@ -1291,49 +1261,74 @@ static void check_raw_module(Context* ctx, WasmRawModule* raw) { } /* returns the result type of the invoked function, checked by the caller; - * returning WASM_CHECK_TYPE_ANY means that another error occured first, so the - * result type should be ignored. */ -static WasmCheckType check_invoke(Context* ctx, - const WasmCommandInvoke* invoke) { + * returning NULL means that another error occured first, so the result type + * should be ignored. */ +static const WasmTypeVector* check_invoke(Context* ctx, + const WasmAction* action) { + const WasmActionInvoke* invoke = &action->invoke; const WasmModule* module = ctx->current_module; if (!module) { - print_error(ctx, CHECK_STYLE_FULL, &invoke->loc, + print_error(ctx, CHECK_STYLE_FULL, &action->loc, "invoke must occur after a module definition"); - return WASM_CHECK_TYPE_ANY; + return NULL; } WasmExport* export = wasm_get_export_by_name(module, &invoke->name); if (!export) { - print_error(ctx, CHECK_STYLE_NAME, &invoke->loc, + print_error(ctx, CHECK_STYLE_NAME, &action->loc, "unknown function export \"" PRIstringslice "\"", WASM_PRINTF_STRING_SLICE_ARG(invoke->name)); - return WASM_CHECK_TYPE_ANY; + return NULL; } WasmFunc* func = wasm_get_func_by_var(module, &export->var); if (!func) { /* this error will have already been reported, just skip it */ - return WASM_CHECK_TYPE_ANY; + return NULL; } size_t actual_args = invoke->args.size; - size_t expected_args = wasm_get_num_params(module, func); + size_t expected_args = wasm_get_num_params(func); if (expected_args != actual_args) { - print_error(ctx, CHECK_STYLE_FULL, &invoke->loc, + print_error(ctx, CHECK_STYLE_FULL, &action->loc, "too %s parameters to function. got %" PRIzd ", expected %" PRIzd, actual_args > expected_args ? "many" : "few", actual_args, expected_args); - return WASM_CHECK_TYPE_ANY; + return NULL; } size_t i; for (i = 0; i < actual_args; ++i) { WasmConst* const_ = &invoke->args.data[i]; - check_type_arg(ctx, &const_->loc, const_->type, - wasm_get_param_type(module, func, i), "invoke", i); + check_type_index(ctx, &const_->loc, const_->type, + wasm_get_param_type(func, i), "invoke", i, "argument"); + } + + return &func->decl.sig.result_types; +} + +static WasmType check_get(Context* ctx, const WasmAction* action) { + /* TODO */ + return WASM_TYPE_ANY; +} + +static ActionResult check_action(Context* ctx, const WasmAction* action) { + ActionResult result; + WASM_ZERO_MEMORY(result); + + switch (action->type) { + case WASM_ACTION_TYPE_INVOKE: + result.kind = ACTION_RESULT_KIND_TYPES; + result.types = check_invoke(ctx, action); + break; + + case WASM_ACTION_TYPE_GET: + result.kind = ACTION_RESULT_KIND_TYPE; + result.type = check_get(ctx, action); + break; } - return wasm_get_result_type(module, func); + return result; } static void check_command(Context* ctx, const WasmCommand* command) { @@ -1342,40 +1337,64 @@ static void check_command(Context* ctx, const WasmCommand* command) { check_module(ctx, &command->module); break; - case WASM_COMMAND_TYPE_INVOKE: + case WASM_COMMAND_TYPE_ACTION: /* ignore result type */ - check_invoke(ctx, &command->invoke); + check_action(ctx, &command->action); break; + case WASM_COMMAND_TYPE_REGISTER: case WASM_COMMAND_TYPE_ASSERT_INVALID: /* ignore */ break; case WASM_COMMAND_TYPE_ASSERT_RETURN: { - const WasmCommandInvoke* invoke = &command->assert_return.invoke; - WasmCheckType result_type = check_invoke(ctx, invoke); - if (result_type != WASM_CHECK_TYPE_ANY) { - check_type(ctx, &invoke->loc, result_type, - command->assert_return.expected.type, "invoke"); + const WasmAction* action = &command->assert_return.action; + ActionResult result = check_action(ctx, action); + switch (result.kind) { + case ACTION_RESULT_KIND_TYPES: + check_const_types(ctx, &action->loc, result.types, + &command->assert_return.expected, "action"); + break; + + case ACTION_RESULT_KIND_TYPE: + check_const_type(ctx, &action->loc, result.type, + &command->assert_return.expected, "action"); + break; } break; } case WASM_COMMAND_TYPE_ASSERT_RETURN_NAN: { - const WasmCommandInvoke* invoke = &command->assert_return_nan.invoke; - WasmCheckType result_type = check_invoke(ctx, invoke); - if (result_type != WASM_CHECK_TYPE_ANY) { - check_assert_return_nan_type(ctx, &invoke->loc, result_type, "invoke"); + const WasmAction* action = &command->assert_return_nan.action; + ActionResult result = check_action(ctx, action); + + /* a valid result type will either be f32 or f64; convert a TYPES result + * into a TYPE result, so it is easier to check below. WASM_TYPE_ANY is + * used to specify a type that should not be checked (because an earlier + * error occurred). */ + if (result.kind == ACTION_RESULT_KIND_TYPES) { + if (result.types->size == 1) { + result.kind = ACTION_RESULT_KIND_TYPE; + result.type = result.types->data[0]; + } else { + print_error(ctx, CHECK_STYLE_FULL, &action->loc, + "expected 1 result, got %" PRIzd, result.types->size); + result.type = WASM_TYPE_ANY; + } } + + if (result.type != WASM_TYPE_ANY) + check_assert_return_nan_type(ctx, &action->loc, result.type, "action"); break; } case WASM_COMMAND_TYPE_ASSERT_TRAP: /* ignore result type */ - check_invoke(ctx, &command->assert_trap.invoke); + check_action(ctx, &command->assert_trap.action); break; - default: + case WASM_NUM_COMMAND_TYPES: + assert(0); break; } } diff --git a/src/wasm-ast-parser-lexer-shared.c b/src/wasm-ast-parser-lexer-shared.c index 2ff81fd3..ca75bac6 100644 --- a/src/wasm-ast-parser-lexer-shared.c +++ b/src/wasm-ast-parser-lexer-shared.c @@ -71,9 +71,16 @@ void wasm_ast_format_error(WasmSourceErrorHandler* error_handler, va_end(args_copy); } +void wasm_destroy_optional_export(WasmAllocator* allocator, + WasmOptionalExport* export_) { + if (export_->has_export) + wasm_destroy_export(allocator, &export_->export_); +} + void wasm_destroy_exported_func(WasmAllocator* allocator, WasmExportedFunc* exported_func) { - wasm_destroy_export(allocator, &exported_func->export_); + wasm_destroy_optional_export(allocator, &exported_func->export_); + wasm_destroy_func(allocator, exported_func->func); wasm_free(allocator, exported_func->func); } @@ -115,14 +122,18 @@ void wasm_destroy_func_fields(struct WasmAllocator* allocator, } } -void wasm_destroy_memory_data_segment_pair(WasmAllocator* allocator, - WasmMemoryDataSegmentPair* pair) { - if (pair->has_data_segment) - wasm_destroy_data_segment(allocator, &pair->data_segment); +void wasm_destroy_exported_memory(WasmAllocator* allocator, + WasmExportedMemory* memory) { + wasm_destroy_memory(allocator, &memory->memory); + wasm_destroy_optional_export(allocator, &memory->export_); + if (memory->has_data_segment) + wasm_destroy_data_segment(allocator, &memory->data_segment); } -void wasm_destroy_table_elem_segment_pair(WasmAllocator* allocator, - WasmTableElemSegmentPair* pair) { - if (pair->has_elem_segment) - wasm_destroy_elem_segment(allocator, &pair->elem_segment); +void wasm_destroy_exported_table(WasmAllocator* allocator, + WasmExportedTable* table) { + wasm_destroy_table(allocator, &table->table); + wasm_destroy_optional_export(allocator, &table->export_); + if (table->has_elem_segment) + wasm_destroy_elem_segment(allocator, &table->elem_segment); } diff --git a/src/wasm-ast-parser-lexer-shared.h b/src/wasm-ast-parser-lexer-shared.h index f516d8fd..8f677e9f 100644 --- a/src/wasm-ast-parser-lexer-shared.h +++ b/src/wasm-ast-parser-lexer-shared.h @@ -48,22 +48,34 @@ typedef struct WasmTextList { WasmTextListNode* last; } WasmTextList; +typedef struct WasmOptionalExport { + WasmExport export_; + WasmBool has_export; +} WasmOptionalExport; + typedef struct WasmExportedFunc { WasmFunc* func; - WasmExport export_; + WasmOptionalExport export_; } WasmExportedFunc; -typedef struct WasmTableElemSegmentPair { +typedef struct WasmExportedGlobal { + WasmGlobal global; + WasmOptionalExport export_; +} WasmExportedGlobal; + +typedef struct WasmExportedTable { WasmTable table; WasmElemSegment elem_segment; + WasmOptionalExport export_; WasmBool has_elem_segment; -} WasmTableElemSegmentPair; +} WasmExportedTable; -typedef struct WasmMemoryDataSegmentPair { +typedef struct WasmExportedMemory { WasmMemory memory; WasmDataSegment data_segment; + WasmOptionalExport export_; WasmBool has_data_segment; -} WasmMemoryDataSegmentPair; +} WasmExportedMemory; typedef enum WasmFuncFieldType { WASM_FUNC_FIELD_TYPE_EXPRS, @@ -100,35 +112,40 @@ typedef union WasmToken { /* non-terminals */ /* some of these use pointers to keep the size of WasmToken down; copying the tokens is a hotspot when parsing large files. */ - uint32_t u32; - uint64_t u64; - WasmTextList text_list; - WasmTypeVector types; - WasmVar var; - WasmVarVector vars; + WasmAction action; + WasmBlock block; + WasmCommand* command; + WasmCommandVector commands; + WasmConst const_; + WasmConstVector consts; + WasmDataSegment data_segment; WasmElemSegment elem_segment; + WasmExport export_; + WasmExportedFunc exported_func; + WasmExportedGlobal exported_global; + WasmExportedMemory exported_memory; + WasmExportedTable exported_table; WasmExpr* expr; WasmExprList expr_list; WasmFuncField* func_fields; WasmFunc* func; - WasmExportedFunc exported_func; - WasmLimits limits; - WasmDataSegment data_segment; - WasmMemoryDataSegmentPair memory; WasmFuncSignature func_sig; WasmFuncType func_type; WasmGlobal global; WasmImport* import; - WasmExport export_; - WasmExportMemory export_memory; + WasmLimits limits; + WasmOptionalExport optional_export; + WasmMemory memory; WasmModule* module; WasmRawModule raw_module; - WasmConst const_; - WasmConstVector consts; - WasmCommand* command; - WasmCommandVector commands; WasmScript script; - WasmTableElemSegmentPair table; + WasmTable table; + WasmTextList text_list; + WasmTypeVector types; + uint32_t u32; + uint64_t u64; + WasmVar var; + WasmVarVector vars; } WasmToken; typedef struct WasmAstParser { @@ -160,12 +177,12 @@ void wasm_ast_format_error(WasmSourceErrorHandler*, WasmAstLexer*, const char* format, va_list); +void wasm_destroy_optional_export(WasmAllocator*, WasmOptionalExport*); void wasm_destroy_exported_func(WasmAllocator*, WasmExportedFunc*); +void wasm_destroy_exported_global(WasmAllocator*, WasmExportedFunc*); +void wasm_destroy_exported_memory(WasmAllocator*, WasmExportedMemory*); +void wasm_destroy_exported_table(WasmAllocator*, WasmExportedTable*); void wasm_destroy_func_fields(WasmAllocator*, WasmFuncField*); -void wasm_destroy_memory_data_segment_pair(WasmAllocator*, - WasmMemoryDataSegmentPair*); -void wasm_destroy_table_elem_segment_pair(WasmAllocator*, - WasmTableElemSegmentPair*); void wasm_destroy_text_list(WasmAllocator*, WasmTextList*); WASM_EXTERN_C_END diff --git a/src/wasm-ast-parser.y b/src/wasm-ast-parser.y index 1552d41c..9356c390 100644 --- a/src/wasm-ast-parser.y +++ b/src/wasm-ast-parser.y @@ -57,29 +57,54 @@ } \ while (0) +#define APPEND_FIELD_TO_LIST(module, field, KIND, kind, loc_, item) \ + do { \ + field = wasm_append_module_field(parser->allocator, module); \ + field->loc = loc_; \ + field->type = WASM_MODULE_FIELD_TYPE_##KIND; \ + field->kind = item; \ + } while (0) + +#define APPEND_ITEM_TO_VECTOR(module, Kind, kind, kinds, item_ptr) \ + do { \ + Wasm##Kind* dummy = item_ptr; \ + wasm_append_##kind##_ptr_value(parser->allocator, &(module)->kinds, \ + &dummy); \ + } while (0) + +#define INSERT_BINDING(module, kind, kinds, loc_, item) \ + do \ + if ((item).name.start) { \ + WasmBinding* binding = wasm_insert_binding( \ + parser->allocator, &(module)->kind##_bindings, &(item).name); \ + binding->loc = loc_; \ + binding->index = (module)->kinds.size - 1; \ + } \ + while (0) + +#define APPEND_INLINE_EXPORT(module, KIND, loc_, value, index_) \ + do \ + if ((value).export_.has_export) { \ + WasmModuleField* export_field; \ + APPEND_FIELD_TO_LIST(module, export_field, EXPORT, export_, loc_, \ + (value).export_.export_); \ + export_field->export_.kind = WASM_EXPORT_KIND_##KIND; \ + export_field->export_.var.index = index_; \ + APPEND_ITEM_TO_VECTOR(module, Export, export, exports, \ + &export_field->export_); \ + INSERT_BINDING(module, export, exports, export_field->loc, \ + export_field->export_); \ + } \ + while (0) + #define YYMALLOC(size) wasm_alloc(parser->allocator, size, WASM_DEFAULT_ALIGN) #define YYFREE(p) wasm_free(parser->allocator, p) #define USE_NATURAL_ALIGNMENT (~0) -#define PARSE_NAT(dst, s, s_loc, error_msg) \ - do { \ - if (WASM_FAILED(wasm_parse_uint64(s.text.start, \ - s.text.start + s.text.length, &dst))) { \ - wasm_ast_parser_error(&s_loc, lexer, parser, \ - error_msg PRIstringslice "\"", \ - WASM_PRINTF_STRING_SLICE_ARG(s.text)); \ - } \ - } while (0) - static WasmExprList join_exprs1(WasmLocation* loc, WasmExpr* expr1); static WasmExprList join_exprs2(WasmLocation* loc, WasmExprList* expr1, WasmExpr* expr2); -static WasmExprList join_exprs3(WasmLocation* loc, WasmExprList* expr1, - WasmExprList* expr2, WasmExpr* expr3); -static WasmExprList join_exprs4(WasmLocation* loc, WasmExprList* expr1, - WasmExprList* expr2, WasmExprList* expr3, - WasmExpr* expr4); static WasmFuncField* new_func_field(WasmAllocator* allocator) { return wasm_alloc_zero(allocator, sizeof(WasmFuncField), WASM_DEFAULT_ALIGN); @@ -116,8 +141,6 @@ static WasmBool is_empty_signature(WasmFuncSignature* sig); static void append_implicit_func_declaration(WasmAllocator*, WasmLocation*, WasmModule*, WasmFuncDeclaration*); -static WasmType get_result_type_from_type_vector(WasmTypeVector* types); - typedef struct BinaryErrorCallbackData { WasmLocation* loc; WasmAstLexer* lexer; @@ -163,63 +186,69 @@ static void on_read_binary_error(uint32_t offset, const char* error, %type<type> CONST VALUE_TYPE %type<literal> NAT INT FLOAT +%type<action> action +%type<block> block %type<command> cmd %type<commands> cmd_list -%type<const_> const const_opt +%type<const_> const %type<consts> const_list +%type<data_segment> data %type<elem_segment> elem -%type<export_> export -%type<export_memory> export_memory +%type<export_> export export_kind %type<exported_func> func -%type<expr> op -%type<expr_list> expr expr1 expr_list const_expr offset +%type<exported_global> global +%type<exported_table> table +%type<exported_memory> memory +%type<expr> plain_instr block_instr +%type<expr_list> instr instr_list expr expr1 expr_list if_ const_expr offset %type<func_fields> func_fields func_body %type<func> func_info -%type<func_sig> func_type +%type<func_sig> func_sig func_type %type<func_type> type_def -%type<global> global -%type<import> import -%type<limits> memory_limits table_limits -%type<memory> memory -%type<data_segment> data +%type<global> global_type +%type<import> import import_kind inline_import +%type<limits> limits +%type<memory> memory_sig %type<module> module module_fields +%type<optional_export> inline_export inline_export_opt %type<raw_module> raw_module %type<literal> literal %type<script> script -%type<table> table -%type<text> bind_var labeling labeling1 quoted_text export_opt +%type<table> table_sig +%type<text> bind_var bind_var_opt labeling_opt quoted_text script_var_opt %type<text_list> non_empty_text_list text_list %type<types> value_type_list -%type<u32> nat align_opt -%type<u64> offset_opt initial_elems max_elems initial_pages max_pages +%type<u32> align_opt +%type<u64> nat offset_opt %type<vars> var_list %type<var> start type_use var -%destructor { wasm_destroy_command(parser->allocator, $$); wasm_free(parser->allocator, $$); } cmd -%destructor { wasm_destroy_command_vector_and_elements(parser->allocator, &$$); } cmd_list -%destructor { wasm_destroy_const_vector(parser->allocator, &$$); } const_list -%destructor { wasm_destroy_elem_segment(parser->allocator, &$$); } elem -%destructor { wasm_destroy_export(parser->allocator, &$$); } export -%destructor { wasm_destroy_exported_func(parser->allocator, &$$); } func -%destructor { wasm_destroy_expr(parser->allocator, $$); } op -%destructor { wasm_destroy_expr_list(parser->allocator, $$.first); } expr expr1 expr_list const_expr offset -%destructor { wasm_destroy_func_fields(parser->allocator, $$); } func_fields func_body -%destructor { wasm_destroy_func(parser->allocator, $$); wasm_free(parser->allocator, $$); } func_info -%destructor { wasm_destroy_func_signature(parser->allocator, &$$); } func_type -%destructor { wasm_destroy_func_type(parser->allocator, &$$); } type_def -%destructor { wasm_destroy_import(parser->allocator, $$); wasm_free(parser->allocator, $$); } import -%destructor { wasm_destroy_memory_data_segment_pair(parser->allocator, &$$); } memory -%destructor { wasm_destroy_data_segment(parser->allocator, &$$); } data -%destructor { wasm_destroy_module(parser->allocator, $$); wasm_free(parser->allocator, $$); } module module_fields -%destructor { wasm_destroy_raw_module(parser->allocator, &$$); } raw_module -%destructor { wasm_destroy_string_slice(parser->allocator, &$$.text); } literal -%destructor { wasm_destroy_script(&$$); } script -%destructor { wasm_destroy_table_elem_segment_pair(parser->allocator, &$$); } table -%destructor { wasm_destroy_string_slice(parser->allocator, &$$); } bind_var labeling labeling1 quoted_text export_opt -%destructor { wasm_destroy_text_list(parser->allocator, &$$); } non_empty_text_list text_list -%destructor { wasm_destroy_type_vector(parser->allocator, &$$); } value_type_list -%destructor { wasm_destroy_var_vector_and_elements(parser->allocator, &$$); } var_list -%destructor { wasm_destroy_var(parser->allocator, &$$); } var +%destructor { wasm_destroy_block(parser->allocator, &$$); } <block> +%destructor { wasm_destroy_command(parser->allocator, $$); wasm_free(parser->allocator, $$); } <command> +%destructor { wasm_destroy_command_vector_and_elements(parser->allocator, &$$); } <commands> +%destructor { wasm_destroy_const_vector(parser->allocator, &$$); } <consts> +%destructor { wasm_destroy_elem_segment(parser->allocator, &$$); } <elem_segment> +%destructor { wasm_destroy_export(parser->allocator, &$$); } <export_> +%destructor { wasm_destroy_exported_func(parser->allocator, &$$); } <exported_func> +%destructor { wasm_destroy_exported_memory(parser->allocator, &$$); } <exported_memory> +%destructor { wasm_destroy_exported_table(parser->allocator, &$$); } <exported_table> +%destructor { wasm_destroy_expr(parser->allocator, $$); } <expr> +%destructor { wasm_destroy_expr_list(parser->allocator, $$.first); } <expr_list> +%destructor { wasm_destroy_func_fields(parser->allocator, $$); } <func_fields> +%destructor { wasm_destroy_func(parser->allocator, $$); wasm_free(parser->allocator, $$); } <func> +%destructor { wasm_destroy_func_signature(parser->allocator, &$$); } <func_sig> +%destructor { wasm_destroy_func_type(parser->allocator, &$$); } <func_type> +%destructor { wasm_destroy_import(parser->allocator, $$); wasm_free(parser->allocator, $$); } <import> +%destructor { wasm_destroy_data_segment(parser->allocator, &$$); } <data_segment> +%destructor { wasm_destroy_module(parser->allocator, $$); wasm_free(parser->allocator, $$); } <module> +%destructor { wasm_destroy_raw_module(parser->allocator, &$$); } <raw_module> +%destructor { wasm_destroy_string_slice(parser->allocator, &$$.text); } <literal> +%destructor { wasm_destroy_script(&$$); } <script> +%destructor { wasm_destroy_string_slice(parser->allocator, &$$); } <text> +%destructor { wasm_destroy_text_list(parser->allocator, &$$); } <text_list> +%destructor { wasm_destroy_type_vector(parser->allocator, &$$); } <types> +%destructor { wasm_destroy_var_vector_and_elements(parser->allocator, &$$); } <vars> +%destructor { wasm_destroy_var(parser->allocator, &$$); } <var> %nonassoc LOW @@ -229,6 +258,8 @@ static void on_read_binary_error(uint32_t offset, const char* error, %% +/* Auxiliaries */ + non_empty_text_list : TEXT { WasmTextListNode* node = new_text_list_node(parser->allocator); @@ -250,6 +281,22 @@ text_list : | non_empty_text_list ; +quoted_text : + TEXT { + WasmTextListNode node; + node.text = $1; + node.next = NULL; + WasmTextList text_list; + text_list.first = &node; + text_list.last = &node; + void* data; + size_t size; + dup_text_list(parser->allocator, &text_list, &data, &size); + $$.start = data; + $$.length = size; + } +; + /* Types */ value_type_list : @@ -262,31 +309,68 @@ value_type_list : elem_type : ANYFUNC {} ; +global_type : + VALUE_TYPE { + WASM_ZERO_MEMORY($$); + $$.type = $1; + $$.mutable_ = WASM_FALSE; + } + | LPAR MUT VALUE_TYPE RPAR { + WASM_ZERO_MEMORY($$); + $$.type = $3; + $$.mutable_ = WASM_TRUE; + } +; func_type : + LPAR FUNC func_sig RPAR { $$ = $3; } +; +func_sig : /* empty */ { WASM_ZERO_MEMORY($$); } | LPAR PARAM value_type_list RPAR { - $$.result_type = WASM_TYPE_VOID; + WASM_ZERO_MEMORY($$); $$.param_types = $3; } | LPAR PARAM value_type_list RPAR LPAR RESULT value_type_list RPAR { + WASM_ZERO_MEMORY($$); $$.param_types = $3; - $$.result_type = get_result_type_from_type_vector(&$7); + $$.result_types = $7; } | LPAR RESULT value_type_list RPAR { WASM_ZERO_MEMORY($$); - $$.result_type = get_result_type_from_type_vector(&$3); + $$.result_types = $3; } ; +table_sig : + limits elem_type { $$.elem_limits = $1; } +; +memory_sig : + limits { $$.page_limits = $1; } +; +limits : + nat { + $$.has_max = WASM_FALSE; + $$.initial = $1; + $$.max = 0; + } + | nat nat { + $$.has_max = WASM_TRUE; + $$.initial = $1; + $$.max = $2; + } +; +type_use : + LPAR TYPE var RPAR { $$ = $3; } +; /* Expressions */ nat : NAT { - if (WASM_FAILED(wasm_parse_int32($1.text.start, - $1.text.start + $1.text.length, &$$, - WASM_PARSE_UNSIGNED_ONLY))) { - wasm_ast_parser_error(&@1, lexer, parser, "invalid int " PRIstringslice, + if (WASM_FAILED(wasm_parse_uint64($1.text.start, + $1.text.start + $1.text.length, &$$))) { + wasm_ast_parser_error(&@1, lexer, parser, + "invalid int " PRIstringslice "\"", WASM_PRINTF_STRING_SLICE_ARG($1.text)); } } @@ -308,17 +392,10 @@ literal : ; var : - NAT { + nat { $$.loc = @1; $$.type = WASM_VAR_TYPE_INDEX; - uint64_t index; - if (WASM_FAILED(wasm_parse_int64($1.text.start, - $1.text.start + $1.text.length, &index, - WASM_PARSE_UNSIGNED_ONLY))) { - wasm_ast_parser_error(&@1, lexer, parser, "invalid int " PRIstringslice, - WASM_PRINTF_STRING_SLICE_ARG($1.text)); - } - $$.index = index; + $$.index = $1; } | VAR { $$.loc = @1; @@ -333,31 +410,18 @@ var_list : wasm_append_var_value(parser->allocator, &$$, &$2); } ; +bind_var_opt : + /* empty */ { WASM_ZERO_MEMORY($$); } + | bind_var +; bind_var : VAR { DUPTEXT($$, $1); } ; -quoted_text : - TEXT { - WasmTextListNode node; - node.text = $1; - node.next = NULL; - WasmTextList text_list; - text_list.first = &node; - text_list.last = &node; - void* data; - size_t size; - dup_text_list(parser->allocator, &text_list, &data, &size); - $$.start = data; - $$.length = size; - } -; - -labeling : +labeling_opt : /* empty */ %prec LOW { WASM_ZERO_MEMORY($$); } - | labeling1 + | bind_var ; -labeling1 : bind_var ; offset_opt : /* empty */ { $$ = 0; } @@ -382,11 +446,12 @@ align_opt : } ; -expr : - op { $$ = join_exprs1(&@1, $1); } - | LPAR expr1 RPAR { $$ = $2; } +instr : + plain_instr { $$ = join_exprs1(&@1, $1); } + | block_instr { $$ = join_exprs1(&@1, $1); } + | expr { $$ = $1; } ; -op : +plain_instr : UNREACHABLE { $$ = wasm_new_unreachable_expr(parser->allocator); } @@ -396,68 +461,29 @@ op : | DROP { $$ = wasm_new_drop_expr(parser->allocator); } - | BLOCK labeling expr_list END { - $$ = wasm_new_block_expr(parser->allocator); - $$->block.label = $2; - $$->block.first = $3.first; - } - | LOOP labeling expr_list END { - $$ = wasm_new_loop_expr(parser->allocator); - $$->loop.label = $2; - $$->loop.first = $3.first; - } - | LOOP labeling1 labeling1 expr_list END { - $$ = wasm_new_block_expr(parser->allocator); - $$->block.label = $2; - WasmExpr* loop = wasm_new_loop_expr(parser->allocator); - loop->loc = @1; - loop->loop.label = $3; - loop->loop.first = $4.first; - $$->block.first = loop; + | SELECT { + $$ = wasm_new_select_expr(parser->allocator); } - | BR nat var { + | BR var { $$ = wasm_new_br_expr(parser->allocator); - $$->br.arity = $2; - $$->br.var = $3; + $$->br.var = $2; } - | BR_IF nat var { + | BR_IF var { $$ = wasm_new_br_if_expr(parser->allocator); - $$->br_if.arity = $2; - $$->br_if.var = $3; + $$->br_if.var = $2; } - | BR_TABLE nat var_list var { + | BR_TABLE var_list var { $$ = wasm_new_br_table_expr(parser->allocator); - $$->br_table.arity = $2; - $$->br_table.targets = $3; - $$->br_table.default_target = $4; - // split_var_list_as_br_table_targets(&$$, $3); + $$->br_table.targets = $2; + $$->br_table.default_target = $3; } | RETURN { $$ = wasm_new_return_expr(parser->allocator); } - | IF labeling expr_list END { - $$ = wasm_new_if_expr(parser->allocator); - $$->if_.true_.label = $2; - $$->if_.true_.first = $3.first; - } - | IF labeling expr_list ELSE labeling expr_list END { - $$ = wasm_new_if_else_expr(parser->allocator); - $$->if_else.true_.label = $2; - $$->if_else.true_.first = $3.first; - $$->if_else.false_.label = $5; - $$->if_else.false_.first = $6.first; - } - | SELECT { - $$ = wasm_new_select_expr(parser->allocator); - } | CALL var { $$ = wasm_new_call_expr(parser->allocator); $$->call.var = $2; } - | CALL_IMPORT var { - $$ = wasm_new_call_import_expr(parser->allocator); - $$->call_import.var = $2; - } | CALL_INDIRECT var { $$ = wasm_new_call_indirect_expr(parser->allocator); $$->call_indirect.var = $2; @@ -529,211 +555,108 @@ op : $$ = wasm_new_grow_memory_expr(parser->allocator); } ; -expr1 : - UNREACHABLE { - $$ = join_exprs1(&@1, wasm_new_unreachable_expr(parser->allocator)); +block_instr : + BLOCK labeling_opt block END { + $$ = wasm_new_block_expr(parser->allocator); + $$->block = $3; + $$->block.label = $2; } - | NOP { - $$ = join_exprs1(&@1, wasm_new_nop_expr(parser->allocator)); + | LOOP labeling_opt block END { + $$ = wasm_new_loop_expr(parser->allocator); + $$->loop = $3; + $$->loop.label = $2; } - | DROP expr { - $$ = join_exprs2(&@1, &$2, wasm_new_drop_expr(parser->allocator)); + | IF labeling_opt block END { + $$ = wasm_new_if_expr(parser->allocator); + $$->if_.true_ = $3; + $$->if_.true_.label = $2; + } + | IF labeling_opt block ELSE instr_list END { + $$ = wasm_new_if_expr(parser->allocator); + $$->if_.true_ = $3; + $$->if_.true_.label = $2; + $$->if_.false_ = $5.first; } - | BLOCK labeling expr_list { +; +block : + value_type_list instr_list { + WASM_ZERO_MEMORY($$); + $$.sig = $1; + $$.first = $2.first; + } +; + +expr : + LPAR expr1 RPAR { $$ = $2; } +; + +expr1 : + plain_instr expr_list { + $$ = join_exprs2(&@1, &$2, $1); + } + | BLOCK labeling_opt block { WasmExpr* expr = wasm_new_block_expr(parser->allocator); + expr->block = $3; expr->block.label = $2; - expr->block.first = $3.first; $$ = join_exprs1(&@1, expr); } - | LOOP labeling expr_list { + | LOOP labeling_opt block { WasmExpr* expr = wasm_new_loop_expr(parser->allocator); + expr->loop = $3; expr->loop.label = $2; - expr->loop.first = $3.first; $$ = join_exprs1(&@1, expr); } - | LOOP labeling1 labeling1 expr_list { - WasmExpr* block = wasm_new_block_expr(parser->allocator); - block->block.label = $2; - WasmExpr* loop = wasm_new_loop_expr(parser->allocator); - loop->loc = @1; - loop->loop.label = $3; - loop->loop.first = $4.first; - block->block.first = loop; - $$ = join_exprs1(&@1, block); - } - | BR var { - WasmExpr* expr = wasm_new_br_expr(parser->allocator); - expr->br.arity = 0; - expr->br.var = $2; - $$ = join_exprs1(&@1, expr); + | IF labeling_opt value_type_list if_ { + $$ = $4; + WasmExpr* if_ = $4.last; + assert(if_->type == WASM_EXPR_TYPE_IF); + if_->if_.true_.label = $2; + if_->if_.true_.sig = $3; } - | BR var expr { - WasmExpr* expr = wasm_new_br_expr(parser->allocator); - expr->br.arity = 1; - expr->br.var = $2; - $$ = join_exprs2(&@1, &$3, expr); - } - | BR_IF var expr { - WasmExpr* expr = wasm_new_br_if_expr(parser->allocator); - expr->br_if.arity = 0; - expr->br_if.var = $2; - $$ = join_exprs2(&@1, &$3, expr); - } - | BR_IF var expr expr { - WasmExpr* expr = wasm_new_br_if_expr(parser->allocator); - expr->br_if.arity = 1; - expr->br_if.var = $2; - $$ = join_exprs3(&@1, &$3, &$4, expr); - } - | BR_TABLE var_list var expr { - WasmExpr* expr = wasm_new_br_table_expr(parser->allocator); - expr->br_table.arity = 0; - expr->br_table.targets = $2; - expr->br_table.default_target = $3; - // split_var_list_as_br_table_targets(expr, $2); - $$ = join_exprs2(&@1, &$4, expr); - } - | BR_TABLE var_list var expr expr { - WasmExpr* expr = wasm_new_br_table_expr(parser->allocator); - expr->br_table.arity = 1; - expr->br_table.targets = $2; - expr->br_table.default_target = $3; - // split_var_list_as_br_table_targets(expr, $2); - $$ = join_exprs3(&@1, &$4, &$5, expr); - } - | RETURN expr_list { - WasmExpr* expr = wasm_new_return_expr(parser->allocator); - $$ = join_exprs2(&@1, &$2, expr); - } - | IF expr expr { +; +if_ : + LPAR THEN instr_list RPAR LPAR ELSE instr_list RPAR { WasmExpr* expr = wasm_new_if_expr(parser->allocator); expr->if_.true_.first = $3.first; - $$ = join_exprs2(&@1, &$2, expr); - } - | IF expr expr expr { - WasmExpr* expr = wasm_new_if_else_expr(parser->allocator); - expr->if_else.true_.first = $3.first; - expr->if_else.false_.first = $4.first; - $$ = join_exprs2(&@1, &$2, expr); - } - | IF expr LPAR THEN labeling expr_list RPAR { - WasmExpr* expr = wasm_new_if_expr(parser->allocator); - expr->if_.true_.label = $5; - expr->if_.true_.first = $6.first; - $$ = join_exprs2(&@1, &$2, expr); - } - | IF expr LPAR THEN labeling expr_list RPAR LPAR ELSE labeling expr_list RPAR { - WasmExpr* expr = wasm_new_if_else_expr(parser->allocator); - expr->if_else.true_.label = $5; - expr->if_else.true_.first = $6.first; - expr->if_else.false_.label = $10; - expr->if_else.false_.first = $11.first; - $$ = join_exprs2(&@1, &$2, expr); - } - | IF expr_list ELSE expr_list { - WasmExpr* expr = wasm_new_if_else_expr(parser->allocator); - expr->if_else.true_.first = $2.first; - expr->if_else.false_.first = $4.first; - $$ = join_exprs1(&@1, expr); - } - | SELECT expr expr expr { - $$ = join_exprs4(&@1, &$2, &$3, &$4, - wasm_new_select_expr(parser->allocator)); - } - | CALL var expr_list { - WasmExpr* expr = wasm_new_call_expr(parser->allocator); - expr->call.var = $2; - $$ = join_exprs2(&@1, &$3, expr); - } - | CALL_IMPORT var expr_list { - WasmExpr* expr = wasm_new_call_import_expr(parser->allocator); - expr->call_import.var = $2; - $$ = join_exprs2(&@1, &$3, expr); - } - | CALL_INDIRECT var expr expr_list { - WasmExpr* expr = wasm_new_call_indirect_expr(parser->allocator); - expr->call_indirect.var = $2; - $$ = join_exprs3(&@1, &$3, &$4, expr); - } - | GET_LOCAL var { - WasmExpr* expr = wasm_new_get_local_expr(parser->allocator); - expr->get_local.var = $2; - $$ = join_exprs1(&@1, expr); - } - | SET_LOCAL var expr { - WasmExpr* expr = wasm_new_set_local_expr(parser->allocator); - expr->set_local.var = $2; - $$ = join_exprs2(&@1, &$3, expr); - } - | TEE_LOCAL var expr { - WasmExpr* expr = wasm_new_tee_local_expr(parser->allocator); - expr->tee_local.var = $2; - $$ = join_exprs2(&@1, &$3, expr); - } - | GET_GLOBAL var { - WasmExpr* expr = wasm_new_get_global_expr(parser->allocator); - expr->get_global.var = $2; + expr->if_.false_ = $7.first; $$ = join_exprs1(&@1, expr); } - | SET_GLOBAL var expr { - WasmExpr* expr = wasm_new_set_global_expr(parser->allocator); - expr->set_global.var = $2; - $$ = join_exprs2(&@1, &$3, expr); - } - | LOAD offset_opt align_opt expr { - WasmExpr* expr = wasm_new_load_expr(parser->allocator); - expr->load.opcode = $1; - expr->load.offset = $2; - expr->load.align = $3; - $$ = join_exprs2(&@1, &$4, expr); - } - | STORE offset_opt align_opt expr expr { - WasmExpr* expr = wasm_new_store_expr(parser->allocator); - expr->store.opcode = $1; - expr->store.offset = $2; - expr->store.align = $3; - $$ = join_exprs3(&@1, &$4, &$5, expr); - } - | CONST literal { - WasmExpr* expr = wasm_new_const_expr(parser->allocator); - expr->const_.loc = @1; - if (WASM_FAILED(parse_const($1, $2.type, $2.text.start, - $2.text.start + $2.text.length, - &expr->const_))) { - wasm_ast_parser_error(&@2, lexer, parser, - "invalid literal \"" PRIstringslice "\"", - WASM_PRINTF_STRING_SLICE_ARG($2.text)); - } - wasm_free(parser->allocator, (char*)$2.text.start); + | LPAR THEN instr_list RPAR { + WasmExpr* expr = wasm_new_if_expr(parser->allocator); + expr->if_.true_.first = $3.first; $$ = join_exprs1(&@1, expr); } - | UNARY expr { - WasmExpr* expr = wasm_new_unary_expr(parser->allocator); - expr->unary.opcode = $1; - $$ = join_exprs2(&@1, &$2, expr); - } - | BINARY expr expr { - WasmExpr* expr = wasm_new_binary_expr(parser->allocator); - expr->binary.opcode = $1; - $$ = join_exprs3(&@1, &$2, &$3, expr); + | expr LPAR THEN instr_list RPAR LPAR ELSE instr_list RPAR { + WasmExpr* expr = wasm_new_if_expr(parser->allocator); + expr->if_.true_.first = $4.first; + expr->if_.false_ = $8.first; + $$ = join_exprs2(&@1, &$1, expr); } - | COMPARE expr expr { - WasmExpr* expr = wasm_new_compare_expr(parser->allocator); - expr->compare.opcode = $1; - $$ = join_exprs3(&@1, &$2, &$3, expr); + | expr LPAR THEN instr_list RPAR { + WasmExpr* expr = wasm_new_if_expr(parser->allocator); + expr->if_.true_.first = $4.first; + $$ = join_exprs2(&@1, &$1, expr); } - | CONVERT expr { - WasmExpr* expr = wasm_new_convert_expr(parser->allocator); - expr->convert.opcode = $1; - $$ = join_exprs2(&@1, &$2, expr); + | expr expr expr { + WasmExpr* expr = wasm_new_if_expr(parser->allocator); + expr->if_.true_.first = $2.first; + expr->if_.false_ = $3.first; + $$ = join_exprs2(&@1, &$1, expr); } - | CURRENT_MEMORY { - WasmExpr* expr = wasm_new_current_memory_expr(parser->allocator); - $$ = join_exprs1(&@1, expr); + | expr expr { + WasmExpr* expr = wasm_new_if_expr(parser->allocator); + expr->if_.true_.first = $2.first; + $$ = join_exprs2(&@1, &$1, expr); } - | GROW_MEMORY expr { - WasmExpr* expr = wasm_new_grow_memory_expr(parser->allocator); - $$ = join_exprs2(&@1, &$2, expr); +; + +instr_list : + /* empty */ { WASM_ZERO_MEMORY($$); } + | instr instr_list { + $$.first = $1.first; + $1.last->next = $2.first; + $$.last = $2.last ? $2.last : $1.last; + $$.size = $1.size + $2.size; } ; expr_list : @@ -744,9 +667,9 @@ expr_list : $$.last = $2.last ? $2.last : $1.last; $$.size = $1.size + $2.size; } -; + const_expr : - expr_list + instr_list ; /* Functions */ @@ -774,7 +697,7 @@ func_fields : } ; func_body : - expr_list { + instr_list { $$ = new_func_field(parser->allocator); $$->type = WASM_FUNC_FIELD_TYPE_EXPRS; $$->first_expr = $1.first; @@ -795,9 +718,6 @@ func_body : $$->next = $6; } ; -type_use : - LPAR TYPE var RPAR { $$ = $3; } -; func_info : func_fields { $$ = new_func(parser->allocator); @@ -843,8 +763,7 @@ func_info : } case WASM_FUNC_FIELD_TYPE_RESULT_TYPES: - $$->decl.sig.result_type = - get_result_type_from_type_vector(&field->types); + $$->decl.sig.result_types = field->types; break; } @@ -855,41 +774,34 @@ func_info : } ; func : - LPAR FUNC export_opt type_use func_info RPAR { - $$.func = $5; - $$.func->decl.flags |= WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; - $$.func->decl.type_var = $4; - $$.export_.name = $3; - $$.export_.var.type = WASM_VAR_TYPE_INDEX; - $$.export_.var.index = -1; - } - | LPAR FUNC export_opt bind_var type_use func_info RPAR { + LPAR FUNC bind_var_opt inline_export type_use func_info RPAR { + WASM_ZERO_MEMORY($$); $$.func = $6; $$.func->decl.flags |= WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; $$.func->decl.type_var = $5; - $$.func->name = $4; - $$.export_.name = $3; - $$.export_.var.type = WASM_VAR_TYPE_INDEX; - $$.export_.var.index = -1; + $$.func->name = $3; + $$.export_ = $4; } - | LPAR FUNC export_opt func_info RPAR { - $$.func = $4; - $$.export_.name = $3; - $$.export_.var.type = WASM_VAR_TYPE_INDEX; - $$.export_.var.index = -1; + /* Duplicate above for empty inline_export_opt to avoid LR(1) conflict. */ + | LPAR FUNC bind_var_opt type_use func_info RPAR { + WASM_ZERO_MEMORY($$); + $$.func = $5; + $$.func->decl.flags |= WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + $$.func->decl.type_var = $4; + $$.func->name = $3; } - | LPAR FUNC export_opt bind_var func_info RPAR { + | LPAR FUNC bind_var_opt inline_export func_info RPAR { + WASM_ZERO_MEMORY($$); $$.func = $5; - $$.func->name = $4; - $$.export_.name = $3; - $$.export_.var.type = WASM_VAR_TYPE_INDEX; - $$.export_.var.index = -1; + $$.func->name = $3; + $$.export_ = $4; + } + /* Duplicate above for empty inline_export_opt to avoid LR(1) conflict. */ + | LPAR FUNC bind_var_opt func_info RPAR { + WASM_ZERO_MEMORY($$); + $$.func = $4; + $$.func->name = $3; } -; - -export_opt : - /* empty */ { WASM_ZERO_MEMORY($$); } - | quoted_text ; /* Tables & Memories */ @@ -898,84 +810,72 @@ offset : LPAR OFFSET const_expr RPAR { $$ = $3; } - | LPAR expr1 RPAR { - $$ = $2; - } + | expr ; + elem : - LPAR ELEM offset var_list RPAR { + LPAR ELEM var offset var_list RPAR { + $$.table_var = $3; + $$.offset = $4.first; + $$.vars = $5; + } + | LPAR ELEM offset var_list RPAR { + $$.table_var.type = WASM_VAR_TYPE_INDEX; + $$.table_var.index = 0; $$.offset = $3.first; $$.vars = $4; } ; -initial_elems : - NAT { PARSE_NAT($$, $1, @1, "invalid initial table elems"); } -; -max_elems : - NAT { PARSE_NAT($$, $1, @1, "invalid max table elems"); } -; -table_limits : - initial_elems { - $$.initial = $1; - $$.max = 0; - $$.has_max = WASM_FALSE; - } - | initial_elems max_elems { - $$.initial = $1; - $$.max = $2; - $$.has_max = WASM_TRUE; - } -; + table : - LPAR TABLE table_limits elem_type RPAR { - $$.table.elem_limits = $3; + LPAR TABLE bind_var_opt inline_export_opt table_sig RPAR { + $$.table = $5; + $$.table.name = $3; $$.has_elem_segment = WASM_FALSE; + $$.export_ = $4; } - | LPAR TABLE elem_type LPAR ELEM var_list RPAR RPAR { + | LPAR TABLE bind_var_opt inline_export_opt elem_type + LPAR ELEM var_list RPAR RPAR { WasmExpr* expr = wasm_new_const_expr(parser->allocator); expr->loc = @2; expr->const_.type = WASM_TYPE_I32; expr->const_.u32 = 0; WASM_ZERO_MEMORY($$); - $$.table.elem_limits.initial = $6.size; - $$.table.elem_limits.max = $6.size; + $$.table.name = $3; + $$.table.elem_limits.initial = $8.size; + $$.table.elem_limits.max = $8.size; $$.table.elem_limits.has_max = WASM_TRUE; $$.has_elem_segment = WASM_TRUE; $$.elem_segment.offset = expr; - $$.elem_segment.vars = $6; + $$.elem_segment.vars = $8; + $$.export_ = $4; } ; + data : - LPAR DATA offset text_list RPAR { + LPAR DATA var offset text_list RPAR { + $$.memory_var = $3; + $$.offset = $4.first; + dup_text_list(parser->allocator, &$5, &$$.data, &$$.size); + } + | LPAR DATA offset text_list RPAR { + $$.memory_var.type = WASM_VAR_TYPE_INDEX; + $$.memory_var.index = 0; $$.offset = $3.first; dup_text_list(parser->allocator, &$4, &$$.data, &$$.size); } ; -initial_pages : - NAT { PARSE_NAT($$, $1, @1, "invalid initial memory pages"); } -; -max_pages : - NAT { PARSE_NAT($$, $1, @1, "invalid max memory pages"); } -; -memory_limits : - initial_pages { - $$.initial = $1; - $$.max = 0; - $$.has_max = WASM_FALSE; - } - | initial_pages max_pages { - $$.initial = $1; - $$.max = $2; - $$.has_max = WASM_TRUE; - } -; + memory : - LPAR MEMORY memory_limits RPAR { - $$.memory.page_limits = $3; + LPAR MEMORY bind_var_opt inline_export_opt memory_sig RPAR { + WASM_ZERO_MEMORY($$); + $$.memory = $5; + $$.memory.name = $3; $$.has_data_segment = WASM_FALSE; + $$.export_ = $4; } - | LPAR MEMORY LPAR DATA text_list RPAR RPAR { + | LPAR MEMORY bind_var_opt inline_export LPAR DATA text_list RPAR RPAR { WasmExpr* expr = wasm_new_const_expr(parser->allocator); expr->loc = @2; expr->const_.type = WASM_TYPE_I32; @@ -984,305 +884,338 @@ memory : WASM_ZERO_MEMORY($$); $$.has_data_segment = WASM_TRUE; $$.data_segment.offset = expr; - dup_text_list(parser->allocator, &$5, &$$.data_segment.data, + dup_text_list(parser->allocator, &$7, &$$.data_segment.data, &$$.data_segment.size); uint32_t byte_size = WASM_ALIGN_UP_TO_PAGE($$.data_segment.size); uint32_t page_size = WASM_BYTES_TO_PAGES(byte_size); + $$.memory.name = $3; $$.memory.page_limits.initial = page_size; $$.memory.page_limits.max = page_size; $$.memory.page_limits.has_max = WASM_TRUE; + $$.export_ = $4; } -; - -/* Modules */ + /* Duplicate above for empty inline_export_opt to avoid LR(1) conflict. */ + | LPAR MEMORY bind_var_opt LPAR DATA text_list RPAR RPAR { + WasmExpr* expr = wasm_new_const_expr(parser->allocator); + expr->loc = @2; + expr->const_.type = WASM_TYPE_I32; + expr->const_.u32 = 0; -start : - LPAR START var RPAR { $$ = $3; } + WASM_ZERO_MEMORY($$); + $$.has_data_segment = WASM_TRUE; + $$.data_segment.offset = expr; + dup_text_list(parser->allocator, &$6, &$$.data_segment.data, + &$$.data_segment.size); + uint32_t byte_size = WASM_ALIGN_UP_TO_PAGE($$.data_segment.size); + uint32_t page_size = WASM_BYTES_TO_PAGES(byte_size); + $$.memory.name = $3; + $$.memory.page_limits.initial = page_size; + $$.memory.page_limits.max = page_size; + $$.memory.page_limits.has_max = WASM_TRUE; + $$.export_.has_export = WASM_FALSE; + } ; global : - LPAR GLOBAL VALUE_TYPE expr RPAR { + LPAR GLOBAL bind_var_opt inline_export global_type const_expr RPAR { WASM_ZERO_MEMORY($$); - $$.type = $3; - $$.init_expr = $4.first; + $$.global = $5; + $$.global.name = $3; + $$.global.init_expr = $6.first; + $$.export_ = $4; } - | LPAR GLOBAL bind_var VALUE_TYPE expr RPAR { + | LPAR GLOBAL bind_var_opt global_type const_expr RPAR { WASM_ZERO_MEMORY($$); - $$.name = $3; - $$.type = $4; - $$.init_expr = $5.first; + $$.global = $4; + $$.global.name = $3; + $$.global.init_expr = $5.first; + $$.export_.has_export = WASM_FALSE; } ; -type_def : - LPAR TYPE LPAR FUNC func_type RPAR RPAR { - WASM_ZERO_MEMORY($$); - $$.sig = $5; +/* Imports & Exports */ + +import_kind : + LPAR FUNC bind_var_opt type_use RPAR { + $$ = new_import(parser->allocator); + $$->name = $3; + $$->kind = WASM_IMPORT_KIND_FUNC; + $$->func.decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + $$->func.decl.type_var = $4; } - | LPAR TYPE bind_var LPAR FUNC func_type RPAR RPAR { - $$.name = $3; - $$.sig = $6; + | LPAR FUNC bind_var_opt func_sig RPAR { + $$ = new_import(parser->allocator); + $$->name = $3; + $$->kind = WASM_IMPORT_KIND_FUNC; + $$->func.decl.sig = $4; } -; - -import : - LPAR IMPORT quoted_text quoted_text type_use RPAR { + | LPAR TABLE bind_var_opt table_sig RPAR { $$ = new_import(parser->allocator); - $$->module_name = $3; - $$->func_name = $4; - $$->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; - $$->decl.type_var = $5; + $$->name = $3; + $$->kind = WASM_IMPORT_KIND_TABLE; + $$->table = $4; } - | LPAR IMPORT bind_var quoted_text quoted_text type_use RPAR /* Sugar */ { + | LPAR MEMORY bind_var_opt memory_sig RPAR { $$ = new_import(parser->allocator); $$->name = $3; - $$->module_name = $4; - $$->func_name = $5; - $$->decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; - $$->decl.type_var = $6; + $$->kind = WASM_IMPORT_KIND_MEMORY; + $$->memory = $4; } - | LPAR IMPORT quoted_text quoted_text func_type RPAR /* Sugar */ { + | LPAR GLOBAL bind_var_opt global_type RPAR { $$ = new_import(parser->allocator); + $$->name = $3; + $$->kind = WASM_IMPORT_KIND_GLOBAL; + $$->global = $4; + } +; +import : + LPAR IMPORT quoted_text quoted_text import_kind RPAR { + $$ = $5; $$->module_name = $3; - $$->func_name = $4; - $$->decl.sig = $5; + $$->item_name = $4; } - | LPAR IMPORT bind_var quoted_text quoted_text func_type RPAR /* Sugar */ { - $$ = new_import(parser->allocator); + | LPAR FUNC bind_var_opt inline_import type_use RPAR { + $$ = $4; + $$->name = $3; + $$->kind = WASM_IMPORT_KIND_FUNC; + $$->func.decl.flags = WASM_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE; + $$->func.decl.type_var = $5; + } + | LPAR FUNC bind_var_opt inline_import func_sig RPAR { + $$ = $4; + $$->name = $3; + $$->kind = WASM_IMPORT_KIND_FUNC; + $$->func.decl.sig = $5; + } + | LPAR TABLE bind_var_opt inline_import table_sig RPAR { + $$ = $4; + $$->name = $3; + $$->kind = WASM_IMPORT_KIND_TABLE; + $$->table = $5; + } + | LPAR MEMORY bind_var_opt inline_import memory_sig RPAR { + $$ = $4; + $$->name = $3; + $$->kind = WASM_IMPORT_KIND_MEMORY; + $$->memory = $5; + } + | LPAR GLOBAL bind_var_opt inline_import global_type RPAR { + $$ = $4; $$->name = $3; - $$->module_name = $4; - $$->func_name = $5; - $$->decl.sig = $6; + $$->kind = WASM_IMPORT_KIND_GLOBAL; + $$->global = $5; } ; -export : - LPAR EXPORT quoted_text var RPAR { - $$.name = $3; - $$.var = $4; +inline_import : + LPAR IMPORT quoted_text quoted_text RPAR { + $$ = new_import(parser->allocator); + $$->module_name = $3; + $$->item_name = $4; } ; -export_memory : - LPAR EXPORT quoted_text MEMORY RPAR { +export_kind : + LPAR FUNC var RPAR { + WASM_ZERO_MEMORY($$); + $$.kind = WASM_EXPORT_KIND_FUNC; + $$.var = $3; + } + | LPAR TABLE var RPAR { + WASM_ZERO_MEMORY($$); + $$.kind = WASM_EXPORT_KIND_TABLE; + $$.var = $3; + } + | LPAR MEMORY var RPAR { + WASM_ZERO_MEMORY($$); + $$.kind = WASM_EXPORT_KIND_MEMORY; + $$.var = $3; + } + | LPAR GLOBAL var RPAR { + WASM_ZERO_MEMORY($$); + $$.kind = WASM_EXPORT_KIND_GLOBAL; + $$.var = $3; + } +; +export : + LPAR EXPORT quoted_text export_kind RPAR { + $$ = $4; $$.name = $3; } ; -module_fields : - /* empty */ { - $$ = new_module(parser->allocator); +inline_export_opt : + /* empty */ { + WASM_ZERO_MEMORY($$); + $$.has_export = WASM_FALSE; } - | module_fields func { - $$ = $1; - WasmModuleField* field = wasm_append_module_field(parser->allocator, $$); - field->loc = @2; - field->type = WASM_MODULE_FIELD_TYPE_FUNC; - field->func = *$2.func; - wasm_free(parser->allocator, $2.func); + | inline_export +; +inline_export : + LPAR EXPORT quoted_text RPAR { + WASM_ZERO_MEMORY($$); + $$.has_export = WASM_TRUE; + $$.export_.name = $3; + } +; - append_implicit_func_declaration(parser->allocator, &@2, $$, - &field->func.decl); - WasmFunc* func_ptr = &field->func; - wasm_append_func_ptr_value(parser->allocator, &$$->funcs, &func_ptr); - if (field->func.name.start) { - WasmBinding* binding = wasm_insert_binding( - parser->allocator, &$$->func_bindings, &field->func.name); - binding->loc = field->loc; - binding->index = $$->funcs.size - 1; - } +/* Modules */ - /* is this function using the export syntactic sugar? */ - if ($2.export_.name.start != NULL) { - WasmModuleField* export_field = - wasm_append_module_field(parser->allocator, $$); - export_field->loc = @2; - export_field->type = WASM_MODULE_FIELD_TYPE_EXPORT; - export_field->export_ = $2.export_; - export_field->export_.var.index = $$->funcs.size - 1; - - WasmExport* export_ptr = &export_field->export_; - wasm_append_export_ptr_value(parser->allocator, &$$->exports, - &export_ptr); - WasmBinding* binding = - wasm_insert_binding(parser->allocator, &$$->export_bindings, - &export_field->export_.name); - binding->loc = export_field->loc; - binding->index = $$->exports.size - 1; - } +type_def : + LPAR TYPE func_type RPAR { + WASM_ZERO_MEMORY($$); + $$.sig = $3; } - | module_fields global { - $$ = $1; - WasmModuleField* field = wasm_append_module_field(parser->allocator, $$); - field->loc = @2; - field->type = WASM_MODULE_FIELD_TYPE_GLOBAL; - field->global = $2; - - WasmGlobal* global_ptr = &field->global; - wasm_append_global_ptr_value(parser->allocator, &$$->globals, - &global_ptr); - if (field->global.name.start) { - WasmBinding* binding = wasm_insert_binding( - parser->allocator, &$$->global_bindings, &field->global.name); - binding->loc = field->loc; - binding->index = $$->globals.size - 1; - } + | LPAR TYPE bind_var func_type RPAR { + $$.name = $3; + $$.sig = $4; } - | module_fields import { - $$ = $1; - WasmModuleField* field = wasm_append_module_field(parser->allocator, $$); - field->loc = @2; - field->type = WASM_MODULE_FIELD_TYPE_IMPORT; - field->import = *$2; - wasm_free(parser->allocator, $2); +; - append_implicit_func_declaration(parser->allocator, &@2, $$, - &field->import.decl); - - WasmImport* import_ptr = &field->import; - wasm_append_import_ptr_value(parser->allocator, &$$->imports, - &import_ptr); - if (field->import.name.start) { - WasmBinding* binding = wasm_insert_binding( - parser->allocator, &$$->import_bindings, &field->import.name); - binding->loc = field->loc; - binding->index = $$->imports.size - 1; - } +start : + LPAR START var RPAR { $$ = $3; } +; + +module_fields : + /* empty */ { + $$ = new_module(parser->allocator); } - | module_fields export { + | module_fields type_def { $$ = $1; - WasmModuleField* field = wasm_append_module_field(parser->allocator, $$); - field->loc = @2; - field->type = WASM_MODULE_FIELD_TYPE_EXPORT; - field->export_ = $2; - - WasmExport* export_ptr = &field->export_; - wasm_append_export_ptr_value(parser->allocator, &$$->exports, - &export_ptr); - if (field->export_.name.start) { - WasmBinding* binding = wasm_insert_binding( - parser->allocator, &$$->export_bindings, &field->export_.name); - binding->loc = field->loc; - binding->index = $$->exports.size - 1; - } + WasmModuleField* field; + APPEND_FIELD_TO_LIST($$, field, FUNC_TYPE, func_type, @2, $2); + APPEND_ITEM_TO_VECTOR($$, FuncType, func_type, func_types, + &field->func_type); + INSERT_BINDING($$, func_type, func_types, @2, $2); } - | module_fields export_memory { + | module_fields global { $$ = $1; - WasmModuleField* field = wasm_append_module_field(parser->allocator, $$); - field->loc = @2; - field->type = WASM_MODULE_FIELD_TYPE_EXPORT_MEMORY; - field->export_memory = $2; - $$->export_memory = &field->export_memory; + WasmModuleField* field; + APPEND_FIELD_TO_LIST($$, field, GLOBAL, global, @2, $2.global); + APPEND_ITEM_TO_VECTOR($$, Global, global, globals, &field->global); + INSERT_BINDING($$, global, globals, @2, $2.global); + APPEND_INLINE_EXPORT($$, GLOBAL, @2, $2, $$->globals.size - 1); } | module_fields table { $$ = $1; - WasmModuleField* field = wasm_append_module_field(parser->allocator, $$); - field->loc = @2; - field->type = WASM_MODULE_FIELD_TYPE_TABLE; - field->table = $2.table; - $$->table = &field->table; + WasmModuleField* field; + APPEND_FIELD_TO_LIST($$, field, TABLE, table, @2, $2.table); + APPEND_ITEM_TO_VECTOR($$, Table, table, tables, &field->table); + INSERT_BINDING($$, table, tables, @2, $2.table); + APPEND_INLINE_EXPORT($$, TABLE, @2, $2, $$->tables.size - 1); - /* is this table using the elem_segment syntactic sugar? */ if ($2.has_elem_segment) { - WasmModuleField* elem_segment_field = - wasm_append_module_field(parser->allocator, $$); - elem_segment_field->loc = @2; - elem_segment_field->type = WASM_MODULE_FIELD_TYPE_ELEM_SEGMENT; - elem_segment_field->elem_segment = $2.elem_segment; - - WasmElemSegment* elem_segment_ptr = &elem_segment_field->elem_segment; - wasm_append_elem_segment_ptr_value( - parser->allocator, &$$->elem_segments, &elem_segment_ptr); + WasmModuleField* elem_segment_field; + APPEND_FIELD_TO_LIST($$, elem_segment_field, ELEM_SEGMENT, elem_segment, + @2, $2.elem_segment); + APPEND_ITEM_TO_VECTOR($$, ElemSegment, elem_segment, elem_segments, + &elem_segment_field->elem_segment); } - } - | module_fields elem { - $$ = $1; - WasmModuleField* field = wasm_append_module_field(parser->allocator, $$); - field->loc = @2; - field->type = WASM_MODULE_FIELD_TYPE_ELEM_SEGMENT; - field->elem_segment = $2; - WasmElemSegment* elem_segment_ptr = &field->elem_segment; - wasm_append_elem_segment_ptr_value(parser->allocator, &$$->elem_segments, - &elem_segment_ptr); - } - | module_fields type_def { - $$ = $1; - WasmModuleField* field = wasm_append_module_field(parser->allocator, $$); - field->loc = @2; - field->type = WASM_MODULE_FIELD_TYPE_FUNC_TYPE; - field->func_type = $2; - - WasmFuncType* func_type_ptr = &field->func_type; - wasm_append_func_type_ptr_value(parser->allocator, &$$->func_types, - &func_type_ptr); - if (field->func_type.name.start) { - WasmBinding* binding = - wasm_insert_binding(parser->allocator, &$$->func_type_bindings, - &field->func_type.name); - binding->loc = field->loc; - binding->index = $$->func_types.size - 1; - } } | module_fields memory { $$ = $1; - WasmModuleField* field = wasm_append_module_field(parser->allocator, $$); - field->loc = @2; - field->type = WASM_MODULE_FIELD_TYPE_MEMORY; - field->memory = $2.memory; - $$->memory = &field->memory; + WasmModuleField* field; + APPEND_FIELD_TO_LIST($$, field, MEMORY, memory, @2, $2.memory); + APPEND_ITEM_TO_VECTOR($$, Memory, memory, memories, &field->memory); + INSERT_BINDING($$, memory, memories, @2, $2.memory); + APPEND_INLINE_EXPORT($$, MEMORY, @2, $2, $$->memories.size - 1); - /* is this table using the memory data syntactic sugar? */ if ($2.has_data_segment) { - WasmModuleField* data_segment_field = - wasm_append_module_field(parser->allocator, $$); - data_segment_field->loc = @2; - data_segment_field->type = WASM_MODULE_FIELD_TYPE_DATA_SEGMENT; - data_segment_field->data_segment = $2.data_segment; - - WasmDataSegment* data_segment_ptr = &data_segment_field->data_segment; - wasm_append_data_segment_ptr_value( - parser->allocator, &$$->data_segments, &data_segment_ptr); + WasmModuleField* data_segment_field; + APPEND_FIELD_TO_LIST($$, data_segment_field, DATA_SEGMENT, data_segment, + @2, $2.data_segment); + APPEND_ITEM_TO_VECTOR($$, DataSegment, data_segment, data_segments, + &data_segment_field->data_segment); } } + | module_fields func { + $$ = $1; + WasmModuleField* field; + APPEND_FIELD_TO_LIST($$, field, FUNC, func, @2, *$2.func); + wasm_free(parser->allocator, $2.func); + append_implicit_func_declaration(parser->allocator, &@2, $$, + &field->func.decl); + APPEND_ITEM_TO_VECTOR($$, Func, func, funcs, &field->func); + INSERT_BINDING($$, func, funcs, @2, *$2.func); + APPEND_INLINE_EXPORT($$, FUNC, @2, $2, $$->funcs.size - 1); + } + | module_fields elem { + $$ = $1; + WasmModuleField* field; + APPEND_FIELD_TO_LIST($$, field, ELEM_SEGMENT, elem_segment, @2, $2); + APPEND_ITEM_TO_VECTOR($$, ElemSegment, elem_segment, elem_segments, + &field->elem_segment); + } | module_fields data { $$ = $1; - WasmModuleField* field = wasm_append_module_field(parser->allocator, $$); - field->loc = @2; - field->type = WASM_MODULE_FIELD_TYPE_DATA_SEGMENT; - field->data_segment = $2; - - WasmDataSegment* data_segment_ptr = &field->data_segment; - wasm_append_data_segment_ptr_value(parser->allocator, &$$->data_segments, - &data_segment_ptr); + WasmModuleField* field; + APPEND_FIELD_TO_LIST($$, field, DATA_SEGMENT, data_segment, @2, $2); + APPEND_ITEM_TO_VECTOR($$, DataSegment, data_segment, data_segments, + &field->data_segment); } | module_fields start { $$ = $1; - WasmModuleField* field = wasm_append_module_field(parser->allocator, $$); - field->loc = @2; - field->type = WASM_MODULE_FIELD_TYPE_START; - field->start = $2; + WasmModuleField* field; + APPEND_FIELD_TO_LIST($$, field, START, start, @2, $2); $$->start = &field->start; } + | module_fields import { + $$ = $1; + WasmModuleField* field; + APPEND_FIELD_TO_LIST($$, field, IMPORT, import, @2, *$2); + switch ($2->kind) { + case WASM_IMPORT_KIND_FUNC: + append_implicit_func_declaration(parser->allocator, &@2, $$, + &$2->func.decl); + APPEND_ITEM_TO_VECTOR($$, Func, func, funcs, &field->import.func); + INSERT_BINDING($$, func, funcs, @2, *$2); + break; + case WASM_IMPORT_KIND_TABLE: + APPEND_ITEM_TO_VECTOR($$, Table, table, tables, &field->import.table); + INSERT_BINDING($$, table, tables, @2, *$2); + break; + case WASM_IMPORT_KIND_MEMORY: + APPEND_ITEM_TO_VECTOR($$, Memory, memory, memories, + &field->import.memory); + INSERT_BINDING($$, memory, memories, @2, *$2); + break; + case WASM_IMPORT_KIND_GLOBAL: + APPEND_ITEM_TO_VECTOR($$, Global, global, globals, + &field->import.global); + INSERT_BINDING($$, global, globals, @2, *$2); + break; + } + wasm_free(parser->allocator, $2); + APPEND_ITEM_TO_VECTOR($$, Import, import, imports, &field->import); + } + | module_fields export { + $$ = $1; + WasmModuleField* field = wasm_append_module_field(parser->allocator, $$); + APPEND_FIELD_TO_LIST($$, field, EXPORT, export_, @2, $2); + APPEND_ITEM_TO_VECTOR($$, Export, export, exports, &field->export_); + INSERT_BINDING($$, export, exports, @2, $2); + } ; raw_module : - LPAR MODULE module_fields RPAR { + LPAR MODULE script_var_opt module_fields RPAR { $$.type = WASM_RAW_MODULE_TYPE_TEXT; - $$.text = $3; + $$.text = $4; + $$.text->name = $3; $$.loc = @2; /* resolve func type variables where the signature was not specified * explicitly */ size_t i; - for (i = 0; i < $3->funcs.size; ++i) { - WasmFunc* func = $3->funcs.data[i]; + for (i = 0; i < $4->funcs.size; ++i) { + WasmFunc* func = $4->funcs.data[i]; if (wasm_decl_has_func_type(&func->decl) && is_empty_signature(&func->decl.sig)) { WasmFuncType* func_type = - wasm_get_func_type_by_var($3, &func->decl.type_var); + wasm_get_func_type_by_var($4, &func->decl.type_var); if (func_type) { func->decl.sig = func_type->sig; func->decl.flags |= WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE; @@ -1290,24 +1223,27 @@ raw_module : } } - for (i = 0; i < $3->imports.size; ++i) { - WasmImport* import = $3->imports.data[i]; - if (wasm_decl_has_func_type(&import->decl) && - is_empty_signature(&import->decl.sig)) { + for (i = 0; i < $4->imports.size; ++i) { + WasmImport* import = $4->imports.data[i]; + if (import->kind == WASM_IMPORT_KIND_FUNC && + wasm_decl_has_func_type(&import->func.decl) && + is_empty_signature(&import->func.decl.sig)) { WasmFuncType* func_type = - wasm_get_func_type_by_var($3, &import->decl.type_var); + wasm_get_func_type_by_var($4, &import->func.decl.type_var); if (func_type) { - import->decl.sig = func_type->sig; - import->decl.flags |= WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE; + import->func.decl.sig = func_type->sig; + import->func.decl.flags |= + WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE; } } } } - | LPAR MODULE non_empty_text_list RPAR { + | LPAR MODULE script_var_opt non_empty_text_list RPAR { $$.type = WASM_RAW_MODULE_TYPE_BINARY; + $$.binary.name = $3; $$.loc = @2; - dup_text_list(parser->allocator, &$3, &$$.binary.data, &$$.binary.size); - wasm_destroy_text_list(parser->allocator, &$3); + dup_text_list(parser->allocator, &$4, &$$.binary.data, &$$.binary.size); + wasm_destroy_text_list(parser->allocator, &$4); } ; @@ -1329,12 +1265,36 @@ module : wasm_read_binary_ast(parser->allocator, $1.binary.data, $1.binary.size, &options, &error_handler, $$); wasm_free(parser->allocator, $1.binary.data); + $$->name = $1.binary.name; } } ; /* Scripts */ +script_var_opt : + /* empty */ { WASM_ZERO_MEMORY($$); } + | VAR { DUPTEXT($$, $1); } +; + +action : + LPAR INVOKE script_var_opt quoted_text const_list RPAR { + WASM_ZERO_MEMORY($$); + $$.loc = @2; + $$.module_var_name = $3; + $$.type = WASM_ACTION_TYPE_INVOKE; + $$.invoke.name = $4; + $$.invoke.args = $5; + } + | LPAR GET script_var_opt TEXT RPAR { + WASM_ZERO_MEMORY($$); + $$.loc = @2; + $$.module_var_name = $3; + $$.type = WASM_ACTION_TYPE_GET; + $$.invoke.name = $4; + } +; + cmd : module { $$ = new_command(parser->allocator); @@ -1342,12 +1302,16 @@ cmd : $$->module = *$1; wasm_free(parser->allocator, $1); } - | LPAR INVOKE quoted_text const_list RPAR { + | action { $$ = new_command(parser->allocator); - $$->type = WASM_COMMAND_TYPE_INVOKE; - $$->invoke.loc = @2; - $$->invoke.name = $3; - $$->invoke.args = $4; + $$->type = WASM_COMMAND_TYPE_ACTION; + $$->action = $1; + } + | LPAR REGISTER quoted_text script_var_opt RPAR { + $$ = new_command(parser->allocator); + $$->type = WASM_COMMAND_TYPE_REGISTER; + $$->register_.module_name = $3; + $$->register_.module_var_name = $4; } | LPAR ASSERT_INVALID raw_module quoted_text RPAR { $$ = new_command(parser->allocator); @@ -1355,28 +1319,22 @@ cmd : $$->assert_invalid.module = $3; $$->assert_invalid.text = $4; } - | LPAR ASSERT_RETURN LPAR INVOKE quoted_text const_list RPAR const_opt RPAR { + | LPAR ASSERT_RETURN action const_list RPAR { $$ = new_command(parser->allocator); $$->type = WASM_COMMAND_TYPE_ASSERT_RETURN; - $$->assert_return.invoke.loc = @4; - $$->assert_return.invoke.name = $5; - $$->assert_return.invoke.args = $6; - $$->assert_return.expected = $8; + $$->assert_return.action = $3; + $$->assert_return.expected = $4; } - | LPAR ASSERT_RETURN_NAN LPAR INVOKE quoted_text const_list RPAR RPAR { + | LPAR ASSERT_RETURN_NAN action RPAR { $$ = new_command(parser->allocator); $$->type = WASM_COMMAND_TYPE_ASSERT_RETURN_NAN; - $$->assert_return_nan.invoke.loc = @4; - $$->assert_return_nan.invoke.name = $5; - $$->assert_return_nan.invoke.args = $6; + $$->assert_return_nan.action = $3; } - | LPAR ASSERT_TRAP LPAR INVOKE quoted_text const_list RPAR quoted_text RPAR { + | LPAR ASSERT_TRAP action quoted_text RPAR { $$ = new_command(parser->allocator); $$->type = WASM_COMMAND_TYPE_ASSERT_TRAP; - $$->assert_trap.invoke.loc = @4; - $$->assert_trap.invoke.name = $5; - $$->assert_trap.invoke.args = $6; - $$->assert_trap.text = $8; + $$->assert_trap.action = $3; + $$->assert_trap.text = $4; } ; cmd_list : @@ -1400,10 +1358,6 @@ const : wasm_free(parser->allocator, (char*)$3.text.start); } ; -const_opt : - /* empty */ { $$.type = WASM_TYPE_VOID; } - | const -; const_list : /* empty */ { WASM_ZERO_MEMORY($$); } | const_list const { @@ -1465,30 +1419,6 @@ static WasmExprList join_exprs2(WasmLocation* loc, WasmExprList* expr1, return result; } -static WasmExprList join_exprs3(WasmLocation* loc, WasmExprList* expr1, - WasmExprList* expr2, WasmExpr* expr3) { - WasmExprList result; - WASM_ZERO_MEMORY(result); - append_expr_list(&result, expr1); - append_expr_list(&result, expr2); - append_expr(&result, expr3); - expr3->loc = *loc; - return result; -} - -static WasmExprList join_exprs4(WasmLocation* loc, WasmExprList* expr1, - WasmExprList* expr2, WasmExprList* expr3, - WasmExpr* expr4) { - WasmExprList result; - WASM_ZERO_MEMORY(result); - append_expr_list(&result, expr1); - append_expr_list(&result, expr2); - append_expr_list(&result, expr3); - append_expr(&result, expr4); - expr4->loc = *loc; - return result; -} - static WasmResult parse_const(WasmType type, WasmLiteralType literal_type, const char* s, @@ -1589,7 +1519,7 @@ static void dup_text_list(WasmAllocator* allocator, } static WasmBool is_empty_signature(WasmFuncSignature* sig) { - return sig->result_type == WASM_TYPE_VOID && sig->param_types.size == 0; + return sig->result_types.size == 0 && sig->param_types.size == 0; } static void append_implicit_func_declaration(WasmAllocator* allocator, @@ -1612,15 +1542,6 @@ static void append_implicit_func_declaration(WasmAllocator* allocator, decl->flags |= WASM_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE; } -static WasmType get_result_type_from_type_vector(WasmTypeVector* types) { - /* TODO(binji): handle multiple result types more cleanly */ - switch (types->size) { - case 0: return WASM_TYPE_VOID; break; - case 1: return types->data[0]; break; - default: return WASM_TYPE_MULTIPLE; break; - } -} - WasmResult wasm_parse_ast(WasmAstLexer* lexer, struct WasmScript* out_script, WasmSourceErrorHandler* error_handler) { diff --git a/src/wasm-ast.c b/src/wasm-ast.c index 90ae402a..d1cbb660 100644 --- a/src/wasm-ast.c +++ b/src/wasm-ast.c @@ -191,10 +191,6 @@ int wasm_get_func_type_index_by_var(const WasmModule* module, return wasm_get_index_from_var(&module->func_type_bindings, var); } -int wasm_get_import_index_by_var(const WasmModule* module, const WasmVar* var) { - return wasm_get_index_from_var(&module->import_bindings, var); -} - int wasm_get_local_index_by_var(const WasmFunc* func, const WasmVar* var) { if (var->type == WASM_VAR_TYPE_INDEX) return (int)var->index; @@ -252,14 +248,6 @@ int wasm_get_func_type_index_by_decl(const WasmModule* module, } } -WasmImportPtr wasm_get_import_by_var(const WasmModule* module, - const WasmVar* var) { - int index = wasm_get_index_from_var(&module->import_bindings, var); - if (index < 0 || (size_t)index >= module->imports.size) - return NULL; - return module->imports.data[index]; -} - void wasm_make_type_binding_reverse_mapping( struct WasmAllocator* allocator, const WasmTypeVector* types, @@ -322,7 +310,6 @@ WasmFuncType* wasm_append_implicit_func_type(struct WasmAllocator* allocator, V(WASM_EXPR_TYPE_BR_IF, br_if, br_if) \ V(WASM_EXPR_TYPE_BR_TABLE, br_table, br_table) \ V(WASM_EXPR_TYPE_CALL, call, call) \ - V(WASM_EXPR_TYPE_CALL_IMPORT, call_import, call_import) \ V(WASM_EXPR_TYPE_CALL_INDIRECT, call_indirect, call_indirect) \ V(WASM_EXPR_TYPE_COMPARE, compare, compare) \ V(WASM_EXPR_TYPE_CONST, const, const_) \ @@ -330,7 +317,6 @@ WasmFuncType* wasm_append_implicit_func_type(struct WasmAllocator* allocator, V(WASM_EXPR_TYPE_GET_GLOBAL, get_global, get_global) \ V(WASM_EXPR_TYPE_GET_LOCAL, get_local, get_local) \ V(WASM_EXPR_TYPE_IF, if, if_) \ - V(WASM_EXPR_TYPE_IF_ELSE, if_else, if_else) \ V(WASM_EXPR_TYPE_LOAD, load, load) \ V(WASM_EXPR_TYPE_LOOP, loop, loop) \ V(WASM_EXPR_TYPE_SET_GLOBAL, set_global, set_global) \ @@ -414,6 +400,7 @@ void wasm_destroy_expr_list(WasmAllocator* allocator, WasmExpr* first) { void wasm_destroy_block(WasmAllocator* allocator, WasmBlock* block) { wasm_destroy_string_slice(allocator, &block->label); + wasm_destroy_type_vector(allocator, &block->sig); wasm_destroy_expr_list(allocator, block->first); } @@ -435,9 +422,6 @@ void wasm_destroy_expr(WasmAllocator* allocator, WasmExpr* expr) { case WASM_EXPR_TYPE_CALL: wasm_destroy_var(allocator, &expr->call.var); break; - case WASM_EXPR_TYPE_CALL_IMPORT: - wasm_destroy_var(allocator, &expr->call_import.var); - break; case WASM_EXPR_TYPE_CALL_INDIRECT: wasm_destroy_var(allocator, &expr->call_indirect.var); break; @@ -449,10 +433,7 @@ void wasm_destroy_expr(WasmAllocator* allocator, WasmExpr* expr) { break; case WASM_EXPR_TYPE_IF: wasm_destroy_block(allocator, &expr->if_.true_); - break; - case WASM_EXPR_TYPE_IF_ELSE: - wasm_destroy_block(allocator, &expr->if_else.true_); - wasm_destroy_block(allocator, &expr->if_else.false_); + wasm_destroy_expr_list(allocator, expr->if_.false_); break; case WASM_EXPR_TYPE_LOOP: wasm_destroy_block(allocator, &expr->loop); @@ -510,8 +491,21 @@ void wasm_destroy_global(WasmAllocator* allocator, WasmGlobal* global) { 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_func_declaration(allocator, &import->decl); + wasm_destroy_string_slice(allocator, &import->item_name); + switch (import->kind) { + case WASM_IMPORT_KIND_FUNC: + wasm_destroy_func(allocator, &import->func); + break; + case WASM_IMPORT_KIND_TABLE: + wasm_destroy_table(allocator, &import->table); + break; + case WASM_IMPORT_KIND_MEMORY: + wasm_destroy_memory(allocator, &import->memory); + break; + case WASM_IMPORT_KIND_GLOBAL: + wasm_destroy_global(allocator, &import->global); + break; + } } void wasm_destroy_export(WasmAllocator* allocator, WasmExport* export) { @@ -526,9 +520,19 @@ void wasm_destroy_func_type(WasmAllocator* allocator, WasmFuncType* func_type) { void wasm_destroy_data_segment(WasmAllocator* allocator, WasmDataSegment* data) { + wasm_destroy_var(allocator, &data->memory_var); + wasm_destroy_expr_list(allocator, data->offset); wasm_free(allocator, data->data); } +void wasm_destroy_memory(struct WasmAllocator* allocator, WasmMemory* memory) { + wasm_destroy_string_slice(allocator, &memory->name); +} + +void wasm_destroy_table(struct WasmAllocator* allocator, WasmTable* table) { + wasm_destroy_string_slice(allocator, &table->name); +} + static void destroy_module_field(WasmAllocator* allocator, WasmModuleField* field) { switch (field->type) { @@ -544,20 +548,17 @@ static void destroy_module_field(WasmAllocator* allocator, case WASM_MODULE_FIELD_TYPE_EXPORT: wasm_destroy_export(allocator, &field->export_); break; - case WASM_MODULE_FIELD_TYPE_EXPORT_MEMORY: - wasm_destroy_string_slice(allocator, &field->export_memory.name); - break; case WASM_MODULE_FIELD_TYPE_FUNC_TYPE: wasm_destroy_func_type(allocator, &field->func_type); break; case WASM_MODULE_FIELD_TYPE_TABLE: - /* nothing to destroy */ + wasm_destroy_table(allocator, &field->table); break; case WASM_MODULE_FIELD_TYPE_ELEM_SEGMENT: wasm_destroy_elem_segment(allocator, &field->elem_segment); break; case WASM_MODULE_FIELD_TYPE_MEMORY: - /* nothing to destroy */ + wasm_destroy_memory(allocator, &field->memory); break; case WASM_MODULE_FIELD_TYPE_DATA_SEGMENT: wasm_destroy_data_segment(allocator, &field->data_segment); @@ -580,17 +581,24 @@ void wasm_destroy_module(WasmAllocator* allocator, WasmModule* module) { /* everything that follows shares data with the module fields above, so we only need to destroy the containing vectors */ wasm_destroy_func_ptr_vector(allocator, &module->funcs); + wasm_destroy_global_ptr_vector(allocator, &module->globals); wasm_destroy_import_ptr_vector(allocator, &module->imports); wasm_destroy_export_ptr_vector(allocator, &module->exports); wasm_destroy_func_type_ptr_vector(allocator, &module->func_types); + wasm_destroy_table_ptr_vector(allocator, &module->tables); + wasm_destroy_memory_ptr_vector(allocator, &module->memories); wasm_destroy_binding_hash_entry_vector(allocator, &module->func_bindings.entries); wasm_destroy_binding_hash_entry_vector(allocator, - &module->import_bindings.entries); + &module->global_bindings.entries); wasm_destroy_binding_hash_entry_vector(allocator, &module->export_bindings.entries); wasm_destroy_binding_hash_entry_vector(allocator, &module->func_type_bindings.entries); + wasm_destroy_binding_hash_entry_vector(allocator, + &module->table_bindings.entries); + wasm_destroy_binding_hash_entry_vector(allocator, + &module->memory_bindings.entries); } void wasm_destroy_raw_module(WasmAllocator* allocator, WasmRawModule* raw) { @@ -598,14 +606,22 @@ void wasm_destroy_raw_module(WasmAllocator* allocator, WasmRawModule* raw) { wasm_destroy_module(allocator, raw->text); wasm_free(allocator, raw->text); } else { + wasm_destroy_string_slice(allocator, &raw->binary.name); wasm_free(allocator, raw->binary.data); } } -static void destroy_invoke(WasmAllocator* allocator, - WasmCommandInvoke* invoke) { - wasm_destroy_string_slice(allocator, &invoke->name); - wasm_destroy_const_vector(allocator, &invoke->args); +void wasm_destroy_action(WasmAllocator* allocator, WasmAction* action) { + wasm_destroy_string_slice(allocator, &action->module_var_name); + switch (action->type) { + case WASM_ACTION_TYPE_INVOKE: + wasm_destroy_string_slice(allocator, &action->invoke.name); + wasm_destroy_const_vector(allocator, &action->invoke.args); + break; + case WASM_ACTION_TYPE_GET: + wasm_destroy_string_slice(allocator, &action->get.name); + break; + } } void wasm_destroy_command(WasmAllocator* allocator, WasmCommand* command) { @@ -613,24 +629,28 @@ void wasm_destroy_command(WasmAllocator* allocator, WasmCommand* command) { case WASM_COMMAND_TYPE_MODULE: wasm_destroy_module(allocator, &command->module); break; - case WASM_COMMAND_TYPE_INVOKE: - destroy_invoke(allocator, &command->invoke); + case WASM_COMMAND_TYPE_ACTION: + wasm_destroy_action(allocator, &command->action); + break; + case WASM_COMMAND_TYPE_REGISTER: + wasm_destroy_string_slice(allocator, &command->register_.module_name); + wasm_destroy_string_slice(allocator, &command->register_.module_var_name); break; case WASM_COMMAND_TYPE_ASSERT_INVALID: wasm_destroy_raw_module(allocator, &command->assert_invalid.module); wasm_destroy_string_slice(allocator, &command->assert_invalid.text); break; case WASM_COMMAND_TYPE_ASSERT_RETURN: - destroy_invoke(allocator, &command->assert_return.invoke); + wasm_destroy_action(allocator, &command->assert_return.action); break; case WASM_COMMAND_TYPE_ASSERT_RETURN_NAN: - destroy_invoke(allocator, &command->assert_return_nan.invoke); + wasm_destroy_action(allocator, &command->assert_return_nan.action); break; case WASM_COMMAND_TYPE_ASSERT_TRAP: - destroy_invoke(allocator, &command->assert_trap.invoke); + wasm_destroy_action(allocator, &command->assert_trap.action); wasm_destroy_string_slice(allocator, &command->assert_trap.text); break; - default: + case WASM_NUM_COMMAND_TYPES: assert(0); break; } @@ -641,9 +661,11 @@ void wasm_destroy_command_vector_and_elements(WasmAllocator* allocator, WASM_DESTROY_VECTOR_AND_ELEMENTS(allocator, *commands, command); } -void wasm_destroy_elem_segment(WasmAllocator* allocator, WasmElemSegment* segment) { - wasm_destroy_expr_list(allocator, segment->offset); - WASM_DESTROY_VECTOR_AND_ELEMENTS(allocator, segment->vars, var); +void wasm_destroy_elem_segment(WasmAllocator* allocator, + WasmElemSegment* elem) { + wasm_destroy_var(allocator, &elem->table_var); + wasm_destroy_expr_list(allocator, elem->offset); + WASM_DESTROY_VECTOR_AND_ELEMENTS(allocator, elem->vars, var); } void wasm_destroy_script(WasmScript* script) { @@ -699,10 +721,6 @@ static WasmResult visit_expr(WasmExpr* expr, WasmExprVisitor* visitor) { CALLBACK(on_call_expr); break; - case WASM_EXPR_TYPE_CALL_IMPORT: - CALLBACK(on_call_import_expr); - break; - case WASM_EXPR_TYPE_CALL_INDIRECT: CALLBACK(on_call_indirect_expr); break; @@ -742,17 +760,11 @@ static WasmResult visit_expr(WasmExpr* expr, WasmExprVisitor* visitor) { case WASM_EXPR_TYPE_IF: CALLBACK(begin_if_expr); CHECK_RESULT(visit_expr_list(expr->if_.true_.first, visitor)); + CALLBACK(after_if_true_expr); + CHECK_RESULT(visit_expr_list(expr->if_.false_, visitor)); CALLBACK(end_if_expr); break; - case WASM_EXPR_TYPE_IF_ELSE: - CALLBACK(begin_if_else_expr); - CHECK_RESULT(visit_expr_list(expr->if_else.true_.first, visitor)); - CALLBACK(after_if_else_true_expr); - CHECK_RESULT(visit_expr_list(expr->if_else.false_.first, visitor)); - CALLBACK(end_if_else_expr); - break; - case WASM_EXPR_TYPE_LOAD: CALLBACK(on_load_expr); break; diff --git a/src/wasm-ast.h b/src/wasm-ast.h index 25d1a19c..6df0c15c 100644 --- a/src/wasm-ast.h +++ b/src/wasm-ast.h @@ -62,7 +62,6 @@ typedef enum WasmExprType { WASM_EXPR_TYPE_BR_IF, WASM_EXPR_TYPE_BR_TABLE, WASM_EXPR_TYPE_CALL, - WASM_EXPR_TYPE_CALL_IMPORT, WASM_EXPR_TYPE_CALL_INDIRECT, WASM_EXPR_TYPE_COMPARE, WASM_EXPR_TYPE_CONST, @@ -73,7 +72,6 @@ typedef enum WasmExprType { WASM_EXPR_TYPE_GET_LOCAL, WASM_EXPR_TYPE_GROW_MEMORY, WASM_EXPR_TYPE_IF, - WASM_EXPR_TYPE_IF_ELSE, WASM_EXPR_TYPE_LOAD, WASM_EXPR_TYPE_LOOP, WASM_EXPR_TYPE_NOP, @@ -105,8 +103,11 @@ typedef struct WasmBindingHash { WasmBindingHashEntry* free_head; } WasmBindingHash; +typedef WasmTypeVector WasmBlockSignature; + typedef struct WasmBlock { WasmLabel label; + WasmBlockSignature sig; struct WasmExpr* first; } WasmBlock; @@ -118,25 +119,20 @@ struct WasmExpr { union { struct { WasmOpcode opcode; } binary, compare, convert, unary; WasmBlock block, loop; - struct { WasmVar var; uint8_t arity; } br, br_if; - struct { - WasmVarVector targets; - WasmVar default_target; - uint8_t arity; - } br_table; - struct { WasmVar var; } call, call_import, call_indirect; + struct { WasmVar var; } br, br_if; + struct { WasmVarVector targets; WasmVar default_target; } br_table; + struct { WasmVar var; } call, call_indirect; WasmConst const_; struct { WasmVar var; } get_global, set_global; struct { WasmVar var; } get_local, set_local, tee_local; - struct { WasmBlock true_; } if_; - struct { WasmBlock true_, false_; } if_else; + struct { WasmBlock true_; struct WasmExpr* false_; } if_; struct { WasmOpcode opcode; uint32_t align; uint64_t offset; } load, store; }; }; typedef struct WasmFuncSignature { - WasmType result_type; WasmTypeVector param_types; + WasmTypeVector result_types; } WasmFuncSignature; typedef struct WasmFuncType { @@ -173,31 +169,12 @@ WASM_DEFINE_VECTOR(func_ptr, WasmFuncPtr); typedef struct WasmGlobal { WasmStringSlice name; WasmType type; + WasmBool mutable_; WasmExpr* init_expr; } WasmGlobal; typedef WasmGlobal* WasmGlobalPtr; WASM_DEFINE_VECTOR(global_ptr, WasmGlobalPtr); -typedef struct WasmImport { - WasmStringSlice name; - WasmStringSlice module_name; - WasmStringSlice func_name; - WasmFuncDeclaration decl; -} WasmImport; -typedef WasmImport* WasmImportPtr; -WASM_DEFINE_VECTOR(import_ptr, WasmImportPtr); - -typedef struct WasmExport { - WasmStringSlice name; - WasmVar var; -} WasmExport; -typedef WasmExport* WasmExportPtr; -WASM_DEFINE_VECTOR(export_ptr, WasmExportPtr); - -typedef struct WasmExportMemory { - WasmStringSlice name; -} WasmExportMemory; - typedef struct WasmLimits { uint64_t initial; uint64_t max; @@ -205,10 +182,14 @@ typedef struct WasmLimits { } WasmLimits; typedef struct WasmTable { + WasmStringSlice name; WasmLimits elem_limits; } WasmTable; +typedef WasmTable* WasmTablePtr; +WASM_DEFINE_VECTOR(table_ptr, WasmTablePtr); typedef struct WasmElemSegment { + WasmVar table_var; WasmExpr* offset; WasmVarVector vars; } WasmElemSegment; @@ -216,10 +197,14 @@ typedef WasmElemSegment* WasmElemSegmentPtr; WASM_DEFINE_VECTOR(elem_segment_ptr, WasmElemSegmentPtr); typedef struct WasmMemory { + WasmStringSlice name; WasmLimits page_limits; } WasmMemory; +typedef WasmMemory* WasmMemoryPtr; +WASM_DEFINE_VECTOR(memory_ptr, WasmMemoryPtr); typedef struct WasmDataSegment { + WasmVar memory_var; WasmExpr* offset; void* data; size_t size; @@ -227,12 +212,51 @@ typedef struct WasmDataSegment { typedef WasmDataSegment* WasmDataSegmentPtr; WASM_DEFINE_VECTOR(data_segment_ptr, WasmDataSegmentPtr); +typedef enum WasmImportKind { + WASM_IMPORT_KIND_FUNC, + WASM_IMPORT_KIND_TABLE, + WASM_IMPORT_KIND_MEMORY, + WASM_IMPORT_KIND_GLOBAL, +} WasmImportKind; + +typedef struct WasmImport { + WasmStringSlice name; + WasmStringSlice module_name; + WasmStringSlice item_name; + WasmImportKind kind; + union { + /* an imported func is has the type WasmFunc so it can be more easily + * included in the Module's vector of funcs; but only the + * WasmFuncDeclaration will have any useful information */ + WasmFunc func; + WasmTable table; + WasmMemory memory; + WasmGlobal global; + }; +} WasmImport; +typedef WasmImport* WasmImportPtr; +WASM_DEFINE_VECTOR(import_ptr, WasmImportPtr); + +typedef enum WasmExportKind { + WASM_EXPORT_KIND_FUNC, + WASM_EXPORT_KIND_TABLE, + WASM_EXPORT_KIND_MEMORY, + WASM_EXPORT_KIND_GLOBAL, +} WasmExportKind; + +typedef struct WasmExport { + WasmStringSlice name; + WasmExportKind kind; + WasmVar var; +} WasmExport; +typedef WasmExport* WasmExportPtr; +WASM_DEFINE_VECTOR(export_ptr, WasmExportPtr); + typedef enum WasmModuleFieldType { WASM_MODULE_FIELD_TYPE_FUNC, WASM_MODULE_FIELD_TYPE_GLOBAL, WASM_MODULE_FIELD_TYPE_IMPORT, WASM_MODULE_FIELD_TYPE_EXPORT, - WASM_MODULE_FIELD_TYPE_EXPORT_MEMORY, WASM_MODULE_FIELD_TYPE_FUNC_TYPE, WASM_MODULE_FIELD_TYPE_TABLE, WASM_MODULE_FIELD_TYPE_ELEM_SEGMENT, @@ -250,7 +274,6 @@ typedef struct WasmModuleField { WasmGlobal global; WasmImport import; WasmExport export_; - WasmExportMemory export_memory; WasmFuncType func_type; WasmTable table; WasmElemSegment elem_segment; @@ -261,27 +284,29 @@ typedef struct WasmModuleField { } WasmModuleField; typedef struct WasmModule { + WasmStringSlice name; WasmModuleField* first_field; WasmModuleField* last_field; - /* cached for convenience */ + /* cached for convenience; the pointers are shared with values that are + * stored in either WasmModuleField or WasmImport. */ WasmFuncPtrVector funcs; WasmGlobalPtrVector globals; WasmImportPtrVector imports; WasmExportPtrVector exports; WasmFuncTypePtrVector func_types; - WasmTable* table; + WasmTablePtrVector tables; WasmElemSegmentPtrVector elem_segments; - WasmMemory* memory; + WasmMemoryPtrVector memories; WasmDataSegmentPtrVector data_segments; WasmVar* start; - WasmExportMemory* export_memory; WasmBindingHash func_bindings; WasmBindingHash global_bindings; - WasmBindingHash import_bindings; WasmBindingHash export_bindings; WasmBindingHash func_type_bindings; + WasmBindingHash table_bindings; + WasmBindingHash memory_bindings; } WasmModule; typedef enum WasmRawModuleType { @@ -300,15 +325,41 @@ typedef struct WasmRawModule { union { WasmModule* text; struct { + WasmStringSlice name; void* data; size_t size; } binary; }; } WasmRawModule; +typedef enum WasmActionType { + WASM_ACTION_TYPE_INVOKE, + WASM_ACTION_TYPE_GET, +} WasmActionType; + +typedef struct WasmActionInvoke { + WasmStringSlice name; + WasmConstVector args; +} WasmActionInvoke; + +typedef struct WasmActionGet { + WasmStringSlice name; +} WasmActionGet; + +typedef struct WasmAction { + WasmLocation loc; + WasmActionType type; + WasmStringSlice module_var_name; + union { + WasmActionInvoke invoke; + WasmActionGet get; + }; +} WasmAction; + typedef enum WasmCommandType { WASM_COMMAND_TYPE_MODULE, - WASM_COMMAND_TYPE_INVOKE, + WASM_COMMAND_TYPE_ACTION, + WASM_COMMAND_TYPE_REGISTER, WASM_COMMAND_TYPE_ASSERT_INVALID, WASM_COMMAND_TYPE_ASSERT_RETURN, WASM_COMMAND_TYPE_ASSERT_RETURN_NAN, @@ -316,20 +367,15 @@ typedef enum WasmCommandType { WASM_NUM_COMMAND_TYPES, } WasmCommandType; -typedef struct WasmCommandInvoke { - WasmLocation loc; - WasmStringSlice name; - WasmConstVector args; -} WasmCommandInvoke; - typedef struct WasmCommand { WasmCommandType type; union { WasmModule module; - WasmCommandInvoke invoke; - struct { WasmCommandInvoke invoke; WasmConst expected; } assert_return; - struct { WasmCommandInvoke invoke; } assert_return_nan; - struct { WasmCommandInvoke invoke; WasmStringSlice text; } assert_trap; + WasmAction action; + struct { WasmStringSlice module_name, module_var_name; } register_; + struct { WasmAction action; WasmConstVector expected; } assert_return; + struct { WasmAction action; } assert_return_nan; + struct { WasmAction action; WasmStringSlice text; } assert_trap; struct { WasmRawModule module; WasmStringSlice text; } assert_invalid; }; } WasmCommand; @@ -349,7 +395,6 @@ typedef struct WasmExprVisitor { WasmResult (*on_br_if_expr)(WasmExpr*, void* user_data); WasmResult (*on_br_table_expr)(WasmExpr*, void* user_data); WasmResult (*on_call_expr)(WasmExpr*, void* user_data); - WasmResult (*on_call_import_expr)(WasmExpr*, void* user_data); WasmResult (*on_call_indirect_expr)(WasmExpr*, void* user_data); WasmResult (*on_compare_expr)(WasmExpr*, void* user_data); WasmResult (*on_const_expr)(WasmExpr*, void* user_data); @@ -360,10 +405,8 @@ typedef struct WasmExprVisitor { WasmResult (*on_get_local_expr)(WasmExpr*, void* user_data); WasmResult (*on_grow_memory_expr)(WasmExpr*, void* user_data); WasmResult (*begin_if_expr)(WasmExpr*, void* user_data); + WasmResult (*after_if_true_expr)(WasmExpr*, void* user_data); WasmResult (*end_if_expr)(WasmExpr*, void* user_data); - WasmResult (*begin_if_else_expr)(WasmExpr*, void* user_data); - WasmResult (*after_if_else_true_expr)(WasmExpr*, void* user_data); - WasmResult (*end_if_else_expr)(WasmExpr*, void* user_data); WasmResult (*on_load_expr)(WasmExpr*, void* user_data); WasmResult (*begin_loop_expr)(WasmExpr*, void* user_data); WasmResult (*end_loop_expr)(WasmExpr*, void* user_data); @@ -382,6 +425,7 @@ WASM_EXTERN_C_BEGIN WasmBinding* wasm_insert_binding(struct WasmAllocator*, WasmBindingHash*, const WasmStringSlice*); + WasmBool wasm_hash_entry_is_free(const WasmBindingHashEntry*); WasmModuleField* wasm_append_module_field(struct WasmAllocator*, WasmModule*); @@ -398,7 +442,6 @@ WasmExpr* wasm_new_br_expr(struct WasmAllocator*); WasmExpr* wasm_new_br_if_expr(struct WasmAllocator*); WasmExpr* wasm_new_br_table_expr(struct WasmAllocator*); WasmExpr* wasm_new_call_expr(struct WasmAllocator*); -WasmExpr* wasm_new_call_import_expr(struct WasmAllocator*); WasmExpr* wasm_new_call_indirect_expr(struct WasmAllocator*); WasmExpr* wasm_new_compare_expr(struct WasmAllocator*); WasmExpr* wasm_new_const_expr(struct WasmAllocator*); @@ -409,7 +452,6 @@ WasmExpr* wasm_new_get_global_expr(struct WasmAllocator*); WasmExpr* wasm_new_get_local_expr(struct WasmAllocator*); WasmExpr* wasm_new_grow_memory_expr(struct WasmAllocator*); WasmExpr* wasm_new_if_expr(struct WasmAllocator*); -WasmExpr* wasm_new_if_else_expr(struct WasmAllocator*); WasmExpr* wasm_new_load_expr(struct WasmAllocator*); WasmExpr* wasm_new_loop_expr(struct WasmAllocator*); WasmExpr* wasm_new_nop_expr(struct WasmAllocator*); @@ -425,10 +467,12 @@ WasmExpr* wasm_new_unreachable_expr(struct WasmAllocator*); /* destruction functions. not needed unless you're creating your own AST elements */ void wasm_destroy_script(struct WasmScript*); +void wasm_destroy_action(struct WasmAllocator*, struct WasmAction*); void wasm_destroy_block(struct WasmAllocator*, struct WasmBlock*); void wasm_destroy_command_vector_and_elements(struct WasmAllocator*, WasmCommandVector*); void wasm_destroy_command(struct WasmAllocator*, WasmCommand*); +void wasm_destroy_data_segment(struct WasmAllocator*, WasmDataSegment*); void wasm_destroy_elem_segment(struct WasmAllocator*, WasmElemSegment*); void wasm_destroy_export(struct WasmAllocator*, WasmExport*); void wasm_destroy_expr(struct WasmAllocator*, WasmExpr*); @@ -438,9 +482,10 @@ void wasm_destroy_func_signature(struct WasmAllocator*, WasmFuncSignature*); void wasm_destroy_func_type(struct WasmAllocator*, WasmFuncType*); void wasm_destroy_func(struct WasmAllocator*, WasmFunc*); void wasm_destroy_import(struct WasmAllocator*, WasmImport*); -void wasm_destroy_data_segment(struct WasmAllocator*, WasmDataSegment*); +void wasm_destroy_memory(struct WasmAllocator*, WasmMemory*); void wasm_destroy_module(struct WasmAllocator*, WasmModule*); void wasm_destroy_raw_module(struct WasmAllocator*, WasmRawModule*); +void wasm_destroy_table(struct WasmAllocator*, WasmTable*); void wasm_destroy_var_vector_and_elements(struct WasmAllocator*, WasmVarVector*); void wasm_destroy_var(struct WasmAllocator*, WasmVar*); @@ -485,36 +530,42 @@ wasm_decl_has_func_type(const WasmFuncDeclaration* decl) { } static WASM_INLINE WasmBool -wasm_signatures_are_equal(const WasmFuncSignature* sig1, - const WasmFuncSignature* sig2) { - if (sig1->result_type != sig2->result_type) - return WASM_FALSE; - if (sig1->param_types.size != sig2->param_types.size) +wasm_type_vectors_are_equal(const WasmTypeVector* types1, + const WasmTypeVector* types2) { + if (types1->size != types2->size) return WASM_FALSE; size_t i; - for (i = 0; i < sig1->param_types.size; ++i) { - if (sig1->param_types.data[i] != sig2->param_types.data[i]) + for (i = 0; i < types1->size; ++i) { + if (types1->data[i] != types2->data[i]) return WASM_FALSE; } return WASM_TRUE; } -static WASM_INLINE size_t wasm_get_num_params(const WasmModule* module, - const WasmFunc* func) { +static WASM_INLINE WasmBool +wasm_signatures_are_equal(const WasmFuncSignature* sig1, + const WasmFuncSignature* sig2) { + return wasm_type_vectors_are_equal(&sig1->param_types, &sig2->param_types) && + wasm_type_vectors_are_equal(&sig1->result_types, &sig2->result_types); +} + +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_results(const WasmFunc* func) { + return func->decl.sig.result_types.size; +} + static WASM_INLINE size_t wasm_get_num_locals(const WasmFunc* func) { return func->local_types.size; } -static WASM_INLINE size_t -wasm_get_num_params_and_locals(const WasmModule* module, const WasmFunc* func) { - return wasm_get_num_params(module, func) + wasm_get_num_locals(func); +static WASM_INLINE size_t wasm_get_num_params_and_locals(const WasmFunc* func) { + return wasm_get_num_params(func) + wasm_get_num_locals(func); } -static WASM_INLINE WasmType wasm_get_param_type(const WasmModule* module, - const WasmFunc* func, +static WASM_INLINE WasmType wasm_get_param_type(const WasmFunc* func, int index) { assert((size_t)index < func->decl.sig.param_types.size); return func->decl.sig.param_types.data[index]; @@ -526,14 +577,10 @@ static WASM_INLINE WasmType wasm_get_local_type(const WasmFunc* func, return func->local_types.data[index]; } -static WASM_INLINE WasmType wasm_get_result_type(const WasmModule* module, - 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_result_type(const WasmFunc* func, + int index) { + assert((size_t)index < func->decl.sig.result_types.size); + return func->decl.sig.result_types.data[index]; } static WASM_INLINE WasmType @@ -546,6 +593,16 @@ wasm_get_func_type_num_params(const WasmFuncType* func_type) { return func_type->sig.param_types.size; } +static WASM_INLINE WasmType +wasm_get_func_type_result_type(const WasmFuncType* func_type, int index) { + return func_type->sig.result_types.data[index]; +} + +static WASM_INLINE size_t +wasm_get_func_type_num_results(const WasmFuncType* func_type) { + return func_type->sig.result_types.size; +} + WASM_EXTERN_C_END #endif /* WASM_AST_H_ */ |