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
signature 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 {...@@ -126,6 +126,12 @@ pub const Inst = struct {
126 condbr,126 condbr,
127 /// Special case, has no textual representation.127 /// Special case, has no textual representation.
128 @"const",128 @"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,
129 /// Declares the beginning of a statement. Used for debug info.135 /// Declares the beginning of a statement. Used for debug info.
130 dbg_stmt,136 dbg_stmt,
131 /// Represents a pointer to a global decl by name.137 /// Represents a pointer to a global decl by name.
...@@ -245,6 +251,8 @@ pub const Inst = struct {...@@ -245,6 +251,8 @@ pub const Inst = struct {
245 store,251 store,
246 /// String Literal. Makes an anonymous Decl and then takes a pointer to it.252 /// String Literal. Makes an anonymous Decl and then takes a pointer to it.
247 str,253 str,
254 /// Create a struct type.
255 struct_type,
248 /// Arithmetic subtraction. Asserts no integer overflow.256 /// Arithmetic subtraction. Asserts no integer overflow.
249 sub,257 sub,
250 /// Twos complement wrapping integer subtraction.258 /// Twos complement wrapping integer subtraction.
...@@ -262,6 +270,8 @@ pub const Inst = struct {...@@ -262,6 +270,8 @@ pub const Inst = struct {
262 xor,270 xor,
263 /// Create an optional type '?T'271 /// Create an optional type '?T'
264 optional_type,272 optional_type,
273 /// Create a union type.
274 union_type,
265 /// Unwraps an optional value 'lhs.?'275 /// Unwraps an optional value 'lhs.?'
266 unwrap_optional_safe,276 unwrap_optional_safe,
267 /// Same as previous, but without safety checks. Used for orelse, if and while277 /// Same as previous, but without safety checks. Used for orelse, if and while
...@@ -274,8 +284,10 @@ pub const Inst = struct {...@@ -274,8 +284,10 @@ pub const Inst = struct {
274 unwrap_err_code,284 unwrap_err_code,
275 /// Takes a *E!T and raises a compiler error if T != void285 /// Takes a *E!T and raises a compiler error if T != void
276 ensure_err_payload_void,286 ensure_err_payload_void,
277 /// Enum literal287 /// Create a enum literal,
278 enum_literal,288 enum_literal,
289 /// Create an enum type.
290 enum_type,
279 /// A switch expression.291 /// A switch expression.
280 switchbr,292 switchbr,
281 /// A range in a switch case, `lhs...rhs`.293 /// A range in a switch case, `lhs...rhs`.
...@@ -403,6 +415,12 @@ pub const Inst = struct {...@@ -403,6 +415,12 @@ pub const Inst = struct {
403 .error_set => ErrorSet,415 .error_set => ErrorSet,
404 .slice => Slice,416 .slice => Slice,
405 .switchbr => SwitchBr,417 .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,
406 };424 };
407 }425 }
408426
...@@ -510,6 +528,9 @@ pub const Inst = struct {...@@ -510,6 +528,9 @@ pub const Inst = struct {
510 .slice_start,528 .slice_start,
511 .import,529 .import,
512 .switch_range,530 .switch_range,
531 .enum_type,
532 .union_type,
533 .struct_type,
513 => false,534 => false,
514535
515 .@"break",536 .@"break",
...@@ -522,6 +543,9 @@ pub const Inst = struct {...@@ -522,6 +543,9 @@ pub const Inst = struct {
522 .@"unreachable",543 .@"unreachable",
523 .loop,544 .loop,
524 .switchbr,545 .switchbr,
546 .container_field_named,
547 .container_field_typed,
548 .container_field,
525 => true,549 => true,
526 };550 };
527 }551 }
...@@ -1032,6 +1056,83 @@ pub const Inst = struct {...@@ -1032,6 +1056,83 @@ pub const Inst = struct {
1032 body: Module.Body,1056 body: Module.Body,
1033 };1057 };
1034 };1058 };
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 };
1035};1136};
10361137
1037pub const ErrorMsg = struct {1138pub const ErrorMsg = struct {