From e63b0624f57472d40af32a006c32cc47d403b822 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 18:06:30 -0300 Subject: canim: what the review found; the band as two panels; list and sort by instruction The first videos were reviewed frame by frame and the catalogue changed with them. A lens is a drawing over the program column and its view over the state column, so the stack keeps six slots, its window on the whole frame. Operands are whole. list and sort are recorded by instruction from main (record --from), so their registers strike, links reach nodes and cells, rows that ran are marked and jumps are drawn. A call's node is a projection of its return address; pins travel and keep their side; a mark covers the bytes that changed, at the element's width; a syscall's result is stored after the kernel returns it and every panel is of one moment; fast passes are veiled; the clock stands still during a step; captions get their reading time and a scene's first step comes by four seconds. Co-Authored-By: Claude Fable 5.2 --- anim/src/nodes.zig | 188 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 160 insertions(+), 28 deletions(-) (limited to 'anim/src/nodes.zig') diff --git a/anim/src/nodes.zig b/anim/src/nodes.zig index e6ba663..1f8acec 100644 --- a/anim/src/nodes.zig +++ b/anim/src/nodes.zig @@ -44,7 +44,11 @@ pub const Nodes = struct { pub fn draw(g: *const Nodes, f: *sk.Frame, placed: anim.Placed) void { const box = g.stage.box(placed, .band); if (box.h < m.tag + m.row) return; - const u = context.at(f, placed, box); + const u = context.at(f, placed, box).faded(placed.value(g.stage.drawing)); + // A relayout moves the band: what is drawn in it stays inside it + // (its view, drawn below, clips itself and hands the clip back). + u.clip(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }); + defer u.unclip(); const now = g.cursor.now(placed); const rec = g.cursor.rec; const heap = theme.color.region.heap; @@ -54,27 +58,26 @@ pub const Nodes = struct { .{ .text = "malloc's", .ink = ui.rgb(t.dim) }, .{ .text = "never read", .ink = ui.rgb(t.faint) }, }; - _ = u.panel(box.w, box.h, g.title, .{ .focus = g.focus, .legend = &legend }); - const half = theme.layout.state.x - theme.layout.program.x; + _ = u.panel(box.w, box.h, g.title, .{ .focus = g.focus }); const moment = now.shown(.idea); const things = objects.reach(f.scratch, rec, moment, null); const before = objects.reach(f.scratch, rec, now.before(), null); - // The dump: the heap the nodes are in, from the first one's chunk to the last's. + // Its view: the heap the nodes are in, from the first one's chunk to the last's. var lo: u64 = std.math.maxInt(u64); var hi: u64 = 0; for (rec.allocations) |a| if (things.len > 0 and a.size == things[0].type.record.size) { lo = @min(lo, (a.ptr - 16) & ~@as(u64, 15)); hi = @max(hi, (a.ptr + a.size + 15) & ~@as(u64, 15)); }; - const count = theme.layout.rowsIn(box.h); if (lo < hi) { + const count = theme.layout.rowsIn(g.stage.box(placed, .view).h); const first = hexdump.window(now, lo, hi, count); const shown = @min(count, (hi - first) / 16); - const base = theme.size.sans.tag; - u.text(.sans_medium, base, half + 12, m.tag - 6, "its bytes", t.primary); - u.text(.sans, theme.size.sans.micro, half + 12 + u.width(.sans_medium, base, "its bytes") + 12, m.tag - 6, u.print("the heap, {x} to {x}", .{ first, first + 16 * shown - 1 }), t.faint); - hexdump.draw(u, now, half, m.tag + m.pad, first, shown, .{ .things = things }); + const v = hexdump.panel(f, placed, g.stage, u.print("the heap, {x} to {x}", .{ first, first + 16 * shown - 1 }), &legend); + if (v.rows > 0) hexdump.draw(v.u, now, 0, m.tag + m.pad, first, @min(shown, v.rows), .{ .things = things }); + v.veil(now); + u.clip(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }); } if (things.len == 0) { const root = rec.variable(f.scratch, moment, g.root); @@ -93,8 +96,8 @@ pub const Nodes = struct { for (rec.allocations) |a| slots += @intFromBool(a.size == things[0].type.record.size); slots = @max(slots, 1); const n: f32 = @floatFromInt(slots); - const x0 = (half - 32 - n * size[0] - (n - 1) * size[2]) / 2; - const ly = m.tag + @as(f32, if (subject) 44 else 16); + const x0 = (box.w - n * size[0] - (n - 1) * size[2]) / 2; + const ly = m.tag + @as(f32, if (subject) 72 else 16); const ny = ly + label * 1.2 + 4; const places = f.scratch.alloc(Rect, things.len) catch return; for (things, places, 0..) |o, *place, i| { @@ -102,19 +105,39 @@ pub const Nodes = struct { ties.anchor(u, .{ .node = o.addr }, place.*); } + // Each node as much as it has risen from its bytes (`establish`): by address. + const rising = placed.value(g.stage.rise); + const shows = f.scratch.alloc(f32, things.len) catch return; + const belows = f.scratch.alloc(f32, things.len) catch return; + for (things, shows, belows) |o, *show, *below| { + var k: usize = 0; + for (things) |other| k += @intFromBool(other.addr < o.addr); + const r = ties.rise(rising, k, things.len); + show.* = r.element; + below.* = r.below; + } + // Arrows first, under the nodes' edges. const since = now.since(.idea, 0); - for (things, places) |o, place| for (o.type.record.fields) |field| { + const whole = u; + for (things, places, shows) |o, place, show| for (o.type.record.fields) |field| { if (field.type != .pointer) continue; const from_addr = o.addr + field.offset; const start = ui.Vec{ place.x + place.w - theme.metric.node.pointer_w / 2 + 6, place.y + place.h / 2 }; const new = if (Recording.word(now.moment(), from_addr, 8) catch null) |target| placeOf(things, places, target) else null; const old = if (Recording.word(now.before(), from_addr, 8) catch null) |target| placeOf(things, places, target) else null; + // An arrow is there once both its ends are. + var reach = show; + if (Recording.word(now.moment(), from_addr, 8) catch null) |target| for (things, shows) |other, other_show| { + if (other.addr == target) reach = @min(reach, other_show); + }; + if (reach <= 0) continue; + const v = if (reach < 1) whole.faded(reach) else whole; const fresh = now.writeAge(from_addr, 8) == 0; const ink = ui.rgb(heap); const head = theme.metric.node.arrow_head; if (!fresh or !now.walking()) { - if (if (now.landed(.idea, 0)) new else old) |to| u.route(route(u, start, place, to), ink, .{ .width = theme.stroke.line, .head = head, .progress = if (fresh) cursors.standard(now.moving(.idea, 0, time.redirect.head)) else 1 }); + if (if (now.landed(.idea, 0)) new else old) |to| v.route(route(v, start, place, to), ink, .{ .width = theme.stroke.line, .head = head, .progress = if (fresh) cursors.standard(now.moving(.idea, 0, time.redirect.head)) else 1 }); continue; } // A pointer rewritten. Anticipation: as its half is armed the @@ -123,24 +146,25 @@ pub const Nodes = struct { // answers with a bright frame. The old one lingers, then goes. const armed = since >= -time.strike.arm; if (old) |to| { - const ghost = if (armed) u.faded(1 - std.math.clamp((since - time.redirect.ghost_hold) / time.redirect.ghost_out, 0, 1)) else u; - ghost.route(route(u, start, place, to), if (armed) ui.rgb(t.faint) else ink, .{ .dashed = armed, .head = if (armed) null else head, .width = if (armed) theme.stroke.rule else theme.stroke.line }); + const ghost = if (armed) v.faded(1 - std.math.clamp((since - time.redirect.ghost_hold) / time.redirect.ghost_out, 0, 1)) else v; + ghost.route(route(v, start, place, to), if (armed) ui.rgb(t.faint) else ink, .{ .dashed = armed, .head = if (armed) null else head, .width = if (armed) theme.stroke.rule else theme.stroke.line }); } if (new) |to| { - u.route(route(u, start, place, to), ink, .{ .width = theme.stroke.line, .head = head, .progress = cursors.standard(std.math.clamp((since - time.snap) / time.redirect.head, 0, 1)) }); + v.route(route(v, start, place, to), ink, .{ .width = theme.stroke.line, .head = head, .progress = cursors.standard(std.math.clamp((since - time.snap) / time.redirect.head, 0, 1)) }); const landed = since - time.snap - time.redirect.head; const out = 4; - if (landed >= 0 and landed < time.redirect.landing) u.faded(1 - landed / time.redirect.landing).frame(.{ .x = to.x - out, .y = to.y - out, .w = to.w + 2 * out, .h = to.h + 2 * out }, theme.mark(.attention).solid, theme.stroke.rule); + if (landed >= 0 and landed < time.redirect.landing) v.faded(1 - landed / time.redirect.landing).frame(.{ .x = to.x - out, .y = to.y - out, .w = to.w + 2 * out, .h = to.h + 2 * out }, theme.mark(.attention).solid, theme.stroke.rule); } }; - for (things, places) |o, place| { + for (things, places, shows, belows) |o, place, show, below| { const new = for (before) |was| { if (was.addr == o.addr) break false; } else true; // What begins fades in; it does not pop. - g.node(if (new) u.faded(now.moving(.idea, 0, time.quick)) else u, now, o, place, label, value_size); + if (show > 0) g.node(u.faded(show * (if (new) now.moving(.idea, 0, time.quick) else 1)).moved(0, below), now, o, place, label, value_size); } + g.tags(u, now, things, places, label); } fn node(g: *const Nodes, u: ui.Ui, now: cursors.Now, o: objects.Object, r: Rect, label: f32, value_size: f32) void { @@ -172,7 +196,7 @@ pub const Nodes = struct { if (Recording.word(moment, at, bytes) catch null) |n| { const shift: u6 = @intCast(64 - 8 * bytes); const signed = @as(i64, @bitCast(n << shift)) >> shift; - u.label(ink.face, value_size, value, .center, u.print("{d}", .{signed}), if (o.freed) ui.rgb(t.faint) else ink.ink); + u.label(ink.face, value_size, value, .center, objects.reading(u.f.scratch, signed, field.type), if (o.freed) ui.rgb(t.faint) else ink.ink); } else u.unknown(value); } // The first pointer field: the square its arrow leaves from, or a slash for null. @@ -195,26 +219,85 @@ pub const Nodes = struct { const names = g.pins(u, now, o.addr); const cx = r.x + r.w / 2; ties.anchor(u, .{ .node_pin = o.addr }, .{ .x = cx - 1, .y = r.y + r.h, .w = 2, .h = label + 10 }); - if (names.names.len > 0 and names.shows > 0) u.faded(names.shows).pinUnder(cx, r.y + r.h, names.names, heap, label); + if (names.names.len > 0 and names.shows > 0) u.faded(names.shows).pinUnderInked(cx, r.y + r.h, names.names, names.inks, heap, label); } - const Pins = struct { names: []const []const u8, shows: f32 }; + /// Where variable `name`'s tag is: it travels from node to node in the + /// drawing's slot, after its word has been struck (`glide`, 30 f to the + /// next node, 36 f further); it does not jump. + fn tagOf(g: *const Nodes, u: ui.Ui, now: cursors.Now, name: []const u8) Tag { + const rec = g.cursor.rec; + const at = struct { + fn value(r: *Recording, scratch: std.mem.Allocator, then: Recording.Moment, n: []const u8) u64 { + const v = r.variable(scratch, then, n) orelse return 0; + if (!r.assigned(v, then.index)) return 0; + return (Recording.word(then, v.addr, 8) catch null) orelse 0; + } + }; + const to = at.value(rec, u.f.scratch, now.moment(), name); + const from = at.value(rec, u.f.scratch, now.before(), name); + if (from == to or now.resting()) return .{ .from = from, .to = to, .p = 1 }; + const far: f32 = if (from != 0 and to != 0 and @abs(@as(i64, @bitCast(to -% from))) > 0x30) time.flight.mid else time.flight.near; + const p = switch (now.plan.gait) { + .walk => std.math.clamp(now.since(.idea, 0) / far, 0, 1), + .run => now.moving(.idea, 0, time.run_ease), + .sprint => 1, + }; + return .{ .from = from, .to = to, .p = p }; + } + + /// The tags on their way: from node to node along the band's bottom, + /// or arriving where there was none (fading in, rising 8), or leaving + /// for none (fading out). + fn tags(g: *const Nodes, u: ui.Ui, now: cursors.Now, things: []const objects.Object, places: []const Rect, label: f32) void { + const heap = theme.color.region.heap; + for (g.track) |name| { + const tag = g.tagOf(u, now, name); + if (!tag.moving() or tag.p <= 0) continue; + const a = placeOf(things, places, tag.from); + const b = placeOf(things, places, tag.to); + // It keeps the side it had where it leaves; one that comes to + // names already there goes on the stub's right. + const was_regs = (now.before().regs(g.cursor.rec.tid) catch null) orelse zt.Regs{}; + const left_from = g.namesBefore(u, now, tag.from, was_regs); + const was_right = left_from.len >= 2 and !std.mem.eql(u8, left_from[0], name); + const crowded = was_right or (a == null and g.pins(u, now, tag.to).names.len > 0); + const names: []const []const u8 = if (crowded) &.{ "", name } else &.{name}; + const ink = g.home(u, now, name); + const inks: []const u24 = if (crowded) &.{ t.primary, ink } else &.{ink}; + if (a != null and b != null) { + const x = std.math.lerp(a.?.x + a.?.w / 2, b.?.x + b.?.w / 2, cursors.glide(tag.p)); + u.pinUnderInked(x, a.?.y + a.?.h, names, inks, heap, label); + } else if (b) |r| { + const p = std.math.clamp(tag.p / (time.quick / time.flight.near), 0, 1); + u.faded(p).pinUnderInked(r.x + r.w / 2, r.y + r.h + (1 - p) * theme.time.caption_rise, names, inks, heap, label); + } else if (a) |r| { + u.faded(1 - std.math.clamp(tag.p / (time.quick / time.flight.near), 0, 1)).pinUnderInked(r.x + r.w / 2, r.y + r.h, names, inks, heap, label); + } + } + } + + const Pins = struct { names: []const []const u8, inks: []const u24, shows: f32 }; /// The registers that hold `addr` (before this step, and after it once /// their link has landed), then the scene's variables that do. fn pins(g: *const Nodes, u: ui.Ui, now: cursors.Now, addr: u64) Pins { const rec = g.cursor.rec; var out: std.ArrayList([]const u8) = .empty; + var inks: std.ArrayList(u24) = .empty; var shows: f32 = 0; const is = (now.moment().regs(rec.tid) catch null) orelse zt.Regs{}; const was = (now.before().regs(rec.tid) catch null) orelse is; - // The scene's variables first: what the narration names. - const moment = now.shown(.idea); + // The scene's variables first: what the narration names, in the ink + // of where each lives. One on its way from another node is drawn + // apart (`tags`). for (g.track) |name| { - const v = rec.variable(u.f.scratch, moment, name) orelse continue; - if (!rec.assigned(v, moment.index)) continue; - if ((Recording.word(moment, v.addr, 8) catch null) != addr) continue; + const tag = g.tagOf(u, now, name); + // Where it is: at the node it leaves until it sets off. + const here = if (tag.p <= 0) tag.from else tag.to; + if ((tag.moving() and tag.p > 0) or here != addr) continue; out.append(u.f.scratch, name) catch break; + inks.append(u.f.scratch, g.home(u, now, name)) catch break; shows = 1; } if (!g.quiet) for (theme.metric.all_registers[0..16]) |name| { @@ -226,9 +309,58 @@ pub const Nodes = struct { const this = if (before and after) 1 else if (after) s.new else s.old; if (this < 0.5) continue; out.append(u.f.scratch, name) catch break; + inks.append(u.f.scratch, t.primary) catch break; shows = @max(shows, this); }; - return .{ .names = out.items, .shows = shows }; + // Names keep their side: one left alone where it was on the right stays there. + if (out.items.len == 1) { + const first_before = g.firstBefore(u, now, addr, was); + if (first_before != null and !std.mem.eql(u8, first_before.?, out.items[0])) { + out.insert(u.f.scratch, 0, "") catch {}; + inks.insert(u.f.scratch, 0, t.primary) catch {}; + } + } + return .{ .names = out.items, .inks = inks.items, .shows = shows }; + } + + /// The first name on `addr`'s pin before this step, if another name was beside it. + fn firstBefore(g: *const Nodes, u: ui.Ui, now: cursors.Now, addr: u64, was: zt.Regs) ?[]const u8 { + const names = g.namesBefore(u, now, addr, was); + return if (names.len >= 2) names[0] else null; + } + + /// The names on `addr`'s pin before this step, in their order (the first left). + fn namesBefore(g: *const Nodes, u: ui.Ui, now: cursors.Now, addr: u64, was: zt.Regs) []const []const u8 { + const rec = g.cursor.rec; + var out: std.ArrayList([]const u8) = .empty; + for (g.track) |name| { + const v = rec.variable(u.f.scratch, now.before(), name) orelse continue; + if (!rec.assigned(v, now.before().index)) continue; + if ((Recording.word(now.before(), v.addr, 8) catch null) != addr) continue; + out.append(u.f.scratch, name) catch break; + } + if (!g.quiet) for (theme.metric.all_registers[0..16]) |name| if (was.named(name) == addr) { + out.append(u.f.scratch, name) catch break; + }; + return out.items; + } + + /// The ink of where variable `name` lives: stack for a local, data for a global. + fn home(g: *const Nodes, u: ui.Ui, now: cursors.Now, name: []const u8) u24 { + const v = g.cursor.rec.variable(u.f.scratch, now.moment(), name) orelse return t.primary; + return rows.ink(rows.regionOf(now.moment(), v.addr)); + } +}; + +/// A variable's tag: the node it was under before the step and the one +/// it is under after it (0: none), and how far it has gone. +const Tag = struct { + from: u64, + to: u64, + p: f32, + + fn moving(tag: Tag) bool { + return tag.from != tag.to and tag.p < 1; } }; -- cgit v1.3