diff options
| author | Vexu <git@vexu.eu> | 2020-11-13 17:32:52 +0200 |
|---|---|---|
| committer | Vexu <git@vexu.eu> | 2020-11-13 17:32:52 +0200 |
| commit | 643f526cd121173b4102ce3a07ee9bb4a1582cc2 (patch) | |
| tree | c28127530f9418bb05f218d6ca6d61a1691bfa80 | |
| parent | 51717314e4c955f696919aea6f17d758b4b6430f (diff) | |
| download | zig-643f526cd121173b4102ce3a07ee9bb4a1582cc2.tar.gz zig-643f526cd121173b4102ce3a07ee9bb4a1582cc2.zip | |
stage2: add zir instructions for creating container types
| -rw-r--r-- | src/zir.zig | 103 |
1 files changed, 102 insertions, 1 deletions
diff --git a/src/zir.zig b/src/zir.zig index a03b492bd5..03b3a630a4 100644 --- a/src/zir.zig +++ b/src/zir.zig @@ -126,6 +126,12 @@ pub const Inst = struct { condbr, /// Special case, has no textual representation. @"const", + /// Container field with just the name. + container_field_named, + /// Container field with a type and a name, + container_field_typed, + /// Container field with all the bells and whistles. + container_field, /// Declares the beginning of a statement. Used for debug info. dbg_stmt, /// Represents a pointer to a global decl by name. @@ -245,6 +251,8 @@ pub const Inst = struct { store, /// String Literal. Makes an anonymous Decl and then takes a pointer to it. str, + /// Create a struct type. + struct_type, /// Arithmetic subtraction. Asserts no integer overflow. sub, /// Twos complement wrapping integer subtraction. @@ -262,6 +270,8 @@ pub const Inst = struct { xor, /// Create an optional type '?T' optional_type, + /// Create a union type. + union_type, /// Unwraps an optional value 'lhs.?' unwrap_optional_safe, /// Same as previous, but without safety checks. Used for orelse, if and while @@ -274,8 +284,10 @@ pub const Inst = struct { unwrap_err_code, /// Takes a *E!T and raises a compiler error if T != void ensure_err_payload_void, - /// Enum literal + /// Create a enum literal, enum_literal, + /// Create an enum type. + enum_type, /// A switch expression. switchbr, /// A range in a switch case, `lhs...rhs`. @@ -403,6 +415,12 @@ pub const Inst = struct { .error_set => ErrorSet, .slice => Slice, .switchbr => SwitchBr, + .container_field_named => ContainerFieldNamed, + .container_field_typed => ContainerFieldTyped, + .container_field => ContainerField, + .enum_type => EnumType, + .union_type => UnionType, + .struct_type => StructType, }; } @@ -510,6 +528,9 @@ pub const Inst = struct { .slice_start, .import, .switch_range, + .enum_type, + .union_type, + .struct_type, => false, .@"break", @@ -522,6 +543,9 @@ pub const Inst = struct { .@"unreachable", .loop, .switchbr, + .container_field_named, + .container_field_typed, + .container_field, => true, }; } @@ -1032,6 +1056,83 @@ pub const Inst = struct { body: Module.Body, }; }; + + pub const ContainerFieldNamed = struct { + pub const base_tag = Tag.container_field_named; + base: Inst, + + positionals: struct { + bytes: []const u8, + }, + kw_args: struct {}, + }; + + pub const ContainerFieldTyped = struct { + pub const base_tag = Tag.container_field_typed; + base: Inst, + + positionals: struct { + bytes: []const u8, + ty: *Inst, + }, + kw_args: struct {}, + }; + + pub const ContainerField = struct { + pub const base_tag = Tag.container_field; + base: Inst, + + positionals: struct { + bytes: []const u8, + ty: ?*Inst, + init: ?*Inst, + alignment: ?*Inst, + is_comptime: bool, + }, + kw_args: struct {}, + }; + + pub const EnumType = struct { + pub const base_tag = Tag.enum_type; + base: Inst, + + positionals: struct { + fields: []*Inst, + }, + kw_args: struct { + tag_type: ?*Inst = null, + layout: std.builtin.TypeInfo.ContainerLayout = .Auto, + }, + }; + + pub const StructType = struct { + pub const base_tag = Tag.struct_type; + base: Inst, + + positionals: struct { + fields: []*Inst, + }, + kw_args: struct { + layout: std.builtin.TypeInfo.ContainerLayout = .Auto, + }, + }; + + pub const UnionType = struct { + pub const base_tag = Tag.union_type; + base: Inst, + + positionals: struct { + fields: []*Inst, + }, + kw_args: struct { + init_expr: union(enum) { + enum_type: ?*Inst, + tag_type: *Inst, + none, + }, + layout: std.builtin.TypeInfo.ContainerLayout = .Auto, + }, + }; }; pub const ErrorMsg = struct { |
