1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
//! 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 };
if (at.t < 1) atoms(u, p) else if (at.t < 2) 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; under; a count after three names");
y += 12;
u.pinRow(64, y, &.{ "rsp", "rbp" }, region.stack);
u.pinRow(64, y + row, &.{ "rax", "rdi", "rsi", "r8" }, region.heap);
u.fill(.{ .x = 400, .y = y - 20, .w = 116, .h = 20 }, theme.color.raised);
u.pinUnder(458, 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);
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);
}
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 = 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(2);
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 3 s, its strikes and ties at about 3.6.
s.wait(3 - s.cursor);
at.walk(s, .line, rec.next(.line, rest));
s.wait(5 - s.cursor);
ctx.stage.relayout(s, canim.layout.split.subject);
s.wait(7 - s.cursor);
ctx.stage.relayout(s, canim.layout.split.none);
s.wait(9 - s.cursor);
near.open(s);
s.wait(9.8 - s.cursor);
deeper.open(s);
s.wait(11 - s.cursor);
}
|