| ... | ... | @@ -70,6 +70,7 @@ pub const Value = extern union { |
| 70 | 70 | // After this, the tag requires a payload. |
| 71 | 71 | |
| 72 | 72 | ty, |
| 73 | int_type, |
| 73 | 74 | int_u64, |
| 74 | 75 | int_i64, |
| 75 | 76 | int_big_positive, |
| ... | ... | @@ -178,6 +179,7 @@ pub const Value = extern union { |
| 178 | 179 | }; |
| 179 | 180 | return Value{ .ptr_otherwise = &new_payload.base }; |
| 180 | 181 | }, |
| 182 | .int_type => return self.copyPayloadShallow(allocator, Payload.IntType), |
| 181 | 183 | .int_u64 => return self.copyPayloadShallow(allocator, Payload.Int_u64), |
| 182 | 184 | .int_i64 => return self.copyPayloadShallow(allocator, Payload.Int_i64), |
| 183 | 185 | .int_big_positive => { |
| ... | ... | @@ -287,6 +289,13 @@ pub const Value = extern union { |
| 287 | 289 | .bool_true => return out_stream.writeAll("true"), |
| 288 | 290 | .bool_false => return out_stream.writeAll("false"), |
| 289 | 291 | .ty => return val.cast(Payload.Ty).?.ty.format("", options, out_stream), |
| 292 | .int_type => { |
| 293 | const int_type = val.cast(Payload.IntType).?; |
| 294 | return out_stream.print("{}{}", .{ |
| 295 | if (int_type.signed) "s" else "u", |
| 296 | int_type.bits, |
| 297 | }); |
| 298 | }, |
| 290 | 299 | .int_u64 => return std.fmt.formatIntValue(val.cast(Payload.Int_u64).?.int, "", options, out_stream), |
| 291 | 300 | .int_i64 => return std.fmt.formatIntValue(val.cast(Payload.Int_i64).?.int, "", options, out_stream), |
| 292 | 301 | .int_big_positive => return out_stream.print("{}", .{val.cast(Payload.IntBigPositive).?.asBigInt()}), |
| ... | ... | @@ -335,6 +344,7 @@ pub const Value = extern union { |
| 335 | 344 | pub fn toType(self: Value) Type { |
| 336 | 345 | return switch (self.tag()) { |
| 337 | 346 | .ty => self.cast(Payload.Ty).?.ty, |
| 347 | .int_type => @panic("TODO int type to type"), |
| 338 | 348 | |
| 339 | 349 | .u8_type => Type.initTag(.u8), |
| 340 | 350 | .i8_type => Type.initTag(.i8), |
| ... | ... | @@ -404,6 +414,7 @@ pub const Value = extern union { |
| 404 | 414 | pub fn toBigInt(self: Value, space: *BigIntSpace) BigIntConst { |
| 405 | 415 | switch (self.tag()) { |
| 406 | 416 | .ty, |
| 417 | .int_type, |
| 407 | 418 | .u8_type, |
| 408 | 419 | .i8_type, |
| 409 | 420 | .u16_type, |
| ... | ... | @@ -475,6 +486,7 @@ pub const Value = extern union { |
| 475 | 486 | pub fn toUnsignedInt(self: Value) u64 { |
| 476 | 487 | switch (self.tag()) { |
| 477 | 488 | .ty, |
| 489 | .int_type, |
| 478 | 490 | .u8_type, |
| 479 | 491 | .i8_type, |
| 480 | 492 | .u16_type, |
| ... | ... | @@ -553,7 +565,7 @@ pub const Value = extern union { |
| 553 | 565 | /// Asserts that the value is a float or an integer. |
| 554 | 566 | pub fn toF128(self: Value) f128 { |
| 555 | 567 | return switch (self.tag()) { |
| 556 | | .float_16 => self.cast(Payload.Float_16).?.val, |
| 568 | .float_16 => @panic("TODO soft float"), |
| 557 | 569 | .float_32 => self.cast(Payload.Float_32).?.val, |
| 558 | 570 | .float_64 => self.cast(Payload.Float_64).?.val, |
| 559 | 571 | .float_128 => self.cast(Payload.Float_128).?.val, |
| ... | ... | @@ -573,6 +585,7 @@ pub const Value = extern union { |
| 573 | 585 | pub fn intBitCountTwosComp(self: Value) usize { |
| 574 | 586 | switch (self.tag()) { |
| 575 | 587 | .ty, |
| 588 | .int_type, |
| 576 | 589 | .u8_type, |
| 577 | 590 | .i8_type, |
| 578 | 591 | .u16_type, |
| ... | ... | @@ -650,6 +663,7 @@ pub const Value = extern union { |
| 650 | 663 | pub fn intFitsInType(self: Value, ty: Type, target: Target) bool { |
| 651 | 664 | switch (self.tag()) { |
| 652 | 665 | .ty, |
| 666 | .int_type, |
| 653 | 667 | .u8_type, |
| 654 | 668 | .i8_type, |
| 655 | 669 | .u16_type, |
| ... | ... | @@ -763,6 +777,7 @@ pub const Value = extern union { |
| 763 | 777 | pub fn floatHasFraction(self: Value) bool { |
| 764 | 778 | return switch (self.tag()) { |
| 765 | 779 | .ty, |
| 780 | .int_type, |
| 766 | 781 | .u8_type, |
| 767 | 782 | .i8_type, |
| 768 | 783 | .u16_type, |
| ... | ... | @@ -832,6 +847,7 @@ pub const Value = extern union { |
| 832 | 847 | pub fn orderAgainstZero(lhs: Value) std.math.Order { |
| 833 | 848 | return switch (lhs.tag()) { |
| 834 | 849 | .ty, |
| 850 | .int_type, |
| 835 | 851 | .u8_type, |
| 836 | 852 | .i8_type, |
| 837 | 853 | .u16_type, |
| ... | ... | @@ -955,6 +971,7 @@ pub const Value = extern union { |
| 955 | 971 | pub fn pointerDeref(self: Value, allocator: *Allocator) error{ AnalysisFail, OutOfMemory }!Value { |
| 956 | 972 | return switch (self.tag()) { |
| 957 | 973 | .ty, |
| 974 | .int_type, |
| 958 | 975 | .u8_type, |
| 959 | 976 | .i8_type, |
| 960 | 977 | .u16_type, |
| ... | ... | @@ -1028,6 +1045,7 @@ pub const Value = extern union { |
| 1028 | 1045 | pub fn elemValue(self: Value, allocator: *Allocator, index: usize) error{OutOfMemory}!Value { |
| 1029 | 1046 | switch (self.tag()) { |
| 1030 | 1047 | .ty, |
| 1048 | .int_type, |
| 1031 | 1049 | .u8_type, |
| 1032 | 1050 | .i8_type, |
| 1033 | 1051 | .u16_type, |
| ... | ... | @@ -1118,6 +1136,7 @@ pub const Value = extern union { |
| 1118 | 1136 | pub fn isNull(self: Value) bool { |
| 1119 | 1137 | return switch (self.tag()) { |
| 1120 | 1138 | .ty, |
| 1139 | .int_type, |
| 1121 | 1140 | .u8_type, |
| 1122 | 1141 | .i8_type, |
| 1123 | 1142 | .u16_type, |
| ... | ... | @@ -1266,6 +1285,12 @@ pub const Value = extern union { |
| 1266 | 1285 | ty: Type, |
| 1267 | 1286 | }; |
| 1268 | 1287 | |
| 1288 | pub const IntType = struct { |
| 1289 | base: Payload = Payload{ .tag = .int_type }, |
| 1290 | bits: u16, |
| 1291 | signed: bool, |
| 1292 | }; |
| 1293 | |
| 1269 | 1294 | pub const Repeated = struct { |
| 1270 | 1295 | base: Payload = Payload{ .tag = .ty }, |
| 1271 | 1296 | /// This value is repeated some number of times. The amount of times to repeat |