| ... | ... | @@ -65,7 +65,7 @@ pub const Type = extern union { |
| 65 | 65 | .fn_ccc_void_no_args => return .Fn, |
| 66 | 66 | .function => return .Fn, |
| 67 | 67 | |
| 68 | | .array, .array_u8_sentinel_0 => return .Array, |
| 68 | .array, .array_u8_sentinel_0, .array_u8, .array_sentinel => return .Array, |
| 69 | 69 | .single_const_pointer => return .Pointer, |
| 70 | 70 | .single_mut_pointer => return .Pointer, |
| 71 | 71 | .single_const_pointer_to_comptime_int => return .Pointer, |
| ... | ... | @@ -330,6 +330,7 @@ pub const Type = extern union { |
| 330 | 330 | => unreachable, |
| 331 | 331 | |
| 332 | 332 | .array_u8_sentinel_0 => return self.copyPayloadShallow(allocator, Payload.Array_u8_Sentinel0), |
| 333 | .array_u8 => return self.copyPayloadShallow(allocator, Payload.Array_u8), |
| 333 | 334 | .array => { |
| 334 | 335 | const payload = @fieldParentPtr(Payload.Array, "base", self.ptr_otherwise); |
| 335 | 336 | const new_payload = try allocator.create(Payload.Array); |
| ... | ... | @@ -340,6 +341,17 @@ pub const Type = extern union { |
| 340 | 341 | }; |
| 341 | 342 | return Type{ .ptr_otherwise = &new_payload.base }; |
| 342 | 343 | }, |
| 344 | .array_sentinel => { |
| 345 | const payload = @fieldParentPtr(Payload.ArraySentinel, "base", self.ptr_otherwise); |
| 346 | const new_payload = try allocator.create(Payload.ArraySentinel); |
| 347 | new_payload.* = .{ |
| 348 | .base = payload.base, |
| 349 | .len = payload.len, |
| 350 | .sentinel = try payload.sentinel.copy(allocator), |
| 351 | .elem_type = try payload.elem_type.copy(allocator), |
| 352 | }; |
| 353 | return Type{ .ptr_otherwise = &new_payload.base }; |
| 354 | }, |
| 343 | 355 | .int_signed => return self.copyPayloadShallow(allocator, Payload.IntSigned), |
| 344 | 356 | .int_unsigned => return self.copyPayloadShallow(allocator, Payload.IntUnsigned), |
| 345 | 357 | .function => { |
| ... | ... | @@ -445,6 +457,10 @@ pub const Type = extern union { |
| 445 | 457 | try payload.return_type.format("", .{}, out_stream); |
| 446 | 458 | }, |
| 447 | 459 | |
| 460 | .array_u8 => { |
| 461 | const payload = @fieldParentPtr(Payload.Array_u8, "base", ty.ptr_otherwise); |
| 462 | return out_stream.print("[{}]u8", .{payload.len}); |
| 463 | }, |
| 448 | 464 | .array_u8_sentinel_0 => { |
| 449 | 465 | const payload = @fieldParentPtr(Payload.Array_u8_Sentinel0, "base", ty.ptr_otherwise); |
| 450 | 466 | return out_stream.print("[{}:0]u8", .{payload.len}); |
| ... | ... | @@ -455,6 +471,12 @@ pub const Type = extern union { |
| 455 | 471 | ty = payload.elem_type; |
| 456 | 472 | continue; |
| 457 | 473 | }, |
| 474 | .array_sentinel => { |
| 475 | const payload = @fieldParentPtr(Payload.ArraySentinel, "base", ty.ptr_otherwise); |
| 476 | try out_stream.print("[{}:{}]", .{ payload.len, payload.sentinel }); |
| 477 | ty = payload.elem_type; |
| 478 | continue; |
| 479 | }, |
| 458 | 480 | .single_const_pointer => { |
| 459 | 481 | const payload = @fieldParentPtr(Payload.Pointer, "base", ty.ptr_otherwise); |
| 460 | 482 | try out_stream.writeAll("*const "); |
| ... | ... | @@ -588,6 +610,8 @@ pub const Type = extern union { |
| 588 | 610 | => true, |
| 589 | 611 | // TODO lazy types |
| 590 | 612 | .array => self.elemType().hasCodeGenBits() and self.arrayLen() != 0, |
| 613 | .array_u8 => self.arrayLen() != 0, |
| 614 | .array_sentinel => self.elemType().hasCodeGenBits(), |
| 591 | 615 | .single_const_pointer => self.elemType().hasCodeGenBits(), |
| 592 | 616 | .single_mut_pointer => self.elemType().hasCodeGenBits(), |
| 593 | 617 | .int_signed => self.cast(Payload.IntSigned).?.bits == 0, |
| ... | ... | @@ -616,6 +640,7 @@ pub const Type = extern union { |
| 616 | 640 | .i8, |
| 617 | 641 | .bool, |
| 618 | 642 | .array_u8_sentinel_0, |
| 643 | .array_u8, |
| 619 | 644 | => return 1, |
| 620 | 645 | |
| 621 | 646 | .fn_noreturn_no_args, // represents machine code; not a pointer |
| ... | ... | @@ -659,7 +684,7 @@ pub const Type = extern union { |
| 659 | 684 | |
| 660 | 685 | .anyerror => return 2, // TODO revisit this when we have the concept of the error tag type |
| 661 | 686 | |
| 662 | | .array => return self.cast(Payload.Array).?.elem_type.abiAlignment(target), |
| 687 | .array, .array_sentinel => return self.elemType().abiAlignment(target), |
| 663 | 688 | |
| 664 | 689 | .int_signed, .int_unsigned => { |
| 665 | 690 | const bits: u16 = if (self.cast(Payload.IntSigned)) |pl| |
| ... | ... | @@ -717,12 +742,18 @@ pub const Type = extern union { |
| 717 | 742 | .bool, |
| 718 | 743 | => return 1, |
| 719 | 744 | |
| 720 | | .array_u8_sentinel_0 => @fieldParentPtr(Payload.Array_u8_Sentinel0, "base", self.ptr_otherwise).len, |
| 745 | .array_u8 => @fieldParentPtr(Payload.Array_u8_Sentinel0, "base", self.ptr_otherwise).len, |
| 746 | .array_u8_sentinel_0 => @fieldParentPtr(Payload.Array_u8_Sentinel0, "base", self.ptr_otherwise).len + 1, |
| 721 | 747 | .array => { |
| 722 | 748 | const payload = @fieldParentPtr(Payload.Array, "base", self.ptr_otherwise); |
| 723 | 749 | const elem_size = std.math.max(payload.elem_type.abiAlignment(target), payload.elem_type.abiSize(target)); |
| 724 | 750 | return payload.len * elem_size; |
| 725 | 751 | }, |
| 752 | .array_sentinel => { |
| 753 | const payload = @fieldParentPtr(Payload.ArraySentinel, "base", self.ptr_otherwise); |
| 754 | const elem_size = std.math.max(payload.elem_type.abiAlignment(target), payload.elem_type.abiSize(target)); |
| 755 | return (payload.len + 1) * elem_size; |
| 756 | }, |
| 726 | 757 | .i16, .u16 => return 2, |
| 727 | 758 | .i32, .u32 => return 4, |
| 728 | 759 | .i64, .u64 => return 8, |
| ... | ... | @@ -818,6 +849,8 @@ pub const Type = extern union { |
| 818 | 849 | .@"null", |
| 819 | 850 | .@"undefined", |
| 820 | 851 | .array, |
| 852 | .array_sentinel, |
| 853 | .array_u8, |
| 821 | 854 | .array_u8_sentinel_0, |
| 822 | 855 | .const_slice_u8, |
| 823 | 856 | .fn_noreturn_no_args, |
| ... | ... | @@ -875,6 +908,8 @@ pub const Type = extern union { |
| 875 | 908 | .@"null", |
| 876 | 909 | .@"undefined", |
| 877 | 910 | .array, |
| 911 | .array_sentinel, |
| 912 | .array_u8, |
| 878 | 913 | .array_u8_sentinel_0, |
| 879 | 914 | .single_const_pointer, |
| 880 | 915 | .single_mut_pointer, |
| ... | ... | @@ -931,6 +966,8 @@ pub const Type = extern union { |
| 931 | 966 | .@"null", |
| 932 | 967 | .@"undefined", |
| 933 | 968 | .array, |
| 969 | .array_sentinel, |
| 970 | .array_u8, |
| 934 | 971 | .array_u8_sentinel_0, |
| 935 | 972 | .fn_noreturn_no_args, |
| 936 | 973 | .fn_void_no_args, |
| ... | ... | @@ -988,6 +1025,8 @@ pub const Type = extern union { |
| 988 | 1025 | .@"null", |
| 989 | 1026 | .@"undefined", |
| 990 | 1027 | .array, |
| 1028 | .array_sentinel, |
| 1029 | .array_u8, |
| 991 | 1030 | .array_u8_sentinel_0, |
| 992 | 1031 | .fn_noreturn_no_args, |
| 993 | 1032 | .fn_void_no_args, |
| ... | ... | @@ -1072,9 +1111,10 @@ pub const Type = extern union { |
| 1072 | 1111 | => unreachable, |
| 1073 | 1112 | |
| 1074 | 1113 | .array => self.cast(Payload.Array).?.elem_type, |
| 1114 | .array_sentinel => self.cast(Payload.ArraySentinel).?.elem_type, |
| 1075 | 1115 | .single_const_pointer => self.castPointer().?.pointee_type, |
| 1076 | 1116 | .single_mut_pointer => self.castPointer().?.pointee_type, |
| 1077 | | .array_u8_sentinel_0, .const_slice_u8 => Type.initTag(.u8), |
| 1117 | .array_u8, .array_u8_sentinel_0, .const_slice_u8 => Type.initTag(.u8), |
| 1078 | 1118 | .single_const_pointer_to_comptime_int => Type.initTag(.comptime_int), |
| 1079 | 1119 | }; |
| 1080 | 1120 | } |
| ... | ... | @@ -1176,6 +1216,8 @@ pub const Type = extern union { |
| 1176 | 1216 | => unreachable, |
| 1177 | 1217 | |
| 1178 | 1218 | .array => self.cast(Payload.Array).?.len, |
| 1219 | .array_sentinel => self.cast(Payload.ArraySentinel).?.len, |
| 1220 | .array_u8 => self.cast(Payload.Array_u8).?.len, |
| 1179 | 1221 | .array_u8_sentinel_0 => self.cast(Payload.Array_u8_Sentinel0).?.len, |
| 1180 | 1222 | }; |
| 1181 | 1223 | } |
| ... | ... | @@ -1232,7 +1274,8 @@ pub const Type = extern union { |
| 1232 | 1274 | .optional_single_const_pointer, |
| 1233 | 1275 | => unreachable, |
| 1234 | 1276 | |
| 1235 | | .array => return null, |
| 1277 | .array, .array_u8 => return null, |
| 1278 | .array_sentinel => return self.cast(Payload.ArraySentinel).?.sentinel, |
| 1236 | 1279 | .array_u8_sentinel_0 => return Value.initTag(.zero), |
| 1237 | 1280 | }; |
| 1238 | 1281 | } |
| ... | ... | @@ -1266,10 +1309,12 @@ pub const Type = extern union { |
| 1266 | 1309 | .fn_ccc_void_no_args, |
| 1267 | 1310 | .function, |
| 1268 | 1311 | .array, |
| 1312 | .array_sentinel, |
| 1313 | .array_u8, |
| 1314 | .array_u8_sentinel_0, |
| 1269 | 1315 | .single_const_pointer, |
| 1270 | 1316 | .single_mut_pointer, |
| 1271 | 1317 | .single_const_pointer_to_comptime_int, |
| 1272 | | .array_u8_sentinel_0, |
| 1273 | 1318 | .const_slice_u8, |
| 1274 | 1319 | .int_unsigned, |
| 1275 | 1320 | .u8, |
| ... | ... | @@ -1324,10 +1369,12 @@ pub const Type = extern union { |
| 1324 | 1369 | .fn_ccc_void_no_args, |
| 1325 | 1370 | .function, |
| 1326 | 1371 | .array, |
| 1372 | .array_sentinel, |
| 1373 | .array_u8, |
| 1374 | .array_u8_sentinel_0, |
| 1327 | 1375 | .single_const_pointer, |
| 1328 | 1376 | .single_mut_pointer, |
| 1329 | 1377 | .single_const_pointer_to_comptime_int, |
| 1330 | | .array_u8_sentinel_0, |
| 1331 | 1378 | .const_slice_u8, |
| 1332 | 1379 | .int_signed, |
| 1333 | 1380 | .i8, |
| ... | ... | @@ -1382,10 +1429,12 @@ pub const Type = extern union { |
| 1382 | 1429 | .fn_ccc_void_no_args, |
| 1383 | 1430 | .function, |
| 1384 | 1431 | .array, |
| 1432 | .array_sentinel, |
| 1433 | .array_u8, |
| 1434 | .array_u8_sentinel_0, |
| 1385 | 1435 | .single_const_pointer, |
| 1386 | 1436 | .single_mut_pointer, |
| 1387 | 1437 | .single_const_pointer_to_comptime_int, |
| 1388 | | .array_u8_sentinel_0, |
| 1389 | 1438 | .const_slice_u8, |
| 1390 | 1439 | .optional, |
| 1391 | 1440 | .optional_single_mut_pointer, |
| ... | ... | @@ -1438,10 +1487,12 @@ pub const Type = extern union { |
| 1438 | 1487 | .fn_ccc_void_no_args, |
| 1439 | 1488 | .function, |
| 1440 | 1489 | .array, |
| 1490 | .array_sentinel, |
| 1491 | .array_u8, |
| 1492 | .array_u8_sentinel_0, |
| 1441 | 1493 | .single_const_pointer, |
| 1442 | 1494 | .single_mut_pointer, |
| 1443 | 1495 | .single_const_pointer_to_comptime_int, |
| 1444 | | .array_u8_sentinel_0, |
| 1445 | 1496 | .const_slice_u8, |
| 1446 | 1497 | .int_unsigned, |
| 1447 | 1498 | .int_signed, |
| ... | ... | @@ -1523,10 +1574,12 @@ pub const Type = extern union { |
| 1523 | 1574 | .@"null", |
| 1524 | 1575 | .@"undefined", |
| 1525 | 1576 | .array, |
| 1577 | .array_sentinel, |
| 1578 | .array_u8, |
| 1579 | .array_u8_sentinel_0, |
| 1526 | 1580 | .single_const_pointer, |
| 1527 | 1581 | .single_mut_pointer, |
| 1528 | 1582 | .single_const_pointer_to_comptime_int, |
| 1529 | | .array_u8_sentinel_0, |
| 1530 | 1583 | .const_slice_u8, |
| 1531 | 1584 | .u8, |
| 1532 | 1585 | .i8, |
| ... | ... | @@ -1584,10 +1637,12 @@ pub const Type = extern union { |
| 1584 | 1637 | .@"null", |
| 1585 | 1638 | .@"undefined", |
| 1586 | 1639 | .array, |
| 1640 | .array_sentinel, |
| 1641 | .array_u8, |
| 1642 | .array_u8_sentinel_0, |
| 1587 | 1643 | .single_const_pointer, |
| 1588 | 1644 | .single_mut_pointer, |
| 1589 | 1645 | .single_const_pointer_to_comptime_int, |
| 1590 | | .array_u8_sentinel_0, |
| 1591 | 1646 | .const_slice_u8, |
| 1592 | 1647 | .u8, |
| 1593 | 1648 | .i8, |
| ... | ... | @@ -1644,10 +1699,12 @@ pub const Type = extern union { |
| 1644 | 1699 | .@"null", |
| 1645 | 1700 | .@"undefined", |
| 1646 | 1701 | .array, |
| 1702 | .array_sentinel, |
| 1703 | .array_u8, |
| 1704 | .array_u8_sentinel_0, |
| 1647 | 1705 | .single_const_pointer, |
| 1648 | 1706 | .single_mut_pointer, |
| 1649 | 1707 | .single_const_pointer_to_comptime_int, |
| 1650 | | .array_u8_sentinel_0, |
| 1651 | 1708 | .const_slice_u8, |
| 1652 | 1709 | .u8, |
| 1653 | 1710 | .i8, |
| ... | ... | @@ -1704,10 +1761,12 @@ pub const Type = extern union { |
| 1704 | 1761 | .@"null", |
| 1705 | 1762 | .@"undefined", |
| 1706 | 1763 | .array, |
| 1764 | .array_sentinel, |
| 1765 | .array_u8, |
| 1766 | .array_u8_sentinel_0, |
| 1707 | 1767 | .single_const_pointer, |
| 1708 | 1768 | .single_mut_pointer, |
| 1709 | 1769 | .single_const_pointer_to_comptime_int, |
| 1710 | | .array_u8_sentinel_0, |
| 1711 | 1770 | .const_slice_u8, |
| 1712 | 1771 | .u8, |
| 1713 | 1772 | .i8, |
| ... | ... | @@ -1761,10 +1820,12 @@ pub const Type = extern union { |
| 1761 | 1820 | .@"null", |
| 1762 | 1821 | .@"undefined", |
| 1763 | 1822 | .array, |
| 1823 | .array_sentinel, |
| 1824 | .array_u8, |
| 1825 | .array_u8_sentinel_0, |
| 1764 | 1826 | .single_const_pointer, |
| 1765 | 1827 | .single_mut_pointer, |
| 1766 | 1828 | .single_const_pointer_to_comptime_int, |
| 1767 | | .array_u8_sentinel_0, |
| 1768 | 1829 | .const_slice_u8, |
| 1769 | 1830 | .u8, |
| 1770 | 1831 | .i8, |
| ... | ... | @@ -1818,10 +1879,12 @@ pub const Type = extern union { |
| 1818 | 1879 | .@"null", |
| 1819 | 1880 | .@"undefined", |
| 1820 | 1881 | .array, |
| 1882 | .array_sentinel, |
| 1883 | .array_u8, |
| 1884 | .array_u8_sentinel_0, |
| 1821 | 1885 | .single_const_pointer, |
| 1822 | 1886 | .single_mut_pointer, |
| 1823 | 1887 | .single_const_pointer_to_comptime_int, |
| 1824 | | .array_u8_sentinel_0, |
| 1825 | 1888 | .const_slice_u8, |
| 1826 | 1889 | .u8, |
| 1827 | 1890 | .i8, |
| ... | ... | @@ -1895,10 +1958,12 @@ pub const Type = extern union { |
| 1895 | 1958 | .fn_ccc_void_no_args, |
| 1896 | 1959 | .function, |
| 1897 | 1960 | .array, |
| 1961 | .array_sentinel, |
| 1962 | .array_u8, |
| 1963 | .array_u8_sentinel_0, |
| 1898 | 1964 | .single_const_pointer, |
| 1899 | 1965 | .single_mut_pointer, |
| 1900 | 1966 | .single_const_pointer_to_comptime_int, |
| 1901 | | .array_u8_sentinel_0, |
| 1902 | 1967 | .const_slice_u8, |
| 1903 | 1968 | .optional, |
| 1904 | 1969 | .optional_single_mut_pointer, |
| ... | ... | @@ -1944,6 +2009,7 @@ pub const Type = extern union { |
| 1944 | 2009 | .fn_ccc_void_no_args, |
| 1945 | 2010 | .function, |
| 1946 | 2011 | .single_const_pointer_to_comptime_int, |
| 2012 | .array_sentinel, |
| 1947 | 2013 | .array_u8_sentinel_0, |
| 1948 | 2014 | .const_slice_u8, |
| 1949 | 2015 | .c_void, |
| ... | ... | @@ -1971,11 +2037,10 @@ pub const Type = extern union { |
| 1971 | 2037 | return null; |
| 1972 | 2038 | } |
| 1973 | 2039 | }, |
| 1974 | | .array => { |
| 1975 | | const array = ty.cast(Payload.Array).?; |
| 1976 | | if (array.len == 0) |
| 2040 | .array, .array_u8 => { |
| 2041 | if (ty.arrayLen() == 0) |
| 1977 | 2042 | return Value.initTag(.empty_array); |
| 1978 | | ty = array.elem_type; |
| 2043 | ty = ty.elemType(); |
| 1979 | 2044 | continue; |
| 1980 | 2045 | }, |
| 1981 | 2046 | .single_const_pointer, .single_mut_pointer => { |
| ... | ... | @@ -2022,7 +2087,6 @@ pub const Type = extern union { |
| 2022 | 2087 | .fn_ccc_void_no_args, |
| 2023 | 2088 | .function, |
| 2024 | 2089 | .single_const_pointer_to_comptime_int, |
| 2025 | | .array_u8_sentinel_0, |
| 2026 | 2090 | .const_slice_u8, |
| 2027 | 2091 | .c_void, |
| 2028 | 2092 | .void, |
| ... | ... | @@ -2032,6 +2096,9 @@ pub const Type = extern union { |
| 2032 | 2096 | .int_unsigned, |
| 2033 | 2097 | .int_signed, |
| 2034 | 2098 | .array, |
| 2099 | .array_sentinel, |
| 2100 | .array_u8, |
| 2101 | .array_u8_sentinel_0, |
| 2035 | 2102 | .single_const_pointer, |
| 2036 | 2103 | .single_mut_pointer, |
| 2037 | 2104 | .optional, |
| ... | ... | @@ -2090,8 +2157,10 @@ pub const Type = extern union { |
| 2090 | 2157 | const_slice_u8, // See last_no_payload_tag below. |
| 2091 | 2158 | // After this, the tag requires a payload. |
| 2092 | 2159 | |
| 2160 | array_u8, |
| 2093 | 2161 | array_u8_sentinel_0, |
| 2094 | 2162 | array, |
| 2163 | array_sentinel, |
| 2095 | 2164 | single_const_pointer, |
| 2096 | 2165 | single_mut_pointer, |
| 2097 | 2166 | int_signed, |
| ... | ... | @@ -2114,11 +2183,25 @@ pub const Type = extern union { |
| 2114 | 2183 | len: u64, |
| 2115 | 2184 | }; |
| 2116 | 2185 | |
| 2186 | pub const Array_u8 = struct { |
| 2187 | base: Payload = Payload{ .tag = .array_u8 }, |
| 2188 | |
| 2189 | len: u64, |
| 2190 | }; |
| 2191 | |
| 2117 | 2192 | pub const Array = struct { |
| 2118 | 2193 | base: Payload = Payload{ .tag = .array }, |
| 2119 | 2194 | |
| 2195 | len: u64, |
| 2120 | 2196 | elem_type: Type, |
| 2197 | }; |
| 2198 | |
| 2199 | pub const ArraySentinel = struct { |
| 2200 | base: Payload = Payload{ .tag = .array_sentinel }, |
| 2201 | |
| 2121 | 2202 | len: u64, |
| 2203 | sentinel: Value, |
| 2204 | elem_type: Type, |
| 2122 | 2205 | }; |
| 2123 | 2206 | |
| 2124 | 2207 | pub const Pointer = struct { |