diff options
author | Julien Dessaux | 2024-11-22 09:27:23 +0100 |
---|---|---|
committer | Julien Dessaux | 2024-11-22 09:28:09 +0100 |
commit | 06468c1272035fcacf6d46a80b5738b55cffae38 (patch) | |
tree | 55ae36dc5c9d25cbf73da49c6bd6c887fe79605f | |
parent | Removed useless testing boilerplate (diff) | |
download | zigfunge98-master.tar.gz zigfunge98-master.tar.bz2 zigfunge98-master.zip |
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | build.zig | 14 | ||||
m--------- | lib/spoon | 0 | ||||
-rw-r--r-- | src/field.zig | 26 | ||||
-rw-r--r-- | src/io.zig | 6 | ||||
-rw-r--r-- | src/main.zig | 6 | ||||
-rw-r--r-- | src/pointer.zig | 4 | ||||
-rw-r--r-- | src/tui.zig | 18 |
8 files changed, 39 insertions, 37 deletions
@@ -17,7 +17,7 @@ Current limitations are : ## Dependencies -zig is required. Only zig version 0.11 on linux amd64 (Gentoo) is being regularly tested. +zig is required. Only zig version 0.13 on linux amd64 (Gentoo) is being regularly tested. ## Quick Install @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "zigfunge98", - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); @@ -19,7 +19,7 @@ pub fn build(b: *std.Build) void { const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); const unit_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); @@ -34,7 +34,7 @@ pub fn build(b: *std.Build) void { const exclude = std.fmt.allocPrint(gpa, "--exclude-path={s}/.zig/", .{home}) catch ""; defer gpa.free(exclude); if (coverage) { - unit_tests.test_runner = "/usr/bin/kcov"; + unit_tests.test_runner = b.path("/usr/bin/kcov"); unit_tests.setExecCmd(&[_]?[]const u8{ "kcov", exclude, @@ -51,14 +51,14 @@ pub fn build(b: *std.Build) void { // ----- TUI -------------------------------------------------------------- const tui = b.addExecutable(.{ .name = "zigfunge98-tui", - .root_source_file = .{ .path = "src/tui.zig" }, + .root_source_file = b.path("src/tui.zig"), .target = target, .optimize = optimize, }); const spoon = b.createModule(.{ - .source_file = .{ .path = "lib/spoon/import.zig" }, + .root_source_file = b.path("lib/spoon/import.zig"), }); - tui.addModule("spoon", spoon); + tui.root_module.addImport("spoon", spoon); b.installArtifact(tui); const tui_cmd = b.addRunArtifact(tui); tui_cmd.step.dependOn(b.getInstallStep()); @@ -68,7 +68,7 @@ pub fn build(b: *std.Build) void { const tui_step = b.step("run-tui", "Run the app"); tui_step.dependOn(&tui_cmd.step); const tui_unit_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/tui.zig" }, + .root_source_file = b.path("src/tui.zig"), .target = target, .optimize = optimize, }); diff --git a/lib/spoon b/lib/spoon -Subproject 9fa5bb1eafc30b3ff0cbe297a3e0f51dbc90383 +Subproject 3e6c5ab4617e1869c2781e698e14cd976135e99 diff --git a/src/field.zig b/src/field.zig index 079bb81..6062e3c 100644 --- a/src/field.zig +++ b/src/field.zig @@ -1,5 +1,7 @@ const std = @import("std"); +const position = struct { x: i64, y: i64 }; + const Line = struct { allocator: std.mem.Allocator, x: i64 = 0, @@ -16,7 +18,7 @@ const Line = struct { var i: usize = 1; while (l.data.items[i] == ' ') : (i += 1) {} l.x += @intCast(i); - std.mem.copy(i64, l.data.items[0 .. l.len() - i], l.data.items[i..]); + std.mem.copyForwards(i64, l.data.items[0 .. l.len() - i], l.data.items[i..]); l.data.items.len -= i; } else { // we need to remove trailing spaces var i: usize = l.len() - 1; @@ -168,7 +170,7 @@ pub const Field = struct { f.lines.items[i].deinit(); } f.y += @intCast(i); - std.mem.copy(*Line, f.lines.items[0 .. f.lines.items.len - i], f.lines.items[i..]); + std.mem.copyForwards(*Line, f.lines.items[0 .. f.lines.items.len - i], f.lines.items[i..]); f.lines.items.len -= i; } else if (y == f.y + lly - 1) { // we need to remove trailing lines l.deinit(); @@ -259,7 +261,7 @@ pub const Field = struct { f.x = undefined; f.y = 0; f.lines = std.ArrayList(*Line).init(allocator); - var l = try f.lines.addOne(); + const l = try f.lines.addOne(); l.* = try Line.init(allocator); f.lx = 0; return f; @@ -282,7 +284,7 @@ pub const Field = struct { var y: i64 = 0; while (true) { var buffer: [4096]u8 = undefined; - var l = try reader.read(buffer[0..]); + const l = try reader.read(buffer[0..]); if (l == 0) return; var i: usize = 0; while (i < l) : (i += 1) { @@ -411,7 +413,7 @@ pub const Field = struct { try std.testing.expectEqual(f.get(8, 2), '2'); try std.testing.expectEqual(f.get(9, 2), ' '); } - pub fn step(f: *Field, x: i64, y: i64, dx: i64, dy: i64, smartAdvance: bool, jumping: bool) struct { x: i64, y: i64 } { + pub fn step(f: *Field, x: i64, y: i64, dx: i64, dy: i64, smartAdvance: bool, jumping: bool) position { var a = x + dx; var b = y + dy; if (!f.isIn(a, b)) { @@ -419,8 +421,8 @@ pub const Field = struct { a = x; b = y; while (true) { - var c = a - dx; - var d = b - dy; + const c = a - dx; + const d = b - dy; if (!f.isIn(c, d)) break; a = c; b = d; @@ -445,15 +447,15 @@ pub const Field = struct { var f = try Field.init(std.testing.allocator); defer f.deinit(); try f.load(minimal.reader()); - try std.testing.expectEqual(f.step(0, 0, 0, 0, false, false), .{ .x = 0, .y = 0 }); - try std.testing.expectEqual(f.step(0, 0, 1, 0, false, false), .{ .x = 0, .y = 0 }); + try std.testing.expectEqual(f.step(0, 0, 0, 0, false, false), @as(position, .{ .x = 0, .y = 0 })); + try std.testing.expectEqual(f.step(0, 0, 1, 0, false, false), @as(position, .{ .x = 0, .y = 0 })); var hello = std.io.fixedBufferStream("64+\"!dlroW ,olleH\">:#,_@\n"); var fHello = try Field.init(std.testing.allocator); defer fHello.deinit(); try fHello.load(hello.reader()); - try std.testing.expectEqual(fHello.step(3, 0, 0, 0, false, false), .{ .x = 3, .y = 0 }); - try std.testing.expectEqual(fHello.step(3, 0, 1, 0, false, false), .{ .x = 4, .y = 0 }); - try std.testing.expectEqual(fHello.step(0, 0, -1, 0, false, false), .{ .x = 23, .y = 0 }); + try std.testing.expectEqual(fHello.step(3, 0, 0, 0, false, false), @as(position, .{ .x = 3, .y = 0 })); + try std.testing.expectEqual(fHello.step(3, 0, 1, 0, false, false), @as(position, .{ .x = 4, .y = 0 })); + try std.testing.expectEqual(fHello.step(0, 0, -1, 0, false, false), @as(position, .{ .x = 23, .y = 0 })); } }; @@ -12,14 +12,14 @@ pub fn Context(comptime readerType: anytype, comptime writerType: anytype) type return c; } var buffer = [_]u8{0}; - var n = try self.reader.read(buffer[0..]); + const n = try self.reader.read(buffer[0..]); if (n == 1) { return buffer[0]; } return error.IOError; } test "characterInput" { - var stdin = std.io.fixedBufferStream("ab0"); + const stdin = std.io.fixedBufferStream("ab0"); var stdout = std.ArrayList(u8).init(std.testing.allocator); defer stdout.deinit(); var ioContext = context(stdin, stdout); @@ -49,7 +49,7 @@ pub fn Context(comptime readerType: anytype, comptime writerType: anytype) type return result; } test "decimalInput" { - var stdin = std.io.fixedBufferStream("1 234abc5d6ef"); + const stdin = std.io.fixedBufferStream("1 234abc5d6ef"); var stdout = std.ArrayList(u8).init(std.testing.allocator); defer stdout.deinit(); var ioContext = context(stdin, stdout); diff --git a/src/main.zig b/src/main.zig index 381a6cb..5872724 100644 --- a/src/main.zig +++ b/src/main.zig @@ -5,11 +5,11 @@ const io = @import("io.zig"); pub fn main() anyerror!void { var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; const gpa = general_purpose_allocator.allocator(); - var args = try std.process.argsAlloc(gpa); + const args = try std.process.argsAlloc(gpa); defer std.process.argsFree(gpa, args); if (args.len < 2) { std.debug.print("Usage: {s} <b98_file_to_run>\n", .{args[0]}); - std.os.exit(1); + std.posix.exit(1); } var file = try std.fs.cwd().openFile(args[1], .{}); @@ -20,7 +20,7 @@ pub fn main() anyerror!void { defer i.deinit(); var ioContext = io.context(std.io.getStdIn().reader(), std.io.getStdOut().writer()); - std.os.exit(@intCast(try i.run(&ioContext))); + std.posix.exit(@intCast(try i.run(&ioContext))); } const testTimestamp: i64 = 1660681247; diff --git a/src/pointer.zig b/src/pointer.zig index ce170af..fe6a526 100644 --- a/src/pointer.zig +++ b/src/pointer.zig @@ -44,7 +44,7 @@ pub const Pointer = struct { p.step(false); }, 'j' => { - var n = p.ss.toss.pop(); + const n = p.ss.toss.pop(); var j: usize = 0; if (n > 0) { while (j < n) : (j += 1) { @@ -379,7 +379,7 @@ pub const Pointer = struct { p.lastCharWasSpace = false; // Initializing the random number generator var seed: u64 = undefined; - try std.os.getrandom(std.mem.asBytes(&seed)); + try std.posix.getrandom(std.mem.asBytes(&seed)); p.rand = std.rand.DefaultPrng.init(seed); p.timestamp = timestamp; return p; diff --git a/src/tui.zig b/src/tui.zig index 8c4145f..55a848b 100644 --- a/src/tui.zig +++ b/src/tui.zig @@ -15,7 +15,7 @@ pub fn main() anyerror!void { defer std.process.argsFree(gpa, args); if (args.len < 2) { std.debug.print("Usage: {s} <b98_file_to_run>\n", .{args[0]}); - std.os.exit(1); + std.posix.exit(1); } var file = try std.fs.cwd().openFile(args[1], .{}); @@ -29,19 +29,19 @@ pub fn main() anyerror!void { //--- Term initialization ------------------------------------------------- try term.init(.{}); - defer term.deinit(); + defer term.deinit() catch {}; - try std.os.sigaction(std.os.SIG.WINCH, &std.os.Sigaction{ + try std.posix.sigaction(std.posix.SIG.WINCH, &std.posix.Sigaction{ .handler = .{ .handler = handleSigWinch }, - .mask = std.os.empty_sigset, + .mask = std.posix.empty_sigset, .flags = 0, }, null); - var fds: [1]std.os.pollfd = undefined; + var fds: [1]std.posix.pollfd = undefined; if (term.tty) |tty| { fds[0] = .{ .fd = tty, - .events = std.os.POLL.IN, + .events = std.posix.POLL.IN, .revents = undefined, }; } @@ -56,7 +56,7 @@ pub fn main() anyerror!void { var buf: [16]u8 = undefined; var done = false; while (!done) { - _ = try std.os.poll(&fds, -1); + _ = try std.posix.poll(&fds, -1); const read = try term.readInput(&buf); var it = spoon.inputParser(buf[0..read]); @@ -67,11 +67,11 @@ pub fn main() anyerror!void { } else if (in.eqlDescription("s")) { if (try intp.step(&ioContext)) |code| { try term.cook(); - term.deinit(); + term.deinit() catch {}; intp.deinit(); file.close(); std.process.argsFree(gpa, args); - std.os.exit(@intCast(code)); + std.posix.exit(@intCast(code)); } try render(); } |