zig 0.12 and 0.13 changes
This commit is contained in:
parent
8048ef0c75
commit
06468c1272
8 changed files with 40 additions and 38 deletions
|
@ -17,7 +17,7 @@ Current limitations are :
|
||||||
|
|
||||||
## Dependencies
|
## 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
|
## Quick Install
|
||||||
|
|
||||||
|
|
14
build.zig
14
build.zig
|
@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void {
|
||||||
|
|
||||||
const exe = b.addExecutable(.{
|
const exe = b.addExecutable(.{
|
||||||
.name = "zigfunge98",
|
.name = "zigfunge98",
|
||||||
.root_source_file = .{ .path = "src/main.zig" },
|
.root_source_file = b.path("src/main.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
|
@ -19,7 +19,7 @@ pub fn build(b: *std.Build) void {
|
||||||
const run_step = b.step("run", "Run the app");
|
const run_step = b.step("run", "Run the app");
|
||||||
run_step.dependOn(&run_cmd.step);
|
run_step.dependOn(&run_cmd.step);
|
||||||
const unit_tests = b.addTest(.{
|
const unit_tests = b.addTest(.{
|
||||||
.root_source_file = .{ .path = "src/main.zig" },
|
.root_source_file = b.path("src/main.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.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 "";
|
const exclude = std.fmt.allocPrint(gpa, "--exclude-path={s}/.zig/", .{home}) catch "";
|
||||||
defer gpa.free(exclude);
|
defer gpa.free(exclude);
|
||||||
if (coverage) {
|
if (coverage) {
|
||||||
unit_tests.test_runner = "/usr/bin/kcov";
|
unit_tests.test_runner = b.path("/usr/bin/kcov");
|
||||||
unit_tests.setExecCmd(&[_]?[]const u8{
|
unit_tests.setExecCmd(&[_]?[]const u8{
|
||||||
"kcov",
|
"kcov",
|
||||||
exclude,
|
exclude,
|
||||||
|
@ -51,14 +51,14 @@ pub fn build(b: *std.Build) void {
|
||||||
// ----- TUI --------------------------------------------------------------
|
// ----- TUI --------------------------------------------------------------
|
||||||
const tui = b.addExecutable(.{
|
const tui = b.addExecutable(.{
|
||||||
.name = "zigfunge98-tui",
|
.name = "zigfunge98-tui",
|
||||||
.root_source_file = .{ .path = "src/tui.zig" },
|
.root_source_file = b.path("src/tui.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
const spoon = b.createModule(.{
|
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);
|
b.installArtifact(tui);
|
||||||
const tui_cmd = b.addRunArtifact(tui);
|
const tui_cmd = b.addRunArtifact(tui);
|
||||||
tui_cmd.step.dependOn(b.getInstallStep());
|
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");
|
const tui_step = b.step("run-tui", "Run the app");
|
||||||
tui_step.dependOn(&tui_cmd.step);
|
tui_step.dependOn(&tui_cmd.step);
|
||||||
const tui_unit_tests = b.addTest(.{
|
const tui_unit_tests = b.addTest(.{
|
||||||
.root_source_file = .{ .path = "src/tui.zig" },
|
.root_source_file = b.path("src/tui.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 9fa5bb1eafc30b3ff0cbe297a3e0f51dbc903831
|
Subproject commit 3e6c5ab4617e1869c2781e698e14cd976135e998
|
|
@ -1,5 +1,7 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
|
const position = struct { x: i64, y: i64 };
|
||||||
|
|
||||||
const Line = struct {
|
const Line = struct {
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
x: i64 = 0,
|
x: i64 = 0,
|
||||||
|
@ -16,7 +18,7 @@ const Line = struct {
|
||||||
var i: usize = 1;
|
var i: usize = 1;
|
||||||
while (l.data.items[i] == ' ') : (i += 1) {}
|
while (l.data.items[i] == ' ') : (i += 1) {}
|
||||||
l.x += @intCast(i);
|
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;
|
l.data.items.len -= i;
|
||||||
} else { // we need to remove trailing spaces
|
} else { // we need to remove trailing spaces
|
||||||
var i: usize = l.len() - 1;
|
var i: usize = l.len() - 1;
|
||||||
|
@ -168,7 +170,7 @@ pub const Field = struct {
|
||||||
f.lines.items[i].deinit();
|
f.lines.items[i].deinit();
|
||||||
}
|
}
|
||||||
f.y += @intCast(i);
|
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;
|
f.lines.items.len -= i;
|
||||||
} else if (y == f.y + lly - 1) { // we need to remove trailing lines
|
} else if (y == f.y + lly - 1) { // we need to remove trailing lines
|
||||||
l.deinit();
|
l.deinit();
|
||||||
|
@ -259,7 +261,7 @@ pub const Field = struct {
|
||||||
f.x = undefined;
|
f.x = undefined;
|
||||||
f.y = 0;
|
f.y = 0;
|
||||||
f.lines = std.ArrayList(*Line).init(allocator);
|
f.lines = std.ArrayList(*Line).init(allocator);
|
||||||
var l = try f.lines.addOne();
|
const l = try f.lines.addOne();
|
||||||
l.* = try Line.init(allocator);
|
l.* = try Line.init(allocator);
|
||||||
f.lx = 0;
|
f.lx = 0;
|
||||||
return f;
|
return f;
|
||||||
|
@ -282,7 +284,7 @@ pub const Field = struct {
|
||||||
var y: i64 = 0;
|
var y: i64 = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
var buffer: [4096]u8 = undefined;
|
var buffer: [4096]u8 = undefined;
|
||||||
var l = try reader.read(buffer[0..]);
|
const l = try reader.read(buffer[0..]);
|
||||||
if (l == 0) return;
|
if (l == 0) return;
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
while (i < l) : (i += 1) {
|
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(8, 2), '2');
|
||||||
try std.testing.expectEqual(f.get(9, 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 a = x + dx;
|
||||||
var b = y + dy;
|
var b = y + dy;
|
||||||
if (!f.isIn(a, b)) {
|
if (!f.isIn(a, b)) {
|
||||||
|
@ -419,8 +421,8 @@ pub const Field = struct {
|
||||||
a = x;
|
a = x;
|
||||||
b = y;
|
b = y;
|
||||||
while (true) {
|
while (true) {
|
||||||
var c = a - dx;
|
const c = a - dx;
|
||||||
var d = b - dy;
|
const d = b - dy;
|
||||||
if (!f.isIn(c, d)) break;
|
if (!f.isIn(c, d)) break;
|
||||||
a = c;
|
a = c;
|
||||||
b = d;
|
b = d;
|
||||||
|
@ -445,15 +447,15 @@ pub const Field = struct {
|
||||||
var f = try Field.init(std.testing.allocator);
|
var f = try Field.init(std.testing.allocator);
|
||||||
defer f.deinit();
|
defer f.deinit();
|
||||||
try f.load(minimal.reader());
|
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, 0, 0, false, false), @as(position, .{ .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, 1, 0, false, false), @as(position, .{ .x = 0, .y = 0 }));
|
||||||
var hello = std.io.fixedBufferStream("64+\"!dlroW ,olleH\">:#,_@\n");
|
var hello = std.io.fixedBufferStream("64+\"!dlroW ,olleH\">:#,_@\n");
|
||||||
var fHello = try Field.init(std.testing.allocator);
|
var fHello = try Field.init(std.testing.allocator);
|
||||||
defer fHello.deinit();
|
defer fHello.deinit();
|
||||||
try fHello.load(hello.reader());
|
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, 0, 0, false, false), @as(position, .{ .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(3, 0, 1, 0, false, false), @as(position, .{ .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(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;
|
return c;
|
||||||
}
|
}
|
||||||
var buffer = [_]u8{0};
|
var buffer = [_]u8{0};
|
||||||
var n = try self.reader.read(buffer[0..]);
|
const n = try self.reader.read(buffer[0..]);
|
||||||
if (n == 1) {
|
if (n == 1) {
|
||||||
return buffer[0];
|
return buffer[0];
|
||||||
}
|
}
|
||||||
return error.IOError;
|
return error.IOError;
|
||||||
}
|
}
|
||||||
test "characterInput" {
|
test "characterInput" {
|
||||||
var stdin = std.io.fixedBufferStream("ab0");
|
const stdin = std.io.fixedBufferStream("ab0");
|
||||||
var stdout = std.ArrayList(u8).init(std.testing.allocator);
|
var stdout = std.ArrayList(u8).init(std.testing.allocator);
|
||||||
defer stdout.deinit();
|
defer stdout.deinit();
|
||||||
var ioContext = context(stdin, stdout);
|
var ioContext = context(stdin, stdout);
|
||||||
|
@ -49,7 +49,7 @@ pub fn Context(comptime readerType: anytype, comptime writerType: anytype) type
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
test "decimalInput" {
|
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);
|
var stdout = std.ArrayList(u8).init(std.testing.allocator);
|
||||||
defer stdout.deinit();
|
defer stdout.deinit();
|
||||||
var ioContext = context(stdin, stdout);
|
var ioContext = context(stdin, stdout);
|
||||||
|
|
|
@ -5,11 +5,11 @@ const io = @import("io.zig");
|
||||||
pub fn main() anyerror!void {
|
pub fn main() anyerror!void {
|
||||||
var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
|
var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
const gpa = general_purpose_allocator.allocator();
|
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);
|
defer std.process.argsFree(gpa, args);
|
||||||
if (args.len < 2) {
|
if (args.len < 2) {
|
||||||
std.debug.print("Usage: {s} <b98_file_to_run>\n", .{args[0]});
|
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], .{});
|
var file = try std.fs.cwd().openFile(args[1], .{});
|
||||||
|
@ -20,7 +20,7 @@ pub fn main() anyerror!void {
|
||||||
defer i.deinit();
|
defer i.deinit();
|
||||||
|
|
||||||
var ioContext = io.context(std.io.getStdIn().reader(), std.io.getStdOut().writer());
|
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;
|
const testTimestamp: i64 = 1660681247;
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub const Pointer = struct {
|
||||||
p.step(false);
|
p.step(false);
|
||||||
},
|
},
|
||||||
'j' => {
|
'j' => {
|
||||||
var n = p.ss.toss.pop();
|
const n = p.ss.toss.pop();
|
||||||
var j: usize = 0;
|
var j: usize = 0;
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
while (j < n) : (j += 1) {
|
while (j < n) : (j += 1) {
|
||||||
|
@ -379,7 +379,7 @@ pub const Pointer = struct {
|
||||||
p.lastCharWasSpace = false;
|
p.lastCharWasSpace = false;
|
||||||
// Initializing the random number generator
|
// Initializing the random number generator
|
||||||
var seed: u64 = undefined;
|
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.rand = std.rand.DefaultPrng.init(seed);
|
||||||
p.timestamp = timestamp;
|
p.timestamp = timestamp;
|
||||||
return p;
|
return p;
|
||||||
|
|
18
src/tui.zig
18
src/tui.zig
|
@ -15,7 +15,7 @@ pub fn main() anyerror!void {
|
||||||
defer std.process.argsFree(gpa, args);
|
defer std.process.argsFree(gpa, args);
|
||||||
if (args.len < 2) {
|
if (args.len < 2) {
|
||||||
std.debug.print("Usage: {s} <b98_file_to_run>\n", .{args[0]});
|
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], .{});
|
var file = try std.fs.cwd().openFile(args[1], .{});
|
||||||
|
@ -29,19 +29,19 @@ pub fn main() anyerror!void {
|
||||||
|
|
||||||
//--- Term initialization -------------------------------------------------
|
//--- Term initialization -------------------------------------------------
|
||||||
try term.init(.{});
|
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 },
|
.handler = .{ .handler = handleSigWinch },
|
||||||
.mask = std.os.empty_sigset,
|
.mask = std.posix.empty_sigset,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
}, null);
|
}, null);
|
||||||
|
|
||||||
var fds: [1]std.os.pollfd = undefined;
|
var fds: [1]std.posix.pollfd = undefined;
|
||||||
if (term.tty) |tty| {
|
if (term.tty) |tty| {
|
||||||
fds[0] = .{
|
fds[0] = .{
|
||||||
.fd = tty,
|
.fd = tty,
|
||||||
.events = std.os.POLL.IN,
|
.events = std.posix.POLL.IN,
|
||||||
.revents = undefined,
|
.revents = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ pub fn main() anyerror!void {
|
||||||
var buf: [16]u8 = undefined;
|
var buf: [16]u8 = undefined;
|
||||||
var done = false;
|
var done = false;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
_ = try std.os.poll(&fds, -1);
|
_ = try std.posix.poll(&fds, -1);
|
||||||
|
|
||||||
const read = try term.readInput(&buf);
|
const read = try term.readInput(&buf);
|
||||||
var it = spoon.inputParser(buf[0..read]);
|
var it = spoon.inputParser(buf[0..read]);
|
||||||
|
@ -67,11 +67,11 @@ pub fn main() anyerror!void {
|
||||||
} else if (in.eqlDescription("s")) {
|
} else if (in.eqlDescription("s")) {
|
||||||
if (try intp.step(&ioContext)) |code| {
|
if (try intp.step(&ioContext)) |code| {
|
||||||
try term.cook();
|
try term.cook();
|
||||||
term.deinit();
|
term.deinit() catch {};
|
||||||
intp.deinit();
|
intp.deinit();
|
||||||
file.close();
|
file.close();
|
||||||
std.process.argsFree(gpa, args);
|
std.process.argsFree(gpa, args);
|
||||||
std.os.exit(@intCast(code));
|
std.posix.exit(@intCast(code));
|
||||||
}
|
}
|
||||||
try render();
|
try render();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue