mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 12:59:04 +00:00
stage2 astgen for LabeledBlock
This commit is contained in:
parent
9a5a1013a8
commit
b49d3672f3
@ -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.
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user