authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-11-13 17:32:52+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-11-13 17:32:52+02:00
log643f526cd121173b4102ce3a07ee9bb4a1582cc2
treec28127530f9418bb05f218d6ca6d61a1691bfa80
parent51717314e4c955f696919aea6f17d758b4b6430f
signaturelock-open Commit is signed but in an unrecognized format.

stage2: add zir instructions for creating container types


1 files changed, 102 insertions(+), 1 deletions(-)

src/zir.zig+102-1
......@@ -126,6 +126,12 @@ pub const Inst = struct {
126126 condbr,
127127 /// Special case, has no textual representation.
128128 @"const",
129 /// Container field with just the name.
130 container_field_named,
131 /// Container field with a type and a name,
132 container_field_typed,
133 /// Container field with all the bells and whistles.
134 container_field,
129135 /// Declares the beginning of a statement. Used for debug info.
130136 dbg_stmt,
131137 /// Represents a pointer to a global decl by name.
......@@ -245,6 +251,8 @@ pub const Inst = struct {
245251 store,
246252 /// String Literal. Makes an anonymous Decl and then takes a pointer to it.
247253 str,
254 /// Create a struct type.
255 struct_type,
248256 /// Arithmetic subtraction. Asserts no integer overflow.
249257 sub,
250258 /// Twos complement wrapping integer subtraction.
......@@ -262,6 +270,8 @@ pub const Inst = struct {
262270 xor,
263271 /// Create an optional type '?T'
264272 optional_type,
273 /// Create a union type.
274 union_type,
265275 /// Unwraps an optional value 'lhs.?'
266276 unwrap_optional_safe,
267277 /// Same as previous, but without safety checks. Used for orelse, if and while
......@@ -274,8 +284,10 @@ pub const Inst = struct {
274284 unwrap_err_code,
275285 /// Takes a *E!T and raises a compiler error if T != void
276286 ensure_err_payload_void,
277 /// Enum literal
287 /// Create a enum literal,
278288 enum_literal,
289 /// Create an enum type.
290 enum_type,
279291 /// A switch expression.
280292 switchbr,
281293 /// A range in a switch case, `lhs...rhs`.
......@@ -403,6 +415,12 @@ pub const Inst = struct {
403415 .error_set => ErrorSet,
404416 .slice => Slice,
405417 .switchbr => SwitchBr,
418 .container_field_named => ContainerFieldNamed,
419 .container_field_typed => ContainerFieldTyped,
420 .container_field => ContainerField,
421 .enum_type => EnumType,
422 .union_type => UnionType,
423 .struct_type => StructType,
406424 };
407425 }
408426
......@@ -510,6 +528,9 @@ pub const Inst = struct {
510528 .slice_start,
511529 .import,
512530 .switch_range,
531 .enum_type,
532 .union_type,
533 .struct_type,
513534 => false,
514535
515536 .@"break",
......@@ -522,6 +543,9 @@ pub const Inst = struct {
522543 .@"unreachable",
523544 .loop,
524545 .switchbr,
546 .container_field_named,
547 .container_field_typed,
548 .container_field,
525549 => true,
526550 };
527551 }
......@@ -1032,6 +1056,83 @@ pub const Inst = struct {
10321056 body: Module.Body,
10331057 };
10341058 };
1059
1060 pub const ContainerFieldNamed = struct {
1061 pub const base_tag = Tag.container_field_named;
1062 base: Inst,
1063
1064 positionals: struct {
1065 bytes: []const u8,
1066 },
1067 kw_args: struct {},
1068 };
1069
1070 pub const ContainerFieldTyped = struct {
1071 pub const base_tag = Tag.container_field_typed;
1072 base: Inst,
1073
1074 positionals: struct {
1075 bytes: []const u8,
1076 ty: *Inst,
1077 },
1078 kw_args: struct {},
1079 };
1080
1081 pub const ContainerField = struct {
1082 pub const base_tag = Tag.container_field;
1083 base: Inst,
1084
1085 positionals: struct {
1086 bytes: []const u8,
1087 ty: ?*Inst,
1088 init: ?*Inst,
1089 alignment: ?*Inst,
1090 is_comptime: bool,
1091 },
1092 kw_args: struct {},
1093 };
1094
1095 pub const EnumType = struct {
1096 pub const base_tag = Tag.enum_type;
1097 base: Inst,
1098
1099 positionals: struct {
1100 fields: []*Inst,
1101 },
1102 kw_args: struct {
1103 tag_type: ?*Inst = null,
1104 layout: std.builtin.TypeInfo.ContainerLayout = .Auto,
1105 },
1106 };
1107
1108 pub const StructType = struct {
1109 pub const base_tag = Tag.struct_type;
1110 base: Inst,
1111
1112 positionals: struct {
1113 fields: []*Inst,
1114 },
1115 kw_args: struct {
1116 layout: std.builtin.TypeInfo.ContainerLayout = .Auto,
1117 },
1118 };
1119
1120 pub const UnionType = struct {
1121 pub const base_tag = Tag.union_type;
1122 base: Inst,
1123
1124 positionals: struct {
1125 fields: []*Inst,
1126 },
1127 kw_args: struct {
1128 init_expr: union(enum) {
1129 enum_type: ?*Inst,
1130 tag_type: *Inst,
1131 none,
1132 },
1133 layout: std.builtin.TypeInfo.ContainerLayout = .Auto,
1134 },
1135 };
10351136};
10361137
10371138pub const ErrorMsg = struct {