From 165bb6c1344b98de7bef1d3c2b72147b4a40797a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 16:05:20 -0300 Subject: canim: the renderer speaks the design language The blocks, their states and the tokens carry the catalogue's names: atoms in ui, chain/reg/slot in rows, insn with its line column, jump lane and annotations (read, write, taken or not, a call with its arguments, a return, a syscall) in disasm, bytes and hexdump with field paper and the reading column, the three splits and relayout in stage, the ties (thread, link and pin, projection, echo). A lens is a band over the whole context, its drawing left and its bytes right. Frames' spans on the stack, each instruction's line and a callee's parameter count come from the tracer. A gallery scene draws every block; the test compares six of its pages with pictures kept in test/gallery, drawn from a recording kept there too. The scenes are ported; the motion checks report no pop and no metronome in any of them. Co-Authored-By: Claude Fable 5.2 --- anim/src/syscalls.zig | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'anim/src/syscalls.zig') diff --git a/anim/src/syscalls.zig b/anim/src/syscalls.zig index 9136ebb..a19324f 100644 --- a/anim/src/syscalls.zig +++ b/anim/src/syscalls.zig @@ -13,6 +13,8 @@ const zt = @import("ztrace"); const ui = @import("ui.zig"); const cursors = @import("cursor.zig"); const Recording = @import("Recording.zig"); +const context = @import("context.zig"); +const Stage = @import("stage.zig").Stage; const theme = ui.theme; const time = theme.time; const Rect = ui.Rect; @@ -135,24 +137,28 @@ pub fn fills(call: Recording.Syscall) ?Recording.Span { /// side and returns. pub const Crossing = struct { cursor: cursors.Cursor, - box: Rect = theme.layout.split.beside.lens, + stage: *const Stage, focus: bool = false, const row_h = theme.metric.context.row; const size = theme.size.mono.context; pub fn draw(c: *const Crossing, f: *sk.Frame, placed: anim.Placed) void { - const u: ui.Ui = .{ .f = f, .at = placed }; + const box = c.stage.box(placed, .band); + if (box.h < theme.metric.context.tag + 24) return; + const u = context.at(f, placed, box); const now = c.cursor.now(placed); const rec = c.cursor.rec; - const body = u.panel(c.box.w, c.box.h, "kernel", .{ .focus = c.focus, .note = "the other side of a system call" }); + const body = u.panel(box.w, box.h, "kernel", .{ .focus = c.focus, .note = "the other side of a system call" }); u.fill(.{ .x = theme.stroke.rule, .y = body.y, .w = body.w - 2 * theme.stroke.rule, .h = body.h - theme.stroke.rule }, theme.color.kernel); + context.clipBody(u, box); + defer u.unclip(); u.text(.sans, theme.size.sans.micro, 12, body.y + 22, "calls so far", k.dim); const newest = latest(rec, now.stops[0]) orelse return; const live = rec.syscalls[newest].enter > now.stops[1] and now.walking(); const p = Plan.of(rec.syscalls[newest]); const t: f32 = if (live) now.time else std.math.inf(f32); - if (t >= p.enters) c.arrows(u, body, t, p, rec.syscalls[newest]); + if (t >= p.enters) arrows(u, body, t, p, rec.syscalls[newest]); // No effect before its cause: until the arrow is through the // line the kernel knows nothing of this call, and shows the last. if (t < p.name) { @@ -243,32 +249,31 @@ pub const Crossing = struct { /// The crossing itself: in from the side the registers are on as the /// call enters, and back out as it returns. Vellum outside the /// kernel, ink inside it. Machines do not lob: straight. - fn arrows(c: *const Crossing, u: ui.Ui, body: Rect, t: f32, p: Plan, made: Recording.Syscall) void { - const edge = c.box.w; + /// The crossing itself: up out of the registers below the band (the + /// ones that carried it), into the kernel, as the call enters; and back + /// down as it returns. Machines do not lob: straight. + fn arrows(u: ui.Ui, body: Rect, t: f32, p: Plan, made: Recording.Syscall) void { + const x = theme.layout.state.x - theme.layout.program.x + 40; + const bottom = body.y + body.h; + const reach = 64; // Off promptly, and settling in the kernel. - const down = cursors.standard(std.math.clamp((t - p.enters) / Plan.cross, 0, 1)); + const up = cursors.standard(std.math.clamp((t - p.enters) / Plan.cross, 0, 1)); const gone = std.math.clamp((t - p.returns - theme.time.quick) / theme.time.read.out, 0, 1); const v = u.faded(1 - gone); - if (t < p.back) across(v, body.y + 190, edge + 26, edge + 26 - down * 86, edge); - if (made.exit != null and t > p.back) across(v, body.y + 226, edge - 60, edge - 60 + cursors.standard(std.math.clamp((t - p.back) / Plan.cross, 0, 1)) * 86, edge); + if (t < p.back) along(v, x, bottom, bottom - up * reach); + if (made.exit != null and t > p.back) along(v, x + 40, bottom - reach, bottom - reach + cursors.standard(std.math.clamp((t - p.back) / Plan.cross, 0, 1)) * reach); } - /// An arrow along the row at `y` from `from` to `to`, in the colour of - /// the ground it is over: ink inside the kernel (left of `edge`), vellum outside. - fn across(u: ui.Ui, y: f32, from: f32, to: f32, edge: f32) void { + /// An arrow down the column at `x` from `from` to `to`, in ink: it is inside the kernel. + fn along(u: ui.Ui, x: f32, from: f32, to: f32) void { if (@abs(to - from) < 1) return; const w = theme.stroke.arrow; const head = theme.stroke.flow_head; const dir: f32 = if (to > from) 1 else -1; const neck = to - dir * (head[0] - 2); - const lo = @min(from, neck); - const hi = @max(from, neck); - if ((neck - from) * dir > 0) { - if (lo < edge) u.fill(.{ .x = lo, .y = y - w / 2, .w = @min(hi, edge) - lo, .h = w }, k.ink); - if (hi > edge) u.fill(.{ .x = @max(lo, edge), .y = y - w / 2, .w = hi - @max(lo, edge), .h = w }, theme.color.kernel); - } + if ((neck - from) * dir > 0) u.fill(.{ .x = x - w / 2, .y = @min(from, neck), .w = w, .h = @abs(neck - from) }, k.ink); if (@abs(to - from) < head[0]) return; - sk.draw.polygon(u.f, &.{ .{ to, y }, .{ to - dir * head[0], y - head[1] / 2 }, .{ to - dir * head[0], y + head[1] / 2 } }, u.at.pen(.{ .fill = if (to - dir * head[0] / 2 < edge) ui.rgb(k.ink) else ui.rgb(theme.color.kernel) })); + sk.draw.polygon(u.f, &.{ .{ x, to }, .{ x - head[1] / 2, to - dir * head[0] }, .{ x + head[1] / 2, to - dir * head[0] } }, u.at.pen(.{ .fill = ui.rgb(k.ink) })); } }; @@ -304,13 +309,9 @@ fn value(u: ui.Ui, made: Recording.Syscall, kind: u8, arg: usize, text_used: *bo }, else => {}, } - return grouped(u, a); + return u.print("{x}", .{a}); } -/// Hex in groups of four, as everywhere. -fn grouped(u: ui.Ui, n: u64) []const u8 { - return ui.grouped(u.f.scratch.alloc(u8, 20) catch return "?", n); -} /// What came back: a count, an address, or an error by name. fn result(u: ui.Ui, made: Recording.Syscall) []const u8 { @@ -319,7 +320,7 @@ fn result(u: ui.Ui, made: Recording.Syscall) []const u8 { if (std.enums.fromInt(std.os.linux.E, -ret)) |e| return u.print("{d} E{t}", .{ ret, e }); return u.print("{d}", .{ret}); } - return if (ret > 0xffffff or ret < 0) grouped(u, made.result) else u.print("{d}", .{ret}); + return if (ret > 0xffffff or ret < 0) u.print("{x}", .{made.result}) else u.print("{d}", .{ret}); } pub const Timeline = struct { -- cgit v1.3