summaryrefslogtreecommitdiff
path: root/anim/scenes/fib.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/fib.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/fib.zig')
-rw-r--r--anim/scenes/fib.zig59
1 files changed, 59 insertions, 0 deletions
diff --git a/anim/scenes/fib.zig b/anim/scenes/fib.zig
new file mode 100644
index 0000000..e98727d
--- /dev/null
+++ b/anim/scenes/fib.zig
@@ -0,0 +1,59 @@
+//! Recursion: fib(5), a call at a time. The debugger's whole context, from
+//! one recording of every instruction, and beside it the lens: every call
+//! of fib as a tree.
+//!
+//! How it moves (design/motion.md): the picture is established, then one
+//! call is walked in full (the line fires, `rdi` and `rsp` strike, the
+//! stack's words, then the backtrace's row and the tree's node; last the
+//! marks move on); the way down the first branch is hurried, a run that
+//! ramps in and out; the first return is walked (the answer in `rax`, the
+//! frame leaving); the rest of the tree is a sprint with the context
+//! veiled; and the last return, `fib(5)` itself, is walked again.
+const anim = @import("anim");
+const canim = @import("canim");
+const recordings = @import("recordings");
+
+pub const background = canim.background;
+pub const scene = anim.Live(frame, struct {});
+
+fn frame(s: *anim.Frame) void {
+ const rec = canim.open(recordings.steps);
+ // The calls of fib, in the order they are made: fib(5), fib(4), fib(3), fib(2), fib(1), fib(0), ...
+ const call = struct {
+ fn of(r: *canim.Recording, nth: usize) canim.Recording.Call {
+ return r.call("fib", nth);
+ }
+ }.of;
+ const split = canim.layout.split.beside;
+ // From main's line, about to call fib(5), to where fib(5) has returned to it.
+ var at = canim.cursor(s, rec, rec.lineMoment(10, rec.call("main", 0).enter));
+ at.levels = .{ .idea = .calls, .source_rows = 8 };
+ at.journey(.line, call(rec, 0).exit.?);
+ const ctx = canim.context(s, at, .{ .split = split });
+ // The lens: every call of fib as a tree, beside the frames they are on the stack.
+ const tree = canim.callTree(s, .{ .cursor = at, .box = split.lens, .function = "fib", .focus = true });
+ var says: canim.Narrator = .{};
+
+ // Staging: the whole picture, still, before a word; the words, before a step.
+ const joins = canim.ties(s, .{ .cursor = at });
+ canim.establish(s, .{ ctx.clock, ctx.source, ctx.disasm, ctx.registers, ctx.stack, ctx.backtrace, tree, joins });
+ says.line(s, "`fib` calls itself. A call is a frame on the stack and a node\nin the tree; its argument arrives in `rdi`.");
+ // The call, once, in full; and the two lines that lead to the next one.
+ at.walk(s, .line, rec.lineMoment(6, call(rec, 0).enter));
+ s.wait(canim.theme.time.beat);
+
+ // Pacing: the same three lines three times more. Seen once, so
+ // hurried: down the first branch at a run, to the call that does not call.
+ at.hurry(s, .line, rec.lineMoment(5, call(rec, 4).enter), .{});
+
+ says.line(s, "`fib(1)` needs no other call. Its answer leaves in `rax`,\nand its frame goes.");
+ // The return, in full: what recursion is for.
+ at.walk(s, .line, call(rec, 4).exit.?);
+
+ says.line(s, "And so on through every branch: fifteen calls,\nto add up `fib(5)`.");
+ // The pattern is known: the rest of the tree at a sprint, the tree its
+ // subject, slowing into the last answers.
+ at.hurry(s, .line, call(rec, 10).exit.?, .{ .pace = canim.theme.time.sprint });
+ at.walk(s, .line, call(rec, 0).exit.?);
+ s.wait(canim.theme.time.before_cut);
+}