authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-02-25 21:29:56+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-01 13:57:41-05:00
log00be934569d25e3b041091ff63a4cf6c456d1403
tree0e041a8f62b213acec0016cdb041fec59f50a07d
parent3c1432701129bacf95b944f0f86af2d96ae72c69

short std.builtin enum literals in std lib


19 files changed, 97 insertions(+), 103 deletions(-)

lib/std/build.zig+4-4
......@@ -1898,10 +1898,10 @@ pub const LibExeObjStep = struct {
18981898 }
18991899
19001900 switch (self.build_mode) {
1901 builtin.Mode.Debug => {},
1902 builtin.Mode.ReleaseSafe => zig_args.append("--release-safe") catch unreachable,
1903 builtin.Mode.ReleaseFast => zig_args.append("--release-fast") catch unreachable,
1904 builtin.Mode.ReleaseSmall => zig_args.append("--release-small") catch unreachable,
1901 .Debug => {},
1902 .ReleaseSafe => zig_args.append("--release-safe") catch unreachable,
1903 .ReleaseFast => zig_args.append("--release-fast") catch unreachable,
1904 .ReleaseSmall => zig_args.append("--release-small") catch unreachable,
19051905 }
19061906
19071907 try zig_args.append("--cache-dir");
lib/std/crypto/benchmark.zig+1-1
......@@ -120,7 +120,7 @@ fn usage() void {
120120}
121121
122122fn mode(comptime x: comptime_int) comptime_int {
123 return if (builtin.mode == builtin.Mode.Debug) x / 64 else x;
123 return if (builtin.mode == .Debug) x / 64 else x;
124124}
125125
126126// TODO(#1358): Replace with builtin formatted padding when available.
lib/std/elf.zig+2-2
......@@ -370,8 +370,8 @@ pub const Elf = struct {
370370 };
371371
372372 elf.endian = switch (try in.readByte()) {
373 1 => builtin.Endian.Little,
374 2 => builtin.Endian.Big,
373 1 => .Little,
374 2 => .Big,
375375 else => return error.InvalidFormat,
376376 };
377377
lib/std/hash/auto_hash.zig+3-5
......@@ -25,13 +25,13 @@ pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void {
2525 const info = @typeInfo(@TypeOf(key));
2626
2727 switch (info.Pointer.size) {
28 builtin.TypeInfo.Pointer.Size.One => switch (strat) {
28 .One => switch (strat) {
2929 .Shallow => hash(hasher, @ptrToInt(key), .Shallow),
3030 .Deep => hash(hasher, key.*, .Shallow),
3131 .DeepRecursive => hash(hasher, key.*, .DeepRecursive),
3232 },
3333
34 builtin.TypeInfo.Pointer.Size.Slice => switch (strat) {
34 .Slice => switch (strat) {
3535 .Shallow => {
3636 hashPointer(hasher, key.ptr, .Shallow);
3737 hash(hasher, key.len, .Shallow);
......@@ -40,9 +40,7 @@ pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void {
4040 .DeepRecursive => hashArray(hasher, key, .DeepRecursive),
4141 },
4242
43 builtin.TypeInfo.Pointer.Size.Many,
44 builtin.TypeInfo.Pointer.Size.C,
45 => switch (strat) {
43 .Many, .C, => switch (strat) {
4644 .Shallow => hash(hasher, @ptrToInt(key), .Shallow),
4745 else => @compileError(
4846 \\ unknown-length pointers and C pointers cannot be hashed deeply.
lib/std/hash/benchmark.zig+1-1
......@@ -168,7 +168,7 @@ fn usage() void {
168168}
169169
170170fn mode(comptime x: comptime_int) comptime_int {
171 return if (builtin.mode == builtin.Mode.Debug) x / 64 else x;
171 return if (builtin.mode == .Debug) x / 64 else x;
172172}
173173
174174pub fn main() !void {
lib/std/hash/cityhash.zig+4-4
......@@ -11,7 +11,7 @@ pub const CityHash32 = struct {
1111 fn fetch32(ptr: [*]const u8) u32 {
1212 var v: u32 = undefined;
1313 @memcpy(@ptrCast([*]u8, &v), ptr, 4);
14 if (builtin.endian == builtin.Endian.Big)
14 if (builtin.endian == .Big)
1515 return @byteSwap(u32, v);
1616 return v;
1717 }
......@@ -174,7 +174,7 @@ pub const CityHash64 = struct {
174174 fn fetch32(ptr: [*]const u8) u32 {
175175 var v: u32 = undefined;
176176 @memcpy(@ptrCast([*]u8, &v), ptr, 4);
177 if (builtin.endian == builtin.Endian.Big)
177 if (builtin.endian == .Big)
178178 return @byteSwap(u32, v);
179179 return v;
180180 }
......@@ -182,7 +182,7 @@ pub const CityHash64 = struct {
182182 fn fetch64(ptr: [*]const u8) u64 {
183183 var v: u64 = undefined;
184184 @memcpy(@ptrCast([*]u8, &v), ptr, 8);
185 if (builtin.endian == builtin.Endian.Big)
185 if (builtin.endian == .Big)
186186 return @byteSwap(u64, v);
187187 return v;
188188 }
......@@ -369,7 +369,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
369369 key[i] = @intCast(u8, i);
370370
371371 var h = hash_fn(key[0..i], 256 - i);
372 if (builtin.endian == builtin.Endian.Big)
372 if (builtin.endian == .Big)
373373 h = @byteSwap(@TypeOf(h), h);
374374 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
375375 }
lib/std/hash/murmur.zig+8-8
......@@ -17,7 +17,7 @@ pub const Murmur2_32 = struct {
1717 var h1: u32 = seed ^ len;
1818 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {
1919 var k1: u32 = v;
20 if (builtin.endian == builtin.Endian.Big)
20 if (builtin.endian == .Big)
2121 k1 = @byteSwap(u32, k1);
2222 k1 *%= m;
2323 k1 ^= k1 >> 24;
......@@ -102,7 +102,7 @@ pub const Murmur2_64 = struct {
102102 var h1: u64 = seed ^ (len *% m);
103103 for (@ptrCast([*]align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {
104104 var k1: u64 = v;
105 if (builtin.endian == builtin.Endian.Big)
105 if (builtin.endian == .Big)
106106 k1 = @byteSwap(u64, k1);
107107 k1 *%= m;
108108 k1 ^= k1 >> 47;
......@@ -115,7 +115,7 @@ pub const Murmur2_64 = struct {
115115 if (rest > 0) {
116116 var k1: u64 = 0;
117117 @memcpy(@ptrCast([*]u8, &k1), @ptrCast([*]const u8, &str[@intCast(usize, offset)]), @intCast(usize, rest));
118 if (builtin.endian == builtin.Endian.Big)
118 if (builtin.endian == .Big)
119119 k1 = @byteSwap(u64, k1);
120120 h1 ^= k1;
121121 h1 *%= m;
......@@ -182,7 +182,7 @@ pub const Murmur3_32 = struct {
182182 var h1: u32 = seed;
183183 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {
184184 var k1: u32 = v;
185 if (builtin.endian == builtin.Endian.Big)
185 if (builtin.endian == .Big)
186186 k1 = @byteSwap(u32, k1);
187187 k1 *%= c1;
188188 k1 = rotl32(k1, 15);
......@@ -294,7 +294,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
294294 key[i] = @truncate(u8, i);
295295
296296 var h = hash_fn(key[0..i], 256 - i);
297 if (builtin.endian == builtin.Endian.Big)
297 if (builtin.endian == .Big)
298298 h = @byteSwap(@TypeOf(h), h);
299299 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
300300 }
......@@ -308,7 +308,7 @@ test "murmur2_32" {
308308 var v1: u64 = 0x1234567812345678;
309309 var v0le: u32 = v0;
310310 var v1le: u64 = v1;
311 if (builtin.endian == builtin.Endian.Big) {
311 if (builtin.endian == .Big) {
312312 v0le = @byteSwap(u32, v0le);
313313 v1le = @byteSwap(u64, v1le);
314314 }
......@@ -322,7 +322,7 @@ test "murmur2_64" {
322322 var v1: u64 = 0x1234567812345678;
323323 var v0le: u32 = v0;
324324 var v1le: u64 = v1;
325 if (builtin.endian == builtin.Endian.Big) {
325 if (builtin.endian == .Big) {
326326 v0le = @byteSwap(u32, v0le);
327327 v1le = @byteSwap(u64, v1le);
328328 }
......@@ -336,7 +336,7 @@ test "murmur3_32" {
336336 var v1: u64 = 0x1234567812345678;
337337 var v0le: u32 = v0;
338338 var v1le: u64 = v1;
339 if (builtin.endian == builtin.Endian.Big) {
339 if (builtin.endian == .Big) {
340340 v0le = @byteSwap(u32, v0le);
341341 v1le = @byteSwap(u64, v1le);
342342 }
lib/std/hash_map.zig+1-1
......@@ -10,7 +10,7 @@ const Wyhash = std.hash.Wyhash;
1010const Allocator = mem.Allocator;
1111const builtin = @import("builtin");
1212
13const want_modification_safety = builtin.mode != builtin.Mode.ReleaseFast;
13const want_modification_safety = builtin.mode != .ReleaseFast;
1414const debug_u32 = if (want_modification_safety) u32 else void;
1515
1616pub fn AutoHashMap(comptime K: type, comptime V: type) type {
lib/std/io.zig+14-14
......@@ -348,11 +348,11 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
348348 const n = if (self.bit_count >= bits) @intCast(u3, bits) else self.bit_count;
349349 const shift = u7_bit_count - n;
350350 switch (endian) {
351 builtin.Endian.Big => {
351 .Big => {
352352 out_buffer = @as(Buf, self.bit_buffer >> shift);
353353 self.bit_buffer <<= n;
354354 },
355 builtin.Endian.Little => {
355 .Little => {
356356 const value = (self.bit_buffer << shift) >> shift;
357357 out_buffer = @as(Buf, value);
358358 self.bit_buffer >>= n;
......@@ -376,7 +376,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
376376 };
377377
378378 switch (endian) {
379 builtin.Endian.Big => {
379 .Big => {
380380 if (n >= u8_bit_count) {
381381 out_buffer <<= @intCast(u3, u8_bit_count - 1);
382382 out_buffer <<= 1;
......@@ -392,7 +392,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
392392 self.bit_buffer = @truncate(u7, next_byte << @intCast(u3, n - 1));
393393 self.bit_count = shift;
394394 },
395 builtin.Endian.Little => {
395 .Little => {
396396 if (n >= u8_bit_count) {
397397 out_buffer |= @as(Buf, next_byte) << @intCast(BufShift, out_bits.*);
398398 out_bits.* += u8_bit_count;
......@@ -666,8 +666,8 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {
666666
667667 const high_byte_shift = @intCast(BufShift, buf_bit_count - u8_bit_count);
668668 var in_buffer = switch (endian) {
669 builtin.Endian.Big => buf_value << @intCast(BufShift, buf_bit_count - bits),
670 builtin.Endian.Little => buf_value,
669 .Big => buf_value << @intCast(BufShift, buf_bit_count - bits),
670 .Little => buf_value,
671671 };
672672 var in_bits = bits;
673673
......@@ -675,13 +675,13 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {
675675 const bits_remaining = u8_bit_count - self.bit_count;
676676 const n = @intCast(u3, if (bits_remaining > bits) bits else bits_remaining);
677677 switch (endian) {
678 builtin.Endian.Big => {
678 .Big => {
679679 const shift = @intCast(BufShift, high_byte_shift + self.bit_count);
680680 const v = @intCast(u8, in_buffer >> shift);
681681 self.bit_buffer |= v;
682682 in_buffer <<= n;
683683 },
684 builtin.Endian.Little => {
684 .Little => {
685685 const v = @truncate(u8, in_buffer) << @intCast(u3, self.bit_count);
686686 self.bit_buffer |= v;
687687 in_buffer >>= n;
......@@ -701,13 +701,13 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {
701701 //copy bytes until we can't fill one anymore, then leave the rest in bit_buffer
702702 while (in_bits >= u8_bit_count) {
703703 switch (endian) {
704 builtin.Endian.Big => {
704 .Big => {
705705 const v = @intCast(u8, in_buffer >> high_byte_shift);
706706 try self.out_stream.writeByte(v);
707707 in_buffer <<= @intCast(u3, u8_bit_count - 1);
708708 in_buffer <<= 1;
709709 },
710 builtin.Endian.Little => {
710 .Little => {
711711 const v = @truncate(u8, in_buffer);
712712 try self.out_stream.writeByte(v);
713713 in_buffer >>= @intCast(u3, u8_bit_count - 1);
......@@ -720,8 +720,8 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {
720720 if (in_bits > 0) {
721721 self.bit_count = @intCast(u4, in_bits);
722722 self.bit_buffer = switch (endian) {
723 builtin.Endian.Big => @truncate(u8, in_buffer >> high_byte_shift),
724 builtin.Endian.Little => @truncate(u8, in_buffer),
723 .Big => @truncate(u8, in_buffer >> high_byte_shift),
724 .Little => @truncate(u8, in_buffer),
725725 };
726726 }
727727 }
......@@ -858,10 +858,10 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
858858 var result = @as(U, 0);
859859 for (buffer) |byte, i| {
860860 switch (endian) {
861 builtin.Endian.Big => {
861 .Big => {
862862 result = (result << u8_bit_count) | byte;
863863 },
864 builtin.Endian.Little => {
864 .Little => {
865865 result |= @as(U, byte) << @intCast(Log2U, u8_bit_count * i);
866866 },
867867 }
lib/std/math/pow.zig+1-1
......@@ -32,7 +32,7 @@ const expect = std.testing.expect;
3232/// - pow(-inf, y) = pow(-0, -y)
3333/// - pow(x, y) = nan for finite x < 0 and finite non-integer y
3434pub fn pow(comptime T: type, x: T, y: T) T {
35 if (@typeInfo(T) == builtin.TypeId.Int) {
35 if (@typeInfo(T) == .Int) {
3636 return math.powi(T, x, y) catch unreachable;
3737 }
3838
lib/std/math/powi.zig+1-1
......@@ -25,7 +25,7 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
2525}!T) {
2626 const info = @typeInfo(T);
2727
28 comptime assert(@typeInfo(T) == builtin.TypeId.Int);
28 comptime assert(@typeInfo(T) == .Int);
2929
3030 // powi(x, +-0) = 1 for any x
3131 if (y == 0 or y == -0) {
lib/std/mem.zig+48-48
......@@ -746,12 +746,12 @@ test "mem.indexOf" {
746746pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin.Endian) ReturnType {
747747 var result: ReturnType = 0;
748748 switch (endian) {
749 builtin.Endian.Big => {
749 .Big => {
750750 for (bytes) |b| {
751751 result = (result << 8) | b;
752752 }
753753 },
754 builtin.Endian.Little => {
754 .Little => {
755755 const ShiftType = math.Log2Int(ReturnType);
756756 for (bytes) |b, index| {
757757 result = result | (@as(ReturnType, b) << @intCast(ShiftType, index * 8));
......@@ -779,13 +779,13 @@ pub fn readIntForeign(comptime T: type, bytes: *const [@divExact(T.bit_count, 8)
779779}
780780
781781pub const readIntLittle = switch (builtin.endian) {
782 builtin.Endian.Little => readIntNative,
783 builtin.Endian.Big => readIntForeign,
782 .Little => readIntNative,
783 .Big => readIntForeign,
784784};
785785
786786pub const readIntBig = switch (builtin.endian) {
787 builtin.Endian.Little => readIntForeign,
788 builtin.Endian.Big => readIntNative,
787 .Little => readIntForeign,
788 .Big => readIntNative,
789789};
790790
791791/// Asserts that bytes.len >= T.bit_count / 8. Reads the integer starting from index 0
......@@ -809,13 +809,13 @@ pub fn readIntSliceForeign(comptime T: type, bytes: []const u8) T {
809809}
810810
811811pub const readIntSliceLittle = switch (builtin.endian) {
812 builtin.Endian.Little => readIntSliceNative,
813 builtin.Endian.Big => readIntSliceForeign,
812 .Little => readIntSliceNative,
813 .Big => readIntSliceForeign,
814814};
815815
816816pub const readIntSliceBig = switch (builtin.endian) {
817 builtin.Endian.Little => readIntSliceForeign,
818 builtin.Endian.Big => readIntSliceNative,
817 .Little => readIntSliceForeign,
818 .Big => readIntSliceNative,
819819};
820820
821821/// Reads an integer from memory with bit count specified by T.
......@@ -892,13 +892,13 @@ pub fn writeIntForeign(comptime T: type, buf: *[@divExact(T.bit_count, 8)]u8, va
892892}
893893
894894pub const writeIntLittle = switch (builtin.endian) {
895 builtin.Endian.Little => writeIntNative,
896 builtin.Endian.Big => writeIntForeign,
895 .Little => writeIntNative,
896 .Big => writeIntForeign,
897897};
898898
899899pub const writeIntBig = switch (builtin.endian) {
900 builtin.Endian.Little => writeIntForeign,
901 builtin.Endian.Big => writeIntNative,
900 .Little => writeIntForeign,
901 .Big => writeIntNative,
902902};
903903
904904/// Writes an integer to memory, storing it in twos-complement.
......@@ -950,13 +950,13 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
950950}
951951
952952pub const writeIntSliceNative = switch (builtin.endian) {
953 builtin.Endian.Little => writeIntSliceLittle,
954 builtin.Endian.Big => writeIntSliceBig,
953 .Little => writeIntSliceLittle,
954 .Big => writeIntSliceBig,
955955};
956956
957957pub const writeIntSliceForeign = switch (builtin.endian) {
958 builtin.Endian.Little => writeIntSliceBig,
959 builtin.Endian.Big => writeIntSliceLittle,
958 .Little => writeIntSliceBig,
959 .Big => writeIntSliceLittle,
960960};
961961
962962/// Writes a twos-complement integer to memory, with the specified endianness.
......@@ -967,10 +967,10 @@ pub const writeIntSliceForeign = switch (builtin.endian) {
967967/// use writeInt instead.
968968pub fn writeIntSlice(comptime T: type, buffer: []u8, value: T, endian: builtin.Endian) void {
969969 comptime assert(T.bit_count % 8 == 0);
970 switch (endian) {
971 builtin.Endian.Little => return writeIntSliceLittle(T, buffer, value),
972 builtin.Endian.Big => return writeIntSliceBig(T, buffer, value),
973 }
970 return switch (endian) {
971 .Little => writeIntSliceLittle(T, buffer, value),
972 .Big => writeIntSliceBig(T, buffer, value),
973 };
974974}
975975
976976test "writeIntBig and writeIntLittle" {
......@@ -1506,54 +1506,54 @@ test "rotate" {
15061506/// Converts a little-endian integer to host endianness.
15071507pub fn littleToNative(comptime T: type, x: T) T {
15081508 return switch (builtin.endian) {
1509 builtin.Endian.Little => x,
1510 builtin.Endian.Big => @byteSwap(T, x),
1509 .Little => x,
1510 .Big => @byteSwap(T, x),
15111511 };
15121512}
15131513
15141514/// Converts a big-endian integer to host endianness.
15151515pub fn bigToNative(comptime T: type, x: T) T {
15161516 return switch (builtin.endian) {
1517 builtin.Endian.Little => @byteSwap(T, x),
1518 builtin.Endian.Big => x,
1517 .Little => @byteSwap(T, x),
1518 .Big => x,
15191519 };
15201520}
15211521
15221522/// Converts an integer from specified endianness to host endianness.
15231523pub fn toNative(comptime T: type, x: T, endianness_of_x: builtin.Endian) T {
15241524 return switch (endianness_of_x) {
1525 builtin.Endian.Little => littleToNative(T, x),
1526 builtin.Endian.Big => bigToNative(T, x),
1525 .Little => littleToNative(T, x),
1526 .Big => bigToNative(T, x),
15271527 };
15281528}
15291529
15301530/// Converts an integer which has host endianness to the desired endianness.
15311531pub fn nativeTo(comptime T: type, x: T, desired_endianness: builtin.Endian) T {
15321532 return switch (desired_endianness) {
1533 builtin.Endian.Little => nativeToLittle(T, x),
1534 builtin.Endian.Big => nativeToBig(T, x),
1533 .Little => nativeToLittle(T, x),
1534 .Big => nativeToBig(T, x),
15351535 };
15361536}
15371537
15381538/// Converts an integer which has host endianness to little endian.
15391539pub fn nativeToLittle(comptime T: type, x: T) T {
15401540 return switch (builtin.endian) {
1541 builtin.Endian.Little => x,
1542 builtin.Endian.Big => @byteSwap(T, x),
1541 .Little => x,
1542 .Big => @byteSwap(T, x),
15431543 };
15441544}
15451545
15461546/// Converts an integer which has host endianness to big endian.
15471547pub fn nativeToBig(comptime T: type, x: T) T {
15481548 return switch (builtin.endian) {
1549 builtin.Endian.Little => @byteSwap(T, x),
1550 builtin.Endian.Big => x,
1549 .Little => @byteSwap(T, x),
1550 .Big => x,
15511551 };
15521552}
15531553
15541554fn AsBytesReturnType(comptime P: type) type {
15551555 if (comptime !trait.isSingleItemPtr(P))
1556 @compileError("expected single item " ++ "pointer, passed " ++ @typeName(P));
1556 @compileError("expected single item pointer, passed " ++ @typeName(P));
15571557
15581558 const size = @as(usize, @sizeOf(meta.Child(P)));
15591559 const alignment = comptime meta.alignment(P);
......@@ -1578,8 +1578,8 @@ pub fn asBytes(ptr: var) AsBytesReturnType(@TypeOf(ptr)) {
15781578test "asBytes" {
15791579 const deadbeef = @as(u32, 0xDEADBEEF);
15801580 const deadbeef_bytes = switch (builtin.endian) {
1581 builtin.Endian.Big => "\xDE\xAD\xBE\xEF",
1582 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
1581 .Big => "\xDE\xAD\xBE\xEF",
1582 .Little => "\xEF\xBE\xAD\xDE",
15831583 };
15841584
15851585 testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
......@@ -1617,21 +1617,21 @@ pub fn toBytes(value: var) [@sizeOf(@TypeOf(value))]u8 {
16171617test "toBytes" {
16181618 var my_bytes = toBytes(@as(u32, 0x12345678));
16191619 switch (builtin.endian) {
1620 builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
1621 builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
1620 .Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
1621 .Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
16221622 }
16231623
16241624 my_bytes[0] = '\x99';
16251625 switch (builtin.endian) {
1626 builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
1627 builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
1626 .Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
1627 .Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
16281628 }
16291629}
16301630
16311631fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
16321632 const size = @as(usize, @sizeOf(T));
16331633
1634 if (comptime !trait.is(builtin.TypeId.Pointer)(B) or
1634 if (comptime !trait.is(.Pointer)(B) or
16351635 (meta.Child(B) != [size]u8 and meta.Child(B) != [size:0]u8))
16361636 {
16371637 @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B));
......@@ -1651,15 +1651,15 @@ pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @Typ
16511651test "bytesAsValue" {
16521652 const deadbeef = @as(u32, 0xDEADBEEF);
16531653 const deadbeef_bytes = switch (builtin.endian) {
1654 builtin.Endian.Big => "\xDE\xAD\xBE\xEF",
1655 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
1654 .Big => "\xDE\xAD\xBE\xEF",
1655 .Little => "\xEF\xBE\xAD\xDE",
16561656 };
16571657
16581658 testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
16591659
16601660 var codeface_bytes: [4]u8 = switch (builtin.endian) {
1661 builtin.Endian.Big => "\xC0\xDE\xFA\xCE",
1662 builtin.Endian.Little => "\xCE\xFA\xDE\xC0",
1661 .Big => "\xC0\xDE\xFA\xCE",
1662 .Little => "\xCE\xFA\xDE\xC0",
16631663 }.*;
16641664 var codeface = bytesAsValue(u32, &codeface_bytes);
16651665 testing.expect(codeface.* == 0xC0DEFACE);
......@@ -1692,8 +1692,8 @@ pub fn bytesToValue(comptime T: type, bytes: var) T {
16921692}
16931693test "bytesToValue" {
16941694 const deadbeef_bytes = switch (builtin.endian) {
1695 builtin.Endian.Big => "\xDE\xAD\xBE\xEF",
1696 builtin.Endian.Little => "\xEF\xBE\xAD\xDE",
1695 .Big => "\xDE\xAD\xBE\xEF",
1696 .Little => "\xEF\xBE\xAD\xDE",
16971697 };
16981698
16991699 const deadbeef = bytesToValue(u32, deadbeef_bytes);
lib/std/special/compiler_rt/ashlti3.zig+1-1
......@@ -24,7 +24,7 @@ const twords = extern union {
2424 all: i128,
2525 s: S,
2626
27 const S = if (builtin.endian == builtin.Endian.Little)
27 const S = if (builtin.endian == .Little)
2828 struct {
2929 low: u64,
3030 high: u64,
lib/std/special/compiler_rt/ashrti3.zig+1-1
......@@ -25,7 +25,7 @@ const twords = extern union {
2525 all: i128,
2626 s: S,
2727
28 const S = if (builtin.endian == builtin.Endian.Little)
28 const S = if (builtin.endian == .Little)
2929 struct {
3030 low: i64,
3131 high: i64,
lib/std/special/compiler_rt/lshrti3.zig+1-1
......@@ -24,7 +24,7 @@ const twords = extern union {
2424 all: i128,
2525 s: S,
2626
27 const S = if (builtin.endian == builtin.Endian.Little)
27 const S = if (builtin.endian == .Little)
2828 struct {
2929 low: u64,
3030 high: u64,
lib/std/special/compiler_rt/multi3.zig+1-1
......@@ -45,7 +45,7 @@ const twords = extern union {
4545 all: i128,
4646 s: S,
4747
48 const S = if (builtin.endian == builtin.Endian.Little)
48 const S = if (builtin.endian == .Little)
4949 struct {
5050 low: u64,
5151 high: u64,
lib/std/special/compiler_rt/udivmod.zig+2-2
......@@ -2,8 +2,8 @@ const builtin = @import("builtin");
22const is_test = builtin.is_test;
33
44const low = switch (builtin.endian) {
5 builtin.Endian.Big => 1,
6 builtin.Endian.Little => 0,
5 .Big => 1,
6 .Little => 0,
77};
88const high = 1 - low;
99
lib/std/testing.zig+1-5
......@@ -63,15 +63,11 @@ pub fn expectEqual(expected: var, actual: @TypeOf(expected)) void {
6363
6464 .Pointer => |pointer| {
6565 switch (pointer.size) {
66 .One,
67 .Many,
68 .C,
69 => {
66 .One, .Many, .C => {
7067 if (actual != expected) {
7168 std.debug.panic("expected {*}, found {*}", .{ expected, actual });
7269 }
7370 },
74
7571 .Slice => {
7672 if (actual.ptr != expected.ptr) {
7773 std.debug.panic("expected slice ptr {}, found {}", .{ expected.ptr, actual.ptr });
lib/std/valgrind.zig+2-2
......@@ -8,7 +8,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:
88 }
99
1010 switch (builtin.arch) {
11 builtin.Arch.i386 => {
11 .i386 => {
1212 return asm volatile (
1313 \\ roll $3, %%edi ; roll $13, %%edi
1414 \\ roll $29, %%edi ; roll $19, %%edi
......@@ -19,7 +19,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:
1919 : "cc", "memory"
2020 );
2121 },
22 builtin.Arch.x86_64 => {
22 .x86_64 => {
2323 return asm volatile (
2424 \\ rolq $3, %%rdi ; rolq $13, %%rdi
2525 \\ rolq $61, %%rdi ; rolq $51, %%rdi