diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-12 04:45:57 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-12 07:03:05 -0300 |
| commit | 4907e35bc45d12102d0e09380994814fc2e0a369 (patch) | |
| tree | 7cfd90224653d73b63fbadaf2881fa0e6ba92860 /anim/scenes/intro_code.zig | |
| parent | ebdebe04a76f0302aeb24c1ac08fa9217b1a8257 (diff) | |
| download | computeranim-4907e35bc45d12102d0e09380994814fc2e0a369.tar.gz computeranim-4907e35bc45d12102d0e09380994814fc2e0a369.zip | |
canim: the introduction, from the review
The introduction records the plain build (clang -O0, no instrumentation),
so reverse's frame is the compiler's own push, mov and sub. The stack
chapter says its convention once and keeps four free words over rsp so
a push moves the pin and nothing else; reverse's rows stand under main's
and are stepped, each touching its word, the call before the push, the
aim drawn head first to the row it returns to. The close-up frames the
bytes and the stack together with their 128 bytes marked. Nothing is
named before it is shown; offsets are written in hex as the operands are;
the dump folds into its tag; the map is announced before it is shown.
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 | 102 |
1 files changed, 55 insertions, 47 deletions
diff --git a/anim/scenes/intro_code.zig b/anim/scenes/intro_code.zig index b50c971..cbfa36b 100644 --- a/anim/scenes/intro_code.zig +++ b/anim/scenes/intro_code.zig @@ -6,13 +6,16 @@ //! 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, each pane's minimap drawing itself -//! last; then the map (`surface`). The texts `above` the aligned panel, -//! then below the working frame, and the last one on the map. +//! last; then the map (`surface`). It opens on chapter II's last picture, +//! its state column staying veiled until the decoded code spans it. The +//! texts `above` the aligned panel, then below the working frame, the +//! last landing before the map surfaces under it. const std = @import("std"); const anim = @import("anim"); const sk = @import("sketch"); const canim = @import("canim"); const recordings = @import("recordings"); +const two = @import("intro_stack.zig"); pub const background = canim.background; pub const scene = anim.Live(frame, struct {}); @@ -45,43 +48,33 @@ const Page = struct { /// Chapter II's last picture (scenes/intro_stack.zig, its layout and texts /// as there): its registers and stack, a context of their own at II's last -/// moment; main's rows, faint; II3's text dimmed and II4's. -fn lastOfTwo(s: *anim.Frame, rec: *canim.Recording) struct { panels: [3]anim.Obj, texts: [2]anim.Obj } { +/// moment, the window held as II holds it; main's rows, faint, and reverse's +/// first rows under them; II4's text dimmed and II5's. +fn lastOfTwo(s: *anim.Frame, rec: *canim.Recording) struct { state: [2]anim.Obj, code: [2]anim.Obj, texts: [2]anim.Obj } { const enter = rec.call("reverse", 0).enter; const last = enter + 3; - const row = canim.theme.metric.context.row; - const head = canim.theme.metric.context.tag + canim.theme.metric.context.pad; var at = canim.cursor(s, rec, enter); at.journey(.moment, last); - at.levels = .{ .fire = .disasm, .source_rows = 14 }; - at.jump(s, last); + at.levels = .{ .fire = .disasm, .source_rows = 14, .introduction = true }; + // As II walked it: its push, `mov` and `sub` the steps behind its last moment. + at.jumpWalked(s, enter, last); var split = canim.layout.split.none; split.backtrace.h = 0; const ctx = canim.context(s, at, .{ .split = split }); - const rb = ctx.stage.first.registers; - ctx.stage.first.stack.h = canim.layout.panelH(18); - ctx.stage.first.stack.y = rb.y + rb.h + canim.theme.canvas.row_gap; - const top = ctx.stage.first.stack.y + head; - const rsp = rec.register(enter, "rsp"); - const window = rec.register(last, "rsp") - 16; - const rowY = struct { - fn y(t0: f32, from: u64, addr: u64) f32 { - return t0 + row * @as(f32, @floatFromInt(@as(i64, @bitCast(addr -% from)) >> 3)); - } - }.y; + const g = two.layout(ctx.stage, rec, enter); + two.hold(s, ctx.stage, enter); const stack = canim.add(s, canim.Stack{ .cursor = ctx.cursor, .stage = ctx.stage }); - const back_y = rowY(top, rsp - 8 - 16, rsp); // (Placed at the origin: it draws at its own box.) - const caller = s.custom(s.new(canim.descent.Caller{ .rec = rec, .at = enter, .call = rec.register(enter - 1, "rip"), .box = .{ .x = canim.theme.layout.program.x, .y = back_y + row / 2 + 176, .w = canim.theme.layout.program.w, .h = 4 * row }, .in = s.value(999), .faint = s.value(1) }), .{ .x = -640, .y = -360, .scale = canim.ui.scale }); + const caller = s.custom(s.new(canim.descent.Caller{ .rec = rec, .at = enter, .call = rec.register(enter - 1, "rip"), .box = g.caller, .in = s.value(999), .faint = s.value(1) }), .{ .x = -640, .y = -360, .scale = canim.ui.scale }); const left = canim.theme.canvas.margin_x; const said = [2]canim.Aside{ - .{ .text = "A function's words are its frame: the saved rbp, its locals, the way back.", .x = left, .level = (rowY(top, window, window + 16) + rowY(top, window, rsp + 8)) / 2, .dim = s.value(1) }, - .{ .text = "The registers are the other place values live: seventeen of them.", .x = left, .level = rb.y + head + row * 2.5, .dim = s.value(0) }, + .{ .text = two.texts[two.texts.len - 2], .x = left, .level = g.span_y, .dim = s.value(1) }, + .{ .text = two.texts[two.texts.len - 1], .x = left, .level = g.registers_y, .dim = s.value(0) }, }; var texts: [2]anim.Obj = undefined; for (said, &texts) |a, *o| o.* = s.custom(s.new(a), .{ .x = -640, .y = -360, .scale = canim.ui.scale }); - for ([_]anim.Obj{ ctx.registers, stack, caller, texts[0], texts[1] }) |o| s.play(.{o.fadeIn()}, .{ .seconds = 0 }); - return .{ .panels = .{ ctx.registers, stack, caller }, .texts = texts }; + for ([_]anim.Obj{ ctx.registers, stack, caller, ctx.disasm, texts[0], texts[1] }) |o| s.play(.{o.fadeIn()}, .{ .seconds = 0 }); + return .{ .state = .{ ctx.registers, stack }, .code = .{ caller, ctx.disasm }, .texts = texts }; } /// The variables whose tags the nodes carry, as the list scene's. @@ -89,6 +82,10 @@ const tracked = [_][]const u8{ "prev", "cur", "next", "head" }; fn frame(s: *anim.Frame) void { const rec = canim.open(recordings.intro); + // list.c's types as the pass would tell them: the recording is of the + // plain build, which tells none (its locals are the debug info's). + rec.declare("head", "*`struct node`"); + rec.declare("`struct node`", "struct(16){value@0:i64;next@8:*`struct node`;}"); 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]"); @@ -109,11 +106,12 @@ fn frame(s: *anim.Frame) void { var at = canim.cursor(s, rec, moment); at.journey(.moment, moment + 1); - at.levels = .{ .idea = .data, .follow = t.move, .source_rows = 8 }; + at.levels = .{ .idea = .data, .follow = t.move, .source_rows = 8, .introduction = true }; 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 list = canim.nodes(s, .{ .cursor = at, .stage = ctx.stage, .root = "head", .track = &tracked, .named = true }); + ctx.map.add(s, canim.Nodes{ .cursor = at, .stage = ctx.map.stage, .root = "head", .track = &tracked, .named = true }); + // The relations, and rax's link to the node as III3 names it. + const joins, const rax_link = ctx.tiesWith(s, "rax", 1.0); // Each pane's minimap under the page until III4, where they draw themselves last, top down // (over the panels, under the aligned rows landing on them; on from the panels' first frame). @@ -125,15 +123,17 @@ fn frame(s: *anim.Frame) void { 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 = .{}; + // Texts above the panel that spans both columns: twice a beside's line (two lines in the band of 120). + var asides: canim.Asides = .{ .wrap = 2 * 40 }; const left = canim.theme.canvas.margin_x; const above = canim.theme.canvas.stage.y + 40; - // From II's last picture: it gives way (its texts 12 f, the rest 18 f), the stage clear for the code. + // From II's last picture: its texts and code give way (12 f, 18 f); its + // state column stays, veiled at 50%, until the decoded code takes both columns. s.wait(t.beat); s.play(.{ opening.texts[0].fadeOut(), opening.texts[1].fadeOut() }, .{ .seconds = t.caption_out, .ease = canim.ease.exit }); s.cursor -= t.caption_out; - s.play(.{ opening.panels[0].fadeOut(), opening.panels[1].fadeOut(), opening.panels[2].fadeOut() }, .{ .seconds = f(18), .ease = anim.ease.linear }); + s.play(.{ opening.code[0].fadeOut(), opening.code[1].fadeOut(), opening.state[0].move(.{ .opacity = 0.5 }), opening.state[1].move(.{ .opacity = 0.5 }) }, .{ .seconds = f(18), .ease = anim.ease.linear }); s.wait(t.beat); // III1: the code's bytes, one instruction's framed. @@ -142,16 +142,23 @@ fn frame(s: *anim.Frame) void { 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); + // III2: decoded into its row, its neighbours at a run, each line heading its run. + asides.say(s, std.fmt.allocPrint(s.arena, "Decoded: `{s}`, from line {d}. Each line heads the instructions it compiled to.", .{ text, insn.line orelse 0 }) catch "", left, above); + // II's state column goes as the decoded rows come to span it (12 f). + s.play(.{ opening.state[0].fadeOut(), opening.state[1].fadeOut() }, .{ .seconds = f(12), .ease = anim.ease.linear }); + s.cursor -= f(12); run(s, al.decode, 60); - run(s, al.rows_in, 2 * 32 + 8); + // The neighbours at half the run's pace (rows 4 f apart): they come while the text is read. + s.play(.{al.rows_in.to(0)}, .{ .seconds = 0 }); + s.play(.{al.rows_in.to(2 * 32 + 8)}, .{ .seconds = 2 * f(2 * 32 + 8), .ease = anim.ease.linear }); 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, 80); + asides.say(s, "Two columns: each line by its first instruction. A square after `]`: a byte it touches.", left, above); + // `align` at two thirds of its pace (120 f for 80): the two columns come while the text is read. + s.play(.{al.form.to(0)}, .{ .seconds = 0 }); + s.play(.{al.form.to(80)}, .{ .seconds = f(120), .ease = anim.ease.linear }); s.wait(t.beat); // Into the working frame: the texts above leave; `stack`: the lines glide to @@ -168,7 +175,7 @@ fn frame(s: *anim.Frame) void { // III3: the node it reads, as bytes and drawn: the band comes in, its // elements rising from their bytes. No camera: at x1.5 the drawing's // nodes and its bytes do not both fit the frame, and the band is whole at x1. - says.line(s, "`rax` points at a list node on the heap:\nits bytes, and drawn, the node."); + says.line(s, "Later, at line 21, `rax` points at a list node on the heap:\nits bytes, and drawn, the node."); // The heap's dump first, in the band's right half (18 f); then the nodes drawn from it, rising (`establish`). s.play(.{ctx.stage.drawing.to(0)}, .{ .seconds = 0 }); s.play(.{list.fadeIn()}, .{ .seconds = f(18), .ease = anim.ease.linear }); @@ -177,20 +184,21 @@ fn frame(s: *anim.Frame) void { s.cursor -= f(12); ctx.establish(s, .{}, 3); s.wait(t.beat); - // III4: the whole frame; each pane's minimap draws itself, last, top down (24 f, 48 f apart). - says.line(s, "This is the whole frame.\nEvery view in it is these same bytes."); + // rax framed as read, its link up to the node it points at, held, drawn back. + rax_link.play(s); + s.wait(rax_link.total()); + s.wait(t.beat); + // III4: the whole frame; each pane's minimap draws itself, last, top down (24 f, 72 f apart: while the text is read). + says.line(s, "This is the whole frame. Every view in it is these same bytes;\neach strip, the whole of its pane."); const strips_from = s.cursor; for (strips, 0..) |o, k| { - s.cursor = strips_from + f(48 * @as(f32, @floatFromInt(k))); + s.cursor = strips_from + f(72 * @as(f32, @floatFromInt(k))); s.play(.{o.fadeOut()}, .{ .seconds = f(24), .ease = anim.ease.linear }); } s.wait(t.beat); - // III5: the map, and its text on it, in the key's corner (the middle column's foot, empty on this map). - s.wait(@max(says.read_by - s.cursor, 0)); - s.play(.{says.current.?.fadeOut()}, .{ .seconds = t.caption_out, .ease = canim.ease.exit }); - s.wait(t.caption_gap); + // III5: its text lands before the move, under the map as under the frame; then `surface`. + says.line(s, "And all of it at once: the map."); ctx.map.surface(s); - asides.say(s, "And all of it at once:\nthe map.", 528, 720); - s.wait(@max(asides.read_by - s.cursor, 0)); + s.wait(@max(says.read_by - s.cursor, 0)); s.wait(t.before_cut); } |
