| ... | @@ -107,11 +107,17 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr | ... | @@ -107,11 +107,17 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr |
| 107 | .NullLiteral => return rlWrap(mod, scope, rl, try nullLiteral(mod, scope, node.castTag(.NullLiteral).?)), | 107 | .NullLiteral => return rlWrap(mod, scope, rl, try nullLiteral(mod, scope, node.castTag(.NullLiteral).?)), |
| 108 | .OptionalType => return rlWrap(mod, scope, rl, try optionalType(mod, scope, node.castTag(.OptionalType).?)), | 108 | .OptionalType => return rlWrap(mod, scope, rl, try optionalType(mod, scope, node.castTag(.OptionalType).?)), |
| 109 | .UnwrapOptional => return unwrapOptional(mod, scope, rl, node.castTag(.UnwrapOptional).?), | 109 | .UnwrapOptional => return unwrapOptional(mod, scope, rl, node.castTag(.UnwrapOptional).?), |
| | 110 | .Block => return blockExpr(mod, scope, rl, node.castTag(.Block).?), |
| 110 | else => return mod.failNode(scope, node, "TODO implement astgen.Expr for {}", .{@tagName(node.tag)}), | 111 | else => return mod.failNode(scope, node, "TODO implement astgen.Expr for {}", .{@tagName(node.tag)}), |
| 111 | } | 112 | } |
| 112 | } | 113 | } |
| 113 | | 114 | |
| 114 | pub fn blockExpr(mod: *Module, parent_scope: *Scope, block_node: *ast.Node.Block) !void { | 115 | pub fn blockExpr( |
| | 116 | mod: *Module, |
| | 117 | parent_scope: *Scope, |
| | 118 | rl: ResultLoc, |
| | 119 | block_node: *ast.Node.Block, |
| | 120 | ) InnerError!*zir.Inst { |
| 115 | const tracy = trace(@src()); | 121 | const tracy = trace(@src()); |
| 116 | defer tracy.end(); | 122 | defer tracy.end(); |
| 117 | | 123 | |
| ... | @@ -122,9 +128,11 @@ pub fn blockExpr(mod: *Module, parent_scope: *Scope, block_node: *ast.Node.Block | ... | @@ -122,9 +128,11 @@ pub fn blockExpr(mod: *Module, parent_scope: *Scope, block_node: *ast.Node.Block |
| 122 | var block_arena = std.heap.ArenaAllocator.init(mod.gpa); | 128 | var block_arena = std.heap.ArenaAllocator.init(mod.gpa); |
| 123 | defer block_arena.deinit(); | 129 | defer block_arena.deinit(); |
| 124 | | 130 | |
| | 131 | const tree = parent_scope.tree(); |
| | 132 | |
| 125 | var scope = parent_scope; | 133 | var scope = parent_scope; |
| 126 | for (block_node.statements()) |statement| { | 134 | for (block_node.statements()) |statement| { |
| 127 | const src = scope.tree().token_locs[statement.firstToken()].start; | 135 | const src = tree.token_locs[statement.firstToken()].start; |
| 128 | _ = try addZIRNoOp(mod, scope, src, .dbg_stmt); | 136 | _ = try addZIRNoOp(mod, scope, src, .dbg_stmt); |
| 129 | switch (statement.tag) { | 137 | switch (statement.tag) { |
| 130 | .VarDecl => { | 138 | .VarDecl => { |
| ... | @@ -154,6 +162,12 @@ pub fn blockExpr(mod: *Module, parent_scope: *Scope, block_node: *ast.Node.Block | ... | @@ -154,6 +162,12 @@ pub fn blockExpr(mod: *Module, parent_scope: *Scope, block_node: *ast.Node.Block |
| 154 | }, | 162 | }, |
| 155 | } | 163 | } |
| 156 | } | 164 | } |
| | 165 | |
| | 166 | const src = tree.token_locs[block_node.firstToken()].start; |
| | 167 | return addZIRInstConst(mod, parent_scope, src, .{ |
| | 168 | .ty = Type.initTag(.void), |
| | 169 | .val = Value.initTag(.void_value), |
| | 170 | }); |
| 157 | } | 171 | } |
| 158 | | 172 | |
| 159 | fn varDecl( | 173 | fn varDecl( |