| ... | ... | @@ -708,7 +708,7 @@ pub const Builder = struct { |
| 708 | 708 | self.current_basic_block = basic_block; |
| 709 | 709 | } |
| 710 | 710 | |
| 711 | | pub fn genNode(irb: *Builder, node: *ast.Node, scope: *Scope, lval: LVal) Error!*Inst { |
| 711 | pub async fn genNode(irb: *Builder, node: *ast.Node, scope: *Scope, lval: LVal) Error!*Inst { |
| 712 | 712 | switch (node.id) { |
| 713 | 713 | ast.Node.Id.Root => unreachable, |
| 714 | 714 | ast.Node.Id.Use => unreachable, |
| ... | ... | @@ -724,7 +724,7 @@ pub const Builder = struct { |
| 724 | 724 | ast.Node.Id.If => return error.Unimplemented, |
| 725 | 725 | ast.Node.Id.ControlFlowExpression => { |
| 726 | 726 | const control_flow_expr = @fieldParentPtr(ast.Node.ControlFlowExpression, "base", node); |
| 727 | | return irb.genControlFlowExpr(control_flow_expr, scope, lval); |
| 727 | return await (async irb.genControlFlowExpr(control_flow_expr, scope, lval) catch unreachable); |
| 728 | 728 | }, |
| 729 | 729 | ast.Node.Id.Suspend => return error.Unimplemented, |
| 730 | 730 | ast.Node.Id.VarType => return error.Unimplemented, |
| ... | ... | @@ -746,11 +746,11 @@ pub const Builder = struct { |
| 746 | 746 | ast.Node.Id.Unreachable => return error.Unimplemented, |
| 747 | 747 | ast.Node.Id.Identifier => { |
| 748 | 748 | const identifier = @fieldParentPtr(ast.Node.Identifier, "base", node); |
| 749 | | return irb.genIdentifier(identifier, scope, lval); |
| 749 | return await (async irb.genIdentifier(identifier, scope, lval) catch unreachable); |
| 750 | 750 | }, |
| 751 | 751 | ast.Node.Id.GroupedExpression => { |
| 752 | 752 | const grouped_expr = @fieldParentPtr(ast.Node.GroupedExpression, "base", node); |
| 753 | | return irb.genNode(grouped_expr.expr, scope, lval); |
| 753 | return await (async irb.genNode(grouped_expr.expr, scope, lval) catch unreachable); |
| 754 | 754 | }, |
| 755 | 755 | ast.Node.Id.BuiltinCall => return error.Unimplemented, |
| 756 | 756 | ast.Node.Id.ErrorSetDecl => return error.Unimplemented, |
| ... | ... | @@ -759,7 +759,8 @@ pub const Builder = struct { |
| 759 | 759 | ast.Node.Id.Comptime => return error.Unimplemented, |
| 760 | 760 | ast.Node.Id.Block => { |
| 761 | 761 | const block = @fieldParentPtr(ast.Node.Block, "base", node); |
| 762 | | return irb.lvalWrap(scope, try irb.genBlock(block, scope), lval); |
| 762 | const inst = try await (async irb.genBlock(block, scope) catch unreachable); |
| 763 | return irb.lvalWrap(scope, inst, lval); |
| 763 | 764 | }, |
| 764 | 765 | ast.Node.Id.DocComment => return error.Unimplemented, |
| 765 | 766 | ast.Node.Id.SwitchCase => return error.Unimplemented, |
| ... | ... | @@ -838,7 +839,7 @@ pub const Builder = struct { |
| 838 | 839 | return inst; |
| 839 | 840 | } |
| 840 | 841 | |
| 841 | | pub fn genBlock(irb: *Builder, block: *ast.Node.Block, parent_scope: *Scope) !*Inst { |
| 842 | pub async fn genBlock(irb: *Builder, block: *ast.Node.Block, parent_scope: *Scope) !*Inst { |
| 842 | 843 | const block_scope = try Scope.Block.create(irb.comp, parent_scope); |
| 843 | 844 | |
| 844 | 845 | const outer_block_scope = &block_scope.base; |
| ... | ... | @@ -886,7 +887,7 @@ pub const Builder = struct { |
| 886 | 887 | child_scope = &defer_child_scope.base; |
| 887 | 888 | continue; |
| 888 | 889 | } |
| 889 | | const statement_value = try irb.genNode(statement_node, child_scope, LVal.None); |
| 890 | const statement_value = try await (async irb.genNode(statement_node, child_scope, LVal.None) catch unreachable); |
| 890 | 891 | |
| 891 | 892 | is_continuation_unreachable = statement_value.isNoReturn(); |
| 892 | 893 | if (is_continuation_unreachable) { |
| ... | ... | @@ -926,7 +927,7 @@ pub const Builder = struct { |
| 926 | 927 | try block_scope.incoming_values.append( |
| 927 | 928 | try irb.buildConstVoid(parent_scope, Span.token(block.rbrace), true), |
| 928 | 929 | ); |
| 929 | | _ = try irb.genDefersForBlock(child_scope, outer_block_scope, Scope.Defer.Kind.ScopeExit); |
| 930 | _ = try await (async irb.genDefersForBlock(child_scope, outer_block_scope, Scope.Defer.Kind.ScopeExit) catch unreachable); |
| 930 | 931 | |
| 931 | 932 | _ = try irb.buildGen(Inst.Br, parent_scope, Span.token(block.rbrace), Inst.Br.Params{ |
| 932 | 933 | .dest_block = block_scope.end_block, |
| ... | ... | @@ -941,11 +942,11 @@ pub const Builder = struct { |
| 941 | 942 | }); |
| 942 | 943 | } |
| 943 | 944 | |
| 944 | | _ = try irb.genDefersForBlock(child_scope, outer_block_scope, Scope.Defer.Kind.ScopeExit); |
| 945 | _ = try await (async irb.genDefersForBlock(child_scope, outer_block_scope, Scope.Defer.Kind.ScopeExit) catch unreachable); |
| 945 | 946 | return irb.buildConstVoid(child_scope, Span.token(block.rbrace), true); |
| 946 | 947 | } |
| 947 | 948 | |
| 948 | | pub fn genControlFlowExpr( |
| 949 | pub async fn genControlFlowExpr( |
| 949 | 950 | irb: *Builder, |
| 950 | 951 | control_flow_expr: *ast.Node.ControlFlowExpression, |
| 951 | 952 | scope: *Scope, |
| ... | ... | @@ -979,7 +980,7 @@ pub const Builder = struct { |
| 979 | 980 | |
| 980 | 981 | const outer_scope = irb.begin_scope.?; |
| 981 | 982 | const return_value = if (control_flow_expr.rhs) |rhs| blk: { |
| 982 | | break :blk try irb.genNode(rhs, scope, LVal.None); |
| 983 | break :blk try await (async irb.genNode(rhs, scope, LVal.None) catch unreachable); |
| 983 | 984 | } else blk: { |
| 984 | 985 | break :blk try irb.buildConstVoid(scope, src_span, true); |
| 985 | 986 | }; |
| ... | ... | @@ -990,7 +991,7 @@ pub const Builder = struct { |
| 990 | 991 | const err_block = try irb.createBasicBlock(scope, c"ErrRetErr"); |
| 991 | 992 | const ok_block = try irb.createBasicBlock(scope, c"ErrRetOk"); |
| 992 | 993 | if (!have_err_defers) { |
| 993 | | _ = try irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit); |
| 994 | _ = try await (async irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit) catch unreachable); |
| 994 | 995 | } |
| 995 | 996 | |
| 996 | 997 | const is_err = try irb.build( |
| ... | ... | @@ -1013,7 +1014,7 @@ pub const Builder = struct { |
| 1013 | 1014 | |
| 1014 | 1015 | try irb.setCursorAtEndAndAppendBlock(err_block); |
| 1015 | 1016 | if (have_err_defers) { |
| 1016 | | _ = try irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ErrorExit); |
| 1017 | _ = try await (async irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ErrorExit) catch unreachable); |
| 1017 | 1018 | } |
| 1018 | 1019 | if (irb.comp.have_err_ret_tracing and !irb.isCompTime(scope)) { |
| 1019 | 1020 | _ = try irb.build(Inst.SaveErrRetAddr, scope, src_span, Inst.SaveErrRetAddr.Params{}); |
| ... | ... | @@ -1025,7 +1026,7 @@ pub const Builder = struct { |
| 1025 | 1026 | |
| 1026 | 1027 | try irb.setCursorAtEndAndAppendBlock(ok_block); |
| 1027 | 1028 | if (have_err_defers) { |
| 1028 | | _ = try irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit); |
| 1029 | _ = try await (async irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit) catch unreachable); |
| 1029 | 1030 | } |
| 1030 | 1031 | _ = try irb.build(Inst.Br, scope, src_span, Inst.Br.Params{ |
| 1031 | 1032 | .dest_block = ret_stmt_block, |
| ... | ... | @@ -1035,14 +1036,14 @@ pub const Builder = struct { |
| 1035 | 1036 | try irb.setCursorAtEndAndAppendBlock(ret_stmt_block); |
| 1036 | 1037 | return irb.genAsyncReturn(scope, src_span, return_value, false); |
| 1037 | 1038 | } else { |
| 1038 | | _ = try irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit); |
| 1039 | _ = try await (async irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit) catch unreachable); |
| 1039 | 1040 | return irb.genAsyncReturn(scope, src_span, return_value, false); |
| 1040 | 1041 | } |
| 1041 | 1042 | }, |
| 1042 | 1043 | } |
| 1043 | 1044 | } |
| 1044 | 1045 | |
| 1045 | | pub fn genIdentifier(irb: *Builder, identifier: *ast.Node.Identifier, scope: *Scope, lval: LVal) !*Inst { |
| 1046 | pub async fn genIdentifier(irb: *Builder, identifier: *ast.Node.Identifier, scope: *Scope, lval: LVal) !*Inst { |
| 1046 | 1047 | const src_span = Span.token(identifier.token); |
| 1047 | 1048 | const name = irb.root_scope.tree.tokenSlice(identifier.token); |
| 1048 | 1049 | |
| ... | ... | @@ -1055,7 +1056,7 @@ pub const Builder = struct { |
| 1055 | 1056 | // return &const_instruction->base; |
| 1056 | 1057 | //} |
| 1057 | 1058 | |
| 1058 | | if (irb.comp.getPrimitiveType(name)) |result| { |
| 1059 | if (await (async irb.comp.getPrimitiveType(name) catch unreachable)) |result| { |
| 1059 | 1060 | if (result) |primitive_type| { |
| 1060 | 1061 | defer primitive_type.base.deref(irb.comp); |
| 1061 | 1062 | switch (lval) { |
| ... | ... | @@ -1068,6 +1069,7 @@ pub const Builder = struct { |
| 1068 | 1069 | try irb.comp.addCompileError(irb.root_scope, src_span, "integer too large"); |
| 1069 | 1070 | return error.SemanticAnalysisFailed; |
| 1070 | 1071 | }, |
| 1072 | error.OutOfMemory => return error.OutOfMemory, |
| 1071 | 1073 | } |
| 1072 | 1074 | //TypeTableEntry *primitive_type = get_primitive_type(irb->codegen, variable_name); |
| 1073 | 1075 | //if (primitive_type != nullptr) { |
| ... | ... | @@ -1138,7 +1140,7 @@ pub const Builder = struct { |
| 1138 | 1140 | return result; |
| 1139 | 1141 | } |
| 1140 | 1142 | |
| 1141 | | fn genDefersForBlock( |
| 1143 | async fn genDefersForBlock( |
| 1142 | 1144 | irb: *Builder, |
| 1143 | 1145 | inner_scope: *Scope, |
| 1144 | 1146 | outer_scope: *Scope, |
| ... | ... | @@ -1156,11 +1158,11 @@ pub const Builder = struct { |
| 1156 | 1158 | }; |
| 1157 | 1159 | if (generate) { |
| 1158 | 1160 | const defer_expr_scope = defer_scope.defer_expr_scope; |
| 1159 | | const instruction = try irb.genNode( |
| 1161 | const instruction = try await (async irb.genNode( |
| 1160 | 1162 | defer_expr_scope.expr_node, |
| 1161 | 1163 | &defer_expr_scope.base, |
| 1162 | 1164 | LVal.None, |
| 1163 | | ); |
| 1165 | ) catch unreachable); |
| 1164 | 1166 | if (instruction.isNoReturn()) { |
| 1165 | 1167 | is_noreturn = true; |
| 1166 | 1168 | } else { |
| ... | ... | @@ -1909,7 +1911,7 @@ pub async fn gen( |
| 1909 | 1911 | entry_block.ref(); // Entry block gets a reference because we enter it to begin. |
| 1910 | 1912 | try irb.setCursorAtEndAndAppendBlock(entry_block); |
| 1911 | 1913 | |
| 1912 | | const result = try irb.genNode(body_node, scope, LVal.None); |
| 1914 | const result = try await (async irb.genNode(body_node, scope, LVal.None) catch unreachable); |
| 1913 | 1915 | if (!result.isNoReturn()) { |
| 1914 | 1916 | // no need for save_err_ret_addr because this cannot return error |
| 1915 | 1917 | _ = try irb.genAsyncReturn(scope, Span.token(body_node.lastToken()), result, true); |