Commit b49d3672f3
Changed files (2)
src-self-hosted
src-self-hosted/astgen.zig
@@ -129,14 +129,24 @@ fn labeledBlockExpr(
const tracy = trace(@src());
defer tracy.end();
- const statements = block_node.statements();
+ var block_scope: Scope.GenZIR = .{
+ .parent = parent_scope,
+ .decl = parent_scope.decl().?,
+ .arena = parent_scope.arena(),
+ .instructions = .{},
+ .label = block_node.label,
+ };
+ defer block_scope.instructions.deinit(mod.gpa);
- if (statements.len == 0) {
- // Hot path for `{}`.
- return rlWrapVoid(mod, parent_scope, rl, &block_node.base, {});
- }
+ try blockExprStmts(mod, &block_scope.base, &block_node.base, block_node.statements());
- return mod.failNode(parent_scope, &block_node.base, "TODO implement labeled blocks", .{});
+ const tree = parent_scope.tree();
+ const src = tree.token_locs[block_node.lbrace].start;
+ const block = try addZIRInstBlock(mod, parent_scope, src, .{
+ .instructions = try block_scope.arena.dupe(*zir.Inst, block_scope.instructions.items),
+ });
+
+ return &block.base;
}
fn blockExprStmts(mod: *Module, parent_scope: *Scope, node: *ast.Node, statements: []*ast.Node) !void {
src-self-hosted/Module.zig
@@ -737,6 +737,7 @@ pub const Scope = struct {
arena: *Allocator,
/// The first N instructions in a function body ZIR are arg instructions.
instructions: std.ArrayListUnmanaged(*zir.Inst) = .{},
+ label: ?ast.TokenIndex = null,
};
/// This is always a `const` local and importantly the `inst` is a value type, not a pointer.