From 2f27fbe0aa2da0f85d599c1e5f3ac14d025f590c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 11 Nov 2026 13:22:07 -0300 Subject: canim: the graph of a function's blocks From the user. A blocks lens draws a function's basic blocks as boxes with their offsets and visit counts, loops in their lanes with the turn count, the path's last edges gold, the pc's block gold, and the disassembly as its view; leave and turn carry the mark along an edge, with the compare's flags framed for the edge chosen. On the map the graph takes the disassembly's place with its rows. The layout is a pure function, tested on sort, reverse and libc's open (twelve blocks the run never reached fold into six boxes). The sort scene walks one trip of its inner loop block by block and sprints the middle on the map. Every scene's linear rows carry a rule and a count at each block's head. The stack's panel no longer reads registers from the file on every draw: a frame is 20 ms where it was 57. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa --- anim/src/theme.zig | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'anim/src/theme.zig') diff --git a/anim/src/theme.zig b/anim/src/theme.zig index cb52287..7d505d7 100644 --- a/anim/src/theme.zig +++ b/anim/src/theme.zig @@ -134,6 +134,17 @@ pub const layout = struct { /// its view 200 (a dump of seven); ten lines over nine /// instructions; the registers over six words, a small frame whole. pub const subject: Split = shared(296, 200, 10, 9, 6, 7); + /// The `blocks` lens: its drawing (the graph as shapes) 296 high + /// over the program column, which then holds the source alone + /// (twenty lines); its view the disassembly itself, seven rows over + /// the state column; the registers over six words. + pub const blocks: Split = blk: { + var s = subject; + s.disasm = .{ .x = state.x, .y = canvas.stage.y, .w = state.w, .h = panelH(7) }; + s.view = .{ .x = state.x, .y = canvas.stage.y, .w = state.w, .h = 0 }; + s.source.h = panelH(20); + break :blk s; + }; fn shared(drawing_h: f32, view_h: f32, source_rows: f32, disasm_rows: f32, slots: f32, dump_rows: u32) Split { const band: Rect = .{ .x = program.x, .y = canvas.stage.y, .w = program.w, .h = drawing_h }; @@ -675,6 +686,66 @@ pub const metric = struct { pub const bottom_lane = 8; }; + /// `graph` (design/README.md, "graph"): on the map a block is a head of + /// 24 and its rows: the offset ranged right at 72, the line at 116, the + /// mnemonic at 128, the operands at 212; 300 wide at least; over 16 + /// rows, where the graph is too tall, its first four, `more` and its + /// last four. Layers 48 apart, blocks 56; lanes 16 apart from 24 in, the + /// blocks 24 right of the last; the first layer 36 under the tag; a back + /// edge down 14; ports 40 in; arrivals 48 apart; the right channel 32 + /// out; corners 8; the way out's stub 14 and bar 28; a call's hook 14 + /// out and back a row down. A fold of blocks never reached: 520 wide. + /// Columns are as far apart as the pc's block is wide with its annotation. + /// The `blocks` lens at half measure: boxes 24 high, 60 and 10 a row + /// wide, 132 at least, columns 300 apart; layers 12 apart, lanes 10. + pub const graph = struct { + pub const offset = 72; + pub const line = 116; + pub const mnemonic = 128; + pub const operands = 212; + pub const least = 300; + pub const long = 16; + pub const keep = 4; + pub const layer_gap = 48; + pub const block_gap = 56; + pub const lane = 16; + pub const lane_in = 24; + pub const top = 36; + pub const back_down = 14; + pub const port = 40; + pub const arrivals = 48; + pub const channel = 32; + pub const corner = 8; + pub const exit_stub = 14; + pub const exit_bar = 28; + pub const hook = 14; + pub const fold_w = 520; + pub const head = [2]f32{ 10, 10 }; + /// The rows are `insn`'s, `shift` left (its address column given to + /// the offset); the pc's block widens to its column for the + /// annotation, 30 characters from where `insn` puts it. + pub const shift = 52; + pub const note = 360; + pub const lens = struct { + pub const box = 24; + pub const lead = 60; + pub const per_row = 10; + pub const least = 132; + pub const pitch = 300; + pub const layer_gap = 12; + pub const lane = 10; + pub const blocks_in = 76; + pub const top = 14; + pub const port = 16; + pub const channel = 20; + pub const back_down = 8; + pub const corner = 4; + pub const head = [2]f32{ 7, 8 }; + /// The pc's box: framed gold this wide. + pub const gold = 3; + }; + }; + /// The ties' channels: the thread in the left margin, the gutter's two /// lanes (a link comes up the left, a projection down the right). pub const tie = struct { @@ -932,6 +1003,25 @@ pub const time = struct { pub const out = 0.20; pub const names = 0.20; }; + /// `leave` (and `turn`, along a loop's lane): the jump fires; the + /// compare's chips framed as read from `chips` (the CPU's slot); the + /// edge it takes drawn gold over `edge`, ending as the mark sets off at + /// `sets_off`; the mark along it `mark` and `per_100` a 100 units, + /// `mark_most` at most (`run` at a run); the target's count struck + /// `count` after it lands; the oldest trail edge cooled over `trail`; + /// `rest` from the landing to the step's end. + pub const leave = struct { + pub const chips = 0.30; + pub const edge = 0.30; + pub const sets_off = 0.70; + pub const mark = 0.20; + pub const per_100 = 2.0 / 60.0; + pub const mark_most = 0.50; + pub const count = 0.10; + pub const trail = 0.30; + pub const rest = 0.70; + pub const run = 8.0 / 60.0; + }; /// A return in the calls tree: its frame leaves the backtrace as the /// idea strikes, and the result on the node's shoulder this long after. pub const badge_after = 0.20; -- cgit v1.3