diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-12 01:44:59 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-12 03:17:32 -0300 |
| commit | bf0dfa135319f8c7ca49eace4d1f81152ebfd23e (patch) | |
| tree | 9c80ade769dc9a741c9d00f63770d34dc1769ced /anim/src/descent.zig | |
| parent | aefde257db6e7cf683b923498c0d471885ab67a9 (diff) | |
| download | computeranim-bf0dfa135319f8c7ca49eace4d1f81152ebfd23e.tar.gz computeranim-bf0dfa135319f8c7ca49eace4d1f81152ebfd23e.zip | |
canim: the introduction, three chapters
From the user: a first-principles showcase that builds the views. I,
memory: the stack's bytes, words read low byte first, the address space
to true scale with each cluster enlarged and every band's addresses and
size, the bytes tied to their place, ink and chains. II, the stack: the
words become the stack panel, a real push, the return address aimed at
the row it returns to, rbp and the frame, the registers. III, code: an
instruction's bytes decoded into one listing of lines and addresses, then
two columns, then the working frame assembled and the map. Recorded from
main's call of reverse with record --until.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/src/descent.zig')
| -rw-r--r-- | anim/src/descent.zig | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/anim/src/descent.zig b/anim/src/descent.zig index ad3a5c5..96f6f2d 100644 --- a/anim/src/descent.zig +++ b/anim/src/descent.zig @@ -71,6 +71,50 @@ pub fn step(cur: cursors.Cursor, s: *anim.Frame, by: Recording.Stop) void { cur.step(s, to, plan, plan.total); } +/// A caller's window standing alone (the introduction, motion.md II2: the +/// first code on screen): a descent's head row (the function, its file +/// ranged right) over its call, the row the call returns to and the next, +/// each said as a place (`row`) for an aim, a call's callee named where the +/// annotation goes. `in` (frames): the head, then the rows 2 f apart, 12 f +/// each; `faint` (0 to 1): to half, as it stays under what follows. +pub const Caller = struct { + rec: *const Recording, + at: u64, + /// The call instruction's address. + call: u64, + box: Rect, + in: anim.Value, + faint: anim.Value, + + pub fn draw(r: *const Caller, fr: *sk.Frame, placed: anim.Placed) void { + const clock = placed.value(r.in); + if (clock < 0) return; + const u = (ui.Ui{ .f = fr, .at = placed }).moved(r.box.x, r.box.y).faded(1 - 0.5 * std.math.clamp(placed.value(r.faint), 0, 1)); + const moment = r.rec.moment(r.at); + var name_buf: [128]u8 = undefined; + const head = u.faded(std.math.clamp(clock / 12, 0, 1)); + const name = (moment.string(r.call, &name_buf) catch null) orelse ""; + head.fill(.{ .x = theme.stroke.rule, .y = 0, .w = r.box.w - 2 * theme.stroke.rule, .h = theme.stroke.rule }, theme.color.rule); + head.text(.sans_medium, theme.size.sans.micro, c.address, 18, u.print("{s}", .{name[0 .. std.mem.indexOfScalar(u8, name, '+') orelse name.len]}), t.primary); + head.text(.sans, theme.size.sans.micro, r.box.w - 12 - head.width(.sans, theme.size.sans.micro, r.rec.file), 18, r.rec.file, t.faint); + var addr = r.call; + var buf: [256]u8 = undefined; + for (0..3) |n| { + const insn = r.rec.instruction(r.at, addr, &buf) orelse return; + const y = m.row * @as(f32, @floatFromInt(n + 1)); + const rv = u.faded(std.math.clamp((clock - 12 - 2 * @as(f32, @floatFromInt(n))) / 12, 0, 1)); + _ = rv.address(c.address, rows.baseline(y), addr, .{ .ink = ui.rgb(theme.color.region.code_) }); + const row: Insn = .{ .addr = addr, .len = insn.len, .text = insn.text, .line = insn.line }; + disasm.bareRow(rv, row, y); + if (disasm.target(row)) |to| if (std.mem.startsWith(u8, insn.text, "call")) { + if (moment.string(to, &name_buf) catch null) |callee| rv.text(.mono, size, c.annotation, rows.baseline(y), ui.symbol(rv, callee[0 .. std.mem.indexOfScalar(u8, callee, '+') orelse callee.len]), t.primary); + }; + ties.anchor(u, .{ .row = addr }, .{ .x = 0, .y = y, .w = r.box.w, .h = m.row }); + addr += insn.len; + } + } +}; + /// The key of the head row over function `name`'s window (a `ties.Place.row`). pub fn headKey(name: []const u8) u64 { return std.hash.Wyhash.hash(0, name) | 1 << 63; |
