| author | |
| committer | |
| log | 02c5bda704d30e95e6af23804f9a552e9d8ca2d7 |
| tree | bb7ebbd3bfd59dbf5ac9a97364feb57868a45281 |
| parent | 442e244b4dd371d674436a163d62efdcd4e17a00 |
closes #8035 files changed, 5 insertions(+), 42 deletions(-)
doc/langref.html.in+1-1| ... | ... | @@ -7336,7 +7336,7 @@ Defer(body) = ("defer" | "deferror") body |
| 7336 | 7336 | |
| 7337 | 7337 | IfExpression(body) = "if" "(" Expression ")" body option("else" BlockExpression(body)) |
| 7338 | 7338 | |
| 7339 | SuspendExpression(body) = option(Symbol ":") "suspend" option(("|" Symbol "|" body)) | |
| 7339 | SuspendExpression(body) = "suspend" option(("|" Symbol "|" body)) | |
| 7340 | 7340 | |
| 7341 | 7341 | IfErrorExpression(body) = "if" "(" Expression ")" option("|" option("*") Symbol "|") body "else" "|" Symbol "|" BlockExpression(body) |
| 7342 | 7342 |
src/all_types.hpp-2| ... | ... | @@ -898,7 +898,6 @@ struct AstNodeAwaitExpr { |
| 898 | 898 | }; |
| 899 | 899 | |
| 900 | 900 | struct AstNodeSuspend { |
| 901 | Buf *name; | |
| 902 | 901 | AstNode *block; |
| 903 | 902 | AstNode *promise_symbol; |
| 904 | 903 | }; |
| ... | ... | @@ -1929,7 +1928,6 @@ struct ScopeLoop { |
| 1929 | 1928 | struct ScopeSuspend { |
| 1930 | 1929 | Scope base; |
| 1931 | 1930 | |
| 1932 | Buf *name; | |
| 1933 | 1931 | IrBasicBlock *resume_block; |
| 1934 | 1932 | bool reported_err; |
| 1935 | 1933 | }; |
src/analyze.cpp-1| ... | ... | @@ -161,7 +161,6 @@ ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent) { |
| 161 | 161 | assert(node->type == NodeTypeSuspend); |
| 162 | 162 | ScopeSuspend *scope = allocate<ScopeSuspend>(1); |
| 163 | 163 | init_scope(&scope->base, ScopeIdSuspend, node, parent); |
| 164 | scope->name = node->data.suspend.name; | |
| 165 | 164 | return scope; |
| 166 | 165 | } |
| 167 | 166 |
src/ir.cpp+2-15| ... | ... | @@ -6186,15 +6186,6 @@ static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scop |
| 6186 | 6186 | return ir_build_br(irb, break_scope, node, dest_block, is_comptime); |
| 6187 | 6187 | } |
| 6188 | 6188 | |
| 6189 | static IrInstruction *ir_gen_break_from_suspend(IrBuilder *irb, Scope *break_scope, AstNode *node, ScopeSuspend *suspend_scope) { | |
| 6190 | IrInstruction *is_comptime = ir_build_const_bool(irb, break_scope, node, false); | |
| 6191 | ||
| 6192 | IrBasicBlock *dest_block = suspend_scope->resume_block; | |
| 6193 | ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false); | |
| 6194 | ||
| 6195 | return ir_build_br(irb, break_scope, node, dest_block, is_comptime); | |
| 6196 | } | |
| 6197 | ||
| 6198 | 6189 | static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *node) { |
| 6199 | 6190 | assert(node->type == NodeTypeBreak); |
| 6200 | 6191 | |
| ... | ... | @@ -6235,12 +6226,8 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode * |
| 6235 | 6226 | return ir_gen_return_from_block(irb, break_scope, node, this_block_scope); |
| 6236 | 6227 | } |
| 6237 | 6228 | } else if (search_scope->id == ScopeIdSuspend) { |
| 6238 | ScopeSuspend *this_suspend_scope = (ScopeSuspend *)search_scope; | |
| 6239 | if (node->data.break_expr.name != nullptr && | |
| 6240 | (this_suspend_scope->name != nullptr && buf_eql_buf(node->data.break_expr.name, this_suspend_scope->name))) | |
| 6241 | { | |
| 6242 | return ir_gen_break_from_suspend(irb, break_scope, node, this_suspend_scope); | |
| 6243 | } | |
| 6229 | add_node_error(irb->codegen, node, buf_sprintf("cannot break out of suspend block")); | |
| 6230 | return irb->codegen->invalid_instruction; | |
| 6244 | 6231 | } |
| 6245 | 6232 | search_scope = search_scope->parent; |
| 6246 | 6233 | } |
src/parser.cpp+2-23| ... | ... | @@ -648,30 +648,12 @@ static AstNode *ast_parse_asm_expr(ParseContext *pc, size_t *token_index, bool m |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | /* |
| 651 | SuspendExpression(body) = option(Symbol ":") "suspend" option(("|" Symbol "|" body)) | |
| 651 | SuspendExpression(body) = "suspend" option(("|" Symbol "|" body)) | |
| 652 | 652 | */ |
| 653 | 653 | static AstNode *ast_parse_suspend_block(ParseContext *pc, size_t *token_index, bool mandatory) { |
| 654 | 654 | size_t orig_token_index = *token_index; |
| 655 | 655 | |
| 656 | Token *name_token = nullptr; | |
| 657 | Token *token = &pc->tokens->at(*token_index); | |
| 658 | if (token->id == TokenIdSymbol) { | |
| 659 | *token_index += 1; | |
| 660 | Token *colon_token = &pc->tokens->at(*token_index); | |
| 661 | if (colon_token->id == TokenIdColon) { | |
| 662 | *token_index += 1; | |
| 663 | name_token = token; | |
| 664 | token = &pc->tokens->at(*token_index); | |
| 665 | } else if (mandatory) { | |
| 666 | ast_expect_token(pc, colon_token, TokenIdColon); | |
| 667 | zig_unreachable(); | |
| 668 | } else { | |
| 669 | *token_index = orig_token_index; | |
| 670 | return nullptr; | |
| 671 | } | |
| 672 | } | |
| 673 | ||
| 674 | Token *suspend_token = token; | |
| 656 | Token *suspend_token = &pc->tokens->at(*token_index); | |
| 675 | 657 | if (suspend_token->id == TokenIdKeywordSuspend) { |
| 676 | 658 | *token_index += 1; |
| 677 | 659 | } else if (mandatory) { |
| ... | ... | @@ -693,9 +675,6 @@ static AstNode *ast_parse_suspend_block(ParseContext *pc, size_t *token_index, b |
| 693 | 675 | } |
| 694 | 676 | |
| 695 | 677 | AstNode *node = ast_create_node(pc, NodeTypeSuspend, suspend_token); |
| 696 | if (name_token != nullptr) { | |
| 697 | node->data.suspend.name = token_buf(name_token); | |
| 698 | } | |
| 699 | 678 | node->data.suspend.promise_symbol = ast_parse_symbol(pc, token_index); |
| 700 | 679 | ast_eat_token(pc, token_index, TokenIdBinOr); |
| 701 | 680 | node->data.suspend.block = ast_parse_block(pc, token_index, true); |