From eab50d1c040774351f332a1568fa332c377860bd Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 12 Nov 2026 11:32:59 -0300 Subject: canim: the introduction as one video, with a chapter on registers From the user. One scene, intro, in four chapters: memory, registers, the stack, code and meaning (210 s). The registers chapter builds the panel before the stack needs it: sixteen rows with their chains, rip pinned on the code band and rsp and rbp on the stack's, rdi opened into its parts as mov edi changes one byte, a call to malloc stepped over with its result in rax, the registers a scene never changes folded. The chapters join at seams that say their title and keep it as the clock's label; one recording (from push(9), no agent, the heap from --heap) and one clock. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa --- anim/src/Recording.zig | 57 +++++++++++++++- anim/src/aside.zig | 74 +++++++++++++++++++-- anim/src/context.zig | 175 ++++++++++++++++++++++++++++++++++++++++++++++--- anim/src/cursor.zig | 40 +++++++++-- anim/src/disasm.zig | 57 ++++++++++++++-- anim/src/hexdump.zig | 14 ++-- anim/src/map.zig | 15 ++++- anim/src/objects.zig | 2 +- anim/src/regroup.zig | 35 ++++++---- anim/src/root.zig | 20 +++++- anim/src/segments.zig | 42 +++++++++++- anim/src/ties.zig | 5 ++ anim/src/words.zig | 53 +++++++++++++++ 13 files changed, 541 insertions(+), 48 deletions(-) (limited to 'anim/src') diff --git a/anim/src/Recording.zig b/anim/src/Recording.zig index bcc8903..c6a305f 100644 --- a/anim/src/Recording.zig +++ b/anim/src/Recording.zig @@ -58,7 +58,11 @@ pub const Mark = struct { moment: u64, text: []const u8 }; /// An allocation ever made: its place in this list is its identity, the /// same in every view. -pub const Born = struct { ptr: u64, size: u64, moment: u64, event: u64 }; +/// An allocation: the agent's (`event` its event), or, in a recording with +/// none and glibc's heap at each stop (`--heap`), a chunk in use there, its +/// body (`ptr` 16 into the chunk, `size` the chunk's less its 16), from the +/// first stop that has it to the first that does not (`gone`). +pub const Born = struct { ptr: u64, size: u64, moment: u64, event: u64, gone: u64 = std.math.maxInt(u64) }; /// A run of bytes a moment changed, or read. pub const Span = struct { addr: u64, len: u64 }; @@ -125,6 +129,8 @@ calls: []Call = &.{}, syscalls: []Syscall = &.{}, marks: []Mark = &.{}, allocations: []Born = &.{}, +/// Whether `allocations` were read off the heap (`allocationsFromHeap`). +heap_read: bool = false, /// The registers of `tid` after each moment (the last known, before any). registers: []zt.Regs = &.{}, write_spans: Spans = .{}, @@ -607,6 +613,55 @@ fn index(r: *Recording) !void { r.globals = globals.items; } +/// A scene that draws the program's allocations from glibc's heap +/// (`--heap`) where no agent told them (the introduction's list nodes): +/// `allocations` read off the heap, once. Not by default: a scene of the +/// heap's own (`heap`) times its steps by what it draws, not by these. +pub fn allocationsFromHeap(r: *Recording) void { + if (r.allocations.len > 0 or r.heap_read) return; + r.heap_read = true; + r.allocations = heapBorn(r, r.arena.allocator()) catch &.{}; +} + +/// The program's allocations read off glibc's heap at each stop (`--heap`), +/// where no agent told them: each chunk in use but the tcache's own, from +/// the first stop that has it; `gone` at the first that does not. In the +/// order they were first seen, by address within one stop. +fn heapBorn(r: *const Recording, arena: std.mem.Allocator) ![]Born { + var out: std.ArrayList(Born) = .empty; + var scratch: std.heap.ArenaAllocator = .init(gpa); + defer scratch.deinit(); + var i: u64 = 0; + while (i <= r.end()) : (i += 1) { + _ = scratch.reset(.retain_capacity); + const h = (zt.heap.glibc(scratch.allocator(), r.moment(i), r.tid) catch null) orelse continue; + const own: u64 = if (h.tcache) |tc| tc.addr else 0; + for (h.chunks) |c| { + if (c.free or c.in != .none or c.addr + 16 == own or c.size() < 32) continue; + const ptr = c.addr + 16; + const known = for (out.items) |b| { + if (b.ptr == ptr and b.gone > i) break true; + } else false; + if (!known) try out.append(arena, .{ .ptr = ptr, .size = c.size() - 16, .moment = i, .event = std.math.maxInt(u64) }); + } + // What was in use and is not now has gone. + for (out.items) |*b| if (b.gone > i and b.moment < i) { + const still = for (h.chunks) |c| { + if (c.addr + 16 == b.ptr and !c.free and c.in == .none) break true; + } else false; + if (!still) b.gone = i; + }; + } + return out.items; +} + +/// The allocation live at `m` that holds `addr`: the agent's (`Moment.allocation`) or one read off the heap. +pub fn allocated(r: *const Recording, m: Moment, addr: u64) bool { + if ((m.allocation(addr) catch null) != null) return true; + for (r.allocations) |b| if (b.event == std.math.maxInt(u64) and addr >= b.ptr and addr - b.ptr < @max(b.size, 1) and b.moment <= m.index and m.index < b.gone) return true; + return false; +} + /// A string id for `text`, for names the recording did not define itself. fn intern(r: *Recording, text: []const u8) !u64 { const id = std.hash.Wyhash.hash(0, text) | 1 << 63; diff --git a/anim/src/aside.zig b/anim/src/aside.zig index c2c0ef8..66c8ce7 100644 --- a/anim/src/aside.zig +++ b/anim/src/aside.zig @@ -29,11 +29,13 @@ pub const Aside = struct { level: f32, /// 0 newest, 1 the account (no paper, `dim`). dim: anim.Value, + /// Units it has glided down from `level` to make room for a newer one. + drop: ?anim.Value = null, /// Characters a line, at most. wrap: usize = chars, pub fn draw(a: *const Aside, f: *sk.Frame, placed: anim.Placed) void { - const u = (ui.Ui{ .f = f, .at = placed }).moved(0, (1 - placed.pose.opacity) * theme.time.caption_rise); + const u = (ui.Ui{ .f = f, .at = placed }).moved(0, (1 - placed.pose.opacity) * theme.time.caption_rise + if (a.drop) |d| placed.value(d) else 0); const wrapped = wrap(u, a.text, a.wrap); const top = a.level - first; const h = first * 2 + @as(f32, @floatFromInt(wrapped.len - 1)) * line_pitch; @@ -50,39 +52,101 @@ pub const Aside = struct { /// until the last has been read, arrives (18 f, `enter`), and is followed /// by its lead (60 f); the one before it dims (18 f), or leaves (12 f, /// `exit`, then the caption's gap) where the new one would stand on it. +/// With a `floor`, one in the way glides down under it instead (24 f, +/// `glide`), the others under that with it, as far as the floor (past it, +/// it leaves), and three stand at most (the column's way). /// `leave`: all go together. pub const Asides = struct { shown: [8]?anim.Obj = @splat(null), dims: [8]anim.Value = undefined, + drops: [8]anim.Value = undefined, spans: [8][2]f32 = undefined, + /// Each text's first top, before it glided. + tops: [8]f32 = undefined, n: usize = 0, read_by: f32 = 0, /// Characters a line, at most, of the texts it says. wrap: usize = chars, + /// Where texts in the way glide down to, at most (null: they leave). + floor: ?f32 = null, pub fn say(a: *Asides, s: *anim.Frame, text: []const u8, x: f32, level: f32) void { s.wait(@max(a.read_by - s.cursor, 0)); const dim = s.value(0); - const made = s.new(Aside{ .text = text, .x = x, .level = level, .dim = dim, .wrap = a.wrap }); + const drop = s.value(0); + const made = s.new(Aside{ .text = text, .x = x, .level = level, .dim = dim, .wrap = a.wrap, .drop = drop }); const obj = s.custom(made, .{ .x = -640, .y = -360, .scale = ui.scale }); const span = [2]f32{ level - first, level + first + @as(f32, @floatFromInt(lines(text, a.wrap) - 1)) * line_pitch }; const at = s.cursor; var in_the_way = false; - for (a.shown[0..a.n], a.dims[0..a.n], a.spans[0..a.n]) |*o, d, other| { + var glided = false; + // With a floor: the two newest stay, top down, each in the way gliding under what is over it. + var keep: [8]bool = @splat(false); + if (a.floor) |floor| { + var kept: usize = 0; + var k = a.n; + while (k > 0) { + k -= 1; + if (a.shown[k] == null or kept == 2) continue; + keep[k] = true; + kept += 1; + } + var bottom = span[1] + 12; + while (true) { + // The highest kept one not yet placed. + var next: ?usize = null; + for (0..a.n) |j| if (keep[j] and a.shown[j] != null and (next == null or a.spans[j][0] < a.spans[next.?][0])) { + next = j; + }; + const j = next orelse break; + keep[j] = false; + const sp = a.spans[j]; + s.cursor = at; + s.play(.{a.dims[j].to(1)}, .{ .seconds = 18.0 / 60.0, .ease = easeGlide }); + s.cursor = at; + if (sp[1] + 12 <= span[0]) continue; + const shift = @max(bottom - sp[0], 0); + if (sp[1] + shift > floor) { + s.play(.{a.shown[j].?.fadeOut()}, .{ .seconds = time.caption_out, .ease = easeExit }); + a.shown[j] = null; + in_the_way = true; + continue; + } + if (shift > 0) { + s.play(.{a.drops[j].to(sp[0] + shift - a.tops[j])}, .{ .seconds = 24.0 / 60.0, .ease = easeGlide }); + a.spans[j] = .{ sp[0] + shift, sp[1] + shift }; + glided = true; + } + bottom = a.spans[j][1] + 12; + } + } + for (a.shown[0..a.n], a.dims[0..a.n], a.spans[0..a.n], 0..) |*o, d, other, j| { s.cursor = at; if (o.* == null) continue; + if (a.floor != null) { + // Past the two newest: it leaves. + var newer: usize = 0; + for (a.shown[j + 1 .. a.n]) |later| newer += @intFromBool(later != null); + if (newer >= 2) { + s.play(.{o.*.?.fadeOut()}, .{ .seconds = time.caption_out, .ease = easeExit }); + o.* = null; + } + continue; + } if (other[0] < span[1] + 12 and span[0] < other[1] + 12) { s.play(.{o.*.?.fadeOut()}, .{ .seconds = time.caption_out, .ease = easeExit }); o.* = null; in_the_way = true; } else s.play(.{d.to(1)}, .{ .seconds = 18.0 / 60.0, .ease = easeGlide }); } - // One it would stand on is gone first, then a gap: never two texts over each other. - s.cursor = if (in_the_way) at + time.caption_out + time.caption_gap else at; + // One it would stand on is gone first, then a gap, or has glided from under it: never two texts over each other. + s.cursor = at + @max(@as(f32, if (in_the_way) time.caption_out + time.caption_gap else 0), @as(f32, if (glided) 24.0 / 60.0 else 0)); s.play(.{obj.fadeIn()}, .{ .seconds = time.caption_in, .ease = easeEnter }); a.shown[a.n] = obj; a.dims[a.n] = dim; + a.drops[a.n] = drop; a.spans[a.n] = span; + a.tops[a.n] = span[0]; a.n += 1; a.read_by = s.cursor + time.caption(@intCast(std.unicode.utf8CountCodepoints(text) catch text.len)); s.wait(time.caption_lead); diff --git a/anim/src/context.zig b/anim/src/context.zig index 874a22a..577071d 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -103,16 +103,75 @@ pub const Registers = struct { folds: bool = true, /// Its tag's title (a `pair`'s names its run). title: []const u8 = "registers", + /// The quiet rows folded on a beat the scene plays (`fold`, 0 to 1: + /// every register a row, then folded; the introduction's II8); null: + /// folded, or as a dive has it. + fold: ?anim.Value = null, + /// One register opened into its bytes and its parts (`reg` `parts`, `unpack`, `pack`). + parts: ?*const Parts = null, + /// Registers framed as read on a beat the scene plays (rip's value too). + framed: []const Framed = &.{}, + + pub const Framed = struct { name: []const u8, shows: anim.Value }; + + /// `parts` (design/README.md, `reg`): register `name`'s value as its + /// eight bytes from 72 on a pitch of 30, high first, the zeros in front + /// at `pad`, and under it a row for each name its low bytes go by, + /// widest first, a bracket under the bytes it is. Clocks in frames: + /// `unpack` (the rows under it make room 0 to 18, the bytes spread 18 + /// to 30, the parts' rows 30 to 54, 6 f apart); `pack` (the parts' rows + /// fade 0 to 12, then the bytes close into the value and the rows close + /// up, 12 to 36); `echo`, 0 to 1: the part `echoed` and its bytes framed as read. + pub const Parts = struct { + name: []const u8, + unpack: anim.Value, + pack: anim.Value, + echo: anim.Value, + echoed: usize = 0, + + /// The rows it takes under its register (0 to 3). + fn room(p: *const Parts, placed: anim.Placed) f32 { + const un = placed.value(p.unpack); + if (un < 0) return 0; + const pk = placed.value(p.pack); + return 3 * theme.ease(.glide, std.math.clamp(un / 18, 0, 1)) * (1 - theme.ease(.glide, std.math.clamp((pk - 12) / 24, 0, 1))); + } + + /// How far its bytes have spread out of the value (0 closed, 1 open). + fn spread(p: *const Parts, placed: anim.Placed) f32 { + const un = placed.value(p.unpack); + if (un < 18) return 0; + const pk = placed.value(p.pack); + return theme.ease(.glide, std.math.clamp((un - 18) / 12, 0, 1)) * (1 - theme.ease(.glide, std.math.clamp((pk - 12) / 24, 0, 1))); + } + + /// How much part row `j`'s shows. + fn shows(p: *const Parts, placed: anim.Placed, j: usize) f32 { + const un = placed.value(p.unpack); + return std.math.clamp((un - 30 - 6 * @as(f32, @floatFromInt(j))) / 12, 0, 1) * (1 - std.math.clamp(placed.value(p.pack) / 12, 0, 1)); + } + + /// Its names, widest first (4, 2 and 1 bytes): `eax ax al`, `edi di dil`, `r8d r8w r8b`. + fn names(u: ui.Ui, name: []const u8) [3][]const u8 { + if (name.len >= 2 and std.ascii.isDigit(name[1])) return .{ u.print("{s}d", .{name}), u.print("{s}w", .{name}), u.print("{s}b", .{name}) }; + const bare = name[1..]; + if (bare.len == 2 and bare[1] == 'x') return .{ u.print("e{s}", .{bare}), bare, u.print("{c}l", .{bare[0]}) }; + return .{ u.print("e{s}", .{bare}), bare, u.print("{s}l", .{bare}) }; + } + }; const Shown = struct { regs: zt.Regs, moment: Recording.Moment }; pub fn draw(r: *const Registers, f: *sk.Frame, placed: anim.Placed) void { const box = r.stage.box(placed, .registers); const u = at(f, placed, box); - // In a dive the panel comes whole out of the map and folds as it lands (`Zoom.fold`). - const fold = if (ui.mapping) 1 else foldOf(box); + // In a dive the panel comes whole out of the map and folds as it lands (`Zoom.fold`); on a beat, as the scene plays it. + const fold = if (r.fold) |v| theme.ease(.glide, std.math.clamp(placed.value(v), 0, 1)) else if (ui.mapping) 1 else foldOf(box); var shape = box; shape.h = std.math.lerp(theme.layout.panelH(@floatFromInt(theme.metric.all_registers.len)), box.h, fold); + // A register opened into its parts: the rows under it make room. + const room = if (r.parts) |p| p.room(placed) * m.row else 0; + shape.h += room; const now = r.cursor.now(placed); const rec = r.cursor.rec; const is: Shown = .{ .regs = (now.moment().regs(rec.tid) catch null) orelse zt.Regs{}, .moment = now.moment() }; @@ -128,23 +187,30 @@ pub const Registers = struct { const full = fullRows(r.moves); const top = body.y + m.pad; // The quiet ones under a rule across, in pwndbg's order; rip the last row. - if (full < 16 and r.folds) u.faded(fold).fill(.{ .x = theme.stroke.rule, .y = top + @as(f32, @floatFromInt(full)) * m.row - 1, .w = shape.w - 2 * theme.stroke.rule, .h = theme.stroke.rule }, theme.color.rule); + // (On a beat the rule draws once they have folded, 12 f.) + const rule_shows = if (r.fold != null) std.math.clamp((placed.value(r.fold.?) - 1) * 3, 0, 1) else fold; + if (full < 16 and r.folds) u.faded(rule_shows).fill(.{ .x = theme.stroke.rule, .y = top + @as(f32, @floatFromInt(full)) * m.row - 1 + room, .w = shape.w - 2 * theme.stroke.rule, .h = theme.stroke.rule }, theme.color.rule); var rows_before: usize = 0; var quiet_before: usize = 0; + // The rows under an opened register are `room` lower. + var below: f32 = 0; for (theme.metric.all_registers[0..16], 0..) |name, i| { const unfolded = top + @as(f32, @floatFromInt(i)) * m.row; if (r.moves >> @intCast(i) & 1 != 0) { - r.row(u, now, is, was, name, std.math.lerp(unfolded, top + @as(f32, @floatFromInt(rows_before)) * m.row, fold), shape.w); + r.row(u, placed, now, is, was, name, std.math.lerp(unfolded, top + @as(f32, @floatFromInt(rows_before)) * m.row, fold) + below, shape.w); rows_before += 1; + if (r.parts) |p| if (std.mem.eql(u8, p.name, name)) { + below = room; + }; continue; } if (!r.folds) continue; - const y = std.math.lerp(unfolded, top + @as(f32, @floatFromInt(full + quiet_before / q.quiet_per_row)) * m.row, fold); + const y = std.math.lerp(unfolded, top + @as(f32, @floatFromInt(full + quiet_before / q.quiet_per_row)) * m.row, fold) + below; const x = std.math.lerp(theme.metric.context.side, q.quiet_from + @as(f32, @floatFromInt(quiet_before % q.quiet_per_row)) * q.quiet_pitch, fold); quiet_before += 1; r.quietRow(u, now, is, was, name, x, y, shape.w, fold); } - r.rip(u, now, std.math.lerp(top + 16 * m.row, top + @as(f32, @floatFromInt(if (r.folds) registerRows(r.moves) - 1 else full)) * m.row, fold), shape.w, is, was); + r.rip(u, placed, now, std.math.lerp(top + 16 * m.row, top + @as(f32, @floatFromInt(if (r.folds) registerRows(r.moves) - 1 else full)) * m.row, fold) + below, shape.w, is, was); veiled(u, shape, now.veil); } @@ -157,7 +223,15 @@ pub const Registers = struct { const read_shows = if (r.carrier(now, name, was.regs.named(name) orelse value)) |c| c.shows else 0; if (fold < 1) { const dx = x - theme.metric.context.side; - _ = rows.reg(u.faded(1 - fold).moved(dx, 0), y, w - dx, name, is.moment, value, .{ .hops = 1 - std.math.clamp(fold / 0.4, 0, 1) }); + const v = u.faded(1 - fold).moved(dx, 0); + const hops = 1 - std.math.clamp(fold / 0.4, 0, 1); + // Its chain reads memory as the panels show it: what a step wrote under it, from memory's strike (6 f), never in a frame. + const k = if (now.resting()) 1 else std.math.clamp(now.since(.memory, 0) / time.strike.in, 0, 1); + if (k < 1 and cursors.chainMoved(was.moment, is.moment, value)) { + v.text(.mono, theme.size.mono.context, m.side, rows.baseline(y), name, t.dim); + _ = rows.chain(v.faded(1 - k), m.chain_x, y, was.moment, value, w - dx - m.side, .{ .hops = hops }); + _ = rows.chain(v.faded(k), m.chain_x, y, is.moment, value, w - dx - m.side, .{ .hops = hops }); + } else _ = rows.reg(v, y, w - dx, name, is.moment, value, .{ .hops = hops }); } const hops = rows.quiet(u.faded(fold), x, y, name, is.moment, value, read_shows); anchor(u, i, hops, y, value, w); @@ -185,8 +259,12 @@ pub const Registers = struct { /// rip: where execution is, a current mark like the source's and the /// disassembly's; it moves with them, at the advance. - fn rip(r: *const Registers, u: ui.Ui, now: cursors.Now, y: f32, w: f32, is: Shown, was: Shown) void { + fn rip(r: *const Registers, u: ui.Ui, placed: anim.Placed, now: cursors.Now, y: f32, w: f32, is: Shown, was: Shown) void { const rec = r.cursor.rec; + defer for (r.framed) |fr| if (std.mem.eql(u8, fr.name, "rip")) { + const pc = rec.register(now.marks[1], "rip"); + u.read(.{ .x = theme.metric.context.chain_x, .y = y, .w = @as(f32, @floatFromInt(ui.digits(pc))) * ui.advance(theme.size.mono.context), .h = m.row }, std.math.clamp(placed.value(fr.shows), 0, 1)); + }; // The flags' corners are secondary: 6 f after the registers strike, // not with them; in a continue's wave, in its place after r15. const delay = if (now.plan.wave) ties.strikeDelay(now, index("eflags").?) else cursors.write_apart; @@ -206,9 +284,26 @@ pub const Registers = struct { rows.rip(u, y, w, rec.moment(now.marks[1]), rec.register(now.marks[1], "rip"), is.regs.eflags, changed, held, 0, reads, now.reading(.cpu, 0), .{ .moment = rec.moment(now.marks[0]), .pc = rec.register(now.marks[0], "rip"), .eflags = was.regs.eflags, .going = now.advancing(), .flip = if (now.resting()) 1 else flip }); } - fn row(r: *const Registers, u: ui.Ui, now: cursors.Now, line_is: Shown, line_was: Shown, name: []const u8, y: f32, w: f32) void { + fn row(r: *const Registers, u_row: ui.Ui, placed: anim.Placed, now: cursors.Now, line_is: Shown, line_was: Shown, name: []const u8, y: f32, w: f32) void { const rec = r.cursor.rec; const i = index(name) orelse return; + // Opened into its parts: its value as bytes, its chain gone (the name stays). + const opened = if (r.parts) |p| (if (std.mem.eql(u8, p.name, name)) p else null) else null; + const spread = if (opened) |p| p.spread(placed) else 0; + if (spread > 0) r.partsRow(u_row, placed, now, opened.?, line_is, line_was, name, i, y, spread); + // The value as it was written crossfades with its own pairs where they stand (the spread's + // first tenth), before the pairs move off and the zeros in front come. + const u = u_row.faded(std.math.clamp(1 - 10 * spread, 0, 1)); + // (Its name drawn whole over the fading row's: never dimmer for the crossfade.) + if (spread > 0) u_row.text(.mono, theme.size.mono.context, m.side, rows.baseline(y), name, t.dim); + defer for (r.framed) |fr| if (std.mem.eql(u8, fr.name, name)) { + // Round the value shown: the one before the step's until its strike lands. + const struck = now.registerAge(i) != 0 or now.since(.cpu, ties.strikeDelay(now, i)) >= time.strike.in / 2.0; + const side = if (struck) line_is else line_was; + const value = side.regs.named(name) orelse 0; + const shown = ui.Value.of(value, rows.regionOf(side.moment, value) != .none); + u.read(.{ .x = m.chain_x, .y = y, .w = shown.width(), .h = m.row }, std.math.clamp(placed.value(fr.shows), 0, 1)); + }; // Every register is the program's, at its line stops, as every // other panel is: what crossed into the kernel is the crossing's // to show, and a register is framed as carrying it only where it @@ -278,6 +373,68 @@ pub const Registers = struct { anchor(u, i, hops, y, if (landed or ran < 1) value_now else value_was, w); } + /// A register opened into its parts (`Parts`): its eight bytes, high + /// first, the zeros in front at `pad`, spreading out of the value as it + /// was written (`spread`); the bytes a write changed armed and struck as + /// a dump's; under it its parts' rows, each a bracket under its bytes. + fn partsRow(r: *const Registers, u: ui.Ui, placed: anim.Placed, now: cursors.Now, p: *const Parts, is: Shown, was: Shown, name: []const u8, i: usize, y: f32, spread: f32) void { + const size = theme.size.mono.context; + const adv = ui.advance(size); + const pitch: f32 = 30; + const value_now = is.regs.named(name) orelse return; + const value_was = was.regs.named(name) orelse value_now; + const age = now.registerAge(i); + const delay = if (age == 0) ties.strikeDelay(now, i) else 0; + const heat = if (r.quiet) ui.Heat.none else now.register(i, delay); + const landed = now.resting() or now.since(.cpu, delay) >= time.strike.in / 2.0; + const value = if (landed) value_now else value_was; + // Closed: the pairs side by side, ranged so that the last ends where the value's hex digits end. + const shown = ui.Value.of(value, rows.regionOf(is.moment, value) != .none); + const closed_end = m.chain_x + u.width(.mono, size, shown.prefix) + @as(f32, @floatFromInt(shown.digits().len)) * adv; + var lead: usize = 0; + while (lead < 7 and (value >> @intCast(8 * (7 - lead))) & 0xff == 0) lead += 1; + for (0..8) |k| { + const b: u8 = @truncate(value >> @intCast(8 * (7 - k))); + const before: u8 = @truncate(value_was >> @intCast(8 * (7 - k))); + const after: u8 = @truncate(value_now >> @intCast(8 * (7 - k))); + const open_x = m.chain_x + pitch * @as(f32, @floatFromInt(k)); + // (The zeros in front close onto the value's first digit, fading: never over the name.) + const closed_x = @max(closed_end - 2 * adv * @as(f32, @floatFromInt(8 - k)), if (k < lead) m.chain_x else m.chain_x - 2 * adv); + const x = std.math.lerp(closed_x, open_x, spread); + const cell: Rect = .{ .x = x, .y = y, .w = 2 * adv, .h = m.row }; + const struck = if (before != after) u.faded(spread).written(cell, heat) else null; + const pad = k < lead and struck == null; + // The value's own pairs at once; the zeros in front over the last 40% (never piled up), at `pad`. + const v = u.faded(if (k < lead) std.math.clamp((spread - 0.6) / 0.4, 0, 1) * @as(f32, if (pad) 0.55 else 1) else std.math.clamp(10 * spread, 0, 1)); + const text = u.print("{x:0>2}", .{b}); + if (struck) |in| v.text(in.face, size, x, rows.baseline(y), text, in.ink) else v.text(.mono, size, x, rows.baseline(y), text, if (pad) t.faint else t.primary); + } + // Its parts' rows, widest first: a bracket under the bytes each is, its name before it. + const parts = Parts.names(u, name); + const counts = [3]usize{ 4, 2, 1 }; + const echo = std.math.clamp(placed.value(p.echo), 0, 1); + for (parts, counts, 0..) |part, n, j| { + const shows_ = p.shows(placed, j); + const ry = y + m.row * @as(f32, @floatFromInt(j + 1)); + const x0 = m.chain_x + pitch * @as(f32, @floatFromInt(8 - n)) - 3; + const x1 = m.chain_x + pitch * 7 + 2 * adv + 3; + const by = ry + 10; + if (shows_ > 0) { + const v = u.faded(shows_); + v.fill(.{ .x = x0, .y = by, .w = x1 - x0, .h = 2 }, t.dim); + v.fill(.{ .x = x0, .y = by - 11, .w = 2, .h = 13 }, t.dim); + v.fill(.{ .x = x1 - 2, .y = by - 11, .w = 2, .h = 13 }, t.dim); + const nx = x0 - 10 - v.width(.mono, size, part); + v.text(.mono, size, nx, rows.baseline(ry), part, t.dim); + // The part an instruction names, and its bytes in the register's row, framed as read together (an echo). + if (j == p.echoed and echo > 0) { + u.read(.{ .x = nx, .y = ry, .w = v.width(.mono, size, part), .h = m.row }, echo * shows_); + u.read(.{ .x = x0 + 3, .y = y, .w = x1 - x0 - 6, .h = m.row }, echo * shows_); + } + } + } + } + /// The `fd` class's note after a register's value: faint, what it is open on. fn fdNote(u: ui.Ui, hops: rows.Hops, y: f32, on: []const u8) void { if (hops.n > 0 and on.len > 0) u.text(.mono, theme.size.mono.context, hops.end + 8, rows.baseline(y), on, t.faint); diff --git a/anim/src/cursor.zig b/anim/src/cursor.zig index c145823..f574941 100644 --- a/anim/src/cursor.zig +++ b/anim/src/cursor.zig @@ -129,12 +129,17 @@ pub const Plan = struct { pins: [2]f32 = .{ -1, -1 }, follow: f32 = -1, project: f32 = -1, + /// A call stepped over (design/motion.md, "A call stepped over"): its + /// result first, rax armed and struck as a walked register in the CPU's + /// slot, the call's row taking its C form with it; the others it changed + /// in a wave from here (seconds from the step's first frame); -1: none. + result: f32 = -1, /// How many values a plan is on the timeline (`pack`). - const values = 18; + const values = 19; fn pack(p: Plan) [values]f32 { - return .{ @floatFromInt(@intFromEnum(p.gait)), p.at[0], p.at[1], p.at[2], p.advance, p.travel, p.total, @floatFromInt(@intFromBool(p.wave)), @floatFromInt(@intFromBool(p.fires)), p.cooling, p.touch, p.read, p.carry, @floatFromInt(@intFromBool(p.carry_value)), p.pins[0], p.pins[1], p.follow, p.project }; + return .{ @floatFromInt(@intFromEnum(p.gait)), p.at[0], p.at[1], p.at[2], p.advance, p.travel, p.total, @floatFromInt(@intFromBool(p.wave)), @floatFromInt(@intFromBool(p.fires)), p.cooling, p.touch, p.read, p.carry, @floatFromInt(@intFromBool(p.carry_value)), p.pins[0], p.pins[1], p.follow, p.project, p.result }; } fn unpack(v: [values]f32) Plan { @@ -154,6 +159,7 @@ pub const Plan = struct { .pins = .{ v[14], v[15] }, .follow = v[16], .project = v[17], + .result = v[18], }; } @@ -178,7 +184,11 @@ pub const quiet: u32 = blk: { break :blk mask; }; -/// rsp's and rbp's places in `Regs.names`. +/// rax's, rsp's and rbp's places in `Regs.names`. +pub const rax_index: u5 = blk: { + for (zt.Regs.names, 0..) |name, i| if (std.mem.eql(u8, name, "rax")) break :blk i; + unreachable; +}; pub const sp_index: u5 = blk: { for (zt.Regs.names, 0..) |name, i| if (std.mem.eql(u8, name, "rsp")) break :blk i; unreachable; @@ -523,6 +533,28 @@ pub const Cursor = struct { c.step(s, to, plan, plan.total); } + /// A call stepped over (design/motion.md, "A call stepped over"), from + /// the call's row to the row after it: fire; the arguments framed as read + /// (18 to 24, `Registers`, `Disasm`); still while it runs; rax armed and + /// struck at 48, the row's C form and result with it; the others it + /// changed in a wave from 66, 2 f apart; a hold of 36 f; the advance; a rest. + pub fn over(c: Cursor, s: *anim.Frame, to: u64) void { + const f = 1.0 / 60.0; + const from = c.moment(s); + var plan = c.timetable(from, to, true); + const changed = c.rec.registersChanged(from, to) & ~quiet; + const others: f32 = @floatFromInt(@popCount(changed & ~(@as(u32, 1) << rax_index))); + plan.at[0] = 48 * f; + plan.result = 66 * f; + const last = if (others > 0) plan.result + (others - 1) * time.continue_wave else plan.at[0]; + // What it left in memory is not this beat's: its slot with the wave's end. + plan.at[1] = last; + plan.at[2] = last; + plan.advance = last + time.read_value; + plan.total = plan.advance + plan.travel + time.rest; + c.step(s, to, plan, plan.total); + } + fn timetable(c: Cursor, from: u64, to: u64, wave: bool) Plan { if (c.levels.annotation == .tied and !wave) return c.tiedTable(from, to); const rec = c.rec; @@ -1280,7 +1312,7 @@ pub const Now = struct { /// The mark of a register: the CPU's level. In a continue's wave, no arm and no pulse. pub fn register(n: Now, reg: usize, delay: f32) ui.Heat { var h = n.heat(n.registerAge(reg), n.registerAgeFrom(reg, 1), n.since(.cpu, delay)); - if (n.plan.wave) { + if (n.plan.wave and !(n.plan.result >= 0 and reg == rax_index)) { h.arm = 0; h.out = 0; } diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig index f61c721..67b0572 100644 --- a/anim/src/disasm.zig +++ b/anim/src/disasm.zig @@ -85,6 +85,8 @@ pub const Disasm = struct { /// A `pair`'s stopped run, 0 to 1: the call at the pc never returned. Its /// row reads so, the plaque goes, the tag says `stopped`. stopped: ?anim.Value = null, + /// 0 to 1: how much the pc's mark shows (the introduction's code arrives before its mark, II4). + mark_in: ?anim.Value = null, pub fn draw(d: *const Disasm, f: *sk.Frame, placed: anim.Placed) void { const box = d.stage.box(placed, .disasm); @@ -154,6 +156,7 @@ pub const Disasm = struct { mark_y = top + (j - scroll) * m.row; } if (to.rows.len == 0) mark_shows = 0; + if (d.mark_in) |v| mark_shows *= std.math.clamp(placed.value(v), 0, 1); // Which moment the current mark stands for, and the three steps before it. const base: usize = if (going >= 0.5) 0 else 1; @@ -411,16 +414,41 @@ pub const Disasm = struct { .call => { // Through memory or a register: where it went, and where that was read. if (target(row) == null) return a.went(b.to, touches[0], moment); - // Once it has run: the call in C's form and its result. + // Once it has run: the call in C's form and its result (struck with rax while the step that stepped over it plays). if (state == .ran) if (returned(rec, row, moment, now.stops[base])) |back| { + if (now.plan.result >= 0 and state.ran.at == now.stops[1]) return a.returning(row, b.to, moment, rec.register(back, "rax"), now.register(cursors.rax_index, 0)); return a.said(a.cForm(row, b.to, moment, rec.register(back, "rax"), a.room - a.x), t.primary); }; + // A call stepped over (`Plan.result`, design/motion.md "A call stepped over"): its + // callee and its arguments hanging under it, framed as read from 18 f; then, as rax + // strikes, its C form and its result, struck with it, the hanging rows going (6 f). + if (now.plan.result >= 0 and state == .current and !now.resting()) if (returned(rec, row, moment, now.stops[0])) |back| { + const k = std.math.clamp((now.time - now.plan.at[0]) / (6.0 / 60.0), 0, 1); + var note: Note = .{}; + if (k < 1) { + const before: Say = .{ .u = u.faded(1 - k), .rec = rec, .y = y, .x = x, .room = room }; + note = before.callee(b.to, moment); + note.hangs = before.arguments(row, b.to, moment); + const framed = std.math.clamp((now.time - 18.0 / 60.0) / (6.0 / 60.0), 0, 1) * (1 - k); + for (carriers[0..note.hangs], 1..) |reg, j| { + const v = rec.register(moment, reg); + const shown = ui.Value.of(v, rows.regionOf(rec.moment(moment), v) != .none); + u.read(.{ .x = x + 4 * adv, .y = y + @as(f32, @floatFromInt(j)) * m.row, .w = shown.width(), .h = m.row }, framed); + } + } + if (k > 0) { + const struck: Say = .{ .u = u.faded(k), .rec = rec, .y = y, .x = x, .room = room }; + note = struck.returning(row, b.to, moment, rec.register(back, "rax"), now.register(cursors.rax_index, 0)); + } + return note; + }; // `tied`: a call to the program's own function in C's form (a PLT stub's callee by name, // its arguments under it), then its move of rsp, struck with rsp: `fib(4) · rsp -8`. if (now.annotation == .tied and state == .current) { const stub = pltName(u, rec, target(row).?).len > 0; var note = if (stub) a.callee(b.to, moment) else a.said(a.cForm(row, b.to, moment, null, a.room - a.x - 10 * adv), t.primary); - note.end = a.move(note.end + adv, -8, a.rspHeat(now, base), null, true); + // (The introduction walks no call: the one it shows is stepped over, rsp as it was after it.) + if (!now.introduction) note.end = a.move(note.end + adv, -8, a.rspHeat(now, base), null, true); if (stub) note.hangs = a.arguments(row, b.to, moment); return note; } @@ -548,8 +576,13 @@ pub const Disasm = struct { const at = value_at orelse return .{}; const value = rec.register(at, reg); new.u.text(.mono, size, x, base_y, reg, t.dim); - // `tied`: its first value (the registers' row has its chain, struck in the same frame). - return .{ .drawn = true, .end = rows.chain(new.u, x + @as(f32, @floatFromInt(reg.len + 1)) * adv, y, rec.moment(at), value, room, .{ .most = if (now.annotation == .tied) 1 else 6 }).end }; + // `tied`: its first value (the registers' row has its chain, struck in the same frame); + // in the introduction struck with its register (a part's bytes are struck so: `reg` `parts`). + var marks: rows.Marks = .{ .most = if (now.annotation == .tied) 1 else 6 }; + if (now.introduction and state == .current) if (context.index(reg)) |ri| { + marks.first = now.register(ri, ties.strikeDelay(now, ri)); + }; + return .{ .drawn = true, .end = rows.chain(new.u, x + @as(f32, @floatFromInt(reg.len + 1)) * adv, y, rec.moment(at), value, room, marks).end }; } }; @@ -738,6 +771,14 @@ const Say = struct { return .{ .drawn = true, .end = rows.chain(u, x, a.y, shown, v, a.room, .{ .first = if (marks.changed == 1) marks.changed_heat else .none }).end }; } + /// A call that has run, in C's form with its result struck as `heat` says (rax's: an echo). + fn returning(a: Say, row: Insn, to: u64, moment: u64, value: u64, heat: ui.Heat) Disasm.Note { + const back = resultText(a.u, a.rec, moment, value); + var end = a.word(a.x, a.cForm(row, to, moment, null, a.room - a.x - @as(f32, @floatFromInt(back.len + 3)) * adv), t.primary); + end = a.word(end, " = ", t.primary); + return .{ .drawn = true, .end = a.struck(end, back, heat) }; + } + /// A direct call's callee, bright. fn callee(a: Say, to: u64, moment: u64) Disasm.Note { return .{ .drawn = true, .end = a.word(a.x, a.functionName(to, moment), t.bright) }; @@ -791,7 +832,7 @@ const Say = struct { } if (shown < count) out = u.print("{s}{s}\u{2026}", .{ out, if (shown > 0) ", " else "" }); out = u.print("{s})", .{out}); - if (result) |r| out = u.print("{s} = {d}", .{ out, @as(i64, @bitCast(r)) }); + if (result) |r| out = u.print("{s} = {s}", .{ out, resultText(u, a.rec, moment, r) }); if (shown == 0 or @as(f32, @floatFromInt(std.unicode.utf8CountCodepoints(out) catch out.len)) * adv <= width) return out; } } @@ -994,6 +1035,12 @@ fn returned(rec: *const Recording, row: Insn, moment: u64, until: u64) ?u64 { return null; } +/// A call's result as a caller reads it: an address in hex, as the chains write it; else signed, in decimal. +fn resultText(u: ui.Ui, rec: *const Recording, moment: u64, r: u64) []const u8 { + if (rows.regionOf(rec.moment(moment), r) != .none) return u.print("{x}", .{r}); + return u.print("{d}", .{@as(i64, @bitCast(r))}); +} + /// The slot a `jmp` or `call` through `[rip + X]` reads. fn ripSlot(row: Insn) ?u64 { const ops = row.operands(); diff --git a/anim/src/hexdump.zig b/anim/src/hexdump.zig index d1c363c..3ef1ac9 100644 --- a/anim/src/hexdump.zig +++ b/anim/src/hexdump.zig @@ -30,7 +30,7 @@ pub const Kind = enum { number, pointer, loose, unread }; /// a field of a struct the program's pointers reach (by its type), other /// allocated bytes, `loose` (the allocator's own between allocations), or /// never observed. -pub fn kindOf(things: []const objects.Object, moment: Recording.Moment, addr: u64) struct { Kind, ?Recording.types.Type } { +pub fn kindOf(rec: *const Recording, things: []const objects.Object, moment: Recording.Moment, addr: u64) struct { Kind, ?Recording.types.Type } { for (things) |o| { if (!o.holds(addr)) continue; for (o.type.record.fields) |field| if (o.addr + field.offset == addr) return .{ if (field.type == .pointer) .pointer else .number, field.type }; @@ -40,7 +40,7 @@ pub fn kindOf(things: []const objects.Object, moment: Recording.Moment, addr: u6 var known: [8]bool = undefined; moment.read(addr, &bytes, &known) catch return .{ .unread, null }; if (std.mem.indexOfScalar(bool, &known, true) == null) return .{ .unread, null }; - return .{ if ((moment.allocation(addr) catch null) != null) .number else .loose, null }; + return .{ if (rec.allocated(moment, addr)) .number else .loose, null }; } /// The rows of a region (`lo .. hi`, sixteen-aligned) a dump of `count` @@ -207,7 +207,7 @@ pub fn drawArcs(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: u if (of.array) |arr| if (here < arr.addr and arr.addr < here + run.len) { run.len = @intCast(arr.addr - here); }; - const word, kind = kindOf(of.things, moment, here); + const word, kind = kindOf(now.rec, of.things, moment, here); run.kind = switch (word) { .number => .number, .pointer => .pointer, @@ -240,7 +240,7 @@ pub fn drawArcs(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: u const end = readingIn(v, ry, shift, moment, &values, &known, readings[0..n], room); // The size word of the chunk after: malloc's, a note after the reading. const last = runs[n - 1]; - if (last.kind == .loose and last.first == 8 and last.len == 8 and std.mem.indexOfScalar(bool, known[8..], false) == null and chunkAfter(moment, addr + 8)) { + if (last.kind == .loose and last.first == 8 and last.len == 8 and std.mem.indexOfScalar(bool, known[8..], false) == null and chunkAfter(now.rec, moment, addr + 8)) { const size = std.mem.readInt(u64, values[8..16], .little) & ~@as(u64, 7); v.text(.sans, theme.size.sans.micro, end, rows.baseline(ry) - 1, v.print("malloc's: a chunk of {d}", .{size}), t.faint); } @@ -419,9 +419,9 @@ fn aim(arcs: *rows.Arcs, now: cursors.Now, field: u64, target: u64, from: f32, s /// Whether an allocation the recording has begins just after the word at /// `word` (the chunk's size word, glibc's and musl's alike): only there are /// bytes between allocations the allocator's own, to be read as its. -fn chunkAfter(moment: Recording.Moment, word: u64) bool { - const a = (moment.allocation(word + 8) catch return false) orelse return false; - return a.ptr == word + 8; +fn chunkAfter(rec: *const Recording, moment: Recording.Moment, word: u64) bool { + if ((moment.allocation(word + 8) catch null)) |a| return a.ptr == word + 8; + return rec.allocated(moment, word + 8) and !rec.allocated(moment, word); } /// What a field of a region reads as: a number (little-endian, or `big`), diff --git a/anim/src/map.zig b/anim/src/map.zig index eaec991..2a2077a 100644 --- a/anim/src/map.zig +++ b/anim/src/map.zig @@ -1133,6 +1133,19 @@ fn spanOf2(maybe: ?Window, col: *const Column) ?[2]f32 { /// The map whose columns the strips are (`context` sets it). /// shortcut: process-wide, as the drawing flags are: one scene drawn at a time. pub var current: ?*const Map = null; +/// Every context's map (a scene in chapters has one a context, `context`): a +/// pane's strip is drawn from its own context's, the one whose working +/// frame has the pane's box; `current` where none has. +pub var maps: [8]?*const Map = @splat(null); +pub var maps_frame: u64 = std.math.maxInt(u64); + +fn ownMap(panel: Panel, at: anim.Placed, box: Rect) ?*const Map { + for (maps) |maybe| if (maybe) |m| { + const b = m.frame.box(at, @enumFromInt(@intFromEnum(panel))); + if (@abs(b.x - box.x) < 0.5 and @abs(b.y - box.y) < 0.5 and @abs(b.w - box.w) < 0.5 and @abs(b.h - box.h) < 0.5) return m; + }; + return current; +} /// A mark no working window shows, `flash`ing on its pane's strip. const Flash = struct { panel: Panel, key: u64, ink: u24, p: f32 }; @@ -1220,7 +1233,7 @@ fn stripRect(box: Rect) Rect { /// pane fading through passes its faded one); drawn last, over its rows. pub fn strip(panel: Panel, u: ui.Ui, box: Rect) void { if (ui.mapping) return; - const m = current orelse return; + const m = ownMap(panel, u.at, box) orelse return; const f = u.f; if (looking(f)) return; const slot = slotOf(panel) orelse return; diff --git a/anim/src/objects.zig b/anim/src/objects.zig index dd9ea85..ec40481 100644 --- a/anim/src/objects.zig +++ b/anim/src/objects.zig @@ -67,7 +67,7 @@ fn follow(scratch: std.mem.Allocator, rec: *const Recording, m: Recording.Moment if (std.mem.startsWith(u8, name, "struct ") or std.mem.startsWith(u8, name, "union ")) o.name = name; return; }; - const live = (m.allocation(addr) catch null) != null; + const live = rec.allocated(m, addr); found.append(scratch, .{ .addr = addr, .type = t, .slot = slotOf(rec, addr, m), .freed = !live and wasAllocated(rec, addr, m.index), .name = name }) catch {}; } diff --git a/anim/src/regroup.zig b/anim/src/regroup.zig index a904ba2..f5c5fd9 100644 --- a/anim/src/regroup.zig +++ b/anim/src/regroup.zig @@ -99,10 +99,15 @@ pub const Words = struct { /// address, each word to where the slot's chain has it. become: anim.Value, panel: struct { x: f32 = 0, top: f32 = 0, first: u64 = 0 } = .{}, + /// Its first row's top (`at.top`): folded on the shelf it can be set + /// anew, and unfolds there (the introduction's II8: at the rows III's stack gives the words). + top: anim.Value, + /// 0 to 1: its header back over its rows after the dump was tied to its place (before a fold). + back: anim.Value, pub fn init(s: *anim.Frame, rec: *const Recording, moment: u64) Words { const picked = pick(rec, moment); - return .{ .rec = rec, .at = moment, .in = s.value(-1), .regroup = s.value(-1), .framed = s.value(-1), .fold = s.value(0), .placed = s.value(0), .ink = s.value(-1), .left = s.value(-1), .chains = s.value(-1), .walked = picked.walked, .three = picked.three, .become = s.value(0) }; + return .{ .rec = rec, .at = moment, .in = s.value(-1), .regroup = s.value(-1), .framed = s.value(-1), .fold = s.value(0), .placed = s.value(0), .ink = s.value(-1), .left = s.value(-1), .chains = s.value(-1), .walked = picked.walked, .three = picked.three, .become = s.value(0), .top = s.value(at.top), .back = s.value(0) }; } /// The return address the newest frame has, and the first word that @@ -149,14 +154,14 @@ pub const Words = struct { } /// Word `i`'s row's top, its bytes' first x, and how much its address shows, at regroup clock `r`. - fn where(i: usize, r: f32) struct { y: f32, x: f32, address: f32 } { + fn where(i: usize, r: f32, top: f32) struct { y: f32, x: f32, address: f32 } { const row: f32 = @floatFromInt(i / 2); const half: f32 = @floatFromInt(i % 2); const a = glide(r / 18); const b = glide((r - 18) / 12); const c = glide((r - 30) / 18); return .{ - .y = at.top + pitch * (row + row * a + half * b), + .y = top + pitch * (row + row * a + half * b), .x = at.bytes + half * (8 * at.pair + at.middle) * (1 - c), .address = if (half == 0) 1 else clamp01((r - 36) / 12), }; @@ -172,8 +177,9 @@ pub const Words = struct { const fold = placed.value(w.fold); // Folding: the rows glide up into the header (24 f), which becomes the tag (`tag`). const gather = glide(fold / 24); - const header_y = at.top - pitch; - w.tag(u, fold); + const top = placed.value(w.top); + const header_y = top - pitch; + w.tag(u, fold, top); if (gather >= 1) return; const v = u; const data = read(w.rec, w.at); @@ -181,14 +187,14 @@ pub const Words = struct { // The header (mock 29), with the first row; gone as the dump is tied to its place. // The veil over every row but the walked one, while it is walked (the header too). const veil = clamp01((r - 48) / 18) - clamp01((r - 270 - later) / 18); - const header = clamp01(in / 18) * (1 - placed.value(w.placed)) * (1 - veil) * (1 - clamp01((fold - 12) / 8)); - if (header > 0) v.faded(header).text(.sans, theme.size.sans.micro, at.address, at.top - 12, v.print("128 bytes at {x}", .{w.rec.register(w.at, "rsp")}), t.faint); + const header = clamp01(in / 18) * (1 - placed.value(w.placed) * (1 - clamp01(placed.value(w.back)))) * (1 - veil) * (1 - clamp01((fold - 12) / 8)); + if (header > 0) v.faded(header).text(.sans, theme.size.sans.micro, at.address, top - 12, v.print("128 bytes at {x}", .{w.rec.register(w.at, "rsp")}), t.faint); const address_ink = ui.mix(t.faint, theme.color.region.stack, placed.value(w.placed)); const become = placed.value(w.become); const g = glide(become); for (0..words) |i| { - const p = where(i, r); + const p = where(i, r, top); const arrive = clamp01((in - rows_apart * @as(f32, @floatFromInt(i / 2))) / 18); if (arrive <= 0) continue; const row = v.faded(arrive * (if (i == w.walked) 1 else 1 - theme.color.veil_alpha * veil) * (1 - gather)); @@ -207,7 +213,7 @@ pub const Words = struct { if (framed >= 0) for (w.three, 0..) |i, k| { const shows = clamp01((framed - 30 * @as(f32, @floatFromInt(k))) / 6); var rect = w.wordRect(i, data.words[i], placed); - rect.y = std.math.lerp(rect.y, header_y, gather); + rect.y = std.math.lerp(rect.y - at.top + top, header_y, gather); if (shows > 0) v.faded(1 - gather).read(rect, shows); }; } @@ -395,13 +401,16 @@ pub const Words = struct { /// header out 12 to 20, the tag in 16 to 24, its title where the /// header's was), which then goes to the shelf (24 f, `glide`); back, /// the reverse. - fn tag(_: *const Words, u: ui.Ui, fold: f32) void { + fn tag(_: *const Words, u: ui.Ui, fold: f32, top: f32) void { if (fold <= 16) return; const title = "the 128 bytes"; - const p = glide((fold - 24) / 24); + // To the shelf's height first, then along it (over what stands under it, crossing none); back, the reverse. + const p = clamp01((fold - 24) / 24); const w = u.width(.sans_medium, theme.size.sans.tag, title) + 40; - const x = std.math.lerp(at.address - 28, theme.canvas.margin_x, p); - const y = std.math.lerp(at.top - 30, theme.canvas.stage.y, p); + const dy = @abs(top - 30 - theme.canvas.stage.y); + const share = std.math.clamp(dy / (at.address - 28 - theme.canvas.margin_x + dy), 0.25, 0.6); + const y = std.math.lerp(top - 30, theme.canvas.stage.y, glide(p / share)); + const x = std.math.lerp(at.address - 28, theme.canvas.margin_x, glide((p - 0.6 * share) / (1 - 0.6 * share))); const v = u.faded(clamp01((fold - 16) / 8)).moved(x, y); v.fill(.{ .x = 0, .y = 0, .w = w, .h = theme.metric.context.tag }, theme.color.raised); v.frame(.{ .x = 8, .y = 6, .w = 12, .h = 12 }, t.faint, theme.stroke.rule); diff --git a/anim/src/root.zig b/anim/src/root.zig index 5482285..bc807de 100644 --- a/anim/src/root.zig +++ b/anim/src/root.zig @@ -54,6 +54,8 @@ pub const Ties = tying.Ties; pub const Place = tying.Place; /// Says where a place is this frame, for a scene's own component the ties should find. pub const anchor = tying.anchor; +/// Where a place is this frame, in canvas pixels, if a panel said (`ties.find`). +pub const findPlace = tying.find; pub const Array = @import("array.zig").Array; pub const Loupe = @import("loupe.zig").Loupe; pub const syscalls = @import("syscalls.zig"); @@ -65,6 +67,10 @@ const words = @import("words.zig"); pub const Clock = words.Clock; pub const Caption = words.Caption; pub const Label = words.Label; +pub const Title = words.Title; +pub const ChapterLabel = words.ChapterLabel; +/// A `Ui` in the design's units that the camera does not move (`words.fixed`). +pub const fixed = words.fixed; pub const Veil = words.Veil; pub const Legend = words.Legend; /// The column (design/README.md, "column (an experiment)"): beat by beat, @@ -279,6 +285,9 @@ pub const Context = struct { /// (`graph.Blocks`), the map's drawing over the source; the /// disassembly beside it linear, its blocks ruled. graph: bool = false, + /// The registers the scene moves, where not its clock's way's + /// (`movedBy`): a scene in chapters has one set for all of them. + moves: ?u32 = null, }; /// The ties between the panes, drawn over everything added before. @@ -325,7 +334,7 @@ pub const Context = struct { pub fn context(s: *anim.Frame, cursor_: Cursor, options: Context.Options) Context { // The registers the scene moves keep their rows, the rest fold, chosen // once from its way; the panel is as tall as its rows, the stack has the rest. - const moves = contexts.movedBy(cursor_.rec, cursor_.by, .{ cursor_.first, cursor_.last }); + const moves = options.moves orelse contexts.movedBy(cursor_.rec, cursor_.by, .{ cursor_.first, cursor_.last }); const registers_rows: f32 = @floatFromInt(contexts.registerRows(moves)); const stage = Stage.init(s, layout.fit(options.split, registers_rows)); stage.registers_rows = registers_rows; @@ -352,6 +361,15 @@ pub fn context(s: *anim.Frame, cursor_: Cursor, options: Context.Options) Contex // The rest of the first two columns: no pane's. whole.addIn(s, map.Spare{ .cursor = at, .stage = whole.stage, .map = whole }, .map, .backtrace); map.current = whole; + // (Each frame anew: what a frame's `frame` made lives for that frame.) + if (map.maps_frame != s.in.frame) { + map.maps = @splat(null); + map.maps_frame = s.in.frame; + } + for (&map.maps) |*slot| if (slot.* == null) { + slot.* = whole; + break; + }; return .{ .stage = stage, .map = whole, diff --git a/anim/src/segments.zig b/anim/src/segments.zig index a304993..fa30b76 100644 --- a/anim/src/segments.zig +++ b/anim/src/segments.zig @@ -269,10 +269,16 @@ pub const Segments = struct { /// Frames into each cluster's `enlarge`, top down (negative: not begun). rides: [6]anim.Value, /// `ink`'s echoes: the band holding `addr` framed as read, `shows` of it. - echoes: [16]Echo = undefined, + echoes: [24]Echo = undefined, n_echoes: usize = 0, + /// Live (design/README.md, `segments`): rip a `row` pin at the end of + /// its band's row (`◂ rip`); rsp and rbp an `under` pin in the stack's + /// band, rbp's name left of the stub and rsp's right. Each 0 to 1, in + /// over the scene's 12 f rising 8. + pins: ?Pins = null, pub const Echo = struct { addr: u64, shows: anim.Value }; + pub const Pins = struct { rip: anim.Value, stack: anim.Value }; pub fn init(s: *anim.Frame, rec: *const Recording, at: u64) Segments { var rides: [6]anim.Value = undefined; @@ -369,6 +375,40 @@ pub const Segments = struct { } for (0..n) |i| g.enlarged(u, l, i, placed.value(g.rides[i])); for (g.echoes[0..g.n_echoes]) |echo| g.echoed(u, l, echo.addr, placed.value(echo.shows)); + if (g.pins) |pins| g.live(u, l, pins, placed); + } + + /// The registers' pins (`pins`), at the moment `at`. + fn live(g: *const Segments, u: ui.Ui, l: Layout, pins: Pins, placed: anim.Placed) void { + const mono = theme.size.mono.context; + const rip = std.math.clamp(placed.value(pins.rip), 0, 1); + if (rip > 0) if (g.rowOf(u, l, g.rec.register(g.at, "rip"))) |y| { + const v = u.faded(rip).moved(0, (1 - rip) * theme.time.caption_rise); + const x = g.x + m.size_end + 14; + _ = v.pinEnd(x + theme.metric.pin.row_head[0] + theme.metric.pin.row_gap + v.width(.mono, mono, "rip"), y - 12, &.{"rip"}, region.code_); + }; + const stack = std.math.clamp(placed.value(pins.stack), 0, 1); + if (stack > 0) if (Segments.place(l, g.rec.register(g.at, "rsp"))) |at| { + u.faded(stack).moved(0, (1 - stack) * theme.time.caption_rise).pinUnder(at[0], at[1] + 2, &.{ "rbp", "rsp" }, region.stack, mono); + }; + } + + /// The middle of the row of names of the unit holding `addr`, once its box has landed. + fn rowOf(_: *const Segments, u: ui.Ui, l: Layout, addr: u64) ?f32 { + for (l.space.clusters, 0..) |c, i| if (i < 6 and addr >= c.lo and addr < c.hi) { + const all = rows(l, i, u.f.scratch); + var targets: [64]f32 = undefined; + var ys: [64]f32 = undefined; + const n = @min(all.len, 64); + for (all[0..n], 0..) |r, k| targets[k] = r.target; + const room = share(l, i); + pool(targets[0..n], ys[0..n], room[0], room[1], m.pitch); + for (all[0..n], 0..) |r, k| if (r.kind == .unit) { + const un = l.space.units[r.unit]; + if (addr >= un.lo and addr < un.hi) return ys[k]; + }; + }; + return null; } /// The ink of a cluster's largest band (its line on the whole). diff --git a/anim/src/ties.zig b/anim/src/ties.zig index 3048e32..f746f97 100644 --- a/anim/src/ties.zig +++ b/anim/src/ties.zig @@ -186,13 +186,18 @@ pub fn strikeDelay(now: cursors.Now, i: usize) f32 { const pin = [2]?f32{ now.pinLands(0), now.pinLands(1) }; if (i == cursors.sp_index) if (pin[0]) |land| return land - now.plan.at[0]; if (i == cursors.bp_index) if (pin[1]) |land| return land - now.plan.at[0]; + // A call stepped over: its result (rax) in the CPU's slot, the others in a wave after it. + const over = now.plan.result >= 0; + if (over and i == cursors.rax_index) return 0; var before: f32 = 0; for (theme.metric.all_registers[0..16]) |name| { const k = @import("context.zig").index(name).?; if (k == i) break; if ((k == cursors.sp_index and pin[0] != null) or (k == cursors.bp_index and pin[1] != null)) continue; + if (over and k == cursors.rax_index) continue; if (now.registerAge(k) == 0) before += 1; } + if (over) return now.plan.result - now.plan.at[0] + before * time.continue_wave; if (now.plan.wave) return before * time.continue_wave; return @min(before * cursors.write_apart, time.cascade) + @import("syscalls.zig").crossingDelay(now); } diff --git a/anim/src/words.zig b/anim/src/words.zig index 6549dfb..9bec54c 100644 --- a/anim/src/words.zig +++ b/anim/src/words.zig @@ -110,6 +110,59 @@ pub const Caption = struct { } }; +/// A chapter's title (design/README.md, `chapter`, `title`): said, not +/// carded, in the caption's place, one line of Go Medium 40, its numeral +/// faint and its name bright (`II Registers`); it arrives rising as a +/// caption does, over the picture it grows from. +pub const Title = struct { + numeral: []const u8, + name: []const u8, + box: Rect = theme.canvas.caption, + + pub fn draw(c: *const Title, f: *sk.Frame, at: anim.Placed) void { + const u = fixed(f, at, (1 - at.pose.opacity) * theme.time.caption_rise); + const size = theme.size.sans.caption; + const base = theme.canvas.caption_baseline[0]; + u.text(.sans_medium, size, theme.canvas.margin_x, base, c.numeral, t.faint); + const x = theme.canvas.margin_x + u.width(.sans_medium, size, c.numeral) + 2 * u.width(.sans_medium, size, " "); + u.text(.sans_medium, size, x, base, c.name, t.bright); + } +}; + +/// The clock's label (design/README.md, `clock`): the chapter, Go 18, +/// faint, ranged right 24 left of the clock's count (its widest, so that it +/// stands still as the count grows), or alone at 1856 where there is no +/// clock yet. `which` is the chapter (between two, their names +/// crossfading); `docked` 0 alone, 1 beside the count (out over its first +/// half, in over its second, with the clock: it is secondary, it only fades). +pub const ChapterLabel = struct { + names: []const []const u8, + which: anim.Value, + docked: anim.Value, + /// The count at its widest, `moment 193 of 193`. + widest: []const u8, + + pub fn draw(l: *const ChapterLabel, f: *sk.Frame, at: anim.Placed) void { + const u = fixed(f, at, 0); + const size = theme.size.sans.micro; + const base = theme.canvas.clock_y + 28; + const right = theme.canvas.stage.x + theme.canvas.stage.w; + const ends = [2]f32{ right, right - u.width(.mono, theme.size.mono.context, l.widest) - 24 }; + const which = std.math.clamp(at.value(l.which), 0, @as(f32, @floatFromInt(l.names.len - 1))); + const lo: usize = @intFromFloat(@floor(which)); + const hi = @min(lo + 1, l.names.len - 1); + const k = which - @floor(which); + const docked = std.math.clamp(at.value(l.docked), 0, 1); + for ([2]usize{ lo, hi }, [2]f32{ 1 - k, k }) |n, shows| { + if (shows <= 0) continue; + const name = l.names[n]; + const w = u.width(.sans, size, name); + // Gone from where it stood alone before it comes beside the count: never over it. + for (ends, [2]f32{ std.math.clamp(1 - 2 * docked, 0, 1), std.math.clamp(2 * docked - 1, 0, 1) }) |end, here| if (here > 0) u.faded(shows * here).text(.sans, size, end - w, base, name, t.faint); + } + } +}; + /// Text with `code` between backticks set in mono, from `x` on `baseline`. /// Returns where it ends. pub fn runs(u: ui.Ui, x: f32, baseline: f32, text: []const u8, face: ui.Face, size: f32, mono_size: f32, ink: anytype) f32 { -- cgit v1.3