summaryrefslogtreecommitdiff
path: root/anim/scenes/list.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 14:48:26 -0300
committerGabriel Schneider <[email protected]>2026-11-10 15:14:31 -0300
commit7e9bf9e6e85c6c6e7a400d4fa0b43b77133ed3cb (patch)
treea6add92cd4dcbbf4c31cd1ce989d99b190258353 /anim/scenes/list.zig
parented46c51fe127377eb1fde8dee83da984e0f61860 (diff)
downloadcomputeranim-7e9bf9e6e85c6c6e7a400d4fa0b43b77133ed3cb.tar.gz
computeranim-7e9bf9e6e85c6c6e7a400d4fa0b43b77133ed3cb.zip
canim: animations of recordings, as a debugger's whole context with a lens beside it
A package of its own (anim/), on sketchbook's anim module and pardes's syntax. A scene opens a recording, takes a cursor into it, and declares blocks that read the moment the cursor is at: the state column (registers each followed as a pointer and inked by where it points, the stack telescope, the backtrace), the program column (the whole source, the disassembly in address order, and the scene's lens: a node-link list over a hexdump of its heap, array cells, a call tree, a syscall crossing), and ties between them. Motion is a step told as a sentence (the line fires, its effects cascade a level at a time, the mark moves on last), timed by what the step contains; walk, hurry and sprint pace a loop. Five scenes from real recordings of fib, a linked list, a sort and syscalls. First drafts, by the agent's own handover: the frame of the design's second revision, the hexdump lens and the ties; no disassembly annotations, no gallery, scenes not yet reviewed against the mocks.
Diffstat (limited to 'anim/scenes/list.zig')
-rw-r--r--anim/scenes/list.zig52
1 files changed, 52 insertions, 0 deletions
diff --git a/anim/scenes/list.zig b/anim/scenes/list.zig
new file mode 100644
index 0000000..5f2c843
--- /dev/null
+++ b/anim/scenes/list.zig
@@ -0,0 +1,52 @@
+//! A linked list reversed in place: no node moves, each `next` is rewritten
+//! to point the other way. The debugger's context, and beside it the lens:
+//! the nodes and their arrows over a hexdump of the heap they are made of.
+//!
+//! How it moves (design/motion.md): the picture is established; the first
+//! trip round the loop is walked (each local strikes on the stack and in
+//! the table, then its tag slides to its node; the pointer's rewrite is
+//! armed with its old arrow going dashed, strikes, and the new arrow grows
+//! to the node it lands on); the second trip is hurried, with a rest; the
+//! third is walked again, and `head` takes the last node.
+const anim = @import("anim");
+const canim = @import("canim");
+const recordings = @import("recordings");
+
+pub const background = canim.background;
+pub const scene = anim.Live(frame, struct {});
+
+/// Each a pigment, the same on its tag in the list and in the table.
+const tracked = [_][]const u8{ "prev", "cur", "next" };
+
+fn frame(s: *anim.Frame) void {
+ const rec = canim.open(recordings.list);
+ const t = canim.theme.time;
+ const reverse = rec.call("reverse", 0);
+ // From reverse's first line (the list of three is built) to its last.
+ var at = canim.cursor(s, rec, rec.lineMoment(18, reverse.enter));
+ // The nodes are the idea; a tag slides and an arrow grows after its strike.
+ at.levels = .{ .cpu = false, .idea = .data, .follow = t.move, .source_rows = 5 };
+ const end = rec.lineMoment(27, reverse.enter);
+ at.journey(.line, end);
+ // The idea is the subject: the lens a size up, the nodes over the bytes they are.
+ const split = canim.layout.split.subject;
+ const ctx = canim.context(s, at, .{ .split = split, .quiet = true });
+ const lens = split.lens;
+ const list = canim.nodes(s, .{ .cursor = at, .box = .{ .x = lens.x, .y = lens.y, .w = lens.w, .h = 192 }, .root = "head", .track = &tracked, .focus = true });
+ const bytes = canim.hexdump(s, .{ .cursor = at, .box = .{ .x = lens.x, .y = lens.y + 204, .w = lens.w, .h = lens.h - 204 }, .base = rec.allocations[0].ptr - 16 });
+ var says: canim.Narrator = .{};
+
+ const joins = canim.ties(s, .{ .cursor = at });
+ canim.establish(s, .{ ctx.clock, ctx.source, ctx.disasm, ctx.registers, ctx.stack, ctx.backtrace, list, bytes, joins });
+ says.line(s, "A list is nodes on the heap, each holding the address of the next.\nReversing it moves no node: it rewrites every `next`.");
+ // Three names are set up, then the first trip round the loop, in full.
+ at.walk(s, .line, rec.lineMoment(20, rec.lineMoment(24, reverse.enter)));
+ says.line(s, "`next` remembers the way on, `cur->next` is turned round,\nand `prev` and `cur` each step along.");
+ // Pacing: the second trip is the same, so hurried; it keeps its rest.
+ at.hurry(s, .line, rec.lineMoment(20, rec.lineMoment(24, at.moment(s))), .{});
+ // The third in full again: the last `next` turns, and `cur` runs off the end.
+ at.walk(s, .line, rec.lineMoment(26, at.moment(s)));
+ says.line(s, "`head` takes the last node: the same three nodes,\nin the same places, read the other way.");
+ at.walk(s, .line, end);
+ s.wait(t.before_cut);
+}