astgen: implement breaking from a block
This commit is contained in:
committed by
Andrew Kelley
parent
d73a4940e0
commit
522707622e
@@ -935,11 +935,11 @@ pub const Scope = struct {
|
||||
break_count: usize = 0,
|
||||
/// Tracks `break :foo bar` instructions so they can possibly be elided later if
|
||||
/// the labeled block ends up not needing a result location pointer.
|
||||
labeled_breaks: std.ArrayListUnmanaged(zir.Inst.Index) = .{},
|
||||
labeled_breaks: std.ArrayListUnmanaged(zir.Inst.Ref) = .{},
|
||||
/// Tracks `store_to_block_ptr` instructions that correspond to break instructions
|
||||
/// so they can possibly be elided later if the labeled block ends up not needing
|
||||
/// a result location pointer.
|
||||
labeled_store_to_block_ptr_list: std.ArrayListUnmanaged(zir.Inst.Index) = .{},
|
||||
labeled_store_to_block_ptr_list: std.ArrayListUnmanaged(zir.Inst.Ref) = .{},
|
||||
|
||||
pub const Label = struct {
|
||||
token: ast.TokenIndex,
|
||||
@@ -1222,6 +1222,35 @@ pub const Scope = struct {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn addBreak(
|
||||
gz: *GenZir,
|
||||
break_block: zir.Inst.Index,
|
||||
operand: zir.Inst.Ref,
|
||||
) !zir.Inst.Ref {
|
||||
return try gz.add(.{
|
||||
.tag = .@"break",
|
||||
.data = .{ .@"break" = .{
|
||||
.block_inst = break_block,
|
||||
.operand = operand,
|
||||
} },
|
||||
});
|
||||
}
|
||||
|
||||
pub fn addBreakVoid(
|
||||
inner_gz: *GenZir,
|
||||
block_gz: *GenZir,
|
||||
break_block: zir.Inst.Index,
|
||||
node_index: ast.Node.Index,
|
||||
) !zir.Inst.Ref {
|
||||
return try inner_gz.add(.{
|
||||
.tag = .break_void_node,
|
||||
.data = .{ .break_void_node = .{
|
||||
.src_node = block_gz.zir_code.decl.nodeIndexToRelative(node_index),
|
||||
.block_inst = break_block,
|
||||
} },
|
||||
});
|
||||
}
|
||||
|
||||
pub fn addBin(
|
||||
gz: *GenZir,
|
||||
tag: zir.Inst.Tag,
|
||||
|
||||
Reference in New Issue
Block a user