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 {
13431343
13441344 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
13481348 if (!fn_type.fnReturnType().isNoReturn() and (gen_scope.instructions.items.len == 0 or
13491349 !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
107107 .NullLiteral => return rlWrap(mod, scope, rl, try nullLiteral(mod, scope, node.castTag(.NullLiteral).?)),
108108 .OptionalType => return rlWrap(mod, scope, rl, try optionalType(mod, scope, node.castTag(.OptionalType).?)),
109109 .UnwrapOptional => return unwrapOptional(mod, scope, rl, node.castTag(.UnwrapOptional).?),
110 .Block => return blockExpr(mod, scope, rl, node.castTag(.Block).?),
110111 else => return mod.failNode(scope, node, "TODO implement astgen.Expr for {}", .{@tagName(node.tag)}),
111112 }
112113}
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 {
115121 const tracy = trace(@src());
116122 defer tracy.end();
117123
......@@ -122,9 +128,11 @@ pub fn blockExpr(mod: *Module, parent_scope: *Scope, block_node: *ast.Node.Block
122128 var block_arena = std.heap.ArenaAllocator.init(mod.gpa);
123129 defer block_arena.deinit();
124130
131 const tree = parent_scope.tree();
132
125133 var scope = parent_scope;
126134 for (block_node.statements()) |statement| {
127 const src = scope.tree().token_locs[statement.firstToken()].start;
135 const src = tree.token_locs[statement.firstToken()].start;
128136 _ = try addZIRNoOp(mod, scope, src, .dbg_stmt);
129137 switch (statement.tag) {
130138 .VarDecl => {
......@@ -154,6 +162,12 @@ pub fn blockExpr(mod: *Module, parent_scope: *Scope, block_node: *ast.Node.Block
154162 },
155163 }
156164 }
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 });
157171}
158172
159173fn varDecl(
src-self-hosted/link.zig+3-1
......@@ -1887,7 +1887,9 @@ pub const File = struct {
18871887 else => false,
18881888 };
18891889 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
18921894 // For functions we need to add a prologue to the debug line program.
18931895 try dbg_line_buffer.ensureCapacity(26);