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