summaryrefslogtreecommitdiff
path: root/design/mock/gen.py
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 14:12:42 -0300
committerGabriel Schneider <[email protected]>2026-11-10 14:35:56 -0300
commitf8740f6996eefc235af066a6686f52847c158a6b (patch)
tree1536ce2825e337e2dac75046093b583d04a96d9b /design/mock/gen.py
parente2fa716dcda7de877908de006adc34f0c3593693 (diff)
downloadcomputeranim-f8740f6996eefc235af066a6686f52847c158a6b.tar.gz
computeranim-f8740f6996eefc235af066a6686f52847c158a6b.zip
design, revision 2: the whole context in every frame, a lens beside it
The user's premise: show what pwndbg shows, hide nothing; the semantic views stay as a lens on the machine. So every frame holds the registers (all, each followed as a pointer), the stack telescope and the backtrace in a column that never changes, and the source, the disassembly and the scene's lens in the other. A value's ink says where it points (stack, heap, code, data; rwx underlined), its paper says what happened to it. JetBrains Mono NL for everything mono; the floor is mono 20, which a phone does not read: what narration depends on is also in the caption. Mocks 9 to 11 are drawn from a real recording of targets/list.
Diffstat (limited to 'design/mock/gen.py')
-rw-r--r--design/mock/gen.py227
1 files changed, 131 insertions, 96 deletions
diff --git a/design/mock/gen.py b/design/mock/gen.py
index 6a9733e..afd7a5a 100644
--- a/design/mock/gen.py
+++ b/design/mock/gen.py
@@ -17,12 +17,15 @@ HERE = os.path.dirname(os.path.abspath(__file__))
PAGE, RAISED, RULE = "#0a1030", "#16245f", "#3a4a8a"
VELLUM, BRIGHT, DIM, FAINT = "#eee6d2", "#fff8e8", "#9aa6d9", "#6a7ab8"
INK = "#050a24" # letters on a bright fill
-GOLD, VERM, READ, PTR, ALLOC = "#e8c46a", "#ff6a4a", "#6fd6e6", "#d59cf5", "#7fdc9a"
+GOLD, VERM, READ, ALLOC = "#e8c46a", "#ff6a4a", "#6fd6e6", "#7fdc9a"
+# Where an address points, as pwndbg colours it: the ink of its digits, and of an arrow to it.
+STACK, HEAP, CODE, DATA = "#f2d675", "#86b6ff", "#ff8f9a", "#d59cf5"
+LINK = HEAP # the region the pointers a frame draws point into; each frame sets it
# An accent's ember: its hold state. Chosen, not alpha-blended: gold over lapis blends to grey.
-EMBER = {GOLD: "#4a3d1c", VERM: "#5a2218", READ: "#1c4652", PTR: "#45305a", ALLOC: "#1f4a33"}
+EMBER = {GOLD: "#4a3d1c", VERM: "#5a2218", READ: "#1c4652", ALLOC: "#1f4a33"}
TRAIL = ["#ae9350", "#746235", "#463b20"] # gold, cooling: newest first
KERNEL, KERNEL_RULE, KERNEL_DIM, KERNEL_HELD = "#eee6d2", "#b9ad8e", "#4a5488", "#f3b9a0"
-KW, LIT, COMMENT = "#c0dcff", "#c8f0d8", "#9aa6d9"
+KW, LIT, COMMENT = "#c0dcff", "#b5e8c8", "#9aa6d9"
OCHRE, TEAL = "#8a5e0c", "#17707c" # the first two pigments: identity
MX, MY = 64, 48 # margins
@@ -34,8 +37,8 @@ TAG_H = 48
CELL = 48 # byte cell pitch; drawn 46
ROW = 60 # memory row pitch
LH = 48 # code line, register row
-ADV = 0.6 # Go Mono advance, em
-SM, DATA, VAL, HERO = 25, 30, 35, 60 # mono sizes: multiples of 5, so an advance is whole units
+ADV = 0.6 # JetBrains Mono's advance, em: the same as Go Mono's
+SM, DATA_SIZE, VAL, HERO = 25, 30, 35, 60 # mono sizes: multiples of 5, so an advance is whole units
def colx(i):
@@ -56,9 +59,10 @@ def esc(s):
FONTS = {
- "mono": ("Go Mono", "normal", "normal"),
- "monob": ("Go Mono", "bold", "normal"),
- "monoi": ("Go Mono", "normal", "italic"),
+ "mono": ("JetBrains Mono NL", "normal", "normal"),
+ "monom": ("JetBrains Mono NL", "500", "normal"), # at 20 and 25: thin strokes do not survive a stream
+ "monob": ("JetBrains Mono NL", "bold", "normal"),
+ "monoi": ("JetBrains Mono NL", "normal", "italic"),
"sans": ("Go", "normal", "normal"),
"sansm": ("Go Medium", "normal", "normal"),
"sansb": ("Go", "bold", "normal"),
@@ -127,7 +131,7 @@ class Svg:
a += f' stroke="{stroke}" stroke-width="{sw}"'
self.o.append(a + "/>")
- def t(self, x, y, s, size=DATA, fill=VELLUM, font="mono", anchor="start"):
+ def t(self, x, y, s, size=DATA_SIZE, fill=VELLUM, font="mono", anchor="start"):
"""One run of text; y is the baseline. Mono is laid a character at a time on its
whole-unit advance, as the renderer does."""
fam, wt, st = FONTS[font]
@@ -149,7 +153,7 @@ class Svg:
a += f' text-anchor="{anchor}"'
self.o.append(f'<text x="{x:.1f}" y="{y:.1f}"{a}>{esc(s)}</text>')
- def tc(self, x, y, w, h, s, size=DATA, fill=VELLUM, font="mono"):
+ def tc(self, x, y, w, h, s, size=DATA_SIZE, fill=VELLUM, font="mono"):
"""Text centred in a box, on its cap height."""
self.t(x + w / 2, y + h / 2 + 0.36 * size, s, size, fill, font, "middle")
@@ -158,7 +162,7 @@ class Svg:
a = f'<text x="{x:.1f}" y="{y:.1f}" font-size="{size}" xml:space="preserve">'
for p in parts:
fam, wt, st = FONTS[p[2] if len(p) > 2 else "sans"]
- sz = f' font-size="{round(size * 0.875)}"' if fam == "Go Mono" else ""
+ sz = f' font-size="{round(size * 0.875)}"' if "Mono" in fam else ""
a += f'<tspan font-family="{fam}" font-weight="{wt}" fill="{p[1]}"{sz}>{esc(p[0])}</tspan>'
self.o.append(a + "</text>")
@@ -179,8 +183,10 @@ def head_tri(g, x2, y2, ux, uy, color, hl, hw):
g.path(f"M{x2:.1f},{y2:.1f} L{bx + nx:.1f},{by + ny:.1f} L{bx - nx:.1f},{by - ny:.1f} Z", fill=color)
-def arrow(g, pts, color=PTR, sw=4, r=12, head=True, dash=None, hl=18, hw=16):
- """A polyline with filleted elbows and a filled head on its last point."""
+def arrow(g, pts, color=None, sw=4, r=12, head=True, dash=None, hl=18, hw=16):
+ """A polyline with filleted elbows and a filled head on its last point, in the
+ colour of the region it points into."""
+ color = color or LINK
pts = [tuple(map(float, p)) for p in pts]
(x1, y1), (x2, y2) = pts[-2], pts[-1]
L = math.hypot(x2 - x1, y2 - y1)
@@ -280,13 +286,24 @@ def elide(g, x, y, label="", h=24):
# ---- numbers --------------------------------------------------------------
-def hexw(n, size=DATA):
+def hexw(n, size=DATA_SIZE):
adv = round(ADV * size)
return n * adv + (n // 4 - 1) * round(adv / 2)
-def hexgroups(g, x, y, digits, size=DATA, lead=FAINT, fill=VELLUM, font="mono", right=False, all_fill=None):
- """Hex in fours, half an advance apart; leading zeros in `lead`."""
+def region(digits):
+ """Where a value of these mocks points: the ink of its digits. None for what is not a pointer
+ (and for read-only data, which pwndbg leaves plain)."""
+ d = digits.lstrip("0")
+ for prefix, ink in (("7ffd", STACK), ("55d4a1c03", HEAP), ("55d4a1c01", CODE), ("7f3c", CODE)):
+ if len(d) == 12 and d.startswith(prefix):
+ return ink
+ return None
+
+
+def hexgroups(g, x, y, digits, size=DATA_SIZE, lead=FAINT, fill=None, font="mono", right=False, all_fill=None):
+ """Hex in fours, half an advance apart; leading zeros in `lead`; a pointer in its region's ink."""
+ fill = fill or region(digits) or VELLUM
adv = round(ADV * size)
if right:
x -= hexw(len(digits), size)
@@ -335,7 +352,7 @@ def byte(g, x, y, v, state="plain"):
g.rect(x, y + w - 6, w, 6, VERM)
if state == "read":
g.frame(x, y, w, w, READ, 3)
- g.tc(x, y, w, w, v, DATA, ink, font)
+ g.tc(x, y, w, w, v, DATA_SIZE, ink, font)
def word(g, x, y, digits, state="plain", nbytes=8):
@@ -353,13 +370,13 @@ def word(g, x, y, digits, state="plain", nbytes=8):
g.rect(x, y + h - 6, w, 6, VERM)
if state == "read":
g.frame(x, y, w, h, READ, 3)
- hexgroups(g, x + (w - hexw(len(digits))) / 2, base(y, h, DATA), digits, all_fill=all_fill, font=font)
+ hexgroups(g, x + (w - hexw(len(digits))) / 2, base(y, h, DATA_SIZE), digits, all_fill=all_fill, font=font)
return w
def ptr_frame(g, x, y, nbytes=8):
"""These bytes are one pointer."""
- g.frame(x - 6, y - 6, nbytes * CELL - 2 + 12, CELL - 2 + 12, PTR, 4)
+ g.frame(x - 6, y - 6, nbytes * CELL - 2 + 12, CELL - 2 + 12, LINK, 4)
def regmark(g, xr, y, name, fill=RAISED, rows=1):
@@ -369,10 +386,10 @@ def regmark(g, xr, y, name, fill=RAISED, rows=1):
x = xr - w - 16
g.rect(x, y + 3, w, 40, fill)
if fill == RAISED:
- g.frame(x, y + 3, w, 40, PTR, 2)
+ g.frame(x, y + 3, w, 40, LINK, 2)
g.t(x + 10, base(y, CELL - 2, SM), name, SM, VELLUM, "mono")
if fill == RAISED:
- g.path(f"M{xr},{y + 23} l-14,-9 v18 Z", fill=PTR)
+ g.path(f"M{xr},{y + 23} l-14,-9 v18 Z", fill=LINK)
else:
g.rect(xr - 12, y, 6, (rows - 1) * ROW + CELL - 2, fill)
@@ -387,34 +404,34 @@ def code(g, x, y, w, lines, cur=None, trail=(), unfold=None):
gut = 3 * 18 + 16
ys = {}
for num, parts in lines:
- b = base(y, LH, DATA)
+ b = base(y, LH, DATA_SIZE)
ys[num] = b
if num == cur:
g.rect(x, y + 2, w, LH - 4, EMBER[GOLD])
g.rect(x, y + 2, gut + 4, LH - 4, GOLD)
- g.t(x + gut - 6, b, str(num), DATA, INK, "monob", "end")
+ g.t(x + gut - 6, b, str(num), DATA_SIZE, INK, "monob", "end")
else:
if num in trail:
g.rect(x, y + 2, 6, LH - 4, TRAIL[min(trail.index(num), 2)])
- g.t(x + gut - 6, b, str(num), DATA, FAINT, "mono", "end")
+ g.t(x + gut - 6, b, str(num), DATA_SIZE, FAINT, "mono", "end")
xx = x + gut + 20
for s, cls in parts:
if s.strip():
- g.t(xx + (len(s) - len(s.lstrip())) * 18, b, s.lstrip(), DATA, ink[cls], fnt[cls])
- xx += mw(s, DATA)
+ g.t(xx + (len(s) - len(s.lstrip())) * 18, b, s.lstrip(), DATA_SIZE, ink[cls], fnt[cls])
+ xx += mw(s, DATA_SIZE)
y += LH
if unfold and unfold[0] == num:
ax = x + gut + 20 + 36
g.line(ax - 18, y + 2, ax - 18, y + len(unfold[1]) * LH - 2, RULE, 2)
for i, (op, args) in enumerate(unfold[1]):
- b2 = base(y, LH, DATA)
+ b2 = base(y, LH, DATA_SIZE)
on = i == unfold[2]
if on:
g.rect(ax - 22, y + 3, w - (ax - 22 - x), LH - 6, EMBER[GOLD])
g.rect(ax - 22, y + 3, 8, LH - 6, GOLD)
- g.t(ax, b2, op, DATA, VELLUM if on else DIM, "monob" if on else "mono")
+ g.t(ax, b2, op, DATA_SIZE, VELLUM if on else DIM, "monob" if on else "mono")
if args:
- g.t(ax + 5 * 18, b2, args, DATA, VELLUM if on else DIM, "mono")
+ g.t(ax + 5 * 18, b2, args, DATA_SIZE, VELLUM if on else DIM, "mono")
ys[("asm", i)] = b2
y += LH
return ys
@@ -427,7 +444,7 @@ def regs(g, x, y, w, rows, flags=None):
vx = x + w - 18
vw = hexw(16)
for name, val, st in rows:
- b = base(y, LH, DATA)
+ b = base(y, LH, DATA_SIZE)
cell = (vx - vw - 10, y + 3, vw + 20, LH - 6)
if st == "pc":
g.rect(x, y + 3, w, LH - 6, EMBER[GOLD])
@@ -443,7 +460,7 @@ def regs(g, x, y, w, rows, flags=None):
g.rect(*cell, EMBER[READ])
g.frame(*cell, READ, 3)
hexgroups(g, vx, b, val, right=True)
- g.t(x + 18, b, name, DATA, INK if st == "pc" else DIM, "monob" if st == "pc" else "mono")
+ g.t(x + 18, b, name, DATA_SIZE, INK if st == "pc" else DIM, "monob" if st == "pc" else "mono")
out[name] = y
y += LH
if flags:
@@ -474,10 +491,10 @@ def cards(g, x, y, w, items, h=56, gap=12, on_kernel=False):
else:
g.rect(x, y, w, h, EMBER[GOLD] if cur else RAISED)
g.rect(x, y, 12, h, GOLD if cur else RULE)
- b = base(y, h, DATA)
- g.t(x + 28, b, name, DATA, ink, "monob" if cur else "mono")
+ b = base(y, h, DATA_SIZE)
+ g.t(x + 28, b, name, DATA_SIZE, ink, "monob" if cur else "mono")
if args:
- g.t(x + 28 + mw(name, DATA) + 18, b, args, DATA, ink if cur else dim, "mono")
+ g.t(x + 28 + mw(name, DATA_SIZE) + 18, b, args, DATA_SIZE, ink if cur else dim, "mono")
if where:
g.t(x + w - 14, base(y, h, SM), where, SM, dim if cur or on_kernel else FAINT, "mono", "end")
y += h + gap
@@ -496,7 +513,7 @@ def node(g, x, y, value, state="plain", body=RAISED, null=False, w=180, h=72):
if null:
g.path(f"M{nx + 16},{y + h - 14} L{nx + pw - 14},{y + 14}", DIM, 3)
else:
- g.rect(cx - 7, cy - 7, 14, 14, INK if state == "write" else PTR)
+ g.rect(cx - 7, cy - 7, 14, 14, INK if state == "write" else LINK)
return cx, cy
@@ -549,7 +566,7 @@ def frame1():
]
code(g, bx + 2, by + 16, bw - 4, lines, cur=4, trail=(3, 6))
# what the current frame sees, at the end of its line
- plaque(g, bx + 2 + 70 + 20 + mw(" if (n < 2)", DATA) + 36, by + 16 + 3 * LH + 4, "n = 1", SM, VELLUM, "none", DIM)
+ plaque(g, bx + 2 + 70 + 20 + mw(" if (n < 2)", DATA_SIZE) + 36, by + 16 + 3 * LH + 4, "n = 1", SM, VELLUM, "none", DIM)
# the calls so far
tx, ty, tw_, th = panel(g, colx(5), STAGE_Y, span(7), 336, "calls of fib(n)", right="each result on its call's shoulder")
@@ -573,13 +590,13 @@ def frame1():
y = Y[l]
if s == "current":
g.circle(x, y, R, GOLD)
- g.t(x, y + 0.36 * DATA, str(n), DATA, INK, "monob", "middle")
+ g.t(x, y + 0.36 * DATA_SIZE, str(n), DATA_SIZE, INK, "monob", "middle")
elif s == "active":
g.circle(x, y, R - 2, PAGE, VELLUM, 4)
- g.t(x, y + 0.36 * DATA, str(n), DATA, VELLUM, "mono", "middle")
+ g.t(x, y + 0.36 * DATA_SIZE, str(n), DATA_SIZE, VELLUM, "mono", "middle")
else:
g.circle(x, y, R, RAISED)
- g.t(x, y + 0.36 * DATA, str(n), DATA, DIM, "mono", "middle")
+ g.t(x, y + 0.36 * DATA_SIZE, str(n), DATA_SIZE, DIM, "mono", "middle")
g.rect(x + 14, y - 34, 28, 28, PAGE)
g.frame(x + 14, y - 34, 28, 28, FAINT, 2)
g.t(x + 28, y - 20 + 0.36 * SM, str(r), SM, VELLUM, "mono", "middle")
@@ -610,6 +627,8 @@ def frame1():
# ---- frame 2: linked-list insert, nodes above the heap that holds them ----
def frame2():
+ global LINK
+ LINK = HEAP
g = Svg()
head(g, "Linked lists", lit=("source", "memory"), focus="memory", where="insert after a node")
@@ -637,12 +656,12 @@ def frame2():
y = ly + 28 + i * 52
if pig:
g.rect(bx + 20, y, 12, 46, pig)
- g.t(bx + 48, base(y, 46, DATA), name, DATA, VELLUM, "mono")
+ g.t(bx + 48, base(y, 46, DATA_SIZE), name, DATA_SIZE, VELLUM, "mono")
if val:
- hexgroups(g, bx + 118, base(y, 46, DATA), val)
+ hexgroups(g, bx + 118, base(y, 46, DATA_SIZE), val)
g.t(bx + 118 + hexw(16) + 24, base(y, 46, 28) - 1, note, 28, DIM, "sans")
else:
- g.t(bx + 118, base(y, 46, DATA), note, DATA, VELLUM, "mono")
+ g.t(bx + 118, base(y, 46, DATA_SIZE), note, DATA_SIZE, VELLUM, "mono")
# the list, as the program thinks of it
lx, ly_, lw, lh = panel(g, colx(5), STAGE_Y, span(7), 240, "the list", right="what the code means")
@@ -699,7 +718,7 @@ def frame2():
y += ROW
# pointers, in the lane left of the words; the longest outermost
- def ptr(src, dst, lane, color=PTR, dash=None, sw=4, head=True):
+ def ptr(src, dst, lane, color=None, dash=None, sw=4, head=True):
ys_, yd = ry[src] + 23, ry[dst] + 23
arrow(g, [(cx - 6, ys_), (cx - lane, ys_), (cx - lane, yd), (cx - 4, yd)], color, sw, dash=dash, head=head)
ptr(0x55d4a1c032a8, 0x55d4a1c032c0, 30, FAINT, "12 8", 3, False)
@@ -761,7 +780,7 @@ def frame3():
if ch == " ":
space_glyph(g, x + 23, y + 38)
elif rd:
- g.t(x + 23, y + 38, ch, DATA, VELLUM, "mono", "middle")
+ g.t(x + 23, y + 38, ch, DATA_SIZE, VELLUM, "mono", "middle")
g.t(x + 23, y + 72, hx_, SM, DIM if rd else FAINT, "mono", "middle")
y1 = my_ + 36
g.frame(cx - 5, y1 - 5, 8 * CELL + 8, TH + 10, READ, 3)
@@ -797,16 +816,16 @@ def frame3():
("rdx", "count", "14", "bytes"), ("rax", "returns", "", "not yet"))):
y = BY + 146 + i * 44
g.line(kx, y, kx + span(4), y, KERNEL_RULE, 2)
- b = base(y, 44, DATA)
- g.t(kx, b, reg, DATA, KERNEL_DIM, "mono")
+ b = base(y, 44, DATA_SIZE)
+ g.t(kx, b, reg, DATA_SIZE, KERNEL_DIM, "mono")
g.t(kx + 84, b - 1, name, 28, PAGE, "sansm")
vw = 0
if len(val) > 4:
hexgroups(g, kx + 220, b, val, all_fill=PAGE)
vw = hexw(len(val))
elif val:
- g.t(kx + 220, b, val, DATA, PAGE, "mono")
- vw = mw(val, DATA)
+ g.t(kx + 220, b, val, DATA_SIZE, PAGE, "mono")
+ vw = mw(val, DATA_SIZE)
if note:
g.t(kx + 220 + (vw + 20 if val else 0), b - 1, note, 28, KERNEL_DIM, "sans")
@@ -820,9 +839,9 @@ def frame3():
g.rect(x, y, CELL - 2, CELL - 2, VERM if j == 8 else KERNEL_HELD)
g.frame(x, y, CELL - 2, CELL - 2, PAGE, 2)
if chars[j] == " ":
- space_glyph(g, x + 23, base(y, CELL - 2, DATA), INK)
+ space_glyph(g, x + 23, base(y, CELL - 2, DATA_SIZE), INK)
else:
- g.tc(x, y, CELL - 2, CELL - 2, chars[j], DATA, INK, "monob" if j == 8 else "mono")
+ g.tc(x, y, CELL - 2, CELL - 2, chars[j], DATA_SIZE, INK, "monob" if j == 8 else "mono")
else:
g.frame(x, y, CELL - 2, CELL - 2, KERNEL_RULE, 2)
g.t(tx, BY + 176 + 78, "9 of 14 copied", 24, KERNEL_DIM, "sans")
@@ -834,6 +853,8 @@ def frame3():
# ---- frame 4: glibc and musl malloc, side by side -------------------------
def frame4():
+ global LINK
+ LINK = HEAP
g = Svg()
head(g, "malloc: glibc and musl", lit=("source", "memory"), focus="memory", where="heap.c:9 free(b);")
S = 4 # logical units per byte, in the strips
@@ -889,9 +910,9 @@ def frame4():
g.t(bx_ + 60, ty + CELL + 28, size, SM, DIM, "mono", "middle")
g.rect(bx_, ty, 120, CELL - 2, VERM if cnt else RAISED)
if cnt:
- g.tc(bx_, ty, 120, CELL - 2, "1 free", DATA, INK, "monob")
+ g.tc(bx_, ty, 120, CELL - 2, "1 free", DATA_SIZE, INK, "monob")
else:
- g.tc(bx_, ty, 120, CELL - 2, "0", DATA, FAINT, "mono")
+ g.tc(bx_, ty, 120, CELL - 2, "0", DATA_SIZE, FAINT, "mono")
arrow(g, [(px + 30, ty), (px + 30, rowy[1] + 23), (zx - 4, rowy[1] + 23)])
g.t(px, ty + CELL + 72, "its notes: a list for each size, kept in the heap itself", 24, DIM, "sans")
@@ -935,9 +956,9 @@ def frame4():
bx_ = bx0 + i * CELL
g.rect(bx_, yy, CELL - 2, CELL - 2, VERM if i == struck else RAISED)
if i == struck:
- g.tc(bx_, yy, CELL - 2, CELL - 2, bch, DATA, INK, "monob")
+ g.tc(bx_, yy, CELL - 2, CELL - 2, bch, DATA_SIZE, INK, "monob")
else:
- g.tc(bx_, yy, CELL - 2, CELL - 2, bch, DATA, VELLUM if bch == "1" else FAINT, "mono")
+ g.tc(bx_, yy, CELL - 2, CELL - 2, bch, DATA_SIZE, VELLUM if bch == "1" else FAINT, "mono")
g.t(bx0 + 23, ty + CELL + 28, "a", SM, DIM, "mono", "middle")
g.t(bx0 + CELL + 23, ty + CELL + 28, "b", SM, VELLUM, "mono", "middle")
g.t(bx0 + 2 * CELL + 10, ty + CELL + 28, "one bit for each slot", 22, FAINT, "sans")
@@ -950,6 +971,8 @@ def frame4():
# ---- frame 5: a memory grid mid-write, with a pointer ---------------------
def frame5():
+ global LINK
+ LINK = STACK
g = Svg()
head(g, "Where a pointer lives", lit=("source", "cpu", "memory"), focus="memory", where="hello.c:8")
@@ -1003,9 +1026,9 @@ def frame5():
byte(g, cx + j * CELL, y, v, st)
if asc:
for j, ch in enumerate(asc):
- g.t(ax + j * 18, base(y, CELL - 2, DATA), ch, DATA, FAINT if ch == "·" else VELLUM, "mono")
+ g.t(ax + j * 18, base(y, CELL - 2, DATA_SIZE), ch, DATA_SIZE, FAINT if ch == "·" else VELLUM, "mono")
if label in ("buf", "p"):
- g.t(lx, base(y, CELL - 2, DATA), label, DATA, VELLUM if st == "write" else DIM, "mono")
+ g.t(lx, base(y, CELL - 2, DATA_SIZE), label, DATA_SIZE, VELLUM if st == "write" else DIM, "mono")
elif label:
g.t(lx, base(y, CELL - 2, 28), label, 28, DIM, "sans")
yb = rowy[0x7ffd3a2c1e40]
@@ -1034,7 +1057,7 @@ def frame5():
word(g, cx, wy, "00007ffd3a2c1e40")
ptr_frame(g, cx, wy)
g.t(cx + 8 * CELL + 22, base(wy, CELL - 2, 28), "= where ", 28, DIM, "sans")
- g.t(cx + 8 * CELL + 22 + tw("= where ", 28), base(wy, CELL - 2, DATA), "buf", DATA, VELLUM, "mono")
+ g.t(cx + 8 * CELL + 22 + tw("= where ", 28), base(wy, CELL - 2, DATA_SIZE), "buf", DATA_SIZE, VELLUM, "mono")
g.t(cx + 8 * CELL + 22 + tw("= where ", 28) + 3 * 18 + 10, base(wy, CELL - 2, 28), "starts", 28, DIM, "sans")
caption(g, [[("The pointer ",), ("p", "mono"), (" is eight ordinary bytes on the stack.",)],
@@ -1053,51 +1076,63 @@ def frame6():
g.rich(MX, 540, [("glibc and musl, one ", DIM), ("free()", VELLUM, "mono"), (" at a time", DIM)], 44)
x, y, w, h = panel(g, MX, 624, W - 2 * MX, 264, "legend", right="the same marks in every picture")
- EW = (w - 40) / 6
+ EW = (w - 40) / 8
+ # What happened is on the paper; what a value is, is in its ink.
entries = [
("current", "executing now", "cur"), ("written", "by this step", "write"), ("changed", "a moment ago", "held"),
- ("read", "by this step", "read"), ("pointer", "an address", "ptr"), ("moving", "in transit", "flow"),
- ("allocated", "handed out", "alloc"), ("freed", "handed back", "free"), ("not seen", "never observed", "unk"),
- ("kernel", "the other side", "kern"), ("fault", "signal or error", "err"), ("one object", "in every view", "pig"),
+ ("read", "by this step", "read"), ("moving", "in transit", "flow"), ("not seen", "never observed", "unk"),
+ ("kernel", "the other side", "kern"), ("fault", "signal, error", "err"),
+ ("stack", "points into it", STACK), ("heap", "points into it", HEAP), ("code", "points into it", CODE),
+ ("data", "points into it", DATA), ("rwx", "write and run", "rwx"), ("text", "a string", "str"),
+ ("allocated", "handed out", "alloc"), ("freed", "handed back", "free"),
]
c = CELL - 2
+ SW = 72
for i, (name, gloss, kind) in enumerate(entries):
- ex = x + 24 + (i % 6) * EW
- ey = y + 24 + (i // 6) * 96
+ ex = x + 24 + (i % 8) * EW
+ ey = y + 24 + (i // 8) * 96
sx, sy = ex, ey + 10
if kind == "cur":
- g.rect(sx, sy, 94, c, GOLD)
- g.tc(sx, sy, 94, c, "rip", DATA, INK, "monob")
- elif kind in ("write", "held", "read"):
- byte(g, sx, sy, "2a", kind)
- byte(g, sx + CELL, sy, "00", kind)
- elif kind == "ptr":
- g.rect(sx, sy, 34, c, RAISED)
- g.frame(sx - 6, sy - 6, 46, c + 12, PTR, 4)
- arrow(g, [(sx + 40, sy + 23), (sx + 94, sy + 23)])
+ g.rect(sx, sy, SW, c, GOLD)
+ g.tc(sx, sy, SW, c, "rip", DATA_SIZE, INK, "monob")
+ elif kind == "write":
+ g.rect(sx, sy, SW, c, VERM)
+ g.tc(sx, sy, SW, c, "2a", DATA_SIZE, INK, "monob")
+ elif kind == "held":
+ g.rect(sx, sy, SW, c, EMBER[VERM])
+ g.rect(sx, sy + c - 6, SW, 6, VERM)
+ g.tc(sx, sy, SW, c, "2a", DATA_SIZE, VELLUM, "mono")
+ elif kind == "read":
+ g.rect(sx, sy, SW, c, EMBER[READ])
+ g.frame(sx, sy, SW, c, READ, 3)
+ g.tc(sx, sy, SW, c, "2a", DATA_SIZE, VELLUM, "mono")
elif kind == "flow":
- flow(g, [(sx, sy + 23), (sx + 94, sy + 23)])
- elif kind == "alloc":
- g.rect(sx, sy, 94, c, EMBER[ALLOC])
- g.frame(sx, sy, 94, c, ALLOC, 3)
- elif kind == "free":
- g.rect(sx, sy, 94, c, "url(#hatch)")
- g.frame(sx, sy, 94, c, DIM, 3, dash="12 8")
+ flow(g, [(sx, sy + 23), (sx + SW, sy + 23)])
elif kind == "unk":
- byte(g, sx, sy, None)
- byte(g, sx + CELL, sy, None)
+ g.rect(sx + 22, sy + 20, 6, 6, FAINT)
+ g.rect(sx + 44, sy + 20, 6, 6, FAINT)
elif kind == "kern":
- g.rect(sx, sy, 94, c, KERNEL)
- g.tc(sx, sy, 94, c, "sys", DATA, PAGE, "monob")
+ g.rect(sx, sy, SW, c, KERNEL)
+ g.tc(sx, sy, SW, c, "sys", DATA_SIZE, PAGE, "monob")
elif kind == "err":
- g.rect(sx, sy, 94, c, "url(#hazard)")
- g.rect(sx + 8, sy + 8, 78, c - 16, INK)
- g.tc(sx + 8, sy + 8, 78, c - 16, "SEGV", SM, BRIGHT, "monob")
- elif kind == "pig":
- g.rect(sx, sy, 43, c, OCHRE)
- g.rect(sx + 51, sy, 43, c, TEAL)
- g.t(ex + 110, ey + 28, name, 28, VELLUM, "sansm")
- g.t(ex + 110, ey + 58, gloss, 22, DIM, "sans")
+ g.rect(sx, sy, SW, c, "url(#hazard)")
+ g.rect(sx + 8, sy + 8, SW - 16, c - 16, INK)
+ g.tc(sx + 8, sy + 8, SW - 16, c - 16, "SEGV", 20, BRIGHT, "monob")
+ elif kind == "alloc":
+ g.rect(sx, sy, SW, c, EMBER[ALLOC])
+ g.frame(sx, sy, SW, c, ALLOC, 3)
+ elif kind == "free":
+ g.rect(sx, sy, SW, c, "url(#hatch)")
+ g.frame(sx, sy, SW, c, DIM, 3, dash="12 8")
+ elif kind == "rwx":
+ g.t(sx, base(sy, c, DATA_SIZE), "7f3c", DATA_SIZE, DATA, "mono")
+ g.rect(sx, sy + c - 8, 4 * 18, 2, DATA)
+ elif kind == "str":
+ g.t(sx, base(sy, c, DATA_SIZE), '"hi"', DATA_SIZE, LIT, "mono")
+ else: # a region: the ink of an address that points there
+ g.t(sx, base(sy, c, DATA_SIZE), "7ffe", DATA_SIZE, kind, "mono")
+ g.t(ex + SW + 14, ey + 28, name, 26, VELLUM, "sansm")
+ g.t(ex + SW + 14, ey + 56, gloss, 18, DIM, "sans")
g.save("06-title-legend")
@@ -1130,9 +1165,9 @@ def frame7():
# the comparison that decided it
xa, xb = x0 + (J - 1) * CW + CW / 2, x0 + J * CW + CW / 2
mid = (xa + xb) / 2
- cw_ = mw("31 > 12", DATA) + 32
+ cw_ = mw("31 > 12", DATA_SIZE) + 32
g.frame(mid - cw_ / 2, y + 10, cw_, 46, DIM, 2)
- g.t(mid, base(y + 10, 46, DATA), "31 > 12", DATA, VELLUM, "mono", "middle")
+ g.t(mid, base(y + 10, 46, DATA_SIZE), "31 > 12", DATA_SIZE, VELLUM, "mono", "middle")
g.t(mid + cw_ / 2 + 16, base(y + 10, 46, 24), "so they trade places", 24, DIM, "sans")
# the swap, in flight: one value over, one under
@@ -1164,14 +1199,14 @@ def frame7():
lx, ly, lw, lh = panel(g, colx(7), by0, span(5), bh0, "locals", right="of sort()")
for k, (name, typ, val) in enumerate((("i", "int", "5"), ("j", "int", "4"), ("n", "int", "8"), ("a", "int *", None))):
yy = ly + 12 + k * 56
- b = base(yy, 46, DATA)
- g.t(lx + 24, b, name, DATA, VELLUM, "mono")
+ b = base(yy, 46, DATA_SIZE)
+ g.t(lx + 24, b, name, DATA_SIZE, VELLUM, "mono")
g.t(lx + 84, base(yy, 46, SM), typ, SM, FAINT, "mono")
if val:
if name == "j":
g.rect(lx + 196, yy, 76, 46, EMBER[VERM])
g.rect(lx + 196, yy + 40, 76, 6, VERM)
- g.t(lx + 212, b, val, DATA, VELLUM, "mono")
+ g.t(lx + 212, b, val, DATA_SIZE, VELLUM, "mono")
else:
hexgroups(g, lx + 212, b, "7ffd3a2c1e20")
g.t(lx + 212 + hexw(12) + 20, base(yy, 46, 24), "where a[0] is", 24, DIM, "sans")