| author | |
| committer | |
| log | 8b2622cdd58cec697d9d1f8f49717b6ce7ee3e2e |
| tree | 3de817be4757dd1ad0bbdc0c7c3f863deb0f1d43 |
| parent | 5874cb04bd544ca155d1489bb0bdf9397fa3b41c |
| signature | Commit is signed but in an unrecognized format. |
48 files changed, 643 insertions(+), 839 deletions(-)
build.zig+5-5| ... | @@ -154,7 +154,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void { | ... | @@ -154,7 +154,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void { |
| 154 | const static_bare_name = if (mem.eql(u8, lib, "curses")) | 154 | const static_bare_name = if (mem.eql(u8, lib, "curses")) |
| 155 | @as([]const u8, "libncurses.a") | 155 | @as([]const u8, "libncurses.a") |
| 156 | else | 156 | else |
| 157 | b.fmt("lib{}.a", lib); | 157 | b.fmt("lib{}.a", .{lib}); |
| 158 | const static_lib_name = fs.path.join( | 158 | const static_lib_name = fs.path.join( |
| 159 | b.allocator, | 159 | b.allocator, |
| 160 | &[_][]const u8{ lib_dir, static_bare_name }, | 160 | &[_][]const u8{ lib_dir, static_bare_name }, |
| ... | @@ -186,7 +186,7 @@ fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_na | ... | @@ -186,7 +186,7 @@ fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_na |
| 186 | lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{ | 186 | lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{ |
| 187 | cmake_binary_dir, | 187 | cmake_binary_dir, |
| 188 | "zig_cpp", | 188 | "zig_cpp", |
| 189 | b.fmt("{}{}{}", lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix()), | 189 | b.fmt("{}{}{}", .{ lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix() }), |
| 190 | }) catch unreachable); | 190 | }) catch unreachable); |
| 191 | } | 191 | } |
| 192 | 192 | ||
| ... | @@ -343,14 +343,14 @@ fn addCxxKnownPath( | ... | @@ -343,14 +343,14 @@ fn addCxxKnownPath( |
| 343 | ) !void { | 343 | ) !void { |
| 344 | const path_padded = try b.exec(&[_][]const u8{ | 344 | const path_padded = try b.exec(&[_][]const u8{ |
| 345 | ctx.cxx_compiler, | 345 | ctx.cxx_compiler, |
| 346 | b.fmt("-print-file-name={}", objname), | 346 | b.fmt("-print-file-name={}", .{objname}), |
| 347 | }); | 347 | }); |
| 348 | const path_unpadded = mem.tokenize(path_padded, "\r\n").next().?; | 348 | const path_unpadded = mem.tokenize(path_padded, "\r\n").next().?; |
| 349 | if (mem.eql(u8, path_unpadded, objname)) { | 349 | if (mem.eql(u8, path_unpadded, objname)) { |
| 350 | if (errtxt) |msg| { | 350 | if (errtxt) |msg| { |
| 351 | warn("{}", msg); | 351 | warn("{}", .{msg}); |
| 352 | } else { | 352 | } else { |
| 353 | warn("Unable to determine path to {}\n", objname); | 353 | warn("Unable to determine path to {}\n", .{objname}); |
| 354 | } | 354 | } |
| 355 | return error.RequiredLibraryNotFound; | 355 | return error.RequiredLibraryNotFound; |
| 356 | } | 356 | } |
lib/std/atomic/queue.zig+9-10| ... | @@ -116,19 +116,19 @@ pub fn Queue(comptime T: type) type { | ... | @@ -116,19 +116,19 @@ pub fn Queue(comptime T: type) type { |
| 116 | fn dumpRecursive(s: *std.io.OutStream(Error), optional_node: ?*Node, indent: usize) Error!void { | 116 | fn dumpRecursive(s: *std.io.OutStream(Error), optional_node: ?*Node, indent: usize) Error!void { |
| 117 | try s.writeByteNTimes(' ', indent); | 117 | try s.writeByteNTimes(' ', indent); |
| 118 | if (optional_node) |node| { | 118 | if (optional_node) |node| { |
| 119 | try s.print("0x{x}={}\n", @ptrToInt(node), node.data); | 119 | try s.print("0x{x}={}\n", .{ @ptrToInt(node), node.data }); |
| 120 | try dumpRecursive(s, node.next, indent + 1); | 120 | try dumpRecursive(s, node.next, indent + 1); |
| 121 | } else { | 121 | } else { |
| 122 | try s.print("(null)\n"); | 122 | try s.print("(null)\n", .{}); |
| 123 | } | 123 | } |
| 124 | } | 124 | } |
| 125 | }; | 125 | }; |
| 126 | const held = self.mutex.acquire(); | 126 | const held = self.mutex.acquire(); |
| 127 | defer held.release(); | 127 | defer held.release(); |
| 128 | 128 | ||
| 129 | try stream.print("head: "); | 129 | try stream.print("head: ", .{}); |
| 130 | try S.dumpRecursive(stream, self.head, 0); | 130 | try S.dumpRecursive(stream, self.head, 0); |
| 131 | try stream.print("tail: "); | 131 | try stream.print("tail: ", .{}); |
| 132 | try S.dumpRecursive(stream, self.tail, 0); | 132 | try S.dumpRecursive(stream, self.tail, 0); |
| 133 | } | 133 | } |
| 134 | }; | 134 | }; |
| ... | @@ -207,16 +207,15 @@ test "std.atomic.Queue" { | ... | @@ -207,16 +207,15 @@ test "std.atomic.Queue" { |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | if (context.put_sum != context.get_sum) { | 209 | if (context.put_sum != context.get_sum) { |
| 210 | std.debug.panic("failure\nput_sum:{} != get_sum:{}", context.put_sum, context.get_sum); | 210 | std.debug.panic("failure\nput_sum:{} != get_sum:{}", .{ context.put_sum, context.get_sum }); |
| 211 | } | 211 | } |
| 212 | 212 | ||
| 213 | if (context.get_count != puts_per_thread * put_thread_count) { | 213 | if (context.get_count != puts_per_thread * put_thread_count) { |
| 214 | std.debug.panic( | 214 | std.debug.panic("failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", .{ |
| 215 | "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", | ||
| 216 | context.get_count, | 215 | context.get_count, |
| 217 | @as(u32, puts_per_thread), | 216 | @as(u32, puts_per_thread), |
| 218 | @as(u32, put_thread_count), | 217 | @as(u32, put_thread_count), |
| 219 | ); | 218 | }); |
| 220 | } | 219 | } |
| 221 | } | 220 | } |
| 222 | 221 | ||
| ... | @@ -351,7 +350,7 @@ test "std.atomic.Queue dump" { | ... | @@ -351,7 +350,7 @@ test "std.atomic.Queue dump" { |
| 351 | \\tail: 0x{x}=1 | 350 | \\tail: 0x{x}=1 |
| 352 | \\ (null) | 351 | \\ (null) |
| 353 | \\ | 352 | \\ |
| 354 | , @ptrToInt(queue.head), @ptrToInt(queue.tail)); | 353 | , .{ @ptrToInt(queue.head), @ptrToInt(queue.tail) }); |
| 355 | expect(mem.eql(u8, buffer[0..sos.pos], expected)); | 354 | expect(mem.eql(u8, buffer[0..sos.pos], expected)); |
| 356 | 355 | ||
| 357 | // Test a stream with two elements | 356 | // Test a stream with two elements |
| ... | @@ -372,6 +371,6 @@ test "std.atomic.Queue dump" { | ... | @@ -372,6 +371,6 @@ test "std.atomic.Queue dump" { |
| 372 | \\tail: 0x{x}=2 | 371 | \\tail: 0x{x}=2 |
| 373 | \\ (null) | 372 | \\ (null) |
| 374 | \\ | 373 | \\ |
| 375 | , @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail)); | 374 | , .{ @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail) }); |
| 376 | expect(mem.eql(u8, buffer[0..sos.pos], expected)); | 375 | expect(mem.eql(u8, buffer[0..sos.pos], expected)); |
| 377 | } | 376 | } |
lib/std/atomic/stack.zig+3-4| ... | @@ -134,16 +134,15 @@ test "std.atomic.stack" { | ... | @@ -134,16 +134,15 @@ test "std.atomic.stack" { |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | if (context.put_sum != context.get_sum) { | 136 | if (context.put_sum != context.get_sum) { |
| 137 | std.debug.panic("failure\nput_sum:{} != get_sum:{}", context.put_sum, context.get_sum); | 137 | std.debug.panic("failure\nput_sum:{} != get_sum:{}", .{ context.put_sum, context.get_sum }); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | if (context.get_count != puts_per_thread * put_thread_count) { | 140 | if (context.get_count != puts_per_thread * put_thread_count) { |
| 141 | std.debug.panic( | 141 | std.debug.panic("failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", .{ |
| 142 | "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", | ||
| 143 | context.get_count, | 142 | context.get_count, |
| 144 | @as(u32, puts_per_thread), | 143 | @as(u32, puts_per_thread), |
| 145 | @as(u32, put_thread_count), | 144 | @as(u32, put_thread_count), |
| 146 | ); | 145 | }); |
| 147 | } | 146 | } |
| 148 | } | 147 | } |
| 149 | 148 |
lib/std/buffer.zig+4-4| ... | @@ -16,7 +16,7 @@ pub const Buffer = struct { | ... | @@ -16,7 +16,7 @@ pub const Buffer = struct { |
| 16 | mem.copy(u8, self.list.items, m); | 16 | mem.copy(u8, self.list.items, m); |
| 17 | return self; | 17 | return self; |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | /// Initialize memory to size bytes of undefined values. | 20 | /// Initialize memory to size bytes of undefined values. |
| 21 | /// Must deinitialize with deinit. | 21 | /// Must deinitialize with deinit. |
| 22 | pub fn initSize(allocator: *Allocator, size: usize) !Buffer { | 22 | pub fn initSize(allocator: *Allocator, size: usize) !Buffer { |
| ... | @@ -24,7 +24,7 @@ pub const Buffer = struct { | ... | @@ -24,7 +24,7 @@ pub const Buffer = struct { |
| 24 | try self.resize(size); | 24 | try self.resize(size); |
| 25 | return self; | 25 | return self; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | /// Initialize with capacity to hold at least num bytes. | 28 | /// Initialize with capacity to hold at least num bytes. |
| 29 | /// Must deinitialize with deinit. | 29 | /// Must deinitialize with deinit. |
| 30 | pub fn initCapacity(allocator: *Allocator, num: usize) !Buffer { | 30 | pub fn initCapacity(allocator: *Allocator, num: usize) !Buffer { |
| ... | @@ -64,7 +64,7 @@ pub const Buffer = struct { | ... | @@ -64,7 +64,7 @@ pub const Buffer = struct { |
| 64 | return result; | 64 | return result; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: ...) !Buffer { | 67 | pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: var) !Buffer { |
| 68 | const countSize = struct { | 68 | const countSize = struct { |
| 69 | fn countSize(size: *usize, bytes: []const u8) (error{}!void) { | 69 | fn countSize(size: *usize, bytes: []const u8) (error{}!void) { |
| 70 | size.* += bytes.len; | 70 | size.* += bytes.len; |
| ... | @@ -107,7 +107,7 @@ pub const Buffer = struct { | ... | @@ -107,7 +107,7 @@ pub const Buffer = struct { |
| 107 | pub fn len(self: Buffer) usize { | 107 | pub fn len(self: Buffer) usize { |
| 108 | return self.list.len - 1; | 108 | return self.list.len - 1; |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | pub fn capacity(self: Buffer) usize { | 111 | pub fn capacity(self: Buffer) usize { |
| 112 | return if (self.list.items.len > 0) | 112 | return if (self.list.items.len > 0) |
| 113 | self.list.items.len - 1 | 113 | self.list.items.len - 1 |
lib/std/build.zig+104-82| ... | @@ -232,7 +232,7 @@ pub const Builder = struct { | ... | @@ -232,7 +232,7 @@ pub const Builder = struct { |
| 232 | /// To run an executable built with zig build, see `LibExeObjStep.run`. | 232 | /// To run an executable built with zig build, see `LibExeObjStep.run`. |
| 233 | pub fn addSystemCommand(self: *Builder, argv: []const []const u8) *RunStep { | 233 | pub fn addSystemCommand(self: *Builder, argv: []const []const u8) *RunStep { |
| 234 | assert(argv.len >= 1); | 234 | assert(argv.len >= 1); |
| 235 | const run_step = RunStep.create(self, self.fmt("run {}", argv[0])); | 235 | const run_step = RunStep.create(self, self.fmt("run {}", .{argv[0]})); |
| 236 | run_step.addArgs(argv); | 236 | run_step.addArgs(argv); |
| 237 | return run_step; | 237 | return run_step; |
| 238 | } | 238 | } |
| ... | @@ -258,7 +258,7 @@ pub const Builder = struct { | ... | @@ -258,7 +258,7 @@ pub const Builder = struct { |
| 258 | return write_file_step; | 258 | return write_file_step; |
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | pub fn addLog(self: *Builder, comptime format: []const u8, args: ...) *LogStep { | 261 | pub fn addLog(self: *Builder, comptime format: []const u8, args: var) *LogStep { |
| 262 | const data = self.fmt(format, args); | 262 | const data = self.fmt(format, args); |
| 263 | const log_step = self.allocator.create(LogStep) catch unreachable; | 263 | const log_step = self.allocator.create(LogStep) catch unreachable; |
| 264 | log_step.* = LogStep.init(self, data); | 264 | log_step.* = LogStep.init(self, data); |
| ... | @@ -330,7 +330,7 @@ pub const Builder = struct { | ... | @@ -330,7 +330,7 @@ pub const Builder = struct { |
| 330 | for (self.installed_files.toSliceConst()) |installed_file| { | 330 | for (self.installed_files.toSliceConst()) |installed_file| { |
| 331 | const full_path = self.getInstallPath(installed_file.dir, installed_file.path); | 331 | const full_path = self.getInstallPath(installed_file.dir, installed_file.path); |
| 332 | if (self.verbose) { | 332 | if (self.verbose) { |
| 333 | warn("rm {}\n", full_path); | 333 | warn("rm {}\n", .{full_path}); |
| 334 | } | 334 | } |
| 335 | fs.deleteTree(full_path) catch {}; | 335 | fs.deleteTree(full_path) catch {}; |
| 336 | } | 336 | } |
| ... | @@ -340,7 +340,7 @@ pub const Builder = struct { | ... | @@ -340,7 +340,7 @@ pub const Builder = struct { |
| 340 | 340 | ||
| 341 | fn makeOneStep(self: *Builder, s: *Step) anyerror!void { | 341 | fn makeOneStep(self: *Builder, s: *Step) anyerror!void { |
| 342 | if (s.loop_flag) { | 342 | if (s.loop_flag) { |
| 343 | warn("Dependency loop detected:\n {}\n", s.name); | 343 | warn("Dependency loop detected:\n {}\n", .{s.name}); |
| 344 | return error.DependencyLoopDetected; | 344 | return error.DependencyLoopDetected; |
| 345 | } | 345 | } |
| 346 | s.loop_flag = true; | 346 | s.loop_flag = true; |
| ... | @@ -348,7 +348,7 @@ pub const Builder = struct { | ... | @@ -348,7 +348,7 @@ pub const Builder = struct { |
| 348 | for (s.dependencies.toSlice()) |dep| { | 348 | for (s.dependencies.toSlice()) |dep| { |
| 349 | self.makeOneStep(dep) catch |err| { | 349 | self.makeOneStep(dep) catch |err| { |
| 350 | if (err == error.DependencyLoopDetected) { | 350 | if (err == error.DependencyLoopDetected) { |
| 351 | warn(" {}\n", s.name); | 351 | warn(" {}\n", .{s.name}); |
| 352 | } | 352 | } |
| 353 | return err; | 353 | return err; |
| 354 | }; | 354 | }; |
| ... | @@ -365,7 +365,7 @@ pub const Builder = struct { | ... | @@ -365,7 +365,7 @@ pub const Builder = struct { |
| 365 | return &top_level_step.step; | 365 | return &top_level_step.step; |
| 366 | } | 366 | } |
| 367 | } | 367 | } |
| 368 | warn("Cannot run step '{}' because it does not exist\n", name); | 368 | warn("Cannot run step '{}' because it does not exist\n", .{name}); |
| 369 | return error.InvalidStepName; | 369 | return error.InvalidStepName; |
| 370 | } | 370 | } |
| 371 | 371 | ||
| ... | @@ -378,12 +378,12 @@ pub const Builder = struct { | ... | @@ -378,12 +378,12 @@ pub const Builder = struct { |
| 378 | const word = it.next() orelse break; | 378 | const word = it.next() orelse break; |
| 379 | if (mem.eql(u8, word, "-isystem")) { | 379 | if (mem.eql(u8, word, "-isystem")) { |
| 380 | const include_path = it.next() orelse { | 380 | const include_path = it.next() orelse { |
| 381 | warn("Expected argument after -isystem in NIX_CFLAGS_COMPILE\n"); | 381 | warn("Expected argument after -isystem in NIX_CFLAGS_COMPILE\n", .{}); |
| 382 | break; | 382 | break; |
| 383 | }; | 383 | }; |
| 384 | self.addNativeSystemIncludeDir(include_path); | 384 | self.addNativeSystemIncludeDir(include_path); |
| 385 | } else { | 385 | } else { |
| 386 | warn("Unrecognized C flag from NIX_CFLAGS_COMPILE: {}\n", word); | 386 | warn("Unrecognized C flag from NIX_CFLAGS_COMPILE: {}\n", .{word}); |
| 387 | break; | 387 | break; |
| 388 | } | 388 | } |
| 389 | } | 389 | } |
| ... | @@ -397,7 +397,7 @@ pub const Builder = struct { | ... | @@ -397,7 +397,7 @@ pub const Builder = struct { |
| 397 | const word = it.next() orelse break; | 397 | const word = it.next() orelse break; |
| 398 | if (mem.eql(u8, word, "-rpath")) { | 398 | if (mem.eql(u8, word, "-rpath")) { |
| 399 | const rpath = it.next() orelse { | 399 | const rpath = it.next() orelse { |
| 400 | warn("Expected argument after -rpath in NIX_LDFLAGS\n"); | 400 | warn("Expected argument after -rpath in NIX_LDFLAGS\n", .{}); |
| 401 | break; | 401 | break; |
| 402 | }; | 402 | }; |
| 403 | self.addNativeSystemRPath(rpath); | 403 | self.addNativeSystemRPath(rpath); |
| ... | @@ -405,7 +405,7 @@ pub const Builder = struct { | ... | @@ -405,7 +405,7 @@ pub const Builder = struct { |
| 405 | const lib_path = word[2..]; | 405 | const lib_path = word[2..]; |
| 406 | self.addNativeSystemLibPath(lib_path); | 406 | self.addNativeSystemLibPath(lib_path); |
| 407 | } else { | 407 | } else { |
| 408 | warn("Unrecognized C flag from NIX_LDFLAGS: {}\n", word); | 408 | warn("Unrecognized C flag from NIX_LDFLAGS: {}\n", .{word}); |
| 409 | break; | 409 | break; |
| 410 | } | 410 | } |
| 411 | } | 411 | } |
| ... | @@ -431,8 +431,8 @@ pub const Builder = struct { | ... | @@ -431,8 +431,8 @@ pub const Builder = struct { |
| 431 | self.addNativeSystemIncludeDir("/usr/local/include"); | 431 | self.addNativeSystemIncludeDir("/usr/local/include"); |
| 432 | self.addNativeSystemLibPath("/usr/local/lib"); | 432 | self.addNativeSystemLibPath("/usr/local/lib"); |
| 433 | 433 | ||
| 434 | self.addNativeSystemIncludeDir(self.fmt("/usr/include/{}", triple)); | 434 | self.addNativeSystemIncludeDir(self.fmt("/usr/include/{}", .{triple})); |
| 435 | self.addNativeSystemLibPath(self.fmt("/usr/lib/{}", triple)); | 435 | self.addNativeSystemLibPath(self.fmt("/usr/lib/{}", .{triple})); |
| 436 | 436 | ||
| 437 | self.addNativeSystemIncludeDir("/usr/include"); | 437 | self.addNativeSystemIncludeDir("/usr/include"); |
| 438 | self.addNativeSystemLibPath("/usr/lib"); | 438 | self.addNativeSystemLibPath("/usr/lib"); |
| ... | @@ -440,7 +440,7 @@ pub const Builder = struct { | ... | @@ -440,7 +440,7 @@ pub const Builder = struct { |
| 440 | // example: on a 64-bit debian-based linux distro, with zlib installed from apt: | 440 | // example: on a 64-bit debian-based linux distro, with zlib installed from apt: |
| 441 | // zlib.h is in /usr/include (added above) | 441 | // zlib.h is in /usr/include (added above) |
| 442 | // libz.so.1 is in /lib/x86_64-linux-gnu (added here) | 442 | // libz.so.1 is in /lib/x86_64-linux-gnu (added here) |
| 443 | self.addNativeSystemLibPath(self.fmt("/lib/{}", triple)); | 443 | self.addNativeSystemLibPath(self.fmt("/lib/{}", .{triple})); |
| 444 | }, | 444 | }, |
| 445 | } | 445 | } |
| 446 | } | 446 | } |
| ... | @@ -453,7 +453,7 @@ pub const Builder = struct { | ... | @@ -453,7 +453,7 @@ pub const Builder = struct { |
| 453 | .description = description, | 453 | .description = description, |
| 454 | }; | 454 | }; |
| 455 | if ((self.available_options_map.put(name, available_option) catch unreachable) != null) { | 455 | if ((self.available_options_map.put(name, available_option) catch unreachable) != null) { |
| 456 | panic("Option '{}' declared twice", name); | 456 | panic("Option '{}' declared twice", .{name}); |
| 457 | } | 457 | } |
| 458 | self.available_options_list.append(available_option) catch unreachable; | 458 | self.available_options_list.append(available_option) catch unreachable; |
| 459 | 459 | ||
| ... | @@ -468,33 +468,33 @@ pub const Builder = struct { | ... | @@ -468,33 +468,33 @@ pub const Builder = struct { |
| 468 | } else if (mem.eql(u8, s, "false")) { | 468 | } else if (mem.eql(u8, s, "false")) { |
| 469 | return false; | 469 | return false; |
| 470 | } else { | 470 | } else { |
| 471 | warn("Expected -D{} to be a boolean, but received '{}'\n", name, s); | 471 | warn("Expected -D{} to be a boolean, but received '{}'\n", .{ name, s }); |
| 472 | self.markInvalidUserInput(); | 472 | self.markInvalidUserInput(); |
| 473 | return null; | 473 | return null; |
| 474 | } | 474 | } |
| 475 | }, | 475 | }, |
| 476 | UserValue.List => { | 476 | UserValue.List => { |
| 477 | warn("Expected -D{} to be a boolean, but received a list.\n", name); | 477 | warn("Expected -D{} to be a boolean, but received a list.\n", .{name}); |
| 478 | self.markInvalidUserInput(); | 478 | self.markInvalidUserInput(); |
| 479 | return null; | 479 | return null; |
| 480 | }, | 480 | }, |
| 481 | }, | 481 | }, |
| 482 | TypeId.Int => panic("TODO integer options to build script"), | 482 | TypeId.Int => panic("TODO integer options to build script", .{}), |
| 483 | TypeId.Float => panic("TODO float options to build script"), | 483 | TypeId.Float => panic("TODO float options to build script", .{}), |
| 484 | TypeId.String => switch (entry.value.value) { | 484 | TypeId.String => switch (entry.value.value) { |
| 485 | UserValue.Flag => { | 485 | UserValue.Flag => { |
| 486 | warn("Expected -D{} to be a string, but received a boolean.\n", name); | 486 | warn("Expected -D{} to be a string, but received a boolean.\n", .{name}); |
| 487 | self.markInvalidUserInput(); | 487 | self.markInvalidUserInput(); |
| 488 | return null; | 488 | return null; |
| 489 | }, | 489 | }, |
| 490 | UserValue.List => { | 490 | UserValue.List => { |
| 491 | warn("Expected -D{} to be a string, but received a list.\n", name); | 491 | warn("Expected -D{} to be a string, but received a list.\n", .{name}); |
| 492 | self.markInvalidUserInput(); | 492 | self.markInvalidUserInput(); |
| 493 | return null; | 493 | return null; |
| 494 | }, | 494 | }, |
| 495 | UserValue.Scalar => |s| return s, | 495 | UserValue.Scalar => |s| return s, |
| 496 | }, | 496 | }, |
| 497 | TypeId.List => panic("TODO list options to build script"), | 497 | TypeId.List => panic("TODO list options to build script", .{}), |
| 498 | } | 498 | } |
| 499 | } | 499 | } |
| 500 | 500 | ||
| ... | @@ -513,7 +513,7 @@ pub const Builder = struct { | ... | @@ -513,7 +513,7 @@ pub const Builder = struct { |
| 513 | if (self.release_mode != null) { | 513 | if (self.release_mode != null) { |
| 514 | @panic("setPreferredReleaseMode must be called before standardReleaseOptions and may not be called twice"); | 514 | @panic("setPreferredReleaseMode must be called before standardReleaseOptions and may not be called twice"); |
| 515 | } | 515 | } |
| 516 | const description = self.fmt("create a release build ({})", @tagName(mode)); | 516 | const description = self.fmt("create a release build ({})", .{@tagName(mode)}); |
| 517 | self.is_release = self.option(bool, "release", description) orelse false; | 517 | self.is_release = self.option(bool, "release", description) orelse false; |
| 518 | self.release_mode = if (self.is_release) mode else builtin.Mode.Debug; | 518 | self.release_mode = if (self.is_release) mode else builtin.Mode.Debug; |
| 519 | } | 519 | } |
| ... | @@ -536,7 +536,7 @@ pub const Builder = struct { | ... | @@ -536,7 +536,7 @@ pub const Builder = struct { |
| 536 | else if (!release_fast and !release_safe and !release_small) | 536 | else if (!release_fast and !release_safe and !release_small) |
| 537 | builtin.Mode.Debug | 537 | builtin.Mode.Debug |
| 538 | else x: { | 538 | else x: { |
| 539 | warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)"); | 539 | warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)", .{}); |
| 540 | self.markInvalidUserInput(); | 540 | self.markInvalidUserInput(); |
| 541 | break :x builtin.Mode.Debug; | 541 | break :x builtin.Mode.Debug; |
| 542 | }; | 542 | }; |
| ... | @@ -599,7 +599,7 @@ pub const Builder = struct { | ... | @@ -599,7 +599,7 @@ pub const Builder = struct { |
| 599 | }) catch unreachable; | 599 | }) catch unreachable; |
| 600 | }, | 600 | }, |
| 601 | UserValue.Flag => { | 601 | UserValue.Flag => { |
| 602 | warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", name, value, name); | 602 | warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", .{ name, value, name }); |
| 603 | return true; | 603 | return true; |
| 604 | }, | 604 | }, |
| 605 | } | 605 | } |
| ... | @@ -620,11 +620,11 @@ pub const Builder = struct { | ... | @@ -620,11 +620,11 @@ pub const Builder = struct { |
| 620 | // option already exists | 620 | // option already exists |
| 621 | switch (gop.kv.value.value) { | 621 | switch (gop.kv.value.value) { |
| 622 | UserValue.Scalar => |s| { | 622 | UserValue.Scalar => |s| { |
| 623 | warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", name, name, s); | 623 | warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", .{ name, name, s }); |
| 624 | return true; | 624 | return true; |
| 625 | }, | 625 | }, |
| 626 | UserValue.List => { | 626 | UserValue.List => { |
| 627 | warn("Flag '-D{}' conflicts with multiple options of the same name.\n", name); | 627 | warn("Flag '-D{}' conflicts with multiple options of the same name.\n", .{name}); |
| 628 | return true; | 628 | return true; |
| 629 | }, | 629 | }, |
| 630 | UserValue.Flag => {}, | 630 | UserValue.Flag => {}, |
| ... | @@ -665,7 +665,7 @@ pub const Builder = struct { | ... | @@ -665,7 +665,7 @@ pub const Builder = struct { |
| 665 | while (true) { | 665 | while (true) { |
| 666 | const entry = it.next() orelse break; | 666 | const entry = it.next() orelse break; |
| 667 | if (!entry.value.used) { | 667 | if (!entry.value.used) { |
| 668 | warn("Invalid option: -D{}\n\n", entry.key); | 668 | warn("Invalid option: -D{}\n\n", .{entry.key}); |
| 669 | self.markInvalidUserInput(); | 669 | self.markInvalidUserInput(); |
| 670 | } | 670 | } |
| 671 | } | 671 | } |
| ... | @@ -678,11 +678,11 @@ pub const Builder = struct { | ... | @@ -678,11 +678,11 @@ pub const Builder = struct { |
| 678 | } | 678 | } |
| 679 | 679 | ||
| 680 | fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void { | 680 | fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void { |
| 681 | if (cwd) |yes_cwd| warn("cd {} && ", yes_cwd); | 681 | if (cwd) |yes_cwd| warn("cd {} && ", .{yes_cwd}); |
| 682 | for (argv) |arg| { | 682 | for (argv) |arg| { |
| 683 | warn("{} ", arg); | 683 | warn("{} ", .{arg}); |
| 684 | } | 684 | } |
| 685 | warn("\n"); | 685 | warn("\n", .{}); |
| 686 | } | 686 | } |
| 687 | 687 | ||
| 688 | fn spawnChildEnvMap(self: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) !void { | 688 | fn spawnChildEnvMap(self: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) !void { |
| ... | @@ -697,20 +697,20 @@ pub const Builder = struct { | ... | @@ -697,20 +697,20 @@ pub const Builder = struct { |
| 697 | child.env_map = env_map; | 697 | child.env_map = env_map; |
| 698 | 698 | ||
| 699 | const term = child.spawnAndWait() catch |err| { | 699 | const term = child.spawnAndWait() catch |err| { |
| 700 | warn("Unable to spawn {}: {}\n", argv[0], @errorName(err)); | 700 | warn("Unable to spawn {}: {}\n", .{ argv[0], @errorName(err) }); |
| 701 | return err; | 701 | return err; |
| 702 | }; | 702 | }; |
| 703 | 703 | ||
| 704 | switch (term) { | 704 | switch (term) { |
| 705 | .Exited => |code| { | 705 | .Exited => |code| { |
| 706 | if (code != 0) { | 706 | if (code != 0) { |
| 707 | warn("The following command exited with error code {}:\n", code); | 707 | warn("The following command exited with error code {}:\n", .{code}); |
| 708 | printCmd(cwd, argv); | 708 | printCmd(cwd, argv); |
| 709 | return error.UncleanExit; | 709 | return error.UncleanExit; |
| 710 | } | 710 | } |
| 711 | }, | 711 | }, |
| 712 | else => { | 712 | else => { |
| 713 | warn("The following command terminated unexpectedly:\n"); | 713 | warn("The following command terminated unexpectedly:\n", .{}); |
| 714 | printCmd(cwd, argv); | 714 | printCmd(cwd, argv); |
| 715 | 715 | ||
| 716 | return error.UncleanExit; | 716 | return error.UncleanExit; |
| ... | @@ -720,7 +720,7 @@ pub const Builder = struct { | ... | @@ -720,7 +720,7 @@ pub const Builder = struct { |
| 720 | 720 | ||
| 721 | pub fn makePath(self: *Builder, path: []const u8) !void { | 721 | pub fn makePath(self: *Builder, path: []const u8) !void { |
| 722 | fs.makePath(self.allocator, self.pathFromRoot(path)) catch |err| { | 722 | fs.makePath(self.allocator, self.pathFromRoot(path)) catch |err| { |
| 723 | warn("Unable to create path {}: {}\n", path, @errorName(err)); | 723 | warn("Unable to create path {}: {}\n", .{ path, @errorName(err) }); |
| 724 | return err; | 724 | return err; |
| 725 | }; | 725 | }; |
| 726 | } | 726 | } |
| ... | @@ -793,12 +793,12 @@ pub const Builder = struct { | ... | @@ -793,12 +793,12 @@ pub const Builder = struct { |
| 793 | 793 | ||
| 794 | fn updateFile(self: *Builder, source_path: []const u8, dest_path: []const u8) !void { | 794 | fn updateFile(self: *Builder, source_path: []const u8, dest_path: []const u8) !void { |
| 795 | if (self.verbose) { | 795 | if (self.verbose) { |
| 796 | warn("cp {} {} ", source_path, dest_path); | 796 | warn("cp {} {} ", .{ source_path, dest_path }); |
| 797 | } | 797 | } |
| 798 | const prev_status = try fs.updateFile(source_path, dest_path); | 798 | const prev_status = try fs.updateFile(source_path, dest_path); |
| 799 | if (self.verbose) switch (prev_status) { | 799 | if (self.verbose) switch (prev_status) { |
| 800 | .stale => warn("# installed\n"), | 800 | .stale => warn("# installed\n", .{}), |
| 801 | .fresh => warn("# up-to-date\n"), | 801 | .fresh => warn("# up-to-date\n", .{}), |
| 802 | }; | 802 | }; |
| 803 | } | 803 | } |
| 804 | 804 | ||
| ... | @@ -806,7 +806,7 @@ pub const Builder = struct { | ... | @@ -806,7 +806,7 @@ pub const Builder = struct { |
| 806 | return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable; | 806 | return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable; |
| 807 | } | 807 | } |
| 808 | 808 | ||
| 809 | pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 { | 809 | pub fn fmt(self: *Builder, comptime format: []const u8, args: var) []u8 { |
| 810 | return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable; | 810 | return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable; |
| 811 | } | 811 | } |
| 812 | 812 | ||
| ... | @@ -818,7 +818,11 @@ pub const Builder = struct { | ... | @@ -818,7 +818,11 @@ pub const Builder = struct { |
| 818 | if (fs.path.isAbsolute(name)) { | 818 | if (fs.path.isAbsolute(name)) { |
| 819 | return name; | 819 | return name; |
| 820 | } | 820 | } |
| 821 | const full_path = try fs.path.join(self.allocator, &[_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) }); | 821 | const full_path = try fs.path.join(self.allocator, &[_][]const u8{ |
| 822 | search_prefix, | ||
| 823 | "bin", | ||
| 824 | self.fmt("{}{}", .{ name, exe_extension }), | ||
| 825 | }); | ||
| 822 | return fs.realpathAlloc(self.allocator, full_path) catch continue; | 826 | return fs.realpathAlloc(self.allocator, full_path) catch continue; |
| 823 | } | 827 | } |
| 824 | } | 828 | } |
| ... | @@ -829,7 +833,10 @@ pub const Builder = struct { | ... | @@ -829,7 +833,10 @@ pub const Builder = struct { |
| 829 | } | 833 | } |
| 830 | var it = mem.tokenize(PATH, &[_]u8{fs.path.delimiter}); | 834 | var it = mem.tokenize(PATH, &[_]u8{fs.path.delimiter}); |
| 831 | while (it.next()) |path| { | 835 | while (it.next()) |path| { |
| 832 | const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) }); | 836 | const full_path = try fs.path.join(self.allocator, &[_][]const u8{ |
| 837 | path, | ||
| 838 | self.fmt("{}{}", .{ name, exe_extension }), | ||
| 839 | }); | ||
| 833 | return fs.realpathAlloc(self.allocator, full_path) catch continue; | 840 | return fs.realpathAlloc(self.allocator, full_path) catch continue; |
| 834 | } | 841 | } |
| 835 | } | 842 | } |
| ... | @@ -839,7 +846,10 @@ pub const Builder = struct { | ... | @@ -839,7 +846,10 @@ pub const Builder = struct { |
| 839 | return name; | 846 | return name; |
| 840 | } | 847 | } |
| 841 | for (paths) |path| { | 848 | for (paths) |path| { |
| 842 | const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) }); | 849 | const full_path = try fs.path.join(self.allocator, &[_][]const u8{ |
| 850 | path, | ||
| 851 | self.fmt("{}{}", .{ name, exe_extension }), | ||
| 852 | }); | ||
| 843 | return fs.realpathAlloc(self.allocator, full_path) catch continue; | 853 | return fs.realpathAlloc(self.allocator, full_path) catch continue; |
| 844 | } | 854 | } |
| 845 | } | 855 | } |
| ... | @@ -896,17 +906,17 @@ pub const Builder = struct { | ... | @@ -896,17 +906,17 @@ pub const Builder = struct { |
| 896 | var code: u8 = undefined; | 906 | var code: u8 = undefined; |
| 897 | return self.execAllowFail(argv, &code, .Inherit) catch |err| switch (err) { | 907 | return self.execAllowFail(argv, &code, .Inherit) catch |err| switch (err) { |
| 898 | error.FileNotFound => { | 908 | error.FileNotFound => { |
| 899 | warn("Unable to spawn the following command: file not found\n"); | 909 | warn("Unable to spawn the following command: file not found\n", .{}); |
| 900 | printCmd(null, argv); | 910 | printCmd(null, argv); |
| 901 | std.os.exit(@truncate(u8, code)); | 911 | std.os.exit(@truncate(u8, code)); |
| 902 | }, | 912 | }, |
| 903 | error.ExitCodeFailure => { | 913 | error.ExitCodeFailure => { |
| 904 | warn("The following command exited with error code {}:\n", code); | 914 | warn("The following command exited with error code {}:\n", .{code}); |
| 905 | printCmd(null, argv); | 915 | printCmd(null, argv); |
| 906 | std.os.exit(@truncate(u8, code)); | 916 | std.os.exit(@truncate(u8, code)); |
| 907 | }, | 917 | }, |
| 908 | error.ProcessTerminated => { | 918 | error.ProcessTerminated => { |
| 909 | warn("The following command terminated unexpectedly:\n"); | 919 | warn("The following command terminated unexpectedly:\n", .{}); |
| 910 | printCmd(null, argv); | 920 | printCmd(null, argv); |
| 911 | std.os.exit(@truncate(u8, code)); | 921 | std.os.exit(@truncate(u8, code)); |
| 912 | }, | 922 | }, |
| ... | @@ -1133,7 +1143,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1133,7 +1143,7 @@ pub const LibExeObjStep = struct { |
| 1133 | 1143 | ||
| 1134 | fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, is_dynamic: bool, ver: Version) LibExeObjStep { | 1144 | fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, is_dynamic: bool, ver: Version) LibExeObjStep { |
| 1135 | if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) { | 1145 | if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) { |
| 1136 | panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", name); | 1146 | panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", .{name}); |
| 1137 | } | 1147 | } |
| 1138 | var self = LibExeObjStep{ | 1148 | var self = LibExeObjStep{ |
| 1139 | .strip = false, | 1149 | .strip = false, |
| ... | @@ -1150,9 +1160,9 @@ pub const LibExeObjStep = struct { | ... | @@ -1150,9 +1160,9 @@ pub const LibExeObjStep = struct { |
| 1150 | .step = Step.init(name, builder.allocator, make), | 1160 | .step = Step.init(name, builder.allocator, make), |
| 1151 | .version = ver, | 1161 | .version = ver, |
| 1152 | .out_filename = undefined, | 1162 | .out_filename = undefined, |
| 1153 | .out_h_filename = builder.fmt("{}.h", name), | 1163 | .out_h_filename = builder.fmt("{}.h", .{name}), |
| 1154 | .out_lib_filename = undefined, | 1164 | .out_lib_filename = undefined, |
| 1155 | .out_pdb_filename = builder.fmt("{}.pdb", name), | 1165 | .out_pdb_filename = builder.fmt("{}.pdb", .{name}), |
| 1156 | .major_only_filename = undefined, | 1166 | .major_only_filename = undefined, |
| 1157 | .name_only_filename = undefined, | 1167 | .name_only_filename = undefined, |
| 1158 | .packages = ArrayList(Pkg).init(builder.allocator), | 1168 | .packages = ArrayList(Pkg).init(builder.allocator), |
| ... | @@ -1186,36 +1196,48 @@ pub const LibExeObjStep = struct { | ... | @@ -1186,36 +1196,48 @@ pub const LibExeObjStep = struct { |
| 1186 | fn computeOutFileNames(self: *LibExeObjStep) void { | 1196 | fn computeOutFileNames(self: *LibExeObjStep) void { |
| 1187 | switch (self.kind) { | 1197 | switch (self.kind) { |
| 1188 | .Obj => { | 1198 | .Obj => { |
| 1189 | self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt()); | 1199 | self.out_filename = self.builder.fmt("{}{}", .{ self.name, self.target.oFileExt() }); |
| 1190 | }, | 1200 | }, |
| 1191 | .Exe => { | 1201 | .Exe => { |
| 1192 | self.out_filename = self.builder.fmt("{}{}", self.name, self.target.exeFileExt()); | 1202 | self.out_filename = self.builder.fmt("{}{}", .{ self.name, self.target.exeFileExt() }); |
| 1193 | }, | 1203 | }, |
| 1194 | .Test => { | 1204 | .Test => { |
| 1195 | self.out_filename = self.builder.fmt("test{}", self.target.exeFileExt()); | 1205 | self.out_filename = self.builder.fmt("test{}", .{self.target.exeFileExt()}); |
| 1196 | }, | 1206 | }, |
| 1197 | .Lib => { | 1207 | .Lib => { |
| 1198 | if (!self.is_dynamic) { | 1208 | if (!self.is_dynamic) { |
| 1199 | self.out_filename = self.builder.fmt( | 1209 | self.out_filename = self.builder.fmt("{}{}{}", .{ |
| 1200 | "{}{}{}", | ||
| 1201 | self.target.libPrefix(), | 1210 | self.target.libPrefix(), |
| 1202 | self.name, | 1211 | self.name, |
| 1203 | self.target.staticLibSuffix(), | 1212 | self.target.staticLibSuffix(), |
| 1204 | ); | 1213 | }); |
| 1205 | self.out_lib_filename = self.out_filename; | 1214 | self.out_lib_filename = self.out_filename; |
| 1206 | } else { | 1215 | } else { |
| 1207 | if (self.target.isDarwin()) { | 1216 | if (self.target.isDarwin()) { |
| 1208 | self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", self.name, self.version.major, self.version.minor, self.version.patch); | 1217 | self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", .{ |
| 1209 | self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", self.name, self.version.major); | 1218 | self.name, |
| 1210 | self.name_only_filename = self.builder.fmt("lib{}.dylib", self.name); | 1219 | self.version.major, |
| 1220 | self.version.minor, | ||
| 1221 | self.version.patch, | ||
| 1222 | }); | ||
| 1223 | self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", .{ | ||
| 1224 | self.name, | ||
| 1225 | self.version.major, | ||
| 1226 | }); | ||
| 1227 | self.name_only_filename = self.builder.fmt("lib{}.dylib", .{self.name}); | ||
| 1211 | self.out_lib_filename = self.out_filename; | 1228 | self.out_lib_filename = self.out_filename; |
| 1212 | } else if (self.target.isWindows()) { | 1229 | } else if (self.target.isWindows()) { |
| 1213 | self.out_filename = self.builder.fmt("{}.dll", self.name); | 1230 | self.out_filename = self.builder.fmt("{}.dll", .{self.name}); |
| 1214 | self.out_lib_filename = self.builder.fmt("{}.lib", self.name); | 1231 | self.out_lib_filename = self.builder.fmt("{}.lib", .{self.name}); |
| 1215 | } else { | 1232 | } else { |
| 1216 | self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", self.name, self.version.major, self.version.minor, self.version.patch); | 1233 | self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", .{ |
| 1217 | self.major_only_filename = self.builder.fmt("lib{}.so.{d}", self.name, self.version.major); | 1234 | self.name, |
| 1218 | self.name_only_filename = self.builder.fmt("lib{}.so", self.name); | 1235 | self.version.major, |
| 1236 | self.version.minor, | ||
| 1237 | self.version.patch, | ||
| 1238 | }); | ||
| 1239 | self.major_only_filename = self.builder.fmt("lib{}.so.{d}", .{ self.name, self.version.major }); | ||
| 1240 | self.name_only_filename = self.builder.fmt("lib{}.so", .{self.name}); | ||
| 1219 | self.out_lib_filename = self.out_filename; | 1241 | self.out_lib_filename = self.out_filename; |
| 1220 | } | 1242 | } |
| 1221 | } | 1243 | } |
| ... | @@ -1268,7 +1290,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1268,7 +1290,7 @@ pub const LibExeObjStep = struct { |
| 1268 | // It doesn't have to be native. We catch that if you actually try to run it. | 1290 | // It doesn't have to be native. We catch that if you actually try to run it. |
| 1269 | // Consider that this is declarative; the run step may not be run unless a user | 1291 | // Consider that this is declarative; the run step may not be run unless a user |
| 1270 | // option is supplied. | 1292 | // option is supplied. |
| 1271 | const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", exe.step.name)); | 1293 | const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", .{exe.step.name})); |
| 1272 | run_step.addArtifactArg(exe); | 1294 | run_step.addArtifactArg(exe); |
| 1273 | 1295 | ||
| 1274 | if (exe.vcpkg_bin_path) |path| { | 1296 | if (exe.vcpkg_bin_path) |path| { |
| ... | @@ -1420,7 +1442,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1420,7 +1442,7 @@ pub const LibExeObjStep = struct { |
| 1420 | } else if (mem.eql(u8, tok, "-pthread")) { | 1442 | } else if (mem.eql(u8, tok, "-pthread")) { |
| 1421 | self.linkLibC(); | 1443 | self.linkLibC(); |
| 1422 | } else if (self.builder.verbose) { | 1444 | } else if (self.builder.verbose) { |
| 1423 | warn("Ignoring pkg-config flag '{}'\n", tok); | 1445 | warn("Ignoring pkg-config flag '{}'\n", .{tok}); |
| 1424 | } | 1446 | } |
| 1425 | } | 1447 | } |
| 1426 | } | 1448 | } |
| ... | @@ -1653,7 +1675,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1653,7 +1675,7 @@ pub const LibExeObjStep = struct { |
| 1653 | const builder = self.builder; | 1675 | const builder = self.builder; |
| 1654 | 1676 | ||
| 1655 | if (self.root_src == null and self.link_objects.len == 0) { | 1677 | if (self.root_src == null and self.link_objects.len == 0) { |
| 1656 | warn("{}: linker needs 1 or more objects to link\n", self.step.name); | 1678 | warn("{}: linker needs 1 or more objects to link\n", .{self.step.name}); |
| 1657 | return error.NeedAnObject; | 1679 | return error.NeedAnObject; |
| 1658 | } | 1680 | } |
| 1659 | 1681 | ||
| ... | @@ -1725,7 +1747,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1725,7 +1747,7 @@ pub const LibExeObjStep = struct { |
| 1725 | if (self.build_options_contents.len() > 0) { | 1747 | if (self.build_options_contents.len() > 0) { |
| 1726 | const build_options_file = try fs.path.join( | 1748 | const build_options_file = try fs.path.join( |
| 1727 | builder.allocator, | 1749 | builder.allocator, |
| 1728 | &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) }, | 1750 | &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", .{self.name}) }, |
| 1729 | ); | 1751 | ); |
| 1730 | try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst()); | 1752 | try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst()); |
| 1731 | try zig_args.append("--pkg-begin"); | 1753 | try zig_args.append("--pkg-begin"); |
| ... | @@ -1780,13 +1802,13 @@ pub const LibExeObjStep = struct { | ... | @@ -1780,13 +1802,13 @@ pub const LibExeObjStep = struct { |
| 1780 | 1802 | ||
| 1781 | if (self.kind == Kind.Lib and self.is_dynamic) { | 1803 | if (self.kind == Kind.Lib and self.is_dynamic) { |
| 1782 | zig_args.append("--ver-major") catch unreachable; | 1804 | zig_args.append("--ver-major") catch unreachable; |
| 1783 | zig_args.append(builder.fmt("{}", self.version.major)) catch unreachable; | 1805 | zig_args.append(builder.fmt("{}", .{self.version.major})) catch unreachable; |
| 1784 | 1806 | ||
| 1785 | zig_args.append("--ver-minor") catch unreachable; | 1807 | zig_args.append("--ver-minor") catch unreachable; |
| 1786 | zig_args.append(builder.fmt("{}", self.version.minor)) catch unreachable; | 1808 | zig_args.append(builder.fmt("{}", .{self.version.minor})) catch unreachable; |
| 1787 | 1809 | ||
| 1788 | zig_args.append("--ver-patch") catch unreachable; | 1810 | zig_args.append("--ver-patch") catch unreachable; |
| 1789 | zig_args.append(builder.fmt("{}", self.version.patch)) catch unreachable; | 1811 | zig_args.append(builder.fmt("{}", .{self.version.patch})) catch unreachable; |
| 1790 | } | 1812 | } |
| 1791 | if (self.is_dynamic) { | 1813 | if (self.is_dynamic) { |
| 1792 | try zig_args.append("-dynamic"); | 1814 | try zig_args.append("-dynamic"); |
| ... | @@ -1811,7 +1833,7 @@ pub const LibExeObjStep = struct { | ... | @@ -1811,7 +1833,7 @@ pub const LibExeObjStep = struct { |
| 1811 | 1833 | ||
| 1812 | if (self.target_glibc) |ver| { | 1834 | if (self.target_glibc) |ver| { |
| 1813 | try zig_args.append("-target-glibc"); | 1835 | try zig_args.append("-target-glibc"); |
| 1814 | try zig_args.append(builder.fmt("{}.{}.{}", ver.major, ver.minor, ver.patch)); | 1836 | try zig_args.append(builder.fmt("{}.{}.{}", .{ ver.major, ver.minor, ver.patch })); |
| 1815 | } | 1837 | } |
| 1816 | 1838 | ||
| 1817 | if (self.linker_script) |linker_script| { | 1839 | if (self.linker_script) |linker_script| { |
| ... | @@ -2079,7 +2101,7 @@ pub const RunStep = struct { | ... | @@ -2079,7 +2101,7 @@ pub const RunStep = struct { |
| 2079 | } | 2101 | } |
| 2080 | 2102 | ||
| 2081 | if (prev_path) |pp| { | 2103 | if (prev_path) |pp| { |
| 2082 | const new_path = self.builder.fmt("{}" ++ [1]u8{fs.path.delimiter} ++ "{}", pp, search_path); | 2104 | const new_path = self.builder.fmt("{}" ++ [1]u8{fs.path.delimiter} ++ "{}", .{ pp, search_path }); |
| 2083 | env_map.set(key, new_path) catch unreachable; | 2105 | env_map.set(key, new_path) catch unreachable; |
| 2084 | } else { | 2106 | } else { |
| 2085 | env_map.set(key, search_path) catch unreachable; | 2107 | env_map.set(key, search_path) catch unreachable; |
| ... | @@ -2153,7 +2175,7 @@ const InstallArtifactStep = struct { | ... | @@ -2153,7 +2175,7 @@ const InstallArtifactStep = struct { |
| 2153 | const self = builder.allocator.create(Self) catch unreachable; | 2175 | const self = builder.allocator.create(Self) catch unreachable; |
| 2154 | self.* = Self{ | 2176 | self.* = Self{ |
| 2155 | .builder = builder, | 2177 | .builder = builder, |
| 2156 | .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make), | 2178 | .step = Step.init(builder.fmt("install {}", .{artifact.step.name}), builder.allocator, make), |
| 2157 | .artifact = artifact, | 2179 | .artifact = artifact, |
| 2158 | .dest_dir = switch (artifact.kind) { | 2180 | .dest_dir = switch (artifact.kind) { |
| 2159 | .Obj => unreachable, | 2181 | .Obj => unreachable, |
| ... | @@ -2219,7 +2241,7 @@ pub const InstallFileStep = struct { | ... | @@ -2219,7 +2241,7 @@ pub const InstallFileStep = struct { |
| 2219 | builder.pushInstalledFile(dir, dest_rel_path); | 2241 | builder.pushInstalledFile(dir, dest_rel_path); |
| 2220 | return InstallFileStep{ | 2242 | return InstallFileStep{ |
| 2221 | .builder = builder, | 2243 | .builder = builder, |
| 2222 | .step = Step.init(builder.fmt("install {}", src_path), builder.allocator, make), | 2244 | .step = Step.init(builder.fmt("install {}", .{src_path}), builder.allocator, make), |
| 2223 | .src_path = src_path, | 2245 | .src_path = src_path, |
| 2224 | .dir = dir, | 2246 | .dir = dir, |
| 2225 | .dest_rel_path = dest_rel_path, | 2247 | .dest_rel_path = dest_rel_path, |
| ... | @@ -2253,7 +2275,7 @@ pub const InstallDirStep = struct { | ... | @@ -2253,7 +2275,7 @@ pub const InstallDirStep = struct { |
| 2253 | builder.pushInstalledFile(options.install_dir, options.install_subdir); | 2275 | builder.pushInstalledFile(options.install_dir, options.install_subdir); |
| 2254 | return InstallDirStep{ | 2276 | return InstallDirStep{ |
| 2255 | .builder = builder, | 2277 | .builder = builder, |
| 2256 | .step = Step.init(builder.fmt("install {}/", options.source_dir), builder.allocator, make), | 2278 | .step = Step.init(builder.fmt("install {}/", .{options.source_dir}), builder.allocator, make), |
| 2257 | .options = options, | 2279 | .options = options, |
| 2258 | }; | 2280 | }; |
| 2259 | } | 2281 | } |
| ... | @@ -2290,7 +2312,7 @@ pub const WriteFileStep = struct { | ... | @@ -2290,7 +2312,7 @@ pub const WriteFileStep = struct { |
| 2290 | pub fn init(builder: *Builder, file_path: []const u8, data: []const u8) WriteFileStep { | 2312 | pub fn init(builder: *Builder, file_path: []const u8, data: []const u8) WriteFileStep { |
| 2291 | return WriteFileStep{ | 2313 | return WriteFileStep{ |
| 2292 | .builder = builder, | 2314 | .builder = builder, |
| 2293 | .step = Step.init(builder.fmt("writefile {}", file_path), builder.allocator, make), | 2315 | .step = Step.init(builder.fmt("writefile {}", .{file_path}), builder.allocator, make), |
| 2294 | .file_path = file_path, | 2316 | .file_path = file_path, |
| 2295 | .data = data, | 2317 | .data = data, |
| 2296 | }; | 2318 | }; |
| ... | @@ -2301,11 +2323,11 @@ pub const WriteFileStep = struct { | ... | @@ -2301,11 +2323,11 @@ pub const WriteFileStep = struct { |
| 2301 | const full_path = self.builder.pathFromRoot(self.file_path); | 2323 | const full_path = self.builder.pathFromRoot(self.file_path); |
| 2302 | const full_path_dir = fs.path.dirname(full_path) orelse "."; | 2324 | const full_path_dir = fs.path.dirname(full_path) orelse "."; |
| 2303 | fs.makePath(self.builder.allocator, full_path_dir) catch |err| { | 2325 | fs.makePath(self.builder.allocator, full_path_dir) catch |err| { |
| 2304 | warn("unable to make path {}: {}\n", full_path_dir, @errorName(err)); | 2326 | warn("unable to make path {}: {}\n", .{ full_path_dir, @errorName(err) }); |
| 2305 | return err; | 2327 | return err; |
| 2306 | }; | 2328 | }; |
| 2307 | io.writeFile(full_path, self.data) catch |err| { | 2329 | io.writeFile(full_path, self.data) catch |err| { |
| 2308 | warn("unable to write {}: {}\n", full_path, @errorName(err)); | 2330 | warn("unable to write {}: {}\n", .{ full_path, @errorName(err) }); |
| 2309 | return err; | 2331 | return err; |
| 2310 | }; | 2332 | }; |
| 2311 | } | 2333 | } |
| ... | @@ -2319,14 +2341,14 @@ pub const LogStep = struct { | ... | @@ -2319,14 +2341,14 @@ pub const LogStep = struct { |
| 2319 | pub fn init(builder: *Builder, data: []const u8) LogStep { | 2341 | pub fn init(builder: *Builder, data: []const u8) LogStep { |
| 2320 | return LogStep{ | 2342 | return LogStep{ |
| 2321 | .builder = builder, | 2343 | .builder = builder, |
| 2322 | .step = Step.init(builder.fmt("log {}", data), builder.allocator, make), | 2344 | .step = Step.init(builder.fmt("log {}", .{data}), builder.allocator, make), |
| 2323 | .data = data, | 2345 | .data = data, |
| 2324 | }; | 2346 | }; |
| 2325 | } | 2347 | } |
| 2326 | 2348 | ||
| 2327 | fn make(step: *Step) anyerror!void { | 2349 | fn make(step: *Step) anyerror!void { |
| 2328 | const self = @fieldParentPtr(LogStep, "step", step); | 2350 | const self = @fieldParentPtr(LogStep, "step", step); |
| 2329 | warn("{}", self.data); | 2351 | warn("{}", .{self.data}); |
| 2330 | } | 2352 | } |
| 2331 | }; | 2353 | }; |
| 2332 | 2354 | ||
| ... | @@ -2338,7 +2360,7 @@ pub const RemoveDirStep = struct { | ... | @@ -2338,7 +2360,7 @@ pub const RemoveDirStep = struct { |
| 2338 | pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep { | 2360 | pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep { |
| 2339 | return RemoveDirStep{ | 2361 | return RemoveDirStep{ |
| 2340 | .builder = builder, | 2362 | .builder = builder, |
| 2341 | .step = Step.init(builder.fmt("RemoveDir {}", dir_path), builder.allocator, make), | 2363 | .step = Step.init(builder.fmt("RemoveDir {}", .{dir_path}), builder.allocator, make), |
| 2342 | .dir_path = dir_path, | 2364 | .dir_path = dir_path, |
| 2343 | }; | 2365 | }; |
| 2344 | } | 2366 | } |
| ... | @@ -2348,7 +2370,7 @@ pub const RemoveDirStep = struct { | ... | @@ -2348,7 +2370,7 @@ pub const RemoveDirStep = struct { |
| 2348 | 2370 | ||
| 2349 | const full_path = self.builder.pathFromRoot(self.dir_path); | 2371 | const full_path = self.builder.pathFromRoot(self.dir_path); |
| 2350 | fs.deleteTree(full_path) catch |err| { | 2372 | fs.deleteTree(full_path) catch |err| { |
| 2351 | warn("Unable to remove {}: {}\n", full_path, @errorName(err)); | 2373 | warn("Unable to remove {}: {}\n", .{ full_path, @errorName(err) }); |
| 2352 | return err; | 2374 | return err; |
| 2353 | }; | 2375 | }; |
| 2354 | } | 2376 | } |
| ... | @@ -2397,7 +2419,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj | ... | @@ -2397,7 +2419,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj |
| 2397 | &[_][]const u8{ out_dir, filename_major_only }, | 2419 | &[_][]const u8{ out_dir, filename_major_only }, |
| 2398 | ) catch unreachable; | 2420 | ) catch unreachable; |
| 2399 | fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| { | 2421 | fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| { |
| 2400 | warn("Unable to symlink {} -> {}\n", major_only_path, out_basename); | 2422 | warn("Unable to symlink {} -> {}\n", .{ major_only_path, out_basename }); |
| 2401 | return err; | 2423 | return err; |
| 2402 | }; | 2424 | }; |
| 2403 | // sym link for libfoo.so to libfoo.so.1 | 2425 | // sym link for libfoo.so to libfoo.so.1 |
| ... | @@ -2406,7 +2428,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj | ... | @@ -2406,7 +2428,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj |
| 2406 | &[_][]const u8{ out_dir, filename_name_only }, | 2428 | &[_][]const u8{ out_dir, filename_name_only }, |
| 2407 | ) catch unreachable; | 2429 | ) catch unreachable; |
| 2408 | fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| { | 2430 | fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| { |
| 2409 | warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only); | 2431 | warn("Unable to symlink {} -> {}\n", .{ name_only_path, filename_major_only }); |
| 2410 | return err; | 2432 | return err; |
| 2411 | }; | 2433 | }; |
| 2412 | } | 2434 | } |
lib/std/builtin.zig+2-2| ... | @@ -429,7 +429,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn | ... | @@ -429,7 +429,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn |
| 429 | } | 429 | } |
| 430 | }, | 430 | }, |
| 431 | .wasi => { | 431 | .wasi => { |
| 432 | std.debug.warn("{}", msg); | 432 | std.debug.warn("{}", .{msg}); |
| 433 | _ = std.os.wasi.proc_raise(std.os.wasi.SIGABRT); | 433 | _ = std.os.wasi.proc_raise(std.os.wasi.SIGABRT); |
| 434 | unreachable; | 434 | unreachable; |
| 435 | }, | 435 | }, |
| ... | @@ -439,7 +439,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn | ... | @@ -439,7 +439,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn |
| 439 | }, | 439 | }, |
| 440 | else => { | 440 | else => { |
| 441 | const first_trace_addr = @returnAddress(); | 441 | const first_trace_addr = @returnAddress(); |
| 442 | std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", msg); | 442 | std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", .{msg}); |
| 443 | }, | 443 | }, |
| 444 | } | 444 | } |
| 445 | } | 445 | } |
lib/std/crypto/benchmark.zig+1-1| ... | @@ -114,7 +114,7 @@ fn usage() void { | ... | @@ -114,7 +114,7 @@ fn usage() void { |
| 114 | \\ --seed [int] | 114 | \\ --seed [int] |
| 115 | \\ --help | 115 | \\ --help |
| 116 | \\ | 116 | \\ |
| 117 | ); | 117 | , .{}); |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | fn mode(comptime x: comptime_int) comptime_int { | 120 | fn mode(comptime x: comptime_int) comptime_int { |
lib/std/debug.zig+52-39| ... | @@ -46,7 +46,7 @@ var stderr_file_out_stream: File.OutStream = undefined; | ... | @@ -46,7 +46,7 @@ var stderr_file_out_stream: File.OutStream = undefined; |
| 46 | var stderr_stream: ?*io.OutStream(File.WriteError) = null; | 46 | var stderr_stream: ?*io.OutStream(File.WriteError) = null; |
| 47 | var stderr_mutex = std.Mutex.init(); | 47 | var stderr_mutex = std.Mutex.init(); |
| 48 | 48 | ||
| 49 | pub fn warn(comptime fmt: []const u8, args: ...) void { | 49 | pub fn warn(comptime fmt: []const u8, args: var) void { |
| 50 | const held = stderr_mutex.acquire(); | 50 | const held = stderr_mutex.acquire(); |
| 51 | defer held.release(); | 51 | defer held.release(); |
| 52 | const stderr = getStderrStream(); | 52 | const stderr = getStderrStream(); |
| ... | @@ -92,15 +92,15 @@ fn wantTtyColor() bool { | ... | @@ -92,15 +92,15 @@ fn wantTtyColor() bool { |
| 92 | pub fn dumpCurrentStackTrace(start_addr: ?usize) void { | 92 | pub fn dumpCurrentStackTrace(start_addr: ?usize) void { |
| 93 | const stderr = getStderrStream(); | 93 | const stderr = getStderrStream(); |
| 94 | if (builtin.strip_debug_info) { | 94 | if (builtin.strip_debug_info) { |
| 95 | stderr.print("Unable to dump stack trace: debug info stripped\n") catch return; | 95 | stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return; |
| 96 | return; | 96 | return; |
| 97 | } | 97 | } |
| 98 | const debug_info = getSelfDebugInfo() catch |err| { | 98 | const debug_info = getSelfDebugInfo() catch |err| { |
| 99 | stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return; | 99 | stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return; |
| 100 | return; | 100 | return; |
| 101 | }; | 101 | }; |
| 102 | writeCurrentStackTrace(stderr, debug_info, wantTtyColor(), start_addr) catch |err| { | 102 | writeCurrentStackTrace(stderr, debug_info, wantTtyColor(), start_addr) catch |err| { |
| 103 | stderr.print("Unable to dump stack trace: {}\n", @errorName(err)) catch return; | 103 | stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return; |
| 104 | return; | 104 | return; |
| 105 | }; | 105 | }; |
| 106 | } | 106 | } |
| ... | @@ -111,11 +111,11 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void { | ... | @@ -111,11 +111,11 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void { |
| 111 | pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void { | 111 | pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void { |
| 112 | const stderr = getStderrStream(); | 112 | const stderr = getStderrStream(); |
| 113 | if (builtin.strip_debug_info) { | 113 | if (builtin.strip_debug_info) { |
| 114 | stderr.print("Unable to dump stack trace: debug info stripped\n") catch return; | 114 | stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return; |
| 115 | return; | 115 | return; |
| 116 | } | 116 | } |
| 117 | const debug_info = getSelfDebugInfo() catch |err| { | 117 | const debug_info = getSelfDebugInfo() catch |err| { |
| 118 | stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return; | 118 | stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return; |
| 119 | return; | 119 | return; |
| 120 | }; | 120 | }; |
| 121 | const tty_color = wantTtyColor(); | 121 | const tty_color = wantTtyColor(); |
| ... | @@ -184,15 +184,15 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace | ... | @@ -184,15 +184,15 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace |
| 184 | pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void { | 184 | pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void { |
| 185 | const stderr = getStderrStream(); | 185 | const stderr = getStderrStream(); |
| 186 | if (builtin.strip_debug_info) { | 186 | if (builtin.strip_debug_info) { |
| 187 | stderr.print("Unable to dump stack trace: debug info stripped\n") catch return; | 187 | stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return; |
| 188 | return; | 188 | return; |
| 189 | } | 189 | } |
| 190 | const debug_info = getSelfDebugInfo() catch |err| { | 190 | const debug_info = getSelfDebugInfo() catch |err| { |
| 191 | stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return; | 191 | stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return; |
| 192 | return; | 192 | return; |
| 193 | }; | 193 | }; |
| 194 | writeStackTrace(stack_trace, stderr, getDebugInfoAllocator(), debug_info, wantTtyColor()) catch |err| { | 194 | writeStackTrace(stack_trace, stderr, getDebugInfoAllocator(), debug_info, wantTtyColor()) catch |err| { |
| 195 | stderr.print("Unable to dump stack trace: {}\n", @errorName(err)) catch return; | 195 | stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return; |
| 196 | return; | 196 | return; |
| 197 | }; | 197 | }; |
| 198 | } | 198 | } |
| ... | @@ -211,7 +211,7 @@ pub fn assert(ok: bool) void { | ... | @@ -211,7 +211,7 @@ pub fn assert(ok: bool) void { |
| 211 | if (!ok) unreachable; // assertion failure | 211 | if (!ok) unreachable; // assertion failure |
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | pub fn panic(comptime format: []const u8, args: ...) noreturn { | 214 | pub fn panic(comptime format: []const u8, args: var) noreturn { |
| 215 | @setCold(true); | 215 | @setCold(true); |
| 216 | // TODO: remove conditional once wasi / LLVM defines __builtin_return_address | 216 | // TODO: remove conditional once wasi / LLVM defines __builtin_return_address |
| 217 | const first_trace_addr = if (builtin.os == .wasi) null else @returnAddress(); | 217 | const first_trace_addr = if (builtin.os == .wasi) null else @returnAddress(); |
| ... | @@ -221,7 +221,7 @@ pub fn panic(comptime format: []const u8, args: ...) noreturn { | ... | @@ -221,7 +221,7 @@ pub fn panic(comptime format: []const u8, args: ...) noreturn { |
| 221 | /// TODO multithreaded awareness | 221 | /// TODO multithreaded awareness |
| 222 | var panicking: u8 = 0; // TODO make this a bool | 222 | var panicking: u8 = 0; // TODO make this a bool |
| 223 | 223 | ||
| 224 | pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: ...) noreturn { | 224 | pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: var) noreturn { |
| 225 | @setCold(true); | 225 | @setCold(true); |
| 226 | 226 | ||
| 227 | if (enable_segfault_handler) { | 227 | if (enable_segfault_handler) { |
| ... | @@ -376,13 +376,13 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres | ... | @@ -376,13 +376,13 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres |
| 376 | } else { | 376 | } else { |
| 377 | // we have no information to add to the address | 377 | // we have no information to add to the address |
| 378 | if (tty_color) { | 378 | if (tty_color) { |
| 379 | try out_stream.print("???:?:?: "); | 379 | try out_stream.print("???:?:?: ", .{}); |
| 380 | setTtyColor(TtyColor.Dim); | 380 | setTtyColor(TtyColor.Dim); |
| 381 | try out_stream.print("0x{x} in ??? (???)", relocated_address); | 381 | try out_stream.print("0x{x} in ??? (???)", .{relocated_address}); |
| 382 | setTtyColor(TtyColor.Reset); | 382 | setTtyColor(TtyColor.Reset); |
| 383 | try out_stream.print("\n\n\n"); | 383 | try out_stream.print("\n\n\n", .{}); |
| 384 | } else { | 384 | } else { |
| 385 | try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", relocated_address); | 385 | try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{relocated_address}); |
| 386 | } | 386 | } |
| 387 | return; | 387 | return; |
| 388 | }; | 388 | }; |
| ... | @@ -509,18 +509,18 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres | ... | @@ -509,18 +509,18 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres |
| 509 | if (tty_color) { | 509 | if (tty_color) { |
| 510 | setTtyColor(TtyColor.White); | 510 | setTtyColor(TtyColor.White); |
| 511 | if (opt_line_info) |li| { | 511 | if (opt_line_info) |li| { |
| 512 | try out_stream.print("{}:{}:{}", li.file_name, li.line, li.column); | 512 | try out_stream.print("{}:{}:{}", .{ li.file_name, li.line, li.column }); |
| 513 | } else { | 513 | } else { |
| 514 | try out_stream.print("???:?:?"); | 514 | try out_stream.print("???:?:?", .{}); |
| 515 | } | 515 | } |
| 516 | setTtyColor(TtyColor.Reset); | 516 | setTtyColor(TtyColor.Reset); |
| 517 | try out_stream.print(": "); | 517 | try out_stream.print(": ", .{}); |
| 518 | setTtyColor(TtyColor.Dim); | 518 | setTtyColor(TtyColor.Dim); |
| 519 | try out_stream.print("0x{x} in {} ({})", relocated_address, symbol_name, obj_basename); | 519 | try out_stream.print("0x{x} in {} ({})", .{ relocated_address, symbol_name, obj_basename }); |
| 520 | setTtyColor(TtyColor.Reset); | 520 | setTtyColor(TtyColor.Reset); |
| 521 | 521 | ||
| 522 | if (opt_line_info) |line_info| { | 522 | if (opt_line_info) |line_info| { |
| 523 | try out_stream.print("\n"); | 523 | try out_stream.print("\n", .{}); |
| 524 | if (printLineFromFileAnyOs(out_stream, line_info)) { | 524 | if (printLineFromFileAnyOs(out_stream, line_info)) { |
| 525 | if (line_info.column == 0) { | 525 | if (line_info.column == 0) { |
| 526 | try out_stream.write("\n"); | 526 | try out_stream.write("\n"); |
| ... | @@ -546,13 +546,24 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres | ... | @@ -546,13 +546,24 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres |
| 546 | else => return err, | 546 | else => return err, |
| 547 | } | 547 | } |
| 548 | } else { | 548 | } else { |
| 549 | try out_stream.print("\n\n\n"); | 549 | try out_stream.print("\n\n\n", .{}); |
| 550 | } | 550 | } |
| 551 | } else { | 551 | } else { |
| 552 | if (opt_line_info) |li| { | 552 | if (opt_line_info) |li| { |
| 553 | try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n\n\n", li.file_name, li.line, li.column, relocated_address, symbol_name, obj_basename); | 553 | try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n\n\n", .{ |
| 554 | li.file_name, | ||
| 555 | li.line, | ||
| 556 | li.column, | ||
| 557 | relocated_address, | ||
| 558 | symbol_name, | ||
| 559 | obj_basename, | ||
| 560 | }); | ||
| 554 | } else { | 561 | } else { |
| 555 | try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", relocated_address, symbol_name, obj_basename); | 562 | try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", .{ |
| 563 | relocated_address, | ||
| 564 | symbol_name, | ||
| 565 | obj_basename, | ||
| 566 | }); | ||
| 556 | } | 567 | } |
| 557 | } | 568 | } |
| 558 | } | 569 | } |
| ... | @@ -697,9 +708,9 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt | ... | @@ -697,9 +708,9 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt |
| 697 | 708 | ||
| 698 | const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse { | 709 | const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse { |
| 699 | if (tty_color) { | 710 | if (tty_color) { |
| 700 | try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", address); | 711 | try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", .{address}); |
| 701 | } else { | 712 | } else { |
| 702 | try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", address); | 713 | try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{address}); |
| 703 | } | 714 | } |
| 704 | return; | 715 | return; |
| 705 | }; | 716 | }; |
| ... | @@ -723,9 +734,11 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt | ... | @@ -723,9 +734,11 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt |
| 723 | } else |err| switch (err) { | 734 | } else |err| switch (err) { |
| 724 | error.MissingDebugInfo, error.InvalidDebugInfo => { | 735 | error.MissingDebugInfo, error.InvalidDebugInfo => { |
| 725 | if (tty_color) { | 736 | if (tty_color) { |
| 726 | try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n\n\n", address, symbol_name, compile_unit_name); | 737 | try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n\n\n", .{ |
| 738 | address, symbol_name, compile_unit_name, | ||
| 739 | }); | ||
| 727 | } else { | 740 | } else { |
| 728 | try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", address, symbol_name, compile_unit_name); | 741 | try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", .{ address, symbol_name, compile_unit_name }); |
| 729 | } | 742 | } |
| 730 | }, | 743 | }, |
| 731 | else => return err, | 744 | else => return err, |
| ... | @@ -746,15 +759,14 @@ fn printLineInfo( | ... | @@ -746,15 +759,14 @@ fn printLineInfo( |
| 746 | comptime printLineFromFile: var, | 759 | comptime printLineFromFile: var, |
| 747 | ) !void { | 760 | ) !void { |
| 748 | if (tty_color) { | 761 | if (tty_color) { |
| 749 | try out_stream.print( | 762 | try out_stream.print(WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n", .{ |
| 750 | WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n", | ||
| 751 | line_info.file_name, | 763 | line_info.file_name, |
| 752 | line_info.line, | 764 | line_info.line, |
| 753 | line_info.column, | 765 | line_info.column, |
| 754 | address, | 766 | address, |
| 755 | symbol_name, | 767 | symbol_name, |
| 756 | compile_unit_name, | 768 | compile_unit_name, |
| 757 | ); | 769 | }); |
| 758 | if (printLineFromFile(out_stream, line_info)) { | 770 | if (printLineFromFile(out_stream, line_info)) { |
| 759 | if (line_info.column == 0) { | 771 | if (line_info.column == 0) { |
| 760 | try out_stream.write("\n"); | 772 | try out_stream.write("\n"); |
| ... | @@ -772,15 +784,14 @@ fn printLineInfo( | ... | @@ -772,15 +784,14 @@ fn printLineInfo( |
| 772 | else => return err, | 784 | else => return err, |
| 773 | } | 785 | } |
| 774 | } else { | 786 | } else { |
| 775 | try out_stream.print( | 787 | try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n", .{ |
| 776 | "{}:{}:{}: 0x{x} in {} ({})\n", | ||
| 777 | line_info.file_name, | 788 | line_info.file_name, |
| 778 | line_info.line, | 789 | line_info.line, |
| 779 | line_info.column, | 790 | line_info.column, |
| 780 | address, | 791 | address, |
| 781 | symbol_name, | 792 | symbol_name, |
| 782 | compile_unit_name, | 793 | compile_unit_name, |
| 783 | ); | 794 | }); |
| 784 | } | 795 | } |
| 785 | } | 796 | } |
| 786 | 797 | ||
| ... | @@ -1226,9 +1237,9 @@ pub const DwarfInfo = struct { | ... | @@ -1226,9 +1237,9 @@ pub const DwarfInfo = struct { |
| 1226 | ) !void { | 1237 | ) !void { |
| 1227 | const compile_unit = self.findCompileUnit(address) catch { | 1238 | const compile_unit = self.findCompileUnit(address) catch { |
| 1228 | if (tty_color) { | 1239 | if (tty_color) { |
| 1229 | try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", address); | 1240 | try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", .{address}); |
| 1230 | } else { | 1241 | } else { |
| 1231 | try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", address); | 1242 | try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{address}); |
| 1232 | } | 1243 | } |
| 1233 | return; | 1244 | return; |
| 1234 | }; | 1245 | }; |
| ... | @@ -1248,9 +1259,11 @@ pub const DwarfInfo = struct { | ... | @@ -1248,9 +1259,11 @@ pub const DwarfInfo = struct { |
| 1248 | } else |err| switch (err) { | 1259 | } else |err| switch (err) { |
| 1249 | error.MissingDebugInfo, error.InvalidDebugInfo => { | 1260 | error.MissingDebugInfo, error.InvalidDebugInfo => { |
| 1250 | if (tty_color) { | 1261 | if (tty_color) { |
| 1251 | try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? ({})" ++ RESET ++ "\n\n\n", address, compile_unit_name); | 1262 | try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? ({})" ++ RESET ++ "\n\n\n", .{ |
| 1263 | address, compile_unit_name, | ||
| 1264 | }); | ||
| 1252 | } else { | 1265 | } else { |
| 1253 | try out_stream.print("???:?:?: 0x{x} in ??? ({})\n\n\n", address, compile_unit_name); | 1266 | try out_stream.print("???:?:?: 0x{x} in ??? ({})\n\n\n", .{ address, compile_unit_name }); |
| 1254 | } | 1267 | } |
| 1255 | }, | 1268 | }, |
| 1256 | else => return err, | 1269 | else => return err, |
| ... | @@ -2416,7 +2429,7 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con | ... | @@ -2416,7 +2429,7 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con |
| 2416 | resetSegfaultHandler(); | 2429 | resetSegfaultHandler(); |
| 2417 | 2430 | ||
| 2418 | const addr = @ptrToInt(info.fields.sigfault.addr); | 2431 | const addr = @ptrToInt(info.fields.sigfault.addr); |
| 2419 | std.debug.warn("Segmentation fault at address 0x{x}\n", addr); | 2432 | std.debug.warn("Segmentation fault at address 0x{x}\n", .{addr}); |
| 2420 | 2433 | ||
| 2421 | switch (builtin.arch) { | 2434 | switch (builtin.arch) { |
| 2422 | .i386 => { | 2435 | .i386 => { |
| ... | @@ -2468,7 +2481,7 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void { | ... | @@ -2468,7 +2481,7 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void { |
| 2468 | const sp = asm ("" | 2481 | const sp = asm ("" |
| 2469 | : [argc] "={rsp}" (-> usize) | 2482 | : [argc] "={rsp}" (-> usize) |
| 2470 | ); | 2483 | ); |
| 2471 | std.debug.warn("{} sp = 0x{x}\n", prefix, sp); | 2484 | std.debug.warn("{} sp = 0x{x}\n", .{ prefix, sp }); |
| 2472 | } | 2485 | } |
| 2473 | 2486 | ||
| 2474 | // Reference everything so it gets tested. | 2487 | // Reference everything so it gets tested. |
lib/std/event/channel.zig+2-2| ... | @@ -294,14 +294,14 @@ test "std.event.Channel wraparound" { | ... | @@ -294,14 +294,14 @@ test "std.event.Channel wraparound" { |
| 294 | 294 | ||
| 295 | const channel_size = 2; | 295 | const channel_size = 2; |
| 296 | 296 | ||
| 297 | var buf : [channel_size]i32 = undefined; | 297 | var buf: [channel_size]i32 = undefined; |
| 298 | var channel: Channel(i32) = undefined; | 298 | var channel: Channel(i32) = undefined; |
| 299 | channel.init(&buf); | 299 | channel.init(&buf); |
| 300 | defer channel.deinit(); | 300 | defer channel.deinit(); |
| 301 | 301 | ||
| 302 | // add items to channel and pull them out until | 302 | // add items to channel and pull them out until |
| 303 | // the buffer wraps around, make sure it doesn't crash. | 303 | // the buffer wraps around, make sure it doesn't crash. |
| 304 | var result : i32 = undefined; | 304 | var result: i32 = undefined; |
| 305 | channel.put(5); | 305 | channel.put(5); |
| 306 | testing.expectEqual(@as(i32, 5), channel.get()); | 306 | testing.expectEqual(@as(i32, 5), channel.get()); |
| 307 | channel.put(6); | 307 | channel.put(6); |
lib/std/fifo.zig+2-2| ... | @@ -293,7 +293,7 @@ pub fn LinearFifo( | ... | @@ -293,7 +293,7 @@ pub fn LinearFifo( |
| 293 | 293 | ||
| 294 | pub usingnamespace if (T == u8) | 294 | pub usingnamespace if (T == u8) |
| 295 | struct { | 295 | struct { |
| 296 | pub fn print(self: *Self, comptime format: []const u8, args: ...) !void { | 296 | pub fn print(self: *Self, comptime format: []const u8, args: var) !void { |
| 297 | return std.fmt.format(self, error{OutOfMemory}, Self.write, format, args); | 297 | return std.fmt.format(self, error{OutOfMemory}, Self.write, format, args); |
| 298 | } | 298 | } |
| 299 | } | 299 | } |
| ... | @@ -407,7 +407,7 @@ test "LinearFifo(u8, .Dynamic)" { | ... | @@ -407,7 +407,7 @@ test "LinearFifo(u8, .Dynamic)" { |
| 407 | fifo.shrink(0); | 407 | fifo.shrink(0); |
| 408 | 408 | ||
| 409 | { | 409 | { |
| 410 | try fifo.print("{}, {}!", "Hello", "World"); | 410 | try fifo.print("{}, {}!", .{ "Hello", "World" }); |
| 411 | var result: [30]u8 = undefined; | 411 | var result: [30]u8 = undefined; |
| 412 | testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]); | 412 | testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]); |
| 413 | testing.expectEqual(@as(usize, 0), fifo.readableLength()); | 413 | testing.expectEqual(@as(usize, 0), fifo.readableLength()); |
lib/std/fmt.zig+111-109| ... | @@ -91,10 +91,12 @@ pub fn format( | ... | @@ -91,10 +91,12 @@ pub fn format( |
| 91 | comptime Errors: type, | 91 | comptime Errors: type, |
| 92 | output: fn (@typeOf(context), []const u8) Errors!void, | 92 | output: fn (@typeOf(context), []const u8) Errors!void, |
| 93 | comptime fmt: []const u8, | 93 | comptime fmt: []const u8, |
| 94 | args: ..., | 94 | args: var, |
| 95 | ) Errors!void { | 95 | ) Errors!void { |
| 96 | const ArgSetType = @IntType(false, 32); | 96 | const ArgSetType = @IntType(false, 32); |
| 97 | if (args.len > ArgSetType.bit_count) { | 97 | const args_fields = std.meta.fields(@typeOf(args)); |
| 98 | const args_len = args_fields.len; | ||
| 99 | if (args_len > ArgSetType.bit_count) { | ||
| 98 | @compileError("32 arguments max are supported per format call"); | 100 | @compileError("32 arguments max are supported per format call"); |
| 99 | } | 101 | } |
| 100 | 102 | ||
| ... | @@ -158,14 +160,14 @@ pub fn format( | ... | @@ -158,14 +160,14 @@ pub fn format( |
| 158 | maybe_pos_arg.? += c - '0'; | 160 | maybe_pos_arg.? += c - '0'; |
| 159 | specifier_start = i + 1; | 161 | specifier_start = i + 1; |
| 160 | 162 | ||
| 161 | if (maybe_pos_arg.? >= args.len) { | 163 | if (maybe_pos_arg.? >= args_len) { |
| 162 | @compileError("Positional value refers to non-existent argument"); | 164 | @compileError("Positional value refers to non-existent argument"); |
| 163 | } | 165 | } |
| 164 | }, | 166 | }, |
| 165 | '}' => { | 167 | '}' => { |
| 166 | const arg_to_print = comptime nextArg(&used_pos_args, maybe_pos_arg, &next_arg); | 168 | const arg_to_print = comptime nextArg(&used_pos_args, maybe_pos_arg, &next_arg); |
| 167 | 169 | ||
| 168 | if (arg_to_print >= args.len) { | 170 | if (arg_to_print >= args_len) { |
| 169 | @compileError("Too few arguments"); | 171 | @compileError("Too few arguments"); |
| 170 | } | 172 | } |
| 171 | 173 | ||
| ... | @@ -302,7 +304,7 @@ pub fn format( | ... | @@ -302,7 +304,7 @@ pub fn format( |
| 302 | used_pos_args |= 1 << i; | 304 | used_pos_args |= 1 << i; |
| 303 | } | 305 | } |
| 304 | 306 | ||
| 305 | if (@popCount(ArgSetType, used_pos_args) != args.len) { | 307 | if (@popCount(ArgSetType, used_pos_args) != args_len) { |
| 306 | @compileError("Unused arguments"); | 308 | @compileError("Unused arguments"); |
| 307 | } | 309 | } |
| 308 | if (state != State.Start) { | 310 | if (state != State.Start) { |
| ... | @@ -389,7 +391,7 @@ pub fn formatType( | ... | @@ -389,7 +391,7 @@ pub fn formatType( |
| 389 | } | 391 | } |
| 390 | try output(context, " }"); | 392 | try output(context, " }"); |
| 391 | } else { | 393 | } else { |
| 392 | try format(context, Errors, output, "@{x}", @ptrToInt(&value)); | 394 | try format(context, Errors, output, "@{x}", .{@ptrToInt(&value)}); |
| 393 | } | 395 | } |
| 394 | }, | 396 | }, |
| 395 | .Struct => { | 397 | .Struct => { |
| ... | @@ -421,12 +423,12 @@ pub fn formatType( | ... | @@ -421,12 +423,12 @@ pub fn formatType( |
| 421 | if (info.child == u8) { | 423 | if (info.child == u8) { |
| 422 | return formatText(value, fmt, options, context, Errors, output); | 424 | return formatText(value, fmt, options, context, Errors, output); |
| 423 | } | 425 | } |
| 424 | return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value)); | 426 | return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }); |
| 425 | }, | 427 | }, |
| 426 | builtin.TypeId.Enum, builtin.TypeId.Union, builtin.TypeId.Struct => { | 428 | builtin.TypeId.Enum, builtin.TypeId.Union, builtin.TypeId.Struct => { |
| 427 | return formatType(value.*, fmt, options, context, Errors, output, max_depth); | 429 | return formatType(value.*, fmt, options, context, Errors, output, max_depth); |
| 428 | }, | 430 | }, |
| 429 | else => return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value)), | 431 | else => return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }), |
| 430 | }, | 432 | }, |
| 431 | .Many => { | 433 | .Many => { |
| 432 | if (ptr_info.child == u8) { | 434 | if (ptr_info.child == u8) { |
| ... | @@ -435,7 +437,7 @@ pub fn formatType( | ... | @@ -435,7 +437,7 @@ pub fn formatType( |
| 435 | return formatText(value[0..len], fmt, options, context, Errors, output); | 437 | return formatText(value[0..len], fmt, options, context, Errors, output); |
| 436 | } | 438 | } |
| 437 | } | 439 | } |
| 438 | return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value)); | 440 | return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }); |
| 439 | }, | 441 | }, |
| 440 | .Slice => { | 442 | .Slice => { |
| 441 | if (fmt.len > 0 and ((fmt[0] == 'x') or (fmt[0] == 'X'))) { | 443 | if (fmt.len > 0 and ((fmt[0] == 'x') or (fmt[0] == 'X'))) { |
| ... | @@ -444,10 +446,10 @@ pub fn formatType( | ... | @@ -444,10 +446,10 @@ pub fn formatType( |
| 444 | if (ptr_info.child == u8) { | 446 | if (ptr_info.child == u8) { |
| 445 | return formatText(value, fmt, options, context, Errors, output); | 447 | return formatText(value, fmt, options, context, Errors, output); |
| 446 | } | 448 | } |
| 447 | return format(context, Errors, output, "{}@{x}", @typeName(ptr_info.child), @ptrToInt(value.ptr)); | 449 | return format(context, Errors, output, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value.ptr) }); |
| 448 | }, | 450 | }, |
| 449 | .C => { | 451 | .C => { |
| 450 | return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value)); | 452 | return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }); |
| 451 | }, | 453 | }, |
| 452 | }, | 454 | }, |
| 453 | .Array => |info| { | 455 | .Array => |info| { |
| ... | @@ -465,7 +467,7 @@ pub fn formatType( | ... | @@ -465,7 +467,7 @@ pub fn formatType( |
| 465 | return formatType(@as(Slice, &value), fmt, options, context, Errors, output, max_depth); | 467 | return formatType(@as(Slice, &value), fmt, options, context, Errors, output, max_depth); |
| 466 | }, | 468 | }, |
| 467 | .Fn => { | 469 | .Fn => { |
| 468 | return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value)); | 470 | return format(context, Errors, output, "{}@{x}", .{ @typeName(T), @ptrToInt(value) }); |
| 469 | }, | 471 | }, |
| 470 | else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"), | 472 | else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"), |
| 471 | } | 473 | } |
| ... | @@ -1113,7 +1115,7 @@ pub const BufPrintError = error{ | ... | @@ -1113,7 +1115,7 @@ pub const BufPrintError = error{ |
| 1113 | /// As much as possible was written to the buffer, but it was too small to fit all the printed bytes. | 1115 | /// As much as possible was written to the buffer, but it was too small to fit all the printed bytes. |
| 1114 | BufferTooSmall, | 1116 | BufferTooSmall, |
| 1115 | }; | 1117 | }; |
| 1116 | pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) BufPrintError![]u8 { | 1118 | pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: var) BufPrintError![]u8 { |
| 1117 | var context = BufPrintContext{ .remaining = buf }; | 1119 | var context = BufPrintContext{ .remaining = buf }; |
| 1118 | try format(&context, BufPrintError, bufPrintWrite, fmt, args); | 1120 | try format(&context, BufPrintError, bufPrintWrite, fmt, args); |
| 1119 | return buf[0 .. buf.len - context.remaining.len]; | 1121 | return buf[0 .. buf.len - context.remaining.len]; |
| ... | @@ -1121,7 +1123,7 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) BufPrintError![] | ... | @@ -1121,7 +1123,7 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) BufPrintError![] |
| 1121 | 1123 | ||
| 1122 | pub const AllocPrintError = error{OutOfMemory}; | 1124 | pub const AllocPrintError = error{OutOfMemory}; |
| 1123 | 1125 | ||
| 1124 | pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: ...) AllocPrintError![]u8 { | 1126 | pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: var) AllocPrintError![]u8 { |
| 1125 | var size: usize = 0; | 1127 | var size: usize = 0; |
| 1126 | format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {}; | 1128 | format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {}; |
| 1127 | const buf = try allocator.alloc(u8, size); | 1129 | const buf = try allocator.alloc(u8, size); |
| ... | @@ -1173,46 +1175,46 @@ test "parse unsigned comptime" { | ... | @@ -1173,46 +1175,46 @@ test "parse unsigned comptime" { |
| 1173 | test "optional" { | 1175 | test "optional" { |
| 1174 | { | 1176 | { |
| 1175 | const value: ?i32 = 1234; | 1177 | const value: ?i32 = 1234; |
| 1176 | try testFmt("optional: 1234\n", "optional: {}\n", value); | 1178 | try testFmt("optional: 1234\n", "optional: {}\n", .{value}); |
| 1177 | } | 1179 | } |
| 1178 | { | 1180 | { |
| 1179 | const value: ?i32 = null; | 1181 | const value: ?i32 = null; |
| 1180 | try testFmt("optional: null\n", "optional: {}\n", value); | 1182 | try testFmt("optional: null\n", "optional: {}\n", .{value}); |
| 1181 | } | 1183 | } |
| 1182 | } | 1184 | } |
| 1183 | 1185 | ||
| 1184 | test "error" { | 1186 | test "error" { |
| 1185 | { | 1187 | { |
| 1186 | const value: anyerror!i32 = 1234; | 1188 | const value: anyerror!i32 = 1234; |
| 1187 | try testFmt("error union: 1234\n", "error union: {}\n", value); | 1189 | try testFmt("error union: 1234\n", "error union: {}\n", .{value}); |
| 1188 | } | 1190 | } |
| 1189 | { | 1191 | { |
| 1190 | const value: anyerror!i32 = error.InvalidChar; | 1192 | const value: anyerror!i32 = error.InvalidChar; |
| 1191 | try testFmt("error union: error.InvalidChar\n", "error union: {}\n", value); | 1193 | try testFmt("error union: error.InvalidChar\n", "error union: {}\n", .{value}); |
| 1192 | } | 1194 | } |
| 1193 | } | 1195 | } |
| 1194 | 1196 | ||
| 1195 | test "int.small" { | 1197 | test "int.small" { |
| 1196 | { | 1198 | { |
| 1197 | const value: u3 = 0b101; | 1199 | const value: u3 = 0b101; |
| 1198 | try testFmt("u3: 5\n", "u3: {}\n", value); | 1200 | try testFmt("u3: 5\n", "u3: {}\n", .{value}); |
| 1199 | } | 1201 | } |
| 1200 | } | 1202 | } |
| 1201 | 1203 | ||
| 1202 | test "int.specifier" { | 1204 | test "int.specifier" { |
| 1203 | { | 1205 | { |
| 1204 | const value: u8 = 'a'; | 1206 | const value: u8 = 'a'; |
| 1205 | try testFmt("u8: a\n", "u8: {c}\n", value); | 1207 | try testFmt("u8: a\n", "u8: {c}\n", .{value}); |
| 1206 | } | 1208 | } |
| 1207 | { | 1209 | { |
| 1208 | const value: u8 = 0b1100; | 1210 | const value: u8 = 0b1100; |
| 1209 | try testFmt("u8: 0b1100\n", "u8: 0b{b}\n", value); | 1211 | try testFmt("u8: 0b1100\n", "u8: 0b{b}\n", .{value}); |
| 1210 | } | 1212 | } |
| 1211 | } | 1213 | } |
| 1212 | 1214 | ||
| 1213 | test "int.padded" { | 1215 | test "int.padded" { |
| 1214 | try testFmt("u8: ' 1'", "u8: '{:4}'", @as(u8, 1)); | 1216 | try testFmt("u8: ' 1'", "u8: '{:4}'", .{@as(u8, 1)}); |
| 1215 | try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", @as(u8, 1)); | 1217 | try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", .{@as(u8, 1)}); |
| 1216 | } | 1218 | } |
| 1217 | 1219 | ||
| 1218 | test "buffer" { | 1220 | test "buffer" { |
| ... | @@ -1238,14 +1240,14 @@ test "buffer" { | ... | @@ -1238,14 +1240,14 @@ test "buffer" { |
| 1238 | test "array" { | 1240 | test "array" { |
| 1239 | { | 1241 | { |
| 1240 | const value: [3]u8 = "abc".*; | 1242 | const value: [3]u8 = "abc".*; |
| 1241 | try testFmt("array: abc\n", "array: {}\n", value); | 1243 | try testFmt("array: abc\n", "array: {}\n", .{value}); |
| 1242 | try testFmt("array: abc\n", "array: {}\n", &value); | 1244 | try testFmt("array: abc\n", "array: {}\n", .{&value}); |
| 1243 | 1245 | ||
| 1244 | var buf: [100]u8 = undefined; | 1246 | var buf: [100]u8 = undefined; |
| 1245 | try testFmt( | 1247 | try testFmt( |
| 1246 | try bufPrint(buf[0..], "array: [3]u8@{x}\n", @ptrToInt(&value)), | 1248 | try bufPrint(buf[0..], "array: [3]u8@{x}\n", .{@ptrToInt(&value)}), |
| 1247 | "array: {*}\n", | 1249 | "array: {*}\n", |
| 1248 | &value, | 1250 | .{&value}, |
| 1249 | ); | 1251 | ); |
| 1250 | } | 1252 | } |
| 1251 | } | 1253 | } |
| ... | @@ -1253,36 +1255,36 @@ test "array" { | ... | @@ -1253,36 +1255,36 @@ test "array" { |
| 1253 | test "slice" { | 1255 | test "slice" { |
| 1254 | { | 1256 | { |
| 1255 | const value: []const u8 = "abc"; | 1257 | const value: []const u8 = "abc"; |
| 1256 | try testFmt("slice: abc\n", "slice: {}\n", value); | 1258 | try testFmt("slice: abc\n", "slice: {}\n", .{value}); |
| 1257 | } | 1259 | } |
| 1258 | { | 1260 | { |
| 1259 | const value = @intToPtr([*]const []const u8, 0xdeadbeef)[0..0]; | 1261 | const value = @intToPtr([*]const []const u8, 0xdeadbeef)[0..0]; |
| 1260 | try testFmt("slice: []const u8@deadbeef\n", "slice: {}\n", value); | 1262 | try testFmt("slice: []const u8@deadbeef\n", "slice: {}\n", .{value}); |
| 1261 | } | 1263 | } |
| 1262 | 1264 | ||
| 1263 | try testFmt("buf: Test \n", "buf: {s:5}\n", "Test"); | 1265 | try testFmt("buf: Test \n", "buf: {s:5}\n", .{"Test"}); |
| 1264 | try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", "Test"); | 1266 | try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", .{"Test"}); |
| 1265 | } | 1267 | } |
| 1266 | 1268 | ||
| 1267 | test "pointer" { | 1269 | test "pointer" { |
| 1268 | { | 1270 | { |
| 1269 | const value = @intToPtr(*i32, 0xdeadbeef); | 1271 | const value = @intToPtr(*i32, 0xdeadbeef); |
| 1270 | try testFmt("pointer: i32@deadbeef\n", "pointer: {}\n", value); | 1272 | try testFmt("pointer: i32@deadbeef\n", "pointer: {}\n", .{value}); |
| 1271 | try testFmt("pointer: i32@deadbeef\n", "pointer: {*}\n", value); | 1273 | try testFmt("pointer: i32@deadbeef\n", "pointer: {*}\n", .{value}); |
| 1272 | } | 1274 | } |
| 1273 | { | 1275 | { |
| 1274 | const value = @intToPtr(fn () void, 0xdeadbeef); | 1276 | const value = @intToPtr(fn () void, 0xdeadbeef); |
| 1275 | try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value); | 1277 | try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value}); |
| 1276 | } | 1278 | } |
| 1277 | { | 1279 | { |
| 1278 | const value = @intToPtr(fn () void, 0xdeadbeef); | 1280 | const value = @intToPtr(fn () void, 0xdeadbeef); |
| 1279 | try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value); | 1281 | try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value}); |
| 1280 | } | 1282 | } |
| 1281 | } | 1283 | } |
| 1282 | 1284 | ||
| 1283 | test "cstr" { | 1285 | test "cstr" { |
| 1284 | try testFmt("cstr: Test C\n", "cstr: {s}\n", "Test C"); | 1286 | try testFmt("cstr: Test C\n", "cstr: {s}\n", .{"Test C"}); |
| 1285 | try testFmt("cstr: Test C \n", "cstr: {s:10}\n", "Test C"); | 1287 | try testFmt("cstr: Test C \n", "cstr: {s:10}\n", .{"Test C"}); |
| 1286 | } | 1288 | } |
| 1287 | 1289 | ||
| 1288 | test "filesize" { | 1290 | test "filesize" { |
| ... | @@ -1290,8 +1292,8 @@ test "filesize" { | ... | @@ -1290,8 +1292,8 @@ test "filesize" { |
| 1290 | // TODO https://github.com/ziglang/zig/issues/3289 | 1292 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1291 | return error.SkipZigTest; | 1293 | return error.SkipZigTest; |
| 1292 | } | 1294 | } |
| 1293 | try testFmt("file size: 63MiB\n", "file size: {Bi}\n", @as(usize, 63 * 1024 * 1024)); | 1295 | try testFmt("file size: 63MiB\n", "file size: {Bi}\n", .{@as(usize, 63 * 1024 * 1024)}); |
| 1294 | try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", @as(usize, 63 * 1024 * 1024)); | 1296 | try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", .{@as(usize, 63 * 1024 * 1024)}); |
| 1295 | } | 1297 | } |
| 1296 | 1298 | ||
| 1297 | test "struct" { | 1299 | test "struct" { |
| ... | @@ -1300,8 +1302,8 @@ test "struct" { | ... | @@ -1300,8 +1302,8 @@ test "struct" { |
| 1300 | field: u8, | 1302 | field: u8, |
| 1301 | }; | 1303 | }; |
| 1302 | const value = Struct{ .field = 42 }; | 1304 | const value = Struct{ .field = 42 }; |
| 1303 | try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", value); | 1305 | try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", .{value}); |
| 1304 | try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", &value); | 1306 | try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", .{&value}); |
| 1305 | } | 1307 | } |
| 1306 | { | 1308 | { |
| 1307 | const Struct = struct { | 1309 | const Struct = struct { |
| ... | @@ -1309,7 +1311,7 @@ test "struct" { | ... | @@ -1309,7 +1311,7 @@ test "struct" { |
| 1309 | b: u1, | 1311 | b: u1, |
| 1310 | }; | 1312 | }; |
| 1311 | const value = Struct{ .a = 0, .b = 1 }; | 1313 | const value = Struct{ .a = 0, .b = 1 }; |
| 1312 | try testFmt("struct: Struct{ .a = 0, .b = 1 }\n", "struct: {}\n", value); | 1314 | try testFmt("struct: Struct{ .a = 0, .b = 1 }\n", "struct: {}\n", .{value}); |
| 1313 | } | 1315 | } |
| 1314 | } | 1316 | } |
| 1315 | 1317 | ||
| ... | @@ -1319,8 +1321,8 @@ test "enum" { | ... | @@ -1319,8 +1321,8 @@ test "enum" { |
| 1319 | Two, | 1321 | Two, |
| 1320 | }; | 1322 | }; |
| 1321 | const value = Enum.Two; | 1323 | const value = Enum.Two; |
| 1322 | try testFmt("enum: Enum.Two\n", "enum: {}\n", value); | 1324 | try testFmt("enum: Enum.Two\n", "enum: {}\n", .{value}); |
| 1323 | try testFmt("enum: Enum.Two\n", "enum: {}\n", &value); | 1325 | try testFmt("enum: Enum.Two\n", "enum: {}\n", .{&value}); |
| 1324 | } | 1326 | } |
| 1325 | 1327 | ||
| 1326 | test "float.scientific" { | 1328 | test "float.scientific" { |
| ... | @@ -1328,10 +1330,10 @@ test "float.scientific" { | ... | @@ -1328,10 +1330,10 @@ test "float.scientific" { |
| 1328 | // TODO https://github.com/ziglang/zig/issues/3289 | 1330 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1329 | return error.SkipZigTest; | 1331 | return error.SkipZigTest; |
| 1330 | } | 1332 | } |
| 1331 | try testFmt("f32: 1.34000003e+00", "f32: {e}", @as(f32, 1.34)); | 1333 | try testFmt("f32: 1.34000003e+00", "f32: {e}", .{@as(f32, 1.34)}); |
| 1332 | try testFmt("f32: 1.23400001e+01", "f32: {e}", @as(f32, 12.34)); | 1334 | try testFmt("f32: 1.23400001e+01", "f32: {e}", .{@as(f32, 12.34)}); |
| 1333 | try testFmt("f64: -1.234e+11", "f64: {e}", @as(f64, -12.34e10)); | 1335 | try testFmt("f64: -1.234e+11", "f64: {e}", .{@as(f64, -12.34e10)}); |
| 1334 | try testFmt("f64: 9.99996e-40", "f64: {e}", @as(f64, 9.999960e-40)); | 1336 | try testFmt("f64: 9.99996e-40", "f64: {e}", .{@as(f64, 9.999960e-40)}); |
| 1335 | } | 1337 | } |
| 1336 | 1338 | ||
| 1337 | test "float.scientific.precision" { | 1339 | test "float.scientific.precision" { |
| ... | @@ -1339,12 +1341,12 @@ test "float.scientific.precision" { | ... | @@ -1339,12 +1341,12 @@ test "float.scientific.precision" { |
| 1339 | // TODO https://github.com/ziglang/zig/issues/3289 | 1341 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1340 | return error.SkipZigTest; | 1342 | return error.SkipZigTest; |
| 1341 | } | 1343 | } |
| 1342 | try testFmt("f64: 1.40971e-42", "f64: {e:.5}", @as(f64, 1.409706e-42)); | 1344 | try testFmt("f64: 1.40971e-42", "f64: {e:.5}", .{@as(f64, 1.409706e-42)}); |
| 1343 | try testFmt("f64: 1.00000e-09", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 814313563)))); | 1345 | try testFmt("f64: 1.00000e-09", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 814313563)))}); |
| 1344 | try testFmt("f64: 7.81250e-03", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1006632960)))); | 1346 | try testFmt("f64: 7.81250e-03", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1006632960)))}); |
| 1345 | // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05. | 1347 | // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05. |
| 1346 | // In fact, libc doesn't round a lot of 5 cases up when one past the precision point. | 1348 | // In fact, libc doesn't round a lot of 5 cases up when one past the precision point. |
| 1347 | try testFmt("f64: 1.00001e+05", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1203982400)))); | 1349 | try testFmt("f64: 1.00001e+05", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1203982400)))}); |
| 1348 | } | 1350 | } |
| 1349 | 1351 | ||
| 1350 | test "float.special" { | 1352 | test "float.special" { |
| ... | @@ -1352,14 +1354,14 @@ test "float.special" { | ... | @@ -1352,14 +1354,14 @@ test "float.special" { |
| 1352 | // TODO https://github.com/ziglang/zig/issues/3289 | 1354 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1353 | return error.SkipZigTest; | 1355 | return error.SkipZigTest; |
| 1354 | } | 1356 | } |
| 1355 | try testFmt("f64: nan", "f64: {}", math.nan_f64); | 1357 | try testFmt("f64: nan", "f64: {}", .{math.nan_f64}); |
| 1356 | // negative nan is not defined by IEE 754, | 1358 | // negative nan is not defined by IEE 754, |
| 1357 | // and ARM thus normalizes it to positive nan | 1359 | // and ARM thus normalizes it to positive nan |
| 1358 | if (builtin.arch != builtin.Arch.arm) { | 1360 | if (builtin.arch != builtin.Arch.arm) { |
| 1359 | try testFmt("f64: -nan", "f64: {}", -math.nan_f64); | 1361 | try testFmt("f64: -nan", "f64: {}", .{-math.nan_f64}); |
| 1360 | } | 1362 | } |
| 1361 | try testFmt("f64: inf", "f64: {}", math.inf_f64); | 1363 | try testFmt("f64: inf", "f64: {}", .{math.inf_f64}); |
| 1362 | try testFmt("f64: -inf", "f64: {}", -math.inf_f64); | 1364 | try testFmt("f64: -inf", "f64: {}", .{-math.inf_f64}); |
| 1363 | } | 1365 | } |
| 1364 | 1366 | ||
| 1365 | test "float.decimal" { | 1367 | test "float.decimal" { |
| ... | @@ -1367,21 +1369,21 @@ test "float.decimal" { | ... | @@ -1367,21 +1369,21 @@ test "float.decimal" { |
| 1367 | // TODO https://github.com/ziglang/zig/issues/3289 | 1369 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1368 | return error.SkipZigTest; | 1370 | return error.SkipZigTest; |
| 1369 | } | 1371 | } |
| 1370 | try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29)); | 1372 | try testFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e+29)}); |
| 1371 | try testFmt("f32: 1.1", "f32: {d:.1}", @as(f32, 1.1234)); | 1373 | try testFmt("f32: 1.1", "f32: {d:.1}", .{@as(f32, 1.1234)}); |
| 1372 | try testFmt("f32: 1234.57", "f32: {d:.2}", @as(f32, 1234.567)); | 1374 | try testFmt("f32: 1234.57", "f32: {d:.2}", .{@as(f32, 1234.567)}); |
| 1373 | // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64). | 1375 | // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64). |
| 1374 | // -11.12339... is rounded back up to -11.1234 | 1376 | // -11.12339... is rounded back up to -11.1234 |
| 1375 | try testFmt("f32: -11.1234", "f32: {d:.4}", @as(f32, -11.1234)); | 1377 | try testFmt("f32: -11.1234", "f32: {d:.4}", .{@as(f32, -11.1234)}); |
| 1376 | try testFmt("f32: 91.12345", "f32: {d:.5}", @as(f32, 91.12345)); | 1378 | try testFmt("f32: 91.12345", "f32: {d:.5}", .{@as(f32, 91.12345)}); |
| 1377 | try testFmt("f64: 91.1234567890", "f64: {d:.10}", @as(f64, 91.12345678901235)); | 1379 | try testFmt("f64: 91.1234567890", "f64: {d:.10}", .{@as(f64, 91.12345678901235)}); |
| 1378 | try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 0.0)); | 1380 | try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 0.0)}); |
| 1379 | try testFmt("f64: 6", "f64: {d:.0}", @as(f64, 5.700)); | 1381 | try testFmt("f64: 6", "f64: {d:.0}", .{@as(f64, 5.700)}); |
| 1380 | try testFmt("f64: 10.0", "f64: {d:.1}", @as(f64, 9.999)); | 1382 | try testFmt("f64: 10.0", "f64: {d:.1}", .{@as(f64, 9.999)}); |
| 1381 | try testFmt("f64: 1.000", "f64: {d:.3}", @as(f64, 1.0)); | 1383 | try testFmt("f64: 1.000", "f64: {d:.3}", .{@as(f64, 1.0)}); |
| 1382 | try testFmt("f64: 0.00030000", "f64: {d:.8}", @as(f64, 0.0003)); | 1384 | try testFmt("f64: 0.00030000", "f64: {d:.8}", .{@as(f64, 0.0003)}); |
| 1383 | try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 1.40130e-45)); | 1385 | try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 1.40130e-45)}); |
| 1384 | try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 9.999960e-40)); | 1386 | try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 9.999960e-40)}); |
| 1385 | } | 1387 | } |
| 1386 | 1388 | ||
| 1387 | test "float.libc.sanity" { | 1389 | test "float.libc.sanity" { |
| ... | @@ -1389,22 +1391,22 @@ test "float.libc.sanity" { | ... | @@ -1389,22 +1391,22 @@ test "float.libc.sanity" { |
| 1389 | // TODO https://github.com/ziglang/zig/issues/3289 | 1391 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1390 | return error.SkipZigTest; | 1392 | return error.SkipZigTest; |
| 1391 | } | 1393 | } |
| 1392 | try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 916964781)))); | 1394 | try testFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 916964781)))}); |
| 1393 | try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 925353389)))); | 1395 | try testFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 925353389)))}); |
| 1394 | try testFmt("f64: 0.10000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1036831278)))); | 1396 | try testFmt("f64: 0.10000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1036831278)))}); |
| 1395 | try testFmt("f64: 1.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1065353133)))); | 1397 | try testFmt("f64: 1.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1065353133)))}); |
| 1396 | try testFmt("f64: 10.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1092616192)))); | 1398 | try testFmt("f64: 10.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1092616192)))}); |
| 1397 | 1399 | ||
| 1398 | // libc differences | 1400 | // libc differences |
| 1399 | // | 1401 | // |
| 1400 | // This is 0.015625 exactly according to gdb. We thus round down, | 1402 | // This is 0.015625 exactly according to gdb. We thus round down, |
| 1401 | // however glibc rounds up for some reason. This occurs for all | 1403 | // however glibc rounds up for some reason. This occurs for all |
| 1402 | // floats of the form x.yyyy25 on a precision point. | 1404 | // floats of the form x.yyyy25 on a precision point. |
| 1403 | try testFmt("f64: 0.01563", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1015021568)))); | 1405 | try testFmt("f64: 0.01563", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1015021568)))}); |
| 1404 | // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3 | 1406 | // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3 |
| 1405 | // also rounds to 630 so I'm inclined to believe libc is not | 1407 | // also rounds to 630 so I'm inclined to believe libc is not |
| 1406 | // optimal here. | 1408 | // optimal here. |
| 1407 | try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1518338049)))); | 1409 | try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1518338049)))}); |
| 1408 | } | 1410 | } |
| 1409 | 1411 | ||
| 1410 | test "custom" { | 1412 | test "custom" { |
| ... | @@ -1422,9 +1424,9 @@ test "custom" { | ... | @@ -1422,9 +1424,9 @@ test "custom" { |
| 1422 | output: fn (@typeOf(context), []const u8) Errors!void, | 1424 | output: fn (@typeOf(context), []const u8) Errors!void, |
| 1423 | ) Errors!void { | 1425 | ) Errors!void { |
| 1424 | if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) { | 1426 | if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) { |
| 1425 | return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", self.x, self.y); | 1427 | return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y }); |
| 1426 | } else if (comptime std.mem.eql(u8, fmt, "d")) { | 1428 | } else if (comptime std.mem.eql(u8, fmt, "d")) { |
| 1427 | return std.fmt.format(context, Errors, output, "{d:.3}x{d:.3}", self.x, self.y); | 1429 | return std.fmt.format(context, Errors, output, "{d:.3}x{d:.3}", .{ self.x, self.y }); |
| 1428 | } else { | 1430 | } else { |
| 1429 | @compileError("Unknown format character: '" ++ fmt ++ "'"); | 1431 | @compileError("Unknown format character: '" ++ fmt ++ "'"); |
| 1430 | } | 1432 | } |
| ... | @@ -1436,12 +1438,12 @@ test "custom" { | ... | @@ -1436,12 +1438,12 @@ test "custom" { |
| 1436 | .x = 10.2, | 1438 | .x = 10.2, |
| 1437 | .y = 2.22, | 1439 | .y = 2.22, |
| 1438 | }; | 1440 | }; |
| 1439 | try testFmt("point: (10.200,2.220)\n", "point: {}\n", &value); | 1441 | try testFmt("point: (10.200,2.220)\n", "point: {}\n", .{&value}); |
| 1440 | try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", &value); | 1442 | try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", .{&value}); |
| 1441 | 1443 | ||
| 1442 | // same thing but not passing a pointer | 1444 | // same thing but not passing a pointer |
| 1443 | try testFmt("point: (10.200,2.220)\n", "point: {}\n", value); | 1445 | try testFmt("point: (10.200,2.220)\n", "point: {}\n", .{value}); |
| 1444 | try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", value); | 1446 | try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", .{value}); |
| 1445 | } | 1447 | } |
| 1446 | 1448 | ||
| 1447 | test "struct" { | 1449 | test "struct" { |
| ... | @@ -1455,7 +1457,7 @@ test "struct" { | ... | @@ -1455,7 +1457,7 @@ test "struct" { |
| 1455 | .b = error.Unused, | 1457 | .b = error.Unused, |
| 1456 | }; | 1458 | }; |
| 1457 | 1459 | ||
| 1458 | try testFmt("S{ .a = 456, .b = error.Unused }", "{}", inst); | 1460 | try testFmt("S{ .a = 456, .b = error.Unused }", "{}", .{inst}); |
| 1459 | } | 1461 | } |
| 1460 | 1462 | ||
| 1461 | test "union" { | 1463 | test "union" { |
| ... | @@ -1478,13 +1480,13 @@ test "union" { | ... | @@ -1478,13 +1480,13 @@ test "union" { |
| 1478 | const uu_inst = UU{ .int = 456 }; | 1480 | const uu_inst = UU{ .int = 456 }; |
| 1479 | const eu_inst = EU{ .float = 321.123 }; | 1481 | const eu_inst = EU{ .float = 321.123 }; |
| 1480 | 1482 | ||
| 1481 | try testFmt("TU{ .int = 123 }", "{}", tu_inst); | 1483 | try testFmt("TU{ .int = 123 }", "{}", .{tu_inst}); |
| 1482 | 1484 | ||
| 1483 | var buf: [100]u8 = undefined; | 1485 | var buf: [100]u8 = undefined; |
| 1484 | const uu_result = try bufPrint(buf[0..], "{}", uu_inst); | 1486 | const uu_result = try bufPrint(buf[0..], "{}", .{uu_inst}); |
| 1485 | std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@")); | 1487 | std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@")); |
| 1486 | 1488 | ||
| 1487 | const eu_result = try bufPrint(buf[0..], "{}", eu_inst); | 1489 | const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst}); |
| 1488 | std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@")); | 1490 | std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@")); |
| 1489 | } | 1491 | } |
| 1490 | 1492 | ||
| ... | @@ -1497,7 +1499,7 @@ test "enum" { | ... | @@ -1497,7 +1499,7 @@ test "enum" { |
| 1497 | 1499 | ||
| 1498 | const inst = E.Two; | 1500 | const inst = E.Two; |
| 1499 | 1501 | ||
| 1500 | try testFmt("E.Two", "{}", inst); | 1502 | try testFmt("E.Two", "{}", .{inst}); |
| 1501 | } | 1503 | } |
| 1502 | 1504 | ||
| 1503 | test "struct.self-referential" { | 1505 | test "struct.self-referential" { |
| ... | @@ -1511,7 +1513,7 @@ test "struct.self-referential" { | ... | @@ -1511,7 +1513,7 @@ test "struct.self-referential" { |
| 1511 | }; | 1513 | }; |
| 1512 | inst.a = &inst; | 1514 | inst.a = &inst; |
| 1513 | 1515 | ||
| 1514 | try testFmt("S{ .a = S{ .a = S{ .a = S{ ... } } } }", "{}", inst); | 1516 | try testFmt("S{ .a = S{ .a = S{ .a = S{ ... } } } }", "{}", .{inst}); |
| 1515 | } | 1517 | } |
| 1516 | 1518 | ||
| 1517 | test "struct.zero-size" { | 1519 | test "struct.zero-size" { |
| ... | @@ -1526,30 +1528,30 @@ test "struct.zero-size" { | ... | @@ -1526,30 +1528,30 @@ test "struct.zero-size" { |
| 1526 | const a = A{}; | 1528 | const a = A{}; |
| 1527 | const b = B{ .a = a, .c = 0 }; | 1529 | const b = B{ .a = a, .c = 0 }; |
| 1528 | 1530 | ||
| 1529 | try testFmt("B{ .a = A{ }, .c = 0 }", "{}", b); | 1531 | try testFmt("B{ .a = A{ }, .c = 0 }", "{}", .{b}); |
| 1530 | } | 1532 | } |
| 1531 | 1533 | ||
| 1532 | test "bytes.hex" { | 1534 | test "bytes.hex" { |
| 1533 | const some_bytes = "\xCA\xFE\xBA\xBE"; | 1535 | const some_bytes = "\xCA\xFE\xBA\xBE"; |
| 1534 | try testFmt("lowercase: cafebabe\n", "lowercase: {x}\n", some_bytes); | 1536 | try testFmt("lowercase: cafebabe\n", "lowercase: {x}\n", .{some_bytes}); |
| 1535 | try testFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", some_bytes); | 1537 | try testFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", .{some_bytes}); |
| 1536 | //Test Slices | 1538 | //Test Slices |
| 1537 | try testFmt("uppercase: CAFE\n", "uppercase: {X}\n", some_bytes[0..2]); | 1539 | try testFmt("uppercase: CAFE\n", "uppercase: {X}\n", .{some_bytes[0..2]}); |
| 1538 | try testFmt("lowercase: babe\n", "lowercase: {x}\n", some_bytes[2..]); | 1540 | try testFmt("lowercase: babe\n", "lowercase: {x}\n", .{some_bytes[2..]}); |
| 1539 | const bytes_with_zeros = "\x00\x0E\xBA\xBE"; | 1541 | const bytes_with_zeros = "\x00\x0E\xBA\xBE"; |
| 1540 | try testFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", bytes_with_zeros); | 1542 | try testFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{bytes_with_zeros}); |
| 1541 | } | 1543 | } |
| 1542 | 1544 | ||
| 1543 | fn testFmt(expected: []const u8, comptime template: []const u8, args: ...) !void { | 1545 | fn testFmt(expected: []const u8, comptime template: []const u8, args: var) !void { |
| 1544 | var buf: [100]u8 = undefined; | 1546 | var buf: [100]u8 = undefined; |
| 1545 | const result = try bufPrint(buf[0..], template, args); | 1547 | const result = try bufPrint(buf[0..], template, args); |
| 1546 | if (mem.eql(u8, result, expected)) return; | 1548 | if (mem.eql(u8, result, expected)) return; |
| 1547 | 1549 | ||
| 1548 | std.debug.warn("\n====== expected this output: =========\n"); | 1550 | std.debug.warn("\n====== expected this output: =========\n", .{}); |
| 1549 | std.debug.warn("{}", expected); | 1551 | std.debug.warn("{}", .{expected}); |
| 1550 | std.debug.warn("\n======== instead found this: =========\n"); | 1552 | std.debug.warn("\n======== instead found this: =========\n", .{}); |
| 1551 | std.debug.warn("{}", result); | 1553 | std.debug.warn("{}", .{result}); |
| 1552 | std.debug.warn("\n======================================\n"); | 1554 | std.debug.warn("\n======================================\n", .{}); |
| 1553 | return error.TestFailed; | 1555 | return error.TestFailed; |
| 1554 | } | 1556 | } |
| 1555 | 1557 | ||
| ... | @@ -1602,7 +1604,7 @@ test "hexToBytes" { | ... | @@ -1602,7 +1604,7 @@ test "hexToBytes" { |
| 1602 | const test_hex_str = "909A312BB12ED1F819B3521AC4C1E896F2160507FFC1C8381E3B07BB16BD1706"; | 1604 | const test_hex_str = "909A312BB12ED1F819B3521AC4C1E896F2160507FFC1C8381E3B07BB16BD1706"; |
| 1603 | var pb: [32]u8 = undefined; | 1605 | var pb: [32]u8 = undefined; |
| 1604 | try hexToBytes(pb[0..], test_hex_str); | 1606 | try hexToBytes(pb[0..], test_hex_str); |
| 1605 | try testFmt(test_hex_str, "{X}", pb); | 1607 | try testFmt(test_hex_str, "{X}", .{pb}); |
| 1606 | } | 1608 | } |
| 1607 | 1609 | ||
| 1608 | test "formatIntValue with comptime_int" { | 1610 | test "formatIntValue with comptime_int" { |
| ... | @@ -1628,7 +1630,7 @@ test "formatType max_depth" { | ... | @@ -1628,7 +1630,7 @@ test "formatType max_depth" { |
| 1628 | output: fn (@typeOf(context), []const u8) Errors!void, | 1630 | output: fn (@typeOf(context), []const u8) Errors!void, |
| 1629 | ) Errors!void { | 1631 | ) Errors!void { |
| 1630 | if (fmt.len == 0) { | 1632 | if (fmt.len == 0) { |
| 1631 | return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", self.x, self.y); | 1633 | return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y }); |
| 1632 | } else { | 1634 | } else { |
| 1633 | @compileError("Unknown format string: '" ++ fmt ++ "'"); | 1635 | @compileError("Unknown format string: '" ++ fmt ++ "'"); |
| 1634 | } | 1636 | } |
| ... | @@ -1680,17 +1682,17 @@ test "formatType max_depth" { | ... | @@ -1680,17 +1682,17 @@ test "formatType max_depth" { |
| 1680 | } | 1682 | } |
| 1681 | 1683 | ||
| 1682 | test "positional" { | 1684 | test "positional" { |
| 1683 | try testFmt("2 1 0", "{2} {1} {0}", @as(usize, 0), @as(usize, 1), @as(usize, 2)); | 1685 | try testFmt("2 1 0", "{2} {1} {0}", .{ @as(usize, 0), @as(usize, 1), @as(usize, 2) }); |
| 1684 | try testFmt("2 1 0", "{2} {1} {}", @as(usize, 0), @as(usize, 1), @as(usize, 2)); | 1686 | try testFmt("2 1 0", "{2} {1} {}", .{ @as(usize, 0), @as(usize, 1), @as(usize, 2) }); |
| 1685 | try testFmt("0 0", "{0} {0}", @as(usize, 0)); | 1687 | try testFmt("0 0", "{0} {0}", .{@as(usize, 0)}); |
| 1686 | try testFmt("0 1", "{} {1}", @as(usize, 0), @as(usize, 1)); | 1688 | try testFmt("0 1", "{} {1}", .{ @as(usize, 0), @as(usize, 1) }); |
| 1687 | try testFmt("1 0 0 1", "{1} {} {0} {}", @as(usize, 0), @as(usize, 1)); | 1689 | try testFmt("1 0 0 1", "{1} {} {0} {}", .{ @as(usize, 0), @as(usize, 1) }); |
| 1688 | } | 1690 | } |
| 1689 | 1691 | ||
| 1690 | test "positional with specifier" { | 1692 | test "positional with specifier" { |
| 1691 | try testFmt("10.0", "{0d:.1}", @as(f64, 9.999)); | 1693 | try testFmt("10.0", "{0d:.1}", .{@as(f64, 9.999)}); |
| 1692 | } | 1694 | } |
| 1693 | 1695 | ||
| 1694 | test "positional/alignment/width/precision" { | 1696 | test "positional/alignment/width/precision" { |
| 1695 | try testFmt("10.0", "{0d: >3.1}", @as(f64, 9.999)); | 1697 | try testFmt("10.0", "{0d: >3.1}", .{@as(f64, 9.999)}); |
| 1696 | } | 1698 | } |
lib/std/hash/benchmark.zig+1-1| ... | @@ -164,7 +164,7 @@ fn usage() void { | ... | @@ -164,7 +164,7 @@ fn usage() void { |
| 164 | \\ --iterative-only | 164 | \\ --iterative-only |
| 165 | \\ --help | 165 | \\ --help |
| 166 | \\ | 166 | \\ |
| 167 | ); | 167 | , .{}); |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | fn mode(comptime x: comptime_int) comptime_int { | 170 | fn mode(comptime x: comptime_int) comptime_int { |
lib/std/http/headers.zig+1-1| ... | @@ -610,5 +610,5 @@ test "Headers.format" { | ... | @@ -610,5 +610,5 @@ test "Headers.format" { |
| 610 | \\foo: bar | 610 | \\foo: bar |
| 611 | \\cookie: somevalue | 611 | \\cookie: somevalue |
| 612 | \\ | 612 | \\ |
| 613 | , try std.fmt.bufPrint(buf[0..], "{}", h)); | 613 | , try std.fmt.bufPrint(buf[0..], "{}", .{h})); |
| 614 | } | 614 | } |
lib/std/io.zig+1-1| ... | @@ -492,7 +492,7 @@ test "io.SliceOutStream" { | ... | @@ -492,7 +492,7 @@ test "io.SliceOutStream" { |
| 492 | var slice_stream = SliceOutStream.init(buf[0..]); | 492 | var slice_stream = SliceOutStream.init(buf[0..]); |
| 493 | const stream = &slice_stream.stream; | 493 | const stream = &slice_stream.stream; |
| 494 | 494 | ||
| 495 | try stream.print("{}{}!", "Hello", "World"); | 495 | try stream.print("{}{}!", .{ "Hello", "World" }); |
| 496 | testing.expectEqualSlices(u8, "HelloWorld!", slice_stream.getWritten()); | 496 | testing.expectEqualSlices(u8, "HelloWorld!", slice_stream.getWritten()); |
| 497 | } | 497 | } |
| 498 | 498 |
lib/std/io/out_stream.zig+1-1| ... | @@ -35,7 +35,7 @@ pub fn OutStream(comptime WriteError: type) type { | ... | @@ -35,7 +35,7 @@ pub fn OutStream(comptime WriteError: type) type { |
| 35 | } | 35 | } |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | pub fn print(self: *Self, comptime format: []const u8, args: ...) Error!void { | 38 | pub fn print(self: *Self, comptime format: []const u8, args: var) Error!void { |
| 39 | return std.fmt.format(self, Error, self.writeFn, format, args); | 39 | return std.fmt.format(self, Error, self.writeFn, format, args); |
| 40 | } | 40 | } |
| 41 | 41 |
lib/std/io/test.zig+4-4| ... | @@ -27,9 +27,9 @@ test "write a file, read it, then delete it" { | ... | @@ -27,9 +27,9 @@ test "write a file, read it, then delete it" { |
| 27 | var file_out_stream = file.outStream(); | 27 | var file_out_stream = file.outStream(); |
| 28 | var buf_stream = io.BufferedOutStream(File.WriteError).init(&file_out_stream.stream); | 28 | var buf_stream = io.BufferedOutStream(File.WriteError).init(&file_out_stream.stream); |
| 29 | const st = &buf_stream.stream; | 29 | const st = &buf_stream.stream; |
| 30 | try st.print("begin"); | 30 | try st.print("begin", .{}); |
| 31 | try st.write(data[0..]); | 31 | try st.write(data[0..]); |
| 32 | try st.print("end"); | 32 | try st.print("end", .{}); |
| 33 | try buf_stream.flush(); | 33 | try buf_stream.flush(); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| ... | @@ -72,7 +72,7 @@ test "BufferOutStream" { | ... | @@ -72,7 +72,7 @@ test "BufferOutStream" { |
| 72 | 72 | ||
| 73 | const x: i32 = 42; | 73 | const x: i32 = 42; |
| 74 | const y: i32 = 1234; | 74 | const y: i32 = 1234; |
| 75 | try buf_stream.print("x: {}\ny: {}\n", x, y); | 75 | try buf_stream.print("x: {}\ny: {}\n", .{ x, y }); |
| 76 | 76 | ||
| 77 | expect(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n")); | 77 | expect(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n")); |
| 78 | } | 78 | } |
| ... | @@ -605,7 +605,7 @@ test "c out stream" { | ... | @@ -605,7 +605,7 @@ test "c out stream" { |
| 605 | } | 605 | } |
| 606 | 606 | ||
| 607 | const out_stream = &io.COutStream.init(out_file).stream; | 607 | const out_stream = &io.COutStream.init(out_file).stream; |
| 608 | try out_stream.print("hi: {}\n", @as(i32, 123)); | 608 | try out_stream.print("hi: {}\n", .{@as(i32, 123)}); |
| 609 | } | 609 | } |
| 610 | 610 | ||
| 611 | test "File seek ops" { | 611 | test "File seek ops" { |
lib/std/json/write_stream.zig+4-4| ... | @@ -158,24 +158,24 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { | ... | @@ -158,24 +158,24 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { |
| 158 | switch (@typeInfo(@typeOf(value))) { | 158 | switch (@typeInfo(@typeOf(value))) { |
| 159 | .Int => |info| { | 159 | .Int => |info| { |
| 160 | if (info.bits < 53) { | 160 | if (info.bits < 53) { |
| 161 | try self.stream.print("{}", value); | 161 | try self.stream.print("{}", .{value}); |
| 162 | self.popState(); | 162 | self.popState(); |
| 163 | return; | 163 | return; |
| 164 | } | 164 | } |
| 165 | if (value < 4503599627370496 and (!info.is_signed or value > -4503599627370496)) { | 165 | if (value < 4503599627370496 and (!info.is_signed or value > -4503599627370496)) { |
| 166 | try self.stream.print("{}", value); | 166 | try self.stream.print("{}", .{value}); |
| 167 | self.popState(); | 167 | self.popState(); |
| 168 | return; | 168 | return; |
| 169 | } | 169 | } |
| 170 | }, | 170 | }, |
| 171 | .Float => if (@floatCast(f64, value) == value) { | 171 | .Float => if (@floatCast(f64, value) == value) { |
| 172 | try self.stream.print("{}", value); | 172 | try self.stream.print("{}", .{value}); |
| 173 | self.popState(); | 173 | self.popState(); |
| 174 | return; | 174 | return; |
| 175 | }, | 175 | }, |
| 176 | else => {}, | 176 | else => {}, |
| 177 | } | 177 | } |
| 178 | try self.stream.print("\"{}\"", value); | 178 | try self.stream.print("\"{}\"", .{value}); |
| 179 | self.popState(); | 179 | self.popState(); |
| 180 | } | 180 | } |
| 181 | 181 |
lib/std/math/big/int.zig+2-2| ... | @@ -180,9 +180,9 @@ pub const Int = struct { | ... | @@ -180,9 +180,9 @@ pub const Int = struct { |
| 180 | 180 | ||
| 181 | pub fn dump(self: Int) void { | 181 | pub fn dump(self: Int) void { |
| 182 | for (self.limbs) |limb| { | 182 | for (self.limbs) |limb| { |
| 183 | debug.warn("{x} ", limb); | 183 | debug.warn("{x} ", .{limb}); |
| 184 | } | 184 | } |
| 185 | debug.warn("\n"); | 185 | debug.warn("\n", .{}); |
| 186 | } | 186 | } |
| 187 | 187 | ||
| 188 | /// Negate the sign of an Int. | 188 | /// Negate the sign of an Int. |
lib/std/net.zig+7-15| ... | @@ -277,32 +277,24 @@ pub const Address = extern union { | ... | @@ -277,32 +277,24 @@ pub const Address = extern union { |
| 277 | os.AF_INET => { | 277 | os.AF_INET => { |
| 278 | const port = mem.bigToNative(u16, self.in.port); | 278 | const port = mem.bigToNative(u16, self.in.port); |
| 279 | const bytes = @ptrCast(*const [4]u8, &self.in.addr); | 279 | const bytes = @ptrCast(*const [4]u8, &self.in.addr); |
| 280 | try std.fmt.format( | 280 | try std.fmt.format(context, Errors, output, "{}.{}.{}.{}:{}", .{ |
| 281 | context, | ||
| 282 | Errors, | ||
| 283 | output, | ||
| 284 | "{}.{}.{}.{}:{}", | ||
| 285 | bytes[0], | 281 | bytes[0], |
| 286 | bytes[1], | 282 | bytes[1], |
| 287 | bytes[2], | 283 | bytes[2], |
| 288 | bytes[3], | 284 | bytes[3], |
| 289 | port, | 285 | port, |
| 290 | ); | 286 | }); |
| 291 | }, | 287 | }, |
| 292 | os.AF_INET6 => { | 288 | os.AF_INET6 => { |
| 293 | const port = mem.bigToNative(u16, self.in6.port); | 289 | const port = mem.bigToNative(u16, self.in6.port); |
| 294 | if (mem.eql(u8, self.in6.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) { | 290 | if (mem.eql(u8, self.in6.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) { |
| 295 | try std.fmt.format( | 291 | try std.fmt.format(context, Errors, output, "[::ffff:{}.{}.{}.{}]:{}", .{ |
| 296 | context, | ||
| 297 | Errors, | ||
| 298 | output, | ||
| 299 | "[::ffff:{}.{}.{}.{}]:{}", | ||
| 300 | self.in6.addr[12], | 292 | self.in6.addr[12], |
| 301 | self.in6.addr[13], | 293 | self.in6.addr[13], |
| 302 | self.in6.addr[14], | 294 | self.in6.addr[14], |
| 303 | self.in6.addr[15], | 295 | self.in6.addr[15], |
| 304 | port, | 296 | port, |
| 305 | ); | 297 | }); |
| 306 | return; | 298 | return; |
| 307 | } | 299 | } |
| 308 | const big_endian_parts = @ptrCast(*align(1) const [8]u16, &self.in6.addr); | 300 | const big_endian_parts = @ptrCast(*align(1) const [8]u16, &self.in6.addr); |
| ... | @@ -327,19 +319,19 @@ pub const Address = extern union { | ... | @@ -327,19 +319,19 @@ pub const Address = extern union { |
| 327 | } | 319 | } |
| 328 | continue; | 320 | continue; |
| 329 | } | 321 | } |
| 330 | try std.fmt.format(context, Errors, output, "{x}", native_endian_parts[i]); | 322 | try std.fmt.format(context, Errors, output, "{x}", .{native_endian_parts[i]}); |
| 331 | if (i != native_endian_parts.len - 1) { | 323 | if (i != native_endian_parts.len - 1) { |
| 332 | try output(context, ":"); | 324 | try output(context, ":"); |
| 333 | } | 325 | } |
| 334 | } | 326 | } |
| 335 | try std.fmt.format(context, Errors, output, "]:{}", port); | 327 | try std.fmt.format(context, Errors, output, "]:{}", .{port}); |
| 336 | }, | 328 | }, |
| 337 | os.AF_UNIX => { | 329 | os.AF_UNIX => { |
| 338 | if (!has_unix_sockets) { | 330 | if (!has_unix_sockets) { |
| 339 | unreachable; | 331 | unreachable; |
| 340 | } | 332 | } |
| 341 | 333 | ||
| 342 | try std.fmt.format(context, Errors, output, "{}", &self.un.path); | 334 | try std.fmt.format(context, Errors, output, "{}", .{&self.un.path}); |
| 343 | }, | 335 | }, |
| 344 | else => unreachable, | 336 | else => unreachable, |
| 345 | } | 337 | } |
lib/std/net/test.zig+3-3| ... | @@ -29,7 +29,7 @@ test "parse and render IPv6 addresses" { | ... | @@ -29,7 +29,7 @@ test "parse and render IPv6 addresses" { |
| 29 | }; | 29 | }; |
| 30 | for (ips) |ip, i| { | 30 | for (ips) |ip, i| { |
| 31 | var addr = net.Address.parseIp6(ip, 0) catch unreachable; | 31 | var addr = net.Address.parseIp6(ip, 0) catch unreachable; |
| 32 | var newIp = std.fmt.bufPrint(buffer[0..], "{}", addr) catch unreachable; | 32 | var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; |
| 33 | std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3])); | 33 | std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3])); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| ... | @@ -51,7 +51,7 @@ test "parse and render IPv4 addresses" { | ... | @@ -51,7 +51,7 @@ test "parse and render IPv4 addresses" { |
| 51 | "127.0.0.1", | 51 | "127.0.0.1", |
| 52 | }) |ip| { | 52 | }) |ip| { |
| 53 | var addr = net.Address.parseIp4(ip, 0) catch unreachable; | 53 | var addr = net.Address.parseIp4(ip, 0) catch unreachable; |
| 54 | var newIp = std.fmt.bufPrint(buffer[0..], "{}", addr) catch unreachable; | 54 | var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; |
| 55 | std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2])); | 55 | std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2])); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| ... | @@ -118,5 +118,5 @@ fn testServer(server: *net.StreamServer) anyerror!void { | ... | @@ -118,5 +118,5 @@ fn testServer(server: *net.StreamServer) anyerror!void { |
| 118 | var client = try server.accept(); | 118 | var client = try server.accept(); |
| 119 | 119 | ||
| 120 | const stream = &client.file.outStream().stream; | 120 | const stream = &client.file.outStream().stream; |
| 121 | try stream.print("hello from server\n"); | 121 | try stream.print("hello from server\n", .{}); |
| 122 | } | 122 | } |
lib/std/os.zig+2-2| ... | @@ -2603,7 +2603,7 @@ pub fn realpathC(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP | ... | @@ -2603,7 +2603,7 @@ pub fn realpathC(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP |
| 2603 | defer close(fd); | 2603 | defer close(fd); |
| 2604 | 2604 | ||
| 2605 | var procfs_buf: ["/proc/self/fd/-2147483648".len:0]u8 = undefined; | 2605 | var procfs_buf: ["/proc/self/fd/-2147483648".len:0]u8 = undefined; |
| 2606 | const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{}\x00", fd) catch unreachable; | 2606 | const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{}\x00", .{fd}) catch unreachable; |
| 2607 | 2607 | ||
| 2608 | return readlinkC(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer); | 2608 | return readlinkC(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer); |
| 2609 | } | 2609 | } |
| ... | @@ -2832,7 +2832,7 @@ pub const UnexpectedError = error{ | ... | @@ -2832,7 +2832,7 @@ pub const UnexpectedError = error{ |
| 2832 | /// and you get an unexpected error. | 2832 | /// and you get an unexpected error. |
| 2833 | pub fn unexpectedErrno(err: usize) UnexpectedError { | 2833 | pub fn unexpectedErrno(err: usize) UnexpectedError { |
| 2834 | if (unexpected_error_tracing) { | 2834 | if (unexpected_error_tracing) { |
| 2835 | std.debug.warn("unexpected errno: {}\n", err); | 2835 | std.debug.warn("unexpected errno: {}\n", .{err}); |
| 2836 | std.debug.dumpCurrentStackTrace(null); | 2836 | std.debug.dumpCurrentStackTrace(null); |
| 2837 | } | 2837 | } |
| 2838 | return error.Unexpected; | 2838 | return error.Unexpected; |
lib/std/os/windows.zig+2-2| ... | @@ -1039,7 +1039,7 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError { | ... | @@ -1039,7 +1039,7 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError { |
| 1039 | var buf_u8: [614]u8 = undefined; | 1039 | var buf_u8: [614]u8 = undefined; |
| 1040 | var len = kernel32.FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, null, err, MAKELANGID(LANG.NEUTRAL, SUBLANG.DEFAULT), buf_u16[0..].ptr, buf_u16.len / @sizeOf(TCHAR), null); | 1040 | var len = kernel32.FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, null, err, MAKELANGID(LANG.NEUTRAL, SUBLANG.DEFAULT), buf_u16[0..].ptr, buf_u16.len / @sizeOf(TCHAR), null); |
| 1041 | _ = std.unicode.utf16leToUtf8(&buf_u8, buf_u16[0..len]) catch unreachable; | 1041 | _ = std.unicode.utf16leToUtf8(&buf_u8, buf_u16[0..len]) catch unreachable; |
| 1042 | std.debug.warn("error.Unexpected: GetLastError({}): {}\n", err, buf_u8[0..len]); | 1042 | std.debug.warn("error.Unexpected: GetLastError({}): {}\n", .{ err, buf_u8[0..len] }); |
| 1043 | std.debug.dumpCurrentStackTrace(null); | 1043 | std.debug.dumpCurrentStackTrace(null); |
| 1044 | } | 1044 | } |
| 1045 | return error.Unexpected; | 1045 | return error.Unexpected; |
| ... | @@ -1053,7 +1053,7 @@ pub fn unexpectedWSAError(err: c_int) std.os.UnexpectedError { | ... | @@ -1053,7 +1053,7 @@ pub fn unexpectedWSAError(err: c_int) std.os.UnexpectedError { |
| 1053 | /// and you get an unexpected status. | 1053 | /// and you get an unexpected status. |
| 1054 | pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError { | 1054 | pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError { |
| 1055 | if (std.os.unexpected_error_tracing) { | 1055 | if (std.os.unexpected_error_tracing) { |
| 1056 | std.debug.warn("error.Unexpected NTSTATUS=0x{x}\n", status); | 1056 | std.debug.warn("error.Unexpected NTSTATUS=0x{x}\n", .{status}); |
| 1057 | std.debug.dumpCurrentStackTrace(null); | 1057 | std.debug.dumpCurrentStackTrace(null); |
| 1058 | } | 1058 | } |
| 1059 | return error.Unexpected; | 1059 | return error.Unexpected; |
lib/std/os/zen.zig deleted-260| ... | @@ -1,260 +0,0 @@ | ||
| 1 | const std = @import("../std.zig"); | ||
| 2 | const assert = std.debug.assert; | ||
| 3 | |||
| 4 | ////////////////////////// | ||
| 5 | //// IPC structures //// | ||
| 6 | ////////////////////////// | ||
| 7 | |||
| 8 | pub const Message = struct { | ||
| 9 | sender: MailboxId, | ||
| 10 | receiver: MailboxId, | ||
| 11 | code: usize, | ||
| 12 | args: [5]usize, | ||
| 13 | payload: ?[]const u8, | ||
| 14 | |||
| 15 | pub fn from(mailbox_id: MailboxId) Message { | ||
| 16 | return Message{ | ||
| 17 | .sender = MailboxId.Undefined, | ||
| 18 | .receiver = mailbox_id, | ||
| 19 | .code = undefined, | ||
| 20 | .args = undefined, | ||
| 21 | .payload = null, | ||
| 22 | }; | ||
| 23 | } | ||
| 24 | |||
| 25 | pub fn to(mailbox_id: MailboxId, msg_code: usize, args: ...) Message { | ||
| 26 | var message = Message{ | ||
| 27 | .sender = MailboxId.This, | ||
| 28 | .receiver = mailbox_id, | ||
| 29 | .code = msg_code, | ||
| 30 | .args = undefined, | ||
| 31 | .payload = null, | ||
| 32 | }; | ||
| 33 | |||
| 34 | assert(args.len <= message.args.len); | ||
| 35 | comptime var i = 0; | ||
| 36 | inline while (i < args.len) : (i += 1) { | ||
| 37 | message.args[i] = args[i]; | ||
| 38 | } | ||
| 39 | |||
| 40 | return message; | ||
| 41 | } | ||
| 42 | |||
| 43 | pub fn as(self: Message, sender: MailboxId) Message { | ||
| 44 | var message = self; | ||
| 45 | message.sender = sender; | ||
| 46 | return message; | ||
| 47 | } | ||
| 48 | |||
| 49 | pub fn withPayload(self: Message, payload: []const u8) Message { | ||
| 50 | var message = self; | ||
| 51 | message.payload = payload; | ||
| 52 | return message; | ||
| 53 | } | ||
| 54 | }; | ||
| 55 | |||
| 56 | pub const MailboxId = union(enum) { | ||
| 57 | Undefined, | ||
| 58 | This, | ||
| 59 | Kernel, | ||
| 60 | Port: u16, | ||
| 61 | Thread: u16, | ||
| 62 | }; | ||
| 63 | |||
| 64 | ////////////////////////////////////// | ||
| 65 | //// Ports reserved for servers //// | ||
| 66 | ////////////////////////////////////// | ||
| 67 | |||
| 68 | pub const Server = struct { | ||
| 69 | pub const Keyboard = MailboxId{ .Port = 0 }; | ||
| 70 | pub const Terminal = MailboxId{ .Port = 1 }; | ||
| 71 | }; | ||
| 72 | |||
| 73 | //////////////////////// | ||
| 74 | //// POSIX things //// | ||
| 75 | //////////////////////// | ||
| 76 | |||
| 77 | // Standard streams. | ||
| 78 | pub const STDIN_FILENO = 0; | ||
| 79 | pub const STDOUT_FILENO = 1; | ||
| 80 | pub const STDERR_FILENO = 2; | ||
| 81 | |||
| 82 | // FIXME: let's borrow Linux's error numbers for now. | ||
| 83 | usingnamespace @import("bits/linux/errno-generic.zig"); | ||
| 84 | // Get the errno from a syscall return value, or 0 for no error. | ||
| 85 | pub fn getErrno(r: usize) usize { | ||
| 86 | const signed_r = @bitCast(isize, r); | ||
| 87 | return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0; | ||
| 88 | } | ||
| 89 | |||
| 90 | // TODO: implement this correctly. | ||
| 91 | pub fn read(fd: i32, buf: [*]u8, count: usize) usize { | ||
| 92 | switch (fd) { | ||
| 93 | STDIN_FILENO => { | ||
| 94 | var i: usize = 0; | ||
| 95 | while (i < count) : (i += 1) { | ||
| 96 | send(&Message.to(Server.Keyboard, 0)); | ||
| 97 | |||
| 98 | // FIXME: we should be certain that we are receiving from Keyboard. | ||
| 99 | var message = Message.from(MailboxId.This); | ||
| 100 | receive(&message); | ||
| 101 | |||
| 102 | buf[i] = @intCast(u8, message.args[0]); | ||
| 103 | } | ||
| 104 | }, | ||
| 105 | else => unreachable, | ||
| 106 | } | ||
| 107 | return count; | ||
| 108 | } | ||
| 109 | |||
| 110 | // TODO: implement this correctly. | ||
| 111 | pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { | ||
| 112 | switch (fd) { | ||
| 113 | STDOUT_FILENO, STDERR_FILENO => { | ||
| 114 | send(&Message.to(Server.Terminal, 1).withPayload(buf[0..count])); | ||
| 115 | }, | ||
| 116 | else => unreachable, | ||
| 117 | } | ||
| 118 | return count; | ||
| 119 | } | ||
| 120 | |||
| 121 | /////////////////////////// | ||
| 122 | //// Syscall numbers //// | ||
| 123 | /////////////////////////// | ||
| 124 | |||
| 125 | pub const Syscall = enum(usize) { | ||
| 126 | exit = 0, | ||
| 127 | send = 1, | ||
| 128 | receive = 2, | ||
| 129 | subscribeIRQ = 3, | ||
| 130 | inb = 4, | ||
| 131 | outb = 5, | ||
| 132 | map = 6, | ||
| 133 | createThread = 7, | ||
| 134 | }; | ||
| 135 | |||
| 136 | //////////////////// | ||
| 137 | //// Syscalls //// | ||
| 138 | //////////////////// | ||
| 139 | |||
| 140 | pub fn exit(status: i32) noreturn { | ||
| 141 | _ = syscall1(Syscall.exit, @bitCast(usize, @as(isize, status))); | ||
| 142 | unreachable; | ||
| 143 | } | ||
| 144 | |||
| 145 | pub fn send(message: *const Message) void { | ||
| 146 | _ = syscall1(Syscall.send, @ptrToInt(message)); | ||
| 147 | } | ||
| 148 | |||
| 149 | pub fn receive(destination: *Message) void { | ||
| 150 | _ = syscall1(Syscall.receive, @ptrToInt(destination)); | ||
| 151 | } | ||
| 152 | |||
| 153 | pub fn subscribeIRQ(irq: u8, mailbox_id: *const MailboxId) void { | ||
| 154 | _ = syscall2(Syscall.subscribeIRQ, irq, @ptrToInt(mailbox_id)); | ||
| 155 | } | ||
| 156 | |||
| 157 | pub fn inb(port: u16) u8 { | ||
| 158 | return @intCast(u8, syscall1(Syscall.inb, port)); | ||
| 159 | } | ||
| 160 | |||
| 161 | pub fn outb(port: u16, value: u8) void { | ||
| 162 | _ = syscall2(Syscall.outb, port, value); | ||
| 163 | } | ||
| 164 | |||
| 165 | pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool { | ||
| 166 | return syscall4(Syscall.map, v_addr, p_addr, size, @boolToInt(writable)) != 0; | ||
| 167 | } | ||
| 168 | |||
| 169 | pub fn createThread(function: fn () void) u16 { | ||
| 170 | return @as(u16, syscall1(Syscall.createThread, @ptrToInt(function))); | ||
| 171 | } | ||
| 172 | |||
| 173 | ///////////////////////// | ||
| 174 | //// Syscall stubs //// | ||
| 175 | ///////////////////////// | ||
| 176 | |||
| 177 | inline fn syscall0(number: Syscall) usize { | ||
| 178 | return asm volatile ("int $0x80" | ||
| 179 | : [ret] "={eax}" (-> usize) | ||
| 180 | : [number] "{eax}" (number) | ||
| 181 | ); | ||
| 182 | } | ||
| 183 | |||
| 184 | inline fn syscall1(number: Syscall, arg1: usize) usize { | ||
| 185 | return asm volatile ("int $0x80" | ||
| 186 | : [ret] "={eax}" (-> usize) | ||
| 187 | : [number] "{eax}" (number), | ||
| 188 | [arg1] "{ecx}" (arg1) | ||
| 189 | ); | ||
| 190 | } | ||
| 191 | |||
| 192 | inline fn syscall2(number: Syscall, arg1: usize, arg2: usize) usize { | ||
| 193 | return asm volatile ("int $0x80" | ||
| 194 | : [ret] "={eax}" (-> usize) | ||
| 195 | : [number] "{eax}" (number), | ||
| 196 | [arg1] "{ecx}" (arg1), | ||
| 197 | [arg2] "{edx}" (arg2) | ||
| 198 | ); | ||
| 199 | } | ||
| 200 | |||
| 201 | inline fn syscall3(number: Syscall, arg1: usize, arg2: usize, arg3: usize) usize { | ||
| 202 | return asm volatile ("int $0x80" | ||
| 203 | : [ret] "={eax}" (-> usize) | ||
| 204 | : [number] "{eax}" (number), | ||
| 205 | [arg1] "{ecx}" (arg1), | ||
| 206 | [arg2] "{edx}" (arg2), | ||
| 207 | [arg3] "{ebx}" (arg3) | ||
| 208 | ); | ||
| 209 | } | ||
| 210 | |||
| 211 | inline fn syscall4(number: Syscall, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | ||
| 212 | return asm volatile ("int $0x80" | ||
| 213 | : [ret] "={eax}" (-> usize) | ||
| 214 | : [number] "{eax}" (number), | ||
| 215 | [arg1] "{ecx}" (arg1), | ||
| 216 | [arg2] "{edx}" (arg2), | ||
| 217 | [arg3] "{ebx}" (arg3), | ||
| 218 | [arg4] "{esi}" (arg4) | ||
| 219 | ); | ||
| 220 | } | ||
| 221 | |||
| 222 | inline fn syscall5( | ||
| 223 | number: Syscall, | ||
| 224 | arg1: usize, | ||
| 225 | arg2: usize, | ||
| 226 | arg3: usize, | ||
| 227 | arg4: usize, | ||
| 228 | arg5: usize, | ||
| 229 | ) usize { | ||
| 230 | return asm volatile ("int $0x80" | ||
| 231 | : [ret] "={eax}" (-> usize) | ||
| 232 | : [number] "{eax}" (number), | ||
| 233 | [arg1] "{ecx}" (arg1), | ||
| 234 | [arg2] "{edx}" (arg2), | ||
| 235 | [arg3] "{ebx}" (arg3), | ||
| 236 | [arg4] "{esi}" (arg4), | ||
| 237 | [arg5] "{edi}" (arg5) | ||
| 238 | ); | ||
| 239 | } | ||
| 240 | |||
| 241 | inline fn syscall6( | ||
| 242 | number: Syscall, | ||
| 243 | arg1: usize, | ||
| 244 | arg2: usize, | ||
| 245 | arg3: usize, | ||
| 246 | arg4: usize, | ||
| 247 | arg5: usize, | ||
| 248 | arg6: usize, | ||
| 249 | ) usize { | ||
| 250 | return asm volatile ("int $0x80" | ||
| 251 | : [ret] "={eax}" (-> usize) | ||
| 252 | : [number] "{eax}" (number), | ||
| 253 | [arg1] "{ecx}" (arg1), | ||
| 254 | [arg2] "{edx}" (arg2), | ||
| 255 | [arg3] "{ebx}" (arg3), | ||
| 256 | [arg4] "{esi}" (arg4), | ||
| 257 | [arg5] "{edi}" (arg5), | ||
| 258 | [arg6] "{ebp}" (arg6) | ||
| 259 | ); | ||
| 260 | } | ||
lib/std/priority_queue.zig+8-8| ... | @@ -199,19 +199,19 @@ pub fn PriorityQueue(comptime T: type) type { | ... | @@ -199,19 +199,19 @@ pub fn PriorityQueue(comptime T: type) type { |
| 199 | } | 199 | } |
| 200 | 200 | ||
| 201 | fn dump(self: *Self) void { | 201 | fn dump(self: *Self) void { |
| 202 | warn("{{ "); | 202 | warn("{{ ", .{}); |
| 203 | warn("items: "); | 203 | warn("items: ", .{}); |
| 204 | for (self.items) |e, i| { | 204 | for (self.items) |e, i| { |
| 205 | if (i >= self.len) break; | 205 | if (i >= self.len) break; |
| 206 | warn("{}, ", e); | 206 | warn("{}, ", .{e}); |
| 207 | } | 207 | } |
| 208 | warn("array: "); | 208 | warn("array: ", .{}); |
| 209 | for (self.items) |e, i| { | 209 | for (self.items) |e, i| { |
| 210 | warn("{}, ", e); | 210 | warn("{}, ", .{e}); |
| 211 | } | 211 | } |
| 212 | warn("len: {} ", self.len); | 212 | warn("len: {} ", .{self.len}); |
| 213 | warn("capacity: {}", self.capacity()); | 213 | warn("capacity: {}", .{self.capacity()}); |
| 214 | warn(" }}\n"); | 214 | warn(" }}\n", .{}); |
| 215 | } | 215 | } |
| 216 | }; | 216 | }; |
| 217 | } | 217 | } |
lib/std/progress.zig+11-11| ... | @@ -130,11 +130,11 @@ pub const Progress = struct { | ... | @@ -130,11 +130,11 @@ pub const Progress = struct { |
| 130 | var end: usize = 0; | 130 | var end: usize = 0; |
| 131 | if (self.columns_written > 0) { | 131 | if (self.columns_written > 0) { |
| 132 | // restore cursor position | 132 | // restore cursor position |
| 133 | end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{}D", self.columns_written) catch unreachable).len; | 133 | end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{}D", .{self.columns_written}) catch unreachable).len; |
| 134 | self.columns_written = 0; | 134 | self.columns_written = 0; |
| 135 | 135 | ||
| 136 | // clear rest of line | 136 | // clear rest of line |
| 137 | end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K") catch unreachable).len; | 137 | end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K", .{}) catch unreachable).len; |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | if (!self.done) { | 140 | if (!self.done) { |
| ... | @@ -142,28 +142,28 @@ pub const Progress = struct { | ... | @@ -142,28 +142,28 @@ pub const Progress = struct { |
| 142 | var maybe_node: ?*Node = &self.root; | 142 | var maybe_node: ?*Node = &self.root; |
| 143 | while (maybe_node) |node| { | 143 | while (maybe_node) |node| { |
| 144 | if (need_ellipse) { | 144 | if (need_ellipse) { |
| 145 | self.bufWrite(&end, "..."); | 145 | self.bufWrite(&end, "...", .{}); |
| 146 | } | 146 | } |
| 147 | need_ellipse = false; | 147 | need_ellipse = false; |
| 148 | if (node.name.len != 0 or node.estimated_total_items != null) { | 148 | if (node.name.len != 0 or node.estimated_total_items != null) { |
| 149 | if (node.name.len != 0) { | 149 | if (node.name.len != 0) { |
| 150 | self.bufWrite(&end, "{}", node.name); | 150 | self.bufWrite(&end, "{}", .{node.name}); |
| 151 | need_ellipse = true; | 151 | need_ellipse = true; |
| 152 | } | 152 | } |
| 153 | if (node.estimated_total_items) |total| { | 153 | if (node.estimated_total_items) |total| { |
| 154 | if (need_ellipse) self.bufWrite(&end, " "); | 154 | if (need_ellipse) self.bufWrite(&end, " ", .{}); |
| 155 | self.bufWrite(&end, "[{}/{}] ", node.completed_items + 1, total); | 155 | self.bufWrite(&end, "[{}/{}] ", .{ node.completed_items + 1, total }); |
| 156 | need_ellipse = false; | 156 | need_ellipse = false; |
| 157 | } else if (node.completed_items != 0) { | 157 | } else if (node.completed_items != 0) { |
| 158 | if (need_ellipse) self.bufWrite(&end, " "); | 158 | if (need_ellipse) self.bufWrite(&end, " ", .{}); |
| 159 | self.bufWrite(&end, "[{}] ", node.completed_items + 1); | 159 | self.bufWrite(&end, "[{}] ", .{node.completed_items + 1}); |
| 160 | need_ellipse = false; | 160 | need_ellipse = false; |
| 161 | } | 161 | } |
| 162 | } | 162 | } |
| 163 | maybe_node = node.recently_updated_child; | 163 | maybe_node = node.recently_updated_child; |
| 164 | } | 164 | } |
| 165 | if (need_ellipse) { | 165 | if (need_ellipse) { |
| 166 | self.bufWrite(&end, "..."); | 166 | self.bufWrite(&end, "...", .{}); |
| 167 | } | 167 | } |
| 168 | } | 168 | } |
| 169 | 169 | ||
| ... | @@ -174,7 +174,7 @@ pub const Progress = struct { | ... | @@ -174,7 +174,7 @@ pub const Progress = struct { |
| 174 | self.prev_refresh_timestamp = self.timer.read(); | 174 | self.prev_refresh_timestamp = self.timer.read(); |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | pub fn log(self: *Progress, comptime format: []const u8, args: ...) void { | 177 | pub fn log(self: *Progress, comptime format: []const u8, args: var) void { |
| 178 | const file = self.terminal orelse return; | 178 | const file = self.terminal orelse return; |
| 179 | self.refresh(); | 179 | self.refresh(); |
| 180 | file.outStream().stream.print(format, args) catch { | 180 | file.outStream().stream.print(format, args) catch { |
| ... | @@ -184,7 +184,7 @@ pub const Progress = struct { | ... | @@ -184,7 +184,7 @@ pub const Progress = struct { |
| 184 | self.columns_written = 0; | 184 | self.columns_written = 0; |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: ...) void { | 187 | fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: var) void { |
| 188 | if (std.fmt.bufPrint(self.output_buffer[end.*..], format, args)) |written| { | 188 | if (std.fmt.bufPrint(self.output_buffer[end.*..], format, args)) |written| { |
| 189 | const amt = written.len; | 189 | const amt = written.len; |
| 190 | end.* += amt; | 190 | end.* += amt; |
lib/std/special/build_runner.zig+18-15| ... | @@ -26,15 +26,15 @@ pub fn main() !void { | ... | @@ -26,15 +26,15 @@ pub fn main() !void { |
| 26 | _ = arg_it.skip(); | 26 | _ = arg_it.skip(); |
| 27 | 27 | ||
| 28 | const zig_exe = try unwrapArg(arg_it.next(allocator) orelse { | 28 | const zig_exe = try unwrapArg(arg_it.next(allocator) orelse { |
| 29 | warn("Expected first argument to be path to zig compiler\n"); | 29 | warn("Expected first argument to be path to zig compiler\n", .{}); |
| 30 | return error.InvalidArgs; | 30 | return error.InvalidArgs; |
| 31 | }); | 31 | }); |
| 32 | const build_root = try unwrapArg(arg_it.next(allocator) orelse { | 32 | const build_root = try unwrapArg(arg_it.next(allocator) orelse { |
| 33 | warn("Expected second argument to be build root directory path\n"); | 33 | warn("Expected second argument to be build root directory path\n", .{}); |
| 34 | return error.InvalidArgs; | 34 | return error.InvalidArgs; |
| 35 | }); | 35 | }); |
| 36 | const cache_root = try unwrapArg(arg_it.next(allocator) orelse { | 36 | const cache_root = try unwrapArg(arg_it.next(allocator) orelse { |
| 37 | warn("Expected third argument to be cache root directory path\n"); | 37 | warn("Expected third argument to be cache root directory path\n", .{}); |
| 38 | return error.InvalidArgs; | 38 | return error.InvalidArgs; |
| 39 | }); | 39 | }); |
| 40 | 40 | ||
| ... | @@ -51,7 +51,7 @@ pub fn main() !void { | ... | @@ -51,7 +51,7 @@ pub fn main() !void { |
| 51 | if (mem.startsWith(u8, arg, "-D")) { | 51 | if (mem.startsWith(u8, arg, "-D")) { |
| 52 | const option_contents = arg[2..]; | 52 | const option_contents = arg[2..]; |
| 53 | if (option_contents.len == 0) { | 53 | if (option_contents.len == 0) { |
| 54 | warn("Expected option name after '-D'\n\n"); | 54 | warn("Expected option name after '-D'\n\n", .{}); |
| 55 | return usageAndErr(builder, false, stderr_stream); | 55 | return usageAndErr(builder, false, stderr_stream); |
| 56 | } | 56 | } |
| 57 | if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| { | 57 | if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| { |
| ... | @@ -70,18 +70,18 @@ pub fn main() !void { | ... | @@ -70,18 +70,18 @@ pub fn main() !void { |
| 70 | return usage(builder, false, stdout_stream); | 70 | return usage(builder, false, stdout_stream); |
| 71 | } else if (mem.eql(u8, arg, "--prefix")) { | 71 | } else if (mem.eql(u8, arg, "--prefix")) { |
| 72 | builder.install_prefix = try unwrapArg(arg_it.next(allocator) orelse { | 72 | builder.install_prefix = try unwrapArg(arg_it.next(allocator) orelse { |
| 73 | warn("Expected argument after --prefix\n\n"); | 73 | warn("Expected argument after --prefix\n\n", .{}); |
| 74 | return usageAndErr(builder, false, stderr_stream); | 74 | return usageAndErr(builder, false, stderr_stream); |
| 75 | }); | 75 | }); |
| 76 | } else if (mem.eql(u8, arg, "--search-prefix")) { | 76 | } else if (mem.eql(u8, arg, "--search-prefix")) { |
| 77 | const search_prefix = try unwrapArg(arg_it.next(allocator) orelse { | 77 | const search_prefix = try unwrapArg(arg_it.next(allocator) orelse { |
| 78 | warn("Expected argument after --search-prefix\n\n"); | 78 | warn("Expected argument after --search-prefix\n\n", .{}); |
| 79 | return usageAndErr(builder, false, stderr_stream); | 79 | return usageAndErr(builder, false, stderr_stream); |
| 80 | }); | 80 | }); |
| 81 | builder.addSearchPrefix(search_prefix); | 81 | builder.addSearchPrefix(search_prefix); |
| 82 | } else if (mem.eql(u8, arg, "--override-lib-dir")) { | 82 | } else if (mem.eql(u8, arg, "--override-lib-dir")) { |
| 83 | builder.override_lib_dir = try unwrapArg(arg_it.next(allocator) orelse { | 83 | builder.override_lib_dir = try unwrapArg(arg_it.next(allocator) orelse { |
| 84 | warn("Expected argument after --override-lib-dir\n\n"); | 84 | warn("Expected argument after --override-lib-dir\n\n", .{}); |
| 85 | return usageAndErr(builder, false, stderr_stream); | 85 | return usageAndErr(builder, false, stderr_stream); |
| 86 | }); | 86 | }); |
| 87 | } else if (mem.eql(u8, arg, "--verbose-tokenize")) { | 87 | } else if (mem.eql(u8, arg, "--verbose-tokenize")) { |
| ... | @@ -99,7 +99,7 @@ pub fn main() !void { | ... | @@ -99,7 +99,7 @@ pub fn main() !void { |
| 99 | } else if (mem.eql(u8, arg, "--verbose-cc")) { | 99 | } else if (mem.eql(u8, arg, "--verbose-cc")) { |
| 100 | builder.verbose_cc = true; | 100 | builder.verbose_cc = true; |
| 101 | } else { | 101 | } else { |
| 102 | warn("Unrecognized argument: {}\n\n", arg); | 102 | warn("Unrecognized argument: {}\n\n", .{arg}); |
| 103 | return usageAndErr(builder, false, stderr_stream); | 103 | return usageAndErr(builder, false, stderr_stream); |
| 104 | } | 104 | } |
| 105 | } else { | 105 | } else { |
| ... | @@ -145,15 +145,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void { | ... | @@ -145,15 +145,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void { |
| 145 | \\ | 145 | \\ |
| 146 | \\Steps: | 146 | \\Steps: |
| 147 | \\ | 147 | \\ |
| 148 | , builder.zig_exe); | 148 | , .{builder.zig_exe}); |
| 149 | 149 | ||
| 150 | const allocator = builder.allocator; | 150 | const allocator = builder.allocator; |
| 151 | for (builder.top_level_steps.toSliceConst()) |top_level_step| { | 151 | for (builder.top_level_steps.toSliceConst()) |top_level_step| { |
| 152 | const name = if (&top_level_step.step == builder.default_step) | 152 | const name = if (&top_level_step.step == builder.default_step) |
| 153 | try fmt.allocPrint(allocator, "{} (default)", top_level_step.step.name) | 153 | try fmt.allocPrint(allocator, "{} (default)", .{top_level_step.step.name}) |
| 154 | else | 154 | else |
| 155 | top_level_step.step.name; | 155 | top_level_step.step.name; |
| 156 | try out_stream.print(" {s:22} {}\n", name, top_level_step.description); | 156 | try out_stream.print(" {s:22} {}\n", .{ name, top_level_step.description }); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | try out_stream.write( | 159 | try out_stream.write( |
| ... | @@ -169,12 +169,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void { | ... | @@ -169,12 +169,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void { |
| 169 | ); | 169 | ); |
| 170 | 170 | ||
| 171 | if (builder.available_options_list.len == 0) { | 171 | if (builder.available_options_list.len == 0) { |
| 172 | try out_stream.print(" (none)\n"); | 172 | try out_stream.print(" (none)\n", .{}); |
| 173 | } else { | 173 | } else { |
| 174 | for (builder.available_options_list.toSliceConst()) |option| { | 174 | for (builder.available_options_list.toSliceConst()) |option| { |
| 175 | const name = try fmt.allocPrint(allocator, " -D{}=[{}]", option.name, Builder.typeIdName(option.type_id)); | 175 | const name = try fmt.allocPrint(allocator, " -D{}=[{}]", .{ |
| 176 | option.name, | ||
| 177 | Builder.typeIdName(option.type_id), | ||
| 178 | }); | ||
| 176 | defer allocator.free(name); | 179 | defer allocator.free(name); |
| 177 | try out_stream.print("{s:24} {}\n", name, option.description); | 180 | try out_stream.print("{s:24} {}\n", .{ name, option.description }); |
| 178 | } | 181 | } |
| 179 | } | 182 | } |
| 180 | 183 | ||
| ... | @@ -204,7 +207,7 @@ const UnwrapArgError = error{OutOfMemory}; | ... | @@ -204,7 +207,7 @@ const UnwrapArgError = error{OutOfMemory}; |
| 204 | 207 | ||
| 205 | fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 { | 208 | fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 { |
| 206 | return arg catch |err| { | 209 | return arg catch |err| { |
| 207 | warn("Unable to parse command line: {}\n", err); | 210 | warn("Unable to parse command line: {}\n", .{err}); |
| 208 | return err; | 211 | return err; |
| 209 | }; | 212 | }; |
| 210 | } | 213 | } |
lib/std/special/init-exe/src/main.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | pub fn main() anyerror!void { | 3 | pub fn main() anyerror!void { |
| 4 | std.debug.warn("All your base are belong to us.\n"); | 4 | std.debug.warn("All your base are belong to us.\n", .{}); |
| 5 | } | 5 | } |
lib/std/special/start.zig+2-2| ... | @@ -217,7 +217,7 @@ inline fn initEventLoopAndCallMain() u8 { | ... | @@ -217,7 +217,7 @@ inline fn initEventLoopAndCallMain() u8 { |
| 217 | if (std.event.Loop.instance) |loop| { | 217 | if (std.event.Loop.instance) |loop| { |
| 218 | if (!@hasDecl(root, "event_loop")) { | 218 | if (!@hasDecl(root, "event_loop")) { |
| 219 | loop.init() catch |err| { | 219 | loop.init() catch |err| { |
| 220 | std.debug.warn("error: {}\n", @errorName(err)); | 220 | std.debug.warn("error: {}\n", .{@errorName(err)}); |
| 221 | if (@errorReturnTrace()) |trace| { | 221 | if (@errorReturnTrace()) |trace| { |
| 222 | std.debug.dumpStackTrace(trace.*); | 222 | std.debug.dumpStackTrace(trace.*); |
| 223 | } | 223 | } |
| ... | @@ -264,7 +264,7 @@ fn callMain() u8 { | ... | @@ -264,7 +264,7 @@ fn callMain() u8 { |
| 264 | }, | 264 | }, |
| 265 | .ErrorUnion => { | 265 | .ErrorUnion => { |
| 266 | const result = root.main() catch |err| { | 266 | const result = root.main() catch |err| { |
| 267 | std.debug.warn("error: {}\n", @errorName(err)); | 267 | std.debug.warn("error: {}\n", .{@errorName(err)}); |
| 268 | if (@errorReturnTrace()) |trace| { | 268 | if (@errorReturnTrace()) |trace| { |
| 269 | std.debug.dumpStackTrace(trace.*); | 269 | std.debug.dumpStackTrace(trace.*); |
| 270 | } | 270 | } |
lib/std/special/test_runner.zig+7-7| ... | @@ -16,28 +16,28 @@ pub fn main() anyerror!void { | ... | @@ -16,28 +16,28 @@ pub fn main() anyerror!void { |
| 16 | var test_node = root_node.start(test_fn.name, null); | 16 | var test_node = root_node.start(test_fn.name, null); |
| 17 | test_node.activate(); | 17 | test_node.activate(); |
| 18 | progress.refresh(); | 18 | progress.refresh(); |
| 19 | if (progress.terminal == null) std.debug.warn("{}/{} {}...", i + 1, test_fn_list.len, test_fn.name); | 19 | if (progress.terminal == null) std.debug.warn("{}/{} {}...", .{ i + 1, test_fn_list.len, test_fn.name }); |
| 20 | if (test_fn.func()) |_| { | 20 | if (test_fn.func()) |_| { |
| 21 | ok_count += 1; | 21 | ok_count += 1; |
| 22 | test_node.end(); | 22 | test_node.end(); |
| 23 | if (progress.terminal == null) std.debug.warn("OK\n"); | 23 | if (progress.terminal == null) std.debug.warn("OK\n", .{}); |
| 24 | } else |err| switch (err) { | 24 | } else |err| switch (err) { |
| 25 | error.SkipZigTest => { | 25 | error.SkipZigTest => { |
| 26 | skip_count += 1; | 26 | skip_count += 1; |
| 27 | test_node.end(); | 27 | test_node.end(); |
| 28 | progress.log("{}...SKIP\n", test_fn.name); | 28 | progress.log("{}...SKIP\n", .{test_fn.name}); |
| 29 | if (progress.terminal == null) std.debug.warn("SKIP\n"); | 29 | if (progress.terminal == null) std.debug.warn("SKIP\n", .{}); |
| 30 | }, | 30 | }, |
| 31 | else => { | 31 | else => { |
| 32 | progress.log(""); | 32 | progress.log("", .{}); |
| 33 | return err; | 33 | return err; |
| 34 | }, | 34 | }, |
| 35 | } | 35 | } |
| 36 | } | 36 | } |
| 37 | root_node.end(); | 37 | root_node.end(); |
| 38 | if (ok_count == test_fn_list.len) { | 38 | if (ok_count == test_fn_list.len) { |
| 39 | std.debug.warn("All {} tests passed.\n", ok_count); | 39 | std.debug.warn("All {} tests passed.\n", .{ok_count}); |
| 40 | } else { | 40 | } else { |
| 41 | std.debug.warn("{} passed; {} skipped.\n", ok_count, skip_count); | 41 | std.debug.warn("{} passed; {} skipped.\n", .{ ok_count, skip_count }); |
| 42 | } | 42 | } |
| 43 | } | 43 | } |
lib/std/target.zig+6-12| ... | @@ -321,14 +321,12 @@ pub const Target = union(enum) { | ... | @@ -321,14 +321,12 @@ pub const Target = union(enum) { |
| 321 | pub const stack_align = 16; | 321 | pub const stack_align = 16; |
| 322 | 322 | ||
| 323 | pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 { | 323 | pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 { |
| 324 | return std.fmt.allocPrint( | 324 | return std.fmt.allocPrint(allocator, "{}{}-{}-{}", .{ |
| 325 | allocator, | ||
| 326 | "{}{}-{}-{}", | ||
| 327 | @tagName(self.getArch()), | 325 | @tagName(self.getArch()), |
| 328 | Target.archSubArchName(self.getArch()), | 326 | Target.archSubArchName(self.getArch()), |
| 329 | @tagName(self.getOs()), | 327 | @tagName(self.getOs()), |
| 330 | @tagName(self.getAbi()), | 328 | @tagName(self.getAbi()), |
| 331 | ); | 329 | }); |
| 332 | } | 330 | } |
| 333 | 331 | ||
| 334 | /// Returned slice must be freed by the caller. | 332 | /// Returned slice must be freed by the caller. |
| ... | @@ -372,23 +370,19 @@ pub const Target = union(enum) { | ... | @@ -372,23 +370,19 @@ pub const Target = union(enum) { |
| 372 | } | 370 | } |
| 373 | 371 | ||
| 374 | pub fn zigTripleNoSubArch(self: Target, allocator: *mem.Allocator) ![]u8 { | 372 | pub fn zigTripleNoSubArch(self: Target, allocator: *mem.Allocator) ![]u8 { |
| 375 | return std.fmt.allocPrint( | 373 | return std.fmt.allocPrint(allocator, "{}-{}-{}", .{ |
| 376 | allocator, | ||
| 377 | "{}-{}-{}", | ||
| 378 | @tagName(self.getArch()), | 374 | @tagName(self.getArch()), |
| 379 | @tagName(self.getOs()), | 375 | @tagName(self.getOs()), |
| 380 | @tagName(self.getAbi()), | 376 | @tagName(self.getAbi()), |
| 381 | ); | 377 | }); |
| 382 | } | 378 | } |
| 383 | 379 | ||
| 384 | pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 { | 380 | pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 { |
| 385 | return std.fmt.allocPrint( | 381 | return std.fmt.allocPrint(allocator, "{}-{}-{}", .{ |
| 386 | allocator, | ||
| 387 | "{}-{}-{}", | ||
| 388 | @tagName(self.getArch()), | 382 | @tagName(self.getArch()), |
| 389 | @tagName(self.getOs()), | 383 | @tagName(self.getOs()), |
| 390 | @tagName(self.getAbi()), | 384 | @tagName(self.getAbi()), |
| 391 | ); | 385 | }); |
| 392 | } | 386 | } |
| 393 | 387 | ||
| 394 | pub fn parse(text: []const u8) !Target { | 388 | pub fn parse(text: []const u8) !Target { |
lib/std/testing.zig+23-18| ... | @@ -8,13 +8,19 @@ pub fn expectError(expected_error: anyerror, actual_error_union: var) void { | ... | @@ -8,13 +8,19 @@ pub fn expectError(expected_error: anyerror, actual_error_union: var) void { |
| 8 | if (actual_error_union) |actual_payload| { | 8 | if (actual_error_union) |actual_payload| { |
| 9 | // TODO remove workaround here for https://github.com/ziglang/zig/issues/557 | 9 | // TODO remove workaround here for https://github.com/ziglang/zig/issues/557 |
| 10 | if (@sizeOf(@typeOf(actual_payload)) == 0) { | 10 | if (@sizeOf(@typeOf(actual_payload)) == 0) { |
| 11 | std.debug.panic("expected error.{}, found {} value", @errorName(expected_error), @typeName(@typeOf(actual_payload))); | 11 | std.debug.panic("expected error.{}, found {} value", .{ |
| 12 | @errorName(expected_error), | ||
| 13 | @typeName(@typeOf(actual_payload)), | ||
| 14 | }); | ||
| 12 | } else { | 15 | } else { |
| 13 | std.debug.panic("expected error.{}, found {}", @errorName(expected_error), actual_payload); | 16 | std.debug.panic("expected error.{}, found {}", .{ @errorName(expected_error), actual_payload }); |
| 14 | } | 17 | } |
| 15 | } else |actual_error| { | 18 | } else |actual_error| { |
| 16 | if (expected_error != actual_error) { | 19 | if (expected_error != actual_error) { |
| 17 | std.debug.panic("expected error.{}, found error.{}", @errorName(expected_error), @errorName(actual_error)); | 20 | std.debug.panic("expected error.{}, found error.{}", .{ |
| 21 | @errorName(expected_error), | ||
| 22 | @errorName(actual_error), | ||
| 23 | }); | ||
| 18 | } | 24 | } |
| 19 | } | 25 | } |
| 20 | } | 26 | } |
| ... | @@ -51,7 +57,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { | ... | @@ -51,7 +57,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { |
| 51 | .ErrorSet, | 57 | .ErrorSet, |
| 52 | => { | 58 | => { |
| 53 | if (actual != expected) { | 59 | if (actual != expected) { |
| 54 | std.debug.panic("expected {}, found {}", expected, actual); | 60 | std.debug.panic("expected {}, found {}", .{ expected, actual }); |
| 55 | } | 61 | } |
| 56 | }, | 62 | }, |
| 57 | 63 | ||
| ... | @@ -62,16 +68,16 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { | ... | @@ -62,16 +68,16 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { |
| 62 | builtin.TypeInfo.Pointer.Size.C, | 68 | builtin.TypeInfo.Pointer.Size.C, |
| 63 | => { | 69 | => { |
| 64 | if (actual != expected) { | 70 | if (actual != expected) { |
| 65 | std.debug.panic("expected {*}, found {*}", expected, actual); | 71 | std.debug.panic("expected {*}, found {*}", .{ expected, actual }); |
| 66 | } | 72 | } |
| 67 | }, | 73 | }, |
| 68 | 74 | ||
| 69 | builtin.TypeInfo.Pointer.Size.Slice => { | 75 | builtin.TypeInfo.Pointer.Size.Slice => { |
| 70 | if (actual.ptr != expected.ptr) { | 76 | if (actual.ptr != expected.ptr) { |
| 71 | std.debug.panic("expected slice ptr {}, found {}", expected.ptr, actual.ptr); | 77 | std.debug.panic("expected slice ptr {}, found {}", .{ expected.ptr, actual.ptr }); |
| 72 | } | 78 | } |
| 73 | if (actual.len != expected.len) { | 79 | if (actual.len != expected.len) { |
| 74 | std.debug.panic("expected slice len {}, found {}", expected.len, actual.len); | 80 | std.debug.panic("expected slice len {}, found {}", .{ expected.len, actual.len }); |
| 75 | } | 81 | } |
| 76 | }, | 82 | }, |
| 77 | } | 83 | } |
| ... | @@ -106,7 +112,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { | ... | @@ -106,7 +112,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { |
| 106 | } | 112 | } |
| 107 | 113 | ||
| 108 | // we iterate over *all* union fields | 114 | // we iterate over *all* union fields |
| 109 | // => we should never get here as the loop above is | 115 | // => we should never get here as the loop above is |
| 110 | // including all possible values. | 116 | // including all possible values. |
| 111 | unreachable; | 117 | unreachable; |
| 112 | }, | 118 | }, |
| ... | @@ -116,11 +122,11 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { | ... | @@ -116,11 +122,11 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { |
| 116 | if (actual) |actual_payload| { | 122 | if (actual) |actual_payload| { |
| 117 | expectEqual(expected_payload, actual_payload); | 123 | expectEqual(expected_payload, actual_payload); |
| 118 | } else { | 124 | } else { |
| 119 | std.debug.panic("expected {}, found null", expected_payload); | 125 | std.debug.panic("expected {}, found null", .{expected_payload}); |
| 120 | } | 126 | } |
| 121 | } else { | 127 | } else { |
| 122 | if (actual) |actual_payload| { | 128 | if (actual) |actual_payload| { |
| 123 | std.debug.panic("expected null, found {}", actual_payload); | 129 | std.debug.panic("expected null, found {}", .{actual_payload}); |
| 124 | } | 130 | } |
| 125 | } | 131 | } |
| 126 | }, | 132 | }, |
| ... | @@ -130,11 +136,11 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { | ... | @@ -130,11 +136,11 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { |
| 130 | if (actual) |actual_payload| { | 136 | if (actual) |actual_payload| { |
| 131 | expectEqual(expected_payload, actual_payload); | 137 | expectEqual(expected_payload, actual_payload); |
| 132 | } else |actual_err| { | 138 | } else |actual_err| { |
| 133 | std.debug.panic("expected {}, found {}", expected_payload, actual_err); | 139 | std.debug.panic("expected {}, found {}", .{ expected_payload, actual_err }); |
| 134 | } | 140 | } |
| 135 | } else |expected_err| { | 141 | } else |expected_err| { |
| 136 | if (actual) |actual_payload| { | 142 | if (actual) |actual_payload| { |
| 137 | std.debug.panic("expected {}, found {}", expected_err, actual_payload); | 143 | std.debug.panic("expected {}, found {}", .{ expected_err, actual_payload }); |
| 138 | } else |actual_err| { | 144 | } else |actual_err| { |
| 139 | expectEqual(expected_err, actual_err); | 145 | expectEqual(expected_err, actual_err); |
| 140 | } | 146 | } |
| ... | @@ -143,15 +149,14 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { | ... | @@ -143,15 +149,14 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { |
| 143 | } | 149 | } |
| 144 | } | 150 | } |
| 145 | 151 | ||
| 146 | test "expectEqual.union(enum)" | 152 | test "expectEqual.union(enum)" { |
| 147 | { | ||
| 148 | const T = union(enum) { | 153 | const T = union(enum) { |
| 149 | a: i32, | 154 | a: i32, |
| 150 | b: f32, | 155 | b: f32, |
| 151 | }; | 156 | }; |
| 152 | 157 | ||
| 153 | const a10 = T { .a = 10 }; | 158 | const a10 = T{ .a = 10 }; |
| 154 | const a20 = T { .a = 20 }; | 159 | const a20 = T{ .a = 20 }; |
| 155 | 160 | ||
| 156 | expectEqual(a10, a10); | 161 | expectEqual(a10, a10); |
| 157 | } | 162 | } |
| ... | @@ -165,12 +170,12 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const | ... | @@ -165,12 +170,12 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const |
| 165 | // If the child type is u8 and no weird bytes, we could print it as strings | 170 | // If the child type is u8 and no weird bytes, we could print it as strings |
| 166 | // Even for the length difference, it would be useful to see the values of the slices probably. | 171 | // Even for the length difference, it would be useful to see the values of the slices probably. |
| 167 | if (expected.len != actual.len) { | 172 | if (expected.len != actual.len) { |
| 168 | std.debug.panic("slice lengths differ. expected {}, found {}", expected.len, actual.len); | 173 | std.debug.panic("slice lengths differ. expected {}, found {}", .{ expected.len, actual.len }); |
| 169 | } | 174 | } |
| 170 | var i: usize = 0; | 175 | var i: usize = 0; |
| 171 | while (i < expected.len) : (i += 1) { | 176 | while (i < expected.len) : (i += 1) { |
| 172 | if (expected[i] != actual[i]) { | 177 | if (expected[i] != actual[i]) { |
| 173 | std.debug.panic("index {} incorrect. expected {}, found {}", i, expected[i], actual[i]); | 178 | std.debug.panic("index {} incorrect. expected {}, found {}", .{ i, expected[i], actual[i] }); |
| 174 | } | 179 | } |
| 175 | } | 180 | } |
| 176 | } | 181 | } |
lib/std/unicode.zig+1-1| ... | @@ -170,7 +170,7 @@ pub fn utf8ValidateSlice(s: []const u8) bool { | ... | @@ -170,7 +170,7 @@ pub fn utf8ValidateSlice(s: []const u8) bool { |
| 170 | /// ``` | 170 | /// ``` |
| 171 | /// var utf8 = (try std.unicode.Utf8View.init("hi there")).iterator(); | 171 | /// var utf8 = (try std.unicode.Utf8View.init("hi there")).iterator(); |
| 172 | /// while (utf8.nextCodepointSlice()) |codepoint| { | 172 | /// while (utf8.nextCodepointSlice()) |codepoint| { |
| 173 | /// std.debug.warn("got codepoint {}\n", codepoint); | 173 | /// std.debug.warn("got codepoint {}\n", .{codepoint}); |
| 174 | /// } | 174 | /// } |
| 175 | /// ``` | 175 | /// ``` |
| 176 | pub const Utf8View = struct { | 176 | pub const Utf8View = struct { |
lib/std/unicode/throughput_test.zig+6-2| ... | @@ -24,8 +24,12 @@ pub fn main() !void { | ... | @@ -24,8 +24,12 @@ pub fn main() !void { |
| 24 | const elapsed_ns_better = timer.lap(); | 24 | const elapsed_ns_better = timer.lap(); |
| 25 | @fence(.SeqCst); | 25 | @fence(.SeqCst); |
| 26 | 26 | ||
| 27 | std.debug.warn("original utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", elapsed_ns_orig, elapsed_ns_orig / 1000000); | 27 | std.debug.warn("original utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", .{ |
| 28 | std.debug.warn("new utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", elapsed_ns_better, elapsed_ns_better / 1000000); | 28 | elapsed_ns_orig, elapsed_ns_orig / 1000000, |
| 29 | }); | ||
| 30 | std.debug.warn("new utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", .{ | ||
| 31 | elapsed_ns_better, elapsed_ns_better / 1000000, | ||
| 32 | }); | ||
| 29 | asm volatile ("nop" | 33 | asm volatile ("nop" |
| 30 | : | 34 | : |
| 31 | : [a] "r" (&buffer1), | 35 | : [a] "r" (&buffer1), |
lib/std/valgrind.zig-14| ... | @@ -114,20 +114,6 @@ pub fn innerThreads(qzz: [*]u8) void { | ... | @@ -114,20 +114,6 @@ pub fn innerThreads(qzz: [*]u8) void { |
| 114 | doClientRequestStmt(.InnerThreads, qzz, 0, 0, 0, 0); | 114 | doClientRequestStmt(.InnerThreads, qzz, 0, 0, 0, 0); |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | //pub fn printf(format: [*]const u8, args: ...) usize { | ||
| 118 | // return doClientRequestExpr(0, | ||
| 119 | // .PrintfValistByRef, | ||
| 120 | // @ptrToInt(format), @ptrToInt(args), | ||
| 121 | // 0, 0, 0); | ||
| 122 | //} | ||
| 123 | |||
| 124 | //pub fn printfBacktrace(format: [*]const u8, args: ...) usize { | ||
| 125 | // return doClientRequestExpr(0, | ||
| 126 | // .PrintfBacktraceValistByRef, | ||
| 127 | // @ptrToInt(format), @ptrToInt(args), | ||
| 128 | // 0, 0, 0); | ||
| 129 | //} | ||
| 130 | |||
| 131 | pub fn nonSIMDCall0(func: fn (usize) usize) usize { | 117 | pub fn nonSIMDCall0(func: fn (usize) usize) usize { |
| 132 | return doClientRequestExpr(0, .ClientCall0, @ptrToInt(func), 0, 0, 0, 0); | 118 | return doClientRequestExpr(0, .ClientCall0, @ptrToInt(func), 0, 0, 0, 0); |
| 133 | } | 119 | } |
lib/std/zig/ast.zig+15-9| ... | @@ -301,7 +301,9 @@ pub const Error = union(enum) { | ... | @@ -301,7 +301,9 @@ pub const Error = union(enum) { |
| 301 | node: *Node, | 301 | node: *Node, |
| 302 | 302 | ||
| 303 | pub fn render(self: *const ExpectedCall, tokens: *Tree.TokenList, stream: var) !void { | 303 | pub fn render(self: *const ExpectedCall, tokens: *Tree.TokenList, stream: var) !void { |
| 304 | return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ ", found {}", @tagName(self.node.id)); | 304 | return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ ", found {}", .{ |
| 305 | @tagName(self.node.id), | ||
| 306 | }); | ||
| 305 | } | 307 | } |
| 306 | }; | 308 | }; |
| 307 | 309 | ||
| ... | @@ -309,7 +311,8 @@ pub const Error = union(enum) { | ... | @@ -309,7 +311,8 @@ pub const Error = union(enum) { |
| 309 | node: *Node, | 311 | node: *Node, |
| 310 | 312 | ||
| 311 | pub fn render(self: *const ExpectedCallOrFnProto, tokens: *Tree.TokenList, stream: var) !void { | 313 | pub fn render(self: *const ExpectedCallOrFnProto, tokens: *Tree.TokenList, stream: var) !void { |
| 312 | return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ " or " ++ @tagName(Node.Id.FnProto) ++ ", found {}", @tagName(self.node.id)); | 314 | return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ " or " ++ |
| 315 | @tagName(Node.Id.FnProto) ++ ", found {}", .{@tagName(self.node.id)}); | ||
| 313 | } | 316 | } |
| 314 | }; | 317 | }; |
| 315 | 318 | ||
| ... | @@ -321,14 +324,14 @@ pub const Error = union(enum) { | ... | @@ -321,14 +324,14 @@ pub const Error = union(enum) { |
| 321 | const found_token = tokens.at(self.token); | 324 | const found_token = tokens.at(self.token); |
| 322 | switch (found_token.id) { | 325 | switch (found_token.id) { |
| 323 | .Invalid_ampersands => { | 326 | .Invalid_ampersands => { |
| 324 | return stream.print("`&&` is invalid. Note that `and` is boolean AND."); | 327 | return stream.print("`&&` is invalid. Note that `and` is boolean AND.", .{}); |
| 325 | }, | 328 | }, |
| 326 | .Invalid => { | 329 | .Invalid => { |
| 327 | return stream.print("expected '{}', found invalid bytes", self.expected_id.symbol()); | 330 | return stream.print("expected '{}', found invalid bytes", .{self.expected_id.symbol()}); |
| 328 | }, | 331 | }, |
| 329 | else => { | 332 | else => { |
| 330 | const token_name = found_token.id.symbol(); | 333 | const token_name = found_token.id.symbol(); |
| 331 | return stream.print("expected '{}', found '{}'", self.expected_id.symbol(), token_name); | 334 | return stream.print("expected '{}', found '{}'", .{ self.expected_id.symbol(), token_name }); |
| 332 | }, | 335 | }, |
| 333 | } | 336 | } |
| 334 | } | 337 | } |
| ... | @@ -340,7 +343,10 @@ pub const Error = union(enum) { | ... | @@ -340,7 +343,10 @@ pub const Error = union(enum) { |
| 340 | 343 | ||
| 341 | pub fn render(self: *const ExpectedCommaOrEnd, tokens: *Tree.TokenList, stream: var) !void { | 344 | pub fn render(self: *const ExpectedCommaOrEnd, tokens: *Tree.TokenList, stream: var) !void { |
| 342 | const actual_token = tokens.at(self.token); | 345 | const actual_token = tokens.at(self.token); |
| 343 | return stream.print("expected ',' or '{}', found '{}'", self.end_id.symbol(), actual_token.id.symbol()); | 346 | return stream.print("expected ',' or '{}', found '{}'", .{ |
| 347 | self.end_id.symbol(), | ||
| 348 | actual_token.id.symbol(), | ||
| 349 | }); | ||
| 344 | } | 350 | } |
| 345 | }; | 351 | }; |
| 346 | 352 | ||
| ... | @@ -352,7 +358,7 @@ pub const Error = union(enum) { | ... | @@ -352,7 +358,7 @@ pub const Error = union(enum) { |
| 352 | 358 | ||
| 353 | pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void { | 359 | pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void { |
| 354 | const actual_token = tokens.at(self.token); | 360 | const actual_token = tokens.at(self.token); |
| 355 | return stream.print(msg, actual_token.id.symbol()); | 361 | return stream.print(msg, .{actual_token.id.symbol()}); |
| 356 | } | 362 | } |
| 357 | }; | 363 | }; |
| 358 | } | 364 | } |
| ... | @@ -563,10 +569,10 @@ pub const Node = struct { | ... | @@ -563,10 +569,10 @@ pub const Node = struct { |
| 563 | { | 569 | { |
| 564 | var i: usize = 0; | 570 | var i: usize = 0; |
| 565 | while (i < indent) : (i += 1) { | 571 | while (i < indent) : (i += 1) { |
| 566 | std.debug.warn(" "); | 572 | std.debug.warn(" ", .{}); |
| 567 | } | 573 | } |
| 568 | } | 574 | } |
| 569 | std.debug.warn("{}\n", @tagName(self.id)); | 575 | std.debug.warn("{}\n", .{@tagName(self.id)}); |
| 570 | 576 | ||
| 571 | var child_i: usize = 0; | 577 | var child_i: usize = 0; |
| 572 | while (self.iterate(child_i)) |child| : (child_i += 1) { | 578 | while (self.iterate(child_i)) |child| : (child_i += 1) { |
lib/std/zig/parser_test.zig+16-30| ... | @@ -642,15 +642,6 @@ test "zig fmt: fn decl with trailing comma" { | ... | @@ -642,15 +642,6 @@ test "zig fmt: fn decl with trailing comma" { |
| 642 | ); | 642 | ); |
| 643 | } | 643 | } |
| 644 | 644 | ||
| 645 | test "zig fmt: var_args with trailing comma" { | ||
| 646 | try testCanonical( | ||
| 647 | \\pub fn add( | ||
| 648 | \\ a: ..., | ||
| 649 | \\) void {} | ||
| 650 | \\ | ||
| 651 | ); | ||
| 652 | } | ||
| 653 | |||
| 654 | test "zig fmt: enum decl with no trailing comma" { | 645 | test "zig fmt: enum decl with no trailing comma" { |
| 655 | try testTransform( | 646 | try testTransform( |
| 656 | \\const StrLitKind = enum {Normal, C}; | 647 | \\const StrLitKind = enum {Normal, C}; |
| ... | @@ -1750,13 +1741,6 @@ test "zig fmt: call expression" { | ... | @@ -1750,13 +1741,6 @@ test "zig fmt: call expression" { |
| 1750 | ); | 1741 | ); |
| 1751 | } | 1742 | } |
| 1752 | 1743 | ||
| 1753 | test "zig fmt: var args" { | ||
| 1754 | try testCanonical( | ||
| 1755 | \\fn print(args: ...) void {} | ||
| 1756 | \\ | ||
| 1757 | ); | ||
| 1758 | } | ||
| 1759 | |||
| 1760 | test "zig fmt: var type" { | 1744 | test "zig fmt: var type" { |
| 1761 | try testCanonical( | 1745 | try testCanonical( |
| 1762 | \\fn print(args: var) var {} | 1746 | \\fn print(args: var) var {} |
| ... | @@ -2705,9 +2689,9 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b | ... | @@ -2705,9 +2689,9 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b |
| 2705 | while (error_it.next()) |parse_error| { | 2689 | while (error_it.next()) |parse_error| { |
| 2706 | const token = tree.tokens.at(parse_error.loc()); | 2690 | const token = tree.tokens.at(parse_error.loc()); |
| 2707 | const loc = tree.tokenLocation(0, parse_error.loc()); | 2691 | const loc = tree.tokenLocation(0, parse_error.loc()); |
| 2708 | try stderr.print("(memory buffer):{}:{}: error: ", loc.line + 1, loc.column + 1); | 2692 | try stderr.print("(memory buffer):{}:{}: error: ", .{ loc.line + 1, loc.column + 1 }); |
| 2709 | try tree.renderError(parse_error, stderr); | 2693 | try tree.renderError(parse_error, stderr); |
| 2710 | try stderr.print("\n{}\n", source[loc.line_start..loc.line_end]); | 2694 | try stderr.print("\n{}\n", .{source[loc.line_start..loc.line_end]}); |
| 2711 | { | 2695 | { |
| 2712 | var i: usize = 0; | 2696 | var i: usize = 0; |
| 2713 | while (i < loc.column) : (i += 1) { | 2697 | while (i < loc.column) : (i += 1) { |
| ... | @@ -2743,16 +2727,16 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { | ... | @@ -2743,16 +2727,16 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { |
| 2743 | var anything_changed: bool = undefined; | 2727 | var anything_changed: bool = undefined; |
| 2744 | const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed); | 2728 | const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed); |
| 2745 | if (!mem.eql(u8, result_source, expected_source)) { | 2729 | if (!mem.eql(u8, result_source, expected_source)) { |
| 2746 | warn("\n====== expected this output: =========\n"); | 2730 | warn("\n====== expected this output: =========\n", .{}); |
| 2747 | warn("{}", expected_source); | 2731 | warn("{}", .{expected_source}); |
| 2748 | warn("\n======== instead found this: =========\n"); | 2732 | warn("\n======== instead found this: =========\n", .{}); |
| 2749 | warn("{}", result_source); | 2733 | warn("{}", .{result_source}); |
| 2750 | warn("\n======================================\n"); | 2734 | warn("\n======================================\n", .{}); |
| 2751 | return error.TestFailed; | 2735 | return error.TestFailed; |
| 2752 | } | 2736 | } |
| 2753 | const changes_expected = source.ptr != expected_source.ptr; | 2737 | const changes_expected = source.ptr != expected_source.ptr; |
| 2754 | if (anything_changed != changes_expected) { | 2738 | if (anything_changed != changes_expected) { |
| 2755 | warn("std.zig.render returned {} instead of {}\n", anything_changed, changes_expected); | 2739 | warn("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected }); |
| 2756 | return error.TestFailed; | 2740 | return error.TestFailed; |
| 2757 | } | 2741 | } |
| 2758 | std.testing.expect(anything_changed == changes_expected); | 2742 | std.testing.expect(anything_changed == changes_expected); |
| ... | @@ -2772,12 +2756,14 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { | ... | @@ -2772,12 +2756,14 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { |
| 2772 | if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) { | 2756 | if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) { |
| 2773 | warn( | 2757 | warn( |
| 2774 | "\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n", | 2758 | "\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n", |
| 2775 | fail_index, | 2759 | .{ |
| 2776 | needed_alloc_count, | 2760 | fail_index, |
| 2777 | failing_allocator.allocated_bytes, | 2761 | needed_alloc_count, |
| 2778 | failing_allocator.freed_bytes, | 2762 | failing_allocator.allocated_bytes, |
| 2779 | failing_allocator.allocations, | 2763 | failing_allocator.freed_bytes, |
| 2780 | failing_allocator.deallocations, | 2764 | failing_allocator.allocations, |
| 2765 | failing_allocator.deallocations, | ||
| 2766 | }, | ||
| 2781 | ); | 2767 | ); |
| 2782 | return error.MemoryLeakDetected; | 2768 | return error.MemoryLeakDetected; |
| 2783 | } | 2769 | } |
lib/std/zig/render.zig+3-3| ... | @@ -76,7 +76,7 @@ fn renderRoot( | ... | @@ -76,7 +76,7 @@ fn renderRoot( |
| 76 | // render all the line comments at the beginning of the file | 76 | // render all the line comments at the beginning of the file |
| 77 | while (tok_it.next()) |token| { | 77 | while (tok_it.next()) |token| { |
| 78 | if (token.id != .LineComment) break; | 78 | if (token.id != .LineComment) break; |
| 79 | try stream.print("{}\n", mem.trimRight(u8, tree.tokenSlicePtr(token), " ")); | 79 | try stream.print("{}\n", .{mem.trimRight(u8, tree.tokenSlicePtr(token), " ")}); |
| 80 | if (tok_it.peek()) |next_token| { | 80 | if (tok_it.peek()) |next_token| { |
| 81 | const loc = tree.tokenLocationPtr(token.end, next_token); | 81 | const loc = tree.tokenLocationPtr(token.end, next_token); |
| 82 | if (loc.line >= 2) { | 82 | if (loc.line >= 2) { |
| ... | @@ -1226,7 +1226,7 @@ fn renderExpression( | ... | @@ -1226,7 +1226,7 @@ fn renderExpression( |
| 1226 | 1226 | ||
| 1227 | var skip_first_indent = true; | 1227 | var skip_first_indent = true; |
| 1228 | if (tree.tokens.at(multiline_str_literal.firstToken() - 1).id != .LineComment) { | 1228 | if (tree.tokens.at(multiline_str_literal.firstToken() - 1).id != .LineComment) { |
| 1229 | try stream.print("\n"); | 1229 | try stream.print("\n", .{}); |
| 1230 | skip_first_indent = false; | 1230 | skip_first_indent = false; |
| 1231 | } | 1231 | } |
| 1232 | 1232 | ||
| ... | @@ -2129,7 +2129,7 @@ fn renderTokenOffset( | ... | @@ -2129,7 +2129,7 @@ fn renderTokenOffset( |
| 2129 | 2129 | ||
| 2130 | var loc = tree.tokenLocationPtr(token.end, next_token); | 2130 | var loc = tree.tokenLocationPtr(token.end, next_token); |
| 2131 | if (loc.line == 0) { | 2131 | if (loc.line == 0) { |
| 2132 | try stream.print(" {}", mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ")); | 2132 | try stream.print(" {}", .{mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ")}); |
| 2133 | offset = 2; | 2133 | offset = 2; |
| 2134 | token = next_token; | 2134 | token = next_token; |
| 2135 | next_token = tree.tokens.at(token_index + offset); | 2135 | next_token = tree.tokens.at(token_index + offset); |
lib/std/zig/tokenizer.zig+2-2| ... | @@ -330,7 +330,7 @@ pub const Tokenizer = struct { | ... | @@ -330,7 +330,7 @@ pub const Tokenizer = struct { |
| 330 | 330 | ||
| 331 | /// For debugging purposes | 331 | /// For debugging purposes |
| 332 | pub fn dump(self: *Tokenizer, token: *const Token) void { | 332 | pub fn dump(self: *Tokenizer, token: *const Token) void { |
| 333 | std.debug.warn("{} \"{}\"\n", @tagName(token.id), self.buffer[token.start..token.end]); | 333 | std.debug.warn("{} \"{}\"\n", .{ @tagName(token.id), self.buffer[token.start..token.end] }); |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | pub fn init(buffer: []const u8) Tokenizer { | 336 | pub fn init(buffer: []const u8) Tokenizer { |
| ... | @@ -1576,7 +1576,7 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void { | ... | @@ -1576,7 +1576,7 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void { |
| 1576 | for (expected_tokens) |expected_token_id| { | 1576 | for (expected_tokens) |expected_token_id| { |
| 1577 | const token = tokenizer.next(); | 1577 | const token = tokenizer.next(); |
| 1578 | if (token.id != expected_token_id) { | 1578 | if (token.id != expected_token_id) { |
| 1579 | std.debug.panic("expected {}, found {}\n", @tagName(expected_token_id), @tagName(token.id)); | 1579 | std.debug.panic("expected {}, found {}\n", .{ @tagName(expected_token_id), @tagName(token.id) }); |
| 1580 | } | 1580 | } |
| 1581 | } | 1581 | } |
| 1582 | const last_token = tokenizer.next(); | 1582 | const last_token = tokenizer.next(); |
src-self-hosted/arg.zig+6-6| ... | @@ -98,15 +98,15 @@ pub const Args = struct { | ... | @@ -98,15 +98,15 @@ pub const Args = struct { |
| 98 | const flag_args = readFlagArguments(allocator, args, flag.required, flag.allowed_set, &i) catch |err| { | 98 | const flag_args = readFlagArguments(allocator, args, flag.required, flag.allowed_set, &i) catch |err| { |
| 99 | switch (err) { | 99 | switch (err) { |
| 100 | error.ArgumentNotInAllowedSet => { | 100 | error.ArgumentNotInAllowedSet => { |
| 101 | std.debug.warn("argument '{}' is invalid for flag '{}'\n", args[i], arg); | 101 | std.debug.warn("argument '{}' is invalid for flag '{}'\n", .{ args[i], arg }); |
| 102 | std.debug.warn("allowed options are "); | 102 | std.debug.warn("allowed options are ", .{}); |
| 103 | for (flag.allowed_set.?) |possible| { | 103 | for (flag.allowed_set.?) |possible| { |
| 104 | std.debug.warn("'{}' ", possible); | 104 | std.debug.warn("'{}' ", .{possible}); |
| 105 | } | 105 | } |
| 106 | std.debug.warn("\n"); | 106 | std.debug.warn("\n", .{}); |
| 107 | }, | 107 | }, |
| 108 | error.MissingFlagArguments => { | 108 | error.MissingFlagArguments => { |
| 109 | std.debug.warn("missing argument for flag: {}\n", arg); | 109 | std.debug.warn("missing argument for flag: {}\n", .{arg}); |
| 110 | }, | 110 | }, |
| 111 | else => {}, | 111 | else => {}, |
| 112 | } | 112 | } |
| ... | @@ -134,7 +134,7 @@ pub const Args = struct { | ... | @@ -134,7 +134,7 @@ pub const Args = struct { |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | // TODO: Better errors with context, global error state and return is sufficient. | 136 | // TODO: Better errors with context, global error state and return is sufficient. |
| 137 | std.debug.warn("could not match flag: {}\n", arg); | 137 | std.debug.warn("could not match flag: {}\n", .{arg}); |
| 138 | return error.UnknownFlag; | 138 | return error.UnknownFlag; |
| 139 | } else { | 139 | } else { |
| 140 | try parsed.positionals.append(arg); | 140 | try parsed.positionals.append(arg); |
src-self-hosted/dep_tokenizer.zig+15-15| ... | @@ -38,7 +38,7 @@ pub const Tokenizer = struct { | ... | @@ -38,7 +38,7 @@ pub const Tokenizer = struct { |
| 38 | }, | 38 | }, |
| 39 | .target => |*target| switch (char) { | 39 | .target => |*target| switch (char) { |
| 40 | '\t', '\n', '\r', ' ' => { | 40 | '\t', '\n', '\r', ' ' => { |
| 41 | return self.errorIllegalChar(self.index, char, "invalid target"); | 41 | return self.errorIllegalChar(self.index, char, "invalid target", .{}); |
| 42 | }, | 42 | }, |
| 43 | '$' => { | 43 | '$' => { |
| 44 | self.state = State{ .target_dollar_sign = target.* }; | 44 | self.state = State{ .target_dollar_sign = target.* }; |
| ... | @@ -59,7 +59,7 @@ pub const Tokenizer = struct { | ... | @@ -59,7 +59,7 @@ pub const Tokenizer = struct { |
| 59 | }, | 59 | }, |
| 60 | .target_reverse_solidus => |*target| switch (char) { | 60 | .target_reverse_solidus => |*target| switch (char) { |
| 61 | '\t', '\n', '\r' => { | 61 | '\t', '\n', '\r' => { |
| 62 | return self.errorIllegalChar(self.index, char, "bad target escape"); | 62 | return self.errorIllegalChar(self.index, char, "bad target escape", .{}); |
| 63 | }, | 63 | }, |
| 64 | ' ', '#', '\\' => { | 64 | ' ', '#', '\\' => { |
| 65 | try target.appendByte(char); | 65 | try target.appendByte(char); |
| ... | @@ -84,7 +84,7 @@ pub const Tokenizer = struct { | ... | @@ -84,7 +84,7 @@ pub const Tokenizer = struct { |
| 84 | break; // advance | 84 | break; // advance |
| 85 | }, | 85 | }, |
| 86 | else => { | 86 | else => { |
| 87 | return self.errorIllegalChar(self.index, char, "expecting '$'"); | 87 | return self.errorIllegalChar(self.index, char, "expecting '$'", .{}); |
| 88 | }, | 88 | }, |
| 89 | }, | 89 | }, |
| 90 | .target_colon => |*target| switch (char) { | 90 | .target_colon => |*target| switch (char) { |
| ... | @@ -161,7 +161,7 @@ pub const Tokenizer = struct { | ... | @@ -161,7 +161,7 @@ pub const Tokenizer = struct { |
| 161 | break; // advance | 161 | break; // advance |
| 162 | }, | 162 | }, |
| 163 | else => { | 163 | else => { |
| 164 | return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line"); | 164 | return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line", .{}); |
| 165 | }, | 165 | }, |
| 166 | }, | 166 | }, |
| 167 | .rhs_continuation_linefeed => switch (char) { | 167 | .rhs_continuation_linefeed => switch (char) { |
| ... | @@ -170,7 +170,7 @@ pub const Tokenizer = struct { | ... | @@ -170,7 +170,7 @@ pub const Tokenizer = struct { |
| 170 | break; // advance | 170 | break; // advance |
| 171 | }, | 171 | }, |
| 172 | else => { | 172 | else => { |
| 173 | return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line"); | 173 | return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line", .{}); |
| 174 | }, | 174 | }, |
| 175 | }, | 175 | }, |
| 176 | .prereq_quote => |*prereq| switch (char) { | 176 | .prereq_quote => |*prereq| switch (char) { |
| ... | @@ -231,7 +231,7 @@ pub const Tokenizer = struct { | ... | @@ -231,7 +231,7 @@ pub const Tokenizer = struct { |
| 231 | return Token{ .id = .prereq, .bytes = bytes }; | 231 | return Token{ .id = .prereq, .bytes = bytes }; |
| 232 | }, | 232 | }, |
| 233 | else => { | 233 | else => { |
| 234 | return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line"); | 234 | return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line", .{}); |
| 235 | }, | 235 | }, |
| 236 | }, | 236 | }, |
| 237 | } | 237 | } |
| ... | @@ -249,13 +249,13 @@ pub const Tokenizer = struct { | ... | @@ -249,13 +249,13 @@ pub const Tokenizer = struct { |
| 249 | .rhs_continuation_linefeed, | 249 | .rhs_continuation_linefeed, |
| 250 | => {}, | 250 | => {}, |
| 251 | .target => |target| { | 251 | .target => |target| { |
| 252 | return self.errorPosition(idx, target.toSlice(), "incomplete target"); | 252 | return self.errorPosition(idx, target.toSlice(), "incomplete target", .{}); |
| 253 | }, | 253 | }, |
| 254 | .target_reverse_solidus, | 254 | .target_reverse_solidus, |
| 255 | .target_dollar_sign, | 255 | .target_dollar_sign, |
| 256 | => { | 256 | => { |
| 257 | const index = self.index - 1; | 257 | const index = self.index - 1; |
| 258 | return self.errorIllegalChar(idx, self.bytes[idx], "incomplete escape"); | 258 | return self.errorIllegalChar(idx, self.bytes[idx], "incomplete escape", .{}); |
| 259 | }, | 259 | }, |
| 260 | .target_colon => |target| { | 260 | .target_colon => |target| { |
| 261 | const bytes = target.toSlice(); | 261 | const bytes = target.toSlice(); |
| ... | @@ -278,7 +278,7 @@ pub const Tokenizer = struct { | ... | @@ -278,7 +278,7 @@ pub const Tokenizer = struct { |
| 278 | self.state = State{ .lhs = {} }; | 278 | self.state = State{ .lhs = {} }; |
| 279 | }, | 279 | }, |
| 280 | .prereq_quote => |prereq| { | 280 | .prereq_quote => |prereq| { |
| 281 | return self.errorPosition(idx, prereq.toSlice(), "incomplete quoted prerequisite"); | 281 | return self.errorPosition(idx, prereq.toSlice(), "incomplete quoted prerequisite", .{}); |
| 282 | }, | 282 | }, |
| 283 | .prereq => |prereq| { | 283 | .prereq => |prereq| { |
| 284 | const bytes = prereq.toSlice(); | 284 | const bytes = prereq.toSlice(); |
| ... | @@ -299,29 +299,29 @@ pub const Tokenizer = struct { | ... | @@ -299,29 +299,29 @@ pub const Tokenizer = struct { |
| 299 | return null; | 299 | return null; |
| 300 | } | 300 | } |
| 301 | 301 | ||
| 302 | fn errorf(self: *Tokenizer, comptime fmt: []const u8, args: ...) Error { | 302 | fn errorf(self: *Tokenizer, comptime fmt: []const u8, args: var) Error { |
| 303 | self.error_text = (try std.Buffer.allocPrint(&self.arena.allocator, fmt, args)).toSlice(); | 303 | self.error_text = (try std.Buffer.allocPrint(&self.arena.allocator, fmt, args)).toSlice(); |
| 304 | return Error.InvalidInput; | 304 | return Error.InvalidInput; |
| 305 | } | 305 | } |
| 306 | 306 | ||
| 307 | fn errorPosition(self: *Tokenizer, position: usize, bytes: []const u8, comptime fmt: []const u8, args: ...) Error { | 307 | fn errorPosition(self: *Tokenizer, position: usize, bytes: []const u8, comptime fmt: []const u8, args: var) Error { |
| 308 | var buffer = try std.Buffer.initSize(&self.arena.allocator, 0); | 308 | var buffer = try std.Buffer.initSize(&self.arena.allocator, 0); |
| 309 | std.fmt.format(&buffer, anyerror, std.Buffer.append, fmt, args) catch {}; | 309 | std.fmt.format(&buffer, anyerror, std.Buffer.append, fmt, args) catch {}; |
| 310 | try buffer.append(" '"); | 310 | try buffer.append(" '"); |
| 311 | var out = makeOutput(std.Buffer.append, &buffer); | 311 | var out = makeOutput(std.Buffer.append, &buffer); |
| 312 | try printCharValues(&out, bytes); | 312 | try printCharValues(&out, bytes); |
| 313 | try buffer.append("'"); | 313 | try buffer.append("'"); |
| 314 | std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", position - (bytes.len - 1)) catch {}; | 314 | std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", .{position - (bytes.len - 1)}) catch {}; |
| 315 | self.error_text = buffer.toSlice(); | 315 | self.error_text = buffer.toSlice(); |
| 316 | return Error.InvalidInput; | 316 | return Error.InvalidInput; |
| 317 | } | 317 | } |
| 318 | 318 | ||
| 319 | fn errorIllegalChar(self: *Tokenizer, position: usize, char: u8, comptime fmt: []const u8, args: ...) Error { | 319 | fn errorIllegalChar(self: *Tokenizer, position: usize, char: u8, comptime fmt: []const u8, args: var) Error { |
| 320 | var buffer = try std.Buffer.initSize(&self.arena.allocator, 0); | 320 | var buffer = try std.Buffer.initSize(&self.arena.allocator, 0); |
| 321 | try buffer.append("illegal char "); | 321 | try buffer.append("illegal char "); |
| 322 | var out = makeOutput(std.Buffer.append, &buffer); | 322 | var out = makeOutput(std.Buffer.append, &buffer); |
| 323 | try printUnderstandableChar(&out, char); | 323 | try printUnderstandableChar(&out, char); |
| 324 | std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", position) catch {}; | 324 | std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", .{position}) catch {}; |
| 325 | if (fmt.len != 0) std.fmt.format(&buffer, anyerror, std.Buffer.append, ": " ++ fmt, args) catch {}; | 325 | if (fmt.len != 0) std.fmt.format(&buffer, anyerror, std.Buffer.append, ": " ++ fmt, args) catch {}; |
| 326 | self.error_text = buffer.toSlice(); | 326 | self.error_text = buffer.toSlice(); |
| 327 | return Error.InvalidInput; | 327 | return Error.InvalidInput; |
| ... | @@ -998,7 +998,7 @@ fn printCharValues(out: var, bytes: []const u8) !void { | ... | @@ -998,7 +998,7 @@ fn printCharValues(out: var, bytes: []const u8) !void { |
| 998 | 998 | ||
| 999 | fn printUnderstandableChar(out: var, char: u8) !void { | 999 | fn printUnderstandableChar(out: var, char: u8) !void { |
| 1000 | if (!std.ascii.isPrint(char) or char == ' ') { | 1000 | if (!std.ascii.isPrint(char) or char == ' ') { |
| 1001 | std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", char) catch {}; | 1001 | std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", .{char}) catch {}; |
| 1002 | } else { | 1002 | } else { |
| 1003 | try out.write("'"); | 1003 | try out.write("'"); |
| 1004 | try out.write(&[_]u8{printable_char_tab[char]}); | 1004 | try out.write(&[_]u8{printable_char_tab[char]}); |
src-self-hosted/stage1.zig+6-6| ... | @@ -205,7 +205,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void { | ... | @@ -205,7 +205,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void { |
| 205 | defer allocator.free(source_code); | 205 | defer allocator.free(source_code); |
| 206 | 206 | ||
| 207 | const tree = std.zig.parse(allocator, source_code) catch |err| { | 207 | const tree = std.zig.parse(allocator, source_code) catch |err| { |
| 208 | try stderr.print("error parsing stdin: {}\n", err); | 208 | try stderr.print("error parsing stdin: {}\n", .{err}); |
| 209 | process.exit(1); | 209 | process.exit(1); |
| 210 | }; | 210 | }; |
| 211 | defer tree.deinit(); | 211 | defer tree.deinit(); |
| ... | @@ -294,7 +294,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void | ... | @@ -294,7 +294,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void |
| 294 | }, | 294 | }, |
| 295 | else => { | 295 | else => { |
| 296 | // TODO lock stderr printing | 296 | // TODO lock stderr printing |
| 297 | try stderr.print("unable to open '{}': {}\n", file_path, err); | 297 | try stderr.print("unable to open '{}': {}\n", .{ file_path, err }); |
| 298 | fmt.any_error = true; | 298 | fmt.any_error = true; |
| 299 | return; | 299 | return; |
| 300 | }, | 300 | }, |
| ... | @@ -302,7 +302,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void | ... | @@ -302,7 +302,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void |
| 302 | defer fmt.allocator.free(source_code); | 302 | defer fmt.allocator.free(source_code); |
| 303 | 303 | ||
| 304 | const tree = std.zig.parse(fmt.allocator, source_code) catch |err| { | 304 | const tree = std.zig.parse(fmt.allocator, source_code) catch |err| { |
| 305 | try stderr.print("error parsing file '{}': {}\n", file_path, err); | 305 | try stderr.print("error parsing file '{}': {}\n", .{ file_path, err }); |
| 306 | fmt.any_error = true; | 306 | fmt.any_error = true; |
| 307 | return; | 307 | return; |
| 308 | }; | 308 | }; |
| ... | @@ -320,7 +320,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void | ... | @@ -320,7 +320,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void |
| 320 | if (check_mode) { | 320 | if (check_mode) { |
| 321 | const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, tree); | 321 | const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, tree); |
| 322 | if (anything_changed) { | 322 | if (anything_changed) { |
| 323 | try stderr.print("{}\n", file_path); | 323 | try stderr.print("{}\n", .{file_path}); |
| 324 | fmt.any_error = true; | 324 | fmt.any_error = true; |
| 325 | } | 325 | } |
| 326 | } else { | 326 | } else { |
| ... | @@ -329,7 +329,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void | ... | @@ -329,7 +329,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void |
| 329 | 329 | ||
| 330 | const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree); | 330 | const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree); |
| 331 | if (anything_changed) { | 331 | if (anything_changed) { |
| 332 | try stderr.print("{}\n", file_path); | 332 | try stderr.print("{}\n", .{file_path}); |
| 333 | try baf.finish(); | 333 | try baf.finish(); |
| 334 | } | 334 | } |
| 335 | } | 335 | } |
| ... | @@ -374,7 +374,7 @@ fn printErrMsgToFile( | ... | @@ -374,7 +374,7 @@ fn printErrMsgToFile( |
| 374 | const text = text_buf.toOwnedSlice(); | 374 | const text = text_buf.toOwnedSlice(); |
| 375 | 375 | ||
| 376 | const stream = &file.outStream().stream; | 376 | const stream = &file.outStream().stream; |
| 377 | try stream.print("{}:{}:{}: error: {}\n", path, start_loc.line + 1, start_loc.column + 1, text); | 377 | try stream.print("{}:{}:{}: error: {}\n", .{ path, start_loc.line + 1, start_loc.column + 1, text }); |
| 378 | 378 | ||
| 379 | if (!color_on) return; | 379 | if (!color_on) return; |
| 380 | 380 |
src-self-hosted/translate_c.zig+49-30| ... | @@ -125,7 +125,7 @@ const Context = struct { | ... | @@ -125,7 +125,7 @@ const Context = struct { |
| 125 | 125 | ||
| 126 | const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc); | 126 | const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc); |
| 127 | const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc); | 127 | const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc); |
| 128 | return std.fmt.allocPrint(c.a(), "{}:{}:{}", filename, line, column); | 128 | return std.fmt.allocPrint(c.a(), "{}:{}:{}", .{ filename, line, column }); |
| 129 | } | 129 | } |
| 130 | }; | 130 | }; |
| 131 | 131 | ||
| ... | @@ -228,20 +228,20 @@ fn declVisitor(c: *Context, decl: *const ZigClangDecl) Error!void { | ... | @@ -228,20 +228,20 @@ fn declVisitor(c: *Context, decl: *const ZigClangDecl) Error!void { |
| 228 | return visitFnDecl(c, @ptrCast(*const ZigClangFunctionDecl, decl)); | 228 | return visitFnDecl(c, @ptrCast(*const ZigClangFunctionDecl, decl)); |
| 229 | }, | 229 | }, |
| 230 | .Typedef => { | 230 | .Typedef => { |
| 231 | try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for typedefs"); | 231 | try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for typedefs", .{}); |
| 232 | }, | 232 | }, |
| 233 | .Enum => { | 233 | .Enum => { |
| 234 | try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for enums"); | 234 | try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for enums", .{}); |
| 235 | }, | 235 | }, |
| 236 | .Record => { | 236 | .Record => { |
| 237 | try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for structs"); | 237 | try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for structs", .{}); |
| 238 | }, | 238 | }, |
| 239 | .Var => { | 239 | .Var => { |
| 240 | try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for variables"); | 240 | try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for variables", .{}); |
| 241 | }, | 241 | }, |
| 242 | else => { | 242 | else => { |
| 243 | const decl_name = try c.str(ZigClangDecl_getDeclKindName(decl)); | 243 | const decl_name = try c.str(ZigClangDecl_getDeclKindName(decl)); |
| 244 | try emitWarning(c, ZigClangDecl_getLocation(decl), "ignoring {} declaration", decl_name); | 244 | try emitWarning(c, ZigClangDecl_getLocation(decl), "ignoring {} declaration", .{decl_name}); |
| 245 | }, | 245 | }, |
| 246 | } | 246 | } |
| 247 | } | 247 | } |
| ... | @@ -264,7 +264,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | ... | @@ -264,7 +264,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 264 | .is_export = switch (storage_class) { | 264 | .is_export = switch (storage_class) { |
| 265 | .None => has_body and c.mode != .import, | 265 | .None => has_body and c.mode != .import, |
| 266 | .Extern, .Static => false, | 266 | .Extern, .Static => false, |
| 267 | .PrivateExtern => return failDecl(c, fn_decl_loc, fn_name, "unsupported storage class: private extern"), | 267 | .PrivateExtern => return failDecl(c, fn_decl_loc, fn_name, "unsupported storage class: private extern", .{}), |
| 268 | .Auto => unreachable, // Not legal on functions | 268 | .Auto => unreachable, // Not legal on functions |
| 269 | .Register => unreachable, // Not legal on functions | 269 | .Register => unreachable, // Not legal on functions |
| 270 | }, | 270 | }, |
| ... | @@ -274,7 +274,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | ... | @@ -274,7 +274,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 274 | const fn_proto_type = @ptrCast(*const ZigClangFunctionProtoType, fn_type); | 274 | const fn_proto_type = @ptrCast(*const ZigClangFunctionProtoType, fn_type); |
| 275 | break :blk transFnProto(rp, fn_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) { | 275 | break :blk transFnProto(rp, fn_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) { |
| 276 | error.UnsupportedType => { | 276 | error.UnsupportedType => { |
| 277 | return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function"); | 277 | return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{}); |
| 278 | }, | 278 | }, |
| 279 | error.OutOfMemory => |e| return e, | 279 | error.OutOfMemory => |e| return e, |
| 280 | }; | 280 | }; |
| ... | @@ -283,7 +283,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | ... | @@ -283,7 +283,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 283 | const fn_no_proto_type = @ptrCast(*const ZigClangFunctionType, fn_type); | 283 | const fn_no_proto_type = @ptrCast(*const ZigClangFunctionType, fn_type); |
| 284 | break :blk transFnNoProto(rp, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) { | 284 | break :blk transFnNoProto(rp, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) { |
| 285 | error.UnsupportedType => { | 285 | error.UnsupportedType => { |
| 286 | return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function"); | 286 | return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{}); |
| 287 | }, | 287 | }, |
| 288 | error.OutOfMemory => |e| return e, | 288 | error.OutOfMemory => |e| return e, |
| 289 | }; | 289 | }; |
| ... | @@ -302,7 +302,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | ... | @@ -302,7 +302,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 302 | error.OutOfMemory => |e| return e, | 302 | error.OutOfMemory => |e| return e, |
| 303 | error.UnsupportedTranslation, | 303 | error.UnsupportedTranslation, |
| 304 | error.UnsupportedType, | 304 | error.UnsupportedType, |
| 305 | => return failDecl(c, fn_decl_loc, fn_name, "unable to translate function"), | 305 | => return failDecl(c, fn_decl_loc, fn_name, "unable to translate function", .{}), |
| 306 | }; | 306 | }; |
| 307 | assert(result.node.id == ast.Node.Id.Block); | 307 | assert(result.node.id == ast.Node.Id.Block); |
| 308 | proto_node.body_node = result.node; | 308 | proto_node.body_node = result.node; |
| ... | @@ -344,7 +344,7 @@ fn transStmt( | ... | @@ -344,7 +344,7 @@ fn transStmt( |
| 344 | error.UnsupportedTranslation, | 344 | error.UnsupportedTranslation, |
| 345 | ZigClangStmt_getBeginLoc(stmt), | 345 | ZigClangStmt_getBeginLoc(stmt), |
| 346 | "TODO implement translation of stmt class {}", | 346 | "TODO implement translation of stmt class {}", |
| 347 | @tagName(sc), | 347 | .{@tagName(sc)}, |
| 348 | ); | 348 | ); |
| 349 | }, | 349 | }, |
| 350 | } | 350 | } |
| ... | @@ -364,7 +364,7 @@ fn transBinaryOperator( | ... | @@ -364,7 +364,7 @@ fn transBinaryOperator( |
| 364 | error.UnsupportedTranslation, | 364 | error.UnsupportedTranslation, |
| 365 | ZigClangBinaryOperator_getBeginLoc(stmt), | 365 | ZigClangBinaryOperator_getBeginLoc(stmt), |
| 366 | "TODO: handle more C binary operators: {}", | 366 | "TODO: handle more C binary operators: {}", |
| 367 | op, | 367 | .{op}, |
| 368 | ), | 368 | ), |
| 369 | .Assign => return TransResult{ | 369 | .Assign => return TransResult{ |
| 370 | .node = &(try transCreateNodeAssign(rp, scope, result_used, ZigClangBinaryOperator_getLHS(stmt), ZigClangBinaryOperator_getRHS(stmt))).base, | 370 | .node = &(try transCreateNodeAssign(rp, scope, result_used, ZigClangBinaryOperator_getLHS(stmt), ZigClangBinaryOperator_getRHS(stmt))).base, |
| ... | @@ -415,7 +415,7 @@ fn transBinaryOperator( | ... | @@ -415,7 +415,7 @@ fn transBinaryOperator( |
| 415 | error.UnsupportedTranslation, | 415 | error.UnsupportedTranslation, |
| 416 | ZigClangBinaryOperator_getBeginLoc(stmt), | 416 | ZigClangBinaryOperator_getBeginLoc(stmt), |
| 417 | "TODO: handle more C binary operators: {}", | 417 | "TODO: handle more C binary operators: {}", |
| 418 | op, | 418 | .{op}, |
| 419 | ), | 419 | ), |
| 420 | .MulAssign, | 420 | .MulAssign, |
| 421 | .DivAssign, | 421 | .DivAssign, |
| ... | @@ -567,7 +567,7 @@ fn transDeclStmt(rp: RestorePoint, parent_scope: *Scope, stmt: *const ZigClangDe | ... | @@ -567,7 +567,7 @@ fn transDeclStmt(rp: RestorePoint, parent_scope: *Scope, stmt: *const ZigClangDe |
| 567 | error.UnsupportedTranslation, | 567 | error.UnsupportedTranslation, |
| 568 | ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)), | 568 | ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)), |
| 569 | "TODO implement translation of DeclStmt kind {}", | 569 | "TODO implement translation of DeclStmt kind {}", |
| 570 | @tagName(kind), | 570 | .{@tagName(kind)}, |
| 571 | ), | 571 | ), |
| 572 | } | 572 | } |
| 573 | } | 573 | } |
| ... | @@ -636,7 +636,7 @@ fn transImplicitCastExpr( | ... | @@ -636,7 +636,7 @@ fn transImplicitCastExpr( |
| 636 | error.UnsupportedTranslation, | 636 | error.UnsupportedTranslation, |
| 637 | ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, expr)), | 637 | ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, expr)), |
| 638 | "TODO implement translation of CastKind {}", | 638 | "TODO implement translation of CastKind {}", |
| 639 | @tagName(kind), | 639 | .{@tagName(kind)}, |
| 640 | ), | 640 | ), |
| 641 | } | 641 | } |
| 642 | } | 642 | } |
| ... | @@ -650,7 +650,7 @@ fn transIntegerLiteral( | ... | @@ -650,7 +650,7 @@ fn transIntegerLiteral( |
| 650 | var eval_result: ZigClangExprEvalResult = undefined; | 650 | var eval_result: ZigClangExprEvalResult = undefined; |
| 651 | if (!ZigClangIntegerLiteral_EvaluateAsInt(expr, &eval_result, rp.c.clang_context)) { | 651 | if (!ZigClangIntegerLiteral_EvaluateAsInt(expr, &eval_result, rp.c.clang_context)) { |
| 652 | const loc = ZigClangIntegerLiteral_getBeginLoc(expr); | 652 | const loc = ZigClangIntegerLiteral_getBeginLoc(expr); |
| 653 | return revertAndWarn(rp, error.UnsupportedTranslation, loc, "invalid integer literal"); | 653 | return revertAndWarn(rp, error.UnsupportedTranslation, loc, "invalid integer literal", .{}); |
| 654 | } | 654 | } |
| 655 | const node = try transCreateNodeAPInt(rp.c, ZigClangAPValue_getInt(&eval_result.Val)); | 655 | const node = try transCreateNodeAPInt(rp.c, ZigClangAPValue_getInt(&eval_result.Val)); |
| 656 | const res = TransResult{ | 656 | const res = TransResult{ |
| ... | @@ -719,7 +719,7 @@ fn transStringLiteral( | ... | @@ -719,7 +719,7 @@ fn transStringLiteral( |
| 719 | error.UnsupportedTranslation, | 719 | error.UnsupportedTranslation, |
| 720 | ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)), | 720 | ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)), |
| 721 | "TODO: support string literal kind {}", | 721 | "TODO: support string literal kind {}", |
| 722 | kind, | 722 | .{kind}, |
| 723 | ), | 723 | ), |
| 724 | } | 724 | } |
| 725 | } | 725 | } |
| ... | @@ -751,7 +751,7 @@ fn escapeChar(c: u8, char_buf: *[4]u8) []const u8 { | ... | @@ -751,7 +751,7 @@ fn escapeChar(c: u8, char_buf: *[4]u8) []const u8 { |
| 751 | '\n' => return "\\n"[0..], | 751 | '\n' => return "\\n"[0..], |
| 752 | '\r' => return "\\r"[0..], | 752 | '\r' => return "\\r"[0..], |
| 753 | '\t' => return "\\t"[0..], | 753 | '\t' => return "\\t"[0..], |
| 754 | else => return std.fmt.bufPrint(char_buf[0..], "\\x{x:2}", c) catch unreachable, | 754 | else => return std.fmt.bufPrint(char_buf[0..], "\\x{x:2}", .{c}) catch unreachable, |
| 755 | }; | 755 | }; |
| 756 | std.mem.copy(u8, char_buf, escaped); | 756 | std.mem.copy(u8, char_buf, escaped); |
| 757 | return char_buf[0..escaped.len]; | 757 | return char_buf[0..escaped.len]; |
| ... | @@ -1016,7 +1016,13 @@ fn transCreateNodeAssign( | ... | @@ -1016,7 +1016,13 @@ fn transCreateNodeAssign( |
| 1016 | // zig: lhs = _tmp; | 1016 | // zig: lhs = _tmp; |
| 1017 | // zig: break :x _tmp | 1017 | // zig: break :x _tmp |
| 1018 | // zig: }) | 1018 | // zig: }) |
| 1019 | return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangExpr_getBeginLoc(lhs), "TODO: worst case assign op expr"); | 1019 | return revertAndWarn( |
| 1020 | rp, | ||
| 1021 | error.UnsupportedTranslation, | ||
| 1022 | ZigClangExpr_getBeginLoc(lhs), | ||
| 1023 | "TODO: worst case assign op expr", | ||
| 1024 | .{}, | ||
| 1025 | ); | ||
| 1020 | } | 1026 | } |
| 1021 | 1027 | ||
| 1022 | fn transCreateNodeBuiltinFnCall(c: *Context, name: []const u8) !*ast.Node.BuiltinCall { | 1028 | fn transCreateNodeBuiltinFnCall(c: *Context, name: []const u8) !*ast.Node.BuiltinCall { |
| ... | @@ -1211,7 +1217,7 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour | ... | @@ -1211,7 +1217,7 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour |
| 1211 | .Float128 => return appendIdentifier(rp.c, "f128"), | 1217 | .Float128 => return appendIdentifier(rp.c, "f128"), |
| 1212 | .Float16 => return appendIdentifier(rp.c, "f16"), | 1218 | .Float16 => return appendIdentifier(rp.c, "f16"), |
| 1213 | .LongDouble => return appendIdentifier(rp.c, "c_longdouble"), | 1219 | .LongDouble => return appendIdentifier(rp.c, "c_longdouble"), |
| 1214 | else => return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported builtin type"), | 1220 | else => return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported builtin type", .{}), |
| 1215 | } | 1221 | } |
| 1216 | }, | 1222 | }, |
| 1217 | .FunctionProto => { | 1223 | .FunctionProto => { |
| ... | @@ -1253,7 +1259,7 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour | ... | @@ -1253,7 +1259,7 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour |
| 1253 | }, | 1259 | }, |
| 1254 | else => { | 1260 | else => { |
| 1255 | const type_name = rp.c.str(ZigClangType_getTypeClassName(ty)); | 1261 | const type_name = rp.c.str(ZigClangType_getTypeClassName(ty)); |
| 1256 | return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported type: '{}'", type_name); | 1262 | return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported type: '{}'", .{type_name}); |
| 1257 | }, | 1263 | }, |
| 1258 | } | 1264 | } |
| 1259 | } | 1265 | } |
| ... | @@ -1275,7 +1281,13 @@ fn transCC( | ... | @@ -1275,7 +1281,13 @@ fn transCC( |
| 1275 | switch (clang_cc) { | 1281 | switch (clang_cc) { |
| 1276 | .C => return CallingConvention.C, | 1282 | .C => return CallingConvention.C, |
| 1277 | .X86StdCall => return CallingConvention.Stdcall, | 1283 | .X86StdCall => return CallingConvention.Stdcall, |
| 1278 | else => return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported calling convention: {}", @tagName(clang_cc)), | 1284 | else => return revertAndWarn( |
| 1285 | rp, | ||
| 1286 | error.UnsupportedType, | ||
| 1287 | source_loc, | ||
| 1288 | "unsupported calling convention: {}", | ||
| 1289 | .{@tagName(clang_cc)}, | ||
| 1290 | ), | ||
| 1279 | } | 1291 | } |
| 1280 | } | 1292 | } |
| 1281 | 1293 | ||
| ... | @@ -1292,7 +1304,13 @@ fn transFnProto( | ... | @@ -1292,7 +1304,13 @@ fn transFnProto( |
| 1292 | const param_count: usize = ZigClangFunctionProtoType_getNumParams(fn_proto_ty); | 1304 | const param_count: usize = ZigClangFunctionProtoType_getNumParams(fn_proto_ty); |
| 1293 | var i: usize = 0; | 1305 | var i: usize = 0; |
| 1294 | while (i < param_count) : (i += 1) { | 1306 | while (i < param_count) : (i += 1) { |
| 1295 | return revertAndWarn(rp, error.UnsupportedType, source_loc, "TODO: implement parameters for FunctionProto in transType"); | 1307 | return revertAndWarn( |
| 1308 | rp, | ||
| 1309 | error.UnsupportedType, | ||
| 1310 | source_loc, | ||
| 1311 | "TODO: implement parameters for FunctionProto in transType", | ||
| 1312 | .{}, | ||
| 1313 | ); | ||
| 1296 | } | 1314 | } |
| 1297 | 1315 | ||
| 1298 | return finishTransFnProto(rp, fn_ty, source_loc, fn_decl_context, is_var_args, cc, is_pub); | 1316 | return finishTransFnProto(rp, fn_ty, source_loc, fn_decl_context, is_var_args, cc, is_pub); |
| ... | @@ -1350,7 +1368,7 @@ fn finishTransFnProto( | ... | @@ -1350,7 +1368,7 @@ fn finishTransFnProto( |
| 1350 | } else { | 1368 | } else { |
| 1351 | break :blk transQualType(rp, return_qt, source_loc) catch |err| switch (err) { | 1369 | break :blk transQualType(rp, return_qt, source_loc) catch |err| switch (err) { |
| 1352 | error.UnsupportedType => { | 1370 | error.UnsupportedType => { |
| 1353 | try emitWarning(rp.c, source_loc, "unsupported function proto return type"); | 1371 | try emitWarning(rp.c, source_loc, "unsupported function proto return type", .{}); |
| 1354 | return err; | 1372 | return err; |
| 1355 | }, | 1373 | }, |
| 1356 | error.OutOfMemory => |e| return e, | 1374 | error.OutOfMemory => |e| return e, |
| ... | @@ -1397,18 +1415,19 @@ fn revertAndWarn( | ... | @@ -1397,18 +1415,19 @@ fn revertAndWarn( |
| 1397 | err: var, | 1415 | err: var, |
| 1398 | source_loc: ZigClangSourceLocation, | 1416 | source_loc: ZigClangSourceLocation, |
| 1399 | comptime format: []const u8, | 1417 | comptime format: []const u8, |
| 1400 | args: ..., | 1418 | args: var, |
| 1401 | ) (@typeOf(err) || error{OutOfMemory}) { | 1419 | ) (@typeOf(err) || error{OutOfMemory}) { |
| 1402 | rp.activate(); | 1420 | rp.activate(); |
| 1403 | try emitWarning(rp.c, source_loc, format, args); | 1421 | try emitWarning(rp.c, source_loc, format, args); |
| 1404 | return err; | 1422 | return err; |
| 1405 | } | 1423 | } |
| 1406 | 1424 | ||
| 1407 | fn emitWarning(c: *Context, loc: ZigClangSourceLocation, comptime format: []const u8, args: ...) !void { | 1425 | fn emitWarning(c: *Context, loc: ZigClangSourceLocation, comptime format: []const u8, args: var) !void { |
| 1408 | _ = try appendTokenFmt(c, .LineComment, "// {}: warning: " ++ format, c.locStr(loc), args); | 1426 | const args_prefix = .{c.locStr(loc)}; |
| 1427 | _ = try appendTokenFmt(c, .LineComment, "// {}: warning: " ++ format, args_prefix ++ args); | ||
| 1409 | } | 1428 | } |
| 1410 | 1429 | ||
| 1411 | fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime format: []const u8, args: ...) !void { | 1430 | fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime format: []const u8, args: var) !void { |
| 1412 | // const name = @compileError(msg); | 1431 | // const name = @compileError(msg); |
| 1413 | const const_tok = try appendToken(c, .Keyword_const, "const"); | 1432 | const const_tok = try appendToken(c, .Keyword_const, "const"); |
| 1414 | const name_tok = try appendToken(c, .Identifier, name); | 1433 | const name_tok = try appendToken(c, .Identifier, name); |
| ... | @@ -1456,10 +1475,10 @@ fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime | ... | @@ -1456,10 +1475,10 @@ fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime |
| 1456 | } | 1475 | } |
| 1457 | 1476 | ||
| 1458 | fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenIndex { | 1477 | fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenIndex { |
| 1459 | return appendTokenFmt(c, token_id, "{}", bytes); | 1478 | return appendTokenFmt(c, token_id, "{}", .{bytes}); |
| 1460 | } | 1479 | } |
| 1461 | 1480 | ||
| 1462 | fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: ...) !ast.TokenIndex { | 1481 | fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: var) !ast.TokenIndex { |
| 1463 | const S = struct { | 1482 | const S = struct { |
| 1464 | fn callback(context: *Context, bytes: []const u8) error{OutOfMemory}!void { | 1483 | fn callback(context: *Context, bytes: []const u8) error{OutOfMemory}!void { |
| 1465 | return context.source_buffer.append(bytes); | 1484 | return context.source_buffer.append(bytes); |
src/ir.cpp+12-4| ... | @@ -17025,7 +17025,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s | ... | @@ -17025,7 +17025,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 17025 | { | 17025 | { |
| 17026 | result_loc_pass1 = no_result_loc(); | 17026 | result_loc_pass1 = no_result_loc(); |
| 17027 | } | 17027 | } |
| 17028 | bool was_written = result_loc_pass1->written; | 17028 | bool was_already_resolved = result_loc_pass1->resolved_loc != nullptr; |
| 17029 | IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, | 17029 | IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, |
| 17030 | value, force_runtime, non_null_comptime, allow_discard); | 17030 | value, force_runtime, non_null_comptime, allow_discard); |
| 17031 | if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type))) | 17031 | if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type))) |
| ... | @@ -17038,7 +17038,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s | ... | @@ -17038,7 +17038,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 17038 | } | 17038 | } |
| 17039 | 17039 | ||
| 17040 | InferredStructField *isf = result_loc->value->type->data.pointer.inferred_struct_field; | 17040 | InferredStructField *isf = result_loc->value->type->data.pointer.inferred_struct_field; |
| 17041 | if (!was_written && isf != nullptr) { | 17041 | if (!was_already_resolved && isf != nullptr) { |
| 17042 | // Now it's time to add the field to the struct type. | 17042 | // Now it's time to add the field to the struct type. |
| 17043 | uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count; | 17043 | uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count; |
| 17044 | uint32_t new_field_count = old_field_count + 1; | 17044 | uint32_t new_field_count = old_field_count + 1; |
| ... | @@ -18077,7 +18077,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i | ... | @@ -18077,7 +18077,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18077 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { | 18077 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 18078 | return result_loc; | 18078 | return result_loc; |
| 18079 | } | 18079 | } |
| 18080 | if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) { | 18080 | ZigType *res_child_type = result_loc->value->type->data.pointer.child_type; |
| 18081 | if (res_child_type == ira->codegen->builtin_types.entry_var) { | ||
| 18082 | res_child_type = impl_fn_type_id->return_type; | ||
| 18083 | } | ||
| 18084 | if (!handle_is_ptr(res_child_type)) { | ||
| 18081 | ir_reset_result(call_result_loc); | 18085 | ir_reset_result(call_result_loc); |
| 18082 | result_loc = nullptr; | 18086 | result_loc = nullptr; |
| 18083 | } | 18087 | } |
| ... | @@ -18240,7 +18244,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i | ... | @@ -18240,7 +18244,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18240 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { | 18244 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 18241 | return result_loc; | 18245 | return result_loc; |
| 18242 | } | 18246 | } |
| 18243 | if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) { | 18247 | ZigType *res_child_type = result_loc->value->type->data.pointer.child_type; |
| 18248 | if (res_child_type == ira->codegen->builtin_types.entry_var) { | ||
| 18249 | res_child_type = return_type; | ||
| 18250 | } | ||
| 18251 | if (!handle_is_ptr(res_child_type)) { | ||
| 18244 | ir_reset_result(call_result_loc); | 18252 | ir_reset_result(call_result_loc); |
| 18245 | result_loc = nullptr; | 18253 | result_loc = nullptr; |
| 18246 | } | 18254 | } |
test/cli.zig+11-11| ... | @@ -19,11 +19,11 @@ pub fn main() !void { | ... | @@ -19,11 +19,11 @@ pub fn main() !void { |
| 19 | a = &arena.allocator; | 19 | a = &arena.allocator; |
| 20 | 20 | ||
| 21 | const zig_exe_rel = try (arg_it.next(a) orelse { | 21 | const zig_exe_rel = try (arg_it.next(a) orelse { |
| 22 | std.debug.warn("Expected first argument to be path to zig compiler\n"); | 22 | std.debug.warn("Expected first argument to be path to zig compiler\n", .{}); |
| 23 | return error.InvalidArgs; | 23 | return error.InvalidArgs; |
| 24 | }); | 24 | }); |
| 25 | const cache_root = try (arg_it.next(a) orelse { | 25 | const cache_root = try (arg_it.next(a) orelse { |
| 26 | std.debug.warn("Expected second argument to be cache root directory path\n"); | 26 | std.debug.warn("Expected second argument to be cache root directory path\n", .{}); |
| 27 | return error.InvalidArgs; | 27 | return error.InvalidArgs; |
| 28 | }); | 28 | }); |
| 29 | const zig_exe = try fs.path.resolve(a, &[_][]const u8{zig_exe_rel}); | 29 | const zig_exe = try fs.path.resolve(a, &[_][]const u8{zig_exe_rel}); |
| ... | @@ -45,39 +45,39 @@ pub fn main() !void { | ... | @@ -45,39 +45,39 @@ pub fn main() !void { |
| 45 | 45 | ||
| 46 | fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 { | 46 | fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 { |
| 47 | return arg catch |err| { | 47 | return arg catch |err| { |
| 48 | warn("Unable to parse command line: {}\n", err); | 48 | warn("Unable to parse command line: {}\n", .{err}); |
| 49 | return err; | 49 | return err; |
| 50 | }; | 50 | }; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | fn printCmd(cwd: []const u8, argv: []const []const u8) void { | 53 | fn printCmd(cwd: []const u8, argv: []const []const u8) void { |
| 54 | std.debug.warn("cd {} && ", cwd); | 54 | std.debug.warn("cd {} && ", .{cwd}); |
| 55 | for (argv) |arg| { | 55 | for (argv) |arg| { |
| 56 | std.debug.warn("{} ", arg); | 56 | std.debug.warn("{} ", .{arg}); |
| 57 | } | 57 | } |
| 58 | std.debug.warn("\n"); | 58 | std.debug.warn("\n", .{}); |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult { | 61 | fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult { |
| 62 | const max_output_size = 100 * 1024; | 62 | const max_output_size = 100 * 1024; |
| 63 | const result = ChildProcess.exec(a, argv, cwd, null, max_output_size) catch |err| { | 63 | const result = ChildProcess.exec(a, argv, cwd, null, max_output_size) catch |err| { |
| 64 | std.debug.warn("The following command failed:\n"); | 64 | std.debug.warn("The following command failed:\n", .{}); |
| 65 | printCmd(cwd, argv); | 65 | printCmd(cwd, argv); |
| 66 | return err; | 66 | return err; |
| 67 | }; | 67 | }; |
| 68 | switch (result.term) { | 68 | switch (result.term) { |
| 69 | .Exited => |code| { | 69 | .Exited => |code| { |
| 70 | if (code != 0) { | 70 | if (code != 0) { |
| 71 | std.debug.warn("The following command exited with error code {}:\n", code); | 71 | std.debug.warn("The following command exited with error code {}:\n", .{code}); |
| 72 | printCmd(cwd, argv); | 72 | printCmd(cwd, argv); |
| 73 | std.debug.warn("stderr:\n{}\n", result.stderr); | 73 | std.debug.warn("stderr:\n{}\n", .{result.stderr}); |
| 74 | return error.CommandFailed; | 74 | return error.CommandFailed; |
| 75 | } | 75 | } |
| 76 | }, | 76 | }, |
| 77 | else => { | 77 | else => { |
| 78 | std.debug.warn("The following command terminated unexpectedly:\n"); | 78 | std.debug.warn("The following command terminated unexpectedly:\n", .{}); |
| 79 | printCmd(cwd, argv); | 79 | printCmd(cwd, argv); |
| 80 | std.debug.warn("stderr:\n{}\n", result.stderr); | 80 | std.debug.warn("stderr:\n{}\n", .{result.stderr}); |
| 81 | return error.CommandFailed; | 81 | return error.CommandFailed; |
| 82 | }, | 82 | }, |
| 83 | } | 83 | } |
test/compile_errors.zig+2-4| ... | @@ -2598,14 +2598,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2598,14 +2598,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2598 | \\fn a(b: fn (*const u8) void) void { | 2598 | \\fn a(b: fn (*const u8) void) void { |
| 2599 | \\ b('a'); | 2599 | \\ b('a'); |
| 2600 | \\} | 2600 | \\} |
| 2601 | \\fn c(d: u8) void { | 2601 | \\fn c(d: u8) void {} |
| 2602 | \\ @import("std").debug.warn("{c}\n", d); | ||
| 2603 | \\} | ||
| 2604 | \\export fn entry() void { | 2602 | \\export fn entry() void { |
| 2605 | \\ a(c); | 2603 | \\ a(c); |
| 2606 | \\} | 2604 | \\} |
| 2607 | , | 2605 | , |
| 2608 | "tmp.zig:8:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'", | 2606 | "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'", |
| 2609 | ); | 2607 | ); |
| 2610 | 2608 | ||
| 2611 | cases.add( | 2609 | cases.add( |
test/standalone/cat/main.zig+5-5| ... | @@ -23,7 +23,7 @@ pub fn main() !void { | ... | @@ -23,7 +23,7 @@ pub fn main() !void { |
| 23 | return usage(exe); | 23 | return usage(exe); |
| 24 | } else { | 24 | } else { |
| 25 | const file = cwd.openFile(arg, .{}) catch |err| { | 25 | const file = cwd.openFile(arg, .{}) catch |err| { |
| 26 | warn("Unable to open file: {}\n", @errorName(err)); | 26 | warn("Unable to open file: {}\n", .{@errorName(err)}); |
| 27 | return err; | 27 | return err; |
| 28 | }; | 28 | }; |
| 29 | defer file.close(); | 29 | defer file.close(); |
| ... | @@ -38,7 +38,7 @@ pub fn main() !void { | ... | @@ -38,7 +38,7 @@ pub fn main() !void { |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | fn usage(exe: []const u8) !void { | 40 | fn usage(exe: []const u8) !void { |
| 41 | warn("Usage: {} [FILE]...\n", exe); | 41 | warn("Usage: {} [FILE]...\n", .{exe}); |
| 42 | return error.Invalid; | 42 | return error.Invalid; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| ... | @@ -47,7 +47,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void { | ... | @@ -47,7 +47,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void { |
| 47 | 47 | ||
| 48 | while (true) { | 48 | while (true) { |
| 49 | const bytes_read = file.read(buf[0..]) catch |err| { | 49 | const bytes_read = file.read(buf[0..]) catch |err| { |
| 50 | warn("Unable to read from stream: {}\n", @errorName(err)); | 50 | warn("Unable to read from stream: {}\n", .{@errorName(err)}); |
| 51 | return err; | 51 | return err; |
| 52 | }; | 52 | }; |
| 53 | 53 | ||
| ... | @@ -56,7 +56,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void { | ... | @@ -56,7 +56,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void { |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | stdout.write(buf[0..bytes_read]) catch |err| { | 58 | stdout.write(buf[0..bytes_read]) catch |err| { |
| 59 | warn("Unable to write to stdout: {}\n", @errorName(err)); | 59 | warn("Unable to write to stdout: {}\n", .{@errorName(err)}); |
| 60 | return err; | 60 | return err; |
| 61 | }; | 61 | }; |
| 62 | } | 62 | } |
| ... | @@ -64,7 +64,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void { | ... | @@ -64,7 +64,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void { |
| 64 | 64 | ||
| 65 | fn unwrapArg(arg: anyerror![]u8) ![]u8 { | 65 | fn unwrapArg(arg: anyerror![]u8) ![]u8 { |
| 66 | return arg catch |err| { | 66 | return arg catch |err| { |
| 67 | warn("Unable to parse command line: {}\n", err); | 67 | warn("Unable to parse command line: {}\n", .{err}); |
| 68 | return err; | 68 | return err; |
| 69 | }; | 69 | }; |
| 70 | } | 70 | } |
test/standalone/guess_number/main.zig+1-1| ... | @@ -10,7 +10,7 @@ pub fn main() !void { | ... | @@ -10,7 +10,7 @@ pub fn main() !void { |
| 10 | 10 | ||
| 11 | var seed_bytes: [@sizeOf(u64)]u8 = undefined; | 11 | var seed_bytes: [@sizeOf(u64)]u8 = undefined; |
| 12 | std.crypto.randomBytes(seed_bytes[0..]) catch |err| { | 12 | std.crypto.randomBytes(seed_bytes[0..]) catch |err| { |
| 13 | std.debug.warn("unable to seed random number generator: {}", err); | 13 | std.debug.warn("unable to seed random number generator: {}", .{err}); |
| 14 | return err; | 14 | return err; |
| 15 | }; | 15 | }; |
| 16 | const seed = std.mem.readIntNative(u64, &seed_bytes); | 16 | const seed = std.mem.readIntNative(u64, &seed_bytes); |
test/tests.zig+94-66| ... | @@ -411,7 +411,7 @@ pub fn addPkgTests( | ... | @@ -411,7 +411,7 @@ pub fn addPkgTests( |
| 411 | is_qemu_enabled: bool, | 411 | is_qemu_enabled: bool, |
| 412 | glibc_dir: ?[]const u8, | 412 | glibc_dir: ?[]const u8, |
| 413 | ) *build.Step { | 413 | ) *build.Step { |
| 414 | const step = b.step(b.fmt("test-{}", name), desc); | 414 | const step = b.step(b.fmt("test-{}", .{name}), desc); |
| 415 | 415 | ||
| 416 | for (test_targets) |test_target| { | 416 | for (test_targets) |test_target| { |
| 417 | if (skip_non_native and test_target.target != .Native) | 417 | if (skip_non_native and test_target.target != .Native) |
| ... | @@ -454,14 +454,14 @@ pub fn addPkgTests( | ... | @@ -454,14 +454,14 @@ pub fn addPkgTests( |
| 454 | test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable; | 454 | test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable; |
| 455 | 455 | ||
| 456 | const these_tests = b.addTest(root_src); | 456 | const these_tests = b.addTest(root_src); |
| 457 | these_tests.setNamePrefix(b.fmt( | 457 | const single_threaded_txt = if (test_target.single_threaded) "single" else "multi"; |
| 458 | "{}-{}-{}-{}-{} ", | 458 | these_tests.setNamePrefix(b.fmt("{}-{}-{}-{}-{} ", .{ |
| 459 | name, | 459 | name, |
| 460 | triple_prefix, | 460 | triple_prefix, |
| 461 | @tagName(test_target.mode), | 461 | @tagName(test_target.mode), |
| 462 | libc_prefix, | 462 | libc_prefix, |
| 463 | if (test_target.single_threaded) "single" else "multi", | 463 | single_threaded_txt, |
| 464 | )); | 464 | })); |
| 465 | these_tests.single_threaded = test_target.single_threaded; | 465 | these_tests.single_threaded = test_target.single_threaded; |
| 466 | these_tests.setFilter(test_filter); | 466 | these_tests.setFilter(test_filter); |
| 467 | these_tests.setBuildMode(test_target.mode); | 467 | these_tests.setBuildMode(test_target.mode); |
| ... | @@ -562,7 +562,7 @@ pub const CompareOutputContext = struct { | ... | @@ -562,7 +562,7 @@ pub const CompareOutputContext = struct { |
| 562 | args.append(arg) catch unreachable; | 562 | args.append(arg) catch unreachable; |
| 563 | } | 563 | } |
| 564 | 564 | ||
| 565 | warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name); | 565 | warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name }); |
| 566 | 566 | ||
| 567 | const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable; | 567 | const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable; |
| 568 | defer child.deinit(); | 568 | defer child.deinit(); |
| ... | @@ -572,7 +572,7 @@ pub const CompareOutputContext = struct { | ... | @@ -572,7 +572,7 @@ pub const CompareOutputContext = struct { |
| 572 | child.stderr_behavior = .Pipe; | 572 | child.stderr_behavior = .Pipe; |
| 573 | child.env_map = b.env_map; | 573 | child.env_map = b.env_map; |
| 574 | 574 | ||
| 575 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); | 575 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) }); |
| 576 | 576 | ||
| 577 | var stdout = Buffer.initNull(b.allocator); | 577 | var stdout = Buffer.initNull(b.allocator); |
| 578 | var stderr = Buffer.initNull(b.allocator); | 578 | var stderr = Buffer.initNull(b.allocator); |
| ... | @@ -584,18 +584,18 @@ pub const CompareOutputContext = struct { | ... | @@ -584,18 +584,18 @@ pub const CompareOutputContext = struct { |
| 584 | stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable; | 584 | stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable; |
| 585 | 585 | ||
| 586 | const term = child.wait() catch |err| { | 586 | const term = child.wait() catch |err| { |
| 587 | debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); | 587 | debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) }); |
| 588 | }; | 588 | }; |
| 589 | switch (term) { | 589 | switch (term) { |
| 590 | .Exited => |code| { | 590 | .Exited => |code| { |
| 591 | if (code != 0) { | 591 | if (code != 0) { |
| 592 | warn("Process {} exited with error code {}\n", full_exe_path, code); | 592 | warn("Process {} exited with error code {}\n", .{ full_exe_path, code }); |
| 593 | printInvocation(args.toSliceConst()); | 593 | printInvocation(args.toSliceConst()); |
| 594 | return error.TestFailed; | 594 | return error.TestFailed; |
| 595 | } | 595 | } |
| 596 | }, | 596 | }, |
| 597 | else => { | 597 | else => { |
| 598 | warn("Process {} terminated unexpectedly\n", full_exe_path); | 598 | warn("Process {} terminated unexpectedly\n", .{full_exe_path}); |
| 599 | printInvocation(args.toSliceConst()); | 599 | printInvocation(args.toSliceConst()); |
| 600 | return error.TestFailed; | 600 | return error.TestFailed; |
| 601 | }, | 601 | }, |
| ... | @@ -609,10 +609,10 @@ pub const CompareOutputContext = struct { | ... | @@ -609,10 +609,10 @@ pub const CompareOutputContext = struct { |
| 609 | \\========= But found: ==================== | 609 | \\========= But found: ==================== |
| 610 | \\{} | 610 | \\{} |
| 611 | \\ | 611 | \\ |
| 612 | , self.expected_output, stdout.toSliceConst()); | 612 | , .{ self.expected_output, stdout.toSliceConst() }); |
| 613 | return error.TestFailed; | 613 | return error.TestFailed; |
| 614 | } | 614 | } |
| 615 | warn("OK\n"); | 615 | warn("OK\n", .{}); |
| 616 | } | 616 | } |
| 617 | }; | 617 | }; |
| 618 | 618 | ||
| ... | @@ -644,7 +644,7 @@ pub const CompareOutputContext = struct { | ... | @@ -644,7 +644,7 @@ pub const CompareOutputContext = struct { |
| 644 | 644 | ||
| 645 | const full_exe_path = self.exe.getOutputPath(); | 645 | const full_exe_path = self.exe.getOutputPath(); |
| 646 | 646 | ||
| 647 | warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name); | 647 | warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name }); |
| 648 | 648 | ||
| 649 | const child = std.ChildProcess.init(&[_][]const u8{full_exe_path}, b.allocator) catch unreachable; | 649 | const child = std.ChildProcess.init(&[_][]const u8{full_exe_path}, b.allocator) catch unreachable; |
| 650 | defer child.deinit(); | 650 | defer child.deinit(); |
| ... | @@ -655,28 +655,34 @@ pub const CompareOutputContext = struct { | ... | @@ -655,28 +655,34 @@ pub const CompareOutputContext = struct { |
| 655 | child.stderr_behavior = .Ignore; | 655 | child.stderr_behavior = .Ignore; |
| 656 | 656 | ||
| 657 | const term = child.spawnAndWait() catch |err| { | 657 | const term = child.spawnAndWait() catch |err| { |
| 658 | debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); | 658 | debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) }); |
| 659 | }; | 659 | }; |
| 660 | 660 | ||
| 661 | const expected_exit_code: u32 = 126; | 661 | const expected_exit_code: u32 = 126; |
| 662 | switch (term) { | 662 | switch (term) { |
| 663 | .Exited => |code| { | 663 | .Exited => |code| { |
| 664 | if (code != expected_exit_code) { | 664 | if (code != expected_exit_code) { |
| 665 | warn("\nProgram expected to exit with code {} " ++ "but exited with code {}\n", expected_exit_code, code); | 665 | warn("\nProgram expected to exit with code {} but exited with code {}\n", .{ |
| 666 | expected_exit_code, code, | ||
| 667 | }); | ||
| 666 | return error.TestFailed; | 668 | return error.TestFailed; |
| 667 | } | 669 | } |
| 668 | }, | 670 | }, |
| 669 | .Signal => |sig| { | 671 | .Signal => |sig| { |
| 670 | warn("\nProgram expected to exit with code {} " ++ "but instead signaled {}\n", expected_exit_code, sig); | 672 | warn("\nProgram expected to exit with code {} but instead signaled {}\n", .{ |
| 673 | expected_exit_code, sig, | ||
| 674 | }); | ||
| 671 | return error.TestFailed; | 675 | return error.TestFailed; |
| 672 | }, | 676 | }, |
| 673 | else => { | 677 | else => { |
| 674 | warn("\nProgram expected to exit with code {}" ++ " but exited in an unexpected way\n", expected_exit_code); | 678 | warn("\nProgram expected to exit with code {} but exited in an unexpected way\n", .{ |
| 679 | expected_exit_code, | ||
| 680 | }); | ||
| 675 | return error.TestFailed; | 681 | return error.TestFailed; |
| 676 | }, | 682 | }, |
| 677 | } | 683 | } |
| 678 | 684 | ||
| 679 | warn("OK\n"); | 685 | warn("OK\n", .{}); |
| 680 | } | 686 | } |
| 681 | }; | 687 | }; |
| 682 | 688 | ||
| ... | @@ -729,7 +735,9 @@ pub const CompareOutputContext = struct { | ... | @@ -729,7 +735,9 @@ pub const CompareOutputContext = struct { |
| 729 | 735 | ||
| 730 | switch (case.special) { | 736 | switch (case.special) { |
| 731 | Special.Asm => { | 737 | Special.Asm => { |
| 732 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name) catch unreachable; | 738 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "assemble-and-link {}", .{ |
| 739 | case.name, | ||
| 740 | }) catch unreachable; | ||
| 733 | if (self.test_filter) |filter| { | 741 | if (self.test_filter) |filter| { |
| 734 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; | 742 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 735 | } | 743 | } |
| ... | @@ -758,7 +766,11 @@ pub const CompareOutputContext = struct { | ... | @@ -758,7 +766,11 @@ pub const CompareOutputContext = struct { |
| 758 | }, | 766 | }, |
| 759 | Special.None => { | 767 | Special.None => { |
| 760 | for (self.modes) |mode| { | 768 | for (self.modes) |mode| { |
| 761 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", "compare-output", case.name, @tagName(mode)) catch unreachable; | 769 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", .{ |
| 770 | "compare-output", | ||
| 771 | case.name, | ||
| 772 | @tagName(mode), | ||
| 773 | }) catch unreachable; | ||
| 762 | if (self.test_filter) |filter| { | 774 | if (self.test_filter) |filter| { |
| 763 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; | 775 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; |
| 764 | } | 776 | } |
| ... | @@ -790,7 +802,7 @@ pub const CompareOutputContext = struct { | ... | @@ -790,7 +802,7 @@ pub const CompareOutputContext = struct { |
| 790 | } | 802 | } |
| 791 | }, | 803 | }, |
| 792 | Special.RuntimeSafety => { | 804 | Special.RuntimeSafety => { |
| 793 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", case.name) catch unreachable; | 805 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", .{case.name}) catch unreachable; |
| 794 | if (self.test_filter) |filter| { | 806 | if (self.test_filter) |filter| { |
| 795 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; | 807 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 796 | } | 808 | } |
| ... | @@ -843,7 +855,11 @@ pub const StackTracesContext = struct { | ... | @@ -843,7 +855,11 @@ pub const StackTracesContext = struct { |
| 843 | const expect_for_mode = expect[@enumToInt(mode)]; | 855 | const expect_for_mode = expect[@enumToInt(mode)]; |
| 844 | if (expect_for_mode.len == 0) continue; | 856 | if (expect_for_mode.len == 0) continue; |
| 845 | 857 | ||
| 846 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", "stack-trace", name, @tagName(mode)) catch unreachable; | 858 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", .{ |
| 859 | "stack-trace", | ||
| 860 | name, | ||
| 861 | @tagName(mode), | ||
| 862 | }) catch unreachable; | ||
| 847 | if (self.test_filter) |filter| { | 863 | if (self.test_filter) |filter| { |
| 848 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; | 864 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; |
| 849 | } | 865 | } |
| ... | @@ -907,7 +923,7 @@ pub const StackTracesContext = struct { | ... | @@ -907,7 +923,7 @@ pub const StackTracesContext = struct { |
| 907 | defer args.deinit(); | 923 | defer args.deinit(); |
| 908 | args.append(full_exe_path) catch unreachable; | 924 | args.append(full_exe_path) catch unreachable; |
| 909 | 925 | ||
| 910 | warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name); | 926 | warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name }); |
| 911 | 927 | ||
| 912 | const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable; | 928 | const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable; |
| 913 | defer child.deinit(); | 929 | defer child.deinit(); |
| ... | @@ -917,7 +933,7 @@ pub const StackTracesContext = struct { | ... | @@ -917,7 +933,7 @@ pub const StackTracesContext = struct { |
| 917 | child.stderr_behavior = .Pipe; | 933 | child.stderr_behavior = .Pipe; |
| 918 | child.env_map = b.env_map; | 934 | child.env_map = b.env_map; |
| 919 | 935 | ||
| 920 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); | 936 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) }); |
| 921 | 937 | ||
| 922 | var stdout = Buffer.initNull(b.allocator); | 938 | var stdout = Buffer.initNull(b.allocator); |
| 923 | var stderr = Buffer.initNull(b.allocator); | 939 | var stderr = Buffer.initNull(b.allocator); |
| ... | @@ -929,30 +945,34 @@ pub const StackTracesContext = struct { | ... | @@ -929,30 +945,34 @@ pub const StackTracesContext = struct { |
| 929 | stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable; | 945 | stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable; |
| 930 | 946 | ||
| 931 | const term = child.wait() catch |err| { | 947 | const term = child.wait() catch |err| { |
| 932 | debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); | 948 | debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) }); |
| 933 | }; | 949 | }; |
| 934 | 950 | ||
| 935 | switch (term) { | 951 | switch (term) { |
| 936 | .Exited => |code| { | 952 | .Exited => |code| { |
| 937 | const expect_code: u32 = 1; | 953 | const expect_code: u32 = 1; |
| 938 | if (code != expect_code) { | 954 | if (code != expect_code) { |
| 939 | warn("Process {} exited with error code {} but expected code {}\n", full_exe_path, code, expect_code); | 955 | warn("Process {} exited with error code {} but expected code {}\n", .{ |
| 956 | full_exe_path, | ||
| 957 | code, | ||
| 958 | expect_code, | ||
| 959 | }); | ||
| 940 | printInvocation(args.toSliceConst()); | 960 | printInvocation(args.toSliceConst()); |
| 941 | return error.TestFailed; | 961 | return error.TestFailed; |
| 942 | } | 962 | } |
| 943 | }, | 963 | }, |
| 944 | .Signal => |signum| { | 964 | .Signal => |signum| { |
| 945 | warn("Process {} terminated on signal {}\n", full_exe_path, signum); | 965 | warn("Process {} terminated on signal {}\n", .{ full_exe_path, signum }); |
| 946 | printInvocation(args.toSliceConst()); | 966 | printInvocation(args.toSliceConst()); |
| 947 | return error.TestFailed; | 967 | return error.TestFailed; |
| 948 | }, | 968 | }, |
| 949 | .Stopped => |signum| { | 969 | .Stopped => |signum| { |
| 950 | warn("Process {} stopped on signal {}\n", full_exe_path, signum); | 970 | warn("Process {} stopped on signal {}\n", .{ full_exe_path, signum }); |
| 951 | printInvocation(args.toSliceConst()); | 971 | printInvocation(args.toSliceConst()); |
| 952 | return error.TestFailed; | 972 | return error.TestFailed; |
| 953 | }, | 973 | }, |
| 954 | .Unknown => |code| { | 974 | .Unknown => |code| { |
| 955 | warn("Process {} terminated unexpectedly with error code {}\n", full_exe_path, code); | 975 | warn("Process {} terminated unexpectedly with error code {}\n", .{ full_exe_path, code }); |
| 956 | printInvocation(args.toSliceConst()); | 976 | printInvocation(args.toSliceConst()); |
| 957 | return error.TestFailed; | 977 | return error.TestFailed; |
| 958 | }, | 978 | }, |
| ... | @@ -1003,10 +1023,10 @@ pub const StackTracesContext = struct { | ... | @@ -1003,10 +1023,10 @@ pub const StackTracesContext = struct { |
| 1003 | \\================================================ | 1023 | \\================================================ |
| 1004 | \\{} | 1024 | \\{} |
| 1005 | \\ | 1025 | \\ |
| 1006 | , self.expect_output, got); | 1026 | , .{ self.expect_output, got }); |
| 1007 | return error.TestFailed; | 1027 | return error.TestFailed; |
| 1008 | } | 1028 | } |
| 1009 | warn("OK\n"); | 1029 | warn("OK\n", .{}); |
| 1010 | } | 1030 | } |
| 1011 | }; | 1031 | }; |
| 1012 | }; | 1032 | }; |
| ... | @@ -1129,7 +1149,7 @@ pub const CompileErrorContext = struct { | ... | @@ -1129,7 +1149,7 @@ pub const CompileErrorContext = struct { |
| 1129 | Mode.ReleaseSmall => zig_args.append("--release-small") catch unreachable, | 1149 | Mode.ReleaseSmall => zig_args.append("--release-small") catch unreachable, |
| 1130 | } | 1150 | } |
| 1131 | 1151 | ||
| 1132 | warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name); | 1152 | warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name }); |
| 1133 | 1153 | ||
| 1134 | if (b.verbose) { | 1154 | if (b.verbose) { |
| 1135 | printInvocation(zig_args.toSliceConst()); | 1155 | printInvocation(zig_args.toSliceConst()); |
| ... | @@ -1143,7 +1163,7 @@ pub const CompileErrorContext = struct { | ... | @@ -1143,7 +1163,7 @@ pub const CompileErrorContext = struct { |
| 1143 | child.stdout_behavior = .Pipe; | 1163 | child.stdout_behavior = .Pipe; |
| 1144 | child.stderr_behavior = .Pipe; | 1164 | child.stderr_behavior = .Pipe; |
| 1145 | 1165 | ||
| 1146 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err)); | 1166 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) }); |
| 1147 | 1167 | ||
| 1148 | var stdout_buf = Buffer.initNull(b.allocator); | 1168 | var stdout_buf = Buffer.initNull(b.allocator); |
| 1149 | var stderr_buf = Buffer.initNull(b.allocator); | 1169 | var stderr_buf = Buffer.initNull(b.allocator); |
| ... | @@ -1155,7 +1175,7 @@ pub const CompileErrorContext = struct { | ... | @@ -1155,7 +1175,7 @@ pub const CompileErrorContext = struct { |
| 1155 | stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable; | 1175 | stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable; |
| 1156 | 1176 | ||
| 1157 | const term = child.wait() catch |err| { | 1177 | const term = child.wait() catch |err| { |
| 1158 | debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err)); | 1178 | debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) }); |
| 1159 | }; | 1179 | }; |
| 1160 | switch (term) { | 1180 | switch (term) { |
| 1161 | .Exited => |code| { | 1181 | .Exited => |code| { |
| ... | @@ -1165,7 +1185,7 @@ pub const CompileErrorContext = struct { | ... | @@ -1165,7 +1185,7 @@ pub const CompileErrorContext = struct { |
| 1165 | } | 1185 | } |
| 1166 | }, | 1186 | }, |
| 1167 | else => { | 1187 | else => { |
| 1168 | warn("Process {} terminated unexpectedly\n", b.zig_exe); | 1188 | warn("Process {} terminated unexpectedly\n", .{b.zig_exe}); |
| 1169 | printInvocation(zig_args.toSliceConst()); | 1189 | printInvocation(zig_args.toSliceConst()); |
| 1170 | return error.TestFailed; | 1190 | return error.TestFailed; |
| 1171 | }, | 1191 | }, |
| ... | @@ -1182,7 +1202,7 @@ pub const CompileErrorContext = struct { | ... | @@ -1182,7 +1202,7 @@ pub const CompileErrorContext = struct { |
| 1182 | \\{} | 1202 | \\{} |
| 1183 | \\================================================ | 1203 | \\================================================ |
| 1184 | \\ | 1204 | \\ |
| 1185 | , stdout); | 1205 | , .{stdout}); |
| 1186 | return error.TestFailed; | 1206 | return error.TestFailed; |
| 1187 | } | 1207 | } |
| 1188 | 1208 | ||
| ... | @@ -1200,9 +1220,9 @@ pub const CompileErrorContext = struct { | ... | @@ -1200,9 +1220,9 @@ pub const CompileErrorContext = struct { |
| 1200 | ok = ok and i == self.case.expected_errors.len; | 1220 | ok = ok and i == self.case.expected_errors.len; |
| 1201 | 1221 | ||
| 1202 | if (!ok) { | 1222 | if (!ok) { |
| 1203 | warn("\n======== Expected these compile errors: ========\n"); | 1223 | warn("\n======== Expected these compile errors: ========\n", .{}); |
| 1204 | for (self.case.expected_errors.toSliceConst()) |expected| { | 1224 | for (self.case.expected_errors.toSliceConst()) |expected| { |
| 1205 | warn("{}\n", expected); | 1225 | warn("{}\n", .{expected}); |
| 1206 | } | 1226 | } |
| 1207 | } | 1227 | } |
| 1208 | } else { | 1228 | } else { |
| ... | @@ -1213,7 +1233,7 @@ pub const CompileErrorContext = struct { | ... | @@ -1213,7 +1233,7 @@ pub const CompileErrorContext = struct { |
| 1213 | \\=========== Expected compile error: ============ | 1233 | \\=========== Expected compile error: ============ |
| 1214 | \\{} | 1234 | \\{} |
| 1215 | \\ | 1235 | \\ |
| 1216 | , expected); | 1236 | , .{expected}); |
| 1217 | ok = false; | 1237 | ok = false; |
| 1218 | break; | 1238 | break; |
| 1219 | } | 1239 | } |
| ... | @@ -1225,11 +1245,11 @@ pub const CompileErrorContext = struct { | ... | @@ -1225,11 +1245,11 @@ pub const CompileErrorContext = struct { |
| 1225 | \\================= Full output: ================= | 1245 | \\================= Full output: ================= |
| 1226 | \\{} | 1246 | \\{} |
| 1227 | \\ | 1247 | \\ |
| 1228 | , stderr); | 1248 | , .{stderr}); |
| 1229 | return error.TestFailed; | 1249 | return error.TestFailed; |
| 1230 | } | 1250 | } |
| 1231 | 1251 | ||
| 1232 | warn("OK\n"); | 1252 | warn("OK\n", .{}); |
| 1233 | } | 1253 | } |
| 1234 | }; | 1254 | }; |
| 1235 | 1255 | ||
| ... | @@ -1279,7 +1299,9 @@ pub const CompileErrorContext = struct { | ... | @@ -1279,7 +1299,9 @@ pub const CompileErrorContext = struct { |
| 1279 | pub fn addCase(self: *CompileErrorContext, case: *const TestCase) void { | 1299 | pub fn addCase(self: *CompileErrorContext, case: *const TestCase) void { |
| 1280 | const b = self.b; | 1300 | const b = self.b; |
| 1281 | 1301 | ||
| 1282 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "compile-error {}", case.name) catch unreachable; | 1302 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "compile-error {}", .{ |
| 1303 | case.name, | ||
| 1304 | }) catch unreachable; | ||
| 1283 | if (self.test_filter) |filter| { | 1305 | if (self.test_filter) |filter| { |
| 1284 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; | 1306 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 1285 | } | 1307 | } |
| ... | @@ -1316,7 +1338,7 @@ pub const StandaloneContext = struct { | ... | @@ -1316,7 +1338,7 @@ pub const StandaloneContext = struct { |
| 1316 | pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8) void { | 1338 | pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8) void { |
| 1317 | const b = self.b; | 1339 | const b = self.b; |
| 1318 | 1340 | ||
| 1319 | const annotated_case_name = b.fmt("build {} (Debug)", build_file); | 1341 | const annotated_case_name = b.fmt("build {} (Debug)", .{build_file}); |
| 1320 | if (self.test_filter) |filter| { | 1342 | if (self.test_filter) |filter| { |
| 1321 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; | 1343 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 1322 | } | 1344 | } |
| ... | @@ -1337,7 +1359,7 @@ pub const StandaloneContext = struct { | ... | @@ -1337,7 +1359,7 @@ pub const StandaloneContext = struct { |
| 1337 | 1359 | ||
| 1338 | const run_cmd = b.addSystemCommand(zig_args.toSliceConst()); | 1360 | const run_cmd = b.addSystemCommand(zig_args.toSliceConst()); |
| 1339 | 1361 | ||
| 1340 | const log_step = b.addLog("PASS {}\n", annotated_case_name); | 1362 | const log_step = b.addLog("PASS {}\n", .{annotated_case_name}); |
| 1341 | log_step.step.dependOn(&run_cmd.step); | 1363 | log_step.step.dependOn(&run_cmd.step); |
| 1342 | 1364 | ||
| 1343 | self.step.dependOn(&log_step.step); | 1365 | self.step.dependOn(&log_step.step); |
| ... | @@ -1347,7 +1369,10 @@ pub const StandaloneContext = struct { | ... | @@ -1347,7 +1369,10 @@ pub const StandaloneContext = struct { |
| 1347 | const b = self.b; | 1369 | const b = self.b; |
| 1348 | 1370 | ||
| 1349 | for (self.modes) |mode| { | 1371 | for (self.modes) |mode| { |
| 1350 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {} ({})", root_src, @tagName(mode)) catch unreachable; | 1372 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {} ({})", .{ |
| 1373 | root_src, | ||
| 1374 | @tagName(mode), | ||
| 1375 | }) catch unreachable; | ||
| 1351 | if (self.test_filter) |filter| { | 1376 | if (self.test_filter) |filter| { |
| 1352 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; | 1377 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; |
| 1353 | } | 1378 | } |
| ... | @@ -1358,7 +1383,7 @@ pub const StandaloneContext = struct { | ... | @@ -1358,7 +1383,7 @@ pub const StandaloneContext = struct { |
| 1358 | exe.linkSystemLibrary("c"); | 1383 | exe.linkSystemLibrary("c"); |
| 1359 | } | 1384 | } |
| 1360 | 1385 | ||
| 1361 | const log_step = b.addLog("PASS {}\n", annotated_case_name); | 1386 | const log_step = b.addLog("PASS {}\n", .{annotated_case_name}); |
| 1362 | log_step.step.dependOn(&exe.step); | 1387 | log_step.step.dependOn(&exe.step); |
| 1363 | 1388 | ||
| 1364 | self.step.dependOn(&log_step.step); | 1389 | self.step.dependOn(&log_step.step); |
| ... | @@ -1434,7 +1459,7 @@ pub const TranslateCContext = struct { | ... | @@ -1434,7 +1459,7 @@ pub const TranslateCContext = struct { |
| 1434 | zig_args.append(translate_c_cmd) catch unreachable; | 1459 | zig_args.append(translate_c_cmd) catch unreachable; |
| 1435 | zig_args.append(b.pathFromRoot(root_src)) catch unreachable; | 1460 | zig_args.append(b.pathFromRoot(root_src)) catch unreachable; |
| 1436 | 1461 | ||
| 1437 | warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name); | 1462 | warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name }); |
| 1438 | 1463 | ||
| 1439 | if (b.verbose) { | 1464 | if (b.verbose) { |
| 1440 | printInvocation(zig_args.toSliceConst()); | 1465 | printInvocation(zig_args.toSliceConst()); |
| ... | @@ -1448,7 +1473,10 @@ pub const TranslateCContext = struct { | ... | @@ -1448,7 +1473,10 @@ pub const TranslateCContext = struct { |
| 1448 | child.stdout_behavior = .Pipe; | 1473 | child.stdout_behavior = .Pipe; |
| 1449 | child.stderr_behavior = .Pipe; | 1474 | child.stderr_behavior = .Pipe; |
| 1450 | 1475 | ||
| 1451 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err)); | 1476 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ |
| 1477 | zig_args.toSliceConst()[0], | ||
| 1478 | @errorName(err), | ||
| 1479 | }); | ||
| 1452 | 1480 | ||
| 1453 | var stdout_buf = Buffer.initNull(b.allocator); | 1481 | var stdout_buf = Buffer.initNull(b.allocator); |
| 1454 | var stderr_buf = Buffer.initNull(b.allocator); | 1482 | var stderr_buf = Buffer.initNull(b.allocator); |
| ... | @@ -1460,23 +1488,23 @@ pub const TranslateCContext = struct { | ... | @@ -1460,23 +1488,23 @@ pub const TranslateCContext = struct { |
| 1460 | stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable; | 1488 | stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable; |
| 1461 | 1489 | ||
| 1462 | const term = child.wait() catch |err| { | 1490 | const term = child.wait() catch |err| { |
| 1463 | debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err)); | 1491 | debug.panic("Unable to spawn {}: {}\n", .{ zig_args.toSliceConst()[0], @errorName(err) }); |
| 1464 | }; | 1492 | }; |
| 1465 | switch (term) { | 1493 | switch (term) { |
| 1466 | .Exited => |code| { | 1494 | .Exited => |code| { |
| 1467 | if (code != 0) { | 1495 | if (code != 0) { |
| 1468 | warn("Compilation failed with exit code {}\n", code); | 1496 | warn("Compilation failed with exit code {}\n", .{code}); |
| 1469 | printInvocation(zig_args.toSliceConst()); | 1497 | printInvocation(zig_args.toSliceConst()); |
| 1470 | return error.TestFailed; | 1498 | return error.TestFailed; |
| 1471 | } | 1499 | } |
| 1472 | }, | 1500 | }, |
| 1473 | .Signal => |code| { | 1501 | .Signal => |code| { |
| 1474 | warn("Compilation failed with signal {}\n", code); | 1502 | warn("Compilation failed with signal {}\n", .{code}); |
| 1475 | printInvocation(zig_args.toSliceConst()); | 1503 | printInvocation(zig_args.toSliceConst()); |
| 1476 | return error.TestFailed; | 1504 | return error.TestFailed; |
| 1477 | }, | 1505 | }, |
| 1478 | else => { | 1506 | else => { |
| 1479 | warn("Compilation terminated unexpectedly\n"); | 1507 | warn("Compilation terminated unexpectedly\n", .{}); |
| 1480 | printInvocation(zig_args.toSliceConst()); | 1508 | printInvocation(zig_args.toSliceConst()); |
| 1481 | return error.TestFailed; | 1509 | return error.TestFailed; |
| 1482 | }, | 1510 | }, |
| ... | @@ -1491,7 +1519,7 @@ pub const TranslateCContext = struct { | ... | @@ -1491,7 +1519,7 @@ pub const TranslateCContext = struct { |
| 1491 | \\{} | 1519 | \\{} |
| 1492 | \\============================================ | 1520 | \\============================================ |
| 1493 | \\ | 1521 | \\ |
| 1494 | , stderr); | 1522 | , .{stderr}); |
| 1495 | printInvocation(zig_args.toSliceConst()); | 1523 | printInvocation(zig_args.toSliceConst()); |
| 1496 | return error.TestFailed; | 1524 | return error.TestFailed; |
| 1497 | } | 1525 | } |
| ... | @@ -1505,20 +1533,20 @@ pub const TranslateCContext = struct { | ... | @@ -1505,20 +1533,20 @@ pub const TranslateCContext = struct { |
| 1505 | \\========= But found: =========================== | 1533 | \\========= But found: =========================== |
| 1506 | \\{} | 1534 | \\{} |
| 1507 | \\ | 1535 | \\ |
| 1508 | , expected_line, stdout); | 1536 | , .{ expected_line, stdout }); |
| 1509 | printInvocation(zig_args.toSliceConst()); | 1537 | printInvocation(zig_args.toSliceConst()); |
| 1510 | return error.TestFailed; | 1538 | return error.TestFailed; |
| 1511 | } | 1539 | } |
| 1512 | } | 1540 | } |
| 1513 | warn("OK\n"); | 1541 | warn("OK\n", .{}); |
| 1514 | } | 1542 | } |
| 1515 | }; | 1543 | }; |
| 1516 | 1544 | ||
| 1517 | fn printInvocation(args: []const []const u8) void { | 1545 | fn printInvocation(args: []const []const u8) void { |
| 1518 | for (args) |arg| { | 1546 | for (args) |arg| { |
| 1519 | warn("{} ", arg); | 1547 | warn("{} ", .{arg}); |
| 1520 | } | 1548 | } |
| 1521 | warn("\n"); | 1549 | warn("\n", .{}); |
| 1522 | } | 1550 | } |
| 1523 | 1551 | ||
| 1524 | pub fn create(self: *TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { | 1552 | pub fn create(self: *TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { |
| ... | @@ -1586,7 +1614,7 @@ pub const TranslateCContext = struct { | ... | @@ -1586,7 +1614,7 @@ pub const TranslateCContext = struct { |
| 1586 | const b = self.b; | 1614 | const b = self.b; |
| 1587 | 1615 | ||
| 1588 | const translate_c_cmd = if (case.stage2) "translate-c-2" else "translate-c"; | 1616 | const translate_c_cmd = if (case.stage2) "translate-c-2" else "translate-c"; |
| 1589 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {}", translate_c_cmd, case.name) catch unreachable; | 1617 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {}", .{ translate_c_cmd, case.name }) catch unreachable; |
| 1590 | if (self.test_filter) |filter| { | 1618 | if (self.test_filter) |filter| { |
| 1591 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; | 1619 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 1592 | } | 1620 | } |
| ... | @@ -1666,7 +1694,7 @@ pub const GenHContext = struct { | ... | @@ -1666,7 +1694,7 @@ pub const GenHContext = struct { |
| 1666 | const self = @fieldParentPtr(GenHCmpOutputStep, "step", step); | 1694 | const self = @fieldParentPtr(GenHCmpOutputStep, "step", step); |
| 1667 | const b = self.context.b; | 1695 | const b = self.context.b; |
| 1668 | 1696 | ||
| 1669 | warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name); | 1697 | warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name }); |
| 1670 | 1698 | ||
| 1671 | const full_h_path = self.obj.getOutputHPath(); | 1699 | const full_h_path = self.obj.getOutputHPath(); |
| 1672 | const actual_h = try io.readFileAlloc(b.allocator, full_h_path); | 1700 | const actual_h = try io.readFileAlloc(b.allocator, full_h_path); |
| ... | @@ -1680,19 +1708,19 @@ pub const GenHContext = struct { | ... | @@ -1680,19 +1708,19 @@ pub const GenHContext = struct { |
| 1680 | \\========= But found: =========================== | 1708 | \\========= But found: =========================== |
| 1681 | \\{} | 1709 | \\{} |
| 1682 | \\ | 1710 | \\ |
| 1683 | , expected_line, actual_h); | 1711 | , .{ expected_line, actual_h }); |
| 1684 | return error.TestFailed; | 1712 | return error.TestFailed; |
| 1685 | } | 1713 | } |
| 1686 | } | 1714 | } |
| 1687 | warn("OK\n"); | 1715 | warn("OK\n", .{}); |
| 1688 | } | 1716 | } |
| 1689 | }; | 1717 | }; |
| 1690 | 1718 | ||
| 1691 | fn printInvocation(args: []const []const u8) void { | 1719 | fn printInvocation(args: []const []const u8) void { |
| 1692 | for (args) |arg| { | 1720 | for (args) |arg| { |
| 1693 | warn("{} ", arg); | 1721 | warn("{} ", .{arg}); |
| 1694 | } | 1722 | } |
| 1695 | warn("\n"); | 1723 | warn("\n", .{}); |
| 1696 | } | 1724 | } |
| 1697 | 1725 | ||
| 1698 | pub fn create(self: *GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { | 1726 | pub fn create(self: *GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { |
| ... | @@ -1724,7 +1752,7 @@ pub const GenHContext = struct { | ... | @@ -1724,7 +1752,7 @@ pub const GenHContext = struct { |
| 1724 | ) catch unreachable; | 1752 | ) catch unreachable; |
| 1725 | 1753 | ||
| 1726 | const mode = builtin.Mode.Debug; | 1754 | const mode = builtin.Mode.Debug; |
| 1727 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {} ({})", case.name, @tagName(mode)) catch unreachable; | 1755 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {} ({})", .{ case.name, @tagName(mode) }) catch unreachable; |
| 1728 | if (self.test_filter) |filter| { | 1756 | if (self.test_filter) |filter| { |
| 1729 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; | 1757 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 1730 | } | 1758 | } |
| ... | @@ -1749,7 +1777,7 @@ pub const GenHContext = struct { | ... | @@ -1749,7 +1777,7 @@ pub const GenHContext = struct { |
| 1749 | 1777 | ||
| 1750 | fn printInvocation(args: []const []const u8) void { | 1778 | fn printInvocation(args: []const []const u8) void { |
| 1751 | for (args) |arg| { | 1779 | for (args) |arg| { |
| 1752 | warn("{} ", arg); | 1780 | warn("{} ", .{arg}); |
| 1753 | } | 1781 | } |
| 1754 | warn("\n"); | 1782 | warn("\n", .{}); |
| 1755 | } | 1783 | } |