From 8ebfdc14f68521ac129ee7d2c3f4e7250e4e7418 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 1 Apr 2021 22:34:40 -0700 Subject: 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. --- src/AstGen.zig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/AstGen.zig') 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 + -- cgit v1.2.3