authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-09 21:17:05-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-09 21:17:05-04:00
log774b6ffe1e0577a2d1a32b04d71c86525627748a
tree27215adb7bc1552eb9b6a28b5854476f4187f74a
parent403e5239e3668f626ac105fbfbb08456b859963a

fix parser performance regression


2 files changed, 660 insertions(+), 662 deletions(-)

std/zig/parse.zig+327-328
......@@ -1,6 +1,5 @@
11const std = @import("../index.zig");
22const assert = std.debug.assert;
3const SegmentedList = std.SegmentedList;
43const mem = std.mem;
54const ast = std.zig.ast;
65const Tokenizer = std.zig.Tokenizer;
......@@ -15,7 +14,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
1514 var tree_arena = std.heap.ArenaAllocator.init(allocator);
1615 errdefer tree_arena.deinit();
1716
18 var stack = SegmentedList(State, 32).init(allocator);
17 var stack = std.ArrayList(State).init(allocator);
1918 defer stack.deinit();
2019
2120 const arena = &tree_arena.allocator;
......@@ -46,11 +45,11 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
4645 }
4746 var tok_it = tree.tokens.iterator(0);
4847
49 try stack.push(State.TopLevel);
48 try stack.append(State.TopLevel);
5049
5150 while (true) {
5251 // This gives us 1 free push that can't fail
53 const state = ??stack.pop();
52 const state = stack.pop();
5453
5554 switch (state) {
5655 State.TopLevel => {
......@@ -65,7 +64,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
6564 const token_ptr = token.ptr;
6665 switch (token_ptr.id) {
6766 Token.Id.Keyword_test => {
68 stack.push(State.TopLevel) catch unreachable;
67 stack.append(State.TopLevel) catch unreachable;
6968
7069 const block = try arena.construct(ast.Node.Block {
7170 .base = ast.Node {
......@@ -86,14 +85,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
8685 .body_node = &block.base,
8786 });
8887 try root_node.decls.push(&test_node.base);
89 try stack.push(State { .Block = block });
90 try stack.push(State {
88 try stack.append(State { .Block = block });
89 try stack.append(State {
9190 .ExpectTokenSave = ExpectTokenSave {
9291 .id = Token.Id.LBrace,
9392 .ptr = &block.rbrace,
9493 }
9594 });
96 try stack.push(State { .StringLiteral = OptionalCtx { .Required = &test_node.name } });
95 try stack.append(State { .StringLiteral = OptionalCtx { .Required = &test_node.name } });
9796 continue;
9897 },
9998 Token.Id.Eof => {
......@@ -102,8 +101,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
102101 return tree;
103102 },
104103 Token.Id.Keyword_pub => {
105 stack.push(State.TopLevel) catch unreachable;
106 try stack.push(State {
104 stack.append(State.TopLevel) catch unreachable;
105 try stack.append(State {
107106 .TopLevelExtern = TopLevelDeclCtx {
108107 .decls = &root_node.decls,
109108 .visib_token = token_index,
......@@ -134,9 +133,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
134133 });
135134 try root_node.decls.push(&node.base);
136135
137 stack.push(State.TopLevel) catch unreachable;
138 try stack.push(State { .Block = block });
139 try stack.push(State {
136 stack.append(State.TopLevel) catch unreachable;
137 try stack.append(State { .Block = block });
138 try stack.append(State {
140139 .ExpectTokenSave = ExpectTokenSave {
141140 .id = Token.Id.LBrace,
142141 .ptr = &block.rbrace,
......@@ -146,8 +145,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
146145 },
147146 else => {
148147 putBackToken(&tok_it, &tree);
149 stack.push(State.TopLevel) catch unreachable;
150 try stack.push(State {
148 stack.append(State.TopLevel) catch unreachable;
149 try stack.append(State {
151150 .TopLevelExtern = TopLevelDeclCtx {
152151 .decls = &root_node.decls,
153152 .visib_token = null,
......@@ -166,7 +165,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
166165 const token_ptr = token.ptr;
167166 switch (token_ptr.id) {
168167 Token.Id.Keyword_export, Token.Id.Keyword_inline => {
169 stack.push(State {
168 stack.append(State {
170169 .TopLevelDecl = TopLevelDeclCtx {
171170 .decls = ctx.decls,
172171 .visib_token = ctx.visib_token,
......@@ -181,7 +180,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
181180 continue;
182181 },
183182 Token.Id.Keyword_extern => {
184 stack.push(State {
183 stack.append(State {
185184 .TopLevelLibname = TopLevelDeclCtx {
186185 .decls = ctx.decls,
187186 .visib_token = ctx.visib_token,
......@@ -197,7 +196,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
197196 },
198197 else => {
199198 putBackToken(&tok_it, &tree);
200 stack.push(State { .TopLevelDecl = ctx }) catch unreachable;
199 stack.append(State { .TopLevelDecl = ctx }) catch unreachable;
201200 continue;
202201 }
203202 }
......@@ -213,7 +212,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
213212 };
214213 };
215214
216 stack.push(State {
215 stack.append(State {
217216 .TopLevelDecl = TopLevelDeclCtx {
218217 .decls = ctx.decls,
219218 .visib_token = ctx.visib_token,
......@@ -246,13 +245,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
246245 });
247246 try ctx.decls.push(&node.base);
248247
249 stack.push(State {
248 stack.append(State {
250249 .ExpectTokenSave = ExpectTokenSave {
251250 .id = Token.Id.Semicolon,
252251 .ptr = &node.semicolon_token,
253252 }
254253 }) catch unreachable;
255 try stack.push(State { .Expression = OptionalCtx { .Required = &node.expr } });
254 try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } });
256255 continue;
257256 },
258257 Token.Id.Keyword_var, Token.Id.Keyword_const => {
......@@ -265,7 +264,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
265264 }
266265 }
267266
268 try stack.push(State {
267 try stack.append(State {
269268 .VarDecl = VarDeclCtx {
270269 .comments = ctx.comments,
271270 .visib_token = ctx.visib_token,
......@@ -299,13 +298,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
299298 .align_expr = null,
300299 });
301300 try ctx.decls.push(&fn_proto.base);
302 stack.push(State { .FnDef = fn_proto }) catch unreachable;
303 try stack.push(State { .FnProto = fn_proto });
301 stack.append(State { .FnDef = fn_proto }) catch unreachable;
302 try stack.append(State { .FnProto = fn_proto });
304303
305304 switch (token_ptr.id) {
306305 Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => {
307306 fn_proto.cc_token = token_index;
308 try stack.push(State {
307 try stack.append(State {
309308 .ExpectTokenSave = ExpectTokenSave {
310309 .id = Token.Id.Keyword_fn,
311310 .ptr = &fn_proto.fn_token,
......@@ -324,13 +323,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
324323 );
325324 fn_proto.async_attr = async_node;
326325
327 try stack.push(State {
326 try stack.append(State {
328327 .ExpectTokenSave = ExpectTokenSave {
329328 .id = Token.Id.Keyword_fn,
330329 .ptr = &fn_proto.fn_token,
331330 }
332331 });
333 try stack.push(State { .AsyncAllocator = async_node });
332 try stack.append(State { .AsyncAllocator = async_node });
334333 continue;
335334 },
336335 Token.Id.Keyword_fn => {
......@@ -363,14 +362,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
363362 const node_ptr = try ctx.container_decl.fields_and_decls.addOne();
364363 *node_ptr = &node.base;
365364
366 stack.push(State { .FieldListCommaOrEnd = ctx.container_decl }) catch unreachable;
367 try stack.push(State { .Expression = OptionalCtx { .Required = &node.type_expr } });
368 try stack.push(State { .ExpectToken = Token.Id.Colon });
365 stack.append(State { .FieldListCommaOrEnd = ctx.container_decl }) catch unreachable;
366 try stack.append(State { .Expression = OptionalCtx { .Required = &node.type_expr } });
367 try stack.append(State { .ExpectToken = Token.Id.Colon });
369368 continue;
370369 }
371370
372 stack.push(State{ .ContainerDecl = ctx.container_decl }) catch unreachable;
373 try stack.push(State {
371 stack.append(State{ .ContainerDecl = ctx.container_decl }) catch unreachable;
372 try stack.append(State {
374373 .TopLevelExtern = TopLevelDeclCtx {
375374 .decls = &ctx.container_decl.fields_and_decls,
376375 .visib_token = ctx.visib_token,
......@@ -390,7 +389,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
390389 putBackToken(&tok_it, &tree);
391390 continue;
392391 }
393 stack.push(State { .Expression = ctx }) catch unreachable;
392 stack.append(State { .Expression = ctx }) catch unreachable;
394393 continue;
395394 },
396395
......@@ -420,9 +419,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
420419 }
421420 );
422421
423 stack.push(State { .ContainerDecl = node }) catch unreachable;
424 try stack.push(State { .ExpectToken = Token.Id.LBrace });
425 try stack.push(State { .ContainerInitArgStart = node });
422 stack.append(State { .ContainerDecl = node }) catch unreachable;
423 try stack.append(State { .ExpectToken = Token.Id.LBrace });
424 try stack.append(State { .ContainerInitArgStart = node });
426425 continue;
427426 },
428427
......@@ -431,8 +430,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
431430 continue;
432431 }
433432
434 stack.push(State { .ExpectToken = Token.Id.RParen }) catch unreachable;
435 try stack.push(State { .ContainerInitArg = container_decl });
433 stack.append(State { .ExpectToken = Token.Id.RParen }) catch unreachable;
434 try stack.append(State { .ContainerInitArg = container_decl });
436435 continue;
437436 },
438437
......@@ -447,8 +446,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
447446 const lparen_tok_index = lparen_tok.index;
448447 const lparen_tok_ptr = lparen_tok.ptr;
449448 if (lparen_tok_ptr.id == Token.Id.LParen) {
450 try stack.push(State { .ExpectToken = Token.Id.RParen } );
451 try stack.push(State { .Expression = OptionalCtx {
449 try stack.append(State { .ExpectToken = Token.Id.RParen } );
450 try stack.append(State { .Expression = OptionalCtx {
452451 .RequiredNull = &container_decl.init_arg_expr.Enum,
453452 } });
454453 } else {
......@@ -458,7 +457,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
458457 else => {
459458 putBackToken(&tok_it, &tree);
460459 container_decl.init_arg_expr = ast.Node.ContainerDecl.InitArg { .Type = undefined };
461 stack.push(State { .Expression = OptionalCtx { .Required = &container_decl.init_arg_expr.Type } }) catch unreachable;
460 stack.append(State { .Expression = OptionalCtx { .Required = &container_decl.init_arg_expr.Type } }) catch unreachable;
462461 },
463462 }
464463 continue;
......@@ -489,9 +488,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
489488 const node_ptr = try container_decl.fields_and_decls.addOne();
490489 *node_ptr = &node.base;
491490
492 try stack.push(State { .FieldListCommaOrEnd = container_decl });
493 try stack.push(State { .TypeExprBegin = OptionalCtx { .Required = &node.type_expr } });
494 try stack.push(State { .ExpectToken = Token.Id.Colon });
491 try stack.append(State { .FieldListCommaOrEnd = container_decl });
492 try stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &node.type_expr } });
493 try stack.append(State { .ExpectToken = Token.Id.Colon });
495494 continue;
496495 },
497496 ast.Node.ContainerDecl.Kind.Union => {
......@@ -504,10 +503,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
504503 });
505504 try container_decl.fields_and_decls.push(&node.base);
506505
507 stack.push(State { .FieldListCommaOrEnd = container_decl }) catch unreachable;
508 try stack.push(State { .FieldInitValue = OptionalCtx { .RequiredNull = &node.value_expr } });
509 try stack.push(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &node.type_expr } });
510 try stack.push(State { .IfToken = Token.Id.Colon });
506 stack.append(State { .FieldListCommaOrEnd = container_decl }) catch unreachable;
507 try stack.append(State { .FieldInitValue = OptionalCtx { .RequiredNull = &node.value_expr } });
508 try stack.append(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &node.type_expr } });
509 try stack.append(State { .IfToken = Token.Id.Colon });
511510 continue;
512511 },
513512 ast.Node.ContainerDecl.Kind.Enum => {
......@@ -519,9 +518,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
519518 });
520519 try container_decl.fields_and_decls.push(&node.base);
521520
522 stack.push(State { .FieldListCommaOrEnd = container_decl }) catch unreachable;
523 try stack.push(State { .Expression = OptionalCtx { .RequiredNull = &node.value } });
524 try stack.push(State { .IfToken = Token.Id.Equal });
521 stack.append(State { .FieldListCommaOrEnd = container_decl }) catch unreachable;
522 try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &node.value } });
523 try stack.append(State { .IfToken = Token.Id.Equal });
525524 continue;
526525 },
527526 }
......@@ -529,7 +528,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
529528 Token.Id.Keyword_pub => {
530529 switch (container_decl.kind) {
531530 ast.Node.ContainerDecl.Kind.Struct => {
532 try stack.push(State {
531 try stack.append(State {
533532 .TopLevelExternOrField = TopLevelExternOrFieldCtx {
534533 .visib_token = token_index,
535534 .container_decl = container_decl,
......@@ -539,8 +538,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
539538 continue;
540539 },
541540 else => {
542 stack.push(State{ .ContainerDecl = container_decl }) catch unreachable;
543 try stack.push(State {
541 stack.append(State{ .ContainerDecl = container_decl }) catch unreachable;
542 try stack.append(State {
544543 .TopLevelExtern = TopLevelDeclCtx {
545544 .decls = &container_decl.fields_and_decls,
546545 .visib_token = token_index,
......@@ -554,8 +553,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
554553 }
555554 },
556555 Token.Id.Keyword_export => {
557 stack.push(State{ .ContainerDecl = container_decl }) catch unreachable;
558 try stack.push(State {
556 stack.append(State{ .ContainerDecl = container_decl }) catch unreachable;
557 try stack.append(State {
559558 .TopLevelExtern = TopLevelDeclCtx {
560559 .decls = &container_decl.fields_and_decls,
561560 .visib_token = token_index,
......@@ -578,8 +577,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
578577 },
579578 else => {
580579 putBackToken(&tok_it, &tree);
581 stack.push(State{ .ContainerDecl = container_decl }) catch unreachable;
582 try stack.push(State {
580 stack.append(State{ .ContainerDecl = container_decl }) catch unreachable;
581 try stack.append(State {
583582 .TopLevelExtern = TopLevelDeclCtx {
584583 .decls = &container_decl.fields_and_decls,
585584 .visib_token = null,
......@@ -615,10 +614,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
615614 });
616615 try ctx.list.push(&var_decl.base);
617616
618 try stack.push(State { .VarDeclAlign = var_decl });
619 try stack.push(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &var_decl.type_node} });
620 try stack.push(State { .IfToken = Token.Id.Colon });
621 try stack.push(State {
617 try stack.append(State { .VarDeclAlign = var_decl });
618 try stack.append(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &var_decl.type_node} });
619 try stack.append(State { .IfToken = Token.Id.Colon });
620 try stack.append(State {
622621 .ExpectTokenSave = ExpectTokenSave {
623622 .id = Token.Id.Identifier,
624623 .ptr = &var_decl.name_token,
......@@ -627,15 +626,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
627626 continue;
628627 },
629628 State.VarDeclAlign => |var_decl| {
630 try stack.push(State { .VarDeclEq = var_decl });
629 try stack.append(State { .VarDeclEq = var_decl });
631630
632631 const next_token = nextToken(&tok_it, &tree);
633632 const next_token_index = next_token.index;
634633 const next_token_ptr = next_token.ptr;
635634 if (next_token_ptr.id == Token.Id.Keyword_align) {
636 try stack.push(State { .ExpectToken = Token.Id.RParen });
637 try stack.push(State { .Expression = OptionalCtx { .RequiredNull = &var_decl.align_node} });
638 try stack.push(State { .ExpectToken = Token.Id.LParen });
635 try stack.append(State { .ExpectToken = Token.Id.RParen });
636 try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &var_decl.align_node} });
637 try stack.append(State { .ExpectToken = Token.Id.LParen });
639638 continue;
640639 }
641640
......@@ -649,13 +648,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
649648 switch (token_ptr.id) {
650649 Token.Id.Equal => {
651650 var_decl.eq_token = token_index;
652 stack.push(State {
651 stack.append(State {
653652 .ExpectTokenSave = ExpectTokenSave {
654653 .id = Token.Id.Semicolon,
655654 .ptr = &var_decl.semicolon_token,
656655 },
657656 }) catch unreachable;
658 try stack.push(State { .Expression = OptionalCtx { .RequiredNull = &var_decl.init_node } });
657 try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &var_decl.init_node } });
659658 continue;
660659 },
661660 Token.Id.Semicolon => {
......@@ -686,7 +685,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
686685 .rbrace = undefined,
687686 });
688687 fn_proto.body_node = &block.base;
689 stack.push(State { .Block = block }) catch unreachable;
688 stack.append(State { .Block = block }) catch unreachable;
690689 continue;
691690 },
692691 Token.Id.Semicolon => continue,
......@@ -699,9 +698,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
699698 }
700699 },
701700 State.FnProto => |fn_proto| {
702 stack.push(State { .FnProtoAlign = fn_proto }) catch unreachable;
703 try stack.push(State { .ParamDecl = fn_proto });
704 try stack.push(State { .ExpectToken = Token.Id.LParen });
701 stack.append(State { .FnProtoAlign = fn_proto }) catch unreachable;
702 try stack.append(State { .ParamDecl = fn_proto });
703 try stack.append(State { .ExpectToken = Token.Id.LParen });
705704
706705 if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |name_token| {
707706 fn_proto.name_token = name_token;
......@@ -709,12 +708,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
709708 continue;
710709 },
711710 State.FnProtoAlign => |fn_proto| {
712 stack.push(State { .FnProtoReturnType = fn_proto }) catch unreachable;
711 stack.append(State { .FnProtoReturnType = fn_proto }) catch unreachable;
713712
714713 if (eatToken(&tok_it, &tree, Token.Id.Keyword_align)) |align_token| {
715 try stack.push(State { .ExpectToken = Token.Id.RParen });
716 try stack.push(State { .Expression = OptionalCtx { .RequiredNull = &fn_proto.align_expr } });
717 try stack.push(State { .ExpectToken = Token.Id.LParen });
714 try stack.append(State { .ExpectToken = Token.Id.RParen });
715 try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &fn_proto.align_expr } });
716 try stack.append(State { .ExpectToken = Token.Id.LParen });
718717 }
719718 continue;
720719 },
......@@ -725,7 +724,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
725724 switch (token_ptr.id) {
726725 Token.Id.Bang => {
727726 fn_proto.return_type = ast.Node.FnProto.ReturnType { .InferErrorSet = undefined };
728 stack.push(State {
727 stack.append(State {
729728 .TypeExprBegin = OptionalCtx { .Required = &fn_proto.return_type.InferErrorSet },
730729 }) catch unreachable;
731730 continue;
......@@ -747,7 +746,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
747746
748747 putBackToken(&tok_it, &tree);
749748 fn_proto.return_type = ast.Node.FnProto.ReturnType { .Explicit = undefined };
750 stack.push(State { .TypeExprBegin = OptionalCtx { .Required = &fn_proto.return_type.Explicit }, }) catch unreachable;
749 stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &fn_proto.return_type.Explicit }, }) catch unreachable;
751750 continue;
752751 },
753752 }
......@@ -768,14 +767,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
768767 });
769768 try fn_proto.params.push(&param_decl.base);
770769
771 stack.push(State {
770 stack.append(State {
772771 .ParamDeclEnd = ParamDeclEndCtx {
773772 .param_decl = param_decl,
774773 .fn_proto = fn_proto,
775774 }
776775 }) catch unreachable;
777 try stack.push(State { .ParamDeclName = param_decl });
778 try stack.push(State { .ParamDeclAliasOrComptime = param_decl });
776 try stack.append(State { .ParamDeclName = param_decl });
777 try stack.append(State { .ParamDeclAliasOrComptime = param_decl });
779778 continue;
780779 },
781780 State.ParamDeclAliasOrComptime => |param_decl| {
......@@ -801,12 +800,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
801800 State.ParamDeclEnd => |ctx| {
802801 if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| {
803802 ctx.param_decl.var_args_token = ellipsis3;
804 stack.push(State { .ExpectToken = Token.Id.RParen }) catch unreachable;
803 stack.append(State { .ExpectToken = Token.Id.RParen }) catch unreachable;
805804 continue;
806805 }
807806
808 try stack.push(State { .ParamDeclComma = ctx.fn_proto });
809 try stack.push(State {
807 try stack.append(State { .ParamDeclComma = ctx.fn_proto });
808 try stack.append(State {
810809 .TypeExprBegin = OptionalCtx { .Required = &ctx.param_decl.type_node }
811810 });
812811 continue;
......@@ -815,7 +814,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
815814 switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RParen)) {
816815 ExpectCommaOrEndResult.end_token => |t| {
817816 if (t == null) {
818 stack.push(State { .ParamDecl = fn_proto }) catch unreachable;
817 stack.append(State { .ParamDecl = fn_proto }) catch unreachable;
819818 }
820819 continue;
821820 },
......@@ -828,7 +827,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
828827
829828 State.MaybeLabeledExpression => |ctx| {
830829 if (eatToken(&tok_it, &tree, Token.Id.Colon)) |_| {
831 stack.push(State {
830 stack.append(State {
832831 .LabeledExpression = LabelCtx {
833832 .label = ctx.label,
834833 .opt_ctx = ctx.opt_ctx,
......@@ -855,11 +854,11 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
855854 .rbrace = undefined,
856855 }
857856 );
858 stack.push(State { .Block = block }) catch unreachable;
857 stack.append(State { .Block = block }) catch unreachable;
859858 continue;
860859 },
861860 Token.Id.Keyword_while => {
862 stack.push(State {
861 stack.append(State {
863862 .While = LoopCtx {
864863 .label = ctx.label,
865864 .inline_token = null,
......@@ -870,7 +869,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
870869 continue;
871870 },
872871 Token.Id.Keyword_for => {
873 stack.push(State {
872 stack.append(State {
874873 .For = LoopCtx {
875874 .label = ctx.label,
876875 .inline_token = null,
......@@ -891,12 +890,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
891890 .body = null,
892891 });
893892 ctx.opt_ctx.store(&node.base);
894 stack.push(State { .SuspendBody = node }) catch unreachable;
895 try stack.push(State { .Payload = OptionalCtx { .Optional = &node.payload } });
893 stack.append(State { .SuspendBody = node }) catch unreachable;
894 try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } });
896895 continue;
897896 },
898897 Token.Id.Keyword_inline => {
899 stack.push(State {
898 stack.append(State {
900899 .Inline = InlineCtx {
901900 .label = ctx.label,
902901 .inline_token = token_index,
......@@ -924,7 +923,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
924923 const token_ptr = token.ptr;
925924 switch (token_ptr.id) {
926925 Token.Id.Keyword_while => {
927 stack.push(State {
926 stack.append(State {
928927 .While = LoopCtx {
929928 .inline_token = ctx.inline_token,
930929 .label = ctx.label,
......@@ -935,7 +934,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
935934 continue;
936935 },
937936 Token.Id.Keyword_for => {
938 stack.push(State {
937 stack.append(State {
939938 .For = LoopCtx {
940939 .inline_token = ctx.inline_token,
941940 .label = ctx.label,
......@@ -972,20 +971,20 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
972971 .@"else" = null,
973972 }
974973 );
975 stack.push(State { .Else = &node.@"else" }) catch unreachable;
976 try stack.push(State { .Expression = OptionalCtx { .Required = &node.body } });
977 try stack.push(State { .WhileContinueExpr = &node.continue_expr });
978 try stack.push(State { .IfToken = Token.Id.Colon });
979 try stack.push(State { .PointerPayload = OptionalCtx { .Optional = &node.payload } });
980 try stack.push(State { .ExpectToken = Token.Id.RParen });
981 try stack.push(State { .Expression = OptionalCtx { .Required = &node.condition } });
982 try stack.push(State { .ExpectToken = Token.Id.LParen });
974 stack.append(State { .Else = &node.@"else" }) catch unreachable;
975 try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } });
976 try stack.append(State { .WhileContinueExpr = &node.continue_expr });
977 try stack.append(State { .IfToken = Token.Id.Colon });
978 try stack.append(State { .PointerPayload = OptionalCtx { .Optional = &node.payload } });
979 try stack.append(State { .ExpectToken = Token.Id.RParen });
980 try stack.append(State { .Expression = OptionalCtx { .Required = &node.condition } });
981 try stack.append(State { .ExpectToken = Token.Id.LParen });
983982 continue;
984983 },
985984 State.WhileContinueExpr => |dest| {
986 stack.push(State { .ExpectToken = Token.Id.RParen }) catch unreachable;
987 try stack.push(State { .AssignmentExpressionBegin = OptionalCtx { .RequiredNull = dest } });
988 try stack.push(State { .ExpectToken = Token.Id.LParen });
985 stack.append(State { .ExpectToken = Token.Id.RParen }) catch unreachable;
986 try stack.append(State { .AssignmentExpressionBegin = OptionalCtx { .RequiredNull = dest } });
987 try stack.append(State { .ExpectToken = Token.Id.LParen });
989988 continue;
990989 },
991990 State.For => |ctx| {
......@@ -1001,12 +1000,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
10011000 .@"else" = null,
10021001 }
10031002 );
1004 stack.push(State { .Else = &node.@"else" }) catch unreachable;
1005 try stack.push(State { .Expression = OptionalCtx { .Required = &node.body } });
1006 try stack.push(State { .PointerIndexPayload = OptionalCtx { .Optional = &node.payload } });
1007 try stack.push(State { .ExpectToken = Token.Id.RParen });
1008 try stack.push(State { .Expression = OptionalCtx { .Required = &node.array_expr } });
1009 try stack.push(State { .ExpectToken = Token.Id.LParen });
1003 stack.append(State { .Else = &node.@"else" }) catch unreachable;
1004 try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } });
1005 try stack.append(State { .PointerIndexPayload = OptionalCtx { .Optional = &node.payload } });
1006 try stack.append(State { .ExpectToken = Token.Id.RParen });
1007 try stack.append(State { .Expression = OptionalCtx { .Required = &node.array_expr } });
1008 try stack.append(State { .ExpectToken = Token.Id.LParen });
10101009 continue;
10111010 },
10121011 State.Else => |dest| {
......@@ -1021,8 +1020,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
10211020 );
10221021 *dest = node;
10231022
1024 stack.push(State { .Expression = OptionalCtx { .Required = &node.body } }) catch unreachable;
1025 try stack.push(State { .Payload = OptionalCtx { .Optional = &node.payload } });
1023 stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }) catch unreachable;
1024 try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } });
10261025 continue;
10271026 } else {
10281027 continue;
......@@ -1041,7 +1040,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
10411040 },
10421041 else => {
10431042 putBackToken(&tok_it, &tree);
1044 stack.push(State { .Block = block }) catch unreachable;
1043 stack.append(State { .Block = block }) catch unreachable;
10451044
10461045 var any_comments = false;
10471046 while (try eatLineComment(arena, &tok_it, &tree)) |line_comment| {
......@@ -1050,7 +1049,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
10501049 }
10511050 if (any_comments) continue;
10521051
1053 try stack.push(State { .Statement = block });
1052 try stack.append(State { .Statement = block });
10541053 continue;
10551054 },
10561055 }
......@@ -1061,7 +1060,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
10611060 const token_ptr = token.ptr;
10621061 switch (token_ptr.id) {
10631062 Token.Id.Keyword_comptime => {
1064 stack.push(State {
1063 stack.append(State {
10651064 .ComptimeStatement = ComptimeStatementCtx {
10661065 .comptime_token = token_index,
10671066 .block = block,
......@@ -1070,7 +1069,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
10701069 continue;
10711070 },
10721071 Token.Id.Keyword_var, Token.Id.Keyword_const => {
1073 stack.push(State {
1072 stack.append(State {
10741073 .VarDecl = VarDeclCtx {
10751074 .comments = null,
10761075 .visib_token = null,
......@@ -1099,8 +1098,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
10991098 const node_ptr = try block.statements.addOne();
11001099 *node_ptr = &node.base;
11011100
1102 stack.push(State { .Semicolon = node_ptr }) catch unreachable;
1103 try stack.push(State { .AssignmentExpressionBegin = OptionalCtx{ .Required = &node.expr } });
1101 stack.append(State { .Semicolon = node_ptr }) catch unreachable;
1102 try stack.append(State { .AssignmentExpressionBegin = OptionalCtx{ .Required = &node.expr } });
11041103 continue;
11051104 },
11061105 Token.Id.LBrace => {
......@@ -1113,14 +1112,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
11131112 });
11141113 try block.statements.push(&inner_block.base);
11151114
1116 stack.push(State { .Block = inner_block }) catch unreachable;
1115 stack.append(State { .Block = inner_block }) catch unreachable;
11171116 continue;
11181117 },
11191118 else => {
11201119 putBackToken(&tok_it, &tree);
11211120 const statement = try block.statements.addOne();
1122 try stack.push(State { .Semicolon = statement });
1123 try stack.push(State { .AssignmentExpressionBegin = OptionalCtx{ .Required = statement } });
1121 try stack.append(State { .Semicolon = statement });
1122 try stack.append(State { .AssignmentExpressionBegin = OptionalCtx{ .Required = statement } });
11241123 continue;
11251124 }
11261125 }
......@@ -1131,7 +1130,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
11311130 const token_ptr = token.ptr;
11321131 switch (token_ptr.id) {
11331132 Token.Id.Keyword_var, Token.Id.Keyword_const => {
1134 stack.push(State {
1133 stack.append(State {
11351134 .VarDecl = VarDeclCtx {
11361135 .comments = null,
11371136 .visib_token = null,
......@@ -1148,8 +1147,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
11481147 putBackToken(&tok_it, &tree);
11491148 putBackToken(&tok_it, &tree);
11501149 const statement = try ctx.block.statements.addOne();
1151 try stack.push(State { .Semicolon = statement });
1152 try stack.push(State { .Expression = OptionalCtx { .Required = statement } });
1150 try stack.append(State { .Semicolon = statement });
1151 try stack.append(State { .Expression = OptionalCtx { .Required = statement } });
11531152 continue;
11541153 }
11551154 }
......@@ -1157,7 +1156,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
11571156 State.Semicolon => |node_ptr| {
11581157 const node = *node_ptr;
11591158 if (node.requireSemiColon()) {
1160 stack.push(State { .ExpectToken = Token.Id.Semicolon }) catch unreachable;
1159 stack.append(State { .ExpectToken = Token.Id.Semicolon }) catch unreachable;
11611160 continue;
11621161 }
11631162 continue;
......@@ -1182,14 +1181,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
11821181 );
11831182 try items.push(node);
11841183
1185 stack.push(State { .AsmOutputItems = items }) catch unreachable;
1186 try stack.push(State { .IfToken = Token.Id.Comma });
1187 try stack.push(State { .ExpectToken = Token.Id.RParen });
1188 try stack.push(State { .AsmOutputReturnOrType = node });
1189 try stack.push(State { .ExpectToken = Token.Id.LParen });
1190 try stack.push(State { .StringLiteral = OptionalCtx { .Required = &node.constraint } });
1191 try stack.push(State { .ExpectToken = Token.Id.RBracket });
1192 try stack.push(State { .Identifier = OptionalCtx { .Required = &node.symbolic_name } });
1184 stack.append(State { .AsmOutputItems = items }) catch unreachable;
1185 try stack.append(State { .IfToken = Token.Id.Comma });
1186 try stack.append(State { .ExpectToken = Token.Id.RParen });
1187 try stack.append(State { .AsmOutputReturnOrType = node });
1188 try stack.append(State { .ExpectToken = Token.Id.LParen });
1189 try stack.append(State { .StringLiteral = OptionalCtx { .Required = &node.constraint } });
1190 try stack.append(State { .ExpectToken = Token.Id.RBracket });
1191 try stack.append(State { .Identifier = OptionalCtx { .Required = &node.symbolic_name } });
11931192 continue;
11941193 },
11951194 State.AsmOutputReturnOrType => |node| {
......@@ -1203,7 +1202,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
12031202 },
12041203 Token.Id.Arrow => {
12051204 node.kind = ast.Node.AsmOutput.Kind { .Return = undefined };
1206 try stack.push(State { .TypeExprBegin = OptionalCtx { .Required = &node.kind.Return } });
1205 try stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &node.kind.Return } });
12071206 continue;
12081207 },
12091208 else => {
......@@ -1235,20 +1234,20 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
12351234 );
12361235 try items.push(node);
12371236
1238 stack.push(State { .AsmInputItems = items }) catch unreachable;
1239 try stack.push(State { .IfToken = Token.Id.Comma });
1240 try stack.push(State { .ExpectToken = Token.Id.RParen });
1241 try stack.push(State { .Expression = OptionalCtx { .Required = &node.expr } });
1242 try stack.push(State { .ExpectToken = Token.Id.LParen });
1243 try stack.push(State { .StringLiteral = OptionalCtx { .Required = &node.constraint } });
1244 try stack.push(State { .ExpectToken = Token.Id.RBracket });
1245 try stack.push(State { .Identifier = OptionalCtx { .Required = &node.symbolic_name } });
1237 stack.append(State { .AsmInputItems = items }) catch unreachable;
1238 try stack.append(State { .IfToken = Token.Id.Comma });
1239 try stack.append(State { .ExpectToken = Token.Id.RParen });
1240 try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } });
1241 try stack.append(State { .ExpectToken = Token.Id.LParen });
1242 try stack.append(State { .StringLiteral = OptionalCtx { .Required = &node.constraint } });
1243 try stack.append(State { .ExpectToken = Token.Id.RBracket });
1244 try stack.append(State { .Identifier = OptionalCtx { .Required = &node.symbolic_name } });
12461245 continue;
12471246 },
12481247 State.AsmClobberItems => |items| {
1249 stack.push(State { .AsmClobberItems = items }) catch unreachable;
1250 try stack.push(State { .IfToken = Token.Id.Comma });
1251 try stack.push(State { .StringLiteral = OptionalCtx { .Required = try items.addOne() } });
1248 stack.append(State { .AsmClobberItems = items }) catch unreachable;
1249 try stack.append(State { .IfToken = Token.Id.Comma });
1250 try stack.append(State { .StringLiteral = OptionalCtx { .Required = try items.addOne() } });
12521251 continue;
12531252 },
12541253
......@@ -1259,8 +1258,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
12591258 continue;
12601259 }
12611260
1262 stack.push(State { .ExprListCommaOrEnd = list_state }) catch unreachable;
1263 try stack.push(State { .Expression = OptionalCtx { .Required = try list_state.list.addOne() } });
1261 stack.append(State { .ExprListCommaOrEnd = list_state }) catch unreachable;
1262 try stack.append(State { .Expression = OptionalCtx { .Required = try list_state.list.addOne() } });
12641263 continue;
12651264 },
12661265 State.ExprListCommaOrEnd => |list_state| {
......@@ -1269,7 +1268,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
12691268 *list_state.ptr = end;
12701269 continue;
12711270 } else {
1272 stack.push(State { .ExprListItemOrEnd = list_state }) catch unreachable;
1271 stack.append(State { .ExprListItemOrEnd = list_state }) catch unreachable;
12731272 continue;
12741273 },
12751274 ExpectCommaOrEndResult.parse_error => |e| {
......@@ -1298,16 +1297,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
12981297 });
12991298 try list_state.list.push(&node.base);
13001299
1301 stack.push(State { .FieldInitListCommaOrEnd = list_state }) catch unreachable;
1302 try stack.push(State { .Expression = OptionalCtx{ .Required = &node.expr } });
1303 try stack.push(State { .ExpectToken = Token.Id.Equal });
1304 try stack.push(State {
1300 stack.append(State { .FieldInitListCommaOrEnd = list_state }) catch unreachable;
1301 try stack.append(State { .Expression = OptionalCtx{ .Required = &node.expr } });
1302 try stack.append(State { .ExpectToken = Token.Id.Equal });
1303 try stack.append(State {
13051304 .ExpectTokenSave = ExpectTokenSave {
13061305 .id = Token.Id.Identifier,
13071306 .ptr = &node.name_token,
13081307 }
13091308 });
1310 try stack.push(State {
1309 try stack.append(State {
13111310 .ExpectTokenSave = ExpectTokenSave {
13121311 .id = Token.Id.Period,
13131312 .ptr = &node.period_token,
......@@ -1321,7 +1320,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
13211320 *list_state.ptr = end;
13221321 continue;
13231322 } else {
1324 stack.push(State { .FieldInitListItemOrEnd = list_state }) catch unreachable;
1323 stack.append(State { .FieldInitListItemOrEnd = list_state }) catch unreachable;
13251324 continue;
13261325 },
13271326 ExpectCommaOrEndResult.parse_error => |e| {
......@@ -1336,7 +1335,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
13361335 container_decl.rbrace_token = end;
13371336 continue;
13381337 } else {
1339 try stack.push(State { .ContainerDecl = container_decl });
1338 try stack.append(State { .ContainerDecl = container_decl });
13401339 continue;
13411340 },
13421341 ExpectCommaOrEndResult.parse_error => |e| {
......@@ -1357,8 +1356,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
13571356
13581357 const node_ptr = try list_state.list.addOne();
13591358
1360 try stack.push(State { .ErrorTagListCommaOrEnd = list_state });
1361 try stack.push(State { .ErrorTag = node_ptr });
1359 try stack.append(State { .ErrorTagListCommaOrEnd = list_state });
1360 try stack.append(State { .ErrorTag = node_ptr });
13621361 continue;
13631362 },
13641363 State.ErrorTagListCommaOrEnd => |list_state| {
......@@ -1367,7 +1366,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
13671366 *list_state.ptr = end;
13681367 continue;
13691368 } else {
1370 stack.push(State { .ErrorTagListItemOrEnd = list_state }) catch unreachable;
1369 stack.append(State { .ErrorTagListItemOrEnd = list_state }) catch unreachable;
13711370 continue;
13721371 },
13731372 ExpectCommaOrEndResult.parse_error => |e| {
......@@ -1396,10 +1395,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
13961395 .expr = undefined,
13971396 });
13981397 try list_state.list.push(&node.base);
1399 try stack.push(State { .SwitchCaseCommaOrEnd = list_state });
1400 try stack.push(State { .AssignmentExpressionBegin = OptionalCtx { .Required = &node.expr } });
1401 try stack.push(State { .PointerPayload = OptionalCtx { .Optional = &node.payload } });
1402 try stack.push(State { .SwitchCaseFirstItem = &node.items });
1398 try stack.append(State { .SwitchCaseCommaOrEnd = list_state });
1399 try stack.append(State { .AssignmentExpressionBegin = OptionalCtx { .Required = &node.expr } });
1400 try stack.append(State { .PointerPayload = OptionalCtx { .Optional = &node.payload } });
1401 try stack.append(State { .SwitchCaseFirstItem = &node.items });
14031402
14041403 continue;
14051404 },
......@@ -1410,7 +1409,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
14101409 *list_state.ptr = end;
14111410 continue;
14121411 } else {
1413 try stack.push(State { .SwitchCaseOrEnd = list_state });
1412 try stack.append(State { .SwitchCaseOrEnd = list_state });
14141413 continue;
14151414 },
14161415 ExpectCommaOrEndResult.parse_error => |e| {
......@@ -1431,23 +1430,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
14311430 });
14321431 try case_items.push(&else_node.base);
14331432
1434 try stack.push(State { .ExpectToken = Token.Id.EqualAngleBracketRight });
1433 try stack.append(State { .ExpectToken = Token.Id.EqualAngleBracketRight });
14351434 continue;
14361435 } else {
14371436 putBackToken(&tok_it, &tree);
1438 try stack.push(State { .SwitchCaseItem = case_items });
1437 try stack.append(State { .SwitchCaseItem = case_items });
14391438 continue;
14401439 }
14411440 },
14421441 State.SwitchCaseItem => |case_items| {
1443 stack.push(State { .SwitchCaseItemCommaOrEnd = case_items }) catch unreachable;
1444 try stack.push(State { .RangeExpressionBegin = OptionalCtx { .Required = try case_items.addOne() } });
1442 stack.append(State { .SwitchCaseItemCommaOrEnd = case_items }) catch unreachable;
1443 try stack.append(State { .RangeExpressionBegin = OptionalCtx { .Required = try case_items.addOne() } });
14451444 },
14461445 State.SwitchCaseItemCommaOrEnd => |case_items| {
14471446 switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.EqualAngleBracketRight)) {
14481447 ExpectCommaOrEndResult.end_token => |t| {
14491448 if (t == null) {
1450 stack.push(State { .SwitchCaseItem = case_items }) catch unreachable;
1449 stack.append(State { .SwitchCaseItem = case_items }) catch unreachable;
14511450 }
14521451 continue;
14531452 },
......@@ -1462,7 +1461,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
14621461
14631462 State.SuspendBody => |suspend_node| {
14641463 if (suspend_node.payload != null) {
1465 try stack.push(State { .AssignmentExpressionBegin = OptionalCtx { .RequiredNull = &suspend_node.body } });
1464 try stack.append(State { .AssignmentExpressionBegin = OptionalCtx { .RequiredNull = &suspend_node.body } });
14661465 }
14671466 continue;
14681467 },
......@@ -1472,13 +1471,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
14721471 }
14731472
14741473 async_node.rangle_bracket = TokenIndex(0);
1475 try stack.push(State {
1474 try stack.append(State {
14761475 .ExpectTokenSave = ExpectTokenSave {
14771476 .id = Token.Id.AngleBracketRight,
14781477 .ptr = &??async_node.rangle_bracket,
14791478 }
14801479 });
1481 try stack.push(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &async_node.allocator_type } });
1480 try stack.append(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &async_node.allocator_type } });
14821481 continue;
14831482 },
14841483 State.AsyncEnd => |ctx| {
......@@ -1533,11 +1532,11 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
15331532 .align_expr = null,
15341533 });
15351534 ctx.opt_ctx.store(&fn_proto.base);
1536 stack.push(State { .FnProto = fn_proto }) catch unreachable;
1535 stack.append(State { .FnProto = fn_proto }) catch unreachable;
15371536 continue;
15381537 }
15391538
1540 stack.push(State {
1539 stack.append(State {
15411540 .ContainerKind = ContainerKindCtx {
15421541 .opt_ctx = ctx.opt_ctx,
15431542 .ltoken = ctx.extern_token,
......@@ -1560,13 +1559,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
15601559 }
15611560 };
15621561
1563 stack.push(State {
1562 stack.append(State {
15641563 .ExpectTokenSave = ExpectTokenSave {
15651564 .id = Token.Id.RBracket,
15661565 .ptr = &node.rtoken,
15671566 }
15681567 }) catch unreachable;
1569 try stack.push(State { .Expression = OptionalCtx { .Optional = &node.op.Slice.end } });
1568 try stack.append(State { .Expression = OptionalCtx { .Optional = &node.op.Slice.end } });
15701569 continue;
15711570 },
15721571 Token.Id.RBracket => {
......@@ -1592,15 +1591,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
15921591 .volatile_token = null,
15931592 }
15941593 };
1595 stack.push(State { .TypeExprBegin = OptionalCtx { .Required = &node.rhs } }) catch unreachable;
1596 try stack.push(State { .AddrOfModifiers = &node.op.SliceType });
1594 stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &node.rhs } }) catch unreachable;
1595 try stack.append(State { .AddrOfModifiers = &node.op.SliceType });
15971596 continue;
15981597 }
15991598
16001599 node.op = ast.Node.PrefixOp.Op { .ArrayType = undefined };
1601 stack.push(State { .TypeExprBegin = OptionalCtx { .Required = &node.rhs } }) catch unreachable;
1602 try stack.push(State { .ExpectToken = Token.Id.RBracket });
1603 try stack.push(State { .Expression = OptionalCtx { .Required = &node.op.ArrayType } });
1600 stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &node.rhs } }) catch unreachable;
1601 try stack.append(State { .ExpectToken = Token.Id.RBracket });
1602 try stack.append(State { .Expression = OptionalCtx { .Required = &node.op.ArrayType } });
16041603 continue;
16051604 },
16061605 State.AddrOfModifiers => |addr_of_info| {
......@@ -1609,20 +1608,20 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
16091608 const token_ptr = token.ptr;
16101609 switch (token_ptr.id) {
16111610 Token.Id.Keyword_align => {
1612 stack.push(state) catch unreachable;
1611 stack.append(state) catch unreachable;
16131612 if (addr_of_info.align_expr != null) {
16141613 *(try tree.errors.addOne()) = Error {
16151614 .ExtraAlignQualifier = Error.ExtraAlignQualifier { .token = token_index },
16161615 };
16171616 return tree;
16181617 }
1619 try stack.push(State { .ExpectToken = Token.Id.RParen });
1620 try stack.push(State { .Expression = OptionalCtx { .RequiredNull = &addr_of_info.align_expr} });
1621 try stack.push(State { .ExpectToken = Token.Id.LParen });
1618 try stack.append(State { .ExpectToken = Token.Id.RParen });
1619 try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &addr_of_info.align_expr} });
1620 try stack.append(State { .ExpectToken = Token.Id.LParen });
16221621 continue;
16231622 },
16241623 Token.Id.Keyword_const => {
1625 stack.push(state) catch unreachable;
1624 stack.append(state) catch unreachable;
16261625 if (addr_of_info.const_token != null) {
16271626 *(try tree.errors.addOne()) = Error {
16281627 .ExtraConstQualifier = Error.ExtraConstQualifier { .token = token_index },
......@@ -1633,7 +1632,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
16331632 continue;
16341633 },
16351634 Token.Id.Keyword_volatile => {
1636 stack.push(state) catch unreachable;
1635 stack.append(state) catch unreachable;
16371636 if (addr_of_info.volatile_token != null) {
16381637 *(try tree.errors.addOne()) = Error {
16391638 .ExtraVolatileQualifier = Error.ExtraVolatileQualifier { .token = token_index },
......@@ -1679,13 +1678,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
16791678 }
16801679 );
16811680
1682 stack.push(State {
1681 stack.append(State {
16831682 .ExpectTokenSave = ExpectTokenSave {
16841683 .id = Token.Id.Pipe,
16851684 .ptr = &node.rpipe,
16861685 }
16871686 }) catch unreachable;
1688 try stack.push(State { .Identifier = OptionalCtx { .Required = &node.error_symbol } });
1687 try stack.append(State { .Identifier = OptionalCtx { .Required = &node.error_symbol } });
16891688 continue;
16901689 },
16911690 State.PointerPayload => |opt_ctx| {
......@@ -1717,14 +1716,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
17171716 }
17181717 );
17191718
1720 try stack.push(State {
1719 try stack.append(State {
17211720 .ExpectTokenSave = ExpectTokenSave {
17221721 .id = Token.Id.Pipe,
17231722 .ptr = &node.rpipe,
17241723 }
17251724 });
1726 try stack.push(State { .Identifier = OptionalCtx { .Required = &node.value_symbol } });
1727 try stack.push(State {
1725 try stack.append(State { .Identifier = OptionalCtx { .Required = &node.value_symbol } });
1726 try stack.append(State {
17281727 .OptionalTokenSave = OptionalTokenSave {
17291728 .id = Token.Id.Asterisk,
17301729 .ptr = &node.ptr_token,
......@@ -1762,16 +1761,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
17621761 }
17631762 );
17641763
1765 stack.push(State {
1764 stack.append(State {
17661765 .ExpectTokenSave = ExpectTokenSave {
17671766 .id = Token.Id.Pipe,
17681767 .ptr = &node.rpipe,
17691768 }
17701769 }) catch unreachable;
1771 try stack.push(State { .Identifier = OptionalCtx { .RequiredNull = &node.index_symbol } });
1772 try stack.push(State { .IfToken = Token.Id.Comma });
1773 try stack.push(State { .Identifier = OptionalCtx { .Required = &node.value_symbol } });
1774 try stack.push(State {
1770 try stack.append(State { .Identifier = OptionalCtx { .RequiredNull = &node.index_symbol } });
1771 try stack.append(State { .IfToken = Token.Id.Comma });
1772 try stack.append(State { .Identifier = OptionalCtx { .Required = &node.value_symbol } });
1773 try stack.append(State {
17751774 .OptionalTokenSave = OptionalTokenSave {
17761775 .id = Token.Id.Asterisk,
17771776 .ptr = &node.ptr_token,
......@@ -1796,18 +1795,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
17961795 }
17971796 );
17981797
1799 stack.push(State { .Expression = OptionalCtx { .Optional = &node.rhs } }) catch unreachable;
1798 stack.append(State { .Expression = OptionalCtx { .Optional = &node.rhs } }) catch unreachable;
18001799
18011800 switch (token_ptr.id) {
18021801 Token.Id.Keyword_break => {
18031802 node.kind = ast.Node.ControlFlowExpression.Kind { .Break = null };
1804 try stack.push(State { .Identifier = OptionalCtx { .RequiredNull = &node.kind.Break } });
1805 try stack.push(State { .IfToken = Token.Id.Colon });
1803 try stack.append(State { .Identifier = OptionalCtx { .RequiredNull = &node.kind.Break } });
1804 try stack.append(State { .IfToken = Token.Id.Colon });
18061805 },
18071806 Token.Id.Keyword_continue => {
18081807 node.kind = ast.Node.ControlFlowExpression.Kind { .Continue = null };
1809 try stack.push(State { .Identifier = OptionalCtx { .RequiredNull = &node.kind.Continue } });
1810 try stack.push(State { .IfToken = Token.Id.Colon });
1808 try stack.append(State { .Identifier = OptionalCtx { .RequiredNull = &node.kind.Continue } });
1809 try stack.append(State { .IfToken = Token.Id.Colon });
18111810 },
18121811 Token.Id.Keyword_return => {
18131812 node.kind = ast.Node.ControlFlowExpression.Kind.Return;
......@@ -1831,21 +1830,21 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
18311830 }
18321831 );
18331832
1834 stack.push(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable;
1833 stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable;
18351834 continue;
18361835 },
18371836 else => {
18381837 if (!try parseBlockExpr(&stack, arena, opt_ctx, token_ptr, token_index)) {
18391838 putBackToken(&tok_it, &tree);
1840 stack.push(State { .UnwrapExpressionBegin = opt_ctx }) catch unreachable;
1839 stack.append(State { .UnwrapExpressionBegin = opt_ctx }) catch unreachable;
18411840 }
18421841 continue;
18431842 }
18441843 }
18451844 },
18461845 State.RangeExpressionBegin => |opt_ctx| {
1847 stack.push(State { .RangeExpressionEnd = opt_ctx }) catch unreachable;
1848 try stack.push(State { .Expression = opt_ctx });
1846 stack.append(State { .RangeExpressionEnd = opt_ctx }) catch unreachable;
1847 try stack.append(State { .Expression = opt_ctx });
18491848 continue;
18501849 },
18511850 State.RangeExpressionEnd => |opt_ctx| {
......@@ -1861,13 +1860,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
18611860 .rhs = undefined,
18621861 }
18631862 );
1864 stack.push(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable;
1863 stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable;
18651864 continue;
18661865 }
18671866 },
18681867 State.AssignmentExpressionBegin => |opt_ctx| {
1869 stack.push(State { .AssignmentExpressionEnd = opt_ctx }) catch unreachable;
1870 try stack.push(State { .Expression = opt_ctx });
1868 stack.append(State { .AssignmentExpressionEnd = opt_ctx }) catch unreachable;
1869 try stack.append(State { .Expression = opt_ctx });
18711870 continue;
18721871 },
18731872
......@@ -1887,8 +1886,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
18871886 .rhs = undefined,
18881887 }
18891888 );
1890 stack.push(State { .AssignmentExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1891 try stack.push(State { .Expression = OptionalCtx { .Required = &node.rhs } });
1889 stack.append(State { .AssignmentExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1890 try stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } });
18921891 continue;
18931892 } else {
18941893 putBackToken(&tok_it, &tree);
......@@ -1897,8 +1896,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
18971896 },
18981897
18991898 State.UnwrapExpressionBegin => |opt_ctx| {
1900 stack.push(State { .UnwrapExpressionEnd = opt_ctx }) catch unreachable;
1901 try stack.push(State { .BoolOrExpressionBegin = opt_ctx });
1899 stack.append(State { .UnwrapExpressionEnd = opt_ctx }) catch unreachable;
1900 try stack.append(State { .BoolOrExpressionBegin = opt_ctx });
19021901 continue;
19031902 },
19041903
......@@ -1919,11 +1918,11 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
19191918 }
19201919 );
19211920
1922 stack.push(State { .UnwrapExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1923 try stack.push(State { .Expression = OptionalCtx { .Required = &node.rhs } });
1921 stack.append(State { .UnwrapExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1922 try stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } });
19241923
19251924 if (node.op == ast.Node.InfixOp.Op.Catch) {
1926 try stack.push(State { .Payload = OptionalCtx { .Optional = &node.op.Catch } });
1925 try stack.append(State { .Payload = OptionalCtx { .Optional = &node.op.Catch } });
19271926 }
19281927 continue;
19291928 } else {
......@@ -1933,8 +1932,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
19331932 },
19341933
19351934 State.BoolOrExpressionBegin => |opt_ctx| {
1936 stack.push(State { .BoolOrExpressionEnd = opt_ctx }) catch unreachable;
1937 try stack.push(State { .BoolAndExpressionBegin = opt_ctx });
1935 stack.append(State { .BoolOrExpressionEnd = opt_ctx }) catch unreachable;
1936 try stack.append(State { .BoolAndExpressionBegin = opt_ctx });
19381937 continue;
19391938 },
19401939
......@@ -1951,15 +1950,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
19511950 .rhs = undefined,
19521951 }
19531952 );
1954 stack.push(State { .BoolOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1955 try stack.push(State { .BoolAndExpressionBegin = OptionalCtx { .Required = &node.rhs } });
1953 stack.append(State { .BoolOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1954 try stack.append(State { .BoolAndExpressionBegin = OptionalCtx { .Required = &node.rhs } });
19561955 continue;
19571956 }
19581957 },
19591958
19601959 State.BoolAndExpressionBegin => |opt_ctx| {
1961 stack.push(State { .BoolAndExpressionEnd = opt_ctx }) catch unreachable;
1962 try stack.push(State { .ComparisonExpressionBegin = opt_ctx });
1960 stack.append(State { .BoolAndExpressionEnd = opt_ctx }) catch unreachable;
1961 try stack.append(State { .ComparisonExpressionBegin = opt_ctx });
19631962 continue;
19641963 },
19651964
......@@ -1976,15 +1975,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
19761975 .rhs = undefined,
19771976 }
19781977 );
1979 stack.push(State { .BoolAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1980 try stack.push(State { .ComparisonExpressionBegin = OptionalCtx { .Required = &node.rhs } });
1978 stack.append(State { .BoolAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1979 try stack.append(State { .ComparisonExpressionBegin = OptionalCtx { .Required = &node.rhs } });
19811980 continue;
19821981 }
19831982 },
19841983
19851984 State.ComparisonExpressionBegin => |opt_ctx| {
1986 stack.push(State { .ComparisonExpressionEnd = opt_ctx }) catch unreachable;
1987 try stack.push(State { .BinaryOrExpressionBegin = opt_ctx });
1985 stack.append(State { .ComparisonExpressionEnd = opt_ctx }) catch unreachable;
1986 try stack.append(State { .BinaryOrExpressionBegin = opt_ctx });
19881987 continue;
19891988 },
19901989
......@@ -2004,8 +2003,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
20042003 .rhs = undefined,
20052004 }
20062005 );
2007 stack.push(State { .ComparisonExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2008 try stack.push(State { .BinaryOrExpressionBegin = OptionalCtx { .Required = &node.rhs } });
2006 stack.append(State { .ComparisonExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2007 try stack.append(State { .BinaryOrExpressionBegin = OptionalCtx { .Required = &node.rhs } });
20092008 continue;
20102009 } else {
20112010 putBackToken(&tok_it, &tree);
......@@ -2014,8 +2013,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
20142013 },
20152014
20162015 State.BinaryOrExpressionBegin => |opt_ctx| {
2017 stack.push(State { .BinaryOrExpressionEnd = opt_ctx }) catch unreachable;
2018 try stack.push(State { .BinaryXorExpressionBegin = opt_ctx });
2016 stack.append(State { .BinaryOrExpressionEnd = opt_ctx }) catch unreachable;
2017 try stack.append(State { .BinaryXorExpressionBegin = opt_ctx });
20192018 continue;
20202019 },
20212020
......@@ -2032,15 +2031,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
20322031 .rhs = undefined,
20332032 }
20342033 );
2035 stack.push(State { .BinaryOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2036 try stack.push(State { .BinaryXorExpressionBegin = OptionalCtx { .Required = &node.rhs } });
2034 stack.append(State { .BinaryOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2035 try stack.append(State { .BinaryXorExpressionBegin = OptionalCtx { .Required = &node.rhs } });
20372036 continue;
20382037 }
20392038 },
20402039
20412040 State.BinaryXorExpressionBegin => |opt_ctx| {
2042 stack.push(State { .BinaryXorExpressionEnd = opt_ctx }) catch unreachable;
2043 try stack.push(State { .BinaryAndExpressionBegin = opt_ctx });
2041 stack.append(State { .BinaryXorExpressionEnd = opt_ctx }) catch unreachable;
2042 try stack.append(State { .BinaryAndExpressionBegin = opt_ctx });
20442043 continue;
20452044 },
20462045
......@@ -2057,15 +2056,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
20572056 .rhs = undefined,
20582057 }
20592058 );
2060 stack.push(State { .BinaryXorExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2061 try stack.push(State { .BinaryAndExpressionBegin = OptionalCtx { .Required = &node.rhs } });
2059 stack.append(State { .BinaryXorExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2060 try stack.append(State { .BinaryAndExpressionBegin = OptionalCtx { .Required = &node.rhs } });
20622061 continue;
20632062 }
20642063 },
20652064
20662065 State.BinaryAndExpressionBegin => |opt_ctx| {
2067 stack.push(State { .BinaryAndExpressionEnd = opt_ctx }) catch unreachable;
2068 try stack.push(State { .BitShiftExpressionBegin = opt_ctx });
2066 stack.append(State { .BinaryAndExpressionEnd = opt_ctx }) catch unreachable;
2067 try stack.append(State { .BitShiftExpressionBegin = opt_ctx });
20692068 continue;
20702069 },
20712070
......@@ -2082,15 +2081,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
20822081 .rhs = undefined,
20832082 }
20842083 );
2085 stack.push(State { .BinaryAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2086 try stack.push(State { .BitShiftExpressionBegin = OptionalCtx { .Required = &node.rhs } });
2084 stack.append(State { .BinaryAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2085 try stack.append(State { .BitShiftExpressionBegin = OptionalCtx { .Required = &node.rhs } });
20872086 continue;
20882087 }
20892088 },
20902089
20912090 State.BitShiftExpressionBegin => |opt_ctx| {
2092 stack.push(State { .BitShiftExpressionEnd = opt_ctx }) catch unreachable;
2093 try stack.push(State { .AdditionExpressionBegin = opt_ctx });
2091 stack.append(State { .BitShiftExpressionEnd = opt_ctx }) catch unreachable;
2092 try stack.append(State { .AdditionExpressionBegin = opt_ctx });
20942093 continue;
20952094 },
20962095
......@@ -2110,8 +2109,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21102109 .rhs = undefined,
21112110 }
21122111 );
2113 stack.push(State { .BitShiftExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2114 try stack.push(State { .AdditionExpressionBegin = OptionalCtx { .Required = &node.rhs } });
2112 stack.append(State { .BitShiftExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2113 try stack.append(State { .AdditionExpressionBegin = OptionalCtx { .Required = &node.rhs } });
21152114 continue;
21162115 } else {
21172116 putBackToken(&tok_it, &tree);
......@@ -2120,8 +2119,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21202119 },
21212120
21222121 State.AdditionExpressionBegin => |opt_ctx| {
2123 stack.push(State { .AdditionExpressionEnd = opt_ctx }) catch unreachable;
2124 try stack.push(State { .MultiplyExpressionBegin = opt_ctx });
2122 stack.append(State { .AdditionExpressionEnd = opt_ctx }) catch unreachable;
2123 try stack.append(State { .MultiplyExpressionBegin = opt_ctx });
21252124 continue;
21262125 },
21272126
......@@ -2141,8 +2140,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21412140 .rhs = undefined,
21422141 }
21432142 );
2144 stack.push(State { .AdditionExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2145 try stack.push(State { .MultiplyExpressionBegin = OptionalCtx { .Required = &node.rhs } });
2143 stack.append(State { .AdditionExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2144 try stack.append(State { .MultiplyExpressionBegin = OptionalCtx { .Required = &node.rhs } });
21462145 continue;
21472146 } else {
21482147 putBackToken(&tok_it, &tree);
......@@ -2151,8 +2150,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21512150 },
21522151
21532152 State.MultiplyExpressionBegin => |opt_ctx| {
2154 stack.push(State { .MultiplyExpressionEnd = opt_ctx }) catch unreachable;
2155 try stack.push(State { .CurlySuffixExpressionBegin = opt_ctx });
2153 stack.append(State { .MultiplyExpressionEnd = opt_ctx }) catch unreachable;
2154 try stack.append(State { .CurlySuffixExpressionBegin = opt_ctx });
21562155 continue;
21572156 },
21582157
......@@ -2172,8 +2171,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21722171 .rhs = undefined,
21732172 }
21742173 );
2175 stack.push(State { .MultiplyExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2176 try stack.push(State { .CurlySuffixExpressionBegin = OptionalCtx { .Required = &node.rhs } });
2174 stack.append(State { .MultiplyExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2175 try stack.append(State { .CurlySuffixExpressionBegin = OptionalCtx { .Required = &node.rhs } });
21772176 continue;
21782177 } else {
21792178 putBackToken(&tok_it, &tree);
......@@ -2182,9 +2181,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21822181 },
21832182
21842183 State.CurlySuffixExpressionBegin => |opt_ctx| {
2185 stack.push(State { .CurlySuffixExpressionEnd = opt_ctx }) catch unreachable;
2186 try stack.push(State { .IfToken = Token.Id.LBrace });
2187 try stack.push(State { .TypeExprBegin = opt_ctx });
2184 stack.append(State { .CurlySuffixExpressionEnd = opt_ctx }) catch unreachable;
2185 try stack.append(State { .IfToken = Token.Id.LBrace });
2186 try stack.append(State { .TypeExprBegin = opt_ctx });
21882187 continue;
21892188 },
21902189
......@@ -2202,9 +2201,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
22022201 });
22032202 opt_ctx.store(&node.base);
22042203
2205 stack.push(State { .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2206 try stack.push(State { .IfToken = Token.Id.LBrace });
2207 try stack.push(State {
2204 stack.append(State { .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2205 try stack.append(State { .IfToken = Token.Id.LBrace });
2206 try stack.append(State {
22082207 .FieldInitListItemOrEnd = ListSave(@typeOf(node.op.StructInitializer)) {
22092208 .list = &node.op.StructInitializer,
22102209 .ptr = &node.rtoken,
......@@ -2223,9 +2222,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
22232222 .rtoken = undefined,
22242223 }
22252224 );
2226 stack.push(State { .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2227 try stack.push(State { .IfToken = Token.Id.LBrace });
2228 try stack.push(State {
2225 stack.append(State { .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2226 try stack.append(State { .IfToken = Token.Id.LBrace });
2227 try stack.append(State {
22292228 .ExprListItemOrEnd = ExprListCtx {
22302229 .list = &node.op.ArrayInitializer,
22312230 .end = Token.Id.RBrace,
......@@ -2236,8 +2235,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
22362235 },
22372236
22382237 State.TypeExprBegin => |opt_ctx| {
2239 stack.push(State { .TypeExprEnd = opt_ctx }) catch unreachable;
2240 try stack.push(State { .PrefixOpExpression = opt_ctx });
2238 stack.append(State { .TypeExprEnd = opt_ctx }) catch unreachable;
2239 try stack.append(State { .PrefixOpExpression = opt_ctx });
22412240 continue;
22422241 },
22432242
......@@ -2254,8 +2253,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
22542253 .rhs = undefined,
22552254 }
22562255 );
2257 stack.push(State { .TypeExprEnd = opt_ctx.toRequired() }) catch unreachable;
2258 try stack.push(State { .PrefixOpExpression = OptionalCtx { .Required = &node.rhs } });
2256 stack.append(State { .TypeExprEnd = opt_ctx.toRequired() }) catch unreachable;
2257 try stack.append(State { .PrefixOpExpression = OptionalCtx { .Required = &node.rhs } });
22592258 continue;
22602259 }
22612260 },
......@@ -2288,14 +2287,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
22882287 node = child;
22892288 }
22902289
2291 stack.push(State { .TypeExprBegin = OptionalCtx { .Required = &node.rhs } }) catch unreachable;
2290 stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &node.rhs } }) catch unreachable;
22922291 if (node.op == ast.Node.PrefixOp.Op.AddrOf) {
2293 try stack.push(State { .AddrOfModifiers = &node.op.AddrOf });
2292 try stack.append(State { .AddrOfModifiers = &node.op.AddrOf });
22942293 }
22952294 continue;
22962295 } else {
22972296 putBackToken(&tok_it, &tree);
2298 stack.push(State { .SuffixOpExpressionBegin = opt_ctx }) catch unreachable;
2297 stack.append(State { .SuffixOpExpressionBegin = opt_ctx }) catch unreachable;
22992298 continue;
23002299 }
23012300 },
......@@ -2310,20 +2309,20 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
23102309 .rangle_bracket = null,
23112310 }
23122311 );
2313 stack.push(State {
2312 stack.append(State {
23142313 .AsyncEnd = AsyncEndCtx {
23152314 .ctx = opt_ctx,
23162315 .attribute = async_node,
23172316 }
23182317 }) catch unreachable;
2319 try stack.push(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() });
2320 try stack.push(State { .PrimaryExpression = opt_ctx.toRequired() });
2321 try stack.push(State { .AsyncAllocator = async_node });
2318 try stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() });
2319 try stack.append(State { .PrimaryExpression = opt_ctx.toRequired() });
2320 try stack.append(State { .AsyncAllocator = async_node });
23222321 continue;
23232322 }
23242323
2325 stack.push(State { .SuffixOpExpressionEnd = opt_ctx }) catch unreachable;
2326 try stack.push(State { .PrimaryExpression = opt_ctx });
2324 stack.append(State { .SuffixOpExpressionEnd = opt_ctx }) catch unreachable;
2325 try stack.append(State { .PrimaryExpression = opt_ctx });
23272326 continue;
23282327 },
23292328
......@@ -2348,8 +2347,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
23482347 .rtoken = undefined,
23492348 }
23502349 );
2351 stack.push(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2352 try stack.push(State {
2350 stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2351 try stack.append(State {
23532352 .ExprListItemOrEnd = ExprListCtx {
23542353 .list = &node.op.Call.params,
23552354 .end = Token.Id.RParen,
......@@ -2369,9 +2368,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
23692368 .rtoken = undefined
23702369 }
23712370 );
2372 stack.push(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2373 try stack.push(State { .SliceOrArrayAccess = node });
2374 try stack.push(State { .Expression = OptionalCtx { .Required = &node.op.ArrayAccess }});
2371 stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2372 try stack.append(State { .SliceOrArrayAccess = node });
2373 try stack.append(State { .Expression = OptionalCtx { .Required = &node.op.ArrayAccess }});
23752374 continue;
23762375 },
23772376 Token.Id.Period => {
......@@ -2384,8 +2383,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
23842383 .rhs = undefined,
23852384 }
23862385 );
2387 stack.push(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2388 try stack.push(State { .Identifier = OptionalCtx { .Required = &node.rhs } });
2386 stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2387 try stack.append(State { .Identifier = OptionalCtx { .Required = &node.rhs } });
23892388 continue;
23902389 },
23912390 else => {
......@@ -2455,7 +2454,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
24552454 .return_type = undefined,
24562455 };
24572456 const return_type_ptr = &((??node.result).return_type);
2458 try stack.push(State { .Expression = OptionalCtx { .Required = return_type_ptr, } });
2457 try stack.append(State { .Expression = OptionalCtx { .Required = return_type_ptr, } });
24592458 continue;
24602459 },
24612460 Token.Id.StringLiteral, Token.Id.MultilineStringLiteralLine => {
......@@ -2471,13 +2470,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
24712470 .rparen = undefined,
24722471 }
24732472 );
2474 stack.push(State {
2473 stack.append(State {
24752474 .ExpectTokenSave = ExpectTokenSave {
24762475 .id = Token.Id.RParen,
24772476 .ptr = &node.rparen,
24782477 }
24792478 }) catch unreachable;
2480 try stack.push(State { .Expression = OptionalCtx { .Required = &node.expr } });
2479 try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } });
24812480 continue;
24822481 },
24832482 Token.Id.Builtin => {
......@@ -2489,14 +2488,14 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
24892488 .rparen_token = undefined,
24902489 }
24912490 );
2492 stack.push(State {
2491 stack.append(State {
24932492 .ExprListItemOrEnd = ExprListCtx {
24942493 .list = &node.params,
24952494 .end = Token.Id.RParen,
24962495 .ptr = &node.rparen_token,
24972496 }
24982497 }) catch unreachable;
2499 try stack.push(State { .ExpectToken = Token.Id.LParen, });
2498 try stack.append(State { .ExpectToken = Token.Id.LParen, });
25002499 continue;
25012500 },
25022501 Token.Id.LBracket => {
......@@ -2508,11 +2507,11 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
25082507 .rhs = undefined,
25092508 }
25102509 );
2511 stack.push(State { .SliceOrArrayType = node }) catch unreachable;
2510 stack.append(State { .SliceOrArrayType = node }) catch unreachable;
25122511 continue;
25132512 },
25142513 Token.Id.Keyword_error => {
2515 stack.push(State {
2514 stack.append(State {
25162515 .ErrorTypeOrSetDecl = ErrorTypeOrSetDeclCtx {
25172516 .error_token = token.index,
25182517 .opt_ctx = opt_ctx
......@@ -2521,7 +2520,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
25212520 continue;
25222521 },
25232522 Token.Id.Keyword_packed => {
2524 stack.push(State {
2523 stack.append(State {
25252524 .ContainerKind = ContainerKindCtx {
25262525 .opt_ctx = opt_ctx,
25272526 .ltoken = token.index,
......@@ -2531,7 +2530,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
25312530 continue;
25322531 },
25332532 Token.Id.Keyword_extern => {
2534 stack.push(State {
2533 stack.append(State {
25352534 .ExternType = ExternTypeCtx {
25362535 .opt_ctx = opt_ctx,
25372536 .extern_token = token.index,
......@@ -2542,7 +2541,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
25422541 },
25432542 Token.Id.Keyword_struct, Token.Id.Keyword_union, Token.Id.Keyword_enum => {
25442543 putBackToken(&tok_it, &tree);
2545 stack.push(State {
2544 stack.append(State {
25462545 .ContainerKind = ContainerKindCtx {
25472546 .opt_ctx = opt_ctx,
25482547 .ltoken = token.index,
......@@ -2552,7 +2551,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
25522551 continue;
25532552 },
25542553 Token.Id.Identifier => {
2555 stack.push(State {
2554 stack.append(State {
25562555 .MaybeLabeledExpression = MaybeLabeledExpressionCtx {
25572556 .label = token.index,
25582557 .opt_ctx = opt_ctx
......@@ -2580,7 +2579,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
25802579 .align_expr = null,
25812580 });
25822581 opt_ctx.store(&fn_proto.base);
2583 stack.push(State { .FnProto = fn_proto }) catch unreachable;
2582 stack.append(State { .FnProto = fn_proto }) catch unreachable;
25842583 continue;
25852584 },
25862585 Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => {
......@@ -2603,8 +2602,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
26032602 .align_expr = null,
26042603 });
26052604 opt_ctx.store(&fn_proto.base);
2606 stack.push(State { .FnProto = fn_proto }) catch unreachable;
2607 try stack.push(State {
2605 stack.append(State { .FnProto = fn_proto }) catch unreachable;
2606 try stack.append(State {
26082607 .ExpectTokenSave = ExpectTokenSave {
26092608 .id = Token.Id.Keyword_fn,
26102609 .ptr = &fn_proto.fn_token
......@@ -2625,21 +2624,21 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
26252624 .rparen = undefined,
26262625 }
26272626 );
2628 stack.push(State {
2627 stack.append(State {
26292628 .ExpectTokenSave = ExpectTokenSave {
26302629 .id = Token.Id.RParen,
26312630 .ptr = &node.rparen,
26322631 }
26332632 }) catch unreachable;
2634 try stack.push(State { .AsmClobberItems = &node.clobbers });
2635 try stack.push(State { .IfToken = Token.Id.Colon });
2636 try stack.push(State { .AsmInputItems = &node.inputs });
2637 try stack.push(State { .IfToken = Token.Id.Colon });
2638 try stack.push(State { .AsmOutputItems = &node.outputs });
2639 try stack.push(State { .IfToken = Token.Id.Colon });
2640 try stack.push(State { .StringLiteral = OptionalCtx { .Required = &node.template } });
2641 try stack.push(State { .ExpectToken = Token.Id.LParen });
2642 try stack.push(State {
2633 try stack.append(State { .AsmClobberItems = &node.clobbers });
2634 try stack.append(State { .IfToken = Token.Id.Colon });
2635 try stack.append(State { .AsmInputItems = &node.inputs });
2636 try stack.append(State { .IfToken = Token.Id.Colon });
2637 try stack.append(State { .AsmOutputItems = &node.outputs });
2638 try stack.append(State { .IfToken = Token.Id.Colon });
2639 try stack.append(State { .StringLiteral = OptionalCtx { .Required = &node.template } });
2640 try stack.append(State { .ExpectToken = Token.Id.LParen });
2641 try stack.append(State {
26432642 .OptionalTokenSave = OptionalTokenSave {
26442643 .id = Token.Id.Keyword_volatile,
26452644 .ptr = &node.volatile_token,
......@@ -2647,7 +2646,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
26472646 });
26482647 },
26492648 Token.Id.Keyword_inline => {
2650 stack.push(State {
2649 stack.append(State {
26512650 .Inline = InlineCtx {
26522651 .label = null,
26532652 .inline_token = token.index,
......@@ -2688,7 +2687,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
26882687 });
26892688 ctx.opt_ctx.store(&node.base);
26902689
2691 stack.push(State {
2690 stack.append(State {
26922691 .ErrorTagListItemOrEnd = ListSave(@typeOf(node.decls)) {
26932692 .list = &node.decls,
26942693 .ptr = &node.rbrace_token,
......@@ -3153,7 +3152,7 @@ fn parseStringLiteral(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterato
31533152 }
31543153}
31553154
3156fn parseBlockExpr(stack: &SegmentedList(State, 32), arena: &mem.Allocator, ctx: &const OptionalCtx,
3155fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &const OptionalCtx,
31573156 token_ptr: &const Token, token_index: TokenIndex) !bool {
31583157 switch (token_ptr.id) {
31593158 Token.Id.Keyword_suspend => {
......@@ -3167,8 +3166,8 @@ fn parseBlockExpr(stack: &SegmentedList(State, 32), arena: &mem.Allocator, ctx:
31673166 }
31683167 );
31693168
3170 stack.push(State { .SuspendBody = node }) catch unreachable;
3171 try stack.push(State { .Payload = OptionalCtx { .Optional = &node.payload } });
3169 stack.append(State { .SuspendBody = node }) catch unreachable;
3170 try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } });
31723171 return true;
31733172 },
31743173 Token.Id.Keyword_if => {
......@@ -3183,16 +3182,16 @@ fn parseBlockExpr(stack: &SegmentedList(State, 32), arena: &mem.Allocator, ctx:
31833182 }
31843183 );
31853184
3186 stack.push(State { .Else = &node.@"else" }) catch unreachable;
3187 try stack.push(State { .Expression = OptionalCtx { .Required = &node.body } });
3188 try stack.push(State { .PointerPayload = OptionalCtx { .Optional = &node.payload } });
3189 try stack.push(State { .ExpectToken = Token.Id.RParen });
3190 try stack.push(State { .Expression = OptionalCtx { .Required = &node.condition } });
3191 try stack.push(State { .ExpectToken = Token.Id.LParen });
3185 stack.append(State { .Else = &node.@"else" }) catch unreachable;
3186 try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } });
3187 try stack.append(State { .PointerPayload = OptionalCtx { .Optional = &node.payload } });
3188 try stack.append(State { .ExpectToken = Token.Id.RParen });
3189 try stack.append(State { .Expression = OptionalCtx { .Required = &node.condition } });
3190 try stack.append(State { .ExpectToken = Token.Id.LParen });
31923191 return true;
31933192 },
31943193 Token.Id.Keyword_while => {
3195 stack.push(State {
3194 stack.append(State {
31963195 .While = LoopCtx {
31973196 .label = null,
31983197 .inline_token = null,
......@@ -3203,7 +3202,7 @@ fn parseBlockExpr(stack: &SegmentedList(State, 32), arena: &mem.Allocator, ctx:
32033202 return true;
32043203 },
32053204 Token.Id.Keyword_for => {
3206 stack.push(State {
3205 stack.append(State {
32073206 .For = LoopCtx {
32083207 .label = null,
32093208 .inline_token = null,
......@@ -3225,16 +3224,16 @@ fn parseBlockExpr(stack: &SegmentedList(State, 32), arena: &mem.Allocator, ctx:
32253224 });
32263225 ctx.store(&node.base);
32273226
3228 stack.push(State {
3227 stack.append(State {
32293228 .SwitchCaseOrEnd = ListSave(@typeOf(node.cases)) {
32303229 .list = &node.cases,
32313230 .ptr = &node.rbrace,
32323231 },
32333232 }) catch unreachable;
3234 try stack.push(State { .ExpectToken = Token.Id.LBrace });
3235 try stack.push(State { .ExpectToken = Token.Id.RParen });
3236 try stack.push(State { .Expression = OptionalCtx { .Required = &node.expr } });
3237 try stack.push(State { .ExpectToken = Token.Id.LParen });
3233 try stack.append(State { .ExpectToken = Token.Id.LBrace });
3234 try stack.append(State { .ExpectToken = Token.Id.RParen });
3235 try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } });
3236 try stack.append(State { .ExpectToken = Token.Id.LParen });
32383237 return true;
32393238 },
32403239 Token.Id.Keyword_comptime => {
......@@ -3246,7 +3245,7 @@ fn parseBlockExpr(stack: &SegmentedList(State, 32), arena: &mem.Allocator, ctx:
32463245 .doc_comments = null,
32473246 }
32483247 );
3249 try stack.push(State { .Expression = OptionalCtx { .Required = &node.expr } });
3248 try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } });
32503249 return true;
32513250 },
32523251 Token.Id.LBrace => {
......@@ -3258,7 +3257,7 @@ fn parseBlockExpr(stack: &SegmentedList(State, 32), arena: &mem.Allocator, ctx:
32583257 .rbrace = undefined,
32593258 });
32603259 ctx.store(&block.base);
3261 stack.push(State { .Block = block }) catch unreachable;
3260 stack.append(State { .Block = block }) catch unreachable;
32623261 return true;
32633262 },
32643263 else => {
......@@ -3473,10 +3472,10 @@ const RenderAstFrame = struct {
34733472};
34743473
34753474pub fn renderAst(allocator: &mem.Allocator, tree: &const ast.Tree, stream: var) !void {
3476 var stack = SegmentedList(State, 32).init(allocator);
3475 var stack = std.ArrayList(State).init(allocator);
34773476 defer stack.deinit();
34783477
3479 try stack.push(RenderAstFrame {
3478 try stack.append(RenderAstFrame {
34803479 .node = &root_node.base,
34813480 .indent = 0,
34823481 });
......@@ -3491,7 +3490,7 @@ pub fn renderAst(allocator: &mem.Allocator, tree: &const ast.Tree, stream: var)
34913490 try stream.print("{}\n", @tagName(frame.node.id));
34923491 var child_i: usize = 0;
34933492 while (frame.node.iterate(child_i)) |child| : (child_i += 1) {
3494 try stack.push(RenderAstFrame {
3493 try stack.append(RenderAstFrame {
34953494 .node = child,
34963495 .indent = frame.indent + 2,
34973496 });
std/zig/render.zig+333-334
......@@ -1,6 +1,5 @@
11const std = @import("../index.zig");
22const assert = std.debug.assert;
3const SegmentedList = std.SegmentedList;
43const mem = std.mem;
54const ast = std.zig.ast;
65const Token = std.zig.Token;
......@@ -22,19 +21,19 @@ const RenderState = union(enum) {
2221const indent_delta = 4;
2322
2423pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
25 var stack = SegmentedList(RenderState, 32).init(allocator);
24 var stack = std.ArrayList(RenderState).init(allocator);
2625 defer stack.deinit();
2726
2827 {
29 try stack.push(RenderState { .Text = "\n"});
28 try stack.append(RenderState { .Text = "\n"});
3029
3130 var i = tree.root_node.decls.len;
3231 while (i != 0) {
3332 i -= 1;
3433 const decl = *tree.root_node.decls.at(i);
35 try stack.push(RenderState {.TopLevelDecl = decl});
34 try stack.append(RenderState {.TopLevelDecl = decl});
3635 if (i != 0) {
37 try stack.push(RenderState {
36 try stack.append(RenderState {
3837 .Text = blk: {
3938 const prev_node = *tree.root_node.decls.at(i - 1);
4039 const prev_node_last_token = tree.tokens.at(prev_node.lastToken());
......@@ -50,7 +49,7 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
5049 }
5150
5251 var indent: usize = 0;
53 while (stack.pop()) |state| {
52 while (stack.popOrNull()) |state| {
5453 switch (state) {
5554 RenderState.TopLevelDecl => |decl| {
5655 switch (decl.id) {
......@@ -59,13 +58,13 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
5958 try renderComments(tree, stream, fn_proto, indent);
6059
6160 if (fn_proto.body_node) |body_node| {
62 stack.push(RenderState { .Expression = body_node}) catch unreachable;
63 try stack.push(RenderState { .Text = " "});
61 stack.append(RenderState { .Expression = body_node}) catch unreachable;
62 try stack.append(RenderState { .Text = " "});
6463 } else {
65 stack.push(RenderState { .Text = ";" }) catch unreachable;
64 stack.append(RenderState { .Text = ";" }) catch unreachable;
6665 }
6766
68 try stack.push(RenderState { .Expression = decl });
67 try stack.append(RenderState { .Expression = decl });
6968 },
7069 ast.Node.Id.Use => {
7170 const use_decl = @fieldParentPtr(ast.Node.Use, "base", decl);
......@@ -73,21 +72,21 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
7372 try stream.print("{} ", tree.tokenSlice(visib_token));
7473 }
7574 try stream.print("use ");
76 try stack.push(RenderState { .Text = ";" });
77 try stack.push(RenderState { .Expression = use_decl.expr });
75 try stack.append(RenderState { .Text = ";" });
76 try stack.append(RenderState { .Expression = use_decl.expr });
7877 },
7978 ast.Node.Id.VarDecl => {
8079 const var_decl = @fieldParentPtr(ast.Node.VarDecl, "base", decl);
8180 try renderComments(tree, stream, var_decl, indent);
82 try stack.push(RenderState { .VarDecl = var_decl});
81 try stack.append(RenderState { .VarDecl = var_decl});
8382 },
8483 ast.Node.Id.TestDecl => {
8584 const test_decl = @fieldParentPtr(ast.Node.TestDecl, "base", decl);
8685 try renderComments(tree, stream, test_decl, indent);
8786 try stream.print("test ");
88 try stack.push(RenderState { .Expression = test_decl.body_node });
89 try stack.push(RenderState { .Text = " " });
90 try stack.push(RenderState { .Expression = test_decl.name });
87 try stack.append(RenderState { .Expression = test_decl.body_node });
88 try stack.append(RenderState { .Text = " " });
89 try stack.append(RenderState { .Expression = test_decl.name });
9190 },
9291 ast.Node.Id.StructField => {
9392 const field = @fieldParentPtr(ast.Node.StructField, "base", decl);
......@@ -96,24 +95,24 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
9695 try stream.print("{} ", tree.tokenSlice(visib_token));
9796 }
9897 try stream.print("{}: ", tree.tokenSlice(field.name_token));
99 try stack.push(RenderState { .Token = field.lastToken() + 1 });
100 try stack.push(RenderState { .Expression = field.type_expr});
98 try stack.append(RenderState { .Token = field.lastToken() + 1 });
99 try stack.append(RenderState { .Expression = field.type_expr});
101100 },
102101 ast.Node.Id.UnionTag => {
103102 const tag = @fieldParentPtr(ast.Node.UnionTag, "base", decl);
104103 try renderComments(tree, stream, tag, indent);
105104 try stream.print("{}", tree.tokenSlice(tag.name_token));
106105
107 try stack.push(RenderState { .Text = "," });
106 try stack.append(RenderState { .Text = "," });
108107
109108 if (tag.value_expr) |value_expr| {
110 try stack.push(RenderState { .Expression = value_expr });
111 try stack.push(RenderState { .Text = " = " });
109 try stack.append(RenderState { .Expression = value_expr });
110 try stack.append(RenderState { .Text = " = " });
112111 }
113112
114113 if (tag.type_expr) |type_expr| {
115114 try stream.print(": ");
116 try stack.push(RenderState { .Expression = type_expr});
115 try stack.append(RenderState { .Expression = type_expr});
117116 }
118117 },
119118 ast.Node.Id.EnumTag => {
......@@ -121,10 +120,10 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
121120 try renderComments(tree, stream, tag, indent);
122121 try stream.print("{}", tree.tokenSlice(tag.name_token));
123122
124 try stack.push(RenderState { .Text = "," });
123 try stack.append(RenderState { .Text = "," });
125124 if (tag.value) |value| {
126125 try stream.print(" = ");
127 try stack.push(RenderState { .Expression = value});
126 try stack.append(RenderState { .Expression = value});
128127 }
129128 },
130129 ast.Node.Id.ErrorTag => {
......@@ -133,8 +132,8 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
133132 try stream.print("{}", tree.tokenSlice(tag.name_token));
134133 },
135134 ast.Node.Id.Comptime => {
136 try stack.push(RenderState { .MaybeSemiColon = decl });
137 try stack.push(RenderState { .Expression = decl });
135 try stack.append(RenderState { .MaybeSemiColon = decl });
136 try stack.append(RenderState { .Expression = decl });
138137 },
139138 ast.Node.Id.LineComment => {
140139 const line_comment_node = @fieldParentPtr(ast.Node.LineComment, "base", decl);
......@@ -145,42 +144,42 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
145144 },
146145
147146 RenderState.VarDecl => |var_decl| {
148 try stack.push(RenderState { .Token = var_decl.semicolon_token });
147 try stack.append(RenderState { .Token = var_decl.semicolon_token });
149148 if (var_decl.init_node) |init_node| {
150 try stack.push(RenderState { .Expression = init_node });
149 try stack.append(RenderState { .Expression = init_node });
151150 const text = if (init_node.id == ast.Node.Id.MultilineStringLiteral) " =" else " = ";
152 try stack.push(RenderState { .Text = text });
151 try stack.append(RenderState { .Text = text });
153152 }
154153 if (var_decl.align_node) |align_node| {
155 try stack.push(RenderState { .Text = ")" });
156 try stack.push(RenderState { .Expression = align_node });
157 try stack.push(RenderState { .Text = " align(" });
154 try stack.append(RenderState { .Text = ")" });
155 try stack.append(RenderState { .Expression = align_node });
156 try stack.append(RenderState { .Text = " align(" });
158157 }
159158 if (var_decl.type_node) |type_node| {
160 try stack.push(RenderState { .Expression = type_node });
161 try stack.push(RenderState { .Text = ": " });
159 try stack.append(RenderState { .Expression = type_node });
160 try stack.append(RenderState { .Text = ": " });
162161 }
163 try stack.push(RenderState { .Text = tree.tokenSlice(var_decl.name_token) });
164 try stack.push(RenderState { .Text = " " });
165 try stack.push(RenderState { .Text = tree.tokenSlice(var_decl.mut_token) });
162 try stack.append(RenderState { .Text = tree.tokenSlice(var_decl.name_token) });
163 try stack.append(RenderState { .Text = " " });
164 try stack.append(RenderState { .Text = tree.tokenSlice(var_decl.mut_token) });
166165
167166 if (var_decl.comptime_token) |comptime_token| {
168 try stack.push(RenderState { .Text = " " });
169 try stack.push(RenderState { .Text = tree.tokenSlice(comptime_token) });
167 try stack.append(RenderState { .Text = " " });
168 try stack.append(RenderState { .Text = tree.tokenSlice(comptime_token) });
170169 }
171170
172171 if (var_decl.extern_export_token) |extern_export_token| {
173172 if (var_decl.lib_name != null) {
174 try stack.push(RenderState { .Text = " " });
175 try stack.push(RenderState { .Expression = ??var_decl.lib_name });
173 try stack.append(RenderState { .Text = " " });
174 try stack.append(RenderState { .Expression = ??var_decl.lib_name });
176175 }
177 try stack.push(RenderState { .Text = " " });
178 try stack.push(RenderState { .Text = tree.tokenSlice(extern_export_token) });
176 try stack.append(RenderState { .Text = " " });
177 try stack.append(RenderState { .Text = tree.tokenSlice(extern_export_token) });
179178 }
180179
181180 if (var_decl.visib_token) |visib_token| {
182 try stack.push(RenderState { .Text = " " });
183 try stack.push(RenderState { .Text = tree.tokenSlice(visib_token) });
181 try stack.append(RenderState { .Text = " " });
182 try stack.append(RenderState { .Text = tree.tokenSlice(visib_token) });
184183 }
185184 },
186185
......@@ -198,7 +197,7 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
198197 if (param_decl.var_args_token) |var_args_token| {
199198 try stream.print("{}", tree.tokenSlice(var_args_token));
200199 } else {
201 try stack.push(RenderState { .Expression = param_decl.type_node});
200 try stack.append(RenderState { .Expression = param_decl.type_node});
202201 }
203202 },
204203 RenderState.Text => |bytes| {
......@@ -219,18 +218,18 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
219218 try stream.write("{}");
220219 } else {
221220 try stream.write("{");
222 try stack.push(RenderState { .Text = "}"});
223 try stack.push(RenderState.PrintIndent);
224 try stack.push(RenderState { .Indent = indent});
225 try stack.push(RenderState { .Text = "\n"});
221 try stack.append(RenderState { .Text = "}"});
222 try stack.append(RenderState.PrintIndent);
223 try stack.append(RenderState { .Indent = indent});
224 try stack.append(RenderState { .Text = "\n"});
226225 var i = block.statements.len;
227226 while (i != 0) {
228227 i -= 1;
229228 const statement_node = *block.statements.at(i);
230 try stack.push(RenderState { .Statement = statement_node});
231 try stack.push(RenderState.PrintIndent);
232 try stack.push(RenderState { .Indent = indent + indent_delta});
233 try stack.push(RenderState {
229 try stack.append(RenderState { .Statement = statement_node});
230 try stack.append(RenderState.PrintIndent);
231 try stack.append(RenderState { .Indent = indent + indent_delta});
232 try stack.append(RenderState {
234233 .Text = blk: {
235234 if (i != 0) {
236235 const prev_node = *block.statements.at(i - 1);
......@@ -249,21 +248,21 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
249248 ast.Node.Id.Defer => {
250249 const defer_node = @fieldParentPtr(ast.Node.Defer, "base", base);
251250 try stream.print("{} ", tree.tokenSlice(defer_node.defer_token));
252 try stack.push(RenderState { .Expression = defer_node.expr });
251 try stack.append(RenderState { .Expression = defer_node.expr });
253252 },
254253 ast.Node.Id.Comptime => {
255254 const comptime_node = @fieldParentPtr(ast.Node.Comptime, "base", base);
256255 try stream.print("{} ", tree.tokenSlice(comptime_node.comptime_token));
257 try stack.push(RenderState { .Expression = comptime_node.expr });
256 try stack.append(RenderState { .Expression = comptime_node.expr });
258257 },
259258 ast.Node.Id.AsyncAttribute => {
260259 const async_attr = @fieldParentPtr(ast.Node.AsyncAttribute, "base", base);
261260 try stream.print("{}", tree.tokenSlice(async_attr.async_token));
262261
263262 if (async_attr.allocator_type) |allocator_type| {
264 try stack.push(RenderState { .Text = ">" });
265 try stack.push(RenderState { .Expression = allocator_type });
266 try stack.push(RenderState { .Text = "<" });
263 try stack.append(RenderState { .Text = ">" });
264 try stack.append(RenderState { .Expression = allocator_type });
265 try stack.append(RenderState { .Text = "<" });
267266 }
268267 },
269268 ast.Node.Id.Suspend => {
......@@ -274,25 +273,25 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
274273 try stream.print("{}", tree.tokenSlice(suspend_node.suspend_token));
275274
276275 if (suspend_node.body) |body| {
277 try stack.push(RenderState { .Expression = body });
278 try stack.push(RenderState { .Text = " " });
276 try stack.append(RenderState { .Expression = body });
277 try stack.append(RenderState { .Text = " " });
279278 }
280279
281280 if (suspend_node.payload) |payload| {
282 try stack.push(RenderState { .Expression = payload });
283 try stack.push(RenderState { .Text = " " });
281 try stack.append(RenderState { .Expression = payload });
282 try stack.append(RenderState { .Text = " " });
284283 }
285284 },
286285 ast.Node.Id.InfixOp => {
287286 const prefix_op_node = @fieldParentPtr(ast.Node.InfixOp, "base", base);
288 try stack.push(RenderState { .Expression = prefix_op_node.rhs });
287 try stack.append(RenderState { .Expression = prefix_op_node.rhs });
289288
290289 if (prefix_op_node.op == ast.Node.InfixOp.Op.Catch) {
291290 if (prefix_op_node.op.Catch) |payload| {
292 try stack.push(RenderState { .Text = " " });
293 try stack.push(RenderState { .Expression = payload });
291 try stack.append(RenderState { .Text = " " });
292 try stack.append(RenderState { .Expression = payload });
294293 }
295 try stack.push(RenderState { .Text = " catch " });
294 try stack.append(RenderState { .Text = " catch " });
296295 } else {
297296 const text = switch (prefix_op_node.op) {
298297 ast.Node.InfixOp.Op.Add => " + ",
......@@ -340,46 +339,46 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
340339 ast.Node.InfixOp.Op.Catch => unreachable,
341340 };
342341
343 try stack.push(RenderState { .Text = text });
342 try stack.append(RenderState { .Text = text });
344343 }
345 try stack.push(RenderState { .Expression = prefix_op_node.lhs });
344 try stack.append(RenderState { .Expression = prefix_op_node.lhs });
346345 },
347346 ast.Node.Id.PrefixOp => {
348347 const prefix_op_node = @fieldParentPtr(ast.Node.PrefixOp, "base", base);
349 try stack.push(RenderState { .Expression = prefix_op_node.rhs });
348 try stack.append(RenderState { .Expression = prefix_op_node.rhs });
350349 switch (prefix_op_node.op) {
351350 ast.Node.PrefixOp.Op.AddrOf => |addr_of_info| {
352351 try stream.write("&");
353352 if (addr_of_info.volatile_token != null) {
354 try stack.push(RenderState { .Text = "volatile "});
353 try stack.append(RenderState { .Text = "volatile "});
355354 }
356355 if (addr_of_info.const_token != null) {
357 try stack.push(RenderState { .Text = "const "});
356 try stack.append(RenderState { .Text = "const "});
358357 }
359358 if (addr_of_info.align_expr) |align_expr| {
360359 try stream.print("align(");
361 try stack.push(RenderState { .Text = ") "});
362 try stack.push(RenderState { .Expression = align_expr});
360 try stack.append(RenderState { .Text = ") "});
361 try stack.append(RenderState { .Expression = align_expr});
363362 }
364363 },
365364 ast.Node.PrefixOp.Op.SliceType => |addr_of_info| {
366365 try stream.write("[]");
367366 if (addr_of_info.volatile_token != null) {
368 try stack.push(RenderState { .Text = "volatile "});
367 try stack.append(RenderState { .Text = "volatile "});
369368 }
370369 if (addr_of_info.const_token != null) {
371 try stack.push(RenderState { .Text = "const "});
370 try stack.append(RenderState { .Text = "const "});
372371 }
373372 if (addr_of_info.align_expr) |align_expr| {
374373 try stream.print("align(");
375 try stack.push(RenderState { .Text = ") "});
376 try stack.push(RenderState { .Expression = align_expr});
374 try stack.append(RenderState { .Text = ") "});
375 try stack.append(RenderState { .Expression = align_expr});
377376 }
378377 },
379378 ast.Node.PrefixOp.Op.ArrayType => |array_index| {
380 try stack.push(RenderState { .Text = "]"});
381 try stack.push(RenderState { .Expression = array_index});
382 try stack.push(RenderState { .Text = "["});
379 try stack.append(RenderState { .Text = "]"});
380 try stack.append(RenderState { .Expression = array_index});
381 try stack.append(RenderState { .Text = "["});
383382 },
384383 ast.Node.PrefixOp.Op.BitNot => try stream.write("~"),
385384 ast.Node.PrefixOp.Op.BoolNot => try stream.write("!"),
......@@ -399,70 +398,70 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
399398
400399 switch (suffix_op.op) {
401400 @TagType(ast.Node.SuffixOp.Op).Call => |*call_info| {
402 try stack.push(RenderState { .Text = ")"});
401 try stack.append(RenderState { .Text = ")"});
403402 var i = call_info.params.len;
404403 while (i != 0) {
405404 i -= 1;
406405 const param_node = *call_info.params.at(i);
407 try stack.push(RenderState { .Expression = param_node});
406 try stack.append(RenderState { .Expression = param_node});
408407 if (i != 0) {
409 try stack.push(RenderState { .Text = ", " });
408 try stack.append(RenderState { .Text = ", " });
410409 }
411410 }
412 try stack.push(RenderState { .Text = "("});
413 try stack.push(RenderState { .Expression = suffix_op.lhs });
411 try stack.append(RenderState { .Text = "("});
412 try stack.append(RenderState { .Expression = suffix_op.lhs });
414413
415414 if (call_info.async_attr) |async_attr| {
416 try stack.push(RenderState { .Text = " "});
417 try stack.push(RenderState { .Expression = &async_attr.base });
415 try stack.append(RenderState { .Text = " "});
416 try stack.append(RenderState { .Expression = &async_attr.base });
418417 }
419418 },
420419 ast.Node.SuffixOp.Op.ArrayAccess => |index_expr| {
421 try stack.push(RenderState { .Text = "]"});
422 try stack.push(RenderState { .Expression = index_expr});
423 try stack.push(RenderState { .Text = "["});
424 try stack.push(RenderState { .Expression = suffix_op.lhs });
420 try stack.append(RenderState { .Text = "]"});
421 try stack.append(RenderState { .Expression = index_expr});
422 try stack.append(RenderState { .Text = "["});
423 try stack.append(RenderState { .Expression = suffix_op.lhs });
425424 },
426425 @TagType(ast.Node.SuffixOp.Op).Slice => |range| {
427 try stack.push(RenderState { .Text = "]"});
426 try stack.append(RenderState { .Text = "]"});
428427 if (range.end) |end| {
429 try stack.push(RenderState { .Expression = end});
428 try stack.append(RenderState { .Expression = end});
430429 }
431 try stack.push(RenderState { .Text = ".."});
432 try stack.push(RenderState { .Expression = range.start});
433 try stack.push(RenderState { .Text = "["});
434 try stack.push(RenderState { .Expression = suffix_op.lhs });
430 try stack.append(RenderState { .Text = ".."});
431 try stack.append(RenderState { .Expression = range.start});
432 try stack.append(RenderState { .Text = "["});
433 try stack.append(RenderState { .Expression = suffix_op.lhs });
435434 },
436435 ast.Node.SuffixOp.Op.StructInitializer => |*field_inits| {
437436 if (field_inits.len == 0) {
438 try stack.push(RenderState { .Text = "{}" });
439 try stack.push(RenderState { .Expression = suffix_op.lhs });
437 try stack.append(RenderState { .Text = "{}" });
438 try stack.append(RenderState { .Expression = suffix_op.lhs });
440439 continue;
441440 }
442441 if (field_inits.len == 1) {
443442 const field_init = *field_inits.at(0);
444443
445 try stack.push(RenderState { .Text = " }" });
446 try stack.push(RenderState { .Expression = field_init });
447 try stack.push(RenderState { .Text = "{ " });
448 try stack.push(RenderState { .Expression = suffix_op.lhs });
444 try stack.append(RenderState { .Text = " }" });
445 try stack.append(RenderState { .Expression = field_init });
446 try stack.append(RenderState { .Text = "{ " });
447 try stack.append(RenderState { .Expression = suffix_op.lhs });
449448 continue;
450449 }
451 try stack.push(RenderState { .Text = "}"});
452 try stack.push(RenderState.PrintIndent);
453 try stack.push(RenderState { .Indent = indent });
454 try stack.push(RenderState { .Text = "\n" });
450 try stack.append(RenderState { .Text = "}"});
451 try stack.append(RenderState.PrintIndent);
452 try stack.append(RenderState { .Indent = indent });
453 try stack.append(RenderState { .Text = "\n" });
455454 var i = field_inits.len;
456455 while (i != 0) {
457456 i -= 1;
458457 const field_init = *field_inits.at(i);
459458 if (field_init.id != ast.Node.Id.LineComment) {
460 try stack.push(RenderState { .Text = "," });
459 try stack.append(RenderState { .Text = "," });
461460 }
462 try stack.push(RenderState { .Expression = field_init });
463 try stack.push(RenderState.PrintIndent);
461 try stack.append(RenderState { .Expression = field_init });
462 try stack.append(RenderState.PrintIndent);
464463 if (i != 0) {
465 try stack.push(RenderState { .Text = blk: {
464 try stack.append(RenderState { .Text = blk: {
466465 const prev_node = *field_inits.at(i - 1);
467466 const prev_node_last_token_end = tree.tokens.at(prev_node.lastToken()).end;
468467 const loc = tree.tokenLocation(prev_node_last_token_end, field_init.firstToken());
......@@ -473,40 +472,40 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
473472 }});
474473 }
475474 }
476 try stack.push(RenderState { .Indent = indent + indent_delta });
477 try stack.push(RenderState { .Text = "{\n"});
478 try stack.push(RenderState { .Expression = suffix_op.lhs });
475 try stack.append(RenderState { .Indent = indent + indent_delta });
476 try stack.append(RenderState { .Text = "{\n"});
477 try stack.append(RenderState { .Expression = suffix_op.lhs });
479478 },
480479 ast.Node.SuffixOp.Op.ArrayInitializer => |*exprs| {
481480 if (exprs.len == 0) {
482 try stack.push(RenderState { .Text = "{}" });
483 try stack.push(RenderState { .Expression = suffix_op.lhs });
481 try stack.append(RenderState { .Text = "{}" });
482 try stack.append(RenderState { .Expression = suffix_op.lhs });
484483 continue;
485484 }
486485 if (exprs.len == 1) {
487486 const expr = *exprs.at(0);
488487
489 try stack.push(RenderState { .Text = "}" });
490 try stack.push(RenderState { .Expression = expr });
491 try stack.push(RenderState { .Text = "{" });
492 try stack.push(RenderState { .Expression = suffix_op.lhs });
488 try stack.append(RenderState { .Text = "}" });
489 try stack.append(RenderState { .Expression = expr });
490 try stack.append(RenderState { .Text = "{" });
491 try stack.append(RenderState { .Expression = suffix_op.lhs });
493492 continue;
494493 }
495494
496 try stack.push(RenderState { .Text = "}"});
497 try stack.push(RenderState.PrintIndent);
498 try stack.push(RenderState { .Indent = indent });
495 try stack.append(RenderState { .Text = "}"});
496 try stack.append(RenderState.PrintIndent);
497 try stack.append(RenderState { .Indent = indent });
499498 var i = exprs.len;
500499 while (i != 0) {
501500 i -= 1;
502501 const expr = *exprs.at(i);
503 try stack.push(RenderState { .Text = ",\n" });
504 try stack.push(RenderState { .Expression = expr });
505 try stack.push(RenderState.PrintIndent);
502 try stack.append(RenderState { .Text = ",\n" });
503 try stack.append(RenderState { .Expression = expr });
504 try stack.append(RenderState.PrintIndent);
506505 }
507 try stack.push(RenderState { .Indent = indent + indent_delta });
508 try stack.push(RenderState { .Text = "{\n"});
509 try stack.push(RenderState { .Expression = suffix_op.lhs });
506 try stack.append(RenderState { .Indent = indent + indent_delta });
507 try stack.append(RenderState { .Text = "{\n"});
508 try stack.append(RenderState { .Expression = suffix_op.lhs });
510509 },
511510 }
512511 },
......@@ -514,8 +513,8 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
514513 const flow_expr = @fieldParentPtr(ast.Node.ControlFlowExpression, "base", base);
515514
516515 if (flow_expr.rhs) |rhs| {
517 try stack.push(RenderState { .Expression = rhs });
518 try stack.push(RenderState { .Text = " " });
516 try stack.append(RenderState { .Expression = rhs });
517 try stack.append(RenderState { .Text = " " });
519518 }
520519
521520 switch (flow_expr.kind) {
......@@ -523,14 +522,14 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
523522 try stream.print("break");
524523 if (maybe_label) |label| {
525524 try stream.print(" :");
526 try stack.push(RenderState { .Expression = label });
525 try stack.append(RenderState { .Expression = label });
527526 }
528527 },
529528 ast.Node.ControlFlowExpression.Kind.Continue => |maybe_label| {
530529 try stream.print("continue");
531530 if (maybe_label) |label| {
532531 try stream.print(" :");
533 try stack.push(RenderState { .Expression = label });
532 try stack.append(RenderState { .Expression = label });
534533 }
535534 },
536535 ast.Node.ControlFlowExpression.Kind.Return => {
......@@ -541,48 +540,48 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
541540 },
542541 ast.Node.Id.Payload => {
543542 const payload = @fieldParentPtr(ast.Node.Payload, "base", base);
544 try stack.push(RenderState { .Text = "|"});
545 try stack.push(RenderState { .Expression = payload.error_symbol });
546 try stack.push(RenderState { .Text = "|"});
543 try stack.append(RenderState { .Text = "|"});
544 try stack.append(RenderState { .Expression = payload.error_symbol });
545 try stack.append(RenderState { .Text = "|"});
547546 },
548547 ast.Node.Id.PointerPayload => {
549548 const payload = @fieldParentPtr(ast.Node.PointerPayload, "base", base);
550 try stack.push(RenderState { .Text = "|"});
551 try stack.push(RenderState { .Expression = payload.value_symbol });
549 try stack.append(RenderState { .Text = "|"});
550 try stack.append(RenderState { .Expression = payload.value_symbol });
552551
553552 if (payload.ptr_token) |ptr_token| {
554 try stack.push(RenderState { .Text = tree.tokenSlice(ptr_token) });
553 try stack.append(RenderState { .Text = tree.tokenSlice(ptr_token) });
555554 }
556555
557 try stack.push(RenderState { .Text = "|"});
556 try stack.append(RenderState { .Text = "|"});
558557 },
559558 ast.Node.Id.PointerIndexPayload => {
560559 const payload = @fieldParentPtr(ast.Node.PointerIndexPayload, "base", base);
561 try stack.push(RenderState { .Text = "|"});
560 try stack.append(RenderState { .Text = "|"});
562561
563562 if (payload.index_symbol) |index_symbol| {
564 try stack.push(RenderState { .Expression = index_symbol });
565 try stack.push(RenderState { .Text = ", "});
563 try stack.append(RenderState { .Expression = index_symbol });
564 try stack.append(RenderState { .Text = ", "});
566565 }
567566
568 try stack.push(RenderState { .Expression = payload.value_symbol });
567 try stack.append(RenderState { .Expression = payload.value_symbol });
569568
570569 if (payload.ptr_token) |ptr_token| {
571 try stack.push(RenderState { .Text = tree.tokenSlice(ptr_token) });
570 try stack.append(RenderState { .Text = tree.tokenSlice(ptr_token) });
572571 }
573572
574 try stack.push(RenderState { .Text = "|"});
573 try stack.append(RenderState { .Text = "|"});
575574 },
576575 ast.Node.Id.GroupedExpression => {
577576 const grouped_expr = @fieldParentPtr(ast.Node.GroupedExpression, "base", base);
578 try stack.push(RenderState { .Text = ")"});
579 try stack.push(RenderState { .Expression = grouped_expr.expr });
580 try stack.push(RenderState { .Text = "("});
577 try stack.append(RenderState { .Text = ")"});
578 try stack.append(RenderState { .Expression = grouped_expr.expr });
579 try stack.append(RenderState { .Text = "("});
581580 },
582581 ast.Node.Id.FieldInitializer => {
583582 const field_init = @fieldParentPtr(ast.Node.FieldInitializer, "base", base);
584583 try stream.print(".{} = ", tree.tokenSlice(field_init.name_token));
585 try stack.push(RenderState { .Expression = field_init.expr });
584 try stack.append(RenderState { .Expression = field_init.expr });
586585 },
587586 ast.Node.Id.IntegerLiteral => {
588587 const integer_literal = @fieldParentPtr(ast.Node.IntegerLiteral, "base", base);
......@@ -640,20 +639,20 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
640639 }
641640
642641 if (container_decl.fields_and_decls.len == 0) {
643 try stack.push(RenderState { .Text = "{}"});
642 try stack.append(RenderState { .Text = "{}"});
644643 } else {
645 try stack.push(RenderState { .Text = "}"});
646 try stack.push(RenderState.PrintIndent);
647 try stack.push(RenderState { .Indent = indent });
648 try stack.push(RenderState { .Text = "\n"});
644 try stack.append(RenderState { .Text = "}"});
645 try stack.append(RenderState.PrintIndent);
646 try stack.append(RenderState { .Indent = indent });
647 try stack.append(RenderState { .Text = "\n"});
649648
650649 var i = container_decl.fields_and_decls.len;
651650 while (i != 0) {
652651 i -= 1;
653652 const node = *container_decl.fields_and_decls.at(i);
654 try stack.push(RenderState { .TopLevelDecl = node});
655 try stack.push(RenderState.PrintIndent);
656 try stack.push(RenderState {
653 try stack.append(RenderState { .TopLevelDecl = node});
654 try stack.append(RenderState.PrintIndent);
655 try stack.append(RenderState {
657656 .Text = blk: {
658657 if (i != 0) {
659658 const prev_node = *container_decl.fields_and_decls.at(i - 1);
......@@ -667,25 +666,25 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
667666 },
668667 });
669668 }
670 try stack.push(RenderState { .Indent = indent + indent_delta});
671 try stack.push(RenderState { .Text = "{"});
669 try stack.append(RenderState { .Indent = indent + indent_delta});
670 try stack.append(RenderState { .Text = "{"});
672671 }
673672
674673 switch (container_decl.init_arg_expr) {
675 ast.Node.ContainerDecl.InitArg.None => try stack.push(RenderState { .Text = " "}),
674 ast.Node.ContainerDecl.InitArg.None => try stack.append(RenderState { .Text = " "}),
676675 ast.Node.ContainerDecl.InitArg.Enum => |enum_tag_type| {
677676 if (enum_tag_type) |expr| {
678 try stack.push(RenderState { .Text = ")) "});
679 try stack.push(RenderState { .Expression = expr});
680 try stack.push(RenderState { .Text = "(enum("});
677 try stack.append(RenderState { .Text = ")) "});
678 try stack.append(RenderState { .Expression = expr});
679 try stack.append(RenderState { .Text = "(enum("});
681680 } else {
682 try stack.push(RenderState { .Text = "(enum) "});
681 try stack.append(RenderState { .Text = "(enum) "});
683682 }
684683 },
685684 ast.Node.ContainerDecl.InitArg.Type => |type_expr| {
686 try stack.push(RenderState { .Text = ") "});
687 try stack.push(RenderState { .Expression = type_expr});
688 try stack.push(RenderState { .Text = "("});
685 try stack.append(RenderState { .Text = ") "});
686 try stack.append(RenderState { .Expression = type_expr});
687 try stack.append(RenderState { .Text = "("});
689688 },
690689 }
691690 },
......@@ -710,28 +709,28 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
710709
711710
712711 try stream.write("error{");
713 try stack.push(RenderState { .Text = "}" });
714 try stack.push(RenderState { .TopLevelDecl = node });
712 try stack.append(RenderState { .Text = "}" });
713 try stack.append(RenderState { .TopLevelDecl = node });
715714 continue;
716715 }
717716
718717 try stream.write("error{");
719718
720 try stack.push(RenderState { .Text = "}"});
721 try stack.push(RenderState.PrintIndent);
722 try stack.push(RenderState { .Indent = indent });
723 try stack.push(RenderState { .Text = "\n"});
719 try stack.append(RenderState { .Text = "}"});
720 try stack.append(RenderState.PrintIndent);
721 try stack.append(RenderState { .Indent = indent });
722 try stack.append(RenderState { .Text = "\n"});
724723
725724 var i = err_set_decl.decls.len;
726725 while (i != 0) {
727726 i -= 1;
728727 const node = *err_set_decl.decls.at(i);
729728 if (node.id != ast.Node.Id.LineComment) {
730 try stack.push(RenderState { .Text = "," });
729 try stack.append(RenderState { .Text = "," });
731730 }
732 try stack.push(RenderState { .TopLevelDecl = node });
733 try stack.push(RenderState.PrintIndent);
734 try stack.push(RenderState {
731 try stack.append(RenderState { .TopLevelDecl = node });
732 try stack.append(RenderState.PrintIndent);
733 try stack.append(RenderState {
735734 .Text = blk: {
736735 if (i != 0) {
737736 const prev_node = *err_set_decl.decls.at(i - 1);
......@@ -745,7 +744,7 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
745744 },
746745 });
747746 }
748 try stack.push(RenderState { .Indent = indent + indent_delta});
747 try stack.append(RenderState { .Indent = indent + indent_delta});
749748 },
750749 ast.Node.Id.MultilineStringLiteral => {
751750 const multiline_str_literal = @fieldParentPtr(ast.Node.MultilineStringLiteral, "base", base);
......@@ -766,14 +765,14 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
766765 ast.Node.Id.BuiltinCall => {
767766 const builtin_call = @fieldParentPtr(ast.Node.BuiltinCall, "base", base);
768767 try stream.print("{}(", tree.tokenSlice(builtin_call.builtin_token));
769 try stack.push(RenderState { .Text = ")"});
768 try stack.append(RenderState { .Text = ")"});
770769 var i = builtin_call.params.len;
771770 while (i != 0) {
772771 i -= 1;
773772 const param_node = *builtin_call.params.at(i);
774 try stack.push(RenderState { .Expression = param_node});
773 try stack.append(RenderState { .Expression = param_node});
775774 if (i != 0) {
776 try stack.push(RenderState { .Text = ", " });
775 try stack.append(RenderState { .Text = ", " });
777776 }
778777 }
779778 },
......@@ -782,63 +781,63 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
782781
783782 switch (fn_proto.return_type) {
784783 ast.Node.FnProto.ReturnType.Explicit => |node| {
785 try stack.push(RenderState { .Expression = node});
784 try stack.append(RenderState { .Expression = node});
786785 },
787786 ast.Node.FnProto.ReturnType.InferErrorSet => |node| {
788 try stack.push(RenderState { .Expression = node});
789 try stack.push(RenderState { .Text = "!"});
787 try stack.append(RenderState { .Expression = node});
788 try stack.append(RenderState { .Text = "!"});
790789 },
791790 }
792791
793792 if (fn_proto.align_expr) |align_expr| {
794 try stack.push(RenderState { .Text = ") " });
795 try stack.push(RenderState { .Expression = align_expr});
796 try stack.push(RenderState { .Text = "align(" });
793 try stack.append(RenderState { .Text = ") " });
794 try stack.append(RenderState { .Expression = align_expr});
795 try stack.append(RenderState { .Text = "align(" });
797796 }
798797
799 try stack.push(RenderState { .Text = ") " });
798 try stack.append(RenderState { .Text = ") " });
800799 var i = fn_proto.params.len;
801800 while (i != 0) {
802801 i -= 1;
803802 const param_decl_node = *fn_proto.params.at(i);
804 try stack.push(RenderState { .ParamDecl = param_decl_node});
803 try stack.append(RenderState { .ParamDecl = param_decl_node});
805804 if (i != 0) {
806 try stack.push(RenderState { .Text = ", " });
805 try stack.append(RenderState { .Text = ", " });
807806 }
808807 }
809808
810 try stack.push(RenderState { .Text = "(" });
809 try stack.append(RenderState { .Text = "(" });
811810 if (fn_proto.name_token) |name_token| {
812 try stack.push(RenderState { .Text = tree.tokenSlice(name_token) });
813 try stack.push(RenderState { .Text = " " });
811 try stack.append(RenderState { .Text = tree.tokenSlice(name_token) });
812 try stack.append(RenderState { .Text = " " });
814813 }
815814
816 try stack.push(RenderState { .Text = "fn" });
815 try stack.append(RenderState { .Text = "fn" });
817816
818817 if (fn_proto.async_attr) |async_attr| {
819 try stack.push(RenderState { .Text = " " });
820 try stack.push(RenderState { .Expression = &async_attr.base });
818 try stack.append(RenderState { .Text = " " });
819 try stack.append(RenderState { .Expression = &async_attr.base });
821820 }
822821
823822 if (fn_proto.cc_token) |cc_token| {
824 try stack.push(RenderState { .Text = " " });
825 try stack.push(RenderState { .Text = tree.tokenSlice(cc_token) });
823 try stack.append(RenderState { .Text = " " });
824 try stack.append(RenderState { .Text = tree.tokenSlice(cc_token) });
826825 }
827826
828827 if (fn_proto.lib_name) |lib_name| {
829 try stack.push(RenderState { .Text = " " });
830 try stack.push(RenderState { .Expression = lib_name });
828 try stack.append(RenderState { .Text = " " });
829 try stack.append(RenderState { .Expression = lib_name });
831830 }
832831 if (fn_proto.extern_export_inline_token) |extern_export_inline_token| {
833 try stack.push(RenderState { .Text = " " });
834 try stack.push(RenderState { .Text = tree.tokenSlice(extern_export_inline_token) });
832 try stack.append(RenderState { .Text = " " });
833 try stack.append(RenderState { .Text = tree.tokenSlice(extern_export_inline_token) });
835834 }
836835
837836 if (fn_proto.visib_token) |visib_token_index| {
838837 const visib_token = tree.tokens.at(visib_token_index);
839838 assert(visib_token.id == Token.Id.Keyword_pub or visib_token.id == Token.Id.Keyword_export);
840 try stack.push(RenderState { .Text = " " });
841 try stack.push(RenderState { .Text = tree.tokenSlice(visib_token_index) });
839 try stack.append(RenderState { .Text = " " });
840 try stack.append(RenderState { .Text = tree.tokenSlice(visib_token_index) });
842841 }
843842 },
844843 ast.Node.Id.PromiseType => {
......@@ -846,7 +845,7 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
846845 try stream.write(tree.tokenSlice(promise_type.promise_token));
847846 if (promise_type.result) |result| {
848847 try stream.write(tree.tokenSlice(result.arrow_token));
849 try stack.push(RenderState { .Expression = result.return_type});
848 try stack.append(RenderState { .Expression = result.return_type});
850849 }
851850 },
852851 ast.Node.Id.LineComment => {
......@@ -860,23 +859,23 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
860859 try stream.print("{} (", tree.tokenSlice(switch_node.switch_token));
861860
862861 if (switch_node.cases.len == 0) {
863 try stack.push(RenderState { .Text = ") {}"});
864 try stack.push(RenderState { .Expression = switch_node.expr });
862 try stack.append(RenderState { .Text = ") {}"});
863 try stack.append(RenderState { .Expression = switch_node.expr });
865864 continue;
866865 }
867866
868 try stack.push(RenderState { .Text = "}"});
869 try stack.push(RenderState.PrintIndent);
870 try stack.push(RenderState { .Indent = indent });
871 try stack.push(RenderState { .Text = "\n"});
867 try stack.append(RenderState { .Text = "}"});
868 try stack.append(RenderState.PrintIndent);
869 try stack.append(RenderState { .Indent = indent });
870 try stack.append(RenderState { .Text = "\n"});
872871
873872 var i = switch_node.cases.len;
874873 while (i != 0) {
875874 i -= 1;
876875 const node = *switch_node.cases.at(i);
877 try stack.push(RenderState { .Expression = node});
878 try stack.push(RenderState.PrintIndent);
879 try stack.push(RenderState {
876 try stack.append(RenderState { .Expression = node});
877 try stack.append(RenderState.PrintIndent);
878 try stack.append(RenderState {
880879 .Text = blk: {
881880 if (i != 0) {
882881 const prev_node = *switch_node.cases.at(i - 1);
......@@ -890,29 +889,29 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
890889 },
891890 });
892891 }
893 try stack.push(RenderState { .Indent = indent + indent_delta});
894 try stack.push(RenderState { .Text = ") {"});
895 try stack.push(RenderState { .Expression = switch_node.expr });
892 try stack.append(RenderState { .Indent = indent + indent_delta});
893 try stack.append(RenderState { .Text = ") {"});
894 try stack.append(RenderState { .Expression = switch_node.expr });
896895 },
897896 ast.Node.Id.SwitchCase => {
898897 const switch_case = @fieldParentPtr(ast.Node.SwitchCase, "base", base);
899898
900 try stack.push(RenderState { .Token = switch_case.lastToken() + 1 });
901 try stack.push(RenderState { .Expression = switch_case.expr });
899 try stack.append(RenderState { .Token = switch_case.lastToken() + 1 });
900 try stack.append(RenderState { .Expression = switch_case.expr });
902901 if (switch_case.payload) |payload| {
903 try stack.push(RenderState { .Text = " " });
904 try stack.push(RenderState { .Expression = payload });
902 try stack.append(RenderState { .Text = " " });
903 try stack.append(RenderState { .Expression = payload });
905904 }
906 try stack.push(RenderState { .Text = " => "});
905 try stack.append(RenderState { .Text = " => "});
907906
908907 var i = switch_case.items.len;
909908 while (i != 0) {
910909 i -= 1;
911 try stack.push(RenderState { .Expression = *switch_case.items.at(i) });
910 try stack.append(RenderState { .Expression = *switch_case.items.at(i) });
912911
913912 if (i != 0) {
914 try stack.push(RenderState.PrintIndent);
915 try stack.push(RenderState { .Text = ",\n" });
913 try stack.append(RenderState.PrintIndent);
914 try stack.append(RenderState { .Text = ",\n" });
916915 }
917916 }
918917 },
......@@ -929,20 +928,20 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
929928 ast.Node.Id.For, ast.Node.Id.While,
930929 ast.Node.Id.Switch => {
931930 try stream.print(" ");
932 try stack.push(RenderState { .Expression = else_node.body });
931 try stack.append(RenderState { .Expression = else_node.body });
933932 },
934933 else => {
935 try stack.push(RenderState { .Indent = indent });
936 try stack.push(RenderState { .Expression = else_node.body });
937 try stack.push(RenderState.PrintIndent);
938 try stack.push(RenderState { .Indent = indent + indent_delta });
939 try stack.push(RenderState { .Text = "\n" });
934 try stack.append(RenderState { .Indent = indent });
935 try stack.append(RenderState { .Expression = else_node.body });
936 try stack.append(RenderState.PrintIndent);
937 try stack.append(RenderState { .Indent = indent + indent_delta });
938 try stack.append(RenderState { .Text = "\n" });
940939 }
941940 }
942941
943942 if (else_node.payload) |payload| {
944 try stack.push(RenderState { .Text = " " });
945 try stack.push(RenderState { .Expression = payload });
943 try stack.append(RenderState { .Text = " " });
944 try stack.append(RenderState { .Expression = payload });
946945 }
947946 },
948947 ast.Node.Id.While => {
......@@ -958,42 +957,42 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
958957 try stream.print("{} ", tree.tokenSlice(while_node.while_token));
959958
960959 if (while_node.@"else") |@"else"| {
961 try stack.push(RenderState { .Expression = &@"else".base });
960 try stack.append(RenderState { .Expression = &@"else".base });
962961
963962 if (while_node.body.id == ast.Node.Id.Block) {
964 try stack.push(RenderState { .Text = " " });
963 try stack.append(RenderState { .Text = " " });
965964 } else {
966 try stack.push(RenderState.PrintIndent);
967 try stack.push(RenderState { .Text = "\n" });
965 try stack.append(RenderState.PrintIndent);
966 try stack.append(RenderState { .Text = "\n" });
968967 }
969968 }
970969
971970 if (while_node.body.id == ast.Node.Id.Block) {
972 try stack.push(RenderState { .Expression = while_node.body });
973 try stack.push(RenderState { .Text = " " });
971 try stack.append(RenderState { .Expression = while_node.body });
972 try stack.append(RenderState { .Text = " " });
974973 } else {
975 try stack.push(RenderState { .Indent = indent });
976 try stack.push(RenderState { .Expression = while_node.body });
977 try stack.push(RenderState.PrintIndent);
978 try stack.push(RenderState { .Indent = indent + indent_delta });
979 try stack.push(RenderState { .Text = "\n" });
974 try stack.append(RenderState { .Indent = indent });
975 try stack.append(RenderState { .Expression = while_node.body });
976 try stack.append(RenderState.PrintIndent);
977 try stack.append(RenderState { .Indent = indent + indent_delta });
978 try stack.append(RenderState { .Text = "\n" });
980979 }
981980
982981 if (while_node.continue_expr) |continue_expr| {
983 try stack.push(RenderState { .Text = ")" });
984 try stack.push(RenderState { .Expression = continue_expr });
985 try stack.push(RenderState { .Text = ": (" });
986 try stack.push(RenderState { .Text = " " });
982 try stack.append(RenderState { .Text = ")" });
983 try stack.append(RenderState { .Expression = continue_expr });
984 try stack.append(RenderState { .Text = ": (" });
985 try stack.append(RenderState { .Text = " " });
987986 }
988987
989988 if (while_node.payload) |payload| {
990 try stack.push(RenderState { .Expression = payload });
991 try stack.push(RenderState { .Text = " " });
989 try stack.append(RenderState { .Expression = payload });
990 try stack.append(RenderState { .Text = " " });
992991 }
993992
994 try stack.push(RenderState { .Text = ")" });
995 try stack.push(RenderState { .Expression = while_node.condition });
996 try stack.push(RenderState { .Text = "(" });
993 try stack.append(RenderState { .Text = ")" });
994 try stack.append(RenderState { .Expression = while_node.condition });
995 try stack.append(RenderState { .Text = "(" });
997996 },
998997 ast.Node.Id.For => {
999998 const for_node = @fieldParentPtr(ast.Node.For, "base", base);
......@@ -1008,35 +1007,35 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
10081007 try stream.print("{} ", tree.tokenSlice(for_node.for_token));
10091008
10101009 if (for_node.@"else") |@"else"| {
1011 try stack.push(RenderState { .Expression = &@"else".base });
1010 try stack.append(RenderState { .Expression = &@"else".base });
10121011
10131012 if (for_node.body.id == ast.Node.Id.Block) {
1014 try stack.push(RenderState { .Text = " " });
1013 try stack.append(RenderState { .Text = " " });
10151014 } else {
1016 try stack.push(RenderState.PrintIndent);
1017 try stack.push(RenderState { .Text = "\n" });
1015 try stack.append(RenderState.PrintIndent);
1016 try stack.append(RenderState { .Text = "\n" });
10181017 }
10191018 }
10201019
10211020 if (for_node.body.id == ast.Node.Id.Block) {
1022 try stack.push(RenderState { .Expression = for_node.body });
1023 try stack.push(RenderState { .Text = " " });
1021 try stack.append(RenderState { .Expression = for_node.body });
1022 try stack.append(RenderState { .Text = " " });
10241023 } else {
1025 try stack.push(RenderState { .Indent = indent });
1026 try stack.push(RenderState { .Expression = for_node.body });
1027 try stack.push(RenderState.PrintIndent);
1028 try stack.push(RenderState { .Indent = indent + indent_delta });
1029 try stack.push(RenderState { .Text = "\n" });
1024 try stack.append(RenderState { .Indent = indent });
1025 try stack.append(RenderState { .Expression = for_node.body });
1026 try stack.append(RenderState.PrintIndent);
1027 try stack.append(RenderState { .Indent = indent + indent_delta });
1028 try stack.append(RenderState { .Text = "\n" });
10301029 }
10311030
10321031 if (for_node.payload) |payload| {
1033 try stack.push(RenderState { .Expression = payload });
1034 try stack.push(RenderState { .Text = " " });
1032 try stack.append(RenderState { .Expression = payload });
1033 try stack.append(RenderState { .Text = " " });
10351034 }
10361035
1037 try stack.push(RenderState { .Text = ")" });
1038 try stack.push(RenderState { .Expression = for_node.array_expr });
1039 try stack.push(RenderState { .Text = "(" });
1036 try stack.append(RenderState { .Text = ")" });
1037 try stack.append(RenderState { .Expression = for_node.array_expr });
1038 try stack.append(RenderState { .Text = "(" });
10401039 },
10411040 ast.Node.Id.If => {
10421041 const if_node = @fieldParentPtr(ast.Node.If, "base", base);
......@@ -1047,42 +1046,42 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
10471046 ast.Node.Id.For, ast.Node.Id.While,
10481047 ast.Node.Id.Switch => {
10491048 if (if_node.@"else") |@"else"| {
1050 try stack.push(RenderState { .Expression = &@"else".base });
1049 try stack.append(RenderState { .Expression = &@"else".base });
10511050
10521051 if (if_node.body.id == ast.Node.Id.Block) {
1053 try stack.push(RenderState { .Text = " " });
1052 try stack.append(RenderState { .Text = " " });
10541053 } else {
1055 try stack.push(RenderState.PrintIndent);
1056 try stack.push(RenderState { .Text = "\n" });
1054 try stack.append(RenderState.PrintIndent);
1055 try stack.append(RenderState { .Text = "\n" });
10571056 }
10581057 }
10591058 },
10601059 else => {
10611060 if (if_node.@"else") |@"else"| {
1062 try stack.push(RenderState { .Expression = @"else".body });
1061 try stack.append(RenderState { .Expression = @"else".body });
10631062
10641063 if (@"else".payload) |payload| {
1065 try stack.push(RenderState { .Text = " " });
1066 try stack.push(RenderState { .Expression = payload });
1064 try stack.append(RenderState { .Text = " " });
1065 try stack.append(RenderState { .Expression = payload });
10671066 }
10681067
1069 try stack.push(RenderState { .Text = " " });
1070 try stack.push(RenderState { .Text = tree.tokenSlice(@"else".else_token) });
1071 try stack.push(RenderState { .Text = " " });
1068 try stack.append(RenderState { .Text = " " });
1069 try stack.append(RenderState { .Text = tree.tokenSlice(@"else".else_token) });
1070 try stack.append(RenderState { .Text = " " });
10721071 }
10731072 }
10741073 }
10751074
1076 try stack.push(RenderState { .Expression = if_node.body });
1075 try stack.append(RenderState { .Expression = if_node.body });
10771076
10781077 if (if_node.payload) |payload| {
1079 try stack.push(RenderState { .Text = " " });
1080 try stack.push(RenderState { .Expression = payload });
1078 try stack.append(RenderState { .Text = " " });
1079 try stack.append(RenderState { .Expression = payload });
10811080 }
10821081
1083 try stack.push(RenderState { .NonBreakToken = if_node.condition.lastToken() + 1 });
1084 try stack.push(RenderState { .Expression = if_node.condition });
1085 try stack.push(RenderState { .Text = "(" });
1082 try stack.append(RenderState { .NonBreakToken = if_node.condition.lastToken() + 1 });
1083 try stack.append(RenderState { .Expression = if_node.condition });
1084 try stack.append(RenderState { .Text = "(" });
10861085 },
10871086 ast.Node.Id.Asm => {
10881087 const asm_node = @fieldParentPtr(ast.Node.Asm, "base", base);
......@@ -1092,33 +1091,33 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
10921091 try stream.print("{} ", tree.tokenSlice(volatile_token));
10931092 }
10941093
1095 try stack.push(RenderState { .Indent = indent });
1096 try stack.push(RenderState { .Text = ")" });
1094 try stack.append(RenderState { .Indent = indent });
1095 try stack.append(RenderState { .Text = ")" });
10971096 {
10981097 var i = asm_node.clobbers.len;
10991098 while (i != 0) {
11001099 i -= 1;
1101 try stack.push(RenderState { .Expression = *asm_node.clobbers.at(i) });
1100 try stack.append(RenderState { .Expression = *asm_node.clobbers.at(i) });
11021101
11031102 if (i != 0) {
1104 try stack.push(RenderState { .Text = ", " });
1103 try stack.append(RenderState { .Text = ", " });
11051104 }
11061105 }
11071106 }
1108 try stack.push(RenderState { .Text = ": " });
1109 try stack.push(RenderState.PrintIndent);
1110 try stack.push(RenderState { .Indent = indent + indent_delta });
1111 try stack.push(RenderState { .Text = "\n" });
1107 try stack.append(RenderState { .Text = ": " });
1108 try stack.append(RenderState.PrintIndent);
1109 try stack.append(RenderState { .Indent = indent + indent_delta });
1110 try stack.append(RenderState { .Text = "\n" });
11121111 {
11131112 var i = asm_node.inputs.len;
11141113 while (i != 0) {
11151114 i -= 1;
11161115 const node = *asm_node.inputs.at(i);
1117 try stack.push(RenderState { .Expression = &node.base});
1116 try stack.append(RenderState { .Expression = &node.base});
11181117
11191118 if (i != 0) {
1120 try stack.push(RenderState.PrintIndent);
1121 try stack.push(RenderState {
1119 try stack.append(RenderState.PrintIndent);
1120 try stack.append(RenderState {
11221121 .Text = blk: {
11231122 const prev_node = *asm_node.inputs.at(i - 1);
11241123 const prev_node_last_token_end = tree.tokens.at(prev_node.lastToken()).end;
......@@ -1129,25 +1128,25 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
11291128 break :blk "\n";
11301129 },
11311130 });
1132 try stack.push(RenderState { .Text = "," });
1131 try stack.append(RenderState { .Text = "," });
11331132 }
11341133 }
11351134 }
1136 try stack.push(RenderState { .Indent = indent + indent_delta + 2});
1137 try stack.push(RenderState { .Text = ": "});
1138 try stack.push(RenderState.PrintIndent);
1139 try stack.push(RenderState { .Indent = indent + indent_delta});
1140 try stack.push(RenderState { .Text = "\n" });
1135 try stack.append(RenderState { .Indent = indent + indent_delta + 2});
1136 try stack.append(RenderState { .Text = ": "});
1137 try stack.append(RenderState.PrintIndent);
1138 try stack.append(RenderState { .Indent = indent + indent_delta});
1139 try stack.append(RenderState { .Text = "\n" });
11411140 {
11421141 var i = asm_node.outputs.len;
11431142 while (i != 0) {
11441143 i -= 1;
11451144 const node = *asm_node.outputs.at(i);
1146 try stack.push(RenderState { .Expression = &node.base});
1145 try stack.append(RenderState { .Expression = &node.base});
11471146
11481147 if (i != 0) {
1149 try stack.push(RenderState.PrintIndent);
1150 try stack.push(RenderState {
1148 try stack.append(RenderState.PrintIndent);
1149 try stack.append(RenderState {
11511150 .Text = blk: {
11521151 const prev_node = *asm_node.outputs.at(i - 1);
11531152 const prev_node_last_token_end = tree.tokens.at(prev_node.lastToken()).end;
......@@ -1158,47 +1157,47 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
11581157 break :blk "\n";
11591158 },
11601159 });
1161 try stack.push(RenderState { .Text = "," });
1160 try stack.append(RenderState { .Text = "," });
11621161 }
11631162 }
11641163 }
1165 try stack.push(RenderState { .Indent = indent + indent_delta + 2});
1166 try stack.push(RenderState { .Text = ": "});
1167 try stack.push(RenderState.PrintIndent);
1168 try stack.push(RenderState { .Indent = indent + indent_delta});
1169 try stack.push(RenderState { .Text = "\n" });
1170 try stack.push(RenderState { .Expression = asm_node.template });
1171 try stack.push(RenderState { .Text = "(" });
1164 try stack.append(RenderState { .Indent = indent + indent_delta + 2});
1165 try stack.append(RenderState { .Text = ": "});
1166 try stack.append(RenderState.PrintIndent);
1167 try stack.append(RenderState { .Indent = indent + indent_delta});
1168 try stack.append(RenderState { .Text = "\n" });
1169 try stack.append(RenderState { .Expression = asm_node.template });
1170 try stack.append(RenderState { .Text = "(" });
11721171 },
11731172 ast.Node.Id.AsmInput => {
11741173 const asm_input = @fieldParentPtr(ast.Node.AsmInput, "base", base);
11751174
1176 try stack.push(RenderState { .Text = ")"});
1177 try stack.push(RenderState { .Expression = asm_input.expr});
1178 try stack.push(RenderState { .Text = " ("});
1179 try stack.push(RenderState { .Expression = asm_input.constraint });
1180 try stack.push(RenderState { .Text = "] "});
1181 try stack.push(RenderState { .Expression = asm_input.symbolic_name });
1182 try stack.push(RenderState { .Text = "["});
1175 try stack.append(RenderState { .Text = ")"});
1176 try stack.append(RenderState { .Expression = asm_input.expr});
1177 try stack.append(RenderState { .Text = " ("});
1178 try stack.append(RenderState { .Expression = asm_input.constraint });
1179 try stack.append(RenderState { .Text = "] "});
1180 try stack.append(RenderState { .Expression = asm_input.symbolic_name });
1181 try stack.append(RenderState { .Text = "["});
11831182 },
11841183 ast.Node.Id.AsmOutput => {
11851184 const asm_output = @fieldParentPtr(ast.Node.AsmOutput, "base", base);
11861185
1187 try stack.push(RenderState { .Text = ")"});
1186 try stack.append(RenderState { .Text = ")"});
11881187 switch (asm_output.kind) {
11891188 ast.Node.AsmOutput.Kind.Variable => |variable_name| {
1190 try stack.push(RenderState { .Expression = &variable_name.base});
1189 try stack.append(RenderState { .Expression = &variable_name.base});
11911190 },
11921191 ast.Node.AsmOutput.Kind.Return => |return_type| {
1193 try stack.push(RenderState { .Expression = return_type});
1194 try stack.push(RenderState { .Text = "-> "});
1192 try stack.append(RenderState { .Expression = return_type});
1193 try stack.append(RenderState { .Text = "-> "});
11951194 },
11961195 }
1197 try stack.push(RenderState { .Text = " ("});
1198 try stack.push(RenderState { .Expression = asm_output.constraint });
1199 try stack.push(RenderState { .Text = "] "});
1200 try stack.push(RenderState { .Expression = asm_output.symbolic_name });
1201 try stack.push(RenderState { .Text = "["});
1196 try stack.append(RenderState { .Text = " ("});
1197 try stack.append(RenderState { .Expression = asm_output.constraint });
1198 try stack.append(RenderState { .Text = "] "});
1199 try stack.append(RenderState { .Expression = asm_output.symbolic_name });
1200 try stack.append(RenderState { .Text = "["});
12021201 },
12031202
12041203 ast.Node.Id.StructField,
......@@ -1215,11 +1214,11 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) !void {
12151214 switch (base.id) {
12161215 ast.Node.Id.VarDecl => {
12171216 const var_decl = @fieldParentPtr(ast.Node.VarDecl, "base", base);
1218 try stack.push(RenderState { .VarDecl = var_decl});
1217 try stack.append(RenderState { .VarDecl = var_decl});
12191218 },
12201219 else => {
1221 try stack.push(RenderState { .MaybeSemiColon = base });
1222 try stack.push(RenderState { .Expression = base });
1220 try stack.append(RenderState { .MaybeSemiColon = base });
1221 try stack.append(RenderState { .Expression = base });
12231222 },
12241223 }
12251224 },