| author | |
| committer | |
| log | 45da72c5b64069b7d5238465130a50f96678a148 |
| tree | 136529c703d9cb9e52f2df2354dc0bb03fcbc482 |
| parent | 1d06c82c3bc44e808a3d7b4fe07e5c9fc492e8c3 |
| signature |
28 files changed, 145 insertions(+), 315 deletions(-)
lib/std/build.zig+11-11| ... | ... | @@ -607,13 +607,13 @@ pub const Builder = struct { |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | fn typeToEnum(comptime T: type) TypeId { |
| 610 | return switch (@typeId(T)) { | |
| 611 | builtin.TypeId.Int => TypeId.Int, | |
| 612 | builtin.TypeId.Float => TypeId.Float, | |
| 613 | builtin.TypeId.Bool => TypeId.Bool, | |
| 610 | return switch (@typeInfo(T)) { | |
| 611 | .Int => .Int, | |
| 612 | .Float => .Float, | |
| 613 | .Bool => .Bool, | |
| 614 | 614 | else => switch (T) { |
| 615 | []const u8 => TypeId.String, | |
| 616 | []const []const u8 => TypeId.List, | |
| 615 | []const u8 => .String, | |
| 616 | []const []const u8 => .List, | |
| 617 | 617 | else => @compileError("Unsupported type: " ++ @typeName(T)), |
| 618 | 618 | }, |
| 619 | 619 | }; |
| ... | ... | @@ -625,11 +625,11 @@ pub const Builder = struct { |
| 625 | 625 | |
| 626 | 626 | pub fn typeIdName(id: TypeId) []const u8 { |
| 627 | 627 | return switch (id) { |
| 628 | TypeId.Bool => "bool", | |
| 629 | TypeId.Int => "int", | |
| 630 | TypeId.Float => "float", | |
| 631 | TypeId.String => "string", | |
| 632 | TypeId.List => "list", | |
| 628 | .Bool => "bool", | |
| 629 | .Int => "int", | |
| 630 | .Float => "float", | |
| 631 | .String => "string", | |
| 632 | .List => "list", | |
| 633 | 633 | }; |
| 634 | 634 | } |
| 635 | 635 |
lib/std/fmt.zig+8-7| ... | ... | @@ -405,7 +405,7 @@ pub fn formatType( |
| 405 | 405 | try format(context, Errors, output, "@{x}", .{@ptrToInt(&value)}); |
| 406 | 406 | } |
| 407 | 407 | }, |
| 408 | .Struct => { | |
| 408 | .Struct => |StructT| { | |
| 409 | 409 | if (comptime std.meta.trait.hasFn("format")(T)) { |
| 410 | 410 | return value.format(fmt, options, context, Errors, output); |
| 411 | 411 | } |
| ... | ... | @@ -416,27 +416,28 @@ pub fn formatType( |
| 416 | 416 | } |
| 417 | 417 | comptime var field_i = 0; |
| 418 | 418 | try output(context, "{"); |
| 419 | inline while (field_i < @memberCount(T)) : (field_i += 1) { | |
| 419 | inline for (StructT.fields) |f| { | |
| 420 | 420 | if (field_i == 0) { |
| 421 | 421 | try output(context, " ."); |
| 422 | 422 | } else { |
| 423 | 423 | try output(context, ", ."); |
| 424 | 424 | } |
| 425 | try output(context, @memberName(T, field_i)); | |
| 425 | try output(context, f.name); | |
| 426 | 426 | try output(context, " = "); |
| 427 | try formatType(@field(value, @memberName(T, field_i)), fmt, options, context, Errors, output, max_depth - 1); | |
| 427 | try formatType(@field(value, f.name), fmt, options, context, Errors, output, max_depth - 1); | |
| 428 | field_i += 1; | |
| 428 | 429 | } |
| 429 | 430 | try output(context, " }"); |
| 430 | 431 | }, |
| 431 | 432 | .Pointer => |ptr_info| switch (ptr_info.size) { |
| 432 | 433 | .One => switch (@typeInfo(ptr_info.child)) { |
| 433 | builtin.TypeId.Array => |info| { | |
| 434 | .Array => |info| { | |
| 434 | 435 | if (info.child == u8) { |
| 435 | 436 | return formatText(value, fmt, options, context, Errors, output); |
| 436 | 437 | } |
| 437 | 438 | return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }); |
| 438 | 439 | }, |
| 439 | builtin.TypeId.Enum, builtin.TypeId.Union, builtin.TypeId.Struct => { | |
| 440 | .Enum, .Union, .Struct => { | |
| 440 | 441 | return formatType(value.*, fmt, options, context, Errors, output, max_depth); |
| 441 | 442 | }, |
| 442 | 443 | else => return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }), |
| ... | ... | @@ -509,7 +510,7 @@ fn formatValue( |
| 509 | 510 | } |
| 510 | 511 | |
| 511 | 512 | const T = @TypeOf(value); |
| 512 | switch (@typeId(T)) { | |
| 513 | switch (@typeInfo(T)) { | |
| 513 | 514 | .Float => return formatFloatValue(value, fmt, options, context, Errors, output), |
| 514 | 515 | .Int, .ComptimeInt => return formatIntValue(value, fmt, options, context, Errors, output), |
| 515 | 516 | .Bool => return output(context, if (value) "true" else "false"), |
lib/std/io.zig+23-23| ... | ... | @@ -831,7 +831,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, |
| 831 | 831 | |
| 832 | 832 | //@BUG: inferred error issue. See: #1386 |
| 833 | 833 | fn deserializeInt(self: *Self, comptime T: type) (Error || error{EndOfStream})!T { |
| 834 | comptime assert(trait.is(builtin.TypeId.Int)(T) or trait.is(builtin.TypeId.Float)(T)); | |
| 834 | comptime assert(trait.is(.Int)(T) or trait.is(.Float)(T)); | |
| 835 | 835 | |
| 836 | 836 | const u8_bit_count = 8; |
| 837 | 837 | const t_bit_count = comptime meta.bitCount(T); |
| ... | ... | @@ -880,9 +880,9 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, |
| 880 | 880 | /// Deserializes data into the type pointed to by `ptr` |
| 881 | 881 | pub fn deserializeInto(self: *Self, ptr: var) !void { |
| 882 | 882 | const T = @TypeOf(ptr); |
| 883 | comptime assert(trait.is(builtin.TypeId.Pointer)(T)); | |
| 883 | comptime assert(trait.is(.Pointer)(T)); | |
| 884 | 884 | |
| 885 | if (comptime trait.isSlice(T) or comptime trait.isPtrTo(builtin.TypeId.Array)(T)) { | |
| 885 | if (comptime trait.isSlice(T) or comptime trait.isPtrTo(.Array)(T)) { | |
| 886 | 886 | for (ptr) |*v| |
| 887 | 887 | try self.deserializeInto(v); |
| 888 | 888 | return; |
| ... | ... | @@ -891,7 +891,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, |
| 891 | 891 | comptime assert(trait.isSingleItemPtr(T)); |
| 892 | 892 | |
| 893 | 893 | const C = comptime meta.Child(T); |
| 894 | const child_type_id = @typeId(C); | |
| 894 | const child_type_id = @typeInfo(C); | |
| 895 | 895 | |
| 896 | 896 | //custom deserializer: fn(self: *Self, deserializer: var) !void |
| 897 | 897 | if (comptime trait.hasFn("deserialize")(C)) return C.deserialize(ptr, self); |
| ... | ... | @@ -902,10 +902,10 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | switch (child_type_id) { |
| 905 | builtin.TypeId.Void => return, | |
| 906 | builtin.TypeId.Bool => ptr.* = (try self.deserializeInt(u1)) > 0, | |
| 907 | builtin.TypeId.Float, builtin.TypeId.Int => ptr.* = try self.deserializeInt(C), | |
| 908 | builtin.TypeId.Struct => { | |
| 905 | .Void => return, | |
| 906 | .Bool => ptr.* = (try self.deserializeInt(u1)) > 0, | |
| 907 | .Float, .Int => ptr.* = try self.deserializeInt(C), | |
| 908 | .Struct => { | |
| 909 | 909 | const info = @typeInfo(C).Struct; |
| 910 | 910 | |
| 911 | 911 | inline for (info.fields) |*field_info| { |
| ... | ... | @@ -915,7 +915,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, |
| 915 | 915 | if (FieldType == void or FieldType == u0) continue; |
| 916 | 916 | |
| 917 | 917 | //it doesn't make any sense to read pointers |
| 918 | if (comptime trait.is(builtin.TypeId.Pointer)(FieldType)) { | |
| 918 | if (comptime trait.is(.Pointer)(FieldType)) { | |
| 919 | 919 | @compileError("Will not " ++ "read field " ++ name ++ " of struct " ++ |
| 920 | 920 | @typeName(C) ++ " because it " ++ "is of pointer-type " ++ |
| 921 | 921 | @typeName(FieldType) ++ "."); |
| ... | ... | @@ -924,7 +924,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, |
| 924 | 924 | try self.deserializeInto(&@field(ptr, name)); |
| 925 | 925 | } |
| 926 | 926 | }, |
| 927 | builtin.TypeId.Union => { | |
| 927 | .Union => { | |
| 928 | 928 | const info = @typeInfo(C).Union; |
| 929 | 929 | if (info.tag_type) |TagType| { |
| 930 | 930 | //we avoid duplicate iteration over the enum tags |
| ... | ... | @@ -948,7 +948,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, |
| 948 | 948 | @compileError("Cannot meaningfully deserialize " ++ @typeName(C) ++ |
| 949 | 949 | " because it is an untagged union. Use a custom deserialize()."); |
| 950 | 950 | }, |
| 951 | builtin.TypeId.Optional => { | |
| 951 | .Optional => { | |
| 952 | 952 | const OC = comptime meta.Child(C); |
| 953 | 953 | const exists = (try self.deserializeInt(u1)) > 0; |
| 954 | 954 | if (!exists) { |
| ... | ... | @@ -960,7 +960,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, |
| 960 | 960 | const val_ptr = &ptr.*.?; |
| 961 | 961 | try self.deserializeInto(val_ptr); |
| 962 | 962 | }, |
| 963 | builtin.TypeId.Enum => { | |
| 963 | .Enum => { | |
| 964 | 964 | var value = try self.deserializeInt(@TagType(C)); |
| 965 | 965 | ptr.* = try meta.intToEnum(C, value); |
| 966 | 966 | }, |
| ... | ... | @@ -1009,7 +1009,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co |
| 1009 | 1009 | |
| 1010 | 1010 | fn serializeInt(self: *Self, value: var) Error!void { |
| 1011 | 1011 | const T = @TypeOf(value); |
| 1012 | comptime assert(trait.is(builtin.TypeId.Int)(T) or trait.is(builtin.TypeId.Float)(T)); | |
| 1012 | comptime assert(trait.is(.Int)(T) or trait.is(.Float)(T)); | |
| 1013 | 1013 | |
| 1014 | 1014 | const t_bit_count = comptime meta.bitCount(T); |
| 1015 | 1015 | const u8_bit_count = comptime meta.bitCount(u8); |
| ... | ... | @@ -1058,11 +1058,11 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co |
| 1058 | 1058 | return; |
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | switch (@typeId(T)) { | |
| 1062 | builtin.TypeId.Void => return, | |
| 1063 | builtin.TypeId.Bool => try self.serializeInt(@as(u1, @boolToInt(value))), | |
| 1064 | builtin.TypeId.Float, builtin.TypeId.Int => try self.serializeInt(value), | |
| 1065 | builtin.TypeId.Struct => { | |
| 1061 | switch (@typeInfo(T)) { | |
| 1062 | .Void => return, | |
| 1063 | .Bool => try self.serializeInt(@as(u1, @boolToInt(value))), | |
| 1064 | .Float, .Int => try self.serializeInt(value), | |
| 1065 | .Struct => { | |
| 1066 | 1066 | const info = @typeInfo(T); |
| 1067 | 1067 | |
| 1068 | 1068 | inline for (info.Struct.fields) |*field_info| { |
| ... | ... | @@ -1072,7 +1072,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co |
| 1072 | 1072 | if (FieldType == void or FieldType == u0) continue; |
| 1073 | 1073 | |
| 1074 | 1074 | //It doesn't make sense to write pointers |
| 1075 | if (comptime trait.is(builtin.TypeId.Pointer)(FieldType)) { | |
| 1075 | if (comptime trait.is(.Pointer)(FieldType)) { | |
| 1076 | 1076 | @compileError("Will not " ++ "serialize field " ++ name ++ |
| 1077 | 1077 | " of struct " ++ @typeName(T) ++ " because it " ++ |
| 1078 | 1078 | "is of pointer-type " ++ @typeName(FieldType) ++ "."); |
| ... | ... | @@ -1080,7 +1080,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co |
| 1080 | 1080 | try self.serialize(@field(value, name)); |
| 1081 | 1081 | } |
| 1082 | 1082 | }, |
| 1083 | builtin.TypeId.Union => { | |
| 1083 | .Union => { | |
| 1084 | 1084 | const info = @typeInfo(T).Union; |
| 1085 | 1085 | if (info.tag_type) |TagType| { |
| 1086 | 1086 | const active_tag = meta.activeTag(value); |
| ... | ... | @@ -1101,7 +1101,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co |
| 1101 | 1101 | @compileError("Cannot meaningfully serialize " ++ @typeName(T) ++ |
| 1102 | 1102 | " because it is an untagged union. Use a custom serialize()."); |
| 1103 | 1103 | }, |
| 1104 | builtin.TypeId.Optional => { | |
| 1104 | .Optional => { | |
| 1105 | 1105 | if (value == null) { |
| 1106 | 1106 | try self.serializeInt(@as(u1, @boolToInt(false))); |
| 1107 | 1107 | return; |
| ... | ... | @@ -1112,10 +1112,10 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co |
| 1112 | 1112 | const val_ptr = &value.?; |
| 1113 | 1113 | try self.serialize(val_ptr.*); |
| 1114 | 1114 | }, |
| 1115 | builtin.TypeId.Enum => { | |
| 1115 | .Enum => { | |
| 1116 | 1116 | try self.serializeInt(@enumToInt(value)); |
| 1117 | 1117 | }, |
| 1118 | else => @compileError("Cannot serialize " ++ @tagName(@typeId(T)) ++ " types (unimplemented)."), | |
| 1118 | else => @compileError("Cannot serialize " ++ @tagName(@typeInfo(T)) ++ " types (unimplemented)."), | |
| 1119 | 1119 | } |
| 1120 | 1120 | } |
| 1121 | 1121 | }; |
lib/std/math.zig+15-17| ... | ... | @@ -1,6 +1,4 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | 1 | const std = @import("std.zig"); |
| 3 | const TypeId = builtin.TypeId; | |
| 4 | 2 | const assert = std.debug.assert; |
| 5 | 3 | const testing = std.testing; |
| 6 | 4 | |
| ... | ... | @@ -89,7 +87,7 @@ pub const snan = @import("math/nan.zig").snan; |
| 89 | 87 | pub const inf = @import("math/inf.zig").inf; |
| 90 | 88 | |
| 91 | 89 | pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool { |
| 92 | assert(@typeId(T) == TypeId.Float); | |
| 90 | assert(@typeInfo(T) == .Float); | |
| 93 | 91 | return fabs(x - y) < epsilon; |
| 94 | 92 | } |
| 95 | 93 | |
| ... | ... | @@ -198,7 +196,7 @@ test "" { |
| 198 | 196 | } |
| 199 | 197 | |
| 200 | 198 | pub fn floatMantissaBits(comptime T: type) comptime_int { |
| 201 | assert(@typeId(T) == builtin.TypeId.Float); | |
| 199 | assert(@typeInfo(T) == .Float); | |
| 202 | 200 | |
| 203 | 201 | return switch (T.bit_count) { |
| 204 | 202 | 16 => 10, |
| ... | ... | @@ -211,7 +209,7 @@ pub fn floatMantissaBits(comptime T: type) comptime_int { |
| 211 | 209 | } |
| 212 | 210 | |
| 213 | 211 | pub fn floatExponentBits(comptime T: type) comptime_int { |
| 214 | assert(@typeId(T) == builtin.TypeId.Float); | |
| 212 | assert(@typeInfo(T) == .Float); | |
| 215 | 213 | |
| 216 | 214 | return switch (T.bit_count) { |
| 217 | 215 | 16 => 5, |
| ... | ... | @@ -526,7 +524,7 @@ fn testOverflow() void { |
| 526 | 524 | |
| 527 | 525 | pub fn absInt(x: var) !@TypeOf(x) { |
| 528 | 526 | const T = @TypeOf(x); |
| 529 | comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt | |
| 527 | comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt | |
| 530 | 528 | comptime assert(T.is_signed); // must pass a signed integer to absInt |
| 531 | 529 | |
| 532 | 530 | if (x == minInt(@TypeOf(x))) { |
| ... | ... | @@ -560,7 +558,7 @@ fn testAbsFloat() void { |
| 560 | 558 | pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T { |
| 561 | 559 | @setRuntimeSafety(false); |
| 562 | 560 | if (denominator == 0) return error.DivisionByZero; |
| 563 | if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow; | |
| 561 | if (@typeInfo(T) == .Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow; | |
| 564 | 562 | return @divTrunc(numerator, denominator); |
| 565 | 563 | } |
| 566 | 564 | |
| ... | ... | @@ -581,7 +579,7 @@ fn testDivTrunc() void { |
| 581 | 579 | pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T { |
| 582 | 580 | @setRuntimeSafety(false); |
| 583 | 581 | if (denominator == 0) return error.DivisionByZero; |
| 584 | if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow; | |
| 582 | if (@typeInfo(T) == .Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow; | |
| 585 | 583 | return @divFloor(numerator, denominator); |
| 586 | 584 | } |
| 587 | 585 | |
| ... | ... | @@ -602,7 +600,7 @@ fn testDivFloor() void { |
| 602 | 600 | pub fn divExact(comptime T: type, numerator: T, denominator: T) !T { |
| 603 | 601 | @setRuntimeSafety(false); |
| 604 | 602 | if (denominator == 0) return error.DivisionByZero; |
| 605 | if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow; | |
| 603 | if (@typeInfo(T) == .Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow; | |
| 606 | 604 | const result = @divTrunc(numerator, denominator); |
| 607 | 605 | if (result * denominator != numerator) return error.UnexpectedRemainder; |
| 608 | 606 | return result; |
| ... | ... | @@ -727,8 +725,8 @@ test "math.negateCast" { |
| 727 | 725 | /// Cast an integer to a different integer type. If the value doesn't fit, |
| 728 | 726 | /// return an error. |
| 729 | 727 | pub fn cast(comptime T: type, x: var) (error{Overflow}!T) { |
| 730 | comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer | |
| 731 | comptime assert(@typeId(@TypeOf(x)) == builtin.TypeId.Int); // must pass an integer | |
| 728 | comptime assert(@typeInfo(T) == .Int); // must pass an integer | |
| 729 | comptime assert(@typeInfo(@TypeOf(x)) == .Int); // must pass an integer | |
| 732 | 730 | if (maxInt(@TypeOf(x)) > maxInt(T) and x > maxInt(T)) { |
| 733 | 731 | return error.Overflow; |
| 734 | 732 | } else if (minInt(@TypeOf(x)) < minInt(T) and x < minInt(T)) { |
| ... | ... | @@ -793,7 +791,7 @@ fn testFloorPowerOfTwo() void { |
| 793 | 791 | /// Only unsigned integers can be used. Zero is not an allowed input. |
| 794 | 792 | /// Result is a type with 1 more bit than the input type. |
| 795 | 793 | pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T.bit_count + 1) { |
| 796 | comptime assert(@typeId(T) == builtin.TypeId.Int); | |
| 794 | comptime assert(@typeInfo(T) == .Int); | |
| 797 | 795 | comptime assert(!T.is_signed); |
| 798 | 796 | assert(value != 0); |
| 799 | 797 | comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1); |
| ... | ... | @@ -805,7 +803,7 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T |
| 805 | 803 | /// Only unsigned integers can be used. Zero is not an allowed input. |
| 806 | 804 | /// If the value doesn't fit, returns an error. |
| 807 | 805 | pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) { |
| 808 | comptime assert(@typeId(T) == builtin.TypeId.Int); | |
| 806 | comptime assert(@typeInfo(T) == .Int); | |
| 809 | 807 | comptime assert(!T.is_signed); |
| 810 | 808 | comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1); |
| 811 | 809 | comptime const overflowBit = @as(PromotedType, 1) << T.bit_count; |
| ... | ... | @@ -878,10 +876,10 @@ test "std.math.log2_int_ceil" { |
| 878 | 876 | |
| 879 | 877 | pub fn lossyCast(comptime T: type, value: var) T { |
| 880 | 878 | switch (@typeInfo(@TypeOf(value))) { |
| 881 | builtin.TypeId.Int => return @intToFloat(T, value), | |
| 882 | builtin.TypeId.Float => return @floatCast(T, value), | |
| 883 | builtin.TypeId.ComptimeInt => return @as(T, value), | |
| 884 | builtin.TypeId.ComptimeFloat => return @as(T, value), | |
| 879 | .Int => return @intToFloat(T, value), | |
| 880 | .Float => return @floatCast(T, value), | |
| 881 | .ComptimeInt => return @as(T, value), | |
| 882 | .ComptimeFloat => return @as(T, value), | |
| 885 | 883 | else => @compileError("bad type"), |
| 886 | 884 | } |
| 887 | 885 | } |
lib/std/math/big/int.zig+4-7| ... | ... | @@ -1,5 +1,4 @@ |
| 1 | 1 | const std = @import("../../std.zig"); |
| 2 | const builtin = @import("builtin"); | |
| 3 | 2 | const debug = std.debug; |
| 4 | 3 | const testing = std.testing; |
| 5 | 4 | const math = std.math; |
| ... | ... | @@ -9,8 +8,6 @@ const ArrayList = std.ArrayList; |
| 9 | 8 | const maxInt = std.math.maxInt; |
| 10 | 9 | const minInt = std.math.minInt; |
| 11 | 10 | |
| 12 | const TypeId = builtin.TypeId; | |
| 13 | ||
| 14 | 11 | pub const Limb = usize; |
| 15 | 12 | pub const DoubleLimb = @IntType(false, 2 * Limb.bit_count); |
| 16 | 13 | pub const Log2Limb = math.Log2Int(Limb); |
| ... | ... | @@ -270,7 +267,7 @@ pub const Int = struct { |
| 270 | 267 | const T = @TypeOf(value); |
| 271 | 268 | |
| 272 | 269 | switch (@typeInfo(T)) { |
| 273 | TypeId.Int => |info| { | |
| 270 | .Int => |info| { | |
| 274 | 271 | const UT = if (T.is_signed) @IntType(false, T.bit_count - 1) else T; |
| 275 | 272 | |
| 276 | 273 | try self.ensureCapacity(@sizeOf(UT) / @sizeOf(Limb)); |
| ... | ... | @@ -294,7 +291,7 @@ pub const Int = struct { |
| 294 | 291 | } |
| 295 | 292 | } |
| 296 | 293 | }, |
| 297 | TypeId.ComptimeInt => { | |
| 294 | .ComptimeInt => { | |
| 298 | 295 | comptime var w_value = if (value < 0) -value else value; |
| 299 | 296 | |
| 300 | 297 | const req_limbs = @divFloor(math.log2(w_value), Limb.bit_count) + 1; |
| ... | ... | @@ -332,8 +329,8 @@ pub const Int = struct { |
| 332 | 329 | /// |
| 333 | 330 | /// Returns an error if self cannot be narrowed into the requested type without truncation. |
| 334 | 331 | pub fn to(self: Int, comptime T: type) ConvertError!T { |
| 335 | switch (@typeId(T)) { | |
| 336 | TypeId.Int => { | |
| 332 | switch (@typeInfo(T)) { | |
| 333 | .Int => { | |
| 337 | 334 | const UT = @IntType(false, T.bit_count); |
| 338 | 335 | |
| 339 | 336 | if (self.bitCountTwosComp() > T.bit_count) { |
lib/std/math/big/rational.zig+3-6| ... | ... | @@ -1,5 +1,4 @@ |
| 1 | 1 | const std = @import("../../std.zig"); |
| 2 | const builtin = @import("builtin"); | |
| 3 | 2 | const debug = std.debug; |
| 4 | 3 | const math = std.math; |
| 5 | 4 | const mem = std.mem; |
| ... | ... | @@ -7,8 +6,6 @@ const testing = std.testing; |
| 7 | 6 | const Allocator = mem.Allocator; |
| 8 | 7 | const ArrayList = std.ArrayList; |
| 9 | 8 | |
| 10 | const TypeId = builtin.TypeId; | |
| 11 | ||
| 12 | 9 | const bn = @import("int.zig"); |
| 13 | 10 | const Limb = bn.Limb; |
| 14 | 11 | const DoubleLimb = bn.DoubleLimb; |
| ... | ... | @@ -129,7 +126,7 @@ pub const Rational = struct { |
| 129 | 126 | /// completely represent the provided float. |
| 130 | 127 | pub fn setFloat(self: *Rational, comptime T: type, f: T) !void { |
| 131 | 128 | // Translated from golang.go/src/math/big/rat.go. |
| 132 | debug.assert(@typeId(T) == builtin.TypeId.Float); | |
| 129 | debug.assert(@typeInfo(T) == .Float); | |
| 133 | 130 | |
| 134 | 131 | const UnsignedIntType = @IntType(false, T.bit_count); |
| 135 | 132 | const f_bits = @bitCast(UnsignedIntType, f); |
| ... | ... | @@ -187,7 +184,7 @@ pub const Rational = struct { |
| 187 | 184 | pub fn toFloat(self: Rational, comptime T: type) !T { |
| 188 | 185 | // Translated from golang.go/src/math/big/rat.go. |
| 189 | 186 | // TODO: Indicate whether the result is not exact. |
| 190 | debug.assert(@typeId(T) == builtin.TypeId.Float); | |
| 187 | debug.assert(@typeInfo(T) == .Float); | |
| 191 | 188 | |
| 192 | 189 | const fsize = T.bit_count; |
| 193 | 190 | const BitReprType = @IntType(false, T.bit_count); |
| ... | ... | @@ -653,7 +650,7 @@ test "big.rational gcd one large" { |
| 653 | 650 | } |
| 654 | 651 | |
| 655 | 652 | fn extractLowBits(a: Int, comptime T: type) T { |
| 656 | testing.expect(@typeId(T) == builtin.TypeId.Int); | |
| 653 | testing.expect(@typeInfo(T) == .Int); | |
| 657 | 654 | |
| 658 | 655 | if (T.bit_count <= Limb.bit_count) { |
| 659 | 656 | return @truncate(T, a.limbs[0]); |
lib/std/math/ln.zig+5-7| ... | ... | @@ -7,8 +7,6 @@ |
| 7 | 7 | const std = @import("../std.zig"); |
| 8 | 8 | const math = std.math; |
| 9 | 9 | const expect = std.testing.expect; |
| 10 | const builtin = @import("builtin"); | |
| 11 | const TypeId = builtin.TypeId; | |
| 12 | 10 | |
| 13 | 11 | /// Returns the natural logarithm of x. |
| 14 | 12 | /// |
| ... | ... | @@ -19,21 +17,21 @@ const TypeId = builtin.TypeId; |
| 19 | 17 | /// - ln(nan) = nan |
| 20 | 18 | pub fn ln(x: var) @TypeOf(x) { |
| 21 | 19 | const T = @TypeOf(x); |
| 22 | switch (@typeId(T)) { | |
| 23 | TypeId.ComptimeFloat => { | |
| 20 | switch (@typeInfo(T)) { | |
| 21 | .ComptimeFloat => { | |
| 24 | 22 | return @as(comptime_float, ln_64(x)); |
| 25 | 23 | }, |
| 26 | TypeId.Float => { | |
| 24 | .Float => { | |
| 27 | 25 | return switch (T) { |
| 28 | 26 | f32 => ln_32(x), |
| 29 | 27 | f64 => ln_64(x), |
| 30 | 28 | else => @compileError("ln not implemented for " ++ @typeName(T)), |
| 31 | 29 | }; |
| 32 | 30 | }, |
| 33 | TypeId.ComptimeInt => { | |
| 31 | .ComptimeInt => { | |
| 34 | 32 | return @as(comptime_int, math.floor(ln_64(@as(f64, x)))); |
| 35 | 33 | }, |
| 36 | TypeId.Int => { | |
| 34 | .Int => { | |
| 37 | 35 | return @as(T, math.floor(ln_64(@as(f64, x)))); |
| 38 | 36 | }, |
| 39 | 37 | else => @compileError("ln not implemented for " ++ @typeName(T)), |
lib/std/math/log.zig+6-8| ... | ... | @@ -6,8 +6,6 @@ |
| 6 | 6 | |
| 7 | 7 | const std = @import("../std.zig"); |
| 8 | 8 | const math = std.math; |
| 9 | const builtin = @import("builtin"); | |
| 10 | const TypeId = builtin.TypeId; | |
| 11 | 9 | const expect = std.testing.expect; |
| 12 | 10 | |
| 13 | 11 | /// Returns the logarithm of x for the provided base. |
| ... | ... | @@ -16,24 +14,24 @@ pub fn log(comptime T: type, base: T, x: T) T { |
| 16 | 14 | return math.log2(x); |
| 17 | 15 | } else if (base == 10) { |
| 18 | 16 | return math.log10(x); |
| 19 | } else if ((@typeId(T) == TypeId.Float or @typeId(T) == TypeId.ComptimeFloat) and base == math.e) { | |
| 17 | } else if ((@typeInfo(T) == .Float or @typeInfo(T) == .ComptimeFloat) and base == math.e) { | |
| 20 | 18 | return math.ln(x); |
| 21 | 19 | } |
| 22 | 20 | |
| 23 | 21 | const float_base = math.lossyCast(f64, base); |
| 24 | switch (@typeId(T)) { | |
| 25 | TypeId.ComptimeFloat => { | |
| 22 | switch (@typeInfo(T)) { | |
| 23 | .ComptimeFloat => { | |
| 26 | 24 | return @as(comptime_float, math.ln(@as(f64, x)) / math.ln(float_base)); |
| 27 | 25 | }, |
| 28 | TypeId.ComptimeInt => { | |
| 26 | .ComptimeInt => { | |
| 29 | 27 | return @as(comptime_int, math.floor(math.ln(@as(f64, x)) / math.ln(float_base))); |
| 30 | 28 | }, |
| 31 | builtin.TypeId.Int => { | |
| 29 | .Int => { | |
| 32 | 30 | // TODO implement integer log without using float math |
| 33 | 31 | return @floatToInt(T, math.floor(math.ln(@intToFloat(f64, x)) / math.ln(float_base))); |
| 34 | 32 | }, |
| 35 | 33 | |
| 36 | builtin.TypeId.Float => { | |
| 34 | .Float => { | |
| 37 | 35 | switch (T) { |
| 38 | 36 | f32 => return @floatCast(f32, math.ln(@as(f64, x)) / math.ln(float_base)), |
| 39 | 37 | f64 => return math.ln(x) / math.ln(float_base), |
lib/std/math/log10.zig+5-7| ... | ... | @@ -7,8 +7,6 @@ |
| 7 | 7 | const std = @import("../std.zig"); |
| 8 | 8 | const math = std.math; |
| 9 | 9 | const testing = std.testing; |
| 10 | const builtin = @import("builtin"); | |
| 11 | const TypeId = builtin.TypeId; | |
| 12 | 10 | const maxInt = std.math.maxInt; |
| 13 | 11 | |
| 14 | 12 | /// Returns the base-10 logarithm of x. |
| ... | ... | @@ -20,21 +18,21 @@ const maxInt = std.math.maxInt; |
| 20 | 18 | /// - log10(nan) = nan |
| 21 | 19 | pub fn log10(x: var) @TypeOf(x) { |
| 22 | 20 | const T = @TypeOf(x); |
| 23 | switch (@typeId(T)) { | |
| 24 | TypeId.ComptimeFloat => { | |
| 21 | switch (@typeInfo(T)) { | |
| 22 | .ComptimeFloat => { | |
| 25 | 23 | return @as(comptime_float, log10_64(x)); |
| 26 | 24 | }, |
| 27 | TypeId.Float => { | |
| 25 | .Float => { | |
| 28 | 26 | return switch (T) { |
| 29 | 27 | f32 => log10_32(x), |
| 30 | 28 | f64 => log10_64(x), |
| 31 | 29 | else => @compileError("log10 not implemented for " ++ @typeName(T)), |
| 32 | 30 | }; |
| 33 | 31 | }, |
| 34 | TypeId.ComptimeInt => { | |
| 32 | .ComptimeInt => { | |
| 35 | 33 | return @as(comptime_int, math.floor(log10_64(@as(f64, x)))); |
| 36 | 34 | }, |
| 37 | TypeId.Int => { | |
| 35 | .Int => { | |
| 38 | 36 | return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x)))); |
| 39 | 37 | }, |
| 40 | 38 | else => @compileError("log10 not implemented for " ++ @typeName(T)), |
lib/std/math/log2.zig+5-7| ... | ... | @@ -7,8 +7,6 @@ |
| 7 | 7 | const std = @import("../std.zig"); |
| 8 | 8 | const math = std.math; |
| 9 | 9 | const expect = std.testing.expect; |
| 10 | const builtin = @import("builtin"); | |
| 11 | const TypeId = builtin.TypeId; | |
| 12 | 10 | const maxInt = std.math.maxInt; |
| 13 | 11 | |
| 14 | 12 | /// Returns the base-2 logarithm of x. |
| ... | ... | @@ -20,18 +18,18 @@ const maxInt = std.math.maxInt; |
| 20 | 18 | /// - log2(nan) = nan |
| 21 | 19 | pub fn log2(x: var) @TypeOf(x) { |
| 22 | 20 | const T = @TypeOf(x); |
| 23 | switch (@typeId(T)) { | |
| 24 | TypeId.ComptimeFloat => { | |
| 21 | switch (@typeInfo(T)) { | |
| 22 | .ComptimeFloat => { | |
| 25 | 23 | return @as(comptime_float, log2_64(x)); |
| 26 | 24 | }, |
| 27 | TypeId.Float => { | |
| 25 | .Float => { | |
| 28 | 26 | return switch (T) { |
| 29 | 27 | f32 => log2_32(x), |
| 30 | 28 | f64 => log2_64(x), |
| 31 | 29 | else => @compileError("log2 not implemented for " ++ @typeName(T)), |
| 32 | 30 | }; |
| 33 | 31 | }, |
| 34 | TypeId.ComptimeInt => comptime { | |
| 32 | .ComptimeInt => comptime { | |
| 35 | 33 | var result = 0; |
| 36 | 34 | var x_shifted = x; |
| 37 | 35 | while (b: { |
| ... | ... | @@ -40,7 +38,7 @@ pub fn log2(x: var) @TypeOf(x) { |
| 40 | 38 | }) : (result += 1) {} |
| 41 | 39 | return result; |
| 42 | 40 | }, |
| 43 | TypeId.Int => { | |
| 41 | .Int => { | |
| 44 | 42 | return math.log2_int(T, x); |
| 45 | 43 | }, |
| 46 | 44 | else => @compileError("log2 not implemented for " ++ @typeName(T)), |
lib/std/meta.zig+2-3| ... | ... | @@ -536,9 +536,8 @@ test "intToEnum with error return" { |
| 536 | 536 | pub const IntToEnumError = error{InvalidEnumTag}; |
| 537 | 537 | |
| 538 | 538 | pub fn intToEnum(comptime Tag: type, tag_int: var) IntToEnumError!Tag { |
| 539 | comptime var i = 0; | |
| 540 | inline while (i != @memberCount(Tag)) : (i += 1) { | |
| 541 | const this_tag_value = @field(Tag, @memberName(Tag, i)); | |
| 539 | inline for (@typeInfo(Tag).Enum.fields) |f| { | |
| 540 | const this_tag_value = @field(Tag, f.name); | |
| 542 | 541 | if (tag_int == @enumToInt(this_tag_value)) { |
| 543 | 542 | return this_tag_value; |
| 544 | 543 | } |
lib/std/meta/trait.zig+7-7| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("../std.zig"); |
| 2 | const builtin = @import("builtin"); | |
| 2 | const builtin = std.builtin; | |
| 3 | 3 | const mem = std.mem; |
| 4 | 4 | const debug = std.debug; |
| 5 | 5 | const testing = std.testing; |
| ... | ... | @@ -54,7 +54,7 @@ pub fn hasFn(comptime name: []const u8) TraitFn { |
| 54 | 54 | if (!comptime isContainer(T)) return false; |
| 55 | 55 | if (!comptime @hasDecl(T, name)) return false; |
| 56 | 56 | const DeclType = @TypeOf(@field(T, name)); |
| 57 | return @typeId(DeclType) == .Fn; | |
| 57 | return @typeInfo(DeclType) == .Fn; | |
| 58 | 58 | } |
| 59 | 59 | }; |
| 60 | 60 | return Closure.trait; |
| ... | ... | @@ -105,7 +105,7 @@ test "std.meta.trait.hasField" { |
| 105 | 105 | pub fn is(comptime id: builtin.TypeId) TraitFn { |
| 106 | 106 | const Closure = struct { |
| 107 | 107 | pub fn trait(comptime T: type) bool { |
| 108 | return id == @typeId(T); | |
| 108 | return id == @typeInfo(T); | |
| 109 | 109 | } |
| 110 | 110 | }; |
| 111 | 111 | return Closure.trait; |
| ... | ... | @@ -123,7 +123,7 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn { |
| 123 | 123 | const Closure = struct { |
| 124 | 124 | pub fn trait(comptime T: type) bool { |
| 125 | 125 | if (!comptime isSingleItemPtr(T)) return false; |
| 126 | return id == @typeId(meta.Child(T)); | |
| 126 | return id == @typeInfo(meta.Child(T)); | |
| 127 | 127 | } |
| 128 | 128 | }; |
| 129 | 129 | return Closure.trait; |
| ... | ... | @@ -139,7 +139,7 @@ pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn { |
| 139 | 139 | const Closure = struct { |
| 140 | 140 | pub fn trait(comptime T: type) bool { |
| 141 | 141 | if (!comptime isSlice(T)) return false; |
| 142 | return id == @typeId(meta.Child(T)); | |
| 142 | return id == @typeInfo(meta.Child(T)); | |
| 143 | 143 | } |
| 144 | 144 | }; |
| 145 | 145 | return Closure.trait; |
| ... | ... | @@ -285,7 +285,7 @@ test "std.meta.trait.isIndexable" { |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | pub fn isNumber(comptime T: type) bool { |
| 288 | return switch (@typeId(T)) { | |
| 288 | return switch (@typeInfo(T)) { | |
| 289 | 289 | .Int, .Float, .ComptimeInt, .ComptimeFloat => true, |
| 290 | 290 | else => false, |
| 291 | 291 | }; |
| ... | ... | @@ -320,7 +320,7 @@ test "std.meta.trait.isConstPtr" { |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | pub fn isContainer(comptime T: type) bool { |
| 323 | return switch (@typeId(T)) { | |
| 323 | return switch (@typeInfo(T)) { | |
| 324 | 324 | .Struct, .Union, .Enum => true, |
| 325 | 325 | else => false, |
| 326 | 326 | }; |
lib/std/special/build_runner.zig+1-1| ... | ... | @@ -126,7 +126,7 @@ pub fn main() !void { |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | fn runBuild(builder: *Builder) anyerror!void { |
| 129 | switch (@typeId(@TypeOf(root.build).ReturnType)) { | |
| 129 | switch (@typeInfo(@TypeOf(root.build).ReturnType)) { | |
| 130 | 130 | .Void => root.build(builder), |
| 131 | 131 | .ErrorUnion => try root.build(builder), |
| 132 | 132 | else => @compileError("expected return type of build to be 'void' or '!void'"), |
lib/std/thread.zig+2-2| ... | ... | @@ -158,7 +158,7 @@ pub const Thread = struct { |
| 158 | 158 | }; |
| 159 | 159 | fn threadMain(raw_arg: windows.LPVOID) callconv(.C) windows.DWORD { |
| 160 | 160 | const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), raw_arg)).*; |
| 161 | switch (@typeId(@TypeOf(startFn).ReturnType)) { | |
| 161 | switch (@typeInfo(@TypeOf(startFn).ReturnType)) { | |
| 162 | 162 | .Int => { |
| 163 | 163 | return startFn(arg); |
| 164 | 164 | }, |
| ... | ... | @@ -201,7 +201,7 @@ pub const Thread = struct { |
| 201 | 201 | fn linuxThreadMain(ctx_addr: usize) callconv(.C) u8 { |
| 202 | 202 | const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*; |
| 203 | 203 | |
| 204 | switch (@typeId(@TypeOf(startFn).ReturnType)) { | |
| 204 | switch (@typeInfo(@TypeOf(startFn).ReturnType)) { | |
| 205 | 205 | .Int => { |
| 206 | 206 | return startFn(arg); |
| 207 | 207 | }, |
lib/std/zig/ast.zig+12-16| ... | ... | @@ -457,10 +457,9 @@ pub const Node = struct { |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | pub fn iterate(base: *Node, index: usize) ?*Node { |
| 460 | comptime var i = 0; | |
| 461 | inline while (i < @memberCount(Id)) : (i += 1) { | |
| 462 | if (base.id == @field(Id, @memberName(Id, i))) { | |
| 463 | const T = @field(Node, @memberName(Id, i)); | |
| 460 | inline for (@typeInfo(Id).Enum.fields) |f| { | |
| 461 | if (base.id == @field(Id, f.name)) { | |
| 462 | const T = @field(Node, f.name); | |
| 464 | 463 | return @fieldParentPtr(T, "base", base).iterate(index); |
| 465 | 464 | } |
| 466 | 465 | } |
| ... | ... | @@ -468,10 +467,9 @@ pub const Node = struct { |
| 468 | 467 | } |
| 469 | 468 | |
| 470 | 469 | pub fn firstToken(base: *const Node) TokenIndex { |
| 471 | comptime var i = 0; | |
| 472 | inline while (i < @memberCount(Id)) : (i += 1) { | |
| 473 | if (base.id == @field(Id, @memberName(Id, i))) { | |
| 474 | const T = @field(Node, @memberName(Id, i)); | |
| 470 | inline for (@typeInfo(Id).Enum.fields) |f| { | |
| 471 | if (base.id == @field(Id, f.name)) { | |
| 472 | const T = @field(Node, f.name); | |
| 475 | 473 | return @fieldParentPtr(T, "base", base).firstToken(); |
| 476 | 474 | } |
| 477 | 475 | } |
| ... | ... | @@ -479,10 +477,9 @@ pub const Node = struct { |
| 479 | 477 | } |
| 480 | 478 | |
| 481 | 479 | pub fn lastToken(base: *const Node) TokenIndex { |
| 482 | comptime var i = 0; | |
| 483 | inline while (i < @memberCount(Id)) : (i += 1) { | |
| 484 | if (base.id == @field(Id, @memberName(Id, i))) { | |
| 485 | const T = @field(Node, @memberName(Id, i)); | |
| 480 | inline for (@typeInfo(Id).Enum.fields) |f| { | |
| 481 | if (base.id == @field(Id, f.name)) { | |
| 482 | const T = @field(Node, f.name); | |
| 486 | 483 | return @fieldParentPtr(T, "base", base).lastToken(); |
| 487 | 484 | } |
| 488 | 485 | } |
| ... | ... | @@ -490,10 +487,9 @@ pub const Node = struct { |
| 490 | 487 | } |
| 491 | 488 | |
| 492 | 489 | pub fn typeToId(comptime T: type) Id { |
| 493 | comptime var i = 0; | |
| 494 | inline while (i < @memberCount(Id)) : (i += 1) { | |
| 495 | if (T == @field(Node, @memberName(Id, i))) { | |
| 496 | return @field(Id, @memberName(Id, i)); | |
| 490 | inline for (@typeInfo(Id).Enum.fields) |f| { | |
| 491 | if (T == @field(Node, f.name)) { | |
| 492 | return @field(Id, f.name); | |
| 497 | 493 | } |
| 498 | 494 | } |
| 499 | 495 | unreachable; |
lib/std/zig/parser_test.zig+1-1| ... | ... | @@ -1410,7 +1410,7 @@ test "zig fmt: same-line comment after non-block if expression" { |
| 1410 | 1410 | test "zig fmt: same-line comment on comptime expression" { |
| 1411 | 1411 | try testCanonical( |
| 1412 | 1412 | \\test "" { |
| 1413 | \\ comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt | |
| 1413 | \\ comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt | |
| 1414 | 1414 | \\} |
| 1415 | 1415 | \\ |
| 1416 | 1416 | ); |
lib/std/zig/render.zig+1-2| ... | ... | @@ -1,5 +1,4 @@ |
| 1 | 1 | const std = @import("../std.zig"); |
| 2 | const builtin = @import("builtin"); | |
| 3 | 2 | const assert = std.debug.assert; |
| 4 | 3 | const mem = std.mem; |
| 5 | 4 | const ast = std.zig.ast; |
| ... | ... | @@ -14,7 +13,7 @@ pub const Error = error{ |
| 14 | 13 | |
| 15 | 14 | /// Returns whether anything changed |
| 16 | 15 | pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@TypeOf(stream).Child.Error || Error)!bool { |
| 17 | comptime assert(@typeId(@TypeOf(stream)) == builtin.TypeId.Pointer); | |
| 16 | comptime assert(@typeInfo(@TypeOf(stream)) == .Pointer); | |
| 18 | 17 | |
| 19 | 18 | var anything_changed: bool = false; |
| 20 | 19 |
src-self-hosted/ir.zig+17-22| ... | ... | @@ -76,20 +76,18 @@ pub const Inst = struct { |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | pub fn typeToId(comptime T: type) Id { |
| 79 | comptime var i = 0; | |
| 80 | inline while (i < @memberCount(Id)) : (i += 1) { | |
| 81 | if (T == @field(Inst, @memberName(Id, i))) { | |
| 82 | return @field(Id, @memberName(Id, i)); | |
| 79 | inline for (@typeInfo(Id).Enum.fields) |f| { | |
| 80 | if (T == @field(Inst, f.name)) { | |
| 81 | return @field(Id, f.name); | |
| 83 | 82 | } |
| 84 | 83 | } |
| 85 | 84 | unreachable; |
| 86 | 85 | } |
| 87 | 86 | |
| 88 | 87 | pub fn dump(base: *const Inst) void { |
| 89 | comptime var i = 0; | |
| 90 | inline while (i < @memberCount(Id)) : (i += 1) { | |
| 91 | if (base.id == @field(Id, @memberName(Id, i))) { | |
| 92 | const T = @field(Inst, @memberName(Id, i)); | |
| 88 | inline for (@typeInfo(Id).Enum.fields) |f| { | |
| 89 | if (base.id == @field(Id, f.name)) { | |
| 90 | const T = @field(Inst, f.name); | |
| 93 | 91 | std.debug.warn("#{} = {}(", .{ base.debug_id, @tagName(base.id) }); |
| 94 | 92 | @fieldParentPtr(T, "base", base).dump(); |
| 95 | 93 | std.debug.warn(")", .{}); |
| ... | ... | @@ -100,10 +98,9 @@ pub const Inst = struct { |
| 100 | 98 | } |
| 101 | 99 | |
| 102 | 100 | pub fn hasSideEffects(base: *const Inst) bool { |
| 103 | comptime var i = 0; | |
| 104 | inline while (i < @memberCount(Id)) : (i += 1) { | |
| 105 | if (base.id == @field(Id, @memberName(Id, i))) { | |
| 106 | const T = @field(Inst, @memberName(Id, i)); | |
| 101 | inline for (@typeInfo(Id).Enum.fields) |f| { | |
| 102 | if (base.id == @field(Id, f.name)) { | |
| 103 | const T = @field(Inst, f.name); | |
| 107 | 104 | return @fieldParentPtr(T, "base", base).hasSideEffects(); |
| 108 | 105 | } |
| 109 | 106 | } |
| ... | ... | @@ -1805,21 +1802,19 @@ pub const Builder = struct { |
| 1805 | 1802 | }; |
| 1806 | 1803 | |
| 1807 | 1804 | // Look at the params and ref() other instructions |
| 1808 | comptime var i = 0; | |
| 1809 | inline while (i < @memberCount(I.Params)) : (i += 1) { | |
| 1810 | const FieldType = comptime @TypeOf(@field(@as(I.Params, undefined), @memberName(I.Params, i))); | |
| 1811 | switch (FieldType) { | |
| 1812 | *Inst => @field(inst.params, @memberName(I.Params, i)).ref(self), | |
| 1813 | *BasicBlock => @field(inst.params, @memberName(I.Params, i)).ref(self), | |
| 1814 | ?*Inst => if (@field(inst.params, @memberName(I.Params, i))) |other| other.ref(self), | |
| 1805 | inline for (@typeInfo(I.Params).Struct.fields) |f| { | |
| 1806 | switch (f.fiedl_type) { | |
| 1807 | *Inst => @field(inst.params, f.name).ref(self), | |
| 1808 | *BasicBlock => @field(inst.params, f.name).ref(self), | |
| 1809 | ?*Inst => if (@field(inst.params, f.name)) |other| other.ref(self), | |
| 1815 | 1810 | []*Inst => { |
| 1816 | 1811 | // TODO https://github.com/ziglang/zig/issues/1269 |
| 1817 | for (@field(inst.params, @memberName(I.Params, i))) |other| | |
| 1812 | for (@field(inst.params, f.name)) |other| | |
| 1818 | 1813 | other.ref(self); |
| 1819 | 1814 | }, |
| 1820 | 1815 | []*BasicBlock => { |
| 1821 | 1816 | // TODO https://github.com/ziglang/zig/issues/1269 |
| 1822 | for (@field(inst.params, @memberName(I.Params, i))) |other| | |
| 1817 | for (@field(inst.params, f.name)) |other| | |
| 1823 | 1818 | other.ref(self); |
| 1824 | 1819 | }, |
| 1825 | 1820 | Type.Pointer.Mut, |
| ... | ... | @@ -1831,7 +1826,7 @@ pub const Builder = struct { |
| 1831 | 1826 | => {}, |
| 1832 | 1827 | // it's ok to add more types here, just make sure that |
| 1833 | 1828 | // any instructions and basic blocks are ref'd appropriately |
| 1834 | else => @compileError("unrecognized type in Params: " ++ @typeName(FieldType)), | |
| 1829 | else => @compileError("unrecognized type in Params: " ++ @typeName(f.field_type)), | |
| 1835 | 1830 | } |
| 1836 | 1831 | } |
| 1837 | 1832 |
src-self-hosted/translate_c.zig+4-4| ... | ... | @@ -5381,15 +5381,15 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8, |
| 5381 | 5381 | return error.ParseError; |
| 5382 | 5382 | } |
| 5383 | 5383 | |
| 5384 | //if (@typeId(@TypeOf(x)) == .Pointer) | |
| 5384 | //if (@typeInfo(@TypeOf(x)) == .Pointer) | |
| 5385 | 5385 | // @ptrCast(dest, x) |
| 5386 | //else if (@typeId(@TypeOf(x)) == .Integer) | |
| 5386 | //else if (@typeInfo(@TypeOf(x)) == .Integer) | |
| 5387 | 5387 | // @intToPtr(dest, x) |
| 5388 | 5388 | //else |
| 5389 | 5389 | // @as(dest, x) |
| 5390 | 5390 | |
| 5391 | 5391 | const if_1 = try transCreateNodeIf(c); |
| 5392 | const type_id_1 = try transCreateNodeBuiltinFnCall(c, "@typeId"); | |
| 5392 | const type_id_1 = try transCreateNodeBuiltinFnCall(c, "@typeInfo"); | |
| 5393 | 5393 | const type_of_1 = try transCreateNodeBuiltinFnCall(c, "@TypeOf"); |
| 5394 | 5394 | try type_id_1.params.push(&type_of_1.base); |
| 5395 | 5395 | try type_of_1.params.push(node_to_cast); |
| ... | ... | @@ -5416,7 +5416,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8, |
| 5416 | 5416 | if_1.@"else" = else_1; |
| 5417 | 5417 | |
| 5418 | 5418 | const if_2 = try transCreateNodeIf(c); |
| 5419 | const type_id_2 = try transCreateNodeBuiltinFnCall(c, "@typeId"); | |
| 5419 | const type_id_2 = try transCreateNodeBuiltinFnCall(c, "@typeInfo"); | |
| 5420 | 5420 | const type_of_2 = try transCreateNodeBuiltinFnCall(c, "@TypeOf"); |
| 5421 | 5421 | try type_id_2.params.push(&type_of_2.base); |
| 5422 | 5422 | try type_of_2.params.push(node_to_cast); |
test/compile_errors.zig-78| ... | ... | @@ -2942,14 +2942,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2942 | 2942 | "tmp.zig:11:13: error: error.B not a member of error set 'Set2'", |
| 2943 | 2943 | }); |
| 2944 | 2944 | |
| 2945 | cases.add("@memberCount of error", | |
| 2946 | \\comptime { | |
| 2947 | \\ _ = @memberCount(anyerror); | |
| 2948 | \\} | |
| 2949 | , &[_][]const u8{ | |
| 2950 | "tmp.zig:2:9: error: global error set member count not available at comptime", | |
| 2951 | }); | |
| 2952 | ||
| 2953 | 2945 | cases.add("duplicate error value in error set", |
| 2954 | 2946 | \\const Foo = error { |
| 2955 | 2947 | \\ Bar, |
| ... | ... | @@ -5964,76 +5956,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5964 | 5956 | "tmp.zig:2:32: error: arg index 2 out of bounds; 'fn(i32, i32) i32' has 2 arguments", |
| 5965 | 5957 | }); |
| 5966 | 5958 | |
| 5967 | cases.add("@memberType on unsupported type", | |
| 5968 | \\comptime { | |
| 5969 | \\ _ = @memberType(i32, 0); | |
| 5970 | \\} | |
| 5971 | , &[_][]const u8{ | |
| 5972 | "tmp.zig:2:21: error: type 'i32' does not support @memberType", | |
| 5973 | }); | |
| 5974 | ||
| 5975 | cases.add("@memberType on enum", | |
| 5976 | \\comptime { | |
| 5977 | \\ _ = @memberType(Foo, 0); | |
| 5978 | \\} | |
| 5979 | \\const Foo = enum {A,}; | |
| 5980 | , &[_][]const u8{ | |
| 5981 | "tmp.zig:2:21: error: type 'Foo' does not support @memberType", | |
| 5982 | }); | |
| 5983 | ||
| 5984 | cases.add("@memberType struct out of bounds", | |
| 5985 | \\comptime { | |
| 5986 | \\ _ = @memberType(Foo, 0); | |
| 5987 | \\} | |
| 5988 | \\const Foo = struct {}; | |
| 5989 | , &[_][]const u8{ | |
| 5990 | "tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members", | |
| 5991 | }); | |
| 5992 | ||
| 5993 | cases.add("@memberType union out of bounds", | |
| 5994 | \\comptime { | |
| 5995 | \\ _ = @memberType(Foo, 1); | |
| 5996 | \\} | |
| 5997 | \\const Foo = union {A: void,}; | |
| 5998 | , &[_][]const u8{ | |
| 5999 | "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members", | |
| 6000 | }); | |
| 6001 | ||
| 6002 | cases.add("@memberName on unsupported type", | |
| 6003 | \\comptime { | |
| 6004 | \\ _ = @memberName(i32, 0); | |
| 6005 | \\} | |
| 6006 | , &[_][]const u8{ | |
| 6007 | "tmp.zig:2:21: error: type 'i32' does not support @memberName", | |
| 6008 | }); | |
| 6009 | ||
| 6010 | cases.add("@memberName struct out of bounds", | |
| 6011 | \\comptime { | |
| 6012 | \\ _ = @memberName(Foo, 0); | |
| 6013 | \\} | |
| 6014 | \\const Foo = struct {}; | |
| 6015 | , &[_][]const u8{ | |
| 6016 | "tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members", | |
| 6017 | }); | |
| 6018 | ||
| 6019 | cases.add("@memberName enum out of bounds", | |
| 6020 | \\comptime { | |
| 6021 | \\ _ = @memberName(Foo, 1); | |
| 6022 | \\} | |
| 6023 | \\const Foo = enum {A,}; | |
| 6024 | , &[_][]const u8{ | |
| 6025 | "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members", | |
| 6026 | }); | |
| 6027 | ||
| 6028 | cases.add("@memberName union out of bounds", | |
| 6029 | \\comptime { | |
| 6030 | \\ _ = @memberName(Foo, 1); | |
| 6031 | \\} | |
| 6032 | \\const Foo = union {A:i32,}; | |
| 6033 | , &[_][]const u8{ | |
| 6034 | "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members", | |
| 6035 | }); | |
| 6036 | ||
| 6037 | 5959 | cases.add("calling var args extern function, passing array instead of pointer", |
| 6038 | 5960 | \\export fn entry() void { |
| 6039 | 5961 | \\ foo("hello".*,); |
test/stage1/behavior/bugs/3742.zig+1-1| ... | ... | @@ -17,7 +17,7 @@ pub const GET = struct { |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | 19 | pub fn isCommand(comptime T: type) bool { |
| 20 | const tid = @typeId(T); | |
| 20 | const tid = @typeInfo(T); | |
| 21 | 21 | return (tid == .Struct or tid == .Enum or tid == .Union) and |
| 22 | 22 | @hasDecl(T, "Redis") and @hasDecl(T.Redis, "Command"); |
| 23 | 23 | } |
test/stage1/behavior/enum.zig+2-2| ... | ... | @@ -96,8 +96,8 @@ test "enum type" { |
| 96 | 96 | const bar = Bar.B; |
| 97 | 97 | |
| 98 | 98 | expect(bar == Bar.B); |
| 99 | expect(@memberCount(Foo) == 3); | |
| 100 | expect(@memberCount(Bar) == 4); | |
| 99 | expect(@typeInfo(Foo).Union.fields.len == 3); | |
| 100 | expect(@typeInfo(Bar).Enum.fields.len == 4); | |
| 101 | 101 | expect(@sizeOf(Foo) == @sizeOf(FooNoVoid)); |
| 102 | 102 | expect(@sizeOf(Bar) == 1); |
| 103 | 103 | } |
test/stage1/behavior/error.zig+3-4| ... | ... | @@ -3,7 +3,6 @@ const expect = std.testing.expect; |
| 3 | 3 | const expectError = std.testing.expectError; |
| 4 | 4 | const expectEqual = std.testing.expectEqual; |
| 5 | 5 | const mem = std.mem; |
| 6 | const builtin = @import("builtin"); | |
| 7 | 6 | |
| 8 | 7 | pub fn foo() anyerror!i32 { |
| 9 | 8 | const x = try bar(); |
| ... | ... | @@ -84,8 +83,8 @@ test "error union type " { |
| 84 | 83 | fn testErrorUnionType() void { |
| 85 | 84 | const x: anyerror!i32 = 1234; |
| 86 | 85 | if (x) |value| expect(value == 1234) else |_| unreachable; |
| 87 | expect(@typeId(@TypeOf(x)) == builtin.TypeId.ErrorUnion); | |
| 88 | expect(@typeId(@TypeOf(x).ErrorSet) == builtin.TypeId.ErrorSet); | |
| 86 | expect(@typeInfo(@TypeOf(x)) == .ErrorUnion); | |
| 87 | expect(@typeInfo(@TypeOf(x).ErrorSet) == .ErrorSet); | |
| 89 | 88 | expect(@TypeOf(x).ErrorSet == anyerror); |
| 90 | 89 | } |
| 91 | 90 | |
| ... | ... | @@ -100,7 +99,7 @@ const MyErrSet = error{ |
| 100 | 99 | }; |
| 101 | 100 | |
| 102 | 101 | fn testErrorSetType() void { |
| 103 | expect(@memberCount(MyErrSet) == 2); | |
| 102 | expect(@typeInfo(MyErrSet).ErrorSet.?.len == 2); | |
| 104 | 103 | |
| 105 | 104 | const a: MyErrSet!i32 = 5678; |
| 106 | 105 | const b: MyErrSet!i32 = MyErrSet.OutOfMemory; |
test/stage1/behavior/eval.zig+2-2| ... | ... | @@ -654,8 +654,8 @@ test "call method with comptime pass-by-non-copying-value self parameter" { |
| 654 | 654 | expect(b == 2); |
| 655 | 655 | } |
| 656 | 656 | |
| 657 | test "@tagName of @typeId" { | |
| 658 | const str = @tagName(@typeId(u8)); | |
| 657 | test "@tagName of @typeInfo" { | |
| 658 | const str = @tagName(@typeInfo(u8)); | |
| 659 | 659 | expect(std.mem.eql(u8, str, "Int")); |
| 660 | 660 | } |
| 661 | 661 |
test/stage1/behavior/misc.zig-35| ... | ... | @@ -407,7 +407,6 @@ fn testArray2DConstDoublePtr(ptr: *const f32) void { |
| 407 | 407 | expect(ptr2[1] == 2.0); |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | const Tid = builtin.TypeId; | |
| 411 | 410 | const AStruct = struct { |
| 412 | 411 | x: i32, |
| 413 | 412 | }; |
| ... | ... | @@ -424,40 +423,6 @@ const AUnion = union { |
| 424 | 423 | Two: void, |
| 425 | 424 | }; |
| 426 | 425 | |
| 427 | test "@typeId" { | |
| 428 | comptime { | |
| 429 | expect(@typeId(type) == Tid.Type); | |
| 430 | expect(@typeId(void) == Tid.Void); | |
| 431 | expect(@typeId(bool) == Tid.Bool); | |
| 432 | expect(@typeId(noreturn) == Tid.NoReturn); | |
| 433 | expect(@typeId(i8) == Tid.Int); | |
| 434 | expect(@typeId(u8) == Tid.Int); | |
| 435 | expect(@typeId(i64) == Tid.Int); | |
| 436 | expect(@typeId(u64) == Tid.Int); | |
| 437 | expect(@typeId(f32) == Tid.Float); | |
| 438 | expect(@typeId(f64) == Tid.Float); | |
| 439 | expect(@typeId(*f32) == Tid.Pointer); | |
| 440 | expect(@typeId([2]u8) == Tid.Array); | |
| 441 | expect(@typeId(AStruct) == Tid.Struct); | |
| 442 | expect(@typeId(@TypeOf(1)) == Tid.ComptimeInt); | |
| 443 | expect(@typeId(@TypeOf(1.0)) == Tid.ComptimeFloat); | |
| 444 | expect(@typeId(@TypeOf(undefined)) == Tid.Undefined); | |
| 445 | expect(@typeId(@TypeOf(null)) == Tid.Null); | |
| 446 | expect(@typeId(?i32) == Tid.Optional); | |
| 447 | expect(@typeId(anyerror!i32) == Tid.ErrorUnion); | |
| 448 | expect(@typeId(anyerror) == Tid.ErrorSet); | |
| 449 | expect(@typeId(AnEnum) == Tid.Enum); | |
| 450 | expect(@typeId(@TypeOf(AUnionEnum.One)) == Tid.Enum); | |
| 451 | expect(@typeId(AUnionEnum) == Tid.Union); | |
| 452 | expect(@typeId(AUnion) == Tid.Union); | |
| 453 | expect(@typeId(fn () void) == Tid.Fn); | |
| 454 | expect(@typeId(@TypeOf(builtin)) == Tid.Type); | |
| 455 | // TODO bound fn | |
| 456 | // TODO arg tuple | |
| 457 | // TODO opaque | |
| 458 | } | |
| 459 | } | |
| 460 | ||
| 461 | 426 | test "@typeName" { |
| 462 | 427 | const Struct = struct {}; |
| 463 | 428 | const Union = union { |
test/stage1/behavior/reflection.zig-30| ... | ... | @@ -26,36 +26,6 @@ fn dummy(a: bool, b: i32, c: f32) i32 { |
| 26 | 26 | return 1234; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | test "reflection: struct member types and names" { | |
| 30 | comptime { | |
| 31 | expect(@memberCount(Foo) == 3); | |
| 32 | ||
| 33 | expect(@memberType(Foo, 0) == i32); | |
| 34 | expect(@memberType(Foo, 1) == bool); | |
| 35 | expect(@memberType(Foo, 2) == void); | |
| 36 | ||
| 37 | expect(mem.eql(u8, @memberName(Foo, 0), "one")); | |
| 38 | expect(mem.eql(u8, @memberName(Foo, 1), "two")); | |
| 39 | expect(mem.eql(u8, @memberName(Foo, 2), "three")); | |
| 40 | } | |
| 41 | } | |
| 42 | ||
| 43 | test "reflection: enum member types and names" { | |
| 44 | comptime { | |
| 45 | expect(@memberCount(Bar) == 4); | |
| 46 | ||
| 47 | expect(@memberType(Bar, 0) == void); | |
| 48 | expect(@memberType(Bar, 1) == i32); | |
| 49 | expect(@memberType(Bar, 2) == bool); | |
| 50 | expect(@memberType(Bar, 3) == f64); | |
| 51 | ||
| 52 | expect(mem.eql(u8, @memberName(Bar, 0), "One")); | |
| 53 | expect(mem.eql(u8, @memberName(Bar, 1), "Two")); | |
| 54 | expect(mem.eql(u8, @memberName(Bar, 2), "Three")); | |
| 55 | expect(mem.eql(u8, @memberName(Bar, 3), "Four")); | |
| 56 | } | |
| 57 | } | |
| 58 | ||
| 59 | 29 | test "reflection: @field" { |
| 60 | 30 | var f = Foo{ |
| 61 | 31 | .one = 42, |
test/stage1/behavior/union.zig+1-1| ... | ... | @@ -531,7 +531,7 @@ var glbl: Foo1 = undefined; |
| 531 | 531 | |
| 532 | 532 | test "global union with single field is correctly initialized" { |
| 533 | 533 | glbl = Foo1{ |
| 534 | .f = @memberType(Foo1, 0){ .x = 123 }, | |
| 534 | .f = @typeInfo(Foo1).Union.fields[0].field_type{ .x = 123 }, | |
| 535 | 535 | }; |
| 536 | 536 | expect(glbl.f.x == 123); |
| 537 | 537 | } |
test/translate_c.zig+4-4| ... | ... | @@ -1354,7 +1354,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1354 | 1354 | cases.add("macro pointer cast", |
| 1355 | 1355 | \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) |
| 1356 | 1356 | , &[_][]const u8{ |
| 1357 | \\pub const NRF_GPIO = if (@typeId(@TypeOf(NRF_GPIO_BASE)) == .Pointer) @ptrCast([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@TypeOf(NRF_GPIO_BASE)) == .Int) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else @as([*c]NRF_GPIO_Type, NRF_GPIO_BASE); | |
| 1357 | \\pub const NRF_GPIO = if (@typeInfo(@TypeOf(NRF_GPIO_BASE)) == .Pointer) @ptrCast([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeInfo(@TypeOf(NRF_GPIO_BASE)) == .Int) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else @as([*c]NRF_GPIO_Type, NRF_GPIO_BASE); | |
| 1358 | 1358 | }); |
| 1359 | 1359 | |
| 1360 | 1360 | cases.add("basic macro function", |
| ... | ... | @@ -2538,11 +2538,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2538 | 2538 | \\#define FOO(bar) baz((void *)(baz)) |
| 2539 | 2539 | \\#define BAR (void*) a |
| 2540 | 2540 | , &[_][]const u8{ |
| 2541 | \\pub inline fn FOO(bar: var) @TypeOf(baz(if (@typeId(@TypeOf(baz)) == .Pointer) @ptrCast(*c_void, baz) else if (@typeId(@TypeOf(baz)) == .Int) @intToPtr(*c_void, baz) else @as(*c_void, baz))) { | |
| 2542 | \\ return baz(if (@typeId(@TypeOf(baz)) == .Pointer) @ptrCast(*c_void, baz) else if (@typeId(@TypeOf(baz)) == .Int) @intToPtr(*c_void, baz) else @as(*c_void, baz)); | |
| 2541 | \\pub inline fn FOO(bar: var) @TypeOf(baz(if (@typeInfo(@TypeOf(baz)) == .Pointer) @ptrCast(*c_void, baz) else if (@typeInfo(@TypeOf(baz)) == .Int) @intToPtr(*c_void, baz) else @as(*c_void, baz))) { | |
| 2542 | \\ return baz(if (@typeInfo(@TypeOf(baz)) == .Pointer) @ptrCast(*c_void, baz) else if (@typeInfo(@TypeOf(baz)) == .Int) @intToPtr(*c_void, baz) else @as(*c_void, baz)); | |
| 2543 | 2543 | \\} |
| 2544 | 2544 | , |
| 2545 | \\pub const BAR = if (@typeId(@TypeOf(a)) == .Pointer) @ptrCast(*c_void, a) else if (@typeId(@TypeOf(a)) == .Int) @intToPtr(*c_void, a) else @as(*c_void, a); | |
| 2545 | \\pub const BAR = if (@typeInfo(@TypeOf(a)) == .Pointer) @ptrCast(*c_void, a) else if (@typeInfo(@TypeOf(a)) == .Int) @intToPtr(*c_void, a) else @as(*c_void, a); | |
| 2546 | 2546 | }); |
| 2547 | 2547 | |
| 2548 | 2548 | cases.add("macro conditional operator", |