| author | |
| committer | |
| log | 691afee786d095fef2a7abed73efa035feef3f4e |
| tree | d8bf25bd5d2c833bd0b277d16228dec4eb6670fd |
| parent | 33e302d67a80fe7d213b4c461dc41c91813db869 |
6 files changed, 61 insertions(+), 50 deletions(-)
doc/langref/bad_default_value.zig+1-1| ... | ... | @@ -17,7 +17,7 @@ pub fn main() !void { |
| 17 | 17 | .maximum = 0.20, |
| 18 | 18 | }; |
| 19 | 19 | const category = threshold.categorize(0.90); |
| 20 | try std.fs.File.stdout().writeAll(@tagName(category)); | |
| 20 | std.log.info("category: {t}", .{category}); | |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | const std = @import("std"); |
doc/langref/hello.zig+11-1| ... | ... | @@ -1,7 +1,17 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | |
| 3 | // See https://github.com/ziglang/zig/issues/24510 | |
| 4 | // for the plan to simplify this code. | |
| 3 | 5 | pub fn main() !void { |
| 4 | try std.fs.File.stdout().writeAll("Hello, World!\n"); | |
| 6 | var debug_allocator: std.heap.DebugAllocator(.{}) = .init; | |
| 7 | defer _ = debug_allocator.deinit(); | |
| 8 | const gpa = debug_allocator.allocator(); | |
| 9 | ||
| 10 | var threaded: std.Io.Threaded = .init(gpa, .{}); | |
| 11 | defer threaded.deinit(); | |
| 12 | const io = threaded.io(); | |
| 13 | ||
| 14 | try std.Io.File.stdout().writeStreamingAll(io, "Hello, World!\n"); | |
| 5 | 15 | } |
| 6 | 16 | |
| 7 | 17 | // exe=succeed |
lib/compiler/aro/aro/Compilation.zig+2-1| ... | ... | @@ -1713,7 +1713,8 @@ pub fn initSearchPath(comp: *Compilation, includes: []const Include, verbose: bo |
| 1713 | 1713 | } |
| 1714 | 1714 | } |
| 1715 | 1715 | fn addToSearchPath(comp: *Compilation, include: Include, verbose: bool) !void { |
| 1716 | comp.cwd.access(include.path, .{}) catch { | |
| 1716 | const io = comp.io; | |
| 1717 | comp.cwd.access(io, include.path, .{}) catch { | |
| 1717 | 1718 | if (verbose) { |
| 1718 | 1719 | std.debug.print("ignoring nonexistent directory \"{s}\"\n", .{include.path}); |
| 1719 | 1720 | return; |
lib/compiler/translate-c/main.zig+9-6| ... | ... | @@ -34,11 +34,14 @@ pub fn main() u8 { |
| 34 | 34 | zig_integration = true; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | const NO_COLOR = std.zig.EnvVar.NO_COLOR.isSet(); | |
| 38 | const CLICOLOR_FORCE = std.zig.EnvVar.CLICOLOR_FORCE.isSet(); | |
| 39 | ||
| 37 | 40 | var stderr_buf: [1024]u8 = undefined; |
| 38 | 41 | var stderr = Io.File.stderr().writer(io, &stderr_buf); |
| 39 | 42 | var diagnostics: aro.Diagnostics = switch (zig_integration) { |
| 40 | 43 | false => .{ .output = .{ .to_writer = .{ |
| 41 | .color = .detect(stderr.file), | |
| 44 | .mode = Io.Terminal.Mode.detect(io, stderr.file, NO_COLOR, CLICOLOR_FORCE) catch unreachable, | |
| 42 | 45 | .writer = &stderr.interface, |
| 43 | 46 | } } }, |
| 44 | 47 | true => .{ .output = .{ .to_list = .{ |
| ... | ... | @@ -69,7 +72,7 @@ pub fn main() u8 { |
| 69 | 72 | return 1; |
| 70 | 73 | }, |
| 71 | 74 | error.FatalError => if (zig_integration) { |
| 72 | serveErrorBundle(arena, &diagnostics) catch |bundle_err| { | |
| 75 | serveErrorBundle(arena, io, &diagnostics) catch |bundle_err| { | |
| 73 | 76 | std.debug.print("unable to serve error bundle: {}\n", .{bundle_err}); |
| 74 | 77 | if (fast_exit) process.exit(1); |
| 75 | 78 | return 1; |
| ... | ... | @@ -93,14 +96,14 @@ pub fn main() u8 { |
| 93 | 96 | return @intFromBool(comp.diagnostics.errors != 0); |
| 94 | 97 | } |
| 95 | 98 | |
| 96 | fn serveErrorBundle(arena: std.mem.Allocator, diagnostics: *const aro.Diagnostics) !void { | |
| 99 | fn serveErrorBundle(arena: std.mem.Allocator, io: Io, diagnostics: *const aro.Diagnostics) !void { | |
| 97 | 100 | const error_bundle = try compiler_util.aroDiagnosticsToErrorBundle( |
| 98 | 101 | diagnostics, |
| 99 | 102 | arena, |
| 100 | 103 | "translation failure", |
| 101 | 104 | ); |
| 102 | 105 | var stdout_buffer: [1024]u8 = undefined; |
| 103 | var stdout_writer = Io.File.stdout().writer(&stdout_buffer); | |
| 106 | var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer); | |
| 104 | 107 | var server: std.zig.Server = .{ |
| 105 | 108 | .out = &stdout_writer.interface, |
| 106 | 109 | .in = undefined, |
| ... | ... | @@ -130,13 +133,13 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration |
| 130 | 133 | args[i] = arg; |
| 131 | 134 | if (mem.eql(u8, arg, "--help")) { |
| 132 | 135 | var stdout_buf: [512]u8 = undefined; |
| 133 | var stdout = Io.File.stdout().writer(&stdout_buf); | |
| 136 | var stdout = Io.File.stdout().writer(io, &stdout_buf); | |
| 134 | 137 | try stdout.interface.print(usage, .{args[0]}); |
| 135 | 138 | try stdout.interface.flush(); |
| 136 | 139 | return; |
| 137 | 140 | } else if (mem.eql(u8, arg, "--version")) { |
| 138 | 141 | var stdout_buf: [512]u8 = undefined; |
| 139 | var stdout = Io.File.stdout().writer(&stdout_buf); | |
| 142 | var stdout = Io.File.stdout().writer(io, &stdout_buf); | |
| 140 | 143 | // TODO add version |
| 141 | 144 | try stdout.interface.writeAll("0.0.0-dev\n"); |
| 142 | 145 | try stdout.interface.flush(); |
tools/docgen.zig+14-12| ... | ... | @@ -1,6 +1,8 @@ |
| 1 | const std = @import("std"); | |
| 2 | 1 | const builtin = @import("builtin"); |
| 3 | const fs = std.fs; | |
| 2 | ||
| 3 | const std = @import("std"); | |
| 4 | const Io = std.Io; | |
| 5 | const Dir = std.Io.Dir; | |
| 4 | 6 | const process = std.process; |
| 5 | 7 | const Progress = std.Progress; |
| 6 | 8 | const print = std.debug.print; |
| ... | ... | @@ -8,7 +10,6 @@ const mem = std.mem; |
| 8 | 10 | const testing = std.testing; |
| 9 | 11 | const Allocator = std.mem.Allocator; |
| 10 | 12 | const ArrayList = std.ArrayList; |
| 11 | const getExternalExecutor = std.zig.system.getExternalExecutor; | |
| 12 | 13 | const fatal = std.process.fatal; |
| 13 | 14 | const Writer = std.Io.Writer; |
| 14 | 15 | |
| ... | ... | @@ -49,7 +50,7 @@ pub fn main() !void { |
| 49 | 50 | while (args_it.next()) |arg| { |
| 50 | 51 | if (mem.startsWith(u8, arg, "-")) { |
| 51 | 52 | if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { |
| 52 | try fs.File.stdout().writeAll(usage); | |
| 53 | try Io.File.stdout().writeStreamingAll(io, usage); | |
| 53 | 54 | process.exit(0); |
| 54 | 55 | } else if (mem.eql(u8, arg, "--code-dir")) { |
| 55 | 56 | if (args_it.next()) |param| { |
| ... | ... | @@ -72,15 +73,15 @@ pub fn main() !void { |
| 72 | 73 | const output_path = opt_output orelse fatal("missing output file", .{}); |
| 73 | 74 | const code_dir_path = opt_code_dir orelse fatal("missing --code-dir argument", .{}); |
| 74 | 75 | |
| 75 | var in_file = try fs.cwd().openFile(input_path, .{}); | |
| 76 | var in_file = try Dir.cwd().openFile(io, input_path, .{}); | |
| 76 | 77 | defer in_file.close(io); |
| 77 | 78 | |
| 78 | var out_file = try fs.cwd().createFile(output_path, .{}); | |
| 79 | var out_file = try Dir.cwd().createFile(io, output_path, .{}); | |
| 79 | 80 | defer out_file.close(io); |
| 80 | 81 | var out_file_buffer: [4096]u8 = undefined; |
| 81 | var out_file_writer = out_file.writer(&out_file_buffer); | |
| 82 | var out_file_writer = out_file.writer(io, &out_file_buffer); | |
| 82 | 83 | |
| 83 | var code_dir = try fs.cwd().openDir(code_dir_path, .{}); | |
| 84 | var code_dir = try Dir.cwd().openDir(io, code_dir_path, .{}); | |
| 84 | 85 | defer code_dir.close(io); |
| 85 | 86 | |
| 86 | 87 | var in_file_reader = in_file.reader(io, &.{}); |
| ... | ... | @@ -89,7 +90,7 @@ pub fn main() !void { |
| 89 | 90 | var tokenizer = Tokenizer.init(input_path, input_file_bytes); |
| 90 | 91 | var toc = try genToc(arena, &tokenizer); |
| 91 | 92 | |
| 92 | try genHtml(arena, &tokenizer, &toc, code_dir, &out_file_writer.interface); | |
| 93 | try genHtml(arena, io, &tokenizer, &toc, code_dir, &out_file_writer.interface); | |
| 93 | 94 | try out_file_writer.end(); |
| 94 | 95 | } |
| 95 | 96 | |
| ... | ... | @@ -988,9 +989,10 @@ fn printShell(out: *Writer, shell_content: []const u8, escape: bool) !void { |
| 988 | 989 | |
| 989 | 990 | fn genHtml( |
| 990 | 991 | allocator: Allocator, |
| 992 | io: Io, | |
| 991 | 993 | tokenizer: *Tokenizer, |
| 992 | 994 | toc: *Toc, |
| 993 | code_dir: std.fs.Dir, | |
| 995 | code_dir: Dir, | |
| 994 | 996 | out: *Writer, |
| 995 | 997 | ) !void { |
| 996 | 998 | for (toc.nodes) |node| { |
| ... | ... | @@ -1042,11 +1044,11 @@ fn genHtml( |
| 1042 | 1044 | }, |
| 1043 | 1045 | .Code => |code| { |
| 1044 | 1046 | const out_basename = try std.fmt.allocPrint(allocator, "{s}.out", .{ |
| 1045 | fs.path.stem(code.name), | |
| 1047 | Dir.path.stem(code.name), | |
| 1046 | 1048 | }); |
| 1047 | 1049 | defer allocator.free(out_basename); |
| 1048 | 1050 | |
| 1049 | const contents = code_dir.readFileAlloc(out_basename, allocator, .limited(std.math.maxInt(u32))) catch |err| { | |
| 1051 | const contents = code_dir.readFileAlloc(io, out_basename, allocator, .limited(std.math.maxInt(u32))) catch |err| { | |
| 1050 | 1052 | return parseError(tokenizer, code.token, "unable to open '{s}': {t}", .{ out_basename, err }); |
| 1051 | 1053 | }; |
| 1052 | 1054 | defer allocator.free(contents); |
tools/doctest.zig+24-29| ... | ... | @@ -2,10 +2,10 @@ const builtin = @import("builtin"); |
| 2 | 2 | |
| 3 | 3 | const std = @import("std"); |
| 4 | 4 | const Io = std.Io; |
| 5 | const Dir = std.Io.Dir; | |
| 5 | 6 | const Writer = std.Io.Writer; |
| 6 | 7 | const fatal = std.process.fatal; |
| 7 | 8 | const mem = std.mem; |
| 8 | const fs = std.fs; | |
| 9 | 9 | const process = std.process; |
| 10 | 10 | const Allocator = std.mem.Allocator; |
| 11 | 11 | const testing = std.testing; |
| ... | ... | @@ -53,7 +53,7 @@ pub fn main() !void { |
| 53 | 53 | while (args_it.next()) |arg| { |
| 54 | 54 | if (mem.startsWith(u8, arg, "-")) { |
| 55 | 55 | if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { |
| 56 | try std.fs.File.stdout().writeAll(usage); | |
| 56 | try Io.File.stdout().writeStreamingAll(io, usage); | |
| 57 | 57 | process.exit(0); |
| 58 | 58 | } else if (mem.eql(u8, arg, "-i")) { |
| 59 | 59 | opt_input = args_it.next() orelse fatal("expected parameter after -i", .{}); |
| ... | ... | @@ -78,37 +78,37 @@ pub fn main() !void { |
| 78 | 78 | const zig_path = opt_zig orelse fatal("missing zig compiler path (--zig)", .{}); |
| 79 | 79 | const cache_root = opt_cache_root orelse fatal("missing cache root path (--cache-root)", .{}); |
| 80 | 80 | |
| 81 | const source_bytes = try fs.cwd().readFileAlloc(input_path, arena, .limited(std.math.maxInt(u32))); | |
| 81 | const source_bytes = try Dir.cwd().readFileAlloc(io, input_path, arena, .limited(std.math.maxInt(u32))); | |
| 82 | 82 | const code = try parseManifest(arena, source_bytes); |
| 83 | 83 | const source = stripManifest(source_bytes); |
| 84 | 84 | |
| 85 | 85 | const tmp_dir_path = try std.fmt.allocPrint(arena, "{s}/tmp/{x}", .{ |
| 86 | 86 | cache_root, std.crypto.random.int(u64), |
| 87 | 87 | }); |
| 88 | fs.cwd().createDirPath(io, tmp_dir_path) catch |err| | |
| 88 | Dir.cwd().createDirPath(io, tmp_dir_path) catch |err| | |
| 89 | 89 | fatal("unable to create tmp dir '{s}': {t}", .{ tmp_dir_path, err }); |
| 90 | defer fs.cwd().deleteTree(io, tmp_dir_path) catch |err| std.log.err("unable to delete '{s}': {t}", .{ | |
| 90 | defer Dir.cwd().deleteTree(io, tmp_dir_path) catch |err| std.log.err("unable to delete '{s}': {t}", .{ | |
| 91 | 91 | tmp_dir_path, err, |
| 92 | 92 | }); |
| 93 | 93 | |
| 94 | var out_file = try fs.cwd().createFile(io, output_path, .{}); | |
| 94 | var out_file = try Dir.cwd().createFile(io, output_path, .{}); | |
| 95 | 95 | defer out_file.close(io); |
| 96 | 96 | var out_file_buffer: [4096]u8 = undefined; |
| 97 | 97 | var out_file_writer = out_file.writer(io, &out_file_buffer); |
| 98 | 98 | |
| 99 | 99 | const out = &out_file_writer.interface; |
| 100 | 100 | |
| 101 | try printSourceBlock(arena, out, source, fs.path.basename(input_path)); | |
| 101 | try printSourceBlock(arena, out, source, Dir.path.basename(input_path)); | |
| 102 | 102 | try printOutput( |
| 103 | 103 | arena, |
| 104 | 104 | io, |
| 105 | 105 | out, |
| 106 | 106 | code, |
| 107 | 107 | tmp_dir_path, |
| 108 | try std.fs.path.relative(arena, tmp_dir_path, zig_path), | |
| 109 | try std.fs.path.relative(arena, tmp_dir_path, input_path), | |
| 108 | try Dir.path.relative(arena, tmp_dir_path, zig_path), | |
| 109 | try Dir.path.relative(arena, tmp_dir_path, input_path), | |
| 110 | 110 | if (opt_zig_lib_dir) |zig_lib_dir| |
| 111 | try std.fs.path.relative(arena, tmp_dir_path, zig_lib_dir) | |
| 111 | try Dir.path.relative(arena, tmp_dir_path, zig_lib_dir) | |
| 112 | 112 | else |
| 113 | 113 | null, |
| 114 | 114 | ); |
| ... | ... | @@ -141,7 +141,7 @@ fn printOutput( |
| 141 | 141 | defer shell_buffer.deinit(); |
| 142 | 142 | const shell_out = &shell_buffer.writer; |
| 143 | 143 | |
| 144 | const code_name = std.fs.path.stem(input_path); | |
| 144 | const code_name = Dir.path.stem(input_path); | |
| 145 | 145 | |
| 146 | 146 | switch (code.id) { |
| 147 | 147 | .exe => |expected_outcome| code_block: { |
| ... | ... | @@ -201,8 +201,7 @@ fn printOutput( |
| 201 | 201 | try shell_out.print("\n", .{}); |
| 202 | 202 | |
| 203 | 203 | if (expected_outcome == .build_fail) { |
| 204 | const result = try process.Child.run(.{ | |
| 205 | .allocator = arena, | |
| 204 | const result = try process.Child.run(arena, io, .{ | |
| 206 | 205 | .argv = build_args.items, |
| 207 | 206 | .cwd = tmp_dir_path, |
| 208 | 207 | .env_map = &env_map, |
| ... | ... | @@ -227,7 +226,7 @@ fn printOutput( |
| 227 | 226 | try shell_out.writeAll(colored_stderr); |
| 228 | 227 | break :code_block; |
| 229 | 228 | } |
| 230 | const exec_result = run(arena, &env_map, tmp_dir_path, build_args.items) catch | |
| 229 | const exec_result = run(arena, io, &env_map, tmp_dir_path, build_args.items) catch | |
| 231 | 230 | fatal("example failed to compile", .{}); |
| 232 | 231 | |
| 233 | 232 | if (code.verbose_cimport) { |
| ... | ... | @@ -258,8 +257,7 @@ fn printOutput( |
| 258 | 257 | var exited_with_signal = false; |
| 259 | 258 | |
| 260 | 259 | const result = if (expected_outcome == .fail) blk: { |
| 261 | const result = try process.Child.run(.{ | |
| 262 | .allocator = arena, | |
| 260 | const result = try process.Child.run(arena, io, .{ | |
| 263 | 261 | .argv = run_args, |
| 264 | 262 | .env_map = &env_map, |
| 265 | 263 | .cwd = tmp_dir_path, |
| ... | ... | @@ -278,7 +276,7 @@ fn printOutput( |
| 278 | 276 | } |
| 279 | 277 | break :blk result; |
| 280 | 278 | } else blk: { |
| 281 | break :blk run(arena, &env_map, tmp_dir_path, run_args) catch | |
| 279 | break :blk run(arena, io, &env_map, tmp_dir_path, run_args) catch | |
| 282 | 280 | fatal("example crashed", .{}); |
| 283 | 281 | }; |
| 284 | 282 | |
| ... | ... | @@ -327,7 +325,7 @@ fn printOutput( |
| 327 | 325 | .arch_os_abi = triple, |
| 328 | 326 | }); |
| 329 | 327 | const target = try std.zig.system.resolveTargetQuery(io, target_query); |
| 330 | switch (getExternalExecutor(&host, &target, .{ | |
| 328 | switch (getExternalExecutor(io, &host, &target, .{ | |
| 331 | 329 | .link_libc = code.link_libc, |
| 332 | 330 | })) { |
| 333 | 331 | .native => {}, |
| ... | ... | @@ -347,7 +345,7 @@ fn printOutput( |
| 347 | 345 | } |
| 348 | 346 | } |
| 349 | 347 | |
| 350 | const result = run(arena, &env_map, tmp_dir_path, test_args.items) catch | |
| 348 | const result = run(arena, io, &env_map, tmp_dir_path, test_args.items) catch | |
| 351 | 349 | fatal("test failed", .{}); |
| 352 | 350 | const escaped_stderr = try escapeHtml(arena, result.stderr); |
| 353 | 351 | const escaped_stdout = try escapeHtml(arena, result.stdout); |
| ... | ... | @@ -378,8 +376,7 @@ fn printOutput( |
| 378 | 376 | try test_args.append("-lc"); |
| 379 | 377 | try shell_out.print("-lc ", .{}); |
| 380 | 378 | } |
| 381 | const result = try process.Child.run(.{ | |
| 382 | .allocator = arena, | |
| 379 | const result = try process.Child.run(arena, io, .{ | |
| 383 | 380 | .argv = test_args.items, |
| 384 | 381 | .env_map = &env_map, |
| 385 | 382 | .cwd = tmp_dir_path, |
| ... | ... | @@ -435,8 +432,7 @@ fn printOutput( |
| 435 | 432 | }, |
| 436 | 433 | } |
| 437 | 434 | |
| 438 | const result = try process.Child.run(.{ | |
| 439 | .allocator = arena, | |
| 435 | const result = try process.Child.run(arena, io, .{ | |
| 440 | 436 | .argv = test_args.items, |
| 441 | 437 | .env_map = &env_map, |
| 442 | 438 | .cwd = tmp_dir_path, |
| ... | ... | @@ -512,8 +508,7 @@ fn printOutput( |
| 512 | 508 | } |
| 513 | 509 | |
| 514 | 510 | if (maybe_error_match) |error_match| { |
| 515 | const result = try process.Child.run(.{ | |
| 516 | .allocator = arena, | |
| 511 | const result = try process.Child.run(arena, io, .{ | |
| 517 | 512 | .argv = build_args.items, |
| 518 | 513 | .env_map = &env_map, |
| 519 | 514 | .cwd = tmp_dir_path, |
| ... | ... | @@ -541,7 +536,7 @@ fn printOutput( |
| 541 | 536 | const colored_stderr = try termColor(arena, escaped_stderr); |
| 542 | 537 | try shell_out.print("\n{s} ", .{colored_stderr}); |
| 543 | 538 | } else { |
| 544 | _ = run(arena, &env_map, tmp_dir_path, build_args.items) catch fatal("example failed to compile", .{}); | |
| 539 | _ = run(arena, io, &env_map, tmp_dir_path, build_args.items) catch fatal("example failed to compile", .{}); | |
| 545 | 540 | } |
| 546 | 541 | try shell_out.writeAll("\n"); |
| 547 | 542 | }, |
| ... | ... | @@ -600,7 +595,7 @@ fn printOutput( |
| 600 | 595 | try test_args.append(option); |
| 601 | 596 | try shell_out.print("{s} ", .{option}); |
| 602 | 597 | } |
| 603 | const result = run(arena, &env_map, tmp_dir_path, test_args.items) catch fatal("test failed", .{}); | |
| 598 | const result = run(arena, io, &env_map, tmp_dir_path, test_args.items) catch fatal("test failed", .{}); | |
| 604 | 599 | const escaped_stderr = try escapeHtml(arena, result.stderr); |
| 605 | 600 | const escaped_stdout = try escapeHtml(arena, result.stdout); |
| 606 | 601 | try shell_out.print("\n{s}{s}\n", .{ escaped_stderr, escaped_stdout }); |
| ... | ... | @@ -1132,12 +1127,12 @@ fn in(slice: []const u8, number: u8) bool { |
| 1132 | 1127 | |
| 1133 | 1128 | fn run( |
| 1134 | 1129 | allocator: Allocator, |
| 1130 | io: Io, | |
| 1135 | 1131 | env_map: *process.EnvMap, |
| 1136 | 1132 | cwd: []const u8, |
| 1137 | 1133 | args: []const []const u8, |
| 1138 | 1134 | ) !process.Child.RunResult { |
| 1139 | const result = try process.Child.run(.{ | |
| 1140 | .allocator = allocator, | |
| 1135 | const result = try process.Child.run(allocator, io, .{ | |
| 1141 | 1136 | .argv = args, |
| 1142 | 1137 | .env_map = env_map, |
| 1143 | 1138 | .cwd = cwd, |