From 9d802c755c22f8612b6933da99998e7ddae14886 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 3 May 2026 15:25:50 +0900 Subject: update zig to 0.16 --- src/jq/execute.zig | 4 ++-- src/jq/saveable_stack.zig | 4 ++-- src/jv/value.zig | 4 ++-- src/main.zig | 24 +++++++++++++----------- 4 files changed, 19 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/jq/execute.zig b/src/jq/execute.zig index cee7845..30dabe1 100644 --- a/src/jq/execute.zig +++ b/src/jq/execute.zig @@ -156,11 +156,11 @@ pub const Runtime = struct { return .{ .allocator = allocator, .values = try ValueStack.init(allocator), - .forks = .{}, + .forks = .empty, .instrs = &[_]Instr{}, .pc = 0, .constants = constants, - .variables = .{}, + .variables = .empty, }; } diff --git a/src/jq/saveable_stack.zig b/src/jq/saveable_stack.zig index f3a0b40..6bf2c77 100644 --- a/src/jq/saveable_stack.zig +++ b/src/jq/saveable_stack.zig @@ -67,9 +67,9 @@ pub fn SaveableStack(comptime T: type) type { pub fn init(allocator: std.mem.Allocator) !Self { var stack = Self{ - .segments = .{}, + .segments = .empty, .active_segment_index = 0, - .savepoints = .{}, + .savepoints = .empty, .allocator = allocator, }; diff --git a/src/jv/value.zig b/src/jv/value.zig index eb36c99..f22c44b 100644 --- a/src/jv/value.zig +++ b/src/jv/value.zig @@ -104,7 +104,7 @@ pub const Array = struct { rc: Rc(Inner), pub fn init(allocator: std.mem.Allocator) !Array { - return .{ .rc = try Rc(Inner).init(allocator, .{}) }; + return .{ .rc = try Rc(Inner).init(allocator, .empty) }; } pub fn clone(self: Array) Array { @@ -141,7 +141,7 @@ pub const Array = struct { fn ensureUnique(self: *Array, allocator: std.mem.Allocator) !void { if (!self.rc.isUnique()) { const old_items = self.rc.get().items; - var new_inner: Inner = .{}; + var new_inner: Inner = .empty; try new_inner.ensureTotalCapacity(allocator, old_items.len); for (old_items) |item| { new_inner.appendAssumeCapacity(item.clone()); diff --git a/src/main.zig b/src/main.zig index 51b2262..40a18ba 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2,11 +2,11 @@ const std = @import("std"); const jq = @import("zgjq").jq; const jv = @import("zgjq").jv; -pub fn main() !void { - const allocator = std.heap.smp_allocator; +pub fn main(init: std.process.Init) !void { + const allocator = init.gpa; - const args = try std.process.argsAlloc(allocator); - defer std.process.argsFree(allocator, args); + const args = try init.minimal.args.toSlice(allocator); + defer allocator.free(args); var debug_dump_disasm = false; var query: ?[]const u8 = null; @@ -19,11 +19,13 @@ pub fn main() !void { } if (query == null) { - try std.fs.File.stderr().writeAll("usage: zgjq [--debug-dump-disasm] \n"); + try std.Io.File.stderr().writeStreamingAll(init.io, "usage: zgjq [--debug-dump-disasm] \n"); std.process.exit(1); } - const input = try std.fs.File.stdin().readToEndAlloc(allocator, std.math.maxInt(usize)); + var stdin_buf: [4096]u8 = undefined; + var stdin_reader = std.Io.File.stdin().reader(init.io, &stdin_buf); + const input = try stdin_reader.interface.allocRemaining(allocator, std.Io.Limit.unlimited); defer allocator.free(input); const parsed = try jv.parse(allocator, input); @@ -35,19 +37,19 @@ pub fn main() !void { try runtime.compileFromSlice(query.?); if (debug_dump_disasm) { - var buf: [4096]u8 = undefined; - var stderr = std.fs.File.stderr().writer(&buf); + var stderr_buf: [4096]u8 = undefined; + var stderr = std.Io.File.stderr().writer(init.io, &stderr_buf); try runtime.dumpDisasm(&stderr.interface); try stderr.interface.flush(); } try runtime.start(json); - const stdout = std.fs.File.stdout(); + const stdout = std.Io.File.stdout(); while (try runtime.next()) |result| { const output = try jv.stringify(allocator, result); defer allocator.free(output); - try stdout.writeAll(output); - try stdout.writeAll("\n"); + try stdout.writeStreamingAll(init.io, output); + try stdout.writeStreamingAll(init.io, "\n"); } } -- cgit v1.3.1