diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-11 23:46:02 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-12 01:40:04 -0300 |
| commit | 60e07feef401d9044db3a1c925cb9d1f6d20dac9 (patch) | |
| tree | 98957ba8425193f686c8e8692cd10a10f27dbf4b /anim/scenes/intro_code.zig | |
| parent | 9c0696447dbc5cf37e56aee562c7ebba4f4d4e6b (diff) | |
| download | computeranim-60e07feef401d9044db3a1c925cb9d1f6d20dac9.tar.gz computeranim-60e07feef401d9044db3a1c925cb9d1f6d20dac9.zip | |
canim: relations as one data-oriented subsystem; aim; the ASan pair; the introduction's chapters
From the user. Relations between panes are one subsystem: per-frame
tables of places and values in struct-of-arrays, owned by the frame;
the kinds one table of data; a resolver of pure passes (join, filter,
priority, cut) unit-tested on hand-written tables. Ported kinds draw
byte-identical frames; a synthetic map of 4000 places and 6000 values
resolves in 0.56 ms against the old table's 5.7. aim, a word holding a
code address tied to its row, is the first new kind, off unless a scene
turns it on.
The ASan pair: one overflow built plain and with ASan, recorded by
instruction; the frame as bytes eight a row; the plain run goes on alone
in the column, its return address aimed at main's row until the letters
reach it; the fault at ret. The introduction's three chapters are built
and tested, not yet exported. Annotations, rows and scrolls that changed
in one frame now fade; captions stand twelve seconds at most.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/scenes/intro_code.zig')
| -rw-r--r-- | anim/scenes/intro_code.zig | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/anim/scenes/intro_code.zig b/anim/scenes/intro_code.zig new file mode 100644 index 0000000..a5660ed --- /dev/null +++ b/anim/scenes/intro_code.zig @@ -0,0 +1,110 @@ +//! The introduction, chapter III: code and meaning (design/motion.md, "A +//! scene: the introduction", III1 to III5; mocks 32, 33, 36). On the +//! `list` recording at the load in `reverse` (line 21, `node *next = +//! cur->next;`, the instruction that reads `cur->next`): the code's bytes +//! as a dump row, that instruction's four framed; `decode`d into its row +//! of `aligned` (`interleaved`), its neighbours at a run, each line level +//! with its run; then `align` to `columns`; then the working frame with the +//! nodes drawn from the heap's bytes; then the map (`surface`). The texts +//! `above` the aligned panel, then below the working frame. +const std = @import("std"); +const anim = @import("anim"); +const canim = @import("canim"); +const recordings = @import("recordings"); + +pub const background = canim.background; +pub const scene = anim.Live(frame, struct {}); + +const t = canim.theme.time; + +fn f(frames: f32) f32 { + return frames / 60; +} + +fn run(s: *anim.Frame, v: anim.Value, frames: f32) void { + s.play(.{v.to(0)}, .{ .seconds = 0 }); + s.play(.{v.to(frames)}, .{ .seconds = f(frames), .ease = anim.ease.linear }); +} + +fn on(rec: *canim.Recording, from: u64, text: []const u8) u64 { + var buf: [256]u8 = undefined; + var i = from; + while (i < rec.end()) : (i += 1) if (rec.instruction(i, rec.register(i, "rip"), &buf)) |here| if (std.mem.indexOf(u8, here.text, text) != null) return i; + return from; +} + +/// The variables whose tags the nodes carry, as the list scene's. +const tracked = [_][]const u8{ "prev", "cur", "next", "head" }; + +fn frame(s: *anim.Frame) void { + const rec = canim.open(recordings.list); + const reverse = rec.call("reverse", 0); + // The load: `cur->next` read, line 21's second instruction. + const moment = on(rec, rec.lineMoment(21, reverse.enter), "[rax + 8]"); + const pc = rec.register(moment, "rip"); + var buf: [256]u8 = undefined; + const insn = rec.instruction(moment, pc, &buf).?; + // Its bytes and its text as canim writes it (the size word dropped), from the recording. + var code: [16]u8 = undefined; + var known: [16]bool = undefined; + rec.moment(moment).read(pc, code[0..insn.len], known[0..insn.len]) catch {}; + var hex: std.ArrayList(u8) = .empty; + for (code[0..insn.len], 0..) |b, k| hex.print(s.arena, "{s}{x:0>2}", .{ if (k > 0) " " else "", b }) catch {}; + const text = std.mem.replaceOwned(u8, s.arena, insn.text, "qword ptr ", "") catch insn.text; + + var at = canim.cursor(s, rec, moment); + at.journey(.moment, moment + 1); + at.levels = .{ .idea = .data, .follow = t.move, .source_rows = 8 }; + const ctx = canim.context(s, at, .{ .split = canim.layout.split.subject }); + const list = canim.nodes(s, .{ .cursor = at, .stage = ctx.stage, .root = "head", .track = &tracked }); + ctx.map.add(s, canim.Nodes{ .cursor = at, .stage = ctx.map.stage, .root = "head", .track = &tracked }); + const joins = ctx.ties(s); + + const al = s.new(canim.Aligned.init(s, rec, moment)); + const panel = s.custom(al, .{ .x = -640, .y = -360, .scale = canim.ui.scale }); + s.play(.{panel.fadeIn()}, .{ .seconds = 0 }); + var asides: canim.Asides = .{}; + const left = canim.theme.canvas.margin_x; + const above = canim.theme.canvas.stage.y + 40; + + // III1: the code's bytes, one instruction's framed. + s.wait(1.0); + asides.say(s, std.fmt.allocPrint(s.arena, "Code is bytes too: `{s}` is one instruction.", .{hex.items}) catch "", left, above); + s.wait(t.caption_lead); + run(s, al.bytes, 12 + 2 * 15 + 12 + 6); + s.wait(t.beat); + + // III2: decoded into its row, its neighbours at a run, each line level with its run. + asides.say(s, std.fmt.allocPrint(s.arena, "Decoded: `{s}`, from line {d}. Each line sits level with its code.", .{ text, insn.line orelse 0 }) catch "", left, above); + run(s, al.decode, 60); + run(s, al.rows_in, 2 * 32 + 8); + run(s, al.chrome, 24); + s.wait(t.beat); + + // III2, the other form: two columns, each line level with the first of its instructions. + asides.say(s, "Two columns: each line level with its first instruction.", left, above); + run(s, al.form, 72); + s.wait(t.beat); + + // Into the working frame: the texts above leave, the panel goes, the frame comes in. + asides.leave(s); + s.play(.{panel.fadeOut()}, .{ .seconds = f(12), .ease = anim.ease.linear }); + var says: canim.Narrator = .{}; + var cam: canim.Camera = .{}; + canim.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, ctx.source, ctx.disasm, joins }); + // III3: the node it reads, as bytes and drawn: the band comes in, its + // elements rising from their bytes, and the camera nearer on it (x1.5). + says.line(s, "`rax` points at a list node on the heap:\nits bytes, and drawn, the node."); + ctx.establish(s, .{list}, 3); + cam.go(s, .{ .x = 512, .y = 48, .w = 896, .h = 296 }, 1.5, .{}); + s.wait(t.beat); + // III4: the whole frame: the camera back to x1. + says.line(s, "This is the whole frame.\nEvery view in it is these same bytes."); + cam.back(s, .{}); + s.wait(t.beat); + // III5: the map. + says.line(s, "And all of it at once: the map."); + ctx.map.surface(s); + says.close(s); + cam.apply(s); +} |
