summaryrefslogtreecommitdiff
path: root/design/mock/intro.py
diff options
context:
space:
mode:
Diffstat (limited to 'design/mock/intro.py')
-rw-r--r--design/mock/intro.py122
1 files changed, 117 insertions, 5 deletions
diff --git a/design/mock/intro.py b/design/mock/intro.py
index 098455c..a0684fd 100644
--- a/design/mock/intro.py
+++ b/design/mock/intro.py
@@ -150,11 +150,124 @@ def segments(g, x, y, hot=(), rsp=None, rip=None, label_x=None):
return yy
+TOP = 0x800000000000 # the user half's end: 0x00007fffffffffff + 1, 128 TiB
+
+
+def ink_of(lo, perm, name):
+ return STACK if name == "[stack]" else HEAP if name == "[heap]" else INK[perm]
+
+
+def bar(g, x, y, w, h, lo, hi, unit, step, labels=False, label_x=None, hot=()):
+ """`segments` at one level: the stretch lo..hi to a linear scale, high on top, its ruler on the left in
+ `unit` every `step`, each mapping where it is, a hairline (1 unit) when that is all it comes to."""
+ yof = lambda a: y + h - (a - lo) / (hi - lo) * h
+ g.rect(x, y, w, h, PAGE)
+ g.frame(x, y, w, h, DIM, 2)
+ n = (hi - lo) // step
+ for k in range(int(n) + 1):
+ a = lo + k * step
+ yy = yof(a)
+ g.rect(x - 8, yy - 1, 8, 2, FAINT)
+ if k % max(int(n) // 8, 1) == 0 or k == n:
+ g.t(x - 12, yy + 6, "%d %s" % (k * step // unit, {1 << 40: "TiB", 1 << 30: "GiB", 1 << 20: "MiB",
+ 1 << 10: "KiB"}[unit]), 18, FAINT, "sans", "end")
+ for lo_, hi_, perm, name in MAPPINGS:
+ if hi_ <= lo or lo_ >= hi:
+ continue
+ a, z = max(lo_, lo), min(hi_, hi)
+ y0, y1 = yof(z), yof(a)
+ ink = ink_of(lo_, perm, name)
+ g.rect(x + 2, y0, w - 4, max(y1 - y0, 1), ink if y1 - y0 < 3 else mix(ink, PAGE, 0.35))
+ if lo_ in hot:
+ g.frame(x - 2, y0 - 3, w + 4, max(y1 - y0, 1) + 6, READ, 2)
+ if labels and y1 - y0 >= 6:
+ g.path(f"M{x + w + 4},{(y0 + y1) / 2} H{label_x - 6}", RULE, 2)
+ g.t(label_x, (y0 + y1) / 2 + 7, "%s %s" % (perm, name or "anonymous"), 18, VELLUM, "sans")
+ g.t(label_x + 200, (y0 + y1) / 2 + 7, size(hi_ - lo_), 18, FAINT, "sans")
+ return yof
+
+
+def magnify(g, yof, x0, lo, hi, x1, y1, h1):
+ """The lines of a magnification: from the stretch's two ends on one level to the next level's corners."""
+ g.path(f"M{x0},{yof(hi)} L{x1},{y1}", RULE, 2)
+ g.path(f"M{x0},{yof(lo)} L{x1},{y1 + h1}", RULE, 2)
+
+
+def treatment_a(g, x, y, H, wide=False, hot=()):
+ """A: the whole user half to true scale, then two magnifications of its two clusters, then the libraries."""
+ yof = bar(g, x, y, 60, H, 0, TOP, 1 << 40, 16 << 40)
+ g.t(x - 12, y - 30, "0x7fffffffffff · the user half's end", 18, DIM, "sans")
+ g.t(x - 12, y + H + 26, "0", 18, DIM, "sans")
+ g.t(x - 12, y - 52, "above: 16 EiB not canonical, then the kernel's half", 18, FAINT, "sans")
+ # the top cluster: the libraries and the stack, the last 128 MiB of the user half
+ t_lo, t_hi = TOP - (256 << 20), TOP
+ X2 = x + 240
+ y2 = bar(g, X2, y, 60, H * 0.45, t_lo, t_hi, 1 << 20, 32 << 20, hot=hot)
+ magnify(g, yof, x + 60, t_lo, t_hi, X2, y, H * 0.45)
+ g.t(X2, y - 8, "the top 256 MiB · × 500 000", 18, DIM, "sans")
+ # the libraries: 4 MiB of them, with names
+ l_lo, l_hi = 0x7ffff7c00000, 0x7ffff8000000
+ X3 = X2 + 300
+ y3 = bar(g, X3, y, 60, H * 0.45, l_lo, l_hi, 1 << 20, 1 << 20, labels=True, label_x=X3 + 80, hot=hot)
+ magnify(g, y2, X2 + 60, l_lo, l_hi, X3, y, H * 0.45)
+ g.t(X3, y - 8, "the libraries, 4 MiB · × 32", 18, DIM, "sans")
+ # the bottom cluster: the program and its heap, the first 20 MiB
+ b_lo, b_hi = 0, 20 << 20
+ yb = y + H * 0.55
+ y4 = bar(g, X2, yb, 60, H * 0.45, b_lo, b_hi, 1 << 20, 4 << 20, labels=True, label_x=X2 + 80, hot=hot)
+ magnify(g, yof, x + 60, b_lo, b_hi, X2, yb, H * 0.45)
+ g.t(X2, yb - 8, "the bottom 20 MiB · × 7 000 000", 18, DIM, "sans")
+ # the stack, its 132 KiB, in the top magnification's level: its label there
+ sy = y2(0x7ffffffff000)
+ g.path(f"M{X2 + 64},{sy + 2} L{X2 + 120},{y + H * 0.45 + 30}", RULE, 2)
+ g.t(X2 + 124, y + H * 0.45 + 36, "rw- [stack] 132 KiB, rsp in it: a hairline even here", 18, VELLUM, "sans")
+ gen.arrow(g, [(X2 + 30, sy + 4), (X2 + 30, sy + 26)], BRIGHT, 2, hl=8, hw=8)
+ return yof
+
+
def frame_space(name):
- """Mock 34: the rectangle alone, every label reading."""
+ """Mock 34: treatment A at full size: the whole user half to scale, and magnified into its clusters."""
gen.W, gen.H = 1920, 1080
g = Svg()
- segments(g, 560, 110, rsp=RSP, rip=0x1001926, label_x=760)
+ treatment_a(g, 200, 100, 760)
+ gen.caption(g, [[("If this space were as tall as the Eiffel Tower, all the program has mapped would",)],
+ [("be thinner than a hair: the stack a third of a micron, at the very top.",)]])
+ g.save(name)
+
+
+def sheet_abc(name):
+ """Mock 35: three treatments of physicality, on the list recording's mappings."""
+ gen.W, gen.H = 2880, 1000
+ g = Svg()
+ for k, (t, sub) in enumerate([("A", "true scale, then magnified: the recommended"),
+ ("B", "one long strip of powers of ten, left to right"),
+ ("C", "true scale alone, distances written")]):
+ x0 = 80 + k * 960
+ g.t(x0, 50, t, 44, GOLD, "sansb")
+ g.t(x0 + 50, 50, sub, 22, VELLUM, "sans")
+ if t == "A":
+ treatment_a(g, x0 + 120, 130, 760)
+ elif t == "B":
+ levels = [(0, TOP, 1 << 40, 32 << 40, "128 TiB"), (TOP - (128 << 20), TOP, 1 << 20, 32 << 20, "× 1 000 000"),
+ (0x7ffff7c00000, 0x7ffff8000000, 1 << 20, 1 << 20, "× 32"),
+ (0x7ffffffde000, 0x7ffffffff000, 1 << 10, 32 << 10, "the stack × 30")]
+ prev = None
+ for j, (lo, hi, u, st_, lab) in enumerate(levels):
+ xx = x0 + 70 + j * 210
+ f = bar(g, xx, 130, 50, 760, lo, hi, u, st_)
+ g.t(xx, 120, lab, 18, DIM, "sans")
+ if prev:
+ magnify(g, prev[0], prev[1] + 50, lo, hi, xx, 130, 760)
+ prev = (f, xx)
+ else:
+ yof = bar(g, x0 + 150, 130, 80, 760, 0, TOP, 1 << 40, 16 << 40)
+ for a, txt in [(0x7ffffffde000, "the stack, 132 KiB, a hairline at the top"),
+ (0x7ffff7c00000, "the libraries, 4 MiB, 127 MiB below it"),
+ (0x1000000, "the program and its heap, 0.2 MiB, 16 MiB above 0")]:
+ yy = yof(a)
+ g.path(f"M{x0 + 236},{yy} H{x0 + 300}", RULE, 2)
+ g.t(x0 + 306, yy + 6 + (20 if a == 0x7ffff7c00000 else 0), txt, 18, VELLUM, "sans")
+ g.t(x0 + 306, 500, "127 TiB of nothing between", 22, FAINT, "sans")
g.save(name)
@@ -208,9 +321,7 @@ def frame_words(name):
g.frame(12 * A + 12 + 8 * 30 + 24 - 6, ys[k] - 1, 7 * A + 12, ROW + 2, READ, 2)
g.o.append("</g>")
g.o.append('<g transform="translate(0,0)">')
- g.o.append('<g transform="translate(1000,110) scale(0.8)">') # the stage holds it whole above the caption
- segments(g, 200, 0, hot={0x1001000}, rsp=RSP, label_x=380)
- g.o.append("</g>")
+ treatment_a(g, 1060, 110, 740, hot={0x1001000})
g.o.append("</g>")
gen.caption(g, [[("Eight bytes make a word, stored low byte first: read right to left,",)],
[("this one is ",), ("10018b0", "mono"), (", an address in the code, so it takes code's ink.",)]])
@@ -322,3 +433,4 @@ if __name__ == "__main__":
frame_code("32-intro-code")
frame_aligned("33-aligned")
frame_space("34-segments")
+ sheet_abc("35-segments-abc")