diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 14:48:26 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 15:14:31 -0300 |
| commit | 7e9bf9e6e85c6c6e7a400d4fa0b43b77133ed3cb (patch) | |
| tree | a6add92cd4dcbbf4c31cd1ce989d99b190258353 /anim/scenes/zoom.zig | |
| parent | ed46c51fe127377eb1fde8dee83da984e0f61860 (diff) | |
| download | computeranim-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/zoom.zig')
| -rw-r--r-- | anim/scenes/zoom.zig | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/anim/scenes/zoom.zig b/anim/scenes/zoom.zig new file mode 100644 index 0000000..6eb3248 --- /dev/null +++ b/anim/scenes/zoom.zig @@ -0,0 +1,50 @@ +//! One line of C, all the way down: the instructions it is, the registers +//! they change, the words they write on the stack. Every level is on +//! screen the whole time; the scene steps an instruction at a time and +//! says which one to look at. +//! +//! How it moves (design/motion.md): a step is an instruction: the pc's +//! row fires in the disassembly, the registers it changed strike, then +//! the stack, and the mark walks down the listing. The camera goes +//! nearer once, announced (its target framed, the rest cleared first), +//! for the call: the eight bytes of the way back, and the frame built +//! under them; then back, and the line is where it was, one call deeper. +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); + const t = canim.theme.time; + // fib(5), about to run line 6: `return fib(n-1) + fib(n-2);`. Its first call is fib(4). + const call = rec.call("fib", 1); + var at = canim.cursor(s, rec, rec.lineMoment(6, rec.call("fib", 0).enter)); + const end = rec.lineMoment(6, call.enter); + at.journey(.moment, end); + // A step is an instruction: it fires on the pc's row. + at.levels = .{ .fire = .disasm, .source_rows = 14 }; + const split = canim.layout.split.none; + const ctx = canim.context(s, at, .{ .split = split }); + var cam: canim.Camera = .{}; + 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, joins }); + says.line(s, "A line of C is a handful of instructions.\nThis one calls `fib(n-1)`: follow it down."); + // The CPU's level: an instruction a step. The argument is worked out in `rdi`. + at.walk(s, .moment, call.enter - 1); + + says.line(s, "`call` writes eight bytes on the stack: the way back.\nThe new frame saves `rbp` under them, then its own `n`."); + // Nearer, for the bytes: the stack alone, twice the size. + cam.go(s, canim.layout.stack, 2, .{ ctx.source, ctx.disasm, ctx.registers, ctx.backtrace }); + at.walk(s, .moment, call.enter + 4); + cam.back(s, .{ ctx.source, ctx.disasm, ctx.registers, ctx.backtrace }); + + says.line(s, "Eleven instructions and three words of stack later\n`fib(4)` begins: the same lines, one call deeper."); + at.walk(s, .line, end); + s.wait(t.before_cut); + cam.apply(s); +} |
