aboutsummaryrefslogtreecommitdiff
path: root/src/AstGen.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-01 22:34:40 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-04-01 22:39:09 -0700
commit8ebfdc14f68521ac129ee7d2c3f4e7250e4e7418 (patch)
tree7a20ca7752b10da7e811a52927b6d1ba0869e893 /src/AstGen.zig
parentc66b48194ff83eb5b1774a1428461f5fc94dcd7d (diff)
downloadzig-8ebfdc14f68521ac129ee7d2c3f4e7250e4e7418.tar.gz
zig-8ebfdc14f68521ac129ee7d2c3f4e7250e4e7418.zip
stage2: implement structs in the frontend
New ZIR instructions: * struct_decl_packed * struct_decl_extern New TZIR instruction: struct_field_ptr Introduce `Module.Struct`. It uses `Value` to store default values and abi alignments. Implemented Sema.analyzeStructFieldPtr and zirStructDecl. Some stuff I changed from `@panic("TODO")` to `log.warn("TODO")`. It's becoming more clear that we need the lazy value mechanism soon; Type is becoming unruly, and some of these functions have too much logic given that they don't have any context for memory management or error reporting.
Diffstat (limited to 'src/AstGen.zig')
-rw-r--r--src/AstGen.zig11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 24c06aff64..9b4e6c7c1a 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -1322,6 +1322,8 @@ fn blockExprStmts(
.switch_capture_else_ref,
.struct_init_empty,
.struct_decl,
+ .struct_decl_packed,
+ .struct_decl_extern,
.union_decl,
.enum_decl,
.opaque_decl,
@@ -1789,8 +1791,13 @@ fn containerDecl(
switch (token_tags[container_decl.ast.main_token]) {
.keyword_struct => {
+ const tag = if (container_decl.layout_token) |t| switch (token_tags[t]) {
+ .keyword_packed => zir.Inst.Tag.struct_decl_packed,
+ .keyword_extern => zir.Inst.Tag.struct_decl_extern,
+ else => unreachable,
+ } else zir.Inst.Tag.struct_decl;
if (container_decl.ast.members.len == 0) {
- const result = try gz.addPlNode(.struct_decl, node, zir.Inst.StructDecl{
+ const result = try gz.addPlNode(tag, node, zir.Inst.StructDecl{
.fields_len = 0,
});
return rvalue(gz, scope, rl, result, node);
@@ -1856,7 +1863,7 @@ fn containerDecl(
const empty_slot_count = 16 - ((member_index - 1) % 16);
cur_bit_bag >>= @intCast(u5, empty_slot_count * 2);
- const result = try gz.addPlNode(.struct_decl, node, zir.Inst.StructDecl{
+ const result = try gz.addPlNode(tag, node, zir.Inst.StructDecl{
.fields_len = @intCast(u32, container_decl.ast.members.len),
});
try astgen.extra.ensureCapacity(gpa, astgen.extra.items.len +