diff options
32 files changed, 2463 insertions, 1340 deletions
diff --git a/anim/README.md b/anim/README.md index c6e55bc..8c18c82 100644 --- a/anim/README.md +++ b/anim/README.md @@ -101,13 +101,13 @@ on a primary onset's frame and nothing on it moves a pixel in one. | `title` | the series (six programs, named) and the legend of the marks the scenes use | a card | | | `fib` | recursion: each call a frame and a node | `subject`, `calls` | `steps` | | `list` | a list reversed: each `next` turned; it opens on the map and dives into the frame; after the first load the pointer loaded opens in a loupe, and the `next` in it one deeper | `subject`, `nodes` | `list` | -| `sort` | insertion sort as its blocks: one trip of the inner loop walked a block at a time (each block's rows a cascade onto its last, then `leave` along the edge it takes: the compare's chips framed, the edge drawn gold, the mark along it, the target's count struck; `turn` up the inner loop's lane), the next trip at a run, the long middle a sprint on the map (`surface`, the gold going block to block, the counts growing, `dive`), the last value's trip walked again, the way out run | `blocks` (`graph.Blocks`; the disassembly its view over the state column, the source alone in the program column); on the map the graph with its rows (`Context.Options.graph`) | `sort` | +| `sort` | insertion sort as its blocks, its loops as rings: one trip of the inner loop walked a block at a time (each block's rows a cascade onto its last, then `leave` along the edge it takes: the compare's chips framed, the edge drawn gold, the mark round the ring, the target's count struck; the swap's block `reach`ed the first time, its pill filling; `turn` round the inner ring's foot, `1 turn` struck at its centre), the disassembly unrolled for a beat (the function whole, `unroll` and `roll`), the next trip at a run, the long middle a sprint on the map (`surface`, the gold going round the rings and down the linear column, the counts growing, `dive`), the last value's trip walked again, the way out run | `blocks` (`graph.Blocks`, `rings`: the drawing 880 by 344 over the program column, no view, the source six lines and the disassembly eleven under it, the registers and a stack of twenty beside); on the map the same drawing over the source, the disassembly linear beside it (`Context.Options.graph`) | `sort` | | `syscalls` | glibc's `hello`, by instruction from main: `open` followed down (main's call ringed, the PLT's stub passed, libc's wrapper run to its last three instructions and those walked, its source beside it where the build has it (open64.c, and sysdep-cancel.h where the pc is in what that header's macro made; `zig build sources`), the kernel's window at the floor with the call in C's form and `returns`, and back up), then `read`, `close`, `write` stepped over, each in three parts: the instructions before the call a cascade onto the call row, the crossing from that row with the kernel's window opening under it (the rows after it making room), the stores after it 18 f after rax | `beside`, `syscalls` (the calls so far, as strace writes them); the disassembly a `descent` (`Context.Options.descent`) | `hello` | | `musl` | the same `hello` built by Zig against musl, static: `open` followed down with no PLT and no GOT, the source panel following the pc through musl's own files (open.c, `__syscall_cp.c`, the one line of `syscall_arch.h` that is the `syscall`), the kernel's window, and back up to `main` | `beside`, `syscalls`; the disassembly a `descent` | `musl` | | `heap` | glibc's malloc under a list of three: three pushes, two pops, a push, told by motion.md's storyboard (nine captions; pushes 2 and 3 at a run; each `free` and the `malloc` that takes the head back walked; what the storyboard does not narrate runs: the calls into push and pop with their prologues, the returns to main but the one under the second free's long caption); the chunks by fields (`size`, `protected`, `key`), the program's list over the tcache's free list with its `bin` (a chunk in neither list drawn in the program's row, unarrowed), the tcache in a loupe over the stack, its stem down the gutter from its chunk's row, opened in each step that changes the tcache and closed at its advance | `subject`, the scene's own drawing (`nodes` in two rows) and view, both on its map too | `heap` | | `zoom` | one line of C as its instructions, the call's bytes | `none`, the camera at x1.16 on the instructions and the stack in one view, cause and effect (the stack's window set before the move and held); the map's drawing the calls of `fib` (`Map.drawing`) | `steps` | | `sqlite` | a row's way to disk in SQLite: from `sqlite3_step` to `sqlite3BtreeInsert` (three continues, the row's struct on the stack), the commit's `unixWrite` nine calls under `main`, `pwrite64` of page 2 into the kernel, and the page read as a B-tree leaf | `subject`, `backtrace` (`Context.Options.backtrace`), then `syscalls`; its view a `hexdump.Dump`; as the caption names them, rdi's `BtCursor` opened in a loupe, then rsi linked to its row in the view (`Context.tiesWith`); the page's fields named a group at a time, 2 s apart; the backtrace lens drawn on its map | `sqlite` | -| `gallery` | every block in its states, a page or a state each 3 s; at 21 s the `blocks` lens (at rest, `leave` mid-way, `turn` landing, libc's `open` folded), at 24 s the graph with its rows as the map draws it, at half size (sort's panned to its loop; `open` at its `syscall`, the blocks not reached folded) | all three, `blocks` | `gallery`, and for the graph pages `test/gallery/sort.ztrace` and `hello.ztrace` | +| `gallery` | every block in its states, a page or a state each 3 s; at 21 s the `blocks` lens (sort's rings at rest, `leave` mid-way, a `turn` landing with its ring's count struck; libc's `open` in `layers` at its `syscall`, what it has not reached folded), at 24 s the moves of a first time (sort's first swap `reach`ed, its pill filling; `open` stepped past its `syscall`, its fold mid-`unfold`; sort in `layers` panned to the pc; the fold open, at rest). Its context pages fold the registers its one step does not change | all three, `blocks` | `gallery`, and for the graph pages `test/gallery/sort.ztrace` and `hello.ztrace` (the second page's picture keeps the old name `graph-map.png`) | ## The blocks @@ -116,26 +116,26 @@ every state the code has in the `gallery` scene. | Layer | Block | Where | Notes | | --- | --- | --- | --- | -| 0 tokens | grid, colour, type, the splits | `src/theme.zig` | per "Token changes" (`metric.calls`, `time.pin`, `time.continue_wave`, `time.relayout_fade` there; the insn's character counts gone); JetBrains Mono NL (`.code*` faces) for all mono, Medium under 30 | +| 0 tokens | grid, colour, type, the splits | `src/theme.zig` | per "Token changes" (`layout.split` and `layout.fit`, `metric.registers` (the quiet cells), `time.unroll` (`unroll`, `roll`, a far jump's travel; the extend's 4 f is `time.extend` now), `metric.calls`, `time.pin`, `time.continue_wave`, `time.relayout_fade` there; the insn's character counts gone); JetBrains Mono NL (`.code*` faces) for all mono, Medium under 30 | | 1 atom | `address` (`lead`, `name`, `rwx`), `value` (and `Ui.typed`: `fd`, `bool`, `char`), `arrow` (`points`, `holds`, `more`), `mark`s, `plaque` (`chip`), `pin` (`row`, `under`; and at a view's row's end, `Ui.pinEnd`), `bracket` (`quiet`, `tie`, `thread`), `tag` | `src/ui.zig` (`Ui.address`, `.value`, `.arrow`, `.written`, `.corner`, `.read`, `.cellWritten`, `.cellRead`, `.current`, `.trail`, `.unknown`, `.chip`, `.pinRow`, `.pinUnder`, `.bracket`, `.panel`) | marks as mock 15's column B: `current` the white wash (`color.wash`) and the gold plaque; `struck` the softened paper (`color.struck`) with bold bright digits; `held` a turned corner (9; 12 on a lens's cell), in over the cool's last 6 f (`Heat.corner`, `time.strike.corner`); `armed`, `read` | | | `byte` | `src/rows.zig` `bytes` | `number`, `pointer`, `text` (a string's ink), `loose` (a byte of no field: the allocator's, padding, past what a dump is of), `unread`; `pad`; `bytesAt` moves the bytes right of a long (stack) address, by the dump's widest; a write's arm, strike and held corner cover the bytes whose value changed, first to last (`Run.changed`, `Now.changedBytes`), struck a byte a frame from the low address (what a read fills, 2 f apart); until its strike lands (s+3) a run keeps its old bytes and their reading, through the arm, read by its old field where the step retypes it (`hexdump.keepOld`, `Fields.was`) | | 2 row | `chain`, `reg` (and `rip` with the flags), `slot`, `line`, `bytes`, `call` (`span`, `callRow`) | `src/rows.zig` | `chain` follows `zt.telescope.chase`; cut at its far end, `more`; a register's reads memory as the panels show it, the step's bytes from their strike (s+3): its later hops fade out from the strike and are followed again 4 f after the bytes land (`Now.following`, `Marks.hops`). `slot`: pins from 16, the offset from rsp ranged right to 172, the address at 184, the chain, its role ranged right where the room ends (48 sooner in a pane: its strip), from `zt.telescope.slots` (`saved rbx`, a local's name in primary, `n, high half` for a narrower local in the word's top four bytes, `argc`, `argv[0]`, `argv end`, `envp end`, `auxv`; nothing for a return address or `.none`). `bytes`: the bracket at 24, the address at 34, the bytes 12 after it and at 132 at least | | | `arc` | `src/rows.zig` (`Arcs`), `src/hexdump.zig` (`pointerArcs`) | a pointer to a row of its own panel: lanes at 4, 10, 16 in a dump or a loupe, 4 and 10 on the stack; longest outermost, a chain in one lane; standing at 60% toward the page, full in the step that writes or reads it and always in a loupe; rewritten: the old dashed with the arm, fading from 6 f after the strike as the new draws (12 f), quieting with the cool; a lane change glides while the arc that causes it draws or fades (`Arcs.assign`, with and without the arcs on their way); a stub to the rule for a target in the region past the window, only in its step; a saved rbp's only in its step, going with its advance (18 f); a dump withholds the arcs an open loupe carries | | | `insn` | `src/disasm.zig` | columns at 2, 31, 40, 134, 180, 264, 564 (540 in a pane, whose strip takes 48 of the row; `map.content`); size words dropped from every operand, a `width` of byte cells (`metric.width`) after the `]` where no register outside the brackets has the access's size and the mnemonic does not fix it; `nop` and `endbr64` faint; a PLT target named (`401070 open@plt`); the annotation from 564 or a character after the operands, then the operands give way, never inside `[]`; `current`, `ran` (every instruction of the last three steps), `ahead`, `outside`, `waiting`, `pass`; the jump lane from the jump just before the pc's moment. The row's detail, every value the recording's at that moment: a compare's two values and the flags it leaves as chips (those the conditional after it reads; CF ZF SF OF when none); a conditional's `taken`/`not taken · reads` and its flags, `→ target` when it leaves the window, and while it runs the setting row's chips and rip's framed as read (an echo); `lea`'s `= value`; a call through memory or a register `→ target name · read from open@got, 403fd8` (out of room the slot goes, then the digits); a call through a PLT stub by the function it reaches (`the resolver` while its slot is lazy); `fs:[0x28]` as the stack's canary (`canary` where the row has no room); a `rep`'s count and step; `syscall` with its name and number, its arguments under it by register, typed (`-100 AT_FDCWD`, `O_RDONLY`), the rows they hang over giving up their own annotation; a call that has run in C's form with its result (`read(3, …) = 15`: out of room the arguments go from the right, the result stays); a memory access narrower than a word read at its width (`rows.narrow`: `7fffffffecc4 ◂ 15`) | | | `descent` | `src/descent.zig` (`Descent`, `step`) | the disassembly a call deep: the root's window on top (main), each callee's under the row that called it (that row `waiting`, ringed, its annotation the call in C's form), a PLT stub gone through kept as its `jmp`, `pass`; a head row over each window (the name at 40, Go Medium 18; what it is ranged right: `libc.so.6 · open64.c` (the file of its function's entry, where the build has the source), `libc.so.6 · no source`, `the PLT · its jmp reads open@got, 403fd8`, `the PLT, jumped through`); the call lane at x 14; the nearest caller takes the rows the deepest does not use, all above its call row (one row after it, the return row, the callee's head directly under that), and where its function starts first the rest go back to the deepest window; three code windows at most, the rest one `more` row; each window's addresses its own width; the tag the deepest function and its module (`open · libc.so.6`); at a `syscall` (and the stop after it) the floor's three rows are the kernel's: in a crossing the lane down from the plaque (3, vellum), the window filling down, `the kernel` and `openat, system call 257`, the call in C's form, `returns` struck, `rcx, r11: clobbered`, the answer climbing the lane (24 f, `glide`), the window drawing back at the advance. A crossing stepped over opens the same window under the call row, past the arguments hanging under it, the rows after them making room (18 f) and closing up with the window. Every row keyed (an address, a head), so a step is the rows both stops have gliding and the rest leaving or arriving on its verb's timetable, in two moves, never at once: `descend` (2.9 s: the given-up rows fade 66–78, the kept ones glide 78–96, ring 84–96, lane 96–114, head 108–120, rows 114–138), on through a stub's `jmp` (2.2 s), `ascend` (2.5 s: the window closes 48–72, lane back 72–84, the kept rows glide 84–102, the given-up ones fade in 102–114), `cross` (`syscalls.step`); a row whose state the verb changes (the call row to `waiting` with its hanging arguments, a jmp to `pass`, a waiting call taking its result) crossfades; with it the source's line `waiting` where the pc is in code without source (ringed, the tag `main waits at line 6 · the pc is in libc's open`, crossfading over the 12 f before the advance, as a stack span's name does) and the thread waiting (primary, 2); where the build has the library's source the panel goes on with the pc into it. Its strip is the deepest window's function's linear column (a `Disasm` drawn for the strip alone, `Map.In.strips`), that window framed on it; going down or up it fades through as the mark lands (`map.through`) | -| 3 panel | `registers`, `stack`, `backtrace` | `src/context.zig` | rip's value crossfading over the advance, a flag set or cleared over the 6 f it lands in (`rows.RipWas`); the backtrace newest at the bottom, `#0` last, the oldest dropped from the top (`newest at the bottom · 2 more above`), as a panel, the calls lens's view, the backtrace lens and on the map, all one block (`backtraceRows`: frames leave, slide and arrive; what a kept row says that changes, its depth, its pc's offset, its line, and the tag's count, crossfades, 12 f before the advance); the stack's window on `[rsp, rbp+16)` keeping the touched word in view, its tag the first and last word shown (`rsp+20 to rsp+48`), a word's role and offset, and the tag, crossfading (12 f from memory's strike) where the step changes them, rsp and rbp's pins travelling 18 f after rsp's strike (`time.pin`, keeping their place among the names they leave and join), at rest only where the register points; a window that moves farther than its own height (six or eight slots) fades out and in round memory's strike (12 f each; at a run half its step each), and what it brings, and what changed before it, is plain; while rows slide they keep their roles (those of both windows are read), and a word becoming a saved rbp, or no longer one, has its arc go or come with its role; a frame's name longer than the spans' room shortens the chains beside it; `call` spans and the backtrace (`#n`, name, arguments at 384, file and line) from `zt.telescope.frames`, the frames two stops share sliding to their new depth; the backtrace as a lens's drawing with `Context.Options.backtrace` | -| | `source` | `src/source.zig` | the file the pc is on a line of, of the recording's sources (`Recording.sources`, `shown`: the program's own, or a library's the build gave; else the last such line, a frame up, where the pc waits), whole in a window, its middle third; its lines cut at 63 characters in a pane (67 on the map); the trail's bars (of that file's lines) crossfading with the advance; numbers as wide as the widest file's largest line (SQLite's six digits), the text moved right by as much; another file: the panel fades through (12 f out, 12 f in), its tag's title and note crossfading with it, its strip with it (`map.through`); a window going farther than its own height in one file: the advance is 48 f, the window gliding on the strip for the first 24 (the gold lit on its new row there), then the pane out and in | -| | `disasm` | `src/disasm.zig` | 17 rows (9 as subject), fewer above near a function's start; on the map 69 from the function's start where the pc is in its first three quarters (a strip's column stays still while the pc walks it), else round the pc; the line column as wide as the source's, a row's number where its line is of the file the source panel shows (libc's rows open64.c's while it shows open64.c, main's none then); two windows that overlap scroll, others fade out and in; its tag's function (a descent's tag too) crossfading with the advance; a 2-unit `rule` across over each block's first row (not its function's), and the block's visits by the moment shown ranged right, faint (`×3`), where the row's annotation leaves room, crossfading with the advance (`graph.Rules`, a descent's windows too); the rows clipped above the panel's padding (a row scrolling out takes its rule with it) | -| | `graph` | `src/graph.zig` (`read`, `fold`, `place`, `layout`, `Blocks`, `Map`, `Rules`) | the function's blocks from the recording (`zt.telescope.blocks`; a block of `nop` padding nothing goes to left out), their edges by how each ends, and the run over them by the moment shown: each block's visits, each edge's count, the last three edges taken, the pc's block; counted where one stop in the function follows another across an edge, and only for a recording that stops at every instruction (`exact`; by line, visits only, every edge `rule`). Laid out (`place`, pure, by the whole recording's counts, so it never moves as they grow): back edges by a walk from the entry in address order, layers by the longest forward path, the blocks that return last; in a layer a block under the predecessor that reached it most often, then under the one it falls from, a taken target never taken right of it, the more travelled first where two want one column; columns a pitch apart (the map's as wide as the pc's block with its annotation, 928; the lens's 300); a forward edge out of the bottom on its target's side (40 in, 16 in the lens; the middle when straight below), along the gap's middle, into the target's top (arrivals 48 apart), through the right channel (32 out) where it would cross a block; a back edge down 14, out to its loop's lane (16 apart from 24, the outermost farthest), up, into its header's head. Too tall for its place (`layout`), in the catalogue's order: each run of blocks the whole recording never reached (neighbours in address order joined by an edge; split where folding would make a loop the code does not have) one dashed box, `+5b to +b9 · 5 blocks not reached` (said of the run so far: a graph says only what has happened by the moment shown, never what will not; which blocks fold, and where each block is placed, are still chosen by the whole recording); then blocks over 16 rows to four, `more`, four (not the pc's); then it pans, whole layers, to the largest loop the pc's block is in that fits, else the pc's block in the middle. The static part kept per function and form (`memo`), the moment's counts counted again each frame. `Blocks`: the lens's drawing, boxes 24 high, 60 and 10 a row wide (132 at least), the offset, the visits (`dim`), reached `raised`, not yet on the page, a fold dashed, the pc's framed gold 3; the edges never taken `rule`, taken `dim`, the trail's golds (the newest 3), a loop's turns on its lane (Go 18). `Map`: on the map two columns wide beside the source, each block a head (its address, `lines a to b`, `×n` primary) over `insn`'s rows moved 52 left, the offset where the address was (ranged right at 72); the annotation only in the pc's block (and its rows that ran in the last three steps, with their trail bars), which widens to its column, its rows' annotations kept inside it; a conditional's counts by its ports; a direct call's hook out of the block's side and back a row down, the callee named (`swap`); under a return the way out (stub 14, bar 28), a tail call's stub and name, an indirect jump's `targets not known` | -| | `blocks` lens | `src/graph.zig` (`Blocks`), `theme.layout.split.blocks` | its drawing the graph as shapes over the program column (296 high), which then holds the source alone (twenty lines); its view the disassembly itself, seven rows over the state column; the registers over six words; no thread (the disassembly is not under the source: it fades with the distance between them) | +| 3 panel | `registers`, `stack`, `backtrace` | `src/context.zig` | the registers `quiet` (`Registers.moves`, `movedBy`, `registerRows`): the scene's set chosen once, from its clock's way (`Cursor.journey`: the registers any of its steps of that kind changes, net, with rsp, rbp and rip), each a row with its chain; the rest folded three to a row on a pitch of 285 under a 2-unit rule, in pwndbg's order (`rows.quiet`: the name faint at 12, the value at 60, a pointer cut to `more` at once, a code address alone; framed as read while it carries a system call), rip last; the panel as tall as its rows and the stack the rest (`layout.fit`); in a `dive` it arrives whole from the map and folds as it lands (`Zoom.fold`: each quiet row gliding into its cell, the chain past its first hop gone over the first 40% of the move, a rule fading in); rip's value crossfading over the advance, a flag set or cleared over the 6 f it lands in (`rows.RipWas`); the backtrace newest at the bottom, `#0` last, the oldest dropped from the top (`newest at the bottom · 2 more above`), as a panel, the calls lens's view, the backtrace lens and on the map, all one block (`backtraceRows`: frames leave, slide and arrive; what a kept row says that changes, its depth, its pc's offset, its line, and the tag's count, crossfades, 12 f before the advance); the stack's window on `[rsp, rbp+16)` keeping the touched word in view, its tag the first and last word shown (`rsp+20 to rsp+48`), a word's role and offset, and the tag, crossfading (12 f from memory's strike) where the step changes them, rsp and rbp's pins travelling 18 f after rsp's strike (`time.pin`, keeping their place among the names they leave and join), at rest only where the register points; a window that moves farther than its own height (six or eight slots) fades out and in round memory's strike (12 f each; at a run half its step each), and what it brings, and what changed before it, is plain; while rows slide they keep their roles (those of both windows are read), and a word becoming a saved rbp, or no longer one, has its arc go or come with its role; a frame's name longer than the spans' room shortens the chains beside it; `call` spans and the backtrace (`#n`, name, arguments at 384, file and line) from `zt.telescope.frames`, the frames two stops share sliding to their new depth; the backtrace as a lens's drawing with `Context.Options.backtrace` | +| | `source` | `src/source.zig` | fourteen lines alone, eight with a lens, six with `blocks`; the file the pc is on a line of, of the recording's sources (`Recording.sources`, `shown`: the program's own, or a library's the build gave; else the last such line, a frame up, where the pc waits), whole in a window, its middle third; its lines cut at 63 characters in a pane (67 on the map); the trail's bars (of that file's lines) crossfading with the advance; numbers as wide as the widest file's largest line (SQLite's six digits), the text moved right by as much; another file: the panel fades through (12 f out, 12 f in), its tag's title and note crossfading with it, its strip with it (`map.through`); a window going farther than its own height in one file: the advance is 48 f, the window gliding on the strip for the first 24 (the gold lit on its new row there), then the pane out and in | +| | `disasm` | `src/disasm.zig` | under the source in every split: 17 rows (11 as subject and with `blocks`), fewer above near a function's start; on the map 69 from the function's start where the pc is in its first three quarters (a strip's column stays still while the pc walks it), else round the pc; the line column as wide as the source's, a row's number where its line is of the file the source panel shows (libc's rows open64.c's while it shows open64.c, main's none then); two windows that overlap scroll, others fade out and in; its tag's function (a descent's tag too) crossfading with the advance; a 2-unit `rule` across over each block's first row (not its function's), and the block's visits by the moment shown ranged right, faint (`×3`), where the row's annotation leaves room, crossfading with the advance (`graph.Rules`, a descent's windows too); the rows clipped above the panel's padding (a row scrolling out takes its rule with it) | +| | `graph` | `src/graph.zig` (`read`, `layout`, `place`, `Blocks`, `Rules`, `leave`) | the function's blocks from the recording (`zt.telescope.blocks`; a block of `nop` padding nothing goes to left out), their edges by how each ends, and the run over them by the moment shown and nothing after (design/README.md, Forbidden): each block's visits, each edge's count, the last three edges taken, the pc's block, counted where one stop in the function follows another across an edge (`exact`: by instruction; by line, visits only). Laid out from the code alone (`place`: never the run's counts), in two forms (`Blocks.form`): `rings` wherever the function has a loop (natural loops merged by header, back edges by the walk from the entry in address order; each a ring, its pills upright at their centres clockwise from the header at 9 o'clock, radius as its pills need, 12 apart and 24 of arc between two; a nested loop a smaller ring outside its parent touching it at its header, the parent's 3 o'clock; an edge to the next pill an arc of its ring cut at the pills' frames, the back edge round the ring's foot, a fork inside a loop an arc 30 inside, a way out along the tangent out of the pill's foot 30 in from its far end, then quarter circles of 16; outside every loop the blocks as `layers` lays them, the entry left of the header, the blocks after under it; `3 turns` 30 under the ring's centre, from the first) and `layers` (layers by the longest path, a block under its fall-through predecessor, a taken target right of it, back edges up lanes on the left, every corner a quarter circle of 12; panning by thirds round the pc's pill where it is taller than its pane). A block a pill 24 high: its offset, the program's callees after it, faint (the tracer's `__zt_*` left out), its visits ranged right, room kept for `×99` so it never widens as the run counts; not reached yet on the page, `rule` framed, faint, no count; the pc's framed gold 3. Edges not taken yet `rule`, taken `dim`, the trail's golds, the newest 3. Too big for its pane (`layout`), the blocks not reached by the scene's first moment fold (`cursor.first`: the code beyond each way the run had not taken, `+5b … · 7`), keeping a fold's room; a fold opens when the run reaches a block of it and never closes (`unfold`: the pills beyond make room 24 f, `glide`, the fold's blocks fade in quiet 12 f, 2 f apart, then the mark lands). `leave` and `turn` along the curves (12 f and 2 f a 100 units, 12 to 42 f; the turn's count at the ring's centre armed as the mark leaves the latch, struck as it lands); `reach` (the edge from `rule` to gold under the mark, the pill filling page to `raised` 12 f, `×1` in 6 f and struck). Kept per function, form, room, first moment and open folds (`memo`), counted again each frame. On the map the drawing is the lens's at its size over the source, the disassembly linear beside it (`Rules`) | +| | `blocks` lens | `src/graph.zig` (`Blocks`), `theme.layout.split.blocks` | its drawing the graph, 880 by 344 over the program column (`rings`, or `layers` for a function with no loop: `Blocks.form`); no view: its rows are the disassembly under the source (eleven), each block's first row ruled with its visits, the thread from the source's line to them; the state column the registers and a stack of twenty from its top | | | `hexdump` | `src/hexdump.zig` | malloc's words: a field read as `size` (`0x20 a m P`, the bits as rip's flags) or `protected` (`→ 405050 ^ 405`, `NULL ^ 405`, its arc to the pointer it protects), and a field's `note` (Go 18 faint: `key`, `top`, `slots left`); a lens's view (`hexdump.panel`): `bytes` rows and their reading, veiled at a sprint; a row whose bytes the step changed where the recording saw no write (memory nothing watches, read anew at a stop), or that became known, crossfading over 12 f (`rowPasses`); one reading for every dump (`hexdump.reading`), a list a character apart, a typed number as its type reads (`char` quoted, `bool` by name); the address room once a dump, by its widest; `Dump`, a view of a region by the fields a scene gives it (`Field`: where, how long, read as a number, big-endian or not, a pointer, text, or left to the eye), the rows that hold a field and a `more` row for each stretch left out, and where those rows outnumber the window, a window kept round the first row a mark or the step is on, the rest folded into `more` rows; marks the scene plays, and the step's only from the stop it came in at (`since`); the bytes a syscall was given as the kernel took them (`given`), and only what the debugger read at the stop (`seen`) | | | `loupe` | `src/loupe.zig` (`canim.loupe`, `Loupe.open`, `.close`) | from a register, a loupe's field, or a dump's row read by the scene's fields (`.row`: malloc's tcache, `num_slots[0]` and `entries[0]`, the rest `more`); five rows round a pointer's target, lifted (`color.lift`, `lift_tag`, `shade` 12 and 16; 20 and 26 deeper), hanging from its pointer (its tag on the row's foot, 92 left of the digits, clamped to the stage), a 4-high bracket under the digits its stem, the target's fields framed bright; one opened from the band's view lies over the stack, never the registers, its stem down the gutter's right lane (x 962), its fields struck once it has opened (6 f after, 6 f apart: `Fields.struck`); a deeper one with no room to the right hangs under the one it opens from, its stem down to its tag; a note that does not fit is cut at a word with `…`; `open` 36 f (read 6, stem and rise 18 with the shadow, the frame 6 f after), `close` 12 f; it opens again after a close | -| | lenses: `nodes`, `array`, `calls`, `syscalls`, `backtrace` | `src/nodes.zig`, `src/array.zig`, `src/calls.zig` (`Tree`), `src/syscalls.zig` (`Crossing`), `src/context.zig` (`Backtrace`, `lens`) | the drawing in `band` (over the program column), its view in `view` (over the state column): `nodes` and `array` a dump (`hexdump.panel`), `calls` the backtrace with arguments, `syscalls` the calls so far as strace writes them (oldest on top, the newest coming in once it is back, held; the rows make room for it, a full log scrolling a row, 24 f, `glide`, the count above crossfading; out of room a row gives up its faint names first, then its arguments from the right, and keeps what it returned; a path by its string, the kernel's capture where the stop did not read it) over the bytes the call crossing in the step is given or fills (in with the argument framing, 12 f out and 12 f in; what a read fills landing a byte every 2 f, struck, the stack's words with them; a write's buffer framed as read while the kernel takes it; cleared with the log's new row: between crossings `no call crossing now`), `backtrace` (eleven rows as subject, five beside) a `Dump` the scene gives; an `under` pin's names in the order they came, the first left, faded out through the middle of a register's joining or leaving (`Pins.text`); a call node's look (gold, ringed, done) crossfading as the tree's moment changes (6 f), and at a sprint a new node coming in over its step; a left child's result on its left shoulder, off its parent; a view's row a register points into carries the register's `pin` at the row's end (`hexdump` `rowPin`; 48 to the left in a pane, its strip at the right), the reading ending before it; at a sprint the array's pins hold and move where a phrase ends | +| | lenses: `nodes`, `array`, `calls`, `syscalls`, `backtrace` | `src/nodes.zig`, `src/array.zig`, `src/calls.zig` (`Tree`), `src/syscalls.zig` (`Crossing`), `src/context.zig` (`Backtrace`, `lens`) | the drawing in `band` (over the program column), its view in `view` (over the state column): `nodes` and `array` a dump (`hexdump.panel`), `calls` the backtrace with arguments, `syscalls` the calls so far as strace writes them (oldest on top, the newest coming in once it is back, held; the rows make room for it, a full log scrolling a row, 24 f, `glide`, but from rest at least a pixel a frame (the rows are drawn on whole pixels), the count above crossfading; out of room a row gives up its faint names first, then its arguments from the right, and keeps what it returned; a path by its string, the kernel's capture where the stop did not read it) over the bytes the call crossing in the step is given or fills (in with the argument framing, 12 f out and 12 f in; what a read fills landing a byte every 2 f, struck, the stack's words with them; a write's buffer framed as read while the kernel takes it; cleared with the log's new row: between crossings `no call crossing now`), `backtrace` (eleven rows as subject, five beside) a `Dump` the scene gives; an `under` pin's names in the order they came, the first left, faded out through the middle of a register's joining or leaving (`Pins.text`); a call node's look (gold, ringed, done) crossfading as the tree's moment changes (6 f), and at a sprint a new node coming in over its step; a left child's result on its left shoulder, off its parent; a view's row a register points into carries the register's `pin` at the row's end (`hexdump` `rowPin`; 48 to the left in a pane, its strip at the right), the reading ending before it; at a sprint the array's pins hold and move where a phrase ends | | 4 tie | `thread`, `link` (and its `pin`), `projection`, `echo` | `src/ties.zig` | panels publish places (`anchor`); `Ties`, added last, draws in the channels: a link climbs to a node by the gutter's left lane and goes down to a slot by the right, its name riding its head, a target past the stack's window a stub and a row count; to a view's row (`dump_pin`) by the left lane, into the row's edge; on a beat the narration names (`Context.tiesWith`, `ties.Beat`): the register framed as read, then its link, held, drawn back with the frame; a projection from the view's bytes, or from a frame's return address to its call's node | -| 5 frame | `map`, `minimap`, `dive`, `surface` | `src/map.zig` (`Map`, `split`, `strip`, `Map.strips`), `Context.map` | the working frame's panels bound to a stage of 3840 by 2160 (`map.split`, packed by content: each box as long as the most rows its panel has wanted, `measure`, the backtrace's as long as the deepest call chain of the scene's way, so that it is packed once; the drawing, the source and under it the backtrace; the disassembly; the view (none where nothing draws one), the registers, and in the column's rest the stack going on, `stack, continued`; the stack from 16 words above rsp; and the first two columns' rest (`Split.spare`) given, in the catalogue's order, to `map.Spare`: a five-row dump round each place the registers (pwndbg's order, not rsp or rbp) and the 64 words up from rsp point at outside the stack and the code, none within another's rows, then the loupes open (`Map.loupes`, lifted, nine rows), then the key (the recording and the moment, the marks as drawn, the inks); only then page); its rows published while `ui.mapping` (the dumps' too); the working windows outlined (2 `dim`, 4 out), each window published with where its step took it from and how far its scroll has gone, so its outline glides; the thread across the gutter (x 1008), gold; a scene without a band can put a drawing on its map (`Map.drawing`); with `Context.Options.graph` the disassembly is the function's graph (`graph.Map`), two columns wide beside the source, the registers over the stack in the last column, no band (the lens's window on it is the graph whole, the disassembly's the box round the rows it shows), no thread line (the gold line number is the thread). Each pane's minimap (`map.strip`): a strip 40 wide inside its frame at its right, under the tag, on `well` (`theme.strip`), drawn from its column of the map (the source's boxes, the stack's with `stack, continued`, the view's dump; the disassembly's the linear rows round the pc, drawn for the strips alone where the map has a graph or a descent: `Map.In.strips`) at 4 units a row and 36 of 880 across, from what the map drawn for it collects (`ui.strokes`, `ui.collected`: each run of text a stroke 3 high in its ink 65% from the page, the marks 4 by 4 at a row's left in the catalogue's order, an arc with an end off the window a 2-unit line down the left edge, a block's first row ticked); a column longer than the strip the rows round its window, the window in the middle, clamped to the ends, three faint dots where it goes on (fading in over its first row's scroll); the window framed 2 in primary; a mark no working window shows (a word struck or read on the stack or in the view's dump) flashing on its row (a ring 8 to 14 in the mark's colour, 12 f). The strips are one image a frame (`Map.strips`): the map drawn for them six times, each from the cursor's mirror a frame later (6 to 11 f behind: `Cursor.lagInto`) with the panes' windows as long ago (`past`), every strip drawn as it shows (its rows, dots and window in place) and the six averaged, so that every change on a strip fades in over 6 f from 6 f after its onset and nothing on it moves a pixel in a frame; the panes blit their part (source, disassembly and its descent and the `blocks` lens's view, stack, a dump's view: not the registers, a drawing, a loupe, the backtrace, the `syscalls` lens's log). A pane with a strip has 48 less for its rows (`map.content`). `Map.show`, `.dive` (outlines bright 6 f, veil to 24, each panel from its window to its place 60 f, 6 f apart, a panel drawn over another setting off first (drawing, view, disassembly, stack, source, registers) so that none in its place is crossed by one on its way, opaque on the way, its rows on the window's rows, its tag and rules in from 84 f; with each, the rest of its column (the rows its strip shows) squeezing from its place on the map into the strip, its width and height each on its logarithm (to 36 of 880, 4 of 24 a row), its window's outline riding on it, gone into the strip's own drawing over the 12 f before its pane lands (`Map.squeeze`, `stripShows`); the map's other parts fading where they are, 24 to 72; 120 f and 30 f still), `.surface` (the dive back, 84 f, then 30 f still); per-panel transforms through `context.at` (`context.zoomed`); the clock's count ranged right at 1856 | -| | `stage` and `relayout` | `src/stage.zig` | splits `none`, `beside`, `subject` (`theme.layout.split`): the band is `band` (the drawing) and `view`; `relayout` fades the drawing round its move; `holdStack` holds the stack's window for the camera, with `free` slots | +| 5 frame | `map`, `minimap`, `dive`, `surface` | `src/map.zig` (`Map`, `split`, `strip`, `Map.strips`), `Context.map` | the working frame's panels bound to a stage of 3840 by 2160 (`map.split`, packed by content: each box as long as the most rows its panel has wanted, `measure`, the backtrace's as long as the deepest call chain of the scene's way, so that it is packed once; the drawing, the source and under it the backtrace; the disassembly; the view (none where nothing draws one), the registers, and in the column's rest the stack going on, `stack, continued`; the stack from 16 words above rsp; and the first two columns' rest (`Split.spare`) given, in the catalogue's order, to `map.Spare`: a five-row dump round each place the registers (pwndbg's order, not rsp or rbp) and the 64 words up from rsp point at outside the stack and the code, none within another's rows, then the loupes open (`Map.loupes`, lifted, nine rows), then the key (the recording and the moment, the marks as drawn, the inks); only then page); its rows published while `ui.mapping` (the dumps' too); the working windows outlined (2 `dim`, 4 out), each window published with where its step took it from and how far its scroll has gone, so its outline glides; the thread across the gutter (x 1008), gold; a scene without a band can put a drawing on its map (`Map.drawing`); with `Context.Options.graph` the map's drawing is the `blocks` lens's (`graph.Blocks` at its size, 880 by 344, over the source: `split`'s band is the working frame's), the disassembly linear beside it with its blocks ruled. Each pane's minimap (`map.strip`): a strip 40 wide inside its frame at its right, under the tag, on `well` (`theme.strip`), drawn from its column of the map (the source's boxes, the stack's with `stack, continued`, the view's dump; the disassembly's the linear rows round the pc, drawn for the strips alone where the map has a graph or a descent: `Map.In.strips`) at 4 units a row and 36 of 880 across, from what the map drawn for it collects (`ui.strokes`, `ui.collected`: each run of text a stroke 3 high in its ink 65% from the page, the marks 4 by 4 at a row's left in the catalogue's order, an arc with an end off the window a 2-unit line down the left edge, a block's first row ticked); a column longer than the strip the rows round its window, the window in the middle, clamped to the ends, three faint dots where it goes on (fading in over its first row's scroll); the window framed 2 in primary; a mark no working window shows (a word struck or read on the stack or in the view's dump) flashing on its row (a ring 8 to 14 in the mark's colour, 12 f). The strips are one image a frame (`Map.strips`): the map drawn for them six times, each from the cursor's mirror a frame later (6 to 11 f behind: `Cursor.lagInto`) with the panes' windows as long ago (`past`), every strip drawn as it shows (its rows, dots and window in place) and the six averaged, so that every change on a strip fades in over 6 f from 6 f after its onset and nothing on it moves a pixel in a frame; the panes blit their part (source, disassembly and its descent and the `blocks` lens's view, stack, a dump's view: not the registers, a drawing, a loupe, the backtrace, the `syscalls` lens's log). A pane with a strip has 48 less for its rows (`map.content`). `Map.show`, `.dive` (outlines bright 6 f, veil to 24, each panel from its window to its place 60 f, 6 f apart, a panel drawn over another setting off first (drawing, view, disassembly, stack, source, registers) so that none in its place is crossed by one on its way, opaque on the way, its rows on the window's rows, its tag and rules in from 84 f; with each, the rest of its column (the rows its strip shows) squeezing from its place on the map into the strip, its width and height each on its logarithm (to 36 of 880, 4 of 24 a row), its window's outline riding on it, gone into the strip's own drawing over the 12 f before its pane lands (`Map.squeeze`, `stripShows`); the map's other parts fading where they are, 24 to 72; 120 f and 30 f still), `.surface` (the dive back, 84 f, then 30 f still); per-panel transforms through `context.at` (`context.zoomed`); the clock's count ranged right at 1856. `unroll` and `roll` (`Map.unroll`, `.roll`, `map.Unroll`, added over everything by `Context.ties`): the panes veiled and the strip's window framed bright (18 f), the pane's whole column growing out of its strip (36 f, `glide`) to as many rows as the stage holds (24 a row at most; right on the strip's edge, the window's rows level with the pane's where the stage allows), its scale on the logarithm from the strip's, the window's outline riding from the strip to the pane's rows in it; held as the scene says; `roll` the reverse (36 f), the veil lifting (18 f). A far jump in the same column at a walk (the source's window farther than its height to lines the map's column of the file holds too, `source.unrolling`, `inColumn`: no step said faster in a hurry) is `unroll`, the window travelling along the column (24 f, `glide`, the mark lighting gold at its new line as the window gets there, the tag's note changing then), `roll` (96 f: `Cursor.travel`), the pane going into the column and coming out of it at its new place, never a fade. Out of the column (another function, a long file) the map's column goes over as the advance starts, so the strip (6 to 11 f behind, a 6 f crossfade) shows where the pane goes before the pane fades through (`over`, `far` on the map at half its height); a window going farther than the column holds keeps its place on the strip until the column goes over (`spanOf2`); the tag's line range changes with the pane's fade; the map's disassembly is measured by the moment the pane shows (a continue repacks the map as the pane gets there), and a recording of breakpoints has its deepest chain read at every stop (`deepest`: the backtrace's box packed once) | +| | `stage` and `relayout` | `src/stage.zig` | splits `none`, `beside`, `subject`, `blocks` (`theme.layout.split`, layout A: the disassembly under the source in every split; the source 14, 8, 8 and 6 lines, the disassembly 17, 17, 11 and 11 rows; `blocks` a drawing of 880 by 344 over the program column and no view, the state column the registers' and the stack's from the top), each for a registers panel of eleven rows; `layout.fit` gives the scene's registers their rows and the stack the rest above the backtrace, whole slots, any rest above it (`Stage.registers_rows`: every split a `relayout` goes to keeps them); the band is `band` (the drawing) and `view`; `relayout` fades the drawing round its move; `holdStack` holds the stack's window for the camera, with `free` slots | | | `clock`, `caption`, `veil`, `card` | `src/words.zig`, `src/root.zig` (`Narrator`, `Camera`) | the clock still while a step plays, its piece fading in once the mark lands; a caption stays its reading time; the title card is `scenes/title.zig` | -| 6 verb | `fire`, `arm`, `strike`, `cool`, `read`, `extend`, `link`, `project`, `travel` (pins), `advance`, `cascade`, `continue` (`Cursor.continue`, `Plan.wave`), `run`, `sprint`, `establish` (`Context.establish`: a drawing's elements fade in rising, no lines), `scroll`, `relayout`, `visit`, `say`; `leave` and `turn` (`graph.leave`, from a block's last row, `graph.toEnd` to get there: fire 0–12; the compare's chips framed as read from 18 (the CPU's slot, the jump's echo), held while the edge draws gold, head first, 24–42; the mark (a gold plaque, half size in the lens) along the edge 42 to 42 + 12 f and 2 f a 100 units of the lens's edge (30 f at most), up the lane for a turn; landing, the advance; the target's count armed and struck 6 f after (a turn's lane count as it lands), cooled to nothing by the step's end; the trail recoloured over 18 f from the landing; a rest of 42 f from the landing); over a graph at a walk of several blocks, a run or a sprint the trail, the counts and the gold crossfade with the advance (8 f at a run, the step at a sprint), the pan gliding with it | `src/cursor.zig` (the timetable), `src/graph.zig` (`leave`, `instant`), the blocks (each draws its state at the instant) | tokens in `theme.time`; a level gives up its slot when nothing it touched is drawn (`Recording.drawn`); a label that changes in place with a step crossfades over the 12 f before the advance, or from the step's start where that is sooner (`Now.renaming`); at a run what marked a value goes with the run's ease (8 f) and a pin changes over it; at a sprint an ember and what grows come in over the step (4 f), never in a frame | +| 6 verb | `fire`, `arm`, `strike`, `cool`, `read`, `extend`, `link`, `project`, `travel` (pins), `advance`, `cascade`, `continue` (`Cursor.continue`, `Plan.wave`), `run`, `sprint`, `establish` (`Context.establish`: a drawing's elements fade in rising, no lines), `scroll`, `relayout`, `visit`, `say`; `unroll` and `roll` (`Map.unroll`, `Map.roll`, above); `reach` and `unfold` (`graph`, above); `leave` and `turn` (`graph.leave`, from a block's last row, `graph.toEnd` to get there, along the curves of `rings` or `layers`: fire 0–12; the compare's chips framed as read from 18 (the CPU's slot, the jump's echo), held while the edge draws gold, head first, 24–42; the mark (a gold plaque, its point the way it goes) along the edge 42 to 42 + 12 f and 2 f a 100 units of the drawing's edge (42 f at most), round the ring's foot for a turn; landing, the advance; the target's count armed and struck 6 f after (a ring's turns at its centre armed as the mark leaves the latch, struck as it lands), cooled to nothing by the step's end; the trail recoloured over 18 f from the landing; a rest of 42 f from the landing); over a graph at a walk of several blocks, a run or a sprint the trail, the counts and the gold crossfade with the advance (8 f at a run, the step at a sprint), the pan gliding with it | `src/cursor.zig` (the timetable), `src/graph.zig` (`leave`, `instant`), the blocks (each draws its state at the instant) | tokens in `theme.time`; a level gives up its slot when nothing it touched is drawn (`Recording.drawn`); a label that changes in place with a step crossfades over the 12 f before the advance, or from the step's start where that is sooner (`Now.renaming`); at a run what marked a value goes with the run's ease (8 f) and a pin changes over it; at a sprint an ember and what grows come in over the step (4 f), never in a frame | `Recording` (`src/Recording.zig`) is the index every block reads: lines, calls, syscalls, allocations, which registers and bytes each moment changed @@ -222,8 +222,10 @@ holds is named from its module's first mapping (`list+2c89`). `tools/chart.py chart` on the 1080p exports (the designer's `design/motion/motion.py`, its checks and its regions told where canim's -panels are (sort's the `blocks` split's: the drawing, the view that is -the disassembly, the source alone, the registers and the stack), each +panels are, by split and by each scene's registers panel (layout A: the +registers as tall as the scene's rows, `chart.py`'s `split(…, regs)`; +sort's the `blocks` split's: the drawing, the source and the disassembly +under it, the registers and the stack), each pane's strip a region of its own (`source strip`, `disasm strip`, `stack strip`, and `view strip` where the view is a dump: `motion.strips`, the pane's region stopping 42 short of its right edge), secondary action @@ -253,47 +255,54 @@ list's dive (150 to 300 f) as a caption's change. | | fib | list | sort | syscalls | musl | zoom | sqlite | heap | gallery | title | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | -| POP, before / after | 12 / 7 | 13 / 8 | 3 / 6 | 25 / 7 | – / 12 | 12 / 6 | 8 / 5 | 19 / 16 | 9 / 11 | – / 0 | -| of them the corner minimap's / the strips' | 5 / 1 | 6 / 1 | 2 / 5 | 17 / 1 | – / 1 | 6 / 1 | 3 / 0 | 10 / 6 | 4 / 4 | – / 0 | -| POP exempt, before / after | | | | | | | | | cut 5 / cut 5, keyframe 1 / keyframe 1 | | -| CROWD, before / after | 3 / 4 | 8 / 8 | 10 / 10 | 3 / 4 | – / 2 | 1 / 1 | 1 / 1 | 16 / 16 | 5 / 5 | – / 0 | -| METRONOME, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | – / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | – / 0 | -| CAPTION up over 720 f, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | – / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | | -| CAPTION under its reading time, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | – / 0 | 0 / 0 | 0 / 0 | 0 / 0 | | | -| CAPTION picture moving within 60 f, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | – / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | | -| AIR, before / after | 0 / 0 | 0 / 0 | 1 / 1 | 0 / 0 | – / 0 | 1 / 1 | 2 / 1 | 0 / 0 | 1 / 1 | – / 1 | -| seconds, before / after | 42.0 / 42.0 | 81.7 / 81.7 | 63.8 / 63.8 | 83.8 / 83.8 | – / 68.9 | 33.5 / 33.5 | 62.9 / 62.9 | 78.6 / 78.6 | 27.0 / 27.0 | – / 12.3 | +| POP, before / after | 7 / 7 | 8 / 12 | 6 / 5 | 7 / 7 | 12 / 16 | 6 / 4 | 5 / 4 | 16 / 16 | 11 / 9 | 0 / 0 | +| of them the strips' | 1 / 0 | 1 / 2 | 5 / 4 | 1 / 0 | 1 / 4 | 1 / 0 | 0 / 0 | 6 / 7 | 4 / 3 | 0 / 0 | +| POP exempt, before / after | | | | | | | | | cut 5, keyframe 1 / cut 5 | | +| CROWD, before / after | 4 / 3 | 8 / 9 | 10 / 8 | 4 / 4 | 2 / 3 | 1 / 2 | 1 / 1 | 16 / 17 | 5 / 6 | 0 / 0 | +| METRONOME, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | +| CAPTION up over 720 f, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | | +| CAPTION under its reading time, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | | | +| CAPTION picture moving within 60 f, before / after | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | | +| AIR, before / after | 0 / 0 | 0 / 0 | 1 / 1 | 0 / 0 | 0 / 0 | 1 / 1 | 1 / 1 | 0 / 0 | 1 / 1 | 1 / 1 | +| seconds, before / after | 42.0 / 42.1 | 81.7 / 82.1 | 63.8 / 70.5 | 83.8 / 83.8 | 68.9 / 68.9 | 33.5 / 33.5 | 62.9 / 62.9 | 78.6 / 79.2 | 27.0 / 27.0 | 12.3 / 12.3 | -"Before" is the last pass's "after". The musl scene is new; the title's -export is the last pass's size to the byte (it was not in that table). The -corner minimap is gone and its fires with it (a repack landing in one -frame for all six drawings; its windows' outlines drawn from the frame's -own scroll): syscalls' 17 were most of its 25, in the run through `open`. -The strips that replace it are each the average of six drawings a frame -apart, their windows too (`past`), so a change on a strip fades over 6 f. -sqlite's AIR at 32.95 is gone. Sort's and heap's strips' counts are -mostly not the strips': see below. +"Before" is the last pass's "after". Every scene's layout changed (layout +A), so every count is of new pictures; a POP's place moved with its +scene's timing. The title's export is the last pass's to the byte. Sort +is 6.7 s longer: its first trip walks the swap's `reach` and the ring's +first turn, then the disassembly unrolls for a beat under a caption of +its own (its hold rolled back as the caption's reading time ends: no air +over it). -What this pass built (design/README.md's "The map and the minimap", -mocks 10, 11, 20 and 39; the source following the pc): +What this pass built (design/README.md's "The frame" (layout A), +`registers`, `stack`, `source`, `disasm`, `graph`, the `blocks` lens, the +verbs `reach`, `unfold`, `unroll`, `roll`, `leave`, `turn`, Forbidden's +fact from after the moment; mocks 40 to 43, 22, 24, 25): -- Each pane's strip (`map.strips`, `map.strip`, `map.through`): its - column of the map at 4 units a row, the window framed, the gold, strikes - and reads, an arc's end off the window down its edge, a flash where a - word changes outside it; the corner minimap removed, the clock's count - ranged right at 1856. `dive` squeezes each pane's column into its strip; - `surface` the reverse. The strips' regions in `tools/chart.py` and - `design/motion/motion.py`. -- The source panel follows the pc into any file the build has the source - of (`Recording.sources`, `tools/sources.zig`, `zig build sources`); the - `musl` scene; libraries' frames named by file and line in the backtrace. -- On the way: `rows.fitted` clamps an infinite width (a Debug panic, - `integer part of floating point value out of bounds`, in musl); the - sketchbook's text cache holds 4096 entries and 128 MB, not 512 and 16 - (the map's text drawn six times a frame thrashed it: the list's dive - 0.46 s a frame, about 47 ms after); the heap's recording stops at 46 - steps (libc's lines carried it on through `exit`: 519 moments); the - graph's counts, ink, trail and lane counts are by the moment shown. +- Layout A in every split (`layout.split`, `layout.fit`): the + disassembly under the source; the registers the scene never changes + folded three to a row under a rule (`Registers.moves`, chosen once from + the clock's way), the panel as tall as its rows and the stack the rest: + fib 10 rows and 13 slots, list 9 and 14, sort 11 and 20, syscalls 14 and + 11, musl 15 and 10, zoom 9 and 17 (with the backtrace's four), heap 14 + and 9, sqlite 17 and 6, the gallery 13 and 12 (beside). The `blocks` + split has no view; the thread is drawn in every split. In a `dive` the + registers fold as they land. The view's loupe lies over the stack's + first rows. +- The graph from the code alone, `rings` and `layers` (`graph.zig`, + above), `reach` and `unfold`; on the map the lens's drawing beside the + linear disassembly (the graph-with-rows gone). Sort tells it with its + rings: the swap's first `reach`, the inner ring's first turn. +- `unroll` and `roll` (`map.Unroll`); a far jump in the same column at a + walk unrolls, travels and rolls; the strips' faults at a far jump out of + the column (sqlite: the window lost through a continue, the step back + from `pwrite64`, the tag's range) and the system calls' log's first + pixel steps; a source tag's line range changing with its scroll. +- On the way: a stack word too long for its row's room cut with `…` + (`rows.chain`), a breakpoint recording's deepest chain read at every + stop (sqlite's map no longer repacks as a continue sets off), the map's + disassembly measured by the moment the pane shows; `time.unroll` (the + extend's stagger is `time.extend`). Right in one frame, and exempted by name: the encoder's keyframes and the gallery's cuts (above). @@ -301,85 +310,82 @@ gallery's cuts (above). What fires still, by kind (located on this pass's exports; those not looked at this pass say so): -- The strips' regions: fib 30.37, list 3.87 (in the dive), syscalls - 5.10, musl 63.23, zoom 23.18, 12 to 24 pixels each. Sort's 31.63, - 32.18, 33.93 and 35.25 are the map's own panels under the source - strip's region while the sprint plays on the map (as the view's 32.25); - 52.50 is 14 pixels. Heap's six (12 to 98 pixels) are in the stack - strip's region: 65.07 is a loupe passing over it at a step's first - frame, the rest not looked at. The gallery's 12.22, 18.15 and 20.82 are - at a state's first frame, as its view's re-windowing. +- The strips' regions: list 3.13 and 3.87 (in the dive, 17 and 20 + pixels); sort 0.43 (its opening) and 42.57 (the map's own panels under + the source strip's region while the sprint plays on the map), its 20.52 + and 59.23 (12 and 14 pixels, the stack strip) not looked at; musl's four + (13 to 15 pixels, the stack strip) and heap's seven (the disassembly + strip at 3.62 and 28.62, the stack strip 37.17 to 65.47, 12 to 71 + pixels) not looked at; the gallery's 12.27, 18.15 and 20.82 at a + state's first frame. The unroll's two that fired in a draft (its + window going bright in a frame, its page lifting off the strip in one) + are gone: both fade now. - The stack: a few pixels in the arcs' lanes and the pins (fib 8.20, - 19.50, 24.90, 39.13; syscalls 29.13, 57.72, 70.17; sqlite 20.43, - 31.75); musl's five, list's 7.30, zoom's 19.25 and heap's 55.23 not - looked at. -- Registers: a held corner, a few pixels at a value's top left (fib 21.10, - syscalls 44.32, sqlite 38.67); zoom's 12.80 and 16.40, list's 59.45 and - 70.45, musl's 62.57, heap's 13.68 and the gallery's 22.38 not looked at. -- The source and the disassembly: syscalls 17.92, the line going - `waiting` and back with the descent's rows; zoom 18.10 and 19.60, an - annotation taking its value in place under the camera; musl's five in - the disassembly (31.33 to 66.35), the descent's rows, a library - address's leading digits changing in a frame; heap 13.50, a scroll's - first whole-pixel step from rest. + 25.07, 39.30; syscalls 57.72, 70.17; sqlite 20.43, 31.75; zoom 19.25; + the gallery's 24.62); fib's 3.32 and 19.67 (139 and 235 pixels), + syscalls' 29.13, musl's six, list's 7.30 and heap's 55.83 not looked at. +- Registers: a held corner, a few pixels at a value's top left (fib 21.27, + syscalls 44.32, sqlite 38.67); zoom's 12.80, list's 70.85, musl's 62.57, + heap's 13.68 and the gallery's 26.23 not looked at. +- The source and the disassembly: syscalls 17.92 and 28.23, the + descent's rows; zoom 18.10 and 19.60, an annotation taking its value in + place under the camera; musl's six in the disassembly, the descent's + rows, a library address's leading digits changing in a frame (17.03 + looked at); list 62.97 and 78.87, the source's text changing in one + frame at a run's first step (about 7 400 pixels, not the trail and not + the tag: not identified); list's 46.22 and 51.95 (13 and 18 pixels in + the disassembly) not looked at. - The view: syscalls 64.77, the read's first byte landing over the - buffer's dots; the gallery's view re-windowing at a state's first frame; - sqlite 55.83 (15 pixels) not looked at. -- The drawing: fib 33.63, the calls tree's badge corner; the heap's runs - (its 16 CROWDs too: the calls and returns it does not narrate); sqlite - 42.47, the system calls' log scrolling a line up from rest by whole - pixels (1 every other frame at first); list's 13.12, 40.82, 67.65 and - 68.85 (120 to 277 pixels) not looked at. -- AIR: sort's and zoom's last picture (the last caption read, then held); - sqlite 46.02, where the chart misses the read frame on one byte (`0d`) - at 47.5 s; the gallery's atoms page, 3 s by design; the title's card, - held by design. + buffer's dots; the gallery's 9.00, 12.62 and 15.40, the nodes' dump + re-windowing by a row at a step's first frame (9.00 looked at); sqlite + 55.83 (15 pixels) not looked at. Sqlite's 42.47 (the system calls' + log's first whole-pixel step) is gone. +- The drawing: fib 33.80, the calls tree's badge corner; the heap's eight + in its runs (its 17 CROWDs too: the calls and returns it does not + narrate); list's 13.12, 41.02, 68.05 and 69.25 (120 to 281 pixels) and + sort's 6.73 (18 pixels) not looked at. +- AIR: sort's, zoom's and sqlite's last pictures (the last caption read, + then held), sqlite 46.02 too, where the chart misses the read frame on + one byte (`0d`) at 47.5 s; the gallery's atoms page, 3 s by design; the + title's card, held by design. - CROWD: the advance (thread, plaques and rip as one mark, the source and the disassembly scrolling with it), the veil over three panels at a - run's first step; sort's `surface` and `dive`, every panel at once by - design. + run's first step; zoom's two the camera coming back; sort's `surface` + and `dive`, every panel at once by design. ## What is not done -- The graph's truth: what it shows is the run's by the moment shown (each - block's visits and `seen` paper, each edge's count and ink, the trail, - a loop's turns: `countBy` counts to the moment), and a fold of blocks no - longer says `never reached` but `not reached`. What is still the whole - recording's: where each block is placed (`place`, by the whole run's - edge counts: the hot path straight down, so the picture does not move as - the counts grow) and which blocks fold (the runs it never reached): both - say something of the future to one who reads the layout. Left for the - designer's revision of the graph. -- The graph (`graph`): the map draws the disassembly as its graph only - where the scene asks (`Context.Options.graph`: sort); the catalogue has - it whenever the recording has the function's blocks. Not built for the - rest: the descent on the map (graphs stacked, the caller folded to its - call), a list scene that opens on the map and dives out of a graph, a - 2 510-block `sqlite3VdbeExec`. `spread` and `gather` are not built: in a - `surface` and a `dive` the working rows and the lens fade on their way - (`context.Zoom.shows`) instead of gliding into their blocks. A finished - loop is not folded; a fold is not named (`multi-threaded: a cancellable - call`) since no scene names one; an indirect jump's taken targets do not - become edges. The pan is by whole layers to the largest loop the pc's - block is in that fits: sort's ten layers do not fit the lens (its outer - loop is 284 of 270), so the lens pans three times a trip round the outer - loop (24 f, `glide`). A function change (the pc going into another - function with blocks) is not crossfaded: the graph changes in a frame, - and sort ends at its `ret` for that. A count struck as the mark lands - cools to nothing by the step's end (no held corner: the steps after do - not keep it); at a walked step across several blocks the counts, the - gold and the trail crossfade with the advance, nothing struck. On the - map a `leave`'s plaque fades out of its row (6 f) as the mark sets off - from the block's port, and in at the landing; it does not slide along - the rows to the port. The pc's block widens no further than the right - channel: a block in the last column has no annotation room. A - `syscall`'s or call's arguments hang only as far as the block's last row. +- The graph: the map draws the `blocks` drawing only where the scene asks + (`Context.Options.graph`: sort); the catalogue has it whenever the + recording has the function's blocks. Not built: the descent on the map + (the callee's drawing under its caller's), a list scene whose lens is + reverse's ring (the list's subject is its nodes; reverse's ring is + built and unit-tested, not drawn in a scene or the gallery), a 2 510-block + `sqlite3VdbeExec` (folded from the start to its reached blocks). At a + run the mark goes pill to pill along the edge only where a step + crosses one edge: sort's run steps by line, three edges a step, and + keeps the 8 f crossfade of the counts, the gold and the trail. In an + `unfold` the edges crossfade between the two layouts rather than ride + with the pills, and where the opened layout is wider than the pane the + drawing shifts sideways just enough (65 units in the gallery's). + `rings`' general cases beyond sort's two nested loops (a second loop in + one parent, a second loop at the top level, a way between the blocks + before and after a loop, a way out from a pill not at 9 or 3 o'clock) + are drawn but not kept clear of the rings (`shortcut:` in `graph.zig`). + Sort's angles are computed, not the mock's hand-placed ones (`+84` at + 256°, the mock's `+1e` at 225°; `+c5` at about 116°, the mock's `+5f` at + 75°); the header's way out leaves 30 in from its pill's end (the mock + draws 12); pills keep room for `×99`, 12 wider than the mock's; libc's + `open` in `layers` puts a taken target right, as the rule says (`+f0` in + the right column; the mock placed by the run's path). The map's frames + draw slower than before (about 0.35 s against 0.15 s: the 69 linear + rows the map now draws beside the drawing, not the graph's own code). + A finished loop is not folded; an indirect jump's taken targets do not + become edges; a function change is not crossfaded (sort ends at its + `ret` for that). - Sort's recording is the instrumented build: eleven blocks (`setg`, a - `test`/`jne`, two blocks of a lone `jmp`), not mock 22's eight; its - prologue (25 rows, the instrumentation's calls) folds on the map to four, - `more`, four, and the map pans to the outer loop. Mock 22's exit sits in - the second column; here it is under its fall-through's block, as the - catalogue's rule has it, and its edge runs in the right channel. + `test`/`jne`, two blocks of a lone `jmp`), as the mock now has them; its + prologue's calls are the tracer's (`__zt_var`), left out of `+0`'s pill. - The descent: the kernel's three rows are kept at the floor from the `syscall` to the stop after it, so the rows under the call move up again @@ -443,23 +449,33 @@ looked at this pass say so): conditional jump's annotation (`taken · reads zf sf`) is not cut by its room: with a library's 12-digit addresses it runs under the strip by a few characters (syscalls' hurried run through `open`, sort's view). -- A far jump in one file (the source's window farther than its own - height) takes 48 f: the window glides on the strip for the first 24, - then the pane fades out and in. A far jump of the disassembly alone (no - source window far) fades through over the advance with its window - gliding on the strip over the same frames. A file change (another - source) fades the panel and its strip through over 24 f; at a run over - the run's 8 f advance (syscalls' hurry through open64.c and - sysdep-cancel.h flips the file several times, each a fade). The far - jumps seen in the finals are sqlite's, in its 262 899-line sqlite3.c, - whose strip (the map's source panel, round the line the pc goes to) - cannot hold both places: at a continue the strip goes over to the new - place as the continue sets off (a 6 f fade, the gold lit there at once) - and shows no window until the pane's lands there, about 2 s later; the - step back from `pwrite64` (43.3 s) plays on the crossing's plan, whose - travel is shorter, so the pane fades through in about 6 f, before the - strip (6 to 11 f behind) shows it. The tag's note names the new lines - over the 12 f before the advance, before the pane shows them. +- A far jump in one file to lines the map's column also holds, at a walk, + is `unroll`, the window's travel and `roll` (96 f), built and seen in + frames, but no final shows one: heap's (line 15 to 30, 75.7 s) comes in a + hurry, a sentence said faster, where it fades through as at a run, and + sqlite's step back from `pwrite64` goes 44 lines in a column the map + packs at 38 (`inColumn` reads the map's own column). At a run, and out of + the column, the window glides on the strip for the advance's first half, + then the pane fades out and in (48 f); the catalogue's 24 f glide, then + 12 f out and 12 in, is that at a walk's 48 f, but a run's step is 18 f + and the fade has its share of it. A far jump of the disassembly alone + fades through over the advance, its strip going over as the advance + starts. A file change (another source) fades the panel and its strip + through over 24 f; at a run over the run's 8 f advance. A jump out of + the column at a walk is still not told on the map (`surface`, the jump, + `dive`): sqlite's continues fade through, the strips first. Its strips + now keep their windows through a continue, go over as its advance + starts (6 to 11 f behind it, a 6 f crossfade), about 20 f before the + pane's fade, and the tag's line range changes with the pane; the step + back from `pwrite64` advances over 48 f (the scene's plan; the + crossing's own travel is 12 f). +- The stack's window does not keep the touched word in its middle half + until a step touches outside it (the catalogue's hysteresis): it is + still centred on the word the last three steps touched, wherever the + frame is longer than the window (with 12 to 20 slots, few are). +- A quiet register is folded by the scene's clock's steps: a scene that + walks finer than its clock (sort, by blocks, its clock by line over + calls) could change one unmarked; none of the scenes does. - The heap scene never stops inside malloc or free (they are run through, by the PLT, at a line a stop): there is no frame of theirs to name, and no line column of theirs to show. Their lines are in the diff --git a/anim/scenes/fib.zig b/anim/scenes/fib.zig index 7e5380c..5f958dd 100644 --- a/anim/scenes/fib.zig +++ b/anim/scenes/fib.zig @@ -27,7 +27,7 @@ fn frame(s: *anim.Frame) void { const split = canim.layout.split.subject; // From main's line, about to call fib(5), to where fib(5) has returned to it. var at = canim.cursor(s, rec, rec.lineMoment(10, rec.call("main", 0).enter)); - at.levels = .{ .idea = .calls, .source_rows = 10 }; + at.levels = .{ .idea = .calls, .source_rows = 8 }; at.journey(.line, call(rec, 0).exit.?); const ctx = canim.context(s, at, .{ .split = split }); // The lens: every call of fib as a tree, beside the frames they are on the stack. diff --git a/anim/scenes/gallery.zig b/anim/scenes/gallery.zig index f8964bd..17d38ed 100644 --- a/anim/scenes/gallery.zig +++ b/anim/scenes/gallery.zig @@ -10,11 +10,11 @@ //! 3.6 s a step, mid-way: struck, read, projection, echo (mock 10) //! 6 s `subject` (mock 11); 8 s `none`, with the backtrace //! 10.8 s two loupes in depth, from rax and its node's `next` (mock 21) -//! 21 s the `blocks` lens: at rest (blocks reached and not yet, the trail, -//! an edge never taken), `leave` mid-way, `turn` landing, folds -//! 24 s the graph with its rows, as the map draws it (here at half size): -//! sort's (panned to its loop, the pc's block annotated) and libc's -//! `open` at its syscall (the blocks not reached folded) +//! 21 s the `blocks` lens in its two forms: sort in rings at rest (blocks +//! reached and not yet, the trail, the turns), `leave` round the +//! ring mid-way, `turn` just struck; libc's `open` in layers, folded +//! 24 s a first time: `reach` (sort's first swap) landing, `unfold` (open +//! past its syscall) making room; sort in layers; the unfold at rest const std = @import("std"); const sk = @import("sketch"); const anim = @import("anim"); @@ -317,33 +317,23 @@ const GraphPages = struct { pub fn draw(_: *const GraphPages, f: *sk.Frame, at: anim.Placed) void { const u: ui.Ui = .{ .f = f, .at = at }; + const spots = [_][2]f32{ .{ 64, 72 }, .{ 976, 72 }, .{ 64, 488 }, .{ 976, 488 } }; if (at.t >= 21 and at.t < 24) { - title(u, 64, 40, "graph: the blocks lens"); - for ([_][2]f32{ .{ 64, 72 }, .{ 976, 72 }, .{ 64, 488 }, .{ 976, 488 } }, [_][]const u8{ "at rest: reached, not yet, the trail, not taken so far", "leave: the edge drawn gold, the mark on it", "turn: landed, the lane's count and the header's struck", "folds: libc's open, the blocks not reached" }) |p, words| note(u, p[0], p[1], words); + title(u, 64, 40, "graph: the blocks lens, its two forms"); + for (spots, [_][]const u8{ "rings: sort at rest, reached and not yet, the trail, the turns", "leave: the edge drawn gold, the mark round the ring", "turn: landed, the ring's count struck", "layers: libc's open at its syscall, what it has not reached folded" }) |p, words| note(u, p[0], p[1], words); } else if (at.t >= 24 and at.t < 27) { - title(u, 64, 40, "graph: with its rows, as on the map (half size)"); + title(u, 64, 40, "graph: a first time, reach and unfold"); + for (spots, [_][]const u8{ "reach: the first swap, its pill filling as the mark lands", "unfold: open past its syscall, the way back from the kernel opening", "layers: sort, panned to the pc", "unfold, at rest: the fold open, the pane panned" }) |p, words| note(u, p[0], p[1], words); } } }; -/// A component drawn at half its size (the map's rows as the map shows them filling a 1080p frame). -fn Half(comptime T: type) type { - return struct { - inner: T, - box: canim.Rect = .{ .x = 0, .y = 0, .w = 1920, .h = 1080 }, - - pub fn draw(h: *const @This(), f: *sk.Frame, at: anim.Placed) void { - var p = at; - p.xf = p.xf.mul(.scale(0.5, 0.5)); - p.scale *= 0.5; - h.inner.draw(f, p); - } - }; -} - -/// The graph pages: sort's blocks in the lens, at rest and in `leave` and -/// `turn`, and libc's `open` folded; then the map's form of both. -fn graphPages(s: *anim.Frame, at_time: f32) [3]anim.Obj { +/// The graph pages, each four panes of the `blocks` lens (880 by 344): at +/// 21 s sort in rings at rest, a `leave` round the ring mid-way, a `turn` +/// just landed, libc's `open` in layers, folded; at 24 s a `reach` (the +/// first swap) and an `unfold` (open past its syscall) caught in their +/// moves, sort in layers, and the unfold at rest. +fn graphPages(s: *anim.Frame) [9]anim.Obj { const graph = canim.graph; const sort = canim.open(recordings.gallery_sort); const hello = canim.open(recordings.gallery_hello); @@ -363,47 +353,64 @@ fn graphPages(s: *anim.Frame, at_time: f32) [3]anim.Obj { break; }; const place = struct { - fn stage(s_: *anim.Frame, band: canim.Rect, disasm: canim.Rect) *canim.Stage { + fn stage(s_: *anim.Frame, band: canim.Rect) *canim.Stage { var split = canim.layout.split.blocks; split.band = band; - split.disasm = disasm; return canim.Stage.init(s_, split); } }.stage; - const nowhere: canim.Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }; + const at = [_]canim.Rect{ .{ .x = 64, .y = 84, .w = 880, .h = 344 }, .{ .x = 976, .y = 84, .w = 880, .h = 344 }, .{ .x = 64, .y = 500, .w = 880, .h = 344 }, .{ .x = 976, .y = 500, .w = 880, .h = 344 } }; const rest = canim.cursor(s, sort, start); - const leaving = canim.cursor(s, sort, jne); + // The scene's first leave: the inner test's `jle` not taken, round the ring's top to the compare. + const leaving = canim.cursor(s, sort, graph.blockEnd(sort, start)); const turning = canim.cursor(s, sort, back); const open_at = canim.cursor(s, hello, syscall_at); - const lenses = .{ - canim.add(s, graph.Blocks{ .cursor = rest, .stage = place(s, .{ .x = 64, .y = 84, .w = 880, .h = 296 }, nowhere) }), - canim.add(s, graph.Blocks{ .cursor = leaving, .stage = place(s, .{ .x = 976, .y = 84, .w = 880, .h = 296 }, nowhere) }), - canim.add(s, graph.Blocks{ .cursor = turning, .stage = place(s, .{ .x = 64, .y = 500, .w = 880, .h = 296 }, nowhere) }), - canim.add(s, graph.Blocks{ .cursor = open_at, .stage = place(s, .{ .x = 976, .y = 500, .w = 880, .h = 296 }, nowhere) }), + const reaching = canim.cursor(s, sort, jne); + // Open from its syscall: the fold of the way back from the kernel opens as the run gets there. + const unfolding = canim.cursor(s, hello, syscall_at); + const unfolded = canim.cursor(s, hello, syscall_at); + const first = .{ + canim.add(s, graph.Blocks{ .cursor = rest, .stage = place(s, at[0]) }), + canim.add(s, graph.Blocks{ .cursor = leaving, .stage = place(s, at[1]) }), + canim.add(s, graph.Blocks{ .cursor = turning, .stage = place(s, at[2]) }), + canim.add(s, graph.Blocks{ .cursor = open_at, .stage = place(s, at[3]) }), + }; + const second = .{ + canim.add(s, graph.Blocks{ .cursor = reaching, .stage = place(s, at[0]) }), + canim.add(s, graph.Blocks{ .cursor = unfolding, .stage = place(s, at[1]) }), + canim.add(s, graph.Blocks{ .cursor = rest, .stage = place(s, at[2]), .form = .layers }), + canim.add(s, graph.Blocks{ .cursor = unfolded, .stage = place(s, at[3]) }), }; - // Each step played so that the page shows it at `at_time`: the leave with its mark mid-way, the turn just landed. + // Each step played so that its page shows it mid-move: the leave with its + // mark half-way, the turn just struck; the reach landed and filling, the + // unfold making room. const l = canim.theme.time.leave; - s.cursor = at_time - l.sets_off - l.mark / 2.0 - 0.05; + s.cursor = 0; + unfolding.jump(s, graph.blockEnd(hello, syscall_at)); + unfolded.jump(s, graph.blockEnd(hello, syscall_at)); + s.cursor = 21.8 - l.sets_off - 0.11; graph.leave(leaving, s); - s.cursor = at_time - l.sets_off - 0.30 - l.count; + s.cursor = 21.8 - l.sets_off - 0.22 - 0.12; graph.leave(turning, s); - // The map's form, at half size: the map's units, two columns wide each. - const maps = .{ - canim.add(s, Half(graph.Map){ .inner = .{ .cursor = canim.cursor(s, sort, jne), .stage = place(s, nowhere, .{ .x = 128, .y = 176, .w = 1792, .h = 1688 }) } }), - canim.add(s, Half(graph.Map){ .inner = .{ .cursor = canim.cursor(s, hello, syscall_at), .stage = place(s, nowhere, .{ .x = 1952, .y = 176, .w = 1792, .h = 1688 }) } }), - }; + s.cursor = 25.5 - l.sets_off - 0.24 - 0.10; + graph.leave(reaching, s); + s.cursor = 25.5 - l.sets_off - 0.18; + graph.leave(unfolding, s); + s.cursor = 23; + graph.leave(unfolded, s); const pages = canim.add(s, GraphPages{}); - var all: [lenses.len]anim.Animation = undefined; - inline for (lenses, 0..) |o, i| all[i] = o.fadeIn(); + var all: [first.len]anim.Animation = undefined; s.cursor = 21; s.play(.{pages.fadeIn()}, .{ .seconds = 0 }); + inline for (first, 0..) |o, i| all[i] = o.fadeIn(); s.play(all, .{ .seconds = 0 }); s.cursor = 24; - inline for (lenses, 0..) |o, i| all[i] = o.fadeOut(); + inline for (first, 0..) |o, i| all[i] = o.fadeOut(); + s.play(all, .{ .seconds = 0 }); + inline for (second, 0..) |o, i| all[i] = o.fadeIn(); s.play(all, .{ .seconds = 0 }); - s.play(.{ maps[0].fadeIn(), maps[1].fadeIn() }, .{ .seconds = 0 }); s.cursor = 27; - return .{ pages, maps[0], maps[1] }; + return .{ pages, first[0], first[1], first[2], first[3], second[0], second[1], second[2], second[3] }; } fn frame(s: *anim.Frame) void { @@ -414,7 +421,9 @@ fn frame(s: *anim.Frame) void { const pages = canim.add(s, Pages{ .rec = rec, .moment = rest }); s.play(.{pages.fadeIn()}, .{ .seconds = 0 }); - const at = canim.cursor(s, rec, rest); + var at = canim.cursor(s, rec, rest); + // Its way, the one step it takes: the registers that step does not change are folded. + at.journey(.line, rec.next(.line, rest)); const ctx = canim.context(s, at, .{ .split = canim.layout.split.beside, .quiet = true }); const list = canim.nodes(s, .{ .cursor = at, .stage = ctx.stage, .root = "head", .track = &.{ "prev", "cur", "next" }, .quiet = true }); ctx.map.add(s, canim.Nodes{ .cursor = at, .stage = ctx.map.stage, .root = "head", .track = &.{ "prev", "cur", "next" }, .quiet = true }); @@ -448,5 +457,5 @@ fn frame(s: *anim.Frame) void { // The graph's pages: the context stands aside. inline for (panels, 0..) |o, i| all[i] = o.fadeOut(); s.play(all, .{ .seconds = 0 }); - _ = graphPages(s, 21.8); + _ = graphPages(s); } diff --git a/anim/scenes/heap.zig b/anim/scenes/heap.zig index 1f82766..d42da12 100644 --- a/anim/scenes/heap.zig +++ b/anim/scenes/heap.zig @@ -423,7 +423,7 @@ fn frame(s: *anim.Frame) void { // From main's first line, `push(7)`. var at = canim.cursor(s, rec, rec.lineMoment(24, main.enter)); at.journey(.line, rec.lineMoment(30, main.enter)); - at.levels = .{ .idea = .data, .source_rows = 10 }; + at.levels = .{ .idea = .data, .source_rows = 8 }; const ctx = canim.context(s, at, .{ .split = canim.layout.split.subject }); // `head`, the program's global: where line 13 (`n->next = head;`) reads it, `[rip + X]`. const head_at = globalOf(rec, lineIn(rec, "push", 0, 13)); diff --git a/anim/scenes/list.zig b/anim/scenes/list.zig index 71cdf53..d3d53ed 100644 --- a/anim/scenes/list.zig +++ b/anim/scenes/list.zig @@ -27,7 +27,7 @@ fn frame(s: *anim.Frame) void { // From reverse's first line (the list of three is built) to its last. var at = canim.cursor(s, rec, rec.lineMoment(18, reverse.enter)); // The nodes are the idea; a tag slides and an arrow grows after its strike. - at.levels = .{ .idea = .data, .follow = t.move, .source_rows = 10 }; + at.levels = .{ .idea = .data, .follow = t.move, .source_rows = 8 }; const end = rec.lineMoment(27, reverse.enter); at.journey(.line, end); // The idea is the subject: the lens a size up, the nodes over the bytes they are. diff --git a/anim/scenes/sort.zig b/anim/scenes/sort.zig index 81d55dd..454c3ad 100644 --- a/anim/scenes/sort.zig +++ b/anim/scenes/sort.zig @@ -1,16 +1,19 @@ -//! Insertion sort as its blocks: the graph of `sort` in the band (the -//! `blocks` lens), the disassembly its view over the state column, the -//! source alone in the program column; on the map the same graph with its -//! rows. +//! Insertion sort as its blocks: the graph of `sort` as rings over the +//! program column (the `blocks` lens: the outer loop's ring, the inner's +//! touching it at its header), the source and the disassembly under it, +//! the registers and a stack of twenty beside; on the map the same +//! drawing over the source, the disassembly linear beside it. //! //! How it moves (design/motion.md, "A block left"): it opens where `i` has -//! reached 12, the first value out of order. One trip round the inner -//! loop is walked a block at a time: each block's instructions a cascade -//! onto its last row, then `leave` along the edge that row takes (the -//! compare's chips framed, the edge drawn gold, the mark along it, the -//! target's count struck), and `turn` up the inner loop's lane. The next -//! trip is a run; the long middle is a sprint on the map (`surface`, the -//! gold going block to block, `dive`); the last value's trip is walked +//! reached 12, the first value out of order, the swap's block not reached +//! yet. One trip round the inner loop is walked a block at a time: each block's +//! instructions a cascade onto its last row, then `leave` along the edge +//! that row takes (the compare's chips framed, the edge drawn gold, the +//! mark along it, the target's count struck): the swap's first `reach`, +//! then the inner ring's first `turn`; the disassembly unrolls for a beat, +//! the function whole. The next trip is a run; the long +//! middle a sprint on the map (`surface`, the gold going round the rings +//! and down the linear column, `dive`); the last value's trip is walked //! again, and the way out run. const anim = @import("anim"); const canim = @import("canim"); @@ -29,7 +32,7 @@ fn frame(s: *anim.Frame) void { // The inner loop's test (`j > 0`): where each of its trips begins. const test_pc = rec.register(start, "rip"); var at = canim.cursor(s, rec, start); - at.levels = .{ .fire = .disasm, .source_rows = 20 }; + at.levels = .{ .fire = .disasm, .source_rows = 6 }; const last = rec.call("swap", 9); // The last value's trip: from its test, before the compare that leads to the last swap. var last_trip = last.enter; @@ -48,13 +51,19 @@ fn frame(s: *anim.Frame) void { }.walk; canim.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, ctx.source, ctx.disasm, blocks, joins }); - says.line(s, "`sort` as its blocks: two loops. `j > 0`, so its `jle`\nis not taken, and the inner loop goes on to its compare."); + says.line(s, "`sort` as its blocks: each loop a ring, the inner touching\nthe outer. `j > 0`, so `jle` goes on to the compare."); block(at, s); - says.line(s, "31 > 12: `setg` leaves 1, and `jne` takes the swap."); + says.line(s, "31 > 12: `setg` leaves 1, and `jne` takes the swap,\nthe first time it is reached."); block(at, s); block(at, s); - says.line(s, "The swap and `j--`; then the inner loop turns,\nback up to `j > 0`."); + says.line(s, "The swap and `j--`; then the inner loop turns,\nback up to `j > 0`: its first turn."); block(at, s); + // The whole function for a beat: the disassembly unrolled, each block's first row ruled with its visits. + says.line(s, "The function whole: each block under a rule, with its visits."); + ctx.map.unroll(s, .disasm); + // Held while the caption is read: rolled back in as its reading time ends. + s.wait(@max(says.read_by - s.cursor - t.unroll.roll - t.unroll.veil, t.unroll.hold)); + ctx.map.roll(s); // Pacing: the next trip at a run; then the long middle on the map, at a sprint. says.line(s, "Once more at a run: 17 > 12, a second swap."); diff --git a/anim/scenes/sqlite.zig b/anim/scenes/sqlite.zig index e19a7be..36630bd 100644 --- a/anim/scenes/sqlite.zig +++ b/anim/scenes/sqlite.zig @@ -103,7 +103,7 @@ fn frame(s: *anim.Frame) void { const start = stopAt(rec, "sqlite3_step+", first); var at = canim.cursor(s, rec, start); - at.levels = .{ .source_rows = 10 }; + at.levels = .{ .source_rows = 8 }; at.journey(.moment, back); // The lens is the subject: the backtrace, eleven rows, over the // program column (where the kernel's side comes later), and over the @@ -213,7 +213,13 @@ fn frame(s: *anim.Frame) void { fade.in(s, kernel); s.wait(t.beat); const crossing = canim.syscalls.Plan.of(write); - at.step(s, back, crossing.step(), crossing.total); + // Back in `unixWrite`, 44 lines up from the call it waited on (more + // than the map's column of sqlite3.c holds round it): the panes fade + // through (24 f each way), the strips going over first. + var coming_back = crossing.step(); + coming_back.travel = 2 * t.move; + coming_back.total += coming_back.travel - t.step; + at.step(s, back, coming_back, coming_back.total); // Each field as the caption reaches it, 2 s apart: the picture is never still longer. says.line(s, "Page 2 as the kernel took it: `0d`, a table's leaf; 3 cells,\nat `0ff7 0fef 0fe6`: each a row at the page's end."); diff --git a/anim/src/context.zig b/anim/src/context.zig index 15ece55..d4bc94d 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -44,7 +44,8 @@ pub const legend = blk: { /// While a `dive` or a `surface` plays (`map.Map`): each working panel's /// box, and the rect it is drawn into instead, on its way between its /// window on the map and its place; its tags, rules and lanes how much shown. -pub const Zoom = struct { box: Rect, to: Rect, chrome: f32, shows: f32 = 1 }; +/// `fold`: how far the registers panel has folded its quiet rows (a dive lands it folded; `Registers.draw`). +pub const Zoom = struct { box: Rect, to: Rect, chrome: f32, shows: f32 = 1, fold: f32 = 1 }; pub var zoomed: [8]?Zoom = @splat(null); /// How much the thread shows: it fades in (12 f) once a dive has landed, never in a frame. pub var thread_shows: f32 = 1; @@ -94,32 +95,82 @@ pub const Registers = struct { /// between any two lines, so that nearly all of them change at every one. quiet: bool = false, focus: bool = false, + /// The registers the scene moves (`movedBy`), a bit each of `Regs.names`: + /// a row each, with its chain; the rest folded three to a row + /// (design/README.md, `registers` `quiet`). All of them on the map. + moves: u32 = every, 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); + var shape = box; + shape.h = std.math.lerp(theme.layout.panelH(@floatFromInt(theme.metric.all_registers.len)), box.h, fold); 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() }; const was: Shown = .{ .regs = (now.before().regs(rec.tid) catch null) orelse is.regs, .moment = now.before() }; - const body = u.panel(box.w, box.h, "registers", .{ .focus = r.focus, .legend = &legend }); + // Taller than its place on its way in: its own page under it. + if (fold < 1) u.fill(.{ .x = 0, .y = m.tag, .w = shape.w, .h = shape.h - m.tag }, theme.color.page); + const body = u.panel(shape.w, shape.h, "registers", .{ .focus = r.focus, .legend = &legend }); // A link leaves from the panel's edge, not through a name. - ties.anchor(u, .registers, .{ .x = 0, .y = 0, .w = box.w, .h = box.h }); - clipBody(u, box); + ties.anchor(u, .registers, .{ .x = 0, .y = 0, .w = shape.w, .h = shape.h }); + clipBody(u, shape); defer u.unclip(); - const shown = @min(rowsOf(box), theme.metric.all_registers.len); - // Overlapping action: of the registers one step wrote, each strikes 2 f after the one above it. - for (theme.metric.all_registers[0..shown], 0..) |name, i| { - const y = body.y + m.pad + @as(f32, @floatFromInt(i)) * m.row; - if (std.mem.eql(u8, name, "rip")) { - r.rip(u, now, y, box.w, is, was); + const q = theme.metric.registers; + 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) 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); + var rows_before: usize = 0; + var quiet_before: usize = 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); + rows_before += 1; continue; } - r.row(u, now, is, was, name, y, box.w); + const y = std.math.lerp(unfolded, top + @as(f32, @floatFromInt(full + quiet_before / q.quiet_per_row)) * m.row, fold); + 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); } - veiled(u, box, now.veil); + r.rip(u, now, std.math.lerp(top + 16 * m.row, top + @as(f32, @floatFromInt(registerRows(r.moves) - 1)) * m.row, fold), shape.w, is, was); + veiled(u, shape, now.veil); + } + + /// A register no step of the scene changes, in its cell from `x` (its + /// name's place); in a dive's fold (`fold` below 1), on its way from + /// its whole row, its chain past the first hop gone over the move's first 24 f. + fn quietRow(r: *const Registers, u: ui.Ui, now: cursors.Now, is: Shown, was: Shown, name: []const u8, x: f32, y: f32, w: f32, fold: f32) void { + const i = index(name) orelse return; + const value = is.regs.named(name) orelse return; + 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 hops = rows.quiet(u.faded(fold), x, y, name, is.moment, value, read_shows); + anchor(u, i, hops, y); + } + + /// Whether `name` carries the system call the step makes, holding + /// `value_was` (the argument): which argument, and how much its frame shows. + fn carrier(r: *const Registers, now: cursors.Now, name: []const u8, value_was: u64) ?struct { k: usize, made: Recording.Syscall, shows: f32 } { + const made = (if (r.syscalls) syscalls.inStep(now) else null) orelse return null; + // A register is framed as carrying the call only while it holds the + // argument in the moment shown: the stop before the call, until the + // call is back. (Set by the wrapper, between the stops, it carried + // it where no stop saw it: the kernel's rows say it.) + for (syscalls.carried(made), 1..) |carried, k| if (std.mem.eql(u8, carried, name) and value_was == made.args[k - 1]) { + const framed = now.time - syscalls.Plan.in(now, made).registers - @as(f32, @floatFromInt(k - 1)) * time.flight.second; + return .{ .k = k, .made = made, .shows = @min(std.math.clamp(framed / time.read.in, 0, 1), now.reading(.cpu, 0)) }; + }; + return null; } fn shownAt(rec: *const Recording, i: u64) ?Shown { @@ -166,23 +217,16 @@ pub const Registers = struct { var note: []const u8 = ""; var note_shows: f32 = 1; const crossing: ?Recording.Syscall = if (r.syscalls) syscalls.inStep(now) else null; - // A register is framed as carrying the call only while it holds the - // argument in the moment shown: the stop before the call, until the - // call is back. (Set by the wrapper, between the stops, it carried - // it where no stop saw it: the kernel's rows say it.) - const carrier: ?usize = if (crossing) |made| for (syscalls.carried(made), 1..) |carried, k| { - if (std.mem.eql(u8, carried, name) and value_was == made.args[k - 1]) break k; - } else null else null; - if (carrier) |k| if (crossing) |made| { - const framed = now.time - syscalls.Plan.in(now, made).registers - @as(f32, @floatFromInt(k - 1)) * time.flight.second; + if (r.carrier(now, name, value_was)) |c| { marks.read = 0; - marks.read_shows = @min(std.math.clamp(framed / time.read.in, 0, 1), now.reading(.cpu, 0)); + marks.read_shows = c.shows; // A descriptor says what it is open on: the `value` class `fd`. - const names = zt.syscalls.names(made.nr); - if (k <= names.len and std.mem.endsWith(u8, names[k - 1], "fd")) note = rec.openOn(u.f.scratch, value_was, made.enter); + const names = zt.syscalls.names(c.made.nr); + if (c.k <= names.len and std.mem.endsWith(u8, names[c.k - 1], "fd")) note = rec.openOn(u.f.scratch, value_was, c.made.enter); // In with its framing, over 12 f, and out with it: never in a frame. + const framed = now.time - syscalls.Plan.in(now, c.made).registers - @as(f32, @floatFromInt(c.k - 1)) * time.flight.second; note_shows = @min(std.math.clamp(framed / time.quick, 0, 1), now.reading(.cpu, 0)); - }; + } if (if (std.mem.eql(u8, name, "rax")) crossing else null) |made| { // rax: what was there, then the result, once the kernel's rows // have said it (the call's number went in at the wrapper). @@ -244,6 +288,44 @@ fn runFade(now: cursors.Now, level: cursors.Level) f32 { return std.math.clamp(now.since(level, 0) / time.run_ease, 0, 1); } +/// Every register of the seventeen, a bit each of `Regs.names`: none folded. +pub const every: u32 = (1 << 17) - 1; + +/// The registers a scene moves (design/README.md, `registers` `quiet`): a +/// bit each of `Regs.names` for those any of its steps (of `by`, from +/// `way[0]` to `way[1]`: the clock's, `Cursor.journey`) changes, net, with +/// rsp, rbp and rip always. Chosen once: no row comes or goes while it +/// plays. A scene with no way of its own folds none. +pub fn movedBy(rec: *const Recording, by: Recording.Stop, way: [2]u64) u32 { + if (way[1] <= way[0]) return every; + var mask: u32 = comptime 1 << index("rsp").? | 1 << index("rbp").? | 1 << index("rip").?; + var k = way[0]; + while (k < @min(way[1], rec.end())) { + const n = @min(rec.next(by, k), way[1]); + mask |= rec.registersChanged(k, n); + k = n; + } + return mask & every; +} + +/// How many of the sixteen keep a row of their own. +fn fullRows(moves: u32) usize { + return @popCount(moves & 0xffff); +} + +/// The registers panel's rows for `moves`: a row each for those the scene +/// moves, the quiet ones three to a row, and rip. +pub fn registerRows(moves: u32) usize { + const full = fullRows(moves); + return full + (16 - full + theme.metric.registers.quiet_per_row - 1) / theme.metric.registers.quiet_per_row + 1; +} + +/// How far a dive has folded the registers panel at `box` (1: in its place, folded). +fn foldOf(box: Rect) f32 { + for (zoomed) |z| if (z) |zz| if (@abs(zz.box.x - box.x) < 0.5 and @abs(zz.box.y - box.y) < 0.5 and @abs(zz.box.h - box.h) < 0.5) return zz.fold; + return 1; +} + /// A register's place in `Regs.names`. pub fn index(name: []const u8) ?usize { for (zt.Regs.names, 0..) |known, i| if (std.mem.eql(u8, known, name)) return i; @@ -385,12 +467,8 @@ pub const Stack = struct { return if (d == 0) "rsp" else if (d > 0) u_.print("rsp+{x}", .{@as(u64, @intCast(d))}) else u_.print("rsp-{x}", .{@as(u64, @intCast(-d))}); } }.of; - const words = switch (slots) { - 4 => "four", - 6 => "six", - 8 => "eight", - else => u.print("{d}", .{slots}), - }; + const numbers = [_][]const u8{ "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty" }; + const words = if (slots < numbers.len) numbers[slots] else u.print("{d}", .{slots}); // The first word shown and the last. // The range before memory lands and after: one that changes crossfades (12 f), as a role does. const recast = if (now.resting()) 1 else std.math.clamp(since_memory / time.quick, 0, 1); diff --git a/anim/src/cursor.zig b/anim/src/cursor.zig index 9de02c1..16ccd77 100644 --- a/anim/src/cursor.zig +++ b/anim/src/cursor.zig @@ -142,6 +142,8 @@ pub const Cursor = struct { first: u64, last: u64, of: u32 = 0, + /// The stops the clock counts its way in (`journey`). + by: Recording.Stop = .moment, /// A cursor at rest at moment `start`. pub fn init(s: *anim.Frame, rec: *Recording, start: u64) Cursor { @@ -238,6 +240,7 @@ pub const Cursor = struct { /// what the head's progress line and step counter are measured against. pub fn journey(c: *Cursor, by: Recording.Stop, until: u64) void { c.last = until; + c.by = by; c.of = c.steps(by, c.first, until); } @@ -403,6 +406,8 @@ pub const Cursor = struct { // (the window gliding there, 24 f), then the pane fades through. const fit = c.levels.source_rows; const windows = [2]u32{ rec.shownFirst(fit, a), rec.shownFirst(fit, b) }; + // In the column the map has of the file: `unroll`, the window's travel, `roll` (96 f). + if (@import("source.zig").inColumn(rec, a.src, windows, fit)) return time.unroll.grow + time.unroll.travel + time.unroll.roll; if (@max(windows[0], windows[1]) - @min(windows[0], windows[1]) > fit) return 2 * time.move; if (windows[0] != windows[1]) return time.move; if (wave or jumps(rec, from, to)) return 2 * time.current_jump; diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig index be3452f..7017453 100644 --- a/anim/src/disasm.zig +++ b/anim/src/disasm.zig @@ -87,7 +87,8 @@ pub const Disasm = struct { const from = listing(u, rec, now.marks[0], room); const to = listing(u, rec, now.marks[1], room); // On the map its box is as long as the instructions the recording has round the pc. - if (ui.mapping and d.measures) map.measure(.disasm, listing(u, rec, now.marks[1], theme.map.disasm_rows).rows.len); + // (Of the moment the pane shows: a continue's destination repacks the map as the pane goes there, not as it sets off.) + if (ui.mapping and d.measures) map.measure(.disasm, listing(u, rec, now.marks[if (going >= 0.5) 1 else 0], theme.map.disasm_rows).rows.len); const pc = [2]u64{ rec.register(now.marks[0], "rip"), rec.register(now.marks[1], "rip") }; // The function's name: one that changes with the advance crossfades over it. @@ -113,17 +114,17 @@ pub const Disasm = struct { var merged: []const Insn = to.rows; var offsets = [2]f32{ 0, 0 }; var fade: f32 = 1; - var faded_through = false; var shown = to; if (pc[0] != pc[1] and going < 1) { if (merge(u, from.rows, to.rows)) |both| { merged = both.rows; offsets = .{ @floatFromInt(both.from), @floatFromInt(both.to) }; } else { - merged = if (going < 0.5) from.rows else to.rows; - shown = if (going < 0.5) from else to; - fade = @abs(2 * going - 1); - faded_through = true; + // On the map, for the strip, the other column as the advance starts: the strip shows where the pane goes first. + const over = if (ui.mapping) going > 0 else going >= 0.5; + merged = if (over) to.rows else from.rows; + shown = if (over) to else from; + fade = if (ui.mapping) 1 else @abs(2 * going - 1); } } const scroll = std.math.lerp(offsets[0], offsets[1], cursors.glide(going)); @@ -244,9 +245,9 @@ pub const Disasm = struct { lit.route(&.{ .{ 38, ya }, .{ c.jump_lane, ya }, .{ c.jump_lane, yb }, .{ 39, yb } }, theme.color.trail[0], .{ .width = theme.stroke.rule, .head = .{ 7, 8 }, .radius = 4 }); } context.veiled(u, box, now.veil); - // A window going to another column (another function) fades through, and its strip with it. - const column_changes = faded_through and (from.rows.len == 0 or to.rows.len == 0 or !(map.inColumn(.disasm, .{ from.rows[0].addr, from.rows[from.rows.len - 1].addr }) and map.inColumn(.disasm, .{ to.rows[0].addr, to.rows[to.rows.len - 1].addr }))); - map.strip(.disasm, if (column_changes) u.faded(map.through(now, now.plan.travel)) else u, box); + // A window going to another column (another function): its strip goes over + // as the advance starts (the strip's drawings are 6 f apart: the column going over is a 6 f crossfade on it, ahead of the pane's fade.) + map.strip(.disasm, u, box); } pub const State = union(enum) { diff --git a/anim/src/graph.zig b/anim/src/graph.zig index fa91adb..7066580 100644 --- a/anim/src/graph.zig +++ b/anim/src/graph.zig @@ -1,24 +1,22 @@ //! `graph` (design/README.md, "graph"): the disassembly's other form, a -//! function as its basic blocks with what the run did on them: how often -//! each was entered, how often each edge was taken, the edges never taken, -//! the last three taken (the trail), the block the pc is in. Execution -//! flows down; the one thing that climbs is a loop's back edge. +//! function as its basic blocks with what the run has done on them by the +//! moment shown, and nothing after: how often each was entered, how often +//! each edge was taken, the last three taken (the trail), the block the pc +//! is in; what the run has not reached yet is quiet until it does. //! //! `read` takes a function's blocks from the recording (`zt.telescope.blocks`) -//! and counts the run over them; `place` lays them out, a pure function of -//! the blocks, their sizes and the counts of the whole recording (so the -//! picture does not move as the counts grow): back edges by a walk from the -//! entry in address order, layers by the longest forward path, in a layer -//! each block under the predecessor that reached it most often (the hot -//! path straight down), then under the one it falls from, a taken target -//! to the right; back edges in their loops' lanes on the left, the -//! outermost farthest out; an edge that would cross a block in the right -//! channel. `layout` does both for a form (the map's rows, the lens's -//! shapes), folding what is too big for its place in the catalogue's -//! order: the runs of blocks the whole recording never reached, then long -//! blocks. `Blocks` draws it as the `blocks` lens, `Map` with its rows on -//! the map, `Rules` its blocks on the linear rows; `leave` (and `turn`) is -//! the step across one edge. +//! and counts the run over them by a moment. `place` lays them out from the +//! code alone (its blocks, their edges, their pills' words), never from the +//! run: in `rings` each loop a ring its blocks sit on, a nested loop a +//! smaller ring outside its parent touching it at its header, what is +//! outside every loop as `layers` lays it; in `layers` the blocks in layers +//! by the longest path, the back edges up lanes on the left. `layout` +//! folds a function too big for its pane: the blocks not reached by the +//! scene's first moment, the code beyond each way the run had not taken, +//! one dashed pill each; a fold opens when the run reaches a block of it, +//! and never closes. `Blocks` draws it (the `blocks` lens, and the map's +//! drawing), `Rules` its blocks on the linear rows; `leave` (and `turn`) is +//! the step across one edge, and a first time is a `reach`, or an `unfold`. const std = @import("std"); const sk = @import("sketch"); const anim = @import("anim"); @@ -32,28 +30,29 @@ const disasm = @import("disasm.zig"); const Stage = @import("stage.zig").Stage; const theme = ui.theme; const time = theme.time; +const gm = theme.metric.graph; const t = theme.color.text; +const pi: f32 = std.math.pi; pub const End = zt.Debugger.End; -/// A block, or a fold of blocks never reached, and where it is drawn. +/// A block, or a fold of blocks not reached yet, and where its pill is. pub const Node = struct { start: u64, len: u64, end: End, /// Where a tail call or a call that does not return goes (null: none, or not known). out: ?u64 = null, - /// Its instructions (a fold's: of all its blocks). - rows: u32 = 0, - /// The rows drawn: a long block folded to its first four, `more` and its last four. - shown: u32 = 0, - /// How many blocks the whole recording never reached are folded into it (0: a block of its own). + /// The functions it calls that come back, the program's (not the tracer's): the first two, and whether there are more. + calls: [2]u64 = .{ 0, 0 }, + more_calls: bool = false, + /// How many blocks not reached yet are folded into it (0: a block of its own). folded: u32 = 0, - /// Times the run entered it, by the moment the graph is of; and in the whole recording. + /// Times the run entered it, by the moment the graph is of. visits: u32 = 0, - reached: bool = false, layer: u32 = 0, col: u32 = 0, + /// Its pill: its top left and its size. x: f32 = 0, y: f32 = 0, w: f32 = 0, @@ -62,22 +61,45 @@ pub const Node = struct { pub fn contains(n: Node, addr: u64) bool { return addr -% n.start < n.len; } + + fn cx(n: Node) f32 { + return n.x + n.w / 2; + } + + fn cy(n: Node) f32 { + return n.y + n.h / 2; + } + + fn box(n: Node) Box { + return .{ n.x, n.y, n.x + n.w, n.y + n.h }; + } + + /// Whether `p` is inside its pill, its ends half circles. + fn has(n: Node, p: [2]f32) bool { + const r = n.h / 2; + const y = n.y + r; + if (p[0] >= n.x + r and p[0] <= n.x + n.w - r) return @abs(p[1] - y) <= r; + const x = if (p[0] < n.x + r) n.x + r else n.x + n.w - r; + return (p[0] - x) * (p[0] - x) + (p[1] - y) * (p[1] - y) <= r * r; + } }; pub const Kind = enum { fall, taken, jump }; +/// The points an edge's way is sampled at, at most: arcs and quarter circles as short chords. +const most = 96; + pub const Edge = struct { from: u32, to: u32, kind: Kind, - /// Times taken by the moment the graph is of; in the whole recording (what places the blocks). + /// Times taken, by the moment the graph is of. count: u32 = 0, - total: u32 = 0, - /// To a block at its own layer or above: a loop's turn, in lane `lane` (0 the outermost). + /// To a block on the walk's way: a loop's turn (in `layers`, up lane `lane`, 0 the outermost). back: bool = false, lane: u32 = 0, - /// Its way, out of its block's bottom and into its target. - points: [6][2]f32 = undefined, + /// Its way, from its source's frame to its target's: straight runs, arcs and quarter circles, sampled. + points: [most][2]f32 = undefined, n: u8 = 0, pub fn path(e: *const Edge) []const [2]f32 { @@ -87,33 +109,49 @@ pub const Edge = struct { /// Its length along its way. pub fn length(e: *const Edge) f32 { var total: f32 = 0; - for (e.path()[0 .. e.n -| 1], e.path()[@min(1, e.n)..]) |a, b| total += @abs(b[0] - a[0]) + @abs(b[1] - a[1]); + for (e.path()[0 .. e.n -| 1], e.path()[@min(1, e.n)..]) |a, b| total += dist(a, b); return total; } - /// The point `d` units along its way, and which way it goes there. + /// The point `d` units along its way, and which way it goes there (a unit vector). pub fn at(e: *const Edge, d: f32) struct { [2]f32, [2]f32 } { - var left = @max(d, 0); const pts = e.path(); - for (pts[0 .. pts.len - 1], pts[1..]) |a, b| { - const l = @abs(b[0] - a[0]) + @abs(b[1] - a[1]); - const dir = [2]f32{ std.math.sign(b[0] - a[0]), std.math.sign(b[1] - a[1]) }; - if (left <= l or b[0] == pts[pts.len - 1][0] and b[1] == pts[pts.len - 1][1]) { - const f = if (l > 0) @min(left / l, 1) else 1; + if (pts.len < 2) return .{ if (pts.len > 0) pts[0] else .{ 0, 0 }, .{ 0, 1 } }; + var left = @max(d, 0); + var dir: [2]f32 = .{ 0, 1 }; + for (pts[0 .. pts.len - 1], pts[1..], 0..) |a, b, k| { + const l = dist(a, b); + if (l == 0) continue; + dir = .{ (b[0] - a[0]) / l, (b[1] - a[1]) / l }; + if (left <= l or k + 2 == pts.len) { + const f = @min(left / l, 1); return .{ .{ a[0] + (b[0] - a[0]) * f, a[1] + (b[1] - a[1]) * f }, dir }; } left -= l; } - return .{ pts[pts.len - 1], .{ 0, 1 } }; + return .{ pts[pts.len - 1], dir }; + } + + fn set(e: *Edge, p: *const Path) void { + e.n = @intCast(p.n); + @memcpy(e.points[0..p.n], p.pts[0..p.n]); } }; +/// A block of the function and the node it is drawn in (itself, or its fold). +pub const Span = struct { start: u64, len: u64, node: u32 }; + +/// A loop's ring, where it is drawn: its centre, its radius, its header. +pub const Ring = struct { c: [2]f32, r: f32, header: u32 }; + /// A function's graph at a moment. pub const Graph = struct { start: u64, len: u64, nodes: []Node, edges: []Edge, + /// Every block, in address order, and the node it is in. + spans: []Span, /// The node the pc is in. here: ?u32, /// The last three edges taken, newest first. @@ -122,20 +160,22 @@ pub const Graph = struct { text: bool, /// The recording stops at every instruction: the edges' counts and the trail are known. exact: bool, - /// Its size, from its top left (the lanes' side). + /// Its size, from its top left. w: f32 = 0, h: f32 = 0, - /// The right channel's x, and how many lanes the back edges take. + /// `layers`: the right channel's x, and how many lanes the back edges take. channel: f32 = 0, lanes: u32 = 0, /// The blocks the function has, before any fold. blocks: usize = 0, - /// How far apart the columns are. - pitch: f32 = 0, + /// `rings`: each loop's ring. + rings: []Ring = &.{}, + /// Which of the folds of its layout are open (`layout`). + open: u64 = 0, pub fn nodeOf(g: Graph, addr: u64) ?u32 { - for (g.nodes, 0..) |n, i| if (n.contains(addr)) return @intCast(i); - return null; + const k = spanAt(g.spans, addr) orelse return null; + return g.spans[k].node; } pub fn edgeOf(g: Graph, from: u32, to: u32) ?u32 { @@ -151,48 +191,17 @@ pub const Graph = struct { } }; -/// The sizes a form lays its graph out by (design/README.md, `metric.graph`). -pub const Metric = struct { - layer_gap: f32, - block_gap: f32, - /// Columns are at least this far apart. - pitch: f32 = 0, - /// Lanes: the first this far in, then this far apart; the blocks this far right of the last. - lane_in: f32 = 24, - lane: f32, - blocks_in: f32, - /// The first layer, under the graph's top. - top: f32, - /// A port this far in from its block's side; arrivals into one top this far apart. - port: f32, - arrivals: f32, - /// The right channel, right of the widest layer. - channel: f32, - /// A back edge goes down this far before it turns to its lane, and enters its header this far down. - back_down: f32, - head_in: f32 = 12, - /// Edges sharing a gap run this far apart. - track: f32, -}; - -/// The disassembly's rows on the map, and the `blocks` lens's shapes. -pub const Form = enum { map, lens }; - -pub fn metricOf(form: Form) Metric { - const g = theme.metric.graph; - return switch (form) { - .map => .{ .layer_gap = g.layer_gap, .block_gap = g.block_gap, .pitch = theme.metric.insn.annotation - g.shift + g.note + g.block_gap, .lane = g.lane, .blocks_in = g.lane_in, .top = g.top, .port = g.port, .arrivals = g.arrivals, .channel = g.channel, .back_down = g.back_down, .track = 6 }, - .lens => .{ .layer_gap = g.lens.layer_gap, .block_gap = g.block_gap, .pitch = g.lens.pitch, .lane = g.lens.lane, .blocks_in = g.lens.blocks_in, .top = g.lens.top, .port = g.lens.port, .arrivals = g.lens.port, .channel = g.lens.channel, .back_down = g.lens.back_down, .track = 4 }, - }; -} +/// The graph's two forms (a scene names the one it wants): `rings`, each +/// loop a ring (a function with no loop drawn as `layers`); `layers`. +pub const Form = enum { rings, layers }; // ---------------------------------------------------------------- reading /// The graph of the function that holds `pc`, at moment `i`: its blocks /// (padding no edge reaches left out), their edges by how each block ends, -/// and what the run did on them by then (visits, edge counts, the trail) -/// and in the whole recording (what it reached; the counts the layout is -/// by). Unplaced. Null where the recording has no blocks for it. +/// the functions each calls, and what the run did on them by then (visits, +/// edge counts, the trail). Unplaced. Null where the recording has no +/// blocks for it. pub fn read(arena: std.mem.Allocator, rec: *const Recording, i: u64, pc: u64) ?Graph { return readBlocks(arena, rec, i, pc) catch null; } @@ -204,8 +213,8 @@ fn readBlocks(arena: std.mem.Allocator, rec: *const Recording, i: u64, pc: u64) const found = zt.telescope.blocks(m, pc, blocks) orelse return null; var nodes = try arena.alloc(Node, blocks.len); for (blocks, nodes) |b, *n| n.* = .{ .start = b.start, .len = b.len, .end = b.end, .out = if (b.end == .tail or b.end == .noreturn) b.to else null }; - // Every instruction's row, where the text is recorded; a block of - // padding alone (`nop`s between paths) that nothing goes to is none. + // Every instruction, where the text is recorded; a block of padding + // alone (`nop`s between paths) that nothing goes to is none. var reached_by = try arena.alloc(bool, blocks.len); @memset(reached_by, false); for (blocks) |b| for ([2]?u64{ b.to, b.falls }) |to| if (to) |at| if (blockAt(nodes, at)) |k| { @@ -216,19 +225,27 @@ fn readBlocks(arena: std.mem.Allocator, rec: *const Recording, i: u64, pc: u64) for (nodes, 0..) |*n, k| { var at = n.start; var padding = found.text; - while (found.text and at < n.start + n.len) : (n.rows += 1) { + var calls: usize = 0; + while (found.text and at < n.start + n.len) { const one = rec.instruction(i, at, &buf) orelse break; padding = padding and std.mem.startsWith(u8, one.text, "nop"); + // A call that comes back, of the program's: named in its pill (a call is not an edge). + const row: disasm.Insn = .{ .addr = at, .len = one.len, .text = one.text }; + const last = at + one.len >= n.start + n.len; + if (std.mem.eql(u8, row.mnemonic(), "call") and !(last and n.end == .noreturn)) if (disasm.target(row)) |to| if (callee(rec, to) != null) { + if (calls < 2) n.calls[calls] = to else n.more_calls = true; + calls += 1; + }; at += one.len; } - if (!found.text or n.rows == 0) n.rows = @intCast(@max(n.len / 4, 1)); - n.shown = n.rows; if (padding and !reached_by[k] and k > 0) continue; nodes[keep] = n.*; keep += 1; } nodes = nodes[0..keep]; - var g: Graph = .{ .start = found.start, .len = found.len, .nodes = nodes, .edges = &.{}, .here = blockAt(nodes, pc), .text = found.text, .exact = false, .blocks = keep }; + const spans = try arena.alloc(Span, keep); + for (nodes, spans, 0..) |n, *s, k| s.* = .{ .start = n.start, .len = n.len, .node = @intCast(k) }; + var g: Graph = .{ .start = found.start, .len = found.len, .nodes = nodes, .edges = &.{}, .spans = spans, .here = null, .text = found.text, .exact = false, .blocks = keep }; var edges: std.ArrayList(Edge) = .empty; for (blocks) |b| { const from = blockAt(nodes, b.start) orelse continue; @@ -239,9 +256,21 @@ fn readBlocks(arena: std.mem.Allocator, rec: *const Recording, i: u64, pc: u64) g.edges = edges.items; g.exact = stepsEach(rec, g); count(rec, &g, i); + g.here = g.nodeOf(pc); return g; } +/// A callee's name as its caller's pill says it (`swap`); null for one with +/// none, and for the tracer's own (`__zt_var`): the instrumentation's +/// calls are not the program's. +fn callee(rec: *const Recording, addr: u64) ?[]const u8 { + const full = rec.strings.get(addr) orelse return null; + var name = if (std.mem.indexOfScalar(u8, full, '!')) |bang| full[bang + 1 ..] else full; + name = name[0 .. std.mem.lastIndexOfScalar(u8, name, '+') orelse name.len]; + if (name.len == 0 or std.mem.startsWith(u8, name, "__zt_")) return null; + return name; +} + /// Whether the recording stopped at every instruction of the function: /// wherever one stop in it follows another in another block, the first was /// on the jump that went there, or on the last instruction of a block that @@ -267,52 +296,49 @@ fn stepsEach(rec: *const Recording, g: Graph) bool { } /// The function's blocks at moment `i` and how often the run had entered -/// each by then: no rows, no edges. What the linear rows' block rules need. +/// each by then: no edges. What the linear rows' block rules need. pub fn light(arena: std.mem.Allocator, rec: *const Recording, i: u64, pc: u64) ?Graph { const m = rec.moment(i); const probe = zt.telescope.blocks(m, pc, &.{}) orelse return null; const blocks = arena.alloc(zt.telescope.Block, probe.count) catch return null; const found = zt.telescope.blocks(m, pc, blocks) orelse return null; const nodes = arena.alloc(Node, blocks.len) catch return null; - for (blocks, nodes) |b, *n| n.* = .{ .start = b.start, .len = b.len, .end = b.end }; - var g: Graph = .{ .start = found.start, .len = found.len, .nodes = nodes, .edges = &.{}, .here = blockAt(nodes, pc), .text = found.text, .exact = false, .blocks = nodes.len }; + const spans = arena.alloc(Span, blocks.len) catch return null; + for (blocks, nodes, spans, 0..) |b, *n, *s, k| { + n.* = .{ .start = b.start, .len = b.len, .end = b.end }; + s.* = .{ .start = b.start, .len = b.len, .node = @intCast(k) }; + } + var g: Graph = .{ .start = found.start, .len = found.len, .nodes = nodes, .edges = &.{}, .spans = spans, .here = blockAt(nodes, pc), .text = found.text, .exact = false, .blocks = nodes.len }; g.exact = stepsEach(rec, g); count(rec, &g, i); return g; } -/// The run over the graph: each block's visits and each edge's count, by -/// moment `i` and in the whole recording; the blocks it ever reached; the -/// last three edges taken by `i`. A block is entered at its start (by line, -/// whenever a stop is in it after one in another block); an edge is -/// counted where one stop in the function follows another across it (by -/// instruction only: by line the stops between are not known). +/// The run over the graph by moment `i`: each node's visits and each +/// edge's count, the last three edges taken. A block is entered at its +/// start (by line, whenever a stop is in it after one in another block); +/// an edge is counted where one stop in the function follows another +/// across it (by instruction only: by line the stops between are not known). fn count(rec: *const Recording, g: *Graph, i: u64) void { - countBy(rec, g, i, true); -} - -/// `count`; `whole`: the whole recording's too (what it reached, the totals the layout is by). -fn countBy(rec: *const Recording, g: *Graph, i: u64, whole: bool) void { + for (g.nodes) |*n| n.visits = 0; + for (g.edges) |*e| e.count = 0; var prev: ?u32 = null; var prev_pc: u64 = 0; var trail: [3]?u32 = @splat(null); - for (rec.registers, 0..) |regs, k| { - if (!whole and k > i) break; + for (rec.registers[0..@min(i + 1, rec.registers.len)]) |regs| { const pc = regs.rip; if (pc -% g.start >= g.len) continue; - const b = blockAt(g.nodes, pc) orelse continue; - const n = &g.nodes[b]; - if (whole) n.reached = true; + const s = spanAt(g.spans, pc) orelse continue; + const b = g.spans[s].node; // The first stop in it (a recording that begins inside it) is an entry too. - const entered = prev == null or if (g.exact) pc == n.start and prev_pc != pc else prev.? != b; + const entered = prev == null or if (g.exact) pc == g.spans[s].start and prev_pc != pc else prev.? != b; if (entered) { - if (k <= i) n.visits += 1; + g.nodes[b].visits += 1; if (g.exact) if (prev) |p| if (g.edgeOf(p, b)) |e| { - if (whole) g.edges[e].total += 1; - if (k <= i) { - g.edges[e].count += 1; - trail = .{ e, trail[0], trail[1] }; - } + g.edges[e].count += 1; + // Through a copy: the literal is written in place, its first element before the others are read. + const old = trail; + trail = .{ e, old[0], old[1] }; }; } prev = b; @@ -321,7 +347,7 @@ fn countBy(rec: *const Recording, g: *Graph, i: u64, whole: bool) void { g.trail = trail; } -/// The node holding `addr`, in nodes in address order. +/// The node holding `addr`, in nodes that are blocks in address order. fn blockAt(nodes: []const Node, addr: u64) ?u32 { var lo: usize = 0; var hi: usize = nodes.len; @@ -333,232 +359,199 @@ fn blockAt(nodes: []const Node, addr: u64) ?u32 { return @intCast(lo - 1); } -/// The blocks the whole recording never reached, each connected run of them -/// (neighbours in address order joined by an edge) one node (`folded` its -/// blocks, its rows all theirs), the edges to and from them joined. A run -/// that would make a loop the code does not have (an edge into its middle -/// from a block its rest cannot reach again) is split there. -pub fn fold(arena: std.mem.Allocator, g: *Graph) !void { - const n = g.nodes.len; - // Where a run begins: at every unreached block not joined to the one before it. - const begins = try arena.alloc(bool, n); - for (begins, 0..) |*b, k| b.* = g.nodes[k].reached or k == 0 or g.nodes[k - 1].reached or !joined(g.*, @intCast(k - 1), @intCast(k)); - const into = try arena.alloc(u32, n); - var folded: Graph = undefined; - for (0..8) |_| { - folded = try foldRuns(arena, g.*, begins, into); - var buf: [1 << 14]u8 = undefined; - var fba = std.heap.FixedBufferAllocator.init(&buf); - try backEdges(&folded, fba.allocator()); - var split = false; - for (g.edges) |e| { - const a = into[e.from]; - const b = into[e.to]; - if (a == b or begins[e.to] or folded.nodes[b].folded == 0) continue; - const f = folded.edgeOf(a, b) orelse continue; - if (!folded.edges[f].back or reaches(g.*, e.to, e.from)) continue; - begins[e.to] = true; - split = true; - } - if (!split) break; +/// The span holding `addr`. +fn spanAt(spans: []const Span, addr: u64) ?usize { + var lo: usize = 0; + var hi: usize = spans.len; + while (lo < hi) { + const mid = (lo + hi) / 2; + if (spans[mid].start <= addr) lo = mid + 1 else hi = mid; } - g.* = folded; + if (lo == 0 or addr -% spans[lo - 1].start >= spans[lo - 1].len) return null; + return lo - 1; } -/// Whether blocks `a` and `b` have an edge between them, either way. -fn joined(g: Graph, a: u32, b: u32) bool { - for (g.edges) |e| if (e.from == a and e.to == b or e.from == b and e.to == a) return true; - return false; -} +// ---------------------------------------------------------------- folds -/// Whether block `to` can be reached from block `from` along the edges. -fn reaches(g: Graph, from: u32, to: u32) bool { - var buf: [1 << 14]u8 = undefined; - var fba = std.heap.FixedBufferAllocator.init(&buf); - const seen = fba.allocator().alloc(bool, g.nodes.len) catch return true; - @memset(seen, false); +/// The blocks of `g` (its nodes, unfolded and laid out, so with their +/// layers) not reached by the moment its counts are of, folded: the code +/// beyond each way the run has not taken, as far as it leads without +/// crossing into another way's (the deepest way first), each run of two +/// blocks or more; a block alone stays a quiet pill. As spans, address order. +fn notReached(arena: std.mem.Allocator, g: *const Graph) ![]const []const Span { + const n = g.nodes.len; + const quiet = try arena.alloc(bool, n); + for (g.nodes, quiet) |node, *q| q.* = node.visits == 0; + // The ways not taken: a quiet block an edge from a reached one goes to. + const entry = try arena.alloc(bool, n); + @memset(entry, false); + for (g.edges) |e| if (!quiet[e.from] and quiet[e.to]) { + entry[e.to] = true; + }; + var order: std.ArrayList(u32) = .empty; + for (entry, 0..) |is, k| if (is) try order.append(arena, @intCast(k)); + std.mem.sort(u32, order.items, g, struct { + fn deeper(gr: *const Graph, a: u32, b: u32) bool { + const na = gr.nodes[a]; + const nb = gr.nodes[b]; + return if (na.layer != nb.layer) na.layer > nb.layer else na.start > nb.start; + } + }.deeper); + // Then what no way the run had leads to, from its first block. + for (quiet, 0..) |q, k| if (q and !entry[k]) try order.append(arena, @intCast(k)); + const claimed = try arena.alloc(bool, n); + @memset(claimed, false); + var groups: std.ArrayList([]const Span) = .empty; var stack: std.ArrayList(u32) = .empty; - stack.append(fba.allocator(), from) catch return true; - seen[from] = true; - while (stack.pop()) |at| { - if (at == to) return true; - for (g.edges) |e| if (e.from == at and !seen[e.to]) { - seen[e.to] = true; - stack.append(fba.allocator(), e.to) catch return true; - }; + var group: std.ArrayList(u32) = .empty; + for (order.items) |first| { + if (claimed[first]) continue; + group.clearRetainingCapacity(); + claimed[first] = true; + try stack.append(arena, first); + while (stack.pop()) |x| { + try group.append(arena, x); + for (g.edges) |e| if (e.from == x and quiet[e.to] and !claimed[e.to] and !entry[e.to]) { + claimed[e.to] = true; + try stack.append(arena, e.to); + }; + } + if (group.items.len < 2) continue; + std.mem.sort(u32, group.items, {}, std.sort.asc(u32)); + const spans = try arena.alloc(Span, group.items.len); + for (group.items, spans) |k, *s| s.* = .{ .start = g.nodes[k].start, .len = g.nodes[k].len, .node = 0 }; + try groups.append(arena, spans); } - return false; + return groups.items; } -/// `g` with each run of unreached blocks (from a block `begins` to the next) one node; `into` each block's node. -fn foldRuns(arena: std.mem.Allocator, g: Graph, begins: []const bool, into: []u32) !Graph { +/// `g` (unfolded) with each fold of `groups` that `open` does not name one +/// node in the place of its first block (`folded` its blocks), the edges +/// to and from them joined. +fn fold(arena: std.mem.Allocator, g: *Graph, groups: []const []const Span, open: u64) !void { + const n = g.nodes.len; + const group_of = try arena.alloc(?usize, n); + @memset(group_of, null); + for (groups, 0..) |grp, k| if (k >= 64 or open & (@as(u64, 1) << @intCast(k)) == 0) for (grp) |s| if (g.nodeOf(s.start)) |x| { + group_of[x] = k; + }; + const into = try arena.alloc(u32, n); + const first_of = try arena.alloc(?u32, groups.len); + @memset(first_of, null); var nodes: std.ArrayList(Node) = .empty; - for (g.nodes, 0..) |node, k| { - if (begins[k]) { - into[k] = @intCast(nodes.items.len); - var kept = node; - if (!node.reached) kept.folded = 1; - try nodes.append(arena, kept); + for (g.nodes, 0..) |node, x| { + if (group_of[x]) |k| if (first_of[k]) |f| { + into[x] = f; + nodes.items[f].folded += 1; continue; + }; + into[x] = @intCast(nodes.items.len); + var kept = node; + if (group_of[x]) |k| { + first_of[k] = into[x]; + kept = .{ .start = node.start, .len = node.len, .end = .fall, .folded = 1, .layer = node.layer }; } - const f = &nodes.items[nodes.items.len - 1]; - into[k] = @intCast(nodes.items.len - 1); - f.len = node.start + node.len - f.start; - f.rows += node.rows; - f.folded += 1; + try nodes.append(arena, kept); } - for (nodes.items) |*f| if (f.folded > 0) { - f.end = .fall; - f.out = null; - f.shown = 1; - }; var edges: std.ArrayList(Edge) = .empty; for (g.edges) |e| { const a = into[e.from]; const b = into[e.to]; - if (a == b) continue; + if (a == b and group_of[e.from] != null) continue; const dup = for (edges.items) |*d| { if (d.from == a and d.to == b) break d; } else null; if (dup) |d| { - d.count += e.count; - d.total += e.total; + if (e.kind == .fall) d.kind = .fall; continue; } var kept = e; kept.from = a; kept.to = b; - kept.back = false; try edges.append(arena, kept); } - var out = g; - out.nodes = nodes.items; - out.edges = edges.items; - // The trail and the pc's block, renumbered. - for (&out.trail) |*tr| if (tr.*) |e| { - const old = g.edges[e]; - tr.* = out.edgeOf(into[old.from], into[old.to]); - }; - if (g.here) |h| out.here = into[h]; - return out; -} - -/// How far down a graph `room` high is scrolled with the pc in node -/// `here`: not at all where it fits; else the largest loop the pc's block -/// is in that fits, in the middle; else the pc's block in the middle. -pub fn pan(g: Graph, room: f32, m: Metric) f32 { - if (g.h <= room) return 0; - const h = g.here orelse return 0; - const pc = g.nodes[h]; - var top = pc.y - m.layer_gap / 2; - var bottom = pc.y + pc.h + m.layer_gap / 2; - var widest: f32 = 0; - for (g.edges) |e| if (e.back) { - const head = g.nodes[e.to]; - const tail = g.nodes[e.from]; - if (pc.layer < head.layer or pc.layer > tail.layer) continue; - var lb: f32 = 0; - for (g.nodes) |o| if (o.layer >= head.layer and o.layer <= tail.layer) { - lb = @max(lb, o.y + o.h); - }; - const lt = head.y - m.layer_gap / 2; - lb += m.back_down + m.layer_gap / 2; - if (lb - lt <= room and lb - lt > widest) { - widest = lb - lt; - top = lt; - bottom = lb; - } - }; - // Whole layers: the top of the one nearest where that would put the view's top. - const want = std.math.clamp((top + bottom - room) / 2, 0, g.h - room); - var best: f32 = 0; - for (g.nodes) |o| { - const at = std.math.clamp(o.y - m.top, 0, g.h - room); - if (@abs(at - want) < @abs(best - want)) best = at; - } - return best; + const spans = try arena.dupe(Span, g.spans); + for (spans) |*s| s.node = into[s.node]; + g.nodes = nodes.items; + g.edges = edges.items; + g.spans = spans; + if (g.here) |h| g.here = into[h]; } -/// The linear rows' blocks (`disasm`, `descent`): a 2-unit rule across -/// over each block's first row (not its function's), and where the row's -/// annotation leaves it free the times the run had entered the block, -/// ranged right, faint (`×11`), crossfading from the moment the mark -/// leaves to the one it goes to. -pub const Rules = struct { - of: [2]?Graph, - going: f32, - - /// The blocks of the functions that hold `pc[0]` at `marks[0]` and `pc[1]` at `marks[1]`, `going` of the way between. - pub fn init(arena: std.mem.Allocator, rec: *const Recording, marks: [2]u64, pc: [2]u64, going: f32) Rules { - return .{ .of = .{ light(arena, rec, marks[0], pc[0]), light(arena, rec, marks[1], pc[1]) }, .going = going }; +/// Whether the run had entered a block of `grp` by moment `i`. +fn reachedBy(rec: *const Recording, grp: []const Span, i: u64) bool { + var lo: u64 = std.math.maxInt(u64); + var hi: u64 = 0; + for (grp) |s| { + lo = @min(lo, s.start); + hi = @max(hi, s.start + s.len); } - - pub fn draw(r: Rules, u: ui.Ui, addr: u64, y: f32, w: f32, free: bool) void { - var visits: [2]?u32 = .{ null, null }; - for (r.of, &visits) |maybe, *v| if (maybe) |g| if (blockAt(g.nodes, addr)) |k| if (g.nodes[k].start == addr and addr != g.start) { - v.* = g.nodes[k].visits; - }; - if (visits[0] == null and visits[1] == null) return; - // For a strip: a tick at the row's top. - if (ui.strokes) return ui.collectMark(u, 0, y, .tick, 1); - u.fill(.{ .x = theme.stroke.rule, .y = y, .w = w - 2 * theme.stroke.rule, .h = theme.stroke.rule }, theme.color.rule); - if (!free) return; - const size = theme.size.mono.context; - // The count the mark leaves, then the one it goes to; one that does not change, once. - const same = (visits[0] orelse 0) == (visits[1] orelse 0); - for (visits, [2]f32{ 1 - r.going, r.going }, 0..) |v, shows, k| { - const n = v orelse 0; - if (n == 0 or (same and k == 0)) continue; - const text = u.print("\u{00d7}{d}", .{n}); - u.faded(if (same) 1 else shows).text(.mono, size, w - theme.metric.context.side - u.width(.mono, size, text), rows.baseline(y), text, theme.color.text.faint); - } + for (rec.registers[0..@min(i + 1, rec.registers.len)]) |regs| { + if (regs.rip < lo or regs.rip >= hi) continue; + for (grp) |s| if (regs.rip -% s.start < s.len) return true; } -}; + return false; +} // ---------------------------------------------------------------- layout -/// The graph of the pc's function at moment `i`, laid out for `form` in a -/// place `room` high: folded first where it does not fit (the runs never -/// reached, then long blocks: over 16 rows, their first four and last -/// four, unless the pc is in it). Sizes from the form (`sizes`). -/// shortcut: a loop the pc is not in and will not enter again is not folded, and nothing pans: a graph still too tall runs past its place. -pub fn layout(arena: std.mem.Allocator, rec: *const Recording, i: u64, pc: u64, form: Form, room: f32) ?Graph { +/// The graph of the pc's function at moment `i`, laid out in `form` for a +/// pane `room` (its body's width and height) in a scene whose first moment +/// is `ref`: where it does not fit, folded as at `ref` (`notReached`), the +/// folds the run has reached a block of by `i` open. The layout is kept +/// per function, form, room, reference and open folds (`memo`); a frame +/// counts its own moment's visits again. +pub fn layout(arena: std.mem.Allocator, rec: *const Recording, i: u64, pc: u64, form: Form, room: [2]f32, ref: u64) ?Graph { const start = (zt.telescope.blocks(rec.moment(i), pc, &.{}) orelse return null).start; - for (memo) |maybe| if (maybe) |k| if (k.rec == rec and k.start == start and k.form == form and k.room == room) { - const here = blockAt(k.g.nodes, pc); - const spare: ?u32 = if (here) |h| (if (k.g.nodes[h].rows > theme.metric.graph.long) h else null) else null; - if (!k.long or spare == k.spared) return recount(arena, rec, k.g, i, pc) catch null; + const groups = foldsOf(arena, rec, i, pc, start, form, room, ref) orelse return null; + var open: u64 = 0; + for (groups, 0..) |grp, k| if (k < 64 and reachedBy(rec, grp, i)) { + open |= @as(u64, 1) << @intCast(k); + }; + for (memo) |maybe| if (maybe) |k| if (k.rec == rec and k.start == start and k.form == form and k.room[0] == room[0] and k.room[1] == room[1] and k.ref == ref and k.open == open) { + return recount(arena, rec, k.g, i, pc) catch null; }; var g = read(arena, rec, i, pc) orelse return null; - const m = metricOf(form); - sizes(rec, i, &g, form); - place(&g, m); - var long = false; - if (g.h > room) { - fold(arena, &g) catch return null; - sizes(rec, i, &g, form); - place(&g, m); - } - if (g.h > room) { - long = true; - for (g.nodes, 0..) |*n, k| if (n.folded == 0 and n.rows > theme.metric.graph.long and (g.here == null or g.here.? != k)) { - n.shown = 2 * theme.metric.graph.keep + 1; - }; - sizes(rec, i, &g, form); - place(&g, m); - } - remember(.{ .rec = rec, .start = start, .form = form, .room = room, .long = long, .spared = if (g.here) |h| (if (g.nodes[h].rows > theme.metric.graph.long) h else null) else null, .g = g }); + fold(arena, &g, groups, open) catch return null; + sizes(rec, &g); + place(arena, &g, form) catch return null; + g.open = open; + remember(.{ .rec = rec, .start = start, .form = form, .room = room, .ref = ref, .open = open, .g = g }); + count(rec, &g, i); + g.here = g.nodeOf(pc); return g; } -/// What `layout` made, kept: the blocks, their sizes and their places are -/// the function's and the whole recording's, not the moment's (but for a -/// long block the pc is in, which does not fold); a frame counts its own -/// moment's visits again (`recount`). -/// shortcut: process-wide, the last eight kept and never freed (a few KB each); two players at once would only share it. -const Kept = struct { rec: *const Recording, start: u64, form: Form, room: f32, long: bool, spared: ?u32, g: Graph }; -var memo: [8]?Kept = @splat(null); +/// The folds of a function's layout: none where it fits its pane whole. +fn foldsOf(arena: std.mem.Allocator, rec: *const Recording, i: u64, pc: u64, start: u64, form: Form, room: [2]f32, ref: u64) ?[]const []const Span { + for (kept_folds) |maybe| if (maybe) |k| if (k.rec == rec and k.start == start and k.form == form and k.room[0] == room[0] and k.room[1] == room[1] and k.ref == ref) return k.groups; + var g = read(arena, rec, i, pc) orelse return null; + sizes(rec, &g); + place(arena, &g, form) catch return null; + var groups: []const []const Span = &.{}; + if (g.w > room[0] or g.h > room[1]) { + count(rec, &g, ref); + groups = notReached(arena, &g) catch return null; + } + const a = memo_memory.allocator(); + const copy = a.alloc([]const Span, groups.len) catch return null; + for (groups, copy) |grp, *c| c.* = a.dupe(Span, grp) catch return null; + kept_folds[folds_next] = .{ .rec = rec, .start = start, .form = form, .room = room, .ref = ref, .groups = copy }; + folds_next = (folds_next + 1) % kept_folds.len; + if (groups.len == 0) remember(.{ .rec = rec, .start = start, .form = form, .room = room, .ref = ref, .open = 0, .g = g }); + return copy; +} + +/// What `layout` made, kept: the blocks, their pills and their places are +/// the code's, not the moment's; a frame counts its own moment's visits +/// again (`recount`). +/// shortcut: process-wide, the last 32 layouts and 16 sets of folds kept and never freed (tens of KB each); two players at once would only share it. +const Kept = struct { rec: *const Recording, start: u64, form: Form, room: [2]f32, ref: u64, open: u64, g: Graph }; +var memo: [32]?Kept = @splat(null); var memo_next: usize = 0; +const Folds = struct { rec: *const Recording, start: u64, form: Form, room: [2]f32, ref: u64, groups: []const []const Span }; +var kept_folds: [16]?Folds = @splat(null); +var folds_next: usize = 0; var memo_memory: std.heap.ArenaAllocator = .init(std.heap.page_allocator); fn remember(k: Kept) void { @@ -566,6 +559,8 @@ fn remember(k: Kept) void { const a = memo_memory.allocator(); copy.g.nodes = a.dupe(Node, k.g.nodes) catch return; copy.g.edges = a.dupe(Edge, k.g.edges) catch return; + copy.g.spans = a.dupe(Span, k.g.spans) catch return; + copy.g.rings = a.dupe(Ring, k.g.rings) catch return; memo[memo_next] = copy; memo_next = (memo_next + 1) % memo.len; } @@ -575,125 +570,49 @@ fn recount(arena: std.mem.Allocator, rec: *const Recording, kept_g: Graph, i: u6 var g = kept_g; g.nodes = try arena.dupe(Node, kept_g.nodes); g.edges = try arena.dupe(Edge, kept_g.edges); - for (g.nodes) |*n| n.visits = 0; - for (g.edges) |*e| e.count = 0; - g.here = blockAt(g.nodes, pc); - countBy(rec, &g, i, false); + count(rec, &g, i); + g.here = g.nodeOf(pc); return g; } -/// Each node's size in `form`: on the map a head and its rows, as wide as -/// its widest row, 300 at least; in the lens a box 24 high, 10 a row. A -/// fold: a dashed box of a head and a row. -pub fn sizes(rec: *const Recording, i: u64, g: *Graph, form: Form) void { - const gm = theme.metric.graph; - const cm = theme.metric.context; - const adv = theme.size.mono.context * 3 / 5; - var buf: [256]u8 = undefined; - for (g.nodes) |*n| switch (form) { - .lens => { - n.w = @max(gm.lens.least, gm.lens.lead + gm.lens.per_row * @as(f32, @floatFromInt(n.rows))); - n.h = gm.lens.box; - }, - .map => { - if (n.folded > 0) { - n.w = gm.fold_w; - n.h = cm.tag + cm.row + cm.pad; - continue; - } - var widest: usize = 0; - var at = n.start; - while (g.text and at < n.start + n.len) { - const one = rec.instruction(i, at, &buf) orelse break; - widest = @max(widest, operandChars(one.text)); - at += one.len; - } - n.w = @max(gm.least, gm.operands + @as(f32, @floatFromInt(widest)) * adv + 2 * cm.side); - n.h = cm.tag + @as(f32, @floatFromInt(n.shown)) * cm.row + cm.pad; - }, - }; +/// Each node's pill: 24 high, as wide as its words (its offset, the +/// functions it calls) and its visits, with room kept for `×99` so that it +/// never widens as the run counts; a fold as wide as its words, `+5b … · 7`. +pub fn sizes(rec: *const Recording, g: *Graph) void { + const adv = ui.advance(theme.size.mono.context); + for (g.nodes) |*n| { + const chars: f32 = @floatFromInt(if (n.folded > 0) foldChars(g.*, n.*) else wordsLen(rec, g.*, n.*) + 1 + gm.count_chars); + n.w = 2 * gm.pill_in + chars * adv + gm.spare; + n.h = gm.pill; + } } -/// How many characters an instruction's operands take as `insn` draws them: -/// the size words gone, a jump's or call's target its digits, byte cells a few more. -fn operandChars(text: []const u8) usize { - const space = std.mem.indexOfScalar(u8, text, ' ') orelse return 0; - var ops = std.mem.trim(u8, text[space..], " "); - // A prefix (`rep stosq`, `notrack jmp`): the mnemonic is the next word. - for ([_][]const u8{ "rep", "repe", "repz", "repne", "repnz", "lock", "notrack", "bnd" }) |p| if (std.mem.eql(u8, text[0..space], p)) { - ops = std.mem.trim(u8, ops[std.mem.indexOfScalar(u8, ops, ' ') orelse ops.len ..], " "); - }; - var n = ops.len; - var rest = ops; - while (std.mem.indexOf(u8, rest, " ptr ")) |p| { - var word = p; - while (word > 0 and rest[word - 1] != ' ' and rest[word - 1] != ',') word -= 1; - // The word and " ptr " go; the width's cells come. - n = n - (p - word + 5) + 5; - rest = rest[p + 5 ..]; - } - return n; +/// The characters of a fold's words, `+5b … · 7`. +fn foldChars(g: Graph, n: Node) usize { + return std.fmt.count("+{x}", .{n.start - g.start}) + 5 + std.fmt.count("{d}", .{n.folded}); } -/// Lays `g` out (its nodes' `w` and `h` given): layers, columns, every -/// edge's way. Pure: the same blocks, sizes and whole-recording counts -/// give the same picture at every moment. -pub fn place(g: *Graph, m: Metric) void { - const nodes = g.nodes; - if (nodes.len == 0) return; - var buf: [1 << 16]u8 = undefined; - var fba = std.heap.FixedBufferAllocator.init(&buf); - const tmp = fba.allocator(); - backEdges(g, tmp) catch return; - layers(g, tmp) catch return; - columns(g, tmp) catch return; - // Lanes: the outermost loop (the longest span) farthest out. - var order: [64]u32 = undefined; - var nb: u32 = 0; - for (g.edges, 0..) |e, k| if (e.back and nb < order.len) { - order[nb] = @intCast(k); - nb += 1; +/// The characters of a block's words: its offset, then each callee after a space (two, then `…`). +fn wordsLen(rec: *const Recording, g: Graph, n: Node) usize { + var len = std.fmt.count("+{x}", .{n.start - g.start}); + for (n.calls) |c| if (c != 0) { + len += 1 + if (callee(rec, c)) |name| name.len else 0; }; - std.mem.sort(u32, order[0..nb], g, struct { - fn wider(gr: *Graph, a: u32, b: u32) bool { - const ea = gr.edges[a]; - const eb = gr.edges[b]; - const sa = gr.nodes[ea.from].layer - gr.nodes[ea.to].layer; - const sb = gr.nodes[eb.from].layer - gr.nodes[eb.to].layer; - return if (sa != sb) sa > sb else ea.to < eb.to; - } - }.wider); - for (order[0..nb], 0..) |e, k| g.edges[e].lane = @intCast(k); - g.lanes = nb; - // Columns a pitch apart, right of the lanes; layers a gap apart. - var widest: f32 = 0; - var last_layer: u32 = 0; - for (nodes) |n| { - widest = @max(widest, n.w); - last_layer = @max(last_layer, n.layer); - } - const pitch = @max(m.pitch, widest + m.block_gap); - g.pitch = pitch; - const x0 = m.lane_in + @as(f32, @floatFromInt(nb)) * m.lane + m.blocks_in; - const tops = tmp.alloc(f32, last_layer + 2) catch return; - const heights = tmp.alloc(f32, last_layer + 1) catch return; - @memset(heights, 0); - for (nodes) |n| heights[n.layer] = @max(heights[n.layer], n.h); - tops[0] = m.top; - for (heights, 0..) |h, k| tops[k + 1] = tops[k] + h + m.layer_gap; - var right: f32 = 0; - var bottom: f32 = 0; - for (nodes) |*n| { - n.x = x0 + @as(f32, @floatFromInt(n.col)) * pitch; - n.y = tops[n.layer]; - right = @max(right, n.x + n.w); - bottom = @max(bottom, n.y + n.h); - } - g.channel = right + m.channel; - route(g, m, tops, heights, tmp) catch return; - g.w = g.channel + m.lane_in; - // Under the last layer the way out: a stub and a bar. - g.h = bottom + m.layer_gap; + if (n.more_calls) len += 2; + return len; +} + +/// Lays `g` out (its pills' sizes given) in `form`: where every pill is and +/// every edge's way. Pure: the code alone (its blocks, its edges, its +/// pills), never the run, so the picture is the same at every moment. +pub fn place(arena: std.mem.Allocator, g: *Graph, form: Form) std.mem.Allocator.Error!void { + if (g.nodes.len == 0) return; + for (g.edges) |*e| e.back = false; + try backEdges(g, arena); + try layers(g, arena); + g.rings = &.{}; + if (form == .rings and try placeRings(arena, g)) return; + try placeLayers(arena, g); } /// Back edges: those a walk from the entry (then from each block not yet @@ -772,16 +691,15 @@ fn layers(g: *Graph, tmp: std.mem.Allocator) !void { }; } var last: u32 = 0; - for (g.nodes) |node| if (node.end != .ret) { - last = @max(last, node.layer); - }; var any_ret = false; - for (g.nodes) |node| any_ret = any_ret or node.end == .ret; - if (!any_ret) return; var deepest_ret: u32 = 0; - for (g.nodes) |node| if (node.end == .ret) { - deepest_ret = @max(deepest_ret, node.layer); - }; + for (g.nodes) |node| { + if (node.end == .ret) { + any_ret = true; + deepest_ret = @max(deepest_ret, node.layer); + } else last = @max(last, node.layer); + } + if (!any_ret) return; const others_last = for (g.nodes) |node| { if (node.end != .ret and node.layer == @max(last, deepest_ret)) break true; } else false; @@ -791,16 +709,62 @@ fn layers(g: *Graph, tmp: std.mem.Allocator) !void { }; } -/// Columns, a layer at a time: a block under the predecessor that reached -/// it most often in the whole recording; else under the one it falls from; -/// else (a taken target never taken) right of it. Where two want one -/// column the more travelled has it, then the fall-through, then the -/// lower address; the other the next free column to the right. +// ---------------------------------------------------------------- layers + +/// `layers`: a layer at a time, a block under its fall-through predecessor +/// (else the one it is jumped to from), a taken target right of its +/// branch; where two want one column the fall-through has it, then the +/// lower address, the other the next free column to the right. Columns +/// 300 apart, layers 12; the back edges in lanes on the left, the +/// outermost loop farthest out. +fn placeLayers(arena: std.mem.Allocator, g: *Graph) std.mem.Allocator.Error!void { + const nodes = g.nodes; + try columns(g, arena); + var order: std.ArrayList(u32) = .empty; + for (g.edges, 0..) |e, k| if (e.back) try order.append(arena, @intCast(k)); + std.mem.sort(u32, order.items, g, struct { + fn wider(gr: *Graph, a: u32, b: u32) bool { + const ea = gr.edges[a]; + const eb = gr.edges[b]; + const sa = gr.nodes[ea.from].layer -| gr.nodes[ea.to].layer; + const sb = gr.nodes[eb.from].layer -| gr.nodes[eb.to].layer; + return if (sa != sb) sa > sb else ea.to < eb.to; + } + }.wider); + for (order.items, 0..) |e, k| g.edges[e].lane = @intCast(k); + const nb: u32 = @intCast(order.items.len); + g.lanes = nb; + var widest: f32 = 0; + var last_layer: u32 = 0; + for (nodes) |n| { + widest = @max(widest, n.w); + last_layer = @max(last_layer, n.layer); + } + const pitch = @max(gm.pitch, widest + 2 * gm.apart); + const x0: f32 = if (nb > 0) gm.lane_in + @as(f32, @floatFromInt(nb)) * gm.lane + gm.blocks_in else 0; + const tops = try arena.alloc(f32, last_layer + 2); + const heights = try arena.alloc(f32, last_layer + 1); + @memset(heights, 0); + for (nodes) |n| heights[n.layer] = @max(heights[n.layer], n.h); + tops[0] = gm.top; + for (heights, 0..) |h, k| tops[k + 1] = tops[k] + h + gm.layer_gap; + var right: f32 = 0; + for (nodes) |*n| { + n.x = x0 + @as(f32, @floatFromInt(n.col)) * pitch; + n.y = tops[n.layer]; + right = @max(right, n.x + n.w); + } + g.channel = right + gm.channel; + try route(g, tops, heights, arena); + normalize(g); +} + +/// Columns, a layer at a time (`placeLayers`), from the code alone. fn columns(g: *Graph, tmp: std.mem.Allocator) !void { const n = g.nodes.len; var last: u32 = 0; for (g.nodes) |node| last = @max(last, node.layer); - const Want = struct { node: u32, col: u32, total: u32, fall: bool }; + const Want = struct { node: u32, col: u32, fall: bool }; var wants: std.ArrayList(Want) = .empty; var used: std.ArrayList(u32) = .empty; const placed = try tmp.alloc(bool, n); @@ -810,18 +774,20 @@ fn columns(g: *Graph, tmp: std.mem.Allocator) !void { for (g.nodes, 0..) |node, k| if (node.layer == layer) { var best: ?Edge = null; for (g.edges) |e| if (!e.back and e.to == k and placed[e.from]) { - const better = if (best) |b| e.total > b.total or (e.total == b.total and (e.kind == .fall and b.kind != .fall or (e.kind == .fall) == (b.kind == .fall) and g.nodes[e.from].start < g.nodes[b.from].start)) else true; + // The fall-through, then a block's (not a fold's), then the lower address. + const better = if (best) |b| blk: { + if ((e.kind == .fall) != (b.kind == .fall)) break :blk e.kind == .fall; + const own = g.nodes[e.from].folded == 0; + if (own != (g.nodes[b.from].folded == 0)) break :blk own; + break :blk g.nodes[e.from].start < g.nodes[b.from].start; + } else true; if (better) best = e; }; - const col: u32, const total: u32, const fall = if (best) |b| - .{ g.nodes[b.from].col + @intFromBool(b.total == 0 and b.kind != .fall), b.total, b.kind == .fall } - else - .{ 0, 0, false }; - try wants.append(tmp, .{ .node = @intCast(k), .col = col, .total = total, .fall = fall }); + const col: u32, const fall = if (best) |b| .{ g.nodes[b.from].col + @intFromBool(b.kind == .taken), b.kind == .fall } else .{ 0, false }; + try wants.append(tmp, .{ .node = @intCast(k), .col = col, .fall = fall }); }; std.mem.sort(Want, wants.items, g, struct { fn first(gr: *Graph, a: Want, b: Want) bool { - if (a.total != b.total) return a.total > b.total; if (a.fall != b.fall) return a.fall; return gr.nodes[a.node].start < gr.nodes[b.node].start; } @@ -837,13 +803,13 @@ fn columns(g: *Graph, tmp: std.mem.Allocator) !void { } } -/// Every edge's way. Forward: out of the bottom on the side its target is -/// on (`port` in from it, or the middle when it is straight below), along -/// the middle of the gap under its layer, into its target's top (several -/// into one top `arrivals` apart, in their sources' order); through the -/// right channel where it would cross a block. Back: down `back_down`, out -/// to its lane, up it, into its header's head from the left. -fn route(g: *Graph, m: Metric, tops: []const f32, heights: []const f32, tmp: std.mem.Allocator) !void { +/// Every edge's way in `layers`. Forward: out of the foot on the side its +/// target is on (16 in from the end, or the middle when it is straight +/// below), along the middle of the gap under its layer, into its target's +/// top (several into one top 16 apart); through the right channel where it +/// would cross a block. Back: down 8, out to its lane, up it, into its +/// header's end. Every corner a quarter circle of 12. +fn route(g: *Graph, tops: []const f32, heights: []const f32, tmp: std.mem.Allocator) !void { const n = g.nodes.len; const tracks = try tmp.alloc(u32, heights.len); @memset(tracks, 0); @@ -864,13 +830,13 @@ fn route(g: *Graph, m: Metric, tops: []const f32, heights: []const f32, tmp: std const dst = g.nodes[e.to]; const under = tops[src.layer] + heights[src.layer]; if (e.back) { - const lx = m.lane_in + @as(f32, @floatFromInt(e.lane)) * m.lane; - const by = under + m.back_down + @as(f32, @floatFromInt(back_tracks[src.layer])) * 8; + const lx = gm.lane_in + @as(f32, @floatFromInt(e.lane)) * gm.lane; + const by = under + gm.back_down + @as(f32, @floatFromInt(back_tracks[src.layer])) * gm.track; back_tracks[src.layer] += 1; - const sx = src.x + m.port; - const hy = dst.y + m.head_in; - e.points[0..5].* = .{ .{ sx, src.y + src.h }, .{ sx, by }, .{ lx, by }, .{ lx, hy }, .{ dst.x - 1, hy } }; - e.n = 5; + const sx = src.x + gm.port; + const hy = dst.cy(); + const p = rounded(&.{ .{ sx, src.y + src.h }, .{ sx, by }, .{ lx, by }, .{ lx, hy }, .{ dst.x, hy } }, gm.corner); + e.set(&p); continue; } // Its place among the arrivals into its target's top. @@ -881,103 +847,843 @@ fn route(g: *Graph, m: Metric, tops: []const f32, heights: []const f32, tmp: std const os = g.nodes[o.from]; if (os.x < src.x or (os.x == src.x and o.from < e.from)) slot += 1; }; - const tx = dst.x + dst.w / 2 + (@as(f32, @floatFromInt(slot)) - @as(f32, @floatFromInt(srcs - 1)) / 2) * m.arrivals; + const tx = dst.cx() + (@as(f32, @floatFromInt(slot)) - @as(f32, @floatFromInt(srcs - 1)) / 2) * gm.port; const crosses = for (g.nodes) |o| { if (o.layer > src.layer and o.layer < dst.layer and o.x - 8 < tx and tx < o.x + o.w + 8) break true; } else false; - const side = if (crosses) 1 else (dst.x + dst.w / 2) - (src.x + src.w / 2); - const sx = if (!crosses and @abs(side) < src.w / 2 - m.port) src.x + src.w / 2 else if (side > 0) src.x + src.w - m.port else src.x + m.port; - const gy = under + m.layer_gap / 2 + @as(f32, @floatFromInt(tracks[src.layer])) * m.track; + const side = if (crosses) 1 else dst.cx() - src.cx(); + const sx = if (!crosses and @abs(side) < src.w / 2 - gm.port) src.cx() else if (side > 0) src.x + src.w - gm.port else src.x + gm.port; + const gy = under + gm.layer_gap / 2 + @as(f32, @floatFromInt(tracks[src.layer] % 2)) * gm.track; tracks[src.layer] += 1; - if (crosses) { - const gy2 = tops[dst.layer] - m.layer_gap / 2; - e.points = .{ .{ sx, src.y + src.h }, .{ sx, gy }, .{ g.channel, gy }, .{ g.channel, gy2 }, .{ tx, gy2 }, .{ tx, dst.y } }; - e.n = 6; - } else { - e.points[0..4].* = .{ .{ sx, src.y + src.h }, .{ sx, gy }, .{ tx, gy }, .{ tx, dst.y } }; - e.n = 4; + const p = if (crosses) blk: { + const gy2 = tops[dst.layer] - gm.layer_gap / 2; + break :blk rounded(&.{ .{ sx, src.y + src.h }, .{ sx, gy }, .{ g.channel, gy }, .{ g.channel, gy2 }, .{ tx, gy2 }, .{ tx, dst.y } }, gm.corner); + } else rounded(&.{ .{ sx, src.y + src.h }, .{ sx, gy }, .{ tx, gy }, .{ tx, dst.y } }, gm.corner); + e.set(&p); + }; +} + +/// How far down a drawing too tall for its pane (`room` high) is scrolled: +/// by thirds of the pane, so that the pc's pill is in its middle third. +fn pan(g: Graph, room: f32) f32 { + if (g.h <= room) return 0; + const h = g.here orelse return 0; + const third = room / 3; + return std.math.clamp(@floor((g.nodes[h].cy() - third) / third) * third, 0, g.h - room); +} + +// ---------------------------------------------------------------- rings + +/// A loop: its header, its body (the blocks that reach its latches without +/// passing the header, merged by header), the loop it is nested in, and its +/// ring: its members (its blocks not in a loop nested in it, and those +/// loops' headers) clockwise in the order they run, their angles, its +/// radius, its centre. +const Loop = struct { + header: u32, + body: []bool, + size: u32 = 0, + parent: ?usize = null, + members: []u32 = &.{}, + /// Radians, clockwise on the screen from 3 o'clock: the header at π. + angles: []f32 = &.{}, + r: f32 = 0, + /// Its centre from its parent's (a top-level loop's: from its header's), and where it is in the drawing. + c: [2]f32 = .{ 0, 0 }, + abs: [2]f32 = .{ 0, 0 }, +}; + +/// The natural loops of `g` (its back edges known), merged by header, each with its parent and its ring's members. +fn loopsOf(arena: std.mem.Allocator, g: *const Graph) ![]Loop { + var loops: std.ArrayList(Loop) = .empty; + var stack: std.ArrayList(u32) = .empty; + for (g.edges) |e| if (e.back) { + const li = for (loops.items, 0..) |l, i| { + if (l.header == e.to) break i; + } else blk: { + const body = try arena.alloc(bool, g.nodes.len); + @memset(body, false); + body[e.to] = true; + try loops.append(arena, .{ .header = e.to, .body = body }); + break :blk loops.items.len - 1; + }; + const body = loops.items[li].body; + if (!body[e.from]) { + body[e.from] = true; + try stack.append(arena, e.from); + } + while (stack.pop()) |x| for (g.edges) |f| if (f.to == x and !body[f.from]) { + body[f.from] = true; + try stack.append(arena, f.from); + }; + }; + const ls = loops.items; + for (ls) |*l| for (l.body) |b| { + l.size += @intFromBool(b); + }; + for (ls, 0..) |*l, i| { + var best: ?usize = null; + for (ls, 0..) |o, j| if (j != i and o.body[l.header] and o.size > l.size and (best == null or o.size < ls[best.?].size)) { + best = j; + }; + l.parent = best; + } + for (ls, 0..) |*l, i| { + var list: std.ArrayList(u32) = .empty; + try list.append(arena, l.header); + for (l.body, 0..) |in, k| if (in and k != l.header) { + const deeper = for (ls) |o| { + if (o.parent == i and o.body[k] and o.header != k) break true; + } else false; + if (!deeper) try list.append(arena, @intCast(k)); + }; + std.mem.sort(u32, list.items[1..], g, struct { + fn first(gr: *const Graph, a: u32, b: u32) bool { + const na = gr.nodes[a]; + const nb = gr.nodes[b]; + return if (na.layer != nb.layer) na.layer < nb.layer else na.start < nb.start; + } + }.first); + l.members = list.items; + l.angles = try arena.alloc(f32, list.items.len); + } + return ls; +} + +const Box = [4]f32; + +fn dist(a: [2]f32, b: [2]f32) f32 { + return @sqrt((b[0] - a[0]) * (b[0] - a[0]) + (b[1] - a[1]) * (b[1] - a[1])); +} + +/// How far apart two boxes are (0 where they meet). +fn gap(a: Box, b: Box) f32 { + const dx = @max(b[0] - a[2], a[0] - b[2], 0); + const dy = @max(b[1] - a[3], a[1] - b[3], 0); + return @sqrt(dx * dx + dy * dy); +} + +fn shifted(b: Box, d: [2]f32) Box { + return .{ b[0] + d[0], b[1] + d[1], b[2] + d[0], b[3] + d[1] }; +} + +/// A pill `w` wide on a ring of radius `r` round the origin at angle `a`. +fn pillAt(r: f32, a: f32, w: f32) Box { + const x = r * @cos(a); + const y = r * @sin(a); + return .{ x - w / 2, y - gm.pill / 2, x + w / 2, y + gm.pill / 2 }; +} + +/// A way out of a loop as it leaves a pill at angle `a` on its ring: down +/// from its foot, 30 in from the end farther from the ring's centre, as far as anything can be. +fn exitLine(p: Box, a: f32) Box { + const x = if (@cos(a) < 0) p[0] + gm.exit_in else p[2] - gm.exit_in; + return .{ x - 1, p[3], x + 1, 1e6 }; +} + +/// Where a ring leaves a pill at angle `a`, along the ring from its centre (on the tangent, near enough). +fn cutLen(a: f32, w: f32) f32 { + const s = @abs(@sin(a)); + const c = @abs(@cos(a)); + return @min(if (s > 1e-4) w / 2 / s else 1e9, if (c > 1e-4) gm.pill / 2 / c else 1e9); +} + +/// The fitting of one ring: its members' widths, which have a way out of +/// the loop, which gaps are edges (arcs), the member at 3 o'clock and the +/// child loop there (its pills and ways out the others keep clear of; the +/// blocks its ways out go to under its foot). +const Fit = struct { + w: []f32, + exits: []bool, + arcs: []bool, + three: ?usize, + child_r: f32, + pills: []Box, + lines: []Box, + below: []f32, + cur: []?f32, + fwd: []?f32, + bwd: []?f32, + + const step = std.math.degreesToRadians(0.5); + + /// Whether member `k` at angle `a` on a ring of radius `r` keeps clear of everything placed in `at`. + fn clear(f: *const Fit, r: f32, placed: []const ?f32, k: usize, a: f32) bool { + const p = pillAt(r, a, f.w[k]); + if (r * @sin(a) < f.below[k]) return false; + const off: [2]f32 = .{ r + f.child_r, 0 }; + const line: ?Box = if (f.exits[k]) exitLine(p, a) else null; + for (f.pills) |o| { + if (gap(p, shifted(o, off)) < gm.apart) return false; + if (line) |l| if (gap(l, shifted(o, off)) < gm.apart) return false; + } + for (f.lines) |o| if (gap(p, shifted(o, off)) < gm.apart) return false; + for (placed, 0..) |maybe, j| if (j != k) if (maybe) |b| { + const q = pillAt(r, b, f.w[j]); + if (gap(p, q) < gm.apart) return false; + if (f.exits[j] and gap(p, exitLine(q, b)) < gm.apart) return false; + if (line) |l| if (gap(q, l) < gm.apart) return false; + }; + return true; + } + + /// Whether the arc from member `j` at `a` to the next, `k` at `b`, is long enough to read (where it is an edge). + fn arcOk(f: *const Fit, r: f32, j: usize, a: f32, k: usize, b: f32) bool { + if (!f.arcs[j]) return true; + return r * (b - a) - cutLen(a, f.w[j]) - cutLen(b, f.w[k]) >= gm.arc_least; + } + + /// Fits the ring at radius `r`: the header at π, the member at 3 + /// o'clock at 2π, each run of members between two fixed ones from as + /// early as it can be to as late, halfway. False where they do not fit. + fn fit(f: *Fit, r: f32) bool { + const n = f.w.len; + @memset(f.cur, null); + f.cur[0] = pi; + if (f.three) |k| { + f.cur[k] = 2 * pi; + if (!f.clear(r, f.cur, k, 2 * pi)) return false; + } + var a: usize = 0; + while (a < n) { + var b = a + 1; + while (b < n and f.cur[b] == null) b += 1; + const from = f.cur[a].?; + const to = if (b < n) f.cur[b].? else 3 * pi; + // As early as each can be, then as late. + @memcpy(f.fwd, f.cur); + var prev = a; + for (a + 1..b) |k| { + var th = f.fwd[prev].? + step; + while (th < to and !(f.clear(r, f.fwd, k, th) and f.arcOk(r, prev, f.fwd[prev].?, k, th))) th += step; + if (th >= to) return false; + f.fwd[k] = th; + prev = k; + } + if (!f.arcOk(r, prev, f.fwd[prev].?, b % n, to)) return false; + @memcpy(f.bwd, f.cur); + var next = b; + var k = b; + while (k > a + 1) { + k -= 1; + const next_th = if (next < n) f.bwd[next].? else to; + var th = next_th - step; + while (th > from and !(f.clear(r, f.bwd, k, th) and f.arcOk(r, k, th, next % n, next_th))) th -= step; + f.bwd[k] = if (th > f.fwd[k].?) th else f.fwd[k]; + next = k; + } + for (a + 1..b) |j| f.cur[j] = (f.fwd[j].? + f.bwd[j].?) / 2; + // Halfway may not hold where the two ways differ much: then as early as each can be. + const holds = for (a + 1..b) |j| { + if (!f.clear(r, f.cur, j, f.cur[j].?) or !f.arcOk(r, j - 1, f.cur[j - 1].?, j, f.cur[j].?)) break false; + } else f.arcOk(r, b - 1, f.cur[b - 1].?, b % n, to); + if (!holds) for (a + 1..b) |j| { + f.cur[j] = f.fwd[j]; + }; + a = b; + } + return true; + } +}; + +/// The pills and the ways out of loop `li`'s cluster (its ring and the +/// rings nested in it), round its centre at `o`, but its own header's pill. +fn cluster(arena: std.mem.Allocator, g: *const Graph, loops: []const Loop, li: usize, o: [2]f32, pills: *std.ArrayList(Box), lines: *std.ArrayList(Box)) !void { + const l = loops[li]; + for (l.members, l.angles, 0..) |m, a, k| { + const p = shifted(pillAt(l.r, a, g.nodes[m].w), o); + if (k > 0) try pills.append(arena, p); + if (leavesLoop(g, l, m)) try lines.append(arena, exitLine(p, a)); + } + for (loops, 0..) |c, ci| if (c.parent == li) try cluster(arena, g, loops, ci, .{ o[0] + c.c[0], o[1] + c.c[1] }, pills, lines); +} + +/// Whether block `m` of loop `l` has an edge out of it. +fn leavesLoop(g: *const Graph, l: Loop, m: u32) bool { + for (g.edges) |e| if (e.from == m and !l.body[e.to]) return true; + return false; +} + +/// Fits loop `li`'s ring, its children's fitted: the least radius at which +/// its pills (on it at their centres, upright) are 12 apart from each +/// other and from those of the rings nested in it, an arc between two that +/// is an edge is long enough to read, no way out down from one crosses +/// another, and the blocks a nested loop's ways out go to are under its +/// foot; the header at 9 o'clock, the first nested loop's header (or else +/// the first block with a way out) at 3 o'clock, the nested ring outside, +/// touching there. +/// shortcut: only the first nested loop sits at 3 o'clock; any other hangs out from its header's angle, turned with it, and is not kept clear of; upgrade when a recording has two loops in one. +fn fitRing(arena: std.mem.Allocator, g: *const Graph, loops: []Loop, li: usize) !bool { + const l = &loops[li]; + const ms = l.members; + const n = ms.len; + var f: Fit = .{ .w = try arena.alloc(f32, n), .exits = try arena.alloc(bool, n), .arcs = try arena.alloc(bool, n), .three = null, .child_r = 0, .pills = &.{}, .lines = &.{}, .below = try arena.alloc(f32, n), .cur = try arena.alloc(?f32, n), .fwd = try arena.alloc(?f32, n), .bwd = try arena.alloc(?f32, n) }; + for (ms, 0..) |m, k| { + f.w[k] = g.nodes[m].w; + f.exits[k] = leavesLoop(g, l.*, m); + f.arcs[k] = g.edgeOf(m, ms[(k + 1) % n]) != null; + f.below[k] = -std.math.inf(f32); + } + var child: ?usize = null; + for (ms[1..], 1..) |m, k| { + const c = for (loops, 0..) |o, ci| { + if (o.parent == li and o.header == m) break ci; + } else null; + if (c != null or f.exits[k]) { + f.three = k; + child = c; + break; + } + } + if (child) |ci| { + const c = loops[ci]; + var pills: std.ArrayList(Box) = .empty; + var lines: std.ArrayList(Box) = .empty; + try cluster(arena, g, loops, ci, .{ 0, 0 }, &pills, &lines); + f.pills = pills.items; + f.lines = lines.items; + f.child_r = c.r; + var foot: f32 = c.r * @sin(c.angles[0]) + gm.pill / 2; + for (pills.items) |p| foot = @max(foot, p[3]); + for (ms, 0..) |m, k| for (g.edges) |e| if (e.to == m and c.body[e.from] and !c.body[m]) { + f.below[k] = foot + gm.apart + gm.pill / 2; + }; + } + // The least radius: coarse, then fine. + var r: f32 = gm.pill; + while (!f.fit(r)) { + r += 16; + if (r > 2000) return false; + } + if (r > gm.pill) { + r -= 14; + while (!f.fit(r)) r += 2; + } + l.r = r; + for (l.angles, f.cur) |*a, c| a.* = c.?; + if (child) |ci| loops[ci].c = .{ r + loops[ci].r, 0 }; + for (loops, 0..) |*c, ci| if (c.parent == li and ci != child) { + const a = l.angles[std.mem.indexOfScalar(u32, ms, c.header).?]; + turnBy(loops, ci, a); + c.c = .{ (r + c.r) * @cos(a), (r + c.r) * @sin(a) }; + }; + return true; +} + +/// Turns loop `li`'s ring (and those nested in it) by `a` about its centre. +fn turnBy(loops: []Loop, li: usize, a: f32) void { + for (loops[li].angles) |*x| x.* += a; + for (loops, 0..) |*c, ci| if (c.parent == li) { + const was = c.c; + c.c = .{ was[0] * @cos(a) - was[1] * @sin(a), was[0] * @sin(a) + was[1] * @cos(a) }; + turnBy(loops, ci, a); + }; +} + +/// Puts loop `li`'s pills (and its nested loops') round its centre at `o`. +fn putCluster(g: *Graph, loops: []Loop, li: usize, o: [2]f32) void { + const l = &loops[li]; + l.abs = o; + for (l.members, l.angles) |m, a| { + const n = &g.nodes[m]; + n.x = o[0] + l.r * @cos(a) - n.w / 2; + n.y = o[1] + l.r * @sin(a) - n.h / 2; + } + for (loops, 0..) |c, ci| if (c.parent == li) putCluster(g, loops, ci, .{ o[0] + c.c[0], o[1] + c.c[1] }); +} + +/// A part of `g`, its nodes those `in` names (renumbered; `of` each one's +/// in `g`), with the edges between them. +const Sub = struct { g: Graph, of: []u32 }; + +fn subgraph(arena: std.mem.Allocator, g: *const Graph, in: []const bool) !Sub { + var of: std.ArrayList(u32) = .empty; + const idx = try arena.alloc(u32, g.nodes.len); + for (in, 0..) |x, k| if (x) { + idx[k] = @intCast(of.items.len); + try of.append(arena, @intCast(k)); + }; + const nodes = try arena.alloc(Node, of.items.len); + for (of.items, nodes) |k, *n| n.* = g.nodes[k]; + var edges: std.ArrayList(Edge) = .empty; + for (g.edges) |e| if (in[e.from] and in[e.to]) { + var c = e; + c.from = idx[e.from]; + c.to = idx[e.to]; + try edges.append(arena, c); + }; + return .{ .g = .{ .start = g.start, .len = g.len, .nodes = nodes, .edges = edges.items, .spans = &.{}, .here = null, .text = g.text, .exact = g.exact }, .of = of.items }; +} + +/// Takes a placed part's places and ways into `g`, moved by `d`; marks the ways it brings. +fn adopt(g: *Graph, s: Sub, d: [2]f32, routed: []bool) void { + for (s.g.nodes, s.of) |n, k| { + g.nodes[k].x = n.x + d[0]; + g.nodes[k].y = n.y + d[1]; + } + for (s.g.edges) |e| { + const k = g.edgeOf(s.of[e.from], s.of[e.to]) orelse continue; + var moved = e; + for (moved.points[0..e.n]) |*p| p.* = .{ p[0] + d[0], p[1] + d[1] }; + g.edges[k].points = moved.points; + g.edges[k].n = e.n; + routed[k] = true; + } +} + +/// `rings`: each loop a ring, the first loop's rings in the middle (its +/// header at the origin), the blocks before it laid as `layers` lays them +/// left of its header (the one that comes in on its line), those after it +/// as this form lays them under its header, as high as they clear the +/// rings. False where the function has no loop (or no ring fits). +/// shortcut: a second loop that is no other's is laid among the blocks after the first (rings) or before it (layers); a way between the blocks before and after a loop goes round no ring; upgrade when a recording has one. +fn placeRings(arena: std.mem.Allocator, g: *Graph) std.mem.Allocator.Error!bool { + const loops = try loopsOf(arena, g); + if (loops.len == 0) return false; + // The rings nested deepest first. + const order = try arena.alloc(usize, loops.len); + for (order, 0..) |*o, k| o.* = k; + std.mem.sort(usize, order, loops, struct { + fn smaller(ls: []Loop, a: usize, b: usize) bool { + return ls[a].size < ls[b].size; + } + }.smaller); + for (order) |li| if (!try fitRing(arena, g, loops, li)) return false; + var top: usize = undefined; + var found = false; + for (loops, 0..) |l, i| if (l.parent == null and (!found or g.nodes[l.header].layer < g.nodes[loops[top].header].layer)) { + top = i; + found = true; + }; + const lt = &loops[top]; + putCluster(g, loops, top, .{ lt.r, 0 }); + const header = g.nodes[lt.header]; + const n = g.nodes.len; + // Its parts: before it, it, after it. + const part = try arena.alloc(u8, n); + for (part, lt.body) |*p, in| p.* = if (in) 1 else 0; + var stack: std.ArrayList(u32) = .empty; + for (lt.body, 0..) |in, k| if (in) try stack.append(arena, @intCast(k)); + while (stack.pop()) |x| for (g.edges) |e| if (e.from == x and part[e.to] == 0) { + part[e.to] = 2; + try stack.append(arena, e.to); + }; + const routed = try arena.alloc(bool, g.edges.len); + @memset(routed, false); + const in = try arena.alloc(bool, n); + var way_in: ?u32 = null; + var pills: std.ArrayList(Box) = .empty; + for (g.nodes, part) |node, p| if (p == 1) try pills.append(arena, node.box()); + // Before it: left of the header, the block that comes in on its line. + for (part, in) |p, *x| x.* = p == 0; + if (std.mem.indexOfScalar(bool, in, true) != null) { + var s = try subgraph(arena, g, in); + try place(arena, &s.g, .layers); + var right: f32 = 0; + for (s.g.nodes) |node| right = @max(right, node.x + node.w); + var anchor: ?usize = null; + for (s.of, 0..) |k, j| if (g.edgeOf(k, lt.header) != null and (anchor == null or g.nodes[k].layer > g.nodes[s.of[anchor.?]].layer)) { + anchor = j; + }; + const dy = if (anchor) |j| header.cy() - s.g.nodes[j].cy() else header.y - gm.apart - s.g.h; + adopt(g, s, .{ header.x - gm.way_in - right, dy }, routed); + if (anchor) |j| way_in = s.of[j]; + for (s.of) |k| try pills.append(arena, g.nodes[k].box()); + } + // After it: under the header, the block its way out goes to on that way, as high as all clear the rings. + for (part, in) |p, *x| x.* = p == 2; + if (std.mem.indexOfScalar(bool, in, true) != null) { + var s = try subgraph(arena, g, in); + try place(arena, &s.g, .rings); + var anchor: usize = 0; + var best: ?u32 = null; + for (s.of, 0..) |k, j| for (g.edges) |e| if (e.to == k and lt.body[e.from]) { + const rank: u32 = if (e.from == lt.header) 0 else 1 + g.nodes[k].layer; + if (best == null or rank < best.?) { + best = rank; + anchor = j; + } + }; + const a = s.g.nodes[anchor]; + const dx = header.x + gm.exit_in - a.cx(); + var dy = header.y + header.h + gm.apart - a.y; + while (dy < 1e5) : (dy += 2) { + const fits = for (s.g.nodes) |node| { + const b = shifted(node.box(), .{ dx, dy }); + const near = for (pills.items) |p| { + if (gap(b, p) < gm.apart) break true; + } else false; + if (near) break false; + const crosses = for (loops) |l| { + const q: [2]f32 = .{ std.math.clamp(l.abs[0], b[0], b[2]), std.math.clamp(l.abs[1], b[1], b[3]) }; + if (dist(q, l.abs) < l.r + gm.apart) break true; + } else false; + if (crosses) break false; + } else true; + if (fits) break; + } + adopt(g, s, .{ dx, dy }, routed); + } + // The ways the parts did not bring. + for (g.edges, 0..) |*e, k| if (!routed[k]) { + var p: Path = .{}; + const a = g.nodes[e.from]; + const b = g.nodes[e.to]; + if (sharedRing(loops, e.from, e.to)) |sr| { + // Round the ring: to the next block on it an arc of it; past blocks of it an arc 30 inside. + const l = loops[sr[0]]; + const a0 = l.angles[sr[1]]; + var a1 = l.angles[sr[2]]; + while (a1 <= a0 + 1e-4) a1 += 2 * pi; + const next = (sr[1] + 1) % l.members.len == sr[2]; + if (!next) p.to(a.cx(), a.cy()); + p.arc(l.abs, if (next) l.r else l.r - gm.fork_in, a0, a1); + if (!next) p.to(b.cx(), b.cy()); + p.trim(a, b); + } else if (ringOf(loops, e.from, e.to)) |ra| { + wayOut(&p, a, ra, b); + } else if (way_in == e.from and e.to == lt.header and @abs(a.cy() - b.cy()) < 0.5) { + p.to(a.x + a.w, a.cy()); + p.to(b.x, b.cy()); + } else elbow(&p, a, b); + e.set(&p); + }; + var ring_list: std.ArrayList(Ring) = .empty; + for (loops) |l| try ring_list.append(arena, .{ .c = l.abs, .r = l.r, .header = l.header }); + g.rings = ring_list.items; + normalize(g); + return true; +} + +/// The ring two blocks are both on (the deepest), and where each is on it. +fn sharedRing(loops: []const Loop, a: u32, b: u32) ?[3]usize { + var best: ?[3]usize = null; + for (loops, 0..) |l, i| { + const ia = std.mem.indexOfScalar(u32, l.members, a) orelse continue; + const ib = std.mem.indexOfScalar(u32, l.members, b) orelse continue; + if (best == null or l.size < loops[best.?[0]].size) best = .{ i, ia, ib }; + } + return best; +} + +/// For an edge out of a loop (from `a` in one whose body `b` is not in): +/// where `a` is on its own ring (the deepest it is on). +fn ringOf(loops: []const Loop, a: u32, b: u32) ?f32 { + const leaves = for (loops) |l| { + if (l.body[a] and !l.body[b]) break true; + } else false; + if (!leaves) return null; + var best: ?usize = null; + var at: f32 = 0; + for (loops, 0..) |l, i| if (std.mem.indexOfScalar(u32, l.members, a)) |k| if (best == null or l.size < loops[best.?].size) { + best = i; + at = l.angles[k]; + }; + return if (best != null) at else null; +} + +/// A loop's way out, from `a` at angle `angle` on its ring to `b`: out of +/// its foot 30 in from the end farther from the ring's centre, straight +/// down, then a quarter circle of 16 into `b`'s near end, or straight +/// into its top where it is under. +fn wayOut(p: *Path, a: Node, angle: f32, b: Node) void { + const x = if (@cos(angle) < 0) a.x + gm.exit_in else a.x + a.w - gm.exit_in; + const y = a.y + a.h; + if (b.y >= y + gm.bend and x >= b.x + b.h / 2 and x <= b.x + b.w - b.h / 2) { + p.to(x, y); + p.to(x, b.y); + } else if (b.cy() >= y + gm.bend) { + const tx = if (b.cx() < x) b.x + b.w else b.x; + p.* = rounded(&.{ .{ x, y }, .{ x, b.cy() }, .{ tx, b.cy() } }, gm.bend); + } else elbow(p, a, b); +} + +/// Any other way: down from `a`'s foot, across, down into `b`'s top, its +/// bends quarter circles of 16. +/// shortcut: to a block not under its source the way is a straight line, which may cross a ring; upgrade when a recording has one. +fn elbow(p: *Path, a: Node, b: Node) void { + const sy = a.y + a.h; + if (b.y > sy + 2 * gm.bend) { + const my = (sy + b.y) / 2; + p.* = rounded(&.{ .{ a.cx(), sy }, .{ a.cx(), my }, .{ b.cx(), my }, .{ b.cx(), b.y } }, gm.bend); + return; + } + p.to(a.cx(), a.cy()); + p.to(b.cx(), b.cy()); + p.trim(a, b); +} + +/// Moves the drawing to the origin: its pills, its ways, its rings and their turns; its size. +fn normalize(g: *Graph) void { + var lo: [2]f32 = .{ std.math.inf(f32), std.math.inf(f32) }; + var hi: [2]f32 = .{ -std.math.inf(f32), -std.math.inf(f32) }; + const grow = struct { + fn by(l: *[2]f32, h: *[2]f32, b: Box) void { + l.* = .{ @min(l[0], b[0]), @min(l[1], b[1]) }; + h.* = .{ @max(h[0], b[2]), @max(h[1], b[3]) }; } + }.by; + for (g.nodes) |n| grow(&lo, &hi, n.box()); + for (g.edges) |e| for (e.path()) |p| grow(&lo, &hi, .{ p[0] - 4, p[1] - 4, p[0] + 4, p[1] + 4 }); + for (g.rings) |r| grow(&lo, &hi, .{ r.c[0] - 60, r.c[1], r.c[0] + 60, r.c[1] + gm.turns_down + 12 }); + if (lo[0] > hi[0]) return; + for (g.nodes) |*n| { + n.x -= lo[0]; + n.y -= lo[1]; + } + for (g.edges) |*e| for (e.points[0..e.n]) |*p| { + p.* = .{ p[0] - lo[0], p[1] - lo[1] }; }; + for (g.rings) |*r| r.c = .{ r.c[0] - lo[0], r.c[1] - lo[1] }; + g.channel -= lo[0]; + g.w = hi[0] - lo[0]; + g.h = hi[1] - lo[1]; } +// ---------------------------------------------------------------- paths + +/// A way being made: straight runs and arcs, as points. +const Path = struct { + pts: [most][2]f32 = undefined, + n: usize = 0, + + fn to(p: *Path, x: f32, y: f32) void { + if (p.n > 0 and @abs(p.pts[p.n - 1][0] - x) < 0.01 and @abs(p.pts[p.n - 1][1] - y) < 0.01) return; + if (p.n == most) return; + p.pts[p.n] = .{ x, y }; + p.n += 1; + } + + /// Round the circle at `c` of radius `r` from angle `a0` to `a1` (clockwise on the screen as the angle grows). + fn arc(p: *Path, c: [2]f32, r: f32, a0: f32, a1: f32) void { + // Chords of 5 units or so: smooth at any radius, and few. + const steps: usize = @intFromFloat(std.math.clamp(@ceil(@abs(a1 - a0) * r / 5), 2, 40)); + for (0..steps + 1) |k| { + const a = std.math.lerp(a0, a1, @as(f32, @floatFromInt(k)) / @as(f32, @floatFromInt(steps))); + p.to(c[0] + r * @cos(a), c[1] + r * @sin(a)); + } + } + + /// Cut where the way leaves `a`'s pill and where it enters `b`'s: it runs frame to frame. + fn trim(p: *Path, a: Node, b: Node) void { + if (p.n < 2) return; + var first: usize = 0; + while (first < p.n and a.has(p.pts[first])) first += 1; + var last: usize = p.n; + while (last > first and b.has(p.pts[last - 1])) last -= 1; + if (first == p.n or last == first) return; + var out: Path = .{}; + if (first > 0) out.to2(frameOf(a, p.pts[first - 1], p.pts[first])); + for (p.pts[first..last]) |q| out.to2(q); + if (last < p.n) out.to2(frameOf(b, p.pts[last], p.pts[last - 1])); + p.* = out; + } + + fn to2(p: *Path, q: [2]f32) void { + p.to(q[0], q[1]); + } + + /// Where the segment from `in` (inside `n`'s pill) to `out` crosses its frame. + fn frameOf(n: Node, in: [2]f32, out: [2]f32) [2]f32 { + var lo = in; + var hi = out; + for (0..16) |_| { + const mid: [2]f32 = .{ (lo[0] + hi[0]) / 2, (lo[1] + hi[1]) / 2 }; + if (n.has(mid)) lo = mid else hi = mid; + } + return hi; + } +}; + +/// The polyline through `pts` (each turn a right angle), every corner a +/// quarter circle of `r` (less where a leg is shorter than twice that). +fn rounded(pts: []const [2]f32, r: f32) Path { + var p: Path = .{}; + if (pts.len == 0) return p; + p.to(pts[0][0], pts[0][1]); + for (1..pts.len -| 1) |i| { + const a = pts[i - 1]; + const b = pts[i]; + const c = pts[i + 1]; + const la = dist(a, b); + const lc = dist(b, c); + if (la < 0.01 or lc < 0.01) continue; + const k = @min(r, la / 2, lc / 2); + const da: [2]f32 = .{ (a[0] - b[0]) / la, (a[1] - b[1]) / la }; + const dc: [2]f32 = .{ (c[0] - b[0]) / lc, (c[1] - b[1]) / lc }; + if (@abs(da[0] * dc[0] + da[1] * dc[1]) > 0.99) { + p.to(b[0], b[1]); + continue; + } + const o: [2]f32 = .{ b[0] + (da[0] + dc[0]) * k, b[1] + (da[1] + dc[1]) * k }; + const a0 = std.math.atan2(b[1] + da[1] * k - o[1], b[0] + da[0] * k - o[0]); + var a1 = std.math.atan2(b[1] + dc[1] * k - o[1], b[0] + dc[0] * k - o[0]); + if (a1 - a0 > pi) a1 -= 2 * pi; + if (a0 - a1 > pi) a1 += 2 * pi; + p.arc(o, k, a0, a1); + } + p.to(pts[pts.len - 1][0], pts[pts.len - 1][1]); + return p; +} + +// ---------------------------------------------------------------- the linear rows + +/// The linear rows' blocks (`disasm`, `descent`): a 2-unit rule across +/// over each block's first row (not its function's), and where the row's +/// annotation leaves it free the times the run had entered the block, +/// ranged right, faint (`×11`), crossfading from the moment the mark +/// leaves to the one it goes to. +pub const Rules = struct { + of: [2]?Graph, + going: f32, + + /// The blocks of the functions that hold `pc[0]` at `marks[0]` and `pc[1]` at `marks[1]`, `going` of the way between. + pub fn init(arena: std.mem.Allocator, rec: *const Recording, marks: [2]u64, pc: [2]u64, going: f32) Rules { + return .{ .of = .{ light(arena, rec, marks[0], pc[0]), light(arena, rec, marks[1], pc[1]) }, .going = going }; + } + + pub fn draw(r: Rules, u: ui.Ui, addr: u64, y: f32, w: f32, free: bool) void { + var visits: [2]?u32 = .{ null, null }; + for (r.of, &visits) |maybe, *v| if (maybe) |g| if (blockAt(g.nodes, addr)) |k| if (g.nodes[k].start == addr and addr != g.start) { + v.* = g.nodes[k].visits; + }; + if (visits[0] == null and visits[1] == null) return; + // For a strip: a tick at the row's top. + if (ui.strokes) return ui.collectMark(u, 0, y, .tick, 1); + u.fill(.{ .x = theme.stroke.rule, .y = y, .w = w - 2 * theme.stroke.rule, .h = theme.stroke.rule }, theme.color.rule); + if (!free) return; + const size = theme.size.mono.context; + // The count the mark leaves, then the one it goes to; one that does not change, once. + const same = (visits[0] orelse 0) == (visits[1] orelse 0); + for (visits, [2]f32{ 1 - r.going, r.going }, 0..) |v, shows, k| { + const n = v orelse 0; + if (n == 0 or (same and k == 0)) continue; + const text = u.print("\u{00d7}{d}", .{n}); + u.faded(if (same) 1 else shows).text(.mono, size, w - theme.metric.context.side - u.width(.mono, size, text), rows.baseline(y), text, theme.color.text.faint); + } + } +}; + // ---------------------------------------------------------------- an instant /// The graph as a frame shows it: at the stop shown (`g`, where everything -/// is) and the stop the step came from (`was`, the same function), `p` of -/// the way from the one to the other; a walked step across one edge is -/// `leave`'s (or `turn`'s) frames; the panel's scroll. +/// is) and the stop the step came from (`was`, the same function; another +/// layout of it while a fold opens), `p` of the way from the one to the +/// other; a step across one edge is `leave`'s (or `turn`'s) frames; where +/// the drawing is in its pane. pub const Instant = struct { g: Graph, was: Graph, p: f32, leave: ?Leave = null, - pan: f32 = 0, + /// A fold opening: how far the pills have made room (eased), and seconds since it began. + unfold: ?struct { q: f32, t: f32 } = null, + /// The drawing's top left in its pane's body: centred, or scrolled where it is taller. + at: [2]f32, now: cursors.Now, }; -/// A step across one edge, at a walk (`leave`, `turn`): the edge drawn gold -/// (`draw`, 0 to 1), the mark along it (`travel`), seconds since it landed. -pub const Leave = struct { edge: u32, draw: f32, travel: f32, landed: f32 }; +/// A step across one edge: the edge drawn gold (`draw`, 0 to 1), the mark +/// along it (`travel`), seconds since it landed; walked, or at a run (the +/// edge flashing gold under the mark and cooling in 8 f). +pub const Leave = struct { edge: u32, draw: f32, travel: f32, landed: f32, walk: bool = true }; -/// The graph of the function the pc is in, in `form`, in a place `room` high, now. -pub fn instant(arena: std.mem.Allocator, now: cursors.Now, form: Form, room: f32) ?Instant { +/// The graph of the function the pc is in, in `form`, in a pane's body `room` (width, height), now. +pub fn instant(arena: std.mem.Allocator, now: cursors.Now, form: Form, room: [2]f32) ?Instant { const rec = now.rec; const at = [2]u64{ now.stops[1], now.stops[0] }; const pc = [2]u64{ rec.register(at[0], "rip"), rec.register(at[1], "rip") }; - const g = layout(arena, rec, at[1], pc[1], form, room) orelse return null; + const ref = now.way[0]; + const g = layout(arena, rec, at[1], pc[1], form, room, ref) orelse return null; var was = g; - if (at[0] != at[1] and pc[0] -% g.start < g.len) was = layout(arena, rec, at[0], pc[0], form, room) orelse g; + if (at[0] != at[1] and pc[0] -% g.start < g.len) was = layout(arena, rec, at[0], pc[0], form, room, ref) orelse g; // shortcut: a step into another function changes the graph in a frame (no crossfade between two); scenes keep to one. - if (was.nodes.len != g.nodes.len or was.edges.len != g.edges.len) was = g; - var out: Instant = .{ .g = g, .was = was, .p = now.advancing(), .now = now }; - const m = metricOf(form); + if (was.start != g.start) was = g; + var out: Instant = .{ .g = g, .was = was, .p = now.advancing(), .now = now, .at = .{ 0, 0 } }; var q = out.p; - // One instruction across an edge, walked: its frames are `leave`'s. - if (now.walking() and at[1] == at[0] + 1) if (was.here) |a| if (g.here) |b| if (a != b or pc[1] == g.nodes[b].start) if (g.edgeOf(a, b)) |e| { + // One edge crossed: walked, `leave`'s frames; at a run the mark along it with the advance. + if (!now.resting() and now.plan.gait != .sprint and crossed(was, g) == 1) if (g.trail[0]) |e| { const l = time.leave; const plan = now.plan; + const walk = now.walking(); + const travel = cursors.glide(clamp01((now.time - plan.advance) / @max(plan.travel, 1.0 / 60.0))); out.leave = .{ .edge = e, - .draw = cursors.standard(clamp01((now.time - (plan.advance - l.edge)) / l.edge)), - .travel = cursors.glide(clamp01((now.time - plan.advance) / @max(plan.travel, 1.0 / 60.0))), + .draw = if (walk) cursors.standard(clamp01((now.time - (plan.advance - l.edge)) / l.edge)) else travel, + .travel = travel, .landed = now.time - plan.advance - plan.travel, + .walk = walk, }; - q = out.leave.?.travel; + q = travel; }; - out.pan = std.math.lerp(pan(was, room, m), pan(g, room, m), cursors.glide(q)); + // A fold opening: the pills make room from the mark setting off (with the advance where no mark goes). + if (was.open != g.open) { + const since = if (now.resting()) std.math.inf(f32) else if (out.leave != null) now.time - now.plan.advance else out.p * time.unfold.room; + out.unfold = .{ .q = cursors.glide(clamp01(since / time.unfold.room)), .t = since }; + } + // Across, the entry where the scene's first layout (every fold shut) has it: a fold opening moves nothing sideways. + const first = if (g.open == 0) g else layout(arena, rec, ref, pc[1], form, room, ref) orelse g; + const a = place0(was, first, room); + const b = place0(g, first, room); + const k = if (out.unfold) |u| u.q else cursors.glide(q); + out.at = .{ std.math.lerp(a[0], b[0], k), std.math.lerp(a[1], b[1], k) }; return out; } +/// Where a drawing sits in a pane's body: centred, across as its first +/// layout (`first`, every fold shut) is, as far as it fits; down, scrolled +/// where it is taller (`pan`). +fn place0(g: Graph, first: Graph, room: [2]f32) [2]f32 { + const x = (room[0] - first.w) / 2 + first.nodes[0].x - g.nodes[0].x; + return .{ if (g.w <= room[0]) std.math.clamp(x, 0, room[0] - g.w) else std.math.clamp(x, room[0] - g.w, 0), if (g.h <= room[1]) (room[1] - g.h) / 2 else -pan(g, room[1]) }; +} + +/// How many edges the run took between the two moments (by their counts). +fn crossed(was: Graph, g: Graph) u32 { + var a: u32 = 0; + var b: u32 = 0; + for (was.edges) |e| a += e.count; + for (g.edges) |e| b += e.count; + return b -| a; +} + fn clamp01(v: f32) f32 { return std.math.clamp(v, 0, 1); } -/// How long the mark takes along edge `e`: 12 f and 2 f a 100 units, 30 f at most. +/// How long the mark takes along edge `e`: 12 f and 2 f a 100 units, 42 f at most. pub fn markTime(e: *const Edge) f32 { const l = time.leave; return @min(l.mark + l.per_100 * e.length() / 100, l.mark_most); } -/// `leave` (and `turn`, the same along a loop's lane): from a stop on a -/// block's last instruction (a jump; or one that falls into the next +/// `leave` (and `turn`, round a ring's foot into its header): from a stop +/// on a block's last instruction (a jump; or one that falls into the next /// block), one step across the edge it takes, to motion.md's frames: fire; /// the compare's chips framed as read (the CPU's slot, 18 f), the cause; /// the edge drawn gold, head first (24 to 42 f); the mark along it, 12 f -/// and 2 f a 100 units of the lens's edge (30 f at most); landing, the -/// advance; the target's count struck 6 f after (a turn's lane count as it -/// lands); the oldest trail edge cooled (18 f); a rest to 42 f after the landing. +/// and 2 f a 100 units (42 f at most; into a fold that opens, no sooner +/// than the room is made); landing, the advance; the target's count struck +/// 6 f after (a ring's turns as it lands); the oldest trail edge cooled +/// (18 f); a rest to 42 f after the landing. Measured on the `blocks` +/// lens's pane. pub fn leave(c: cursors.Cursor, s: *anim.Frame) void { const from = c.moment(s); const to = from + 1; const l = time.leave; - var buf: [1 << 18]u8 = undefined; - var fba = std.heap.FixedBufferAllocator.init(&buf); + var arena: std.heap.ArenaAllocator = .init(std.heap.page_allocator); + defer arena.deinit(); const rec = c.rec; + const band = theme.layout.split.blocks.band; + const room: [2]f32 = .{ band.w - 2 * theme.stroke.rule, band.h - theme.metric.context.tag - theme.stroke.rule }; var mark: f32 = l.mark; - if (layout(fba.allocator(), rec, to, rec.register(to, "rip"), .lens, std.math.inf(f32))) |g| { - if (blockAt(g.nodes, rec.register(from, "rip"))) |a| if (g.here) |b| if (g.edgeOf(a, b)) |e| { + if (layout(arena.allocator(), rec, to, rec.register(to, "rip"), .rings, room, c.first)) |g| { + if (g.nodeOf(rec.register(from, "rip"))) |a| if (g.here) |b| if (g.edgeOf(a, b)) |e| { mark = markTime(&g.edges[e]); }; + if (layout(arena.allocator(), rec, from, rec.register(from, "rip"), .rings, room, c.first)) |was| if (was.start == g.start and was.open != g.open) { + mark = @max(mark, time.unfold.room); + }; } const plan: cursors.Plan = .{ .at = @splat(l.chips), .advance = l.sets_off, .travel = mark, .total = l.sets_off + mark + l.rest }; c.step(s, to, plan, plan.total); @@ -1010,13 +1716,32 @@ pub fn toEnd(c: cursors.Cursor, s: *anim.Frame) void { c.step(s, to, plan, plan.total); } -/// An edge's look in `g`: never taken `rule`, taken `dim`, the last three -/// taken the trail's golds (the newest 3 wide). By line, all `rule`. -fn edgeLook(g: Graph, e: u32) struct { ink: u24, w: f32 } { +// ---------------------------------------------------------------- drawing + +/// An edge's look in `g`: not taken yet `rule`, taken `dim`, the last +/// three taken the trail's golds (the newest 3 wide). By line, all `rule`. +const Look = struct { ink: ui.Color, w: f32 }; + +fn edgeLook(g: Graph, e: u32) Look { const tr = theme.color.trail; - if (!g.exact) return .{ .ink = theme.color.rule, .w = theme.stroke.rule }; - for (g.trail, 0..) |maybe, k| if (maybe) |te| if (te == e) return .{ .ink = tr[k], .w = if (k == 0) 3 else theme.stroke.rule }; - return .{ .ink = if (g.edges[e].count > 0) t.dim else theme.color.rule, .w = theme.stroke.rule }; + if (!g.exact) return .{ .ink = ui.rgb(theme.color.rule), .w = theme.stroke.rule }; + for (g.trail, 0..) |maybe, k| if (maybe) |te| if (te == e) return .{ .ink = ui.rgb(tr[k]), .w = if (k == 0) 3 else theme.stroke.rule }; + return .{ .ink = ui.rgb(if (g.edges[e].count > 0) t.dim else theme.color.rule), .w = theme.stroke.rule }; +} + +/// The same edge (by its blocks) in the layout the step came from, if it is there. +fn wasEdge(v: Instant, e: u32) ?u32 { + const g = v.g; + if (v.was.open == g.open) return e; + const a = v.was.nodeOf(g.nodes[g.edges[e].from].start) orelse return null; + const b = v.was.nodeOf(g.nodes[g.edges[e].to].start) orelse return null; + return v.was.edgeOf(a, b); +} + +/// The node holding node `k`'s block in the layout the step came from. +fn wasNode(v: Instant, k: u32) ?Node { + const i = v.was.nodeOf(v.g.nodes[k].start) orelse return null; + return v.was.nodes[i]; } /// A count written as the mark lands: armed 12 f before `s`, struck at @@ -1034,10 +1759,11 @@ fn landing(now: cursors.Now, s: f32) ui.Heat { } /// What a count shows: the old number until a strike's fill is half in, -/// then the new; a strike's paper under it, on its `ground` (a box's, -/// or the page). Crossfading (`p`) where it changes unstruck. `prefix` -/// before the digits; ranged right of `x` when `right`. -fn number(u: ui.Ui, face: sk.Face, size: f32, x: f32, base_y: f32, right: bool, was: u32, is: u32, ink: u24, heat: ?ui.Heat, ground: ?u24, p: f32, prefix: []const u8) void { +/// then the new; a strike's paper under it, on its `ground` (a pill's, or +/// the page). Crossfading (`p`) where it changes unstruck. One that +/// appears (from none) fades in, `appear` of it, until its strike. +/// `prefix` before the digits; ranged right of `x` when `right`. +fn number(u: ui.Ui, face: sk.Face, size: f32, x: f32, base_y: f32, right: bool, was: u32, is: u32, ink: u24, heat: ?ui.Heat, ground: ?u24, p: f32, prefix: []const u8, appear: f32) void { const one = struct { fn draw(v: ui.Ui, fc: sk.Face, sz: f32, xx: f32, by: f32, r: bool, n: u32, c: anytype, pre: []const u8) void { if (n == 0) return; @@ -1050,10 +1776,12 @@ fn number(u: ui.Ui, face: sk.Face, size: f32, x: f32, base_y: f32, right: bool, const text = u.print("{s}{d}", .{ prefix, is }); const w = u.width(face, size, text); const left = if (right) x - w else x; - // Nothing under it but while it is armed or its paper shows: its ground is the box's own, or the page. - // Inside its box's frame: the frame never goes under the paper and back. + // Nothing under it but while it is armed or its paper shows: its ground is the pill's own, or the page. if (h.level > 0 and h.solid > 0 or h.arm > 0) _ = u.cellWritten(.{ .x = left - 3, .y = base_y - size * 0.7, .w = w + 6, .h = size * 0.8 }, h, ground); - if (h.level < 1 or h.in < 0.5) return one(u, face, size, x, base_y, right, was, ink, prefix); + if (h.level < 1 or h.in < 0.5) { + if (was == 0) return one(u.faded(appear), face, size, x, base_y, right, is, ink, prefix); + return one(u, face, size, x, base_y, right, was, ink, prefix); + } // Bold and bright on the paper, cooling to its own ink and face with it. const hot = h.solid * h.in; const bold = hot >= 0.5; @@ -1063,331 +1791,259 @@ fn number(u: ui.Ui, face: sk.Face, size: f32, x: f32, base_y: f32, right: bool, one(u.faded(p), face, size, x, base_y, right, is, ink, prefix); } -/// The edges of `v`, in `u` (the graph's origin): each in its look, mixed -/// from the one before as the step lands; the one a leave takes drawn -/// gold, head first, over its old look, and cooling to the trail's newest -/// after the landing; each loop's turns under its turn into its header. -fn drawEdges(u: ui.Ui, v: Instant, form: Form) void { +/// A pill: `r` with ends half circles, filled `fill` (null: none), framed +/// inside in `frame` `w` wide, or dashed 12 on 8. +fn pill(u: ui.Ui, r: ui.Rect, fill: ?ui.Color, frame: ui.Color, w: f32, dashed: bool) void { + var pts: [2 * 13 + 1]ui.Vec = undefined; + const outline = struct { + fn of(out: []ui.Vec, rr: ui.Rect, inset: f32) void { + const rad = rr.h / 2 - inset; + const cy = rr.y + rr.h / 2; + for (0..13) |k| { + const a = pi / 2 + pi * @as(f32, @floatFromInt(k)) / 12; + out[k] = .{ rr.x + rr.h / 2 + rad * @cos(a), cy + rad * @sin(a) }; + out[13 + k] = .{ rr.x + rr.w - rr.h / 2 + rad * @cos(a + pi), cy + rad * @sin(a + pi) }; + } + out[26] = out[0]; + } + }.of; + if (fill) |c| { + outline(&pts, r, 0); + sk.draw.polygon(u.f, pts[0..26], u.at.pen(.{ .fill = c })); + } + outline(&pts, r, w / 2); + const pen = u.at.pen(.{ .stroke = frame, .width = w, .cap = .butt, .join = .round }); + if (dashed) sk.draw.dashed(u.f, &pts, theme.stroke.dash, pen) else sk.draw.polygon(u.f, pts[0..26], pen); +} + +/// The edges, in `u` (the drawing's origin): each in its look, mixed from +/// the one before as the step lands (the trail drawn last, the newest +/// over all); the one a leave takes drawn gold head first over its old +/// look, cooling to the trail's newest after the landing. While a fold +/// opens, the old layout's edges go as the new one's come. +/// shortcut: during an unfold the edges crossfade between the two layouts rather than following the pills as they make room; no recording has pills beyond a fold that move far. +fn drawEdges(u: ui.Ui, v: Instant) void { const g = v.g; - const lens = form == .lens; - const gm = theme.metric.graph; - const head: [2]f32 = if (lens) gm.lens.head else gm.head; - const radius: f32 = if (lens) gm.lens.corner else gm.corner; - // Recoloured with the landing (a leave's 18 f), else with the advance. - const q = if (v.leave) |l| clamp01(l.landed / time.leave.trail) else v.p; - for (g.edges, 0..) |e, k| { - const a = edgeLook(v.was, @intCast(k)); - const b = edgeLook(g, @intCast(k)); - const ink = ui.mix(a.ink, b.ink, q); - const w = std.math.lerp(a.w, b.w, q); - var pts: [6]ui.Vec = undefined; - for (e.path(), 0..) |pt, n| pts[n] = .{ pt[0], pt[1] }; - u.route(pts[0..e.n], ink, .{ .width = if (ui.strokes) 20 else w, .head = if (ui.strokes) null else head, .radius = radius }); - if (v.leave) |l| if (l.edge == k) { - const gold = theme.mark(.current).solid; - u.faded(1 - q).route(pts[0..e.n], gold, .{ .width = if (ui.strokes) 20 else 3, .head = if (ui.strokes) null else head, .radius = radius, .progress = l.draw }); + const head = gm.head; + const q = recolour(v); + const sets = [2]Graph{ v.was, g }; + var buf: [most]ui.Vec = undefined; + for (sets, 0..) |set, si| { + const shows: f32 = if (v.unfold) |uf| (if (si == 0) 1 - uf.q else uf.q) else if (si == 0) 0 else 1; + if (shows <= 0) continue; + const uu = u.faded(shows); + // Not in the trail first, then the trail from its oldest. + for (0..4) |pass| for (set.edges, 0..) |e, k| { + const rank: usize = for (set.trail, 0..) |maybe, tk| { + if (maybe != null and maybe.? == k) break 3 - tk; + } else 0; + if (rank != pass) continue; + var look = edgeLook(set, @intCast(k)); + if (v.unfold == null) { + const a = edgeLook(v.was, @intCast(k)); + look = .{ .ink = ui.mix(a.ink, look.ink, q), .w = std.math.lerp(a.w, look.w, q) }; + } + uu.route(vecs(&buf, e.path()), look.ink, .{ .width = look.w, .head = head, .radius = 0 }); }; - // A loop's turns so far, on its lane under the turn into its header; struck as a turn lands. - if (e.back and (e.count > 0 or v.was.edges[k].count > 0) and !ui.strokes) { - const lx = pts[2][0]; - const hy = pts[3][1]; - const strike: ?ui.Heat = if (v.leave) |l| (if (l.edge == k) landing(v.now, v.now.plan.advance + v.now.plan.travel) else null) else null; - number(u, .sans, theme.size.sans.micro, lx + 5, hy + 22, false, v.was.edges[k].count, e.count, t.faint, strike, null, v.p, "\u{00d7}"); - } - // On the map a conditional's counts by its ports. - if (!lens and !e.back and e.kind != .jump and g.exact and !ui.strokes) { - const outs = for (g.edges) |o| { - if (o.from == e.from and !o.back and o.to != e.to) break true; - } else false; - if (outs) number(u, .mono, theme.size.mono.context, pts[0][0] + 8, pts[0][1] + 20, false, v.was.edges[k].count, e.count, t.faint, null, null, v.p, ""); - } + } + if (v.leave) |l| { + u.faded(1 - q).route(vecs(&buf, g.edges[l.edge].path()), theme.mark(.current).solid, .{ .width = 3, .head = head, .radius = 0, .progress = l.draw }); } } -/// The mark on its way along the edge a leave takes: a gold plaque (half -/// size in the lens) with an ink head pointing the way it goes. -fn drawMark(u: ui.Ui, v: Instant, form: Form) void { - const l = v.leave orelse return; - if (l.travel <= 0 or l.travel >= 1) return; - const e = &v.g.edges[l.edge]; - const at, const dir = e.at(l.travel * e.length()); - const side: f32 = if (form == .lens) 12 else theme.metric.plaque.pc; - const gold = theme.mark(.current); - u.fill(.{ .x = at[0] - side / 2, .y = at[1] - side / 2, .w = side, .h = side }, gold.solid); - if (ui.strokes) return; - const h = side / 4; - const tip: ui.Vec = .{ at[0] + dir[0] * h, at[1] + dir[1] * h }; - const back: ui.Vec = .{ at[0] - dir[0] * h, at[1] - dir[1] * h }; - const across: ui.Vec = .{ -dir[1] * h, dir[0] * h }; - sk.draw.polygon(u.f, &.{ tip, back + across, back - across }, u.at.pen(.{ .fill = ui.rgb(gold.on_solid) })); +/// How far the edges have taken their new looks: walked, over 18 f from the +/// landing; at a run, from the mark setting off to the step's end (the +/// flash cooled within it); else with the advance. +fn recolour(v: Instant) f32 { + const l = v.leave orelse return v.p; + if (l.walk) return clamp01(l.landed / time.leave.trail); + const plan = v.now.plan; + return clamp01((v.now.time - plan.advance) / @max(plan.total - plan.advance, 1.0 / 60.0)); +} + +/// A way's points as the drawing takes them. +fn vecs(buf: *[most]ui.Vec, pts: []const [2]f32) []const ui.Vec { + for (pts, buf[0..pts.len]) |p, *v| v.* = .{ p[0], p[1] }; + return buf[0..pts.len]; +} + +/// Each ring's turns, 30 under its centre, `5 turns` (the number mono 20, +/// the word Go 18 dim), nothing before the first; struck as a turn lands. +fn drawTurns(u: ui.Ui, v: Instant) void { + const g = v.g; + const size = theme.size.mono.context; + const micro = theme.size.sans.micro; + for (g.rings) |ring| { + var n: u32 = 0; + var was: u32 = 0; + var heat: ?ui.Heat = null; + for (g.edges, 0..) |e, k| if (e.back and e.to == ring.header) { + n += e.count; + if (wasEdge(v, @intCast(k))) |w| was += v.was.edges[w].count; + if (v.leave) |l| if (l.edge == k and l.walk) { + heat = landing(v.now, v.now.plan.advance + v.now.plan.travel); + }; + }; + if (n == 0 and was == 0) continue; + // The first: nothing until it is struck (or, unstruck, as the advance brings it). + const in = if (heat) |h| (if (h.level >= 1) clamp01(h.in * 2) else 0) else v.p; + const shown = if (in >= 1) n else was; + const word = if (@max(shown, 1) == 1) " turn" else " turns"; + const digits = u.print("{d}", .{@max(n, was)}); + const w = u.width(.mono, size, digits) + u.width(.sans, micro, word); + const x = ring.c[0] - w / 2; + const by = ring.c[1] + gm.turns_down + 7; + number(u, .mono, size, x, by, false, was, n, t.primary, heat, null, v.p, "", 0); + u.faded(if (was == 0) in else 1).text(.sans, micro, x + u.width(.mono, size, digits), by, word, t.dim); + } } /// How much node `k` is the pc's: as the mark leaves it and lands, or with the advance. fn golden(v: Instant, k: u32) f32 { - const was: f32 = if (v.was.here == k) 1 else 0; + const was: f32 = if (v.was.here) |h| (if (v.g.nodeOf(v.was.nodes[h].start) == k) 1 else 0) else 0; const is: f32 = if (v.g.here == k) 1 else 0; if (v.leave) |l| { if (was > is) return 1 - l.travel; - if (is > was) return clamp01(l.landed / time.leave.count); + if (is > was) return if (l.walk) clamp01(l.landed / time.leave.count) else l.travel; return is; } return std.math.lerp(was, is, v.p); } -/// The `blocks` lens (design/README.md, `graph`): over the program column -/// the function's graph without its text, a block a box 24 high, as wide -/// as its rows (60 and 10 a row, 132 at least), its offset and its visits, -/// the pc's framed gold 3; the edges, the lanes and the trail at half -/// measure. Its view is the disassembly itself, over the state column -/// (the split `blocks`). +/// The pills: not reached yet on the page, framed `rule`, the offset faint, +/// no count; reached on `raised`, the offset primary, the visits; the pc's +/// framed gold 3; a fold dashed. A first entry fills as the mark lands +/// (`reach`); a fold opening fades into its blocks, quiet, in their places, +/// as the pills beyond make room (`unfold`). +fn drawPills(u: ui.Ui, v: Instant) void { + const g = v.g; + const size = theme.size.mono.context; + const adv = ui.advance(size); + const rec = v.now.rec; + const now = v.now; + for (g.nodes, 0..) |n, k| { + const w = wasNode(v, @intCast(k)); + const opening = v.unfold != null and w != null and w.?.folded > 0 and n.folded == 0; + var x = n.x; + var y = n.y; + var shows: f32 = 1; + if (v.unfold) |uf| { + if (opening) { + // Its place in the fold's blocks, in address order. + var rank: f32 = 0; + for (g.nodes, 0..) |o, j| if (o.folded == 0 and o.start < n.start) if (wasNode(v, @intCast(j))) |ow| if (ow.folded > 0 and ow.start == w.?.start) { + rank += 1; + }; + shows = clamp01((uf.t - rank * time.unfold.apart) / time.unfold.fade); + } else if (w) |ow| { + x = std.math.lerp(ow.x, n.x, uf.q); + y = std.math.lerp(ow.y, n.y, uf.q); + } + } + const o = u.faded(shows); + const r: ui.Rect = .{ .x = x, .y = y, .w = n.w, .h = n.h }; + const base_y = rows.baseline(y); + if (n.folded > 0) { + pill(o, r, ui.rgb(theme.color.page), ui.rgb(theme.color.rule), theme.stroke.rule, true); + o.text(.mono, size, x + gm.pill_in, base_y, o.print("+{x} \u{2026}", .{n.start - g.start}), t.faint); + const words = o.print("\u{00b7} {d}", .{n.folded}); + o.text(.mono, size, x + n.w - gm.pill_in - o.width(.mono, size, words), base_y, words, t.faint); + continue; + } + const was_visits: u32 = if (w) |ow| (if (ow.folded > 0) 0 else ow.visits) else 0; + const gold = golden(v, @intCast(k)); + const filled = if (v.leave) |l| (if (l.walk) clamp01(l.landed / time.reach.fill) else l.travel) else v.p; + const seen = std.math.lerp(@as(f32, if (was_visits > 0) 1 else 0), @as(f32, if (n.visits > 0) 1 else 0), filled); + pill(o, r, ui.mix(theme.color.page, theme.color.raised, seen), ui.mix(theme.color.rule, theme.mark(.current).solid, gold), std.math.lerp(theme.stroke.rule, gm.gold, gold), false); + // The pc's pill's gold frame pulses with the fire on its last row. + const out = if (gold > 0) now.fire() else 0; + if (out > 0) pill(o, .{ .x = x - out, .y = y - out, .w = n.w + 2 * out, .h = n.h + 2 * out }, null, ui.rgb(theme.mark(.current).solid), gm.gold * gold + out, false); + const off = o.print("+{x}", .{n.start - g.start}); + o.text(.mono, size, x + gm.pill_in, base_y, off, ui.mix(t.faint, t.primary, seen)); + var cx = x + gm.pill_in + o.width(.mono, size, off); + for (n.calls) |c| if (c != 0) { + const name = callee(rec, c) orelse ""; + o.text(.mono, size, cx + adv, base_y, name, t.faint); + cx += adv + o.width(.mono, size, name); + }; + if (n.more_calls) o.text(.mono, size, cx + adv, base_y, "\u{2026}", t.faint); + const strike: ?ui.Heat = if (v.leave) |l| (if (l.walk and g.edges[l.edge].to == k) landing(now, now.plan.advance + now.plan.travel + time.leave.count) else null) else null; + const appear = if (v.leave) |l| clamp01(l.landed / time.reach.count) else 1; + number(o, .mono, size, x + n.w - gm.pill_in, base_y, true, was_visits, n.visits, t.dim, strike, if (seen >= 0.5) theme.color.raised else theme.color.page, v.p, "\u{00d7}", appear); + } + // The folds that open: their dashed pills going as their blocks come. + if (v.unfold) |uf| for (v.was.nodes) |wn| if (wn.folded > 0) if (g.nodeOf(wn.start)) |k| if (g.nodes[k].folded == 0) { + const o = u.faded(1 - clamp01(uf.t / time.unfold.fade)); + pill(o, .{ .x = wn.x, .y = wn.y, .w = wn.w, .h = wn.h }, null, ui.rgb(theme.color.rule), theme.stroke.rule, true); + o.text(.mono, size, wn.x + gm.pill_in, rows.baseline(wn.y), o.print("+{x} \u{2026}", .{wn.start - g.start}), t.faint); + }; +} + +/// The mark on its way along the edge a leave takes: a gold plaque 22 with +/// an ink point 12 by 10 the way it goes. +fn drawMark(u: ui.Ui, v: Instant) void { + const l = v.leave orelse return; + if (l.travel <= 0 or l.travel >= 1) return; + const e = &v.g.edges[l.edge]; + const side = gm.mark; + // Its point the way it goes over its own length: a small jog in the way does not turn it. + const d = l.travel * e.length(); + const at, const tangent = e.at(d); + const ahead, _ = e.at(@min(d + side / 2, e.length())); + const behind, _ = e.at(@max(d - side / 2, 0)); + const span = dist(ahead, behind); + const dir: [2]f32 = if (span > 1) .{ (ahead[0] - behind[0]) / span, (ahead[1] - behind[1]) / span } else tangent; + const gold = theme.mark(.current); + u.fill(.{ .x = at[0] - side / 2, .y = at[1] - side / 2, .w = side, .h = side }, gold.solid); + const h = gm.mark_point[0] / 2; + const tip: ui.Vec = .{ at[0] + dir[0] * h, at[1] + dir[1] * h }; + const back: ui.Vec = .{ at[0] - dir[0] * h, at[1] - dir[1] * h }; + const across: ui.Vec = .{ -dir[1] * gm.mark_point[1] / 2, dir[0] * gm.mark_point[1] / 2 }; + sk.draw.polygon(u.f, &.{ tip, back + across, back - across }, u.at.pen(.{ .fill = ui.rgb(gold.on_solid) })); +} + +/// The `blocks` lens (design/README.md, `graph`), and the map's drawing at +/// its size: over the program column the function's graph in the form +/// the scene names (`rings`; `layers` where it has no loop), centred in +/// its pane, a block a pill. Its rows are the disassembly under the source. pub const Blocks = struct { cursor: cursors.Cursor, stage: *const Stage, focus: bool = false, + form: Form = .rings, pub fn draw(b: *const Blocks, f: *sk.Frame, placed: anim.Placed) void { + // Nothing of it on a strip: the band has none. + if (ui.strokes) return; const box = b.stage.box(placed, .band); const m = theme.metric.context; - if (box.h < m.tag + 24) return; + if (box.h < m.tag + gm.pill) return; const u = context.at(f, placed, box).faded(placed.value(b.stage.drawing)); u.clip(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }); defer u.unclip(); const now = b.cursor.now(placed); - const room = box.h - m.tag - theme.stroke.rule; - const v = instant(f.scratch, now, .lens, room) orelse { + const rule = theme.stroke.rule; + const room: [2]f32 = .{ box.w - 2 * rule, box.h - m.tag - rule }; + const v = instant(f.scratch, now, b.form, room) orelse { _ = u.panel(box.w, box.h, "its blocks", .{ .focus = b.focus }); return; }; - const name = ui.symbol(u, b.cursor.rec.strings.get(v.g.start) orelse ""); - _ = u.panel(box.w, box.h, u.print("the blocks of {s}", .{name[0 .. std.mem.lastIndexOfScalar(u8, name, '+') orelse name.len]}), .{ .focus = b.focus, .note = "its blocks \u{00b7} the visits \u{00b7} the path" }); - u.clip(.{ .x = theme.stroke.rule, .y = m.tag, .w = box.w - 2 * theme.stroke.rule, .h = room }); - const o = u.moved(0, m.tag - v.pan); - drawEdges(o, v, .lens); - const gm = theme.metric.graph.lens; - const size = theme.size.mono.context; - for (v.g.nodes, v.was.nodes, 0..) |n, was, k| { - const r: ui.Rect = .{ .x = n.x, .y = n.y, .w = n.w, .h = n.h }; - const gold = golden(v, @intCast(k)); - const seen = std.math.lerp(@as(f32, if (was.visits > 0) 1 else 0), @as(f32, if (n.visits > 0) 1 else 0), if (v.leave != null) clamp01(v.leave.?.landed / time.leave.count) else v.p); - o.fill(r, ui.mix(theme.color.page, theme.color.raised, seen)); - if (n.folded > 0) o.dashedFrame(r, theme.color.rule, theme.stroke.rule) else o.frame(r, ui.mix(theme.color.rule, theme.mark(.current).solid, gold), std.math.lerp(theme.stroke.rule, gm.gold, gold)); - const base_y = rows.baseline(n.y); - const off = o.print("+{x}", .{n.start - v.g.start}); - o.text(.mono, size, n.x + 8, base_y, off, ui.mix(t.faint, t.primary, seen)); - const strike: ?ui.Heat = if (v.leave) |l| (if (v.g.edges[l.edge].to == k) landing(now, now.plan.advance + now.plan.travel + time.leave.count) else null) else null; - number(o, .mono, size, n.x + n.w - 8, base_y, true, was.visits, n.visits, t.dim, strike, if (seen >= 0.5) theme.color.raised else theme.color.page, v.p, "\u{00d7}"); - } - drawMark(o, v, .lens); + const full = b.cursor.rec.strings.get(v.g.start) orelse ""; + const name = ui.symbol(u, full); + const short = name[0 .. std.mem.lastIndexOfScalar(u8, name, '+') orelse name.len]; + const title = if (std.mem.indexOfScalar(u8, full, '!')) |bang| u.print("the blocks of {s} \u{00b7} {s}", .{ short, full[0..bang] }) else u.print("the blocks of {s}", .{short}); + _ = u.panel(box.w, box.h, title, .{ .focus = b.focus, .note = if (v.g.rings.len > 0) "its blocks \u{00b7} the visits so far \u{00b7} the path \u{00b7} the loops' turns" else "its blocks \u{00b7} the visits so far \u{00b7} the path" }); + u.clip(.{ .x = rule, .y = m.tag, .w = room[0], .h = room[1] }); + const o = u.moved(rule + v.at[0], m.tag + v.at[1]); + drawEdges(o, v); + drawTurns(o, v); + drawPills(o, v); + drawMark(o, v); u.unclip(); } }; -/// The disassembly as its graph, on the map (design/README.md, `graph`; -/// mock 22): two columns wide beside the source. A block is a head (its -/// first address, its lines, how often the run entered it) over its rows, -/// `insn`'s with the offset where the address was; the annotation only in -/// the pc's block, which widens to its column; a call a hook out of the -/// block's side and back a row down; under a return, the way out. Too tall, -/// the runs never reached fold, then long blocks, then it pans. -pub const Map = struct { - cursor: cursors.Cursor, - stage: *const Stage, - - pub fn draw(gm: *const Map, f: *sk.Frame, placed: anim.Placed) void { - const box = gm.stage.box(placed, .disasm); - const m = theme.metric.context; - if (box.h < m.tag + m.row) return; - const u = context.at(f, placed, box); - const now = gm.cursor.now(placed); - const rec = gm.cursor.rec; - const room = box.h - m.tag - theme.stroke.rule; - const v = instant(f.scratch, now, .map, room) orelse { - _ = u.panel(box.w, box.h, "disassembly", .{}); - return; - }; - const g = v.g; - const full = rec.strings.get(g.start) orelse ""; - const sym = ui.symbol(u, full); - const name = sym[0 .. std.mem.lastIndexOfScalar(u8, sym, '+') orelse sym.len]; - const module: []const u8 = if (std.mem.indexOfScalar(u8, full, '!')) |bang| full[0..bang] else ""; - const folded = g.foldedBlocks(); - const title = if (module.len > 0) u.print("disassembly \u{00b7} {s} \u{00b7} {s}", .{ name, module }) else u.print("disassembly \u{00b7} {s}", .{name}); - const note = if (folded > 0) u.print("{s}{d} blocks \u{00b7} folded: {d} not reached", .{ if (rec.sourced(now.stops[0])) "" else "no source \u{00b7} ", g.blocks, folded }) else if (g.exact) "its blocks \u{00b7} visits so far \u{00b7} the edges the run took" else "its blocks \u{00b7} visits so far"; - _ = u.panel(box.w, box.h, title, .{ .note = note }); - u.clip(.{ .x = theme.stroke.rule, .y = m.tag, .w = box.w - 2 * theme.stroke.rule, .h = room }); - defer u.unclip(); - const o = u.moved(0, m.tag - v.pan); - drawEdges(o, v, .map); - const d: disasm.Disasm = .{ .cursor = gm.cursor, .stage = gm.stage }; - const body: ui.Rect = .{ .x = theme.stroke.rule, .y = v.pan, .w = box.w - 2 * theme.stroke.rule, .h = room }; - for (g.nodes, 0..) |_, k| block(o, v, @intCast(k), d, body); - drawMark(o, v, .map); - } - - /// Block `k`: its head, its rows, its hooks and its way out. - fn block(o: ui.Ui, v: Instant, k: u32, d: disasm.Disasm, body: ui.Rect) void { - const gm = theme.metric.graph; - const m = theme.metric.context; - const size = theme.size.mono.context; - const adv = size * 3 / 5; - const now = v.now; - const rec = now.rec; - const g = v.g; - const n = g.nodes[k]; - const was = v.was.nodes[k]; - const here = g.here == k or v.was.here == k; - // The pc's block widens to its column for the annotation, never into the channel. - const w = if (here and n.folded == 0) @max(n.w, @min(g.pitch - gm.block_gap, g.channel - gm.channel / 2 - n.x)) else n.w; - const r: ui.Rect = .{ .x = n.x, .y = n.y, .w = w, .h = n.h }; - const landing_q = if (v.leave) |l| clamp01(l.landed / time.leave.count) else v.p; - const seen = std.math.lerp(@as(f32, if (was.visits > 0) 1 else 0), @as(f32, if (n.visits > 0) 1 else 0), landing_q); - const gold = golden(v, k); - o.fill(r, theme.color.page); - if (n.folded > 0) { - // Blocks the whole recording never reached: one dashed box, its offsets and its count, - // said of the run so far (a graph says what has happened by the moment shown, never what will not). - o.dashedFrame(r, theme.color.rule, theme.stroke.rule); - const last = n.start + n.len - 1; - o.text(.mono, size, n.x + m.side, rows.baseline(n.y), o.print("+{x} to +{x}", .{ n.start - g.start, last - g.start }), t.faint); - const words = if (n.folded > 1) o.print("{d} blocks not reached", .{n.folded}) else "not reached"; - const micro = theme.size.sans.micro; - o.text(.sans, micro, n.x + w - m.side - o.width(.sans, micro, words), n.y + m.tag - 6, words, t.faint); - return; - } - o.fill(.{ .x = r.x, .y = r.y, .w = r.w, .h = m.tag }, ui.mix(theme.color.page, theme.color.raised, seen)); - o.frame(r, ui.mix(theme.color.rule, theme.mark(.current).solid, gold), theme.stroke.rule); - // The head: its first address, its lines, its visits. - const head_y = rows.baseline(n.y); - const end = o.address(n.x + m.side, head_y, n.start, .{ .ink = ui.rgb(theme.color.region.code_) }); - var buf: [256]u8 = undefined; - var first_line: ?u32 = null; - var last_line: ?u32 = null; - var at = n.start; - const i = now.stops[0]; - // Its rows, as `insn` takes them (a long block: four, `more`, four). - var list: std.ArrayList(disasm.Insn) = .empty; - while (at < n.start + n.len) { - const one = rec.instruction(i, at, &buf) orelse break; - list.append(o.f.scratch, .{ .addr = at, .len = one.len, .text = o.print("{s}", .{one.text}), .line = one.line, .params = one.params, .bare = true }) catch break; - if (one.line) |l| { - first_line = @min(first_line orelse l, l); - last_line = @max(last_line orelse l, l); - } - at += one.len; - } - const micro = theme.size.sans.micro; - if (first_line) |a| o.text(.sans, micro, end + 16, n.y + m.tag - 6, if (a == last_line.?) o.print("line {d}", .{a}) else o.print("lines {d} to {d}", .{ a, last_line.? }), t.faint); - const strike: ?ui.Heat = if (v.leave) |l| (if (v.g.edges[l.edge].to == k) landing(now, now.plan.advance + now.plan.travel + time.leave.count) else null) else null; - number(o, .mono, size, n.x + w - m.side, head_y, true, was.visits, n.visits, t.primary, strike, if (seen >= 0.5) theme.color.raised else theme.color.page, v.p, "\u{00d7}"); - - // Where the mark is, and was: the plaque leaves its row as the mark sets off, and lands with it. - const pcs = [2]u64{ rec.register(now.stops[1], "rip"), rec.register(now.stops[0], "rip") }; - var shows = [2]f32{ 1 - v.p, v.p }; - if (v.leave) |l| shows = .{ 1 - clamp01((now.time - now.plan.advance) / time.leave.count), clamp01(l.landed / time.leave.count) }; - if (pcs[0] == pcs[1]) shows = .{ 0, 1 }; - // What the annotation reads as current (the moment the mark stands for), and the rows that ran in the last three steps. - const going = now.advancing(); - const base: usize = if (going >= 0.5) 0 else 1; - const current_line = rec.own[now.marked()]; - const annotated = g.here == k and now.plan.gait != .sprint; - const sprinting = now.plan.gait == .sprint and !now.resting(); - const echo = disasm.jumpEcho(now, base); - var covered: usize = 0; - var line_before: ?u32 = null; - const long = n.shown < n.rows; - // Its rows' annotations stay in it: a call's arguments hang no further than its last row. - const top = @max(n.y, body.y); - const under = @min(n.y + n.h, body.y + body.h); - if (under > top) o.clip(.{ .x = body.x, .y = top, .w = body.w, .h = under - top }); - var y = n.y + m.tag; - for (list.items, 0..) |row, j| { - if (long and j >= gm.keep and j < list.items.len - gm.keep) { - if (j == gm.keep) { - _ = o.arrow(n.x + gm.offset - 36, y + m.row / 2, .more); - o.text(.mono, size, n.x + gm.mnemonic, rows.baseline(y), o.print("{d} rows", .{list.items.len - 2 * gm.keep}), t.faint); - y += m.row; - } - continue; - } - const rr: ui.Rect = .{ .x = n.x, .y = y, .w = w, .h = m.row }; - @import("map.zig").row(.disasm, row.addr, o, rr); - for (pcs, shows) |pc, a| if (pc == row.addr and a > 0) { - const lit = o.faded(a); - lit.current(.{ .x = n.x + theme.stroke.rule, .y = y, .w = w - 2 * theme.stroke.rule, .h = m.row }, theme.metric.plaque.pc, now.fires(.disasm)); - sk.draw.polygon(o.f, &.{ .{ n.x + 20, y + m.row / 2 }, .{ n.x + 10, y + 6 }, .{ n.x + 10, y + m.row - 6 } }, lit.at.pen(.{ .fill = ui.rgb(theme.mark(.current).on_solid) })); - }; - const ran = if (annotated) ranAt(now, base, row.addr) else null; - if (ran) |rn| if (row.addr != pcs[1]) o.trail(n.x + theme.metric.insn.mark, y, rn.k); - // The offset where the address was. - const off = o.print("+{x}", .{row.addr - g.start}); - o.text(.mono, size, n.x + gm.offset - o.width(.mono, size, off), rows.baseline(y), off, t.faint); - const lit = o.moved(n.x - gm.shift, 0); - if (annotated and !sprinting) { - const state: disasm.Disasm.State = if (row.addr == rec.register(now.marks[if (going >= 0.5) 1 else 0], "rip")) .current else if (ran) |rn| .{ .ran = rn } else .ahead; - const hangs = d.insn(lit, now, row, y, w + gm.shift, 0, row.line, row.line != line_before, current_line, 0, state, base, covered > 0, .{ g.start, g.start + g.len }, echo); - covered = @max(covered -| 1, hangs); - } else { - if (row.line) |l| if (row.line != line_before) { - const num = o.print("{d}", .{l}); - o.text(.mono, size, n.x + gm.line - o.width(.mono, size, num), rows.baseline(y), num, t.faint); - }; - disasm.bareRow(lit, row, y); - } - line_before = row.line; - // A call that comes back: out of the block's side and in again a row down, the callee named. - if (std.mem.eql(u8, row.mnemonic(), "call") and !ui.strokes) if (disasm.target(row)) |to| { - const ink = if (n.visits > 0) t.dim else theme.color.rule; - const back = !(j + 1 == list.items.len and n.end == .noreturn); - const hx = n.x + w; - if (back) o.route(&.{ .{ hx, y + m.row / 2 }, .{ hx + gm.hook + 6, y + m.row / 2 }, .{ hx + gm.hook + 6, y + 1.5 * m.row }, .{ hx + 1, y + 1.5 * m.row } }, ink, .{ .width = theme.stroke.rule, .head = .{ 7, 8 }, .radius = 6 }) else o.route(&.{ .{ hx, y + m.row / 2 }, .{ hx + gm.hook + 6, y + m.row / 2 } }, ink, .{ .width = theme.stroke.rule, .head = null }); - const callee = ui.symbol(o, rec.strings.get(to) orelse ""); - o.text(.mono, size, hx + gm.hook + 6 + adv, rows.baseline(y) + m.row / 2, callee[0 .. std.mem.lastIndexOfScalar(u8, callee, '+') orelse callee.len], t.primary); - }; - y += m.row; - } - o.clip(body); - // How it ends, under it: the way out (a return, a call that does not return), a tail call, an indirect jump. - const ink = if (n.visits > 0) t.dim else theme.color.rule; - const cx = n.x + n.w / 2; - const bottom = n.y + n.h; - switch (n.end) { - .ret, .noreturn => { - o.fill(.{ .x = cx - 1, .y = bottom, .w = theme.stroke.rule, .h = gm.exit_stub }, ink); - o.fill(.{ .x = cx - gm.exit_bar / 2, .y = bottom + gm.exit_stub, .w = gm.exit_bar, .h = 3 }, ink); - }, - .tail => { - o.fill(.{ .x = cx - 1, .y = bottom, .w = theme.stroke.rule, .h = 24 }, ink); - if (n.out) |to| { - const callee = ui.symbol(o, rec.strings.get(to) orelse ""); - o.text(.mono, size, cx + 8, rows.baseline(bottom + 6), callee[0 .. std.mem.lastIndexOfScalar(u8, callee, '+') orelse callee.len], t.primary); - } - }, - .indirect => { - o.fill(.{ .x = cx - 1, .y = bottom, .w = theme.stroke.rule, .h = 24 }, ink); - _ = o.arrow(cx - 8, bottom + 30, .more); - o.text(.sans, micro, cx + 60, bottom + 36, "targets not known", t.faint); - }, - else => {}, - } - } -}; - -/// The step (`k` steps ago, 0 newest) a row last ran in, of the three the -/// mark's trail is (by the stops `base` on), and the moment it ran at. -fn ranAt(now: cursors.Now, base: usize, addr: u64) ?disasm.Disasm.Ran { - for (0..3) |k| { - const first = now.stops[@min(base + 1 + k, now.stops.len - 1)]; - const last = now.stops[base + k]; - var at = last; - while (at > first and last - at < 4096) { - at -= 1; - if (now.rec.register(at, "rip") == addr) return .{ .k = k, .at = at }; - } - } - return null; -} - -test "a loop's back edge climbs, the hot path is straight down, a never-taken target sits right of its block" { +test "a loop's back edge climbs its lane in layers, the fall-through straight down, a taken target right of its branch" { // sort's shape: entry, the outer loop's test, its body, the inner test, // the compare, the swap, the outer step, the exit. var nodes = [_]Node{ @@ -1401,39 +2057,49 @@ test "a loop's back edge climbs, the hot path is straight down, a never-taken ta .{ .start = 0xaa, .len = 0x04, .end = .ret }, // B7 }; for (&nodes) |*nd| { - nd.w = 300; - nd.h = 52; + nd.w = 116; + nd.h = 24; } var edges = [_]Edge{ - .{ .from = 0, .to = 6, .kind = .jump, .total = 1 }, - .{ .from = 1, .to = 3, .kind = .jump, .total = 7 }, - .{ .from = 2, .to = 3, .kind = .fall, .total = 10 }, - .{ .from = 3, .to = 5, .kind = .taken, .total = 0 }, - .{ .from = 3, .to = 4, .kind = .fall, .total = 17 }, - .{ .from = 4, .to = 2, .kind = .taken, .total = 10 }, - .{ .from = 4, .to = 5, .kind = .fall, .total = 7 }, - .{ .from = 5, .to = 6, .kind = .fall, .total = 7 }, - .{ .from = 6, .to = 1, .kind = .taken, .total = 7 }, - .{ .from = 6, .to = 7, .kind = .fall, .total = 1 }, + .{ .from = 0, .to = 6, .kind = .jump }, + .{ .from = 1, .to = 3, .kind = .jump }, + .{ .from = 2, .to = 3, .kind = .fall }, + .{ .from = 3, .to = 5, .kind = .taken }, + .{ .from = 3, .to = 4, .kind = .fall }, + .{ .from = 4, .to = 2, .kind = .taken }, + .{ .from = 4, .to = 5, .kind = .fall }, + .{ .from = 5, .to = 6, .kind = .fall }, + .{ .from = 6, .to = 1, .kind = .taken }, + .{ .from = 6, .to = 7, .kind = .fall }, }; - var g: Graph = .{ .start = 0, .len = 0xae, .nodes = &nodes, .edges = &edges, .here = null, .text = true, .exact = true }; - place(&g, metricOf(.map)); + var g: Graph = .{ .start = 0, .len = 0xae, .nodes = &nodes, .edges = &edges, .spans = &.{}, .here = null, .text = true, .exact = true }; + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + try place(arena.allocator(), &g, .layers); // Two loops: the inner turns from the swap, the outer from its step. try std.testing.expect(edges[2].back and edges[7].back); for (edges, 0..) |e, k| if (k != 2 and k != 7) try std.testing.expect(!e.back); // Layers by the longest path; the exit last, alone. const want = [_]u32{ 0, 2, 5, 3, 4, 5, 1, 6 }; for (nodes, want) |nd, l| try std.testing.expectEqual(l, nd.layer); - // The hot path straight down; the step beside the swap. - for ([_]usize{ 0, 1, 2, 3, 4, 6, 7 }) |k| try std.testing.expectEqual(@as(u32, 0), nodes[k].col); - try std.testing.expectEqual(@as(u32, 1), nodes[5].col); - // The outer loop's lane outermost; a back edge climbs into its header's head from the left. + // The outer loop's lane outermost; a back edge climbs into its header's end from the left. try std.testing.expect(edges[7].lane == 0 and edges[2].lane == 1); const turn = edges[7].path(); - try std.testing.expect(turn[3][1] < turn[2][1] and turn[4][0] < nodes[6].x); - // The exit's edge would cross the loop's blocks: it runs in the right channel. - try std.testing.expectEqual(@as(u8, 6), edges[9].n); - try std.testing.expectEqual(g.channel, edges[9].points[2][0]); + try std.testing.expect(turn[turn.len - 1][0] <= nodes[6].x + 0.5 and @abs(turn[turn.len - 1][1] - (nodes[6].y + 12)) < 0.01); + // A taken target right of its branch; a fall-through under it. + try std.testing.expect(nodes[2].col == nodes[4].col + 1 and nodes[4].col == nodes[3].col); // Every forward edge ends on its target's top. - for (edges) |e| if (!e.back) try std.testing.expectEqual(nodes[e.to].y, e.points[e.n - 1][1]); + for (edges) |e| if (!e.back) try std.testing.expectApproxEqAbs(nodes[e.to].y, e.points[e.n - 1][1], 0.01); +} + +test "a way's corners are quarter circles, and its length is along them" { + const p = rounded(&.{ .{ 0, 0 }, .{ 0, 100 }, .{ 100, 100 } }, 16); + var e: Edge = .{ .from = 0, .to = 0, .kind = .fall }; + e.set(&p); + // Two straights of 84 and a quarter of a circle of 16. + try std.testing.expectApproxEqAbs(2 * 84 + pi * 8, e.length(), 0.2); + const mid, const dir = e.at(e.length() / 2); + try std.testing.expect(mid[0] > 0 and mid[1] > 84 and dir[0] > 0 and dir[1] > 0); + // Every point on the bend is 16 from its centre. + for (e.path()) |q| if (q[1] > 84 and q[0] < 16) try std.testing.expectApproxEqAbs(@as(f32, 16), dist(q, .{ 16, 84 }), 0.01); } diff --git a/anim/src/loupe.zig b/anim/src/loupe.zig index 4ffe860..d3ae878 100644 --- a/anim/src/loupe.zig +++ b/anim/src/loupe.zig @@ -118,10 +118,10 @@ pub const Loupe = struct { const b = back.apply(.{ px[2], px[3] }); pointer = .{ .x = a[0], .y = a[1], .w = b[0] - a[0], .h = b[1] - a[1] }; target = row.fields.base; - // From the band's view it lies over the stack, never the registers (what a step changes there is what the captions are about). + // From the band's view it lies over the stack's first rows, its tag on the stack's, never over the registers (what a step changes there is what the captions are about). const stack = l.stage.box(u.at, .stack); const h = theme.layout.panelH(k.rows); - return .{ .box = .{ .x = stack.x, .y = stack.y + stack.h - h, .w = k.width, .h = h }, .pointer = pointer, .target = target, .first = target, .ink = rows.ink(rows.regionOf(moment, target)) }; + return .{ .box = .{ .x = stack.x, .y = stack.y, .w = k.width, .h = h }, .pointer = pointer, .target = target, .first = target, .ink = rows.ink(rows.regionOf(moment, target)) }; }, } if (target == 0) return null; diff --git a/anim/src/map.zig b/anim/src/map.zig index ee1d2a1..eaec991 100644 --- a/anim/src/map.zig +++ b/anim/src/map.zig @@ -119,7 +119,7 @@ pub fn content(w: f32) f32 { /// lens's view, the registers, and in the rest the stack going on /// (`continued`), in the third; the stack in the fourth, whole. // shortcut: a column's rest after the disassembly is page: the 5-row dumps round what the registers point at, the open loupes and the key are not built. -pub fn split(rec: *const Recording, lens: bool, way: [2]u64, graph: bool) Split { +pub fn split(rec: *const Recording, band_h: f32, way: [2]u64) Split { const st = theme.map.stage; const c = theme.map.columns; const w = theme.map.column; @@ -132,7 +132,9 @@ pub fn split(rec: *const Recording, lens: bool, way: [2]u64, graph: bool) Split return @floatFromInt(if (n > 0) n else default); } }.of; - const band: Rect = .{ .x = c[0], .y = st.y, .w = w, .h = if (lens) theme.layout.split.subject.band.h else 0 }; + // The drawing as high as the working frame's. + const band: Rect = .{ .x = c[0], .y = st.y, .w = w, .h = band_h }; + const lens = band_h > 0; const source_y = if (lens) band.y + band.h + gap else st.y; // The backtrace as long as the call chain gets over the scene's way: packed once, never repacked under the eye. const bt_rows = @max(want(.backtrace, 0), deepest(rec, way)); @@ -159,25 +161,6 @@ pub fn split(rec: *const Recording, lens: bool, way: [2]u64, graph: bool) Split return .{ .x = r.x, .y = y, .w = r.w, .h = @max(bottom - y, 0) }; } }.under; - // The disassembly as its graph (`graph.Map`): two columns wide beside the - // source, the drawing it is (no band); the registers over the stack in the last. - if (graph) { - const regs: Rect = .{ .x = c[3], .y = st.y, .w = w, .h = panelH(17) }; - const nothing: Rect = .{ .x = c[3], .y = st.y, .w = w, .h = 0 }; - const src: Rect = .{ .x = c[0], .y = st.y, .w = w, .h = panelH(@floatFromInt(@min(rec.most_lines, theme.layout.rowsIn(foot - st.y - gap - panelH(bt_rows))))) }; - const bt: Rect = .{ .x = c[0], .y = src.y + src.h + gap, .w = w, .h = @min(panelH(bt_rows), foot - (src.y + src.h + gap)) }; - return .{ - .band = .{ .x = c[0], .y = st.y, .w = w, .h = 0 }, - .view = nothing, - .source = src, - .disasm = .{ .x = c[1], .y = st.y, .w = c[2] + w - c[1], .h = st.h }, - .registers = regs, - .stack = rest(regs, foot), - .backtrace = bt, - .dump_rows = theme.map.memory_rows, - .spare = .{ rest(bt, foot), .{ .x = c[1], .y = foot, .w = w, .h = 0 } }, - }; - } return .{ .band = band, .view = view, @@ -200,7 +183,8 @@ fn deepest(rec: *const Recording, way: [2]u64) f32 { var seen: ?@TypeOf(rec.depths[0]) = null; var i = way[0]; while (i <= @min(way[1], rec.end())) : (i += 1) { - if (seen != null and rec.depths[i] <= seen.?) continue; + // A recording that counts its calls is read where it goes deeper; one of breakpoints (no calls counted: sqlite's) at every stop. + if (seen != null and rec.depths[i] <= seen.? and rec.len() > 512) continue; seen = rec.depths[i]; var buf: [24]context.Frame = undefined; most = @max(most, context.frames(rec, i, &buf).len); @@ -362,13 +346,34 @@ pub const Map = struct { cursor: ?@import("cursor.zig").Cursor = null, /// The scene's loupes: open, each is a panel of its own on the map (`Spare`). loupes: [2]?*const @import("loupe.zig").Loupe = .{ null, null }, - /// The disassembly is its graph (`graph.Map`): the thread is its digits, - /// no line crosses the lanes; the band's window is the whole graph; the - /// disassembly's, the rows it shows. - graph: bool = false, - /// With `graph`: the stage of the linear disassembly the strip is a - /// column of (the map draws the graph, which is its own whole). - linear: ?*Stage = null, + /// The scene's `unroll`s, each a pane's column out of its strip for a beat (`Unroll` draws them). + unrolls: [4]Unrolled = undefined, + n_unrolls: usize = 0, + + const Unrolled = struct { panel: Panel, veil: anim.Value, grow: anim.Value }; + + /// `unroll`: the pane `panel`'s whole column out of its strip over the + /// frame, for a beat ("the whole function", "the whole stack"): the + /// panes it covers veiled and its strip's window bright (18 f), then the + /// column growing (36 f, `glide`), its window's outline riding from the + /// strip to the pane's rows in it; held until `roll`. + pub fn unroll(m: *Map, s: *anim.Frame, panel: Panel) void { + const u: Unrolled = .{ .panel = panel, .veil = s.value(0), .grow = s.value(0) }; + m.unrolls[m.n_unrolls] = u; + m.n_unrolls += 1; + const t = theme.time.unroll; + s.play(.{u.veil.to(1)}, .{ .seconds = t.veil, .ease = anim.ease.linear }); + s.play(.{u.grow.to(1)}, .{ .seconds = t.grow, .ease = anim.ease.linear }); + } + + /// `roll`: the last `unroll` back into its strip (36 f), the window's + /// outline landing as the strip's window; the veil lifts (18 f). + pub fn roll(m: *Map, s: *anim.Frame) void { + const u = m.unrolls[m.n_unrolls - 1]; + const t = theme.time.unroll; + s.play(.{u.grow.to(0)}, .{ .seconds = t.roll, .ease = anim.ease.linear }); + s.play(.{u.veil.to(0)}, .{ .seconds = t.veil, .ease = anim.ease.linear }); + } /// Which drawings a part is in: the map's, the strips' (what they are /// drawn from: a pane's column, as the linear disassembly the map draws @@ -397,7 +402,7 @@ pub const Map = struct { /// Puts a drawing on the map, in a band of its own over the source, /// for a scene whose working frame has none (its map is split anew). pub fn drawing(m: *Map, s: *anim.Frame, rec: *const Recording, component: anytype) void { - m.stage.first = split(rec, true, if (m.cursor) |c| .{ c.first, c.last } else .{ 0, 0 }, m.graph); + m.stage.first = split(rec, theme.layout.split.subject.band.h, if (m.cursor) |c| .{ c.first, c.last } else .{ 0, 0 }); m.add(s, component); } @@ -485,9 +490,8 @@ pub const Map = struct { const y = std.math.lerp(from.y, box.y, p); // The tags, rules and lanes, and the strips, come in as the map lands. const chrome = std.math.clamp((t - diving.lift) / 12, 0, 1); - // Out of a graph the rows and the lens are another form of what the map shows there: they come in on their way. - const other = m.graph and (i == @intFromEnum(Panel.disasm) or i == @intFromEnum(Panel.band)); - context.zoomed[i] = .{ .box = box, .to = .{ .x = x, .y = y, .w = box.w * scale, .h = box.h * scale }, .chrome = chrome, .shows = if (other) p else 1 }; + // The registers arrive whole from the map and fold as they land: each quiet row glides into its cell. + context.zoomed[i] = .{ .box = box, .to = .{ .x = x, .y = y, .w = box.w * scale, .h = box.h * scale }, .chrome = chrome, .fold = if (i == @intFromEnum(Panel.registers)) p else 1 }; }; } // Each pane's column squeezing into its strip: their places on the map give way first, then they go. @@ -496,8 +500,7 @@ pub const Map = struct { inline else => |tag| @field(working, @tagName(tag)), }; const gone = 1 - stripShows(panel, t); - // The graph's linear column is not on the map: its strip comes in with the tags. - if (box.h > 0 and gone > 0 and windows[@intFromEnum(panel)] != null and !(m.graph and panel == .disasm)) m.squeeze(f, fixed, at, panel, box, ways[@intFromEnum(panel)], .{ .masking = masking, .shows = gone, .veil = veil, .bright = bright }); + if (box.h > 0 and gone > 0 and windows[@intFromEnum(panel)] != null) m.squeeze(f, fixed, at, panel, box, ways[@intFromEnum(panel)], .{ .masking = masking, .shows = gone, .veil = veil, .bright = bright }); }; } @@ -620,7 +623,7 @@ pub const Map = struct { ui.mapping = true; counts = @splat(0); for (m.parts[0..m.n]) |p| if (p.in != .strips) p.draw(p.ctx, f, at); - if (m.cursor) |c| if (!m.graph) m.thread(f, at, c.now(at)); + if (m.cursor) |c| m.thread(f, at, c.now(at)); ui.mapping = false; } @@ -671,8 +674,7 @@ pub const Map = struct { inline for (.{ "band", "view", "source", "disasm", "registers", "stack", "backtrace" }) |name| { const panel = @field(Panel, name); const i = @intFromEnum(panel); - // The lens drawing the graph is: its window is the graph whole. - const box = if (m.graph and panel == .band) split_.disasm else @field(split_, name); + const box = @field(split_, name); if (box.h > 0) { const a = at.xf.apply(.{ box.x, box.y }); const b = at.xf.apply(.{ box.x + box.w, box.y + box.h }); @@ -687,16 +689,10 @@ pub const Map = struct { r[1] = std.math.lerp(from[0], to[0], win.p); r[3] = std.math.lerp(from[1], to[1], win.p); shown = true; - // In a graph the rows a window shows are in blocks: round them, not the panel's width. - if (m.graph and panel == .disasm) if (boxOf(i, win.now)) |round| { - const was_box = boxOf(i, win.was) orelse round; - r[0] = std.math.lerp(was_box[0], round[0], win.p); - r[2] = std.math.lerp(was_box[2], round[2], win.p); - }; } } window_px[i] = if (shown) r else null; - const rides = riding and slotOf(panel) != null and !(m.graph and panel == .disasm); + const rides = riding and slotOf(panel) != null; if (shown and !rides) { const w = theme.map.outline * k; const out = theme.map.outline_out * k; @@ -714,7 +710,7 @@ pub const Map = struct { const none: Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }; return switch (panel) { .source => .{ sp.source, sp.source_more }, - .disasm => .{ if (m.linear) |l| l.now(at).disasm else sp.disasm, none }, + .disasm => .{ sp.disasm, none }, .stack => .{ sp.stack, sp.more }, .view => .{ sp.view, none }, else => .{ none, none }, @@ -949,6 +945,127 @@ pub const Map = struct { } }; +/// A pane's far jump in its own column at a walk, this frame (the pane +/// publishes it as it draws; `Unroll` draws it and clears it): how far +/// the column has grown out of its strip (0 to 1, before its `glide`) and +/// how far the panes it covers are veiled. +pub var jumping: ?struct { panel: Panel, grow: f32, veil: f32 } = null; + +/// `unroll` and `roll` drawn (design/README.md, "6. Verbs"; motion.md, +/// "The map and the working frame"): the column grows out of the strip +/// over the pane and the panes under it, a row of the map's 4 units +/// scaling on its logarithm to as many as the stage holds (24 a row where +/// the column is short enough to read, to fit where it is long), right on +/// the strip's right edge, the pane's window in it level with the pane's +/// rows where the stage allows; the window's outline rides from the strip +/// to its rows in the column. Added last (`Context.ties`): it lies over +/// everything in the frame but the caption and the clock. +pub const Unroll = struct { + map: *const Map, + + pub fn draw(un: *const Unroll, f: *sk.Frame, placed: anim.Placed) void { + const m = un.map; + defer jumping = null; + if (ui.mapping or looking(f) or !m.settled(placed)) return; + var panel: Panel = .source; + var grow: f32 = 0; + var veil: f32 = 0; + for (m.unrolls[0..m.n_unrolls]) |u| { + const v = placed.value(u.veil); + if (v <= 0) continue; + panel = u.panel; + grow = placed.value(u.grow); + veil = v; + } + if (jumping) |j| { + panel = j.panel; + grow = j.grow; + veil = j.veil; + } + if (veil <= 0) return; + const fixed = @import("words.zig").fixed(f, placed, 0); + fixed.veil(theme.canvas.stage, veil); + m.strips(f, fixed.at); + const slot = slotOf(panel) orelse return; + const col = &atlas.columns[slot]; + if (col.n == 0 or col.rows <= 0) return; + const working = m.frame.now(placed); + const box = switch (panel) { + inline else => |tag| @field(working, @tagName(tag)), + }; + // The strip's window goes bright over the veil's first third (6 f), never in a frame. + unrolled(m, f, fixed, panel, box, col, theme.ease(.glide, grow), std.math.clamp(veil * 3, 0, 1)); + } +}; + +/// A pane's column `q` of its way (eased) from its strip to unrolled, in +/// `fixed` (the canvas's units). +fn unrolled(m: *const Map, f: *sk.Frame, fixed: ui.Ui, panel: Panel, box: Rect, col: *const Column, q: f32, bright: f32) void { + const st = theme.strip; + const cm = theme.metric.context; + const stage = theme.canvas.stage; + const r = stripRect(box); + const cap = @floor((r.h - st.top - st.foot) / st.pitch); + const win = windowOn(panel, col) orelse .{ 0, 0 }; + const first = firstShown(col, win, cap); + // Unrolled: as many rows as the stage holds, 24 a row at most. + const a = @min(cm.row, stage.h / col.rows); + const k1 = a / cm.row; + const h1 = col.rows * a; + const w1 = theme.map.column * k1; + const pane_mid = box.y + cm.tag + cm.pad + @as(f32, @floatFromInt(theme.layout.rowsIn(box.h))) * cm.row / 2; + const y1 = std.math.clamp(pane_mid - (win[0] + win[1] + 1) / 2 * a, stage.y, @max(stage.y + stage.h - h1, stage.y)); + const x1 = @max(r.x + r.w - w1, stage.x); + // Its scale on the logarithm, from the strip's (36 of 880 across, 4 of 24 a row) to the unrolled. + const kx = std.math.pow(f32, st.across, 1 - q) * std.math.pow(f32, k1, q); + const ky = std.math.pow(f32, @as(f32, st.pitch) / cm.row, 1 - q) * std.math.pow(f32, k1, q); + // The window rides: its first row from its place on the strip to its place in the column. + const wy = std.math.lerp(r.y + st.top + (win[0] - first) * st.pitch, y1 + win[0] * a, q); + const oy = wy - win[0] * cm.row * ky; + const ox = std.math.lerp(r.x + st.left, x1, q); + // What shows: the strip's rows at first, the column whole at last. + const top = std.math.lerp(r.y + st.top, y1, q); + const bottom = std.math.lerp(r.y + st.top + @min(cap, col.rows - first) * st.pitch, y1 + h1, q); + const left = std.math.lerp(r.x, x1, q); + const right = std.math.lerp(r.x + r.w, x1 + w1, q); + // Over the strip as it grows out of it, and gone into it as it lands: the strip's own drawing crossfades under it. + const lifts = std.math.clamp(q * 8, 0, 1); + if (q > 0) fixed.faded(lifts).fill(.{ .x = left - 4, .y = top - 4, .w = right - left + 8, .h = bottom - top + 8 }, theme.color.page); + var offset: f32 = 0; + for (m.column(fixed.at, panel)) |b| { + if (q <= 0) break; + if (b.h <= 0) continue; + const n: f32 = @floatFromInt(theme.layout.rowsIn(b.h)); + defer offset += n; + const body = b.y + cm.tag + cm.pad; + // The rows of this box inside what shows, in rows from the column's top. + const lo = std.math.clamp((top - oy) / (cm.row * ky), offset, offset + n); + const hi = std.math.clamp((bottom - oy) / (cm.row * ky), offset, offset + n); + if (hi <= lo) continue; + var moved = fixed.at; + moved.xf = fixed.at.xf.mul(.translate(ox, oy)).mul(.scale(kx, ky)).mul(.translate(-b.x, -(body - offset * cm.row))); + moved.scale = fixed.at.scale * ky; + // The text comes in over the strip's strokes as it starts to grow. + moved.pose.opacity *= lifts; + const u: ui.Ui = .{ .f = f, .at = moved }; + // Its parts clip to their own boxes inside this one's rows (`ui.bound`). + const rows_rect: Rect = .{ .x = b.x, .y = body + (lo - offset) * cm.row, .w = b.w, .h = (hi - lo) * cm.row }; + const a0 = moved.xf.apply(.{ rows_rect.x, rows_rect.y }); + const a1 = moved.xf.apply(.{ rows_rect.x + rows_rect.w, rows_rect.y + rows_rect.h }); + ui.bound = .{ .x = @round(a0[0]), .y = @round(a0[1]), .w = @round(a1[0]) - @round(a0[0]), .h = @round(a1[1]) - @round(a0[1]) }; + u.clip(rows_rect); + m.drawPanel(f, moved, panel); + ui.bound = null; + u.unclip(); + } + // The window's outline, the strip's framed bright as it begins (and as it ends), riding to round the pane's rows in the column. + const wt = oy + win[0] * cm.row * ky; + const wb = oy + (win[1] + 1) * cm.row * ky; + // On the strip it is the strip's window's own frame (primary, `bright` of the way to bright). + const ink = ui.mix(theme.color.text.primary, theme.color.text.bright, bright); + fixed.frame(.{ .x = std.math.lerp(r.x, left - st.window, q), .y = wt - st.window, .w = std.math.lerp(st.w, right - left + 2 * st.window, q), .h = wb - wt + st.window + std.math.lerp(1, st.window, q) }, ink, st.window); +} + /// The most rows a column has in the strips' images. const atlas_rows = 160; @@ -1004,9 +1121,13 @@ fn pastWindows(now: u64, back: u64) [7]?Window { /// was and where it is, as far as its scroll had gone. fn spanOf2(maybe: ?Window, col: *const Column) ?[2]f32 { const win = maybe orelse return null; - const is = col.span(win.now) orelse return null; - const was = col.span(win.was) orelse is; - return .{ std.math.lerp(was[0], is[0], win.p), std.math.lerp(was[1], is[1], win.p) }; + // A window going farther than the column holds (another place in a long + // file, another function) is where the column is: where it was until the + // column goes over with the pane, then where it is. + const was = col.span(win.was); + const is = col.span(win.now) orelse return was; + const from = was orelse is; + return .{ std.math.lerp(from[0], is[0], win.p), std.math.lerp(from[1], is[1], win.p) }; } /// The map whose columns the strips are (`context` sets it). diff --git a/anim/src/root.zig b/anim/src/root.zig index 78da9dc..dca9a60 100644 --- a/anim/src/root.zig +++ b/anim/src/root.zig @@ -247,22 +247,32 @@ pub const Context = struct { /// callee's window under the call row, and a system call the /// kernel's under the `syscall` (step with `descent.step`). descent: bool = false, - /// On the map the disassembly as the function's graph (`graph.Map`), - /// two columns wide beside the source, the registers and the stack - /// in the last column. + /// On the map the function's graph as the `blocks` lens draws it + /// (`graph.Blocks`), the map's drawing over the source; the + /// disassembly beside it linear, its blocks ruled. graph: bool = false, }; /// The ties between the panes, drawn over everything added before. pub fn ties(c: Context, s: *anim.Frame) anim.Obj { - return add(s, Ties{ .cursor = c.cursor, .stage = c.stage, .quiet = c.quiet }); + const obj = add(s, Ties{ .cursor = c.cursor, .stage = c.stage, .quiet = c.quiet }); + c.unrolls(s); + return obj; + } + + /// Over everything added before: a pane's column unrolled (`map.Unroll`). + fn unrolls(c: Context, s: *anim.Frame) void { + const o = add(s, map.Unroll{ .map = c.map }); + s.play(.{o.fadeIn()}, .{ .seconds = 0 }); } /// The ties, and a link the scene plays on a beat of its own (`Beat.play`): /// register `name` framed as read, then linked to what it points at, held `hold`. pub fn tiesWith(c: Context, s: *anim.Frame, name: []const u8, hold: f32) struct { anim.Obj, *const tying.Beat } { const beat = s.new(tying.Beat{ .cursor = c.cursor, .name = name, .hold = hold, .t = s.value(-1) }); - return .{ add(s, Ties{ .cursor = c.cursor, .stage = c.stage, .quiet = c.quiet, .beat = beat }), beat }; + const obj = add(s, Ties{ .cursor = c.cursor, .stage = c.stage, .quiet = c.quiet, .beat = beat }); + c.unrolls(s); + return .{ obj, beat }; } /// A scene's opening with a lens drawn from bytes (`nodes`, `array`): @@ -285,21 +295,24 @@ pub const Context = struct { }; pub fn context(s: *anim.Frame, cursor_: Cursor, options: Context.Options) Context { - const stage = Stage.init(s, options.split); + // 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 registers_rows: f32 = @floatFromInt(contexts.registerRows(moves)); + const stage = Stage.init(s, layout.fit(options.split, registers_rows)); + stage.registers_rows = registers_rows; var at = cursor_; at.levels.crossings = options.syscalls; // The map first: while it fills the frame it is under the panels diving out of it. - const whole = s.new(map.Map{ .stage = Stage.init(s, map.split(at.rec, options.split.band.h > 0, .{ at.first, at.last }, options.graph)), .frame = stage, .t = s.value(map.diving.land + map.diving.still), .cursor = at, .graph = options.graph }); + const whole = s.new(map.Map{ .stage = Stage.init(s, map.split(at.rec, options.split.band.h, .{ at.first, at.last })), .frame = stage, .t = s.value(map.diving.land + map.diving.still), .cursor = at }); whole.obj = s.custom(whole, .{ .x = -640, .y = -360, .scale = ui.scale }); whole.addIn(s, Source{ .cursor = at, .stage = whole.stage, .descent = options.descent }, .both, .source); whole.addIn(s, Source{ .cursor = at, .stage = whole.stage, .descent = options.descent, .part = .source_more }, .both, .source); + // The graph on the map is the lens's drawing at its size, over the source. + if (options.graph) whole.add(s, graph.Blocks{ .cursor = at, .stage = whole.stage }); // The disassembly's strip is its linear column: where the map draws a - // graph or a descent, the rows round the pc are drawn for the strip alone. - if (options.graph) { - whole.linear = Stage.init(s, map.split(at.rec, options.split.band.h > 0, .{ at.first, at.last }, false)); - whole.addIn(s, graph.Map{ .cursor = at, .stage = whole.stage }, .map, .disasm); - whole.addIn(s, Disasm{ .cursor = at, .stage = whole.linear.?, .measures = false }, .strips, .disasm); - } else if (options.descent) { + // descent, the rows round the pc are drawn for the strip alone. + if (options.descent) { whole.addIn(s, Descent{ .cursor = at, .stage = whole.stage }, .map, .disasm); whole.addIn(s, Disasm{ .cursor = at, .stage = whole.stage, .measures = false }, .strips, .disasm); } else whole.addIn(s, Disasm{ .cursor = at, .stage = whole.stage }, .both, .disasm); @@ -318,7 +331,7 @@ pub fn context(s: *anim.Frame, cursor_: Cursor, options: Context.Options) Contex .quiet = options.quiet, .source = add(s, Source{ .cursor = at, .stage = stage, .descent = options.descent }), .disasm = if (options.descent) add(s, Descent{ .cursor = at, .stage = stage }) else add(s, Disasm{ .cursor = at, .stage = stage }), - .registers = add(s, Registers{ .cursor = at, .stage = stage, .syscalls = options.syscalls, .quiet = options.quiet }), + .registers = add(s, Registers{ .cursor = at, .stage = stage, .syscalls = options.syscalls, .quiet = options.quiet, .moves = moves }), .stack = add(s, Stack{ .cursor = at, .stage = stage }), .backtrace = add(s, Backtrace{ .cursor = at, .stage = stage, .lens = options.backtrace }), .clock = add(s, Clock{ .cursor = at, .map = whole }), diff --git a/anim/src/rows.zig b/anim/src/rows.zig index f82bb81..03c5898 100644 --- a/anim/src/rows.zig +++ b/anim/src/rows.zig @@ -122,7 +122,7 @@ pub fn chain(u: ui.Ui, x: f32, y: f32, moment: Recording.Moment, value: u64, roo const shown = ui.Value.of(link.value, pointer); const w = shown.width(); // The hops after a struck first one are followed again, one at a time. - const followed: f32 = if (marks.extend) |e| std.math.clamp((e - @as(f32, @floatFromInt(i -| 1)) * theme.time.unroll) / (6.0 / 60.0), 0, 1) else 1; + const followed: f32 = if (marks.extend) |e| std.math.clamp((e - @as(f32, @floatFromInt(i -| 1)) * theme.time.extend) / (6.0 / 60.0), 0, 1) else 1; const v = if (i > 0) u.faded(followed * marks.hops) else u; if (i > 0) { const named: f32 = if (link.region == .code and link.text.len > 0 and !link.string) 10 + @as(f32, @floatFromInt(link.text.len)) * adv else 0; @@ -148,6 +148,16 @@ pub fn chain(u: ui.Ui, x: f32, y: f32, moment: Recording.Moment, value: u64, roo if (marks.read == i) v.read(marked, marks.read_shows); if (pointer) { _ = v.address(at, base, link.value, .{ .ink = face_ink.ink, .face = face_ink.face, .lead = if (i == 0) marks.lead else 0, .rwx = link.region == .rwx }); + } else if (i == 0 and at + w > room) { + // A word too long for its row's room (a stack word beside its role): cut, with `…`. + const all = u.print("{s}{s}", .{ shown.prefix, shown.digits() }); + const fits: usize = @intFromFloat(std.math.clamp((room - at) / adv, 2, @as(f32, @floatFromInt(all.len)))); + v.text(face_ink.face, size, at, base, u.print("{s}\u{2026}", .{all[0 .. fits - 1]}), face_ink.ink); + at += @as(f32, @floatFromInt(fits)) * adv; + hops.x[0] = at - @as(f32, @floatFromInt(fits)) * adv; + hops.w[0] = @as(f32, @floatFromInt(fits)) * adv; + hops.n = 1; + break; } else _ = v.value(at, base, link.value, false, face_ink); if (hops.n < hops.x.len) { hops.x[hops.n] = at; @@ -198,6 +208,27 @@ pub fn reg(u: ui.Ui, y: f32, w: f32, name: []const u8, moment: Recording.Moment, return chain(u, m.chain_x, y, moment, value, w - m.side, marks); } +/// `registers` `quiet`: a register the scene never changes, in its cell +/// at `x`: its name faint, its value 48 in, in its ink; a pointer's chain +/// cut to `more` at once (a code address alone: its name is on the map), +/// framed as read while a step reads it (`read_shows`). +pub fn quiet(u: ui.Ui, x: f32, y: f32, name: []const u8, moment: Recording.Moment, value: u64, read_shows: f32) Hops { + u.text(.mono, size, x, baseline(y), name, t.faint); + const vx = x + theme.metric.registers.quiet_value; + const region = regionOf(moment, value); + const pointer = region != .none; + const shown = ui.Value.of(value, pointer); + if (read_shows > 0) u.read(.{ .x = vx, .y = y, .w = shown.width(), .h = row_h }, read_shows); + var hops: Hops = .{ .n = 1, .end = vx + shown.width() }; + hops.x[0] = vx; + hops.w[0] = shown.width(); + if (pointer) { + _ = u.address(vx, baseline(y), value, .{ .ink = ui.rgb(ink(region)), .rwx = region == .rwx }); + if (region != .code) hops.end = u.arrow(hops.end, y + row_h / 2, .more) + 24; + } else _ = u.value(vx, baseline(y), value, false, .{ .ink = ui.rgb(t.primary) }); + return hops; +} + /// The flags, in rip's row: their names, the value. pub const Flag = struct { name: []const u8, bit: u6 }; pub const flags = [_]Flag{ .{ .name = "CF", .bit = 0 }, .{ .name = "PF", .bit = 2 }, .{ .name = "AF", .bit = 4 }, .{ .name = "ZF", .bit = 6 }, .{ .name = "SF", .bit = 7 }, .{ .name = "IF", .bit = 9 }, .{ .name = "DF", .bit = 10 }, .{ .name = "OF", .bit = 11 } }; diff --git a/anim/src/source.zig b/anim/src/source.zig index 5a5f1cd..ab49bc0 100644 --- a/anim/src/source.zig +++ b/anim/src/source.zig @@ -64,12 +64,24 @@ pub const Source = struct { // arrives; a scroll of more lines than the window shows would be a // blur, and say nothing. const turn = at[0].src != at[1].src and going < 1; - const far = !turn and @abs(windows[1] - windows[0]) > @as(f32, @floatFromInt(fit)) and going < 1; - const side: usize = if (turn) @intFromBool(going >= 0.5) else if (far) @intFromBool(going >= 0.75) else @intFromBool(going >= 0.5); + // At a walk, a window going farther than its height to lines its + // column on the map has too: the pane `unroll`s to the column, its + // window travels there along it, and it `roll`s back in at its new + // place (`unrolling`, 96 f); the pane goes into the column as it + // grows and comes out of it as it rolls back, never a fade. + const jump = unrolling(rec, now, at, p.cursor.levels.source_rows); + // (On the map, for the strips, half its height: a column scrolling most of its rows would be a smear on a strip.) + const far = !turn and jump == null and @abs(windows[1] - windows[0]) > @as(f32, @floatFromInt(if (ui.mapping) fit / 2 else fit)) and going < 1; + if (jump) |j| if (!ui.mapping and p.part == .source) { + map.jumping = .{ .panel = .source, .grow = j.grow, .veil = j.veil }; + }; + // On the map, for the strip, a far window's column goes over as the advance starts: + // the strip (6 to 11 f behind) shows where the pane goes before the pane fades. + const side: usize = if (jump) |j| @intFromBool(j.travel >= 0.5) else if (turn) @intFromBool(going >= 0.5) else if (far) @intFromBool(if (ui.mapping) going > 0 else going >= 0.75) else @intFromBool(going >= 0.5); const file = rec.sources[at[side].src]; const text = prepared(file.text, file.path) orelse return; - const first = if (turn or far) windows[side] else std.math.lerp(windows[0], windows[1], cursors.glide(going)); - const fade: f32 = if (turn) @abs(2 * going - 1) else if (far) (if (going < 0.5) 1 else @abs(4 * going - 3)) else 1; + const first = if (jump) |j| (if (ui.mapping) std.math.lerp(windows[0], windows[1], cursors.glide(j.travel)) else windows[side]) else if (turn or far) windows[side] else std.math.lerp(windows[0], windows[1], cursors.glide(going)); + const fade: f32 = if (jump) |j| (if (ui.mapping) 1 else 1 - theme.ease(.glide, j.grow)) else if (turn) @abs(2 * going - 1) else if (far and !ui.mapping) (if (going < 0.5) 1 else @abs(4 * going - 3)) else 1; const lit = u.faded(fade); const from: u32 = @intFromFloat(@floor(first)); const last: u32 = @min(from + @as(u32, @intCast(context.rowsOf(box))), file.lines); @@ -92,8 +104,12 @@ pub const Source = struct { // Its tag's file and note change with the fade through it; a note otherwise over the 12 f before the advance. if (turn) for (titles, [2]f32{ 1 - 2 * going, 2 * going - 1 }) |t, shows| u.faded(shows).tagTitle(t, p.focus); if (swap) { - const c = if (turn) std.math.clamp(2 * going - 1, 0, 1) else now.renaming(); - u.faded(if (turn) 1 - 2 * going else 1 - c).tagNote(box.w, notes[0]); + // Through another file, or to lines far off, it changes with the pane's fade: the lines it names are the lines shown. + // A window scrolling: its range changes with the scroll, the lines it names the lines shown (never before them). + const scrolls = std.mem.eql(u8, notes[0], lines_notes[0]) and std.mem.eql(u8, notes[1], lines_notes[1]); + const c = if (jump) |j| std.math.clamp(2 * j.travel - 0.5, 0, 1) else if (turn) std.math.clamp(2 * going - 1, 0, 1) else if (far) std.math.clamp(4 * going - 3, 0, 1) else if (scrolls) cursors.glide(going) else now.renaming(); + const old = if (jump != null) 1 - c else if (turn) 1 - 2 * going else if (far) std.math.clamp(3 - 4 * going, 0, 1) else 1 - c; + u.faded(old).tagNote(box.w, notes[0]); u.faded(c).tagNote(box.w, notes[1]); } const top = body.y + m.pad; @@ -104,7 +120,12 @@ pub const Source = struct { var mark_line = here; var mark_at: f32 = @floatFromInt(here); var shows: f32 = 1; - if (turn or far) { + if (jump) |j| { + // In the column it lights at its new line as the window gets there; in the pane it goes with the pane. + mark_line = if (j.travel >= 0.5) here else was; + mark_at = @floatFromInt(mark_line); + shows = fade; + } else if (turn or far) { // It goes with the fade: out with the old window, in with the new. mark_line = at[side].line; mark_at = @floatFromInt(mark_line); @@ -173,7 +194,7 @@ pub const Source = struct { } }.of; // On the strip the window glides there; a window fading through goes before the fade, so the strip shows where it went first. - map.window(.source, lines_of(windows[1], fit, rec.sources[at[1].src].lines), lines_of(windows[0], fit, rec.sources[at[0].src].lines), if (turn) @floatFromInt(side) else cursors.glide(if (far) @min(2 * going, 1) else going)); + map.window(.source, lines_of(windows[1], fit, rec.sources[at[1].src].lines), lines_of(windows[0], fit, rec.sources[at[0].src].lines), if (jump) |j| cursors.glide(j.travel) else if (turn) @floatFromInt(side) else cursors.glide(if (far) @min(2 * going, 1) else going)); var line = @max(from, 1); while (line <= last) : (line += 1) { const y = top + (@as(f32, @floatFromInt(line)) - first) * m.row; @@ -194,6 +215,41 @@ pub const Source = struct { } }; +/// A walked step whose source window (`fit` lines) goes farther than its +/// own height to lines the map's column holds as well (69 round the line, +/// or the whole file): the far jump in the same column, told by `unroll`, +/// the window's travel and `roll` (design/motion.md, "The map and the +/// working frame"). Where it is in them, 0 to 1 each: how far the column +/// has grown (before its `glide`), the window's travel along it, the veil. +pub fn unrolling(rec: *const Recording, now: cursors.Now, at: [2]Recording.Shown, fit: u32) ?struct { grow: f32, travel: f32, veil: f32 } { + const going = now.advancing(); + // A step said faster in a hurry is no beat for it: it fades through as at a run. + if (!now.walking() or now.hurried > 0 or going <= 0 or going >= 1 or at[0].src != at[1].src) return null; + const w = [2]u32{ rec.shownFirst(fit, at[0]), rec.shownFirst(fit, at[1]) }; + if (!inColumn(rec, at[0].src, w, fit)) return null; + const t = theme.time.unroll; + // Its phases in proportion to the advance's travel (96 f as `Cursor.travel` gives it). + const g = going * (t.grow + t.travel + t.roll); + const back = g - t.grow - t.travel; + return .{ + .grow = if (back <= 0) std.math.clamp(g / t.grow, 0, 1) else 1 - std.math.clamp(back / t.roll, 0, 1), + .travel = std.math.clamp((g - t.grow) / t.travel, 0, 1), + .veil = @min(std.math.clamp(g / t.veil, 0, 1), std.math.clamp((t.grow + t.travel + t.roll - g) / t.veil, 0, 1)), + }; +} + +/// Whether windows of `fit` lines at `w` in source `src` are farther apart +/// than their height and both in the map's column of it (the lines its +/// source panels hold round the line, or the file whole): a far jump the +/// unrolled column can show. +pub fn inColumn(rec: *const Recording, src: u16, w: [2]u32, fit: u32) bool { + const lo = @min(w[0], w[1]); + const hi = @max(w[0], w[1]); + // The map's column as the scene's map packs it (69 lines where there is none). + const column: u32 = if (map.current) |mp| @intCast(theme.layout.rowsIn(mp.stage.first.source.h) + theme.layout.rowsIn(mp.stage.first.source_more.h)) else theme.map.disasm_rows; + return hi - lo > fit and (rec.sources[src].lines <= column or hi + fit - lo <= column); +} + /// The last moment at or before `i` whose pc was on a line the panel can show. fn lastShown(rec: *const Recording, i: u64) u64 { var at = i; diff --git a/anim/src/stage.zig b/anim/src/stage.zig index 35988aa..a03c8bd 100644 --- a/anim/src/stage.zig +++ b/anim/src/stage.zig @@ -29,6 +29,8 @@ pub const Stage = struct { hold_free: anim.Value, /// 0 to 1 as the window goes from where it was to where it is held (and back). hold_in: anim.Value, + /// The registers panel's rows (the scene's, `layout.fit`): every split it changes to keeps them. 0: as the split has it. + registers_rows: f32 = 0, const Move = struct { from: Split, to: Split, p: anim.Value }; @@ -45,7 +47,7 @@ pub const Stage = struct { /// A change of split: every panel glides to its place in `to`. pub fn relayout(st: *Stage, s: *anim.Frame, to: Split) void { const p = s.value(0); - st.moves[st.count] = .{ .from = st.last(), .to = to, .p = p }; + st.moves[st.count] = .{ .from = st.last(), .to = if (st.registers_rows > 0) theme.layout.fit(to, st.registers_rows) else to, .p = p }; st.count += 1; // The drawing fades out (12 f), the panels move, it fades in at its new size. s.play(.{st.drawing.to(0)}, .{ .seconds = theme.time.relayout_fade, .ease = anim.ease.linear }); diff --git a/anim/src/syscalls.zig b/anim/src/syscalls.zig index 3788fe3..c00aec5 100644 --- a/anim/src/syscalls.zig +++ b/anim/src/syscalls.zig @@ -281,7 +281,10 @@ pub const Crossing = struct { const count = if (newest) |n| n + 1 - first else 0; const above = [2]usize{ (count -| 1) -| room, count -| room }; const notes = [2][]const u8{ logNote(u, above[0]), logNote(u, above[1]) }; - const scroll = cursors.glide(arrives); + // From rest it moves at once, a pixel a frame at least: a glide's first + // frames are each under a pixel, and the rows, drawn on whole pixels, + // would step one and stand still a frame. + const scroll = @min(@max(cursors.glide(arrives), arrives * theme.time.move * 60 / (row_h * @max(u.at.scale, 0.01))), 1); const renote = above[0] != above[1] and arrives < 1; const body = u.panel(box.w, box.h, "system calls", .{ .focus = c.focus, .note = if (renote) "" else notes[1] }); if (renote) { diff --git a/anim/src/theme.zig b/anim/src/theme.zig index 156088c..8d4b044 100644 --- a/anim/src/theme.zig +++ b/anim/src/theme.zig @@ -135,43 +135,53 @@ pub const layout = struct { /// and the stack point at, the loupes open and the key (`map.Spare`). spare: [2]Rect = @splat(.{ .x = 0, .y = 0, .w = 0, .h = 0 }), }; + /// Layout A (design/README.md, "5. The frame"): the disassembly under + /// the source in every split; the registers as tall as their rows (the + /// scene's: `fit`), the stack what the state column has left. The + /// splits here are for a panel of eleven rows (sort's), as the + /// catalogue's table is. pub const split = struct { /// The machine alone: fourteen lines over seventeen instructions; - /// the registers, eight words and four frames of backtrace. - pub const none: Split = blk: { - const registers = rows(state, 0, 17); - const stack = below(registers, 8); - break :blk .{ .band = .{ .x = program.x, .y = canvas.stage.y, .w = program.w, .h = 0 }, .view = .{ .x = state.x, .y = canvas.stage.y, .w = state.w, .h = 0 }, .source = rows(program, 0, 14), .disasm = below(rows(program, 0, 14), 17), .registers = registers, .stack = stack, .backtrace = below(stack, 4), .dump_rows = 0 }; - }; + /// the registers, the stack and four frames of backtrace at the foot. + pub const none: Split = shared(0, 0, 14, 17, 0, 4); /// The machine is the subject and the lens beside it: a drawing /// and its view of 152 (a dump of five); eight lines over - /// seventeen instructions; the registers over eight words. - pub const beside: Split = shared(152, 152, 8, 17, 8, 5); + /// seventeen instructions; the registers over the stack. + pub const beside: Split = shared(152, 152, 8, 17, 5, 0); /// The idea is the subject: the drawing 296 high and a size up, - /// 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; - }; + /// its view 200 (a dump of seven); eight lines over eleven + /// instructions; the registers over the stack. + pub const subject: Split = shared(296, 200, 8, 11, 7, 0); + /// The `blocks` lens: its drawing (the graph) 880 by 344 over the + /// program column and no view (its rows are the disassembly under + /// the source: six lines over eleven); the state column the + /// registers' and the stack's from the top. + pub const blocks: Split = shared(344, 0, 6, 11, 0, 0); - fn shared(drawing_h: f32, view_h: f32, source_rows: f32, disasm_rows: f32, slots: f32, dump_rows: u32) Split { + fn shared(drawing_h: f32, view_h: f32, source_rows: f32, disasm_rows: f32, dump_rows: u32, backtrace_rows: f32) Split { const band: Rect = .{ .x = program.x, .y = canvas.stage.y, .w = program.w, .h = drawing_h }; const view: Rect = .{ .x = state.x, .y = canvas.stage.y, .w = state.w, .h = view_h }; - const source: Rect = .{ .x = program.x, .y = band.y + band.h + canvas.row_gap, .w = program.w, .h = panelH(source_rows) }; - const registers: Rect = .{ .x = state.x, .y = view.y + view.h + canvas.row_gap, .w = state.w, .h = panelH(17) }; - return .{ .band = band, .view = view, .source = source, .disasm = below(source, disasm_rows), .registers = registers, .stack = below(registers, slots), .backtrace = .{ .x = state.x, .y = canvas.stage.y + canvas.stage.h, .w = state.w, .h = 0 }, .dump_rows = dump_rows }; + const source: Rect = .{ .x = program.x, .y = if (drawing_h > 0) band.y + band.h + canvas.row_gap else canvas.stage.y, .w = program.w, .h = panelH(source_rows) }; + const registers: Rect = .{ .x = state.x, .y = if (view_h > 0) view.y + view.h + canvas.row_gap else canvas.stage.y, .w = state.w, .h = 0 }; + const bottom = canvas.stage.y + canvas.stage.h; + const backtrace: Rect = .{ .x = state.x, .y = bottom - panelH(backtrace_rows), .w = state.w, .h = if (backtrace_rows > 0) panelH(backtrace_rows) else 0 }; + return fit(.{ .band = band, .view = view, .source = source, .disasm = below(source, disasm_rows), .registers = registers, .stack = registers, .backtrace = backtrace, .dump_rows = dump_rows }, 11); } }; + /// `s` with a registers panel of `rows` rows (the scene's: its + /// registers, the quiet ones folded) and the stack the rest of the + /// state column above the backtrace, whole slots, any rest above it. + pub fn fit(s: Split, registers_rows: f32) Split { + var out = s; + out.registers.h = panelH(registers_rows); + const top = out.registers.y + out.registers.h + canvas.row_gap; + const bottom = if (s.backtrace.h > 0) s.backtrace.y - canvas.row_gap else canvas.stage.y + canvas.stage.h; + const slots = @floor((bottom - top - panelH(0)) / metric.context.row); + out.stack = .{ .x = state.x, .y = bottom - panelH(slots), .w = state.w, .h = panelH(slots) }; + return out; + } + /// A panel of `n` rows: a tag, the padding, the rows. pub fn panelH(n: f32) f32 { return metric.context.tag + 2 * metric.context.pad + n * metric.context.row; @@ -182,10 +192,6 @@ pub const layout = struct { return @intFromFloat(@max(@floor((h - metric.context.tag - 2 * metric.context.pad) / metric.context.row), 0)); } - fn rows(column: Rect, y: f32, n: f32) Rect { - return .{ .x = column.x, .y = column.y + y, .w = column.w, .h = panelH(n) }; - } - fn below(r: Rect, n: f32) Rect { return .{ .x = r.x, .y = r.y + r.h + canvas.row_gap, .w = r.w, .h = panelH(n) }; } @@ -563,6 +569,17 @@ pub const metric = struct { pub const source_chars = 67; }; + /// `registers` `quiet`: a register no step of the scene changes, folded + /// three to a row on a pitch of 285 from 12, under a 2-unit `rule` + /// across: its name faint at the cell's start, its value 48 in (60 from + /// the panel's edge), a pointer's chain cut to `more` at once. + pub const registers = struct { + pub const quiet_from = 12; + pub const quiet_pitch = 285; + pub const quiet_value = 48; + pub const quiet_per_row = 3; + }; + /// `insn`: columns, from the panel's left edge. pub const insn = struct { pub const mark = 2; @@ -703,64 +720,46 @@ 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. + /// `graph` (design/README.md, "graph"), the `blocks` lens's drawing (and + /// the map's, at its size). A block a pill 24 high, its ends half + /// circles: its offset 12 in, the functions it calls after it, its + /// visits ranged right 12 from its end, room kept for `×99` (and 8 to + /// spare) so that it never widens as the run counts; any two pills 12 + /// apart. `rings`: an arc between two pills 24 long at least to read; a + /// fork 30 inside its ring; a way out 30 in from the pill's far end, + /// its bends quarter circles of 16; the turns 30 under the centre; the + /// way in 48 long from the left. `layers`: layers 12 apart, lanes 10 + /// from 24 in, the blocks 76 right of them, columns 300 apart, the first + /// layer 14 down, ports 16 in, the right channel 20 out, a back edge + /// down 8, every corner a quarter circle of 12. Heads 8 by 8; the pc's + /// pill framed gold 3; the mark a gold plaque 22 with its point 12 by 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 pill = 24; + pub const pill_in = 12; + pub const count_chars = 3; + pub const spare = 8; + pub const apart = 12; + pub const arc_least = 24; + pub const fork_in = 30; + pub const exit_in = 30; + pub const bend = 16; + pub const turns_down = 30; + pub const way_in = 48; + pub const layer_gap = 12; + pub const lane = 10; 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; - }; + pub const blocks_in = 76; + pub const pitch = 300; + pub const top = 14; + pub const port = 16; + pub const channel = 20; + pub const back_down = 8; + pub const track = 4; + pub const corner = 12; + pub const head = [2]f32{ 8, 8 }; + pub const gold = 3; + pub const mark = 22; + pub const mark_point = [2]f32{ 12, 10 }; }; /// The ties' channels: the thread in the left margin, the gutter's two @@ -953,7 +952,22 @@ pub const time = struct { pub const veil = 0.30; /// A telescope extends: the links after one that changed are followed /// again one at a time, this far apart. - pub const unroll = 4.0 / 60.0; + pub const extend = 4.0 / 60.0; + /// `unroll` and `roll`: a pane's column out of its strip for a beat and + /// back (design/motion.md, "The map and the working frame"): the panes + /// it covers veiled first (`veil`), the column growing (`grow`, glide), + /// held at least `hold`, rolled back (`roll`), the veil lifting + /// (`veil`). A far jump in the same column at a walk: `grow`, the + /// window travelling along the column (`travel`, glide), `roll`: 96 f. + pub const unroll = struct { + pub const veil = 0.30; + pub const grow = 0.60; + pub const hold = 1.00; + pub const roll = 0.60; + pub const travel = 0.40; + /// The strip's window framed bright as it begins. + pub const bright = 0.10; + }; /// A tie between two panes: this long to draw (after what it leaves /// from has struck), and to go, as the marks advance. /// `link`: 6 f after the register's strike its old pin fades @@ -1020,25 +1034,42 @@ 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 + /// `leave` (and `turn`, round a ring's foot): 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. + /// `sets_off`; the mark along it (arcs and all) `mark` and `per_100` a + /// 100 units, `mark_most` at most (`run` at a run, the edge flashing + /// gold and cooling over it); the target's count struck `count` after + /// it lands (a ring's turns as 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 mark_most = 0.70; pub const count = 0.10; pub const trail = 0.30; pub const rest = 0.70; pub const run = 8.0 / 60.0; }; + /// `reach`: a block's first entry. As the mark lands its pill fills from + /// the page to `raised` over `fill`, its offset brightening with it, + /// and `×1` fades in over `count`, then is struck (the leave's own). + pub const reach = struct { + pub const fill = 0.20; + pub const count = 0.10; + }; + /// `unfold`: a fold the run reaches opens. From the mark setting off, + /// the pills beyond make room over `room` (`glide`), the fold's blocks + /// fade in, quiet, over `fade`, `apart` in address order; the mark + /// lands on the one reached no sooner than the room is made. + pub const unfold = struct { + pub const room = 0.40; + pub const fade = 0.20; + pub const apart = 2.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; @@ -1193,14 +1224,19 @@ test "the splits fill the stage, panels 12 apart" { try expect(layout.program.w == 880 and layout.state.x == 976); const bottom = canvas.stage.y + canvas.stage.h; const sp = layout.split; - // design/README.md, "5. The frame". - try expect(sp.none.source.h == 368 and sp.none.disasm.y == 428 and sp.none.disasm.y + sp.none.disasm.h == 868); - try expect(sp.none.registers.h == 440 and sp.none.stack.y == 500 and sp.none.backtrace.y == 736 and sp.none.backtrace.y + sp.none.backtrace.h == 864); - try expect(sp.beside.band.h == 152 and sp.beside.view.h == 152 and sp.beside.source.y == 212 and sp.beside.disasm.y == 448 and sp.beside.disasm.y + sp.beside.disasm.h == bottom); - try expect(sp.beside.registers.y == 212 and sp.beside.stack.y == 664 and sp.beside.stack.y + sp.beside.stack.h == bottom); - try expect(sp.subject.band.h == 296 and sp.subject.view.h == 200 and sp.subject.source.y == 356 and sp.subject.disasm.y == 640 and sp.subject.disasm.y + sp.subject.disasm.h == bottom); - try expect(sp.subject.registers.y == 260 and sp.subject.stack.y == 712 and sp.subject.stack.y + sp.subject.stack.h == bottom); - try expect(layout.rowsIn(sp.beside.disasm.h) == 17 and layout.rowsIn(sp.subject.disasm.h) == 9 and layout.rowsIn(sp.subject.stack.h) == 6 and layout.rowsIn(sp.subject.view.h) == 7); + const rows = layout.rowsIn; + // design/README.md, "5. The frame": layout A, for a registers panel of eleven rows. + try expect(sp.none.source.y == 48 and sp.none.source.h == 368 and sp.none.disasm.y == 428 and sp.none.disasm.y + sp.none.disasm.h == 868); + try expect(sp.none.registers.y == 48 and sp.none.registers.h == 296 and sp.none.stack.y == 356 and rows(sp.none.stack.h) == 15 and sp.none.backtrace.y == 760 and sp.none.backtrace.y + sp.none.backtrace.h == bottom); + try expect(sp.beside.band.h == 152 and sp.beside.view.h == 152 and sp.beside.source.y == 212 and rows(sp.beside.source.h) == 8 and sp.beside.disasm.y == 448 and sp.beside.disasm.y + sp.beside.disasm.h == bottom); + try expect(sp.beside.registers.y == 212 and sp.beside.stack.y == 520 and rows(sp.beside.stack.h) == 14 and sp.beside.stack.y + sp.beside.stack.h == bottom); + try expect(sp.subject.band.h == 296 and sp.subject.view.h == 200 and sp.subject.source.y == 356 and rows(sp.subject.source.h) == 8 and sp.subject.disasm.y == 592 and sp.subject.disasm.y + sp.subject.disasm.h == bottom); + try expect(sp.subject.registers.y == 260 and sp.subject.stack.y == 568 and rows(sp.subject.stack.h) == 12 and sp.subject.stack.y + sp.subject.stack.h == bottom); + try expect(sp.blocks.band.h == 344 and sp.blocks.view.h == 0 and sp.blocks.source.y == 404 and rows(sp.blocks.source.h) == 6 and sp.blocks.disasm.y == 592 and rows(sp.blocks.disasm.h) == 11); + try expect(sp.blocks.registers.y == 48 and sp.blocks.stack.y == 376 and rows(sp.blocks.stack.h) == 20 and sp.blocks.stack.y + sp.blocks.stack.h == bottom); + try expect(rows(sp.beside.disasm.h) == 17 and rows(sp.subject.disasm.h) == 11 and rows(sp.subject.view.h) == 7 and rows(sp.beside.view.h) == 5); + // A scene that folds none (17 rows) has six slots fewer; one that folds more, more. + try expect(rows(layout.fit(sp.subject, 17).stack.h) == 6 and rows(layout.fit(sp.subject, 10).stack.h) == 13 and rows(layout.fit(sp.none, 17).stack.h) == 9); // The band's two panels are the columns' width, the gutter between them the ties'. try expect(sp.subject.band.x == layout.program.x and sp.subject.band.w == 880 and sp.subject.view.x == layout.state.x); } diff --git a/anim/src/ties.zig b/anim/src/ties.zig index 36dc635..58ada36 100644 --- a/anim/src/ties.zig +++ b/anim/src/ties.zig @@ -197,9 +197,7 @@ pub const Ties = struct { raw.at.xf = .identity; const k = at.scale; const split = g.stage.now(at); - // No thread where the disassembly is not under the source (the `blocks` lens has it over the state column). - const apart = @abs(split.disasm.x - split.source.x) / (theme.layout.state.x - theme.layout.program.x); - if (g.threaded and apart < 1) thread(raw.faded(@import("context.zig").thread_shows * (1 - apart)), at, k); + if (g.threaded) thread(raw.faded(@import("context.zig").thread_shows), at, k); if (g.beat) |b| named(raw, at, now, k, split, b); if (!now.walking()) return; if (!g.quiet) g.link(raw, at, now, k, split); diff --git a/anim/test/gallery/atoms.png b/anim/test/gallery/atoms.png Binary files differindex acd54a8..9ae1959 100644 --- a/anim/test/gallery/atoms.png +++ b/anim/test/gallery/atoms.png diff --git a/anim/test/gallery/graph-map.png b/anim/test/gallery/graph-map.png Binary files differindex 951d4af..eec101e 100644 --- a/anim/test/gallery/graph-map.png +++ b/anim/test/gallery/graph-map.png diff --git a/anim/test/gallery/graph.png b/anim/test/gallery/graph.png Binary files differindex d43db42..305b3d4 100644 --- a/anim/test/gallery/graph.png +++ b/anim/test/gallery/graph.png diff --git a/anim/test/gallery/loupe.png b/anim/test/gallery/loupe.png Binary files differindex 52bc89a..47977d6 100644 --- a/anim/test/gallery/loupe.png +++ b/anim/test/gallery/loupe.png diff --git a/anim/test/gallery/none.png b/anim/test/gallery/none.png Binary files differindex 4e4d5b1..ba6f328 100644 --- a/anim/test/gallery/none.png +++ b/anim/test/gallery/none.png diff --git a/anim/test/gallery/rest.png b/anim/test/gallery/rest.png Binary files differindex 205fc0d..c1a9e52 100644 --- a/anim/test/gallery/rest.png +++ b/anim/test/gallery/rest.png diff --git a/anim/test/gallery/rows.png b/anim/test/gallery/rows.png Binary files differindex 4d936ab..280b72c 100644 --- a/anim/test/gallery/rows.png +++ b/anim/test/gallery/rows.png diff --git a/anim/test/gallery/step.png b/anim/test/gallery/step.png Binary files differindex 5ccb082..56c798d 100644 --- a/anim/test/gallery/step.png +++ b/anim/test/gallery/step.png diff --git a/anim/test/gallery/subject.png b/anim/test/gallery/subject.png Binary files differindex 9e36a1d..15857f9 100644 --- a/anim/test/gallery/subject.png +++ b/anim/test/gallery/subject.png diff --git a/anim/test/recordings.zig b/anim/test/recordings.zig index e3af983..7c3a26e 100644 --- a/anim/test/recordings.zig +++ b/anim/test/recordings.zig @@ -115,71 +115,121 @@ fn firstIn(rec: *const Recording, name: []const u8) u64 { unreachable; } -test "sort's graph: two loops in their lanes, the hot path straight down, the jle never taken" { +/// The `blocks` lens's pane, its body: what the graph is laid out for. +const lens_room = [2]f32{ 880 - 4, 344 - 24 - 2 }; + +/// The moment the sort scene opens at: the inner loop's test, about to compare 31 with 12. +fn sortStart(rec: *const Recording) u64 { + var start = rec.call("sort", 0).enter; + while (rec.next(.over, rec.next(.over, start)) < rec.call("swap", 0).enter) start = rec.next(.over, start); + return start; +} + +/// Whether node `n`'s centre is on ring `r`. +fn onRing(n: canim.graph.Node, r: canim.graph.Ring) bool { + const dx = n.x + n.w / 2 - r.c[0]; + const dy = n.y + n.h / 2 - r.c[1]; + return @abs(@sqrt(dx * dx + dy * dy) - r.r) < 0.5; +} + +test "sort's graph: two rings from the code alone, the inner touching the outer at its header, whole in the lens" { var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); defer arena.deinit(); const graph = canim.graph; const rec = canim.open(recordings.sort); - const at = firstIn(rec, "sort"); - var g = graph.read(arena.allocator(), rec, rec.end(), rec.registers[at].rip).?; + const start = sortStart(rec); + const pc = rec.registers[start].rip; + const g = graph.layout(arena.allocator(), rec, start, pc, .rings, lens_room, start).?; try expect(g.exact and g.text); try expectEqual(@as(usize, 11), g.nodes.len); - for (g.nodes) |n| try expect(n.reached); - // The inner loop's `j > 0` is never false: its jle never taken. - const jle = g.edgeOf(g.nodeOf(g.start + 0x8a).?, g.nodeOf(g.start + 0xbc).?).?; - try expect(g.edges[jle].kind == .taken and g.edges[jle].total == 0); - // The compare's jne to the swap, ten times; the swap entered as often. - const swap = g.nodeOf(g.start + 0xc5).?; - try expectEqual(@as(u32, 10), g.edges[g.edgeOf(g.nodeOf(g.start + 0xbc).?, swap).?].count); - try expectEqual(@as(u32, 10), g.nodes[swap].visits); - graph.sizes(rec, rec.end(), &g, .map); - graph.place(&g, graph.metricOf(.map)); - var backs: usize = 0; - for (g.edges) |e| backs += @intFromBool(e.back); - try expectEqual(@as(usize, 2), backs); - // The outer loop (i++ back to the test) outermost, the inner (the swap back to `j > 0`) inside it. - const outer = g.edges[g.edgeOf(g.nodeOf(g.start + 0xff).?, g.nodeOf(g.start + 0x78).?).?]; - const inner = g.edges[g.edgeOf(swap, g.nodeOf(g.start + 0x8a).?).?]; - try expect(outer.back and inner.back and outer.lane == 0 and inner.lane == 1); - // The swap straight under the compare that goes to it ten times in ten; the way on beside it. - try expectEqual(g.nodes[g.nodeOf(g.start + 0xbc).?].col, g.nodes[swap].col); - try expect(g.nodes[g.nodeOf(g.start + 0xc3).?].col > g.nodes[swap].col); - // The jle and the loop's exit would cross blocks: the right channel. - try expectEqual(@as(u8, 6), g.edges[jle].n); - try expectEqual(g.channel, g.edges[jle].points[2][0]); - // On the map (1688 high): too tall; the long prologue folds, and the outer loop is panned into view whole. - var buf: [1 << 20]u8 = undefined; - var fba = std.heap.FixedBufferAllocator.init(&buf); - const room = 1688 - 24; - const in_loop = rec.lineMoment(12, at); - const laid = graph.layout(fba.allocator(), rec, in_loop, rec.registers[in_loop].rip, .map, room).?; - try expectEqual(@as(u32, 9), laid.nodes[0].shown); - const off = graph.pan(laid, room, graph.metricOf(.map)); - for (laid.nodes[1 .. laid.nodes.len - 1]) |n| try expect(n.y >= off and n.y + n.h <= off + room); + try expectEqual(@as(usize, 0), g.foldedBlocks()); + const at = struct { + fn of(gr: canim.graph.Graph, off: u64) canim.graph.Node { + return gr.nodes[gr.nodeOf(gr.start + off).?]; + } + }.of; + // Two rings: the outer loop's (the test at +78), the inner's (its test at +8a). + try expectEqual(@as(usize, 2), g.rings.len); + const outer = if (g.nodes[g.rings[0].header].start == g.start + 0x78) g.rings[0] else g.rings[1]; + const inner = if (g.nodes[g.rings[0].header].start == g.start + 0x8a) g.rings[0] else g.rings[1]; + try expect(g.nodes[outer.header].start == g.start + 0x78 and g.nodes[inner.header].start == g.start + 0x8a); + for ([_]u64{ 0x78, 0x84, 0x8a, 0xc3, 0xfd, 0xff }) |off| try expect(onRing(at(g, off), outer)); + for ([_]u64{ 0x8a, 0x95, 0xbc, 0xc5 }) |off| try expect(onRing(at(g, off), inner)); + for ([_]u64{ 0x0, 0x10d }) |off| try expect(!onRing(at(g, off), outer) and !onRing(at(g, off), inner)); + // The inner ring outside the outer, touching it at +8a: the outer's 3 o'clock, the inner's 9. + const h = at(g, 0x8a); + try std.testing.expectApproxEqAbs(outer.c[0] + outer.r, h.x + h.w / 2, 0.5); + try std.testing.expectApproxEqAbs(inner.c[0] - inner.r, h.x + h.w / 2, 0.5); + try std.testing.expectApproxEqAbs(outer.c[1], inner.c[1], 0.5); + // The headers at 9 o'clock; +0 left of +78 on its line, +10d under it. + const o = at(g, 0x78); + try std.testing.expectApproxEqAbs(outer.c[0] - outer.r, o.x + o.w / 2, 0.5); + const entry = at(g, 0x0); + try expect(entry.y == o.y and entry.x + entry.w < o.x); + const exit = at(g, 0x10d); + try expect(exit.y > o.y + o.h and exit.x < o.x + o.w and exit.x + exit.w > o.x); + // Any two pills 12 apart. + for (g.nodes, 0..) |a, i| for (g.nodes[i + 1 ..]) |b| { + const dx = @max(b.x - (a.x + a.w), a.x - (b.x + b.w), 0); + const dy = @max(b.y - (a.y + a.h), a.y - (b.y + b.h), 0); + try expect(dx * dx + dy * dy >= 12 * 12 - 0.01); + }; + // Whole in the lens's pane, no pan. + try expect(g.w <= lens_room[0] and g.h <= lens_room[1]); } -test "reverse's graph: one loop, its exit in the right channel" { +test "sort's graph says nothing from after the moment: the same layout at every moment, quiet until reached" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const graph = canim.graph; + const rec = canim.open(recordings.sort); + const start = sortStart(rec); + const later = rec.call("swap", 5).enter - 1; + const a = graph.layout(arena.allocator(), rec, start, rec.registers[start].rip, .rings, lens_room, start).?; + const b = graph.layout(arena.allocator(), rec, later, rec.registers[later].rip, .rings, lens_room, start).?; + // Where every block is, and every edge's way: the code's, not the run's. + try expectEqual(a.nodes.len, b.nodes.len); + for (a.nodes, b.nodes) |x, y| try expect(x.x == y.x and x.y == y.y and x.w == y.w); + for (a.edges, b.edges) |x, y| { + try expect(x.n == y.n); + for (x.path(), y.path()) |p, q| try expect(p[0] == q[0] and p[1] == q[1]); + } + // At the opening: every block reached but the swap and the way out; no count, no edge, into either. + for (a.nodes) |n| { + const off = n.start - a.start; + try expectEqual(off == 0xc5 or off == 0x10d, n.visits == 0); + } + for (a.edges) |e| if (a.nodes[e.to].visits == 0) try expectEqual(@as(u32, 0), e.count); + // The inner loop's `jle` not taken so far; its turns none yet. + const jle = a.edgeOf(a.nodeOf(a.start + 0x8a).?, a.nodeOf(a.start + 0xbc).?).?; + try expectEqual(@as(u32, 0), a.edges[jle].count); + const turn = a.edgeOf(a.nodeOf(a.start + 0xc5).?, a.nodeOf(a.start + 0x8a).?).?; + try expect(a.edges[turn].back and a.edges[turn].count == 0 and b.edges[turn].count == 5); + // The trail: taken edges only, the newest into the pc's block. + for (a.trail) |maybe| try expect(a.edges[maybe.?].count > 0); + // Three different edges: the last three taken, round the outer loop and into the inner. + try expect(a.trail[0].? != a.trail[1].? and a.trail[1].? != a.trail[2].? and a.trail[0].? != a.trail[2].?); + try expectEqual(b.here.?, b.edges[b.trail[0].?].to); +} + +test "reverse's graph: one ring of two blocks, the way in from the left, the way out down" { var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); defer arena.deinit(); const graph = canim.graph; const rec = canim.open(recordings.list); const at = firstIn(rec, "reverse"); - var g = graph.read(arena.allocator(), rec, rec.end(), rec.registers[at].rip).?; + const g = graph.layout(arena.allocator(), rec, at, rec.registers[at].rip, .rings, lens_room, at).?; try expectEqual(@as(usize, 4), g.nodes.len); - graph.sizes(rec, rec.end(), &g, .map); - graph.place(&g, graph.metricOf(.map)); - const layers = [_]u32{ 0, 1, 2, 3 }; - for (g.nodes, layers) |n, l| try expect(n.layer == l and n.col == 0); - // The body's jmp back to the test: the one edge that climbs, three turns. - const turn = g.edges[g.edgeOf(2, 1).?]; - try expect(turn.back and turn.count == 3); - try expectEqual(@as(u8, 6), g.edges[g.edgeOf(1, 3).?].n); + try expectEqual(@as(usize, 1), g.rings.len); + var on: usize = 0; + for (g.nodes) |n| on += @intFromBool(onRing(n, g.rings[0])); + try expectEqual(@as(usize, 2), on); // The recording begins inside it: its first block was entered once. try expectEqual(@as(u32, 1), g.nodes[0].visits); - try expect(g.h <= 1688 - 24); + try expect(g.w <= lens_room[0] and g.h <= lens_room[1]); } -test "libc's open at its syscall: the blocks never reached folded, no loop made by folding" { +test "libc's open at its syscall: what it has not reached folded, a fold opening as the run gets there" { var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); defer arena.deinit(); const graph = canim.graph; @@ -187,28 +237,38 @@ test "libc's open at its syscall: the blocks never reached folded, no loop made var at = firstIn(rec, "libc.so.6!open"); var buf: [256]u8 = undefined; while (!std.mem.eql(u8, rec.instruction(at, rec.registers[at].rip, &buf).?.text, "syscall")) at += 1; - const g = graph.layout(arena.allocator(), rec, at, rec.registers[at].rip, .map, 1688 - 24).?; - // Twenty blocks (two of `nop` padding left out), eight of them reached. - try expectEqual(@as(usize, 20), g.blocks); - var reached: usize = 0; + const a = graph.layout(arena.allocator(), rec, at, rec.registers[at].rip, .rings, lens_room, at).?; + // Twenty blocks (two of `nop` padding left out); no loop: layers. + try expectEqual(@as(usize, 20), a.blocks); + try expectEqual(@as(usize, 0), a.rings.len); + for (a.edges) |e| try expect(!e.back); + // Folded: only blocks not reached by the moment, two folds (the cancellable call's, the way back from the kernel). var folds: usize = 0; - for (g.nodes) |n| { - reached += @intFromBool(n.reached); - folds += @intFromBool(n.folded > 0); - } - try expectEqual(@as(usize, 8), reached); - try expectEqual(@as(usize, 12), g.foldedBlocks()); - try expect(folds >= 4 and folds < 12); - // open has no loop, and the folds make none. - for (g.edges) |e| try expect(!e.back); + for (a.nodes) |n| if (n.folded > 0) { + folds += 1; + try expectEqual(@as(u32, 0), n.visits); + }; + try expectEqual(@as(usize, 2), folds); + try expectEqual(@as(usize, 15), a.foldedBlocks()); + // `+5b … · 7`, the cancellable call's; `+be … · 8`, the way back from the kernel; +d0 alone stays a quiet pill. + try expectEqual(@as(u32, 7), a.nodes[a.nodeOf(a.start + 0x5b).?].folded); + try expectEqual(@as(u32, 8), a.nodes[a.nodeOf(a.start + 0xbe).?].folded); + try expectEqual(@as(u32, 0), a.nodes[a.nodeOf(a.start + 0xd0).?].folded); + try expect(a.w <= lens_room[0] and a.h <= lens_room[1]); // At its syscall: the blocks before entered once, those after not yet. - try expectEqual(g.nodeOf(rec.registers[at].rip).?, g.here.?); - for (g.nodes) |n| if (n.reached) try expectEqual(@as(u32, @intFromBool(n.start <= rec.registers[at].rip)), n.visits); - // Still taller than the map: it pans, the pc's block in view; as wide as two columns at most. - const room = 1688 - 24; - const off = graph.pan(g, room, graph.metricOf(.map)); - const here = g.nodes[g.here.?]; - try expect(here.y >= off and here.y + here.h <= off + room and g.w <= 1792); + try expectEqual(a.nodeOf(rec.registers[at].rip).?, a.here.?); + for (a.nodes) |n| if (n.folded == 0 and n.visits > 0) try expectEqual(@as(u32, 1), n.visits); + // On to its block's last stop: the same layout. A step on, into the way back from the kernel: its fold open, the other still folded. + const end = graph.blockEnd(rec, at); + const b = graph.layout(arena.allocator(), rec, end, rec.registers[end].rip, .rings, lens_room, at).?; + for (a.nodes, b.nodes) |x, y| try expect(x.x == y.x and x.y == y.y and x.folded == y.folded); + const c = graph.layout(arena.allocator(), rec, end + 1, rec.registers[end + 1].rip, .rings, lens_room, at).?; + try expect(c.open != a.open); + try expectEqual(@as(u32, 0), c.nodes[c.here.?].folded); + try expectEqual(@as(u32, 1), c.nodes[c.here.?].visits); + var still: usize = 0; + for (c.nodes) |n| still += @intFromBool(n.folded > 0); + try expectEqual(@as(usize, 1), still); } test "the source follows the pc into musl's own files and back to main's line" { diff --git a/anim/tools/chart.py b/anim/tools/chart.py index 290c59e..0f2894f 100644 --- a/anim/tools/chart.py +++ b/anim/tools/chart.py @@ -24,30 +24,38 @@ W = motion.W def ph(rows): return 32 + 24 * rows -def split(drawing, view, source, disasm, slots, backtrace=0): +def split(drawing, view, source, disasm, regs, backtrace=0): + """Layout A: the disassembly under the source; the registers as tall as the scene's rows + (`regs`), the stack the state column's rest above the backtrace, whole slots, any rest above it.""" out = {} if drawing: out["drawing"] = (64, 48, 880, drawing) - out["view"] = (976, 48, 880, view) + if view: + out["view"] = (976, 48, 880, view) left = 48 + (drawing + 12 if drawing else 0) right = 48 + (view + 12 if view else 0) out["source"] = (64, left, 880, ph(source)) out["disasm"] = (64, left + ph(source) + 12, 880, ph(disasm)) - out["registers"] = (976, right, 880, ph(17)) - out["stack"] = (976, right + ph(17) + 12, 880, ph(slots)) + out["registers"] = (976, right, 880, ph(regs)) + bottom = 888 - (ph(backtrace) + 12 if backtrace else 0) + slots = (bottom - (right + ph(regs) + 12) - 32) // 24 + out["stack"] = (976, bottom - ph(slots), 880, ph(slots)) if backtrace: - out["backtrace"] = (976, right + ph(17) + 12 + ph(slots) + 12, 880, ph(backtrace)) + out["backtrace"] = (976, 888 - ph(backtrace), 880, ph(backtrace)) return out # The words that are not panels (motion.WORDS): the clock (its count, ranged right at 1856, # changes in a frame by design) and the caption (its 1400 from the margin). The caption's box # starts under the clock's count and the run's step counter (912 to 934). words = {"clock": (0, 888, 1920, 46), "caption": (0, 940, 1464, 140)} -none, beside, subject = split(0, 0, 14, 17, 8, 4), split(152, 152, 8, 17, 8), split(296, 200, 10, 9, 6) -# The `blocks` lens: the graph over the program column, the source alone under it; the disassembly -# (its view) over the state column, seven rows, the registers and six words under it. -blocks = {**subject, "view": (976, 48, 880, ph(7)), "source": (64, 356, 880, ph(20))} -del blocks["disasm"] +# The splits (theme.layout.split), each scene's registers panel as tall as its rows (the +# registers its steps change, the rest folded three to a row: `context.movedBy`). +none = lambda regs: split(0, 0, 14, 17, regs, 4) +beside = lambda regs: split(152, 152, 8, 17, regs) +subject = lambda regs: split(296, 200, 8, 11, regs) +# The `blocks` lens: the graph alone over the program column (880 by 344, no view), the source +# six lines and the disassembly eleven under it; the registers and the stack from the top. +blocks = lambda regs: split(344, 0, 6, 11, regs) # Each pane's minimap a region of its own (motion.strips), secondary action: the source's, the # disassembly's, the stack's, and the view's where it is a dump (not the calls lens's backtrace, # not the syscalls lens's log). @@ -58,17 +66,17 @@ def strips(panes, view): out["view"] = panes["view"] return out motion.REGIONS.update({ - "fib": {**strips(subject, False), **words}, - "sort": {**strips(blocks, True), **words}, + "fib": {**strips(subject(10), False), **words}, + "sort": {**strips(blocks(11), True), **words}, # The band is the calls so far; the disassembly a descent. - "syscalls": {**strips(beside, False), **words}, - "musl": {**strips(beside, False), **words}, - "heap": {**strips(subject, True), **words}, - "list": {**strips(subject, True), **words}, - # The band's drawing is the backtrace, then the kernel's side; its view a dump. - "sqlite": {**strips(subject, True), **words}, - "zoom": {**strips(none, False), **words}, - "gallery": {**strips(beside, True), **words}, + "syscalls": {**strips(beside(14), False), **words}, + "musl": {**strips(beside(15), False), **words}, + "heap": {**strips(subject(14), True), **words}, + "list": {**strips(subject(9), True), **words}, + # The band's drawing is the backtrace, then the kernel's side; its view a dump. It folds none. + "sqlite": {**strips(subject(17), True), **words}, + "zoom": {**strips(none(9), False), **words}, + "gallery": {**strips(beside(13), True), **words}, }) # `cut`: the gallery is the catalogue's pages, cut from one to the next (scenes/gallery.zig: 3, 6, 9.6, 13, 16, # 19.8, 21 and 24 s), not a scene: a page's first frame changes everything at once by design. diff --git a/design/motion/motion.py b/design/motion/motion.py index 87823ff..4feba0e 100644 --- a/design/motion/motion.py +++ b/design/motion/motion.py @@ -69,25 +69,30 @@ def strips(panes): return out -def split(drawing, view, source, disasm, slots, backtrace=0): - """A split's panes (theme.layout.split): a panel of n rows is 32 + 24 n, 12 apart.""" +def split(drawing, view, source, disasm, regs=11, backtrace=0): + """A split's panes (theme.layout.split, layout A): a panel of n rows is 32 + 24 n, 12 apart; the disassembly + under the source; the registers as tall as their rows (`regs`: sort's 11 by default), the stack the state + column's rest above the backtrace, whole slots, any rest above it.""" ph = lambda n: 32 + 24 * n - out = {"drawing": (64, 48, 880, drawing), "view": (976, 48, 880, view)} if drawing else {} + out = {"drawing": (64, 48, 880, drawing)} if drawing else {} + if view: + out["view"] = (976, 48, 880, view) left, right = 48 + (drawing + 12 if drawing else 0), 48 + (view + 12 if view else 0) + bottom = 888 - (ph(backtrace) + 12 if backtrace else 0) + slots = (bottom - (right + ph(regs) + 12) - 32) // 24 out.update({"source": (64, left, 880, ph(source)), "disasm": (64, left + ph(source) + 12, 880, ph(disasm)), - "registers": (976, right, 880, ph(17)), "stack": (976, right + ph(17) + 12, 880, ph(slots))}) + "registers": (976, right, 880, ph(regs)), "stack": (976, bottom - ph(slots), 880, ph(slots))}) if backtrace: - out["backtrace"] = (976, right + ph(17) + 12 + ph(slots) + 12, 880, ph(backtrace)) + out["backtrace"] = (976, 888 - ph(backtrace), 880, ph(backtrace)) return out -# The working frame by split, its strips apart (`--regions none|beside|subject|blocks`): `blocks` is the -# graph over the program column, the source alone (twenty lines), the disassembly its view, seven rows. +# The working frame by split, its strips apart (`--regions none|beside|subject|blocks`), for a registers panel of +# eleven rows: `blocks` is the graph alone over the program column (880 by 344), the source six lines and the +# disassembly eleven under it, the registers and the stack from the state column's top. _words = {"caption": (64, 906, 1400, 126), "clock": (64, 894, 1792, 52)} -_blocks = {**split(296, 200, 10, 9, 6), "view": (976, 48, 880, 32 + 24 * 7), "source": (64, 356, 880, 32 + 24 * 20)} -del _blocks["disasm"] -for _name, _panes in {"none": split(0, 0, 14, 17, 8, 4), "beside": split(152, 152, 8, 17, 8), - "subject": split(296, 200, 10, 9, 6), "blocks": _blocks}.items(): +for _name, _panes in {"none": split(0, 0, 14, 17, backtrace=4), "beside": split(152, 152, 8, 17), + "subject": split(296, 200, 8, 11), "blocks": split(344, 0, 6, 11)}.items(): REGIONS[_name] = {**strips(_panes), **_words} PALETTE = ["#9aa6d9", "#e8c46a", "#6fd6e6", "#7fdc9a", "#d59cf5", "#ff6a4a", "#eee6d2", "#17a0b0"] |
