| author | |
| committer | |
| log | e0b01bd4a98e2605f197a04f84e0c281ccc90f81 |
| tree | 0bac6d2e6d24d57e0d6312dcf637e2a7915288be |
| parent | 31d8efc6b32a6b60b7ab292ac50e0f6c02bc140e |
| signature | Commit is signed but in an unrecognized format. |
5 files changed, 98 insertions(+), 4 deletions(-)
src-self-hosted/astgen.zig+9-1| ... | ... | @@ -130,6 +130,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr |
| 130 | 130 | .GroupedExpression => return expr(mod, scope, rl, node.castTag(.GroupedExpression).?.expr), |
| 131 | 131 | .ArrayType => return rlWrap(mod, scope, rl, try arrayType(mod, scope, node.castTag(.ArrayType).?)), |
| 132 | 132 | .ArrayTypeSentinel => return rlWrap(mod, scope, rl, try arrayTypeSentinel(mod, scope, node.castTag(.ArrayTypeSentinel).?)), |
| 133 | .EnumLiteral => return rlWrap(mod, scope, rl, try enumLiteral(mod, scope, node.castTag(.EnumLiteral).?)), | |
| 133 | 134 | |
| 134 | 135 | .Defer => return mod.failNode(scope, node, "TODO implement astgen.expr for .Defer", .{}), |
| 135 | 136 | .Catch => return mod.failNode(scope, node, "TODO implement astgen.expr for .Catch", .{}), |
| ... | ... | @@ -158,7 +159,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr |
| 158 | 159 | .ErrorType => return mod.failNode(scope, node, "TODO implement astgen.expr for .ErrorType", .{}), |
| 159 | 160 | .FnProto => return mod.failNode(scope, node, "TODO implement astgen.expr for .FnProto", .{}), |
| 160 | 161 | .AnyFrameType => return mod.failNode(scope, node, "TODO implement astgen.expr for .AnyFrameType", .{}), |
| 161 | .EnumLiteral => return mod.failNode(scope, node, "TODO implement astgen.expr for .EnumLiteral", .{}), | |
| 162 | 162 | .MultilineStringLiteral => return mod.failNode(scope, node, "TODO implement astgen.expr for .MultilineStringLiteral", .{}), |
| 163 | 163 | .CharLiteral => return mod.failNode(scope, node, "TODO implement astgen.expr for .CharLiteral", .{}), |
| 164 | 164 | .ErrorSetDecl => return mod.failNode(scope, node, "TODO implement astgen.expr for .ErrorSetDecl", .{}), |
| ... | ... | @@ -527,6 +527,14 @@ fn arrayTypeSentinel(mod: *Module, scope: *Scope, node: *ast.Node.ArrayTypeSenti |
| 527 | 527 | }, .{}); |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | fn enumLiteral(mod: *Module, scope: *Scope, node: *ast.Node.EnumLiteral) !*zir.Inst { | |
| 531 | const tree = scope.tree(); | |
| 532 | const src = tree.token_locs[node.name].start; | |
| 533 | const name = try identifierTokenString(mod, scope, node.name); | |
| 534 | ||
| 535 | return addZIRInst(mod, scope, src, zir.Inst.EnumLiteral, .{ .name = name }, .{}); | |
| 536 | } | |
| 537 | ||
| 530 | 538 | fn unwrapOptional(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node.SimpleSuffixOp) InnerError!*zir.Inst { |
| 531 | 539 | const tree = scope.tree(); |
| 532 | 540 | const src = tree.token_locs[node.rtoken].start; |
src-self-hosted/type.zig+29-1| ... | ... | @@ -75,6 +75,7 @@ pub const Type = extern union { |
| 75 | 75 | .optional_single_const_pointer, |
| 76 | 76 | .optional_single_mut_pointer, |
| 77 | 77 | => return .Optional, |
| 78 | .enum_literal => return .EnumLiteral, | |
| 78 | 79 | } |
| 79 | 80 | } |
| 80 | 81 | |
| ... | ... | @@ -127,6 +128,7 @@ pub const Type = extern union { |
| 127 | 128 | if (zig_tag_a != zig_tag_b) |
| 128 | 129 | return false; |
| 129 | 130 | switch (zig_tag_a) { |
| 131 | .EnumLiteral => return true, | |
| 130 | 132 | .Type => return true, |
| 131 | 133 | .Void => return true, |
| 132 | 134 | .Bool => return true, |
| ... | ... | @@ -211,7 +213,6 @@ pub const Type = extern union { |
| 211 | 213 | .Frame, |
| 212 | 214 | .AnyFrame, |
| 213 | 215 | .Vector, |
| 214 | .EnumLiteral, | |
| 215 | 216 | => std.debug.panic("TODO implement Type equality comparison of {} and {}", .{ a, b }), |
| 216 | 217 | } |
| 217 | 218 | } |
| ... | ... | @@ -327,6 +328,7 @@ pub const Type = extern union { |
| 327 | 328 | .fn_ccc_void_no_args, |
| 328 | 329 | .single_const_pointer_to_comptime_int, |
| 329 | 330 | .const_slice_u8, |
| 331 | .enum_literal, | |
| 330 | 332 | => unreachable, |
| 331 | 333 | |
| 332 | 334 | .array_u8_sentinel_0 => return self.copyPayloadShallow(allocator, Payload.Array_u8_Sentinel0), |
| ... | ... | @@ -437,6 +439,7 @@ pub const Type = extern union { |
| 437 | 439 | .noreturn, |
| 438 | 440 | => return out_stream.writeAll(@tagName(t)), |
| 439 | 441 | |
| 442 | .enum_literal => return out_stream.writeAll("@TypeOf(.EnumLiteral)"), | |
| 440 | 443 | .@"null" => return out_stream.writeAll("@TypeOf(null)"), |
| 441 | 444 | .@"undefined" => return out_stream.writeAll("@TypeOf(undefined)"), |
| 442 | 445 | |
| ... | ... | @@ -561,6 +564,7 @@ pub const Type = extern union { |
| 561 | 564 | .fn_ccc_void_no_args => return Value.initTag(.fn_ccc_void_no_args_type), |
| 562 | 565 | .single_const_pointer_to_comptime_int => return Value.initTag(.single_const_pointer_to_comptime_int_type), |
| 563 | 566 | .const_slice_u8 => return Value.initTag(.const_slice_u8_type), |
| 567 | .enum_literal => return Value.initTag(.enum_literal_type), | |
| 564 | 568 | else => { |
| 565 | 569 | const ty_payload = try allocator.create(Value.Payload.Ty); |
| 566 | 570 | ty_payload.* = .{ .ty = self }; |
| ... | ... | @@ -625,6 +629,7 @@ pub const Type = extern union { |
| 625 | 629 | .noreturn, |
| 626 | 630 | .@"null", |
| 627 | 631 | .@"undefined", |
| 632 | .enum_literal, | |
| 628 | 633 | => false, |
| 629 | 634 | }; |
| 630 | 635 | } |
| ... | ... | @@ -716,6 +721,7 @@ pub const Type = extern union { |
| 716 | 721 | .noreturn, |
| 717 | 722 | .@"null", |
| 718 | 723 | .@"undefined", |
| 724 | .enum_literal, | |
| 719 | 725 | => unreachable, |
| 720 | 726 | }; |
| 721 | 727 | } |
| ... | ... | @@ -736,6 +742,7 @@ pub const Type = extern union { |
| 736 | 742 | .noreturn => unreachable, |
| 737 | 743 | .@"null" => unreachable, |
| 738 | 744 | .@"undefined" => unreachable, |
| 745 | .enum_literal => unreachable, | |
| 739 | 746 | |
| 740 | 747 | .u8, |
| 741 | 748 | .i8, |
| ... | ... | @@ -863,6 +870,7 @@ pub const Type = extern union { |
| 863 | 870 | .optional, |
| 864 | 871 | .optional_single_mut_pointer, |
| 865 | 872 | .optional_single_const_pointer, |
| 873 | .enum_literal, | |
| 866 | 874 | => false, |
| 867 | 875 | |
| 868 | 876 | .single_const_pointer, |
| ... | ... | @@ -924,6 +932,7 @@ pub const Type = extern union { |
| 924 | 932 | .optional, |
| 925 | 933 | .optional_single_mut_pointer, |
| 926 | 934 | .optional_single_const_pointer, |
| 935 | .enum_literal, | |
| 927 | 936 | => false, |
| 928 | 937 | |
| 929 | 938 | .const_slice_u8 => true, |
| ... | ... | @@ -980,6 +989,7 @@ pub const Type = extern union { |
| 980 | 989 | .optional, |
| 981 | 990 | .optional_single_mut_pointer, |
| 982 | 991 | .optional_single_const_pointer, |
| 992 | .enum_literal, | |
| 983 | 993 | => false, |
| 984 | 994 | |
| 985 | 995 | .single_const_pointer, |
| ... | ... | @@ -1042,6 +1052,7 @@ pub const Type = extern union { |
| 1042 | 1052 | .optional, |
| 1043 | 1053 | .optional_single_mut_pointer, |
| 1044 | 1054 | .optional_single_const_pointer, |
| 1055 | .enum_literal, | |
| 1045 | 1056 | => false, |
| 1046 | 1057 | }; |
| 1047 | 1058 | } |
| ... | ... | @@ -1147,6 +1158,7 @@ pub const Type = extern union { |
| 1147 | 1158 | .optional, |
| 1148 | 1159 | .optional_single_const_pointer, |
| 1149 | 1160 | .optional_single_mut_pointer, |
| 1161 | .enum_literal, | |
| 1150 | 1162 | => unreachable, |
| 1151 | 1163 | |
| 1152 | 1164 | .array => self.cast(Payload.Array).?.elem_type, |
| ... | ... | @@ -1252,6 +1264,7 @@ pub const Type = extern union { |
| 1252 | 1264 | .optional, |
| 1253 | 1265 | .optional_single_mut_pointer, |
| 1254 | 1266 | .optional_single_const_pointer, |
| 1267 | .enum_literal, | |
| 1255 | 1268 | => unreachable, |
| 1256 | 1269 | |
| 1257 | 1270 | .array => self.cast(Payload.Array).?.len, |
| ... | ... | @@ -1311,6 +1324,7 @@ pub const Type = extern union { |
| 1311 | 1324 | .optional, |
| 1312 | 1325 | .optional_single_mut_pointer, |
| 1313 | 1326 | .optional_single_const_pointer, |
| 1327 | .enum_literal, | |
| 1314 | 1328 | => unreachable, |
| 1315 | 1329 | |
| 1316 | 1330 | .array, .array_u8 => return null, |
| ... | ... | @@ -1368,6 +1382,7 @@ pub const Type = extern union { |
| 1368 | 1382 | .optional, |
| 1369 | 1383 | .optional_single_mut_pointer, |
| 1370 | 1384 | .optional_single_const_pointer, |
| 1385 | .enum_literal, | |
| 1371 | 1386 | => false, |
| 1372 | 1387 | |
| 1373 | 1388 | .int_signed, |
| ... | ... | @@ -1428,6 +1443,7 @@ pub const Type = extern union { |
| 1428 | 1443 | .optional, |
| 1429 | 1444 | .optional_single_mut_pointer, |
| 1430 | 1445 | .optional_single_const_pointer, |
| 1446 | .enum_literal, | |
| 1431 | 1447 | => false, |
| 1432 | 1448 | |
| 1433 | 1449 | .int_unsigned, |
| ... | ... | @@ -1478,6 +1494,7 @@ pub const Type = extern union { |
| 1478 | 1494 | .optional, |
| 1479 | 1495 | .optional_single_mut_pointer, |
| 1480 | 1496 | .optional_single_const_pointer, |
| 1497 | .enum_literal, | |
| 1481 | 1498 | => unreachable, |
| 1482 | 1499 | |
| 1483 | 1500 | .int_unsigned => .{ .signed = false, .bits = self.cast(Payload.IntUnsigned).?.bits }, |
| ... | ... | @@ -1546,6 +1563,7 @@ pub const Type = extern union { |
| 1546 | 1563 | .optional, |
| 1547 | 1564 | .optional_single_mut_pointer, |
| 1548 | 1565 | .optional_single_const_pointer, |
| 1566 | .enum_literal, | |
| 1549 | 1567 | => false, |
| 1550 | 1568 | |
| 1551 | 1569 | .usize, |
| ... | ... | @@ -1643,6 +1661,7 @@ pub const Type = extern union { |
| 1643 | 1661 | .optional, |
| 1644 | 1662 | .optional_single_mut_pointer, |
| 1645 | 1663 | .optional_single_const_pointer, |
| 1664 | .enum_literal, | |
| 1646 | 1665 | => unreachable, |
| 1647 | 1666 | }; |
| 1648 | 1667 | } |
| ... | ... | @@ -1706,6 +1725,7 @@ pub const Type = extern union { |
| 1706 | 1725 | .optional, |
| 1707 | 1726 | .optional_single_mut_pointer, |
| 1708 | 1727 | .optional_single_const_pointer, |
| 1728 | .enum_literal, | |
| 1709 | 1729 | => unreachable, |
| 1710 | 1730 | } |
| 1711 | 1731 | } |
| ... | ... | @@ -1768,6 +1788,7 @@ pub const Type = extern union { |
| 1768 | 1788 | .optional, |
| 1769 | 1789 | .optional_single_mut_pointer, |
| 1770 | 1790 | .optional_single_const_pointer, |
| 1791 | .enum_literal, | |
| 1771 | 1792 | => unreachable, |
| 1772 | 1793 | } |
| 1773 | 1794 | } |
| ... | ... | @@ -1830,6 +1851,7 @@ pub const Type = extern union { |
| 1830 | 1851 | .optional, |
| 1831 | 1852 | .optional_single_mut_pointer, |
| 1832 | 1853 | .optional_single_const_pointer, |
| 1854 | .enum_literal, | |
| 1833 | 1855 | => unreachable, |
| 1834 | 1856 | }; |
| 1835 | 1857 | } |
| ... | ... | @@ -1889,6 +1911,7 @@ pub const Type = extern union { |
| 1889 | 1911 | .optional, |
| 1890 | 1912 | .optional_single_mut_pointer, |
| 1891 | 1913 | .optional_single_const_pointer, |
| 1914 | .enum_literal, | |
| 1892 | 1915 | => unreachable, |
| 1893 | 1916 | }; |
| 1894 | 1917 | } |
| ... | ... | @@ -1948,6 +1971,7 @@ pub const Type = extern union { |
| 1948 | 1971 | .optional, |
| 1949 | 1972 | .optional_single_mut_pointer, |
| 1950 | 1973 | .optional_single_const_pointer, |
| 1974 | .enum_literal, | |
| 1951 | 1975 | => unreachable, |
| 1952 | 1976 | }; |
| 1953 | 1977 | } |
| ... | ... | @@ -2007,6 +2031,7 @@ pub const Type = extern union { |
| 2007 | 2031 | .optional, |
| 2008 | 2032 | .optional_single_mut_pointer, |
| 2009 | 2033 | .optional_single_const_pointer, |
| 2034 | .enum_literal, | |
| 2010 | 2035 | => false, |
| 2011 | 2036 | }; |
| 2012 | 2037 | } |
| ... | ... | @@ -2055,6 +2080,7 @@ pub const Type = extern union { |
| 2055 | 2080 | .optional, |
| 2056 | 2081 | .optional_single_mut_pointer, |
| 2057 | 2082 | .optional_single_const_pointer, |
| 2083 | .enum_literal, | |
| 2058 | 2084 | => return null, |
| 2059 | 2085 | |
| 2060 | 2086 | .void => return Value.initTag(.void_value), |
| ... | ... | @@ -2143,6 +2169,7 @@ pub const Type = extern union { |
| 2143 | 2169 | .optional, |
| 2144 | 2170 | .optional_single_mut_pointer, |
| 2145 | 2171 | .optional_single_const_pointer, |
| 2172 | .enum_literal, | |
| 2146 | 2173 | => return false, |
| 2147 | 2174 | }; |
| 2148 | 2175 | } |
| ... | ... | @@ -2186,6 +2213,7 @@ pub const Type = extern union { |
| 2186 | 2213 | comptime_int, |
| 2187 | 2214 | comptime_float, |
| 2188 | 2215 | noreturn, |
| 2216 | enum_literal, | |
| 2189 | 2217 | @"null", |
| 2190 | 2218 | @"undefined", |
| 2191 | 2219 | fn_noreturn_no_args, |
src-self-hosted/value.zig+33-2| ... | ... | @@ -60,6 +60,7 @@ pub const Value = extern union { |
| 60 | 60 | fn_ccc_void_no_args_type, |
| 61 | 61 | single_const_pointer_to_comptime_int_type, |
| 62 | 62 | const_slice_u8_type, |
| 63 | enum_literal_type, | |
| 63 | 64 | |
| 64 | 65 | undef, |
| 65 | 66 | zero, |
| ... | ... | @@ -87,6 +88,7 @@ pub const Value = extern union { |
| 87 | 88 | float_32, |
| 88 | 89 | float_64, |
| 89 | 90 | float_128, |
| 91 | enum_literal, | |
| 90 | 92 | |
| 91 | 93 | pub const last_no_payload_tag = Tag.bool_false; |
| 92 | 94 | pub const no_payload_count = @enumToInt(last_no_payload_tag) + 1; |
| ... | ... | @@ -164,6 +166,7 @@ pub const Value = extern union { |
| 164 | 166 | .fn_ccc_void_no_args_type, |
| 165 | 167 | .single_const_pointer_to_comptime_int_type, |
| 166 | 168 | .const_slice_u8_type, |
| 169 | .enum_literal_type, | |
| 167 | 170 | .undef, |
| 168 | 171 | .zero, |
| 169 | 172 | .void_value, |
| ... | ... | @@ -213,7 +216,7 @@ pub const Value = extern union { |
| 213 | 216 | }; |
| 214 | 217 | return Value{ .ptr_otherwise = &new_payload.base }; |
| 215 | 218 | }, |
| 216 | .bytes => return self.copyPayloadShallow(allocator, Payload.Bytes), | |
| 219 | .enum_literal, .bytes => return self.copyPayloadShallow(allocator, Payload.Bytes), | |
| 217 | 220 | .repeated => { |
| 218 | 221 | const payload = @fieldParentPtr(Payload.Repeated, "base", self.ptr_otherwise); |
| 219 | 222 | const new_payload = try allocator.create(Payload.Repeated); |
| ... | ... | @@ -285,6 +288,7 @@ pub const Value = extern union { |
| 285 | 288 | .fn_ccc_void_no_args_type => return out_stream.writeAll("fn() callconv(.C) void"), |
| 286 | 289 | .single_const_pointer_to_comptime_int_type => return out_stream.writeAll("*const comptime_int"), |
| 287 | 290 | .const_slice_u8_type => return out_stream.writeAll("[]const u8"), |
| 291 | .enum_literal_type => return out_stream.writeAll("@TypeOf(.EnumLiteral)"), | |
| 288 | 292 | |
| 289 | 293 | .null_value => return out_stream.writeAll("null"), |
| 290 | 294 | .undef => return out_stream.writeAll("undefined"), |
| ... | ... | @@ -318,7 +322,7 @@ pub const Value = extern union { |
| 318 | 322 | val = elem_ptr.array_ptr; |
| 319 | 323 | }, |
| 320 | 324 | .empty_array => return out_stream.writeAll(".{}"), |
| 321 | .bytes => return std.zig.renderStringLiteral(self.cast(Payload.Bytes).?.data, out_stream), | |
| 325 | .enum_literal, .bytes => return std.zig.renderStringLiteral(self.cast(Payload.Bytes).?.data, out_stream), | |
| 322 | 326 | .repeated => { |
| 323 | 327 | try out_stream.writeAll("(repeated) "); |
| 324 | 328 | val = val.cast(Payload.Repeated).?.val; |
| ... | ... | @@ -391,6 +395,7 @@ pub const Value = extern union { |
| 391 | 395 | .fn_ccc_void_no_args_type => Type.initTag(.fn_ccc_void_no_args), |
| 392 | 396 | .single_const_pointer_to_comptime_int_type => Type.initTag(.single_const_pointer_to_comptime_int), |
| 393 | 397 | .const_slice_u8_type => Type.initTag(.const_slice_u8), |
| 398 | .enum_literal_type => Type.initTag(.enum_literal), | |
| 394 | 399 | |
| 395 | 400 | .undef, |
| 396 | 401 | .zero, |
| ... | ... | @@ -414,6 +419,7 @@ pub const Value = extern union { |
| 414 | 419 | .float_32, |
| 415 | 420 | .float_64, |
| 416 | 421 | .float_128, |
| 422 | .enum_literal, | |
| 417 | 423 | => unreachable, |
| 418 | 424 | }; |
| 419 | 425 | } |
| ... | ... | @@ -462,6 +468,7 @@ pub const Value = extern union { |
| 462 | 468 | .fn_ccc_void_no_args_type, |
| 463 | 469 | .single_const_pointer_to_comptime_int_type, |
| 464 | 470 | .const_slice_u8_type, |
| 471 | .enum_literal_type, | |
| 465 | 472 | .null_value, |
| 466 | 473 | .function, |
| 467 | 474 | .ref_val, |
| ... | ... | @@ -476,6 +483,7 @@ pub const Value = extern union { |
| 476 | 483 | .void_value, |
| 477 | 484 | .unreachable_value, |
| 478 | 485 | .empty_array, |
| 486 | .enum_literal, | |
| 479 | 487 | => unreachable, |
| 480 | 488 | |
| 481 | 489 | .undef => unreachable, |
| ... | ... | @@ -537,6 +545,7 @@ pub const Value = extern union { |
| 537 | 545 | .fn_ccc_void_no_args_type, |
| 538 | 546 | .single_const_pointer_to_comptime_int_type, |
| 539 | 547 | .const_slice_u8_type, |
| 548 | .enum_literal_type, | |
| 540 | 549 | .null_value, |
| 541 | 550 | .function, |
| 542 | 551 | .ref_val, |
| ... | ... | @@ -551,6 +560,7 @@ pub const Value = extern union { |
| 551 | 560 | .void_value, |
| 552 | 561 | .unreachable_value, |
| 553 | 562 | .empty_array, |
| 563 | .enum_literal, | |
| 554 | 564 | => unreachable, |
| 555 | 565 | |
| 556 | 566 | .undef => unreachable, |
| ... | ... | @@ -612,6 +622,7 @@ pub const Value = extern union { |
| 612 | 622 | .fn_ccc_void_no_args_type, |
| 613 | 623 | .single_const_pointer_to_comptime_int_type, |
| 614 | 624 | .const_slice_u8_type, |
| 625 | .enum_literal_type, | |
| 615 | 626 | .null_value, |
| 616 | 627 | .function, |
| 617 | 628 | .ref_val, |
| ... | ... | @@ -626,6 +637,7 @@ pub const Value = extern union { |
| 626 | 637 | .void_value, |
| 627 | 638 | .unreachable_value, |
| 628 | 639 | .empty_array, |
| 640 | .enum_literal, | |
| 629 | 641 | => unreachable, |
| 630 | 642 | |
| 631 | 643 | .undef => unreachable, |
| ... | ... | @@ -713,6 +725,7 @@ pub const Value = extern union { |
| 713 | 725 | .fn_ccc_void_no_args_type, |
| 714 | 726 | .single_const_pointer_to_comptime_int_type, |
| 715 | 727 | .const_slice_u8_type, |
| 728 | .enum_literal_type, | |
| 716 | 729 | .null_value, |
| 717 | 730 | .function, |
| 718 | 731 | .ref_val, |
| ... | ... | @@ -728,6 +741,7 @@ pub const Value = extern union { |
| 728 | 741 | .void_value, |
| 729 | 742 | .unreachable_value, |
| 730 | 743 | .empty_array, |
| 744 | .enum_literal, | |
| 731 | 745 | => unreachable, |
| 732 | 746 | |
| 733 | 747 | .zero, |
| ... | ... | @@ -793,6 +807,7 @@ pub const Value = extern union { |
| 793 | 807 | .fn_ccc_void_no_args_type, |
| 794 | 808 | .single_const_pointer_to_comptime_int_type, |
| 795 | 809 | .const_slice_u8_type, |
| 810 | .enum_literal_type, | |
| 796 | 811 | .null_value, |
| 797 | 812 | .function, |
| 798 | 813 | .ref_val, |
| ... | ... | @@ -807,6 +822,7 @@ pub const Value = extern union { |
| 807 | 822 | .void_value, |
| 808 | 823 | .unreachable_value, |
| 809 | 824 | .empty_array, |
| 825 | .enum_literal, | |
| 810 | 826 | => unreachable, |
| 811 | 827 | |
| 812 | 828 | .zero, |
| ... | ... | @@ -953,6 +969,7 @@ pub const Value = extern union { |
| 953 | 969 | .fn_ccc_void_no_args_type, |
| 954 | 970 | .single_const_pointer_to_comptime_int_type, |
| 955 | 971 | .const_slice_u8_type, |
| 972 | .enum_literal_type, | |
| 956 | 973 | .bool_true, |
| 957 | 974 | .bool_false, |
| 958 | 975 | .null_value, |
| ... | ... | @@ -970,6 +987,7 @@ pub const Value = extern union { |
| 970 | 987 | .empty_array, |
| 971 | 988 | .void_value, |
| 972 | 989 | .unreachable_value, |
| 990 | .enum_literal, | |
| 973 | 991 | => unreachable, |
| 974 | 992 | |
| 975 | 993 | .zero => false, |
| ... | ... | @@ -1025,6 +1043,7 @@ pub const Value = extern union { |
| 1025 | 1043 | .fn_ccc_void_no_args_type, |
| 1026 | 1044 | .single_const_pointer_to_comptime_int_type, |
| 1027 | 1045 | .const_slice_u8_type, |
| 1046 | .enum_literal_type, | |
| 1028 | 1047 | .null_value, |
| 1029 | 1048 | .function, |
| 1030 | 1049 | .ref_val, |
| ... | ... | @@ -1036,6 +1055,7 @@ pub const Value = extern union { |
| 1036 | 1055 | .void_value, |
| 1037 | 1056 | .unreachable_value, |
| 1038 | 1057 | .empty_array, |
| 1058 | .enum_literal, | |
| 1039 | 1059 | => unreachable, |
| 1040 | 1060 | |
| 1041 | 1061 | .zero, |
| ... | ... | @@ -1102,6 +1122,11 @@ pub const Value = extern union { |
| 1102 | 1122 | } |
| 1103 | 1123 | |
| 1104 | 1124 | pub fn eql(a: Value, b: Value) bool { |
| 1125 | if (a.tag() == b.tag() and a.tag() == .enum_literal) { | |
| 1126 | const a_name = @fieldParentPtr(Payload.Bytes, "base", a.ptr_otherwise).data; | |
| 1127 | const b_name = @fieldParentPtr(Payload.Bytes, "base", b.ptr_otherwise).data; | |
| 1128 | return std.mem.eql(u8, a_name, b_name); | |
| 1129 | } | |
| 1105 | 1130 | // TODO non numerical comparisons |
| 1106 | 1131 | return compare(a, .eq, b); |
| 1107 | 1132 | } |
| ... | ... | @@ -1151,6 +1176,7 @@ pub const Value = extern union { |
| 1151 | 1176 | .fn_ccc_void_no_args_type, |
| 1152 | 1177 | .single_const_pointer_to_comptime_int_type, |
| 1153 | 1178 | .const_slice_u8_type, |
| 1179 | .enum_literal_type, | |
| 1154 | 1180 | .zero, |
| 1155 | 1181 | .bool_true, |
| 1156 | 1182 | .bool_false, |
| ... | ... | @@ -1170,6 +1196,7 @@ pub const Value = extern union { |
| 1170 | 1196 | .void_value, |
| 1171 | 1197 | .unreachable_value, |
| 1172 | 1198 | .empty_array, |
| 1199 | .enum_literal, | |
| 1173 | 1200 | => unreachable, |
| 1174 | 1201 | |
| 1175 | 1202 | .ref_val => self.cast(Payload.RefVal).?.val, |
| ... | ... | @@ -1227,6 +1254,7 @@ pub const Value = extern union { |
| 1227 | 1254 | .fn_ccc_void_no_args_type, |
| 1228 | 1255 | .single_const_pointer_to_comptime_int_type, |
| 1229 | 1256 | .const_slice_u8_type, |
| 1257 | .enum_literal_type, | |
| 1230 | 1258 | .zero, |
| 1231 | 1259 | .bool_true, |
| 1232 | 1260 | .bool_false, |
| ... | ... | @@ -1246,6 +1274,7 @@ pub const Value = extern union { |
| 1246 | 1274 | .float_128, |
| 1247 | 1275 | .void_value, |
| 1248 | 1276 | .unreachable_value, |
| 1277 | .enum_literal, | |
| 1249 | 1278 | => unreachable, |
| 1250 | 1279 | |
| 1251 | 1280 | .empty_array => unreachable, // out of bounds array index |
| ... | ... | @@ -1320,6 +1349,7 @@ pub const Value = extern union { |
| 1320 | 1349 | .fn_ccc_void_no_args_type, |
| 1321 | 1350 | .single_const_pointer_to_comptime_int_type, |
| 1322 | 1351 | .const_slice_u8_type, |
| 1352 | .enum_literal_type, | |
| 1323 | 1353 | .zero, |
| 1324 | 1354 | .empty_array, |
| 1325 | 1355 | .bool_true, |
| ... | ... | @@ -1339,6 +1369,7 @@ pub const Value = extern union { |
| 1339 | 1369 | .float_64, |
| 1340 | 1370 | .float_128, |
| 1341 | 1371 | .void_value, |
| 1372 | .enum_literal, | |
| 1342 | 1373 | => false, |
| 1343 | 1374 | |
| 1344 | 1375 | .undef => unreachable, |
src-self-hosted/zir.zig+14| ... | ... | @@ -231,6 +231,8 @@ pub const Inst = struct { |
| 231 | 231 | unwrap_err_unsafe, |
| 232 | 232 | /// Takes a *E!T and raises a compiler error if T != void |
| 233 | 233 | ensure_err_payload_void, |
| 234 | /// Enum literal | |
| 235 | enum_literal, | |
| 234 | 236 | |
| 235 | 237 | pub fn Type(tag: Tag) type { |
| 236 | 238 | return switch (tag) { |
| ... | ... | @@ -326,6 +328,7 @@ pub const Inst = struct { |
| 326 | 328 | .elemptr => ElemPtr, |
| 327 | 329 | .condbr => CondBr, |
| 328 | 330 | .ptr_type => PtrType, |
| 331 | .enum_literal => EnumLiteral, | |
| 329 | 332 | }; |
| 330 | 333 | } |
| 331 | 334 | |
| ... | ... | @@ -410,6 +413,7 @@ pub const Inst = struct { |
| 410 | 413 | .unwrap_err_unsafe, |
| 411 | 414 | .ptr_type, |
| 412 | 415 | .ensure_err_payload_void, |
| 416 | .enum_literal, | |
| 413 | 417 | => false, |
| 414 | 418 | |
| 415 | 419 | .@"break", |
| ... | ... | @@ -869,6 +873,16 @@ pub const Inst = struct { |
| 869 | 873 | }, |
| 870 | 874 | kw_args: struct {}, |
| 871 | 875 | }; |
| 876 | ||
| 877 | pub const EnumLiteral = struct { | |
| 878 | pub const base_tag = Tag.enum_literal; | |
| 879 | base: Inst, | |
| 880 | ||
| 881 | positionals: struct { | |
| 882 | name: []const u8, | |
| 883 | }, | |
| 884 | kw_args: struct {}, | |
| 885 | }; | |
| 872 | 886 | }; |
| 873 | 887 | |
| 874 | 888 | pub const ErrorMsg = struct { |
src-self-hosted/zir_sema.zig+13| ... | ... | @@ -115,6 +115,7 @@ pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError! |
| 115 | 115 | .ensure_err_payload_void => return analyzeInstEnsureErrPayloadVoid(mod, scope, old_inst.castTag(.ensure_err_payload_void).?), |
| 116 | 116 | .array_type => return analyzeInstArrayType(mod, scope, old_inst.castTag(.array_type).?), |
| 117 | 117 | .array_type_sentinel => return analyzeInstArrayTypeSentinel(mod, scope, old_inst.castTag(.array_type_sentinel).?), |
| 118 | .enum_literal => return analyzeInstEnumLiteral(mod, scope, old_inst.castTag(.enum_literal).?), | |
| 118 | 119 | } |
| 119 | 120 | } |
| 120 | 121 | |
| ... | ... | @@ -701,6 +702,18 @@ fn analyzeInstArrayTypeSentinel(mod: *Module, scope: *Scope, array: *zir.Inst.Ar |
| 701 | 702 | return mod.constType(scope, array.base.src, try mod.arrayType(scope, len.val.toUnsignedInt(), sentinel.val, elem_type)); |
| 702 | 703 | } |
| 703 | 704 | |
| 705 | fn analyzeInstEnumLiteral(mod: *Module, scope: *Scope, inst: *zir.Inst.EnumLiteral) InnerError!*Inst { | |
| 706 | const payload = try scope.arena().create(Value.Payload.Bytes); | |
| 707 | payload.* = .{ | |
| 708 | .base = .{ .tag = .enum_literal }, | |
| 709 | .data = try scope.arena().dupe(u8, inst.positionals.name), | |
| 710 | }; | |
| 711 | return mod.constInst(scope, inst.base.src, .{ | |
| 712 | .ty = Type.initTag(.enum_literal), | |
| 713 | .val = Value.initPayload(&payload.base), | |
| 714 | }); | |
| 715 | } | |
| 716 | ||
| 704 | 717 | fn analyzeInstUnwrapOptional(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp, safety_check: bool) InnerError!*Inst { |
| 705 | 718 | const operand = try resolveInst(mod, scope, unwrap.positionals.operand); |
| 706 | 719 | assert(operand.ty.zigTypeTag() == .Pointer); |