summaryrefslogtreecommitdiff
path: root/anim/src/rows.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-13 12:18:26 -0300
committerGabriel Schneider <[email protected]>2026-11-13 12:18:26 -0300
commit4f31aaef1338b53195f8c475db5a72d75cc1fc82 (patch)
treef2c3c2140269a5559f60bcd9e2520f5ff7431565 /anim/src/rows.zig
parent771e377f6db9c3aed1ab85bc36a774f4176272cc (diff)
downloadcomputeranim-4f31aaef1338b53195f8c475db5a72d75cc1fc82.tar.gz
computeranim-4f31aaef1338b53195f8c475db5a72d75cc1fc82.zip
debugger: add refractive lenses and configurable memory values
Use disassembly lenses for executable pointers, browse surrounding segment context, and keep the reading surface opaque with GPU refraction at the edges. Route right-clicks by stack mapping and expose byte-width and numeric-format controls. Replace matching-address arrows with staggered shared-renderer highlights. Verified GUI and renderer suites, native restart/zoom cycles, independent float-extrema and popup review, and a live wrong-map stop at Deoptimizer::New with JS origin context. Requires Sketchbook 409c1ac.
Diffstat (limited to 'anim/src/rows.zig')
-rw-r--r--anim/src/rows.zig59
1 files changed, 59 insertions, 0 deletions
diff --git a/anim/src/rows.zig b/anim/src/rows.zig
index 4666ffd..0e4f58c 100644
--- a/anim/src/rows.zig
+++ b/anim/src/rows.zig
@@ -40,6 +40,65 @@ pub fn baseline(y: f32) f32 {
return theme.baseline(y, row_h, size);
}
+pub const NumberFormat = enum { hex, unsigned, signed, float };
+
+pub fn numberText(buf: []u8, octets: []const u8, format: NumberFormat) []const u8 {
+ var value: u64 = 0;
+ std.debug.assert(octets.len == 1 or octets.len == 2 or octets.len == 4 or octets.len == 8);
+ for (octets, 0..) |byte, i| value |= @as(u64, byte) << @intCast(i * 8);
+ return switch (format) {
+ .hex => switch (octets.len) {
+ 1 => std.fmt.bufPrint(buf, "{x:0>2}", .{value}),
+ 2 => std.fmt.bufPrint(buf, "{x:0>4}", .{value}),
+ 4 => std.fmt.bufPrint(buf, "{x:0>8}", .{value}),
+ else => std.fmt.bufPrint(buf, "{x:0>16}", .{value}),
+ },
+ .unsigned => std.fmt.bufPrint(buf, "{d}", .{value}),
+ .signed => blk: {
+ const shift: u6 = @intCast(64 - octets.len * 8);
+ const signed: i64 = @bitCast(value << shift);
+ break :blk std.fmt.bufPrint(buf, "{d}", .{signed >> shift});
+ },
+ .float => if (octets.len == 4) std.fmt.bufPrint(buf, "{e}", .{@as(f32, @bitCast(@as(u32, @truncate(value))))}) else if (octets.len == 8) std.fmt.bufPrint(buf, "{e}", .{@as(f64, @bitCast(value))}) else return "—",
+ } catch "?";
+}
+
+/// Sixteen octets, grouped as little-endian values; pointer hits use the same geometry as hex rows.
+pub fn wordsAt(u: ui.Ui, y: f32, addr: u64, values: *const [16]u8, known: *const [16]bool, unit: u8, format: NumberFormat, moment: Recording.Moment) f32 {
+ std.debug.assert(unit == 1 or unit == 2 or unit == 4 or unit == 8);
+ _ = u.address(theme.metric.bytes.address, baseline(y), addr, .{ .ink = ui.rgb(ink(regionOf(moment, addr))) });
+ var x = theme.metric.bytes.first + addressRoom(addr);
+ var at_byte: usize = 0;
+ while (at_byte < 16) : (at_byte += unit) {
+ const octets = values[at_byte..][0..unit];
+ const captured = std.mem.indexOfScalar(bool, known[at_byte..][0..unit], false) == null;
+ var buf: [64]u8 = undefined;
+ const text = if (captured) numberText(&buf, octets, format) else "?";
+ const digits: usize = switch (format) {
+ .hex => unit * 2,
+ .unsigned => if (unit == 8) 20 else if (unit == 4) 10 else if (unit == 2) 5 else 3,
+ .signed => if (unit == 8) 20 else if (unit == 4) 11 else if (unit == 2) 6 else 4,
+ .float => if (unit == 8) 25 else 16,
+ };
+ const width = @as(f32, @floatFromInt(digits)) * adv;
+ const value = if (unit == 8) std.mem.readInt(u64, octets[0..8], .little) else 0;
+ const pointer = captured and unit == 8 and format != .float and regionOf(moment, value) != .none;
+ u.text(.mono, size, x, baseline(y), text, if (pointer) ink(regionOf(moment, value)) else t.primary);
+ if (pointer) u.hitAddress(value, .{ .x = x, .y = y, .w = width, .h = row_h });
+ x += width + adv * 2;
+ }
+ return x;
+}
+
+test "memory scalar formats preserve byte order, sign and width" {
+ var buf: [64]u8 = undefined;
+ try std.testing.expectEqualStrings("1234", numberText(&buf, &.{ 0x34, 0x12 }, .hex));
+ try std.testing.expectEqualStrings("-1", numberText(&buf, &.{ 255, 255 }, .signed));
+ try std.testing.expectEqualStrings("18446744073709551615", numberText(&buf, &@as([8]u8, @splat(255)), .unsigned));
+ try std.testing.expectEqualStrings("-9223372036854775808", numberText(&buf, &.{ 0, 0, 0, 0, 0, 0, 0, 128 }, .signed));
+ try std.testing.expectEqualStrings("1e0", numberText(&buf, &.{ 0, 0, 128, 63 }, .float));
+}
+
/// The marks on a chain's hops.
pub const Marks = struct {
/// The first hop: a register (or a word) written: armed, struck, held.