aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/field.zig9
-rw-r--r--src/interpreter.zig14
-rw-r--r--src/pointer.zig3
-rw-r--r--src/tui.zig46
4 files changed, 32 insertions, 40 deletions
diff --git a/src/field.zig b/src/field.zig
index 03f9da3..0130848 100644
--- a/src/field.zig
+++ b/src/field.zig
@@ -69,12 +69,6 @@ const Line = struct {
if (x >= l.x and x < l.x + @intCast(i64, l.len())) return l.data.items[@intCast(usize, x - @intCast(i64, l.x))];
return ' ';
}
- pub inline fn getData(l: *Line) std.ArrayList(i64) {
- return l.data;
- }
- pub inline fn getX(l: *Line) i64 {
- return l.x;
- }
fn init(allocator: std.mem.Allocator) !*Line {
var l = try allocator.create(Line);
l.allocator = allocator;
@@ -250,9 +244,6 @@ pub const Field = struct {
if (y >= f.y and y < f.y + @intCast(i64, f.lines.items.len)) return f.lines.items[@intCast(usize, y - @intCast(i64, f.y))].get(x);
return ' ';
}
- pub fn getLine(f: *Field, y: usize) *Line {
- return f.lines.items[y];
- }
pub fn getSize(f: Field) [4]i64 {
return [4]i64{ f.x, f.y, @intCast(i64, f.lx), @intCast(i64, f.lines.items.len) };
}
diff --git a/src/interpreter.zig b/src/interpreter.zig
index 51a542e..37ebba9 100644
--- a/src/interpreter.zig
+++ b/src/interpreter.zig
@@ -13,12 +13,6 @@ pub const Interpreter = struct {
self.field.deinit();
self.allocator.destroy(self);
}
- pub inline fn getField(self: *Interpreter) *field.Field {
- return self.field;
- }
- pub inline fn getPointer(self: *Interpreter) *pointer.Pointer {
- return self.pointer;
- }
pub fn init(allocator: std.mem.Allocator, fileReader: anytype, timestamp: ?i64, args: []const []const u8, env: []const [*:0]const u8) !*Interpreter {
var i = try allocator.create(Interpreter);
errdefer allocator.destroy(i);
@@ -31,12 +25,8 @@ pub const Interpreter = struct {
}
pub fn run(self: *Interpreter, ioContext: anytype) !i64 {
while (true) {
- if (try self.pointer.exec(ioContext)) |ret| {
- if (ret.code) |code| {
- return code;
- } else {
- return 0;
- }
+ if (try self.step(ioContext)) |ret| {
+ return ret;
}
}
}
diff --git a/src/pointer.zig b/src/pointer.zig
index ce188f8..653f890 100644
--- a/src/pointer.zig
+++ b/src/pointer.zig
@@ -352,9 +352,6 @@ pub const Pointer = struct {
self.step();
return result;
}
- pub inline fn getInfo(self: *Pointer) PointerInfo {
- return .{ .x = self.x, .y = self.y, .dx = self.dx, .dy = self.dy };
- }
pub fn init(allocator: std.mem.Allocator, f: *field.Field, timestamp: ?i64, argv: []const []const u8, env: []const [*:0]const u8) !*Pointer {
var p = try allocator.create(Pointer);
errdefer allocator.destroy(p);
diff --git a/src/tui.zig b/src/tui.zig
index 2867a71..8d60bce 100644
--- a/src/tui.zig
+++ b/src/tui.zig
@@ -64,6 +64,12 @@ pub fn main() anyerror!void {
break;
} else if (in.eqlDescription("s")) {
if (try intp.step(&ioContext)) |code| {
+ try term.cook();
+ term.deinit();
+ intp.deinit();
+ file.close();
+ std.process.argsFree(gpa.allocator(), args);
+ std.debug.assert(!gpa.deinit());
std.os.exit(@intCast(u8, code));
}
try render();
@@ -89,8 +95,6 @@ fn render() !void {
return;
}
- const pointer = intp.getPointer().getInfo();
-
try rc.moveCursorTo(0, 0);
var filename = rc.restrictedPaddingWriter(term.width);
try filename.writer().print("{s} | steps:{d}", .{ args[1], 0 });
@@ -99,38 +103,48 @@ fn render() !void {
try rc.setAttribute(.{ .fg = .green, .reverse = true });
var stack = rc.restrictedPaddingWriter(16);
try stack.writer().writeAll("---- Stack ----");
+ try rc.setAttribute(.{ .fg = .green, .reverse = false });
+ var n: usize = 0;
+ while (n < intp.pointer.ss.toss.data.items.len) : (n += 1) {
+ try rc.moveCursorTo(3 + n, 0);
+ var s = rc.restrictedPaddingWriter(16);
+ const v = intp.pointer.ss.toss.data.items[n];
+ if (v >= 32 and v < 127) {
+ try s.writer().print("{c} - {d}", .{ @intCast(u8, v), v });
+ } else {
+ try s.writer().print("{d}", .{v});
+ }
+ }
try rc.moveCursorTo(2, 18);
try rc.setAttribute(.{ .fg = .blue, .reverse = true });
var fieldTitle = rc.restrictedPaddingWriter(term.width - 17);
- const size = intp.getField().getSize();
+ const size = intp.field.getSize();
try fieldTitle.writer().print("Funge field | top left corner:({d},{d}) size:{d}x{d}", .{ size[0], size[1], size[2], size[3] });
try fieldTitle.pad();
try rc.setAttribute(.{ .fg = .blue, .reverse = false });
var y: usize = 0; // TODO negative lines
while (y < @min(@intCast(usize, size[3]), term.height - 3)) : (y += 1) {
var field = rc.restrictedPaddingWriter(term.width - 17);
- const line = intp.getField().getLine(y);
- const data = line.getData();
+ const line = intp.field.lines.items[y];
var x: usize = 0;
- if (line.getX() >= 0) {
- try rc.moveCursorTo(y + 3, 18 + @intCast(usize, line.getX()));
+ if (line.x >= 0) {
+ try rc.moveCursorTo(y + 3, 18 + @intCast(usize, line.x));
} else {
try rc.moveCursorTo(y + 3, 18); // TODO negative columns
}
- while (x < @min(data.items.len, term.width - 18)) : (x += 1) {
- if (x == pointer.x and y == pointer.y) {
- try rc.setAttribute(.{ .fg = .magenta, .reverse = true });
- }
- if (x == pointer.x + pointer.dx and y == pointer.y + pointer.dy) { // TODO optmize that?
- try rc.setAttribute(.{ .fg = .magenta, .reverse = false });
+ while (x < @min(line.data.items.len, term.width - 18)) : (x += 1) {
+ var reset = false;
+ if (x + @intCast(usize, line.x) == intp.pointer.x and y == intp.pointer.y) { // TODO negatives
+ try rc.setAttribute(.{ .fg = .red, .reverse = true });
+ reset = true;
}
- if (data.items[x] >= 32 and data.items[x] < 127) {
- try field.writer().print("{c}", .{@intCast(u8, data.items[x])});
+ if (line.data.items[x] >= 32 and line.data.items[x] < 127) {
+ try field.writer().print("{c}", .{@intCast(u8, line.data.items[x])});
} else {
try field.writer().writeAll("®");
}
- if (x == pointer.x and y == pointer.y or x == pointer.x + pointer.dx and y == pointer.y + pointer.dy) {
+ if (reset) {
try rc.setAttribute(.{ .fg = .blue, .reverse = false });
}
}