authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-14 11:28:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-14 11:28:40-07:00
log5f7c7191ab16c4c9320c28652a0d4c4e53af0024
treeb8f9bf672d03fad7a4f3d7ef4ea0c14c12ffed4f
parent4adc052f0b8fbb5c3f5ac06cc92d2fc9bd7e409e

stage2: astgen for non-labeled blocks


3 files changed, 20 insertions(+), 4 deletions(-)

src-self-hosted/Module.zig+1-1
...@@ -1343,7 +1343,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool {...@@ -1343,7 +1343,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool {
13431343
1344 const body_block = body_node.cast(ast.Node.Block).?;1344 const body_block = body_node.cast(ast.Node.Block).?;
13451345
1346 try astgen.blockExpr(self, params_scope, body_block);1346 _ = try astgen.blockExpr(self, params_scope, .none, body_block);
13471347
1348 if (!fn_type.fnReturnType().isNoReturn() and (gen_scope.instructions.items.len == 0 or1348 if (!fn_type.fnReturnType().isNoReturn() and (gen_scope.instructions.items.len == 0 or
1349 !gen_scope.instructions.items[gen_scope.instructions.items.len - 1].tag.isNoReturn()))1349 !gen_scope.instructions.items[gen_scope.instructions.items.len - 1].tag.isNoReturn()))
src-self-hosted/astgen.zig+16-2
...@@ -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}
113114
114pub fn blockExpr(mod: *Module, parent_scope: *Scope, block_node: *ast.Node.Block) !void {115pub 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();
117123
...@@ -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();
124130
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}
158172
159fn varDecl(173fn varDecl(
src-self-hosted/link.zig+3-1
...@@ -1887,7 +1887,9 @@ pub const File = struct {...@@ -1887,7 +1887,9 @@ pub const File = struct {
1887 else => false,1887 else => false,
1888 };1888 };
1889 if (is_fn) {1889 if (is_fn) {
1890 //typed_value.val.cast(Value.Payload.Function).?.func.dump(module.*);1890 //if (mem.eql(u8, mem.spanZ(decl.name), "add")) {
1891 // typed_value.val.cast(Value.Payload.Function).?.func.dump(module.*);
1892 //}
18911893
1892 // For functions we need to add a prologue to the debug line program.1894 // For functions we need to add a prologue to the debug line program.
1893 try dbg_line_buffer.ensureCapacity(26);1895 try dbg_line_buffer.ensureCapacity(26);