//! The gallery: every block of the design language (design/README.md, the //! vocabulary) drawn in its states, a page at a time, under the //! catalogue's names. The test of the catalogue is that this shows what it //! says; `test/gallery.script` compares its pages with the pictures in //! `test/gallery/`. //! //! 0 s atoms: address, value, arrow, byte, mark, plaque, pin, bracket, tag //! 1 s rows: chain, reg (rip with the flags), slot, line, bytes, call //! 2 s the frame at rest, `beside`: every panel, the thread (mock 9) //! 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) const std = @import("std"); const sk = @import("sketch"); const anim = @import("anim"); const canim = @import("canim"); const recordings = @import("recordings"); pub const background = canim.background; pub const scene = anim.Live(frame, struct {}); const ui = canim.ui; const rows = canim.rows; const theme = canim.theme; const t = theme.color.text; const region = theme.color.region; /// The pages of atoms and rows, drawn from a moment of the list's recording. const Pages = struct { rec: *canim.Recording, moment: u64, box: canim.Rect = .{ .x = 0, .y = 0, .w = 1920, .h = 1080 }, pub fn draw(p: *const Pages, f: *sk.Frame, at: anim.Placed) void { const u: ui.Ui = .{ .f = f, .at = at }; // Each page 3 s: long enough to be looked at. if (at.t < 3) atoms(u, p) else if (at.t < 6) rowsPage(u, p); } }; fn title(u: ui.Ui, x: f32, y: f32, name: []const u8) void { u.text(.sans_medium, theme.size.sans.tag, x, y, name, t.primary); } fn note(u: ui.Ui, x: f32, y: f32, words: []const u8) void { u.text(.sans, theme.size.sans.micro, x, y, words, t.faint); } fn atoms(u: ui.Ui, p: *const Pages) void { const m = p.rec.moment(p.moment); const regs = (m.regs(p.rec.tid) catch null).?; const row = theme.metric.context.row; title(u, 64, 40, "1 atoms"); // address var y: f32 = 80; title(u, 64, y, "address"); note(u, 200, y, "plain, lead, name, rwx; struck, read, held"); y += 12; var x: f32 = 64; x = u.address(x, rows.baseline(y), 0x407010, .{ .ink = ui.rgb(region.heap) }) + 40; for ([_]u64{ 0x402470, 0x402481, 0x402495 }, 0..) |a, i| _ = u.address(x, rows.baseline(y + @as(f32, @floatFromInt(i)) * row), a, .{ .ink = ui.rgb(region.code_), .lead = ui.shared(&.{ 0x402470, 0x402495 }) }); x += 120; x = u.address(x, rows.baseline(y), regs.rip, .{ .ink = ui.rgb(region.code_), .name = p.rec.strings.get(regs.rip) orelse "" }) + 40; x = u.address(x, rows.baseline(y), 0x7ffff7ff0000, .{ .ink = ui.rgb(region.data), .rwx = true }) + 40; const struck: ui.Heat = .struck; const cell: canim.Rect = .{ .x = x, .y = y, .w = 6 * 12, .h = row }; _ = u.written(cell, struck); _ = u.address(x, rows.baseline(y), 0x407050, .{ .ink = ui.rgb(t.bright), .face = .mono_bold }); x += 112; u.read(.{ .x = x, .y = y, .w = 72, .h = row }, 1); _ = u.address(x, rows.baseline(y), 0x407058, .{ .ink = ui.rgb(region.heap) }); x += 112; _ = u.written(.{ .x = x, .y = y, .w = 72, .h = row }, .ember); _ = u.address(x, rows.baseline(y), 0x407030, .{ .ink = ui.rgb(region.heap) }); // value y = 196; title(u, 64, y, "value"); note(u, 200, y, "digit, small number, large number, small negative, string, unknown; by a signature or a type: fd, bool, char"); y += 12; x = 64; for ([_]u64{ 4, 0x21, 0x8dea2ff80214, std.math.maxInt(u64) }) |v| x = u.value(x, rows.baseline(y), v, false, .{}) + 60; u.text(.mono, theme.size.mono.context, x, rows.baseline(y), "\"./list\"", theme.color.string); x += 140; u.unknown(.{ .x = x, .y = y, .w = 24, .h = row }); x += 84; x = u.typed(x, rows.baseline(y), 3, .{ .fd = "\"note\"" }, .{}) + 60; x = u.typed(x, rows.baseline(y), 1, .boolean, .{}) + 60; _ = u.typed(x, rows.baseline(y), 'A', .character, .{}); // arrow y = 270; title(u, 64, y, "arrow, hop"); note(u, 240, y, "points, holds, more"); y += 12; _ = u.arrow(64, y + row / 2, .points); _ = u.arrow(130, y + row / 2, .holds); _ = u.arrow(196, y + row / 2, .more); _ = u.arrow(320, y + row / 2, .points); _ = u.address(350, rows.baseline(y), 0x407030, .{ .ink = ui.rgb(region.heap) }); // byte y = 330; title(u, 64, y, "byte"); note(u, 200, y, "number, pointer, text, loose, unread; pad"); y += 12; { var values: [16]u8 = .{ 9, 0, 0, 0, 0, 0, 0, 0, 0x30, 0x70, 0x40, 0, 0, 0, 0, 0 }; var known: [16]bool = @splat(true); rows.bytes(u, y, 0x407050, &values, &known, &.{ .{ .first = 0, .len = 8, .kind = .number }, .{ .first = 8, .len = 8, .kind = .pointer } }, region.heap, 4, true, m); values = .{ 0, 0, 0, 0, 0, 0, 0, 0, 0x21, 0, 0, 0, 0, 0, 0, 0 }; rows.bytes(u, y + row, 0x407060, &values, &known, &.{ .{ .first = 0, .len = 8, .kind = .unread }, .{ .first = 8, .len = 8, .kind = .loose } }, region.heap, 4, false, m); values = .{ '.', '/', 'l', 'i', 's', 't', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; rows.bytes(u, y + 2 * row, 0x407070, &values, &known, &.{ .{ .first = 0, .len = 7, .kind = .text }, .{ .first = 7, .len = 9, .kind = .loose } }, region.heap, 4, true, m); } // mark, in the context and in a lens's cell y = 442; title(u, 64, y, "mark"); note(u, 200, y, "in the context: current, armed, struck, held, read, trail, unknown"); y += 12; u.current(.{ .x = 64, .y = y, .w = 200, .h = row }, theme.metric.plaque.line, 0); u.text(.mono_bold, theme.size.mono.context, 64 + 46 - 24, rows.baseline(y), "21", t.ink); x = 300; for ([_]ui.Heat{ .{ .arm = 1 }, struck, .ember }) |h| { const ink = u.written(.{ .x = x, .y = y, .w = 72, .h = row }, h); _ = u.address(x, rows.baseline(y), 0x407070, .{ .ink = if (ink) |i| i.ink else ui.rgb(region.heap), .face = if (ink) |i| i.face else .mono }); x += 120; } u.read(.{ .x = x, .y = y, .w = 72, .h = row }, 1); _ = u.address(x, rows.baseline(y), 0x407098, .{ .ink = ui.rgb(region.heap) }); x += 120; for (0..3) |k| u.trail(x + @as(f32, @floatFromInt(k)) * 16, y, k); x += 70; u.unknown(.{ .x = x, .y = y, .w = 24, .h = row }); y += 40; note(u, 64, y, "in a lens's cell: armed, struck, held, read, allocated, freed, fault, attention, kernel"); y += 12; x = 64; const cell_size = [2]f32{ 72, 44 }; for ([_]ui.Heat{ .{ .arm = 1 }, struck, .ember }, [_][]const u8{ "4", "9", "16" }) |h, digits| { const r: canim.Rect = .{ .x = x, .y = y, .w = cell_size[0], .h = cell_size[1] }; const ink = u.cellWritten(r, h, theme.color.raised); u.label(ink.face, theme.size.mono.small, r, .center, digits, ink.ink); x += 100; } { const r: canim.Rect = .{ .x = x, .y = y, .w = cell_size[0], .h = cell_size[1] }; u.fill(r, theme.color.raised); u.cellRead(r, 1); u.label(.mono, theme.size.mono.small, r, .center, "25", t.primary); x += 100; const a: canim.Rect = .{ .x = x, .y = y, .w = cell_size[0], .h = cell_size[1] }; u.fill(a, theme.mark(.allocated).ember); u.frame(a, theme.mark(.allocated).solid, theme.stroke.line); x += 100; u.dashedFrame(.{ .x = x, .y = y, .w = cell_size[0], .h = cell_size[1] }, theme.mark(.freed).solid, theme.stroke.line); x += 100; const fault: canim.Rect = .{ .x = x, .y = y, .w = 120, .h = cell_size[1] }; u.fill(fault, theme.mark(.fault).solid); u.fill(.{ .x = fault.x + 8, .y = fault.y + 8, .w = fault.w - 16, .h = fault.h - 16 }, t.ink); u.label(.mono_bold, theme.size.mono.context, fault, .center, "SIGSEGV", t.bright); x += 148; u.frame(.{ .x = x, .y = y, .w = cell_size[0], .h = cell_size[1] }, theme.mark(.attention).solid, theme.stroke.line); x += 100; const k: canim.Rect = .{ .x = x, .y = y, .w = 120, .h = cell_size[1] }; u.fill(k, theme.color.kernel); u.label(.mono_bold, theme.size.mono.context, k, .center, "read", theme.color.on_kernel.ink); } // plaque, pin, bracket y = 624; title(u, 64, y, "plaque"); note(u, 200, y, "gold: rip 54, a line 50, the pc 24; chip"); y += 12; u.fill(.{ .x = 64, .y = y, .w = theme.metric.plaque.rip, .h = row }, theme.mark(.current).solid); u.text(.mono_bold, theme.size.mono.context, 74, rows.baseline(y), "rip", t.ink); u.fill(.{ .x = 140, .y = y, .w = theme.metric.plaque.line, .h = row }, theme.mark(.current).solid); u.text(.mono_bold, theme.size.mono.context, 140 + 46 - 24, rows.baseline(y), "21", t.ink); u.fill(.{ .x = 212, .y = y, .w = theme.metric.plaque.pc, .h = row }, theme.mark(.current).solid); sk.draw.polygon(u.f, &.{ .{ 230, y + 12 }, .{ 220, y + 6 }, .{ 220, y + 18 } }, u.at.pen(.{ .fill = ui.rgb(t.ink) })); u.chip(.{ .x = 260, .y = y + 2, .w = 32, .h = 20 }); u.text(.mono_bold, theme.size.mono.context, 264, rows.baseline(y), "PF", t.bright); y = 698; title(u, 64, y, "pin"); note(u, 140, y, "row, end; under; a count after three names"); y += 12; u.pinRow(64, y, &.{ "rsp", "rbp" }, region.stack); // At a view's row's end (a dump has no lane before its addresses). _ = u.pinEnd(440, y, &.{"rsi"}, region.stack); u.pinRow(64, y + row, &.{ "rax", "rdi", "rsi", "r8" }, region.heap); // Clear of the note over it. u.fill(.{ .x = 520, .y = y - 20, .w = 116, .h = 20 }, theme.color.raised); u.pinUnder(578, y, &.{ "rax", "rdi" }, region.heap, theme.size.mono.context); y = 698; title(u, 700, y, "bracket"); note(u, 800, y, "quiet, tie, thread"); y += 12; u.bracket(712, y, y + 2 * row, ui.mix(region.heap, theme.color.page, 0.6), theme.metric.bracket.quiet, 1, false); u.bracket(762, y, y + 2 * row, theme.mark(.read).solid, theme.metric.bracket.tie, 1, false); u.bracket(812, y, y + 2 * row, theme.mark(.current).solid, theme.metric.bracket.thread, 1, false); // tag y = 800; title(u, 64, y, "tag"); note(u, 120, y, "focus; a note; a legend"); y += 12; _ = (u.moved(64, y)).panel(560, 56, "the list", .{ .focus = true, .note = "a note, ranged right" }); _ = (u.moved(660, y)).panel(880, 56, "registers", .{ .legend = &canim.contextLegend }); } fn rowsPage(u: ui.Ui, p: *const Pages) void { const m = p.rec.moment(p.moment); const regs = (m.regs(p.rec.tid) catch null).?; const row = theme.metric.context.row; title(u, 64, 40, "2 rows"); var y: f32 = 80; title(u, 64, y, "chain"); note(u, 160, y, "as far as it points; cut where its room ends: a string first, then `more`"); y += 12; _ = rows.chain(u, 64, y, m, regs.rbp, 880, .{}); _ = rows.chain(u, 64, y + row, m, regs.rbp, 420, .{}); _ = rows.chain(u, 64, y + 2 * row, m, regs.r12, 880, .{}); _ = rows.chain(u, 64, y + 3 * row, m, regs.r12, 320, .{}); y = 214; title(u, 64, y, "reg"); note(u, 140, y, "plain, struck, held, read; rip with the flags"); y += 12; var panel = u.moved(64, y); _ = rows.reg(panel, 0, 880, "rsi", m, regs.rsi, .{}); _ = rows.reg(panel, row, 880, "rdi", m, regs.rdi, .{ .first = .struck }); _ = rows.reg(panel, 2 * row, 880, "rax", m, regs.rax, .{ .first = .ember }); _ = rows.reg(panel, 3 * row, 880, "rbp", m, regs.rbp, .{ .read = 1, .read_shows = 1 }); rows.rip(panel, 4 * row, 880, m, regs.rip, regs.eflags, 1 << 6, 1, 0, 1 << 6, 1, null); y = 380; title(u, 64, y, "slot"); note(u, 140, y, "its pins in the lane; the offset from rsp; the address from 184 and its chain; a role; `call` spans at the right"); y += 12; panel = u.moved(64, y); for (0..4) |i| { const addr = regs.rsp + 8 * i; _ = rows.slot(panel, @as(f32, @floatFromInt(i)) * row, 880, m, addr, @intCast(8 * i), if (i == 0) &.{ "rsp", "rbp" } else &.{}, 1, .{ .lead = ui.shared(&.{ regs.rsp, regs.rsp + 24 }), .first = if (i == 2) .ember else .none }, if (i == 0) "saved rbp" else if (i == 1) "cur" else "", i == 1, null); } rows.span(panel, 880, 0, 2 * row, "reverse", true, false); rows.span(panel, 880, 2 * row, 4 * row, "main", false, true); y = 520; title(u, 64, y, "call"); note(u, 140, y, "row, in a backtrace"); y += 12; panel = u.moved(64, y); rows.callRow(panel, 0, 880, 0, "reverse+225", "", "list.c:22", true); rows.callRow(panel, row, 880, 1, "main+42", "", "list.c:40", false); y = 600; title(u, 64, y, "line"); note(u, 140, y, "current, trail, plain; cut at 67 characters"); y += 12; panel = u.moved(64, y); const plain = " cur->next = prev;"; const styles: [128]u8 = @splat(0); rows.line(panel, 0, 880, 22, 0, plain, styles[0..plain.len], .{ .current = 0 }); rows.line(panel, row, 880, 21, 0, " node *next = cur->next;", styles[0..31], .{ .trail = 0 }); rows.line(panel, 2 * row, 880, 20, 0, " while (cur) {", styles[0..17], .{ .trail = 1 }); const long = " a line of source longer than the panel has room for, which is cut at its end"; rows.line(panel, 3 * row, 880, 9, 0, long, styles[0..long.len], .plain); y = 860; title(u, 64, y, "insn"); note(u, 140, y, "operands without size words; a width where no register says it; padding faint"); y += 12; panel = u.moved(64, y); const Insn = canim.Disasm.Row; for ([_]Insn{ .{ .addr = 0x100191b, .len = 5, .text = "nop dword ptr [rax + rax]" }, .{ .addr = 0x100192a, .len = 4, .text = "mov qword ptr [rax + 8], rcx" }, .{ .addr = 0x7ffff7d10f0e, .len = 7, .text = "cmp byte ptr [rip + 0x11018b], 0" }, .{ .addr = 0x7ffff7d10f94, .len = 7, .text = "mov dword ptr [rbp - 0x60], 0x10" }, .{ .addr = 0x7ffff7d10f9b, .len = 4, .text = "movsxd r10, dword ptr [rbp - 0x30]" }, }, 0..) |one, i| canim.disasm.plainRow(panel, one, @as(f32, @floatFromInt(i)) * row); y = 750; title(u, 64, y, "bytes"); note(u, 160, y, "runs from the types; marks per run: struck, read, held; read as their types: a char, a bool, an int, a pointer"); y += 12; panel = u.moved(976, y); var values: [16]u8 = .{ 12, 0, 0, 0, 0, 0, 0, 0, 0x10, 0x70, 0x40, 0, 0, 0, 0, 0 }; var known: [16]bool = @splat(true); rows.bytes(panel, 0, 0x407030, &values, &known, &.{ .{ .first = 0, .len = 8, .kind = .number, .read = 1 }, .{ .first = 8, .len = 8, .kind = .pointer, .heat = .struck } }, region.heap, 4, true, m); values[8] = 0x50; rows.bytes(panel, row, 0x407050, &values, &known, &.{ .{ .first = 0, .len = 8, .kind = .number }, .{ .first = 8, .len = 8, .kind = .pointer, .heat = .ember } }, region.heap, 4, true, m); known = @splat(false); rows.bytes(panel, 2 * row, 0x407060, &values, &known, &.{ .{ .first = 0, .len = 8, .kind = .unread }, .{ .first = 8, .len = 8, .kind = .unread } }, region.heap, 4, false, m); // A struct of a char, a bool, padding, an int and a pointer: each read as its type says. values = .{ 'A', 1, 0, 0, 0xfd, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0 }; known = @splat(true); const types = canim.Recording.types; const char: types.Type = .{ .scalar = .{ .kind = .char, .bits = 8 } }; const boolean: types.Type = .{ .scalar = .{ .kind = .bool, .bits = 8 } }; const int: types.Type = .{ .scalar = .{ .kind = .int, .bits = 32 } }; rows.bytes(panel, 3 * row, 0x407080, &values, &known, &.{ .{ .first = 0, .len = 1, .kind = .number }, .{ .first = 1, .len = 1, .kind = .number }, .{ .first = 2, .len = 2, .kind = .loose }, .{ .first = 4, .len = 4, .kind = .number }, .{ .first = 8, .len = 8, .kind = .pointer } }, region.heap, 4, true, m); _ = canim.hexdump.reading(panel, 3 * row, 0, m, &values, &known, &.{ .{ .at = 0, .len = 1, .type = char }, .{ .at = 1, .len = 1, .type = boolean }, .{ .at = 4, .len = 4, .type = int }, .{ .at = 8, .len = 8, .reads = .pointer } }); } fn frame(s: *anim.Frame) void { const rec = canim.open(recordings.gallery); const reverse = rec.call("reverse", 0); // In the loop, about to read `cur->next`. const rest = rec.lineMoment(21, rec.lineMoment(24, reverse.enter)); const pages = canim.add(s, Pages{ .rec = rec, .moment = rest }); s.play(.{pages.fadeIn()}, .{ .seconds = 0 }); const at = canim.cursor(s, rec, 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 }); // A loupe from rax (the last node, whose `next` is NULL by then), and // one from the `next` of the node before it in the first's rows: two in depth. const rax = rec.register(rec.next(.line, rest), "rax"); const near = canim.loupe(s, .{ .cursor = at, .stage = ctx.stage, .from = .{ .register = "rax" } }); const deeper = canim.loupe(s, .{ .cursor = at, .stage = ctx.stage, .from = .{ .field = .{ .loupe = near, .at = rax - 0x20 + 8 } } }); const joins = ctx.ties(s); const says = canim.caption(s, "The gallery: the frame, at rest. Every panel, the thread,\nthe lens beside it: the list and the bytes it is drawn from."); const panels = .{ ctx.clock, ctx.registers, ctx.stack, ctx.backtrace, ctx.source, ctx.disasm, list, joins, says }; s.wait(6); var all: [panels.len]anim.Animation = undefined; inline for (panels, 0..) |o, i| all[i] = o.fadeIn(); s.play(all, .{ .seconds = 0 }); // A step at 9 s, its strikes and ties at about 9.6; each state 3 s. s.wait(9 - s.cursor); at.walk(s, .line, rec.next(.line, rest)); s.wait(12 - s.cursor); ctx.stage.relayout(s, canim.layout.split.subject); s.wait(15 - s.cursor); ctx.stage.relayout(s, canim.layout.split.none); s.wait(18 - s.cursor); near.open(s); s.wait(18.8 - s.cursor); deeper.open(s); s.wait(21 - s.cursor); }