authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-09 10:51:47-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-12-09 10:51:47-05:00
log640e09183d3100c477a26c6cdc26f1eae31472a1
tree0bddf7eb99d6daaaa2e5ee80b51a6766aefb7d9c
parent5874cb04bd544ca155d1489bb0bdf9397fa3b41c
parent8b3c0bbeeef080b77d0cb7999682abc52de437e3
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #3873 from ziglang/format-no-var-args

std.fmt.format: tuple parameter instead of var args

63 files changed, 1052 insertions(+), 1234 deletions(-)

build.zig+5-5
...@@ -154,7 +154,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {...@@ -154,7 +154,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
154 const static_bare_name = if (mem.eql(u8, lib, "curses"))154 const static_bare_name = if (mem.eql(u8, lib, "curses"))
155 @as([]const u8, "libncurses.a")155 @as([]const u8, "libncurses.a")
156 else156 else
157 b.fmt("lib{}.a", lib);157 b.fmt("lib{}.a", .{lib});
158 const static_lib_name = fs.path.join(158 const static_lib_name = fs.path.join(
159 b.allocator,159 b.allocator,
160 &[_][]const u8{ lib_dir, static_bare_name },160 &[_][]const u8{ lib_dir, static_bare_name },
...@@ -186,7 +186,7 @@ fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_na...@@ -186,7 +186,7 @@ fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_na
186 lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{186 lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
187 cmake_binary_dir,187 cmake_binary_dir,
188 "zig_cpp",188 "zig_cpp",
189 b.fmt("{}{}{}", lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix()),189 b.fmt("{}{}{}", .{ lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix() }),
190 }) catch unreachable);190 }) catch unreachable);
191}191}
192192
...@@ -343,14 +343,14 @@ fn addCxxKnownPath(...@@ -343,14 +343,14 @@ fn addCxxKnownPath(
343) !void {343) !void {
344 const path_padded = try b.exec(&[_][]const u8{344 const path_padded = try b.exec(&[_][]const u8{
345 ctx.cxx_compiler,345 ctx.cxx_compiler,
346 b.fmt("-print-file-name={}", objname),346 b.fmt("-print-file-name={}", .{objname}),
347 });347 });
348 const path_unpadded = mem.tokenize(path_padded, "\r\n").next().?;348 const path_unpadded = mem.tokenize(path_padded, "\r\n").next().?;
349 if (mem.eql(u8, path_unpadded, objname)) {349 if (mem.eql(u8, path_unpadded, objname)) {
350 if (errtxt) |msg| {350 if (errtxt) |msg| {
351 warn("{}", msg);351 warn("{}", .{msg});
352 } else {352 } else {
353 warn("Unable to determine path to {}\n", objname);353 warn("Unable to determine path to {}\n", .{objname});
354 }354 }
355 return error.RequiredLibraryNotFound;355 return error.RequiredLibraryNotFound;
356 }356 }
doc/docgen.zig+146-135
...@@ -215,32 +215,33 @@ const Tokenizer = struct {...@@ -215,32 +215,33 @@ const Tokenizer = struct {
215 }215 }
216};216};
217217
218fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: ...) anyerror {218fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: var) anyerror {
219 const loc = tokenizer.getTokenLocation(token);219 const loc = tokenizer.getTokenLocation(token);
220 warn("{}:{}:{}: error: " ++ fmt ++ "\n", tokenizer.source_file_name, loc.line + 1, loc.column + 1, args);220 const args_prefix = .{ tokenizer.source_file_name, loc.line + 1, loc.column + 1 };
221 warn("{}:{}:{}: error: " ++ fmt ++ "\n", args_prefix ++ args);
221 if (loc.line_start <= loc.line_end) {222 if (loc.line_start <= loc.line_end) {
222 warn("{}\n", tokenizer.buffer[loc.line_start..loc.line_end]);223 warn("{}\n", .{tokenizer.buffer[loc.line_start..loc.line_end]});
223 {224 {
224 var i: usize = 0;225 var i: usize = 0;
225 while (i < loc.column) : (i += 1) {226 while (i < loc.column) : (i += 1) {
226 warn(" ");227 warn(" ", .{});
227 }228 }
228 }229 }
229 {230 {
230 const caret_count = token.end - token.start;231 const caret_count = token.end - token.start;
231 var i: usize = 0;232 var i: usize = 0;
232 while (i < caret_count) : (i += 1) {233 while (i < caret_count) : (i += 1) {
233 warn("~");234 warn("~", .{});
234 }235 }
235 }236 }
236 warn("\n");237 warn("\n", .{});
237 }238 }
238 return error.ParseError;239 return error.ParseError;
239}240}
240241
241fn assertToken(tokenizer: *Tokenizer, token: Token, id: Token.Id) !void {242fn assertToken(tokenizer: *Tokenizer, token: Token, id: Token.Id) !void {
242 if (token.id != id) {243 if (token.id != id) {
243 return parseError(tokenizer, token, "expected {}, found {}", @tagName(id), @tagName(token.id));244 return parseError(tokenizer, token, "expected {}, found {}", .{ @tagName(id), @tagName(token.id) });
244 }245 }
245}246}
246247
...@@ -339,7 +340,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {...@@ -339,7 +340,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
339 switch (token.id) {340 switch (token.id) {
340 Token.Id.Eof => {341 Token.Id.Eof => {
341 if (header_stack_size != 0) {342 if (header_stack_size != 0) {
342 return parseError(tokenizer, token, "unbalanced headers");343 return parseError(tokenizer, token, "unbalanced headers", .{});
343 }344 }
344 try toc.write(" </ul>\n");345 try toc.write(" </ul>\n");
345 break;346 break;
...@@ -373,10 +374,15 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {...@@ -373,10 +374,15 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
373 if (mem.eql(u8, param, "3col")) {374 if (mem.eql(u8, param, "3col")) {
374 columns = 3;375 columns = 3;
375 } else {376 } else {
376 return parseError(tokenizer, bracket_tok, "unrecognized header_open param: {}", param);377 return parseError(
378 tokenizer,
379 bracket_tok,
380 "unrecognized header_open param: {}",
381 .{param},
382 );
377 }383 }
378 },384 },
379 else => return parseError(tokenizer, bracket_tok, "invalid header_open token"),385 else => return parseError(tokenizer, bracket_tok, "invalid header_open token", .{}),
380 }386 }
381 }387 }
382388
...@@ -391,15 +397,15 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {...@@ -391,15 +397,15 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
391 },397 },
392 });398 });
393 if (try urls.put(urlized, tag_token)) |entry| {399 if (try urls.put(urlized, tag_token)) |entry| {
394 parseError(tokenizer, tag_token, "duplicate header url: #{}", urlized) catch {};400 parseError(tokenizer, tag_token, "duplicate header url: #{}", .{urlized}) catch {};
395 parseError(tokenizer, entry.value, "other tag here") catch {};401 parseError(tokenizer, entry.value, "other tag here", .{}) catch {};
396 return error.ParseError;402 return error.ParseError;
397 }403 }
398 if (last_action == Action.Open) {404 if (last_action == Action.Open) {
399 try toc.writeByte('\n');405 try toc.writeByte('\n');
400 try toc.writeByteNTimes(' ', header_stack_size * 4);406 try toc.writeByteNTimes(' ', header_stack_size * 4);
401 if (last_columns) |n| {407 if (last_columns) |n| {
402 try toc.print("<ul style=\"columns: {}\">\n", n);408 try toc.print("<ul style=\"columns: {}\">\n", .{n});
403 } else {409 } else {
404 try toc.write("<ul>\n");410 try toc.write("<ul>\n");
405 }411 }
...@@ -408,10 +414,10 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {...@@ -408,10 +414,10 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
408 }414 }
409 last_columns = columns;415 last_columns = columns;
410 try toc.writeByteNTimes(' ', 4 + header_stack_size * 4);416 try toc.writeByteNTimes(' ', 4 + header_stack_size * 4);
411 try toc.print("<li><a id=\"toc-{}\" href=\"#{}\">{}</a>", urlized, urlized, content);417 try toc.print("<li><a id=\"toc-{}\" href=\"#{}\">{}</a>", .{ urlized, urlized, content });
412 } else if (mem.eql(u8, tag_name, "header_close")) {418 } else if (mem.eql(u8, tag_name, "header_close")) {
413 if (header_stack_size == 0) {419 if (header_stack_size == 0) {
414 return parseError(tokenizer, tag_token, "unbalanced close header");420 return parseError(tokenizer, tag_token, "unbalanced close header", .{});
415 }421 }
416 header_stack_size -= 1;422 header_stack_size -= 1;
417 _ = try eatToken(tokenizer, Token.Id.BracketClose);423 _ = try eatToken(tokenizer, Token.Id.BracketClose);
...@@ -442,7 +448,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {...@@ -442,7 +448,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
442 try nodes.append(Node{ .SeeAlso = list.toOwnedSlice() });448 try nodes.append(Node{ .SeeAlso = list.toOwnedSlice() });
443 break;449 break;
444 },450 },
445 else => return parseError(tokenizer, see_also_tok, "invalid see_also token"),451 else => return parseError(tokenizer, see_also_tok, "invalid see_also token", .{}),
446 }452 }
447 }453 }
448 } else if (mem.eql(u8, tag_name, "link")) {454 } else if (mem.eql(u8, tag_name, "link")) {
...@@ -459,7 +465,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {...@@ -459,7 +465,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
459 _ = try eatToken(tokenizer, Token.Id.BracketClose);465 _ = try eatToken(tokenizer, Token.Id.BracketClose);
460 break :blk tokenizer.buffer[explicit_text.start..explicit_text.end];466 break :blk tokenizer.buffer[explicit_text.start..explicit_text.end];
461 },467 },
462 else => return parseError(tokenizer, tok, "invalid link token"),468 else => return parseError(tokenizer, tok, "invalid link token", .{}),
463 }469 }
464 };470 };
465471
...@@ -482,7 +488,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {...@@ -482,7 +488,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
482 _ = try eatToken(tokenizer, Token.Id.BracketClose);488 _ = try eatToken(tokenizer, Token.Id.BracketClose);
483 },489 },
484 Token.Id.BracketClose => {},490 Token.Id.BracketClose => {},
485 else => return parseError(tokenizer, token, "invalid token"),491 else => return parseError(tokenizer, token, "invalid token", .{}),
486 }492 }
487 const code_kind_str = tokenizer.buffer[code_kind_tok.start..code_kind_tok.end];493 const code_kind_str = tokenizer.buffer[code_kind_tok.start..code_kind_tok.end];
488 var code_kind_id: Code.Id = undefined;494 var code_kind_id: Code.Id = undefined;
...@@ -512,7 +518,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {...@@ -512,7 +518,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
512 code_kind_id = Code.Id{ .Obj = null };518 code_kind_id = Code.Id{ .Obj = null };
513 is_inline = true;519 is_inline = true;
514 } else {520 } else {
515 return parseError(tokenizer, code_kind_tok, "unrecognized code kind: {}", code_kind_str);521 return parseError(tokenizer, code_kind_tok, "unrecognized code kind: {}", .{code_kind_str});
516 }522 }
517523
518 var mode = builtin.Mode.Debug;524 var mode = builtin.Mode.Debug;
...@@ -550,7 +556,12 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {...@@ -550,7 +556,12 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
550 _ = try eatToken(tokenizer, Token.Id.BracketClose);556 _ = try eatToken(tokenizer, Token.Id.BracketClose);
551 break content_tok;557 break content_tok;
552 } else {558 } else {
553 return parseError(tokenizer, end_code_tag, "invalid token inside code_begin: {}", end_tag_name);559 return parseError(
560 tokenizer,
561 end_code_tag,
562 "invalid token inside code_begin: {}",
563 .{end_tag_name},
564 );
554 }565 }
555 _ = try eatToken(tokenizer, Token.Id.BracketClose);566 _ = try eatToken(tokenizer, Token.Id.BracketClose);
556 } else567 } else
...@@ -575,15 +586,20 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {...@@ -575,15 +586,20 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
575 const end_syntax_tag = try eatToken(tokenizer, Token.Id.TagContent);586 const end_syntax_tag = try eatToken(tokenizer, Token.Id.TagContent);
576 const end_tag_name = tokenizer.buffer[end_syntax_tag.start..end_syntax_tag.end];587 const end_tag_name = tokenizer.buffer[end_syntax_tag.start..end_syntax_tag.end];
577 if (!mem.eql(u8, end_tag_name, "endsyntax")) {588 if (!mem.eql(u8, end_tag_name, "endsyntax")) {
578 return parseError(tokenizer, end_syntax_tag, "invalid token inside syntax: {}", end_tag_name);589 return parseError(
590 tokenizer,
591 end_syntax_tag,
592 "invalid token inside syntax: {}",
593 .{end_tag_name},
594 );
579 }595 }
580 _ = try eatToken(tokenizer, Token.Id.BracketClose);596 _ = try eatToken(tokenizer, Token.Id.BracketClose);
581 try nodes.append(Node{ .Syntax = content_tok });597 try nodes.append(Node{ .Syntax = content_tok });
582 } else {598 } else {
583 return parseError(tokenizer, tag_token, "unrecognized tag name: {}", tag_name);599 return parseError(tokenizer, tag_token, "unrecognized tag name: {}", .{tag_name});
584 }600 }
585 },601 },
586 else => return parseError(tokenizer, token, "invalid token"),602 else => return parseError(tokenizer, token, "invalid token", .{}),
587 }603 }
588 }604 }
589605
...@@ -729,7 +745,7 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {...@@ -729,7 +745,7 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
729 try out.write("</span>");745 try out.write("</span>");
730 }746 }
731 if (first_number != 0 or second_number != 0) {747 if (first_number != 0 or second_number != 0) {
732 try out.print("<span class=\"t{}_{}\">", first_number, second_number);748 try out.print("<span class=\"t{}_{}\">", .{ first_number, second_number });
733 open_span_count += 1;749 open_span_count += 1;
734 }750 }
735 },751 },
...@@ -960,6 +976,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok...@@ -960,6 +976,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
960 docgen_tokenizer,976 docgen_tokenizer,
961 source_token,977 source_token,
962 "syntax error",978 "syntax error",
979 .{},
963 ),980 ),
964 }981 }
965 index = token.end;982 index = token.end;
...@@ -987,9 +1004,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -987,9 +1004,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
987 },1004 },
988 Node.Link => |info| {1005 Node.Link => |info| {
989 if (!toc.urls.contains(info.url)) {1006 if (!toc.urls.contains(info.url)) {
990 return parseError(tokenizer, info.token, "url not found: {}", info.url);1007 return parseError(tokenizer, info.token, "url not found: {}", .{info.url});
991 }1008 }
992 try out.print("<a href=\"#{}\">{}</a>", info.url, info.name);1009 try out.print("<a href=\"#{}\">{}</a>", .{ info.url, info.name });
993 },1010 },
994 Node.Nav => {1011 Node.Nav => {
995 try out.write(toc.toc);1012 try out.write(toc.toc);
...@@ -1002,12 +1019,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1002,12 +1019,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1002 Node.HeaderOpen => |info| {1019 Node.HeaderOpen => |info| {
1003 try out.print(1020 try out.print(
1004 "<h{} id=\"{}\"><a href=\"#toc-{}\">{}</a> <a class=\"hdr\" href=\"#{}\">§</a></h{}>\n",1021 "<h{} id=\"{}\"><a href=\"#toc-{}\">{}</a> <a class=\"hdr\" href=\"#{}\">§</a></h{}>\n",
1005 info.n,1022 .{ info.n, info.url, info.url, info.name, info.url, info.n },
1006 info.url,
1007 info.url,
1008 info.name,
1009 info.url,
1010 info.n,
1011 );1023 );
1012 },1024 },
1013 Node.SeeAlso => |items| {1025 Node.SeeAlso => |items| {
...@@ -1015,9 +1027,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1015,9 +1027,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1015 for (items) |item| {1027 for (items) |item| {
1016 const url = try urlize(allocator, item.name);1028 const url = try urlize(allocator, item.name);
1017 if (!toc.urls.contains(url)) {1029 if (!toc.urls.contains(url)) {
1018 return parseError(tokenizer, item.token, "url not found: {}", url);1030 return parseError(tokenizer, item.token, "url not found: {}", .{url});
1019 }1031 }
1020 try out.print("<li><a href=\"#{}\">{}</a></li>\n", url, item.name);1032 try out.print("<li><a href=\"#{}\">{}</a></li>\n", .{ url, item.name });
1021 }1033 }
1022 try out.write("</ul>\n");1034 try out.write("</ul>\n");
1023 },1035 },
...@@ -1026,17 +1038,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1026,17 +1038,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1026 },1038 },
1027 Node.Code => |code| {1039 Node.Code => |code| {
1028 code_progress_index += 1;1040 code_progress_index += 1;
1029 warn("docgen example code {}/{}...", code_progress_index, tokenizer.code_node_count);1041 warn("docgen example code {}/{}...", .{ code_progress_index, tokenizer.code_node_count });
10301042
1031 const raw_source = tokenizer.buffer[code.source_token.start..code.source_token.end];1043 const raw_source = tokenizer.buffer[code.source_token.start..code.source_token.end];
1032 const trimmed_raw_source = mem.trim(u8, raw_source, " \n");1044 const trimmed_raw_source = mem.trim(u8, raw_source, " \n");
1033 if (!code.is_inline) {1045 if (!code.is_inline) {
1034 try out.print("<p class=\"file\">{}.zig</p>", code.name);1046 try out.print("<p class=\"file\">{}.zig</p>", .{code.name});
1035 }1047 }
1036 try out.write("<pre>");1048 try out.write("<pre>");
1037 try tokenizeAndPrint(tokenizer, out, code.source_token);1049 try tokenizeAndPrint(tokenizer, out, code.source_token);
1038 try out.write("</pre>");1050 try out.write("</pre>");
1039 const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", code.name);1051 const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", .{code.name});
1040 const tmp_source_file_name = try fs.path.join(1052 const tmp_source_file_name = try fs.path.join(
1041 allocator,1053 allocator,
1042 &[_][]const u8{ tmp_dir_name, name_plus_ext },1054 &[_][]const u8{ tmp_dir_name, name_plus_ext },
...@@ -1045,7 +1057,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1045,7 +1057,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10451057
1046 switch (code.id) {1058 switch (code.id) {
1047 Code.Id.Exe => |expected_outcome| code_block: {1059 Code.Id.Exe => |expected_outcome| code_block: {
1048 const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, exe_ext);1060 const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{}{}", .{ code.name, exe_ext });
1049 var build_args = std.ArrayList([]const u8).init(allocator);1061 var build_args = std.ArrayList([]const u8).init(allocator);
1050 defer build_args.deinit();1062 defer build_args.deinit();
1051 try build_args.appendSlice(&[_][]const u8{1063 try build_args.appendSlice(&[_][]const u8{
...@@ -1059,40 +1071,40 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1059,40 +1071,40 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1059 "--cache",1071 "--cache",
1060 "on",1072 "on",
1061 });1073 });
1062 try out.print("<pre><code class=\"shell\">$ zig build-exe {}.zig", code.name);1074 try out.print("<pre><code class=\"shell\">$ zig build-exe {}.zig", .{code.name});
1063 switch (code.mode) {1075 switch (code.mode) {
1064 builtin.Mode.Debug => {},1076 builtin.Mode.Debug => {},
1065 builtin.Mode.ReleaseSafe => {1077 builtin.Mode.ReleaseSafe => {
1066 try build_args.append("--release-safe");1078 try build_args.append("--release-safe");
1067 try out.print(" --release-safe");1079 try out.print(" --release-safe", .{});
1068 },1080 },
1069 builtin.Mode.ReleaseFast => {1081 builtin.Mode.ReleaseFast => {
1070 try build_args.append("--release-fast");1082 try build_args.append("--release-fast");
1071 try out.print(" --release-fast");1083 try out.print(" --release-fast", .{});
1072 },1084 },
1073 builtin.Mode.ReleaseSmall => {1085 builtin.Mode.ReleaseSmall => {
1074 try build_args.append("--release-small");1086 try build_args.append("--release-small");
1075 try out.print(" --release-small");1087 try out.print(" --release-small", .{});
1076 },1088 },
1077 }1089 }
1078 for (code.link_objects) |link_object| {1090 for (code.link_objects) |link_object| {
1079 const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", link_object, obj_ext);1091 const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", .{ link_object, obj_ext });
1080 const full_path_object = try fs.path.join(1092 const full_path_object = try fs.path.join(
1081 allocator,1093 allocator,
1082 &[_][]const u8{ tmp_dir_name, name_with_ext },1094 &[_][]const u8{ tmp_dir_name, name_with_ext },
1083 );1095 );
1084 try build_args.append("--object");1096 try build_args.append("--object");
1085 try build_args.append(full_path_object);1097 try build_args.append(full_path_object);
1086 try out.print(" --object {}", name_with_ext);1098 try out.print(" --object {}", .{name_with_ext});
1087 }1099 }
1088 if (code.link_libc) {1100 if (code.link_libc) {
1089 try build_args.append("-lc");1101 try build_args.append("-lc");
1090 try out.print(" -lc");1102 try out.print(" -lc", .{});
1091 }1103 }
1092 if (code.target_str) |triple| {1104 if (code.target_str) |triple| {
1093 try build_args.appendSlice(&[_][]const u8{ "-target", triple });1105 try build_args.appendSlice(&[_][]const u8{ "-target", triple });
1094 if (!code.is_inline) {1106 if (!code.is_inline) {
1095 try out.print(" -target {}", triple);1107 try out.print(" -target {}", .{triple});
1096 }1108 }
1097 }1109 }
1098 if (expected_outcome == .BuildFail) {1110 if (expected_outcome == .BuildFail) {
...@@ -1106,29 +1118,29 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1106,29 +1118,29 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1106 switch (result.term) {1118 switch (result.term) {
1107 .Exited => |exit_code| {1119 .Exited => |exit_code| {
1108 if (exit_code == 0) {1120 if (exit_code == 0) {
1109 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);1121 warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
1110 for (build_args.toSliceConst()) |arg|1122 for (build_args.toSliceConst()) |arg|
1111 warn("{} ", arg)1123 warn("{} ", .{arg})
1112 else1124 else
1113 warn("\n");1125 warn("\n", .{});
1114 return parseError(tokenizer, code.source_token, "example incorrectly compiled");1126 return parseError(tokenizer, code.source_token, "example incorrectly compiled", .{});
1115 }1127 }
1116 },1128 },
1117 else => {1129 else => {
1118 warn("{}\nThe following command crashed:\n", result.stderr);1130 warn("{}\nThe following command crashed:\n", .{result.stderr});
1119 for (build_args.toSliceConst()) |arg|1131 for (build_args.toSliceConst()) |arg|
1120 warn("{} ", arg)1132 warn("{} ", .{arg})
1121 else1133 else
1122 warn("\n");1134 warn("\n", .{});
1123 return parseError(tokenizer, code.source_token, "example compile crashed");1135 return parseError(tokenizer, code.source_token, "example compile crashed", .{});
1124 },1136 },
1125 }1137 }
1126 const escaped_stderr = try escapeHtml(allocator, result.stderr);1138 const escaped_stderr = try escapeHtml(allocator, result.stderr);
1127 const colored_stderr = try termColor(allocator, escaped_stderr);1139 const colored_stderr = try termColor(allocator, escaped_stderr);
1128 try out.print("\n{}</code></pre>\n", colored_stderr);1140 try out.print("\n{}</code></pre>\n", .{colored_stderr});
1129 break :code_block;1141 break :code_block;
1130 }1142 }
1131 const exec_result = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile");1143 const exec_result = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
11321144
1133 if (code.target_str) |triple| {1145 if (code.target_str) |triple| {
1134 if (mem.startsWith(u8, triple, "wasm32") or1146 if (mem.startsWith(u8, triple, "wasm32") or
...@@ -1137,7 +1149,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1137,7 +1149,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1137 (builtin.os != .linux or builtin.arch != .x86_64))1149 (builtin.os != .linux or builtin.arch != .x86_64))
1138 {1150 {
1139 // skip execution1151 // skip execution
1140 try out.print("</code></pre>\n");1152 try out.print("</code></pre>\n", .{});
1141 break :code_block;1153 break :code_block;
1142 }1154 }
1143 }1155 }
...@@ -1152,12 +1164,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1152,12 +1164,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1152 switch (result.term) {1164 switch (result.term) {
1153 .Exited => |exit_code| {1165 .Exited => |exit_code| {
1154 if (exit_code == 0) {1166 if (exit_code == 0) {
1155 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);1167 warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
1156 for (run_args) |arg|1168 for (run_args) |arg|
1157 warn("{} ", arg)1169 warn("{} ", .{arg})
1158 else1170 else
1159 warn("\n");1171 warn("\n", .{});
1160 return parseError(tokenizer, code.source_token, "example incorrectly compiled");1172 return parseError(tokenizer, code.source_token, "example incorrectly compiled", .{});
1161 }1173 }
1162 },1174 },
1163 .Signal => exited_with_signal = true,1175 .Signal => exited_with_signal = true,
...@@ -1165,7 +1177,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1165,7 +1177,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1165 }1177 }
1166 break :blk result;1178 break :blk result;
1167 } else blk: {1179 } else blk: {
1168 break :blk exec(allocator, &env_map, run_args) catch return parseError(tokenizer, code.source_token, "example crashed");1180 break :blk exec(allocator, &env_map, run_args) catch return parseError(tokenizer, code.source_token, "example crashed", .{});
1169 };1181 };
11701182
1171 const escaped_stderr = try escapeHtml(allocator, result.stderr);1183 const escaped_stderr = try escapeHtml(allocator, result.stderr);
...@@ -1174,11 +1186,11 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1174,11 +1186,11 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1174 const colored_stderr = try termColor(allocator, escaped_stderr);1186 const colored_stderr = try termColor(allocator, escaped_stderr);
1175 const colored_stdout = try termColor(allocator, escaped_stdout);1187 const colored_stdout = try termColor(allocator, escaped_stdout);
11761188
1177 try out.print("\n$ ./{}\n{}{}", code.name, colored_stdout, colored_stderr);1189 try out.print("\n$ ./{}\n{}{}", .{ code.name, colored_stdout, colored_stderr });
1178 if (exited_with_signal) {1190 if (exited_with_signal) {
1179 try out.print("(process terminated by signal)");1191 try out.print("(process terminated by signal)", .{});
1180 }1192 }
1181 try out.print("</code></pre>\n");1193 try out.print("</code></pre>\n", .{});
1182 },1194 },
1183 Code.Id.Test => {1195 Code.Id.Test => {
1184 var test_args = std.ArrayList([]const u8).init(allocator);1196 var test_args = std.ArrayList([]const u8).init(allocator);
...@@ -1191,34 +1203,34 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1191,34 +1203,34 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1191 "--cache",1203 "--cache",
1192 "on",1204 "on",
1193 });1205 });
1194 try out.print("<pre><code class=\"shell\">$ zig test {}.zig", code.name);1206 try out.print("<pre><code class=\"shell\">$ zig test {}.zig", .{code.name});
1195 switch (code.mode) {1207 switch (code.mode) {
1196 builtin.Mode.Debug => {},1208 builtin.Mode.Debug => {},
1197 builtin.Mode.ReleaseSafe => {1209 builtin.Mode.ReleaseSafe => {
1198 try test_args.append("--release-safe");1210 try test_args.append("--release-safe");
1199 try out.print(" --release-safe");1211 try out.print(" --release-safe", .{});
1200 },1212 },
1201 builtin.Mode.ReleaseFast => {1213 builtin.Mode.ReleaseFast => {
1202 try test_args.append("--release-fast");1214 try test_args.append("--release-fast");
1203 try out.print(" --release-fast");1215 try out.print(" --release-fast", .{});
1204 },1216 },
1205 builtin.Mode.ReleaseSmall => {1217 builtin.Mode.ReleaseSmall => {
1206 try test_args.append("--release-small");1218 try test_args.append("--release-small");
1207 try out.print(" --release-small");1219 try out.print(" --release-small", .{});
1208 },1220 },
1209 }1221 }
1210 if (code.link_libc) {1222 if (code.link_libc) {
1211 try test_args.append("-lc");1223 try test_args.append("-lc");
1212 try out.print(" -lc");1224 try out.print(" -lc", .{});
1213 }1225 }
1214 if (code.target_str) |triple| {1226 if (code.target_str) |triple| {
1215 try test_args.appendSlice(&[_][]const u8{ "-target", triple });1227 try test_args.appendSlice(&[_][]const u8{ "-target", triple });
1216 try out.print(" -target {}", triple);1228 try out.print(" -target {}", .{triple});
1217 }1229 }
1218 const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed");1230 const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed", .{});
1219 const escaped_stderr = try escapeHtml(allocator, result.stderr);1231 const escaped_stderr = try escapeHtml(allocator, result.stderr);
1220 const escaped_stdout = try escapeHtml(allocator, result.stdout);1232 const escaped_stdout = try escapeHtml(allocator, result.stdout);
1221 try out.print("\n{}{}</code></pre>\n", escaped_stderr, escaped_stdout);1233 try out.print("\n{}{}</code></pre>\n", .{ escaped_stderr, escaped_stdout });
1222 },1234 },
1223 Code.Id.TestError => |error_match| {1235 Code.Id.TestError => |error_match| {
1224 var test_args = std.ArrayList([]const u8).init(allocator);1236 var test_args = std.ArrayList([]const u8).init(allocator);
...@@ -1233,50 +1245,50 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1233,50 +1245,50 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1233 "--output-dir",1245 "--output-dir",
1234 tmp_dir_name,1246 tmp_dir_name,
1235 });1247 });
1236 try out.print("<pre><code class=\"shell\">$ zig test {}.zig", code.name);1248 try out.print("<pre><code class=\"shell\">$ zig test {}.zig", .{code.name});
1237 switch (code.mode) {1249 switch (code.mode) {
1238 builtin.Mode.Debug => {},1250 builtin.Mode.Debug => {},
1239 builtin.Mode.ReleaseSafe => {1251 builtin.Mode.ReleaseSafe => {
1240 try test_args.append("--release-safe");1252 try test_args.append("--release-safe");
1241 try out.print(" --release-safe");1253 try out.print(" --release-safe", .{});
1242 },1254 },
1243 builtin.Mode.ReleaseFast => {1255 builtin.Mode.ReleaseFast => {
1244 try test_args.append("--release-fast");1256 try test_args.append("--release-fast");
1245 try out.print(" --release-fast");1257 try out.print(" --release-fast", .{});
1246 },1258 },
1247 builtin.Mode.ReleaseSmall => {1259 builtin.Mode.ReleaseSmall => {
1248 try test_args.append("--release-small");1260 try test_args.append("--release-small");
1249 try out.print(" --release-small");1261 try out.print(" --release-small", .{});
1250 },1262 },
1251 }1263 }
1252 const result = try ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size);1264 const result = try ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size);
1253 switch (result.term) {1265 switch (result.term) {
1254 .Exited => |exit_code| {1266 .Exited => |exit_code| {
1255 if (exit_code == 0) {1267 if (exit_code == 0) {
1256 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);1268 warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
1257 for (test_args.toSliceConst()) |arg|1269 for (test_args.toSliceConst()) |arg|
1258 warn("{} ", arg)1270 warn("{} ", .{arg})
1259 else1271 else
1260 warn("\n");1272 warn("\n", .{});
1261 return parseError(tokenizer, code.source_token, "example incorrectly compiled");1273 return parseError(tokenizer, code.source_token, "example incorrectly compiled", .{});
1262 }1274 }
1263 },1275 },
1264 else => {1276 else => {
1265 warn("{}\nThe following command crashed:\n", result.stderr);1277 warn("{}\nThe following command crashed:\n", .{result.stderr});
1266 for (test_args.toSliceConst()) |arg|1278 for (test_args.toSliceConst()) |arg|
1267 warn("{} ", arg)1279 warn("{} ", .{arg})
1268 else1280 else
1269 warn("\n");1281 warn("\n", .{});
1270 return parseError(tokenizer, code.source_token, "example compile crashed");1282 return parseError(tokenizer, code.source_token, "example compile crashed", .{});
1271 },1283 },
1272 }1284 }
1273 if (mem.indexOf(u8, result.stderr, error_match) == null) {1285 if (mem.indexOf(u8, result.stderr, error_match) == null) {
1274 warn("{}\nExpected to find '{}' in stderr", result.stderr, error_match);1286 warn("{}\nExpected to find '{}' in stderr", .{ result.stderr, error_match });
1275 return parseError(tokenizer, code.source_token, "example did not have expected compile error");1287 return parseError(tokenizer, code.source_token, "example did not have expected compile error", .{});
1276 }1288 }
1277 const escaped_stderr = try escapeHtml(allocator, result.stderr);1289 const escaped_stderr = try escapeHtml(allocator, result.stderr);
1278 const colored_stderr = try termColor(allocator, escaped_stderr);1290 const colored_stderr = try termColor(allocator, escaped_stderr);
1279 try out.print("\n{}</code></pre>\n", colored_stderr);1291 try out.print("\n{}</code></pre>\n", .{colored_stderr});
1280 },1292 },
12811293
1282 Code.Id.TestSafety => |error_match| {1294 Code.Id.TestSafety => |error_match| {
...@@ -1311,38 +1323,37 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1311,38 +1323,37 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1311 switch (result.term) {1323 switch (result.term) {
1312 .Exited => |exit_code| {1324 .Exited => |exit_code| {
1313 if (exit_code == 0) {1325 if (exit_code == 0) {
1314 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);1326 warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
1315 for (test_args.toSliceConst()) |arg|1327 for (test_args.toSliceConst()) |arg|
1316 warn("{} ", arg)1328 warn("{} ", .{arg})
1317 else1329 else
1318 warn("\n");1330 warn("\n", .{});
1319 return parseError(tokenizer, code.source_token, "example test incorrectly succeeded");1331 return parseError(tokenizer, code.source_token, "example test incorrectly succeeded", .{});
1320 }1332 }
1321 },1333 },
1322 else => {1334 else => {
1323 warn("{}\nThe following command crashed:\n", result.stderr);1335 warn("{}\nThe following command crashed:\n", .{result.stderr});
1324 for (test_args.toSliceConst()) |arg|1336 for (test_args.toSliceConst()) |arg|
1325 warn("{} ", arg)1337 warn("{} ", .{arg})
1326 else1338 else
1327 warn("\n");1339 warn("\n", .{});
1328 return parseError(tokenizer, code.source_token, "example compile crashed");1340 return parseError(tokenizer, code.source_token, "example compile crashed", .{});
1329 },1341 },
1330 }1342 }
1331 if (mem.indexOf(u8, result.stderr, error_match) == null) {1343 if (mem.indexOf(u8, result.stderr, error_match) == null) {
1332 warn("{}\nExpected to find '{}' in stderr", result.stderr, error_match);1344 warn("{}\nExpected to find '{}' in stderr", .{ result.stderr, error_match });
1333 return parseError(tokenizer, code.source_token, "example did not have expected runtime safety error message");1345 return parseError(tokenizer, code.source_token, "example did not have expected runtime safety error message", .{});
1334 }1346 }
1335 const escaped_stderr = try escapeHtml(allocator, result.stderr);1347 const escaped_stderr = try escapeHtml(allocator, result.stderr);
1336 const colored_stderr = try termColor(allocator, escaped_stderr);1348 const colored_stderr = try termColor(allocator, escaped_stderr);
1337 try out.print(1349 try out.print("<pre><code class=\"shell\">$ zig test {}.zig{}\n{}</code></pre>\n", .{
1338 "<pre><code class=\"shell\">$ zig test {}.zig{}\n{}</code></pre>\n",
1339 code.name,1350 code.name,
1340 mode_arg,1351 mode_arg,
1341 colored_stderr,1352 colored_stderr,
1342 );1353 });
1343 },1354 },
1344 Code.Id.Obj => |maybe_error_match| {1355 Code.Id.Obj => |maybe_error_match| {
1345 const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, obj_ext);1356 const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", .{ code.name, obj_ext });
1346 const tmp_obj_file_name = try fs.path.join(1357 const tmp_obj_file_name = try fs.path.join(
1347 allocator,1358 allocator,
1348 &[_][]const u8{ tmp_dir_name, name_plus_obj_ext },1359 &[_][]const u8{ tmp_dir_name, name_plus_obj_ext },
...@@ -1350,7 +1361,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1350,7 +1361,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1350 var build_args = std.ArrayList([]const u8).init(allocator);1361 var build_args = std.ArrayList([]const u8).init(allocator);
1351 defer build_args.deinit();1362 defer build_args.deinit();
13521363
1353 const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{}.h", code.name);1364 const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{}.h", .{code.name});
1354 const output_h_file_name = try fs.path.join(1365 const output_h_file_name = try fs.path.join(
1355 allocator,1366 allocator,
1356 &[_][]const u8{ tmp_dir_name, name_plus_h_ext },1367 &[_][]const u8{ tmp_dir_name, name_plus_h_ext },
...@@ -1369,7 +1380,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1369,7 +1380,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1369 });1380 });
13701381
1371 if (!code.is_inline) {1382 if (!code.is_inline) {
1372 try out.print("<pre><code class=\"shell\">$ zig build-obj {}.zig", code.name);1383 try out.print("<pre><code class=\"shell\">$ zig build-obj {}.zig", .{code.name});
1373 }1384 }
13741385
1375 switch (code.mode) {1386 switch (code.mode) {
...@@ -1377,26 +1388,26 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1377,26 +1388,26 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1377 builtin.Mode.ReleaseSafe => {1388 builtin.Mode.ReleaseSafe => {
1378 try build_args.append("--release-safe");1389 try build_args.append("--release-safe");
1379 if (!code.is_inline) {1390 if (!code.is_inline) {
1380 try out.print(" --release-safe");1391 try out.print(" --release-safe", .{});
1381 }1392 }
1382 },1393 },
1383 builtin.Mode.ReleaseFast => {1394 builtin.Mode.ReleaseFast => {
1384 try build_args.append("--release-fast");1395 try build_args.append("--release-fast");
1385 if (!code.is_inline) {1396 if (!code.is_inline) {
1386 try out.print(" --release-fast");1397 try out.print(" --release-fast", .{});
1387 }1398 }
1388 },1399 },
1389 builtin.Mode.ReleaseSmall => {1400 builtin.Mode.ReleaseSmall => {
1390 try build_args.append("--release-small");1401 try build_args.append("--release-small");
1391 if (!code.is_inline) {1402 if (!code.is_inline) {
1392 try out.print(" --release-small");1403 try out.print(" --release-small", .{});
1393 }1404 }
1394 },1405 },
1395 }1406 }
13961407
1397 if (code.target_str) |triple| {1408 if (code.target_str) |triple| {
1398 try build_args.appendSlice(&[_][]const u8{ "-target", triple });1409 try build_args.appendSlice(&[_][]const u8{ "-target", triple });
1399 try out.print(" -target {}", triple);1410 try out.print(" -target {}", .{triple});
1400 }1411 }
14011412
1402 if (maybe_error_match) |error_match| {1413 if (maybe_error_match) |error_match| {
...@@ -1404,35 +1415,35 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1404,35 +1415,35 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1404 switch (result.term) {1415 switch (result.term) {
1405 .Exited => |exit_code| {1416 .Exited => |exit_code| {
1406 if (exit_code == 0) {1417 if (exit_code == 0) {
1407 warn("{}\nThe following command incorrectly succeeded:\n", result.stderr);1418 warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
1408 for (build_args.toSliceConst()) |arg|1419 for (build_args.toSliceConst()) |arg|
1409 warn("{} ", arg)1420 warn("{} ", .{arg})
1410 else1421 else
1411 warn("\n");1422 warn("\n", .{});
1412 return parseError(tokenizer, code.source_token, "example build incorrectly succeeded");1423 return parseError(tokenizer, code.source_token, "example build incorrectly succeeded", .{});
1413 }1424 }
1414 },1425 },
1415 else => {1426 else => {
1416 warn("{}\nThe following command crashed:\n", result.stderr);1427 warn("{}\nThe following command crashed:\n", .{result.stderr});
1417 for (build_args.toSliceConst()) |arg|1428 for (build_args.toSliceConst()) |arg|
1418 warn("{} ", arg)1429 warn("{} ", .{arg})
1419 else1430 else
1420 warn("\n");1431 warn("\n", .{});
1421 return parseError(tokenizer, code.source_token, "example compile crashed");1432 return parseError(tokenizer, code.source_token, "example compile crashed", .{});
1422 },1433 },
1423 }1434 }
1424 if (mem.indexOf(u8, result.stderr, error_match) == null) {1435 if (mem.indexOf(u8, result.stderr, error_match) == null) {
1425 warn("{}\nExpected to find '{}' in stderr", result.stderr, error_match);1436 warn("{}\nExpected to find '{}' in stderr", .{ result.stderr, error_match });
1426 return parseError(tokenizer, code.source_token, "example did not have expected compile error message");1437 return parseError(tokenizer, code.source_token, "example did not have expected compile error message", .{});
1427 }1438 }
1428 const escaped_stderr = try escapeHtml(allocator, result.stderr);1439 const escaped_stderr = try escapeHtml(allocator, result.stderr);
1429 const colored_stderr = try termColor(allocator, escaped_stderr);1440 const colored_stderr = try termColor(allocator, escaped_stderr);
1430 try out.print("\n{}", colored_stderr);1441 try out.print("\n{}", .{colored_stderr});
1431 } else {1442 } else {
1432 _ = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile");1443 _ = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
1433 }1444 }
1434 if (!code.is_inline) {1445 if (!code.is_inline) {
1435 try out.print("</code></pre>\n");1446 try out.print("</code></pre>\n", .{});
1436 }1447 }
1437 },1448 },
1438 Code.Id.Lib => {1449 Code.Id.Lib => {
...@@ -1446,33 +1457,33 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1446,33 +1457,33 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1446 "--output-dir",1457 "--output-dir",
1447 tmp_dir_name,1458 tmp_dir_name,
1448 });1459 });
1449 try out.print("<pre><code class=\"shell\">$ zig build-lib {}.zig", code.name);1460 try out.print("<pre><code class=\"shell\">$ zig build-lib {}.zig", .{code.name});
1450 switch (code.mode) {1461 switch (code.mode) {
1451 builtin.Mode.Debug => {},1462 builtin.Mode.Debug => {},
1452 builtin.Mode.ReleaseSafe => {1463 builtin.Mode.ReleaseSafe => {
1453 try test_args.append("--release-safe");1464 try test_args.append("--release-safe");
1454 try out.print(" --release-safe");1465 try out.print(" --release-safe", .{});
1455 },1466 },
1456 builtin.Mode.ReleaseFast => {1467 builtin.Mode.ReleaseFast => {
1457 try test_args.append("--release-fast");1468 try test_args.append("--release-fast");
1458 try out.print(" --release-fast");1469 try out.print(" --release-fast", .{});
1459 },1470 },
1460 builtin.Mode.ReleaseSmall => {1471 builtin.Mode.ReleaseSmall => {
1461 try test_args.append("--release-small");1472 try test_args.append("--release-small");
1462 try out.print(" --release-small");1473 try out.print(" --release-small", .{});
1463 },1474 },
1464 }1475 }
1465 if (code.target_str) |triple| {1476 if (code.target_str) |triple| {
1466 try test_args.appendSlice(&[_][]const u8{ "-target", triple });1477 try test_args.appendSlice(&[_][]const u8{ "-target", triple });
1467 try out.print(" -target {}", triple);1478 try out.print(" -target {}", .{triple});
1468 }1479 }
1469 const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed");1480 const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed", .{});
1470 const escaped_stderr = try escapeHtml(allocator, result.stderr);1481 const escaped_stderr = try escapeHtml(allocator, result.stderr);
1471 const escaped_stdout = try escapeHtml(allocator, result.stdout);1482 const escaped_stdout = try escapeHtml(allocator, result.stdout);
1472 try out.print("\n{}{}</code></pre>\n", escaped_stderr, escaped_stdout);1483 try out.print("\n{}{}</code></pre>\n", .{ escaped_stderr, escaped_stdout });
1473 },1484 },
1474 }1485 }
1475 warn("OK\n");1486 warn("OK\n", .{});
1476 },1487 },
1477 }1488 }
1478 }1489 }
...@@ -1483,20 +1494,20 @@ fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u...@@ -1483,20 +1494,20 @@ fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u
1483 switch (result.term) {1494 switch (result.term) {
1484 .Exited => |exit_code| {1495 .Exited => |exit_code| {
1485 if (exit_code != 0) {1496 if (exit_code != 0) {
1486 warn("{}\nThe following command exited with code {}:\n", result.stderr, exit_code);1497 warn("{}\nThe following command exited with code {}:\n", .{ result.stderr, exit_code });
1487 for (args) |arg|1498 for (args) |arg|
1488 warn("{} ", arg)1499 warn("{} ", .{arg})
1489 else1500 else
1490 warn("\n");1501 warn("\n", .{});
1491 return error.ChildExitError;1502 return error.ChildExitError;
1492 }1503 }
1493 },1504 },
1494 else => {1505 else => {
1495 warn("{}\nThe following command crashed:\n", result.stderr);1506 warn("{}\nThe following command crashed:\n", .{result.stderr});
1496 for (args) |arg|1507 for (args) |arg|
1497 warn("{} ", arg)1508 warn("{} ", .{arg})
1498 else1509 else
1499 warn("\n");1510 warn("\n", .{});
1500 return error.ChildCrashed;1511 return error.ChildCrashed;
1501 },1512 },
1502 }1513 }
doc/langref.html.in+82-70
...@@ -205,7 +205,7 @@ const std = @import("std");...@@ -205,7 +205,7 @@ const std = @import("std");
205205
206pub fn main() !void {206pub fn main() !void {
207 const stdout = &std.io.getStdOut().outStream().stream;207 const stdout = &std.io.getStdOut().outStream().stream;
208 try stdout.print("Hello, {}!\n", "world");208 try stdout.print("Hello, {}!\n", .{"world"});
209}209}
210 {#code_end#}210 {#code_end#}
211 <p>211 <p>
...@@ -217,7 +217,7 @@ pub fn main() !void {...@@ -217,7 +217,7 @@ pub fn main() !void {
217const warn = @import("std").debug.warn;217const warn = @import("std").debug.warn;
218218
219pub fn main() void {219pub fn main() void {
220 warn("Hello, world!\n");220 warn("Hello, world!\n", .{});
221}221}
222 {#code_end#}222 {#code_end#}
223 <p>223 <p>
...@@ -289,41 +289,50 @@ const assert = std.debug.assert;...@@ -289,41 +289,50 @@ const assert = std.debug.assert;
289pub fn main() void {289pub fn main() void {
290 // integers290 // integers
291 const one_plus_one: i32 = 1 + 1;291 const one_plus_one: i32 = 1 + 1;
292 warn("1 + 1 = {}\n", one_plus_one);292 warn("1 + 1 = {}\n", .{one_plus_one});
293293
294 // floats294 // floats
295 const seven_div_three: f32 = 7.0 / 3.0;295 const seven_div_three: f32 = 7.0 / 3.0;
296 warn("7.0 / 3.0 = {}\n", seven_div_three);296 warn("7.0 / 3.0 = {}\n", .{seven_div_three});
297297
298 // boolean298 // boolean
299 warn("{}\n{}\n{}\n",299 warn("{}\n{}\n{}\n", .{
300 true and false,300 true and false,
301 true or false,301 true or false,
302 !true);302 !true,
303 });
303304
304 // optional305 // optional
305 var optional_value: ?[]const u8 = null;306 var optional_value: ?[]const u8 = null;
306 assert(optional_value == null);307 assert(optional_value == null);
307308
308 warn("\noptional 1\ntype: {}\nvalue: {}\n",309 warn("\noptional 1\ntype: {}\nvalue: {}\n", .{
309 @typeName(@typeOf(optional_value)), optional_value);310 @typeName(@typeOf(optional_value)),
311 optional_value,
312 });
310313
311 optional_value = "hi";314 optional_value = "hi";
312 assert(optional_value != null);315 assert(optional_value != null);
313316
314 warn("\noptional 2\ntype: {}\nvalue: {}\n",317 warn("\noptional 2\ntype: {}\nvalue: {}\n", .{
315 @typeName(@typeOf(optional_value)), optional_value);318 @typeName(@typeOf(optional_value)),
319 optional_value,
320 });
316321
317 // error union322 // error union
318 var number_or_error: anyerror!i32 = error.ArgNotFound;323 var number_or_error: anyerror!i32 = error.ArgNotFound;
319324
320 warn("\nerror union 1\ntype: {}\nvalue: {}\n",325 warn("\nerror union 1\ntype: {}\nvalue: {}\n", .{
321 @typeName(@typeOf(number_or_error)), number_or_error);326 @typeName(@typeOf(number_or_error)),
327 number_or_error,
328 });
322329
323 number_or_error = 1234;330 number_or_error = 1234;
324331
325 warn("\nerror union 2\ntype: {}\nvalue: {}\n",332 warn("\nerror union 2\ntype: {}\nvalue: {}\n", .{
326 @typeName(@typeOf(number_or_error)), number_or_error);333 @typeName(@typeOf(number_or_error)),
334 number_or_error,
335 });
327}336}
328 {#code_end#}337 {#code_end#}
329 {#header_open|Primitive Types#}338 {#header_open|Primitive Types#}
...@@ -954,8 +963,8 @@ extern fn foo_optimized(x: f64) f64;...@@ -954,8 +963,8 @@ extern fn foo_optimized(x: f64) f64;
954963
955pub fn main() void {964pub fn main() void {
956 const x = 0.001;965 const x = 0.001;
957 warn("optimized = {}\n", foo_optimized(x));966 warn("optimized = {}\n", .{foo_optimized(x)});
958 warn("strict = {}\n", foo_strict(x));967 warn("strict = {}\n", .{foo_strict(x)});
959}968}
960 {#code_end#}969 {#code_end#}
961 {#see_also|@setFloatMode|Division by Zero#}970 {#see_also|@setFloatMode|Division by Zero#}
...@@ -2182,7 +2191,7 @@ test "using slices for strings" {...@@ -2182,7 +2191,7 @@ test "using slices for strings" {
2182 // You can use slice syntax on an array to convert an array into a slice.2191 // You can use slice syntax on an array to convert an array into a slice.
2183 const all_together_slice = all_together[0..];2192 const all_together_slice = all_together[0..];
2184 // String concatenation example.2193 // String concatenation example.
2185 const hello_world = try fmt.bufPrint(all_together_slice, "{} {}", hello, world);2194 const hello_world = try fmt.bufPrint(all_together_slice, "{} {}", .{hello, world});
21862195
2187 // Generally, you can use UTF-8 and not worry about whether something is a2196 // Generally, you can use UTF-8 and not worry about whether something is a
2188 // string. If you don't need to deal with individual characters, no need2197 // string. If you don't need to deal with individual characters, no need
...@@ -2623,9 +2632,9 @@ const std = @import("std");...@@ -2623,9 +2632,9 @@ const std = @import("std");
26232632
2624pub fn main() void {2633pub fn main() void {
2625 const Foo = struct {};2634 const Foo = struct {};
2626 std.debug.warn("variable: {}\n", @typeName(Foo));2635 std.debug.warn("variable: {}\n", .{@typeName(Foo)});
2627 std.debug.warn("anonymous: {}\n", @typeName(struct {}));2636 std.debug.warn("anonymous: {}\n", .{@typeName(struct {})});
2628 std.debug.warn("function: {}\n", @typeName(List(i32)));2637 std.debug.warn("function: {}\n", .{@typeName(List(i32))});
2629}2638}
26302639
2631fn List(comptime T: type) type {2640fn List(comptime T: type) type {
...@@ -3806,18 +3815,18 @@ test "defer basics" {...@@ -3806,18 +3815,18 @@ test "defer basics" {
3806// If multiple defer statements are specified, they will be executed in3815// If multiple defer statements are specified, they will be executed in
3807// the reverse order they were run.3816// the reverse order they were run.
3808fn deferUnwindExample() void {3817fn deferUnwindExample() void {
3809 warn("\n");3818 warn("\n", .{});
38103819
3811 defer {3820 defer {
3812 warn("1 ");3821 warn("1 ", .{});
3813 }3822 }
3814 defer {3823 defer {
3815 warn("2 ");3824 warn("2 ", .{});
3816 }3825 }
3817 if (false) {3826 if (false) {
3818 // defers are not run if they are never executed.3827 // defers are not run if they are never executed.
3819 defer {3828 defer {
3820 warn("3 ");3829 warn("3 ", .{});
3821 }3830 }
3822 }3831 }
3823}3832}
...@@ -3832,15 +3841,15 @@ test "defer unwinding" {...@@ -3832,15 +3841,15 @@ test "defer unwinding" {
3832// This is especially useful in allowing a function to clean up properly3841// This is especially useful in allowing a function to clean up properly
3833// on error, and replaces goto error handling tactics as seen in c.3842// on error, and replaces goto error handling tactics as seen in c.
3834fn deferErrorExample(is_error: bool) !void {3843fn deferErrorExample(is_error: bool) !void {
3835 warn("\nstart of function\n");3844 warn("\nstart of function\n", .{});
38363845
3837 // This will always be executed on exit3846 // This will always be executed on exit
3838 defer {3847 defer {
3839 warn("end of function\n");3848 warn("end of function\n", .{});
3840 }3849 }
38413850
3842 errdefer {3851 errdefer {
3843 warn("encountered an error!\n");3852 warn("encountered an error!\n", .{});
3844 }3853 }
38453854
3846 if (is_error) {3855 if (is_error) {
...@@ -5843,7 +5852,7 @@ const a_number: i32 = 1234;...@@ -5843,7 +5852,7 @@ const a_number: i32 = 1234;
5843const a_string = "foobar";5852const a_string = "foobar";
58445853
5845pub fn main() void {5854pub fn main() void {
5846 warn("here is a string: '{}' here is a number: {}\n", a_string, a_number);5855 warn("here is a string: '{}' here is a number: {}\n", .{a_string, a_number});
5847}5856}
5848 {#code_end#}5857 {#code_end#}
58495858
...@@ -5960,8 +5969,11 @@ const a_number: i32 = 1234;...@@ -5960,8 +5969,11 @@ const a_number: i32 = 1234;
5960const a_string = "foobar";5969const a_string = "foobar";
59615970
5962test "printf too many arguments" {5971test "printf too many arguments" {
5963 warn("here is a string: '{}' here is a number: {}\n",5972 warn("here is a string: '{}' here is a number: {}\n", .{
5964 a_string, a_number, a_number);5973 a_string,
5974 a_number,
5975 a_number,
5976 });
5965}5977}
5966 {#code_end#}5978 {#code_end#}
5967 <p>5979 <p>
...@@ -5979,7 +5991,7 @@ const a_string = "foobar";...@@ -5979,7 +5991,7 @@ const a_string = "foobar";
5979const fmt = "here is a string: '{}' here is a number: {}\n";5991const fmt = "here is a string: '{}' here is a number: {}\n";
59805992
5981pub fn main() void {5993pub fn main() void {
5982 warn(fmt, a_string, a_number);5994 warn(fmt, .{a_string, a_number});
5983}5995}
5984 {#code_end#}5996 {#code_end#}
5985 <p>5997 <p>
...@@ -6417,7 +6429,7 @@ pub fn main() void {...@@ -6417,7 +6429,7 @@ pub fn main() void {
64176429
6418fn amainWrap() void {6430fn amainWrap() void {
6419 amain() catch |e| {6431 amain() catch |e| {
6420 std.debug.warn("{}\n", e);6432 std.debug.warn("{}\n", .{e});
6421 if (@errorReturnTrace()) |trace| {6433 if (@errorReturnTrace()) |trace| {
6422 std.debug.dumpStackTrace(trace.*);6434 std.debug.dumpStackTrace(trace.*);
6423 }6435 }
...@@ -6447,8 +6459,8 @@ fn amain() !void {...@@ -6447,8 +6459,8 @@ fn amain() !void {
6447 const download_text = try await download_frame;6459 const download_text = try await download_frame;
6448 defer allocator.free(download_text);6460 defer allocator.free(download_text);
64496461
6450 std.debug.warn("download_text: {}\n", download_text);6462 std.debug.warn("download_text: {}\n", .{download_text});
6451 std.debug.warn("file_text: {}\n", file_text);6463 std.debug.warn("file_text: {}\n", .{file_text});
6452}6464}
64536465
6454var global_download_frame: anyframe = undefined;6466var global_download_frame: anyframe = undefined;
...@@ -6458,7 +6470,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {...@@ -6458,7 +6470,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {
6458 suspend {6470 suspend {
6459 global_download_frame = @frame();6471 global_download_frame = @frame();
6460 }6472 }
6461 std.debug.warn("fetchUrl returning\n");6473 std.debug.warn("fetchUrl returning\n", .{});
6462 return result;6474 return result;
6463}6475}
64646476
...@@ -6469,7 +6481,7 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {...@@ -6469,7 +6481,7 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {
6469 suspend {6481 suspend {
6470 global_file_frame = @frame();6482 global_file_frame = @frame();
6471 }6483 }
6472 std.debug.warn("readFile returning\n");6484 std.debug.warn("readFile returning\n", .{});
6473 return result;6485 return result;
6474}6486}
6475 {#code_end#}6487 {#code_end#}
...@@ -6487,7 +6499,7 @@ pub fn main() void {...@@ -6487,7 +6499,7 @@ pub fn main() void {
64876499
6488fn amainWrap() void {6500fn amainWrap() void {
6489 amain() catch |e| {6501 amain() catch |e| {
6490 std.debug.warn("{}\n", e);6502 std.debug.warn("{}\n", .{e});
6491 if (@errorReturnTrace()) |trace| {6503 if (@errorReturnTrace()) |trace| {
6492 std.debug.dumpStackTrace(trace.*);6504 std.debug.dumpStackTrace(trace.*);
6493 }6505 }
...@@ -6517,21 +6529,21 @@ fn amain() !void {...@@ -6517,21 +6529,21 @@ fn amain() !void {
6517 const download_text = try await download_frame;6529 const download_text = try await download_frame;
6518 defer allocator.free(download_text);6530 defer allocator.free(download_text);
65196531
6520 std.debug.warn("download_text: {}\n", download_text);6532 std.debug.warn("download_text: {}\n", .{download_text});
6521 std.debug.warn("file_text: {}\n", file_text);6533 std.debug.warn("file_text: {}\n", .{file_text});
6522}6534}
65236535
6524fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {6536fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {
6525 const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents");6537 const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents");
6526 errdefer allocator.free(result);6538 errdefer allocator.free(result);
6527 std.debug.warn("fetchUrl returning\n");6539 std.debug.warn("fetchUrl returning\n", .{});
6528 return result;6540 return result;
6529}6541}
65306542
6531fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {6543fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {
6532 const result = try std.mem.dupe(allocator, u8, "this is the file contents");6544 const result = try std.mem.dupe(allocator, u8, "this is the file contents");
6533 errdefer allocator.free(result);6545 errdefer allocator.free(result);
6534 std.debug.warn("readFile returning\n");6546 std.debug.warn("readFile returning\n", .{});
6535 return result;6547 return result;
6536}6548}
6537 {#code_end#}6549 {#code_end#}
...@@ -7103,7 +7115,7 @@ const num1 = blk: {...@@ -7103,7 +7115,7 @@ const num1 = blk: {
7103test "main" {7115test "main" {
7104 @compileLog("comptime in main");7116 @compileLog("comptime in main");
71057117
7106 warn("Runtime in main, num1 = {}.\n", num1);7118 warn("Runtime in main, num1 = {}.\n", .{num1});
7107}7119}
7108 {#code_end#}7120 {#code_end#}
7109 <p>7121 <p>
...@@ -7124,7 +7136,7 @@ const num1 = blk: {...@@ -7124,7 +7136,7 @@ const num1 = blk: {
7124};7136};
71257137
7126test "main" {7138test "main" {
7127 warn("Runtime in main, num1 = {}.\n", num1);7139 warn("Runtime in main, num1 = {}.\n", .{num1});
7128}7140}
7129 {#code_end#}7141 {#code_end#}
7130 {#header_close#}7142 {#header_close#}
...@@ -8706,7 +8718,7 @@ const std = @import("std");...@@ -8706,7 +8718,7 @@ const std = @import("std");
8706pub fn main() void {8718pub fn main() void {
8707 var value: i32 = -1;8719 var value: i32 = -1;
8708 var unsigned = @intCast(u32, value);8720 var unsigned = @intCast(u32, value);
8709 std.debug.warn("value: {}\n", unsigned);8721 std.debug.warn("value: {}\n", .{unsigned});
8710}8722}
8711 {#code_end#}8723 {#code_end#}
8712 <p>8724 <p>
...@@ -8728,7 +8740,7 @@ const std = @import("std");...@@ -8728,7 +8740,7 @@ const std = @import("std");
8728pub fn main() void {8740pub fn main() void {
8729 var spartan_count: u16 = 300;8741 var spartan_count: u16 = 300;
8730 const byte = @intCast(u8, spartan_count);8742 const byte = @intCast(u8, spartan_count);
8731 std.debug.warn("value: {}\n", byte);8743 std.debug.warn("value: {}\n", .{byte});
8732}8744}
8733 {#code_end#}8745 {#code_end#}
8734 <p>8746 <p>
...@@ -8762,7 +8774,7 @@ const std = @import("std");...@@ -8762,7 +8774,7 @@ const std = @import("std");
8762pub fn main() void {8774pub fn main() void {
8763 var byte: u8 = 255;8775 var byte: u8 = 255;
8764 byte += 1;8776 byte += 1;
8765 std.debug.warn("value: {}\n", byte);8777 std.debug.warn("value: {}\n", .{byte});
8766}8778}
8767 {#code_end#}8779 {#code_end#}
8768 {#header_close#}8780 {#header_close#}
...@@ -8785,11 +8797,11 @@ pub fn main() !void {...@@ -8785,11 +8797,11 @@ pub fn main() !void {
8785 var byte: u8 = 255;8797 var byte: u8 = 255;
87868798
8787 byte = if (math.add(u8, byte, 1)) |result| result else |err| {8799 byte = if (math.add(u8, byte, 1)) |result| result else |err| {
8788 warn("unable to add one: {}\n", @errorName(err));8800 warn("unable to add one: {}\n", .{@errorName(err)});
8789 return err;8801 return err;
8790 };8802 };
87918803
8792 warn("result: {}\n", byte);8804 warn("result: {}\n", .{byte});
8793}8805}
8794 {#code_end#}8806 {#code_end#}
8795 {#header_close#}8807 {#header_close#}
...@@ -8814,9 +8826,9 @@ pub fn main() void {...@@ -8814,9 +8826,9 @@ pub fn main() void {
88148826
8815 var result: u8 = undefined;8827 var result: u8 = undefined;
8816 if (@addWithOverflow(u8, byte, 10, &result)) {8828 if (@addWithOverflow(u8, byte, 10, &result)) {
8817 warn("overflowed result: {}\n", result);8829 warn("overflowed result: {}\n", .{result});
8818 } else {8830 } else {
8819 warn("result: {}\n", result);8831 warn("result: {}\n", .{result});
8820 }8832 }
8821}8833}
8822 {#code_end#}8834 {#code_end#}
...@@ -8861,7 +8873,7 @@ const std = @import("std");...@@ -8861,7 +8873,7 @@ const std = @import("std");
8861pub fn main() void {8873pub fn main() void {
8862 var x: u8 = 0b01010101;8874 var x: u8 = 0b01010101;
8863 var y = @shlExact(x, 2);8875 var y = @shlExact(x, 2);
8864 std.debug.warn("value: {}\n", y);8876 std.debug.warn("value: {}\n", .{y});
8865}8877}
8866 {#code_end#}8878 {#code_end#}
8867 {#header_close#}8879 {#header_close#}
...@@ -8879,7 +8891,7 @@ const std = @import("std");...@@ -8879,7 +8891,7 @@ const std = @import("std");
8879pub fn main() void {8891pub fn main() void {
8880 var x: u8 = 0b10101010;8892 var x: u8 = 0b10101010;
8881 var y = @shrExact(x, 2);8893 var y = @shrExact(x, 2);
8882 std.debug.warn("value: {}\n", y);8894 std.debug.warn("value: {}\n", .{y});
8883}8895}
8884 {#code_end#}8896 {#code_end#}
8885 {#header_close#}8897 {#header_close#}
...@@ -8900,7 +8912,7 @@ pub fn main() void {...@@ -8900,7 +8912,7 @@ pub fn main() void {
8900 var a: u32 = 1;8912 var a: u32 = 1;
8901 var b: u32 = 0;8913 var b: u32 = 0;
8902 var c = a / b;8914 var c = a / b;
8903 std.debug.warn("value: {}\n", c);8915 std.debug.warn("value: {}\n", .{c});
8904}8916}
8905 {#code_end#}8917 {#code_end#}
8906 {#header_close#}8918 {#header_close#}
...@@ -8921,7 +8933,7 @@ pub fn main() void {...@@ -8921,7 +8933,7 @@ pub fn main() void {
8921 var a: u32 = 10;8933 var a: u32 = 10;
8922 var b: u32 = 0;8934 var b: u32 = 0;
8923 var c = a % b;8935 var c = a % b;
8924 std.debug.warn("value: {}\n", c);8936 std.debug.warn("value: {}\n", .{c});
8925}8937}
8926 {#code_end#}8938 {#code_end#}
8927 {#header_close#}8939 {#header_close#}
...@@ -8942,7 +8954,7 @@ pub fn main() void {...@@ -8942,7 +8954,7 @@ pub fn main() void {
8942 var a: u32 = 10;8954 var a: u32 = 10;
8943 var b: u32 = 3;8955 var b: u32 = 3;
8944 var c = @divExact(a, b);8956 var c = @divExact(a, b);
8945 std.debug.warn("value: {}\n", c);8957 std.debug.warn("value: {}\n", .{c});
8946}8958}
8947 {#code_end#}8959 {#code_end#}
8948 {#header_close#}8960 {#header_close#}
...@@ -8961,7 +8973,7 @@ const std = @import("std");...@@ -8961,7 +8973,7 @@ const std = @import("std");
8961pub fn main() void {8973pub fn main() void {
8962 var bytes = [5]u8{ 1, 2, 3, 4, 5 };8974 var bytes = [5]u8{ 1, 2, 3, 4, 5 };
8963 var slice = @bytesToSlice(u32, bytes[0..]);8975 var slice = @bytesToSlice(u32, bytes[0..]);
8964 std.debug.warn("value: {}\n", slice[0]);8976 std.debug.warn("value: {}\n", .{slice[0]});
8965}8977}
8966 {#code_end#}8978 {#code_end#}
8967 {#header_close#}8979 {#header_close#}
...@@ -8980,7 +8992,7 @@ const std = @import("std");...@@ -8980,7 +8992,7 @@ const std = @import("std");
8980pub fn main() void {8992pub fn main() void {
8981 var optional_number: ?i32 = null;8993 var optional_number: ?i32 = null;
8982 var number = optional_number.?;8994 var number = optional_number.?;
8983 std.debug.warn("value: {}\n", number);8995 std.debug.warn("value: {}\n", .{number});
8984}8996}
8985 {#code_end#}8997 {#code_end#}
8986 <p>One way to avoid this crash is to test for null instead of assuming non-null, with8998 <p>One way to avoid this crash is to test for null instead of assuming non-null, with
...@@ -8991,9 +9003,9 @@ pub fn main() void {...@@ -8991,9 +9003,9 @@ pub fn main() void {
8991 const optional_number: ?i32 = null;9003 const optional_number: ?i32 = null;
89929004
8993 if (optional_number) |number| {9005 if (optional_number) |number| {
8994 warn("got number: {}\n", number);9006 warn("got number: {}\n", .{number});
8995 } else {9007 } else {
8996 warn("it's null\n");9008 warn("it's null\n", .{});
8997 }9009 }
8998}9010}
8999 {#code_end#}9011 {#code_end#}
...@@ -9016,7 +9028,7 @@ const std = @import("std");...@@ -9016,7 +9028,7 @@ const std = @import("std");
90169028
9017pub fn main() void {9029pub fn main() void {
9018 const number = getNumberOrFail() catch unreachable;9030 const number = getNumberOrFail() catch unreachable;
9019 std.debug.warn("value: {}\n", number);9031 std.debug.warn("value: {}\n", .{number});
9020}9032}
90219033
9022fn getNumberOrFail() !i32 {9034fn getNumberOrFail() !i32 {
...@@ -9032,9 +9044,9 @@ pub fn main() void {...@@ -9032,9 +9044,9 @@ pub fn main() void {
9032 const result = getNumberOrFail();9044 const result = getNumberOrFail();
90339045
9034 if (result) |number| {9046 if (result) |number| {
9035 warn("got number: {}\n", number);9047 warn("got number: {}\n", .{number});
9036 } else |err| {9048 } else |err| {
9037 warn("got error: {}\n", @errorName(err));9049 warn("got error: {}\n", .{@errorName(err)});
9038 }9050 }
9039}9051}
90409052
...@@ -9061,7 +9073,7 @@ pub fn main() void {...@@ -9061,7 +9073,7 @@ pub fn main() void {
9061 var err = error.AnError;9073 var err = error.AnError;
9062 var number = @errorToInt(err) + 500;9074 var number = @errorToInt(err) + 500;
9063 var invalid_err = @intToError(number);9075 var invalid_err = @intToError(number);
9064 std.debug.warn("value: {}\n", number);9076 std.debug.warn("value: {}\n", .{number});
9065}9077}
9066 {#code_end#}9078 {#code_end#}
9067 {#header_close#}9079 {#header_close#}
...@@ -9091,7 +9103,7 @@ const Foo = enum {...@@ -9091,7 +9103,7 @@ const Foo = enum {
9091pub fn main() void {9103pub fn main() void {
9092 var a: u2 = 3;9104 var a: u2 = 3;
9093 var b = @intToEnum(Foo, a);9105 var b = @intToEnum(Foo, a);
9094 std.debug.warn("value: {}\n", @tagName(b));9106 std.debug.warn("value: {}\n", .{@tagName(b)});
9095}9107}
9096 {#code_end#}9108 {#code_end#}
9097 {#header_close#}9109 {#header_close#}
...@@ -9128,7 +9140,7 @@ pub fn main() void {...@@ -9128,7 +9140,7 @@ pub fn main() void {
9128}9140}
9129fn foo(set1: Set1) void {9141fn foo(set1: Set1) void {
9130 const x = @errSetCast(Set2, set1);9142 const x = @errSetCast(Set2, set1);
9131 std.debug.warn("value: {}\n", x);9143 std.debug.warn("value: {}\n", .{x});
9132}9144}
9133 {#code_end#}9145 {#code_end#}
9134 {#header_close#}9146 {#header_close#}
...@@ -9184,7 +9196,7 @@ pub fn main() void {...@@ -9184,7 +9196,7 @@ pub fn main() void {
91849196
9185fn bar(f: *Foo) void {9197fn bar(f: *Foo) void {
9186 f.float = 12.34;9198 f.float = 12.34;
9187 std.debug.warn("value: {}\n", f.float);9199 std.debug.warn("value: {}\n", .{f.float});
9188}9200}
9189 {#code_end#}9201 {#code_end#}
9190 <p>9202 <p>
...@@ -9208,7 +9220,7 @@ pub fn main() void {...@@ -9208,7 +9220,7 @@ pub fn main() void {
92089220
9209fn bar(f: *Foo) void {9221fn bar(f: *Foo) void {
9210 f.* = Foo{ .float = 12.34 };9222 f.* = Foo{ .float = 12.34 };
9211 std.debug.warn("value: {}\n", f.float);9223 std.debug.warn("value: {}\n", .{f.float});
9212}9224}
9213 {#code_end#}9225 {#code_end#}
9214 <p>9226 <p>
...@@ -9227,7 +9239,7 @@ pub fn main() void {...@@ -9227,7 +9239,7 @@ pub fn main() void {
9227 var f = Foo{ .int = 42 };9239 var f = Foo{ .int = 42 };
9228 f = Foo{ .float = undefined };9240 f = Foo{ .float = undefined };
9229 bar(&f);9241 bar(&f);
9230 std.debug.warn("value: {}\n", f.float);9242 std.debug.warn("value: {}\n", .{f.float});
9231}9243}
92329244
9233fn bar(f: *Foo) void {9245fn bar(f: *Foo) void {
...@@ -9348,7 +9360,7 @@ pub fn main() !void {...@@ -9348,7 +9360,7 @@ pub fn main() !void {
9348 const allocator = &arena.allocator;9360 const allocator = &arena.allocator;
93499361
9350 const ptr = try allocator.create(i32);9362 const ptr = try allocator.create(i32);
9351 std.debug.warn("ptr={*}\n", ptr);9363 std.debug.warn("ptr={*}\n", .{ptr});
9352}9364}
9353 {#code_end#}9365 {#code_end#}
9354 When using this kind of allocator, there is no need to free anything manually. Everything9366 When using this kind of allocator, there is no need to free anything manually. Everything
...@@ -9881,7 +9893,7 @@ pub fn main() !void {...@@ -9881,7 +9893,7 @@ pub fn main() !void {
9881 defer std.process.argsFree(std.heap.page_allocator, args);9893 defer std.process.argsFree(std.heap.page_allocator, args);
98829894
9883 for (args) |arg, i| {9895 for (args) |arg, i| {
9884 std.debug.warn("{}: {}\n", i, arg);9896 std.debug.warn("{}: {}\n", .{i, arg});
9885 }9897 }
9886}9898}
9887 {#code_end#}9899 {#code_end#}
lib/std/atomic/queue.zig+9-10
...@@ -116,19 +116,19 @@ pub fn Queue(comptime T: type) type {...@@ -116,19 +116,19 @@ pub fn Queue(comptime T: type) type {
116 fn dumpRecursive(s: *std.io.OutStream(Error), optional_node: ?*Node, indent: usize) Error!void {116 fn dumpRecursive(s: *std.io.OutStream(Error), optional_node: ?*Node, indent: usize) Error!void {
117 try s.writeByteNTimes(' ', indent);117 try s.writeByteNTimes(' ', indent);
118 if (optional_node) |node| {118 if (optional_node) |node| {
119 try s.print("0x{x}={}\n", @ptrToInt(node), node.data);119 try s.print("0x{x}={}\n", .{ @ptrToInt(node), node.data });
120 try dumpRecursive(s, node.next, indent + 1);120 try dumpRecursive(s, node.next, indent + 1);
121 } else {121 } else {
122 try s.print("(null)\n");122 try s.print("(null)\n", .{});
123 }123 }
124 }124 }
125 };125 };
126 const held = self.mutex.acquire();126 const held = self.mutex.acquire();
127 defer held.release();127 defer held.release();
128128
129 try stream.print("head: ");129 try stream.print("head: ", .{});
130 try S.dumpRecursive(stream, self.head, 0);130 try S.dumpRecursive(stream, self.head, 0);
131 try stream.print("tail: ");131 try stream.print("tail: ", .{});
132 try S.dumpRecursive(stream, self.tail, 0);132 try S.dumpRecursive(stream, self.tail, 0);
133 }133 }
134 };134 };
...@@ -207,16 +207,15 @@ test "std.atomic.Queue" {...@@ -207,16 +207,15 @@ test "std.atomic.Queue" {
207 }207 }
208208
209 if (context.put_sum != context.get_sum) {209 if (context.put_sum != context.get_sum) {
210 std.debug.panic("failure\nput_sum:{} != get_sum:{}", context.put_sum, context.get_sum);210 std.debug.panic("failure\nput_sum:{} != get_sum:{}", .{ context.put_sum, context.get_sum });
211 }211 }
212212
213 if (context.get_count != puts_per_thread * put_thread_count) {213 if (context.get_count != puts_per_thread * put_thread_count) {
214 std.debug.panic(214 std.debug.panic("failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", .{
215 "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
216 context.get_count,215 context.get_count,
217 @as(u32, puts_per_thread),216 @as(u32, puts_per_thread),
218 @as(u32, put_thread_count),217 @as(u32, put_thread_count),
219 );218 });
220 }219 }
221}220}
222221
...@@ -351,7 +350,7 @@ test "std.atomic.Queue dump" {...@@ -351,7 +350,7 @@ test "std.atomic.Queue dump" {
351 \\tail: 0x{x}=1350 \\tail: 0x{x}=1
352 \\ (null)351 \\ (null)
353 \\352 \\
354 , @ptrToInt(queue.head), @ptrToInt(queue.tail));353 , .{ @ptrToInt(queue.head), @ptrToInt(queue.tail) });
355 expect(mem.eql(u8, buffer[0..sos.pos], expected));354 expect(mem.eql(u8, buffer[0..sos.pos], expected));
356355
357 // Test a stream with two elements356 // Test a stream with two elements
...@@ -372,6 +371,6 @@ test "std.atomic.Queue dump" {...@@ -372,6 +371,6 @@ test "std.atomic.Queue dump" {
372 \\tail: 0x{x}=2371 \\tail: 0x{x}=2
373 \\ (null)372 \\ (null)
374 \\373 \\
375 , @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail));374 , .{ @ptrToInt(queue.head), @ptrToInt(queue.head.?.next), @ptrToInt(queue.tail) });
376 expect(mem.eql(u8, buffer[0..sos.pos], expected));375 expect(mem.eql(u8, buffer[0..sos.pos], expected));
377}376}
lib/std/atomic/stack.zig+3-4
...@@ -134,16 +134,15 @@ test "std.atomic.stack" {...@@ -134,16 +134,15 @@ test "std.atomic.stack" {
134 }134 }
135135
136 if (context.put_sum != context.get_sum) {136 if (context.put_sum != context.get_sum) {
137 std.debug.panic("failure\nput_sum:{} != get_sum:{}", context.put_sum, context.get_sum);137 std.debug.panic("failure\nput_sum:{} != get_sum:{}", .{ context.put_sum, context.get_sum });
138 }138 }
139139
140 if (context.get_count != puts_per_thread * put_thread_count) {140 if (context.get_count != puts_per_thread * put_thread_count) {
141 std.debug.panic(141 std.debug.panic("failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}", .{
142 "failure\nget_count:{} != puts_per_thread:{} * put_thread_count:{}",
143 context.get_count,142 context.get_count,
144 @as(u32, puts_per_thread),143 @as(u32, puts_per_thread),
145 @as(u32, put_thread_count),144 @as(u32, put_thread_count),
146 );145 });
147 }146 }
148}147}
149148
lib/std/buffer.zig+4-4
...@@ -16,7 +16,7 @@ pub const Buffer = struct {...@@ -16,7 +16,7 @@ pub const Buffer = struct {
16 mem.copy(u8, self.list.items, m);16 mem.copy(u8, self.list.items, m);
17 return self;17 return self;
18 }18 }
19 19
20 /// Initialize memory to size bytes of undefined values.20 /// Initialize memory to size bytes of undefined values.
21 /// Must deinitialize with deinit.21 /// Must deinitialize with deinit.
22 pub fn initSize(allocator: *Allocator, size: usize) !Buffer {22 pub fn initSize(allocator: *Allocator, size: usize) !Buffer {
...@@ -24,7 +24,7 @@ pub const Buffer = struct {...@@ -24,7 +24,7 @@ pub const Buffer = struct {
24 try self.resize(size);24 try self.resize(size);
25 return self;25 return self;
26 }26 }
27 27
28 /// Initialize with capacity to hold at least num bytes.28 /// Initialize with capacity to hold at least num bytes.
29 /// Must deinitialize with deinit.29 /// Must deinitialize with deinit.
30 pub fn initCapacity(allocator: *Allocator, num: usize) !Buffer {30 pub fn initCapacity(allocator: *Allocator, num: usize) !Buffer {
...@@ -64,7 +64,7 @@ pub const Buffer = struct {...@@ -64,7 +64,7 @@ pub const Buffer = struct {
64 return result;64 return result;
65 }65 }
6666
67 pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: ...) !Buffer {67 pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: var) !Buffer {
68 const countSize = struct {68 const countSize = struct {
69 fn countSize(size: *usize, bytes: []const u8) (error{}!void) {69 fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
70 size.* += bytes.len;70 size.* += bytes.len;
...@@ -107,7 +107,7 @@ pub const Buffer = struct {...@@ -107,7 +107,7 @@ pub const Buffer = struct {
107 pub fn len(self: Buffer) usize {107 pub fn len(self: Buffer) usize {
108 return self.list.len - 1;108 return self.list.len - 1;
109 }109 }
110 110
111 pub fn capacity(self: Buffer) usize {111 pub fn capacity(self: Buffer) usize {
112 return if (self.list.items.len > 0)112 return if (self.list.items.len > 0)
113 self.list.items.len - 1113 self.list.items.len - 1
lib/std/build.zig+104-82
...@@ -232,7 +232,7 @@ pub const Builder = struct {...@@ -232,7 +232,7 @@ pub const Builder = struct {
232 /// To run an executable built with zig build, see `LibExeObjStep.run`.232 /// To run an executable built with zig build, see `LibExeObjStep.run`.
233 pub fn addSystemCommand(self: *Builder, argv: []const []const u8) *RunStep {233 pub fn addSystemCommand(self: *Builder, argv: []const []const u8) *RunStep {
234 assert(argv.len >= 1);234 assert(argv.len >= 1);
235 const run_step = RunStep.create(self, self.fmt("run {}", argv[0]));235 const run_step = RunStep.create(self, self.fmt("run {}", .{argv[0]}));
236 run_step.addArgs(argv);236 run_step.addArgs(argv);
237 return run_step;237 return run_step;
238 }238 }
...@@ -258,7 +258,7 @@ pub const Builder = struct {...@@ -258,7 +258,7 @@ pub const Builder = struct {
258 return write_file_step;258 return write_file_step;
259 }259 }
260260
261 pub fn addLog(self: *Builder, comptime format: []const u8, args: ...) *LogStep {261 pub fn addLog(self: *Builder, comptime format: []const u8, args: var) *LogStep {
262 const data = self.fmt(format, args);262 const data = self.fmt(format, args);
263 const log_step = self.allocator.create(LogStep) catch unreachable;263 const log_step = self.allocator.create(LogStep) catch unreachable;
264 log_step.* = LogStep.init(self, data);264 log_step.* = LogStep.init(self, data);
...@@ -330,7 +330,7 @@ pub const Builder = struct {...@@ -330,7 +330,7 @@ pub const Builder = struct {
330 for (self.installed_files.toSliceConst()) |installed_file| {330 for (self.installed_files.toSliceConst()) |installed_file| {
331 const full_path = self.getInstallPath(installed_file.dir, installed_file.path);331 const full_path = self.getInstallPath(installed_file.dir, installed_file.path);
332 if (self.verbose) {332 if (self.verbose) {
333 warn("rm {}\n", full_path);333 warn("rm {}\n", .{full_path});
334 }334 }
335 fs.deleteTree(full_path) catch {};335 fs.deleteTree(full_path) catch {};
336 }336 }
...@@ -340,7 +340,7 @@ pub const Builder = struct {...@@ -340,7 +340,7 @@ pub const Builder = struct {
340340
341 fn makeOneStep(self: *Builder, s: *Step) anyerror!void {341 fn makeOneStep(self: *Builder, s: *Step) anyerror!void {
342 if (s.loop_flag) {342 if (s.loop_flag) {
343 warn("Dependency loop detected:\n {}\n", s.name);343 warn("Dependency loop detected:\n {}\n", .{s.name});
344 return error.DependencyLoopDetected;344 return error.DependencyLoopDetected;
345 }345 }
346 s.loop_flag = true;346 s.loop_flag = true;
...@@ -348,7 +348,7 @@ pub const Builder = struct {...@@ -348,7 +348,7 @@ pub const Builder = struct {
348 for (s.dependencies.toSlice()) |dep| {348 for (s.dependencies.toSlice()) |dep| {
349 self.makeOneStep(dep) catch |err| {349 self.makeOneStep(dep) catch |err| {
350 if (err == error.DependencyLoopDetected) {350 if (err == error.DependencyLoopDetected) {
351 warn(" {}\n", s.name);351 warn(" {}\n", .{s.name});
352 }352 }
353 return err;353 return err;
354 };354 };
...@@ -365,7 +365,7 @@ pub const Builder = struct {...@@ -365,7 +365,7 @@ pub const Builder = struct {
365 return &top_level_step.step;365 return &top_level_step.step;
366 }366 }
367 }367 }
368 warn("Cannot run step '{}' because it does not exist\n", name);368 warn("Cannot run step '{}' because it does not exist\n", .{name});
369 return error.InvalidStepName;369 return error.InvalidStepName;
370 }370 }
371371
...@@ -378,12 +378,12 @@ pub const Builder = struct {...@@ -378,12 +378,12 @@ pub const Builder = struct {
378 const word = it.next() orelse break;378 const word = it.next() orelse break;
379 if (mem.eql(u8, word, "-isystem")) {379 if (mem.eql(u8, word, "-isystem")) {
380 const include_path = it.next() orelse {380 const include_path = it.next() orelse {
381 warn("Expected argument after -isystem in NIX_CFLAGS_COMPILE\n");381 warn("Expected argument after -isystem in NIX_CFLAGS_COMPILE\n", .{});
382 break;382 break;
383 };383 };
384 self.addNativeSystemIncludeDir(include_path);384 self.addNativeSystemIncludeDir(include_path);
385 } else {385 } else {
386 warn("Unrecognized C flag from NIX_CFLAGS_COMPILE: {}\n", word);386 warn("Unrecognized C flag from NIX_CFLAGS_COMPILE: {}\n", .{word});
387 break;387 break;
388 }388 }
389 }389 }
...@@ -397,7 +397,7 @@ pub const Builder = struct {...@@ -397,7 +397,7 @@ pub const Builder = struct {
397 const word = it.next() orelse break;397 const word = it.next() orelse break;
398 if (mem.eql(u8, word, "-rpath")) {398 if (mem.eql(u8, word, "-rpath")) {
399 const rpath = it.next() orelse {399 const rpath = it.next() orelse {
400 warn("Expected argument after -rpath in NIX_LDFLAGS\n");400 warn("Expected argument after -rpath in NIX_LDFLAGS\n", .{});
401 break;401 break;
402 };402 };
403 self.addNativeSystemRPath(rpath);403 self.addNativeSystemRPath(rpath);
...@@ -405,7 +405,7 @@ pub const Builder = struct {...@@ -405,7 +405,7 @@ pub const Builder = struct {
405 const lib_path = word[2..];405 const lib_path = word[2..];
406 self.addNativeSystemLibPath(lib_path);406 self.addNativeSystemLibPath(lib_path);
407 } else {407 } else {
408 warn("Unrecognized C flag from NIX_LDFLAGS: {}\n", word);408 warn("Unrecognized C flag from NIX_LDFLAGS: {}\n", .{word});
409 break;409 break;
410 }410 }
411 }411 }
...@@ -431,8 +431,8 @@ pub const Builder = struct {...@@ -431,8 +431,8 @@ pub const Builder = struct {
431 self.addNativeSystemIncludeDir("/usr/local/include");431 self.addNativeSystemIncludeDir("/usr/local/include");
432 self.addNativeSystemLibPath("/usr/local/lib");432 self.addNativeSystemLibPath("/usr/local/lib");
433433
434 self.addNativeSystemIncludeDir(self.fmt("/usr/include/{}", triple));434 self.addNativeSystemIncludeDir(self.fmt("/usr/include/{}", .{triple}));
435 self.addNativeSystemLibPath(self.fmt("/usr/lib/{}", triple));435 self.addNativeSystemLibPath(self.fmt("/usr/lib/{}", .{triple}));
436436
437 self.addNativeSystemIncludeDir("/usr/include");437 self.addNativeSystemIncludeDir("/usr/include");
438 self.addNativeSystemLibPath("/usr/lib");438 self.addNativeSystemLibPath("/usr/lib");
...@@ -440,7 +440,7 @@ pub const Builder = struct {...@@ -440,7 +440,7 @@ pub const Builder = struct {
440 // example: on a 64-bit debian-based linux distro, with zlib installed from apt:440 // example: on a 64-bit debian-based linux distro, with zlib installed from apt:
441 // zlib.h is in /usr/include (added above)441 // zlib.h is in /usr/include (added above)
442 // libz.so.1 is in /lib/x86_64-linux-gnu (added here)442 // libz.so.1 is in /lib/x86_64-linux-gnu (added here)
443 self.addNativeSystemLibPath(self.fmt("/lib/{}", triple));443 self.addNativeSystemLibPath(self.fmt("/lib/{}", .{triple}));
444 },444 },
445 }445 }
446 }446 }
...@@ -453,7 +453,7 @@ pub const Builder = struct {...@@ -453,7 +453,7 @@ pub const Builder = struct {
453 .description = description,453 .description = description,
454 };454 };
455 if ((self.available_options_map.put(name, available_option) catch unreachable) != null) {455 if ((self.available_options_map.put(name, available_option) catch unreachable) != null) {
456 panic("Option '{}' declared twice", name);456 panic("Option '{}' declared twice", .{name});
457 }457 }
458 self.available_options_list.append(available_option) catch unreachable;458 self.available_options_list.append(available_option) catch unreachable;
459459
...@@ -468,33 +468,33 @@ pub const Builder = struct {...@@ -468,33 +468,33 @@ pub const Builder = struct {
468 } else if (mem.eql(u8, s, "false")) {468 } else if (mem.eql(u8, s, "false")) {
469 return false;469 return false;
470 } else {470 } else {
471 warn("Expected -D{} to be a boolean, but received '{}'\n", name, s);471 warn("Expected -D{} to be a boolean, but received '{}'\n", .{ name, s });
472 self.markInvalidUserInput();472 self.markInvalidUserInput();
473 return null;473 return null;
474 }474 }
475 },475 },
476 UserValue.List => {476 UserValue.List => {
477 warn("Expected -D{} to be a boolean, but received a list.\n", name);477 warn("Expected -D{} to be a boolean, but received a list.\n", .{name});
478 self.markInvalidUserInput();478 self.markInvalidUserInput();
479 return null;479 return null;
480 },480 },
481 },481 },
482 TypeId.Int => panic("TODO integer options to build script"),482 TypeId.Int => panic("TODO integer options to build script", .{}),
483 TypeId.Float => panic("TODO float options to build script"),483 TypeId.Float => panic("TODO float options to build script", .{}),
484 TypeId.String => switch (entry.value.value) {484 TypeId.String => switch (entry.value.value) {
485 UserValue.Flag => {485 UserValue.Flag => {
486 warn("Expected -D{} to be a string, but received a boolean.\n", name);486 warn("Expected -D{} to be a string, but received a boolean.\n", .{name});
487 self.markInvalidUserInput();487 self.markInvalidUserInput();
488 return null;488 return null;
489 },489 },
490 UserValue.List => {490 UserValue.List => {
491 warn("Expected -D{} to be a string, but received a list.\n", name);491 warn("Expected -D{} to be a string, but received a list.\n", .{name});
492 self.markInvalidUserInput();492 self.markInvalidUserInput();
493 return null;493 return null;
494 },494 },
495 UserValue.Scalar => |s| return s,495 UserValue.Scalar => |s| return s,
496 },496 },
497 TypeId.List => panic("TODO list options to build script"),497 TypeId.List => panic("TODO list options to build script", .{}),
498 }498 }
499 }499 }
500500
...@@ -513,7 +513,7 @@ pub const Builder = struct {...@@ -513,7 +513,7 @@ pub const Builder = struct {
513 if (self.release_mode != null) {513 if (self.release_mode != null) {
514 @panic("setPreferredReleaseMode must be called before standardReleaseOptions and may not be called twice");514 @panic("setPreferredReleaseMode must be called before standardReleaseOptions and may not be called twice");
515 }515 }
516 const description = self.fmt("create a release build ({})", @tagName(mode));516 const description = self.fmt("create a release build ({})", .{@tagName(mode)});
517 self.is_release = self.option(bool, "release", description) orelse false;517 self.is_release = self.option(bool, "release", description) orelse false;
518 self.release_mode = if (self.is_release) mode else builtin.Mode.Debug;518 self.release_mode = if (self.is_release) mode else builtin.Mode.Debug;
519 }519 }
...@@ -536,7 +536,7 @@ pub const Builder = struct {...@@ -536,7 +536,7 @@ pub const Builder = struct {
536 else if (!release_fast and !release_safe and !release_small)536 else if (!release_fast and !release_safe and !release_small)
537 builtin.Mode.Debug537 builtin.Mode.Debug
538 else x: {538 else x: {
539 warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)");539 warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)", .{});
540 self.markInvalidUserInput();540 self.markInvalidUserInput();
541 break :x builtin.Mode.Debug;541 break :x builtin.Mode.Debug;
542 };542 };
...@@ -599,7 +599,7 @@ pub const Builder = struct {...@@ -599,7 +599,7 @@ pub const Builder = struct {
599 }) catch unreachable;599 }) catch unreachable;
600 },600 },
601 UserValue.Flag => {601 UserValue.Flag => {
602 warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", name, value, name);602 warn("Option '-D{}={}' conflicts with flag '-D{}'.\n", .{ name, value, name });
603 return true;603 return true;
604 },604 },
605 }605 }
...@@ -620,11 +620,11 @@ pub const Builder = struct {...@@ -620,11 +620,11 @@ pub const Builder = struct {
620 // option already exists620 // option already exists
621 switch (gop.kv.value.value) {621 switch (gop.kv.value.value) {
622 UserValue.Scalar => |s| {622 UserValue.Scalar => |s| {
623 warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", name, name, s);623 warn("Flag '-D{}' conflicts with option '-D{}={}'.\n", .{ name, name, s });
624 return true;624 return true;
625 },625 },
626 UserValue.List => {626 UserValue.List => {
627 warn("Flag '-D{}' conflicts with multiple options of the same name.\n", name);627 warn("Flag '-D{}' conflicts with multiple options of the same name.\n", .{name});
628 return true;628 return true;
629 },629 },
630 UserValue.Flag => {},630 UserValue.Flag => {},
...@@ -665,7 +665,7 @@ pub const Builder = struct {...@@ -665,7 +665,7 @@ pub const Builder = struct {
665 while (true) {665 while (true) {
666 const entry = it.next() orelse break;666 const entry = it.next() orelse break;
667 if (!entry.value.used) {667 if (!entry.value.used) {
668 warn("Invalid option: -D{}\n\n", entry.key);668 warn("Invalid option: -D{}\n\n", .{entry.key});
669 self.markInvalidUserInput();669 self.markInvalidUserInput();
670 }670 }
671 }671 }
...@@ -678,11 +678,11 @@ pub const Builder = struct {...@@ -678,11 +678,11 @@ pub const Builder = struct {
678 }678 }
679679
680 fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void {680 fn printCmd(cwd: ?[]const u8, argv: []const []const u8) void {
681 if (cwd) |yes_cwd| warn("cd {} && ", yes_cwd);681 if (cwd) |yes_cwd| warn("cd {} && ", .{yes_cwd});
682 for (argv) |arg| {682 for (argv) |arg| {
683 warn("{} ", arg);683 warn("{} ", .{arg});
684 }684 }
685 warn("\n");685 warn("\n", .{});
686 }686 }
687687
688 fn spawnChildEnvMap(self: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) !void {688 fn spawnChildEnvMap(self: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) !void {
...@@ -697,20 +697,20 @@ pub const Builder = struct {...@@ -697,20 +697,20 @@ pub const Builder = struct {
697 child.env_map = env_map;697 child.env_map = env_map;
698698
699 const term = child.spawnAndWait() catch |err| {699 const term = child.spawnAndWait() catch |err| {
700 warn("Unable to spawn {}: {}\n", argv[0], @errorName(err));700 warn("Unable to spawn {}: {}\n", .{ argv[0], @errorName(err) });
701 return err;701 return err;
702 };702 };
703703
704 switch (term) {704 switch (term) {
705 .Exited => |code| {705 .Exited => |code| {
706 if (code != 0) {706 if (code != 0) {
707 warn("The following command exited with error code {}:\n", code);707 warn("The following command exited with error code {}:\n", .{code});
708 printCmd(cwd, argv);708 printCmd(cwd, argv);
709 return error.UncleanExit;709 return error.UncleanExit;
710 }710 }
711 },711 },
712 else => {712 else => {
713 warn("The following command terminated unexpectedly:\n");713 warn("The following command terminated unexpectedly:\n", .{});
714 printCmd(cwd, argv);714 printCmd(cwd, argv);
715715
716 return error.UncleanExit;716 return error.UncleanExit;
...@@ -720,7 +720,7 @@ pub const Builder = struct {...@@ -720,7 +720,7 @@ pub const Builder = struct {
720720
721 pub fn makePath(self: *Builder, path: []const u8) !void {721 pub fn makePath(self: *Builder, path: []const u8) !void {
722 fs.makePath(self.allocator, self.pathFromRoot(path)) catch |err| {722 fs.makePath(self.allocator, self.pathFromRoot(path)) catch |err| {
723 warn("Unable to create path {}: {}\n", path, @errorName(err));723 warn("Unable to create path {}: {}\n", .{ path, @errorName(err) });
724 return err;724 return err;
725 };725 };
726 }726 }
...@@ -793,12 +793,12 @@ pub const Builder = struct {...@@ -793,12 +793,12 @@ pub const Builder = struct {
793793
794 fn updateFile(self: *Builder, source_path: []const u8, dest_path: []const u8) !void {794 fn updateFile(self: *Builder, source_path: []const u8, dest_path: []const u8) !void {
795 if (self.verbose) {795 if (self.verbose) {
796 warn("cp {} {} ", source_path, dest_path);796 warn("cp {} {} ", .{ source_path, dest_path });
797 }797 }
798 const prev_status = try fs.updateFile(source_path, dest_path);798 const prev_status = try fs.updateFile(source_path, dest_path);
799 if (self.verbose) switch (prev_status) {799 if (self.verbose) switch (prev_status) {
800 .stale => warn("# installed\n"),800 .stale => warn("# installed\n", .{}),
801 .fresh => warn("# up-to-date\n"),801 .fresh => warn("# up-to-date\n", .{}),
802 };802 };
803 }803 }
804804
...@@ -806,7 +806,7 @@ pub const Builder = struct {...@@ -806,7 +806,7 @@ pub const Builder = struct {
806 return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable;806 return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable;
807 }807 }
808808
809 pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {809 pub fn fmt(self: *Builder, comptime format: []const u8, args: var) []u8 {
810 return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;810 return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;
811 }811 }
812812
...@@ -818,7 +818,11 @@ pub const Builder = struct {...@@ -818,7 +818,11 @@ pub const Builder = struct {
818 if (fs.path.isAbsolute(name)) {818 if (fs.path.isAbsolute(name)) {
819 return name;819 return name;
820 }820 }
821 const full_path = try fs.path.join(self.allocator, &[_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });821 const full_path = try fs.path.join(self.allocator, &[_][]const u8{
822 search_prefix,
823 "bin",
824 self.fmt("{}{}", .{ name, exe_extension }),
825 });
822 return fs.realpathAlloc(self.allocator, full_path) catch continue;826 return fs.realpathAlloc(self.allocator, full_path) catch continue;
823 }827 }
824 }828 }
...@@ -829,7 +833,10 @@ pub const Builder = struct {...@@ -829,7 +833,10 @@ pub const Builder = struct {
829 }833 }
830 var it = mem.tokenize(PATH, &[_]u8{fs.path.delimiter});834 var it = mem.tokenize(PATH, &[_]u8{fs.path.delimiter});
831 while (it.next()) |path| {835 while (it.next()) |path| {
832 const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });836 const full_path = try fs.path.join(self.allocator, &[_][]const u8{
837 path,
838 self.fmt("{}{}", .{ name, exe_extension }),
839 });
833 return fs.realpathAlloc(self.allocator, full_path) catch continue;840 return fs.realpathAlloc(self.allocator, full_path) catch continue;
834 }841 }
835 }842 }
...@@ -839,7 +846,10 @@ pub const Builder = struct {...@@ -839,7 +846,10 @@ pub const Builder = struct {
839 return name;846 return name;
840 }847 }
841 for (paths) |path| {848 for (paths) |path| {
842 const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });849 const full_path = try fs.path.join(self.allocator, &[_][]const u8{
850 path,
851 self.fmt("{}{}", .{ name, exe_extension }),
852 });
843 return fs.realpathAlloc(self.allocator, full_path) catch continue;853 return fs.realpathAlloc(self.allocator, full_path) catch continue;
844 }854 }
845 }855 }
...@@ -896,17 +906,17 @@ pub const Builder = struct {...@@ -896,17 +906,17 @@ pub const Builder = struct {
896 var code: u8 = undefined;906 var code: u8 = undefined;
897 return self.execAllowFail(argv, &code, .Inherit) catch |err| switch (err) {907 return self.execAllowFail(argv, &code, .Inherit) catch |err| switch (err) {
898 error.FileNotFound => {908 error.FileNotFound => {
899 warn("Unable to spawn the following command: file not found\n");909 warn("Unable to spawn the following command: file not found\n", .{});
900 printCmd(null, argv);910 printCmd(null, argv);
901 std.os.exit(@truncate(u8, code));911 std.os.exit(@truncate(u8, code));
902 },912 },
903 error.ExitCodeFailure => {913 error.ExitCodeFailure => {
904 warn("The following command exited with error code {}:\n", code);914 warn("The following command exited with error code {}:\n", .{code});
905 printCmd(null, argv);915 printCmd(null, argv);
906 std.os.exit(@truncate(u8, code));916 std.os.exit(@truncate(u8, code));
907 },917 },
908 error.ProcessTerminated => {918 error.ProcessTerminated => {
909 warn("The following command terminated unexpectedly:\n");919 warn("The following command terminated unexpectedly:\n", .{});
910 printCmd(null, argv);920 printCmd(null, argv);
911 std.os.exit(@truncate(u8, code));921 std.os.exit(@truncate(u8, code));
912 },922 },
...@@ -1133,7 +1143,7 @@ pub const LibExeObjStep = struct {...@@ -1133,7 +1143,7 @@ pub const LibExeObjStep = struct {
11331143
1134 fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, is_dynamic: bool, ver: Version) LibExeObjStep {1144 fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, is_dynamic: bool, ver: Version) LibExeObjStep {
1135 if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) {1145 if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) {
1136 panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", name);1146 panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", .{name});
1137 }1147 }
1138 var self = LibExeObjStep{1148 var self = LibExeObjStep{
1139 .strip = false,1149 .strip = false,
...@@ -1150,9 +1160,9 @@ pub const LibExeObjStep = struct {...@@ -1150,9 +1160,9 @@ pub const LibExeObjStep = struct {
1150 .step = Step.init(name, builder.allocator, make),1160 .step = Step.init(name, builder.allocator, make),
1151 .version = ver,1161 .version = ver,
1152 .out_filename = undefined,1162 .out_filename = undefined,
1153 .out_h_filename = builder.fmt("{}.h", name),1163 .out_h_filename = builder.fmt("{}.h", .{name}),
1154 .out_lib_filename = undefined,1164 .out_lib_filename = undefined,
1155 .out_pdb_filename = builder.fmt("{}.pdb", name),1165 .out_pdb_filename = builder.fmt("{}.pdb", .{name}),
1156 .major_only_filename = undefined,1166 .major_only_filename = undefined,
1157 .name_only_filename = undefined,1167 .name_only_filename = undefined,
1158 .packages = ArrayList(Pkg).init(builder.allocator),1168 .packages = ArrayList(Pkg).init(builder.allocator),
...@@ -1186,36 +1196,48 @@ pub const LibExeObjStep = struct {...@@ -1186,36 +1196,48 @@ pub const LibExeObjStep = struct {
1186 fn computeOutFileNames(self: *LibExeObjStep) void {1196 fn computeOutFileNames(self: *LibExeObjStep) void {
1187 switch (self.kind) {1197 switch (self.kind) {
1188 .Obj => {1198 .Obj => {
1189 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.oFileExt());1199 self.out_filename = self.builder.fmt("{}{}", .{ self.name, self.target.oFileExt() });
1190 },1200 },
1191 .Exe => {1201 .Exe => {
1192 self.out_filename = self.builder.fmt("{}{}", self.name, self.target.exeFileExt());1202 self.out_filename = self.builder.fmt("{}{}", .{ self.name, self.target.exeFileExt() });
1193 },1203 },
1194 .Test => {1204 .Test => {
1195 self.out_filename = self.builder.fmt("test{}", self.target.exeFileExt());1205 self.out_filename = self.builder.fmt("test{}", .{self.target.exeFileExt()});
1196 },1206 },
1197 .Lib => {1207 .Lib => {
1198 if (!self.is_dynamic) {1208 if (!self.is_dynamic) {
1199 self.out_filename = self.builder.fmt(1209 self.out_filename = self.builder.fmt("{}{}{}", .{
1200 "{}{}{}",
1201 self.target.libPrefix(),1210 self.target.libPrefix(),
1202 self.name,1211 self.name,
1203 self.target.staticLibSuffix(),1212 self.target.staticLibSuffix(),
1204 );1213 });
1205 self.out_lib_filename = self.out_filename;1214 self.out_lib_filename = self.out_filename;
1206 } else {1215 } else {
1207 if (self.target.isDarwin()) {1216 if (self.target.isDarwin()) {
1208 self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", self.name, self.version.major, self.version.minor, self.version.patch);1217 self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib", .{
1209 self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", self.name, self.version.major);1218 self.name,
1210 self.name_only_filename = self.builder.fmt("lib{}.dylib", self.name);1219 self.version.major,
1220 self.version.minor,
1221 self.version.patch,
1222 });
1223 self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", .{
1224 self.name,
1225 self.version.major,
1226 });
1227 self.name_only_filename = self.builder.fmt("lib{}.dylib", .{self.name});
1211 self.out_lib_filename = self.out_filename;1228 self.out_lib_filename = self.out_filename;
1212 } else if (self.target.isWindows()) {1229 } else if (self.target.isWindows()) {
1213 self.out_filename = self.builder.fmt("{}.dll", self.name);1230 self.out_filename = self.builder.fmt("{}.dll", .{self.name});
1214 self.out_lib_filename = self.builder.fmt("{}.lib", self.name);1231 self.out_lib_filename = self.builder.fmt("{}.lib", .{self.name});
1215 } else {1232 } else {
1216 self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", self.name, self.version.major, self.version.minor, self.version.patch);1233 self.out_filename = self.builder.fmt("lib{}.so.{d}.{d}.{d}", .{
1217 self.major_only_filename = self.builder.fmt("lib{}.so.{d}", self.name, self.version.major);1234 self.name,
1218 self.name_only_filename = self.builder.fmt("lib{}.so", self.name);1235 self.version.major,
1236 self.version.minor,
1237 self.version.patch,
1238 });
1239 self.major_only_filename = self.builder.fmt("lib{}.so.{d}", .{ self.name, self.version.major });
1240 self.name_only_filename = self.builder.fmt("lib{}.so", .{self.name});
1219 self.out_lib_filename = self.out_filename;1241 self.out_lib_filename = self.out_filename;
1220 }1242 }
1221 }1243 }
...@@ -1268,7 +1290,7 @@ pub const LibExeObjStep = struct {...@@ -1268,7 +1290,7 @@ pub const LibExeObjStep = struct {
1268 // It doesn't have to be native. We catch that if you actually try to run it.1290 // It doesn't have to be native. We catch that if you actually try to run it.
1269 // Consider that this is declarative; the run step may not be run unless a user1291 // Consider that this is declarative; the run step may not be run unless a user
1270 // option is supplied.1292 // option is supplied.
1271 const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", exe.step.name));1293 const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", .{exe.step.name}));
1272 run_step.addArtifactArg(exe);1294 run_step.addArtifactArg(exe);
12731295
1274 if (exe.vcpkg_bin_path) |path| {1296 if (exe.vcpkg_bin_path) |path| {
...@@ -1420,7 +1442,7 @@ pub const LibExeObjStep = struct {...@@ -1420,7 +1442,7 @@ pub const LibExeObjStep = struct {
1420 } else if (mem.eql(u8, tok, "-pthread")) {1442 } else if (mem.eql(u8, tok, "-pthread")) {
1421 self.linkLibC();1443 self.linkLibC();
1422 } else if (self.builder.verbose) {1444 } else if (self.builder.verbose) {
1423 warn("Ignoring pkg-config flag '{}'\n", tok);1445 warn("Ignoring pkg-config flag '{}'\n", .{tok});
1424 }1446 }
1425 }1447 }
1426 }1448 }
...@@ -1653,7 +1675,7 @@ pub const LibExeObjStep = struct {...@@ -1653,7 +1675,7 @@ pub const LibExeObjStep = struct {
1653 const builder = self.builder;1675 const builder = self.builder;
16541676
1655 if (self.root_src == null and self.link_objects.len == 0) {1677 if (self.root_src == null and self.link_objects.len == 0) {
1656 warn("{}: linker needs 1 or more objects to link\n", self.step.name);1678 warn("{}: linker needs 1 or more objects to link\n", .{self.step.name});
1657 return error.NeedAnObject;1679 return error.NeedAnObject;
1658 }1680 }
16591681
...@@ -1725,7 +1747,7 @@ pub const LibExeObjStep = struct {...@@ -1725,7 +1747,7 @@ pub const LibExeObjStep = struct {
1725 if (self.build_options_contents.len() > 0) {1747 if (self.build_options_contents.len() > 0) {
1726 const build_options_file = try fs.path.join(1748 const build_options_file = try fs.path.join(
1727 builder.allocator,1749 builder.allocator,
1728 &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },1750 &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", .{self.name}) },
1729 );1751 );
1730 try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());1752 try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());
1731 try zig_args.append("--pkg-begin");1753 try zig_args.append("--pkg-begin");
...@@ -1780,13 +1802,13 @@ pub const LibExeObjStep = struct {...@@ -1780,13 +1802,13 @@ pub const LibExeObjStep = struct {
17801802
1781 if (self.kind == Kind.Lib and self.is_dynamic) {1803 if (self.kind == Kind.Lib and self.is_dynamic) {
1782 zig_args.append("--ver-major") catch unreachable;1804 zig_args.append("--ver-major") catch unreachable;
1783 zig_args.append(builder.fmt("{}", self.version.major)) catch unreachable;1805 zig_args.append(builder.fmt("{}", .{self.version.major})) catch unreachable;
17841806
1785 zig_args.append("--ver-minor") catch unreachable;1807 zig_args.append("--ver-minor") catch unreachable;
1786 zig_args.append(builder.fmt("{}", self.version.minor)) catch unreachable;1808 zig_args.append(builder.fmt("{}", .{self.version.minor})) catch unreachable;
17871809
1788 zig_args.append("--ver-patch") catch unreachable;1810 zig_args.append("--ver-patch") catch unreachable;
1789 zig_args.append(builder.fmt("{}", self.version.patch)) catch unreachable;1811 zig_args.append(builder.fmt("{}", .{self.version.patch})) catch unreachable;
1790 }1812 }
1791 if (self.is_dynamic) {1813 if (self.is_dynamic) {
1792 try zig_args.append("-dynamic");1814 try zig_args.append("-dynamic");
...@@ -1811,7 +1833,7 @@ pub const LibExeObjStep = struct {...@@ -1811,7 +1833,7 @@ pub const LibExeObjStep = struct {
18111833
1812 if (self.target_glibc) |ver| {1834 if (self.target_glibc) |ver| {
1813 try zig_args.append("-target-glibc");1835 try zig_args.append("-target-glibc");
1814 try zig_args.append(builder.fmt("{}.{}.{}", ver.major, ver.minor, ver.patch));1836 try zig_args.append(builder.fmt("{}.{}.{}", .{ ver.major, ver.minor, ver.patch }));
1815 }1837 }
18161838
1817 if (self.linker_script) |linker_script| {1839 if (self.linker_script) |linker_script| {
...@@ -2079,7 +2101,7 @@ pub const RunStep = struct {...@@ -2079,7 +2101,7 @@ pub const RunStep = struct {
2079 }2101 }
20802102
2081 if (prev_path) |pp| {2103 if (prev_path) |pp| {
2082 const new_path = self.builder.fmt("{}" ++ [1]u8{fs.path.delimiter} ++ "{}", pp, search_path);2104 const new_path = self.builder.fmt("{}" ++ [1]u8{fs.path.delimiter} ++ "{}", .{ pp, search_path });
2083 env_map.set(key, new_path) catch unreachable;2105 env_map.set(key, new_path) catch unreachable;
2084 } else {2106 } else {
2085 env_map.set(key, search_path) catch unreachable;2107 env_map.set(key, search_path) catch unreachable;
...@@ -2153,7 +2175,7 @@ const InstallArtifactStep = struct {...@@ -2153,7 +2175,7 @@ const InstallArtifactStep = struct {
2153 const self = builder.allocator.create(Self) catch unreachable;2175 const self = builder.allocator.create(Self) catch unreachable;
2154 self.* = Self{2176 self.* = Self{
2155 .builder = builder,2177 .builder = builder,
2156 .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make),2178 .step = Step.init(builder.fmt("install {}", .{artifact.step.name}), builder.allocator, make),
2157 .artifact = artifact,2179 .artifact = artifact,
2158 .dest_dir = switch (artifact.kind) {2180 .dest_dir = switch (artifact.kind) {
2159 .Obj => unreachable,2181 .Obj => unreachable,
...@@ -2219,7 +2241,7 @@ pub const InstallFileStep = struct {...@@ -2219,7 +2241,7 @@ pub const InstallFileStep = struct {
2219 builder.pushInstalledFile(dir, dest_rel_path);2241 builder.pushInstalledFile(dir, dest_rel_path);
2220 return InstallFileStep{2242 return InstallFileStep{
2221 .builder = builder,2243 .builder = builder,
2222 .step = Step.init(builder.fmt("install {}", src_path), builder.allocator, make),2244 .step = Step.init(builder.fmt("install {}", .{src_path}), builder.allocator, make),
2223 .src_path = src_path,2245 .src_path = src_path,
2224 .dir = dir,2246 .dir = dir,
2225 .dest_rel_path = dest_rel_path,2247 .dest_rel_path = dest_rel_path,
...@@ -2253,7 +2275,7 @@ pub const InstallDirStep = struct {...@@ -2253,7 +2275,7 @@ pub const InstallDirStep = struct {
2253 builder.pushInstalledFile(options.install_dir, options.install_subdir);2275 builder.pushInstalledFile(options.install_dir, options.install_subdir);
2254 return InstallDirStep{2276 return InstallDirStep{
2255 .builder = builder,2277 .builder = builder,
2256 .step = Step.init(builder.fmt("install {}/", options.source_dir), builder.allocator, make),2278 .step = Step.init(builder.fmt("install {}/", .{options.source_dir}), builder.allocator, make),
2257 .options = options,2279 .options = options,
2258 };2280 };
2259 }2281 }
...@@ -2290,7 +2312,7 @@ pub const WriteFileStep = struct {...@@ -2290,7 +2312,7 @@ pub const WriteFileStep = struct {
2290 pub fn init(builder: *Builder, file_path: []const u8, data: []const u8) WriteFileStep {2312 pub fn init(builder: *Builder, file_path: []const u8, data: []const u8) WriteFileStep {
2291 return WriteFileStep{2313 return WriteFileStep{
2292 .builder = builder,2314 .builder = builder,
2293 .step = Step.init(builder.fmt("writefile {}", file_path), builder.allocator, make),2315 .step = Step.init(builder.fmt("writefile {}", .{file_path}), builder.allocator, make),
2294 .file_path = file_path,2316 .file_path = file_path,
2295 .data = data,2317 .data = data,
2296 };2318 };
...@@ -2301,11 +2323,11 @@ pub const WriteFileStep = struct {...@@ -2301,11 +2323,11 @@ pub const WriteFileStep = struct {
2301 const full_path = self.builder.pathFromRoot(self.file_path);2323 const full_path = self.builder.pathFromRoot(self.file_path);
2302 const full_path_dir = fs.path.dirname(full_path) orelse ".";2324 const full_path_dir = fs.path.dirname(full_path) orelse ".";
2303 fs.makePath(self.builder.allocator, full_path_dir) catch |err| {2325 fs.makePath(self.builder.allocator, full_path_dir) catch |err| {
2304 warn("unable to make path {}: {}\n", full_path_dir, @errorName(err));2326 warn("unable to make path {}: {}\n", .{ full_path_dir, @errorName(err) });
2305 return err;2327 return err;
2306 };2328 };
2307 io.writeFile(full_path, self.data) catch |err| {2329 io.writeFile(full_path, self.data) catch |err| {
2308 warn("unable to write {}: {}\n", full_path, @errorName(err));2330 warn("unable to write {}: {}\n", .{ full_path, @errorName(err) });
2309 return err;2331 return err;
2310 };2332 };
2311 }2333 }
...@@ -2319,14 +2341,14 @@ pub const LogStep = struct {...@@ -2319,14 +2341,14 @@ pub const LogStep = struct {
2319 pub fn init(builder: *Builder, data: []const u8) LogStep {2341 pub fn init(builder: *Builder, data: []const u8) LogStep {
2320 return LogStep{2342 return LogStep{
2321 .builder = builder,2343 .builder = builder,
2322 .step = Step.init(builder.fmt("log {}", data), builder.allocator, make),2344 .step = Step.init(builder.fmt("log {}", .{data}), builder.allocator, make),
2323 .data = data,2345 .data = data,
2324 };2346 };
2325 }2347 }
23262348
2327 fn make(step: *Step) anyerror!void {2349 fn make(step: *Step) anyerror!void {
2328 const self = @fieldParentPtr(LogStep, "step", step);2350 const self = @fieldParentPtr(LogStep, "step", step);
2329 warn("{}", self.data);2351 warn("{}", .{self.data});
2330 }2352 }
2331};2353};
23322354
...@@ -2338,7 +2360,7 @@ pub const RemoveDirStep = struct {...@@ -2338,7 +2360,7 @@ pub const RemoveDirStep = struct {
2338 pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep {2360 pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep {
2339 return RemoveDirStep{2361 return RemoveDirStep{
2340 .builder = builder,2362 .builder = builder,
2341 .step = Step.init(builder.fmt("RemoveDir {}", dir_path), builder.allocator, make),2363 .step = Step.init(builder.fmt("RemoveDir {}", .{dir_path}), builder.allocator, make),
2342 .dir_path = dir_path,2364 .dir_path = dir_path,
2343 };2365 };
2344 }2366 }
...@@ -2348,7 +2370,7 @@ pub const RemoveDirStep = struct {...@@ -2348,7 +2370,7 @@ pub const RemoveDirStep = struct {
23482370
2349 const full_path = self.builder.pathFromRoot(self.dir_path);2371 const full_path = self.builder.pathFromRoot(self.dir_path);
2350 fs.deleteTree(full_path) catch |err| {2372 fs.deleteTree(full_path) catch |err| {
2351 warn("Unable to remove {}: {}\n", full_path, @errorName(err));2373 warn("Unable to remove {}: {}\n", .{ full_path, @errorName(err) });
2352 return err;2374 return err;
2353 };2375 };
2354 }2376 }
...@@ -2397,7 +2419,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj...@@ -2397,7 +2419,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
2397 &[_][]const u8{ out_dir, filename_major_only },2419 &[_][]const u8{ out_dir, filename_major_only },
2398 ) catch unreachable;2420 ) catch unreachable;
2399 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {2421 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
2400 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);2422 warn("Unable to symlink {} -> {}\n", .{ major_only_path, out_basename });
2401 return err;2423 return err;
2402 };2424 };
2403 // sym link for libfoo.so to libfoo.so.12425 // sym link for libfoo.so to libfoo.so.1
...@@ -2406,7 +2428,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj...@@ -2406,7 +2428,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
2406 &[_][]const u8{ out_dir, filename_name_only },2428 &[_][]const u8{ out_dir, filename_name_only },
2407 ) catch unreachable;2429 ) catch unreachable;
2408 fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {2430 fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
2409 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);2431 warn("Unable to symlink {} -> {}\n", .{ name_only_path, filename_major_only });
2410 return err;2432 return err;
2411 };2433 };
2412}2434}
lib/std/builtin.zig+2-2
...@@ -429,7 +429,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn...@@ -429,7 +429,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
429 }429 }
430 },430 },
431 .wasi => {431 .wasi => {
432 std.debug.warn("{}", msg);432 std.debug.warn("{}", .{msg});
433 _ = std.os.wasi.proc_raise(std.os.wasi.SIGABRT);433 _ = std.os.wasi.proc_raise(std.os.wasi.SIGABRT);
434 unreachable;434 unreachable;
435 },435 },
...@@ -439,7 +439,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn...@@ -439,7 +439,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
439 },439 },
440 else => {440 else => {
441 const first_trace_addr = @returnAddress();441 const first_trace_addr = @returnAddress();
442 std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", msg);442 std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", .{msg});
443 },443 },
444 }444 }
445}445}
lib/std/crypto/benchmark.zig+1-1
...@@ -114,7 +114,7 @@ fn usage() void {...@@ -114,7 +114,7 @@ fn usage() void {
114 \\ --seed [int]114 \\ --seed [int]
115 \\ --help115 \\ --help
116 \\116 \\
117 );117 , .{});
118}118}
119119
120fn mode(comptime x: comptime_int) comptime_int {120fn mode(comptime x: comptime_int) comptime_int {
lib/std/debug.zig+56-43
...@@ -46,7 +46,7 @@ var stderr_file_out_stream: File.OutStream = undefined;...@@ -46,7 +46,7 @@ var stderr_file_out_stream: File.OutStream = undefined;
46var stderr_stream: ?*io.OutStream(File.WriteError) = null;46var stderr_stream: ?*io.OutStream(File.WriteError) = null;
47var stderr_mutex = std.Mutex.init();47var stderr_mutex = std.Mutex.init();
4848
49pub fn warn(comptime fmt: []const u8, args: ...) void {49pub fn warn(comptime fmt: []const u8, args: var) void {
50 const held = stderr_mutex.acquire();50 const held = stderr_mutex.acquire();
51 defer held.release();51 defer held.release();
52 const stderr = getStderrStream();52 const stderr = getStderrStream();
...@@ -92,15 +92,15 @@ fn wantTtyColor() bool {...@@ -92,15 +92,15 @@ fn wantTtyColor() bool {
92pub fn dumpCurrentStackTrace(start_addr: ?usize) void {92pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
93 const stderr = getStderrStream();93 const stderr = getStderrStream();
94 if (builtin.strip_debug_info) {94 if (builtin.strip_debug_info) {
95 stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;95 stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
96 return;96 return;
97 }97 }
98 const debug_info = getSelfDebugInfo() catch |err| {98 const debug_info = getSelfDebugInfo() catch |err| {
99 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return;99 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;
100 return;100 return;
101 };101 };
102 writeCurrentStackTrace(stderr, debug_info, wantTtyColor(), start_addr) catch |err| {102 writeCurrentStackTrace(stderr, debug_info, wantTtyColor(), start_addr) catch |err| {
103 stderr.print("Unable to dump stack trace: {}\n", @errorName(err)) catch return;103 stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return;
104 return;104 return;
105 };105 };
106}106}
...@@ -111,11 +111,11 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {...@@ -111,11 +111,11 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
111pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {111pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {
112 const stderr = getStderrStream();112 const stderr = getStderrStream();
113 if (builtin.strip_debug_info) {113 if (builtin.strip_debug_info) {
114 stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;114 stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
115 return;115 return;
116 }116 }
117 const debug_info = getSelfDebugInfo() catch |err| {117 const debug_info = getSelfDebugInfo() catch |err| {
118 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return;118 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;
119 return;119 return;
120 };120 };
121 const tty_color = wantTtyColor();121 const tty_color = wantTtyColor();
...@@ -184,15 +184,15 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace...@@ -184,15 +184,15 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace
184pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void {184pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void {
185 const stderr = getStderrStream();185 const stderr = getStderrStream();
186 if (builtin.strip_debug_info) {186 if (builtin.strip_debug_info) {
187 stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;187 stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return;
188 return;188 return;
189 }189 }
190 const debug_info = getSelfDebugInfo() catch |err| {190 const debug_info = getSelfDebugInfo() catch |err| {
191 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", @errorName(err)) catch return;191 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;
192 return;192 return;
193 };193 };
194 writeStackTrace(stack_trace, stderr, getDebugInfoAllocator(), debug_info, wantTtyColor()) catch |err| {194 writeStackTrace(stack_trace, stderr, getDebugInfoAllocator(), debug_info, wantTtyColor()) catch |err| {
195 stderr.print("Unable to dump stack trace: {}\n", @errorName(err)) catch return;195 stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return;
196 return;196 return;
197 };197 };
198}198}
...@@ -211,7 +211,7 @@ pub fn assert(ok: bool) void {...@@ -211,7 +211,7 @@ pub fn assert(ok: bool) void {
211 if (!ok) unreachable; // assertion failure211 if (!ok) unreachable; // assertion failure
212}212}
213213
214pub fn panic(comptime format: []const u8, args: ...) noreturn {214pub fn panic(comptime format: []const u8, args: var) noreturn {
215 @setCold(true);215 @setCold(true);
216 // TODO: remove conditional once wasi / LLVM defines __builtin_return_address216 // TODO: remove conditional once wasi / LLVM defines __builtin_return_address
217 const first_trace_addr = if (builtin.os == .wasi) null else @returnAddress();217 const first_trace_addr = if (builtin.os == .wasi) null else @returnAddress();
...@@ -221,7 +221,7 @@ pub fn panic(comptime format: []const u8, args: ...) noreturn {...@@ -221,7 +221,7 @@ pub fn panic(comptime format: []const u8, args: ...) noreturn {
221/// TODO multithreaded awareness221/// TODO multithreaded awareness
222var panicking: u8 = 0; // TODO make this a bool222var panicking: u8 = 0; // TODO make this a bool
223223
224pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: ...) noreturn {224pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: var) noreturn {
225 @setCold(true);225 @setCold(true);
226226
227 if (enable_segfault_handler) {227 if (enable_segfault_handler) {
...@@ -376,13 +376,13 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres...@@ -376,13 +376,13 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
376 } else {376 } else {
377 // we have no information to add to the address377 // we have no information to add to the address
378 if (tty_color) {378 if (tty_color) {
379 try out_stream.print("???:?:?: ");379 try out_stream.print("???:?:?: ", .{});
380 setTtyColor(TtyColor.Dim);380 setTtyColor(TtyColor.Dim);
381 try out_stream.print("0x{x} in ??? (???)", relocated_address);381 try out_stream.print("0x{x} in ??? (???)", .{relocated_address});
382 setTtyColor(TtyColor.Reset);382 setTtyColor(TtyColor.Reset);
383 try out_stream.print("\n\n\n");383 try out_stream.print("\n\n\n", .{});
384 } else {384 } else {
385 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", relocated_address);385 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{relocated_address});
386 }386 }
387 return;387 return;
388 };388 };
...@@ -509,18 +509,18 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres...@@ -509,18 +509,18 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
509 if (tty_color) {509 if (tty_color) {
510 setTtyColor(TtyColor.White);510 setTtyColor(TtyColor.White);
511 if (opt_line_info) |li| {511 if (opt_line_info) |li| {
512 try out_stream.print("{}:{}:{}", li.file_name, li.line, li.column);512 try out_stream.print("{}:{}:{}", .{ li.file_name, li.line, li.column });
513 } else {513 } else {
514 try out_stream.print("???:?:?");514 try out_stream.print("???:?:?", .{});
515 }515 }
516 setTtyColor(TtyColor.Reset);516 setTtyColor(TtyColor.Reset);
517 try out_stream.print(": ");517 try out_stream.print(": ", .{});
518 setTtyColor(TtyColor.Dim);518 setTtyColor(TtyColor.Dim);
519 try out_stream.print("0x{x} in {} ({})", relocated_address, symbol_name, obj_basename);519 try out_stream.print("0x{x} in {} ({})", .{ relocated_address, symbol_name, obj_basename });
520 setTtyColor(TtyColor.Reset);520 setTtyColor(TtyColor.Reset);
521521
522 if (opt_line_info) |line_info| {522 if (opt_line_info) |line_info| {
523 try out_stream.print("\n");523 try out_stream.print("\n", .{});
524 if (printLineFromFileAnyOs(out_stream, line_info)) {524 if (printLineFromFileAnyOs(out_stream, line_info)) {
525 if (line_info.column == 0) {525 if (line_info.column == 0) {
526 try out_stream.write("\n");526 try out_stream.write("\n");
...@@ -546,13 +546,24 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres...@@ -546,13 +546,24 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
546 else => return err,546 else => return err,
547 }547 }
548 } else {548 } else {
549 try out_stream.print("\n\n\n");549 try out_stream.print("\n\n\n", .{});
550 }550 }
551 } else {551 } else {
552 if (opt_line_info) |li| {552 if (opt_line_info) |li| {
553 try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n\n\n", li.file_name, li.line, li.column, relocated_address, symbol_name, obj_basename);553 try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n\n\n", .{
554 li.file_name,
555 li.line,
556 li.column,
557 relocated_address,
558 symbol_name,
559 obj_basename,
560 });
554 } else {561 } else {
555 try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", relocated_address, symbol_name, obj_basename);562 try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", .{
563 relocated_address,
564 symbol_name,
565 obj_basename,
566 });
556 }567 }
557 }568 }
558}569}
...@@ -697,9 +708,9 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt...@@ -697,9 +708,9 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt
697708
698 const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse {709 const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse {
699 if (tty_color) {710 if (tty_color) {
700 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", address);711 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", .{address});
701 } else {712 } else {
702 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", address);713 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{address});
703 }714 }
704 return;715 return;
705 };716 };
...@@ -723,9 +734,11 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt...@@ -723,9 +734,11 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt
723 } else |err| switch (err) {734 } else |err| switch (err) {
724 error.MissingDebugInfo, error.InvalidDebugInfo => {735 error.MissingDebugInfo, error.InvalidDebugInfo => {
725 if (tty_color) {736 if (tty_color) {
726 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n\n\n", address, symbol_name, compile_unit_name);737 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n\n\n", .{
738 address, symbol_name, compile_unit_name,
739 });
727 } else {740 } else {
728 try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", address, symbol_name, compile_unit_name);741 try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", .{ address, symbol_name, compile_unit_name });
729 }742 }
730 },743 },
731 else => return err,744 else => return err,
...@@ -746,15 +759,14 @@ fn printLineInfo(...@@ -746,15 +759,14 @@ fn printLineInfo(
746 comptime printLineFromFile: var,759 comptime printLineFromFile: var,
747) !void {760) !void {
748 if (tty_color) {761 if (tty_color) {
749 try out_stream.print(762 try out_stream.print(WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n", .{
750 WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n",
751 line_info.file_name,763 line_info.file_name,
752 line_info.line,764 line_info.line,
753 line_info.column,765 line_info.column,
754 address,766 address,
755 symbol_name,767 symbol_name,
756 compile_unit_name,768 compile_unit_name,
757 );769 });
758 if (printLineFromFile(out_stream, line_info)) {770 if (printLineFromFile(out_stream, line_info)) {
759 if (line_info.column == 0) {771 if (line_info.column == 0) {
760 try out_stream.write("\n");772 try out_stream.write("\n");
...@@ -772,15 +784,14 @@ fn printLineInfo(...@@ -772,15 +784,14 @@ fn printLineInfo(
772 else => return err,784 else => return err,
773 }785 }
774 } else {786 } else {
775 try out_stream.print(787 try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n", .{
776 "{}:{}:{}: 0x{x} in {} ({})\n",
777 line_info.file_name,788 line_info.file_name,
778 line_info.line,789 line_info.line,
779 line_info.column,790 line_info.column,
780 address,791 address,
781 symbol_name,792 symbol_name,
782 compile_unit_name,793 compile_unit_name,
783 );794 });
784 }795 }
785}796}
786797
...@@ -1226,9 +1237,9 @@ pub const DwarfInfo = struct {...@@ -1226,9 +1237,9 @@ pub const DwarfInfo = struct {
1226 ) !void {1237 ) !void {
1227 const compile_unit = self.findCompileUnit(address) catch {1238 const compile_unit = self.findCompileUnit(address) catch {
1228 if (tty_color) {1239 if (tty_color) {
1229 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", address);1240 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", .{address});
1230 } else {1241 } else {
1231 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", address);1242 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{address});
1232 }1243 }
1233 return;1244 return;
1234 };1245 };
...@@ -1248,9 +1259,11 @@ pub const DwarfInfo = struct {...@@ -1248,9 +1259,11 @@ pub const DwarfInfo = struct {
1248 } else |err| switch (err) {1259 } else |err| switch (err) {
1249 error.MissingDebugInfo, error.InvalidDebugInfo => {1260 error.MissingDebugInfo, error.InvalidDebugInfo => {
1250 if (tty_color) {1261 if (tty_color) {
1251 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? ({})" ++ RESET ++ "\n\n\n", address, compile_unit_name);1262 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? ({})" ++ RESET ++ "\n\n\n", .{
1263 address, compile_unit_name,
1264 });
1252 } else {1265 } else {
1253 try out_stream.print("???:?:?: 0x{x} in ??? ({})\n\n\n", address, compile_unit_name);1266 try out_stream.print("???:?:?: 0x{x} in ??? ({})\n\n\n", .{ address, compile_unit_name });
1254 }1267 }
1255 },1268 },
1256 else => return err,1269 else => return err,
...@@ -2416,7 +2429,7 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con...@@ -2416,7 +2429,7 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con
2416 resetSegfaultHandler();2429 resetSegfaultHandler();
24172430
2418 const addr = @ptrToInt(info.fields.sigfault.addr);2431 const addr = @ptrToInt(info.fields.sigfault.addr);
2419 std.debug.warn("Segmentation fault at address 0x{x}\n", addr);2432 std.debug.warn("Segmentation fault at address 0x{x}\n", .{addr});
24202433
2421 switch (builtin.arch) {2434 switch (builtin.arch) {
2422 .i386 => {2435 .i386 => {
...@@ -2456,10 +2469,10 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con...@@ -2456,10 +2469,10 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con
2456stdcallcc fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) c_long {2469stdcallcc fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) c_long {
2457 const exception_address = @ptrToInt(info.ExceptionRecord.ExceptionAddress);2470 const exception_address = @ptrToInt(info.ExceptionRecord.ExceptionAddress);
2458 switch (info.ExceptionRecord.ExceptionCode) {2471 switch (info.ExceptionRecord.ExceptionCode) {
2459 windows.EXCEPTION_DATATYPE_MISALIGNMENT => panicExtra(null, exception_address, "Unaligned Memory Access"),2472 windows.EXCEPTION_DATATYPE_MISALIGNMENT => panicExtra(null, exception_address, "Unaligned Memory Access", .{}),
2460 windows.EXCEPTION_ACCESS_VIOLATION => panicExtra(null, exception_address, "Segmentation fault at address 0x{x}", info.ExceptionRecord.ExceptionInformation[1]),2473 windows.EXCEPTION_ACCESS_VIOLATION => panicExtra(null, exception_address, "Segmentation fault at address 0x{x}", .{info.ExceptionRecord.ExceptionInformation[1]}),
2461 windows.EXCEPTION_ILLEGAL_INSTRUCTION => panicExtra(null, exception_address, "Illegal Instruction"),2474 windows.EXCEPTION_ILLEGAL_INSTRUCTION => panicExtra(null, exception_address, "Illegal Instruction", .{}),
2462 windows.EXCEPTION_STACK_OVERFLOW => panicExtra(null, exception_address, "Stack Overflow"),2475 windows.EXCEPTION_STACK_OVERFLOW => panicExtra(null, exception_address, "Stack Overflow", .{}),
2463 else => return windows.EXCEPTION_CONTINUE_SEARCH,2476 else => return windows.EXCEPTION_CONTINUE_SEARCH,
2464 }2477 }
2465}2478}
...@@ -2468,7 +2481,7 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void {...@@ -2468,7 +2481,7 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void {
2468 const sp = asm (""2481 const sp = asm (""
2469 : [argc] "={rsp}" (-> usize)2482 : [argc] "={rsp}" (-> usize)
2470 );2483 );
2471 std.debug.warn("{} sp = 0x{x}\n", prefix, sp);2484 std.debug.warn("{} sp = 0x{x}\n", .{ prefix, sp });
2472}2485}
24732486
2474// Reference everything so it gets tested.2487// Reference everything so it gets tested.
lib/std/event/channel.zig+2-2
...@@ -294,14 +294,14 @@ test "std.event.Channel wraparound" {...@@ -294,14 +294,14 @@ test "std.event.Channel wraparound" {
294294
295 const channel_size = 2;295 const channel_size = 2;
296296
297 var buf : [channel_size]i32 = undefined;297 var buf: [channel_size]i32 = undefined;
298 var channel: Channel(i32) = undefined;298 var channel: Channel(i32) = undefined;
299 channel.init(&buf);299 channel.init(&buf);
300 defer channel.deinit();300 defer channel.deinit();
301301
302 // add items to channel and pull them out until302 // add items to channel and pull them out until
303 // the buffer wraps around, make sure it doesn't crash.303 // the buffer wraps around, make sure it doesn't crash.
304 var result : i32 = undefined;304 var result: i32 = undefined;
305 channel.put(5);305 channel.put(5);
306 testing.expectEqual(@as(i32, 5), channel.get());306 testing.expectEqual(@as(i32, 5), channel.get());
307 channel.put(6);307 channel.put(6);
lib/std/fifo.zig+2-2
...@@ -293,7 +293,7 @@ pub fn LinearFifo(...@@ -293,7 +293,7 @@ pub fn LinearFifo(
293293
294 pub usingnamespace if (T == u8)294 pub usingnamespace if (T == u8)
295 struct {295 struct {
296 pub fn print(self: *Self, comptime format: []const u8, args: ...) !void {296 pub fn print(self: *Self, comptime format: []const u8, args: var) !void {
297 return std.fmt.format(self, error{OutOfMemory}, Self.write, format, args);297 return std.fmt.format(self, error{OutOfMemory}, Self.write, format, args);
298 }298 }
299 }299 }
...@@ -407,7 +407,7 @@ test "LinearFifo(u8, .Dynamic)" {...@@ -407,7 +407,7 @@ test "LinearFifo(u8, .Dynamic)" {
407 fifo.shrink(0);407 fifo.shrink(0);
408408
409 {409 {
410 try fifo.print("{}, {}!", "Hello", "World");410 try fifo.print("{}, {}!", .{ "Hello", "World" });
411 var result: [30]u8 = undefined;411 var result: [30]u8 = undefined;
412 testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);412 testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);
413 testing.expectEqual(@as(usize, 0), fifo.readableLength());413 testing.expectEqual(@as(usize, 0), fifo.readableLength());
lib/std/fmt.zig+111-109
...@@ -91,10 +91,12 @@ pub fn format(...@@ -91,10 +91,12 @@ pub fn format(
91 comptime Errors: type,91 comptime Errors: type,
92 output: fn (@typeOf(context), []const u8) Errors!void,92 output: fn (@typeOf(context), []const u8) Errors!void,
93 comptime fmt: []const u8,93 comptime fmt: []const u8,
94 args: ...,94 args: var,
95) Errors!void {95) Errors!void {
96 const ArgSetType = @IntType(false, 32);96 const ArgSetType = @IntType(false, 32);
97 if (args.len > ArgSetType.bit_count) {97 const args_fields = std.meta.fields(@typeOf(args));
98 const args_len = args_fields.len;
99 if (args_len > ArgSetType.bit_count) {
98 @compileError("32 arguments max are supported per format call");100 @compileError("32 arguments max are supported per format call");
99 }101 }
100102
...@@ -158,14 +160,14 @@ pub fn format(...@@ -158,14 +160,14 @@ pub fn format(
158 maybe_pos_arg.? += c - '0';160 maybe_pos_arg.? += c - '0';
159 specifier_start = i + 1;161 specifier_start = i + 1;
160162
161 if (maybe_pos_arg.? >= args.len) {163 if (maybe_pos_arg.? >= args_len) {
162 @compileError("Positional value refers to non-existent argument");164 @compileError("Positional value refers to non-existent argument");
163 }165 }
164 },166 },
165 '}' => {167 '}' => {
166 const arg_to_print = comptime nextArg(&used_pos_args, maybe_pos_arg, &next_arg);168 const arg_to_print = comptime nextArg(&used_pos_args, maybe_pos_arg, &next_arg);
167169
168 if (arg_to_print >= args.len) {170 if (arg_to_print >= args_len) {
169 @compileError("Too few arguments");171 @compileError("Too few arguments");
170 }172 }
171173
...@@ -302,7 +304,7 @@ pub fn format(...@@ -302,7 +304,7 @@ pub fn format(
302 used_pos_args |= 1 << i;304 used_pos_args |= 1 << i;
303 }305 }
304306
305 if (@popCount(ArgSetType, used_pos_args) != args.len) {307 if (@popCount(ArgSetType, used_pos_args) != args_len) {
306 @compileError("Unused arguments");308 @compileError("Unused arguments");
307 }309 }
308 if (state != State.Start) {310 if (state != State.Start) {
...@@ -389,7 +391,7 @@ pub fn formatType(...@@ -389,7 +391,7 @@ pub fn formatType(
389 }391 }
390 try output(context, " }");392 try output(context, " }");
391 } else {393 } else {
392 try format(context, Errors, output, "@{x}", @ptrToInt(&value));394 try format(context, Errors, output, "@{x}", .{@ptrToInt(&value)});
393 }395 }
394 },396 },
395 .Struct => {397 .Struct => {
...@@ -421,12 +423,12 @@ pub fn formatType(...@@ -421,12 +423,12 @@ pub fn formatType(
421 if (info.child == u8) {423 if (info.child == u8) {
422 return formatText(value, fmt, options, context, Errors, output);424 return formatText(value, fmt, options, context, Errors, output);
423 }425 }
424 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value));426 return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
425 },427 },
426 builtin.TypeId.Enum, builtin.TypeId.Union, builtin.TypeId.Struct => {428 builtin.TypeId.Enum, builtin.TypeId.Union, builtin.TypeId.Struct => {
427 return formatType(value.*, fmt, options, context, Errors, output, max_depth);429 return formatType(value.*, fmt, options, context, Errors, output, max_depth);
428 },430 },
429 else => return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value)),431 else => return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }),
430 },432 },
431 .Many => {433 .Many => {
432 if (ptr_info.child == u8) {434 if (ptr_info.child == u8) {
...@@ -435,7 +437,7 @@ pub fn formatType(...@@ -435,7 +437,7 @@ pub fn formatType(
435 return formatText(value[0..len], fmt, options, context, Errors, output);437 return formatText(value[0..len], fmt, options, context, Errors, output);
436 }438 }
437 }439 }
438 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value));440 return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
439 },441 },
440 .Slice => {442 .Slice => {
441 if (fmt.len > 0 and ((fmt[0] == 'x') or (fmt[0] == 'X'))) {443 if (fmt.len > 0 and ((fmt[0] == 'x') or (fmt[0] == 'X'))) {
...@@ -444,10 +446,10 @@ pub fn formatType(...@@ -444,10 +446,10 @@ pub fn formatType(
444 if (ptr_info.child == u8) {446 if (ptr_info.child == u8) {
445 return formatText(value, fmt, options, context, Errors, output);447 return formatText(value, fmt, options, context, Errors, output);
446 }448 }
447 return format(context, Errors, output, "{}@{x}", @typeName(ptr_info.child), @ptrToInt(value.ptr));449 return format(context, Errors, output, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value.ptr) });
448 },450 },
449 .C => {451 .C => {
450 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value));452 return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
451 },453 },
452 },454 },
453 .Array => |info| {455 .Array => |info| {
...@@ -465,7 +467,7 @@ pub fn formatType(...@@ -465,7 +467,7 @@ pub fn formatType(
465 return formatType(@as(Slice, &value), fmt, options, context, Errors, output, max_depth);467 return formatType(@as(Slice, &value), fmt, options, context, Errors, output, max_depth);
466 },468 },
467 .Fn => {469 .Fn => {
468 return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value));470 return format(context, Errors, output, "{}@{x}", .{ @typeName(T), @ptrToInt(value) });
469 },471 },
470 else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"),472 else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"),
471 }473 }
...@@ -1113,7 +1115,7 @@ pub const BufPrintError = error{...@@ -1113,7 +1115,7 @@ pub const BufPrintError = error{
1113 /// As much as possible was written to the buffer, but it was too small to fit all the printed bytes.1115 /// As much as possible was written to the buffer, but it was too small to fit all the printed bytes.
1114 BufferTooSmall,1116 BufferTooSmall,
1115};1117};
1116pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) BufPrintError![]u8 {1118pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: var) BufPrintError![]u8 {
1117 var context = BufPrintContext{ .remaining = buf };1119 var context = BufPrintContext{ .remaining = buf };
1118 try format(&context, BufPrintError, bufPrintWrite, fmt, args);1120 try format(&context, BufPrintError, bufPrintWrite, fmt, args);
1119 return buf[0 .. buf.len - context.remaining.len];1121 return buf[0 .. buf.len - context.remaining.len];
...@@ -1121,7 +1123,7 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) BufPrintError![]...@@ -1121,7 +1123,7 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) BufPrintError![]
11211123
1122pub const AllocPrintError = error{OutOfMemory};1124pub const AllocPrintError = error{OutOfMemory};
11231125
1124pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: ...) AllocPrintError![]u8 {1126pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: var) AllocPrintError![]u8 {
1125 var size: usize = 0;1127 var size: usize = 0;
1126 format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {};1128 format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {};
1127 const buf = try allocator.alloc(u8, size);1129 const buf = try allocator.alloc(u8, size);
...@@ -1173,46 +1175,46 @@ test "parse unsigned comptime" {...@@ -1173,46 +1175,46 @@ test "parse unsigned comptime" {
1173test "optional" {1175test "optional" {
1174 {1176 {
1175 const value: ?i32 = 1234;1177 const value: ?i32 = 1234;
1176 try testFmt("optional: 1234\n", "optional: {}\n", value);1178 try testFmt("optional: 1234\n", "optional: {}\n", .{value});
1177 }1179 }
1178 {1180 {
1179 const value: ?i32 = null;1181 const value: ?i32 = null;
1180 try testFmt("optional: null\n", "optional: {}\n", value);1182 try testFmt("optional: null\n", "optional: {}\n", .{value});
1181 }1183 }
1182}1184}
11831185
1184test "error" {1186test "error" {
1185 {1187 {
1186 const value: anyerror!i32 = 1234;1188 const value: anyerror!i32 = 1234;
1187 try testFmt("error union: 1234\n", "error union: {}\n", value);1189 try testFmt("error union: 1234\n", "error union: {}\n", .{value});
1188 }1190 }
1189 {1191 {
1190 const value: anyerror!i32 = error.InvalidChar;1192 const value: anyerror!i32 = error.InvalidChar;
1191 try testFmt("error union: error.InvalidChar\n", "error union: {}\n", value);1193 try testFmt("error union: error.InvalidChar\n", "error union: {}\n", .{value});
1192 }1194 }
1193}1195}
11941196
1195test "int.small" {1197test "int.small" {
1196 {1198 {
1197 const value: u3 = 0b101;1199 const value: u3 = 0b101;
1198 try testFmt("u3: 5\n", "u3: {}\n", value);1200 try testFmt("u3: 5\n", "u3: {}\n", .{value});
1199 }1201 }
1200}1202}
12011203
1202test "int.specifier" {1204test "int.specifier" {
1203 {1205 {
1204 const value: u8 = 'a';1206 const value: u8 = 'a';
1205 try testFmt("u8: a\n", "u8: {c}\n", value);1207 try testFmt("u8: a\n", "u8: {c}\n", .{value});
1206 }1208 }
1207 {1209 {
1208 const value: u8 = 0b1100;1210 const value: u8 = 0b1100;
1209 try testFmt("u8: 0b1100\n", "u8: 0b{b}\n", value);1211 try testFmt("u8: 0b1100\n", "u8: 0b{b}\n", .{value});
1210 }1212 }
1211}1213}
12121214
1213test "int.padded" {1215test "int.padded" {
1214 try testFmt("u8: ' 1'", "u8: '{:4}'", @as(u8, 1));1216 try testFmt("u8: ' 1'", "u8: '{:4}'", .{@as(u8, 1)});
1215 try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", @as(u8, 1));1217 try testFmt("u8: 'xxx1'", "u8: '{:x<4}'", .{@as(u8, 1)});
1216}1218}
12171219
1218test "buffer" {1220test "buffer" {
...@@ -1238,14 +1240,14 @@ test "buffer" {...@@ -1238,14 +1240,14 @@ test "buffer" {
1238test "array" {1240test "array" {
1239 {1241 {
1240 const value: [3]u8 = "abc".*;1242 const value: [3]u8 = "abc".*;
1241 try testFmt("array: abc\n", "array: {}\n", value);1243 try testFmt("array: abc\n", "array: {}\n", .{value});
1242 try testFmt("array: abc\n", "array: {}\n", &value);1244 try testFmt("array: abc\n", "array: {}\n", .{&value});
12431245
1244 var buf: [100]u8 = undefined;1246 var buf: [100]u8 = undefined;
1245 try testFmt(1247 try testFmt(
1246 try bufPrint(buf[0..], "array: [3]u8@{x}\n", @ptrToInt(&value)),1248 try bufPrint(buf[0..], "array: [3]u8@{x}\n", .{@ptrToInt(&value)}),
1247 "array: {*}\n",1249 "array: {*}\n",
1248 &value,1250 .{&value},
1249 );1251 );
1250 }1252 }
1251}1253}
...@@ -1253,36 +1255,36 @@ test "array" {...@@ -1253,36 +1255,36 @@ test "array" {
1253test "slice" {1255test "slice" {
1254 {1256 {
1255 const value: []const u8 = "abc";1257 const value: []const u8 = "abc";
1256 try testFmt("slice: abc\n", "slice: {}\n", value);1258 try testFmt("slice: abc\n", "slice: {}\n", .{value});
1257 }1259 }
1258 {1260 {
1259 const value = @intToPtr([*]const []const u8, 0xdeadbeef)[0..0];1261 const value = @intToPtr([*]const []const u8, 0xdeadbeef)[0..0];
1260 try testFmt("slice: []const u8@deadbeef\n", "slice: {}\n", value);1262 try testFmt("slice: []const u8@deadbeef\n", "slice: {}\n", .{value});
1261 }1263 }
12621264
1263 try testFmt("buf: Test \n", "buf: {s:5}\n", "Test");1265 try testFmt("buf: Test \n", "buf: {s:5}\n", .{"Test"});
1264 try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", "Test");1266 try testFmt("buf: Test\n Other text", "buf: {s}\n Other text", .{"Test"});
1265}1267}
12661268
1267test "pointer" {1269test "pointer" {
1268 {1270 {
1269 const value = @intToPtr(*i32, 0xdeadbeef);1271 const value = @intToPtr(*i32, 0xdeadbeef);
1270 try testFmt("pointer: i32@deadbeef\n", "pointer: {}\n", value);1272 try testFmt("pointer: i32@deadbeef\n", "pointer: {}\n", .{value});
1271 try testFmt("pointer: i32@deadbeef\n", "pointer: {*}\n", value);1273 try testFmt("pointer: i32@deadbeef\n", "pointer: {*}\n", .{value});
1272 }1274 }
1273 {1275 {
1274 const value = @intToPtr(fn () void, 0xdeadbeef);1276 const value = @intToPtr(fn () void, 0xdeadbeef);
1275 try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value);1277 try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});
1276 }1278 }
1277 {1279 {
1278 const value = @intToPtr(fn () void, 0xdeadbeef);1280 const value = @intToPtr(fn () void, 0xdeadbeef);
1279 try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", value);1281 try testFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});
1280 }1282 }
1281}1283}
12821284
1283test "cstr" {1285test "cstr" {
1284 try testFmt("cstr: Test C\n", "cstr: {s}\n", "Test C");1286 try testFmt("cstr: Test C\n", "cstr: {s}\n", .{"Test C"});
1285 try testFmt("cstr: Test C \n", "cstr: {s:10}\n", "Test C");1287 try testFmt("cstr: Test C \n", "cstr: {s:10}\n", .{"Test C"});
1286}1288}
12871289
1288test "filesize" {1290test "filesize" {
...@@ -1290,8 +1292,8 @@ test "filesize" {...@@ -1290,8 +1292,8 @@ test "filesize" {
1290 // TODO https://github.com/ziglang/zig/issues/32891292 // TODO https://github.com/ziglang/zig/issues/3289
1291 return error.SkipZigTest;1293 return error.SkipZigTest;
1292 }1294 }
1293 try testFmt("file size: 63MiB\n", "file size: {Bi}\n", @as(usize, 63 * 1024 * 1024));1295 try testFmt("file size: 63MiB\n", "file size: {Bi}\n", .{@as(usize, 63 * 1024 * 1024)});
1294 try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", @as(usize, 63 * 1024 * 1024));1296 try testFmt("file size: 66.06MB\n", "file size: {B:.2}\n", .{@as(usize, 63 * 1024 * 1024)});
1295}1297}
12961298
1297test "struct" {1299test "struct" {
...@@ -1300,8 +1302,8 @@ test "struct" {...@@ -1300,8 +1302,8 @@ test "struct" {
1300 field: u8,1302 field: u8,
1301 };1303 };
1302 const value = Struct{ .field = 42 };1304 const value = Struct{ .field = 42 };
1303 try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", value);1305 try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", .{value});
1304 try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", &value);1306 try testFmt("struct: Struct{ .field = 42 }\n", "struct: {}\n", .{&value});
1305 }1307 }
1306 {1308 {
1307 const Struct = struct {1309 const Struct = struct {
...@@ -1309,7 +1311,7 @@ test "struct" {...@@ -1309,7 +1311,7 @@ test "struct" {
1309 b: u1,1311 b: u1,
1310 };1312 };
1311 const value = Struct{ .a = 0, .b = 1 };1313 const value = Struct{ .a = 0, .b = 1 };
1312 try testFmt("struct: Struct{ .a = 0, .b = 1 }\n", "struct: {}\n", value);1314 try testFmt("struct: Struct{ .a = 0, .b = 1 }\n", "struct: {}\n", .{value});
1313 }1315 }
1314}1316}
13151317
...@@ -1319,8 +1321,8 @@ test "enum" {...@@ -1319,8 +1321,8 @@ test "enum" {
1319 Two,1321 Two,
1320 };1322 };
1321 const value = Enum.Two;1323 const value = Enum.Two;
1322 try testFmt("enum: Enum.Two\n", "enum: {}\n", value);1324 try testFmt("enum: Enum.Two\n", "enum: {}\n", .{value});
1323 try testFmt("enum: Enum.Two\n", "enum: {}\n", &value);1325 try testFmt("enum: Enum.Two\n", "enum: {}\n", .{&value});
1324}1326}
13251327
1326test "float.scientific" {1328test "float.scientific" {
...@@ -1328,10 +1330,10 @@ test "float.scientific" {...@@ -1328,10 +1330,10 @@ test "float.scientific" {
1328 // TODO https://github.com/ziglang/zig/issues/32891330 // TODO https://github.com/ziglang/zig/issues/3289
1329 return error.SkipZigTest;1331 return error.SkipZigTest;
1330 }1332 }
1331 try testFmt("f32: 1.34000003e+00", "f32: {e}", @as(f32, 1.34));1333 try testFmt("f32: 1.34000003e+00", "f32: {e}", .{@as(f32, 1.34)});
1332 try testFmt("f32: 1.23400001e+01", "f32: {e}", @as(f32, 12.34));1334 try testFmt("f32: 1.23400001e+01", "f32: {e}", .{@as(f32, 12.34)});
1333 try testFmt("f64: -1.234e+11", "f64: {e}", @as(f64, -12.34e10));1335 try testFmt("f64: -1.234e+11", "f64: {e}", .{@as(f64, -12.34e10)});
1334 try testFmt("f64: 9.99996e-40", "f64: {e}", @as(f64, 9.999960e-40));1336 try testFmt("f64: 9.99996e-40", "f64: {e}", .{@as(f64, 9.999960e-40)});
1335}1337}
13361338
1337test "float.scientific.precision" {1339test "float.scientific.precision" {
...@@ -1339,12 +1341,12 @@ test "float.scientific.precision" {...@@ -1339,12 +1341,12 @@ test "float.scientific.precision" {
1339 // TODO https://github.com/ziglang/zig/issues/32891341 // TODO https://github.com/ziglang/zig/issues/3289
1340 return error.SkipZigTest;1342 return error.SkipZigTest;
1341 }1343 }
1342 try testFmt("f64: 1.40971e-42", "f64: {e:.5}", @as(f64, 1.409706e-42));1344 try testFmt("f64: 1.40971e-42", "f64: {e:.5}", .{@as(f64, 1.409706e-42)});
1343 try testFmt("f64: 1.00000e-09", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 814313563))));1345 try testFmt("f64: 1.00000e-09", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 814313563)))});
1344 try testFmt("f64: 7.81250e-03", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1006632960))));1346 try testFmt("f64: 7.81250e-03", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1006632960)))});
1345 // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.1347 // libc rounds 1.000005e+05 to 1.00000e+05 but zig does 1.00001e+05.
1346 // In fact, libc doesn't round a lot of 5 cases up when one past the precision point.1348 // In fact, libc doesn't round a lot of 5 cases up when one past the precision point.
1347 try testFmt("f64: 1.00001e+05", "f64: {e:.5}", @as(f64, @bitCast(f32, @as(u32, 1203982400))));1349 try testFmt("f64: 1.00001e+05", "f64: {e:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1203982400)))});
1348}1350}
13491351
1350test "float.special" {1352test "float.special" {
...@@ -1352,14 +1354,14 @@ test "float.special" {...@@ -1352,14 +1354,14 @@ test "float.special" {
1352 // TODO https://github.com/ziglang/zig/issues/32891354 // TODO https://github.com/ziglang/zig/issues/3289
1353 return error.SkipZigTest;1355 return error.SkipZigTest;
1354 }1356 }
1355 try testFmt("f64: nan", "f64: {}", math.nan_f64);1357 try testFmt("f64: nan", "f64: {}", .{math.nan_f64});
1356 // negative nan is not defined by IEE 754,1358 // negative nan is not defined by IEE 754,
1357 // and ARM thus normalizes it to positive nan1359 // and ARM thus normalizes it to positive nan
1358 if (builtin.arch != builtin.Arch.arm) {1360 if (builtin.arch != builtin.Arch.arm) {
1359 try testFmt("f64: -nan", "f64: {}", -math.nan_f64);1361 try testFmt("f64: -nan", "f64: {}", .{-math.nan_f64});
1360 }1362 }
1361 try testFmt("f64: inf", "f64: {}", math.inf_f64);1363 try testFmt("f64: inf", "f64: {}", .{math.inf_f64});
1362 try testFmt("f64: -inf", "f64: {}", -math.inf_f64);1364 try testFmt("f64: -inf", "f64: {}", .{-math.inf_f64});
1363}1365}
13641366
1365test "float.decimal" {1367test "float.decimal" {
...@@ -1367,21 +1369,21 @@ test "float.decimal" {...@@ -1367,21 +1369,21 @@ test "float.decimal" {
1367 // TODO https://github.com/ziglang/zig/issues/32891369 // TODO https://github.com/ziglang/zig/issues/3289
1368 return error.SkipZigTest;1370 return error.SkipZigTest;
1369 }1371 }
1370 try testFmt("f64: 152314000000000000000000000000", "f64: {d}", @as(f64, 1.52314e+29));1372 try testFmt("f64: 152314000000000000000000000000", "f64: {d}", .{@as(f64, 1.52314e+29)});
1371 try testFmt("f32: 1.1", "f32: {d:.1}", @as(f32, 1.1234));1373 try testFmt("f32: 1.1", "f32: {d:.1}", .{@as(f32, 1.1234)});
1372 try testFmt("f32: 1234.57", "f32: {d:.2}", @as(f32, 1234.567));1374 try testFmt("f32: 1234.57", "f32: {d:.2}", .{@as(f32, 1234.567)});
1373 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).1375 // -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
1374 // -11.12339... is rounded back up to -11.12341376 // -11.12339... is rounded back up to -11.1234
1375 try testFmt("f32: -11.1234", "f32: {d:.4}", @as(f32, -11.1234));1377 try testFmt("f32: -11.1234", "f32: {d:.4}", .{@as(f32, -11.1234)});
1376 try testFmt("f32: 91.12345", "f32: {d:.5}", @as(f32, 91.12345));1378 try testFmt("f32: 91.12345", "f32: {d:.5}", .{@as(f32, 91.12345)});
1377 try testFmt("f64: 91.1234567890", "f64: {d:.10}", @as(f64, 91.12345678901235));1379 try testFmt("f64: 91.1234567890", "f64: {d:.10}", .{@as(f64, 91.12345678901235)});
1378 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 0.0));1380 try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 0.0)});
1379 try testFmt("f64: 6", "f64: {d:.0}", @as(f64, 5.700));1381 try testFmt("f64: 6", "f64: {d:.0}", .{@as(f64, 5.700)});
1380 try testFmt("f64: 10.0", "f64: {d:.1}", @as(f64, 9.999));1382 try testFmt("f64: 10.0", "f64: {d:.1}", .{@as(f64, 9.999)});
1381 try testFmt("f64: 1.000", "f64: {d:.3}", @as(f64, 1.0));1383 try testFmt("f64: 1.000", "f64: {d:.3}", .{@as(f64, 1.0)});
1382 try testFmt("f64: 0.00030000", "f64: {d:.8}", @as(f64, 0.0003));1384 try testFmt("f64: 0.00030000", "f64: {d:.8}", .{@as(f64, 0.0003)});
1383 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 1.40130e-45));1385 try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 1.40130e-45)});
1384 try testFmt("f64: 0.00000", "f64: {d:.5}", @as(f64, 9.999960e-40));1386 try testFmt("f64: 0.00000", "f64: {d:.5}", .{@as(f64, 9.999960e-40)});
1385}1387}
13861388
1387test "float.libc.sanity" {1389test "float.libc.sanity" {
...@@ -1389,22 +1391,22 @@ test "float.libc.sanity" {...@@ -1389,22 +1391,22 @@ test "float.libc.sanity" {
1389 // TODO https://github.com/ziglang/zig/issues/32891391 // TODO https://github.com/ziglang/zig/issues/3289
1390 return error.SkipZigTest;1392 return error.SkipZigTest;
1391 }1393 }
1392 try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 916964781))));1394 try testFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 916964781)))});
1393 try testFmt("f64: 0.00001", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 925353389))));1395 try testFmt("f64: 0.00001", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 925353389)))});
1394 try testFmt("f64: 0.10000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1036831278))));1396 try testFmt("f64: 0.10000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1036831278)))});
1395 try testFmt("f64: 1.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1065353133))));1397 try testFmt("f64: 1.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1065353133)))});
1396 try testFmt("f64: 10.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1092616192))));1398 try testFmt("f64: 10.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1092616192)))});
13971399
1398 // libc differences1400 // libc differences
1399 //1401 //
1400 // This is 0.015625 exactly according to gdb. We thus round down,1402 // This is 0.015625 exactly according to gdb. We thus round down,
1401 // however glibc rounds up for some reason. This occurs for all1403 // however glibc rounds up for some reason. This occurs for all
1402 // floats of the form x.yyyy25 on a precision point.1404 // floats of the form x.yyyy25 on a precision point.
1403 try testFmt("f64: 0.01563", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1015021568))));1405 try testFmt("f64: 0.01563", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1015021568)))});
1404 // errol3 rounds to ... 630 but libc rounds to ...632. Grisu31406 // errol3 rounds to ... 630 but libc rounds to ...632. Grisu3
1405 // also rounds to 630 so I'm inclined to believe libc is not1407 // also rounds to 630 so I'm inclined to believe libc is not
1406 // optimal here.1408 // optimal here.
1407 try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", @as(f64, @bitCast(f32, @as(u32, 1518338049))));1409 try testFmt("f64: 18014400656965630.00000", "f64: {d:.5}", .{@as(f64, @bitCast(f32, @as(u32, 1518338049)))});
1408}1410}
14091411
1410test "custom" {1412test "custom" {
...@@ -1422,9 +1424,9 @@ test "custom" {...@@ -1422,9 +1424,9 @@ test "custom" {
1422 output: fn (@typeOf(context), []const u8) Errors!void,1424 output: fn (@typeOf(context), []const u8) Errors!void,
1423 ) Errors!void {1425 ) Errors!void {
1424 if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) {1426 if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) {
1425 return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", self.x, self.y);1427 return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y });
1426 } else if (comptime std.mem.eql(u8, fmt, "d")) {1428 } else if (comptime std.mem.eql(u8, fmt, "d")) {
1427 return std.fmt.format(context, Errors, output, "{d:.3}x{d:.3}", self.x, self.y);1429 return std.fmt.format(context, Errors, output, "{d:.3}x{d:.3}", .{ self.x, self.y });
1428 } else {1430 } else {
1429 @compileError("Unknown format character: '" ++ fmt ++ "'");1431 @compileError("Unknown format character: '" ++ fmt ++ "'");
1430 }1432 }
...@@ -1436,12 +1438,12 @@ test "custom" {...@@ -1436,12 +1438,12 @@ test "custom" {
1436 .x = 10.2,1438 .x = 10.2,
1437 .y = 2.22,1439 .y = 2.22,
1438 };1440 };
1439 try testFmt("point: (10.200,2.220)\n", "point: {}\n", &value);1441 try testFmt("point: (10.200,2.220)\n", "point: {}\n", .{&value});
1440 try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", &value);1442 try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", .{&value});
14411443
1442 // same thing but not passing a pointer1444 // same thing but not passing a pointer
1443 try testFmt("point: (10.200,2.220)\n", "point: {}\n", value);1445 try testFmt("point: (10.200,2.220)\n", "point: {}\n", .{value});
1444 try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", value);1446 try testFmt("dim: 10.200x2.220\n", "dim: {d}\n", .{value});
1445}1447}
14461448
1447test "struct" {1449test "struct" {
...@@ -1455,7 +1457,7 @@ test "struct" {...@@ -1455,7 +1457,7 @@ test "struct" {
1455 .b = error.Unused,1457 .b = error.Unused,
1456 };1458 };
14571459
1458 try testFmt("S{ .a = 456, .b = error.Unused }", "{}", inst);1460 try testFmt("S{ .a = 456, .b = error.Unused }", "{}", .{inst});
1459}1461}
14601462
1461test "union" {1463test "union" {
...@@ -1478,13 +1480,13 @@ test "union" {...@@ -1478,13 +1480,13 @@ test "union" {
1478 const uu_inst = UU{ .int = 456 };1480 const uu_inst = UU{ .int = 456 };
1479 const eu_inst = EU{ .float = 321.123 };1481 const eu_inst = EU{ .float = 321.123 };
14801482
1481 try testFmt("TU{ .int = 123 }", "{}", tu_inst);1483 try testFmt("TU{ .int = 123 }", "{}", .{tu_inst});
14821484
1483 var buf: [100]u8 = undefined;1485 var buf: [100]u8 = undefined;
1484 const uu_result = try bufPrint(buf[0..], "{}", uu_inst);1486 const uu_result = try bufPrint(buf[0..], "{}", .{uu_inst});
1485 std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));1487 std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));
14861488
1487 const eu_result = try bufPrint(buf[0..], "{}", eu_inst);1489 const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst});
1488 std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@"));1490 std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@"));
1489}1491}
14901492
...@@ -1497,7 +1499,7 @@ test "enum" {...@@ -1497,7 +1499,7 @@ test "enum" {
14971499
1498 const inst = E.Two;1500 const inst = E.Two;
14991501
1500 try testFmt("E.Two", "{}", inst);1502 try testFmt("E.Two", "{}", .{inst});
1501}1503}
15021504
1503test "struct.self-referential" {1505test "struct.self-referential" {
...@@ -1511,7 +1513,7 @@ test "struct.self-referential" {...@@ -1511,7 +1513,7 @@ test "struct.self-referential" {
1511 };1513 };
1512 inst.a = &inst;1514 inst.a = &inst;
15131515
1514 try testFmt("S{ .a = S{ .a = S{ .a = S{ ... } } } }", "{}", inst);1516 try testFmt("S{ .a = S{ .a = S{ .a = S{ ... } } } }", "{}", .{inst});
1515}1517}
15161518
1517test "struct.zero-size" {1519test "struct.zero-size" {
...@@ -1526,30 +1528,30 @@ test "struct.zero-size" {...@@ -1526,30 +1528,30 @@ test "struct.zero-size" {
1526 const a = A{};1528 const a = A{};
1527 const b = B{ .a = a, .c = 0 };1529 const b = B{ .a = a, .c = 0 };
15281530
1529 try testFmt("B{ .a = A{ }, .c = 0 }", "{}", b);1531 try testFmt("B{ .a = A{ }, .c = 0 }", "{}", .{b});
1530}1532}
15311533
1532test "bytes.hex" {1534test "bytes.hex" {
1533 const some_bytes = "\xCA\xFE\xBA\xBE";1535 const some_bytes = "\xCA\xFE\xBA\xBE";
1534 try testFmt("lowercase: cafebabe\n", "lowercase: {x}\n", some_bytes);1536 try testFmt("lowercase: cafebabe\n", "lowercase: {x}\n", .{some_bytes});
1535 try testFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", some_bytes);1537 try testFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", .{some_bytes});
1536 //Test Slices1538 //Test Slices
1537 try testFmt("uppercase: CAFE\n", "uppercase: {X}\n", some_bytes[0..2]);1539 try testFmt("uppercase: CAFE\n", "uppercase: {X}\n", .{some_bytes[0..2]});
1538 try testFmt("lowercase: babe\n", "lowercase: {x}\n", some_bytes[2..]);1540 try testFmt("lowercase: babe\n", "lowercase: {x}\n", .{some_bytes[2..]});
1539 const bytes_with_zeros = "\x00\x0E\xBA\xBE";1541 const bytes_with_zeros = "\x00\x0E\xBA\xBE";
1540 try testFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", bytes_with_zeros);1542 try testFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{bytes_with_zeros});
1541}1543}
15421544
1543fn testFmt(expected: []const u8, comptime template: []const u8, args: ...) !void {1545fn testFmt(expected: []const u8, comptime template: []const u8, args: var) !void {
1544 var buf: [100]u8 = undefined;1546 var buf: [100]u8 = undefined;
1545 const result = try bufPrint(buf[0..], template, args);1547 const result = try bufPrint(buf[0..], template, args);
1546 if (mem.eql(u8, result, expected)) return;1548 if (mem.eql(u8, result, expected)) return;
15471549
1548 std.debug.warn("\n====== expected this output: =========\n");1550 std.debug.warn("\n====== expected this output: =========\n", .{});
1549 std.debug.warn("{}", expected);1551 std.debug.warn("{}", .{expected});
1550 std.debug.warn("\n======== instead found this: =========\n");1552 std.debug.warn("\n======== instead found this: =========\n", .{});
1551 std.debug.warn("{}", result);1553 std.debug.warn("{}", .{result});
1552 std.debug.warn("\n======================================\n");1554 std.debug.warn("\n======================================\n", .{});
1553 return error.TestFailed;1555 return error.TestFailed;
1554}1556}
15551557
...@@ -1602,7 +1604,7 @@ test "hexToBytes" {...@@ -1602,7 +1604,7 @@ test "hexToBytes" {
1602 const test_hex_str = "909A312BB12ED1F819B3521AC4C1E896F2160507FFC1C8381E3B07BB16BD1706";1604 const test_hex_str = "909A312BB12ED1F819B3521AC4C1E896F2160507FFC1C8381E3B07BB16BD1706";
1603 var pb: [32]u8 = undefined;1605 var pb: [32]u8 = undefined;
1604 try hexToBytes(pb[0..], test_hex_str);1606 try hexToBytes(pb[0..], test_hex_str);
1605 try testFmt(test_hex_str, "{X}", pb);1607 try testFmt(test_hex_str, "{X}", .{pb});
1606}1608}
16071609
1608test "formatIntValue with comptime_int" {1610test "formatIntValue with comptime_int" {
...@@ -1628,7 +1630,7 @@ test "formatType max_depth" {...@@ -1628,7 +1630,7 @@ test "formatType max_depth" {
1628 output: fn (@typeOf(context), []const u8) Errors!void,1630 output: fn (@typeOf(context), []const u8) Errors!void,
1629 ) Errors!void {1631 ) Errors!void {
1630 if (fmt.len == 0) {1632 if (fmt.len == 0) {
1631 return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", self.x, self.y);1633 return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y });
1632 } else {1634 } else {
1633 @compileError("Unknown format string: '" ++ fmt ++ "'");1635 @compileError("Unknown format string: '" ++ fmt ++ "'");
1634 }1636 }
...@@ -1680,17 +1682,17 @@ test "formatType max_depth" {...@@ -1680,17 +1682,17 @@ test "formatType max_depth" {
1680}1682}
16811683
1682test "positional" {1684test "positional" {
1683 try testFmt("2 1 0", "{2} {1} {0}", @as(usize, 0), @as(usize, 1), @as(usize, 2));1685 try testFmt("2 1 0", "{2} {1} {0}", .{ @as(usize, 0), @as(usize, 1), @as(usize, 2) });
1684 try testFmt("2 1 0", "{2} {1} {}", @as(usize, 0), @as(usize, 1), @as(usize, 2));1686 try testFmt("2 1 0", "{2} {1} {}", .{ @as(usize, 0), @as(usize, 1), @as(usize, 2) });
1685 try testFmt("0 0", "{0} {0}", @as(usize, 0));1687 try testFmt("0 0", "{0} {0}", .{@as(usize, 0)});
1686 try testFmt("0 1", "{} {1}", @as(usize, 0), @as(usize, 1));1688 try testFmt("0 1", "{} {1}", .{ @as(usize, 0), @as(usize, 1) });
1687 try testFmt("1 0 0 1", "{1} {} {0} {}", @as(usize, 0), @as(usize, 1));1689 try testFmt("1 0 0 1", "{1} {} {0} {}", .{ @as(usize, 0), @as(usize, 1) });
1688}1690}
16891691
1690test "positional with specifier" {1692test "positional with specifier" {
1691 try testFmt("10.0", "{0d:.1}", @as(f64, 9.999));1693 try testFmt("10.0", "{0d:.1}", .{@as(f64, 9.999)});
1692}1694}
16931695
1694test "positional/alignment/width/precision" {1696test "positional/alignment/width/precision" {
1695 try testFmt("10.0", "{0d: >3.1}", @as(f64, 9.999));1697 try testFmt("10.0", "{0d: >3.1}", .{@as(f64, 9.999)});
1696}1698}
lib/std/hash/benchmark.zig+1-1
...@@ -164,7 +164,7 @@ fn usage() void {...@@ -164,7 +164,7 @@ fn usage() void {
164 \\ --iterative-only164 \\ --iterative-only
165 \\ --help165 \\ --help
166 \\166 \\
167 );167 , .{});
168}168}
169169
170fn mode(comptime x: comptime_int) comptime_int {170fn mode(comptime x: comptime_int) comptime_int {
lib/std/http/headers.zig+1-1
...@@ -610,5 +610,5 @@ test "Headers.format" {...@@ -610,5 +610,5 @@ test "Headers.format" {
610 \\foo: bar610 \\foo: bar
611 \\cookie: somevalue611 \\cookie: somevalue
612 \\612 \\
613 , try std.fmt.bufPrint(buf[0..], "{}", h));613 , try std.fmt.bufPrint(buf[0..], "{}", .{h}));
614}614}
lib/std/io.zig+1-1
...@@ -492,7 +492,7 @@ test "io.SliceOutStream" {...@@ -492,7 +492,7 @@ test "io.SliceOutStream" {
492 var slice_stream = SliceOutStream.init(buf[0..]);492 var slice_stream = SliceOutStream.init(buf[0..]);
493 const stream = &slice_stream.stream;493 const stream = &slice_stream.stream;
494494
495 try stream.print("{}{}!", "Hello", "World");495 try stream.print("{}{}!", .{ "Hello", "World" });
496 testing.expectEqualSlices(u8, "HelloWorld!", slice_stream.getWritten());496 testing.expectEqualSlices(u8, "HelloWorld!", slice_stream.getWritten());
497}497}
498498
lib/std/io/out_stream.zig+1-1
...@@ -35,7 +35,7 @@ pub fn OutStream(comptime WriteError: type) type {...@@ -35,7 +35,7 @@ pub fn OutStream(comptime WriteError: type) type {
35 }35 }
36 }36 }
3737
38 pub fn print(self: *Self, comptime format: []const u8, args: ...) Error!void {38 pub fn print(self: *Self, comptime format: []const u8, args: var) Error!void {
39 return std.fmt.format(self, Error, self.writeFn, format, args);39 return std.fmt.format(self, Error, self.writeFn, format, args);
40 }40 }
4141
lib/std/io/test.zig+4-4
...@@ -27,9 +27,9 @@ test "write a file, read it, then delete it" {...@@ -27,9 +27,9 @@ test "write a file, read it, then delete it" {
27 var file_out_stream = file.outStream();27 var file_out_stream = file.outStream();
28 var buf_stream = io.BufferedOutStream(File.WriteError).init(&file_out_stream.stream);28 var buf_stream = io.BufferedOutStream(File.WriteError).init(&file_out_stream.stream);
29 const st = &buf_stream.stream;29 const st = &buf_stream.stream;
30 try st.print("begin");30 try st.print("begin", .{});
31 try st.write(data[0..]);31 try st.write(data[0..]);
32 try st.print("end");32 try st.print("end", .{});
33 try buf_stream.flush();33 try buf_stream.flush();
34 }34 }
3535
...@@ -72,7 +72,7 @@ test "BufferOutStream" {...@@ -72,7 +72,7 @@ test "BufferOutStream" {
7272
73 const x: i32 = 42;73 const x: i32 = 42;
74 const y: i32 = 1234;74 const y: i32 = 1234;
75 try buf_stream.print("x: {}\ny: {}\n", x, y);75 try buf_stream.print("x: {}\ny: {}\n", .{ x, y });
7676
77 expect(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n"));77 expect(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n"));
78}78}
...@@ -605,7 +605,7 @@ test "c out stream" {...@@ -605,7 +605,7 @@ test "c out stream" {
605 }605 }
606606
607 const out_stream = &io.COutStream.init(out_file).stream;607 const out_stream = &io.COutStream.init(out_file).stream;
608 try out_stream.print("hi: {}\n", @as(i32, 123));608 try out_stream.print("hi: {}\n", .{@as(i32, 123)});
609}609}
610610
611test "File seek ops" {611test "File seek ops" {
lib/std/json/write_stream.zig+4-4
...@@ -158,24 +158,24 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {...@@ -158,24 +158,24 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
158 switch (@typeInfo(@typeOf(value))) {158 switch (@typeInfo(@typeOf(value))) {
159 .Int => |info| {159 .Int => |info| {
160 if (info.bits < 53) {160 if (info.bits < 53) {
161 try self.stream.print("{}", value);161 try self.stream.print("{}", .{value});
162 self.popState();162 self.popState();
163 return;163 return;
164 }164 }
165 if (value < 4503599627370496 and (!info.is_signed or value > -4503599627370496)) {165 if (value < 4503599627370496 and (!info.is_signed or value > -4503599627370496)) {
166 try self.stream.print("{}", value);166 try self.stream.print("{}", .{value});
167 self.popState();167 self.popState();
168 return;168 return;
169 }169 }
170 },170 },
171 .Float => if (@floatCast(f64, value) == value) {171 .Float => if (@floatCast(f64, value) == value) {
172 try self.stream.print("{}", value);172 try self.stream.print("{}", .{value});
173 self.popState();173 self.popState();
174 return;174 return;
175 },175 },
176 else => {},176 else => {},
177 }177 }
178 try self.stream.print("\"{}\"", value);178 try self.stream.print("\"{}\"", .{value});
179 self.popState();179 self.popState();
180 }180 }
181181
lib/std/math/big/int.zig+2-2
...@@ -180,9 +180,9 @@ pub const Int = struct {...@@ -180,9 +180,9 @@ pub const Int = struct {
180180
181 pub fn dump(self: Int) void {181 pub fn dump(self: Int) void {
182 for (self.limbs) |limb| {182 for (self.limbs) |limb| {
183 debug.warn("{x} ", limb);183 debug.warn("{x} ", .{limb});
184 }184 }
185 debug.warn("\n");185 debug.warn("\n", .{});
186 }186 }
187187
188 /// Negate the sign of an Int.188 /// Negate the sign of an Int.
lib/std/net.zig+8-16
...@@ -277,32 +277,24 @@ pub const Address = extern union {...@@ -277,32 +277,24 @@ pub const Address = extern union {
277 os.AF_INET => {277 os.AF_INET => {
278 const port = mem.bigToNative(u16, self.in.port);278 const port = mem.bigToNative(u16, self.in.port);
279 const bytes = @ptrCast(*const [4]u8, &self.in.addr);279 const bytes = @ptrCast(*const [4]u8, &self.in.addr);
280 try std.fmt.format(280 try std.fmt.format(context, Errors, output, "{}.{}.{}.{}:{}", .{
281 context,
282 Errors,
283 output,
284 "{}.{}.{}.{}:{}",
285 bytes[0],281 bytes[0],
286 bytes[1],282 bytes[1],
287 bytes[2],283 bytes[2],
288 bytes[3],284 bytes[3],
289 port,285 port,
290 );286 });
291 },287 },
292 os.AF_INET6 => {288 os.AF_INET6 => {
293 const port = mem.bigToNative(u16, self.in6.port);289 const port = mem.bigToNative(u16, self.in6.port);
294 if (mem.eql(u8, self.in6.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {290 if (mem.eql(u8, self.in6.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
295 try std.fmt.format(291 try std.fmt.format(context, Errors, output, "[::ffff:{}.{}.{}.{}]:{}", .{
296 context,
297 Errors,
298 output,
299 "[::ffff:{}.{}.{}.{}]:{}",
300 self.in6.addr[12],292 self.in6.addr[12],
301 self.in6.addr[13],293 self.in6.addr[13],
302 self.in6.addr[14],294 self.in6.addr[14],
303 self.in6.addr[15],295 self.in6.addr[15],
304 port,296 port,
305 );297 });
306 return;298 return;
307 }299 }
308 const big_endian_parts = @ptrCast(*align(1) const [8]u16, &self.in6.addr);300 const big_endian_parts = @ptrCast(*align(1) const [8]u16, &self.in6.addr);
...@@ -327,19 +319,19 @@ pub const Address = extern union {...@@ -327,19 +319,19 @@ pub const Address = extern union {
327 }319 }
328 continue;320 continue;
329 }321 }
330 try std.fmt.format(context, Errors, output, "{x}", native_endian_parts[i]);322 try std.fmt.format(context, Errors, output, "{x}", .{native_endian_parts[i]});
331 if (i != native_endian_parts.len - 1) {323 if (i != native_endian_parts.len - 1) {
332 try output(context, ":");324 try output(context, ":");
333 }325 }
334 }326 }
335 try std.fmt.format(context, Errors, output, "]:{}", port);327 try std.fmt.format(context, Errors, output, "]:{}", .{port});
336 },328 },
337 os.AF_UNIX => {329 os.AF_UNIX => {
338 if (!has_unix_sockets) {330 if (!has_unix_sockets) {
339 unreachable;331 unreachable;
340 }332 }
341333
342 try std.fmt.format(context, Errors, output, "{}", &self.un.path);334 try std.fmt.format(context, Errors, output, "{}", .{&self.un.path});
343 },335 },
344 else => unreachable,336 else => unreachable,
345 }337 }
...@@ -445,7 +437,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*...@@ -445,7 +437,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
445 const name_c = try std.cstr.addNullByte(allocator, name);437 const name_c = try std.cstr.addNullByte(allocator, name);
446 defer allocator.free(name_c);438 defer allocator.free(name_c);
447439
448 const port_c = try std.fmt.allocPrint(allocator, "{}\x00", port);440 const port_c = try std.fmt.allocPrint(allocator, "{}\x00", .{port});
449 defer allocator.free(port_c);441 defer allocator.free(port_c);
450442
451 const hints = os.addrinfo{443 const hints = os.addrinfo{
lib/std/net/test.zig+3-3
...@@ -29,7 +29,7 @@ test "parse and render IPv6 addresses" {...@@ -29,7 +29,7 @@ test "parse and render IPv6 addresses" {
29 };29 };
30 for (ips) |ip, i| {30 for (ips) |ip, i| {
31 var addr = net.Address.parseIp6(ip, 0) catch unreachable;31 var addr = net.Address.parseIp6(ip, 0) catch unreachable;
32 var newIp = std.fmt.bufPrint(buffer[0..], "{}", addr) catch unreachable;32 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
33 std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));33 std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3]));
34 }34 }
3535
...@@ -51,7 +51,7 @@ test "parse and render IPv4 addresses" {...@@ -51,7 +51,7 @@ test "parse and render IPv4 addresses" {
51 "127.0.0.1",51 "127.0.0.1",
52 }) |ip| {52 }) |ip| {
53 var addr = net.Address.parseIp4(ip, 0) catch unreachable;53 var addr = net.Address.parseIp4(ip, 0) catch unreachable;
54 var newIp = std.fmt.bufPrint(buffer[0..], "{}", addr) catch unreachable;54 var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable;
55 std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));55 std.testing.expect(std.mem.eql(u8, ip, newIp[0 .. newIp.len - 2]));
56 }56 }
5757
...@@ -118,5 +118,5 @@ fn testServer(server: *net.StreamServer) anyerror!void {...@@ -118,5 +118,5 @@ fn testServer(server: *net.StreamServer) anyerror!void {
118 var client = try server.accept();118 var client = try server.accept();
119119
120 const stream = &client.file.outStream().stream;120 const stream = &client.file.outStream().stream;
121 try stream.print("hello from server\n");121 try stream.print("hello from server\n", .{});
122}122}
lib/std/os.zig+2-2
...@@ -2603,7 +2603,7 @@ pub fn realpathC(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP...@@ -2603,7 +2603,7 @@ pub fn realpathC(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
2603 defer close(fd);2603 defer close(fd);
26042604
2605 var procfs_buf: ["/proc/self/fd/-2147483648".len:0]u8 = undefined;2605 var procfs_buf: ["/proc/self/fd/-2147483648".len:0]u8 = undefined;
2606 const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{}\x00", fd) catch unreachable;2606 const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{}\x00", .{fd}) catch unreachable;
26072607
2608 return readlinkC(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer);2608 return readlinkC(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer);
2609 }2609 }
...@@ -2832,7 +2832,7 @@ pub const UnexpectedError = error{...@@ -2832,7 +2832,7 @@ pub const UnexpectedError = error{
2832/// and you get an unexpected error.2832/// and you get an unexpected error.
2833pub fn unexpectedErrno(err: usize) UnexpectedError {2833pub fn unexpectedErrno(err: usize) UnexpectedError {
2834 if (unexpected_error_tracing) {2834 if (unexpected_error_tracing) {
2835 std.debug.warn("unexpected errno: {}\n", err);2835 std.debug.warn("unexpected errno: {}\n", .{err});
2836 std.debug.dumpCurrentStackTrace(null);2836 std.debug.dumpCurrentStackTrace(null);
2837 }2837 }
2838 return error.Unexpected;2838 return error.Unexpected;
lib/std/os/windows.zig+3-3
...@@ -323,7 +323,7 @@ pub fn GetQueuedCompletionStatus(...@@ -323,7 +323,7 @@ pub fn GetQueuedCompletionStatus(
323 ERROR.HANDLE_EOF => return GetQueuedCompletionStatusResult.EOF,323 ERROR.HANDLE_EOF => return GetQueuedCompletionStatusResult.EOF,
324 else => |err| {324 else => |err| {
325 if (std.debug.runtime_safety) {325 if (std.debug.runtime_safety) {
326 std.debug.panic("unexpected error: {}\n", err);326 std.debug.panic("unexpected error: {}\n", .{err});
327 }327 }
328 },328 },
329 }329 }
...@@ -1039,7 +1039,7 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError {...@@ -1039,7 +1039,7 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError {
1039 var buf_u8: [614]u8 = undefined;1039 var buf_u8: [614]u8 = undefined;
1040 var len = kernel32.FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, null, err, MAKELANGID(LANG.NEUTRAL, SUBLANG.DEFAULT), buf_u16[0..].ptr, buf_u16.len / @sizeOf(TCHAR), null);1040 var len = kernel32.FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, null, err, MAKELANGID(LANG.NEUTRAL, SUBLANG.DEFAULT), buf_u16[0..].ptr, buf_u16.len / @sizeOf(TCHAR), null);
1041 _ = std.unicode.utf16leToUtf8(&buf_u8, buf_u16[0..len]) catch unreachable;1041 _ = std.unicode.utf16leToUtf8(&buf_u8, buf_u16[0..len]) catch unreachable;
1042 std.debug.warn("error.Unexpected: GetLastError({}): {}\n", err, buf_u8[0..len]);1042 std.debug.warn("error.Unexpected: GetLastError({}): {}\n", .{ err, buf_u8[0..len] });
1043 std.debug.dumpCurrentStackTrace(null);1043 std.debug.dumpCurrentStackTrace(null);
1044 }1044 }
1045 return error.Unexpected;1045 return error.Unexpected;
...@@ -1053,7 +1053,7 @@ pub fn unexpectedWSAError(err: c_int) std.os.UnexpectedError {...@@ -1053,7 +1053,7 @@ pub fn unexpectedWSAError(err: c_int) std.os.UnexpectedError {
1053/// and you get an unexpected status.1053/// and you get an unexpected status.
1054pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError {1054pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError {
1055 if (std.os.unexpected_error_tracing) {1055 if (std.os.unexpected_error_tracing) {
1056 std.debug.warn("error.Unexpected NTSTATUS=0x{x}\n", status);1056 std.debug.warn("error.Unexpected NTSTATUS=0x{x}\n", .{status});
1057 std.debug.dumpCurrentStackTrace(null);1057 std.debug.dumpCurrentStackTrace(null);
1058 }1058 }
1059 return error.Unexpected;1059 return error.Unexpected;
lib/std/os/zen.zig deleted-260
...@@ -1,260 +0,0 @@
1const std = @import("../std.zig");
2const assert = std.debug.assert;
3
4//////////////////////////
5//// IPC structures ////
6//////////////////////////
7
8pub const Message = struct {
9 sender: MailboxId,
10 receiver: MailboxId,
11 code: usize,
12 args: [5]usize,
13 payload: ?[]const u8,
14
15 pub fn from(mailbox_id: MailboxId) Message {
16 return Message{
17 .sender = MailboxId.Undefined,
18 .receiver = mailbox_id,
19 .code = undefined,
20 .args = undefined,
21 .payload = null,
22 };
23 }
24
25 pub fn to(mailbox_id: MailboxId, msg_code: usize, args: ...) Message {
26 var message = Message{
27 .sender = MailboxId.This,
28 .receiver = mailbox_id,
29 .code = msg_code,
30 .args = undefined,
31 .payload = null,
32 };
33
34 assert(args.len <= message.args.len);
35 comptime var i = 0;
36 inline while (i < args.len) : (i += 1) {
37 message.args[i] = args[i];
38 }
39
40 return message;
41 }
42
43 pub fn as(self: Message, sender: MailboxId) Message {
44 var message = self;
45 message.sender = sender;
46 return message;
47 }
48
49 pub fn withPayload(self: Message, payload: []const u8) Message {
50 var message = self;
51 message.payload = payload;
52 return message;
53 }
54};
55
56pub const MailboxId = union(enum) {
57 Undefined,
58 This,
59 Kernel,
60 Port: u16,
61 Thread: u16,
62};
63
64//////////////////////////////////////
65//// Ports reserved for servers ////
66//////////////////////////////////////
67
68pub const Server = struct {
69 pub const Keyboard = MailboxId{ .Port = 0 };
70 pub const Terminal = MailboxId{ .Port = 1 };
71};
72
73////////////////////////
74//// POSIX things ////
75////////////////////////
76
77// Standard streams.
78pub const STDIN_FILENO = 0;
79pub const STDOUT_FILENO = 1;
80pub const STDERR_FILENO = 2;
81
82// FIXME: let's borrow Linux's error numbers for now.
83usingnamespace @import("bits/linux/errno-generic.zig");
84// Get the errno from a syscall return value, or 0 for no error.
85pub fn getErrno(r: usize) usize {
86 const signed_r = @bitCast(isize, r);
87 return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0;
88}
89
90// TODO: implement this correctly.
91pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
92 switch (fd) {
93 STDIN_FILENO => {
94 var i: usize = 0;
95 while (i < count) : (i += 1) {
96 send(&Message.to(Server.Keyboard, 0));
97
98 // FIXME: we should be certain that we are receiving from Keyboard.
99 var message = Message.from(MailboxId.This);
100 receive(&message);
101
102 buf[i] = @intCast(u8, message.args[0]);
103 }
104 },
105 else => unreachable,
106 }
107 return count;
108}
109
110// TODO: implement this correctly.
111pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
112 switch (fd) {
113 STDOUT_FILENO, STDERR_FILENO => {
114 send(&Message.to(Server.Terminal, 1).withPayload(buf[0..count]));
115 },
116 else => unreachable,
117 }
118 return count;
119}
120
121///////////////////////////
122//// Syscall numbers ////
123///////////////////////////
124
125pub const Syscall = enum(usize) {
126 exit = 0,
127 send = 1,
128 receive = 2,
129 subscribeIRQ = 3,
130 inb = 4,
131 outb = 5,
132 map = 6,
133 createThread = 7,
134};
135
136////////////////////
137//// Syscalls ////
138////////////////////
139
140pub fn exit(status: i32) noreturn {
141 _ = syscall1(Syscall.exit, @bitCast(usize, @as(isize, status)));
142 unreachable;
143}
144
145pub fn send(message: *const Message) void {
146 _ = syscall1(Syscall.send, @ptrToInt(message));
147}
148
149pub fn receive(destination: *Message) void {
150 _ = syscall1(Syscall.receive, @ptrToInt(destination));
151}
152
153pub fn subscribeIRQ(irq: u8, mailbox_id: *const MailboxId) void {
154 _ = syscall2(Syscall.subscribeIRQ, irq, @ptrToInt(mailbox_id));
155}
156
157pub fn inb(port: u16) u8 {
158 return @intCast(u8, syscall1(Syscall.inb, port));
159}
160
161pub fn outb(port: u16, value: u8) void {
162 _ = syscall2(Syscall.outb, port, value);
163}
164
165pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {
166 return syscall4(Syscall.map, v_addr, p_addr, size, @boolToInt(writable)) != 0;
167}
168
169pub fn createThread(function: fn () void) u16 {
170 return @as(u16, syscall1(Syscall.createThread, @ptrToInt(function)));
171}
172
173/////////////////////////
174//// Syscall stubs ////
175/////////////////////////
176
177inline fn syscall0(number: Syscall) usize {
178 return asm volatile ("int $0x80"
179 : [ret] "={eax}" (-> usize)
180 : [number] "{eax}" (number)
181 );
182}
183
184inline fn syscall1(number: Syscall, arg1: usize) usize {
185 return asm volatile ("int $0x80"
186 : [ret] "={eax}" (-> usize)
187 : [number] "{eax}" (number),
188 [arg1] "{ecx}" (arg1)
189 );
190}
191
192inline fn syscall2(number: Syscall, arg1: usize, arg2: usize) usize {
193 return asm volatile ("int $0x80"
194 : [ret] "={eax}" (-> usize)
195 : [number] "{eax}" (number),
196 [arg1] "{ecx}" (arg1),
197 [arg2] "{edx}" (arg2)
198 );
199}
200
201inline fn syscall3(number: Syscall, arg1: usize, arg2: usize, arg3: usize) usize {
202 return asm volatile ("int $0x80"
203 : [ret] "={eax}" (-> usize)
204 : [number] "{eax}" (number),
205 [arg1] "{ecx}" (arg1),
206 [arg2] "{edx}" (arg2),
207 [arg3] "{ebx}" (arg3)
208 );
209}
210
211inline fn syscall4(number: Syscall, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
212 return asm volatile ("int $0x80"
213 : [ret] "={eax}" (-> usize)
214 : [number] "{eax}" (number),
215 [arg1] "{ecx}" (arg1),
216 [arg2] "{edx}" (arg2),
217 [arg3] "{ebx}" (arg3),
218 [arg4] "{esi}" (arg4)
219 );
220}
221
222inline fn syscall5(
223 number: Syscall,
224 arg1: usize,
225 arg2: usize,
226 arg3: usize,
227 arg4: usize,
228 arg5: usize,
229) usize {
230 return asm volatile ("int $0x80"
231 : [ret] "={eax}" (-> usize)
232 : [number] "{eax}" (number),
233 [arg1] "{ecx}" (arg1),
234 [arg2] "{edx}" (arg2),
235 [arg3] "{ebx}" (arg3),
236 [arg4] "{esi}" (arg4),
237 [arg5] "{edi}" (arg5)
238 );
239}
240
241inline fn syscall6(
242 number: Syscall,
243 arg1: usize,
244 arg2: usize,
245 arg3: usize,
246 arg4: usize,
247 arg5: usize,
248 arg6: usize,
249) usize {
250 return asm volatile ("int $0x80"
251 : [ret] "={eax}" (-> usize)
252 : [number] "{eax}" (number),
253 [arg1] "{ecx}" (arg1),
254 [arg2] "{edx}" (arg2),
255 [arg3] "{ebx}" (arg3),
256 [arg4] "{esi}" (arg4),
257 [arg5] "{edi}" (arg5),
258 [arg6] "{ebp}" (arg6)
259 );
260}
lib/std/priority_queue.zig+8-8
...@@ -199,19 +199,19 @@ pub fn PriorityQueue(comptime T: type) type {...@@ -199,19 +199,19 @@ pub fn PriorityQueue(comptime T: type) type {
199 }199 }
200200
201 fn dump(self: *Self) void {201 fn dump(self: *Self) void {
202 warn("{{ ");202 warn("{{ ", .{});
203 warn("items: ");203 warn("items: ", .{});
204 for (self.items) |e, i| {204 for (self.items) |e, i| {
205 if (i >= self.len) break;205 if (i >= self.len) break;
206 warn("{}, ", e);206 warn("{}, ", .{e});
207 }207 }
208 warn("array: ");208 warn("array: ", .{});
209 for (self.items) |e, i| {209 for (self.items) |e, i| {
210 warn("{}, ", e);210 warn("{}, ", .{e});
211 }211 }
212 warn("len: {} ", self.len);212 warn("len: {} ", .{self.len});
213 warn("capacity: {}", self.capacity());213 warn("capacity: {}", .{self.capacity()});
214 warn(" }}\n");214 warn(" }}\n", .{});
215 }215 }
216 };216 };
217}217}
lib/std/progress.zig+11-11
...@@ -130,11 +130,11 @@ pub const Progress = struct {...@@ -130,11 +130,11 @@ pub const Progress = struct {
130 var end: usize = 0;130 var end: usize = 0;
131 if (self.columns_written > 0) {131 if (self.columns_written > 0) {
132 // restore cursor position132 // restore cursor position
133 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{}D", self.columns_written) catch unreachable).len;133 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{}D", .{self.columns_written}) catch unreachable).len;
134 self.columns_written = 0;134 self.columns_written = 0;
135135
136 // clear rest of line136 // clear rest of line
137 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K") catch unreachable).len;137 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K", .{}) catch unreachable).len;
138 }138 }
139139
140 if (!self.done) {140 if (!self.done) {
...@@ -142,28 +142,28 @@ pub const Progress = struct {...@@ -142,28 +142,28 @@ pub const Progress = struct {
142 var maybe_node: ?*Node = &self.root;142 var maybe_node: ?*Node = &self.root;
143 while (maybe_node) |node| {143 while (maybe_node) |node| {
144 if (need_ellipse) {144 if (need_ellipse) {
145 self.bufWrite(&end, "...");145 self.bufWrite(&end, "...", .{});
146 }146 }
147 need_ellipse = false;147 need_ellipse = false;
148 if (node.name.len != 0 or node.estimated_total_items != null) {148 if (node.name.len != 0 or node.estimated_total_items != null) {
149 if (node.name.len != 0) {149 if (node.name.len != 0) {
150 self.bufWrite(&end, "{}", node.name);150 self.bufWrite(&end, "{}", .{node.name});
151 need_ellipse = true;151 need_ellipse = true;
152 }152 }
153 if (node.estimated_total_items) |total| {153 if (node.estimated_total_items) |total| {
154 if (need_ellipse) self.bufWrite(&end, " ");154 if (need_ellipse) self.bufWrite(&end, " ", .{});
155 self.bufWrite(&end, "[{}/{}] ", node.completed_items + 1, total);155 self.bufWrite(&end, "[{}/{}] ", .{ node.completed_items + 1, total });
156 need_ellipse = false;156 need_ellipse = false;
157 } else if (node.completed_items != 0) {157 } else if (node.completed_items != 0) {
158 if (need_ellipse) self.bufWrite(&end, " ");158 if (need_ellipse) self.bufWrite(&end, " ", .{});
159 self.bufWrite(&end, "[{}] ", node.completed_items + 1);159 self.bufWrite(&end, "[{}] ", .{node.completed_items + 1});
160 need_ellipse = false;160 need_ellipse = false;
161 }161 }
162 }162 }
163 maybe_node = node.recently_updated_child;163 maybe_node = node.recently_updated_child;
164 }164 }
165 if (need_ellipse) {165 if (need_ellipse) {
166 self.bufWrite(&end, "...");166 self.bufWrite(&end, "...", .{});
167 }167 }
168 }168 }
169169
...@@ -174,7 +174,7 @@ pub const Progress = struct {...@@ -174,7 +174,7 @@ pub const Progress = struct {
174 self.prev_refresh_timestamp = self.timer.read();174 self.prev_refresh_timestamp = self.timer.read();
175 }175 }
176176
177 pub fn log(self: *Progress, comptime format: []const u8, args: ...) void {177 pub fn log(self: *Progress, comptime format: []const u8, args: var) void {
178 const file = self.terminal orelse return;178 const file = self.terminal orelse return;
179 self.refresh();179 self.refresh();
180 file.outStream().stream.print(format, args) catch {180 file.outStream().stream.print(format, args) catch {
...@@ -184,7 +184,7 @@ pub const Progress = struct {...@@ -184,7 +184,7 @@ pub const Progress = struct {
184 self.columns_written = 0;184 self.columns_written = 0;
185 }185 }
186186
187 fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: ...) void {187 fn bufWrite(self: *Progress, end: *usize, comptime format: []const u8, args: var) void {
188 if (std.fmt.bufPrint(self.output_buffer[end.*..], format, args)) |written| {188 if (std.fmt.bufPrint(self.output_buffer[end.*..], format, args)) |written| {
189 const amt = written.len;189 const amt = written.len;
190 end.* += amt;190 end.* += amt;
lib/std/special/build_runner.zig+18-15
...@@ -26,15 +26,15 @@ pub fn main() !void {...@@ -26,15 +26,15 @@ pub fn main() !void {
26 _ = arg_it.skip();26 _ = arg_it.skip();
2727
28 const zig_exe = try unwrapArg(arg_it.next(allocator) orelse {28 const zig_exe = try unwrapArg(arg_it.next(allocator) orelse {
29 warn("Expected first argument to be path to zig compiler\n");29 warn("Expected first argument to be path to zig compiler\n", .{});
30 return error.InvalidArgs;30 return error.InvalidArgs;
31 });31 });
32 const build_root = try unwrapArg(arg_it.next(allocator) orelse {32 const build_root = try unwrapArg(arg_it.next(allocator) orelse {
33 warn("Expected second argument to be build root directory path\n");33 warn("Expected second argument to be build root directory path\n", .{});
34 return error.InvalidArgs;34 return error.InvalidArgs;
35 });35 });
36 const cache_root = try unwrapArg(arg_it.next(allocator) orelse {36 const cache_root = try unwrapArg(arg_it.next(allocator) orelse {
37 warn("Expected third argument to be cache root directory path\n");37 warn("Expected third argument to be cache root directory path\n", .{});
38 return error.InvalidArgs;38 return error.InvalidArgs;
39 });39 });
4040
...@@ -51,7 +51,7 @@ pub fn main() !void {...@@ -51,7 +51,7 @@ pub fn main() !void {
51 if (mem.startsWith(u8, arg, "-D")) {51 if (mem.startsWith(u8, arg, "-D")) {
52 const option_contents = arg[2..];52 const option_contents = arg[2..];
53 if (option_contents.len == 0) {53 if (option_contents.len == 0) {
54 warn("Expected option name after '-D'\n\n");54 warn("Expected option name after '-D'\n\n", .{});
55 return usageAndErr(builder, false, stderr_stream);55 return usageAndErr(builder, false, stderr_stream);
56 }56 }
57 if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {57 if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {
...@@ -70,18 +70,18 @@ pub fn main() !void {...@@ -70,18 +70,18 @@ pub fn main() !void {
70 return usage(builder, false, stdout_stream);70 return usage(builder, false, stdout_stream);
71 } else if (mem.eql(u8, arg, "--prefix")) {71 } else if (mem.eql(u8, arg, "--prefix")) {
72 builder.install_prefix = try unwrapArg(arg_it.next(allocator) orelse {72 builder.install_prefix = try unwrapArg(arg_it.next(allocator) orelse {
73 warn("Expected argument after --prefix\n\n");73 warn("Expected argument after --prefix\n\n", .{});
74 return usageAndErr(builder, false, stderr_stream);74 return usageAndErr(builder, false, stderr_stream);
75 });75 });
76 } else if (mem.eql(u8, arg, "--search-prefix")) {76 } else if (mem.eql(u8, arg, "--search-prefix")) {
77 const search_prefix = try unwrapArg(arg_it.next(allocator) orelse {77 const search_prefix = try unwrapArg(arg_it.next(allocator) orelse {
78 warn("Expected argument after --search-prefix\n\n");78 warn("Expected argument after --search-prefix\n\n", .{});
79 return usageAndErr(builder, false, stderr_stream);79 return usageAndErr(builder, false, stderr_stream);
80 });80 });
81 builder.addSearchPrefix(search_prefix);81 builder.addSearchPrefix(search_prefix);
82 } else if (mem.eql(u8, arg, "--override-lib-dir")) {82 } else if (mem.eql(u8, arg, "--override-lib-dir")) {
83 builder.override_lib_dir = try unwrapArg(arg_it.next(allocator) orelse {83 builder.override_lib_dir = try unwrapArg(arg_it.next(allocator) orelse {
84 warn("Expected argument after --override-lib-dir\n\n");84 warn("Expected argument after --override-lib-dir\n\n", .{});
85 return usageAndErr(builder, false, stderr_stream);85 return usageAndErr(builder, false, stderr_stream);
86 });86 });
87 } else if (mem.eql(u8, arg, "--verbose-tokenize")) {87 } else if (mem.eql(u8, arg, "--verbose-tokenize")) {
...@@ -99,7 +99,7 @@ pub fn main() !void {...@@ -99,7 +99,7 @@ pub fn main() !void {
99 } else if (mem.eql(u8, arg, "--verbose-cc")) {99 } else if (mem.eql(u8, arg, "--verbose-cc")) {
100 builder.verbose_cc = true;100 builder.verbose_cc = true;
101 } else {101 } else {
102 warn("Unrecognized argument: {}\n\n", arg);102 warn("Unrecognized argument: {}\n\n", .{arg});
103 return usageAndErr(builder, false, stderr_stream);103 return usageAndErr(builder, false, stderr_stream);
104 }104 }
105 } else {105 } else {
...@@ -145,15 +145,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {...@@ -145,15 +145,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
145 \\145 \\
146 \\Steps:146 \\Steps:
147 \\147 \\
148 , builder.zig_exe);148 , .{builder.zig_exe});
149149
150 const allocator = builder.allocator;150 const allocator = builder.allocator;
151 for (builder.top_level_steps.toSliceConst()) |top_level_step| {151 for (builder.top_level_steps.toSliceConst()) |top_level_step| {
152 const name = if (&top_level_step.step == builder.default_step)152 const name = if (&top_level_step.step == builder.default_step)
153 try fmt.allocPrint(allocator, "{} (default)", top_level_step.step.name)153 try fmt.allocPrint(allocator, "{} (default)", .{top_level_step.step.name})
154 else154 else
155 top_level_step.step.name;155 top_level_step.step.name;
156 try out_stream.print(" {s:22} {}\n", name, top_level_step.description);156 try out_stream.print(" {s:22} {}\n", .{ name, top_level_step.description });
157 }157 }
158158
159 try out_stream.write(159 try out_stream.write(
...@@ -169,12 +169,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {...@@ -169,12 +169,15 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
169 );169 );
170170
171 if (builder.available_options_list.len == 0) {171 if (builder.available_options_list.len == 0) {
172 try out_stream.print(" (none)\n");172 try out_stream.print(" (none)\n", .{});
173 } else {173 } else {
174 for (builder.available_options_list.toSliceConst()) |option| {174 for (builder.available_options_list.toSliceConst()) |option| {
175 const name = try fmt.allocPrint(allocator, " -D{}=[{}]", option.name, Builder.typeIdName(option.type_id));175 const name = try fmt.allocPrint(allocator, " -D{}=[{}]", .{
176 option.name,
177 Builder.typeIdName(option.type_id),
178 });
176 defer allocator.free(name);179 defer allocator.free(name);
177 try out_stream.print("{s:24} {}\n", name, option.description);180 try out_stream.print("{s:24} {}\n", .{ name, option.description });
178 }181 }
179 }182 }
180183
...@@ -204,7 +207,7 @@ const UnwrapArgError = error{OutOfMemory};...@@ -204,7 +207,7 @@ const UnwrapArgError = error{OutOfMemory};
204207
205fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 {208fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 {
206 return arg catch |err| {209 return arg catch |err| {
207 warn("Unable to parse command line: {}\n", err);210 warn("Unable to parse command line: {}\n", .{err});
208 return err;211 return err;
209 };212 };
210}213}
lib/std/special/compiler_rt/truncXfYf2_test.zig+1-1
...@@ -217,7 +217,7 @@ fn test__truncdfsf2(a: f64, expected: u32) void {...@@ -217,7 +217,7 @@ fn test__truncdfsf2(a: f64, expected: u32) void {
217 }217 }
218 }218 }
219219
220 @import("std").debug.warn("got 0x{x} wanted 0x{x}\n", rep, expected);220 @import("std").debug.warn("got 0x{x} wanted 0x{x}\n", .{ rep, expected });
221221
222 @panic("__trunctfsf2 test failure");222 @panic("__trunctfsf2 test failure");
223}223}
lib/std/special/init-exe/src/main.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn main() anyerror!void {3pub fn main() anyerror!void {
4 std.debug.warn("All your base are belong to us.\n");4 std.debug.warn("All your base are belong to us.\n", .{});
5}5}
lib/std/special/start.zig+2-2
...@@ -217,7 +217,7 @@ inline fn initEventLoopAndCallMain() u8 {...@@ -217,7 +217,7 @@ inline fn initEventLoopAndCallMain() u8 {
217 if (std.event.Loop.instance) |loop| {217 if (std.event.Loop.instance) |loop| {
218 if (!@hasDecl(root, "event_loop")) {218 if (!@hasDecl(root, "event_loop")) {
219 loop.init() catch |err| {219 loop.init() catch |err| {
220 std.debug.warn("error: {}\n", @errorName(err));220 std.debug.warn("error: {}\n", .{@errorName(err)});
221 if (@errorReturnTrace()) |trace| {221 if (@errorReturnTrace()) |trace| {
222 std.debug.dumpStackTrace(trace.*);222 std.debug.dumpStackTrace(trace.*);
223 }223 }
...@@ -264,7 +264,7 @@ fn callMain() u8 {...@@ -264,7 +264,7 @@ fn callMain() u8 {
264 },264 },
265 .ErrorUnion => {265 .ErrorUnion => {
266 const result = root.main() catch |err| {266 const result = root.main() catch |err| {
267 std.debug.warn("error: {}\n", @errorName(err));267 std.debug.warn("error: {}\n", .{@errorName(err)});
268 if (@errorReturnTrace()) |trace| {268 if (@errorReturnTrace()) |trace| {
269 std.debug.dumpStackTrace(trace.*);269 std.debug.dumpStackTrace(trace.*);
270 }270 }
lib/std/special/test_runner.zig+7-7
...@@ -16,28 +16,28 @@ pub fn main() anyerror!void {...@@ -16,28 +16,28 @@ pub fn main() anyerror!void {
16 var test_node = root_node.start(test_fn.name, null);16 var test_node = root_node.start(test_fn.name, null);
17 test_node.activate();17 test_node.activate();
18 progress.refresh();18 progress.refresh();
19 if (progress.terminal == null) std.debug.warn("{}/{} {}...", i + 1, test_fn_list.len, test_fn.name);19 if (progress.terminal == null) std.debug.warn("{}/{} {}...", .{ i + 1, test_fn_list.len, test_fn.name });
20 if (test_fn.func()) |_| {20 if (test_fn.func()) |_| {
21 ok_count += 1;21 ok_count += 1;
22 test_node.end();22 test_node.end();
23 if (progress.terminal == null) std.debug.warn("OK\n");23 if (progress.terminal == null) std.debug.warn("OK\n", .{});
24 } else |err| switch (err) {24 } else |err| switch (err) {
25 error.SkipZigTest => {25 error.SkipZigTest => {
26 skip_count += 1;26 skip_count += 1;
27 test_node.end();27 test_node.end();
28 progress.log("{}...SKIP\n", test_fn.name);28 progress.log("{}...SKIP\n", .{test_fn.name});
29 if (progress.terminal == null) std.debug.warn("SKIP\n");29 if (progress.terminal == null) std.debug.warn("SKIP\n", .{});
30 },30 },
31 else => {31 else => {
32 progress.log("");32 progress.log("", .{});
33 return err;33 return err;
34 },34 },
35 }35 }
36 }36 }
37 root_node.end();37 root_node.end();
38 if (ok_count == test_fn_list.len) {38 if (ok_count == test_fn_list.len) {
39 std.debug.warn("All {} tests passed.\n", ok_count);39 std.debug.warn("All {} tests passed.\n", .{ok_count});
40 } else {40 } else {
41 std.debug.warn("{} passed; {} skipped.\n", ok_count, skip_count);41 std.debug.warn("{} passed; {} skipped.\n", .{ ok_count, skip_count });
42 }42 }
43}43}
lib/std/target.zig+6-12
...@@ -321,14 +321,12 @@ pub const Target = union(enum) {...@@ -321,14 +321,12 @@ pub const Target = union(enum) {
321 pub const stack_align = 16;321 pub const stack_align = 16;
322322
323 pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 {323 pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
324 return std.fmt.allocPrint(324 return std.fmt.allocPrint(allocator, "{}{}-{}-{}", .{
325 allocator,
326 "{}{}-{}-{}",
327 @tagName(self.getArch()),325 @tagName(self.getArch()),
328 Target.archSubArchName(self.getArch()),326 Target.archSubArchName(self.getArch()),
329 @tagName(self.getOs()),327 @tagName(self.getOs()),
330 @tagName(self.getAbi()),328 @tagName(self.getAbi()),
331 );329 });
332 }330 }
333331
334 /// Returned slice must be freed by the caller.332 /// Returned slice must be freed by the caller.
...@@ -372,23 +370,19 @@ pub const Target = union(enum) {...@@ -372,23 +370,19 @@ pub const Target = union(enum) {
372 }370 }
373371
374 pub fn zigTripleNoSubArch(self: Target, allocator: *mem.Allocator) ![]u8 {372 pub fn zigTripleNoSubArch(self: Target, allocator: *mem.Allocator) ![]u8 {
375 return std.fmt.allocPrint(373 return std.fmt.allocPrint(allocator, "{}-{}-{}", .{
376 allocator,
377 "{}-{}-{}",
378 @tagName(self.getArch()),374 @tagName(self.getArch()),
379 @tagName(self.getOs()),375 @tagName(self.getOs()),
380 @tagName(self.getAbi()),376 @tagName(self.getAbi()),
381 );377 });
382 }378 }
383379
384 pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 {380 pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
385 return std.fmt.allocPrint(381 return std.fmt.allocPrint(allocator, "{}-{}-{}", .{
386 allocator,
387 "{}-{}-{}",
388 @tagName(self.getArch()),382 @tagName(self.getArch()),
389 @tagName(self.getOs()),383 @tagName(self.getOs()),
390 @tagName(self.getAbi()),384 @tagName(self.getAbi()),
391 );385 });
392 }386 }
393387
394 pub fn parse(text: []const u8) !Target {388 pub fn parse(text: []const u8) !Target {
lib/std/testing.zig+23-18
...@@ -8,13 +8,19 @@ pub fn expectError(expected_error: anyerror, actual_error_union: var) void {...@@ -8,13 +8,19 @@ pub fn expectError(expected_error: anyerror, actual_error_union: var) void {
8 if (actual_error_union) |actual_payload| {8 if (actual_error_union) |actual_payload| {
9 // TODO remove workaround here for https://github.com/ziglang/zig/issues/5579 // TODO remove workaround here for https://github.com/ziglang/zig/issues/557
10 if (@sizeOf(@typeOf(actual_payload)) == 0) {10 if (@sizeOf(@typeOf(actual_payload)) == 0) {
11 std.debug.panic("expected error.{}, found {} value", @errorName(expected_error), @typeName(@typeOf(actual_payload)));11 std.debug.panic("expected error.{}, found {} value", .{
12 @errorName(expected_error),
13 @typeName(@typeOf(actual_payload)),
14 });
12 } else {15 } else {
13 std.debug.panic("expected error.{}, found {}", @errorName(expected_error), actual_payload);16 std.debug.panic("expected error.{}, found {}", .{ @errorName(expected_error), actual_payload });
14 }17 }
15 } else |actual_error| {18 } else |actual_error| {
16 if (expected_error != actual_error) {19 if (expected_error != actual_error) {
17 std.debug.panic("expected error.{}, found error.{}", @errorName(expected_error), @errorName(actual_error));20 std.debug.panic("expected error.{}, found error.{}", .{
21 @errorName(expected_error),
22 @errorName(actual_error),
23 });
18 }24 }
19 }25 }
20}26}
...@@ -51,7 +57,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {...@@ -51,7 +57,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
51 .ErrorSet,57 .ErrorSet,
52 => {58 => {
53 if (actual != expected) {59 if (actual != expected) {
54 std.debug.panic("expected {}, found {}", expected, actual);60 std.debug.panic("expected {}, found {}", .{ expected, actual });
55 }61 }
56 },62 },
5763
...@@ -62,16 +68,16 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {...@@ -62,16 +68,16 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
62 builtin.TypeInfo.Pointer.Size.C,68 builtin.TypeInfo.Pointer.Size.C,
63 => {69 => {
64 if (actual != expected) {70 if (actual != expected) {
65 std.debug.panic("expected {*}, found {*}", expected, actual);71 std.debug.panic("expected {*}, found {*}", .{ expected, actual });
66 }72 }
67 },73 },
6874
69 builtin.TypeInfo.Pointer.Size.Slice => {75 builtin.TypeInfo.Pointer.Size.Slice => {
70 if (actual.ptr != expected.ptr) {76 if (actual.ptr != expected.ptr) {
71 std.debug.panic("expected slice ptr {}, found {}", expected.ptr, actual.ptr);77 std.debug.panic("expected slice ptr {}, found {}", .{ expected.ptr, actual.ptr });
72 }78 }
73 if (actual.len != expected.len) {79 if (actual.len != expected.len) {
74 std.debug.panic("expected slice len {}, found {}", expected.len, actual.len);80 std.debug.panic("expected slice len {}, found {}", .{ expected.len, actual.len });
75 }81 }
76 },82 },
77 }83 }
...@@ -106,7 +112,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {...@@ -106,7 +112,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
106 }112 }
107113
108 // we iterate over *all* union fields114 // we iterate over *all* union fields
109 // => we should never get here as the loop above is 115 // => we should never get here as the loop above is
110 // including all possible values.116 // including all possible values.
111 unreachable;117 unreachable;
112 },118 },
...@@ -116,11 +122,11 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {...@@ -116,11 +122,11 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
116 if (actual) |actual_payload| {122 if (actual) |actual_payload| {
117 expectEqual(expected_payload, actual_payload);123 expectEqual(expected_payload, actual_payload);
118 } else {124 } else {
119 std.debug.panic("expected {}, found null", expected_payload);125 std.debug.panic("expected {}, found null", .{expected_payload});
120 }126 }
121 } else {127 } else {
122 if (actual) |actual_payload| {128 if (actual) |actual_payload| {
123 std.debug.panic("expected null, found {}", actual_payload);129 std.debug.panic("expected null, found {}", .{actual_payload});
124 }130 }
125 }131 }
126 },132 },
...@@ -130,11 +136,11 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {...@@ -130,11 +136,11 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
130 if (actual) |actual_payload| {136 if (actual) |actual_payload| {
131 expectEqual(expected_payload, actual_payload);137 expectEqual(expected_payload, actual_payload);
132 } else |actual_err| {138 } else |actual_err| {
133 std.debug.panic("expected {}, found {}", expected_payload, actual_err);139 std.debug.panic("expected {}, found {}", .{ expected_payload, actual_err });
134 }140 }
135 } else |expected_err| {141 } else |expected_err| {
136 if (actual) |actual_payload| {142 if (actual) |actual_payload| {
137 std.debug.panic("expected {}, found {}", expected_err, actual_payload);143 std.debug.panic("expected {}, found {}", .{ expected_err, actual_payload });
138 } else |actual_err| {144 } else |actual_err| {
139 expectEqual(expected_err, actual_err);145 expectEqual(expected_err, actual_err);
140 }146 }
...@@ -143,15 +149,14 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {...@@ -143,15 +149,14 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
143 }149 }
144}150}
145151
146test "expectEqual.union(enum)"152test "expectEqual.union(enum)" {
147{
148 const T = union(enum) {153 const T = union(enum) {
149 a: i32,154 a: i32,
150 b: f32,155 b: f32,
151 };156 };
152157
153 const a10 = T { .a = 10 };158 const a10 = T{ .a = 10 };
154 const a20 = T { .a = 20 };159 const a20 = T{ .a = 20 };
155160
156 expectEqual(a10, a10);161 expectEqual(a10, a10);
157}162}
...@@ -165,12 +170,12 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const...@@ -165,12 +170,12 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const
165 // If the child type is u8 and no weird bytes, we could print it as strings170 // If the child type is u8 and no weird bytes, we could print it as strings
166 // Even for the length difference, it would be useful to see the values of the slices probably.171 // Even for the length difference, it would be useful to see the values of the slices probably.
167 if (expected.len != actual.len) {172 if (expected.len != actual.len) {
168 std.debug.panic("slice lengths differ. expected {}, found {}", expected.len, actual.len);173 std.debug.panic("slice lengths differ. expected {}, found {}", .{ expected.len, actual.len });
169 }174 }
170 var i: usize = 0;175 var i: usize = 0;
171 while (i < expected.len) : (i += 1) {176 while (i < expected.len) : (i += 1) {
172 if (expected[i] != actual[i]) {177 if (expected[i] != actual[i]) {
173 std.debug.panic("index {} incorrect. expected {}, found {}", i, expected[i], actual[i]);178 std.debug.panic("index {} incorrect. expected {}, found {}", .{ i, expected[i], actual[i] });
174 }179 }
175 }180 }
176}181}
lib/std/unicode.zig+1-1
...@@ -170,7 +170,7 @@ pub fn utf8ValidateSlice(s: []const u8) bool {...@@ -170,7 +170,7 @@ pub fn utf8ValidateSlice(s: []const u8) bool {
170/// ```170/// ```
171/// var utf8 = (try std.unicode.Utf8View.init("hi there")).iterator();171/// var utf8 = (try std.unicode.Utf8View.init("hi there")).iterator();
172/// while (utf8.nextCodepointSlice()) |codepoint| {172/// while (utf8.nextCodepointSlice()) |codepoint| {
173/// std.debug.warn("got codepoint {}\n", codepoint);173/// std.debug.warn("got codepoint {}\n", .{codepoint});
174/// }174/// }
175/// ```175/// ```
176pub const Utf8View = struct {176pub const Utf8View = struct {
lib/std/unicode/throughput_test.zig+6-2
...@@ -24,8 +24,12 @@ pub fn main() !void {...@@ -24,8 +24,12 @@ pub fn main() !void {
24 const elapsed_ns_better = timer.lap();24 const elapsed_ns_better = timer.lap();
25 @fence(.SeqCst);25 @fence(.SeqCst);
2626
27 std.debug.warn("original utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", elapsed_ns_orig, elapsed_ns_orig / 1000000);27 std.debug.warn("original utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", .{
28 std.debug.warn("new utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", elapsed_ns_better, elapsed_ns_better / 1000000);28 elapsed_ns_orig, elapsed_ns_orig / 1000000,
29 });
30 std.debug.warn("new utf8ToUtf16Le: elapsed: {} ns ({} ms)\n", .{
31 elapsed_ns_better, elapsed_ns_better / 1000000,
32 });
29 asm volatile ("nop"33 asm volatile ("nop"
30 :34 :
31 : [a] "r" (&buffer1),35 : [a] "r" (&buffer1),
lib/std/valgrind.zig-14
...@@ -114,20 +114,6 @@ pub fn innerThreads(qzz: [*]u8) void {...@@ -114,20 +114,6 @@ pub fn innerThreads(qzz: [*]u8) void {
114 doClientRequestStmt(.InnerThreads, qzz, 0, 0, 0, 0);114 doClientRequestStmt(.InnerThreads, qzz, 0, 0, 0, 0);
115}115}
116116
117//pub fn printf(format: [*]const u8, args: ...) usize {
118// return doClientRequestExpr(0,
119// .PrintfValistByRef,
120// @ptrToInt(format), @ptrToInt(args),
121// 0, 0, 0);
122//}
123
124//pub fn printfBacktrace(format: [*]const u8, args: ...) usize {
125// return doClientRequestExpr(0,
126// .PrintfBacktraceValistByRef,
127// @ptrToInt(format), @ptrToInt(args),
128// 0, 0, 0);
129//}
130
131pub fn nonSIMDCall0(func: fn (usize) usize) usize {117pub fn nonSIMDCall0(func: fn (usize) usize) usize {
132 return doClientRequestExpr(0, .ClientCall0, @ptrToInt(func), 0, 0, 0, 0);118 return doClientRequestExpr(0, .ClientCall0, @ptrToInt(func), 0, 0, 0, 0);
133}119}
lib/std/zig/ast.zig+15-9
...@@ -301,7 +301,9 @@ pub const Error = union(enum) {...@@ -301,7 +301,9 @@ pub const Error = union(enum) {
301 node: *Node,301 node: *Node,
302302
303 pub fn render(self: *const ExpectedCall, tokens: *Tree.TokenList, stream: var) !void {303 pub fn render(self: *const ExpectedCall, tokens: *Tree.TokenList, stream: var) !void {
304 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ ", found {}", @tagName(self.node.id));304 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ ", found {}", .{
305 @tagName(self.node.id),
306 });
305 }307 }
306 };308 };
307309
...@@ -309,7 +311,8 @@ pub const Error = union(enum) {...@@ -309,7 +311,8 @@ pub const Error = union(enum) {
309 node: *Node,311 node: *Node,
310312
311 pub fn render(self: *const ExpectedCallOrFnProto, tokens: *Tree.TokenList, stream: var) !void {313 pub fn render(self: *const ExpectedCallOrFnProto, tokens: *Tree.TokenList, stream: var) !void {
312 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ " or " ++ @tagName(Node.Id.FnProto) ++ ", found {}", @tagName(self.node.id));314 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ " or " ++
315 @tagName(Node.Id.FnProto) ++ ", found {}", .{@tagName(self.node.id)});
313 }316 }
314 };317 };
315318
...@@ -321,14 +324,14 @@ pub const Error = union(enum) {...@@ -321,14 +324,14 @@ pub const Error = union(enum) {
321 const found_token = tokens.at(self.token);324 const found_token = tokens.at(self.token);
322 switch (found_token.id) {325 switch (found_token.id) {
323 .Invalid_ampersands => {326 .Invalid_ampersands => {
324 return stream.print("`&&` is invalid. Note that `and` is boolean AND.");327 return stream.print("`&&` is invalid. Note that `and` is boolean AND.", .{});
325 },328 },
326 .Invalid => {329 .Invalid => {
327 return stream.print("expected '{}', found invalid bytes", self.expected_id.symbol());330 return stream.print("expected '{}', found invalid bytes", .{self.expected_id.symbol()});
328 },331 },
329 else => {332 else => {
330 const token_name = found_token.id.symbol();333 const token_name = found_token.id.symbol();
331 return stream.print("expected '{}', found '{}'", self.expected_id.symbol(), token_name);334 return stream.print("expected '{}', found '{}'", .{ self.expected_id.symbol(), token_name });
332 },335 },
333 }336 }
334 }337 }
...@@ -340,7 +343,10 @@ pub const Error = union(enum) {...@@ -340,7 +343,10 @@ pub const Error = union(enum) {
340343
341 pub fn render(self: *const ExpectedCommaOrEnd, tokens: *Tree.TokenList, stream: var) !void {344 pub fn render(self: *const ExpectedCommaOrEnd, tokens: *Tree.TokenList, stream: var) !void {
342 const actual_token = tokens.at(self.token);345 const actual_token = tokens.at(self.token);
343 return stream.print("expected ',' or '{}', found '{}'", self.end_id.symbol(), actual_token.id.symbol());346 return stream.print("expected ',' or '{}', found '{}'", .{
347 self.end_id.symbol(),
348 actual_token.id.symbol(),
349 });
344 }350 }
345 };351 };
346352
...@@ -352,7 +358,7 @@ pub const Error = union(enum) {...@@ -352,7 +358,7 @@ pub const Error = union(enum) {
352358
353 pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void {359 pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void {
354 const actual_token = tokens.at(self.token);360 const actual_token = tokens.at(self.token);
355 return stream.print(msg, actual_token.id.symbol());361 return stream.print(msg, .{actual_token.id.symbol()});
356 }362 }
357 };363 };
358 }364 }
...@@ -563,10 +569,10 @@ pub const Node = struct {...@@ -563,10 +569,10 @@ pub const Node = struct {
563 {569 {
564 var i: usize = 0;570 var i: usize = 0;
565 while (i < indent) : (i += 1) {571 while (i < indent) : (i += 1) {
566 std.debug.warn(" ");572 std.debug.warn(" ", .{});
567 }573 }
568 }574 }
569 std.debug.warn("{}\n", @tagName(self.id));575 std.debug.warn("{}\n", .{@tagName(self.id)});
570576
571 var child_i: usize = 0;577 var child_i: usize = 0;
572 while (self.iterate(child_i)) |child| : (child_i += 1) {578 while (self.iterate(child_i)) |child| : (child_i += 1) {
lib/std/zig/parser_test.zig+16-30
...@@ -642,15 +642,6 @@ test "zig fmt: fn decl with trailing comma" {...@@ -642,15 +642,6 @@ test "zig fmt: fn decl with trailing comma" {
642 );642 );
643}643}
644644
645test "zig fmt: var_args with trailing comma" {
646 try testCanonical(
647 \\pub fn add(
648 \\ a: ...,
649 \\) void {}
650 \\
651 );
652}
653
654test "zig fmt: enum decl with no trailing comma" {645test "zig fmt: enum decl with no trailing comma" {
655 try testTransform(646 try testTransform(
656 \\const StrLitKind = enum {Normal, C};647 \\const StrLitKind = enum {Normal, C};
...@@ -1750,13 +1741,6 @@ test "zig fmt: call expression" {...@@ -1750,13 +1741,6 @@ test "zig fmt: call expression" {
1750 );1741 );
1751}1742}
17521743
1753test "zig fmt: var args" {
1754 try testCanonical(
1755 \\fn print(args: ...) void {}
1756 \\
1757 );
1758}
1759
1760test "zig fmt: var type" {1744test "zig fmt: var type" {
1761 try testCanonical(1745 try testCanonical(
1762 \\fn print(args: var) var {}1746 \\fn print(args: var) var {}
...@@ -2705,9 +2689,9 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b...@@ -2705,9 +2689,9 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b
2705 while (error_it.next()) |parse_error| {2689 while (error_it.next()) |parse_error| {
2706 const token = tree.tokens.at(parse_error.loc());2690 const token = tree.tokens.at(parse_error.loc());
2707 const loc = tree.tokenLocation(0, parse_error.loc());2691 const loc = tree.tokenLocation(0, parse_error.loc());
2708 try stderr.print("(memory buffer):{}:{}: error: ", loc.line + 1, loc.column + 1);2692 try stderr.print("(memory buffer):{}:{}: error: ", .{ loc.line + 1, loc.column + 1 });
2709 try tree.renderError(parse_error, stderr);2693 try tree.renderError(parse_error, stderr);
2710 try stderr.print("\n{}\n", source[loc.line_start..loc.line_end]);2694 try stderr.print("\n{}\n", .{source[loc.line_start..loc.line_end]});
2711 {2695 {
2712 var i: usize = 0;2696 var i: usize = 0;
2713 while (i < loc.column) : (i += 1) {2697 while (i < loc.column) : (i += 1) {
...@@ -2743,16 +2727,16 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {...@@ -2743,16 +2727,16 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
2743 var anything_changed: bool = undefined;2727 var anything_changed: bool = undefined;
2744 const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed);2728 const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed);
2745 if (!mem.eql(u8, result_source, expected_source)) {2729 if (!mem.eql(u8, result_source, expected_source)) {
2746 warn("\n====== expected this output: =========\n");2730 warn("\n====== expected this output: =========\n", .{});
2747 warn("{}", expected_source);2731 warn("{}", .{expected_source});
2748 warn("\n======== instead found this: =========\n");2732 warn("\n======== instead found this: =========\n", .{});
2749 warn("{}", result_source);2733 warn("{}", .{result_source});
2750 warn("\n======================================\n");2734 warn("\n======================================\n", .{});
2751 return error.TestFailed;2735 return error.TestFailed;
2752 }2736 }
2753 const changes_expected = source.ptr != expected_source.ptr;2737 const changes_expected = source.ptr != expected_source.ptr;
2754 if (anything_changed != changes_expected) {2738 if (anything_changed != changes_expected) {
2755 warn("std.zig.render returned {} instead of {}\n", anything_changed, changes_expected);2739 warn("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected });
2756 return error.TestFailed;2740 return error.TestFailed;
2757 }2741 }
2758 std.testing.expect(anything_changed == changes_expected);2742 std.testing.expect(anything_changed == changes_expected);
...@@ -2772,12 +2756,14 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {...@@ -2772,12 +2756,14 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void {
2772 if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {2756 if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) {
2773 warn(2757 warn(
2774 "\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n",2758 "\nfail_index: {}/{}\nallocated bytes: {}\nfreed bytes: {}\nallocations: {}\ndeallocations: {}\n",
2775 fail_index,2759 .{
2776 needed_alloc_count,2760 fail_index,
2777 failing_allocator.allocated_bytes,2761 needed_alloc_count,
2778 failing_allocator.freed_bytes,2762 failing_allocator.allocated_bytes,
2779 failing_allocator.allocations,2763 failing_allocator.freed_bytes,
2780 failing_allocator.deallocations,2764 failing_allocator.allocations,
2765 failing_allocator.deallocations,
2766 },
2781 );2767 );
2782 return error.MemoryLeakDetected;2768 return error.MemoryLeakDetected;
2783 }2769 }
lib/std/zig/render.zig+3-3
...@@ -76,7 +76,7 @@ fn renderRoot(...@@ -76,7 +76,7 @@ fn renderRoot(
76 // render all the line comments at the beginning of the file76 // render all the line comments at the beginning of the file
77 while (tok_it.next()) |token| {77 while (tok_it.next()) |token| {
78 if (token.id != .LineComment) break;78 if (token.id != .LineComment) break;
79 try stream.print("{}\n", mem.trimRight(u8, tree.tokenSlicePtr(token), " "));79 try stream.print("{}\n", .{mem.trimRight(u8, tree.tokenSlicePtr(token), " ")});
80 if (tok_it.peek()) |next_token| {80 if (tok_it.peek()) |next_token| {
81 const loc = tree.tokenLocationPtr(token.end, next_token);81 const loc = tree.tokenLocationPtr(token.end, next_token);
82 if (loc.line >= 2) {82 if (loc.line >= 2) {
...@@ -1226,7 +1226,7 @@ fn renderExpression(...@@ -1226,7 +1226,7 @@ fn renderExpression(
12261226
1227 var skip_first_indent = true;1227 var skip_first_indent = true;
1228 if (tree.tokens.at(multiline_str_literal.firstToken() - 1).id != .LineComment) {1228 if (tree.tokens.at(multiline_str_literal.firstToken() - 1).id != .LineComment) {
1229 try stream.print("\n");1229 try stream.print("\n", .{});
1230 skip_first_indent = false;1230 skip_first_indent = false;
1231 }1231 }
12321232
...@@ -2129,7 +2129,7 @@ fn renderTokenOffset(...@@ -2129,7 +2129,7 @@ fn renderTokenOffset(
21292129
2130 var loc = tree.tokenLocationPtr(token.end, next_token);2130 var loc = tree.tokenLocationPtr(token.end, next_token);
2131 if (loc.line == 0) {2131 if (loc.line == 0) {
2132 try stream.print(" {}", mem.trimRight(u8, tree.tokenSlicePtr(next_token), " "));2132 try stream.print(" {}", .{mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ")});
2133 offset = 2;2133 offset = 2;
2134 token = next_token;2134 token = next_token;
2135 next_token = tree.tokens.at(token_index + offset);2135 next_token = tree.tokens.at(token_index + offset);
lib/std/zig/tokenizer.zig+2-2
...@@ -330,7 +330,7 @@ pub const Tokenizer = struct {...@@ -330,7 +330,7 @@ pub const Tokenizer = struct {
330330
331 /// For debugging purposes331 /// For debugging purposes
332 pub fn dump(self: *Tokenizer, token: *const Token) void {332 pub fn dump(self: *Tokenizer, token: *const Token) void {
333 std.debug.warn("{} \"{}\"\n", @tagName(token.id), self.buffer[token.start..token.end]);333 std.debug.warn("{} \"{}\"\n", .{ @tagName(token.id), self.buffer[token.start..token.end] });
334 }334 }
335335
336 pub fn init(buffer: []const u8) Tokenizer {336 pub fn init(buffer: []const u8) Tokenizer {
...@@ -1576,7 +1576,7 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void {...@@ -1576,7 +1576,7 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void {
1576 for (expected_tokens) |expected_token_id| {1576 for (expected_tokens) |expected_token_id| {
1577 const token = tokenizer.next();1577 const token = tokenizer.next();
1578 if (token.id != expected_token_id) {1578 if (token.id != expected_token_id) {
1579 std.debug.panic("expected {}, found {}\n", @tagName(expected_token_id), @tagName(token.id));1579 std.debug.panic("expected {}, found {}\n", .{ @tagName(expected_token_id), @tagName(token.id) });
1580 }1580 }
1581 }1581 }
1582 const last_token = tokenizer.next();1582 const last_token = tokenizer.next();
src-self-hosted/arg.zig+6-6
...@@ -98,15 +98,15 @@ pub const Args = struct {...@@ -98,15 +98,15 @@ pub const Args = struct {
98 const flag_args = readFlagArguments(allocator, args, flag.required, flag.allowed_set, &i) catch |err| {98 const flag_args = readFlagArguments(allocator, args, flag.required, flag.allowed_set, &i) catch |err| {
99 switch (err) {99 switch (err) {
100 error.ArgumentNotInAllowedSet => {100 error.ArgumentNotInAllowedSet => {
101 std.debug.warn("argument '{}' is invalid for flag '{}'\n", args[i], arg);101 std.debug.warn("argument '{}' is invalid for flag '{}'\n", .{ args[i], arg });
102 std.debug.warn("allowed options are ");102 std.debug.warn("allowed options are ", .{});
103 for (flag.allowed_set.?) |possible| {103 for (flag.allowed_set.?) |possible| {
104 std.debug.warn("'{}' ", possible);104 std.debug.warn("'{}' ", .{possible});
105 }105 }
106 std.debug.warn("\n");106 std.debug.warn("\n", .{});
107 },107 },
108 error.MissingFlagArguments => {108 error.MissingFlagArguments => {
109 std.debug.warn("missing argument for flag: {}\n", arg);109 std.debug.warn("missing argument for flag: {}\n", .{arg});
110 },110 },
111 else => {},111 else => {},
112 }112 }
...@@ -134,7 +134,7 @@ pub const Args = struct {...@@ -134,7 +134,7 @@ pub const Args = struct {
134 }134 }
135135
136 // TODO: Better errors with context, global error state and return is sufficient.136 // TODO: Better errors with context, global error state and return is sufficient.
137 std.debug.warn("could not match flag: {}\n", arg);137 std.debug.warn("could not match flag: {}\n", .{arg});
138 return error.UnknownFlag;138 return error.UnknownFlag;
139 } else {139 } else {
140 try parsed.positionals.append(arg);140 try parsed.positionals.append(arg);
src-self-hosted/codegen.zig+6-8
...@@ -45,13 +45,11 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)...@@ -45,13 +45,11 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
4545
46 // Don't use ZIG_VERSION_STRING here. LLVM misparses it when it includes46 // Don't use ZIG_VERSION_STRING here. LLVM misparses it when it includes
47 // the git revision.47 // the git revision.
48 const producer = try std.Buffer.allocPrint(48 const producer = try std.Buffer.allocPrint(&code.arena.allocator, "zig {}.{}.{}", .{
49 &code.arena.allocator,
50 "zig {}.{}.{}",
51 @as(u32, c.ZIG_VERSION_MAJOR),49 @as(u32, c.ZIG_VERSION_MAJOR),
52 @as(u32, c.ZIG_VERSION_MINOR),50 @as(u32, c.ZIG_VERSION_MINOR),
53 @as(u32, c.ZIG_VERSION_PATCH),51 @as(u32, c.ZIG_VERSION_PATCH),
54 );52 });
55 const flags = "";53 const flags = "";
56 const runtime_version = 0;54 const runtime_version = 0;
57 const compile_unit_file = llvm.CreateFile(55 const compile_unit_file = llvm.CreateFile(
...@@ -93,7 +91,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)...@@ -93,7 +91,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
93 llvm.DIBuilderFinalize(dibuilder);91 llvm.DIBuilderFinalize(dibuilder);
9492
95 if (comp.verbose_llvm_ir) {93 if (comp.verbose_llvm_ir) {
96 std.debug.warn("raw module:\n");94 std.debug.warn("raw module:\n", .{});
97 llvm.DumpModule(ofile.module);95 llvm.DumpModule(ofile.module);
98 }96 }
9997
...@@ -120,18 +118,18 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)...@@ -120,18 +118,18 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
120 is_small,118 is_small,
121 )) {119 )) {
122 if (std.debug.runtime_safety) {120 if (std.debug.runtime_safety) {
123 std.debug.panic("unable to write object file {}: {s}\n", output_path.toSliceConst(), err_msg);121 std.debug.panic("unable to write object file {}: {s}\n", .{ output_path.toSliceConst(), err_msg });
124 }122 }
125 return error.WritingObjectFileFailed;123 return error.WritingObjectFileFailed;
126 }124 }
127 //validate_inline_fns(g); TODO125 //validate_inline_fns(g); TODO
128 fn_val.containing_object = output_path;126 fn_val.containing_object = output_path;
129 if (comp.verbose_llvm_ir) {127 if (comp.verbose_llvm_ir) {
130 std.debug.warn("optimized module:\n");128 std.debug.warn("optimized module:\n", .{});
131 llvm.DumpModule(ofile.module);129 llvm.DumpModule(ofile.module);
132 }130 }
133 if (comp.verbose_link) {131 if (comp.verbose_link) {
134 std.debug.warn("created {}\n", output_path.toSliceConst());132 std.debug.warn("created {}\n", .{output_path.toSliceConst()});
135 }133 }
136}134}
137135
src-self-hosted/compilation.zig+12-15
...@@ -807,7 +807,7 @@ pub const Compilation = struct {...@@ -807,7 +807,7 @@ pub const Compilation = struct {
807 root_scope.realpath,807 root_scope.realpath,
808 max_src_size,808 max_src_size,
809 ) catch |err| {809 ) catch |err| {
810 try self.addCompileErrorCli(root_scope.realpath, "unable to open: {}", @errorName(err));810 try self.addCompileErrorCli(root_scope.realpath, "unable to open: {}", .{@errorName(err)});
811 return;811 return;
812 };812 };
813 errdefer self.gpa().free(source_code);813 errdefer self.gpa().free(source_code);
...@@ -878,7 +878,7 @@ pub const Compilation = struct {...@@ -878,7 +878,7 @@ pub const Compilation = struct {
878 try self.addCompileError(tree_scope, Span{878 try self.addCompileError(tree_scope, Span{
879 .first = fn_proto.fn_token,879 .first = fn_proto.fn_token,
880 .last = fn_proto.fn_token + 1,880 .last = fn_proto.fn_token + 1,
881 }, "missing function name");881 }, "missing function name", .{});
882 continue;882 continue;
883 };883 };
884884
...@@ -942,7 +942,7 @@ pub const Compilation = struct {...@@ -942,7 +942,7 @@ pub const Compilation = struct {
942 const root_scope = blk: {942 const root_scope = blk: {
943 // TODO async/await std.fs.realpath943 // TODO async/await std.fs.realpath
944 const root_src_real_path = std.fs.realpathAlloc(self.gpa(), root_src_path) catch |err| {944 const root_src_real_path = std.fs.realpathAlloc(self.gpa(), root_src_path) catch |err| {
945 try self.addCompileErrorCli(root_src_path, "unable to open: {}", @errorName(err));945 try self.addCompileErrorCli(root_src_path, "unable to open: {}", .{@errorName(err)});
946 return;946 return;
947 };947 };
948 errdefer self.gpa().free(root_src_real_path);948 errdefer self.gpa().free(root_src_real_path);
...@@ -991,7 +991,7 @@ pub const Compilation = struct {...@@ -991,7 +991,7 @@ pub const Compilation = struct {
991 defer unanalyzed_code.destroy(comp.gpa());991 defer unanalyzed_code.destroy(comp.gpa());
992992
993 if (comp.verbose_ir) {993 if (comp.verbose_ir) {
994 std.debug.warn("unanalyzed:\n");994 std.debug.warn("unanalyzed:\n", .{});
995 unanalyzed_code.dump();995 unanalyzed_code.dump();
996 }996 }
997997
...@@ -1003,7 +1003,7 @@ pub const Compilation = struct {...@@ -1003,7 +1003,7 @@ pub const Compilation = struct {
1003 errdefer analyzed_code.destroy(comp.gpa());1003 errdefer analyzed_code.destroy(comp.gpa());
10041004
1005 if (comp.verbose_ir) {1005 if (comp.verbose_ir) {
1006 std.debug.warn("analyzed:\n");1006 std.debug.warn("analyzed:\n", .{});
1007 analyzed_code.dump();1007 analyzed_code.dump();
1008 }1008 }
10091009
...@@ -1048,14 +1048,14 @@ pub const Compilation = struct {...@@ -1048,14 +1048,14 @@ pub const Compilation = struct {
10481048
1049 const gop = try locked_table.getOrPut(decl.name);1049 const gop = try locked_table.getOrPut(decl.name);
1050 if (gop.found_existing) {1050 if (gop.found_existing) {
1051 try self.addCompileError(decl.tree_scope, decl.getSpan(), "redefinition of '{}'", decl.name);1051 try self.addCompileError(decl.tree_scope, decl.getSpan(), "redefinition of '{}'", .{decl.name});
1052 // TODO note: other definition here1052 // TODO note: other definition here
1053 } else {1053 } else {
1054 gop.kv.value = decl;1054 gop.kv.value = decl;
1055 }1055 }
1056 }1056 }
10571057
1058 fn addCompileError(self: *Compilation, tree_scope: *Scope.AstTree, span: Span, comptime fmt: []const u8, args: ...) !void {1058 fn addCompileError(self: *Compilation, tree_scope: *Scope.AstTree, span: Span, comptime fmt: []const u8, args: var) !void {
1059 const text = try std.fmt.allocPrint(self.gpa(), fmt, args);1059 const text = try std.fmt.allocPrint(self.gpa(), fmt, args);
1060 errdefer self.gpa().free(text);1060 errdefer self.gpa().free(text);
10611061
...@@ -1065,7 +1065,7 @@ pub const Compilation = struct {...@@ -1065,7 +1065,7 @@ pub const Compilation = struct {
1065 try self.prelink_group.call(addCompileErrorAsync, self, msg);1065 try self.prelink_group.call(addCompileErrorAsync, self, msg);
1066 }1066 }
10671067
1068 fn addCompileErrorCli(self: *Compilation, realpath: []const u8, comptime fmt: []const u8, args: ...) !void {1068 fn addCompileErrorCli(self: *Compilation, realpath: []const u8, comptime fmt: []const u8, args: var) !void {
1069 const text = try std.fmt.allocPrint(self.gpa(), fmt, args);1069 const text = try std.fmt.allocPrint(self.gpa(), fmt, args);
1070 errdefer self.gpa().free(text);1070 errdefer self.gpa().free(text);
10711071
...@@ -1092,12 +1092,9 @@ pub const Compilation = struct {...@@ -1092,12 +1092,9 @@ pub const Compilation = struct {
1092 defer exported_symbol_names.release();1092 defer exported_symbol_names.release();
10931093
1094 if (try exported_symbol_names.value.put(decl.name, decl)) |other_decl| {1094 if (try exported_symbol_names.value.put(decl.name, decl)) |other_decl| {
1095 try self.addCompileError(1095 try self.addCompileError(decl.tree_scope, decl.getSpan(), "exported symbol collision: '{}'", .{
1096 decl.tree_scope,
1097 decl.getSpan(),
1098 "exported symbol collision: '{}'",
1099 decl.name,1096 decl.name,
1100 );1097 });
1101 // TODO add error note showing location of other symbol1098 // TODO add error note showing location of other symbol
1102 }1099 }
1103 }1100 }
...@@ -1162,7 +1159,7 @@ pub const Compilation = struct {...@@ -1162,7 +1159,7 @@ pub const Compilation = struct {
1162 const tmp_dir = try self.getTmpDir();1159 const tmp_dir = try self.getTmpDir();
1163 const file_prefix = self.getRandomFileName();1160 const file_prefix = self.getRandomFileName();
11641161
1165 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix);1162 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", .{ file_prefix[0..], suffix });
1166 defer self.gpa().free(file_name);1163 defer self.gpa().free(file_name);
11671164
1168 const full_path = try std.fs.path.join(self.gpa(), &[_][]const u8{ tmp_dir, file_name[0..] });1165 const full_path = try std.fs.path.join(self.gpa(), &[_][]const u8{ tmp_dir, file_name[0..] });
...@@ -1303,7 +1300,7 @@ fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void {...@@ -1303,7 +1300,7 @@ fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void {
1303 try comp.addCompileError(tree_scope, Span{1300 try comp.addCompileError(tree_scope, Span{
1304 .first = param_decl.firstToken(),1301 .first = param_decl.firstToken(),
1305 .last = param_decl.type_node.firstToken(),1302 .last = param_decl.type_node.firstToken(),
1306 }, "missing parameter name");1303 }, "missing parameter name", .{});
1307 return error.SemanticAnalysisFailed;1304 return error.SemanticAnalysisFailed;
1308 };1305 };
1309 const param_name = tree_scope.tree.tokenSlice(name_token);1306 const param_name = tree_scope.tree.tokenSlice(name_token);
src-self-hosted/dep_tokenizer.zig+15-15
...@@ -38,7 +38,7 @@ pub const Tokenizer = struct {...@@ -38,7 +38,7 @@ pub const Tokenizer = struct {
38 },38 },
39 .target => |*target| switch (char) {39 .target => |*target| switch (char) {
40 '\t', '\n', '\r', ' ' => {40 '\t', '\n', '\r', ' ' => {
41 return self.errorIllegalChar(self.index, char, "invalid target");41 return self.errorIllegalChar(self.index, char, "invalid target", .{});
42 },42 },
43 '$' => {43 '$' => {
44 self.state = State{ .target_dollar_sign = target.* };44 self.state = State{ .target_dollar_sign = target.* };
...@@ -59,7 +59,7 @@ pub const Tokenizer = struct {...@@ -59,7 +59,7 @@ pub const Tokenizer = struct {
59 },59 },
60 .target_reverse_solidus => |*target| switch (char) {60 .target_reverse_solidus => |*target| switch (char) {
61 '\t', '\n', '\r' => {61 '\t', '\n', '\r' => {
62 return self.errorIllegalChar(self.index, char, "bad target escape");62 return self.errorIllegalChar(self.index, char, "bad target escape", .{});
63 },63 },
64 ' ', '#', '\\' => {64 ' ', '#', '\\' => {
65 try target.appendByte(char);65 try target.appendByte(char);
...@@ -84,7 +84,7 @@ pub const Tokenizer = struct {...@@ -84,7 +84,7 @@ pub const Tokenizer = struct {
84 break; // advance84 break; // advance
85 },85 },
86 else => {86 else => {
87 return self.errorIllegalChar(self.index, char, "expecting '$'");87 return self.errorIllegalChar(self.index, char, "expecting '$'", .{});
88 },88 },
89 },89 },
90 .target_colon => |*target| switch (char) {90 .target_colon => |*target| switch (char) {
...@@ -161,7 +161,7 @@ pub const Tokenizer = struct {...@@ -161,7 +161,7 @@ pub const Tokenizer = struct {
161 break; // advance161 break; // advance
162 },162 },
163 else => {163 else => {
164 return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line");164 return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line", .{});
165 },165 },
166 },166 },
167 .rhs_continuation_linefeed => switch (char) {167 .rhs_continuation_linefeed => switch (char) {
...@@ -170,7 +170,7 @@ pub const Tokenizer = struct {...@@ -170,7 +170,7 @@ pub const Tokenizer = struct {
170 break; // advance170 break; // advance
171 },171 },
172 else => {172 else => {
173 return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line");173 return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line", .{});
174 },174 },
175 },175 },
176 .prereq_quote => |*prereq| switch (char) {176 .prereq_quote => |*prereq| switch (char) {
...@@ -231,7 +231,7 @@ pub const Tokenizer = struct {...@@ -231,7 +231,7 @@ pub const Tokenizer = struct {
231 return Token{ .id = .prereq, .bytes = bytes };231 return Token{ .id = .prereq, .bytes = bytes };
232 },232 },
233 else => {233 else => {
234 return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line");234 return self.errorIllegalChar(self.index, char, "continuation expecting end-of-line", .{});
235 },235 },
236 },236 },
237 }237 }
...@@ -249,13 +249,13 @@ pub const Tokenizer = struct {...@@ -249,13 +249,13 @@ pub const Tokenizer = struct {
249 .rhs_continuation_linefeed,249 .rhs_continuation_linefeed,
250 => {},250 => {},
251 .target => |target| {251 .target => |target| {
252 return self.errorPosition(idx, target.toSlice(), "incomplete target");252 return self.errorPosition(idx, target.toSlice(), "incomplete target", .{});
253 },253 },
254 .target_reverse_solidus,254 .target_reverse_solidus,
255 .target_dollar_sign,255 .target_dollar_sign,
256 => {256 => {
257 const index = self.index - 1;257 const index = self.index - 1;
258 return self.errorIllegalChar(idx, self.bytes[idx], "incomplete escape");258 return self.errorIllegalChar(idx, self.bytes[idx], "incomplete escape", .{});
259 },259 },
260 .target_colon => |target| {260 .target_colon => |target| {
261 const bytes = target.toSlice();261 const bytes = target.toSlice();
...@@ -278,7 +278,7 @@ pub const Tokenizer = struct {...@@ -278,7 +278,7 @@ pub const Tokenizer = struct {
278 self.state = State{ .lhs = {} };278 self.state = State{ .lhs = {} };
279 },279 },
280 .prereq_quote => |prereq| {280 .prereq_quote => |prereq| {
281 return self.errorPosition(idx, prereq.toSlice(), "incomplete quoted prerequisite");281 return self.errorPosition(idx, prereq.toSlice(), "incomplete quoted prerequisite", .{});
282 },282 },
283 .prereq => |prereq| {283 .prereq => |prereq| {
284 const bytes = prereq.toSlice();284 const bytes = prereq.toSlice();
...@@ -299,29 +299,29 @@ pub const Tokenizer = struct {...@@ -299,29 +299,29 @@ pub const Tokenizer = struct {
299 return null;299 return null;
300 }300 }
301301
302 fn errorf(self: *Tokenizer, comptime fmt: []const u8, args: ...) Error {302 fn errorf(self: *Tokenizer, comptime fmt: []const u8, args: var) Error {
303 self.error_text = (try std.Buffer.allocPrint(&self.arena.allocator, fmt, args)).toSlice();303 self.error_text = (try std.Buffer.allocPrint(&self.arena.allocator, fmt, args)).toSlice();
304 return Error.InvalidInput;304 return Error.InvalidInput;
305 }305 }
306306
307 fn errorPosition(self: *Tokenizer, position: usize, bytes: []const u8, comptime fmt: []const u8, args: ...) Error {307 fn errorPosition(self: *Tokenizer, position: usize, bytes: []const u8, comptime fmt: []const u8, args: var) Error {
308 var buffer = try std.Buffer.initSize(&self.arena.allocator, 0);308 var buffer = try std.Buffer.initSize(&self.arena.allocator, 0);
309 std.fmt.format(&buffer, anyerror, std.Buffer.append, fmt, args) catch {};309 std.fmt.format(&buffer, anyerror, std.Buffer.append, fmt, args) catch {};
310 try buffer.append(" '");310 try buffer.append(" '");
311 var out = makeOutput(std.Buffer.append, &buffer);311 var out = makeOutput(std.Buffer.append, &buffer);
312 try printCharValues(&out, bytes);312 try printCharValues(&out, bytes);
313 try buffer.append("'");313 try buffer.append("'");
314 std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", position - (bytes.len - 1)) catch {};314 std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", .{position - (bytes.len - 1)}) catch {};
315 self.error_text = buffer.toSlice();315 self.error_text = buffer.toSlice();
316 return Error.InvalidInput;316 return Error.InvalidInput;
317 }317 }
318318
319 fn errorIllegalChar(self: *Tokenizer, position: usize, char: u8, comptime fmt: []const u8, args: ...) Error {319 fn errorIllegalChar(self: *Tokenizer, position: usize, char: u8, comptime fmt: []const u8, args: var) Error {
320 var buffer = try std.Buffer.initSize(&self.arena.allocator, 0);320 var buffer = try std.Buffer.initSize(&self.arena.allocator, 0);
321 try buffer.append("illegal char ");321 try buffer.append("illegal char ");
322 var out = makeOutput(std.Buffer.append, &buffer);322 var out = makeOutput(std.Buffer.append, &buffer);
323 try printUnderstandableChar(&out, char);323 try printUnderstandableChar(&out, char);
324 std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", position) catch {};324 std.fmt.format(&buffer, anyerror, std.Buffer.append, " at position {}", .{position}) catch {};
325 if (fmt.len != 0) std.fmt.format(&buffer, anyerror, std.Buffer.append, ": " ++ fmt, args) catch {};325 if (fmt.len != 0) std.fmt.format(&buffer, anyerror, std.Buffer.append, ": " ++ fmt, args) catch {};
326 self.error_text = buffer.toSlice();326 self.error_text = buffer.toSlice();
327 return Error.InvalidInput;327 return Error.InvalidInput;
...@@ -998,7 +998,7 @@ fn printCharValues(out: var, bytes: []const u8) !void {...@@ -998,7 +998,7 @@ fn printCharValues(out: var, bytes: []const u8) !void {
998998
999fn printUnderstandableChar(out: var, char: u8) !void {999fn printUnderstandableChar(out: var, char: u8) !void {
1000 if (!std.ascii.isPrint(char) or char == ' ') {1000 if (!std.ascii.isPrint(char) or char == ' ') {
1001 std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", char) catch {};1001 std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", .{char}) catch {};
1002 } else {1002 } else {
1003 try out.write("'");1003 try out.write("'");
1004 try out.write(&[_]u8{printable_char_tab[char]});1004 try out.write(&[_]u8{printable_char_tab[char]});
src-self-hosted/errmsg.zig+5-7
...@@ -231,7 +231,7 @@ pub const Msg = struct {...@@ -231,7 +231,7 @@ pub const Msg = struct {
231 pub fn printToStream(msg: *const Msg, stream: var, color_on: bool) !void {231 pub fn printToStream(msg: *const Msg, stream: var, color_on: bool) !void {
232 switch (msg.data) {232 switch (msg.data) {
233 .Cli => {233 .Cli => {
234 try stream.print("{}:-:-: error: {}\n", msg.realpath, msg.text);234 try stream.print("{}:-:-: error: {}\n", .{ msg.realpath, msg.text });
235 return;235 return;
236 },236 },
237 else => {},237 else => {},
...@@ -254,24 +254,22 @@ pub const Msg = struct {...@@ -254,24 +254,22 @@ pub const Msg = struct {
254 const start_loc = tree.tokenLocationPtr(0, first_token);254 const start_loc = tree.tokenLocationPtr(0, first_token);
255 const end_loc = tree.tokenLocationPtr(first_token.end, last_token);255 const end_loc = tree.tokenLocationPtr(first_token.end, last_token);
256 if (!color_on) {256 if (!color_on) {
257 try stream.print(257 try stream.print("{}:{}:{}: error: {}\n", .{
258 "{}:{}:{}: error: {}\n",
259 path,258 path,
260 start_loc.line + 1,259 start_loc.line + 1,
261 start_loc.column + 1,260 start_loc.column + 1,
262 msg.text,261 msg.text,
263 );262 });
264 return;263 return;
265 }264 }
266265
267 try stream.print(266 try stream.print("{}:{}:{}: error: {}\n{}\n", .{
268 "{}:{}:{}: error: {}\n{}\n",
269 path,267 path,
270 start_loc.line + 1,268 start_loc.line + 1,
271 start_loc.column + 1,269 start_loc.column + 1,
272 msg.text,270 msg.text,
273 tree.source[start_loc.line_start..start_loc.line_end],271 tree.source[start_loc.line_start..start_loc.line_end],
274 );272 });
275 try stream.writeByteNTimes(' ', start_loc.column);273 try stream.writeByteNTimes(' ', start_loc.column);
276 try stream.writeByteNTimes('~', last_token.end - first_token.start);274 try stream.writeByteNTimes('~', last_token.end - first_token.start);
277 try stream.write("\n");275 try stream.write("\n");
src-self-hosted/introspect.zig+1-1
...@@ -48,7 +48,7 @@ pub fn resolveZigLibDir(allocator: *mem.Allocator) ![]u8 {...@@ -48,7 +48,7 @@ pub fn resolveZigLibDir(allocator: *mem.Allocator) ![]u8 {
48 \\Unable to find zig lib directory: {}.48 \\Unable to find zig lib directory: {}.
49 \\Reinstall Zig or use --zig-install-prefix.49 \\Reinstall Zig or use --zig-install-prefix.
50 \\50 \\
51 , @errorName(err));51 , .{@errorName(err)});
5252
53 return error.ZigLibDirNotFound;53 return error.ZigLibDirNotFound;
54 };54 };
src-self-hosted/ir.zig+38-40
...@@ -32,16 +32,16 @@ pub const IrVal = union(enum) {...@@ -32,16 +32,16 @@ pub const IrVal = union(enum) {
3232
33 pub fn dump(self: IrVal) void {33 pub fn dump(self: IrVal) void {
34 switch (self) {34 switch (self) {
35 .Unknown => std.debug.warn("Unknown"),35 .Unknown => std.debug.warn("Unknown", .{}),
36 .KnownType => |typ| {36 .KnownType => |typ| {
37 std.debug.warn("KnownType(");37 std.debug.warn("KnownType(", .{});
38 typ.dump();38 typ.dump();
39 std.debug.warn(")");39 std.debug.warn(")", .{});
40 },40 },
41 .KnownValue => |value| {41 .KnownValue => |value| {
42 std.debug.warn("KnownValue(");42 std.debug.warn("KnownValue(", .{});
43 value.dump();43 value.dump();
44 std.debug.warn(")");44 std.debug.warn(")", .{});
45 },45 },
46 }46 }
47 }47 }
...@@ -90,9 +90,9 @@ pub const Inst = struct {...@@ -90,9 +90,9 @@ pub const Inst = struct {
90 inline while (i < @memberCount(Id)) : (i += 1) {90 inline while (i < @memberCount(Id)) : (i += 1) {
91 if (base.id == @field(Id, @memberName(Id, i))) {91 if (base.id == @field(Id, @memberName(Id, i))) {
92 const T = @field(Inst, @memberName(Id, i));92 const T = @field(Inst, @memberName(Id, i));
93 std.debug.warn("#{} = {}(", base.debug_id, @tagName(base.id));93 std.debug.warn("#{} = {}(", .{ base.debug_id, @tagName(base.id) });
94 @fieldParentPtr(T, "base", base).dump();94 @fieldParentPtr(T, "base", base).dump();
95 std.debug.warn(")");95 std.debug.warn(")", .{});
96 return;96 return;
97 }97 }
98 }98 }
...@@ -173,7 +173,7 @@ pub const Inst = struct {...@@ -173,7 +173,7 @@ pub const Inst = struct {
173 if (self.isCompTime()) {173 if (self.isCompTime()) {
174 return self.val.KnownValue;174 return self.val.KnownValue;
175 } else {175 } else {
176 try ira.addCompileError(self.span, "unable to evaluate constant expression");176 try ira.addCompileError(self.span, "unable to evaluate constant expression", .{});
177 return error.SemanticAnalysisFailed;177 return error.SemanticAnalysisFailed;
178 }178 }
179 }179 }
...@@ -269,11 +269,11 @@ pub const Inst = struct {...@@ -269,11 +269,11 @@ pub const Inst = struct {
269 const ir_val_init = IrVal.Init.Unknown;269 const ir_val_init = IrVal.Init.Unknown;
270270
271 pub fn dump(self: *const Call) void {271 pub fn dump(self: *const Call) void {
272 std.debug.warn("#{}(", self.params.fn_ref.debug_id);272 std.debug.warn("#{}(", .{self.params.fn_ref.debug_id});
273 for (self.params.args) |arg| {273 for (self.params.args) |arg| {
274 std.debug.warn("#{},", arg.debug_id);274 std.debug.warn("#{},", .{arg.debug_id});
275 }275 }
276 std.debug.warn(")");276 std.debug.warn(")", .{});
277 }277 }
278278
279 pub fn hasSideEffects(self: *const Call) bool {279 pub fn hasSideEffects(self: *const Call) bool {
...@@ -284,19 +284,17 @@ pub const Inst = struct {...@@ -284,19 +284,17 @@ pub const Inst = struct {
284 const fn_ref = try self.params.fn_ref.getAsParam();284 const fn_ref = try self.params.fn_ref.getAsParam();
285 const fn_ref_type = fn_ref.getKnownType();285 const fn_ref_type = fn_ref.getKnownType();
286 const fn_type = fn_ref_type.cast(Type.Fn) orelse {286 const fn_type = fn_ref_type.cast(Type.Fn) orelse {
287 try ira.addCompileError(fn_ref.span, "type '{}' not a function", fn_ref_type.name);287 try ira.addCompileError(fn_ref.span, "type '{}' not a function", .{fn_ref_type.name});
288 return error.SemanticAnalysisFailed;288 return error.SemanticAnalysisFailed;
289 };289 };
290290
291 const fn_type_param_count = fn_type.paramCount();291 const fn_type_param_count = fn_type.paramCount();
292292
293 if (fn_type_param_count != self.params.args.len) {293 if (fn_type_param_count != self.params.args.len) {
294 try ira.addCompileError(294 try ira.addCompileError(self.base.span, "expected {} arguments, found {}", .{
295 self.base.span,
296 "expected {} arguments, found {}",
297 fn_type_param_count,295 fn_type_param_count,
298 self.params.args.len,296 self.params.args.len,
299 );297 });
300 return error.SemanticAnalysisFailed;298 return error.SemanticAnalysisFailed;
301 }299 }
302300
...@@ -375,7 +373,7 @@ pub const Inst = struct {...@@ -375,7 +373,7 @@ pub const Inst = struct {
375 const ir_val_init = IrVal.Init.NoReturn;373 const ir_val_init = IrVal.Init.NoReturn;
376374
377 pub fn dump(self: *const Return) void {375 pub fn dump(self: *const Return) void {
378 std.debug.warn("#{}", self.params.return_value.debug_id);376 std.debug.warn("#{}", .{self.params.return_value.debug_id});
379 }377 }
380378
381 pub fn hasSideEffects(self: *const Return) bool {379 pub fn hasSideEffects(self: *const Return) bool {
...@@ -509,7 +507,7 @@ pub const Inst = struct {...@@ -509,7 +507,7 @@ pub const Inst = struct {
509 const ir_val_init = IrVal.Init.Unknown;507 const ir_val_init = IrVal.Init.Unknown;
510508
511 pub fn dump(inst: *const VarPtr) void {509 pub fn dump(inst: *const VarPtr) void {
512 std.debug.warn("{}", inst.params.var_scope.name);510 std.debug.warn("{}", .{inst.params.var_scope.name});
513 }511 }
514512
515 pub fn hasSideEffects(inst: *const VarPtr) bool {513 pub fn hasSideEffects(inst: *const VarPtr) bool {
...@@ -567,7 +565,7 @@ pub const Inst = struct {...@@ -567,7 +565,7 @@ pub const Inst = struct {
567 const target = try self.params.target.getAsParam();565 const target = try self.params.target.getAsParam();
568 const target_type = target.getKnownType();566 const target_type = target.getKnownType();
569 if (target_type.id != .Pointer) {567 if (target_type.id != .Pointer) {
570 try ira.addCompileError(self.base.span, "dereference of non pointer type '{}'", target_type.name);568 try ira.addCompileError(self.base.span, "dereference of non pointer type '{}'", .{target_type.name});
571 return error.SemanticAnalysisFailed;569 return error.SemanticAnalysisFailed;
572 }570 }
573 const ptr_type = @fieldParentPtr(Type.Pointer, "base", target_type);571 const ptr_type = @fieldParentPtr(Type.Pointer, "base", target_type);
...@@ -705,7 +703,7 @@ pub const Inst = struct {...@@ -705,7 +703,7 @@ pub const Inst = struct {
705 const ir_val_init = IrVal.Init.Unknown;703 const ir_val_init = IrVal.Init.Unknown;
706704
707 pub fn dump(self: *const CheckVoidStmt) void {705 pub fn dump(self: *const CheckVoidStmt) void {
708 std.debug.warn("#{}", self.params.target.debug_id);706 std.debug.warn("#{}", .{self.params.target.debug_id});
709 }707 }
710708
711 pub fn hasSideEffects(inst: *const CheckVoidStmt) bool {709 pub fn hasSideEffects(inst: *const CheckVoidStmt) bool {
...@@ -715,7 +713,7 @@ pub const Inst = struct {...@@ -715,7 +713,7 @@ pub const Inst = struct {
715 pub fn analyze(self: *const CheckVoidStmt, ira: *Analyze) !*Inst {713 pub fn analyze(self: *const CheckVoidStmt, ira: *Analyze) !*Inst {
716 const target = try self.params.target.getAsParam();714 const target = try self.params.target.getAsParam();
717 if (target.getKnownType().id != .Void) {715 if (target.getKnownType().id != .Void) {
718 try ira.addCompileError(self.base.span, "expression value is ignored");716 try ira.addCompileError(self.base.span, "expression value is ignored", .{});
719 return error.SemanticAnalysisFailed;717 return error.SemanticAnalysisFailed;
720 }718 }
721 return ira.irb.buildConstVoid(self.base.scope, self.base.span, true);719 return ira.irb.buildConstVoid(self.base.scope, self.base.span, true);
...@@ -801,7 +799,7 @@ pub const Inst = struct {...@@ -801,7 +799,7 @@ pub const Inst = struct {
801 const ir_val_init = IrVal.Init.Unknown;799 const ir_val_init = IrVal.Init.Unknown;
802800
803 pub fn dump(inst: *const AddImplicitReturnType) void {801 pub fn dump(inst: *const AddImplicitReturnType) void {
804 std.debug.warn("#{}", inst.params.target.debug_id);802 std.debug.warn("#{}", .{inst.params.target.debug_id});
805 }803 }
806804
807 pub fn hasSideEffects(inst: *const AddImplicitReturnType) bool {805 pub fn hasSideEffects(inst: *const AddImplicitReturnType) bool {
...@@ -826,7 +824,7 @@ pub const Inst = struct {...@@ -826,7 +824,7 @@ pub const Inst = struct {
826 const ir_val_init = IrVal.Init.Unknown;824 const ir_val_init = IrVal.Init.Unknown;
827825
828 pub fn dump(inst: *const TestErr) void {826 pub fn dump(inst: *const TestErr) void {
829 std.debug.warn("#{}", inst.params.target.debug_id);827 std.debug.warn("#{}", .{inst.params.target.debug_id});
830 }828 }
831829
832 pub fn hasSideEffects(inst: *const TestErr) bool {830 pub fn hasSideEffects(inst: *const TestErr) bool {
...@@ -888,7 +886,7 @@ pub const Inst = struct {...@@ -888,7 +886,7 @@ pub const Inst = struct {
888 const ir_val_init = IrVal.Init.Unknown;886 const ir_val_init = IrVal.Init.Unknown;
889887
890 pub fn dump(inst: *const TestCompTime) void {888 pub fn dump(inst: *const TestCompTime) void {
891 std.debug.warn("#{}", inst.params.target.debug_id);889 std.debug.warn("#{}", .{inst.params.target.debug_id});
892 }890 }
893891
894 pub fn hasSideEffects(inst: *const TestCompTime) bool {892 pub fn hasSideEffects(inst: *const TestCompTime) bool {
...@@ -971,11 +969,11 @@ pub const Code = struct {...@@ -971,11 +969,11 @@ pub const Code = struct {
971 pub fn dump(self: *Code) void {969 pub fn dump(self: *Code) void {
972 var bb_i: usize = 0;970 var bb_i: usize = 0;
973 for (self.basic_block_list.toSliceConst()) |bb| {971 for (self.basic_block_list.toSliceConst()) |bb| {
974 std.debug.warn("{s}_{}:\n", bb.name_hint, bb.debug_id);972 std.debug.warn("{s}_{}:\n", .{ bb.name_hint, bb.debug_id });
975 for (bb.instruction_list.toSliceConst()) |instr| {973 for (bb.instruction_list.toSliceConst()) |instr| {
976 std.debug.warn(" ");974 std.debug.warn(" ", .{});
977 instr.dump();975 instr.dump();
978 std.debug.warn("\n");976 std.debug.warn("\n", .{});
979 }977 }
980 }978 }
981 }979 }
...@@ -993,6 +991,7 @@ pub const Code = struct {...@@ -993,6 +991,7 @@ pub const Code = struct {
993 self.tree_scope,991 self.tree_scope,
994 ret_value.span,992 ret_value.span,
995 "unable to evaluate constant expression",993 "unable to evaluate constant expression",
994 .{},
996 );995 );
997 return error.SemanticAnalysisFailed;996 return error.SemanticAnalysisFailed;
998 } else if (inst.hasSideEffects()) {997 } else if (inst.hasSideEffects()) {
...@@ -1000,6 +999,7 @@ pub const Code = struct {...@@ -1000,6 +999,7 @@ pub const Code = struct {
1000 self.tree_scope,999 self.tree_scope,
1001 inst.span,1000 inst.span,
1002 "unable to evaluate constant expression",1001 "unable to evaluate constant expression",
1002 .{},
1003 );1003 );
1004 return error.SemanticAnalysisFailed;1004 return error.SemanticAnalysisFailed;
1005 }1005 }
...@@ -1359,7 +1359,7 @@ pub const Builder = struct {...@@ -1359,7 +1359,7 @@ pub const Builder = struct {
1359 irb.code.tree_scope,1359 irb.code.tree_scope,
1360 src_span,1360 src_span,
1361 "invalid character in string literal: '{c}'",1361 "invalid character in string literal: '{c}'",
1362 str_token[bad_index],1362 .{str_token[bad_index]},
1363 );1363 );
1364 return error.SemanticAnalysisFailed;1364 return error.SemanticAnalysisFailed;
1365 },1365 },
...@@ -1523,6 +1523,7 @@ pub const Builder = struct {...@@ -1523,6 +1523,7 @@ pub const Builder = struct {
1523 irb.code.tree_scope,1523 irb.code.tree_scope,
1524 src_span,1524 src_span,
1525 "return expression outside function definition",1525 "return expression outside function definition",
1526 .{},
1526 );1527 );
1527 return error.SemanticAnalysisFailed;1528 return error.SemanticAnalysisFailed;
1528 }1529 }
...@@ -1533,6 +1534,7 @@ pub const Builder = struct {...@@ -1533,6 +1534,7 @@ pub const Builder = struct {
1533 irb.code.tree_scope,1534 irb.code.tree_scope,
1534 src_span,1535 src_span,
1535 "cannot return from defer expression",1536 "cannot return from defer expression",
1537 .{},
1536 );1538 );
1537 scope_defer_expr.reported_err = true;1539 scope_defer_expr.reported_err = true;
1538 }1540 }
...@@ -1629,7 +1631,7 @@ pub const Builder = struct {...@@ -1629,7 +1631,7 @@ pub const Builder = struct {
1629 }1631 }
1630 } else |err| switch (err) {1632 } else |err| switch (err) {
1631 error.Overflow => {1633 error.Overflow => {
1632 try irb.comp.addCompileError(irb.code.tree_scope, src_span, "integer too large");1634 try irb.comp.addCompileError(irb.code.tree_scope, src_span, "integer too large", .{});
1633 return error.SemanticAnalysisFailed;1635 return error.SemanticAnalysisFailed;
1634 },1636 },
1635 error.OutOfMemory => return error.OutOfMemory,1637 error.OutOfMemory => return error.OutOfMemory,
...@@ -1663,7 +1665,7 @@ pub const Builder = struct {...@@ -1663,7 +1665,7 @@ pub const Builder = struct {
1663 // TODO put a variable of same name with invalid type in global scope1665 // TODO put a variable of same name with invalid type in global scope
1664 // so that future references to this same name will find a variable with an invalid type1666 // so that future references to this same name will find a variable with an invalid type
16651667
1666 try irb.comp.addCompileError(irb.code.tree_scope, src_span, "unknown identifier '{}'", name);1668 try irb.comp.addCompileError(irb.code.tree_scope, src_span, "unknown identifier '{}'", .{name});
1667 return error.SemanticAnalysisFailed;1669 return error.SemanticAnalysisFailed;
1668 }1670 }
16691671
...@@ -2008,7 +2010,7 @@ const Analyze = struct {...@@ -2008,7 +2010,7 @@ const Analyze = struct {
2008 const next_instruction = ira.parent_basic_block.instruction_list.at(ira.instruction_index);2010 const next_instruction = ira.parent_basic_block.instruction_list.at(ira.instruction_index);
20092011
2010 if (!next_instruction.is_generated) {2012 if (!next_instruction.is_generated) {
2011 try ira.addCompileError(next_instruction.span, "unreachable code");2013 try ira.addCompileError(next_instruction.span, "unreachable code", .{});
2012 break;2014 break;
2013 }2015 }
2014 ira.instruction_index += 1;2016 ira.instruction_index += 1;
...@@ -2041,7 +2043,7 @@ const Analyze = struct {...@@ -2041,7 +2043,7 @@ const Analyze = struct {
2041 }2043 }
2042 }2044 }
20432045
2044 fn addCompileError(self: *Analyze, span: Span, comptime fmt: []const u8, args: ...) !void {2046 fn addCompileError(self: *Analyze, span: Span, comptime fmt: []const u8, args: var) !void {
2045 return self.irb.comp.addCompileError(self.irb.code.tree_scope, span, fmt, args);2047 return self.irb.comp.addCompileError(self.irb.code.tree_scope, span, fmt, args);
2046 }2048 }
20472049
...@@ -2330,12 +2332,10 @@ const Analyze = struct {...@@ -2330,12 +2332,10 @@ const Analyze = struct {
2330 break :cast;2332 break :cast;
2331 };2333 };
2332 if (!fits) {2334 if (!fits) {
2333 try ira.addCompileError(2335 try ira.addCompileError(source_instr.span, "integer value '{}' cannot be stored in type '{}'", .{
2334 source_instr.span,
2335 "integer value '{}' cannot be stored in type '{}'",
2336 from_int,2336 from_int,
2337 dest_type.name,2337 dest_type.name,
2338 );2338 });
2339 return error.SemanticAnalysisFailed;2339 return error.SemanticAnalysisFailed;
2340 }2340 }
23412341
...@@ -2498,12 +2498,10 @@ const Analyze = struct {...@@ -2498,12 +2498,10 @@ const Analyze = struct {
2498 // }2498 // }
2499 //}2499 //}
25002500
2501 try ira.addCompileError(2501 try ira.addCompileError(source_instr.span, "expected type '{}', found '{}'", .{
2502 source_instr.span,
2503 "expected type '{}', found '{}'",
2504 dest_type.name,2502 dest_type.name,
2505 from_type.name,2503 from_type.name,
2506 );2504 });
2507 //ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,2505 //ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,
2508 // buf_sprintf("expected type '%s', found '%s'",2506 // buf_sprintf("expected type '%s', found '%s'",
2509 // buf_ptr(&wanted_type->name),2507 // buf_ptr(&wanted_type->name),
src-self-hosted/libc_installation.zig+13-15
...@@ -65,7 +65,7 @@ pub const LibCInstallation = struct {...@@ -65,7 +65,7 @@ pub const LibCInstallation = struct {
65 if (line.len == 0 or line[0] == '#') continue;65 if (line.len == 0 or line[0] == '#') continue;
66 var line_it = std.mem.separate(line, "=");66 var line_it = std.mem.separate(line, "=");
67 const name = line_it.next() orelse {67 const name = line_it.next() orelse {
68 try stderr.print("missing equal sign after field name\n");68 try stderr.print("missing equal sign after field name\n", .{});
69 return error.ParseError;69 return error.ParseError;
70 };70 };
71 const value = line_it.rest();71 const value = line_it.rest();
...@@ -83,7 +83,7 @@ pub const LibCInstallation = struct {...@@ -83,7 +83,7 @@ pub const LibCInstallation = struct {
83 },83 },
84 else => {84 else => {
85 if (value.len == 0) {85 if (value.len == 0) {
86 try stderr.print("field cannot be empty: {}\n", key);86 try stderr.print("field cannot be empty: {}\n", .{key});
87 return error.ParseError;87 return error.ParseError;
88 }88 }
89 const dupe = try std.mem.dupe(allocator, u8, value);89 const dupe = try std.mem.dupe(allocator, u8, value);
...@@ -97,7 +97,7 @@ pub const LibCInstallation = struct {...@@ -97,7 +97,7 @@ pub const LibCInstallation = struct {
97 }97 }
98 for (found_keys) |found_key, i| {98 for (found_keys) |found_key, i| {
99 if (!found_key.found) {99 if (!found_key.found) {
100 try stderr.print("missing field: {}\n", keys[i]);100 try stderr.print("missing field: {}\n", .{keys[i]});
101 return error.ParseError;101 return error.ParseError;
102 }102 }
103 }103 }
...@@ -105,6 +105,11 @@ pub const LibCInstallation = struct {...@@ -105,6 +105,11 @@ pub const LibCInstallation = struct {
105105
106 pub fn render(self: *const LibCInstallation, out: *std.io.OutStream(fs.File.WriteError)) !void {106 pub fn render(self: *const LibCInstallation, out: *std.io.OutStream(fs.File.WriteError)) !void {
107 @setEvalBranchQuota(4000);107 @setEvalBranchQuota(4000);
108 const lib_dir = self.lib_dir orelse "";
109 const static_lib_dir = self.static_lib_dir orelse "";
110 const msvc_lib_dir = self.msvc_lib_dir orelse "";
111 const kernel32_lib_dir = self.kernel32_lib_dir orelse "";
112 const dynamic_linker_path = self.dynamic_linker_path orelse util.getDynamicLinkerPath(Target{ .Native = {} });
108 try out.print(113 try out.print(
109 \\# The directory that contains `stdlib.h`.114 \\# The directory that contains `stdlib.h`.
110 \\# On Linux, can be found with: `cc -E -Wp,-v -xc /dev/null`115 \\# On Linux, can be found with: `cc -E -Wp,-v -xc /dev/null`
...@@ -132,14 +137,7 @@ pub const LibCInstallation = struct {...@@ -132,14 +137,7 @@ pub const LibCInstallation = struct {
132 \\# Only needed when targeting Linux.137 \\# Only needed when targeting Linux.
133 \\dynamic_linker_path={}138 \\dynamic_linker_path={}
134 \\139 \\
135 ,140 , .{ self.include_dir, lib_dir, static_lib_dir, msvc_lib_dir, kernel32_lib_dir, dynamic_linker_path });
136 self.include_dir,
137 self.lib_dir orelse "",
138 self.static_lib_dir orelse "",
139 self.msvc_lib_dir orelse "",
140 self.kernel32_lib_dir orelse "",
141 self.dynamic_linker_path orelse util.getDynamicLinkerPath(Target{ .Native = {} }),
142 );
143 }141 }
144142
145 /// Finds the default, native libc.143 /// Finds the default, native libc.
...@@ -255,7 +253,7 @@ pub const LibCInstallation = struct {...@@ -255,7 +253,7 @@ pub const LibCInstallation = struct {
255 for (searches) |search| {253 for (searches) |search| {
256 result_buf.shrink(0);254 result_buf.shrink(0);
257 const stream = &std.io.BufferOutStream.init(&result_buf).stream;255 const stream = &std.io.BufferOutStream.init(&result_buf).stream;
258 try stream.print("{}\\Include\\{}\\ucrt", search.path, search.version);256 try stream.print("{}\\Include\\{}\\ucrt", .{ search.path, search.version });
259257
260 const stdlib_path = try fs.path.join(258 const stdlib_path = try fs.path.join(
261 allocator,259 allocator,
...@@ -282,7 +280,7 @@ pub const LibCInstallation = struct {...@@ -282,7 +280,7 @@ pub const LibCInstallation = struct {
282 for (searches) |search| {280 for (searches) |search| {
283 result_buf.shrink(0);281 result_buf.shrink(0);
284 const stream = &std.io.BufferOutStream.init(&result_buf).stream;282 const stream = &std.io.BufferOutStream.init(&result_buf).stream;
285 try stream.print("{}\\Lib\\{}\\ucrt\\", search.path, search.version);283 try stream.print("{}\\Lib\\{}\\ucrt\\", .{ search.path, search.version });
286 switch (builtin.arch) {284 switch (builtin.arch) {
287 .i386 => try stream.write("x86"),285 .i386 => try stream.write("x86"),
288 .x86_64 => try stream.write("x64"),286 .x86_64 => try stream.write("x64"),
...@@ -360,7 +358,7 @@ pub const LibCInstallation = struct {...@@ -360,7 +358,7 @@ pub const LibCInstallation = struct {
360 for (searches) |search| {358 for (searches) |search| {
361 result_buf.shrink(0);359 result_buf.shrink(0);
362 const stream = &std.io.BufferOutStream.init(&result_buf).stream;360 const stream = &std.io.BufferOutStream.init(&result_buf).stream;
363 try stream.print("{}\\Lib\\{}\\um\\", search.path, search.version);361 try stream.print("{}\\Lib\\{}\\um\\", .{ search.path, search.version });
364 switch (builtin.arch) {362 switch (builtin.arch) {
365 .i386 => try stream.write("x86\\"),363 .i386 => try stream.write("x86\\"),
366 .x86_64 => try stream.write("x64\\"),364 .x86_64 => try stream.write("x64\\"),
...@@ -395,7 +393,7 @@ pub const LibCInstallation = struct {...@@ -395,7 +393,7 @@ pub const LibCInstallation = struct {
395/// caller owns returned memory393/// caller owns returned memory
396fn ccPrintFileName(allocator: *Allocator, o_file: []const u8, want_dirname: bool) ![]u8 {394fn ccPrintFileName(allocator: *Allocator, o_file: []const u8, want_dirname: bool) ![]u8 {
397 const cc_exe = std.os.getenv("CC") orelse "cc";395 const cc_exe = std.os.getenv("CC") orelse "cc";
398 const arg1 = try std.fmt.allocPrint(allocator, "-print-file-name={}", o_file);396 const arg1 = try std.fmt.allocPrint(allocator, "-print-file-name={}", .{o_file});
399 defer allocator.free(arg1);397 defer allocator.free(arg1);
400 const argv = [_][]const u8{ cc_exe, arg1 };398 const argv = [_][]const u8{ cc_exe, arg1 };
401399
src-self-hosted/link.zig+20-13
...@@ -75,9 +75,9 @@ pub fn link(comp: *Compilation) !void {...@@ -75,9 +75,9 @@ pub fn link(comp: *Compilation) !void {
75 if (comp.verbose_link) {75 if (comp.verbose_link) {
76 for (ctx.args.toSliceConst()) |arg, i| {76 for (ctx.args.toSliceConst()) |arg, i| {
77 const space = if (i == 0) "" else " ";77 const space = if (i == 0) "" else " ";
78 std.debug.warn("{}{s}", space, arg);78 std.debug.warn("{}{s}", .{ space, arg });
79 }79 }
80 std.debug.warn("\n");80 std.debug.warn("\n", .{});
81 }81 }
8282
83 const extern_ofmt = toExternObjectFormatType(util.getObjectFormat(comp.target));83 const extern_ofmt = toExternObjectFormatType(util.getObjectFormat(comp.target));
...@@ -94,7 +94,7 @@ pub fn link(comp: *Compilation) !void {...@@ -94,7 +94,7 @@ pub fn link(comp: *Compilation) !void {
94 // TODO capture these messages and pass them through the system, reporting them through the94 // TODO capture these messages and pass them through the system, reporting them through the
95 // event system instead of printing them directly here.95 // event system instead of printing them directly here.
96 // perhaps try to parse and understand them.96 // perhaps try to parse and understand them.
97 std.debug.warn("{}\n", ctx.link_msg.toSliceConst());97 std.debug.warn("{}\n", .{ctx.link_msg.toSliceConst()});
98 }98 }
99 return error.LinkFailed;99 return error.LinkFailed;
100 }100 }
...@@ -334,13 +334,13 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {...@@ -334,13 +334,13 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
334334
335 const is_library = ctx.comp.kind == .Lib;335 const is_library = ctx.comp.kind == .Lib;
336336
337 const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", ctx.out_file_path.toSliceConst());337 const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", .{ctx.out_file_path.toSliceConst()});
338 try ctx.args.append(@ptrCast([*:0]const u8, out_arg.ptr));338 try ctx.args.append(@ptrCast([*:0]const u8, out_arg.ptr));
339339
340 if (ctx.comp.haveLibC()) {340 if (ctx.comp.haveLibC()) {
341 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.msvc_lib_dir.?)).ptr));341 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", .{ctx.libc.msvc_lib_dir.?})).ptr));
342 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.kernel32_lib_dir.?)).ptr));342 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", .{ctx.libc.kernel32_lib_dir.?})).ptr));
343 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", ctx.libc.lib_dir.?)).ptr));343 try ctx.args.append(@ptrCast([*:0]const u8, (try std.fmt.allocPrint(&ctx.arena.allocator, "-LIBPATH:{}\x00", .{ctx.libc.lib_dir.?})).ptr));
344 }344 }
345345
346 if (ctx.link_in_crt) {346 if (ctx.link_in_crt) {
...@@ -348,17 +348,20 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {...@@ -348,17 +348,20 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
348 const d_str = if (ctx.comp.build_mode == .Debug) "d" else "";348 const d_str = if (ctx.comp.build_mode == .Debug) "d" else "";
349349
350 if (ctx.comp.is_static) {350 if (ctx.comp.is_static) {
351 const cmt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "libcmt{}.lib\x00", d_str);351 const cmt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "libcmt{}.lib\x00", .{d_str});
352 try ctx.args.append(@ptrCast([*:0]const u8, cmt_lib_name.ptr));352 try ctx.args.append(@ptrCast([*:0]const u8, cmt_lib_name.ptr));
353 } else {353 } else {
354 const msvcrt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "msvcrt{}.lib\x00", d_str);354 const msvcrt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "msvcrt{}.lib\x00", .{d_str});
355 try ctx.args.append(@ptrCast([*:0]const u8, msvcrt_lib_name.ptr));355 try ctx.args.append(@ptrCast([*:0]const u8, msvcrt_lib_name.ptr));
356 }356 }
357357
358 const vcruntime_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}vcruntime{}.lib\x00", lib_str, d_str);358 const vcruntime_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}vcruntime{}.lib\x00", .{
359 lib_str,
360 d_str,
361 });
359 try ctx.args.append(@ptrCast([*:0]const u8, vcruntime_lib_name.ptr));362 try ctx.args.append(@ptrCast([*:0]const u8, vcruntime_lib_name.ptr));
360363
361 const crt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}ucrt{}.lib\x00", lib_str, d_str);364 const crt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "{}ucrt{}.lib\x00", .{ lib_str, d_str });
362 try ctx.args.append(@ptrCast([*:0]const u8, crt_lib_name.ptr));365 try ctx.args.append(@ptrCast([*:0]const u8, crt_lib_name.ptr));
363366
364 // Visual C++ 2015 Conformance Changes367 // Visual C++ 2015 Conformance Changes
...@@ -508,7 +511,11 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {...@@ -508,7 +511,11 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
508 .IPhoneOS => try ctx.args.append("-iphoneos_version_min"),511 .IPhoneOS => try ctx.args.append("-iphoneos_version_min"),
509 .IPhoneOSSimulator => try ctx.args.append("-ios_simulator_version_min"),512 .IPhoneOSSimulator => try ctx.args.append("-ios_simulator_version_min"),
510 }513 }
511 const ver_str = try std.fmt.allocPrint(&ctx.arena.allocator, "{}.{}.{}\x00", platform.major, platform.minor, platform.micro);514 const ver_str = try std.fmt.allocPrint(&ctx.arena.allocator, "{}.{}.{}\x00", .{
515 platform.major,
516 platform.minor,
517 platform.micro,
518 });
512 try ctx.args.append(@ptrCast([*:0]const u8, ver_str.ptr));519 try ctx.args.append(@ptrCast([*:0]const u8, ver_str.ptr));
513520
514 if (ctx.comp.kind == .Exe) {521 if (ctx.comp.kind == .Exe) {
...@@ -584,7 +591,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {...@@ -584,7 +591,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
584 try ctx.args.append("-lSystem");591 try ctx.args.append("-lSystem");
585 } else {592 } else {
586 if (mem.indexOfScalar(u8, lib.name, '/') == null) {593 if (mem.indexOfScalar(u8, lib.name, '/') == null) {
587 const arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-l{}\x00", lib.name);594 const arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-l{}\x00", .{lib.name});
588 try ctx.args.append(@ptrCast([*:0]const u8, arg.ptr));595 try ctx.args.append(@ptrCast([*:0]const u8, arg.ptr));
589 } else {596 } else {
590 const arg = try std.cstr.addNullByte(&ctx.arena.allocator, lib.name);597 const arg = try std.cstr.addNullByte(&ctx.arena.allocator, lib.name);
src-self-hosted/main.zig+24-25
...@@ -128,7 +128,7 @@ pub fn main() !void {...@@ -128,7 +128,7 @@ pub fn main() !void {
128 }128 }
129 }129 }
130130
131 try stderr.print("unknown command: {}\n\n", args[1]);131 try stderr.print("unknown command: {}\n\n", .{args[1]});
132 try stderr.write(usage);132 try stderr.write(usage);
133 process.argsFree(allocator, args);133 process.argsFree(allocator, args);
134 process.exit(1);134 process.exit(1);
...@@ -329,14 +329,14 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co...@@ -329,14 +329,14 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
329 if (cur_pkg.parent) |parent| {329 if (cur_pkg.parent) |parent| {
330 cur_pkg = parent;330 cur_pkg = parent;
331 } else {331 } else {
332 try stderr.print("encountered --pkg-end with no matching --pkg-begin\n");332 try stderr.print("encountered --pkg-end with no matching --pkg-begin\n", .{});
333 process.exit(1);333 process.exit(1);
334 }334 }
335 }335 }
336 }336 }
337337
338 if (cur_pkg.parent != null) {338 if (cur_pkg.parent != null) {
339 try stderr.print("unmatched --pkg-begin\n");339 try stderr.print("unmatched --pkg-begin\n", .{});
340 process.exit(1);340 process.exit(1);
341 }341 }
342342
...@@ -345,7 +345,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co...@@ -345,7 +345,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
345 0 => null,345 0 => null,
346 1 => flags.positionals.at(0),346 1 => flags.positionals.at(0),
347 else => {347 else => {
348 try stderr.print("unexpected extra parameter: {}\n", flags.positionals.at(1));348 try stderr.print("unexpected extra parameter: {}\n", .{flags.positionals.at(1)});
349 process.exit(1);349 process.exit(1);
350 },350 },
351 };351 };
...@@ -477,13 +477,13 @@ fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void {...@@ -477,13 +477,13 @@ fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void {
477477
478 switch (build_event) {478 switch (build_event) {
479 .Ok => {479 .Ok => {
480 stderr.print("Build {} succeeded\n", count) catch process.exit(1);480 stderr.print("Build {} succeeded\n", .{count}) catch process.exit(1);
481 },481 },
482 .Error => |err| {482 .Error => |err| {
483 stderr.print("Build {} failed: {}\n", count, @errorName(err)) catch process.exit(1);483 stderr.print("Build {} failed: {}\n", .{ count, @errorName(err) }) catch process.exit(1);
484 },484 },
485 .Fail => |msgs| {485 .Fail => |msgs| {
486 stderr.print("Build {} compile errors:\n", count) catch process.exit(1);486 stderr.print("Build {} compile errors:\n", .{count}) catch process.exit(1);
487 for (msgs) |msg| {487 for (msgs) |msg| {
488 defer msg.destroy();488 defer msg.destroy();
489 msg.printToFile(stderr_file, color) catch process.exit(1);489 msg.printToFile(stderr_file, color) catch process.exit(1);
...@@ -544,12 +544,11 @@ const Fmt = struct {...@@ -544,12 +544,11 @@ const Fmt = struct {
544544
545fn parseLibcPaths(allocator: *Allocator, libc: *LibCInstallation, libc_paths_file: []const u8) void {545fn parseLibcPaths(allocator: *Allocator, libc: *LibCInstallation, libc_paths_file: []const u8) void {
546 libc.parse(allocator, libc_paths_file, stderr) catch |err| {546 libc.parse(allocator, libc_paths_file, stderr) catch |err| {
547 stderr.print(547 stderr.print("Unable to parse libc path file '{}': {}.\n" ++
548 "Unable to parse libc path file '{}': {}.\n" ++548 "Try running `zig libc` to see an example for the native target.\n", .{
549 "Try running `zig libc` to see an example for the native target.\n",
550 libc_paths_file,549 libc_paths_file,
551 @errorName(err),550 @errorName(err),
552 ) catch {};551 }) catch {};
553 process.exit(1);552 process.exit(1);
554 };553 };
555}554}
...@@ -563,7 +562,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {...@@ -563,7 +562,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
563 return;562 return;
564 },563 },
565 else => {564 else => {
566 try stderr.print("unexpected extra parameter: {}\n", args[1]);565 try stderr.print("unexpected extra parameter: {}\n", .{args[1]});
567 process.exit(1);566 process.exit(1);
568 },567 },
569 }568 }
...@@ -572,7 +571,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {...@@ -572,7 +571,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
572 defer zig_compiler.deinit();571 defer zig_compiler.deinit();
573572
574 const libc = zig_compiler.getNativeLibC() catch |err| {573 const libc = zig_compiler.getNativeLibC() catch |err| {
575 stderr.print("unable to find libc: {}\n", @errorName(err)) catch {};574 stderr.print("unable to find libc: {}\n", .{@errorName(err)}) catch {};
576 process.exit(1);575 process.exit(1);
577 };576 };
578 libc.render(stdout) catch process.exit(1);577 libc.render(stdout) catch process.exit(1);
...@@ -614,7 +613,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {...@@ -614,7 +613,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
614 defer allocator.free(source_code);613 defer allocator.free(source_code);
615614
616 const tree = std.zig.parse(allocator, source_code) catch |err| {615 const tree = std.zig.parse(allocator, source_code) catch |err| {
617 try stderr.print("error parsing stdin: {}\n", err);616 try stderr.print("error parsing stdin: {}\n", .{err});
618 process.exit(1);617 process.exit(1);
619 };618 };
620 defer tree.deinit();619 defer tree.deinit();
...@@ -718,7 +717,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro...@@ -718,7 +717,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
718 },717 },
719 else => {718 else => {
720 // TODO lock stderr printing719 // TODO lock stderr printing
721 try stderr.print("unable to open '{}': {}\n", file_path, err);720 try stderr.print("unable to open '{}': {}\n", .{ file_path, err });
722 fmt.any_error = true;721 fmt.any_error = true;
723 return;722 return;
724 },723 },
...@@ -726,7 +725,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro...@@ -726,7 +725,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
726 defer fmt.allocator.free(source_code);725 defer fmt.allocator.free(source_code);
727726
728 const tree = std.zig.parse(fmt.allocator, source_code) catch |err| {727 const tree = std.zig.parse(fmt.allocator, source_code) catch |err| {
729 try stderr.print("error parsing file '{}': {}\n", file_path, err);728 try stderr.print("error parsing file '{}': {}\n", .{ file_path, err });
730 fmt.any_error = true;729 fmt.any_error = true;
731 return;730 return;
732 };731 };
...@@ -747,7 +746,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro...@@ -747,7 +746,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
747 if (check_mode) {746 if (check_mode) {
748 const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, tree);747 const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, tree);
749 if (anything_changed) {748 if (anything_changed) {
750 try stderr.print("{}\n", file_path);749 try stderr.print("{}\n", .{file_path});
751 fmt.any_error = true;750 fmt.any_error = true;
752 }751 }
753 } else {752 } else {
...@@ -757,7 +756,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro...@@ -757,7 +756,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
757756
758 const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree);757 const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree);
759 if (anything_changed) {758 if (anything_changed) {
760 try stderr.print("{}\n", file_path);759 try stderr.print("{}\n", .{file_path});
761 try baf.finish();760 try baf.finish();
762 }761 }
763 }762 }
...@@ -774,7 +773,7 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {...@@ -774,7 +773,7 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
774 // NOTE: Cannot use empty string, see #918.773 // NOTE: Cannot use empty string, see #918.
775 comptime const native_str = if (comptime mem.eql(u8, arch_tag, @tagName(builtin.arch))) " (native)\n" else "\n";774 comptime const native_str = if (comptime mem.eql(u8, arch_tag, @tagName(builtin.arch))) " (native)\n" else "\n";
776775
777 try stdout.print(" {}{}", arch_tag, native_str);776 try stdout.print(" {}{}", .{ arch_tag, native_str });
778 }777 }
779 }778 }
780 try stdout.write("\n");779 try stdout.write("\n");
...@@ -787,7 +786,7 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {...@@ -787,7 +786,7 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
787 // NOTE: Cannot use empty string, see #918.786 // NOTE: Cannot use empty string, see #918.
788 comptime const native_str = if (comptime mem.eql(u8, os_tag, @tagName(builtin.os))) " (native)\n" else "\n";787 comptime const native_str = if (comptime mem.eql(u8, os_tag, @tagName(builtin.os))) " (native)\n" else "\n";
789788
790 try stdout.print(" {}{}", os_tag, native_str);789 try stdout.print(" {}{}", .{ os_tag, native_str });
791 }790 }
792 }791 }
793 try stdout.write("\n");792 try stdout.write("\n");
...@@ -800,13 +799,13 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {...@@ -800,13 +799,13 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
800 // NOTE: Cannot use empty string, see #918.799 // NOTE: Cannot use empty string, see #918.
801 comptime const native_str = if (comptime mem.eql(u8, abi_tag, @tagName(builtin.abi))) " (native)\n" else "\n";800 comptime const native_str = if (comptime mem.eql(u8, abi_tag, @tagName(builtin.abi))) " (native)\n" else "\n";
802801
803 try stdout.print(" {}{}", abi_tag, native_str);802 try stdout.print(" {}{}", .{ abi_tag, native_str });
804 }803 }
805 }804 }
806}805}
807806
808fn cmdVersion(allocator: *Allocator, args: []const []const u8) !void {807fn cmdVersion(allocator: *Allocator, args: []const []const u8) !void {
809 try stdout.print("{}\n", std.mem.toSliceConst(u8, c.ZIG_VERSION_STRING));808 try stdout.print("{}\n", .{std.mem.toSliceConst(u8, c.ZIG_VERSION_STRING)});
810}809}
811810
812const args_test_spec = [_]Flag{Flag.Bool("--help")};811const args_test_spec = [_]Flag{Flag.Bool("--help")};
...@@ -865,7 +864,7 @@ fn cmdInternal(allocator: *Allocator, args: []const []const u8) !void {...@@ -865,7 +864,7 @@ fn cmdInternal(allocator: *Allocator, args: []const []const u8) !void {
865 }864 }
866 }865 }
867866
868 try stderr.print("unknown sub command: {}\n\n", args[0]);867 try stderr.print("unknown sub command: {}\n\n", .{args[0]});
869 try stderr.write(usage_internal);868 try stderr.write(usage_internal);
870}869}
871870
...@@ -878,14 +877,14 @@ fn cmdInternalBuildInfo(allocator: *Allocator, args: []const []const u8) !void {...@@ -878,14 +877,14 @@ fn cmdInternalBuildInfo(allocator: *Allocator, args: []const []const u8) !void {
878 \\ZIG_LLVM_CONFIG_EXE {}877 \\ZIG_LLVM_CONFIG_EXE {}
879 \\ZIG_DIA_GUIDS_LIB {}878 \\ZIG_DIA_GUIDS_LIB {}
880 \\879 \\
881 ,880 , .{
882 std.mem.toSliceConst(u8, c.ZIG_CMAKE_BINARY_DIR),881 std.mem.toSliceConst(u8, c.ZIG_CMAKE_BINARY_DIR),
883 std.mem.toSliceConst(u8, c.ZIG_CXX_COMPILER),882 std.mem.toSliceConst(u8, c.ZIG_CXX_COMPILER),
884 std.mem.toSliceConst(u8, c.ZIG_LLD_INCLUDE_PATH),883 std.mem.toSliceConst(u8, c.ZIG_LLD_INCLUDE_PATH),
885 std.mem.toSliceConst(u8, c.ZIG_LLD_LIBRARIES),884 std.mem.toSliceConst(u8, c.ZIG_LLD_LIBRARIES),
886 std.mem.toSliceConst(u8, c.ZIG_LLVM_CONFIG_EXE),885 std.mem.toSliceConst(u8, c.ZIG_LLVM_CONFIG_EXE),
887 std.mem.toSliceConst(u8, c.ZIG_DIA_GUIDS_LIB),886 std.mem.toSliceConst(u8, c.ZIG_DIA_GUIDS_LIB),
888 );887 });
889}888}
890889
891const CliPkg = struct {890const CliPkg = struct {
src-self-hosted/stage1.zig+7-7
...@@ -149,7 +149,7 @@ export fn stage2_fmt(argc: c_int, argv: [*]const [*:0]const u8) c_int {...@@ -149,7 +149,7 @@ export fn stage2_fmt(argc: c_int, argv: [*]const [*:0]const u8) c_int {
149 fmtMain(argc, argv) catch unreachable;149 fmtMain(argc, argv) catch unreachable;
150 } else {150 } else {
151 fmtMain(argc, argv) catch |e| {151 fmtMain(argc, argv) catch |e| {
152 std.debug.warn("{}\n", @errorName(e));152 std.debug.warn("{}\n", .{@errorName(e)});
153 return -1;153 return -1;
154 };154 };
155 }155 }
...@@ -205,7 +205,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {...@@ -205,7 +205,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
205 defer allocator.free(source_code);205 defer allocator.free(source_code);
206206
207 const tree = std.zig.parse(allocator, source_code) catch |err| {207 const tree = std.zig.parse(allocator, source_code) catch |err| {
208 try stderr.print("error parsing stdin: {}\n", err);208 try stderr.print("error parsing stdin: {}\n", .{err});
209 process.exit(1);209 process.exit(1);
210 };210 };
211 defer tree.deinit();211 defer tree.deinit();
...@@ -294,7 +294,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void...@@ -294,7 +294,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
294 },294 },
295 else => {295 else => {
296 // TODO lock stderr printing296 // TODO lock stderr printing
297 try stderr.print("unable to open '{}': {}\n", file_path, err);297 try stderr.print("unable to open '{}': {}\n", .{ file_path, err });
298 fmt.any_error = true;298 fmt.any_error = true;
299 return;299 return;
300 },300 },
...@@ -302,7 +302,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void...@@ -302,7 +302,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
302 defer fmt.allocator.free(source_code);302 defer fmt.allocator.free(source_code);
303303
304 const tree = std.zig.parse(fmt.allocator, source_code) catch |err| {304 const tree = std.zig.parse(fmt.allocator, source_code) catch |err| {
305 try stderr.print("error parsing file '{}': {}\n", file_path, err);305 try stderr.print("error parsing file '{}': {}\n", .{ file_path, err });
306 fmt.any_error = true;306 fmt.any_error = true;
307 return;307 return;
308 };308 };
...@@ -320,7 +320,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void...@@ -320,7 +320,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
320 if (check_mode) {320 if (check_mode) {
321 const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, tree);321 const anything_changed = try std.zig.render(fmt.allocator, io.null_out_stream, tree);
322 if (anything_changed) {322 if (anything_changed) {
323 try stderr.print("{}\n", file_path);323 try stderr.print("{}\n", .{file_path});
324 fmt.any_error = true;324 fmt.any_error = true;
325 }325 }
326 } else {326 } else {
...@@ -329,7 +329,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void...@@ -329,7 +329,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
329329
330 const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree);330 const anything_changed = try std.zig.render(fmt.allocator, baf.stream(), tree);
331 if (anything_changed) {331 if (anything_changed) {
332 try stderr.print("{}\n", file_path);332 try stderr.print("{}\n", .{file_path});
333 try baf.finish();333 try baf.finish();
334 }334 }
335 }335 }
...@@ -374,7 +374,7 @@ fn printErrMsgToFile(...@@ -374,7 +374,7 @@ fn printErrMsgToFile(
374 const text = text_buf.toOwnedSlice();374 const text = text_buf.toOwnedSlice();
375375
376 const stream = &file.outStream().stream;376 const stream = &file.outStream().stream;
377 try stream.print("{}:{}:{}: error: {}\n", path, start_loc.line + 1, start_loc.column + 1, text);377 try stream.print("{}:{}:{}: error: {}\n", .{ path, start_loc.line + 1, start_loc.column + 1, text });
378378
379 if (!color_on) return;379 if (!color_on) return;
380380
src-self-hosted/translate_c.zig+49-30
...@@ -125,7 +125,7 @@ const Context = struct {...@@ -125,7 +125,7 @@ const Context = struct {
125125
126 const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc);126 const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc);
127 const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc);127 const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc);
128 return std.fmt.allocPrint(c.a(), "{}:{}:{}", filename, line, column);128 return std.fmt.allocPrint(c.a(), "{}:{}:{}", .{ filename, line, column });
129 }129 }
130};130};
131131
...@@ -228,20 +228,20 @@ fn declVisitor(c: *Context, decl: *const ZigClangDecl) Error!void {...@@ -228,20 +228,20 @@ fn declVisitor(c: *Context, decl: *const ZigClangDecl) Error!void {
228 return visitFnDecl(c, @ptrCast(*const ZigClangFunctionDecl, decl));228 return visitFnDecl(c, @ptrCast(*const ZigClangFunctionDecl, decl));
229 },229 },
230 .Typedef => {230 .Typedef => {
231 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for typedefs");231 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for typedefs", .{});
232 },232 },
233 .Enum => {233 .Enum => {
234 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for enums");234 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for enums", .{});
235 },235 },
236 .Record => {236 .Record => {
237 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for structs");237 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for structs", .{});
238 },238 },
239 .Var => {239 .Var => {
240 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for variables");240 try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for variables", .{});
241 },241 },
242 else => {242 else => {
243 const decl_name = try c.str(ZigClangDecl_getDeclKindName(decl));243 const decl_name = try c.str(ZigClangDecl_getDeclKindName(decl));
244 try emitWarning(c, ZigClangDecl_getLocation(decl), "ignoring {} declaration", decl_name);244 try emitWarning(c, ZigClangDecl_getLocation(decl), "ignoring {} declaration", .{decl_name});
245 },245 },
246 }246 }
247}247}
...@@ -264,7 +264,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {...@@ -264,7 +264,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
264 .is_export = switch (storage_class) {264 .is_export = switch (storage_class) {
265 .None => has_body and c.mode != .import,265 .None => has_body and c.mode != .import,
266 .Extern, .Static => false,266 .Extern, .Static => false,
267 .PrivateExtern => return failDecl(c, fn_decl_loc, fn_name, "unsupported storage class: private extern"),267 .PrivateExtern => return failDecl(c, fn_decl_loc, fn_name, "unsupported storage class: private extern", .{}),
268 .Auto => unreachable, // Not legal on functions268 .Auto => unreachable, // Not legal on functions
269 .Register => unreachable, // Not legal on functions269 .Register => unreachable, // Not legal on functions
270 },270 },
...@@ -274,7 +274,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {...@@ -274,7 +274,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
274 const fn_proto_type = @ptrCast(*const ZigClangFunctionProtoType, fn_type);274 const fn_proto_type = @ptrCast(*const ZigClangFunctionProtoType, fn_type);
275 break :blk transFnProto(rp, fn_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {275 break :blk transFnProto(rp, fn_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {
276 error.UnsupportedType => {276 error.UnsupportedType => {
277 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function");277 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{});
278 },278 },
279 error.OutOfMemory => |e| return e,279 error.OutOfMemory => |e| return e,
280 };280 };
...@@ -283,7 +283,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {...@@ -283,7 +283,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
283 const fn_no_proto_type = @ptrCast(*const ZigClangFunctionType, fn_type);283 const fn_no_proto_type = @ptrCast(*const ZigClangFunctionType, fn_type);
284 break :blk transFnNoProto(rp, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {284 break :blk transFnNoProto(rp, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {
285 error.UnsupportedType => {285 error.UnsupportedType => {
286 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function");286 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{});
287 },287 },
288 error.OutOfMemory => |e| return e,288 error.OutOfMemory => |e| return e,
289 };289 };
...@@ -302,7 +302,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {...@@ -302,7 +302,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
302 error.OutOfMemory => |e| return e,302 error.OutOfMemory => |e| return e,
303 error.UnsupportedTranslation,303 error.UnsupportedTranslation,
304 error.UnsupportedType,304 error.UnsupportedType,
305 => return failDecl(c, fn_decl_loc, fn_name, "unable to translate function"),305 => return failDecl(c, fn_decl_loc, fn_name, "unable to translate function", .{}),
306 };306 };
307 assert(result.node.id == ast.Node.Id.Block);307 assert(result.node.id == ast.Node.Id.Block);
308 proto_node.body_node = result.node;308 proto_node.body_node = result.node;
...@@ -344,7 +344,7 @@ fn transStmt(...@@ -344,7 +344,7 @@ fn transStmt(
344 error.UnsupportedTranslation,344 error.UnsupportedTranslation,
345 ZigClangStmt_getBeginLoc(stmt),345 ZigClangStmt_getBeginLoc(stmt),
346 "TODO implement translation of stmt class {}",346 "TODO implement translation of stmt class {}",
347 @tagName(sc),347 .{@tagName(sc)},
348 );348 );
349 },349 },
350 }350 }
...@@ -364,7 +364,7 @@ fn transBinaryOperator(...@@ -364,7 +364,7 @@ fn transBinaryOperator(
364 error.UnsupportedTranslation,364 error.UnsupportedTranslation,
365 ZigClangBinaryOperator_getBeginLoc(stmt),365 ZigClangBinaryOperator_getBeginLoc(stmt),
366 "TODO: handle more C binary operators: {}",366 "TODO: handle more C binary operators: {}",
367 op,367 .{op},
368 ),368 ),
369 .Assign => return TransResult{369 .Assign => return TransResult{
370 .node = &(try transCreateNodeAssign(rp, scope, result_used, ZigClangBinaryOperator_getLHS(stmt), ZigClangBinaryOperator_getRHS(stmt))).base,370 .node = &(try transCreateNodeAssign(rp, scope, result_used, ZigClangBinaryOperator_getLHS(stmt), ZigClangBinaryOperator_getRHS(stmt))).base,
...@@ -415,7 +415,7 @@ fn transBinaryOperator(...@@ -415,7 +415,7 @@ fn transBinaryOperator(
415 error.UnsupportedTranslation,415 error.UnsupportedTranslation,
416 ZigClangBinaryOperator_getBeginLoc(stmt),416 ZigClangBinaryOperator_getBeginLoc(stmt),
417 "TODO: handle more C binary operators: {}",417 "TODO: handle more C binary operators: {}",
418 op,418 .{op},
419 ),419 ),
420 .MulAssign,420 .MulAssign,
421 .DivAssign,421 .DivAssign,
...@@ -567,7 +567,7 @@ fn transDeclStmt(rp: RestorePoint, parent_scope: *Scope, stmt: *const ZigClangDe...@@ -567,7 +567,7 @@ fn transDeclStmt(rp: RestorePoint, parent_scope: *Scope, stmt: *const ZigClangDe
567 error.UnsupportedTranslation,567 error.UnsupportedTranslation,
568 ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)),568 ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)),
569 "TODO implement translation of DeclStmt kind {}",569 "TODO implement translation of DeclStmt kind {}",
570 @tagName(kind),570 .{@tagName(kind)},
571 ),571 ),
572 }572 }
573 }573 }
...@@ -636,7 +636,7 @@ fn transImplicitCastExpr(...@@ -636,7 +636,7 @@ fn transImplicitCastExpr(
636 error.UnsupportedTranslation,636 error.UnsupportedTranslation,
637 ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, expr)),637 ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, expr)),
638 "TODO implement translation of CastKind {}",638 "TODO implement translation of CastKind {}",
639 @tagName(kind),639 .{@tagName(kind)},
640 ),640 ),
641 }641 }
642}642}
...@@ -650,7 +650,7 @@ fn transIntegerLiteral(...@@ -650,7 +650,7 @@ fn transIntegerLiteral(
650 var eval_result: ZigClangExprEvalResult = undefined;650 var eval_result: ZigClangExprEvalResult = undefined;
651 if (!ZigClangIntegerLiteral_EvaluateAsInt(expr, &eval_result, rp.c.clang_context)) {651 if (!ZigClangIntegerLiteral_EvaluateAsInt(expr, &eval_result, rp.c.clang_context)) {
652 const loc = ZigClangIntegerLiteral_getBeginLoc(expr);652 const loc = ZigClangIntegerLiteral_getBeginLoc(expr);
653 return revertAndWarn(rp, error.UnsupportedTranslation, loc, "invalid integer literal");653 return revertAndWarn(rp, error.UnsupportedTranslation, loc, "invalid integer literal", .{});
654 }654 }
655 const node = try transCreateNodeAPInt(rp.c, ZigClangAPValue_getInt(&eval_result.Val));655 const node = try transCreateNodeAPInt(rp.c, ZigClangAPValue_getInt(&eval_result.Val));
656 const res = TransResult{656 const res = TransResult{
...@@ -719,7 +719,7 @@ fn transStringLiteral(...@@ -719,7 +719,7 @@ fn transStringLiteral(
719 error.UnsupportedTranslation,719 error.UnsupportedTranslation,
720 ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)),720 ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)),
721 "TODO: support string literal kind {}",721 "TODO: support string literal kind {}",
722 kind,722 .{kind},
723 ),723 ),
724 }724 }
725}725}
...@@ -751,7 +751,7 @@ fn escapeChar(c: u8, char_buf: *[4]u8) []const u8 {...@@ -751,7 +751,7 @@ fn escapeChar(c: u8, char_buf: *[4]u8) []const u8 {
751 '\n' => return "\\n"[0..],751 '\n' => return "\\n"[0..],
752 '\r' => return "\\r"[0..],752 '\r' => return "\\r"[0..],
753 '\t' => return "\\t"[0..],753 '\t' => return "\\t"[0..],
754 else => return std.fmt.bufPrint(char_buf[0..], "\\x{x:2}", c) catch unreachable,754 else => return std.fmt.bufPrint(char_buf[0..], "\\x{x:2}", .{c}) catch unreachable,
755 };755 };
756 std.mem.copy(u8, char_buf, escaped);756 std.mem.copy(u8, char_buf, escaped);
757 return char_buf[0..escaped.len];757 return char_buf[0..escaped.len];
...@@ -1016,7 +1016,13 @@ fn transCreateNodeAssign(...@@ -1016,7 +1016,13 @@ fn transCreateNodeAssign(
1016 // zig: lhs = _tmp;1016 // zig: lhs = _tmp;
1017 // zig: break :x _tmp1017 // zig: break :x _tmp
1018 // zig: })1018 // zig: })
1019 return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangExpr_getBeginLoc(lhs), "TODO: worst case assign op expr");1019 return revertAndWarn(
1020 rp,
1021 error.UnsupportedTranslation,
1022 ZigClangExpr_getBeginLoc(lhs),
1023 "TODO: worst case assign op expr",
1024 .{},
1025 );
1020}1026}
10211027
1022fn transCreateNodeBuiltinFnCall(c: *Context, name: []const u8) !*ast.Node.BuiltinCall {1028fn transCreateNodeBuiltinFnCall(c: *Context, name: []const u8) !*ast.Node.BuiltinCall {
...@@ -1211,7 +1217,7 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour...@@ -1211,7 +1217,7 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour
1211 .Float128 => return appendIdentifier(rp.c, "f128"),1217 .Float128 => return appendIdentifier(rp.c, "f128"),
1212 .Float16 => return appendIdentifier(rp.c, "f16"),1218 .Float16 => return appendIdentifier(rp.c, "f16"),
1213 .LongDouble => return appendIdentifier(rp.c, "c_longdouble"),1219 .LongDouble => return appendIdentifier(rp.c, "c_longdouble"),
1214 else => return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported builtin type"),1220 else => return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported builtin type", .{}),
1215 }1221 }
1216 },1222 },
1217 .FunctionProto => {1223 .FunctionProto => {
...@@ -1253,7 +1259,7 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour...@@ -1253,7 +1259,7 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour
1253 },1259 },
1254 else => {1260 else => {
1255 const type_name = rp.c.str(ZigClangType_getTypeClassName(ty));1261 const type_name = rp.c.str(ZigClangType_getTypeClassName(ty));
1256 return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported type: '{}'", type_name);1262 return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported type: '{}'", .{type_name});
1257 },1263 },
1258 }1264 }
1259}1265}
...@@ -1275,7 +1281,13 @@ fn transCC(...@@ -1275,7 +1281,13 @@ fn transCC(
1275 switch (clang_cc) {1281 switch (clang_cc) {
1276 .C => return CallingConvention.C,1282 .C => return CallingConvention.C,
1277 .X86StdCall => return CallingConvention.Stdcall,1283 .X86StdCall => return CallingConvention.Stdcall,
1278 else => return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported calling convention: {}", @tagName(clang_cc)),1284 else => return revertAndWarn(
1285 rp,
1286 error.UnsupportedType,
1287 source_loc,
1288 "unsupported calling convention: {}",
1289 .{@tagName(clang_cc)},
1290 ),
1279 }1291 }
1280}1292}
12811293
...@@ -1292,7 +1304,13 @@ fn transFnProto(...@@ -1292,7 +1304,13 @@ fn transFnProto(
1292 const param_count: usize = ZigClangFunctionProtoType_getNumParams(fn_proto_ty);1304 const param_count: usize = ZigClangFunctionProtoType_getNumParams(fn_proto_ty);
1293 var i: usize = 0;1305 var i: usize = 0;
1294 while (i < param_count) : (i += 1) {1306 while (i < param_count) : (i += 1) {
1295 return revertAndWarn(rp, error.UnsupportedType, source_loc, "TODO: implement parameters for FunctionProto in transType");1307 return revertAndWarn(
1308 rp,
1309 error.UnsupportedType,
1310 source_loc,
1311 "TODO: implement parameters for FunctionProto in transType",
1312 .{},
1313 );
1296 }1314 }
12971315
1298 return finishTransFnProto(rp, fn_ty, source_loc, fn_decl_context, is_var_args, cc, is_pub);1316 return finishTransFnProto(rp, fn_ty, source_loc, fn_decl_context, is_var_args, cc, is_pub);
...@@ -1350,7 +1368,7 @@ fn finishTransFnProto(...@@ -1350,7 +1368,7 @@ fn finishTransFnProto(
1350 } else {1368 } else {
1351 break :blk transQualType(rp, return_qt, source_loc) catch |err| switch (err) {1369 break :blk transQualType(rp, return_qt, source_loc) catch |err| switch (err) {
1352 error.UnsupportedType => {1370 error.UnsupportedType => {
1353 try emitWarning(rp.c, source_loc, "unsupported function proto return type");1371 try emitWarning(rp.c, source_loc, "unsupported function proto return type", .{});
1354 return err;1372 return err;
1355 },1373 },
1356 error.OutOfMemory => |e| return e,1374 error.OutOfMemory => |e| return e,
...@@ -1397,18 +1415,19 @@ fn revertAndWarn(...@@ -1397,18 +1415,19 @@ fn revertAndWarn(
1397 err: var,1415 err: var,
1398 source_loc: ZigClangSourceLocation,1416 source_loc: ZigClangSourceLocation,
1399 comptime format: []const u8,1417 comptime format: []const u8,
1400 args: ...,1418 args: var,
1401) (@typeOf(err) || error{OutOfMemory}) {1419) (@typeOf(err) || error{OutOfMemory}) {
1402 rp.activate();1420 rp.activate();
1403 try emitWarning(rp.c, source_loc, format, args);1421 try emitWarning(rp.c, source_loc, format, args);
1404 return err;1422 return err;
1405}1423}
14061424
1407fn emitWarning(c: *Context, loc: ZigClangSourceLocation, comptime format: []const u8, args: ...) !void {1425fn emitWarning(c: *Context, loc: ZigClangSourceLocation, comptime format: []const u8, args: var) !void {
1408 _ = try appendTokenFmt(c, .LineComment, "// {}: warning: " ++ format, c.locStr(loc), args);1426 const args_prefix = .{c.locStr(loc)};
1427 _ = try appendTokenFmt(c, .LineComment, "// {}: warning: " ++ format, args_prefix ++ args);
1409}1428}
14101429
1411fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime format: []const u8, args: ...) !void {1430fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime format: []const u8, args: var) !void {
1412 // const name = @compileError(msg);1431 // const name = @compileError(msg);
1413 const const_tok = try appendToken(c, .Keyword_const, "const");1432 const const_tok = try appendToken(c, .Keyword_const, "const");
1414 const name_tok = try appendToken(c, .Identifier, name);1433 const name_tok = try appendToken(c, .Identifier, name);
...@@ -1456,10 +1475,10 @@ fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime...@@ -1456,10 +1475,10 @@ fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime
1456}1475}
14571476
1458fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenIndex {1477fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenIndex {
1459 return appendTokenFmt(c, token_id, "{}", bytes);1478 return appendTokenFmt(c, token_id, "{}", .{bytes});
1460}1479}
14611480
1462fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: ...) !ast.TokenIndex {1481fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: var) !ast.TokenIndex {
1463 const S = struct {1482 const S = struct {
1464 fn callback(context: *Context, bytes: []const u8) error{OutOfMemory}!void {1483 fn callback(context: *Context, bytes: []const u8) error{OutOfMemory}!void {
1465 return context.source_buffer.append(bytes);1484 return context.source_buffer.append(bytes);
src-self-hosted/type.zig+11-15
...@@ -399,7 +399,7 @@ pub const Type = struct {...@@ -399,7 +399,7 @@ pub const Type = struct {
399 .Generic => |generic| {399 .Generic => |generic| {
400 self.non_key = NonKey{ .Generic = {} };400 self.non_key = NonKey{ .Generic = {} };
401 const cc_str = ccFnTypeStr(generic.cc);401 const cc_str = ccFnTypeStr(generic.cc);
402 try name_stream.print("{}fn(", cc_str);402 try name_stream.print("{}fn(", .{cc_str});
403 var param_i: usize = 0;403 var param_i: usize = 0;
404 while (param_i < generic.param_count) : (param_i += 1) {404 while (param_i < generic.param_count) : (param_i += 1) {
405 const arg = if (param_i == 0) "var" else ", var";405 const arg = if (param_i == 0) "var" else ", var";
...@@ -407,7 +407,7 @@ pub const Type = struct {...@@ -407,7 +407,7 @@ pub const Type = struct {
407 }407 }
408 try name_stream.write(")");408 try name_stream.write(")");
409 if (key.alignment) |alignment| {409 if (key.alignment) |alignment| {
410 try name_stream.print(" align({})", alignment);410 try name_stream.print(" align({})", .{alignment});
411 }411 }
412 try name_stream.write(" var");412 try name_stream.write(" var");
413 },413 },
...@@ -416,7 +416,7 @@ pub const Type = struct {...@@ -416,7 +416,7 @@ pub const Type = struct {
416 .Normal = NonKey.Normal{ .variable_list = std.ArrayList(*Scope.Var).init(comp.gpa()) },416 .Normal = NonKey.Normal{ .variable_list = std.ArrayList(*Scope.Var).init(comp.gpa()) },
417 };417 };
418 const cc_str = ccFnTypeStr(normal.cc);418 const cc_str = ccFnTypeStr(normal.cc);
419 try name_stream.print("{}fn(", cc_str);419 try name_stream.print("{}fn(", .{cc_str});
420 for (normal.params) |param, i| {420 for (normal.params) |param, i| {
421 if (i != 0) try name_stream.write(", ");421 if (i != 0) try name_stream.write(", ");
422 if (param.is_noalias) try name_stream.write("noalias ");422 if (param.is_noalias) try name_stream.write("noalias ");
...@@ -428,9 +428,9 @@ pub const Type = struct {...@@ -428,9 +428,9 @@ pub const Type = struct {
428 }428 }
429 try name_stream.write(")");429 try name_stream.write(")");
430 if (key.alignment) |alignment| {430 if (key.alignment) |alignment| {
431 try name_stream.print(" align({})", alignment);431 try name_stream.print(" align({})", .{alignment});
432 }432 }
433 try name_stream.print(" {}", normal.return_type.name);433 try name_stream.print(" {}", .{normal.return_type.name});
434 },434 },
435 }435 }
436436
...@@ -584,7 +584,7 @@ pub const Type = struct {...@@ -584,7 +584,7 @@ pub const Type = struct {
584 errdefer comp.gpa().destroy(self);584 errdefer comp.gpa().destroy(self);
585585
586 const u_or_i = "ui"[@boolToInt(key.is_signed)];586 const u_or_i = "ui"[@boolToInt(key.is_signed)];
587 const name = try std.fmt.allocPrint(comp.gpa(), "{c}{}", u_or_i, key.bit_count);587 const name = try std.fmt.allocPrint(comp.gpa(), "{c}{}", .{ u_or_i, key.bit_count });
588 errdefer comp.gpa().free(name);588 errdefer comp.gpa().free(name);
589589
590 self.base.init(comp, .Int, name);590 self.base.init(comp, .Int, name);
...@@ -767,23 +767,19 @@ pub const Type = struct {...@@ -767,23 +767,19 @@ pub const Type = struct {
767 .Non => "",767 .Non => "",
768 };768 };
769 const name = switch (self.key.alignment) {769 const name = switch (self.key.alignment) {
770 .Abi => try std.fmt.allocPrint(770 .Abi => try std.fmt.allocPrint(comp.gpa(), "{}{}{}{}", .{
771 comp.gpa(),
772 "{}{}{}{}",
773 size_str,771 size_str,
774 mut_str,772 mut_str,
775 vol_str,773 vol_str,
776 self.key.child_type.name,774 self.key.child_type.name,
777 ),775 }),
778 .Override => |alignment| try std.fmt.allocPrint(776 .Override => |alignment| try std.fmt.allocPrint(comp.gpa(), "{}align<{}> {}{}{}", .{
779 comp.gpa(),
780 "{}align<{}> {}{}{}",
781 size_str,777 size_str,
782 alignment,778 alignment,
783 mut_str,779 mut_str,
784 vol_str,780 vol_str,
785 self.key.child_type.name,781 self.key.child_type.name,
786 ),782 }),
787 };783 };
788 errdefer comp.gpa().free(name);784 errdefer comp.gpa().free(name);
789785
...@@ -852,7 +848,7 @@ pub const Type = struct {...@@ -852,7 +848,7 @@ pub const Type = struct {
852 };848 };
853 errdefer comp.gpa().destroy(self);849 errdefer comp.gpa().destroy(self);
854850
855 const name = try std.fmt.allocPrint(comp.gpa(), "[{}]{}", key.len, key.elem_type.name);851 const name = try std.fmt.allocPrint(comp.gpa(), "[{}]{}", .{ key.len, key.elem_type.name });
856 errdefer comp.gpa().free(name);852 errdefer comp.gpa().free(name);
857853
858 self.base.init(comp, .Array, name);854 self.base.init(comp, .Array, name);
src-self-hosted/util.zig+2-2
...@@ -175,7 +175,7 @@ pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target {...@@ -175,7 +175,7 @@ pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target {
175 var result: *llvm.Target = undefined;175 var result: *llvm.Target = undefined;
176 var err_msg: [*:0]u8 = undefined;176 var err_msg: [*:0]u8 = undefined;
177 if (llvm.GetTargetFromTriple(triple.toSlice(), &result, &err_msg) != 0) {177 if (llvm.GetTargetFromTriple(triple.toSlice(), &result, &err_msg) != 0) {
178 std.debug.warn("triple: {s} error: {s}\n", triple.toSlice(), err_msg);178 std.debug.warn("triple: {s} error: {s}\n", .{ triple.toSlice(), err_msg });
179 return error.UnsupportedTarget;179 return error.UnsupportedTarget;
180 }180 }
181 return result;181 return result;
...@@ -206,7 +206,7 @@ pub fn getTriple(allocator: *std.mem.Allocator, self: std.Target) !std.Buffer {...@@ -206,7 +206,7 @@ pub fn getTriple(allocator: *std.mem.Allocator, self: std.Target) !std.Buffer {
206 const env_name = if (self.isWasm()) "wasm" else @tagName(self.getAbi());206 const env_name = if (self.isWasm()) "wasm" else @tagName(self.getAbi());
207207
208 var out = &std.io.BufferOutStream.init(&result).stream;208 var out = &std.io.BufferOutStream.init(&result).stream;
209 try out.print("{}-unknown-{}-{}", @tagName(self.getArch()), @tagName(self.getOs()), env_name);209 try out.print("{}-unknown-{}-{}", .{ @tagName(self.getArch()), @tagName(self.getOs()), env_name });
210210
211 return result;211 return result;
212}212}
src-self-hosted/value.zig+1-1
...@@ -53,7 +53,7 @@ pub const Value = struct {...@@ -53,7 +53,7 @@ pub const Value = struct {
53 }53 }
5454
55 pub fn dump(base: *const Value) void {55 pub fn dump(base: *const Value) void {
56 std.debug.warn("{}", @tagName(base.id));56 std.debug.warn("{}", .{@tagName(base.id)});
57 }57 }
5858
59 pub fn getLlvmConst(base: *Value, ofile: *ObjectFile) (error{OutOfMemory}!?*llvm.Value) {59 pub fn getLlvmConst(base: *Value, ofile: *ObjectFile) (error{OutOfMemory}!?*llvm.Value) {
src/ir.cpp+12-4
...@@ -17025,7 +17025,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -17025,7 +17025,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
17025 {17025 {
17026 result_loc_pass1 = no_result_loc();17026 result_loc_pass1 = no_result_loc();
17027 }17027 }
17028 bool was_written = result_loc_pass1->written;17028 bool was_already_resolved = result_loc_pass1->resolved_loc != nullptr;
17029 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,17029 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
17030 value, force_runtime, non_null_comptime, allow_discard);17030 value, force_runtime, non_null_comptime, allow_discard);
17031 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))17031 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))
...@@ -17038,7 +17038,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -17038,7 +17038,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
17038 }17038 }
1703917039
17040 InferredStructField *isf = result_loc->value->type->data.pointer.inferred_struct_field;17040 InferredStructField *isf = result_loc->value->type->data.pointer.inferred_struct_field;
17041 if (!was_written && isf != nullptr) {17041 if (!was_already_resolved && isf != nullptr) {
17042 // Now it's time to add the field to the struct type.17042 // Now it's time to add the field to the struct type.
17043 uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count;17043 uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count;
17044 uint32_t new_field_count = old_field_count + 1;17044 uint32_t new_field_count = old_field_count + 1;
...@@ -18077,7 +18077,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18077,7 +18077,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18077 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {18077 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
18078 return result_loc;18078 return result_loc;
18079 }18079 }
18080 if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {18080 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;
18081 if (res_child_type == ira->codegen->builtin_types.entry_var) {
18082 res_child_type = impl_fn_type_id->return_type;
18083 }
18084 if (!handle_is_ptr(res_child_type)) {
18081 ir_reset_result(call_result_loc);18085 ir_reset_result(call_result_loc);
18082 result_loc = nullptr;18086 result_loc = nullptr;
18083 }18087 }
...@@ -18240,7 +18244,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18240,7 +18244,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18240 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {18244 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {
18241 return result_loc;18245 return result_loc;
18242 }18246 }
18243 if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {18247 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;
18248 if (res_child_type == ira->codegen->builtin_types.entry_var) {
18249 res_child_type = return_type;
18250 }
18251 if (!handle_is_ptr(res_child_type)) {
18244 ir_reset_result(call_result_loc);18252 ir_reset_result(call_result_loc);
18245 result_loc = nullptr;18253 result_loc = nullptr;
18246 }18254 }
test/cli.zig+11-11
...@@ -19,11 +19,11 @@ pub fn main() !void {...@@ -19,11 +19,11 @@ pub fn main() !void {
19 a = &arena.allocator;19 a = &arena.allocator;
2020
21 const zig_exe_rel = try (arg_it.next(a) orelse {21 const zig_exe_rel = try (arg_it.next(a) orelse {
22 std.debug.warn("Expected first argument to be path to zig compiler\n");22 std.debug.warn("Expected first argument to be path to zig compiler\n", .{});
23 return error.InvalidArgs;23 return error.InvalidArgs;
24 });24 });
25 const cache_root = try (arg_it.next(a) orelse {25 const cache_root = try (arg_it.next(a) orelse {
26 std.debug.warn("Expected second argument to be cache root directory path\n");26 std.debug.warn("Expected second argument to be cache root directory path\n", .{});
27 return error.InvalidArgs;27 return error.InvalidArgs;
28 });28 });
29 const zig_exe = try fs.path.resolve(a, &[_][]const u8{zig_exe_rel});29 const zig_exe = try fs.path.resolve(a, &[_][]const u8{zig_exe_rel});
...@@ -45,39 +45,39 @@ pub fn main() !void {...@@ -45,39 +45,39 @@ pub fn main() !void {
4545
46fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 {46fn unwrapArg(arg: UnwrapArgError![]u8) UnwrapArgError![]u8 {
47 return arg catch |err| {47 return arg catch |err| {
48 warn("Unable to parse command line: {}\n", err);48 warn("Unable to parse command line: {}\n", .{err});
49 return err;49 return err;
50 };50 };
51}51}
5252
53fn printCmd(cwd: []const u8, argv: []const []const u8) void {53fn printCmd(cwd: []const u8, argv: []const []const u8) void {
54 std.debug.warn("cd {} && ", cwd);54 std.debug.warn("cd {} && ", .{cwd});
55 for (argv) |arg| {55 for (argv) |arg| {
56 std.debug.warn("{} ", arg);56 std.debug.warn("{} ", .{arg});
57 }57 }
58 std.debug.warn("\n");58 std.debug.warn("\n", .{});
59}59}
6060
61fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult {61fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult {
62 const max_output_size = 100 * 1024;62 const max_output_size = 100 * 1024;
63 const result = ChildProcess.exec(a, argv, cwd, null, max_output_size) catch |err| {63 const result = ChildProcess.exec(a, argv, cwd, null, max_output_size) catch |err| {
64 std.debug.warn("The following command failed:\n");64 std.debug.warn("The following command failed:\n", .{});
65 printCmd(cwd, argv);65 printCmd(cwd, argv);
66 return err;66 return err;
67 };67 };
68 switch (result.term) {68 switch (result.term) {
69 .Exited => |code| {69 .Exited => |code| {
70 if (code != 0) {70 if (code != 0) {
71 std.debug.warn("The following command exited with error code {}:\n", code);71 std.debug.warn("The following command exited with error code {}:\n", .{code});
72 printCmd(cwd, argv);72 printCmd(cwd, argv);
73 std.debug.warn("stderr:\n{}\n", result.stderr);73 std.debug.warn("stderr:\n{}\n", .{result.stderr});
74 return error.CommandFailed;74 return error.CommandFailed;
75 }75 }
76 },76 },
77 else => {77 else => {
78 std.debug.warn("The following command terminated unexpectedly:\n");78 std.debug.warn("The following command terminated unexpectedly:\n", .{});
79 printCmd(cwd, argv);79 printCmd(cwd, argv);
80 std.debug.warn("stderr:\n{}\n", result.stderr);80 std.debug.warn("stderr:\n{}\n", .{result.stderr});
81 return error.CommandFailed;81 return error.CommandFailed;
82 },82 },
83 }83 }
test/compare_output.zig+33-33
...@@ -20,7 +20,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -20,7 +20,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
20 \\pub fn main() void {20 \\pub fn main() void {
21 \\ privateFunction();21 \\ privateFunction();
22 \\ const stdout = &getStdOut().outStream().stream;22 \\ const stdout = &getStdOut().outStream().stream;
23 \\ stdout.print("OK 2\n") catch unreachable;23 \\ stdout.print("OK 2\n", .{}) catch unreachable;
24 \\}24 \\}
25 \\25 \\
26 \\fn privateFunction() void {26 \\fn privateFunction() void {
...@@ -35,7 +35,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -35,7 +35,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
35 \\// but it's private so it should be OK35 \\// but it's private so it should be OK
36 \\fn privateFunction() void {36 \\fn privateFunction() void {
37 \\ const stdout = &getStdOut().outStream().stream;37 \\ const stdout = &getStdOut().outStream().stream;
38 \\ stdout.print("OK 1\n") catch unreachable;38 \\ stdout.print("OK 1\n", .{}) catch unreachable;
39 \\}39 \\}
40 \\40 \\
41 \\pub fn printText() void {41 \\pub fn printText() void {
...@@ -61,7 +61,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -61,7 +61,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
61 \\usingnamespace @import("std").io;61 \\usingnamespace @import("std").io;
62 \\pub fn foo_function() void {62 \\pub fn foo_function() void {
63 \\ const stdout = &getStdOut().outStream().stream;63 \\ const stdout = &getStdOut().outStream().stream;
64 \\ stdout.print("OK\n") catch unreachable;64 \\ stdout.print("OK\n", .{}) catch unreachable;
65 \\}65 \\}
66 );66 );
6767
...@@ -72,7 +72,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -72,7 +72,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
72 \\pub fn bar_function() void {72 \\pub fn bar_function() void {
73 \\ if (foo_function()) {73 \\ if (foo_function()) {
74 \\ const stdout = &getStdOut().outStream().stream;74 \\ const stdout = &getStdOut().outStream().stream;
75 \\ stdout.print("OK\n") catch unreachable;75 \\ stdout.print("OK\n", .{}) catch unreachable;
76 \\ }76 \\ }
77 \\}77 \\}
78 );78 );
...@@ -104,7 +104,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -104,7 +104,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
104 \\104 \\
105 \\pub fn ok() void {105 \\pub fn ok() void {
106 \\ const stdout = &io.getStdOut().outStream().stream;106 \\ const stdout = &io.getStdOut().outStream().stream;
107 \\ stdout.print(b_text) catch unreachable;107 \\ stdout.print(b_text, .{}) catch unreachable;
108 \\}108 \\}
109 );109 );
110110
...@@ -122,7 +122,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -122,7 +122,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
122 \\122 \\
123 \\pub fn main() void {123 \\pub fn main() void {
124 \\ const stdout = &io.getStdOut().outStream().stream;124 \\ const stdout = &io.getStdOut().outStream().stream;
125 \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", @as(u32, 12), @as(u16, 0x12), @as(u8, 'a')) catch unreachable;125 \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", .{@as(u32, 12), @as(u16, 0x12), @as(u8, 'a')}) catch unreachable;
126 \\}126 \\}
127 , "Hello, world!\n 12 12 a\n");127 , "Hello, world!\n 12 12 a\n");
128128
...@@ -265,7 +265,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -265,7 +265,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
265 \\}265 \\}
266 \\fn print_ok(val: @typeOf(x)) @typeOf(foo) {266 \\fn print_ok(val: @typeOf(x)) @typeOf(foo) {
267 \\ const stdout = &io.getStdOut().outStream().stream;267 \\ const stdout = &io.getStdOut().outStream().stream;
268 \\ stdout.print("OK\n") catch unreachable;268 \\ stdout.print("OK\n", .{}) catch unreachable;
269 \\ return 0;269 \\ return 0;
270 \\}270 \\}
271 \\const foo : i32 = 0;271 \\const foo : i32 = 0;
...@@ -348,12 +348,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -348,12 +348,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
348 \\ const foo = Foo {.field1 = bar,};348 \\ const foo = Foo {.field1 = bar,};
349 \\ const stdout = &io.getStdOut().outStream().stream;349 \\ const stdout = &io.getStdOut().outStream().stream;
350 \\ if (!foo.method()) {350 \\ if (!foo.method()) {
351 \\ stdout.print("BAD\n") catch unreachable;351 \\ stdout.print("BAD\n", .{}) catch unreachable;
352 \\ }352 \\ }
353 \\ if (!bar.method()) {353 \\ if (!bar.method()) {
354 \\ stdout.print("BAD\n") catch unreachable;354 \\ stdout.print("BAD\n", .{}) catch unreachable;
355 \\ }355 \\ }
356 \\ stdout.print("OK\n") catch unreachable;356 \\ stdout.print("OK\n", .{}) catch unreachable;
357 \\}357 \\}
358 , "OK\n");358 , "OK\n");
359359
...@@ -361,11 +361,11 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -361,11 +361,11 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
361 \\const io = @import("std").io;361 \\const io = @import("std").io;
362 \\pub fn main() void {362 \\pub fn main() void {
363 \\ const stdout = &io.getStdOut().outStream().stream;363 \\ const stdout = &io.getStdOut().outStream().stream;
364 \\ stdout.print("before\n") catch unreachable;364 \\ stdout.print("before\n", .{}) catch unreachable;
365 \\ defer stdout.print("defer1\n") catch unreachable;365 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
366 \\ defer stdout.print("defer2\n") catch unreachable;366 \\ defer stdout.print("defer2\n", .{}) catch unreachable;
367 \\ defer stdout.print("defer3\n") catch unreachable;367 \\ defer stdout.print("defer3\n", .{}) catch unreachable;
368 \\ stdout.print("after\n") catch unreachable;368 \\ stdout.print("after\n", .{}) catch unreachable;
369 \\}369 \\}
370 , "before\nafter\ndefer3\ndefer2\ndefer1\n");370 , "before\nafter\ndefer3\ndefer2\ndefer1\n");
371371
...@@ -374,13 +374,13 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -374,13 +374,13 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
374 \\const os = @import("std").os;374 \\const os = @import("std").os;
375 \\pub fn main() void {375 \\pub fn main() void {
376 \\ const stdout = &io.getStdOut().outStream().stream;376 \\ const stdout = &io.getStdOut().outStream().stream;
377 \\ stdout.print("before\n") catch unreachable;377 \\ stdout.print("before\n", .{}) catch unreachable;
378 \\ defer stdout.print("defer1\n") catch unreachable;378 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
379 \\ defer stdout.print("defer2\n") catch unreachable;379 \\ defer stdout.print("defer2\n", .{}) catch unreachable;
380 \\ var args_it = @import("std").process.args();380 \\ var args_it = @import("std").process.args();
381 \\ if (args_it.skip() and !args_it.skip()) return;381 \\ if (args_it.skip() and !args_it.skip()) return;
382 \\ defer stdout.print("defer3\n") catch unreachable;382 \\ defer stdout.print("defer3\n", .{}) catch unreachable;
383 \\ stdout.print("after\n") catch unreachable;383 \\ stdout.print("after\n", .{}) catch unreachable;
384 \\}384 \\}
385 , "before\ndefer2\ndefer1\n");385 , "before\ndefer2\ndefer1\n");
386386
...@@ -391,12 +391,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -391,12 +391,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
391 \\}391 \\}
392 \\fn do_test() !void {392 \\fn do_test() !void {
393 \\ const stdout = &io.getStdOut().outStream().stream;393 \\ const stdout = &io.getStdOut().outStream().stream;
394 \\ stdout.print("before\n") catch unreachable;394 \\ stdout.print("before\n", .{}) catch unreachable;
395 \\ defer stdout.print("defer1\n") catch unreachable;395 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
396 \\ errdefer stdout.print("deferErr\n") catch unreachable;396 \\ errdefer stdout.print("deferErr\n", .{}) catch unreachable;
397 \\ try its_gonna_fail();397 \\ try its_gonna_fail();
398 \\ defer stdout.print("defer3\n") catch unreachable;398 \\ defer stdout.print("defer3\n", .{}) catch unreachable;
399 \\ stdout.print("after\n") catch unreachable;399 \\ stdout.print("after\n", .{}) catch unreachable;
400 \\}400 \\}
401 \\fn its_gonna_fail() !void {401 \\fn its_gonna_fail() !void {
402 \\ return error.IToldYouItWouldFail;402 \\ return error.IToldYouItWouldFail;
...@@ -410,12 +410,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -410,12 +410,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
410 \\}410 \\}
411 \\fn do_test() !void {411 \\fn do_test() !void {
412 \\ const stdout = &io.getStdOut().outStream().stream;412 \\ const stdout = &io.getStdOut().outStream().stream;
413 \\ stdout.print("before\n") catch unreachable;413 \\ stdout.print("before\n", .{}) catch unreachable;
414 \\ defer stdout.print("defer1\n") catch unreachable;414 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
415 \\ errdefer stdout.print("deferErr\n") catch unreachable;415 \\ errdefer stdout.print("deferErr\n", .{}) catch unreachable;
416 \\ try its_gonna_pass();416 \\ try its_gonna_pass();
417 \\ defer stdout.print("defer3\n") catch unreachable;417 \\ defer stdout.print("defer3\n", .{}) catch unreachable;
418 \\ stdout.print("after\n") catch unreachable;418 \\ stdout.print("after\n", .{}) catch unreachable;
419 \\}419 \\}
420 \\fn its_gonna_pass() anyerror!void { }420 \\fn its_gonna_pass() anyerror!void { }
421 , "before\nafter\ndefer3\ndefer1\n");421 , "before\nafter\ndefer3\ndefer1\n");
...@@ -427,7 +427,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -427,7 +427,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
427 \\427 \\
428 \\pub fn main() void {428 \\pub fn main() void {
429 \\ const stdout = &io.getStdOut().outStream().stream;429 \\ const stdout = &io.getStdOut().outStream().stream;
430 \\ stdout.print(foo_txt) catch unreachable;430 \\ stdout.print(foo_txt, .{}) catch unreachable;
431 \\}431 \\}
432 , "1234\nabcd\n");432 , "1234\nabcd\n");
433433
...@@ -452,7 +452,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -452,7 +452,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
452 \\ _ = args_it.skip();452 \\ _ = args_it.skip();
453 \\ while (args_it.next(allocator)) |arg_or_err| : (index += 1) {453 \\ while (args_it.next(allocator)) |arg_or_err| : (index += 1) {
454 \\ const arg = try arg_or_err;454 \\ const arg = try arg_or_err;
455 \\ try stdout.print("{}: {}\n", index, arg);455 \\ try stdout.print("{}: {}\n", .{index, arg});
456 \\ }456 \\ }
457 \\}457 \\}
458 ,458 ,
...@@ -493,7 +493,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -493,7 +493,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
493 \\ _ = args_it.skip();493 \\ _ = args_it.skip();
494 \\ while (args_it.next(allocator)) |arg_or_err| : (index += 1) {494 \\ while (args_it.next(allocator)) |arg_or_err| : (index += 1) {
495 \\ const arg = try arg_or_err;495 \\ const arg = try arg_or_err;
496 \\ try stdout.print("{}: {}\n", index, arg);496 \\ try stdout.print("{}: {}\n", .{index, arg});
497 \\ }497 \\ }
498 \\}498 \\}
499 ,499 ,
test/compile_errors.zig+2-4
...@@ -2598,14 +2598,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2598,14 +2598,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2598 \\fn a(b: fn (*const u8) void) void {2598 \\fn a(b: fn (*const u8) void) void {
2599 \\ b('a');2599 \\ b('a');
2600 \\}2600 \\}
2601 \\fn c(d: u8) void {2601 \\fn c(d: u8) void {}
2602 \\ @import("std").debug.warn("{c}\n", d);
2603 \\}
2604 \\export fn entry() void {2602 \\export fn entry() void {
2605 \\ a(c);2603 \\ a(c);
2606 \\}2604 \\}
2607 ,2605 ,
2608 "tmp.zig:8:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'",2606 "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'",
2609 );2607 );
26102608
2611 cases.add(2609 cases.add(
test/standalone/cat/main.zig+5-5
...@@ -23,7 +23,7 @@ pub fn main() !void {...@@ -23,7 +23,7 @@ pub fn main() !void {
23 return usage(exe);23 return usage(exe);
24 } else {24 } else {
25 const file = cwd.openFile(arg, .{}) catch |err| {25 const file = cwd.openFile(arg, .{}) catch |err| {
26 warn("Unable to open file: {}\n", @errorName(err));26 warn("Unable to open file: {}\n", .{@errorName(err)});
27 return err;27 return err;
28 };28 };
29 defer file.close();29 defer file.close();
...@@ -38,7 +38,7 @@ pub fn main() !void {...@@ -38,7 +38,7 @@ pub fn main() !void {
38}38}
3939
40fn usage(exe: []const u8) !void {40fn usage(exe: []const u8) !void {
41 warn("Usage: {} [FILE]...\n", exe);41 warn("Usage: {} [FILE]...\n", .{exe});
42 return error.Invalid;42 return error.Invalid;
43}43}
4444
...@@ -47,7 +47,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void {...@@ -47,7 +47,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void {
4747
48 while (true) {48 while (true) {
49 const bytes_read = file.read(buf[0..]) catch |err| {49 const bytes_read = file.read(buf[0..]) catch |err| {
50 warn("Unable to read from stream: {}\n", @errorName(err));50 warn("Unable to read from stream: {}\n", .{@errorName(err)});
51 return err;51 return err;
52 };52 };
5353
...@@ -56,7 +56,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void {...@@ -56,7 +56,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void {
56 }56 }
5757
58 stdout.write(buf[0..bytes_read]) catch |err| {58 stdout.write(buf[0..bytes_read]) catch |err| {
59 warn("Unable to write to stdout: {}\n", @errorName(err));59 warn("Unable to write to stdout: {}\n", .{@errorName(err)});
60 return err;60 return err;
61 };61 };
62 }62 }
...@@ -64,7 +64,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void {...@@ -64,7 +64,7 @@ fn cat_file(stdout: fs.File, file: fs.File) !void {
6464
65fn unwrapArg(arg: anyerror![]u8) ![]u8 {65fn unwrapArg(arg: anyerror![]u8) ![]u8 {
66 return arg catch |err| {66 return arg catch |err| {
67 warn("Unable to parse command line: {}\n", err);67 warn("Unable to parse command line: {}\n", .{err});
68 return err;68 return err;
69 };69 };
70}70}
test/standalone/guess_number/main.zig+8-8
...@@ -6,11 +6,11 @@ const fmt = std.fmt;...@@ -6,11 +6,11 @@ const fmt = std.fmt;
6pub fn main() !void {6pub fn main() !void {
7 const stdout = &io.getStdOut().outStream().stream;7 const stdout = &io.getStdOut().outStream().stream;
88
9 try stdout.print("Welcome to the Guess Number Game in Zig.\n");9 try stdout.print("Welcome to the Guess Number Game in Zig.\n", .{});
1010
11 var seed_bytes: [@sizeOf(u64)]u8 = undefined;11 var seed_bytes: [@sizeOf(u64)]u8 = undefined;
12 std.crypto.randomBytes(seed_bytes[0..]) catch |err| {12 std.crypto.randomBytes(seed_bytes[0..]) catch |err| {
13 std.debug.warn("unable to seed random number generator: {}", err);13 std.debug.warn("unable to seed random number generator: {}", .{err});
14 return err;14 return err;
15 };15 };
16 const seed = std.mem.readIntNative(u64, &seed_bytes);16 const seed = std.mem.readIntNative(u64, &seed_bytes);
...@@ -19,27 +19,27 @@ pub fn main() !void {...@@ -19,27 +19,27 @@ pub fn main() !void {
19 const answer = prng.random.range(u8, 0, 100) + 1;19 const answer = prng.random.range(u8, 0, 100) + 1;
2020
21 while (true) {21 while (true) {
22 try stdout.print("\nGuess a number between 1 and 100: ");22 try stdout.print("\nGuess a number between 1 and 100: ", .{});
23 var line_buf: [20]u8 = undefined;23 var line_buf: [20]u8 = undefined;
2424
25 const line = io.readLineSlice(line_buf[0..]) catch |err| switch (err) {25 const line = io.readLineSlice(line_buf[0..]) catch |err| switch (err) {
26 error.OutOfMemory => {26 error.OutOfMemory => {
27 try stdout.print("Input too long.\n");27 try stdout.print("Input too long.\n", .{});
28 continue;28 continue;
29 },29 },
30 else => return err,30 else => return err,
31 };31 };
3232
33 const guess = fmt.parseUnsigned(u8, line, 10) catch {33 const guess = fmt.parseUnsigned(u8, line, 10) catch {
34 try stdout.print("Invalid number.\n");34 try stdout.print("Invalid number.\n", .{});
35 continue;35 continue;
36 };36 };
37 if (guess > answer) {37 if (guess > answer) {
38 try stdout.print("Guess lower.\n");38 try stdout.print("Guess lower.\n", .{});
39 } else if (guess < answer) {39 } else if (guess < answer) {
40 try stdout.print("Guess higher.\n");40 try stdout.print("Guess higher.\n", .{});
41 } else {41 } else {
42 try stdout.print("You win!\n");42 try stdout.print("You win!\n", .{});
43 return;43 return;
44 }44 }
45 }45 }
test/tests.zig+94-66
...@@ -411,7 +411,7 @@ pub fn addPkgTests(...@@ -411,7 +411,7 @@ pub fn addPkgTests(
411 is_qemu_enabled: bool,411 is_qemu_enabled: bool,
412 glibc_dir: ?[]const u8,412 glibc_dir: ?[]const u8,
413) *build.Step {413) *build.Step {
414 const step = b.step(b.fmt("test-{}", name), desc);414 const step = b.step(b.fmt("test-{}", .{name}), desc);
415415
416 for (test_targets) |test_target| {416 for (test_targets) |test_target| {
417 if (skip_non_native and test_target.target != .Native)417 if (skip_non_native and test_target.target != .Native)
...@@ -454,14 +454,14 @@ pub fn addPkgTests(...@@ -454,14 +454,14 @@ pub fn addPkgTests(
454 test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;454 test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;
455455
456 const these_tests = b.addTest(root_src);456 const these_tests = b.addTest(root_src);
457 these_tests.setNamePrefix(b.fmt(457 const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
458 "{}-{}-{}-{}-{} ",458 these_tests.setNamePrefix(b.fmt("{}-{}-{}-{}-{} ", .{
459 name,459 name,
460 triple_prefix,460 triple_prefix,
461 @tagName(test_target.mode),461 @tagName(test_target.mode),
462 libc_prefix,462 libc_prefix,
463 if (test_target.single_threaded) "single" else "multi",463 single_threaded_txt,
464 ));464 }));
465 these_tests.single_threaded = test_target.single_threaded;465 these_tests.single_threaded = test_target.single_threaded;
466 these_tests.setFilter(test_filter);466 these_tests.setFilter(test_filter);
467 these_tests.setBuildMode(test_target.mode);467 these_tests.setBuildMode(test_target.mode);
...@@ -562,7 +562,7 @@ pub const CompareOutputContext = struct {...@@ -562,7 +562,7 @@ pub const CompareOutputContext = struct {
562 args.append(arg) catch unreachable;562 args.append(arg) catch unreachable;
563 }563 }
564564
565 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);565 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
566566
567 const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;567 const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
568 defer child.deinit();568 defer child.deinit();
...@@ -572,7 +572,7 @@ pub const CompareOutputContext = struct {...@@ -572,7 +572,7 @@ pub const CompareOutputContext = struct {
572 child.stderr_behavior = .Pipe;572 child.stderr_behavior = .Pipe;
573 child.env_map = b.env_map;573 child.env_map = b.env_map;
574574
575 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));575 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
576576
577 var stdout = Buffer.initNull(b.allocator);577 var stdout = Buffer.initNull(b.allocator);
578 var stderr = Buffer.initNull(b.allocator);578 var stderr = Buffer.initNull(b.allocator);
...@@ -584,18 +584,18 @@ pub const CompareOutputContext = struct {...@@ -584,18 +584,18 @@ pub const CompareOutputContext = struct {
584 stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;584 stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;
585585
586 const term = child.wait() catch |err| {586 const term = child.wait() catch |err| {
587 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));587 debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
588 };588 };
589 switch (term) {589 switch (term) {
590 .Exited => |code| {590 .Exited => |code| {
591 if (code != 0) {591 if (code != 0) {
592 warn("Process {} exited with error code {}\n", full_exe_path, code);592 warn("Process {} exited with error code {}\n", .{ full_exe_path, code });
593 printInvocation(args.toSliceConst());593 printInvocation(args.toSliceConst());
594 return error.TestFailed;594 return error.TestFailed;
595 }595 }
596 },596 },
597 else => {597 else => {
598 warn("Process {} terminated unexpectedly\n", full_exe_path);598 warn("Process {} terminated unexpectedly\n", .{full_exe_path});
599 printInvocation(args.toSliceConst());599 printInvocation(args.toSliceConst());
600 return error.TestFailed;600 return error.TestFailed;
601 },601 },
...@@ -609,10 +609,10 @@ pub const CompareOutputContext = struct {...@@ -609,10 +609,10 @@ pub const CompareOutputContext = struct {
609 \\========= But found: ====================609 \\========= But found: ====================
610 \\{}610 \\{}
611 \\611 \\
612 , self.expected_output, stdout.toSliceConst());612 , .{ self.expected_output, stdout.toSliceConst() });
613 return error.TestFailed;613 return error.TestFailed;
614 }614 }
615 warn("OK\n");615 warn("OK\n", .{});
616 }616 }
617 };617 };
618618
...@@ -644,7 +644,7 @@ pub const CompareOutputContext = struct {...@@ -644,7 +644,7 @@ pub const CompareOutputContext = struct {
644644
645 const full_exe_path = self.exe.getOutputPath();645 const full_exe_path = self.exe.getOutputPath();
646646
647 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);647 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
648648
649 const child = std.ChildProcess.init(&[_][]const u8{full_exe_path}, b.allocator) catch unreachable;649 const child = std.ChildProcess.init(&[_][]const u8{full_exe_path}, b.allocator) catch unreachable;
650 defer child.deinit();650 defer child.deinit();
...@@ -655,28 +655,34 @@ pub const CompareOutputContext = struct {...@@ -655,28 +655,34 @@ pub const CompareOutputContext = struct {
655 child.stderr_behavior = .Ignore;655 child.stderr_behavior = .Ignore;
656656
657 const term = child.spawnAndWait() catch |err| {657 const term = child.spawnAndWait() catch |err| {
658 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));658 debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
659 };659 };
660660
661 const expected_exit_code: u32 = 126;661 const expected_exit_code: u32 = 126;
662 switch (term) {662 switch (term) {
663 .Exited => |code| {663 .Exited => |code| {
664 if (code != expected_exit_code) {664 if (code != expected_exit_code) {
665 warn("\nProgram expected to exit with code {} " ++ "but exited with code {}\n", expected_exit_code, code);665 warn("\nProgram expected to exit with code {} but exited with code {}\n", .{
666 expected_exit_code, code,
667 });
666 return error.TestFailed;668 return error.TestFailed;
667 }669 }
668 },670 },
669 .Signal => |sig| {671 .Signal => |sig| {
670 warn("\nProgram expected to exit with code {} " ++ "but instead signaled {}\n", expected_exit_code, sig);672 warn("\nProgram expected to exit with code {} but instead signaled {}\n", .{
673 expected_exit_code, sig,
674 });
671 return error.TestFailed;675 return error.TestFailed;
672 },676 },
673 else => {677 else => {
674 warn("\nProgram expected to exit with code {}" ++ " but exited in an unexpected way\n", expected_exit_code);678 warn("\nProgram expected to exit with code {} but exited in an unexpected way\n", .{
679 expected_exit_code,
680 });
675 return error.TestFailed;681 return error.TestFailed;
676 },682 },
677 }683 }
678684
679 warn("OK\n");685 warn("OK\n", .{});
680 }686 }
681 };687 };
682688
...@@ -729,7 +735,9 @@ pub const CompareOutputContext = struct {...@@ -729,7 +735,9 @@ pub const CompareOutputContext = struct {
729735
730 switch (case.special) {736 switch (case.special) {
731 Special.Asm => {737 Special.Asm => {
732 const annotated_case_name = fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name) catch unreachable;738 const annotated_case_name = fmt.allocPrint(self.b.allocator, "assemble-and-link {}", .{
739 case.name,
740 }) catch unreachable;
733 if (self.test_filter) |filter| {741 if (self.test_filter) |filter| {
734 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;742 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
735 }743 }
...@@ -758,7 +766,11 @@ pub const CompareOutputContext = struct {...@@ -758,7 +766,11 @@ pub const CompareOutputContext = struct {
758 },766 },
759 Special.None => {767 Special.None => {
760 for (self.modes) |mode| {768 for (self.modes) |mode| {
761 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", "compare-output", case.name, @tagName(mode)) catch unreachable;769 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", .{
770 "compare-output",
771 case.name,
772 @tagName(mode),
773 }) catch unreachable;
762 if (self.test_filter) |filter| {774 if (self.test_filter) |filter| {
763 if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;775 if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
764 }776 }
...@@ -790,7 +802,7 @@ pub const CompareOutputContext = struct {...@@ -790,7 +802,7 @@ pub const CompareOutputContext = struct {
790 }802 }
791 },803 },
792 Special.RuntimeSafety => {804 Special.RuntimeSafety => {
793 const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", case.name) catch unreachable;805 const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", .{case.name}) catch unreachable;
794 if (self.test_filter) |filter| {806 if (self.test_filter) |filter| {
795 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;807 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
796 }808 }
...@@ -843,7 +855,11 @@ pub const StackTracesContext = struct {...@@ -843,7 +855,11 @@ pub const StackTracesContext = struct {
843 const expect_for_mode = expect[@enumToInt(mode)];855 const expect_for_mode = expect[@enumToInt(mode)];
844 if (expect_for_mode.len == 0) continue;856 if (expect_for_mode.len == 0) continue;
845857
846 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", "stack-trace", name, @tagName(mode)) catch unreachable;858 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", .{
859 "stack-trace",
860 name,
861 @tagName(mode),
862 }) catch unreachable;
847 if (self.test_filter) |filter| {863 if (self.test_filter) |filter| {
848 if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;864 if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
849 }865 }
...@@ -907,7 +923,7 @@ pub const StackTracesContext = struct {...@@ -907,7 +923,7 @@ pub const StackTracesContext = struct {
907 defer args.deinit();923 defer args.deinit();
908 args.append(full_exe_path) catch unreachable;924 args.append(full_exe_path) catch unreachable;
909925
910 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);926 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
911927
912 const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;928 const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
913 defer child.deinit();929 defer child.deinit();
...@@ -917,7 +933,7 @@ pub const StackTracesContext = struct {...@@ -917,7 +933,7 @@ pub const StackTracesContext = struct {
917 child.stderr_behavior = .Pipe;933 child.stderr_behavior = .Pipe;
918 child.env_map = b.env_map;934 child.env_map = b.env_map;
919935
920 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));936 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
921937
922 var stdout = Buffer.initNull(b.allocator);938 var stdout = Buffer.initNull(b.allocator);
923 var stderr = Buffer.initNull(b.allocator);939 var stderr = Buffer.initNull(b.allocator);
...@@ -929,30 +945,34 @@ pub const StackTracesContext = struct {...@@ -929,30 +945,34 @@ pub const StackTracesContext = struct {
929 stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;945 stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;
930946
931 const term = child.wait() catch |err| {947 const term = child.wait() catch |err| {
932 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));948 debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
933 };949 };
934950
935 switch (term) {951 switch (term) {
936 .Exited => |code| {952 .Exited => |code| {
937 const expect_code: u32 = 1;953 const expect_code: u32 = 1;
938 if (code != expect_code) {954 if (code != expect_code) {
939 warn("Process {} exited with error code {} but expected code {}\n", full_exe_path, code, expect_code);955 warn("Process {} exited with error code {} but expected code {}\n", .{
956 full_exe_path,
957 code,
958 expect_code,
959 });
940 printInvocation(args.toSliceConst());960 printInvocation(args.toSliceConst());
941 return error.TestFailed;961 return error.TestFailed;
942 }962 }
943 },963 },
944 .Signal => |signum| {964 .Signal => |signum| {
945 warn("Process {} terminated on signal {}\n", full_exe_path, signum);965 warn("Process {} terminated on signal {}\n", .{ full_exe_path, signum });
946 printInvocation(args.toSliceConst());966 printInvocation(args.toSliceConst());
947 return error.TestFailed;967 return error.TestFailed;
948 },968 },
949 .Stopped => |signum| {969 .Stopped => |signum| {
950 warn("Process {} stopped on signal {}\n", full_exe_path, signum);970 warn("Process {} stopped on signal {}\n", .{ full_exe_path, signum });
951 printInvocation(args.toSliceConst());971 printInvocation(args.toSliceConst());
952 return error.TestFailed;972 return error.TestFailed;
953 },973 },
954 .Unknown => |code| {974 .Unknown => |code| {
955 warn("Process {} terminated unexpectedly with error code {}\n", full_exe_path, code);975 warn("Process {} terminated unexpectedly with error code {}\n", .{ full_exe_path, code });
956 printInvocation(args.toSliceConst());976 printInvocation(args.toSliceConst());
957 return error.TestFailed;977 return error.TestFailed;
958 },978 },
...@@ -1003,10 +1023,10 @@ pub const StackTracesContext = struct {...@@ -1003,10 +1023,10 @@ pub const StackTracesContext = struct {
1003 \\================================================1023 \\================================================
1004 \\{}1024 \\{}
1005 \\1025 \\
1006 , self.expect_output, got);1026 , .{ self.expect_output, got });
1007 return error.TestFailed;1027 return error.TestFailed;
1008 }1028 }
1009 warn("OK\n");1029 warn("OK\n", .{});
1010 }1030 }
1011 };1031 };
1012};1032};
...@@ -1129,7 +1149,7 @@ pub const CompileErrorContext = struct {...@@ -1129,7 +1149,7 @@ pub const CompileErrorContext = struct {
1129 Mode.ReleaseSmall => zig_args.append("--release-small") catch unreachable,1149 Mode.ReleaseSmall => zig_args.append("--release-small") catch unreachable,
1130 }1150 }
11311151
1132 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);1152 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
11331153
1134 if (b.verbose) {1154 if (b.verbose) {
1135 printInvocation(zig_args.toSliceConst());1155 printInvocation(zig_args.toSliceConst());
...@@ -1143,7 +1163,7 @@ pub const CompileErrorContext = struct {...@@ -1143,7 +1163,7 @@ pub const CompileErrorContext = struct {
1143 child.stdout_behavior = .Pipe;1163 child.stdout_behavior = .Pipe;
1144 child.stderr_behavior = .Pipe;1164 child.stderr_behavior = .Pipe;
11451165
1146 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));1166 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) });
11471167
1148 var stdout_buf = Buffer.initNull(b.allocator);1168 var stdout_buf = Buffer.initNull(b.allocator);
1149 var stderr_buf = Buffer.initNull(b.allocator);1169 var stderr_buf = Buffer.initNull(b.allocator);
...@@ -1155,7 +1175,7 @@ pub const CompileErrorContext = struct {...@@ -1155,7 +1175,7 @@ pub const CompileErrorContext = struct {
1155 stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;1175 stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
11561176
1157 const term = child.wait() catch |err| {1177 const term = child.wait() catch |err| {
1158 debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));1178 debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) });
1159 };1179 };
1160 switch (term) {1180 switch (term) {
1161 .Exited => |code| {1181 .Exited => |code| {
...@@ -1165,7 +1185,7 @@ pub const CompileErrorContext = struct {...@@ -1165,7 +1185,7 @@ pub const CompileErrorContext = struct {
1165 }1185 }
1166 },1186 },
1167 else => {1187 else => {
1168 warn("Process {} terminated unexpectedly\n", b.zig_exe);1188 warn("Process {} terminated unexpectedly\n", .{b.zig_exe});
1169 printInvocation(zig_args.toSliceConst());1189 printInvocation(zig_args.toSliceConst());
1170 return error.TestFailed;1190 return error.TestFailed;
1171 },1191 },
...@@ -1182,7 +1202,7 @@ pub const CompileErrorContext = struct {...@@ -1182,7 +1202,7 @@ pub const CompileErrorContext = struct {
1182 \\{}1202 \\{}
1183 \\================================================1203 \\================================================
1184 \\1204 \\
1185 , stdout);1205 , .{stdout});
1186 return error.TestFailed;1206 return error.TestFailed;
1187 }1207 }
11881208
...@@ -1200,9 +1220,9 @@ pub const CompileErrorContext = struct {...@@ -1200,9 +1220,9 @@ pub const CompileErrorContext = struct {
1200 ok = ok and i == self.case.expected_errors.len;1220 ok = ok and i == self.case.expected_errors.len;
12011221
1202 if (!ok) {1222 if (!ok) {
1203 warn("\n======== Expected these compile errors: ========\n");1223 warn("\n======== Expected these compile errors: ========\n", .{});
1204 for (self.case.expected_errors.toSliceConst()) |expected| {1224 for (self.case.expected_errors.toSliceConst()) |expected| {
1205 warn("{}\n", expected);1225 warn("{}\n", .{expected});
1206 }1226 }
1207 }1227 }
1208 } else {1228 } else {
...@@ -1213,7 +1233,7 @@ pub const CompileErrorContext = struct {...@@ -1213,7 +1233,7 @@ pub const CompileErrorContext = struct {
1213 \\=========== Expected compile error: ============1233 \\=========== Expected compile error: ============
1214 \\{}1234 \\{}
1215 \\1235 \\
1216 , expected);1236 , .{expected});
1217 ok = false;1237 ok = false;
1218 break;1238 break;
1219 }1239 }
...@@ -1225,11 +1245,11 @@ pub const CompileErrorContext = struct {...@@ -1225,11 +1245,11 @@ pub const CompileErrorContext = struct {
1225 \\================= Full output: =================1245 \\================= Full output: =================
1226 \\{}1246 \\{}
1227 \\1247 \\
1228 , stderr);1248 , .{stderr});
1229 return error.TestFailed;1249 return error.TestFailed;
1230 }1250 }
12311251
1232 warn("OK\n");1252 warn("OK\n", .{});
1233 }1253 }
1234 };1254 };
12351255
...@@ -1279,7 +1299,9 @@ pub const CompileErrorContext = struct {...@@ -1279,7 +1299,9 @@ pub const CompileErrorContext = struct {
1279 pub fn addCase(self: *CompileErrorContext, case: *const TestCase) void {1299 pub fn addCase(self: *CompileErrorContext, case: *const TestCase) void {
1280 const b = self.b;1300 const b = self.b;
12811301
1282 const annotated_case_name = fmt.allocPrint(self.b.allocator, "compile-error {}", case.name) catch unreachable;1302 const annotated_case_name = fmt.allocPrint(self.b.allocator, "compile-error {}", .{
1303 case.name,
1304 }) catch unreachable;
1283 if (self.test_filter) |filter| {1305 if (self.test_filter) |filter| {
1284 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;1306 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
1285 }1307 }
...@@ -1316,7 +1338,7 @@ pub const StandaloneContext = struct {...@@ -1316,7 +1338,7 @@ pub const StandaloneContext = struct {
1316 pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8) void {1338 pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8) void {
1317 const b = self.b;1339 const b = self.b;
13181340
1319 const annotated_case_name = b.fmt("build {} (Debug)", build_file);1341 const annotated_case_name = b.fmt("build {} (Debug)", .{build_file});
1320 if (self.test_filter) |filter| {1342 if (self.test_filter) |filter| {
1321 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;1343 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
1322 }1344 }
...@@ -1337,7 +1359,7 @@ pub const StandaloneContext = struct {...@@ -1337,7 +1359,7 @@ pub const StandaloneContext = struct {
13371359
1338 const run_cmd = b.addSystemCommand(zig_args.toSliceConst());1360 const run_cmd = b.addSystemCommand(zig_args.toSliceConst());
13391361
1340 const log_step = b.addLog("PASS {}\n", annotated_case_name);1362 const log_step = b.addLog("PASS {}\n", .{annotated_case_name});
1341 log_step.step.dependOn(&run_cmd.step);1363 log_step.step.dependOn(&run_cmd.step);
13421364
1343 self.step.dependOn(&log_step.step);1365 self.step.dependOn(&log_step.step);
...@@ -1347,7 +1369,10 @@ pub const StandaloneContext = struct {...@@ -1347,7 +1369,10 @@ pub const StandaloneContext = struct {
1347 const b = self.b;1369 const b = self.b;
13481370
1349 for (self.modes) |mode| {1371 for (self.modes) |mode| {
1350 const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {} ({})", root_src, @tagName(mode)) catch unreachable;1372 const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {} ({})", .{
1373 root_src,
1374 @tagName(mode),
1375 }) catch unreachable;
1351 if (self.test_filter) |filter| {1376 if (self.test_filter) |filter| {
1352 if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;1377 if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
1353 }1378 }
...@@ -1358,7 +1383,7 @@ pub const StandaloneContext = struct {...@@ -1358,7 +1383,7 @@ pub const StandaloneContext = struct {
1358 exe.linkSystemLibrary("c");1383 exe.linkSystemLibrary("c");
1359 }1384 }
13601385
1361 const log_step = b.addLog("PASS {}\n", annotated_case_name);1386 const log_step = b.addLog("PASS {}\n", .{annotated_case_name});
1362 log_step.step.dependOn(&exe.step);1387 log_step.step.dependOn(&exe.step);
13631388
1364 self.step.dependOn(&log_step.step);1389 self.step.dependOn(&log_step.step);
...@@ -1434,7 +1459,7 @@ pub const TranslateCContext = struct {...@@ -1434,7 +1459,7 @@ pub const TranslateCContext = struct {
1434 zig_args.append(translate_c_cmd) catch unreachable;1459 zig_args.append(translate_c_cmd) catch unreachable;
1435 zig_args.append(b.pathFromRoot(root_src)) catch unreachable;1460 zig_args.append(b.pathFromRoot(root_src)) catch unreachable;
14361461
1437 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);1462 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
14381463
1439 if (b.verbose) {1464 if (b.verbose) {
1440 printInvocation(zig_args.toSliceConst());1465 printInvocation(zig_args.toSliceConst());
...@@ -1448,7 +1473,10 @@ pub const TranslateCContext = struct {...@@ -1448,7 +1473,10 @@ pub const TranslateCContext = struct {
1448 child.stdout_behavior = .Pipe;1473 child.stdout_behavior = .Pipe;
1449 child.stderr_behavior = .Pipe;1474 child.stderr_behavior = .Pipe;
14501475
1451 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));1476 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{
1477 zig_args.toSliceConst()[0],
1478 @errorName(err),
1479 });
14521480
1453 var stdout_buf = Buffer.initNull(b.allocator);1481 var stdout_buf = Buffer.initNull(b.allocator);
1454 var stderr_buf = Buffer.initNull(b.allocator);1482 var stderr_buf = Buffer.initNull(b.allocator);
...@@ -1460,23 +1488,23 @@ pub const TranslateCContext = struct {...@@ -1460,23 +1488,23 @@ pub const TranslateCContext = struct {
1460 stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;1488 stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
14611489
1462 const term = child.wait() catch |err| {1490 const term = child.wait() catch |err| {
1463 debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));1491 debug.panic("Unable to spawn {}: {}\n", .{ zig_args.toSliceConst()[0], @errorName(err) });
1464 };1492 };
1465 switch (term) {1493 switch (term) {
1466 .Exited => |code| {1494 .Exited => |code| {
1467 if (code != 0) {1495 if (code != 0) {
1468 warn("Compilation failed with exit code {}\n", code);1496 warn("Compilation failed with exit code {}\n", .{code});
1469 printInvocation(zig_args.toSliceConst());1497 printInvocation(zig_args.toSliceConst());
1470 return error.TestFailed;1498 return error.TestFailed;
1471 }1499 }
1472 },1500 },
1473 .Signal => |code| {1501 .Signal => |code| {
1474 warn("Compilation failed with signal {}\n", code);1502 warn("Compilation failed with signal {}\n", .{code});
1475 printInvocation(zig_args.toSliceConst());1503 printInvocation(zig_args.toSliceConst());
1476 return error.TestFailed;1504 return error.TestFailed;
1477 },1505 },
1478 else => {1506 else => {
1479 warn("Compilation terminated unexpectedly\n");1507 warn("Compilation terminated unexpectedly\n", .{});
1480 printInvocation(zig_args.toSliceConst());1508 printInvocation(zig_args.toSliceConst());
1481 return error.TestFailed;1509 return error.TestFailed;
1482 },1510 },
...@@ -1491,7 +1519,7 @@ pub const TranslateCContext = struct {...@@ -1491,7 +1519,7 @@ pub const TranslateCContext = struct {
1491 \\{}1519 \\{}
1492 \\============================================1520 \\============================================
1493 \\1521 \\
1494 , stderr);1522 , .{stderr});
1495 printInvocation(zig_args.toSliceConst());1523 printInvocation(zig_args.toSliceConst());
1496 return error.TestFailed;1524 return error.TestFailed;
1497 }1525 }
...@@ -1505,20 +1533,20 @@ pub const TranslateCContext = struct {...@@ -1505,20 +1533,20 @@ pub const TranslateCContext = struct {
1505 \\========= But found: ===========================1533 \\========= But found: ===========================
1506 \\{}1534 \\{}
1507 \\1535 \\
1508 , expected_line, stdout);1536 , .{ expected_line, stdout });
1509 printInvocation(zig_args.toSliceConst());1537 printInvocation(zig_args.toSliceConst());
1510 return error.TestFailed;1538 return error.TestFailed;
1511 }1539 }
1512 }1540 }
1513 warn("OK\n");1541 warn("OK\n", .{});
1514 }1542 }
1515 };1543 };
15161544
1517 fn printInvocation(args: []const []const u8) void {1545 fn printInvocation(args: []const []const u8) void {
1518 for (args) |arg| {1546 for (args) |arg| {
1519 warn("{} ", arg);1547 warn("{} ", .{arg});
1520 }1548 }
1521 warn("\n");1549 warn("\n", .{});
1522 }1550 }
15231551
1524 pub fn create(self: *TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {1552 pub fn create(self: *TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
...@@ -1586,7 +1614,7 @@ pub const TranslateCContext = struct {...@@ -1586,7 +1614,7 @@ pub const TranslateCContext = struct {
1586 const b = self.b;1614 const b = self.b;
15871615
1588 const translate_c_cmd = if (case.stage2) "translate-c-2" else "translate-c";1616 const translate_c_cmd = if (case.stage2) "translate-c-2" else "translate-c";
1589 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {}", translate_c_cmd, case.name) catch unreachable;1617 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {}", .{ translate_c_cmd, case.name }) catch unreachable;
1590 if (self.test_filter) |filter| {1618 if (self.test_filter) |filter| {
1591 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;1619 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
1592 }1620 }
...@@ -1666,7 +1694,7 @@ pub const GenHContext = struct {...@@ -1666,7 +1694,7 @@ pub const GenHContext = struct {
1666 const self = @fieldParentPtr(GenHCmpOutputStep, "step", step);1694 const self = @fieldParentPtr(GenHCmpOutputStep, "step", step);
1667 const b = self.context.b;1695 const b = self.context.b;
16681696
1669 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);1697 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
16701698
1671 const full_h_path = self.obj.getOutputHPath();1699 const full_h_path = self.obj.getOutputHPath();
1672 const actual_h = try io.readFileAlloc(b.allocator, full_h_path);1700 const actual_h = try io.readFileAlloc(b.allocator, full_h_path);
...@@ -1680,19 +1708,19 @@ pub const GenHContext = struct {...@@ -1680,19 +1708,19 @@ pub const GenHContext = struct {
1680 \\========= But found: ===========================1708 \\========= But found: ===========================
1681 \\{}1709 \\{}
1682 \\1710 \\
1683 , expected_line, actual_h);1711 , .{ expected_line, actual_h });
1684 return error.TestFailed;1712 return error.TestFailed;
1685 }1713 }
1686 }1714 }
1687 warn("OK\n");1715 warn("OK\n", .{});
1688 }1716 }
1689 };1717 };
16901718
1691 fn printInvocation(args: []const []const u8) void {1719 fn printInvocation(args: []const []const u8) void {
1692 for (args) |arg| {1720 for (args) |arg| {
1693 warn("{} ", arg);1721 warn("{} ", .{arg});
1694 }1722 }
1695 warn("\n");1723 warn("\n", .{});
1696 }1724 }
16971725
1698 pub fn create(self: *GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {1726 pub fn create(self: *GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
...@@ -1724,7 +1752,7 @@ pub const GenHContext = struct {...@@ -1724,7 +1752,7 @@ pub const GenHContext = struct {
1724 ) catch unreachable;1752 ) catch unreachable;
17251753
1726 const mode = builtin.Mode.Debug;1754 const mode = builtin.Mode.Debug;
1727 const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {} ({})", case.name, @tagName(mode)) catch unreachable;1755 const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {} ({})", .{ case.name, @tagName(mode) }) catch unreachable;
1728 if (self.test_filter) |filter| {1756 if (self.test_filter) |filter| {
1729 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;1757 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
1730 }1758 }
...@@ -1749,7 +1777,7 @@ pub const GenHContext = struct {...@@ -1749,7 +1777,7 @@ pub const GenHContext = struct {
17491777
1750fn printInvocation(args: []const []const u8) void {1778fn printInvocation(args: []const []const u8) void {
1751 for (args) |arg| {1779 for (args) |arg| {
1752 warn("{} ", arg);1780 warn("{} ", .{arg});
1753 }1781 }
1754 warn("\n");1782 warn("\n", .{});
1755}1783}