1
0
Fork 0

Improved tui debugger

This commit is contained in:
Julien Dessaux 2022-12-04 04:06:47 +01:00
parent 0bf0375200
commit b373cbffa1
Signed by: adyxax
GPG key ID: F92E51B86E07177E
4 changed files with 32 additions and 40 deletions

View file

@ -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))]; if (x >= l.x and x < l.x + @intCast(i64, l.len())) return l.data.items[@intCast(usize, x - @intCast(i64, l.x))];
return ' '; 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 { fn init(allocator: std.mem.Allocator) !*Line {
var l = try allocator.create(Line); var l = try allocator.create(Line);
l.allocator = allocator; 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); 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 ' '; return ' ';
} }
pub fn getLine(f: *Field, y: usize) *Line {
return f.lines.items[y];
}
pub fn getSize(f: Field) [4]i64 { pub fn getSize(f: Field) [4]i64 {
return [4]i64{ f.x, f.y, @intCast(i64, f.lx), @intCast(i64, f.lines.items.len) }; return [4]i64{ f.x, f.y, @intCast(i64, f.lx), @intCast(i64, f.lines.items.len) };
} }

View file

@ -13,12 +13,6 @@ pub const Interpreter = struct {
self.field.deinit(); self.field.deinit();
self.allocator.destroy(self); 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 { 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); var i = try allocator.create(Interpreter);
errdefer allocator.destroy(i); errdefer allocator.destroy(i);
@ -31,12 +25,8 @@ pub const Interpreter = struct {
} }
pub fn run(self: *Interpreter, ioContext: anytype) !i64 { pub fn run(self: *Interpreter, ioContext: anytype) !i64 {
while (true) { while (true) {
if (try self.pointer.exec(ioContext)) |ret| { if (try self.step(ioContext)) |ret| {
if (ret.code) |code| { return ret;
return code;
} else {
return 0;
}
} }
} }
} }

View file

@ -352,9 +352,6 @@ pub const Pointer = struct {
self.step(); self.step();
return result; 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 { 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); var p = try allocator.create(Pointer);
errdefer allocator.destroy(p); errdefer allocator.destroy(p);

View file

@ -64,6 +64,12 @@ pub fn main() anyerror!void {
break; break;
} 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();
term.deinit();
intp.deinit();
file.close();
std.process.argsFree(gpa.allocator(), args);
std.debug.assert(!gpa.deinit());
std.os.exit(@intCast(u8, code)); std.os.exit(@intCast(u8, code));
} }
try render(); try render();
@ -89,8 +95,6 @@ fn render() !void {
return; return;
} }
const pointer = intp.getPointer().getInfo();
try rc.moveCursorTo(0, 0); try rc.moveCursorTo(0, 0);
var filename = rc.restrictedPaddingWriter(term.width); var filename = rc.restrictedPaddingWriter(term.width);
try filename.writer().print("{s} | steps:{d}", .{ args[1], 0 }); try filename.writer().print("{s} | steps:{d}", .{ args[1], 0 });
@ -99,38 +103,48 @@ fn render() !void {
try rc.setAttribute(.{ .fg = .green, .reverse = true }); try rc.setAttribute(.{ .fg = .green, .reverse = true });
var stack = rc.restrictedPaddingWriter(16); var stack = rc.restrictedPaddingWriter(16);
try stack.writer().writeAll("---- Stack ----"); 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.moveCursorTo(2, 18);
try rc.setAttribute(.{ .fg = .blue, .reverse = true }); try rc.setAttribute(.{ .fg = .blue, .reverse = true });
var fieldTitle = rc.restrictedPaddingWriter(term.width - 17); 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.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 fieldTitle.pad();
try rc.setAttribute(.{ .fg = .blue, .reverse = false }); try rc.setAttribute(.{ .fg = .blue, .reverse = false });
var y: usize = 0; // TODO negative lines var y: usize = 0; // TODO negative lines
while (y < @min(@intCast(usize, size[3]), term.height - 3)) : (y += 1) { while (y < @min(@intCast(usize, size[3]), term.height - 3)) : (y += 1) {
var field = rc.restrictedPaddingWriter(term.width - 17); var field = rc.restrictedPaddingWriter(term.width - 17);
const line = intp.getField().getLine(y); const line = intp.field.lines.items[y];
const data = line.getData();
var x: usize = 0; var x: usize = 0;
if (line.getX() >= 0) { if (line.x >= 0) {
try rc.moveCursorTo(y + 3, 18 + @intCast(usize, line.getX())); try rc.moveCursorTo(y + 3, 18 + @intCast(usize, line.x));
} else { } else {
try rc.moveCursorTo(y + 3, 18); // TODO negative columns try rc.moveCursorTo(y + 3, 18); // TODO negative columns
} }
while (x < @min(data.items.len, term.width - 18)) : (x += 1) { while (x < @min(line.data.items.len, term.width - 18)) : (x += 1) {
if (x == pointer.x and y == pointer.y) { var reset = false;
try rc.setAttribute(.{ .fg = .magenta, .reverse = true }); 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 (x == pointer.x + pointer.dx and y == pointer.y + pointer.dy) { // TODO optmize that? if (line.data.items[x] >= 32 and line.data.items[x] < 127) {
try rc.setAttribute(.{ .fg = .magenta, .reverse = false }); try field.writer().print("{c}", .{@intCast(u8, line.data.items[x])});
}
if (data.items[x] >= 32 and data.items[x] < 127) {
try field.writer().print("{c}", .{@intCast(u8, data.items[x])});
} else { } else {
try field.writer().writeAll("®"); 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 }); try rc.setAttribute(.{ .fg = .blue, .reverse = false });
} }
} }