mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
std.fmt.format: tuple parameter instead of var args
This commit is contained in:
parent
5874cb04bd
commit
8b2622cdd5
10
build.zig
10
build.zig
@ -154,7 +154,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
|
||||
const static_bare_name = if (mem.eql(u8, lib, "curses"))
|
||||
@as([]const u8, "libncurses.a")
|
||||
else
|
||||
b.fmt("lib{}.a", lib);
|
||||
b.fmt("lib{}.a", .{lib});
|
||||
const static_lib_name = fs.path.join(
|
||||
b.allocator,
|
||||
&[_][]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
|
||||
lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
|
||||
cmake_binary_dir,
|
||||
"zig_cpp",
|
||||
b.fmt("{}{}{}", lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix()),
|
||||
b.fmt("{}{}{}", .{ lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix() }),
|
||||
}) catch unreachable);
|
||||
}
|
||||
|
||||
@ -343,14 +343,14 @@ fn addCxxKnownPath(
|
||||
) !void {
|
||||
const path_padded = try b.exec(&[_][]const u8{
|
||||
ctx.cxx_compiler,
|
||||
b.fmt("-print-file-name={}", objname),
|
||||
b.fmt("-print-file-name={}", .{objname}),
|
||||
});
|
||||
const path_unpadded = mem.tokenize(path_padded, "\r\n").next().?;
|
||||
if (mem.eql(u8, path_unpadded, objname)) {
|
||||
if (errtxt) |msg| {
|
||||
warn("{}", msg);
|
||||
warn("{}", .{msg});
|
||||
} else {
|
||||
warn("Unable to determine path to {}\n", objname);
|
||||
warn("Unable to determine path to {}\n", .{objname});
|
||||
}
|
||||
return error.RequiredLibraryNotFound;
|
||||
}
|
||||
|
@ -116,19 +116,19 @@ pub fn Queue(comptime T: type) type {
|
||||
fn dumpRecursive(s: *std.io.OutStream(Error), optional_node: ?*Node, indent: usize) Error!void {
|
||||
try s.writeByteNTimes(' ', indent);
|
||||
if (optional_node) |node| {
|
||||
try s.print("0x{x}={}\n", @ptrToInt(node), node.data);
|
||||
try s.print("0x{x}={}\n", .{ @ptrToInt(node), node.data });
|
||||
try dumpRecursive(s, node.next, indent + 1);
|
||||
} else {
|
||||
try s.print("(null)\n");
|
||||
try s.print("(null)\n", .{});
|
||||
}
|
||||
}
|
||||
};
|
||||
const held = self.mutex.acquire();
|
||||
defer held.release();
|
||||
|
||||
try stream.print("head: ");
|
||||
try stream.print("head: ", .{});
|
||||
try S.dumpRecursive(stream, self.head, 0);
|
||||
try stream.print("tail: ");
|
||||
try stream.print("tail: ", .{});
|
||||
try S.dumpRecursive(stream, self.tail, 0);
|
||||
}
|
||||
};
|
||||
@ -207,16 +207,15 @@ test "std.atomic.Queue" {
|
||||
}
|
||||
|
||||
if (context.put_sum != context.get_sum) {
|
||||
std.debug.panic("failure\nput_sum:{} != get_sum:{}", context.put_sum, context.get_sum);
|
||||
std.debug.panic("failure\nput_sum:{} != get_sum:{}", .{ context.put_sum, context.get_sum });
|
||||
}
|
||||
|
||||
if (context.get_count != puts_per_thread * put_thread_count) {
|
||||
std.debug.panic(
|
||||
"failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
|
||||
std.debug.panic("failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", .{
|
||||
context.get_count,
|
||||
@as(u32, puts_per_thread),
|
||||
@as(u32, put_thread_count),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -351,7 +350,7 @@ test "std.atomic.Queue dump" {
|
||||
\\tail: 0x{x}=1
|
||||
\\ (null)
|
||||
\\
|
||||
, @ptrToInt(queue.head), @ptrToInt(queue.tail));
|
||||
, .{ @ptrToInt(queue.head), @ptrToInt(queue.tail) });
|
||||
expect(mem.eql(u8, buffer[0..sos.pos], expected));
|
||||
|
||||
// Test a stream with two elements
|
||||
@ -372,6 +371,6 @@ test "std.atomic.Queue dump" {
|
||||
\\tail: 0x{x}=2
|
||||
\\ (null)
|
||||
\\
|
||||
, @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail));
|
||||
, .{ @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail) });
|
||||
expect(mem.eql(u8, buffer[0..sos.pos], expected));
|
||||
}
|
||||
|
@ -134,16 +134,15 @@ test "std.atomic.stack" {
|
||||
}
|
||||
|
||||
if (context.put_sum != context.get_sum) {
|
||||
std.debug.panic("failure\nput_sum:{} != get_sum:{}", context.put_sum, context.get_sum);
|
||||
std.debug.panic("failure\nput_sum:{} != get_sum:{}", .{ context.put_sum, context.get_sum });
|
||||
}
|
||||
|
||||
if (context.get_count != puts_per_thread * put_thread_count) {
|
||||
std.debug.panic(
|
||||
"failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
|
||||
std.debug.panic("failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", .{
|
||||
context.get_count,
|
||||
@as(u32, puts_per_thread),
|
||||
@as(u32, put_thread_count),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ pub const Buffer = struct {
|
||||
mem.copy(u8, self.list.items, m);
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
/// Initialize memory to size bytes of undefined values.
|
||||
/// Must deinitialize with deinit.
|
||||
pub fn initSize(allocator: *Allocator, size: usize) !Buffer {
|
||||
@ -24,7 +24,7 @@ pub const Buffer = struct {
|
||||
try self.resize(size);
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
/// Initialize with capacity to hold at least num bytes.
|
||||
/// Must deinitialize with deinit.
|
||||
pub fn initCapacity(allocator: *Allocator, num: usize) !Buffer {
|
||||
@ -64,7 +64,7 @@ pub const Buffer = struct {
|
||||
return result;
|
||||
}
|
||||
|
||||
pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: ...) !Buffer {
|
||||
pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: var) !Buffer {
|
||||
const countSize = struct {
|
||||
fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
|
||||
size.* += bytes.len;
|
||||
@ -107,7 +107,7 @@ pub const Buffer = struct {
|
||||
pub fn len(self: Buffer) usize {
|
||||
return self.list.len - 1;
|
||||
}
|
||||
|
||||
|
||||
pub fn capacity(self: Buffer) usize {
|
||||
return if (self.list.items.len > 0)
|
||||
self.list.items.len - 1
|
||||
|
@ -232,7 +232,7 @@ pub const Builder = struct {
|
||||
/// To run an executable built with zig build, see `LibExeObjStep.run`.
|
||||
pub fn addSystemCommand(self: *Builder, argv: []const []const u8) *RunStep {
|
||||
assert(argv.len >= 1);
|
||||
const run_step = RunStep.create(self, self.fmt("run {}", argv[0]));
|
||||
const run_step = RunStep.create(self, self.fmt("run {}", .{argv[0]}));
|
||||
run_step.addArgs(argv);
|
||||
return run_step;
|
||||
}
|
||||
@ -258,7 +258,7 @@ pub const Builder = struct {
|
||||
return write_file_step;
|
||||
}
|
||||
|
||||
pub fn addLog(self: *Builder, comptime format: []const u8, args: ...) *LogStep {
|
||||
pub fn addLog(self: *Builder, comptime format: []const u8, args: var) *LogStep {
|
||||
const data = self.fmt(format, args);
|
||||
const log_step = self.allocator.create(LogStep) catch unreachable;
|
||||
log_step.* = LogStep.init(self, data);
|
||||
@ -330,7 +330,7 @@ pub const Builder = struct {
|
||||
for (self.installed_files.toSliceConst()) |installed_file| {
|
||||
const full_path = self.getInstallPath(installed_file.dir, installed_file.path);
|
||||
if (self.verbose) {
|
||||
warn("rm {}\n", full_path);
|
||||
warn("rm {}\n", .{full_path});
|
||||
}
|
||||
fs.deleteTree(full_path) catch {};
|
||||
}
|
||||
@ -340,7 +340,7 @@ pub const Builder = struct {
|
||||
|
||||
fn makeOneStep(self: *Builder, s: *Step) anyerror!void {
|
||||
if (s.loop_flag) {
|
||||
warn("Dependency loop detected:\n {}\n", s.name);
|
||||
warn("Dependency loop detected:\n {}\n", .{s.name});
|
||||
return error.DependencyLoopDetected;
|
||||
}
|
||||
s.loop_flag = true;
|
||||
@ -348,7 +348,7 @@ pub const Builder = struct {
|
||||
for (s.dependencies.toSlice()) |dep| {
|
||||
self.makeOneStep(dep) catch |err| {
|
||||
if (err == error.DependencyLoopDetected) {
|
||||
warn(" {}\n", s.name);
|
||||
warn(" {}\n", .{s.name});
|
||||
}
|
||||
return err;
|
||||
};
|
||||
@ -365,7 +365,7 @@ pub const Builder = struct {
|
||||
return &top_level_step.step;
|
||||
}
|
||||
}
|
||||
warn("Cannot run step '{}' because it does not exist\n", name);
|
||||
warn("Cannot run step '{}' because it does not exist\n", .{name});
|
||||
return error.InvalidStepName;
|
||||
}
|
||||
|
||||
@ -378,12 +378,12 @@ pub const Builder = struct {
|
||||
const word = it.next() orelse break;
|
||||
if (mem.eql(u8, word, "-isystem")) {
|
||||
const include_path = it.next() orelse {
|
||||
warn("Expected argument after -isystem in NIX_CFLAGS_COMPILE\n");
|
||||
warn("Expected argument after -isystem in NIX_CFLAGS_COMPILE\n", .{});
|
||||
break;
|
||||
};
|
||||
self.addNativeSystemIncludeDir(include_path);
|
||||
} else {
|
||||
warn("Unrecognized C flag from NIX_CFLAGS_COMPILE: {}\n", word);
|
||||
warn("Unrecognized C flag from NIX_CFLAGS_COMPILE: {}\n", .{word});
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -397,7 +397,7 @@ pub const Builder = struct {
|
||||
const word = it.next() orelse break;
|
||||
if (mem.eql(u8, word, "-rpath")) {
|
||||
const rpath = it.next() orelse {
|
||||
warn("Expected argument after -rpath in NIX_LDFLAGS\n");
|
||||
warn("Expected argument after -rpath in NIX_LDFLAGS\n", .{});
|
||||
break;
|
||||
};
|
||||
self.addNativeSystemRPath(rpath);
|
||||
@ -405,7 +405,7 @@ pub const Builder = struct {
|
||||
const lib_path = word[2..];
|
||||
self.addNativeSystemLibPath(lib_path);
|
||||
} else {
|
||||
warn("Unrecognized C flag from NIX_LDFLAGS: {}\n", word);
|
||||
warn("Unrecognized C flag from NIX_LDFLAGS: {}\n", .{word});
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -431,8 +431,8 @@ pub const Builder = struct {
|
||||
self.addNativeSystemIncludeDir("/usr/local/include");
|
||||
self.addNativeSystemLibPath("/usr/local/lib");
|
||||
|
||||
self.addNativeSystemIncludeDir(self.fmt("/usr/include/{}", triple));
|
||||
self.addNativeSystemLibPath(self.fmt("/usr/lib/{}", triple));
|
||||
self.addNativeSystemIncludeDir(self.fmt("/usr/include/{}", .{triple}));
|
||||
self.addNativeSystemLibPath(self.fmt("/usr/lib/{}", .{triple}));
|
||||
|
||||
self.addNativeSystemIncludeDir("/usr/include");
|
||||
self.addNativeSystemLibPath("/usr/lib");
|
||||
@ -440,7 +440,7 @@ pub const Builder = struct {
|
||||
// example: on a 64-bit debian-based linux distro, with zlib installed from apt:
|
||||
// zlib.h is in /usr/include (added above)
|
||||
// libz.so.1 is in /lib/x86_64-linux-gnu (added here)
|
||||
self.addNativeSystemLibPath(self.fmt("/lib/{}", triple));
|
||||
self.addNativeSystemLibPath(self.fmt("/lib/{}", .{triple}));
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -453,7 +453,7 @@ pub const Builder = struct {
|
||||
.description = description,
|
||||
};
|
||||
if ((self.available_options_map.put(name, available_option) catch unreachable) != null) {
|
||||
panic("Option '{}' declared twice", name);
|
||||
panic("Option '{}' declared twice", .{name});
|
||||
}
|
||||
self.available_options_list.append(available_option) catch unreachable;
|
||||
|
||||
@ -468,33 +468,33 @@ pub const Builder = struct {
|
||||
} else if (mem.eql(u8, s, "false")) {
|
||||
return false;
|
||||
} else {
|
||||
warn("Expected -D{} to be a boolean, but received '{}'\n", name, s);
|
||||
warn("Expected -D{} to be a boolean, but received '{}'\n", .{ name, s });
|
||||
self.markInvalidUserInput();
|
||||
return null;
|
||||
}
|
||||
},
|
||||
UserValue.List => {
|
||||
warn("Expected -D{} to be a boolean, but received a list.\n", name);
|
||||
warn("Expected -D{} to be a boolean, but received a list.\n", .{name});
|
||||
self.markInvalidUserInput();
|
||||
return null;
|
||||
},
|
||||
},
|
||||
TypeId.Int => panic("TODO integer options to build script"),
|
||||
TypeId.Float => panic("TODO float options to build script"),
|
||||
TypeId.Int => panic("TODO integer options to build script", .{}),
|
||||
TypeId.Float => panic("TODO float options to build script", .{}),
|
||||
TypeId.String => switch (entry.value.value) {
|
||||
UserValue.Flag => {
|
||||
warn("Expected -D{} to be a string, but received a boolean.\n", name);
|
||||
warn("Expected -D{} to be a string, but received a boolean.\n", .{name});
|
||||
self.markInvalidUserInput();
|
||||
return null;
|
||||
},
|
||||
UserValue.List => {
|
||||
warn("Expected -D{} to be a string, but received a list.\n", name);
|
||||
warn("Expected -D{} to be a string, but received a list.\n", .{name});
|
||||
self.markInvalidUserInput();
|
||||
return null;
|
||||
},
|
||||
UserValue.Scalar => |s| return s,
|
||||
},
|
||||
TypeId.List => panic("TODO list options to build script"),
|
||||
TypeId.List => panic("TODO list options to build script", .{}),
|
||||
}
|
||||
}
|
||||
|
||||
@ -513,7 +513,7 @@ pub const Builder = struct {
|
||||
if (self.release_mode != null) {
|
||||
@panic("setPreferredReleaseMode must be called before standardReleaseOptions and may not be called twice");
|
||||
}
|
||||
const description = self.fmt("create a release build ({})", @tagName(mode));
|
||||
const description = self.fmt("create a release build ({})", .{@tagName(mode)});
|
||||
self.is_release = self.option(bool, "release", description) orelse false;
|
||||
self.release_mode = if (self.is_release) mode else builtin.Mode.Debug;
|
||||
}
|
||||
@ -536,7 +536,7 @@ pub const Builder = struct {
|
||||
else if (!release_fast and !release_safe and !release_small)
|
||||
builtin.Mode.Debug
|
||||
else x: {
|
||||
warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)");
|
||||
warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)", .{});
|
||||
self.markInvalidUserInput();
|
||||
break :x builtin.Mode.Debug;
|
||||
};
|
||||
@ -599,7 +599,7 @@ pub const Builder = struct {
|
||||
}) catch unreachable;
|
||||
},
|
||||
UserValue.Flag => {
|
||||
warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", name, value, name);
|
||||
warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", .{ name, value, name });
|
||||
return true;
|
||||
},
|
||||
}
|
||||
@ -620,11 +620,11 @@ pub const Builder = struct {
|
||||
// option already exists
|
||||
switch (gop.kv.value.value) {
|
||||
UserValue.Scalar => |s| {
|
||||
warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", name, name, s);
|
||||
warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", .{ name, name, s });
|
||||
return true;
|
||||
},
|
||||
UserValue.List => {
|
||||
warn("Flag '-D{}' conflicts with multiple options of the same name.\n", name);
|
||||
warn("Flag '-D{}' conflicts with multiple options of the same name.\n", .{name});
|
||||
return true;
|
||||
},
|
||||
UserValue.Flag => {},
|
||||
@ -665,7 +665,7 @@ pub const Builder = struct {
|
||||
while (true) {
|
||||
const entry = it.next() orelse break;
|
||||
if (!entry.value.used) {
|
||||
warn("Invalid option: -D{}\n\n", entry.key);
|
||||
warn("Invalid option: -D{}\n\n", .{entry.key});
|
||||
self.markInvalidUserInput();
|
||||
}
|
||||
}
|
||||
@ -678,11 +678,11 @@ pub const Builder = struct {
|
||||
}
|
||||
|
||||
fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void {
|
||||
if (cwd) |yes_cwd| warn("cd {} && ", yes_cwd);
|
||||
if (cwd) |yes_cwd| warn("cd {} && ", .{yes_cwd});
|
||||
for (argv) |arg| {
|
||||
warn("{} ", arg);
|
||||
warn("{} ", .{arg});
|
||||
}
|
||||
warn("\n");
|
||||
warn("\n", .{});
|
||||
}
|
||||
|
||||
fn spawnChildEnvMap(self: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) !void {
|
||||
@ -697,20 +697,20 @@ pub const Builder = struct {
|
||||
child.env_map = env_map;
|
||||
|
||||
const term = child.spawnAndWait() catch |err| {
|
||||
warn("Unable to spawn {}: {}\n", argv[0], @errorName(err));
|
||||
warn("Unable to spawn {}: {}\n", .{ argv[0], @errorName(err) });
|
||||
return err;
|
||||
};
|
||||
|
||||
switch (term) {
|
||||
.Exited => |code| {
|
||||
if (code != 0) {
|
||||
warn("The following command exited with error code {}:\n", code);
|
||||
warn("The following command exited with error code {}:\n", .{code});
|
||||
printCmd(cwd, argv);
|
||||
return error.UncleanExit;
|
||||
}
|
||||
},
|
||||
else => {
|
||||
warn("The following command terminated unexpectedly:\n");
|
||||
warn("The following command terminated unexpectedly:\n", .{});
|
||||
printCmd(cwd, argv);
|
||||
|
||||
return error.UncleanExit;
|
||||
@ -720,7 +720,7 @@ pub const Builder = struct {
|
||||
|
||||
pub fn makePath(self: *Builder, path: []const u8) !void {
|
||||
fs.makePath(self.allocator, self.pathFromRoot(path)) catch |err| {
|
||||
warn("Unable to create path {}: {}\n", path, @errorName(err));
|
||||
warn("Unable to create path {}: {}\n", .{ path, @errorName(err) });
|
||||
return err;
|
||||
};
|
||||
}
|
||||
@ -793,12 +793,12 @@ pub const Builder = struct {
|
||||
|
||||
fn updateFile(self: *Builder, source_path: []const u8, dest_path: []const u8) !void {
|
||||
if (self.verbose) {
|
||||
warn("cp {} {} ", source_path, dest_path);
|
||||
warn("cp {} {} ", .{ source_path, dest_path });
|
||||
}
|
||||
const prev_status = try fs.updateFile(source_path, dest_path);
|
||||
if (self.verbose) switch (prev_status) {
|
||||
.stale => warn("# installed\n"),
|
||||
.fresh => warn("# up-to-date\n"),
|
||||
.stale => warn("# installed\n", .{}),
|
||||
.fresh => warn("# up-to-date\n", .{}),
|
||||
};
|
||||
}
|
||||
|
||||
@ -806,7 +806,7 @@ pub const Builder = struct {
|
||||
return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {
|
||||
pub fn fmt(self: *Builder, comptime format: []const u8, args: var) []u8 {
|
||||
return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;
|
||||
}
|
||||
|
||||
@ -818,7 +818,11 @@ pub const Builder = struct {
|
||||
if (fs.path.isAbsolute(name)) {
|
||||
return name;
|
||||
}
|
||||
const full_path = try fs.path.join(self.allocator, &[_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });
|
||||
const full_path = try fs.path.join(self.allocator, &[_][]const u8{
|
||||
search_prefix,
|
||||
"bin",
|
||||
self.fmt("{}{}", .{ name, exe_extension }),
|
||||
});
|
||||
return fs.realpathAlloc(self.allocator, full_path) catch continue;
|
||||
}
|
||||
}
|
||||
@ -829,7 +833,10 @@ pub const Builder = struct {
|
||||
}
|
||||
var it = mem.tokenize(PATH, &[_]u8{fs.path.delimiter});
|
||||
while (it.next()) |path| {
|
||||
const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
|
||||
const full_path = try fs.path.join(self.allocator, &[_][]const u8{
|
||||
path,
|
||||
self.fmt("{}{}", .{ name, exe_extension }),
|
||||
});
|
||||
return fs.realpathAlloc(self.allocator, full_path) catch continue;
|
||||
}
|
||||
}
|
||||
@ -839,7 +846,10 @@ pub const Builder = struct {
|
||||
return name;
|
||||
}
|
||||
for (paths) |path| {
|
||||
const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
|
||||
const full_path = try fs.path.join(self.allocator, &[_][]const u8{
|
||||
path,
|
||||
self.fmt("{}{}", .{ name, exe_extension }),
|
||||
});
|
||||
return fs.realpathAlloc(self.allocator, full_path) catch continue;
|
||||
}
|
||||
}
|
||||
@ -896,17 +906,17 @@ pub const Builder = struct {
|
||||
var code: u8 = undefined;
|
||||
return self.execAllowFail(argv, &code, .Inherit) catch |err| switch (err) {
|
||||
error.FileNotFound => {
|
||||
warn("Unable to spawn the following command: file not found\n");
|
||||
warn("Unable to spawn the following command: file not found\n", .{});
|
||||
printCmd(null, argv);
|
||||
std.os.exit(@truncate(u8, code));
|
||||
},
|
||||
error.ExitCodeFailure => {
|
||||
warn("The following command exited with error code {}:\n", code);
|
||||
warn("The following command exited with error code {}:\n", .{code});
|
||||
printCmd(null, argv);
|
||||
std.os.exit(@truncate(u8, code));
|
||||
},
|
||||
error.ProcessTerminated => {
|
||||
warn("The following command terminated unexpectedly:\n");
|
||||
warn("The following command terminated unexpectedly:\n", .{});
|
||||
printCmd(null, argv);
|
||||
std.os.exit(@truncate(u8, code));
|
||||
},
|
||||
@ -1133,7 +1143,7 @@ pub const LibExeObjStep = struct {
|
||||
|
||||
fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, is_dynamic: bool, ver: Version) LibExeObjStep {
|
||||
if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) {
|
||||
panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", name);
|
||||
panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", .{name});
|
||||
}
|
||||
var self = LibExeObjStep{
|
||||
.strip = false,
|
||||
@ -1150,9 +1160,9 @@ pub const LibExeObjStep = struct {
|
||||
.step = Step.init(name, builder.allocator, make),
|
||||
.version = ver,
|
||||
.out_filename = undefined,
|
||||
.out_h_filename = builder.fmt("{}.h", name),
|
||||
.out_h_filename = builder.fmt("{}.h", .{name}),
|
||||
.out_lib_filename = undefined,
|
||||
.out_pdb_filename = builder.fmt("{}.pdb", name),
|
||||
.out_pdb_filename = builder.fmt("{}.pdb", .{name}),
|
||||
.major_only_filename = undefined,
|
||||
.name_only_filename = undefined,
|
||||
.packages = ArrayList(Pkg).init(builder.allocator),
|
||||
@ -1186,36 +1196,48 @@ pub const LibExeObjStep = struct {
|
||||
fn computeOutFileNames(self: *LibExeObjStep) void {
|
||||
switch (self.kind) {
|
||||
.Obj => {
|
||||
self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt());
|
||||
self.out_filename = self.builder.fmt("{}{}", .{ self.name, self.target.oFileExt() });
|
||||
},
|
||||
.Exe => {
|
||||
self.out_filename = self.builder.fmt("{}{}", self.name, self.target.exeFileExt());
|
||||
self.out_filename = self.builder.fmt("{}{}", .{ self.name, self.target.exeFileExt() });
|
||||
},
|
||||
.Test => {
|
||||
self.out_filename = self.builder.fmt("test{}", self.target.exeFileExt());
|
||||
self.out_filename = self.builder.fmt("test{}", .{self.target.exeFileExt()});
|
||||
},
|
||||
.Lib => {
|
||||
if (!self.is_dynamic) {
|
||||
self.out_filename = self.builder.fmt(
|
||||
"{}{}{}",
|
||||
self.out_filename = self.builder.fmt("{}{}{}", .{
|
||||
self.target.libPrefix(),
|
||||
self.name,
|
||||
self.target.staticLibSuffix(),
|
||||
);
|
||||
});
|
||||
self.out_lib_filename = self.out_filename;
|
||||
} else {
|
||||
if (self.target.isDarwin()) {
|
||||
self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", self.name, self.version.major, self.version.minor, self.version.patch);
|
||||
self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", self.name, self.version.major);
|
||||
self.name_only_filename = self.builder.fmt("lib{}.dylib", self.name);
|
||||
self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", .{
|
||||
self.name,
|
||||
self.version.major,
|
||||
self.version.minor,
|
||||
self.version.patch,
|
||||
});
|
||||
self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", .{
|
||||
self.name,
|
||||
self.version.major,
|
||||
});
|
||||
self.name_only_filename = self.builder.fmt("lib{}.dylib", .{self.name});
|
||||
self.out_lib_filename = self.out_filename;
|
||||
} else if (self.target.isWindows()) {
|
||||
self.out_filename = self.builder.fmt("{}.dll", self.name);
|
||||
self.out_lib_filename = self.builder.fmt("{}.lib", self.name);
|
||||
self.out_filename = self.builder.fmt("{}.dll", .{self.name});
|
||||
self.out_lib_filename = self.builder.fmt("{}.lib", .{self.name});
|
||||
} else {
|
||||
self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", self.name, self.version.major, self.version.minor, self.version.patch);
|
||||
self.major_only_filename = self.builder.fmt("lib{}.so.{d}", self.name, self.version.major);
|
||||
self.name_only_filename = self.builder.fmt("lib{}.so", self.name);
|
||||
self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", .{
|
||||
self.name,
|
||||
self.version.major,
|
||||
self.version.minor,
|
||||
self.version.patch,
|
||||
});
|
||||
self.major_only_filename = self.builder.fmt("lib{}.so.{d}", .{ self.name, self.version.major });
|
||||
self.name_only_filename = self.builder.fmt("lib{}.so", .{self.name});
|
||||
self.out_lib_filename = self.out_filename;
|
||||
}
|
||||
}
|
||||
@ -1268,7 +1290,7 @@ pub const LibExeObjStep = struct {
|
||||
// It doesn't have to be native. We catch that if you actually try to run it.
|
||||
// Consider that this is declarative; the run step may not be run unless a user
|
||||
// option is supplied.
|
||||
const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", exe.step.name));
|
||||
const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", .{exe.step.name}));
|
||||
run_step.addArtifactArg(exe);
|
||||
|
||||
if (exe.vcpkg_bin_path) |path| {
|
||||
@ -1420,7 +1442,7 @@ pub const LibExeObjStep = struct {
|
||||
} else if (mem.eql(u8, tok, "-pthread")) {
|
||||
self.linkLibC();
|
||||
} else if (self.builder.verbose) {
|
||||
warn("Ignoring pkg-config flag '{}'\n", tok);
|
||||
warn("Ignoring pkg-config flag '{}'\n", .{tok});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1653,7 +1675,7 @@ pub const LibExeObjStep = struct {
|
||||
const builder = self.builder;
|
||||
|
||||
if (self.root_src == null and self.link_objects.len == 0) {
|
||||
warn("{}: linker needs 1 or more objects to link\n", self.step.name);
|
||||
warn("{}: linker needs 1 or more objects to link\n", .{self.step.name});
|
||||
return error.NeedAnObject;
|
||||
}
|
||||
|
||||
@ -1725,7 +1747,7 @@ pub const LibExeObjStep = struct {
|
||||
if (self.build_options_contents.len() > 0) {
|
||||
const build_options_file = try fs.path.join(
|
||||
builder.allocator,
|
||||
&[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },
|
||||
&[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", .{self.name}) },
|
||||
);
|
||||
try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());
|
||||
try zig_args.append("--pkg-begin");
|
||||
@ -1780,13 +1802,13 @@ pub const LibExeObjStep = struct {
|
||||
|
||||
if (self.kind == Kind.Lib and self.is_dynamic) {
|
||||
zig_args.append("--ver-major") catch unreachable;
|
||||
zig_args.append(builder.fmt("{}", self.version.major)) catch unreachable;
|
||||
zig_args.append(builder.fmt("{}", .{self.version.major})) catch unreachable;
|
||||
|
||||
zig_args.append("--ver-minor") catch unreachable;
|
||||
zig_args.append(builder.fmt("{}", self.version.minor)) catch unreachable;
|
||||
zig_args.append(builder.fmt("{}", .{self.version.minor})) catch unreachable;
|
||||
|
||||
zig_args.append("--ver-patch") catch unreachable;
|
||||
zig_args.append(builder.fmt("{}", self.version.patch)) catch unreachable;
|
||||
zig_args.append(builder.fmt("{}", .{self.version.patch})) catch unreachable;
|
||||
}
|
||||
if (self.is_dynamic) {
|
||||
try zig_args.append("-dynamic");
|
||||
@ -1811,7 +1833,7 @@ pub const LibExeObjStep = struct {
|
||||
|
||||
if (self.target_glibc) |ver| {
|
||||
try zig_args.append("-target-glibc");
|
||||
try zig_args.append(builder.fmt("{}.{}.{}", ver.major, ver.minor, ver.patch));
|
||||
try zig_args.append(builder.fmt("{}.{}.{}", .{ ver.major, ver.minor, ver.patch }));
|
||||
}
|
||||
|
||||
if (self.linker_script) |linker_script| {
|
||||
@ -2079,7 +2101,7 @@ pub const RunStep = struct {
|
||||
}
|
||||
|
||||
if (prev_path) |pp| {
|
||||
const new_path = self.builder.fmt("{}" ++ [1]u8{fs.path.delimiter} ++ "{}", pp, search_path);
|
||||
const new_path = self.builder.fmt("{}" ++ [1]u8{fs.path.delimiter} ++ "{}", .{ pp, search_path });
|
||||
env_map.set(key, new_path) catch unreachable;
|
||||
} else {
|
||||
env_map.set(key, search_path) catch unreachable;
|
||||
@ -2153,7 +2175,7 @@ const InstallArtifactStep = struct {
|
||||
const self = builder.allocator.create(Self) catch unreachable;
|
||||
self.* = Self{
|
||||
.builder = builder,
|
||||
.step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make),
|
||||
.step = Step.init(builder.fmt("install {}", .{artifact.step.name}), builder.allocator, make),
|
||||
.artifact = artifact,
|
||||
.dest_dir = switch (artifact.kind) {
|
||||
.Obj => unreachable,
|
||||
@ -2219,7 +2241,7 @@ pub const InstallFileStep = struct {
|
||||
builder.pushInstalledFile(dir, dest_rel_path);
|
||||
return InstallFileStep{
|
||||
.builder = builder,
|
||||
.step = Step.init(builder.fmt("install {}", src_path), builder.allocator, make),
|
||||
.step = Step.init(builder.fmt("install {}", .{src_path}), builder.allocator, make),
|
||||
.src_path = src_path,
|
||||
.dir = dir,
|
||||
.dest_rel_path = dest_rel_path,
|
||||
@ -2253,7 +2275,7 @@ pub const InstallDirStep = struct {
|
||||
builder.pushInstalledFile(options.install_dir, options.install_subdir);
|
||||
return InstallDirStep{
|
||||
.builder = builder,
|
||||
.step = Step.init(builder.fmt("install {}/", options.source_dir), builder.allocator, make),
|
||||
.step = Step.init(builder.fmt("install {}/", .{options.source_dir}), builder.allocator, make),
|
||||
.options = options,
|
||||
};
|
||||
}
|
||||
@ -2290,7 +2312,7 @@ pub const WriteFileStep = struct {
|
||||
pub fn init(builder: *Builder, file_path: []const u8, data: []const u8) WriteFileStep {
|
||||
return WriteFileStep{
|
||||
.builder = builder,
|
||||
.step = Step.init(builder.fmt("writefile {}", file_path), builder.allocator, make),
|
||||
.step = Step.init(builder.fmt("writefile {}", .{file_path}), builder.allocator, make),
|
||||
.file_path = file_path,
|
||||
.data = data,
|
||||
};
|
||||
@ -2301,11 +2323,11 @@ pub const WriteFileStep = struct {
|
||||
const full_path = self.builder.pathFromRoot(self.file_path);
|
||||
const full_path_dir = fs.path.dirname(full_path) orelse ".";
|
||||
fs.makePath(self.builder.allocator, full_path_dir) catch |err| {
|
||||
warn("unable to make path {}: {}\n", full_path_dir, @errorName(err));
|
||||
warn("unable to make path {}: {}\n", .{ full_path_dir, @errorName(err) });
|
||||
return err;
|
||||
};
|
||||
io.writeFile(full_path, self.data) catch |err| {
|
||||
warn("unable to write {}: {}\n", full_path, @errorName(err));
|
||||
warn("unable to write {}: {}\n", .{ full_path, @errorName(err) });
|
||||
return err;
|
||||
};
|
||||
}
|
||||
@ -2319,14 +2341,14 @@ pub const LogStep = struct {
|
||||
pub fn init(builder: *Builder, data: []const u8) LogStep {
|
||||
return LogStep{
|
||||
.builder = builder,
|
||||
.step = Step.init(builder.fmt("log {}", data), builder.allocator, make),
|
||||
.step = Step.init(builder.fmt("log {}", .{data}), builder.allocator, make),
|
||||
.data = data,
|
||||
};
|
||||
}
|
||||
|
||||
fn make(step: *Step) anyerror!void {
|
||||
const self = @fieldParentPtr(LogStep, "step", step);
|
||||
warn("{}", self.data);
|
||||
warn("{}", .{self.data});
|
||||
}
|
||||
};
|
||||
|
||||
@ -2338,7 +2360,7 @@ pub const RemoveDirStep = struct {
|
||||
pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep {
|
||||
return RemoveDirStep{
|
||||
.builder = builder,
|
||||
.step = Step.init(builder.fmt("RemoveDir {}", dir_path), builder.allocator, make),
|
||||
.step = Step.init(builder.fmt("RemoveDir {}", .{dir_path}), builder.allocator, make),
|
||||
.dir_path = dir_path,
|
||||
};
|
||||
}
|
||||
@ -2348,7 +2370,7 @@ pub const RemoveDirStep = struct {
|
||||
|
||||
const full_path = self.builder.pathFromRoot(self.dir_path);
|
||||
fs.deleteTree(full_path) catch |err| {
|
||||
warn("Unable to remove {}: {}\n", full_path, @errorName(err));
|
||||
warn("Unable to remove {}: {}\n", .{ full_path, @errorName(err) });
|
||||
return err;
|
||||
};
|
||||
}
|
||||
@ -2397,7 +2419,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
|
||||
&[_][]const u8{ out_dir, filename_major_only },
|
||||
) catch unreachable;
|
||||
fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
|
||||
warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
|
||||
warn("Unable to symlink {} -> {}\n", .{ major_only_path, out_basename });
|
||||
return err;
|
||||
};
|
||||
// sym link for libfoo.so to libfoo.so.1
|
||||
@ -2406,7 +2428,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
|
||||
&[_][]const u8{ out_dir, filename_name_only },
|
||||
) catch unreachable;
|
||||
fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
|
||||
warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);
|
||||
warn("Unable to symlink {} -> {}\n", .{ name_only_path, filename_major_only });
|
||||
return err;
|
||||
};
|
||||
}
|
||||
|
@ -429,7 +429,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
|
||||
}
|
||||
},
|
||||
.wasi => {
|
||||
std.debug.warn("{}", msg);
|
||||
std.debug.warn("{}", .{msg});
|
||||
_ = std.os.wasi.proc_raise(std.os.wasi.SIGABRT);
|
||||
unreachable;
|
||||
},
|
||||
@ -439,7 +439,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
|
||||
},
|
||||
else => {
|
||||
const first_trace_addr = @returnAddress();
|
||||
std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", msg);
|
||||
std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", .{msg});
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ fn usage() void {
|
||||
\\ --seed [int]
|
||||
\\ --help
|
||||
\\
|
||||
);
|
||||
, .{});
|
||||
}
|
||||
|
||||
fn mode(comptime x: comptime_int) comptime_int {
|
||||
|
@ -46,7 +46,7 @@ var stderr_file_out_stream: File.OutStream = undefined;
|
||||
var stderr_stream: ?*io.OutStream(File.WriteError) = null;
|
||||
var stderr_mutex = std.Mutex.init();
|
||||
|
||||
pub fn warn(comptime fmt: []const u8, args: ...) void {
|
||||
pub fn warn(comptime fmt: []const u8, args: var) void {
|
||||
const held = stderr_mutex.acquire();
|
||||
defer held.release();
|
||||
const stderr = getStderrStream();
|
||||
@ -92,15 +92,15 @@ fn wantTtyColor() bool {
|
||||
pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
|
||||
const stderr = getStderrStream();
|
||||
if (builtin.strip_debug_info) {
|
||||
stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;
|
||||
stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
|
||||
return;
|
||||
}
|
||||
const debug_info = getSelfDebugInfo() catch |err| {
|
||||
stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return;
|
||||
stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;
|
||||
return;
|
||||
};
|
||||
writeCurrentStackTrace(stderr, debug_info, wantTtyColor(), start_addr) catch |err| {
|
||||
stderr.print("Unable to dump stack trace: {}\n", @errorName(err)) catch return;
|
||||
stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return;
|
||||
return;
|
||||
};
|
||||
}
|
||||
@ -111,11 +111,11 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
|
||||
pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {
|
||||
const stderr = getStderrStream();
|
||||
if (builtin.strip_debug_info) {
|
||||
stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;
|
||||
stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
|
||||
return;
|
||||
}
|
||||
const debug_info = getSelfDebugInfo() catch |err| {
|
||||
stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return;
|
||||
stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;
|
||||
return;
|
||||
};
|
||||
const tty_color = wantTtyColor();
|
||||
@ -184,15 +184,15 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace
|
||||
pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void {
|
||||
const stderr = getStderrStream();
|
||||
if (builtin.strip_debug_info) {
|
||||
stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;
|
||||
stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
|
||||
return;
|
||||
}
|
||||
const debug_info = getSelfDebugInfo() catch |err| {
|
||||
stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return;
|
||||
stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;
|
||||
return;
|
||||
};
|
||||
writeStackTrace(stack_trace, stderr, getDebugInfoAllocator(), debug_info, wantTtyColor()) catch |err| {
|
||||
stderr.print("Unable to dump stack trace: {}\n", @errorName(err)) catch return;
|
||||
stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return;
|
||||
return;
|
||||
};
|
||||
}
|
||||
@ -211,7 +211,7 @@ pub fn assert(ok: bool) void {
|
||||
if (!ok) unreachable; // assertion failure
|
||||
}
|
||||
|
||||
pub fn panic(comptime format: []const u8, args: ...) noreturn {
|
||||
pub fn panic(comptime format: []const u8, args: var) noreturn {
|
||||
@setCold(true);
|
||||
// TODO: remove conditional once wasi / LLVM defines __builtin_return_address
|
||||
const first_trace_addr = if (builtin.os == .wasi) null else @returnAddress();
|
||||
@ -221,7 +221,7 @@ pub fn panic(comptime format: []const u8, args: ...) noreturn {
|
||||
/// TODO multithreaded awareness
|
||||
var panicking: u8 = 0; // TODO make this a bool
|
||||
|
||||
pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: ...) noreturn {
|
||||
pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: var) noreturn {
|
||||
@setCold(true);
|
||||
|
||||
if (enable_segfault_handler) {
|
||||
@ -376,13 +376,13 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
|
||||
} else {
|
||||
// we have no information to add to the address
|
||||
if (tty_color) {
|
||||
try out_stream.print("???:?:?: ");
|
||||
try out_stream.print("???:?:?: ", .{});
|
||||
setTtyColor(TtyColor.Dim);
|
||||
try out_stream.print("0x{x} in ??? (???)", relocated_address);
|
||||
try out_stream.print("0x{x} in ??? (???)", .{relocated_address});
|
||||
setTtyColor(TtyColor.Reset);
|
||||
try out_stream.print("\n\n\n");
|
||||
try out_stream.print("\n\n\n", .{});
|
||||
} else {
|
||||
try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", relocated_address);
|
||||
try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{relocated_address});
|
||||
}
|
||||
return;
|
||||
};
|
||||
@ -509,18 +509,18 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
|
||||
if (tty_color) {
|
||||
setTtyColor(TtyColor.White);
|
||||
if (opt_line_info) |li| {
|
||||
try out_stream.print("{}:{}:{}", li.file_name, li.line, li.column);
|
||||
try out_stream.print("{}:{}:{}", .{ li.file_name, li.line, li.column });
|
||||
} else {
|
||||
try out_stream.print("???:?:?");
|
||||
try out_stream.print("???:?:?", .{});
|
||||
}
|
||||
setTtyColor(TtyColor.Reset);
|
||||
try out_stream.print(": ");
|
||||
try out_stream.print(": ", .{});
|
||||
setTtyColor(TtyColor.Dim);
|
||||
try out_stream.print("0x{x} in {} ({})", relocated_address, symbol_name, obj_basename);
|
||||
try out_stream.print("0x{x} in {} ({})", .{ relocated_address, symbol_name, obj_basename });
|
||||
setTtyColor(TtyColor.Reset);
|
||||
|
||||
if (opt_line_info) |line_info| {
|
||||
try out_stream.print("\n");
|
||||
try out_stream.print("\n", .{});
|
||||
if (printLineFromFileAnyOs(out_stream, line_info)) {
|
||||
if (line_info.column == 0) {
|
||||
try out_stream.write("\n");
|
||||
@ -546,13 +546,24 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
|
||||
else => return err,
|
||||
}
|
||||
} else {
|
||||
try out_stream.print("\n\n\n");
|
||||
try out_stream.print("\n\n\n", .{});
|
||||
}
|
||||
} else {
|
||||
if (opt_line_info) |li| {
|
||||
try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n\n\n", li.file_name, li.line, li.column, relocated_address, symbol_name, obj_basename);
|
||||
try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n\n\n", .{
|
||||
li.file_name,
|
||||
li.line,
|
||||
li.column,
|
||||
relocated_address,
|
||||
symbol_name,
|
||||
obj_basename,
|
||||
});
|
||||
} else {
|
||||
try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", relocated_address, symbol_name, obj_basename);
|
||||
try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", .{
|
||||
relocated_address,
|
||||
symbol_name,
|
||||
obj_basename,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -697,9 +708,9 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt
|
||||
|
||||
const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse {
|
||||
if (tty_color) {
|
||||
try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", address);
|
||||
try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", .{address});
|
||||
} else {
|
||||
try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", address);
|
||||
try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{address});
|
||||
}
|
||||
return;
|
||||
};
|
||||
@ -723,9 +734,11 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt
|
||||
} else |err| switch (err) {
|
||||
error.MissingDebugInfo, error.InvalidDebugInfo => {
|
||||
if (tty_color) {
|
||||
try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n\n\n", address, symbol_name, compile_unit_name);
|
||||
try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n\n\n", .{
|
||||
address, symbol_name, compile_unit_name,
|
||||
});
|
||||
} else {
|
||||
try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", address, symbol_name, compile_unit_name);
|
||||
try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", .{ address, symbol_name, compile_unit_name });
|
||||
}
|
||||
},
|
||||
else => return err,
|
||||
@ -746,15 +759,14 @@ fn printLineInfo(
|
||||
comptime printLineFromFile: var,
|
||||
) !void {
|
||||
if (tty_color) {
|
||||
try out_stream.print(
|
||||
WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n",
|
||||
try out_stream.print(WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n", .{
|
||||
line_info.file_name,
|
||||
line_info.line,
|
||||
line_info.column,
|
||||
address,
|
||||
symbol_name,
|
||||
compile_unit_name,
|
||||
);
|
||||
});
|
||||
if (printLineFromFile(out_stream, line_info)) {
|
||||
if (line_info.column == 0) {
|
||||
try out_stream.write("\n");
|
||||
@ -772,15 +784,14 @@ fn printLineInfo(
|
||||
else => return err,
|
||||
}
|
||||
} else {
|
||||
try out_stream.print(
|
||||
"{}:{}:{}: 0x{x} in {} ({})\n",
|
||||
try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n", .{
|
||||
line_info.file_name,
|
||||
line_info.line,
|
||||
line_info.column,
|
||||
address,
|
||||
symbol_name,
|
||||
compile_unit_name,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1226,9 +1237,9 @@ pub const DwarfInfo = struct {
|
||||
) !void {
|
||||
const compile_unit = self.findCompileUnit(address) catch {
|
||||
if (tty_color) {
|
||||
try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", address);
|
||||
try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", .{address});
|
||||
} else {
|
||||
try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", address);
|
||||
try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{address});
|
||||
}
|
||||
return;
|
||||
};
|
||||
@ -1248,9 +1259,11 @@ pub const DwarfInfo = struct {
|
||||
} else |err| switch (err) {
|
||||
error.MissingDebugInfo, error.InvalidDebugInfo => {
|
||||
if (tty_color) {
|
||||
try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? ({})" ++ RESET ++ "\n\n\n", address, compile_unit_name);
|
||||
try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? ({})" ++ RESET ++ "\n\n\n", .{
|
||||
address, compile_unit_name,
|
||||
});
|
||||
} else {
|
||||
try out_stream.print("???:?:?: 0x{x} in ??? ({})\n\n\n", address, compile_unit_name);
|
||||
try out_stream.print("???:?:?: 0x{x} in ??? ({})\n\n\n", .{ address, compile_unit_name });
|
||||
}
|
||||
},
|
||||
else => return err,
|
||||
@ -2416,7 +2429,7 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con
|
||||
resetSegfaultHandler();
|
||||
|
||||
const addr = @ptrToInt(info.fields.sigfault.addr);
|
||||
std.debug.warn("Segmentation fault at address 0x{x}\n", addr);
|
||||
std.debug.warn("Segmentation fault at address 0x{x}\n", .{addr});
|
||||
|
||||
switch (builtin.arch) {
|
||||
.i386 => {
|
||||
@ -2468,7 +2481,7 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void {
|
||||
const sp = asm (""
|
||||
: [argc] "={rsp}" (-> usize)
|
||||
);
|
||||
std.debug.warn("{} sp = 0x{x}\n", prefix, sp);
|
||||
std.debug.warn("{} sp = 0x{x}\n", .{ prefix, sp });
|
||||
}
|
||||
|
||||
// Reference everything so it gets tested.
|
||||
|
@ -294,14 +294,14 @@ test "std.event.Channel wraparound" {
|
||||
|
||||
const channel_size = 2;
|
||||
|
||||
var buf : [channel_size]i32 = undefined;
|
||||
var buf: [channel_size]i32 = undefined;
|
||||
var channel: Channel(i32) = undefined;
|
||||
channel.init(&buf);
|
||||
defer channel.deinit();
|
||||
|
||||
// add items to channel and pull them out until
|
||||
// the buffer wraps around, make sure it doesn't crash.
|
||||
var result : i32 = undefined;
|
||||
var result: i32 = undefined;
|
||||
channel.put(5);
|
||||
testing.expectEqual(@as(i32, 5), channel.get());
|
||||
channel.put(6);
|
||||
|
@ -293,7 +293,7 @@ pub fn LinearFifo(
|
||||
|
||||
pub usingnamespace if (T == u8)
|
||||
struct {
|
||||
pub fn print(self: *Self, comptime format: []const u8, args: ...) !void {
|
||||
pub fn print(self: *Self, comptime format: []const u8, args: var) !void {
|
||||
return std.fmt.format(self, error{OutOfMemory}, Self.write, format, args);
|
||||
}
|
||||
}
|
||||
@ -407,7 +407,7 @@ test "LinearFifo(u8, .Dynamic)" {
|
||||
fifo.shrink(0);
|
||||
|
||||
{
|
||||
try fifo.print("{}, {}!", "Hello", "World");
|
||||
try fifo.print("{}, {}!", .{ "Hello", "World" });
|
||||
var result: [30]u8 = undefined;
|
||||
testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);
|
||||
testing.expectEqual(@as(usize, 0), fifo.readableLength());
|
||||
|
220
lib/std/fmt.zig
220
lib/std/fmt.zig
@ -91,10 +91,12 @@ pub fn format(
|
||||
comptime Errors: type,
|
||||
output: fn (@typeOf(context), []const u8) Errors!void,
|
||||
comptime fmt: []const u8,
|
||||
args: ...,
|
||||
args: var,
|
||||
) Errors!void {
|
||||
const ArgSetType = @IntType(false, 32);
|
||||
if (args.len > ArgSetType.bit_count) {
|
||||
const args_fields = std.meta.fields(@typeOf(args));
|
||||
const args_len = args_fields.len;
|
||||
if (args_len > ArgSetType.bit_count) {
|
||||
@compileError("32 arguments max are supported per format call");
|
||||
}
|
||||
|
||||
@ -158,14 +160,14 @@ pub fn format(
|
||||
maybe_pos_arg.? += c - '0';
|
||||
specifier_start = i + 1;
|
||||
|
||||
if (maybe_pos_arg.? >= args.len) {
|
||||
if (maybe_pos_arg.? >= args_len) {
|
||||
@compileError("Positional value refers to non-existent argument");
|
||||
}
|
||||
},
|
||||
'}' => {
|
||||
const arg_to_print = comptime nextArg(&used_pos_args, maybe_pos_arg, &next_arg);
|
||||
|
||||
if (arg_to_print >= args.len) {
|
||||
if (arg_to_print >= args_len) {
|
||||
@compileError("Too few arguments");
|
||||
}
|
||||
|
||||
@ -302,7 +304,7 @@ pub fn format(
|
||||
used_pos_args |= 1 << i;
|
||||
}
|
||||
|
||||
if (@popCount(ArgSetType, used_pos_args) != args.len) {
|
||||
if (@popCount(ArgSetType, used_pos_args) != args_len) {
|
||||
@compileError("Unused arguments");
|
||||
}
|
||||
if (state != State.Start) {
|
||||
@ -389,7 +391,7 @@ pub fn formatType(
|
||||
}
|
||||
try output(context, " }");
|
||||
} else {
|
||||
try format(context, Errors, output, "@{x}", @ptrToInt(&value));
|
||||
try format(context, Errors, output, "@{x}", .{@ptrToInt(&value)});
|
||||
}
|
||||
},
|
||||
.Struct => {
|
||||
@ -421,12 +423,12 @@ pub fn formatType(
|
||||
if (info.child == u8) {
|
||||
return formatText(value, fmt, options, context, Errors, output);
|
||||
}
|
||||
return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value));
|
||||
return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
|
||||
},
|
||||
builtin.TypeId.Enum, builtin.TypeId.Union, builtin.TypeId.Struct => {
|
||||
return formatType(value.*, fmt, options, context, Errors, output, max_depth);
|
||||
},
|
||||
else => return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value)),
|
||||
else => return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }),
|
||||
},
|
||||
.Many => {
|
||||
if (ptr_info.child == u8) {
|
||||
@ -435,7 +437,7 @@ pub fn formatType(
|
||||
return formatText(value[0..len], fmt, options, context, Errors, output);
|
||||
}
|
||||
}
|
||||
return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value));
|
||||
return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
|
||||
},
|
||||
.Slice => {
|
||||
if (fmt.len > 0 and ((fmt[0] == 'x') or (fmt[0] == 'X'))) {
|
||||
@ -444,10 +446,10 @@ pub fn formatType(
|
||||
if (ptr_info.child == u8) {
|
||||
return formatText(value, fmt, options, context, Errors, output);
|
||||
}
|
||||
return format(context, Errors, output, "{}@{x}", @typeName(ptr_info.child), @ptrToInt(value.ptr));
|
||||
return format(context, Errors, output, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value.ptr) });
|
||||
},
|
||||
.C => {
|
||||
return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value));
|
||||
return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
|
||||
},
|
||||
},
|
||||
.Array => |info| {
|
||||
@ -465,7 +467,7 @@ pub fn formatType(
|
||||
return formatType(@as(Slice, &value), fmt, options, context, Errors, output, max_depth);
|
||||
},
|
||||
.Fn => {
|
||||
return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value));
|
||||
return format(context, Errors, output, "{}@{x}", .{ @typeName(T), @ptrToInt(value) });
|
||||
},
|
||||
else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"),
|
||||
}
|
||||
@ -1113,7 +1115,7 @@ pub const BufPrintError = error{
|
||||
/// As much as possible was written to the buffer, but it was too small to fit all the printed bytes.
|
||||
BufferTooSmall,
|
||||
};
|
||||
pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) BufPrintError![]u8 {
|
||||
pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: var) BufPrintError![]u8 {
|
||||
var context = BufPrintContext{ .remaining = buf };
|
||||
try format(&context, BufPrintError, bufPrintWrite, fmt, args);
|
||||
return buf[0 .. buf.len - context.remaining.len];
|
||||
@ -1121,7 +1123,7 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) BufPrintError![]
|
||||
|
||||
pub const AllocPrintError = error{OutOfMemory};
|
||||
|
||||
pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: ...) AllocPrintError![]u8 {
|
||||
pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: var) AllocPrintError![]u8 {
|
||||
var size: usize = 0;
|
||||
format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {};
|
||||
const buf = try allocator.alloc(u8, size);
|
||||
@ -1173,46 +1175,46 @@ test "parse unsigned comptime" {
|
||||
test "optional" {
|
||||
{
|
||||
const value: ?i32 = 1234;
|
||||
try testFmt("optional: 1234\n", "optional: {}\n", value);
|
||||
try testFmt("optional: 1234\n", "optional: {}\n", .{value});
|
||||
}
|
||||
{
|
||||
const value: ?i32 = null;
|
||||
try testFmt("optional: null\n", "optional: {}\n", value);
|
||||
try testFmt("optional: null\n", "optional: {}\n", .{value});
|
||||
}
|
||||
}
|
||||
|
||||
test "error" {
|
||||
{
|
||||
const value: anyerror!i32 = 1234;
|
||||
try testFmt("error union: 1234\n", "error union: {}\n", value);
|
||||
try testFmt("error union: 1234\n", "error union: {}\n", .{value});
|
||||
}
|
||||
{
|
||||
const value: anyerror!i32 = error.InvalidChar;
|
||||
try testFmt("error union: error.InvalidChar\n", "error union: {}\n", value);
|
||||
try testFmt("error union: error.InvalidChar\n", "error union: {}\n", .{value});
|
||||
}
|
||||
}
|
||||
|
||||
test "int.small" {
|
||||
{
|
||||
const value: u3 = 0b101;
|
||||
try testFmt("u3: 5\n", "u3: {}\n", value);
|
||||
try testFmt("u3: 5\n", "u3: {}\n", .{value});
|
||||
}
|
||||
}
|
||||
|
||||
test "int.specifier" {
|
||||
{
|
||||
const value: u8 = 'a';
|
||||
try testFmt("u8: a\n", "u8: {c}\n", value);
|
||||
try testFmt("u8: a\n", "u8: {c}\n", .{value});
|
||||
}
|
||||
{
|
||||
const value: u8 = 0b1100;
|
||||
try testFmt("u8: 0b1100\n", "u8: 0b{b}\n", value);
|
||||
try testFmt("u8: 0b1100\n", "u8: 0b{b}\n", .{value});
|
||||
}
|
||||
}
|
||||
|
||||
test "int.padded" {
|
||||
try testFmt("u8: ' 1'", "u8: '{:4}'", @as(u8, 1));
|
||||
try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", @as(u8, 1));
|
||||
try testFmt("u8: ' 1'", "u8: '{:4}'", .{@as(u8, 1)});
|
||||
try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", .{@as(u8, 1)});
|
||||
}
|
||||
|
||||
test "buffer" {
|
||||
@ -1238,14 +1240,14 @@ test "buffer" {
|
||||
test "array" {
|
||||
{
|
||||
const value: [3]u8 = "abc".*;
|
||||
try testFmt("array: abc\n", "array: {}\n", value);
|
||||
try testFmt("array: abc\n", "array: {}\n", &value);
|
||||
try testFmt("array: abc\n", "array: {}\n", .{value});
|
||||
try testFmt("array: abc\n", "array: {}\n", .{&value});
|
||||
|
||||
var buf: [100]u8 = undefined;
|
||||
try testFmt(
|
||||
try bufPrint(buf[0..], "array: [3]u8@{x}\n", @ptrToInt(&value)),
|
||||
try bufPrint(buf[0..], "array: [3]u8@{x}\n", .{@ptrToInt(&value)}),
|
||||
"array: {*}\n",
|
||||
&value,
|
||||
.{&value},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1253,36 +1255,36 @@ test "array" {
|
||||
test "slice" {
|
||||
{
|
||||
const value: []const u8 = "abc";
|
||||
try testFmt("slice: abc\n", "slice: {}\n", value);
|
||||
try testFmt("slice: abc\n", "slice: {}\n", .{value});
|
||||
}
|
||||
{
|
||||
const value = @intToPtr([*]const []const u8, 0xdeadbeef)[0..0];
|
||||
try testFmt("slice: []const u8@deadbeef\n", "slice: {}\n", value);
|
||||
try testFmt("slice: []const u8@deadbeef\n", "slice: {}\n", .{value});
|
||||
}
|
||||
|
||||
try testFmt("buf: Test \n", "buf: {s:5}\n", "Test");
|
||||
try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", "Test");
|
||||
try testFmt("buf: Test \n", "buf: {s:5}\n", .{"Test"});
|
||||
try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", .{"Test"});
|
||||
}
|
||||
|
||||
test "pointer" {
|
||||
{
|
||||
const value = @intToPtr(*i32, 0xdeadbeef);
|
||||
try testFmt("pointer: i32@deadbeef\n", "pointer: {}\n", value);
|
||||
try testFmt("pointer: i32@deadbeef\n", "pointer: {*}\n", value);
|
||||
try testFmt("pointer: i32@deadbeef\n", "pointer: {}\n", .{value});
|
||||
try testFmt("pointer: i32@deadbeef\n", "pointer: {*}\n", .{value});
|
||||
}
|
||||
{
|
||||
const value = @intToPtr(fn () void, 0xdeadbeef);
|
||||
try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value);
|
||||
try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});
|
||||
}
|
||||
{
|
||||
const value = @intToPtr(fn () void, 0xdeadbeef);
|
||||
try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value);
|
||||
try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});
|
||||
}
|
||||
}
|
||||
|
||||
test "cstr" {
|
||||
try testFmt("cstr: Test C\n", "cstr: {s}\n", "Test C");
|
||||
try testFmt("cstr: Test C \n", "cstr: {s:10}\n", "Test C");
|
||||
try testFmt("cstr: Test C\n", "cstr: {s}\n", .{"Test C"});
|
||||
try testFmt("cstr: Test C \n", "cstr: {s:10}\n", .{"Test C"});
|
||||
}
|
||||
|
||||
test "filesize" {
|
||||
@ -1290,8 +1292,8 @@ test "filesize" {
|
||||
// TODO https://github.com/ziglang/zig/issues/3289
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
try testFmt("file size: 63MiB\n", "file size: {Bi}\n", @as(usize, 63 * 1024 * 1024));
|
||||
try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", @as(usize, 63 * 1024 * 1024));
|
||||
try testFmt("file size: 63MiB\n", "file size: {Bi}\n", .{@as(usize, 63 * 1024 * 1024)});
|
||||
try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", .{@as(usize, 63 * 1024 * 1024)});
|
||||
}
|
||||
|
||||
test "struct" {
|
||||
@ -1300,8 +1302,8 @@ test "struct" {
|
||||
field: u8,
|
||||
};
|
||||
const value = Struct{ .field = 42 };
|
||||
try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", value);
|
||||
try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", &value);
|
||||
try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", .{value});
|
||||
try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", .{&value});
|
||||
}
|
||||
{
|
||||
const Struct = struct {
|
||||
@ -1309,7 +1311,7 @@ test "struct" {
|
||||
b: u1,
|
||||
};
|
||||
const value = Struct{ .a = 0, .b = 1 };
|
||||
try testFmt("struct: Struct{ .a = 0, .b = 1 }\n", "struct: {}\n", value);
|
||||
try testFmt("struct: Struct{ .a = 0, .b = 1 }\n", "struct: {}\n", .{value});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1319,8 +1321,8 @@ test "enum" {
|
||||
Two,
|
||||
};
|
||||
const value = Enum.Two;
|
||||
try testFmt("enum: Enum.Two\n", "enum: {}\n", value);
|
||||
try testFmt("enum: Enum.Two\n", "enum: {}\n", &value);
|
||||
try testFmt("enum: Enum.Two\n", "enum: {}\n", .{value});
|
||||
try testFmt("enum: Enum.Two\n", "enum: {}\n", .{&value});
|
||||
}
|
||||
|
||||
test "float.scientific" {
|
||||
@ -1328,10 +1330,10 @@ test "float.scientific" {
|
||||
// TODO https://github.com/ziglang/zig/issues/3289
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
try testFmt("f32: 1.34000003e+00", "f32: {e}", @as(f32, 1.34));
|
||||
try testFmt("f32: 1.23400001e+01", "f32: {e}", @as(f32, 12.34));
|
||||
try testFmt("f64: -1.234e+11", "f64: {e}", @as(f64, -12.34e10));
|
||||
try testFmt("f64: 9.99996e-40", "f64: {e}", @as(f64, 9.999960e-40));
|
||||
try testFmt("f32: 1.34000003e+00", "f32: {e}", .{@as(f32, 1.34)});
|
||||
try testFmt("f32: 1.23400001e+01", "f32: {e}", .{@as(f32, 12.34)});
|
||||
try testFmt("f64: -1.234e+11", "f64: {e}", .{@as(f64, -12.34e10)});
|
||||
try testFmt("f64: 9.99996e-40", "f64: {e}", .{@as(f64, 9.999960e-40)});
|
||||
}
|
||||
|
||||
test "float.scientific.precision" {
|
||||
@ -1339,12 +1341,12 @@ test "float.scientific.precision" {
|
||||
// TODO https://github.com/ziglang/zig/issues/3289
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
try testFmt("f64: 1.40971e-42", "f64: {e:.5}", @as(f64, 1.409706e-42));
|
||||
try testFmt("f64: 1.00000e-09", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 814313563))));
|
||||
try testFmt("f64: 7.81250e-03", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1006632960))));
|
||||
try testFmt("f64: 1.40971e-42", "f64: {e:.5}", .{@as(f64, 1.409706e-42)});
|
||||
try testFmt("f64: 1.00000e-09", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 814313563)))});
|
||||
try testFmt("f64: 7.81250e-03", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1006632960)))});
|
||||
// libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.
|
||||
// In fact, libc doesn't round a lot of 5 cases up when one past the precision point.
|
||||
try testFmt("f64: 1.00001e+05", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1203982400))));
|
||||
try testFmt("f64: 1.00001e+05", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1203982400)))});
|
||||
}
|
||||
|
||||
test "float.special" {
|
||||
@ -1352,14 +1354,14 @@ test "float.special" {
|
||||
// TODO https://github.com/ziglang/zig/issues/3289
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
try testFmt("f64: nan", "f64: {}", math.nan_f64);
|
||||
try testFmt("f64: nan", "f64: {}", .{math.nan_f64});
|
||||
// negative nan is not defined by IEE 754,
|
||||
// and ARM thus normalizes it to positive nan
|
||||
if (builtin.arch != builtin.Arch.arm) {
|
||||
try testFmt("f64: -nan", "f64: {}", -math.nan_f64);
|
||||
try testFmt("f64: -nan", "f64: {}", .{-math.nan_f64});
|
||||
}
|
||||
try testFmt("f64: inf", "f64: {}", math.inf_f64);
|
||||
try testFmt("f64: -inf", "f64: {}", -math.inf_f64);
|
||||
try testFmt("f64: inf", "f64: {}", .{math.inf_f64});
|
||||
try testFmt("f64: -inf", "f64: {}", .{-math.inf_f64});
|
||||
}
|
||||
|
||||
test "float.decimal" {
|
||||
@ -1367,21 +1369,21 @@ test "float.decimal" {
|
||||
// TODO https://github.com/ziglang/zig/issues/3289
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29));
|
||||
try testFmt("f32: 1.1", "f32: {d:.1}", @as(f32, 1.1234));
|
||||
try testFmt("f32: 1234.57", "f32: {d:.2}", @as(f32, 1234.567));
|
||||
try testFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e+29)});
|
||||
try testFmt("f32: 1.1", "f32: {d:.1}", .{@as(f32, 1.1234)});
|
||||
try testFmt("f32: 1234.57", "f32: {d:.2}", .{@as(f32, 1234.567)});
|
||||
// -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
|
||||
// -11.12339... is rounded back up to -11.1234
|
||||
try testFmt("f32: -11.1234", "f32: {d:.4}", @as(f32, -11.1234));
|
||||
try testFmt("f32: 91.12345", "f32: {d:.5}", @as(f32, 91.12345));
|
||||
try testFmt("f64: 91.1234567890", "f64: {d:.10}", @as(f64, 91.12345678901235));
|
||||
try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 0.0));
|
||||
try testFmt("f64: 6", "f64: {d:.0}", @as(f64, 5.700));
|
||||
try testFmt("f64: 10.0", "f64: {d:.1}", @as(f64, 9.999));
|
||||
try testFmt("f64: 1.000", "f64: {d:.3}", @as(f64, 1.0));
|
||||
try testFmt("f64: 0.00030000", "f64: {d:.8}", @as(f64, 0.0003));
|
||||
try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 1.40130e-45));
|
||||
try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 9.999960e-40));
|
||||
try testFmt("f32: -11.1234", "f32: {d:.4}", .{@as(f32, -11.1234)});
|
||||
try testFmt("f32: 91.12345", "f32: {d:.5}", .{@as(f32, 91.12345)});
|
||||
try testFmt("f64: 91.1234567890", "f64: {d:.10}", .{@as(f64, 91.12345678901235)});
|
||||
try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 0.0)});
|
||||
try testFmt("f64: 6", "f64: {d:.0}", .{@as(f64, 5.700)});
|
||||
try testFmt("f64: 10.0", "f64: {d:.1}", .{@as(f64, 9.999)});
|
||||
try testFmt("f64: 1.000", "f64: {d:.3}", .{@as(f64, 1.0)});
|
||||
try testFmt("f64: 0.00030000", "f64: {d:.8}", .{@as(f64, 0.0003)});
|
||||
try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 1.40130e-45)});
|
||||
try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 9.999960e-40)});
|
||||
}
|
||||
|
||||
test "float.libc.sanity" {
|
||||
@ -1389,22 +1391,22 @@ test "float.libc.sanity" {
|
||||
// TODO https://github.com/ziglang/zig/issues/3289
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 916964781))));
|
||||
try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 925353389))));
|
||||
try testFmt("f64: 0.10000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1036831278))));
|
||||
try testFmt("f64: 1.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1065353133))));
|
||||
try testFmt("f64: 10.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1092616192))));
|
||||
try testFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 916964781)))});
|
||||
try testFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 925353389)))});
|
||||
try testFmt("f64: 0.10000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1036831278)))});
|
||||
try testFmt("f64: 1.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1065353133)))});
|
||||
try testFmt("f64: 10.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1092616192)))});
|
||||
|
||||
// libc differences
|
||||
//
|
||||
// This is 0.015625 exactly according to gdb. We thus round down,
|
||||
// however glibc rounds up for some reason. This occurs for all
|
||||
// floats of the form x.yyyy25 on a precision point.
|
||||
try testFmt("f64: 0.01563", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1015021568))));
|
||||
try testFmt("f64: 0.01563", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1015021568)))});
|
||||
// errol3 rounds to ... 630 but libc rounds to ...632. Grisu3
|
||||
// also rounds to 630 so I'm inclined to believe libc is not
|
||||
// optimal here.
|
||||
try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1518338049))));
|
||||
try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1518338049)))});
|
||||
}
|
||||
|
||||
test "custom" {
|
||||
@ -1422,9 +1424,9 @@ test "custom" {
|
||||
output: fn (@typeOf(context), []const u8) Errors!void,
|
||||
) Errors!void {
|
||||
if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) {
|
||||
return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", self.x, self.y);
|
||||
return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y });
|
||||
} else if (comptime std.mem.eql(u8, fmt, "d")) {
|
||||
return std.fmt.format(context, Errors, output, "{d:.3}x{d:.3}", self.x, self.y);
|
||||
return std.fmt.format(context, Errors, output, "{d:.3}x{d:.3}", .{ self.x, self.y });
|
||||
} else {
|
||||
@compileError("Unknown format character: '" ++ fmt ++ "'");
|
||||
}
|
||||
@ -1436,12 +1438,12 @@ test "custom" {
|
||||
.x = 10.2,
|
||||
.y = 2.22,
|
||||
};
|
||||
try testFmt("point: (10.200,2.220)\n", "point: {}\n", &value);
|
||||
try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", &value);
|
||||
try testFmt("point: (10.200,2.220)\n", "point: {}\n", .{&value});
|
||||
try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", .{&value});
|
||||
|
||||
// same thing but not passing a pointer
|
||||
try testFmt("point: (10.200,2.220)\n", "point: {}\n", value);
|
||||
try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", value);
|
||||
try testFmt("point: (10.200,2.220)\n", "point: {}\n", .{value});
|
||||
try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", .{value});
|
||||
}
|
||||
|
||||
test "struct" {
|
||||
@ -1455,7 +1457,7 @@ test "struct" {
|
||||
.b = error.Unused,
|
||||
};
|
||||
|
||||
try testFmt("S{ .a = 456, .b = error.Unused }", "{}", inst);
|
||||
try testFmt("S{ .a = 456, .b = error.Unused }", "{}", .{inst});
|
||||
}
|
||||
|
||||
test "union" {
|
||||
@ -1478,13 +1480,13 @@ test "union" {
|
||||
const uu_inst = UU{ .int = 456 };
|
||||
const eu_inst = EU{ .float = 321.123 };
|
||||
|
||||
try testFmt("TU{ .int = 123 }", "{}", tu_inst);
|
||||
try testFmt("TU{ .int = 123 }", "{}", .{tu_inst});
|
||||
|
||||
var buf: [100]u8 = undefined;
|
||||
const uu_result = try bufPrint(buf[0..], "{}", uu_inst);
|
||||
const uu_result = try bufPrint(buf[0..], "{}", .{uu_inst});
|
||||
std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));
|
||||
|
||||
const eu_result = try bufPrint(buf[0..], "{}", eu_inst);
|
||||
const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst});
|
||||
std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@"));
|
||||
}
|
||||
|
||||
@ -1497,7 +1499,7 @@ test "enum" {
|
||||
|
||||
const inst = E.Two;
|
||||
|
||||
try testFmt("E.Two", "{}", inst);
|
||||
try testFmt("E.Two", "{}", .{inst});
|
||||
}
|
||||
|
||||
test "struct.self-referential" {
|
||||
@ -1511,7 +1513,7 @@ test "struct.self-referential" {
|
||||
};
|
||||
inst.a = &inst;
|
||||
|
||||
try testFmt("S{ .a = S{ .a = S{ .a = S{ ... } } } }", "{}", inst);
|
||||
try testFmt("S{ .a = S{ .a = S{ .a = S{ ... } } } }", "{}", .{inst});
|
||||
}
|
||||
|
||||
test "struct.zero-size" {
|
||||
@ -1526,30 +1528,30 @@ test "struct.zero-size" {
|
||||
const a = A{};
|
||||
const b = B{ .a = a, .c = 0 };
|
||||
|
||||
try testFmt("B{ .a = A{ }, .c = 0 }", "{}", b);
|
||||
try testFmt("B{ .a = A{ }, .c = 0 }", "{}", .{b});
|
||||
}
|
||||
|
||||
test "bytes.hex" {
|
||||
const some_bytes = "\xCA\xFE\xBA\xBE";
|
||||
try testFmt("lowercase: cafebabe\n", "lowercase: {x}\n", some_bytes);
|
||||
try testFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", some_bytes);
|
||||
try testFmt("lowercase: cafebabe\n", "lowercase: {x}\n", .{some_bytes});
|
||||
try testFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", .{some_bytes});
|
||||
//Test Slices
|
||||
try testFmt("uppercase: CAFE\n", "uppercase: {X}\n", some_bytes[0..2]);
|
||||
try testFmt("lowercase: babe\n", "lowercase: {x}\n", some_bytes[2..]);
|
||||
try testFmt("uppercase: CAFE\n", "uppercase: {X}\n", .{some_bytes[0..2]});
|
||||
try testFmt("lowercase: babe\n", "lowercase: {x}\n", .{some_bytes[2..]});
|
||||
const bytes_with_zeros = "\x00\x0E\xBA\xBE";
|
||||
try testFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", bytes_with_zeros);
|
||||
try testFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{bytes_with_zeros});
|
||||
}
|
||||
|
||||
fn testFmt(expected: []const u8, comptime template: []const u8, args: ...) !void {
|
||||
fn testFmt(expected: []const u8, comptime template: []const u8, args: var) !void {
|
||||
var buf: [100]u8 = undefined;
|
||||
const result = try bufPrint(buf[0..], template, args);
|
||||
if (mem.eql(u8, result, expected)) return;
|
||||
|
||||
std.debug.warn("\n====== expected this output: =========\n");
|
||||
std.debug.warn("{}", expected);
|
||||
std.debug.warn("\n======== instead found this: =========\n");
|
||||
std.debug.warn("{}", result);
|
||||
std.debug.warn("\n======================================\n");
|
||||
std.debug.warn("\n====== expected this output: =========\n", .{});
|
||||
std.debug.warn("{}", .{expected});
|
||||
std.debug.warn("\n======== instead found this: =========\n", .{});
|
||||
std.debug.warn("{}", .{result});
|
||||
std.debug.warn("\n======================================\n", .{});
|
||||
return error.TestFailed;
|
||||
}
|
||||
|
||||
@ -1602,7 +1604,7 @@ test "hexToBytes" {
|
||||
const test_hex_str = "909A312BB12ED1F819B3521AC4C1E896F2160507FFC1C8381E3B07BB16BD1706";
|
||||
var pb: [32]u8 = undefined;
|
||||
try hexToBytes(pb[0..], test_hex_str);
|
||||
try testFmt(test_hex_str, "{X}", pb);
|
||||
try testFmt(test_hex_str, "{X}", .{pb});
|
||||
}
|
||||
|
||||
test "formatIntValue with comptime_int" {
|
||||
@ -1628,7 +1630,7 @@ test "formatType max_depth" {
|
||||
output: fn (@typeOf(context), []const u8) Errors!void,
|
||||
) Errors!void {
|
||||
if (fmt.len == 0) {
|
||||
return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", self.x, self.y);
|
||||
return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y });
|
||||
} else {
|
||||
@compileError("Unknown format string: '" ++ fmt ++ "'");
|
||||
}
|
||||
@ -1680,17 +1682,17 @@ test "formatType max_depth" {
|
||||
}
|
||||
|
||||
test "positional" {
|
||||
try testFmt("2 1 0", "{2} {1} {0}", @as(usize, 0), @as(usize, 1), @as(usize, 2));
|
||||
try testFmt("2 1 0", "{2} {1} {}", @as(usize, 0), @as(usize, 1), @as(usize, 2));
|
||||
try testFmt("0 0", "{0} {0}", @as(usize, 0));
|
||||
try testFmt("0 1", "{} {1}", @as(usize, 0), @as(usize, 1));
|
||||
try testFmt("1 0 0 1", "{1} {} {0} {}", @as(usize, 0), @as(usize, 1));
|
||||
try testFmt("2 1 0", "{2} {1} {0}", .{ @as(usize, 0), @as(usize, 1), @as(usize, 2) });
|
||||
try testFmt("2 1 0", "{2} {1} {}", .{ @as(usize, 0), @as(usize, 1), @as(usize, 2) });
|
||||
try testFmt("0 0", "{0} {0}", .{@as(usize, 0)});
|
||||
try testFmt("0 1", "{} {1}", .{ @as(usize, 0), @as(usize, 1) });
|
||||
try testFmt("1 0 0 1", "{1} {} {0} {}", .{ @as(usize, 0), @as(usize, 1) });
|
||||
}
|
||||
|
||||
test "positional with specifier" {
|
||||
try testFmt("10.0", "{0d:.1}", @as(f64, 9.999));
|
||||
try testFmt("10.0", "{0d:.1}", .{@as(f64, 9.999)});
|
||||
}
|
||||
|
||||
test "positional/alignment/width/precision" {
|
||||
try testFmt("10.0", "{0d: >3.1}", @as(f64, 9.999));
|
||||
try testFmt("10.0", "{0d: >3.1}", .{@as(f64, 9.999)});
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ fn usage() void {
|
||||
\\ --iterative-only
|
||||
\\ --help
|
||||
\\
|
||||
);
|
||||
, .{});
|
||||
}
|
||||
|
||||
fn mode(comptime x: comptime_int) comptime_int {
|
||||
|
@ -610,5 +610,5 @@ test "Headers.format" {
|
||||
\\foo: bar
|
||||
\\cookie: somevalue
|
||||
\\
|
||||
, try std.fmt.bufPrint(buf[0..], "{}", h));
|
||||
, try std.fmt.bufPrint(buf[0..], "{}", .{h}));
|
||||
}
|
||||
|
@ -492,7 +492,7 @@ test "io.SliceOutStream" {
|
||||
var slice_stream = SliceOutStream.init(buf[0..]);
|
||||
const stream = &slice_stream.stream;
|
||||
|
||||
try stream.print("{}{}!", "Hello", "World");
|
||||
try stream.print("{}{}!", .{ "Hello", "World" });
|
||||
testing.expectEqualSlices(u8, "HelloWorld!", slice_stream.getWritten());
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ pub fn OutStream(comptime WriteError: type) type {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print(self: *Self, comptime format: []const u8, args: ...) Error!void {
|
||||
pub fn print(self: *Self, comptime format: []const u8, args: var) Error!void {
|
||||
return std.fmt.format(self, Error, self.writeFn, format, args);
|
||||
}
|
||||
|
||||
|
@ -27,9 +27,9 @@ test "write a file, read it, then delete it" {
|
||||
var file_out_stream = file.outStream();
|
||||
var buf_stream = io.BufferedOutStream(File.WriteError).init(&file_out_stream.stream);
|
||||
const st = &buf_stream.stream;
|
||||
try st.print("begin");
|
||||
try st.print("begin", .{});
|
||||
try st.write(data[0..]);
|
||||
try st.print("end");
|
||||
try st.print("end", .{});
|
||||
try buf_stream.flush();
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ test "BufferOutStream" {
|
||||
|
||||
const x: i32 = 42;
|
||||
const y: i32 = 1234;
|
||||
try buf_stream.print("x: {}\ny: {}\n", x, y);
|
||||
try buf_stream.print("x: {}\ny: {}\n", .{ x, y });
|
||||
|
||||
expect(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n"));
|
||||
}
|
||||
@ -605,7 +605,7 @@ test "c out stream" {
|
||||
}
|
||||
|
||||
const out_stream = &io.COutStream.init(out_file).stream;
|
||||
try out_stream.print("hi: {}\n", @as(i32, 123));
|
||||
try out_stream.print("hi: {}\n", .{@as(i32, 123)});
|
||||
}
|
||||
|
||||
test "File seek ops" {
|
||||
|
@ -158,24 +158,24 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
|
||||
switch (@typeInfo(@typeOf(value))) {
|
||||
.Int => |info| {
|
||||
if (info.bits < 53) {
|
||||
try self.stream.print("{}", value);
|
||||
try self.stream.print("{}", .{value});
|
||||
self.popState();
|
||||
return;
|
||||
}
|
||||
if (value < 4503599627370496 and (!info.is_signed or value > -4503599627370496)) {
|
||||
try self.stream.print("{}", value);
|
||||
try self.stream.print("{}", .{value});
|
||||
self.popState();
|
||||
return;
|
||||
}
|
||||
},
|
||||
.Float => if (@floatCast(f64, value) == value) {
|
||||
try self.stream.print("{}", value);
|
||||
try self.stream.print("{}", .{value});
|
||||
self.popState();
|
||||
return;
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
try self.stream.print("\"{}\"", value);
|
||||
try self.stream.print("\"{}\"", .{value});
|
||||
self.popState();
|
||||
}
|
||||
|
||||
|
@ -180,9 +180,9 @@ pub const Int = struct {
|
||||
|
||||
pub fn dump(self: Int) void {
|
||||
for (self.limbs) |limb| {
|
||||
debug.warn("{x} ", limb);
|
||||
debug.warn("{x} ", .{limb});
|
||||
}
|
||||
debug.warn("\n");
|
||||
debug.warn("\n", .{});
|
||||
}
|
||||
|
||||
/// Negate the sign of an Int.
|
||||
|
@ -277,32 +277,24 @@ pub const Address = extern union {
|
||||
os.AF_INET => {
|
||||
const port = mem.bigToNative(u16, self.in.port);
|
||||
const bytes = @ptrCast(*const [4]u8, &self.in.addr);
|
||||
try std.fmt.format(
|
||||
context,
|
||||
Errors,
|
||||
output,
|
||||
"{}.{}.{}.{}:{}",
|
||||
try std.fmt.format(context, Errors, output, "{}.{}.{}.{}:{}", .{
|
||||
bytes[0],
|
||||
bytes[1],
|
||||
bytes[2],
|
||||
bytes[3],
|
||||
port,
|
||||
);
|
||||
});
|
||||
},
|
||||
os.AF_INET6 => {
|
||||
const port = mem.bigToNative(u16, self.in6.port);
|
||||
if (mem.eql(u8, self.in6.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
|
||||
try std.fmt.format(
|
||||
context,
|
||||
Errors,
|
||||
output,
|
||||
"[::ffff:{}.{}.{}.{}]:{}",
|
||||
try std.fmt.format(context, Errors, output, "[::ffff:{}.{}.{}.{}]:{}", .{
|
||||
self.in6.addr[12],
|
||||
self.in6.addr[13],
|
||||
self.in6.addr[14],
|
||||
self.in6.addr[15],
|
||||
port,
|
||||
);
|
||||
});
|
||||
return;
|
||||
}
|
||||
const big_endian_parts = @ptrCast(*align(1) const [8]u16, &self.in6.addr);
|
||||
@ -327,19 +319,19 @@ pub const Address = extern union {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
try std.fmt.format(context, Errors, output, "{x}", native_endian_parts[i]);
|
||||
try std.fmt.format(context, Errors, output, "{x}", .{native_endian_parts[i]});
|
||||
if (i != native_endian_parts.len - 1) {
|
||||
try output(context, ":");
|
||||
}
|
||||
}
|
||||
try std.fmt.format(context, Errors, output, "]:{}", port);
|
||||
try std.fmt.format(context, Errors, output, "]:{}", .{port});
|
||||
},
|
||||
os.AF_UNIX => {
|
||||
if (!has_unix_sockets) {
|
||||
unreachable;
|
||||
}
|
||||
|
||||
try std.fmt.format(context, Errors, output, "{}", &self.un.path);
|
||||
try std.fmt.format(context, Errors, output, "{}", .{&self.un.path});
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ test "parse and render IPv6 addresses" {
|
||||
};
|
||||
for (ips) |ip, i| {
|
||||
var addr = net.Address.parseIp6(ip, 0) catch unreachable;
|
||||
var newIp = std.fmt.bufPrint(buffer[0..], "{}", addr) catch unreachable;
|
||||
var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
|
||||
std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ test "parse and render IPv4 addresses" {
|
||||
"127.0.0.1",
|
||||
}) |ip| {
|
||||
var addr = net.Address.parseIp4(ip, 0) catch unreachable;
|
||||
var newIp = std.fmt.bufPrint(buffer[0..], "{}", addr) catch unreachable;
|
||||
var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
|
||||
std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));
|
||||
}
|
||||
|
||||
@ -118,5 +118,5 @@ fn testServer(server: *net.StreamServer) anyerror!void {
|
||||
var client = try server.accept();
|
||||
|
||||
const stream = &client.file.outStream().stream;
|
||||
try stream.print("hello from server\n");
|
||||
try stream.print("hello from server\n", .{});
|
||||
}
|
||||
|
@ -2603,7 +2603,7 @@ pub fn realpathC(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
|
||||
defer close(fd);
|
||||
|
||||
var procfs_buf: ["/proc/self/fd/-2147483648".len:0]u8 = undefined;
|
||||
const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{}\x00", fd) catch unreachable;
|
||||
const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{}\x00", .{fd}) catch unreachable;
|
||||
|
||||
return readlinkC(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer);
|
||||
}
|
||||
@ -2832,7 +2832,7 @@ pub const UnexpectedError = error{
|
||||
/// and you get an unexpected error.
|
||||
pub fn unexpectedErrno(err: usize) UnexpectedError {
|
||||
if (unexpected_error_tracing) {
|
||||
std.debug.warn("unexpected errno: {}\n", err);
|
||||
std.debug.warn("unexpected errno: {}\n", .{err});
|
||||
std.debug.dumpCurrentStackTrace(null);
|
||||
}
|
||||
return error.Unexpected;
|
||||
|
@ -1039,7 +1039,7 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError {
|
||||
var buf_u8: [614]u8 = undefined;
|
||||
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);
|
||||
_ = std.unicode.utf16leToUtf8(&buf_u8, buf_u16[0..len]) catch unreachable;
|
||||
std.debug.warn("error.Unexpected: GetLastError({}): {}\n", err, buf_u8[0..len]);
|
||||
std.debug.warn("error.Unexpected: GetLastError({}): {}\n", .{ err, buf_u8[0..len] });
|
||||
std.debug.dumpCurrentStackTrace(null);
|
||||
}
|
||||
return error.Unexpected;
|
||||
@ -1053,7 +1053,7 @@ pub fn unexpectedWSAError(err: c_int) std.os.UnexpectedError {
|
||||
/// and you get an unexpected status.
|
||||
pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError {
|
||||
if (std.os.unexpected_error_tracing) {
|
||||
std.debug.warn("error.Unexpected NTSTATUS=0x{x}\n", status);
|
||||
std.debug.warn("error.Unexpected NTSTATUS=0x{x}\n", .{status});
|
||||
std.debug.dumpCurrentStackTrace(null);
|
||||
}
|
||||
return error.Unexpected;
|
||||
|
@ -1,260 +0,0 @@
|
||||
const std = @import("../std.zig");
|
||||
const assert = std.debug.assert;
|
||||
|
||||
//////////////////////////
|
||||
//// IPC structures ////
|
||||
//////////////////////////
|
||||
|
||||
pub const Message = struct {
|
||||
sender: MailboxId,
|
||||
receiver: MailboxId,
|
||||
code: usize,
|
||||
args: [5]usize,
|
||||
payload: ?[]const u8,
|
||||
|
||||
pub fn from(mailbox_id: MailboxId) Message {
|
||||
return Message{
|
||||
.sender = MailboxId.Undefined,
|
||||
.receiver = mailbox_id,
|
||||
.code = undefined,
|
||||
.args = undefined,
|
||||
.payload = null,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn to(mailbox_id: MailboxId, msg_code: usize, args: ...) Message {
|
||||
var message = Message{
|
||||
.sender = MailboxId.This,
|
||||
.receiver = mailbox_id,
|
||||
.code = msg_code,
|
||||
.args = undefined,
|
||||
.payload = null,
|
||||
};
|
||||
|
||||
assert(args.len <= message.args.len);
|
||||
comptime var i = 0;
|
||||
inline while (i < args.len) : (i += 1) {
|
||||
message.args[i] = args[i];
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
pub fn as(self: Message, sender: MailboxId) Message {
|
||||
var message = self;
|
||||
message.sender = sender;
|
||||
return message;
|
||||
}
|
||||
|
||||
pub fn withPayload(self: Message, payload: []const u8) Message {
|
||||
var message = self;
|
||||
message.payload = payload;
|
||||
return message;
|
||||
}
|
||||
};
|
||||
|
||||
pub const MailboxId = union(enum) {
|
||||
Undefined,
|
||||
This,
|
||||
Kernel,
|
||||
Port: u16,
|
||||
Thread: u16,
|
||||
};
|
||||
|
||||
//////////////////////////////////////
|
||||
//// Ports reserved for servers ////
|
||||
//////////////////////////////////////
|
||||
|
||||
pub const Server = struct {
|
||||
pub const Keyboard = MailboxId{ .Port = 0 };
|
||||
pub const Terminal = MailboxId{ .Port = 1 };
|
||||
};
|
||||
|
||||
////////////////////////
|
||||
//// POSIX things ////
|
||||
////////////////////////
|
||||
|
||||
// Standard streams.
|
||||
pub const STDIN_FILENO = 0;
|
||||
pub const STDOUT_FILENO = 1;
|
||||
pub const STDERR_FILENO = 2;
|
||||
|
||||
// FIXME: let's borrow Linux's error numbers for now.
|
||||
usingnamespace @import("bits/linux/errno-generic.zig");
|
||||
// Get the errno from a syscall return value, or 0 for no error.
|
||||
pub fn getErrno(r: usize) usize {
|
||||
const signed_r = @bitCast(isize, r);
|
||||
return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0;
|
||||
}
|
||||
|
||||
// TODO: implement this correctly.
|
||||
pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
|
||||
switch (fd) {
|
||||
STDIN_FILENO => {
|
||||
var i: usize = 0;
|
||||
while (i < count) : (i += 1) {
|
||||
send(&Message.to(Server.Keyboard, 0));
|
||||
|
||||
// FIXME: we should be certain that we are receiving from Keyboard.
|
||||
var message = Message.from(MailboxId.This);
|
||||
receive(&message);
|
||||
|
||||
buf[i] = @intCast(u8, message.args[0]);
|
||||
}
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// TODO: implement this correctly.
|
||||
pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
|
||||
switch (fd) {
|
||||
STDOUT_FILENO, STDERR_FILENO => {
|
||||
send(&Message.to(Server.Terminal, 1).withPayload(buf[0..count]));
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
//// Syscall numbers ////
|
||||
///////////////////////////
|
||||
|
||||
pub const Syscall = enum(usize) {
|
||||
exit = 0,
|
||||
send = 1,
|
||||
receive = 2,
|
||||
subscribeIRQ = 3,
|
||||
inb = 4,
|
||||
outb = 5,
|
||||
map = 6,
|
||||
createThread = 7,
|
||||
};
|
||||
|
||||
////////////////////
|
||||
//// Syscalls ////
|
||||
////////////////////
|
||||
|
||||
pub fn exit(status: i32) noreturn {
|
||||
_ = syscall1(Syscall.exit, @bitCast(usize, @as(isize, status)));
|
||||
unreachable;
|
||||
}
|
||||
|
||||
pub fn send(message: *const Message) void {
|
||||
_ = syscall1(Syscall.send, @ptrToInt(message));
|
||||
}
|
||||
|
||||
pub fn receive(destination: *Message) void {
|
||||
_ = syscall1(Syscall.receive, @ptrToInt(destination));
|
||||
}
|
||||
|
||||
pub fn subscribeIRQ(irq: u8, mailbox_id: *const MailboxId) void {
|
||||
_ = syscall2(Syscall.subscribeIRQ, irq, @ptrToInt(mailbox_id));
|
||||
}
|
||||
|
||||
pub fn inb(port: u16) u8 {
|
||||
return @intCast(u8, syscall1(Syscall.inb, port));
|
||||
}
|
||||
|
||||
pub fn outb(port: u16, value: u8) void {
|
||||
_ = syscall2(Syscall.outb, port, value);
|
||||
}
|
||||
|
||||
pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {
|
||||
return syscall4(Syscall.map, v_addr, p_addr, size, @boolToInt(writable)) != 0;
|
||||
}
|
||||
|
||||
pub fn createThread(function: fn () void) u16 {
|
||||
return @as(u16, syscall1(Syscall.createThread, @ptrToInt(function)));
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
//// Syscall stubs ////
|
||||
/////////////////////////
|
||||
|
||||
inline fn syscall0(number: Syscall) usize {
|
||||
return asm volatile ("int $0x80"
|
||||
: [ret] "={eax}" (-> usize)
|
||||
: [number] "{eax}" (number)
|
||||
);
|
||||
}
|
||||
|
||||
inline fn syscall1(number: Syscall, arg1: usize) usize {
|
||||
return asm volatile ("int $0x80"
|
||||
: [ret] "={eax}" (-> usize)
|
||||
: [number] "{eax}" (number),
|
||||
[arg1] "{ecx}" (arg1)
|
||||
);
|
||||
}
|
||||
|
||||
inline fn syscall2(number: Syscall, arg1: usize, arg2: usize) usize {
|
||||
return asm volatile ("int $0x80"
|
||||
: [ret] "={eax}" (-> usize)
|
||||
: [number] "{eax}" (number),
|
||||
[arg1] "{ecx}" (arg1),
|
||||
[arg2] "{edx}" (arg2)
|
||||
);
|
||||
}
|
||||
|
||||
inline fn syscall3(number: Syscall, arg1: usize, arg2: usize, arg3: usize) usize {
|
||||
return asm volatile ("int $0x80"
|
||||
: [ret] "={eax}" (-> usize)
|
||||
: [number] "{eax}" (number),
|
||||
[arg1] "{ecx}" (arg1),
|
||||
[arg2] "{edx}" (arg2),
|
||||
[arg3] "{ebx}" (arg3)
|
||||
);
|
||||
}
|
||||
|
||||
inline fn syscall4(number: Syscall, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
|
||||
return asm volatile ("int $0x80"
|
||||
: [ret] "={eax}" (-> usize)
|
||||
: [number] "{eax}" (number),
|
||||
[arg1] "{ecx}" (arg1),
|
||||
[arg2] "{edx}" (arg2),
|
||||
[arg3] "{ebx}" (arg3),
|
||||
[arg4] "{esi}" (arg4)
|
||||
);
|
||||
}
|
||||
|
||||
inline fn syscall5(
|
||||
number: Syscall,
|
||||
arg1: usize,
|
||||
arg2: usize,
|
||||
arg3: usize,
|
||||
arg4: usize,
|
||||
arg5: usize,
|
||||
) usize {
|
||||
return asm volatile ("int $0x80"
|
||||
: [ret] "={eax}" (-> usize)
|
||||
: [number] "{eax}" (number),
|
||||
[arg1] "{ecx}" (arg1),
|
||||
[arg2] "{edx}" (arg2),
|
||||
[arg3] "{ebx}" (arg3),
|
||||
[arg4] "{esi}" (arg4),
|
||||
[arg5] "{edi}" (arg5)
|
||||
);
|
||||
}
|
||||
|
||||
inline fn syscall6(
|
||||
number: Syscall,
|
||||
arg1: usize,
|
||||
arg2: usize,
|
||||
arg3: usize,
|
||||
arg4: usize,
|
||||
arg5: usize,
|
||||
arg6: usize,
|
||||
) usize {
|
||||
return asm volatile ("int $0x80"
|
||||
: [ret] "={eax}" (-> usize)
|
||||
: [number] "{eax}" (number),
|
||||
[arg1] "{ecx}" (arg1),
|
||||
[arg2] "{edx}" (arg2),
|
||||
[arg3] "{ebx}" (arg3),
|
||||
[arg4] "{esi}" (arg4),
|
||||
[arg5] "{edi}" (arg5),
|
||||
[arg6] "{ebp}" (arg6)
|
||||
);
|
||||
}
|
@ -199,19 +199,19 @@ pub fn PriorityQueue(comptime T: type) type {
|
||||
}
|
||||
|
||||
fn dump(self: *Self) void {
|
||||
warn("{{ ");
|
||||
warn("items: ");
|
||||
warn("{{ ", .{});
|
||||
warn("items: ", .{});
|
||||
for (self.items) |e, i| {
|
||||
if (i >= self.len) break;
|
||||
warn("{}, ", e);
|
||||
warn("{}, ", .{e});
|
||||
}
|
||||
warn("array: ");
|
||||
warn("array: ", .{});
|
||||
for (self.items) |e, i| {
|
||||
warn("{}, ", e);
|
||||
warn("{}, ", .{e});
|
||||
}
|
||||
warn("len: {} ", self.len);
|
||||
warn("capacity: {}", self.capacity());
|
||||
warn(" }}\n");
|
||||
warn("len: {} ", .{self.len});
|
||||
warn("capacity: {}", .{self.capacity()});
|
||||
warn(" }}\n", .{});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -130,11 +130,11 @@ pub const Progress = struct {
|
||||
var end: usize = 0;
|
||||
if (self.columns_written > 0) {
|
||||
// restore cursor position
|
||||
end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{}D", self.columns_written) catch unreachable).len;
|
||||
end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{}D", .{self.columns_written}) catch unreachable).len;
|
||||
self.columns_written = 0;
|
||||
|
||||
// clear rest of line
|
||||
end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K") catch unreachable).len;
|
||||
end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K", .{}) catch unreachable).len;
|
||||
}
|
||||
|
||||
if (!self.done) {
|
||||
@ -142,28 +142,28 @@ pub const Progress = struct {
|
||||
var maybe_node: ?*Node = &self.root;
|
||||
while (maybe_node) |node| {
|
||||
if (need_ellipse) {
|
||||
self.bufWrite(&end, "...");
|
||||
self.bufWrite(&end, "...", .{});
|
||||
}
|
||||
need_ellipse = false;
|
||||
if (node.name.len != 0 or node.estimated_total_items != null) {
|
||||
if (node.name.len != 0) {
|
||||
self.bufWrite(&end, "{}", node.name);
|
||||
self.bufWrite(&end, "{}", .{node.name});
|
||||
need_ellipse = true;
|
||||
}
|
||||
if (node.estimated_total_items) |total| {
|
||||
if (need_ellipse) self.bufWrite(&end, " ");
|
||||
self.bufWrite(&end, "[{}/{}] ", node.completed_items + 1, total);
|
||||
if (need_ellipse) self.bufWrite(&end, " ", .{});
|
||||
self.bufWrite(&end, "[{}/{}] ", .{ node.completed_items + 1, total });
|
||||
need_ellipse = false;
|
||||
} else if (node.completed_items != 0) {
|
||||
if (need_ellipse) self.bufWrite(&end, " ");
|
||||
self.bufWrite(&end, "[{}] ", node.completed_items + 1);
|
||||
if (need_ellipse) self.bufWrite(&end, " ", .{});
|
||||
self.bufWrite(&end, "[{}] ", .{node.completed_items + 1});
|
||||
need_ellipse = false;
|
||||
}
|
||||
}
|
||||
maybe_node = node.recently_updated_child;
|
||||
}
|
||||
if (need_ellipse) {
|
||||
self.bufWrite(&end, "...");
|
||||
self.bufWrite(&end, "...", .{});
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ pub const Progress = struct {
|
||||
self.prev_refresh_timestamp = self.timer.read();
|
||||
}
|
||||
|
||||
pub fn log(self: *Progress, comptime format: []const u8, args: ...) void {
|
||||
pub fn log(self: *Progress, comptime format: []const u8, args: var) void {
|
||||
const file = self.terminal orelse return;
|
||||
self.refresh();
|
||||
file.outStream().stream.print(format, args) catch {
|
||||
@ -184,7 +184,7 @@ pub const Progress = struct {
|
||||
self.columns_written = 0;
|
||||
}
|
||||
|
||||
fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: ...) void {
|
||||
fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: var) void {
|
||||
if (std.fmt.bufPrint(self.output_buffer[end.*..], format, args)) |written| {
|
||||
const amt = written.len;
|
||||
end.* += amt;
|
||||
|
@ -26,15 +26,15 @@ pub fn main() !void {
|
||||
_ = arg_it.skip();
|
||||
|
||||
const zig_exe = try unwrapArg(arg_it.next(allocator) orelse {
|
||||
warn("Expected first argument to be path to zig compiler\n");
|
||||
warn("Expected first argument to be path to zig compiler\n", .{});
|
||||
return error.InvalidArgs;
|
||||
});
|
||||
const build_root = try unwrapArg(arg_it.next(allocator) orelse {
|
||||
warn("Expected second argument to be build root directory path\n");
|
||||
warn("Expected second argument to be build root directory path\n", .{});
|
||||
return error.InvalidArgs;
|
||||
});
|
||||
const cache_root = try unwrapArg(arg_it.next(allocator) orelse {
|
||||
warn("Expected third argument to be cache root directory path\n");
|
||||
warn("Expected third argument to be cache root directory path\n", .{});
|
||||
return error.InvalidArgs;
|
||||
});
|
||||
|
||||
@ -51,7 +51,7 @@ pub fn main() !void {
|
||||
if (mem.startsWith(u8, arg, "-D")) {
|
||||
const option_contents = arg[2..];
|
||||
if (option_contents.len == 0) {
|
||||
warn("Expected option name after '-D'\n\n");
|
||||
warn("Expected option name after '-D'\n\n", .{});
|
||||
return usageAndErr(builder, false, stderr_stream);
|
||||
}
|
||||
if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {
|
||||
@ -70,18 +70,18 @@ pub fn main() !void {
|
||||
return usage(builder, false, stdout_stream);
|
||||
} else if (mem.eql(u8, arg, "--prefix")) {
|
||||
builder.install_prefix = try unwrapArg(arg_it.next(allocator) orelse {
|
||||
warn("Expected argument after --prefix\n\n");
|
||||
warn("Expected argument after --prefix\n\n", .{});
|
||||
return usageAndErr(builder, false, stderr_stream);
|
||||
});
|
||||
} else if (mem.eql(u8, arg, "--search-prefix")) {
|
||||
const search_prefix = try unwrapArg(arg_it.next(allocator) orelse {
|
||||
warn("Expected argument after --search-prefix\n\n");
|
||||
warn("Expected argument after --search-prefix\n\n", .{});
|
||||
return usageAndErr(builder, false, stderr_stream);
|
||||
});
|
||||
builder.addSearchPrefix(search_prefix);
|
||||
} else if (mem.eql(u8, arg, "--override-lib-dir")) {
|
||||
builder.override_lib_dir = try unwrapArg(arg_it.next(allocator) orelse {
|
||||
warn("Expected argument after --override-lib-dir\n\n");
|
||||
warn("Expected argument after --override-lib-dir\n\n", .{});
|
||||
return usageAndErr(builder, false, stderr_stream);
|
||||
});
|
||||
} else if (mem.eql(u8, arg, "--verbose-tokenize")) {
|
||||
@ -99,7 +99,7 @@ pub fn main() !void {
|
||||
} else if (mem.eql(u8, arg, "--verbose-cc")) {
|
||||
builder.verbose_cc = true;
|
||||
} else {
|
||||
warn("Unrecognized argument: {}\n\n", arg);
|
||||
warn("Unrecognized argument: {}\n\n", .{arg});
|
||||
return usageAndErr(builder, false, stderr_stream);
|
||||
}
|
||||
} else {
|
||||
@ -145,15 +145,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
|
||||
\\
|
||||
\\Steps:
|
||||
\\
|
||||
, builder.zig_exe);
|
||||
, .{builder.zig_exe});
|
||||
|
||||
const allocator = builder.allocator;
|
||||
for (builder.top_level_steps.toSliceConst()) |top_level_step| {
|
||||
const name = if (&top_level_step.step == builder.default_step)
|
||||
try fmt.allocPrint(allocator, "{} (default)", top_level_step.step.name)
|
||||
try fmt.allocPrint(allocator, "{} (default)", .{top_level_step.step.name})
|
||||
else
|
||||
top_level_step.step.name;
|
||||
try out_stream.print(" {s:22} {}\n", name, top_level_step.description);
|
||||
try out_stream.print(" {s:22} {}\n", .{ name, top_level_step.description });
|
||||
}
|
||||
|
||||
try out_stream.write(
|
||||
@ -169,12 +169,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
|
||||
);
|
||||
|
||||
if (builder.available_options_list.len == 0) {
|
||||
try out_stream.print(" (none)\n");
|
||||
try out_stream.print(" (none)\n", .{});
|
||||
} else {
|
||||
for (builder.available_options_list.toSliceConst()) |option| {
|
||||
const name = try fmt.allocPrint(allocator, " -D{}=[{}]", option.name, Builder.typeIdName(option.type_id));
|
||||
const name = try fmt.allocPrint(allocator, " -D{}=[{}]", .{
|
||||
option.name,
|
||||
Builder.typeIdName(option.type_id),
|
||||
});
|
||||
defer allocator.free(name);
|
||||
try out_stream.print("{s:24} {}\n", name, option.description);
|
||||
try out_stream.print("{s:24} {}\n", .{ name, option.description });
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,7 +207,7 @@ const UnwrapArgError = error{OutOfMemory};
|
||||
|
||||
fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 {
|
||||
return arg catch |err| {
|
||||
warn("Unable to parse command line: {}\n", err);
|
||||
warn("Unable to parse command line: {}\n", .{err});
|
||||
return err;
|
||||
};
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() anyerror!void {
|
||||
std.debug.warn("All your base are belong to us.\n");
|
||||
std.debug.warn("All your base are belong to us.\n", .{});
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ inline fn initEventLoopAndCallMain() u8 {
|
||||
if (std.event.Loop.instance) |loop| {
|
||||
if (!@hasDecl(root, "event_loop")) {
|
||||
loop.init() catch |err| {
|
||||
std.debug.warn("error: {}\n", @errorName(err));
|
||||
std.debug.warn("error: {}\n", .{@errorName(err)});
|
||||
if (@errorReturnTrace()) |trace| {
|
||||
std.debug.dumpStackTrace(trace.*);
|
||||
}
|
||||
@ -264,7 +264,7 @@ fn callMain() u8 {
|
||||
},
|
||||
.ErrorUnion => {
|
||||
const result = root.main() catch |err| {
|
||||
std.debug.warn("error: {}\n", @errorName(err));
|
||||
std.debug.warn("error: {}\n", .{@errorName(err)});
|
||||
if (@errorReturnTrace()) |trace| {
|
||||
std.debug.dumpStackTrace(trace.*);
|
||||
}
|
||||
|
@ -16,28 +16,28 @@ pub fn main() anyerror!void {
|
||||
var test_node = root_node.start(test_fn.name, null);
|
||||
test_node.activate();
|
||||
progress.refresh();
|
||||
if (progress.terminal == null) std.debug.warn("{}/{} {}...", i + 1, test_fn_list.len, test_fn.name);
|
||||
if (progress.terminal == null) std.debug.warn("{}/{} {}...", .{ i + 1, test_fn_list.len, test_fn.name });
|
||||
if (test_fn.func()) |_| {
|
||||
ok_count += 1;
|
||||
test_node.end();
|
||||
if (progress.terminal == null) std.debug.warn("OK\n");
|
||||
if (progress.terminal == null) std.debug.warn("OK\n", .{});
|
||||
} else |err| switch (err) {
|
||||
error.SkipZigTest => {
|
||||
skip_count += 1;
|
||||
test_node.end();
|
||||
progress.log("{}...SKIP\n", test_fn.name);
|
||||
if (progress.terminal == null) std.debug.warn("SKIP\n");
|
||||
progress.log("{}...SKIP\n", .{test_fn.name});
|
||||
if (progress.terminal == null) std.debug.warn("SKIP\n", .{});
|
||||
},
|
||||
else => {
|
||||
progress.log("");
|
||||
progress.log("", .{});
|
||||
return err;
|
||||
},
|
||||
}
|
||||
}
|
||||
root_node.end();
|
||||
if (ok_count == test_fn_list.len) {
|
||||
std.debug.warn("All {} tests passed.\n", ok_count);
|
||||
std.debug.warn("All {} tests passed.\n", .{ok_count});
|
||||
} else {
|
||||
std.debug.warn("{} passed; {} skipped.\n", ok_count, skip_count);
|
||||
std.debug.warn("{} passed; {} skipped.\n", .{ ok_count, skip_count });
|
||||
}
|
||||
}
|
||||
|
@ -321,14 +321,12 @@ pub const Target = union(enum) {
|
||||
pub const stack_align = 16;
|
||||
|
||||
pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
|
||||
return std.fmt.allocPrint(
|
||||
allocator,
|
||||
"{}{}-{}-{}",
|
||||
return std.fmt.allocPrint(allocator, "{}{}-{}-{}", .{
|
||||
@tagName(self.getArch()),
|
||||
Target.archSubArchName(self.getArch()),
|
||||
@tagName(self.getOs()),
|
||||
@tagName(self.getAbi()),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// Returned slice must be freed by the caller.
|
||||
@ -372,23 +370,19 @@ pub const Target = union(enum) {
|
||||
}
|
||||
|
||||
pub fn zigTripleNoSubArch(self: Target, allocator: *mem.Allocator) ![]u8 {
|
||||
return std.fmt.allocPrint(
|
||||
allocator,
|
||||
"{}-{}-{}",
|
||||
return std.fmt.allocPrint(allocator, "{}-{}-{}", .{
|
||||
@tagName(self.getArch()),
|
||||
@tagName(self.getOs()),
|
||||
@tagName(self.getAbi()),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
|
||||
return std.fmt.allocPrint(
|
||||
allocator,
|
||||
"{}-{}-{}",
|
||||
return std.fmt.allocPrint(allocator, "{}-{}-{}", .{
|
||||
@tagName(self.getArch()),
|
||||
@tagName(self.getOs()),
|
||||
@tagName(self.getAbi()),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn parse(text: []const u8) !Target {
|
||||
|
@ -8,13 +8,19 @@ pub fn expectError(expected_error: anyerror, actual_error_union: var) void {
|
||||
if (actual_error_union) |actual_payload| {
|
||||
// TODO remove workaround here for https://github.com/ziglang/zig/issues/557
|
||||
if (@sizeOf(@typeOf(actual_payload)) == 0) {
|
||||
std.debug.panic("expected error.{}, found {} value", @errorName(expected_error), @typeName(@typeOf(actual_payload)));
|
||||
std.debug.panic("expected error.{}, found {} value", .{
|
||||
@errorName(expected_error),
|
||||
@typeName(@typeOf(actual_payload)),
|
||||
});
|
||||
} else {
|
||||
std.debug.panic("expected error.{}, found {}", @errorName(expected_error), actual_payload);
|
||||
std.debug.panic("expected error.{}, found {}", .{ @errorName(expected_error), actual_payload });
|
||||
}
|
||||
} else |actual_error| {
|
||||
if (expected_error != actual_error) {
|
||||
std.debug.panic("expected error.{}, found error.{}", @errorName(expected_error), @errorName(actual_error));
|
||||
std.debug.panic("expected error.{}, found error.{}", .{
|
||||
@errorName(expected_error),
|
||||
@errorName(actual_error),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -51,7 +57,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
|
||||
.ErrorSet,
|
||||
=> {
|
||||
if (actual != expected) {
|
||||
std.debug.panic("expected {}, found {}", expected, actual);
|
||||
std.debug.panic("expected {}, found {}", .{ expected, actual });
|
||||
}
|
||||
},
|
||||
|
||||
@ -62,16 +68,16 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
|
||||
builtin.TypeInfo.Pointer.Size.C,
|
||||
=> {
|
||||
if (actual != expected) {
|
||||
std.debug.panic("expected {*}, found {*}", expected, actual);
|
||||
std.debug.panic("expected {*}, found {*}", .{ expected, actual });
|
||||
}
|
||||
},
|
||||
|
||||
builtin.TypeInfo.Pointer.Size.Slice => {
|
||||
if (actual.ptr != expected.ptr) {
|
||||
std.debug.panic("expected slice ptr {}, found {}", expected.ptr, actual.ptr);
|
||||
std.debug.panic("expected slice ptr {}, found {}", .{ expected.ptr, actual.ptr });
|
||||
}
|
||||
if (actual.len != expected.len) {
|
||||
std.debug.panic("expected slice len {}, found {}", expected.len, actual.len);
|
||||
std.debug.panic("expected slice len {}, found {}", .{ expected.len, actual.len });
|
||||
}
|
||||
},
|
||||
}
|
||||
@ -106,7 +112,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
|
||||
}
|
||||
|
||||
// we iterate over *all* union fields
|
||||
// => we should never get here as the loop above is
|
||||
// => we should never get here as the loop above is
|
||||
// including all possible values.
|
||||
unreachable;
|
||||
},
|
||||
@ -116,11 +122,11 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
|
||||
if (actual) |actual_payload| {
|
||||
expectEqual(expected_payload, actual_payload);
|
||||
} else {
|
||||
std.debug.panic("expected {}, found null", expected_payload);
|
||||
std.debug.panic("expected {}, found null", .{expected_payload});
|
||||
}
|
||||
} else {
|
||||
if (actual) |actual_payload| {
|
||||
std.debug.panic("expected null, found {}", actual_payload);
|
||||
std.debug.panic("expected null, found {}", .{actual_payload});
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -130,11 +136,11 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
|
||||
if (actual) |actual_payload| {
|
||||
expectEqual(expected_payload, actual_payload);
|
||||
} else |actual_err| {
|
||||
std.debug.panic("expected {}, found {}", expected_payload, actual_err);
|
||||
std.debug.panic("expected {}, found {}", .{ expected_payload, actual_err });
|
||||
}
|
||||
} else |expected_err| {
|
||||
if (actual) |actual_payload| {
|
||||
std.debug.panic("expected {}, found {}", expected_err, actual_payload);
|
||||
std.debug.panic("expected {}, found {}", .{ expected_err, actual_payload });
|
||||
} else |actual_err| {
|
||||
expectEqual(expected_err, actual_err);
|
||||
}
|
||||
@ -143,15 +149,14 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
|
||||
}
|
||||
}
|
||||
|
||||
test "expectEqual.union(enum)"
|
||||
{
|
||||
test "expectEqual.union(enum)" {
|
||||
const T = union(enum) {
|
||||
a: i32,
|
||||
b: f32,
|
||||
};
|
||||
|
||||
const a10 = T { .a = 10 };
|
||||
const a20 = T { .a = 20 };
|
||||
const a10 = T{ .a = 10 };
|
||||
const a20 = T{ .a = 20 };
|
||||
|
||||
expectEqual(a10, a10);
|
||||
}
|
||||
@ -165,12 +170,12 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const
|
||||
// If the child type is u8 and no weird bytes, we could print it as strings
|
||||
// Even for the length difference, it would be useful to see the values of the slices probably.
|
||||
if (expected.len != actual.len) {
|
||||
std.debug.panic("slice lengths differ. expected {}, found {}", expected.len, actual.len);
|
||||
std.debug.panic("slice lengths differ. expected {}, found {}", .{ expected.len, actual.len });
|
||||
}
|
||||
var i: usize = 0;
|
||||
while (i < expected.len) : (i += 1) {
|
||||
if (expected[i] != actual[i]) {
|
||||
std.debug.panic("index {} incorrect. expected {}, found {}", i, expected[i], actual[i]);
|
||||
std.debug.panic("index {} incorrect. expected {}, found {}", .{ i, expected[i], actual[i] });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ pub fn utf8ValidateSlice(s: []const u8) bool {
|
||||
/// ```
|
||||
/// var utf8 = (try std.unicode.Utf8View.init("hi there")).iterator();
|
||||
/// while (utf8.nextCodepointSlice()) |codepoint| {
|
||||
/// std.debug.warn("got codepoint {}\n", codepoint);
|
||||
/// std.debug.warn("got codepoint {}\n", .{codepoint});
|
||||
/// }
|
||||
/// ```
|
||||
pub const Utf8View = struct {
|
||||
|
@ -24,8 +24,12 @@ pub fn main() !void {
|
||||
const elapsed_ns_better = timer.lap();
|
||||
@fence(.SeqCst);
|
||||
|
||||
std.debug.warn("original utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", elapsed_ns_orig, elapsed_ns_orig / 1000000);
|
||||
std.debug.warn("new utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", elapsed_ns_better, elapsed_ns_better / 1000000);
|
||||
std.debug.warn("original utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", .{
|
||||
elapsed_ns_orig, elapsed_ns_orig / 1000000,
|
||||
});
|
||||
std.debug.warn("new utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", .{
|
||||
elapsed_ns_better, elapsed_ns_better / 1000000,
|
||||
});
|
||||
asm volatile ("nop"
|
||||
:
|
||||
: [a] "r" (&buffer1),
|
||||
|
@ -114,20 +114,6 @@ pub fn innerThreads(qzz: [*]u8) void {
|
||||
doClientRequestStmt(.InnerThreads, qzz, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
//pub fn printf(format: [*]const u8, args: ...) usize {
|
||||
// return doClientRequestExpr(0,
|
||||
// .PrintfValistByRef,
|
||||
// @ptrToInt(format), @ptrToInt(args),
|
||||
// 0, 0, 0);
|
||||
//}
|
||||
|
||||
//pub fn printfBacktrace(format: [*]const u8, args: ...) usize {
|
||||
// return doClientRequestExpr(0,
|
||||
// .PrintfBacktraceValistByRef,
|
||||
// @ptrToInt(format), @ptrToInt(args),
|
||||
// 0, 0, 0);
|
||||
//}
|
||||
|
||||
pub fn nonSIMDCall0(func: fn (usize) usize) usize {
|
||||
return doClientRequestExpr(0, .ClientCall0, @ptrToInt(func), 0, 0, 0, 0);
|
||||
}
|
||||
|
@ -301,7 +301,9 @@ pub const Error = union(enum) {
|
||||
node: *Node,
|
||||
|
||||
pub fn render(self: *const ExpectedCall, tokens: *Tree.TokenList, stream: var) !void {
|
||||
return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ ", found {}", @tagName(self.node.id));
|
||||
return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ ", found {}", .{
|
||||
@tagName(self.node.id),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -309,7 +311,8 @@ pub const Error = union(enum) {
|
||||
node: *Node,
|
||||
|
||||
pub fn render(self: *const ExpectedCallOrFnProto, tokens: *Tree.TokenList, stream: var) !void {
|
||||
return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ " or " ++ @tagName(Node.Id.FnProto) ++ ", found {}", @tagName(self.node.id));
|
||||
return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ " or " ++
|
||||
@tagName(Node.Id.FnProto) ++ ", found {}", .{@tagName(self.node.id)});
|
||||
}
|
||||
};
|
||||
|
||||
@ -321,14 +324,14 @@ pub const Error = union(enum) {
|
||||
const found_token = tokens.at(self.token);
|
||||
switch (found_token.id) {
|
||||
.Invalid_ampersands => {
|
||||
return stream.print("`&&` is invalid. Note that `and` is boolean AND.");
|
||||
return stream.print("`&&` is invalid. Note that `and` is boolean AND.", .{});
|
||||
},
|
||||
.Invalid => {
|
||||
return stream.print("expected '{}', found invalid bytes", self.expected_id.symbol());
|
||||
return stream.print("expected '{}', found invalid bytes", .{self.expected_id.symbol()});
|
||||
},
|
||||
else => {
|
||||
const token_name = found_token.id.symbol();
|
||||
return stream.print("expected '{}', found '{}'", self.expected_id.symbol(), token_name);
|
||||
return stream.print("expected '{}', found '{}'", .{ self.expected_id.symbol(), token_name });
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -340,7 +343,10 @@ pub const Error = union(enum) {
|
||||
|
||||
pub fn render(self: *const ExpectedCommaOrEnd, tokens: *Tree.TokenList, stream: var) !void {
|
||||
const actual_token = tokens.at(self.token);
|
||||
return stream.print("expected ',' or '{}', found '{}'", self.end_id.symbol(), actual_token.id.symbol());
|
||||
return stream.print("expected ',' or '{}', found '{}'", .{
|
||||
self.end_id.symbol(),
|
||||
actual_token.id.symbol(),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -352,7 +358,7 @@ pub const Error = union(enum) {
|
||||
|
||||
pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void {
|
||||
const actual_token = tokens.at(self.token);
|
||||
return stream.print(msg, actual_token.id.symbol());
|
||||
return stream.print(msg, .{actual_token.id.symbol()});
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -563,10 +569,10 @@ pub const Node = struct {
|
||||
{
|
||||
var i: usize = 0;
|
||||
while (i < indent) : (i += 1) {
|
||||
std.debug.warn(" ");
|
||||
std.debug.warn(" ", .{});
|
||||
}
|
||||
}
|
||||
std.debug.warn("{}\n", @tagName(self.id));
|
||||
std.debug.warn("{}\n", .{@tagName(self.id)});
|
||||
|
||||
var child_i: usize = 0;
|
||||
while (self.iterate(child_i)) |child| : (child_i += 1) {
|
||||
|
@ -642,15 +642,6 @@ test "zig fmt: fn decl with trailing comma" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: var_args with trailing comma" {
|
||||
try testCanonical(
|
||||
\\pub fn add(
|
||||
\\ a: ...,
|
||||
\\) void {}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: enum decl with no trailing comma" {
|
||||
try testTransform(
|
||||
\\const StrLitKind = enum {Normal, C};
|
||||
@ -1750,13 +1741,6 @@ test "zig fmt: call expression" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: var args" {
|
||||
try testCanonical(
|
||||
\\fn print(args: ...) void {}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: var type" {
|
||||
try testCanonical(
|
||||
\\fn print(args: var) var {}
|
||||
@ -2705,9 +2689,9 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b
|
||||
while (error_it.next()) |parse_error| {
|
||||
const token = tree.tokens.at(parse_error.loc());
|
||||
const loc = tree.tokenLocation(0, parse_error.loc());
|
||||
try stderr.print("(memory buffer):{}:{}: error: ", loc.line + 1, loc.column + 1);
|
||||
try stderr.print("(memory buffer):{}:{}: error: ", .{ loc.line + 1, loc.column + 1 });
|
||||
try tree.renderError(parse_error, stderr);
|
||||
try stderr.print("\n{}\n", source[loc.line_start..loc.line_end]);
|
||||
try stderr.print("\n{}\n", .{source[loc.line_start..loc.line_end]});
|
||||
{
|
||||
var i: usize = 0;
|
||||
while (i < loc.column) : (i += 1) {
|
||||
@ -2743,16 +2727,16 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
|
||||
var anything_changed: bool = undefined;
|
||||
const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed);
|
||||
if (!mem.eql(u8, result_source, expected_source)) {
|
||||
warn("\n====== expected this output: =========\n");
|
||||
warn("{}", expected_source);
|
||||
warn("\n======== instead found this: =========\n");
|
||||
warn("{}", result_source);
|
||||
warn("\n======================================\n");
|
||||
warn("\n====== expected this output: =========\n", .{});
|
||||
warn("{}", .{expected_source});
|
||||
warn("\n======== instead found this: =========\n", .{});
|
||||
warn("{}", .{result_source});
|
||||
warn("\n======================================\n", .{});
|
||||
return error.TestFailed;
|
||||
}
|
||||
const changes_expected = source.ptr != expected_source.ptr;
|
||||
if (anything_changed != changes_expected) {
|
||||
warn("std.zig.render returned {} instead of {}\n", anything_changed, changes_expected);
|
||||
warn("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected });
|
||||
return error.TestFailed;
|
||||
}
|
||||
std.testing.expect(anything_changed == changes_expected);
|
||||
@ -2772,12 +2756,14 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
|
||||
if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {
|
||||
warn(
|
||||
"\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n",
|
||||
fail_index,
|
||||
needed_alloc_count,
|
||||
failing_allocator.allocated_bytes,
|
||||
failing_allocator.freed_bytes,
|
||||
failing_allocator.allocations,
|
||||
failing_allocator.deallocations,
|
||||
.{
|
||||
fail_index,
|
||||
needed_alloc_count,
|
||||
failing_allocator.allocated_bytes,
|
||||
failing_allocator.freed_bytes,
|
||||
failing_allocator.allocations,
|
||||
failing_allocator.deallocations,
|
||||
},
|
||||
);
|
||||
return error.MemoryLeakDetected;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ fn renderRoot(
|
||||
// render all the line comments at the beginning of the file
|
||||
while (tok_it.next()) |token| {
|
||||
if (token.id != .LineComment) break;
|
||||
try stream.print("{}\n", mem.trimRight(u8, tree.tokenSlicePtr(token), " "));
|
||||
try stream.print("{}\n", .{mem.trimRight(u8, tree.tokenSlicePtr(token), " ")});
|
||||
if (tok_it.peek()) |next_token| {
|
||||
const loc = tree.tokenLocationPtr(token.end, next_token);
|
||||
if (loc.line >= 2) {
|
||||
@ -1226,7 +1226,7 @@ fn renderExpression(
|
||||
|
||||
var skip_first_indent = true;
|
||||
if (tree.tokens.at(multiline_str_literal.firstToken() - 1).id != .LineComment) {
|
||||
try stream.print("\n");
|
||||
try stream.print("\n", .{});
|
||||
skip_first_indent = false;
|
||||
}
|
||||
|
||||
@ -2129,7 +2129,7 @@ fn renderTokenOffset(
|
||||
|
||||
var loc = tree.tokenLocationPtr(token.end, next_token);
|
||||
if (loc.line == 0) {
|
||||
try stream.print(" {}", mem.trimRight(u8, tree.tokenSlicePtr(next_token), " "));
|
||||
try stream.print(" {}", .{mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ")});
|
||||
offset = 2;
|
||||
token = next_token;
|
||||
next_token = tree.tokens.at(token_index + offset);
|
||||
|
@ -330,7 +330,7 @@ pub const Tokenizer = struct {
|
||||
|
||||
/// For debugging purposes
|
||||
pub fn dump(self: *Tokenizer, token: *const Token) void {
|
||||
std.debug.warn("{} \"{}\"\n", @tagName(token.id), self.buffer[token.start..token.end]);
|
||||
std.debug.warn("{} \"{}\"\n", .{ @tagName(token.id), self.buffer[token.start..token.end] });
|
||||
}
|
||||
|
||||
pub fn init(buffer: []const u8) Tokenizer {
|
||||
@ -1576,7 +1576,7 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void {
|
||||
for (expected_tokens) |expected_token_id| {
|
||||
const token = tokenizer.next();
|
||||
if (token.id != expected_token_id) {
|
||||
std.debug.panic("expected {}, found {}\n", @tagName(expected_token_id), @tagName(token.id));
|
||||
std.debug.panic("expected {}, found {}\n", .{ @tagName(expected_token_id), @tagName(token.id) });
|
||||
}
|
||||
}
|
||||
const last_token = tokenizer.next();
|
||||
|
@ -98,15 +98,15 @@ pub const Args = struct {
|
||||
const flag_args = readFlagArguments(allocator, args, flag.required, flag.allowed_set, &i) catch |err| {
|
||||
switch (err) {
|
||||
error.ArgumentNotInAllowedSet => {
|
||||
std.debug.warn("argument '{}' is invalid for flag '{}'\n", args[i], arg);
|
||||
std.debug.warn("allowed options are ");
|
||||
std.debug.warn("argument '{}' is invalid for flag '{}'\n", .{ args[i], arg });
|
||||
std.debug.warn("allowed options are ", .{});
|
||||
for (flag.allowed_set.?) |possible| {
|
||||
std.debug.warn("'{}' ", possible);
|
||||
std.debug.warn("'{}' ", .{possible});
|
||||
}
|
||||
std.debug.warn("\n");
|
||||
std.debug.warn("\n", .{});
|
||||
},
|
||||
error.MissingFlagArguments => {
|
||||
std.debug.warn("missing argument for flag: {}\n", arg);
|
||||
std.debug.warn("missing argument for flag: {}\n", .{arg});
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
@ -134,7 +134,7 @@ pub const Args = struct {
|
||||
}
|
||||
|
||||
// TODO: Better errors with context, global error state and return is sufficient.
|
||||
std.debug.warn("could not match flag: {}\n", arg);
|
||||
std.debug.warn("could not match flag: {}\n", .{arg});
|
||||
return error.UnknownFlag;
|
||||
} else {
|
||||
try parsed.positionals.append(arg);
|
||||
|
@ -38,7 +38,7 @@ pub const Tokenizer = struct {
|
||||
},
|
||||
.target => |*target| switch (char) {
|
||||
'\t', '\n', '\r', ' ' => {
|
||||
return self.errorIllegalChar(self.index, char, "invalid target");
|
||||
return self.errorIllegalChar(self.index, char, "invalid target", .{});
|
||||
},
|
||||
'$' => {
|
||||
self.state = State{ .target_dollar_sign = target.* };
|
||||
@ -59,7 +59,7 @@ pub const Tokenizer = struct {
|
||||
},
|
||||
.target_reverse_solidus => |*target| switch (char) {
|
||||
'\t', '\n', '\r' => {
|
||||
return self.errorIllegalChar(self.index, char, "bad target escape");
|
||||
return self.errorIllegalChar(self.index, char, "bad target escape", .{});
|
||||
},
|
||||
' ', '#', '\\' => {
|
||||
try target.appendByte(char);
|
||||
@ -84,7 +84,7 @@ pub const Tokenizer = struct {
|
||||
break; // advance
|
||||
},
|
||||
else => {
|
||||
return self.errorIllegalChar(self.index, char, "expecting '$'");
|
||||
return self.errorIllegalChar(self.index, char, "expecting '$'", .{});
|
||||
},
|
||||
},
|
||||
.target_colon => |*target| switch (char) {
|
||||
@ -161,7 +161,7 @@ pub const Tokenizer = struct {
|
||||
break; // advance
|
||||
},
|
||||
else => {
|
||||
return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line");
|
||||
return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line", .{});
|
||||
},
|
||||
},
|
||||
.rhs_continuation_linefeed => switch (char) {
|
||||
@ -170,7 +170,7 @@ pub const Tokenizer = struct {
|
||||
break; // advance
|
||||
},
|
||||
else => {
|
||||
return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line");
|
||||
return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line", .{});
|
||||
},
|
||||
},
|
||||
.prereq_quote => |*prereq| switch (char) {
|
||||
@ -231,7 +231,7 @@ pub const Tokenizer = struct {
|
||||
return Token{ .id = .prereq, .bytes = bytes };
|
||||
},
|
||||
else => {
|
||||
return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line");
|
||||
return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line", .{});
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -249,13 +249,13 @@ pub const Tokenizer = struct {
|
||||
.rhs_continuation_linefeed,
|
||||
=> {},
|
||||
.target => |target| {
|
||||
return self.errorPosition(idx, target.toSlice(), "incomplete target");
|
||||
return self.errorPosition(idx, target.toSlice(), "incomplete target", .{});
|
||||
},
|
||||
.target_reverse_solidus,
|
||||
.target_dollar_sign,
|
||||
=> {
|
||||
const index = self.index - 1;
|
||||
return self.errorIllegalChar(idx, self.bytes[idx], "incomplete escape");
|
||||
return self.errorIllegalChar(idx, self.bytes[idx], "incomplete escape", .{});
|
||||
},
|
||||
.target_colon => |target| {
|
||||
const bytes = target.toSlice();
|
||||
@ -278,7 +278,7 @@ pub const Tokenizer = struct {
|
||||
self.state = State{ .lhs = {} };
|
||||
},
|
||||
.prereq_quote => |prereq| {
|
||||
return self.errorPosition(idx, prereq.toSlice(), "incomplete quoted prerequisite");
|
||||
return self.errorPosition(idx, prereq.toSlice(), "incomplete quoted prerequisite", .{});
|
||||
},
|
||||
.prereq => |prereq| {
|
||||
const bytes = prereq.toSlice();
|
||||
@ -299,29 +299,29 @@ pub const Tokenizer = struct {
|
||||
return null;
|
||||
}
|
||||
|
||||
fn errorf(self: *Tokenizer, comptime fmt: []const u8, args: ...) Error {
|
||||
fn errorf(self: *Tokenizer, comptime fmt: []const u8, args: var) Error {
|
||||
self.error_text = (try std.Buffer.allocPrint(&self.arena.allocator, fmt, args)).toSlice();
|
||||
return Error.InvalidInput;
|
||||
}
|
||||
|
||||
fn errorPosition(self: *Tokenizer, position: usize, bytes: []const u8, comptime fmt: []const u8, args: ...) Error {
|
||||
fn errorPosition(self: *Tokenizer, position: usize, bytes: []const u8, comptime fmt: []const u8, args: var) Error {
|
||||
var buffer = try std.Buffer.initSize(&self.arena.allocator, 0);
|
||||
std.fmt.format(&buffer, anyerror, std.Buffer.append, fmt, args) catch {};
|
||||
try buffer.append(" '");
|
||||
var out = makeOutput(std.Buffer.append, &buffer);
|
||||
try printCharValues(&out, bytes);
|
||||
try buffer.append("'");
|
||||
std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", position - (bytes.len - 1)) catch {};
|
||||
std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", .{position - (bytes.len - 1)}) catch {};
|
||||
self.error_text = buffer.toSlice();
|
||||
return Error.InvalidInput;
|
||||
}
|
||||
|
||||
fn errorIllegalChar(self: *Tokenizer, position: usize, char: u8, comptime fmt: []const u8, args: ...) Error {
|
||||
fn errorIllegalChar(self: *Tokenizer, position: usize, char: u8, comptime fmt: []const u8, args: var) Error {
|
||||
var buffer = try std.Buffer.initSize(&self.arena.allocator, 0);
|
||||
try buffer.append("illegal char ");
|
||||
var out = makeOutput(std.Buffer.append, &buffer);
|
||||
try printUnderstandableChar(&out, char);
|
||||
std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", position) catch {};
|
||||
std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", .{position}) catch {};
|
||||
if (fmt.len != 0) std.fmt.format(&buffer, anyerror, std.Buffer.append, ": " ++ fmt, args) catch {};
|
||||
self.error_text = buffer.toSlice();
|
||||
return Error.InvalidInput;
|
||||
@ -998,7 +998,7 @@ fn printCharValues(out: var, bytes: []const u8) !void {
|
||||
|
||||
fn printUnderstandableChar(out: var, char: u8) !void {
|
||||
if (!std.ascii.isPrint(char) or char == ' ') {
|
||||
std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", char) catch {};
|
||||
std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", .{char}) catch {};
|
||||
} else {
|
||||
try out.write("'");
|
||||
try out.write(&[_]u8{printable_char_tab[char]});
|
||||
|
@ -205,7 +205,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
|
||||
defer allocator.free(source_code);
|
||||
|
||||
const tree = std.zig.parse(allocator, source_code) catch |err| {
|
||||
try stderr.print("error parsing stdin: {}\n", err);
|
||||
try stderr.print("error parsing stdin: {}\n", .{err});
|
||||
process.exit(1);
|
||||
};
|
||||
defer tree.deinit();
|
||||
@ -294,7 +294,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
|
||||
},
|
||||
else => {
|
||||
// TODO lock stderr printing
|
||||
try stderr.print("unable to open '{}': {}\n", file_path, err);
|
||||
try stderr.print("unable to open '{}': {}\n", .{ file_path, err });
|
||||
fmt.any_error = true;
|
||||
return;
|
||||
},
|
||||
@ -302,7 +302,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
|
||||
defer fmt.allocator.free(source_code);
|
||||
|
||||
const tree = std.zig.parse(fmt.allocator, source_code) catch |err| {
|
||||
try stderr.print("error parsing file '{}': {}\n", file_path, err);
|
||||
try stderr.print("error parsing file '{}': {}\n", .{ file_path, err });
|
||||
fmt.any_error = true;
|
||||
return;
|
||||
};
|
||||
@ -320,7 +320,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
|
||||
if (check_mode) {
|
||||
const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, tree);
|
||||
if (anything_changed) {
|
||||
try stderr.print("{}\n", file_path);
|
||||
try stderr.print("{}\n", .{file_path});
|
||||
fmt.any_error = true;
|
||||
}
|
||||
} else {
|
||||
@ -329,7 +329,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
|
||||
|
||||
const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree);
|
||||
if (anything_changed) {
|
||||
try stderr.print("{}\n", file_path);
|
||||
try stderr.print("{}\n", .{file_path});
|
||||
try baf.finish();
|
||||
}
|
||||
}
|
||||
@ -374,7 +374,7 @@ fn printErrMsgToFile(
|
||||
const text = text_buf.toOwnedSlice();
|
||||
|
||||
const stream = &file.outStream().stream;
|
||||
try stream.print("{}:{}:{}: error: {}\n", path, start_loc.line + 1, start_loc.column + 1, text);
|
||||
try stream.print("{}:{}:{}: error: {}\n", .{ path, start_loc.line + 1, start_loc.column + 1, text });
|
||||
|
||||
if (!color_on) return;
|
||||
|
||||
|
@ -125,7 +125,7 @@ const Context = struct {
|
||||
|
||||
const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc);
|
||||
const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc);
|
||||
return std.fmt.allocPrint(c.a(), "{}:{}:{}", filename, line, column);
|
||||
return std.fmt.allocPrint(c.a(), "{}:{}:{}", .{ filename, line, column });
|
||||
}
|
||||
};
|
||||
|
||||
@ -228,20 +228,20 @@ fn declVisitor(c: *Context, decl: *const ZigClangDecl) Error!void {
|
||||
return visitFnDecl(c, @ptrCast(*const ZigClangFunctionDecl, decl));
|
||||
},
|
||||
.Typedef => {
|
||||
try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for typedefs");
|
||||
try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for typedefs", .{});
|
||||
},
|
||||
.Enum => {
|
||||
try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for enums");
|
||||
try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for enums", .{});
|
||||
},
|
||||
.Record => {
|
||||
try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for structs");
|
||||
try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for structs", .{});
|
||||
},
|
||||
.Var => {
|
||||
try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for variables");
|
||||
try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for variables", .{});
|
||||
},
|
||||
else => {
|
||||
const decl_name = try c.str(ZigClangDecl_getDeclKindName(decl));
|
||||
try emitWarning(c, ZigClangDecl_getLocation(decl), "ignoring {} declaration", decl_name);
|
||||
try emitWarning(c, ZigClangDecl_getLocation(decl), "ignoring {} declaration", .{decl_name});
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -264,7 +264,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
|
||||
.is_export = switch (storage_class) {
|
||||
.None => has_body and c.mode != .import,
|
||||
.Extern, .Static => false,
|
||||
.PrivateExtern => return failDecl(c, fn_decl_loc, fn_name, "unsupported storage class: private extern"),
|
||||
.PrivateExtern => return failDecl(c, fn_decl_loc, fn_name, "unsupported storage class: private extern", .{}),
|
||||
.Auto => unreachable, // Not legal on functions
|
||||
.Register => unreachable, // Not legal on functions
|
||||
},
|
||||
@ -274,7 +274,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
|
||||
const fn_proto_type = @ptrCast(*const ZigClangFunctionProtoType, fn_type);
|
||||
break :blk transFnProto(rp, fn_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {
|
||||
error.UnsupportedType => {
|
||||
return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function");
|
||||
return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{});
|
||||
},
|
||||
error.OutOfMemory => |e| return e,
|
||||
};
|
||||
@ -283,7 +283,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
|
||||
const fn_no_proto_type = @ptrCast(*const ZigClangFunctionType, fn_type);
|
||||
break :blk transFnNoProto(rp, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {
|
||||
error.UnsupportedType => {
|
||||
return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function");
|
||||
return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{});
|
||||
},
|
||||
error.OutOfMemory => |e| return e,
|
||||
};
|
||||
@ -302,7 +302,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
|
||||
error.OutOfMemory => |e| return e,
|
||||
error.UnsupportedTranslation,
|
||||
error.UnsupportedType,
|
||||
=> return failDecl(c, fn_decl_loc, fn_name, "unable to translate function"),
|
||||
=> return failDecl(c, fn_decl_loc, fn_name, "unable to translate function", .{}),
|
||||
};
|
||||
assert(result.node.id == ast.Node.Id.Block);
|
||||
proto_node.body_node = result.node;
|
||||
@ -344,7 +344,7 @@ fn transStmt(
|
||||
error.UnsupportedTranslation,
|
||||
ZigClangStmt_getBeginLoc(stmt),
|
||||
"TODO implement translation of stmt class {}",
|
||||
@tagName(sc),
|
||||
.{@tagName(sc)},
|
||||
);
|
||||
},
|
||||
}
|
||||
@ -364,7 +364,7 @@ fn transBinaryOperator(
|
||||
error.UnsupportedTranslation,
|
||||
ZigClangBinaryOperator_getBeginLoc(stmt),
|
||||
"TODO: handle more C binary operators: {}",
|
||||
op,
|
||||
.{op},
|
||||
),
|
||||
.Assign => return TransResult{
|
||||
.node = &(try transCreateNodeAssign(rp, scope, result_used, ZigClangBinaryOperator_getLHS(stmt), ZigClangBinaryOperator_getRHS(stmt))).base,
|
||||
@ -415,7 +415,7 @@ fn transBinaryOperator(
|
||||
error.UnsupportedTranslation,
|
||||
ZigClangBinaryOperator_getBeginLoc(stmt),
|
||||
"TODO: handle more C binary operators: {}",
|
||||
op,
|
||||
.{op},
|
||||
),
|
||||
.MulAssign,
|
||||
.DivAssign,
|
||||
@ -567,7 +567,7 @@ fn transDeclStmt(rp: RestorePoint, parent_scope: *Scope, stmt: *const ZigClangDe
|
||||
error.UnsupportedTranslation,
|
||||
ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)),
|
||||
"TODO implement translation of DeclStmt kind {}",
|
||||
@tagName(kind),
|
||||
.{@tagName(kind)},
|
||||
),
|
||||
}
|
||||
}
|
||||
@ -636,7 +636,7 @@ fn transImplicitCastExpr(
|
||||
error.UnsupportedTranslation,
|
||||
ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, expr)),
|
||||
"TODO implement translation of CastKind {}",
|
||||
@tagName(kind),
|
||||
.{@tagName(kind)},
|
||||
),
|
||||
}
|
||||
}
|
||||
@ -650,7 +650,7 @@ fn transIntegerLiteral(
|
||||
var eval_result: ZigClangExprEvalResult = undefined;
|
||||
if (!ZigClangIntegerLiteral_EvaluateAsInt(expr, &eval_result, rp.c.clang_context)) {
|
||||
const loc = ZigClangIntegerLiteral_getBeginLoc(expr);
|
||||
return revertAndWarn(rp, error.UnsupportedTranslation, loc, "invalid integer literal");
|
||||
return revertAndWarn(rp, error.UnsupportedTranslation, loc, "invalid integer literal", .{});
|
||||
}
|
||||
const node = try transCreateNodeAPInt(rp.c, ZigClangAPValue_getInt(&eval_result.Val));
|
||||
const res = TransResult{
|
||||
@ -719,7 +719,7 @@ fn transStringLiteral(
|
||||
error.UnsupportedTranslation,
|
||||
ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)),
|
||||
"TODO: support string literal kind {}",
|
||||
kind,
|
||||
.{kind},
|
||||
),
|
||||
}
|
||||
}
|
||||
@ -751,7 +751,7 @@ fn escapeChar(c: u8, char_buf: *[4]u8) []const u8 {
|
||||
'\n' => return "\\n"[0..],
|
||||
'\r' => return "\\r"[0..],
|
||||
'\t' => return "\\t"[0..],
|
||||
else => return std.fmt.bufPrint(char_buf[0..], "\\x{x:2}", c) catch unreachable,
|
||||
else => return std.fmt.bufPrint(char_buf[0..], "\\x{x:2}", .{c}) catch unreachable,
|
||||
};
|
||||
std.mem.copy(u8, char_buf, escaped);
|
||||
return char_buf[0..escaped.len];
|
||||
@ -1016,7 +1016,13 @@ fn transCreateNodeAssign(
|
||||
// zig: lhs = _tmp;
|
||||
// zig: break :x _tmp
|
||||
// zig: })
|
||||
return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangExpr_getBeginLoc(lhs), "TODO: worst case assign op expr");
|
||||
return revertAndWarn(
|
||||
rp,
|
||||
error.UnsupportedTranslation,
|
||||
ZigClangExpr_getBeginLoc(lhs),
|
||||
"TODO: worst case assign op expr",
|
||||
.{},
|
||||
);
|
||||
}
|
||||
|
||||
fn transCreateNodeBuiltinFnCall(c: *Context, name: []const u8) !*ast.Node.BuiltinCall {
|
||||
@ -1211,7 +1217,7 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour
|
||||
.Float128 => return appendIdentifier(rp.c, "f128"),
|
||||
.Float16 => return appendIdentifier(rp.c, "f16"),
|
||||
.LongDouble => return appendIdentifier(rp.c, "c_longdouble"),
|
||||
else => return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported builtin type"),
|
||||
else => return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported builtin type", .{}),
|
||||
}
|
||||
},
|
||||
.FunctionProto => {
|
||||
@ -1253,7 +1259,7 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour
|
||||
},
|
||||
else => {
|
||||
const type_name = rp.c.str(ZigClangType_getTypeClassName(ty));
|
||||
return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported type: '{}'", type_name);
|
||||
return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported type: '{}'", .{type_name});
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1275,7 +1281,13 @@ fn transCC(
|
||||
switch (clang_cc) {
|
||||
.C => return CallingConvention.C,
|
||||
.X86StdCall => return CallingConvention.Stdcall,
|
||||
else => return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported calling convention: {}", @tagName(clang_cc)),
|
||||
else => return revertAndWarn(
|
||||
rp,
|
||||
error.UnsupportedType,
|
||||
source_loc,
|
||||
"unsupported calling convention: {}",
|
||||
.{@tagName(clang_cc)},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1292,7 +1304,13 @@ fn transFnProto(
|
||||
const param_count: usize = ZigClangFunctionProtoType_getNumParams(fn_proto_ty);
|
||||
var i: usize = 0;
|
||||
while (i < param_count) : (i += 1) {
|
||||
return revertAndWarn(rp, error.UnsupportedType, source_loc, "TODO: implement parameters for FunctionProto in transType");
|
||||
return revertAndWarn(
|
||||
rp,
|
||||
error.UnsupportedType,
|
||||
source_loc,
|
||||
"TODO: implement parameters for FunctionProto in transType",
|
||||
.{},
|
||||
);
|
||||
}
|
||||
|
||||
return finishTransFnProto(rp, fn_ty, source_loc, fn_decl_context, is_var_args, cc, is_pub);
|
||||
@ -1350,7 +1368,7 @@ fn finishTransFnProto(
|
||||
} else {
|
||||
break :blk transQualType(rp, return_qt, source_loc) catch |err| switch (err) {
|
||||
error.UnsupportedType => {
|
||||
try emitWarning(rp.c, source_loc, "unsupported function proto return type");
|
||||
try emitWarning(rp.c, source_loc, "unsupported function proto return type", .{});
|
||||
return err;
|
||||
},
|
||||
error.OutOfMemory => |e| return e,
|
||||
@ -1397,18 +1415,19 @@ fn revertAndWarn(
|
||||
err: var,
|
||||
source_loc: ZigClangSourceLocation,
|
||||
comptime format: []const u8,
|
||||
args: ...,
|
||||
args: var,
|
||||
) (@typeOf(err) || error{OutOfMemory}) {
|
||||
rp.activate();
|
||||
try emitWarning(rp.c, source_loc, format, args);
|
||||
return err;
|
||||
}
|
||||
|
||||
fn emitWarning(c: *Context, loc: ZigClangSourceLocation, comptime format: []const u8, args: ...) !void {
|
||||
_ = try appendTokenFmt(c, .LineComment, "// {}: warning: " ++ format, c.locStr(loc), args);
|
||||
fn emitWarning(c: *Context, loc: ZigClangSourceLocation, comptime format: []const u8, args: var) !void {
|
||||
const args_prefix = .{c.locStr(loc)};
|
||||
_ = try appendTokenFmt(c, .LineComment, "// {}: warning: " ++ format, args_prefix ++ args);
|
||||
}
|
||||
|
||||
fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime format: []const u8, args: ...) !void {
|
||||
fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime format: []const u8, args: var) !void {
|
||||
// const name = @compileError(msg);
|
||||
const const_tok = try appendToken(c, .Keyword_const, "const");
|
||||
const name_tok = try appendToken(c, .Identifier, name);
|
||||
@ -1456,10 +1475,10 @@ fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime
|
||||
}
|
||||
|
||||
fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenIndex {
|
||||
return appendTokenFmt(c, token_id, "{}", bytes);
|
||||
return appendTokenFmt(c, token_id, "{}", .{bytes});
|
||||
}
|
||||
|
||||
fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: ...) !ast.TokenIndex {
|
||||
fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: var) !ast.TokenIndex {
|
||||
const S = struct {
|
||||
fn callback(context: *Context, bytes: []const u8) error{OutOfMemory}!void {
|
||||
return context.source_buffer.append(bytes);
|
||||
|
16
src/ir.cpp
16
src/ir.cpp
@ -17025,7 +17025,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
|
||||
{
|
||||
result_loc_pass1 = no_result_loc();
|
||||
}
|
||||
bool was_written = result_loc_pass1->written;
|
||||
bool was_already_resolved = result_loc_pass1->resolved_loc != nullptr;
|
||||
IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
|
||||
value, force_runtime, non_null_comptime, allow_discard);
|
||||
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
|
||||
}
|
||||
|
||||
InferredStructField *isf = result_loc->value->type->data.pointer.inferred_struct_field;
|
||||
if (!was_written && isf != nullptr) {
|
||||
if (!was_already_resolved && isf != nullptr) {
|
||||
// Now it's time to add the field to the struct type.
|
||||
uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count;
|
||||
uint32_t new_field_count = old_field_count + 1;
|
||||
@ -18077,7 +18077,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
|
||||
if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
|
||||
return result_loc;
|
||||
}
|
||||
if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {
|
||||
ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;
|
||||
if (res_child_type == ira->codegen->builtin_types.entry_var) {
|
||||
res_child_type = impl_fn_type_id->return_type;
|
||||
}
|
||||
if (!handle_is_ptr(res_child_type)) {
|
||||
ir_reset_result(call_result_loc);
|
||||
result_loc = nullptr;
|
||||
}
|
||||
@ -18240,7 +18244,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
|
||||
if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
|
||||
return result_loc;
|
||||
}
|
||||
if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {
|
||||
ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;
|
||||
if (res_child_type == ira->codegen->builtin_types.entry_var) {
|
||||
res_child_type = return_type;
|
||||
}
|
||||
if (!handle_is_ptr(res_child_type)) {
|
||||
ir_reset_result(call_result_loc);
|
||||
result_loc = nullptr;
|
||||
}
|
||||
|
22
test/cli.zig
22
test/cli.zig
@ -19,11 +19,11 @@ pub fn main() !void {
|
||||
a = &arena.allocator;
|
||||
|
||||
const zig_exe_rel = try (arg_it.next(a) orelse {
|
||||
std.debug.warn("Expected first argument to be path to zig compiler\n");
|
||||
std.debug.warn("Expected first argument to be path to zig compiler\n", .{});
|
||||
return error.InvalidArgs;
|
||||
});
|
||||
const cache_root = try (arg_it.next(a) orelse {
|
||||
std.debug.warn("Expected second argument to be cache root directory path\n");
|
||||
std.debug.warn("Expected second argument to be cache root directory path\n", .{});
|
||||
return error.InvalidArgs;
|
||||
});
|
||||
const zig_exe = try fs.path.resolve(a, &[_][]const u8{zig_exe_rel});
|
||||
@ -45,39 +45,39 @@ pub fn main() !void {
|
||||
|
||||
fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 {
|
||||
return arg catch |err| {
|
||||
warn("Unable to parse command line: {}\n", err);
|
||||
warn("Unable to parse command line: {}\n", .{err});
|
||||
return err;
|
||||
};
|
||||
}
|
||||
|
||||
fn printCmd(cwd: []const u8, argv: []const []const u8) void {
|
||||
std.debug.warn("cd {} && ", cwd);
|
||||
std.debug.warn("cd {} && ", .{cwd});
|
||||
for (argv) |arg| {
|
||||
std.debug.warn("{} ", arg);
|
||||
std.debug.warn("{} ", .{arg});
|
||||
}
|
||||
std.debug.warn("\n");
|
||||
std.debug.warn("\n", .{});
|
||||
}
|
||||
|
||||
fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult {
|
||||
const max_output_size = 100 * 1024;
|
||||
const result = ChildProcess.exec(a, argv, cwd, null, max_output_size) catch |err| {
|
||||
std.debug.warn("The following command failed:\n");
|
||||
std.debug.warn("The following command failed:\n", .{});
|
||||
printCmd(cwd, argv);
|
||||
return err;
|
||||
};
|
||||
switch (result.term) {
|
||||
.Exited => |code| {
|
||||
if (code != 0) {
|
||||
std.debug.warn("The following command exited with error code {}:\n", code);
|
||||
std.debug.warn("The following command exited with error code {}:\n", .{code});
|
||||
printCmd(cwd, argv);
|
||||
std.debug.warn("stderr:\n{}\n", result.stderr);
|
||||
std.debug.warn("stderr:\n{}\n", .{result.stderr});
|
||||
return error.CommandFailed;
|
||||
}
|
||||
},
|
||||
else => {
|
||||
std.debug.warn("The following command terminated unexpectedly:\n");
|
||||
std.debug.warn("The following command terminated unexpectedly:\n", .{});
|
||||
printCmd(cwd, argv);
|
||||
std.debug.warn("stderr:\n{}\n", result.stderr);
|
||||
std.debug.warn("stderr:\n{}\n", .{result.stderr});
|
||||
return error.CommandFailed;
|
||||
},
|
||||
}
|
||||
|
@ -2598,14 +2598,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
\\fn a(b: fn (*const u8) void) void {
|
||||
\\ b('a');
|
||||
\\}
|
||||
\\fn c(d: u8) void {
|
||||
\\ @import("std").debug.warn("{c}\n", d);
|
||||
\\}
|
||||
\\fn c(d: u8) void {}
|
||||
\\export fn entry() void {
|
||||
\\ a(c);
|
||||
\\}
|
||||
,
|
||||
"tmp.zig:8:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'",
|
||||
"tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
|
@ -23,7 +23,7 @@ pub fn main() !void {
|
||||
return usage(exe);
|
||||
} else {
|
||||
const file = cwd.openFile(arg, .{}) catch |err| {
|
||||
warn("Unable to open file: {}\n", @errorName(err));
|
||||
warn("Unable to open file: {}\n", .{@errorName(err)});
|
||||
return err;
|
||||
};
|
||||
defer file.close();
|
||||
@ -38,7 +38,7 @@ pub fn main() !void {
|
||||
}
|
||||
|
||||
fn usage(exe: []const u8) !void {
|
||||
warn("Usage: {} [FILE]...\n", exe);
|
||||
warn("Usage: {} [FILE]...\n", .{exe});
|
||||
return error.Invalid;
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void {
|
||||
|
||||
while (true) {
|
||||
const bytes_read = file.read(buf[0..]) catch |err| {
|
||||
warn("Unable to read from stream: {}\n", @errorName(err));
|
||||
warn("Unable to read from stream: {}\n", .{@errorName(err)});
|
||||
return err;
|
||||
};
|
||||
|
||||
@ -56,7 +56,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void {
|
||||
}
|
||||
|
||||
stdout.write(buf[0..bytes_read]) catch |err| {
|
||||
warn("Unable to write to stdout: {}\n", @errorName(err));
|
||||
warn("Unable to write to stdout: {}\n", .{@errorName(err)});
|
||||
return err;
|
||||
};
|
||||
}
|
||||
@ -64,7 +64,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void {
|
||||
|
||||
fn unwrapArg(arg: anyerror![]u8) ![]u8 {
|
||||
return arg catch |err| {
|
||||
warn("Unable to parse command line: {}\n", err);
|
||||
warn("Unable to parse command line: {}\n", .{err});
|
||||
return err;
|
||||
};
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ pub fn main() !void {
|
||||
|
||||
var seed_bytes: [@sizeOf(u64)]u8 = undefined;
|
||||
std.crypto.randomBytes(seed_bytes[0..]) catch |err| {
|
||||
std.debug.warn("unable to seed random number generator: {}", err);
|
||||
std.debug.warn("unable to seed random number generator: {}", .{err});
|
||||
return err;
|
||||
};
|
||||
const seed = std.mem.readIntNative(u64, &seed_bytes);
|
||||
|
160
test/tests.zig
160
test/tests.zig
@ -411,7 +411,7 @@ pub fn addPkgTests(
|
||||
is_qemu_enabled: bool,
|
||||
glibc_dir: ?[]const u8,
|
||||
) *build.Step {
|
||||
const step = b.step(b.fmt("test-{}", name), desc);
|
||||
const step = b.step(b.fmt("test-{}", .{name}), desc);
|
||||
|
||||
for (test_targets) |test_target| {
|
||||
if (skip_non_native and test_target.target != .Native)
|
||||
@ -454,14 +454,14 @@ pub fn addPkgTests(
|
||||
test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;
|
||||
|
||||
const these_tests = b.addTest(root_src);
|
||||
these_tests.setNamePrefix(b.fmt(
|
||||
"{}-{}-{}-{}-{} ",
|
||||
const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
|
||||
these_tests.setNamePrefix(b.fmt("{}-{}-{}-{}-{} ", .{
|
||||
name,
|
||||
triple_prefix,
|
||||
@tagName(test_target.mode),
|
||||
libc_prefix,
|
||||
if (test_target.single_threaded) "single" else "multi",
|
||||
));
|
||||
single_threaded_txt,
|
||||
}));
|
||||
these_tests.single_threaded = test_target.single_threaded;
|
||||
these_tests.setFilter(test_filter);
|
||||
these_tests.setBuildMode(test_target.mode);
|
||||
@ -562,7 +562,7 @@ pub const CompareOutputContext = struct {
|
||||
args.append(arg) catch unreachable;
|
||||
}
|
||||
|
||||
warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
|
||||
warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
|
||||
|
||||
const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
|
||||
defer child.deinit();
|
||||
@ -572,7 +572,7 @@ pub const CompareOutputContext = struct {
|
||||
child.stderr_behavior = .Pipe;
|
||||
child.env_map = b.env_map;
|
||||
|
||||
child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
|
||||
child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
|
||||
|
||||
var stdout = Buffer.initNull(b.allocator);
|
||||
var stderr = Buffer.initNull(b.allocator);
|
||||
@ -584,18 +584,18 @@ pub const CompareOutputContext = struct {
|
||||
stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;
|
||||
|
||||
const term = child.wait() catch |err| {
|
||||
debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
|
||||
debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
|
||||
};
|
||||
switch (term) {
|
||||
.Exited => |code| {
|
||||
if (code != 0) {
|
||||
warn("Process {} exited with error code {}\n", full_exe_path, code);
|
||||
warn("Process {} exited with error code {}\n", .{ full_exe_path, code });
|
||||
printInvocation(args.toSliceConst());
|
||||
return error.TestFailed;
|
||||
}
|
||||
},
|
||||
else => {
|
||||
warn("Process {} terminated unexpectedly\n", full_exe_path);
|
||||
warn("Process {} terminated unexpectedly\n", .{full_exe_path});
|
||||
printInvocation(args.toSliceConst());
|
||||
return error.TestFailed;
|
||||
},
|
||||
@ -609,10 +609,10 @@ pub const CompareOutputContext = struct {
|
||||
\\========= But found: ====================
|
||||
\\{}
|
||||
\\
|
||||
, self.expected_output, stdout.toSliceConst());
|
||||
, .{ self.expected_output, stdout.toSliceConst() });
|
||||
return error.TestFailed;
|
||||
}
|
||||
warn("OK\n");
|
||||
warn("OK\n", .{});
|
||||
}
|
||||
};
|
||||
|
||||
@ -644,7 +644,7 @@ pub const CompareOutputContext = struct {
|
||||
|
||||
const full_exe_path = self.exe.getOutputPath();
|
||||
|
||||
warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
|
||||
warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
|
||||
|
||||
const child = std.ChildProcess.init(&[_][]const u8{full_exe_path}, b.allocator) catch unreachable;
|
||||
defer child.deinit();
|
||||
@ -655,28 +655,34 @@ pub const CompareOutputContext = struct {
|
||||
child.stderr_behavior = .Ignore;
|
||||
|
||||
const term = child.spawnAndWait() catch |err| {
|
||||
debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
|
||||
debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
|
||||
};
|
||||
|
||||
const expected_exit_code: u32 = 126;
|
||||
switch (term) {
|
||||
.Exited => |code| {
|
||||
if (code != expected_exit_code) {
|
||||
warn("\nProgram expected to exit with code {} " ++ "but exited with code {}\n", expected_exit_code, code);
|
||||
warn("\nProgram expected to exit with code {} but exited with code {}\n", .{
|
||||
expected_exit_code, code,
|
||||
});
|
||||
return error.TestFailed;
|
||||
}
|
||||
},
|
||||
.Signal => |sig| {
|
||||
warn("\nProgram expected to exit with code {} " ++ "but instead signaled {}\n", expected_exit_code, sig);
|
||||
warn("\nProgram expected to exit with code {} but instead signaled {}\n", .{
|
||||
expected_exit_code, sig,
|
||||
});
|
||||
return error.TestFailed;
|
||||
},
|
||||
else => {
|
||||
warn("\nProgram expected to exit with code {}" ++ " but exited in an unexpected way\n", expected_exit_code);
|
||||
warn("\nProgram expected to exit with code {} but exited in an unexpected way\n", .{
|
||||
expected_exit_code,
|
||||
});
|
||||
return error.TestFailed;
|
||||
},
|
||||
}
|
||||
|
||||
warn("OK\n");
|
||||
warn("OK\n", .{});
|
||||
}
|
||||
};
|
||||
|
||||
@ -729,7 +735,9 @@ pub const CompareOutputContext = struct {
|
||||
|
||||
switch (case.special) {
|
||||
Special.Asm => {
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name) catch unreachable;
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "assemble-and-link {}", .{
|
||||
case.name,
|
||||
}) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
||||
}
|
||||
@ -758,7 +766,11 @@ pub const CompareOutputContext = struct {
|
||||
},
|
||||
Special.None => {
|
||||
for (self.modes) |mode| {
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", "compare-output", case.name, @tagName(mode)) catch unreachable;
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", .{
|
||||
"compare-output",
|
||||
case.name,
|
||||
@tagName(mode),
|
||||
}) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
|
||||
}
|
||||
@ -790,7 +802,7 @@ pub const CompareOutputContext = struct {
|
||||
}
|
||||
},
|
||||
Special.RuntimeSafety => {
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", case.name) catch unreachable;
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", .{case.name}) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
||||
}
|
||||
@ -843,7 +855,11 @@ pub const StackTracesContext = struct {
|
||||
const expect_for_mode = expect[@enumToInt(mode)];
|
||||
if (expect_for_mode.len == 0) continue;
|
||||
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", "stack-trace", name, @tagName(mode)) catch unreachable;
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", .{
|
||||
"stack-trace",
|
||||
name,
|
||||
@tagName(mode),
|
||||
}) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
|
||||
}
|
||||
@ -907,7 +923,7 @@ pub const StackTracesContext = struct {
|
||||
defer args.deinit();
|
||||
args.append(full_exe_path) catch unreachable;
|
||||
|
||||
warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
|
||||
warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
|
||||
|
||||
const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
|
||||
defer child.deinit();
|
||||
@ -917,7 +933,7 @@ pub const StackTracesContext = struct {
|
||||
child.stderr_behavior = .Pipe;
|
||||
child.env_map = b.env_map;
|
||||
|
||||
child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
|
||||
child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
|
||||
|
||||
var stdout = Buffer.initNull(b.allocator);
|
||||
var stderr = Buffer.initNull(b.allocator);
|
||||
@ -929,30 +945,34 @@ pub const StackTracesContext = struct {
|
||||
stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;
|
||||
|
||||
const term = child.wait() catch |err| {
|
||||
debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
|
||||
debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
|
||||
};
|
||||
|
||||
switch (term) {
|
||||
.Exited => |code| {
|
||||
const expect_code: u32 = 1;
|
||||
if (code != expect_code) {
|
||||
warn("Process {} exited with error code {} but expected code {}\n", full_exe_path, code, expect_code);
|
||||
warn("Process {} exited with error code {} but expected code {}\n", .{
|
||||
full_exe_path,
|
||||
code,
|
||||
expect_code,
|
||||
});
|
||||
printInvocation(args.toSliceConst());
|
||||
return error.TestFailed;
|
||||
}
|
||||
},
|
||||
.Signal => |signum| {
|
||||
warn("Process {} terminated on signal {}\n", full_exe_path, signum);
|
||||
warn("Process {} terminated on signal {}\n", .{ full_exe_path, signum });
|
||||
printInvocation(args.toSliceConst());
|
||||
return error.TestFailed;
|
||||
},
|
||||
.Stopped => |signum| {
|
||||
warn("Process {} stopped on signal {}\n", full_exe_path, signum);
|
||||
warn("Process {} stopped on signal {}\n", .{ full_exe_path, signum });
|
||||
printInvocation(args.toSliceConst());
|
||||
return error.TestFailed;
|
||||
},
|
||||
.Unknown => |code| {
|
||||
warn("Process {} terminated unexpectedly with error code {}\n", full_exe_path, code);
|
||||
warn("Process {} terminated unexpectedly with error code {}\n", .{ full_exe_path, code });
|
||||
printInvocation(args.toSliceConst());
|
||||
return error.TestFailed;
|
||||
},
|
||||
@ -1003,10 +1023,10 @@ pub const StackTracesContext = struct {
|
||||
\\================================================
|
||||
\\{}
|
||||
\\
|
||||
, self.expect_output, got);
|
||||
, .{ self.expect_output, got });
|
||||
return error.TestFailed;
|
||||
}
|
||||
warn("OK\n");
|
||||
warn("OK\n", .{});
|
||||
}
|
||||
};
|
||||
};
|
||||
@ -1129,7 +1149,7 @@ pub const CompileErrorContext = struct {
|
||||
Mode.ReleaseSmall => zig_args.append("--release-small") catch unreachable,
|
||||
}
|
||||
|
||||
warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
|
||||
warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
|
||||
|
||||
if (b.verbose) {
|
||||
printInvocation(zig_args.toSliceConst());
|
||||
@ -1143,7 +1163,7 @@ pub const CompileErrorContext = struct {
|
||||
child.stdout_behavior = .Pipe;
|
||||
child.stderr_behavior = .Pipe;
|
||||
|
||||
child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));
|
||||
child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) });
|
||||
|
||||
var stdout_buf = Buffer.initNull(b.allocator);
|
||||
var stderr_buf = Buffer.initNull(b.allocator);
|
||||
@ -1155,7 +1175,7 @@ pub const CompileErrorContext = struct {
|
||||
stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
|
||||
|
||||
const term = child.wait() catch |err| {
|
||||
debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));
|
||||
debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) });
|
||||
};
|
||||
switch (term) {
|
||||
.Exited => |code| {
|
||||
@ -1165,7 +1185,7 @@ pub const CompileErrorContext = struct {
|
||||
}
|
||||
},
|
||||
else => {
|
||||
warn("Process {} terminated unexpectedly\n", b.zig_exe);
|
||||
warn("Process {} terminated unexpectedly\n", .{b.zig_exe});
|
||||
printInvocation(zig_args.toSliceConst());
|
||||
return error.TestFailed;
|
||||
},
|
||||
@ -1182,7 +1202,7 @@ pub const CompileErrorContext = struct {
|
||||
\\{}
|
||||
\\================================================
|
||||
\\
|
||||
, stdout);
|
||||
, .{stdout});
|
||||
return error.TestFailed;
|
||||
}
|
||||
|
||||
@ -1200,9 +1220,9 @@ pub const CompileErrorContext = struct {
|
||||
ok = ok and i == self.case.expected_errors.len;
|
||||
|
||||
if (!ok) {
|
||||
warn("\n======== Expected these compile errors: ========\n");
|
||||
warn("\n======== Expected these compile errors: ========\n", .{});
|
||||
for (self.case.expected_errors.toSliceConst()) |expected| {
|
||||
warn("{}\n", expected);
|
||||
warn("{}\n", .{expected});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -1213,7 +1233,7 @@ pub const CompileErrorContext = struct {
|
||||
\\=========== Expected compile error: ============
|
||||
\\{}
|
||||
\\
|
||||
, expected);
|
||||
, .{expected});
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
@ -1225,11 +1245,11 @@ pub const CompileErrorContext = struct {
|
||||
\\================= Full output: =================
|
||||
\\{}
|
||||
\\
|
||||
, stderr);
|
||||
, .{stderr});
|
||||
return error.TestFailed;
|
||||
}
|
||||
|
||||
warn("OK\n");
|
||||
warn("OK\n", .{});
|
||||
}
|
||||
};
|
||||
|
||||
@ -1279,7 +1299,9 @@ pub const CompileErrorContext = struct {
|
||||
pub fn addCase(self: *CompileErrorContext, case: *const TestCase) void {
|
||||
const b = self.b;
|
||||
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "compile-error {}", case.name) catch unreachable;
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "compile-error {}", .{
|
||||
case.name,
|
||||
}) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
||||
}
|
||||
@ -1316,7 +1338,7 @@ pub const StandaloneContext = struct {
|
||||
pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8) void {
|
||||
const b = self.b;
|
||||
|
||||
const annotated_case_name = b.fmt("build {} (Debug)", build_file);
|
||||
const annotated_case_name = b.fmt("build {} (Debug)", .{build_file});
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
||||
}
|
||||
@ -1337,7 +1359,7 @@ pub const StandaloneContext = struct {
|
||||
|
||||
const run_cmd = b.addSystemCommand(zig_args.toSliceConst());
|
||||
|
||||
const log_step = b.addLog("PASS {}\n", annotated_case_name);
|
||||
const log_step = b.addLog("PASS {}\n", .{annotated_case_name});
|
||||
log_step.step.dependOn(&run_cmd.step);
|
||||
|
||||
self.step.dependOn(&log_step.step);
|
||||
@ -1347,7 +1369,10 @@ pub const StandaloneContext = struct {
|
||||
const b = self.b;
|
||||
|
||||
for (self.modes) |mode| {
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {} ({})", root_src, @tagName(mode)) catch unreachable;
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {} ({})", .{
|
||||
root_src,
|
||||
@tagName(mode),
|
||||
}) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
|
||||
}
|
||||
@ -1358,7 +1383,7 @@ pub const StandaloneContext = struct {
|
||||
exe.linkSystemLibrary("c");
|
||||
}
|
||||
|
||||
const log_step = b.addLog("PASS {}\n", annotated_case_name);
|
||||
const log_step = b.addLog("PASS {}\n", .{annotated_case_name});
|
||||
log_step.step.dependOn(&exe.step);
|
||||
|
||||
self.step.dependOn(&log_step.step);
|
||||
@ -1434,7 +1459,7 @@ pub const TranslateCContext = struct {
|
||||
zig_args.append(translate_c_cmd) catch unreachable;
|
||||
zig_args.append(b.pathFromRoot(root_src)) catch unreachable;
|
||||
|
||||
warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
|
||||
warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
|
||||
|
||||
if (b.verbose) {
|
||||
printInvocation(zig_args.toSliceConst());
|
||||
@ -1448,7 +1473,10 @@ pub const TranslateCContext = struct {
|
||||
child.stdout_behavior = .Pipe;
|
||||
child.stderr_behavior = .Pipe;
|
||||
|
||||
child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));
|
||||
child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{
|
||||
zig_args.toSliceConst()[0],
|
||||
@errorName(err),
|
||||
});
|
||||
|
||||
var stdout_buf = Buffer.initNull(b.allocator);
|
||||
var stderr_buf = Buffer.initNull(b.allocator);
|
||||
@ -1460,23 +1488,23 @@ pub const TranslateCContext = struct {
|
||||
stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
|
||||
|
||||
const term = child.wait() catch |err| {
|
||||
debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));
|
||||
debug.panic("Unable to spawn {}: {}\n", .{ zig_args.toSliceConst()[0], @errorName(err) });
|
||||
};
|
||||
switch (term) {
|
||||
.Exited => |code| {
|
||||
if (code != 0) {
|
||||
warn("Compilation failed with exit code {}\n", code);
|
||||
warn("Compilation failed with exit code {}\n", .{code});
|
||||
printInvocation(zig_args.toSliceConst());
|
||||
return error.TestFailed;
|
||||
}
|
||||
},
|
||||
.Signal => |code| {
|
||||
warn("Compilation failed with signal {}\n", code);
|
||||
warn("Compilation failed with signal {}\n", .{code});
|
||||
printInvocation(zig_args.toSliceConst());
|
||||
return error.TestFailed;
|
||||
},
|
||||
else => {
|
||||
warn("Compilation terminated unexpectedly\n");
|
||||
warn("Compilation terminated unexpectedly\n", .{});
|
||||
printInvocation(zig_args.toSliceConst());
|
||||
return error.TestFailed;
|
||||
},
|
||||
@ -1491,7 +1519,7 @@ pub const TranslateCContext = struct {
|
||||
\\{}
|
||||
\\============================================
|
||||
\\
|
||||
, stderr);
|
||||
, .{stderr});
|
||||
printInvocation(zig_args.toSliceConst());
|
||||
return error.TestFailed;
|
||||
}
|
||||
@ -1505,20 +1533,20 @@ pub const TranslateCContext = struct {
|
||||
\\========= But found: ===========================
|
||||
\\{}
|
||||
\\
|
||||
, expected_line, stdout);
|
||||
, .{ expected_line, stdout });
|
||||
printInvocation(zig_args.toSliceConst());
|
||||
return error.TestFailed;
|
||||
}
|
||||
}
|
||||
warn("OK\n");
|
||||
warn("OK\n", .{});
|
||||
}
|
||||
};
|
||||
|
||||
fn printInvocation(args: []const []const u8) void {
|
||||
for (args) |arg| {
|
||||
warn("{} ", arg);
|
||||
warn("{} ", .{arg});
|
||||
}
|
||||
warn("\n");
|
||||
warn("\n", .{});
|
||||
}
|
||||
|
||||
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 {
|
||||
const b = self.b;
|
||||
|
||||
const translate_c_cmd = if (case.stage2) "translate-c-2" else "translate-c";
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {}", translate_c_cmd, case.name) catch unreachable;
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {}", .{ translate_c_cmd, case.name }) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
||||
}
|
||||
@ -1666,7 +1694,7 @@ pub const GenHContext = struct {
|
||||
const self = @fieldParentPtr(GenHCmpOutputStep, "step", step);
|
||||
const b = self.context.b;
|
||||
|
||||
warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
|
||||
warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
|
||||
|
||||
const full_h_path = self.obj.getOutputHPath();
|
||||
const actual_h = try io.readFileAlloc(b.allocator, full_h_path);
|
||||
@ -1680,19 +1708,19 @@ pub const GenHContext = struct {
|
||||
\\========= But found: ===========================
|
||||
\\{}
|
||||
\\
|
||||
, expected_line, actual_h);
|
||||
, .{ expected_line, actual_h });
|
||||
return error.TestFailed;
|
||||
}
|
||||
}
|
||||
warn("OK\n");
|
||||
warn("OK\n", .{});
|
||||
}
|
||||
};
|
||||
|
||||
fn printInvocation(args: []const []const u8) void {
|
||||
for (args) |arg| {
|
||||
warn("{} ", arg);
|
||||
warn("{} ", .{arg});
|
||||
}
|
||||
warn("\n");
|
||||
warn("\n", .{});
|
||||
}
|
||||
|
||||
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 {
|
||||
) catch unreachable;
|
||||
|
||||
const mode = builtin.Mode.Debug;
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {} ({})", case.name, @tagName(mode)) catch unreachable;
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {} ({})", .{ case.name, @tagName(mode) }) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
||||
}
|
||||
@ -1749,7 +1777,7 @@ pub const GenHContext = struct {
|
||||
|
||||
fn printInvocation(args: []const []const u8) void {
|
||||
for (args) |arg| {
|
||||
warn("{} ", arg);
|
||||
warn("{} ", .{arg});
|
||||
}
|
||||
warn("\n");
|
||||
warn("\n", .{});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user