| 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 | 154 | const static_bare_name = if (mem.eql(u8, lib, "curses")) |
| 155 | 155 | @as([]const u8, "libncurses.a") |
| 156 | 156 | else |
| 157 | b.fmt("lib{}.a", lib); | |
| 157 | b.fmt("lib{}.a", .{lib}); | |
| 158 | 158 | const static_lib_name = fs.path.join( |
| 159 | 159 | b.allocator, |
| 160 | 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 | 186 | lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{ |
| 187 | 187 | cmake_binary_dir, |
| 188 | 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 | 190 | }) catch unreachable); |
| 191 | 191 | } |
| 192 | 192 | |
| ... | ... | @@ -343,14 +343,14 @@ fn addCxxKnownPath( |
| 343 | 343 | ) !void { |
| 344 | 344 | const path_padded = try b.exec(&[_][]const u8{ |
| 345 | 345 | ctx.cxx_compiler, |
| 346 | b.fmt("-print-file-name={}", objname), | |
| 346 | b.fmt("-print-file-name={}", .{objname}), | |
| 347 | 347 | }); |
| 348 | 348 | const path_unpadded = mem.tokenize(path_padded, "\r\n").next().?; |
| 349 | 349 | if (mem.eql(u8, path_unpadded, objname)) { |
| 350 | 350 | if (errtxt) |msg| { |
| 351 | warn("{}", msg); | |
| 351 | warn("{}", .{msg}); | |
| 352 | 352 | } else { |
| 353 | warn("Unable to determine path to {}\n", objname); | |
| 353 | warn("Unable to determine path to {}\n", .{objname}); | |
| 354 | 354 | } |
| 355 | 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 | 116 | fn dumpRecursive(s: *std.io.OutStream(Error), optional_node: ?*Node, indent: usize) Error!void { |
| 117 | 117 | try s.writeByteNTimes(' ', indent); |
| 118 | 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 | 120 | try dumpRecursive(s, node.next, indent + 1); |
| 121 | 121 | } else { |
| 122 | try s.print("(null)\n"); | |
| 122 | try s.print("(null)\n", .{}); | |
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | }; |
| 126 | 126 | const held = self.mutex.acquire(); |
| 127 | 127 | defer held.release(); |
| 128 | 128 | |
| 129 | try stream.print("head: "); | |
| 129 | try stream.print("head: ", .{}); | |
| 130 | 130 | try S.dumpRecursive(stream, self.head, 0); |
| 131 | try stream.print("tail: "); | |
| 131 | try stream.print("tail: ", .{}); | |
| 132 | 132 | try S.dumpRecursive(stream, self.tail, 0); |
| 133 | 133 | } |
| 134 | 134 | }; |
| ... | ... | @@ -207,16 +207,15 @@ test "std.atomic.Queue" { |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 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 | 213 | if (context.get_count != puts_per_thread * put_thread_count) { |
| 214 | std.debug.panic( | |
| 215 | "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", | |
| 214 | std.debug.panic("failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", .{ | |
| 216 | 215 | context.get_count, |
| 217 | 216 | @as(u32, puts_per_thread), |
| 218 | 217 | @as(u32, put_thread_count), |
| 219 | ); | |
| 218 | }); | |
| 220 | 219 | } |
| 221 | 220 | } |
| 222 | 221 | |
| ... | ... | @@ -351,7 +350,7 @@ test "std.atomic.Queue dump" { |
| 351 | 350 | \\tail: 0x{x}=1 |
| 352 | 351 | \\ (null) |
| 353 | 352 | \\ |
| 354 | , @ptrToInt(queue.head), @ptrToInt(queue.tail)); | |
| 353 | , .{ @ptrToInt(queue.head), @ptrToInt(queue.tail) }); | |
| 355 | 354 | expect(mem.eql(u8, buffer[0..sos.pos], expected)); |
| 356 | 355 | |
| 357 | 356 | // Test a stream with two elements |
| ... | ... | @@ -372,6 +371,6 @@ test "std.atomic.Queue dump" { |
| 372 | 371 | \\tail: 0x{x}=2 |
| 373 | 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 | 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 | 134 | } |
| 135 | 135 | |
| 136 | 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 | 140 | if (context.get_count != puts_per_thread * put_thread_count) { |
| 141 | std.debug.panic( | |
| 142 | "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", | |
| 141 | std.debug.panic("failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", .{ | |
| 143 | 142 | context.get_count, |
| 144 | 143 | @as(u32, puts_per_thread), |
| 145 | 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 | 16 | mem.copy(u8, self.list.items, m); |
| 17 | 17 | return self; |
| 18 | 18 | } |
| 19 | ||
| 19 | ||
| 20 | 20 | /// Initialize memory to size bytes of undefined values. |
| 21 | 21 | /// Must deinitialize with deinit. |
| 22 | 22 | pub fn initSize(allocator: *Allocator, size: usize) !Buffer { |
| ... | ... | @@ -24,7 +24,7 @@ pub const Buffer = struct { |
| 24 | 24 | try self.resize(size); |
| 25 | 25 | return self; |
| 26 | 26 | } |
| 27 | ||
| 27 | ||
| 28 | 28 | /// Initialize with capacity to hold at least num bytes. |
| 29 | 29 | /// Must deinitialize with deinit. |
| 30 | 30 | pub fn initCapacity(allocator: *Allocator, num: usize) !Buffer { |
| ... | ... | @@ -64,7 +64,7 @@ pub const Buffer = struct { |
| 64 | 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 | 68 | const countSize = struct { |
| 69 | 69 | fn countSize(size: *usize, bytes: []const u8) (error{}!void) { |
| 70 | 70 | size.* += bytes.len; |
| ... | ... | @@ -107,7 +107,7 @@ pub const Buffer = struct { |
| 107 | 107 | pub fn len(self: Buffer) usize { |
| 108 | 108 | return self.list.len - 1; |
| 109 | 109 | } |
| 110 | ||
| 110 | ||
| 111 | 111 | pub fn capacity(self: Buffer) usize { |
| 112 | 112 | return if (self.list.items.len > 0) |
| 113 | 113 | self.list.items.len - 1 |
lib/std/build.zig+104-82| ... | ... | @@ -232,7 +232,7 @@ pub const Builder = struct { |
| 232 | 232 | /// To run an executable built with zig build, see `LibExeObjStep.run`. |
| 233 | 233 | pub fn addSystemCommand(self: *Builder, argv: []const []const u8) *RunStep { |
| 234 | 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 | 236 | run_step.addArgs(argv); |
| 237 | 237 | return run_step; |
| 238 | 238 | } |
| ... | ... | @@ -258,7 +258,7 @@ pub const Builder = struct { |
| 258 | 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 | 262 | const data = self.fmt(format, args); |
| 263 | 263 | const log_step = self.allocator.create(LogStep) catch unreachable; |
| 264 | 264 | log_step.* = LogStep.init(self, data); |
| ... | ... | @@ -330,7 +330,7 @@ pub const Builder = struct { |
| 330 | 330 | for (self.installed_files.toSliceConst()) |installed_file| { |
| 331 | 331 | const full_path = self.getInstallPath(installed_file.dir, installed_file.path); |
| 332 | 332 | if (self.verbose) { |
| 333 | warn("rm {}\n", full_path); | |
| 333 | warn("rm {}\n", .{full_path}); | |
| 334 | 334 | } |
| 335 | 335 | fs.deleteTree(full_path) catch {}; |
| 336 | 336 | } |
| ... | ... | @@ -340,7 +340,7 @@ pub const Builder = struct { |
| 340 | 340 | |
| 341 | 341 | fn makeOneStep(self: *Builder, s: *Step) anyerror!void { |
| 342 | 342 | if (s.loop_flag) { |
| 343 | warn("Dependency loop detected:\n {}\n", s.name); | |
| 343 | warn("Dependency loop detected:\n {}\n", .{s.name}); | |
| 344 | 344 | return error.DependencyLoopDetected; |
| 345 | 345 | } |
| 346 | 346 | s.loop_flag = true; |
| ... | ... | @@ -348,7 +348,7 @@ pub const Builder = struct { |
| 348 | 348 | for (s.dependencies.toSlice()) |dep| { |
| 349 | 349 | self.makeOneStep(dep) catch |err| { |
| 350 | 350 | if (err == error.DependencyLoopDetected) { |
| 351 | warn(" {}\n", s.name); | |
| 351 | warn(" {}\n", .{s.name}); | |
| 352 | 352 | } |
| 353 | 353 | return err; |
| 354 | 354 | }; |
| ... | ... | @@ -365,7 +365,7 @@ pub const Builder = struct { |
| 365 | 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 | 369 | return error.InvalidStepName; |
| 370 | 370 | } |
| 371 | 371 | |
| ... | ... | @@ -378,12 +378,12 @@ pub const Builder = struct { |
| 378 | 378 | const word = it.next() orelse break; |
| 379 | 379 | if (mem.eql(u8, word, "-isystem")) { |
| 380 | 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 | 382 | break; |
| 383 | 383 | }; |
| 384 | 384 | self.addNativeSystemIncludeDir(include_path); |
| 385 | 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 | 387 | break; |
| 388 | 388 | } |
| 389 | 389 | } |
| ... | ... | @@ -397,7 +397,7 @@ pub const Builder = struct { |
| 397 | 397 | const word = it.next() orelse break; |
| 398 | 398 | if (mem.eql(u8, word, "-rpath")) { |
| 399 | 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 | 401 | break; |
| 402 | 402 | }; |
| 403 | 403 | self.addNativeSystemRPath(rpath); |
| ... | ... | @@ -405,7 +405,7 @@ pub const Builder = struct { |
| 405 | 405 | const lib_path = word[2..]; |
| 406 | 406 | self.addNativeSystemLibPath(lib_path); |
| 407 | 407 | } else { |
| 408 | warn("Unrecognized C flag from NIX_LDFLAGS: {}\n", word); | |
| 408 | warn("Unrecognized C flag from NIX_LDFLAGS: {}\n", .{word}); | |
| 409 | 409 | break; |
| 410 | 410 | } |
| 411 | 411 | } |
| ... | ... | @@ -431,8 +431,8 @@ pub const Builder = struct { |
| 431 | 431 | self.addNativeSystemIncludeDir("/usr/local/include"); |
| 432 | 432 | self.addNativeSystemLibPath("/usr/local/lib"); |
| 433 | 433 | |
| 434 | self.addNativeSystemIncludeDir(self.fmt("/usr/include/{}", triple)); | |
| 435 | self.addNativeSystemLibPath(self.fmt("/usr/lib/{}", triple)); | |
| 434 | self.addNativeSystemIncludeDir(self.fmt("/usr/include/{}", .{triple})); | |
| 435 | self.addNativeSystemLibPath(self.fmt("/usr/lib/{}", .{triple})); | |
| 436 | 436 | |
| 437 | 437 | self.addNativeSystemIncludeDir("/usr/include"); |
| 438 | 438 | self.addNativeSystemLibPath("/usr/lib"); |
| ... | ... | @@ -440,7 +440,7 @@ pub const Builder = struct { |
| 440 | 440 | // example: on a 64-bit debian-based linux distro, with zlib installed from apt: |
| 441 | 441 | // zlib.h is in /usr/include (added above) |
| 442 | 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 | 453 | .description = description, |
| 454 | 454 | }; |
| 455 | 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 | 458 | self.available_options_list.append(available_option) catch unreachable; |
| 459 | 459 | |
| ... | ... | @@ -468,33 +468,33 @@ pub const Builder = struct { |
| 468 | 468 | } else if (mem.eql(u8, s, "false")) { |
| 469 | 469 | return false; |
| 470 | 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 | 472 | self.markInvalidUserInput(); |
| 473 | 473 | return null; |
| 474 | 474 | } |
| 475 | 475 | }, |
| 476 | 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 | 478 | self.markInvalidUserInput(); |
| 479 | 479 | return null; |
| 480 | 480 | }, |
| 481 | 481 | }, |
| 482 | TypeId.Int => panic("TODO integer options to build script"), | |
| 483 | TypeId.Float => panic("TODO float options to build script"), | |
| 482 | TypeId.Int => panic("TODO integer options to build script", .{}), | |
| 483 | TypeId.Float => panic("TODO float options to build script", .{}), | |
| 484 | 484 | TypeId.String => switch (entry.value.value) { |
| 485 | 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 | 487 | self.markInvalidUserInput(); |
| 488 | 488 | return null; |
| 489 | 489 | }, |
| 490 | 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 | 492 | self.markInvalidUserInput(); |
| 493 | 493 | return null; |
| 494 | 494 | }, |
| 495 | 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 | 513 | if (self.release_mode != null) { |
| 514 | 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 | 517 | self.is_release = self.option(bool, "release", description) orelse false; |
| 518 | 518 | self.release_mode = if (self.is_release) mode else builtin.Mode.Debug; |
| 519 | 519 | } |
| ... | ... | @@ -536,7 +536,7 @@ pub const Builder = struct { |
| 536 | 536 | else if (!release_fast and !release_safe and !release_small) |
| 537 | 537 | builtin.Mode.Debug |
| 538 | 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 | 540 | self.markInvalidUserInput(); |
| 541 | 541 | break :x builtin.Mode.Debug; |
| 542 | 542 | }; |
| ... | ... | @@ -599,7 +599,7 @@ pub const Builder = struct { |
| 599 | 599 | }) catch unreachable; |
| 600 | 600 | }, |
| 601 | 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 | 603 | return true; |
| 604 | 604 | }, |
| 605 | 605 | } |
| ... | ... | @@ -620,11 +620,11 @@ pub const Builder = struct { |
| 620 | 620 | // option already exists |
| 621 | 621 | switch (gop.kv.value.value) { |
| 622 | 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 | 624 | return true; |
| 625 | 625 | }, |
| 626 | 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 | 628 | return true; |
| 629 | 629 | }, |
| 630 | 630 | UserValue.Flag => {}, |
| ... | ... | @@ -665,7 +665,7 @@ pub const Builder = struct { |
| 665 | 665 | while (true) { |
| 666 | 666 | const entry = it.next() orelse break; |
| 667 | 667 | if (!entry.value.used) { |
| 668 | warn("Invalid option: -D{}\n\n", entry.key); | |
| 668 | warn("Invalid option: -D{}\n\n", .{entry.key}); | |
| 669 | 669 | self.markInvalidUserInput(); |
| 670 | 670 | } |
| 671 | 671 | } |
| ... | ... | @@ -678,11 +678,11 @@ pub const Builder = struct { |
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 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 | 682 | for (argv) |arg| { |
| 683 | warn("{} ", arg); | |
| 683 | warn("{} ", .{arg}); | |
| 684 | 684 | } |
| 685 | warn("\n"); | |
| 685 | warn("\n", .{}); | |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 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 | 697 | child.env_map = env_map; |
| 698 | 698 | |
| 699 | 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 | 701 | return err; |
| 702 | 702 | }; |
| 703 | 703 | |
| 704 | 704 | switch (term) { |
| 705 | 705 | .Exited => |code| { |
| 706 | 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 | 708 | printCmd(cwd, argv); |
| 709 | 709 | return error.UncleanExit; |
| 710 | 710 | } |
| 711 | 711 | }, |
| 712 | 712 | else => { |
| 713 | warn("The following command terminated unexpectedly:\n"); | |
| 713 | warn("The following command terminated unexpectedly:\n", .{}); | |
| 714 | 714 | printCmd(cwd, argv); |
| 715 | 715 | |
| 716 | 716 | return error.UncleanExit; |
| ... | ... | @@ -720,7 +720,7 @@ pub const Builder = struct { |
| 720 | 720 | |
| 721 | 721 | pub fn makePath(self: *Builder, path: []const u8) !void { |
| 722 | 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 | 724 | return err; |
| 725 | 725 | }; |
| 726 | 726 | } |
| ... | ... | @@ -793,12 +793,12 @@ pub const Builder = struct { |
| 793 | 793 | |
| 794 | 794 | fn updateFile(self: *Builder, source_path: []const u8, dest_path: []const u8) !void { |
| 795 | 795 | if (self.verbose) { |
| 796 | warn("cp {} {} ", source_path, dest_path); | |
| 796 | warn("cp {} {} ", .{ source_path, dest_path }); | |
| 797 | 797 | } |
| 798 | 798 | const prev_status = try fs.updateFile(source_path, dest_path); |
| 799 | 799 | if (self.verbose) switch (prev_status) { |
| 800 | .stale => warn("# installed\n"), | |
| 801 | .fresh => warn("# up-to-date\n"), | |
| 800 | .stale => warn("# installed\n", .{}), | |
| 801 | .fresh => warn("# up-to-date\n", .{}), | |
| 802 | 802 | }; |
| 803 | 803 | } |
| 804 | 804 | |
| ... | ... | @@ -806,7 +806,7 @@ pub const Builder = struct { |
| 806 | 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 | 810 | return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable; |
| 811 | 811 | } |
| 812 | 812 | |
| ... | ... | @@ -818,7 +818,11 @@ pub const Builder = struct { |
| 818 | 818 | if (fs.path.isAbsolute(name)) { |
| 819 | 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 | 826 | return fs.realpathAlloc(self.allocator, full_path) catch continue; |
| 823 | 827 | } |
| 824 | 828 | } |
| ... | ... | @@ -829,7 +833,10 @@ pub const Builder = struct { |
| 829 | 833 | } |
| 830 | 834 | var it = mem.tokenize(PATH, &[_]u8{fs.path.delimiter}); |
| 831 | 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 | 840 | return fs.realpathAlloc(self.allocator, full_path) catch continue; |
| 834 | 841 | } |
| 835 | 842 | } |
| ... | ... | @@ -839,7 +846,10 @@ pub const Builder = struct { |
| 839 | 846 | return name; |
| 840 | 847 | } |
| 841 | 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 | 853 | return fs.realpathAlloc(self.allocator, full_path) catch continue; |
| 844 | 854 | } |
| 845 | 855 | } |
| ... | ... | @@ -896,17 +906,17 @@ pub const Builder = struct { |
| 896 | 906 | var code: u8 = undefined; |
| 897 | 907 | return self.execAllowFail(argv, &code, .Inherit) catch |err| switch (err) { |
| 898 | 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 | 910 | printCmd(null, argv); |
| 901 | 911 | std.os.exit(@truncate(u8, code)); |
| 902 | 912 | }, |
| 903 | 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 | 915 | printCmd(null, argv); |
| 906 | 916 | std.os.exit(@truncate(u8, code)); |
| 907 | 917 | }, |
| 908 | 918 | error.ProcessTerminated => { |
| 909 | warn("The following command terminated unexpectedly:\n"); | |
| 919 | warn("The following command terminated unexpectedly:\n", .{}); | |
| 910 | 920 | printCmd(null, argv); |
| 911 | 921 | std.os.exit(@truncate(u8, code)); |
| 912 | 922 | }, |
| ... | ... | @@ -1133,7 +1143,7 @@ pub const LibExeObjStep = struct { |
| 1133 | 1143 | |
| 1134 | 1144 | fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, is_dynamic: bool, ver: Version) LibExeObjStep { |
| 1135 | 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 | 1148 | var self = LibExeObjStep{ |
| 1139 | 1149 | .strip = false, |
| ... | ... | @@ -1150,9 +1160,9 @@ pub const LibExeObjStep = struct { |
| 1150 | 1160 | .step = Step.init(name, builder.allocator, make), |
| 1151 | 1161 | .version = ver, |
| 1152 | 1162 | .out_filename = undefined, |
| 1153 | .out_h_filename = builder.fmt("{}.h", name), | |
| 1163 | .out_h_filename = builder.fmt("{}.h", .{name}), | |
| 1154 | 1164 | .out_lib_filename = undefined, |
| 1155 | .out_pdb_filename = builder.fmt("{}.pdb", name), | |
| 1165 | .out_pdb_filename = builder.fmt("{}.pdb", .{name}), | |
| 1156 | 1166 | .major_only_filename = undefined, |
| 1157 | 1167 | .name_only_filename = undefined, |
| 1158 | 1168 | .packages = ArrayList(Pkg).init(builder.allocator), |
| ... | ... | @@ -1186,36 +1196,48 @@ pub const LibExeObjStep = struct { |
| 1186 | 1196 | fn computeOutFileNames(self: *LibExeObjStep) void { |
| 1187 | 1197 | switch (self.kind) { |
| 1188 | 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 | 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 | 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 | 1207 | .Lib => { |
| 1198 | 1208 | if (!self.is_dynamic) { |
| 1199 | self.out_filename = self.builder.fmt( | |
| 1200 | "{}{}{}", | |
| 1209 | self.out_filename = self.builder.fmt("{}{}{}", .{ | |
| 1201 | 1210 | self.target.libPrefix(), |
| 1202 | 1211 | self.name, |
| 1203 | 1212 | self.target.staticLibSuffix(), |
| 1204 | ); | |
| 1213 | }); | |
| 1205 | 1214 | self.out_lib_filename = self.out_filename; |
| 1206 | 1215 | } else { |
| 1207 | 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); | |
| 1209 | self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", self.name, self.version.major); | |
| 1210 | self.name_only_filename = self.builder.fmt("lib{}.dylib", self.name); | |
| 1217 | self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", .{ | |
| 1218 | 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 | 1228 | self.out_lib_filename = self.out_filename; |
| 1212 | 1229 | } else if (self.target.isWindows()) { |
| 1213 | self.out_filename = self.builder.fmt("{}.dll", self.name); | |
| 1214 | self.out_lib_filename = self.builder.fmt("{}.lib", self.name); | |
| 1230 | self.out_filename = self.builder.fmt("{}.dll", .{self.name}); | |
| 1231 | self.out_lib_filename = self.builder.fmt("{}.lib", .{self.name}); | |
| 1215 | 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); | |
| 1217 | self.major_only_filename = self.builder.fmt("lib{}.so.{d}", self.name, self.version.major); | |
| 1218 | self.name_only_filename = self.builder.fmt("lib{}.so", self.name); | |
| 1233 | self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", .{ | |
| 1234 | 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 | 1241 | self.out_lib_filename = self.out_filename; |
| 1220 | 1242 | } |
| 1221 | 1243 | } |
| ... | ... | @@ -1268,7 +1290,7 @@ pub const LibExeObjStep = struct { |
| 1268 | 1290 | // It doesn't have to be native. We catch that if you actually try to run it. |
| 1269 | 1291 | // Consider that this is declarative; the run step may not be run unless a user |
| 1270 | 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 | 1294 | run_step.addArtifactArg(exe); |
| 1273 | 1295 | |
| 1274 | 1296 | if (exe.vcpkg_bin_path) |path| { |
| ... | ... | @@ -1420,7 +1442,7 @@ pub const LibExeObjStep = struct { |
| 1420 | 1442 | } else if (mem.eql(u8, tok, "-pthread")) { |
| 1421 | 1443 | self.linkLibC(); |
| 1422 | 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 | 1675 | const builder = self.builder; |
| 1654 | 1676 | |
| 1655 | 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 | 1679 | return error.NeedAnObject; |
| 1658 | 1680 | } |
| 1659 | 1681 | |
| ... | ... | @@ -1725,7 +1747,7 @@ pub const LibExeObjStep = struct { |
| 1725 | 1747 | if (self.build_options_contents.len() > 0) { |
| 1726 | 1748 | const build_options_file = try fs.path.join( |
| 1727 | 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 | 1752 | try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst()); |
| 1731 | 1753 | try zig_args.append("--pkg-begin"); |
| ... | ... | @@ -1780,13 +1802,13 @@ pub const LibExeObjStep = struct { |
| 1780 | 1802 | |
| 1781 | 1803 | if (self.kind == Kind.Lib and self.is_dynamic) { |
| 1782 | 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 | 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 | 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 | 1813 | if (self.is_dynamic) { |
| 1792 | 1814 | try zig_args.append("-dynamic"); |
| ... | ... | @@ -1811,7 +1833,7 @@ pub const LibExeObjStep = struct { |
| 1811 | 1833 | |
| 1812 | 1834 | if (self.target_glibc) |ver| { |
| 1813 | 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 | 1839 | if (self.linker_script) |linker_script| { |
| ... | ... | @@ -2079,7 +2101,7 @@ pub const RunStep = struct { |
| 2079 | 2101 | } |
| 2080 | 2102 | |
| 2081 | 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 | 2105 | env_map.set(key, new_path) catch unreachable; |
| 2084 | 2106 | } else { |
| 2085 | 2107 | env_map.set(key, search_path) catch unreachable; |
| ... | ... | @@ -2153,7 +2175,7 @@ const InstallArtifactStep = struct { |
| 2153 | 2175 | const self = builder.allocator.create(Self) catch unreachable; |
| 2154 | 2176 | self.* = Self{ |
| 2155 | 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 | 2179 | .artifact = artifact, |
| 2158 | 2180 | .dest_dir = switch (artifact.kind) { |
| 2159 | 2181 | .Obj => unreachable, |
| ... | ... | @@ -2219,7 +2241,7 @@ pub const InstallFileStep = struct { |
| 2219 | 2241 | builder.pushInstalledFile(dir, dest_rel_path); |
| 2220 | 2242 | return InstallFileStep{ |
| 2221 | 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 | 2245 | .src_path = src_path, |
| 2224 | 2246 | .dir = dir, |
| 2225 | 2247 | .dest_rel_path = dest_rel_path, |
| ... | ... | @@ -2253,7 +2275,7 @@ pub const InstallDirStep = struct { |
| 2253 | 2275 | builder.pushInstalledFile(options.install_dir, options.install_subdir); |
| 2254 | 2276 | return InstallDirStep{ |
| 2255 | 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 | 2279 | .options = options, |
| 2258 | 2280 | }; |
| 2259 | 2281 | } |
| ... | ... | @@ -2290,7 +2312,7 @@ pub const WriteFileStep = struct { |
| 2290 | 2312 | pub fn init(builder: *Builder, file_path: []const u8, data: []const u8) WriteFileStep { |
| 2291 | 2313 | return WriteFileStep{ |
| 2292 | 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 | 2316 | .file_path = file_path, |
| 2295 | 2317 | .data = data, |
| 2296 | 2318 | }; |
| ... | ... | @@ -2301,11 +2323,11 @@ pub const WriteFileStep = struct { |
| 2301 | 2323 | const full_path = self.builder.pathFromRoot(self.file_path); |
| 2302 | 2324 | const full_path_dir = fs.path.dirname(full_path) orelse "."; |
| 2303 | 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 | 2327 | return err; |
| 2306 | 2328 | }; |
| 2307 | 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 | 2331 | return err; |
| 2310 | 2332 | }; |
| 2311 | 2333 | } |
| ... | ... | @@ -2319,14 +2341,14 @@ pub const LogStep = struct { |
| 2319 | 2341 | pub fn init(builder: *Builder, data: []const u8) LogStep { |
| 2320 | 2342 | return LogStep{ |
| 2321 | 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 | 2345 | .data = data, |
| 2324 | 2346 | }; |
| 2325 | 2347 | } |
| 2326 | 2348 | |
| 2327 | 2349 | fn make(step: *Step) anyerror!void { |
| 2328 | 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 | 2360 | pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep { |
| 2339 | 2361 | return RemoveDirStep{ |
| 2340 | 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 | 2364 | .dir_path = dir_path, |
| 2343 | 2365 | }; |
| 2344 | 2366 | } |
| ... | ... | @@ -2348,7 +2370,7 @@ pub const RemoveDirStep = struct { |
| 2348 | 2370 | |
| 2349 | 2371 | const full_path = self.builder.pathFromRoot(self.dir_path); |
| 2350 | 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 | 2374 | return err; |
| 2353 | 2375 | }; |
| 2354 | 2376 | } |
| ... | ... | @@ -2397,7 +2419,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj |
| 2397 | 2419 | &[_][]const u8{ out_dir, filename_major_only }, |
| 2398 | 2420 | ) catch unreachable; |
| 2399 | 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 | 2423 | return err; |
| 2402 | 2424 | }; |
| 2403 | 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 | 2428 | &[_][]const u8{ out_dir, filename_name_only }, |
| 2407 | 2429 | ) catch unreachable; |
| 2408 | 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 | 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 | 429 | } |
| 430 | 430 | }, |
| 431 | 431 | .wasi => { |
| 432 | std.debug.warn("{}", msg); | |
| 432 | std.debug.warn("{}", .{msg}); | |
| 433 | 433 | _ = std.os.wasi.proc_raise(std.os.wasi.SIGABRT); |
| 434 | 434 | unreachable; |
| 435 | 435 | }, |
| ... | ... | @@ -439,7 +439,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn |
| 439 | 439 | }, |
| 440 | 440 | else => { |
| 441 | 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 | 114 | \\ --seed [int] |
| 115 | 115 | \\ --help |
| 116 | 116 | \\ |
| 117 | ); | |
| 117 | , .{}); | |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 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 | 46 | var stderr_stream: ?*io.OutStream(File.WriteError) = null; |
| 47 | 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 | 50 | const held = stderr_mutex.acquire(); |
| 51 | 51 | defer held.release(); |
| 52 | 52 | const stderr = getStderrStream(); |
| ... | ... | @@ -92,15 +92,15 @@ fn wantTtyColor() bool { |
| 92 | 92 | pub fn dumpCurrentStackTrace(start_addr: ?usize) void { |
| 93 | 93 | const stderr = getStderrStream(); |
| 94 | 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 | 96 | return; |
| 97 | 97 | } |
| 98 | 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 | 100 | return; |
| 101 | 101 | }; |
| 102 | 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 | 104 | return; |
| 105 | 105 | }; |
| 106 | 106 | } |
| ... | ... | @@ -111,11 +111,11 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void { |
| 111 | 111 | pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void { |
| 112 | 112 | const stderr = getStderrStream(); |
| 113 | 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 | 115 | return; |
| 116 | 116 | } |
| 117 | 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 | 119 | return; |
| 120 | 120 | }; |
| 121 | 121 | const tty_color = wantTtyColor(); |
| ... | ... | @@ -184,15 +184,15 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace |
| 184 | 184 | pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void { |
| 185 | 185 | const stderr = getStderrStream(); |
| 186 | 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 | 188 | return; |
| 189 | 189 | } |
| 190 | 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 | 192 | return; |
| 193 | 193 | }; |
| 194 | 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 | 196 | return; |
| 197 | 197 | }; |
| 198 | 198 | } |
| ... | ... | @@ -211,7 +211,7 @@ pub fn assert(ok: bool) void { |
| 211 | 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 | 215 | @setCold(true); |
| 216 | 216 | // TODO: remove conditional once wasi / LLVM defines __builtin_return_address |
| 217 | 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 | 221 | /// TODO multithreaded awareness |
| 222 | 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 | 225 | @setCold(true); |
| 226 | 226 | |
| 227 | 227 | if (enable_segfault_handler) { |
| ... | ... | @@ -376,13 +376,13 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres |
| 376 | 376 | } else { |
| 377 | 377 | // we have no information to add to the address |
| 378 | 378 | if (tty_color) { |
| 379 | try out_stream.print("???:?:?: "); | |
| 379 | try out_stream.print("???:?:?: ", .{}); | |
| 380 | 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 | 382 | setTtyColor(TtyColor.Reset); |
| 383 | try out_stream.print("\n\n\n"); | |
| 383 | try out_stream.print("\n\n\n", .{}); | |
| 384 | 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 | 387 | return; |
| 388 | 388 | }; |
| ... | ... | @@ -509,18 +509,18 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres |
| 509 | 509 | if (tty_color) { |
| 510 | 510 | setTtyColor(TtyColor.White); |
| 511 | 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 | 513 | } else { |
| 514 | try out_stream.print("???:?:?"); | |
| 514 | try out_stream.print("???:?:?", .{}); | |
| 515 | 515 | } |
| 516 | 516 | setTtyColor(TtyColor.Reset); |
| 517 | try out_stream.print(": "); | |
| 517 | try out_stream.print(": ", .{}); | |
| 518 | 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 | 520 | setTtyColor(TtyColor.Reset); |
| 521 | 521 | |
| 522 | 522 | if (opt_line_info) |line_info| { |
| 523 | try out_stream.print("\n"); | |
| 523 | try out_stream.print("\n", .{}); | |
| 524 | 524 | if (printLineFromFileAnyOs(out_stream, line_info)) { |
| 525 | 525 | if (line_info.column == 0) { |
| 526 | 526 | try out_stream.write("\n"); |
| ... | ... | @@ -546,13 +546,24 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres |
| 546 | 546 | else => return err, |
| 547 | 547 | } |
| 548 | 548 | } else { |
| 549 | try out_stream.print("\n\n\n"); | |
| 549 | try out_stream.print("\n\n\n", .{}); | |
| 550 | 550 | } |
| 551 | 551 | } else { |
| 552 | 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 | 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 | 708 | |
| 698 | 709 | const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse { |
| 699 | 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 | 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 | 715 | return; |
| 705 | 716 | }; |
| ... | ... | @@ -723,9 +734,11 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt |
| 723 | 734 | } else |err| switch (err) { |
| 724 | 735 | error.MissingDebugInfo, error.InvalidDebugInfo => { |
| 725 | 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 | 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 | 744 | else => return err, |
| ... | ... | @@ -746,15 +759,14 @@ fn printLineInfo( |
| 746 | 759 | comptime printLineFromFile: var, |
| 747 | 760 | ) !void { |
| 748 | 761 | if (tty_color) { |
| 749 | try out_stream.print( | |
| 750 | WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n", | |
| 762 | try out_stream.print(WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n", .{ | |
| 751 | 763 | line_info.file_name, |
| 752 | 764 | line_info.line, |
| 753 | 765 | line_info.column, |
| 754 | 766 | address, |
| 755 | 767 | symbol_name, |
| 756 | 768 | compile_unit_name, |
| 757 | ); | |
| 769 | }); | |
| 758 | 770 | if (printLineFromFile(out_stream, line_info)) { |
| 759 | 771 | if (line_info.column == 0) { |
| 760 | 772 | try out_stream.write("\n"); |
| ... | ... | @@ -772,15 +784,14 @@ fn printLineInfo( |
| 772 | 784 | else => return err, |
| 773 | 785 | } |
| 774 | 786 | } else { |
| 775 | try out_stream.print( | |
| 776 | "{}:{}:{}: 0x{x} in {} ({})\n", | |
| 787 | try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n", .{ | |
| 777 | 788 | line_info.file_name, |
| 778 | 789 | line_info.line, |
| 779 | 790 | line_info.column, |
| 780 | 791 | address, |
| 781 | 792 | symbol_name, |
| 782 | 793 | compile_unit_name, |
| 783 | ); | |
| 794 | }); | |
| 784 | 795 | } |
| 785 | 796 | } |
| 786 | 797 | |
| ... | ... | @@ -1226,9 +1237,9 @@ pub const DwarfInfo = struct { |
| 1226 | 1237 | ) !void { |
| 1227 | 1238 | const compile_unit = self.findCompileUnit(address) catch { |
| 1228 | 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 | 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 | 1244 | return; |
| 1234 | 1245 | }; |
| ... | ... | @@ -1248,9 +1259,11 @@ pub const DwarfInfo = struct { |
| 1248 | 1259 | } else |err| switch (err) { |
| 1249 | 1260 | error.MissingDebugInfo, error.InvalidDebugInfo => { |
| 1250 | 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 | 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 | 1269 | else => return err, |
| ... | ... | @@ -2416,7 +2429,7 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con |
| 2416 | 2429 | resetSegfaultHandler(); |
| 2417 | 2430 | |
| 2418 | 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 | 2434 | switch (builtin.arch) { |
| 2422 | 2435 | .i386 => { |
| ... | ... | @@ -2468,7 +2481,7 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void { |
| 2468 | 2481 | const sp = asm ("" |
| 2469 | 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 | 2487 | // Reference everything so it gets tested. |
lib/std/event/channel.zig+2-2| ... | ... | @@ -294,14 +294,14 @@ test "std.event.Channel wraparound" { |
| 294 | 294 | |
| 295 | 295 | const channel_size = 2; |
| 296 | 296 | |
| 297 | var buf : [channel_size]i32 = undefined; | |
| 297 | var buf: [channel_size]i32 = undefined; | |
| 298 | 298 | var channel: Channel(i32) = undefined; |
| 299 | 299 | channel.init(&buf); |
| 300 | 300 | defer channel.deinit(); |
| 301 | 301 | |
| 302 | 302 | // add items to channel and pull them out until |
| 303 | 303 | // the buffer wraps around, make sure it doesn't crash. |
| 304 | var result : i32 = undefined; | |
| 304 | var result: i32 = undefined; | |
| 305 | 305 | channel.put(5); |
| 306 | 306 | testing.expectEqual(@as(i32, 5), channel.get()); |
| 307 | 307 | channel.put(6); |
lib/std/fifo.zig+2-2| ... | ... | @@ -293,7 +293,7 @@ pub fn LinearFifo( |
| 293 | 293 | |
| 294 | 294 | pub usingnamespace if (T == u8) |
| 295 | 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 | 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 | 407 | fifo.shrink(0); |
| 408 | 408 | |
| 409 | 409 | { |
| 410 | try fifo.print("{}, {}!", "Hello", "World"); | |
| 410 | try fifo.print("{}, {}!", .{ "Hello", "World" }); | |
| 411 | 411 | var result: [30]u8 = undefined; |
| 412 | 412 | testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]); |
| 413 | 413 | testing.expectEqual(@as(usize, 0), fifo.readableLength()); |
lib/std/fmt.zig+111-109| ... | ... | @@ -91,10 +91,12 @@ pub fn format( |
| 91 | 91 | comptime Errors: type, |
| 92 | 92 | output: fn (@typeOf(context), []const u8) Errors!void, |
| 93 | 93 | comptime fmt: []const u8, |
| 94 | args: ..., | |
| 94 | args: var, | |
| 95 | 95 | ) Errors!void { |
| 96 | 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 | 100 | @compileError("32 arguments max are supported per format call"); |
| 99 | 101 | } |
| 100 | 102 | |
| ... | ... | @@ -158,14 +160,14 @@ pub fn format( |
| 158 | 160 | maybe_pos_arg.? += c - '0'; |
| 159 | 161 | specifier_start = i + 1; |
| 160 | 162 | |
| 161 | if (maybe_pos_arg.? >= args.len) { | |
| 163 | if (maybe_pos_arg.? >= args_len) { | |
| 162 | 164 | @compileError("Positional value refers to non-existent argument"); |
| 163 | 165 | } |
| 164 | 166 | }, |
| 165 | 167 | '}' => { |
| 166 | 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 | 171 | @compileError("Too few arguments"); |
| 170 | 172 | } |
| 171 | 173 | |
| ... | ... | @@ -302,7 +304,7 @@ pub fn format( |
| 302 | 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 | 308 | @compileError("Unused arguments"); |
| 307 | 309 | } |
| 308 | 310 | if (state != State.Start) { |
| ... | ... | @@ -389,7 +391,7 @@ pub fn formatType( |
| 389 | 391 | } |
| 390 | 392 | try output(context, " }"); |
| 391 | 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 | 397 | .Struct => { |
| ... | ... | @@ -421,12 +423,12 @@ pub fn formatType( |
| 421 | 423 | if (info.child == u8) { |
| 422 | 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 | 428 | builtin.TypeId.Enum, builtin.TypeId.Union, builtin.TypeId.Struct => { |
| 427 | 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 | 433 | .Many => { |
| 432 | 434 | if (ptr_info.child == u8) { |
| ... | ... | @@ -435,7 +437,7 @@ pub fn formatType( |
| 435 | 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 | 442 | .Slice => { |
| 441 | 443 | if (fmt.len > 0 and ((fmt[0] == 'x') or (fmt[0] == 'X'))) { |
| ... | ... | @@ -444,10 +446,10 @@ pub fn formatType( |
| 444 | 446 | if (ptr_info.child == u8) { |
| 445 | 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 | 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 | 455 | .Array => |info| { |
| ... | ... | @@ -465,7 +467,7 @@ pub fn formatType( |
| 465 | 467 | return formatType(@as(Slice, &value), fmt, options, context, Errors, output, max_depth); |
| 466 | 468 | }, |
| 467 | 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 | 472 | else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"), |
| 471 | 473 | } |
| ... | ... | @@ -1113,7 +1115,7 @@ pub const BufPrintError = error{ |
| 1113 | 1115 | /// As much as possible was written to the buffer, but it was too small to fit all the printed bytes. |
| 1114 | 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 | 1119 | var context = BufPrintContext{ .remaining = buf }; |
| 1118 | 1120 | try format(&context, BufPrintError, bufPrintWrite, fmt, args); |
| 1119 | 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 | 1123 | |
| 1122 | 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 | 1127 | var size: usize = 0; |
| 1126 | 1128 | format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {}; |
| 1127 | 1129 | const buf = try allocator.alloc(u8, size); |
| ... | ... | @@ -1173,46 +1175,46 @@ test "parse unsigned comptime" { |
| 1173 | 1175 | test "optional" { |
| 1174 | 1176 | { |
| 1175 | 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 | 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 | 1186 | test "error" { |
| 1185 | 1187 | { |
| 1186 | 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 | 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 | 1197 | test "int.small" { |
| 1196 | 1198 | { |
| 1197 | 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 | 1204 | test "int.specifier" { |
| 1203 | 1205 | { |
| 1204 | 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 | 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 | 1215 | test "int.padded" { |
| 1214 | try testFmt("u8: ' 1'", "u8: '{:4}'", @as(u8, 1)); | |
| 1215 | try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", @as(u8, 1)); | |
| 1216 | try testFmt("u8: ' 1'", "u8: '{:4}'", .{@as(u8, 1)}); | |
| 1217 | try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", .{@as(u8, 1)}); | |
| 1216 | 1218 | } |
| 1217 | 1219 | |
| 1218 | 1220 | test "buffer" { |
| ... | ... | @@ -1238,14 +1240,14 @@ test "buffer" { |
| 1238 | 1240 | test "array" { |
| 1239 | 1241 | { |
| 1240 | 1242 | const value: [3]u8 = "abc".*; |
| 1241 | try testFmt("array: abc\n", "array: {}\n", value); | |
| 1242 | try testFmt("array: abc\n", "array: {}\n", &value); | |
| 1243 | try testFmt("array: abc\n", "array: {}\n", .{value}); | |
| 1244 | try testFmt("array: abc\n", "array: {}\n", .{&value}); | |
| 1243 | 1245 | |
| 1244 | 1246 | var buf: [100]u8 = undefined; |
| 1245 | 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 | 1249 | "array: {*}\n", |
| 1248 | &value, | |
| 1250 | .{&value}, | |
| 1249 | 1251 | ); |
| 1250 | 1252 | } |
| 1251 | 1253 | } |
| ... | ... | @@ -1253,36 +1255,36 @@ test "array" { |
| 1253 | 1255 | test "slice" { |
| 1254 | 1256 | { |
| 1255 | 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 | 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"); | |
| 1264 | try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", "Test"); | |
| 1265 | try testFmt("buf: Test \n", "buf: {s:5}\n", .{"Test"}); | |
| 1266 | try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", .{"Test"}); | |
| 1265 | 1267 | } |
| 1266 | 1268 | |
| 1267 | 1269 | test "pointer" { |
| 1268 | 1270 | { |
| 1269 | 1271 | const value = @intToPtr(*i32, 0xdeadbeef); |
| 1270 | try testFmt("pointer: i32@deadbeef\n", "pointer: {}\n", value); | |
| 1271 | try testFmt("pointer: i32@deadbeef\n", "pointer: {*}\n", value); | |
| 1272 | try testFmt("pointer: i32@deadbeef\n", "pointer: {}\n", .{value}); | |
| 1273 | try testFmt("pointer: i32@deadbeef\n", "pointer: {*}\n", .{value}); | |
| 1272 | 1274 | } |
| 1273 | 1275 | { |
| 1274 | 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 | 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 | 1285 | test "cstr" { |
| 1284 | try testFmt("cstr: Test C\n", "cstr: {s}\n", "Test C"); | |
| 1285 | try testFmt("cstr: Test C \n", "cstr: {s:10}\n", "Test C"); | |
| 1286 | try testFmt("cstr: Test C\n", "cstr: {s}\n", .{"Test C"}); | |
| 1287 | try testFmt("cstr: Test C \n", "cstr: {s:10}\n", .{"Test C"}); | |
| 1286 | 1288 | } |
| 1287 | 1289 | |
| 1288 | 1290 | test "filesize" { |
| ... | ... | @@ -1290,8 +1292,8 @@ test "filesize" { |
| 1290 | 1292 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1291 | 1293 | return error.SkipZigTest; |
| 1292 | 1294 | } |
| 1293 | 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)); | |
| 1295 | try testFmt("file size: 63MiB\n", "file size: {Bi}\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 | 1299 | test "struct" { |
| ... | ... | @@ -1300,8 +1302,8 @@ test "struct" { |
| 1300 | 1302 | field: u8, |
| 1301 | 1303 | }; |
| 1302 | 1304 | const value = Struct{ .field = 42 }; |
| 1303 | try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", value); | |
| 1304 | try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", &value); | |
| 1305 | 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 | 1309 | const Struct = struct { |
| ... | ... | @@ -1309,7 +1311,7 @@ test "struct" { |
| 1309 | 1311 | b: u1, |
| 1310 | 1312 | }; |
| 1311 | 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 | 1321 | Two, |
| 1320 | 1322 | }; |
| 1321 | 1323 | const value = Enum.Two; |
| 1322 | try testFmt("enum: Enum.Two\n", "enum: {}\n", value); | |
| 1323 | try testFmt("enum: Enum.Two\n", "enum: {}\n", &value); | |
| 1324 | try testFmt("enum: Enum.Two\n", "enum: {}\n", .{value}); | |
| 1325 | try testFmt("enum: Enum.Two\n", "enum: {}\n", .{&value}); | |
| 1324 | 1326 | } |
| 1325 | 1327 | |
| 1326 | 1328 | test "float.scientific" { |
| ... | ... | @@ -1328,10 +1330,10 @@ test "float.scientific" { |
| 1328 | 1330 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1329 | 1331 | return error.SkipZigTest; |
| 1330 | 1332 | } |
| 1331 | 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)); | |
| 1333 | 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)); | |
| 1333 | try testFmt("f32: 1.34000003e+00", "f32: {e}", .{@as(f32, 1.34)}); | |
| 1334 | try testFmt("f32: 1.23400001e+01", "f32: {e}", .{@as(f32, 12.34)}); | |
| 1335 | try testFmt("f64: -1.234e+11", "f64: {e}", .{@as(f64, -12.34e10)}); | |
| 1336 | try testFmt("f64: 9.99996e-40", "f64: {e}", .{@as(f64, 9.999960e-40)}); | |
| 1335 | 1337 | } |
| 1336 | 1338 | |
| 1337 | 1339 | test "float.scientific.precision" { |
| ... | ... | @@ -1339,12 +1341,12 @@ test "float.scientific.precision" { |
| 1339 | 1341 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1340 | 1342 | return error.SkipZigTest; |
| 1341 | 1343 | } |
| 1342 | 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)))); | |
| 1344 | try testFmt("f64: 7.81250e-03", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1006632960)))); | |
| 1344 | try testFmt("f64: 1.40971e-42", "f64: {e:.5}", .{@as(f64, 1.409706e-42)}); | |
| 1345 | try testFmt("f64: 1.00000e-09", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 814313563)))}); | |
| 1346 | try testFmt("f64: 7.81250e-03", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1006632960)))}); | |
| 1345 | 1347 | // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05. |
| 1346 | 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 | 1352 | test "float.special" { |
| ... | ... | @@ -1352,14 +1354,14 @@ test "float.special" { |
| 1352 | 1354 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1353 | 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 | 1358 | // negative nan is not defined by IEE 754, |
| 1357 | 1359 | // and ARM thus normalizes it to positive nan |
| 1358 | 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); | |
| 1362 | try testFmt("f64: -inf", "f64: {}", -math.inf_f64); | |
| 1363 | try testFmt("f64: inf", "f64: {}", .{math.inf_f64}); | |
| 1364 | try testFmt("f64: -inf", "f64: {}", .{-math.inf_f64}); | |
| 1363 | 1365 | } |
| 1364 | 1366 | |
| 1365 | 1367 | test "float.decimal" { |
| ... | ... | @@ -1367,21 +1369,21 @@ test "float.decimal" { |
| 1367 | 1369 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1368 | 1370 | return error.SkipZigTest; |
| 1369 | 1371 | } |
| 1370 | try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29)); | |
| 1371 | 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)); | |
| 1372 | try testFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e+29)}); | |
| 1373 | try testFmt("f32: 1.1", "f32: {d:.1}", .{@as(f32, 1.1234)}); | |
| 1374 | try testFmt("f32: 1234.57", "f32: {d:.2}", .{@as(f32, 1234.567)}); | |
| 1373 | 1375 | // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64). |
| 1374 | 1376 | // -11.12339... is rounded back up to -11.1234 |
| 1375 | 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)); | |
| 1377 | 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)); | |
| 1379 | try testFmt("f64: 6", "f64: {d:.0}", @as(f64, 5.700)); | |
| 1380 | 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)); | |
| 1382 | 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)); | |
| 1384 | try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 9.999960e-40)); | |
| 1377 | try testFmt("f32: -11.1234", "f32: {d:.4}", .{@as(f32, -11.1234)}); | |
| 1378 | try testFmt("f32: 91.12345", "f32: {d:.5}", .{@as(f32, 91.12345)}); | |
| 1379 | try testFmt("f64: 91.1234567890", "f64: {d:.10}", .{@as(f64, 91.12345678901235)}); | |
| 1380 | try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 0.0)}); | |
| 1381 | try testFmt("f64: 6", "f64: {d:.0}", .{@as(f64, 5.700)}); | |
| 1382 | try testFmt("f64: 10.0", "f64: {d:.1}", .{@as(f64, 9.999)}); | |
| 1383 | try testFmt("f64: 1.000", "f64: {d:.3}", .{@as(f64, 1.0)}); | |
| 1384 | try testFmt("f64: 0.00030000", "f64: {d:.8}", .{@as(f64, 0.0003)}); | |
| 1385 | try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 1.40130e-45)}); | |
| 1386 | try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 9.999960e-40)}); | |
| 1385 | 1387 | } |
| 1386 | 1388 | |
| 1387 | 1389 | test "float.libc.sanity" { |
| ... | ... | @@ -1389,22 +1391,22 @@ test "float.libc.sanity" { |
| 1389 | 1391 | // TODO https://github.com/ziglang/zig/issues/3289 |
| 1390 | 1392 | return error.SkipZigTest; |
| 1391 | 1393 | } |
| 1392 | 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)))); | |
| 1394 | 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)))); | |
| 1396 | try testFmt("f64: 10.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1092616192)))); | |
| 1394 | try testFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 916964781)))}); | |
| 1395 | try testFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 925353389)))}); | |
| 1396 | try testFmt("f64: 0.10000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1036831278)))}); | |
| 1397 | try testFmt("f64: 1.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1065353133)))}); | |
| 1398 | try testFmt("f64: 10.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1092616192)))}); | |
| 1397 | 1399 | |
| 1398 | 1400 | // libc differences |
| 1399 | 1401 | // |
| 1400 | 1402 | // This is 0.015625 exactly according to gdb. We thus round down, |
| 1401 | 1403 | // however glibc rounds up for some reason. This occurs for all |
| 1402 | 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 | 1406 | // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3 |
| 1405 | 1407 | // also rounds to 630 so I'm inclined to believe libc is not |
| 1406 | 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 | 1412 | test "custom" { |
| ... | ... | @@ -1422,9 +1424,9 @@ test "custom" { |
| 1422 | 1424 | output: fn (@typeOf(context), []const u8) Errors!void, |
| 1423 | 1425 | ) Errors!void { |
| 1424 | 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 | 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 | 1430 | } else { |
| 1429 | 1431 | @compileError("Unknown format character: '" ++ fmt ++ "'"); |
| 1430 | 1432 | } |
| ... | ... | @@ -1436,12 +1438,12 @@ test "custom" { |
| 1436 | 1438 | .x = 10.2, |
| 1437 | 1439 | .y = 2.22, |
| 1438 | 1440 | }; |
| 1439 | try testFmt("point: (10.200,2.220)\n", "point: {}\n", &value); | |
| 1440 | try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", &value); | |
| 1441 | try testFmt("point: (10.200,2.220)\n", "point: {}\n", .{&value}); | |
| 1442 | try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", .{&value}); | |
| 1441 | 1443 | |
| 1442 | 1444 | // same thing but not passing a pointer |
| 1443 | try testFmt("point: (10.200,2.220)\n", "point: {}\n", value); | |
| 1444 | try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", value); | |
| 1445 | try testFmt("point: (10.200,2.220)\n", "point: {}\n", .{value}); | |
| 1446 | try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", .{value}); | |
| 1445 | 1447 | } |
| 1446 | 1448 | |
| 1447 | 1449 | test "struct" { |
| ... | ... | @@ -1455,7 +1457,7 @@ test "struct" { |
| 1455 | 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 | 1463 | test "union" { |
| ... | ... | @@ -1478,13 +1480,13 @@ test "union" { |
| 1478 | 1480 | const uu_inst = UU{ .int = 456 }; |
| 1479 | 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 | 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 | 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 | 1490 | std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@")); |
| 1489 | 1491 | } |
| 1490 | 1492 | |
| ... | ... | @@ -1497,7 +1499,7 @@ test "enum" { |
| 1497 | 1499 | |
| 1498 | 1500 | const inst = E.Two; |
| 1499 | 1501 | |
| 1500 | try testFmt("E.Two", "{}", inst); | |
| 1502 | try testFmt("E.Two", "{}", .{inst}); | |
| 1501 | 1503 | } |
| 1502 | 1504 | |
| 1503 | 1505 | test "struct.self-referential" { |
| ... | ... | @@ -1511,7 +1513,7 @@ test "struct.self-referential" { |
| 1511 | 1513 | }; |
| 1512 | 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 | 1519 | test "struct.zero-size" { |
| ... | ... | @@ -1526,30 +1528,30 @@ test "struct.zero-size" { |
| 1526 | 1528 | const a = A{}; |
| 1527 | 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 | 1534 | test "bytes.hex" { |
| 1533 | 1535 | const some_bytes = "\xCA\xFE\xBA\xBE"; |
| 1534 | try testFmt("lowercase: cafebabe\n", "lowercase: {x}\n", some_bytes); | |
| 1535 | try testFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", some_bytes); | |
| 1536 | try testFmt("lowercase: cafebabe\n", "lowercase: {x}\n", .{some_bytes}); | |
| 1537 | try testFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", .{some_bytes}); | |
| 1536 | 1538 | //Test Slices |
| 1537 | try testFmt("uppercase: CAFE\n", "uppercase: {X}\n", some_bytes[0..2]); | |
| 1538 | try testFmt("lowercase: babe\n", "lowercase: {x}\n", some_bytes[2..]); | |
| 1539 | try testFmt("uppercase: CAFE\n", "uppercase: {X}\n", .{some_bytes[0..2]}); | |
| 1540 | try testFmt("lowercase: babe\n", "lowercase: {x}\n", .{some_bytes[2..]}); | |
| 1539 | 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 | 1546 | var buf: [100]u8 = undefined; |
| 1545 | 1547 | const result = try bufPrint(buf[0..], template, args); |
| 1546 | 1548 | if (mem.eql(u8, result, expected)) return; |
| 1547 | 1549 | |
| 1548 | std.debug.warn("\n====== expected this output: =========\n"); | |
| 1549 | std.debug.warn("{}", expected); | |
| 1550 | std.debug.warn("\n======== instead found this: =========\n"); | |
| 1551 | std.debug.warn("{}", result); | |
| 1552 | std.debug.warn("\n======================================\n"); | |
| 1550 | std.debug.warn("\n====== expected this output: =========\n", .{}); | |
| 1551 | std.debug.warn("{}", .{expected}); | |
| 1552 | std.debug.warn("\n======== instead found this: =========\n", .{}); | |
| 1553 | std.debug.warn("{}", .{result}); | |
| 1554 | std.debug.warn("\n======================================\n", .{}); | |
| 1553 | 1555 | return error.TestFailed; |
| 1554 | 1556 | } |
| 1555 | 1557 | |
| ... | ... | @@ -1602,7 +1604,7 @@ test "hexToBytes" { |
| 1602 | 1604 | const test_hex_str = "909A312BB12ED1F819B3521AC4C1E896F2160507FFC1C8381E3B07BB16BD1706"; |
| 1603 | 1605 | var pb: [32]u8 = undefined; |
| 1604 | 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 | 1610 | test "formatIntValue with comptime_int" { |
| ... | ... | @@ -1628,7 +1630,7 @@ test "formatType max_depth" { |
| 1628 | 1630 | output: fn (@typeOf(context), []const u8) Errors!void, |
| 1629 | 1631 | ) Errors!void { |
| 1630 | 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 | 1634 | } else { |
| 1633 | 1635 | @compileError("Unknown format string: '" ++ fmt ++ "'"); |
| 1634 | 1636 | } |
| ... | ... | @@ -1680,17 +1682,17 @@ test "formatType max_depth" { |
| 1680 | 1682 | } |
| 1681 | 1683 | |
| 1682 | 1684 | test "positional" { |
| 1683 | 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)); | |
| 1685 | try testFmt("0 0", "{0} {0}", @as(usize, 0)); | |
| 1686 | 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)); | |
| 1685 | try testFmt("2 1 0", "{2} {1} {0}", .{ @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) }); | |
| 1687 | try testFmt("0 0", "{0} {0}", .{@as(usize, 0)}); | |
| 1688 | try testFmt("0 1", "{} {1}", .{ @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 | 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 | 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 | 164 | \\ --iterative-only |
| 165 | 165 | \\ --help |
| 166 | 166 | \\ |
| 167 | ); | |
| 167 | , .{}); | |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | fn mode(comptime x: comptime_int) comptime_int { |
lib/std/http/headers.zig+1-1| ... | ... | @@ -610,5 +610,5 @@ test "Headers.format" { |
| 610 | 610 | \\foo: bar |
| 611 | 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 | 492 | var slice_stream = SliceOutStream.init(buf[0..]); |
| 493 | 493 | const stream = &slice_stream.stream; |
| 494 | 494 | |
| 495 | try stream.print("{}{}!", "Hello", "World"); | |
| 495 | try stream.print("{}{}!", .{ "Hello", "World" }); | |
| 496 | 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 | 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 | 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 | 27 | var file_out_stream = file.outStream(); |
| 28 | 28 | var buf_stream = io.BufferedOutStream(File.WriteError).init(&file_out_stream.stream); |
| 29 | 29 | const st = &buf_stream.stream; |
| 30 | try st.print("begin"); | |
| 30 | try st.print("begin", .{}); | |
| 31 | 31 | try st.write(data[0..]); |
| 32 | try st.print("end"); | |
| 32 | try st.print("end", .{}); | |
| 33 | 33 | try buf_stream.flush(); |
| 34 | 34 | } |
| 35 | 35 | |
| ... | ... | @@ -72,7 +72,7 @@ test "BufferOutStream" { |
| 72 | 72 | |
| 73 | 73 | const x: i32 = 42; |
| 74 | 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 | 77 | expect(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n")); |
| 78 | 78 | } |
| ... | ... | @@ -605,7 +605,7 @@ test "c out stream" { |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 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 | 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 | 158 | switch (@typeInfo(@typeOf(value))) { |
| 159 | 159 | .Int => |info| { |
| 160 | 160 | if (info.bits < 53) { |
| 161 | try self.stream.print("{}", value); | |
| 161 | try self.stream.print("{}", .{value}); | |
| 162 | 162 | self.popState(); |
| 163 | 163 | return; |
| 164 | 164 | } |
| 165 | 165 | if (value < 4503599627370496 and (!info.is_signed or value > -4503599627370496)) { |
| 166 | try self.stream.print("{}", value); | |
| 166 | try self.stream.print("{}", .{value}); | |
| 167 | 167 | self.popState(); |
| 168 | 168 | return; |
| 169 | 169 | } |
| 170 | 170 | }, |
| 171 | 171 | .Float => if (@floatCast(f64, value) == value) { |
| 172 | try self.stream.print("{}", value); | |
| 172 | try self.stream.print("{}", .{value}); | |
| 173 | 173 | self.popState(); |
| 174 | 174 | return; |
| 175 | 175 | }, |
| 176 | 176 | else => {}, |
| 177 | 177 | } |
| 178 | try self.stream.print("\"{}\"", value); | |
| 178 | try self.stream.print("\"{}\"", .{value}); | |
| 179 | 179 | self.popState(); |
| 180 | 180 | } |
| 181 | 181 |
lib/std/math/big/int.zig+2-2| ... | ... | @@ -180,9 +180,9 @@ pub const Int = struct { |
| 180 | 180 | |
| 181 | 181 | pub fn dump(self: Int) void { |
| 182 | 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 | 188 | /// Negate the sign of an Int. |
lib/std/net.zig+7-15| ... | ... | @@ -277,32 +277,24 @@ pub const Address = extern union { |
| 277 | 277 | os.AF_INET => { |
| 278 | 278 | const port = mem.bigToNative(u16, self.in.port); |
| 279 | 279 | const bytes = @ptrCast(*const [4]u8, &self.in.addr); |
| 280 | try std.fmt.format( | |
| 281 | context, | |
| 282 | Errors, | |
| 283 | output, | |
| 284 | "{}.{}.{}.{}:{}", | |
| 280 | try std.fmt.format(context, Errors, output, "{}.{}.{}.{}:{}", .{ | |
| 285 | 281 | bytes[0], |
| 286 | 282 | bytes[1], |
| 287 | 283 | bytes[2], |
| 288 | 284 | bytes[3], |
| 289 | 285 | port, |
| 290 | ); | |
| 286 | }); | |
| 291 | 287 | }, |
| 292 | 288 | os.AF_INET6 => { |
| 293 | 289 | const port = mem.bigToNative(u16, self.in6.port); |
| 294 | 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( | |
| 296 | context, | |
| 297 | Errors, | |
| 298 | output, | |
| 299 | "[::ffff:{}.{}.{}.{}]:{}", | |
| 291 | try std.fmt.format(context, Errors, output, "[::ffff:{}.{}.{}.{}]:{}", .{ | |
| 300 | 292 | self.in6.addr[12], |
| 301 | 293 | self.in6.addr[13], |
| 302 | 294 | self.in6.addr[14], |
| 303 | 295 | self.in6.addr[15], |
| 304 | 296 | port, |
| 305 | ); | |
| 297 | }); | |
| 306 | 298 | return; |
| 307 | 299 | } |
| 308 | 300 | const big_endian_parts = @ptrCast(*align(1) const [8]u16, &self.in6.addr); |
| ... | ... | @@ -327,19 +319,19 @@ pub const Address = extern union { |
| 327 | 319 | } |
| 328 | 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 | 323 | if (i != native_endian_parts.len - 1) { |
| 332 | 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 | 329 | os.AF_UNIX => { |
| 338 | 330 | if (!has_unix_sockets) { |
| 339 | 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 | 336 | else => unreachable, |
| 345 | 337 | } |
lib/std/net/test.zig+3-3| ... | ... | @@ -29,7 +29,7 @@ test "parse and render IPv6 addresses" { |
| 29 | 29 | }; |
| 30 | 30 | for (ips) |ip, i| { |
| 31 | 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 | 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 | 51 | "127.0.0.1", |
| 52 | 52 | }) |ip| { |
| 53 | 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 | 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 | 118 | var client = try server.accept(); |
| 119 | 119 | |
| 120 | 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 | 2603 | defer close(fd); |
| 2604 | 2604 | |
| 2605 | 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 | 2608 | return readlinkC(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer); |
| 2609 | 2609 | } |
| ... | ... | @@ -2832,7 +2832,7 @@ pub const UnexpectedError = error{ |
| 2832 | 2832 | /// and you get an unexpected error. |
| 2833 | 2833 | pub fn unexpectedErrno(err: usize) UnexpectedError { |
| 2834 | 2834 | if (unexpected_error_tracing) { |
| 2835 | std.debug.warn("unexpected errno: {}\n", err); | |
| 2835 | std.debug.warn("unexpected errno: {}\n", .{err}); | |
| 2836 | 2836 | std.debug.dumpCurrentStackTrace(null); |
| 2837 | 2837 | } |
| 2838 | 2838 | return error.Unexpected; |
lib/std/os/windows.zig+2-2| ... | ... | @@ -1039,7 +1039,7 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError { |
| 1039 | 1039 | var buf_u8: [614]u8 = undefined; |
| 1040 | 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 | 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 | 1043 | std.debug.dumpCurrentStackTrace(null); |
| 1044 | 1044 | } |
| 1045 | 1045 | return error.Unexpected; |
| ... | ... | @@ -1053,7 +1053,7 @@ pub fn unexpectedWSAError(err: c_int) std.os.UnexpectedError { |
| 1053 | 1053 | /// and you get an unexpected status. |
| 1054 | 1054 | pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError { |
| 1055 | 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 | 1057 | std.debug.dumpCurrentStackTrace(null); |
| 1058 | 1058 | } |
| 1059 | 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 | 199 | } |
| 200 | 200 | |
| 201 | 201 | fn dump(self: *Self) void { |
| 202 | warn("{{ "); | |
| 203 | warn("items: "); | |
| 202 | warn("{{ ", .{}); | |
| 203 | warn("items: ", .{}); | |
| 204 | 204 | for (self.items) |e, i| { |
| 205 | 205 | if (i >= self.len) break; |
| 206 | warn("{}, ", e); | |
| 206 | warn("{}, ", .{e}); | |
| 207 | 207 | } |
| 208 | warn("array: "); | |
| 208 | warn("array: ", .{}); | |
| 209 | 209 | for (self.items) |e, i| { |
| 210 | warn("{}, ", e); | |
| 210 | warn("{}, ", .{e}); | |
| 211 | 211 | } |
| 212 | warn("len: {} ", self.len); | |
| 213 | warn("capacity: {}", self.capacity()); | |
| 214 | warn(" }}\n"); | |
| 212 | warn("len: {} ", .{self.len}); | |
| 213 | warn("capacity: {}", .{self.capacity()}); | |
| 214 | warn(" }}\n", .{}); | |
| 215 | 215 | } |
| 216 | 216 | }; |
| 217 | 217 | } |
lib/std/progress.zig+11-11| ... | ... | @@ -130,11 +130,11 @@ pub const Progress = struct { |
| 130 | 130 | var end: usize = 0; |
| 131 | 131 | if (self.columns_written > 0) { |
| 132 | 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 | 134 | self.columns_written = 0; |
| 135 | 135 | |
| 136 | 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 | 140 | if (!self.done) { |
| ... | ... | @@ -142,28 +142,28 @@ pub const Progress = struct { |
| 142 | 142 | var maybe_node: ?*Node = &self.root; |
| 143 | 143 | while (maybe_node) |node| { |
| 144 | 144 | if (need_ellipse) { |
| 145 | self.bufWrite(&end, "..."); | |
| 145 | self.bufWrite(&end, "...", .{}); | |
| 146 | 146 | } |
| 147 | 147 | need_ellipse = false; |
| 148 | 148 | if (node.name.len != 0 or node.estimated_total_items != null) { |
| 149 | 149 | if (node.name.len != 0) { |
| 150 | self.bufWrite(&end, "{}", node.name); | |
| 150 | self.bufWrite(&end, "{}", .{node.name}); | |
| 151 | 151 | need_ellipse = true; |
| 152 | 152 | } |
| 153 | 153 | if (node.estimated_total_items) |total| { |
| 154 | if (need_ellipse) self.bufWrite(&end, " "); | |
| 155 | self.bufWrite(&end, "[{}/{}] ", node.completed_items + 1, total); | |
| 154 | if (need_ellipse) self.bufWrite(&end, " ", .{}); | |
| 155 | self.bufWrite(&end, "[{}/{}] ", .{ node.completed_items + 1, total }); | |
| 156 | 156 | need_ellipse = false; |
| 157 | 157 | } else if (node.completed_items != 0) { |
| 158 | if (need_ellipse) self.bufWrite(&end, " "); | |
| 159 | self.bufWrite(&end, "[{}] ", node.completed_items + 1); | |
| 158 | if (need_ellipse) self.bufWrite(&end, " ", .{}); | |
| 159 | self.bufWrite(&end, "[{}] ", .{node.completed_items + 1}); | |
| 160 | 160 | need_ellipse = false; |
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | maybe_node = node.recently_updated_child; |
| 164 | 164 | } |
| 165 | 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 | 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 | 178 | const file = self.terminal orelse return; |
| 179 | 179 | self.refresh(); |
| 180 | 180 | file.outStream().stream.print(format, args) catch { |
| ... | ... | @@ -184,7 +184,7 @@ pub const Progress = struct { |
| 184 | 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 | 188 | if (std.fmt.bufPrint(self.output_buffer[end.*..], format, args)) |written| { |
| 189 | 189 | const amt = written.len; |
| 190 | 190 | end.* += amt; |
lib/std/special/build_runner.zig+18-15| ... | ... | @@ -26,15 +26,15 @@ pub fn main() !void { |
| 26 | 26 | _ = arg_it.skip(); |
| 27 | 27 | |
| 28 | 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 | 30 | return error.InvalidArgs; |
| 31 | 31 | }); |
| 32 | 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 | 34 | return error.InvalidArgs; |
| 35 | 35 | }); |
| 36 | 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 | 38 | return error.InvalidArgs; |
| 39 | 39 | }); |
| 40 | 40 | |
| ... | ... | @@ -51,7 +51,7 @@ pub fn main() !void { |
| 51 | 51 | if (mem.startsWith(u8, arg, "-D")) { |
| 52 | 52 | const option_contents = arg[2..]; |
| 53 | 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 | 55 | return usageAndErr(builder, false, stderr_stream); |
| 56 | 56 | } |
| 57 | 57 | if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| { |
| ... | ... | @@ -70,18 +70,18 @@ pub fn main() !void { |
| 70 | 70 | return usage(builder, false, stdout_stream); |
| 71 | 71 | } else if (mem.eql(u8, arg, "--prefix")) { |
| 72 | 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 | 74 | return usageAndErr(builder, false, stderr_stream); |
| 75 | 75 | }); |
| 76 | 76 | } else if (mem.eql(u8, arg, "--search-prefix")) { |
| 77 | 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 | 79 | return usageAndErr(builder, false, stderr_stream); |
| 80 | 80 | }); |
| 81 | 81 | builder.addSearchPrefix(search_prefix); |
| 82 | 82 | } else if (mem.eql(u8, arg, "--override-lib-dir")) { |
| 83 | 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 | 85 | return usageAndErr(builder, false, stderr_stream); |
| 86 | 86 | }); |
| 87 | 87 | } else if (mem.eql(u8, arg, "--verbose-tokenize")) { |
| ... | ... | @@ -99,7 +99,7 @@ pub fn main() !void { |
| 99 | 99 | } else if (mem.eql(u8, arg, "--verbose-cc")) { |
| 100 | 100 | builder.verbose_cc = true; |
| 101 | 101 | } else { |
| 102 | warn("Unrecognized argument: {}\n\n", arg); | |
| 102 | warn("Unrecognized argument: {}\n\n", .{arg}); | |
| 103 | 103 | return usageAndErr(builder, false, stderr_stream); |
| 104 | 104 | } |
| 105 | 105 | } else { |
| ... | ... | @@ -145,15 +145,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void { |
| 145 | 145 | \\ |
| 146 | 146 | \\Steps: |
| 147 | 147 | \\ |
| 148 | , builder.zig_exe); | |
| 148 | , .{builder.zig_exe}); | |
| 149 | 149 | |
| 150 | 150 | const allocator = builder.allocator; |
| 151 | 151 | for (builder.top_level_steps.toSliceConst()) |top_level_step| { |
| 152 | 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 | 154 | else |
| 155 | 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 | 159 | try out_stream.write( |
| ... | ... | @@ -169,12 +169,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void { |
| 169 | 169 | ); |
| 170 | 170 | |
| 171 | 171 | if (builder.available_options_list.len == 0) { |
| 172 | try out_stream.print(" (none)\n"); | |
| 172 | try out_stream.print(" (none)\n", .{}); | |
| 173 | 173 | } else { |
| 174 | 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 | 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 | 207 | |
| 205 | 208 | fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 { |
| 206 | 209 | return arg catch |err| { |
| 207 | warn("Unable to parse command line: {}\n", err); | |
| 210 | warn("Unable to parse command line: {}\n", .{err}); | |
| 208 | 211 | return err; |
| 209 | 212 | }; |
| 210 | 213 | } |
lib/std/special/init-exe/src/main.zig+1-1| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | |
| 3 | 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 | 217 | if (std.event.Loop.instance) |loop| { |
| 218 | 218 | if (!@hasDecl(root, "event_loop")) { |
| 219 | 219 | loop.init() catch |err| { |
| 220 | std.debug.warn("error: {}\n", @errorName(err)); | |
| 220 | std.debug.warn("error: {}\n", .{@errorName(err)}); | |
| 221 | 221 | if (@errorReturnTrace()) |trace| { |
| 222 | 222 | std.debug.dumpStackTrace(trace.*); |
| 223 | 223 | } |
| ... | ... | @@ -264,7 +264,7 @@ fn callMain() u8 { |
| 264 | 264 | }, |
| 265 | 265 | .ErrorUnion => { |
| 266 | 266 | const result = root.main() catch |err| { |
| 267 | std.debug.warn("error: {}\n", @errorName(err)); | |
| 267 | std.debug.warn("error: {}\n", .{@errorName(err)}); | |
| 268 | 268 | if (@errorReturnTrace()) |trace| { |
| 269 | 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 | 16 | var test_node = root_node.start(test_fn.name, null); |
| 17 | 17 | test_node.activate(); |
| 18 | 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 | 20 | if (test_fn.func()) |_| { |
| 21 | 21 | ok_count += 1; |
| 22 | 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 | 24 | } else |err| switch (err) { |
| 25 | 25 | error.SkipZigTest => { |
| 26 | 26 | skip_count += 1; |
| 27 | 27 | test_node.end(); |
| 28 | progress.log("{}...SKIP\n", test_fn.name); | |
| 29 | if (progress.terminal == null) std.debug.warn("SKIP\n"); | |
| 28 | progress.log("{}...SKIP\n", .{test_fn.name}); | |
| 29 | if (progress.terminal == null) std.debug.warn("SKIP\n", .{}); | |
| 30 | 30 | }, |
| 31 | 31 | else => { |
| 32 | progress.log(""); | |
| 32 | progress.log("", .{}); | |
| 33 | 33 | return err; |
| 34 | 34 | }, |
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | root_node.end(); |
| 38 | 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 | 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 | 321 | pub const stack_align = 16; |
| 322 | 322 | |
| 323 | 323 | pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 { |
| 324 | return std.fmt.allocPrint( | |
| 325 | allocator, | |
| 326 | "{}{}-{}-{}", | |
| 324 | return std.fmt.allocPrint(allocator, "{}{}-{}-{}", .{ | |
| 327 | 325 | @tagName(self.getArch()), |
| 328 | 326 | Target.archSubArchName(self.getArch()), |
| 329 | 327 | @tagName(self.getOs()), |
| 330 | 328 | @tagName(self.getAbi()), |
| 331 | ); | |
| 329 | }); | |
| 332 | 330 | } |
| 333 | 331 | |
| 334 | 332 | /// Returned slice must be freed by the caller. |
| ... | ... | @@ -372,23 +370,19 @@ pub const Target = union(enum) { |
| 372 | 370 | } |
| 373 | 371 | |
| 374 | 372 | pub fn zigTripleNoSubArch(self: Target, allocator: *mem.Allocator) ![]u8 { |
| 375 | return std.fmt.allocPrint( | |
| 376 | allocator, | |
| 377 | "{}-{}-{}", | |
| 373 | return std.fmt.allocPrint(allocator, "{}-{}-{}", .{ | |
| 378 | 374 | @tagName(self.getArch()), |
| 379 | 375 | @tagName(self.getOs()), |
| 380 | 376 | @tagName(self.getAbi()), |
| 381 | ); | |
| 377 | }); | |
| 382 | 378 | } |
| 383 | 379 | |
| 384 | 380 | pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 { |
| 385 | return std.fmt.allocPrint( | |
| 386 | allocator, | |
| 387 | "{}-{}-{}", | |
| 381 | return std.fmt.allocPrint(allocator, "{}-{}-{}", .{ | |
| 388 | 382 | @tagName(self.getArch()), |
| 389 | 383 | @tagName(self.getOs()), |
| 390 | 384 | @tagName(self.getAbi()), |
| 391 | ); | |
| 385 | }); | |
| 392 | 386 | } |
| 393 | 387 | |
| 394 | 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 | 8 | if (actual_error_union) |actual_payload| { |
| 9 | 9 | // TODO remove workaround here for https://github.com/ziglang/zig/issues/557 |
| 10 | 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 | 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 | 18 | } else |actual_error| { |
| 16 | 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 | 57 | .ErrorSet, |
| 52 | 58 | => { |
| 53 | 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 | 68 | builtin.TypeInfo.Pointer.Size.C, |
| 63 | 69 | => { |
| 64 | 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 | 75 | builtin.TypeInfo.Pointer.Size.Slice => { |
| 70 | 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 | 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 | 112 | } |
| 107 | 113 | |
| 108 | 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 | 116 | // including all possible values. |
| 111 | 117 | unreachable; |
| 112 | 118 | }, |
| ... | ... | @@ -116,11 +122,11 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { |
| 116 | 122 | if (actual) |actual_payload| { |
| 117 | 123 | expectEqual(expected_payload, actual_payload); |
| 118 | 124 | } else { |
| 119 | std.debug.panic("expected {}, found null", expected_payload); | |
| 125 | std.debug.panic("expected {}, found null", .{expected_payload}); | |
| 120 | 126 | } |
| 121 | 127 | } else { |
| 122 | 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 | 136 | if (actual) |actual_payload| { |
| 131 | 137 | expectEqual(expected_payload, actual_payload); |
| 132 | 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 | 141 | } else |expected_err| { |
| 136 | 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 | 144 | } else |actual_err| { |
| 139 | 145 | expectEqual(expected_err, actual_err); |
| 140 | 146 | } |
| ... | ... | @@ -143,15 +149,14 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { |
| 143 | 149 | } |
| 144 | 150 | } |
| 145 | 151 | |
| 146 | test "expectEqual.union(enum)" | |
| 147 | { | |
| 152 | test "expectEqual.union(enum)" { | |
| 148 | 153 | const T = union(enum) { |
| 149 | 154 | a: i32, |
| 150 | 155 | b: f32, |
| 151 | 156 | }; |
| 152 | 157 | |
| 153 | const a10 = T { .a = 10 }; | |
| 154 | const a20 = T { .a = 20 }; | |
| 158 | const a10 = T{ .a = 10 }; | |
| 159 | const a20 = T{ .a = 20 }; | |
| 155 | 160 | |
| 156 | 161 | expectEqual(a10, a10); |
| 157 | 162 | } |
| ... | ... | @@ -165,12 +170,12 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const |
| 165 | 170 | // If the child type is u8 and no weird bytes, we could print it as strings |
| 166 | 171 | // Even for the length difference, it would be useful to see the values of the slices probably. |
| 167 | 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 | 175 | var i: usize = 0; |
| 171 | 176 | while (i < expected.len) : (i += 1) { |
| 172 | 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 | 170 | /// ``` |
| 171 | 171 | /// var utf8 = (try std.unicode.Utf8View.init("hi there")).iterator(); |
| 172 | 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 | 176 | pub const Utf8View = struct { |
lib/std/unicode/throughput_test.zig+6-2| ... | ... | @@ -24,8 +24,12 @@ pub fn main() !void { |
| 24 | 24 | const elapsed_ns_better = timer.lap(); |
| 25 | 25 | @fence(.SeqCst); |
| 26 | 26 | |
| 27 | std.debug.warn("original utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", elapsed_ns_orig, elapsed_ns_orig / 1000000); | |
| 28 | std.debug.warn("new utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", elapsed_ns_better, elapsed_ns_better / 1000000); | |
| 27 | std.debug.warn("original utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", .{ | |
| 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 | 33 | asm volatile ("nop" |
| 30 | 34 | : |
| 31 | 35 | : [a] "r" (&buffer1), |
lib/std/valgrind.zig-14| ... | ... | @@ -114,20 +114,6 @@ pub fn innerThreads(qzz: [*]u8) void { |
| 114 | 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 | 117 | pub fn nonSIMDCall0(func: fn (usize) usize) usize { |
| 132 | 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 | 301 | node: *Node, |
| 302 | 302 | |
| 303 | 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 | 311 | node: *Node, |
| 310 | 312 | |
| 311 | 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 | 324 | const found_token = tokens.at(self.token); |
| 322 | 325 | switch (found_token.id) { |
| 323 | 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 | 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 | 332 | else => { |
| 330 | 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 | 343 | |
| 341 | 344 | pub fn render(self: *const ExpectedCommaOrEnd, tokens: *Tree.TokenList, stream: var) !void { |
| 342 | 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 | 358 | |
| 353 | 359 | pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void { |
| 354 | 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 | 569 | { |
| 564 | 570 | var i: usize = 0; |
| 565 | 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 | 577 | var child_i: usize = 0; |
| 572 | 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 | 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 | 645 | test "zig fmt: enum decl with no trailing comma" { |
| 655 | 646 | try testTransform( |
| 656 | 647 | \\const StrLitKind = enum {Normal, C}; |
| ... | ... | @@ -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 | 1744 | test "zig fmt: var type" { |
| 1761 | 1745 | try testCanonical( |
| 1762 | 1746 | \\fn print(args: var) var {} |
| ... | ... | @@ -2705,9 +2689,9 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b |
| 2705 | 2689 | while (error_it.next()) |parse_error| { |
| 2706 | 2690 | const token = tree.tokens.at(parse_error.loc()); |
| 2707 | 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 | 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 | 2696 | var i: usize = 0; |
| 2713 | 2697 | while (i < loc.column) : (i += 1) { |
| ... | ... | @@ -2743,16 +2727,16 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { |
| 2743 | 2727 | var anything_changed: bool = undefined; |
| 2744 | 2728 | const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed); |
| 2745 | 2729 | if (!mem.eql(u8, result_source, expected_source)) { |
| 2746 | warn("\n====== expected this output: =========\n"); | |
| 2747 | warn("{}", expected_source); | |
| 2748 | warn("\n======== instead found this: =========\n"); | |
| 2749 | warn("{}", result_source); | |
| 2750 | warn("\n======================================\n"); | |
| 2730 | warn("\n====== expected this output: =========\n", .{}); | |
| 2731 | warn("{}", .{expected_source}); | |
| 2732 | warn("\n======== instead found this: =========\n", .{}); | |
| 2733 | warn("{}", .{result_source}); | |
| 2734 | warn("\n======================================\n", .{}); | |
| 2751 | 2735 | return error.TestFailed; |
| 2752 | 2736 | } |
| 2753 | 2737 | const changes_expected = source.ptr != expected_source.ptr; |
| 2754 | 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 | 2740 | return error.TestFailed; |
| 2757 | 2741 | } |
| 2758 | 2742 | std.testing.expect(anything_changed == changes_expected); |
| ... | ... | @@ -2772,12 +2756,14 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { |
| 2772 | 2756 | if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) { |
| 2773 | 2757 | warn( |
| 2774 | 2758 | "\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n", |
| 2775 | fail_index, | |
| 2776 | needed_alloc_count, | |
| 2777 | failing_allocator.allocated_bytes, | |
| 2778 | failing_allocator.freed_bytes, | |
| 2779 | failing_allocator.allocations, | |
| 2780 | failing_allocator.deallocations, | |
| 2759 | .{ | |
| 2760 | fail_index, | |
| 2761 | needed_alloc_count, | |
| 2762 | failing_allocator.allocated_bytes, | |
| 2763 | failing_allocator.freed_bytes, | |
| 2764 | failing_allocator.allocations, | |
| 2765 | failing_allocator.deallocations, | |
| 2766 | }, | |
| 2781 | 2767 | ); |
| 2782 | 2768 | return error.MemoryLeakDetected; |
| 2783 | 2769 | } |
lib/std/zig/render.zig+3-3| ... | ... | @@ -76,7 +76,7 @@ fn renderRoot( |
| 76 | 76 | // render all the line comments at the beginning of the file |
| 77 | 77 | while (tok_it.next()) |token| { |
| 78 | 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 | 80 | if (tok_it.peek()) |next_token| { |
| 81 | 81 | const loc = tree.tokenLocationPtr(token.end, next_token); |
| 82 | 82 | if (loc.line >= 2) { |
| ... | ... | @@ -1226,7 +1226,7 @@ fn renderExpression( |
| 1226 | 1226 | |
| 1227 | 1227 | var skip_first_indent = true; |
| 1228 | 1228 | if (tree.tokens.at(multiline_str_literal.firstToken() - 1).id != .LineComment) { |
| 1229 | try stream.print("\n"); | |
| 1229 | try stream.print("\n", .{}); | |
| 1230 | 1230 | skip_first_indent = false; |
| 1231 | 1231 | } |
| 1232 | 1232 | |
| ... | ... | @@ -2129,7 +2129,7 @@ fn renderTokenOffset( |
| 2129 | 2129 | |
| 2130 | 2130 | var loc = tree.tokenLocationPtr(token.end, next_token); |
| 2131 | 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 | 2133 | offset = 2; |
| 2134 | 2134 | token = next_token; |
| 2135 | 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 | 330 | |
| 331 | 331 | /// For debugging purposes |
| 332 | 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 | 336 | pub fn init(buffer: []const u8) Tokenizer { |
| ... | ... | @@ -1576,7 +1576,7 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void { |
| 1576 | 1576 | for (expected_tokens) |expected_token_id| { |
| 1577 | 1577 | const token = tokenizer.next(); |
| 1578 | 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 | 1582 | const last_token = tokenizer.next(); |
src-self-hosted/arg.zig+6-6| ... | ... | @@ -98,15 +98,15 @@ pub const Args = struct { |
| 98 | 98 | const flag_args = readFlagArguments(allocator, args, flag.required, flag.allowed_set, &i) catch |err| { |
| 99 | 99 | switch (err) { |
| 100 | 100 | error.ArgumentNotInAllowedSet => { |
| 101 | std.debug.warn("argument '{}' is invalid for flag '{}'\n", args[i], arg); | |
| 102 | std.debug.warn("allowed options are "); | |
| 101 | std.debug.warn("argument '{}' is invalid for flag '{}'\n", .{ args[i], arg }); | |
| 102 | std.debug.warn("allowed options are ", .{}); | |
| 103 | 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 | 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 | 111 | else => {}, |
| 112 | 112 | } |
| ... | ... | @@ -134,7 +134,7 @@ pub const Args = struct { |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 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 | 138 | return error.UnknownFlag; |
| 139 | 139 | } else { |
| 140 | 140 | try parsed.positionals.append(arg); |
src-self-hosted/dep_tokenizer.zig+15-15| ... | ... | @@ -38,7 +38,7 @@ pub const Tokenizer = struct { |
| 38 | 38 | }, |
| 39 | 39 | .target => |*target| switch (char) { |
| 40 | 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 | 44 | self.state = State{ .target_dollar_sign = target.* }; |
| ... | ... | @@ -59,7 +59,7 @@ pub const Tokenizer = struct { |
| 59 | 59 | }, |
| 60 | 60 | .target_reverse_solidus => |*target| switch (char) { |
| 61 | 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 | 65 | try target.appendByte(char); |
| ... | ... | @@ -84,7 +84,7 @@ pub const Tokenizer = struct { |
| 84 | 84 | break; // advance |
| 85 | 85 | }, |
| 86 | 86 | else => { |
| 87 | return self.errorIllegalChar(self.index, char, "expecting '$'"); | |
| 87 | return self.errorIllegalChar(self.index, char, "expecting '$'", .{}); | |
| 88 | 88 | }, |
| 89 | 89 | }, |
| 90 | 90 | .target_colon => |*target| switch (char) { |
| ... | ... | @@ -161,7 +161,7 @@ pub const Tokenizer = struct { |
| 161 | 161 | break; // advance |
| 162 | 162 | }, |
| 163 | 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 | 167 | .rhs_continuation_linefeed => switch (char) { |
| ... | ... | @@ -170,7 +170,7 @@ pub const Tokenizer = struct { |
| 170 | 170 | break; // advance |
| 171 | 171 | }, |
| 172 | 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 | 176 | .prereq_quote => |*prereq| switch (char) { |
| ... | ... | @@ -231,7 +231,7 @@ pub const Tokenizer = struct { |
| 231 | 231 | return Token{ .id = .prereq, .bytes = bytes }; |
| 232 | 232 | }, |
| 233 | 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 | 249 | .rhs_continuation_linefeed, |
| 250 | 250 | => {}, |
| 251 | 251 | .target => |target| { |
| 252 | return self.errorPosition(idx, target.toSlice(), "incomplete target"); | |
| 252 | return self.errorPosition(idx, target.toSlice(), "incomplete target", .{}); | |
| 253 | 253 | }, |
| 254 | 254 | .target_reverse_solidus, |
| 255 | 255 | .target_dollar_sign, |
| 256 | 256 | => { |
| 257 | 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 | 260 | .target_colon => |target| { |
| 261 | 261 | const bytes = target.toSlice(); |
| ... | ... | @@ -278,7 +278,7 @@ pub const Tokenizer = struct { |
| 278 | 278 | self.state = State{ .lhs = {} }; |
| 279 | 279 | }, |
| 280 | 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 | 283 | .prereq => |prereq| { |
| 284 | 284 | const bytes = prereq.toSlice(); |
| ... | ... | @@ -299,29 +299,29 @@ pub const Tokenizer = struct { |
| 299 | 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 | 303 | self.error_text = (try std.Buffer.allocPrint(&self.arena.allocator, fmt, args)).toSlice(); |
| 304 | 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 | 308 | var buffer = try std.Buffer.initSize(&self.arena.allocator, 0); |
| 309 | 309 | std.fmt.format(&buffer, anyerror, std.Buffer.append, fmt, args) catch {}; |
| 310 | 310 | try buffer.append(" '"); |
| 311 | 311 | var out = makeOutput(std.Buffer.append, &buffer); |
| 312 | 312 | try printCharValues(&out, bytes); |
| 313 | 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 | 315 | self.error_text = buffer.toSlice(); |
| 316 | 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 | 320 | var buffer = try std.Buffer.initSize(&self.arena.allocator, 0); |
| 321 | 321 | try buffer.append("illegal char "); |
| 322 | 322 | var out = makeOutput(std.Buffer.append, &buffer); |
| 323 | 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 | 325 | if (fmt.len != 0) std.fmt.format(&buffer, anyerror, std.Buffer.append, ": " ++ fmt, args) catch {}; |
| 326 | 326 | self.error_text = buffer.toSlice(); |
| 327 | 327 | return Error.InvalidInput; |
| ... | ... | @@ -998,7 +998,7 @@ fn printCharValues(out: var, bytes: []const u8) !void { |
| 998 | 998 | |
| 999 | 999 | fn printUnderstandableChar(out: var, char: u8) !void { |
| 1000 | 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 | 1002 | } else { |
| 1003 | 1003 | try out.write("'"); |
| 1004 | 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 | 205 | defer allocator.free(source_code); |
| 206 | 206 | |
| 207 | 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 | 209 | process.exit(1); |
| 210 | 210 | }; |
| 211 | 211 | defer tree.deinit(); |
| ... | ... | @@ -294,7 +294,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void |
| 294 | 294 | }, |
| 295 | 295 | else => { |
| 296 | 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 | 298 | fmt.any_error = true; |
| 299 | 299 | return; |
| 300 | 300 | }, |
| ... | ... | @@ -302,7 +302,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void |
| 302 | 302 | defer fmt.allocator.free(source_code); |
| 303 | 303 | |
| 304 | 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 | 306 | fmt.any_error = true; |
| 307 | 307 | return; |
| 308 | 308 | }; |
| ... | ... | @@ -320,7 +320,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void |
| 320 | 320 | if (check_mode) { |
| 321 | 321 | const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, tree); |
| 322 | 322 | if (anything_changed) { |
| 323 | try stderr.print("{}\n", file_path); | |
| 323 | try stderr.print("{}\n", .{file_path}); | |
| 324 | 324 | fmt.any_error = true; |
| 325 | 325 | } |
| 326 | 326 | } else { |
| ... | ... | @@ -329,7 +329,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void |
| 329 | 329 | |
| 330 | 330 | const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree); |
| 331 | 331 | if (anything_changed) { |
| 332 | try stderr.print("{}\n", file_path); | |
| 332 | try stderr.print("{}\n", .{file_path}); | |
| 333 | 333 | try baf.finish(); |
| 334 | 334 | } |
| 335 | 335 | } |
| ... | ... | @@ -374,7 +374,7 @@ fn printErrMsgToFile( |
| 374 | 374 | const text = text_buf.toOwnedSlice(); |
| 375 | 375 | |
| 376 | 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 | 379 | if (!color_on) return; |
| 380 | 380 |
src-self-hosted/translate_c.zig+49-30| ... | ... | @@ -125,7 +125,7 @@ const Context = struct { |
| 125 | 125 | |
| 126 | 126 | const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc); |
| 127 | 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 | 228 | return visitFnDecl(c, @ptrCast(*const ZigClangFunctionDecl, decl)); |
| 229 | 229 | }, |
| 230 | 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 | 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 | 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 | 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 | 242 | else => { |
| 243 | 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 | 264 | .is_export = switch (storage_class) { |
| 265 | 265 | .None => has_body and c.mode != .import, |
| 266 | 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 | 268 | .Auto => unreachable, // Not legal on functions |
| 269 | 269 | .Register => unreachable, // Not legal on functions |
| 270 | 270 | }, |
| ... | ... | @@ -274,7 +274,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 274 | 274 | const fn_proto_type = @ptrCast(*const ZigClangFunctionProtoType, fn_type); |
| 275 | 275 | break :blk transFnProto(rp, fn_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) { |
| 276 | 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 | 279 | error.OutOfMemory => |e| return e, |
| 280 | 280 | }; |
| ... | ... | @@ -283,7 +283,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 283 | 283 | const fn_no_proto_type = @ptrCast(*const ZigClangFunctionType, fn_type); |
| 284 | 284 | break :blk transFnNoProto(rp, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) { |
| 285 | 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 | 288 | error.OutOfMemory => |e| return e, |
| 289 | 289 | }; |
| ... | ... | @@ -302,7 +302,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 302 | 302 | error.OutOfMemory => |e| return e, |
| 303 | 303 | error.UnsupportedTranslation, |
| 304 | 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 | 307 | assert(result.node.id == ast.Node.Id.Block); |
| 308 | 308 | proto_node.body_node = result.node; |
| ... | ... | @@ -344,7 +344,7 @@ fn transStmt( |
| 344 | 344 | error.UnsupportedTranslation, |
| 345 | 345 | ZigClangStmt_getBeginLoc(stmt), |
| 346 | 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 | 364 | error.UnsupportedTranslation, |
| 365 | 365 | ZigClangBinaryOperator_getBeginLoc(stmt), |
| 366 | 366 | "TODO: handle more C binary operators: {}", |
| 367 | op, | |
| 367 | .{op}, | |
| 368 | 368 | ), |
| 369 | 369 | .Assign => return TransResult{ |
| 370 | 370 | .node = &(try transCreateNodeAssign(rp, scope, result_used, ZigClangBinaryOperator_getLHS(stmt), ZigClangBinaryOperator_getRHS(stmt))).base, |
| ... | ... | @@ -415,7 +415,7 @@ fn transBinaryOperator( |
| 415 | 415 | error.UnsupportedTranslation, |
| 416 | 416 | ZigClangBinaryOperator_getBeginLoc(stmt), |
| 417 | 417 | "TODO: handle more C binary operators: {}", |
| 418 | op, | |
| 418 | .{op}, | |
| 419 | 419 | ), |
| 420 | 420 | .MulAssign, |
| 421 | 421 | .DivAssign, |
| ... | ... | @@ -567,7 +567,7 @@ fn transDeclStmt(rp: RestorePoint, parent_scope: *Scope, stmt: *const ZigClangDe |
| 567 | 567 | error.UnsupportedTranslation, |
| 568 | 568 | ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)), |
| 569 | 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 | 636 | error.UnsupportedTranslation, |
| 637 | 637 | ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, expr)), |
| 638 | 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 | 650 | var eval_result: ZigClangExprEvalResult = undefined; |
| 651 | 651 | if (!ZigClangIntegerLiteral_EvaluateAsInt(expr, &eval_result, rp.c.clang_context)) { |
| 652 | 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 | 655 | const node = try transCreateNodeAPInt(rp.c, ZigClangAPValue_getInt(&eval_result.Val)); |
| 656 | 656 | const res = TransResult{ |
| ... | ... | @@ -719,7 +719,7 @@ fn transStringLiteral( |
| 719 | 719 | error.UnsupportedTranslation, |
| 720 | 720 | ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)), |
| 721 | 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 | 751 | '\n' => return "\\n"[0..], |
| 752 | 752 | '\r' => return "\\r"[0..], |
| 753 | 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 | 756 | std.mem.copy(u8, char_buf, escaped); |
| 757 | 757 | return char_buf[0..escaped.len]; |
| ... | ... | @@ -1016,7 +1016,13 @@ fn transCreateNodeAssign( |
| 1016 | 1016 | // zig: lhs = _tmp; |
| 1017 | 1017 | // zig: break :x _tmp |
| 1018 | 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 | 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 | 1217 | .Float128 => return appendIdentifier(rp.c, "f128"), |
| 1212 | 1218 | .Float16 => return appendIdentifier(rp.c, "f16"), |
| 1213 | 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 | 1223 | .FunctionProto => { |
| ... | ... | @@ -1253,7 +1259,7 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour |
| 1253 | 1259 | }, |
| 1254 | 1260 | else => { |
| 1255 | 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 | 1281 | switch (clang_cc) { |
| 1276 | 1282 | .C => return CallingConvention.C, |
| 1277 | 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 | 1304 | const param_count: usize = ZigClangFunctionProtoType_getNumParams(fn_proto_ty); |
| 1293 | 1305 | var i: usize = 0; |
| 1294 | 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 | 1316 | return finishTransFnProto(rp, fn_ty, source_loc, fn_decl_context, is_var_args, cc, is_pub); |
| ... | ... | @@ -1350,7 +1368,7 @@ fn finishTransFnProto( |
| 1350 | 1368 | } else { |
| 1351 | 1369 | break :blk transQualType(rp, return_qt, source_loc) catch |err| switch (err) { |
| 1352 | 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 | 1372 | return err; |
| 1355 | 1373 | }, |
| 1356 | 1374 | error.OutOfMemory => |e| return e, |
| ... | ... | @@ -1397,18 +1415,19 @@ fn revertAndWarn( |
| 1397 | 1415 | err: var, |
| 1398 | 1416 | source_loc: ZigClangSourceLocation, |
| 1399 | 1417 | comptime format: []const u8, |
| 1400 | args: ..., | |
| 1418 | args: var, | |
| 1401 | 1419 | ) (@typeOf(err) || error{OutOfMemory}) { |
| 1402 | 1420 | rp.activate(); |
| 1403 | 1421 | try emitWarning(rp.c, source_loc, format, args); |
| 1404 | 1422 | return err; |
| 1405 | 1423 | } |
| 1406 | 1424 | |
| 1407 | fn emitWarning(c: *Context, loc: ZigClangSourceLocation, comptime format: []const u8, args: ...) !void { | |
| 1408 | _ = try appendTokenFmt(c, .LineComment, "// {}: warning: " ++ format, c.locStr(loc), args); | |
| 1425 | fn emitWarning(c: *Context, loc: ZigClangSourceLocation, comptime format: []const u8, args: var) !void { | |
| 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 | 1431 | // const name = @compileError(msg); |
| 1413 | 1432 | const const_tok = try appendToken(c, .Keyword_const, "const"); |
| 1414 | 1433 | const name_tok = try appendToken(c, .Identifier, name); |
| ... | ... | @@ -1456,10 +1475,10 @@ fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime |
| 1456 | 1475 | } |
| 1457 | 1476 | |
| 1458 | 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 | 1482 | const S = struct { |
| 1464 | 1483 | fn callback(context: *Context, bytes: []const u8) error{OutOfMemory}!void { |
| 1465 | 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 | 17025 | { |
| 17026 | 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 | 17029 | IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, |
| 17030 | 17030 | value, force_runtime, non_null_comptime, allow_discard); |
| 17031 | 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 | 17038 | } |
| 17039 | 17039 | |
| 17040 | 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 | 17042 | // Now it's time to add the field to the struct type. |
| 17043 | 17043 | uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count; |
| 17044 | 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 | 18077 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 18078 | 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 | 18085 | ir_reset_result(call_result_loc); |
| 18082 | 18086 | result_loc = nullptr; |
| 18083 | 18087 | } |
| ... | ... | @@ -18240,7 +18244,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18240 | 18244 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 18241 | 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 | 18252 | ir_reset_result(call_result_loc); |
| 18245 | 18253 | result_loc = nullptr; |
| 18246 | 18254 | } |
test/cli.zig+11-11| ... | ... | @@ -19,11 +19,11 @@ pub fn main() !void { |
| 19 | 19 | a = &arena.allocator; |
| 20 | 20 | |
| 21 | 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 | 23 | return error.InvalidArgs; |
| 24 | 24 | }); |
| 25 | 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 | 27 | return error.InvalidArgs; |
| 28 | 28 | }); |
| 29 | 29 | const zig_exe = try fs.path.resolve(a, &[_][]const u8{zig_exe_rel}); |
| ... | ... | @@ -45,39 +45,39 @@ pub fn main() !void { |
| 45 | 45 | |
| 46 | 46 | fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 { |
| 47 | 47 | return arg catch |err| { |
| 48 | warn("Unable to parse command line: {}\n", err); | |
| 48 | warn("Unable to parse command line: {}\n", .{err}); | |
| 49 | 49 | return err; |
| 50 | 50 | }; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | fn printCmd(cwd: []const u8, argv: []const []const u8) void { |
| 54 | std.debug.warn("cd {} && ", cwd); | |
| 54 | std.debug.warn("cd {} && ", .{cwd}); | |
| 55 | 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 | 61 | fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult { |
| 62 | 62 | const max_output_size = 100 * 1024; |
| 63 | 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 | 65 | printCmd(cwd, argv); |
| 66 | 66 | return err; |
| 67 | 67 | }; |
| 68 | 68 | switch (result.term) { |
| 69 | 69 | .Exited => |code| { |
| 70 | 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 | 72 | printCmd(cwd, argv); |
| 73 | std.debug.warn("stderr:\n{}\n", result.stderr); | |
| 73 | std.debug.warn("stderr:\n{}\n", .{result.stderr}); | |
| 74 | 74 | return error.CommandFailed; |
| 75 | 75 | } |
| 76 | 76 | }, |
| 77 | 77 | else => { |
| 78 | std.debug.warn("The following command terminated unexpectedly:\n"); | |
| 78 | std.debug.warn("The following command terminated unexpectedly:\n", .{}); | |
| 79 | 79 | printCmd(cwd, argv); |
| 80 | std.debug.warn("stderr:\n{}\n", result.stderr); | |
| 80 | std.debug.warn("stderr:\n{}\n", .{result.stderr}); | |
| 81 | 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 | 2598 | \\fn a(b: fn (*const u8) void) void { |
| 2599 | 2599 | \\ b('a'); |
| 2600 | 2600 | \\} |
| 2601 | \\fn c(d: u8) void { | |
| 2602 | \\ @import("std").debug.warn("{c}\n", d); | |
| 2603 | \\} | |
| 2601 | \\fn c(d: u8) void {} | |
| 2604 | 2602 | \\export fn entry() void { |
| 2605 | 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 | 2609 | cases.add( |
test/standalone/cat/main.zig+5-5| ... | ... | @@ -23,7 +23,7 @@ pub fn main() !void { |
| 23 | 23 | return usage(exe); |
| 24 | 24 | } else { |
| 25 | 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 | 27 | return err; |
| 28 | 28 | }; |
| 29 | 29 | defer file.close(); |
| ... | ... | @@ -38,7 +38,7 @@ pub fn main() !void { |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | fn usage(exe: []const u8) !void { |
| 41 | warn("Usage: {} [FILE]...\n", exe); | |
| 41 | warn("Usage: {} [FILE]...\n", .{exe}); | |
| 42 | 42 | return error.Invalid; |
| 43 | 43 | } |
| 44 | 44 | |
| ... | ... | @@ -47,7 +47,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void { |
| 47 | 47 | |
| 48 | 48 | while (true) { |
| 49 | 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 | 51 | return err; |
| 52 | 52 | }; |
| 53 | 53 | |
| ... | ... | @@ -56,7 +56,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void { |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 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 | 60 | return err; |
| 61 | 61 | }; |
| 62 | 62 | } |
| ... | ... | @@ -64,7 +64,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void { |
| 64 | 64 | |
| 65 | 65 | fn unwrapArg(arg: anyerror![]u8) ![]u8 { |
| 66 | 66 | return arg catch |err| { |
| 67 | warn("Unable to parse command line: {}\n", err); | |
| 67 | warn("Unable to parse command line: {}\n", .{err}); | |
| 68 | 68 | return err; |
| 69 | 69 | }; |
| 70 | 70 | } |
test/standalone/guess_number/main.zig+1-1| ... | ... | @@ -10,7 +10,7 @@ pub fn main() !void { |
| 10 | 10 | |
| 11 | 11 | var seed_bytes: [@sizeOf(u64)]u8 = undefined; |
| 12 | 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 | 14 | return err; |
| 15 | 15 | }; |
| 16 | 16 | const seed = std.mem.readIntNative(u64, &seed_bytes); |
test/tests.zig+94-66| ... | ... | @@ -411,7 +411,7 @@ pub fn addPkgTests( |
| 411 | 411 | is_qemu_enabled: bool, |
| 412 | 412 | glibc_dir: ?[]const u8, |
| 413 | 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 | 416 | for (test_targets) |test_target| { |
| 417 | 417 | if (skip_non_native and test_target.target != .Native) |
| ... | ... | @@ -454,14 +454,14 @@ pub fn addPkgTests( |
| 454 | 454 | test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable; |
| 455 | 455 | |
| 456 | 456 | const these_tests = b.addTest(root_src); |
| 457 | these_tests.setNamePrefix(b.fmt( | |
| 458 | "{}-{}-{}-{}-{} ", | |
| 457 | const single_threaded_txt = if (test_target.single_threaded) "single" else "multi"; | |
| 458 | these_tests.setNamePrefix(b.fmt("{}-{}-{}-{}-{} ", .{ | |
| 459 | 459 | name, |
| 460 | 460 | triple_prefix, |
| 461 | 461 | @tagName(test_target.mode), |
| 462 | 462 | libc_prefix, |
| 463 | if (test_target.single_threaded) "single" else "multi", | |
| 464 | )); | |
| 463 | single_threaded_txt, | |
| 464 | })); | |
| 465 | 465 | these_tests.single_threaded = test_target.single_threaded; |
| 466 | 466 | these_tests.setFilter(test_filter); |
| 467 | 467 | these_tests.setBuildMode(test_target.mode); |
| ... | ... | @@ -562,7 +562,7 @@ pub const CompareOutputContext = struct { |
| 562 | 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 | 567 | const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable; |
| 568 | 568 | defer child.deinit(); |
| ... | ... | @@ -572,7 +572,7 @@ pub const CompareOutputContext = struct { |
| 572 | 572 | child.stderr_behavior = .Pipe; |
| 573 | 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 | 577 | var stdout = Buffer.initNull(b.allocator); |
| 578 | 578 | var stderr = Buffer.initNull(b.allocator); |
| ... | ... | @@ -584,18 +584,18 @@ pub const CompareOutputContext = struct { |
| 584 | 584 | stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable; |
| 585 | 585 | |
| 586 | 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 | 589 | switch (term) { |
| 590 | 590 | .Exited => |code| { |
| 591 | 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 | 593 | printInvocation(args.toSliceConst()); |
| 594 | 594 | return error.TestFailed; |
| 595 | 595 | } |
| 596 | 596 | }, |
| 597 | 597 | else => { |
| 598 | warn("Process {} terminated unexpectedly\n", full_exe_path); | |
| 598 | warn("Process {} terminated unexpectedly\n", .{full_exe_path}); | |
| 599 | 599 | printInvocation(args.toSliceConst()); |
| 600 | 600 | return error.TestFailed; |
| 601 | 601 | }, |
| ... | ... | @@ -609,10 +609,10 @@ pub const CompareOutputContext = struct { |
| 609 | 609 | \\========= But found: ==================== |
| 610 | 610 | \\{} |
| 611 | 611 | \\ |
| 612 | , self.expected_output, stdout.toSliceConst()); | |
| 612 | , .{ self.expected_output, stdout.toSliceConst() }); | |
| 613 | 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 | 644 | |
| 645 | 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 | 649 | const child = std.ChildProcess.init(&[_][]const u8{full_exe_path}, b.allocator) catch unreachable; |
| 650 | 650 | defer child.deinit(); |
| ... | ... | @@ -655,28 +655,34 @@ pub const CompareOutputContext = struct { |
| 655 | 655 | child.stderr_behavior = .Ignore; |
| 656 | 656 | |
| 657 | 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 | 661 | const expected_exit_code: u32 = 126; |
| 662 | 662 | switch (term) { |
| 663 | 663 | .Exited => |code| { |
| 664 | 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 | 668 | return error.TestFailed; |
| 667 | 669 | } |
| 668 | 670 | }, |
| 669 | 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 | 675 | return error.TestFailed; |
| 672 | 676 | }, |
| 673 | 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 | 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 | 735 | |
| 730 | 736 | switch (case.special) { |
| 731 | 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 | 741 | if (self.test_filter) |filter| { |
| 734 | 742 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 735 | 743 | } |
| ... | ... | @@ -758,7 +766,11 @@ pub const CompareOutputContext = struct { |
| 758 | 766 | }, |
| 759 | 767 | Special.None => { |
| 760 | 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 | 774 | if (self.test_filter) |filter| { |
| 763 | 775 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; |
| 764 | 776 | } |
| ... | ... | @@ -790,7 +802,7 @@ pub const CompareOutputContext = struct { |
| 790 | 802 | } |
| 791 | 803 | }, |
| 792 | 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 | 806 | if (self.test_filter) |filter| { |
| 795 | 807 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 796 | 808 | } |
| ... | ... | @@ -843,7 +855,11 @@ pub const StackTracesContext = struct { |
| 843 | 855 | const expect_for_mode = expect[@enumToInt(mode)]; |
| 844 | 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 | 863 | if (self.test_filter) |filter| { |
| 848 | 864 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; |
| 849 | 865 | } |
| ... | ... | @@ -907,7 +923,7 @@ pub const StackTracesContext = struct { |
| 907 | 923 | defer args.deinit(); |
| 908 | 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 | 928 | const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable; |
| 913 | 929 | defer child.deinit(); |
| ... | ... | @@ -917,7 +933,7 @@ pub const StackTracesContext = struct { |
| 917 | 933 | child.stderr_behavior = .Pipe; |
| 918 | 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 | 938 | var stdout = Buffer.initNull(b.allocator); |
| 923 | 939 | var stderr = Buffer.initNull(b.allocator); |
| ... | ... | @@ -929,30 +945,34 @@ pub const StackTracesContext = struct { |
| 929 | 945 | stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable; |
| 930 | 946 | |
| 931 | 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 | 951 | switch (term) { |
| 936 | 952 | .Exited => |code| { |
| 937 | 953 | const expect_code: u32 = 1; |
| 938 | 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 | 960 | printInvocation(args.toSliceConst()); |
| 941 | 961 | return error.TestFailed; |
| 942 | 962 | } |
| 943 | 963 | }, |
| 944 | 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 | 966 | printInvocation(args.toSliceConst()); |
| 947 | 967 | return error.TestFailed; |
| 948 | 968 | }, |
| 949 | 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 | 971 | printInvocation(args.toSliceConst()); |
| 952 | 972 | return error.TestFailed; |
| 953 | 973 | }, |
| 954 | 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 | 976 | printInvocation(args.toSliceConst()); |
| 957 | 977 | return error.TestFailed; |
| 958 | 978 | }, |
| ... | ... | @@ -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 | 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 | 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 | 1154 | if (b.verbose) { |
| 1135 | 1155 | printInvocation(zig_args.toSliceConst()); |
| ... | ... | @@ -1143,7 +1163,7 @@ pub const CompileErrorContext = struct { |
| 1143 | 1163 | child.stdout_behavior = .Pipe; |
| 1144 | 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 | 1168 | var stdout_buf = Buffer.initNull(b.allocator); |
| 1149 | 1169 | var stderr_buf = Buffer.initNull(b.allocator); |
| ... | ... | @@ -1155,7 +1175,7 @@ pub const CompileErrorContext = struct { |
| 1155 | 1175 | stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable; |
| 1156 | 1176 | |
| 1157 | 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 | 1180 | switch (term) { |
| 1161 | 1181 | .Exited => |code| { |
| ... | ... | @@ -1165,7 +1185,7 @@ pub const CompileErrorContext = struct { |
| 1165 | 1185 | } |
| 1166 | 1186 | }, |
| 1167 | 1187 | else => { |
| 1168 | warn("Process {} terminated unexpectedly\n", b.zig_exe); | |
| 1188 | warn("Process {} terminated unexpectedly\n", .{b.zig_exe}); | |
| 1169 | 1189 | printInvocation(zig_args.toSliceConst()); |
| 1170 | 1190 | return error.TestFailed; |
| 1171 | 1191 | }, |
| ... | ... | @@ -1182,7 +1202,7 @@ pub const CompileErrorContext = struct { |
| 1182 | 1202 | \\{} |
| 1183 | 1203 | \\================================================ |
| 1184 | 1204 | \\ |
| 1185 | , stdout); | |
| 1205 | , .{stdout}); | |
| 1186 | 1206 | return error.TestFailed; |
| 1187 | 1207 | } |
| 1188 | 1208 | |
| ... | ... | @@ -1200,9 +1220,9 @@ pub const CompileErrorContext = struct { |
| 1200 | 1220 | ok = ok and i == self.case.expected_errors.len; |
| 1201 | 1221 | |
| 1202 | 1222 | if (!ok) { |
| 1203 | warn("\n======== Expected these compile errors: ========\n"); | |
| 1223 | warn("\n======== Expected these compile errors: ========\n", .{}); | |
| 1204 | 1224 | for (self.case.expected_errors.toSliceConst()) |expected| { |
| 1205 | warn("{}\n", expected); | |
| 1225 | warn("{}\n", .{expected}); | |
| 1206 | 1226 | } |
| 1207 | 1227 | } |
| 1208 | 1228 | } else { |
| ... | ... | @@ -1213,7 +1233,7 @@ pub const CompileErrorContext = struct { |
| 1213 | 1233 | \\=========== Expected compile error: ============ |
| 1214 | 1234 | \\{} |
| 1215 | 1235 | \\ |
| 1216 | , expected); | |
| 1236 | , .{expected}); | |
| 1217 | 1237 | ok = false; |
| 1218 | 1238 | break; |
| 1219 | 1239 | } |
| ... | ... | @@ -1225,11 +1245,11 @@ pub const CompileErrorContext = struct { |
| 1225 | 1245 | \\================= Full output: ================= |
| 1226 | 1246 | \\{} |
| 1227 | 1247 | \\ |
| 1228 | , stderr); | |
| 1248 | , .{stderr}); | |
| 1229 | 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 | 1299 | pub fn addCase(self: *CompileErrorContext, case: *const TestCase) void { |
| 1280 | 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 | 1305 | if (self.test_filter) |filter| { |
| 1284 | 1306 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 1285 | 1307 | } |
| ... | ... | @@ -1316,7 +1338,7 @@ pub const StandaloneContext = struct { |
| 1316 | 1338 | pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8) void { |
| 1317 | 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 | 1342 | if (self.test_filter) |filter| { |
| 1321 | 1343 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 1322 | 1344 | } |
| ... | ... | @@ -1337,7 +1359,7 @@ pub const StandaloneContext = struct { |
| 1337 | 1359 | |
| 1338 | 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 | 1363 | log_step.step.dependOn(&run_cmd.step); |
| 1342 | 1364 | |
| 1343 | 1365 | self.step.dependOn(&log_step.step); |
| ... | ... | @@ -1347,7 +1369,10 @@ pub const StandaloneContext = struct { |
| 1347 | 1369 | const b = self.b; |
| 1348 | 1370 | |
| 1349 | 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 | 1376 | if (self.test_filter) |filter| { |
| 1352 | 1377 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; |
| 1353 | 1378 | } |
| ... | ... | @@ -1358,7 +1383,7 @@ pub const StandaloneContext = struct { |
| 1358 | 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 | 1387 | log_step.step.dependOn(&exe.step); |
| 1363 | 1388 | |
| 1364 | 1389 | self.step.dependOn(&log_step.step); |
| ... | ... | @@ -1434,7 +1459,7 @@ pub const TranslateCContext = struct { |
| 1434 | 1459 | zig_args.append(translate_c_cmd) catch unreachable; |
| 1435 | 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 | 1464 | if (b.verbose) { |
| 1440 | 1465 | printInvocation(zig_args.toSliceConst()); |
| ... | ... | @@ -1448,7 +1473,10 @@ pub const TranslateCContext = struct { |
| 1448 | 1473 | child.stdout_behavior = .Pipe; |
| 1449 | 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 | 1481 | var stdout_buf = Buffer.initNull(b.allocator); |
| 1454 | 1482 | var stderr_buf = Buffer.initNull(b.allocator); |
| ... | ... | @@ -1460,23 +1488,23 @@ pub const TranslateCContext = struct { |
| 1460 | 1488 | stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable; |
| 1461 | 1489 | |
| 1462 | 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 | 1493 | switch (term) { |
| 1466 | 1494 | .Exited => |code| { |
| 1467 | 1495 | if (code != 0) { |
| 1468 | warn("Compilation failed with exit code {}\n", code); | |
| 1496 | warn("Compilation failed with exit code {}\n", .{code}); | |
| 1469 | 1497 | printInvocation(zig_args.toSliceConst()); |
| 1470 | 1498 | return error.TestFailed; |
| 1471 | 1499 | } |
| 1472 | 1500 | }, |
| 1473 | 1501 | .Signal => |code| { |
| 1474 | warn("Compilation failed with signal {}\n", code); | |
| 1502 | warn("Compilation failed with signal {}\n", .{code}); | |
| 1475 | 1503 | printInvocation(zig_args.toSliceConst()); |
| 1476 | 1504 | return error.TestFailed; |
| 1477 | 1505 | }, |
| 1478 | 1506 | else => { |
| 1479 | warn("Compilation terminated unexpectedly\n"); | |
| 1507 | warn("Compilation terminated unexpectedly\n", .{}); | |
| 1480 | 1508 | printInvocation(zig_args.toSliceConst()); |
| 1481 | 1509 | return error.TestFailed; |
| 1482 | 1510 | }, |
| ... | ... | @@ -1491,7 +1519,7 @@ pub const TranslateCContext = struct { |
| 1491 | 1519 | \\{} |
| 1492 | 1520 | \\============================================ |
| 1493 | 1521 | \\ |
| 1494 | , stderr); | |
| 1522 | , .{stderr}); | |
| 1495 | 1523 | printInvocation(zig_args.toSliceConst()); |
| 1496 | 1524 | return error.TestFailed; |
| 1497 | 1525 | } |
| ... | ... | @@ -1505,20 +1533,20 @@ pub const TranslateCContext = struct { |
| 1505 | 1533 | \\========= But found: =========================== |
| 1506 | 1534 | \\{} |
| 1507 | 1535 | \\ |
| 1508 | , expected_line, stdout); | |
| 1536 | , .{ expected_line, stdout }); | |
| 1509 | 1537 | printInvocation(zig_args.toSliceConst()); |
| 1510 | 1538 | return error.TestFailed; |
| 1511 | 1539 | } |
| 1512 | 1540 | } |
| 1513 | warn("OK\n"); | |
| 1541 | warn("OK\n", .{}); | |
| 1514 | 1542 | } |
| 1515 | 1543 | }; |
| 1516 | 1544 | |
| 1517 | 1545 | fn printInvocation(args: []const []const u8) void { |
| 1518 | 1546 | for (args) |arg| { |
| 1519 | warn("{} ", arg); | |
| 1547 | warn("{} ", .{arg}); | |
| 1520 | 1548 | } |
| 1521 | warn("\n"); | |
| 1549 | warn("\n", .{}); | |
| 1522 | 1550 | } |
| 1523 | 1551 | |
| 1524 | 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 | 1614 | const b = self.b; |
| 1587 | 1615 | |
| 1588 | 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 | 1618 | if (self.test_filter) |filter| { |
| 1591 | 1619 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 1592 | 1620 | } |
| ... | ... | @@ -1666,7 +1694,7 @@ pub const GenHContext = struct { |
| 1666 | 1694 | const self = @fieldParentPtr(GenHCmpOutputStep, "step", step); |
| 1667 | 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 | 1699 | const full_h_path = self.obj.getOutputHPath(); |
| 1672 | 1700 | const actual_h = try io.readFileAlloc(b.allocator, full_h_path); |
| ... | ... | @@ -1680,19 +1708,19 @@ pub const GenHContext = struct { |
| 1680 | 1708 | \\========= But found: =========================== |
| 1681 | 1709 | \\{} |
| 1682 | 1710 | \\ |
| 1683 | , expected_line, actual_h); | |
| 1711 | , .{ expected_line, actual_h }); | |
| 1684 | 1712 | return error.TestFailed; |
| 1685 | 1713 | } |
| 1686 | 1714 | } |
| 1687 | warn("OK\n"); | |
| 1715 | warn("OK\n", .{}); | |
| 1688 | 1716 | } |
| 1689 | 1717 | }; |
| 1690 | 1718 | |
| 1691 | 1719 | fn printInvocation(args: []const []const u8) void { |
| 1692 | 1720 | for (args) |arg| { |
| 1693 | warn("{} ", arg); | |
| 1721 | warn("{} ", .{arg}); | |
| 1694 | 1722 | } |
| 1695 | warn("\n"); | |
| 1723 | warn("\n", .{}); | |
| 1696 | 1724 | } |
| 1697 | 1725 | |
| 1698 | 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 | 1752 | ) catch unreachable; |
| 1725 | 1753 | |
| 1726 | 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 | 1756 | if (self.test_filter) |filter| { |
| 1729 | 1757 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 1730 | 1758 | } |
| ... | ... | @@ -1749,7 +1777,7 @@ pub const GenHContext = struct { |
| 1749 | 1777 | |
| 1750 | 1778 | fn printInvocation(args: []const []const u8) void { |
| 1751 | 1779 | for (args) |arg| { |
| 1752 | warn("{} ", arg); | |
| 1780 | warn("{} ", .{arg}); | |
| 1753 | 1781 | } |
| 1754 | warn("\n"); | |
| 1782 | warn("\n", .{}); | |
| 1755 | 1783 | } |