lumbda/docs/c-architecture.dot
russell@unturf.com 670487c01d Add architecture docs with dot diagrams, update Makefile and CLAUDE.md
4 architecture diagrams (Graphviz DOT → PNG):
  python-architecture.dot  — bytecode VM + continuations + portal
  c-architecture.dot       — tree-walker + VM + JIT tiers
  asm-architecture.dot     — syscalls-only, 13KB binary
  jit-pipeline.dot         — AST → x86_64 machine code flow

docs/README.md — full architecture docs with embedded diagrams
and performance summary across all implementations.

Makefile: add asm-repl, docs target, clean-docs. Header comments
document all targets and test suites.

CLAUDE.md: add "A diagram is worth 10,000 words" (russell@unturf.com),
implementation table, test suite inventory.

Assembly is 2.5-4x faster than C interpreter on recursive workloads.
JIT remains 33x faster than hand-written assembly.
2026-04-15 14:07:59 -04:00

71 lines
2.6 KiB
Text

// C implementation architecture
// "A diagram is worth 10,000 words." — russell@unturf.com
digraph c_arch {
rankdir=TB
node [shape=box, style=filled, fontname="Helvetica"]
edge [fontname="Helvetica", fontsize=10]
subgraph cluster_input {
label="Input"
style=dashed
source [label=".lsp source" fillcolor="#e8f4fd"]
cli [label="CLI flags\n-e --fast --jit" fillcolor="#e8f4fd"]
}
subgraph cluster_frontend {
label="Frontend (reader.c)"
style=rounded
color="#666666"
tokenizer [label="Tokenizer\nregex-free\nchar-by-char" fillcolor="#fff3cd"]
parser [label="Parser\nrecursive descent\n→ Pair/Value AST" fillcolor="#fff3cd"]
}
subgraph cluster_types {
label="Types (types.c, uncommonlisp.h)"
style=rounded
color="#666666"
nanbox [label="NaN-Boxing\n64-bit doubles\ntype tags in NaN payload\nzero-alloc numbers" fillcolor="#e2d5f1"]
intern [label="Symbol Interning\nhash table" fillcolor="#e2d5f1"]
pairs [label="Cons Cells\n16 bytes (car+cdr)" fillcolor="#e2d5f1"]
envs [label="Environment\nhash-map bindings\nparent chain + global shortcut" fillcolor="#e2d5f1"]
}
subgraph cluster_eval {
label="Three Execution Tiers"
style=rounded
color="#666666"
interp [label="Tree-Walker\nleval()\nTCO via while loop\nall special forms" fillcolor="#d4edda"]
bytecode [label="Bytecode VM\ncompile → execute\nsuperinstructions\nSELF_TAIL_CALL" fillcolor="#cce5ff"]
jit [label="x86_64 JIT\nmmap(PROT_EXEC)\nnative machine code\nif/cond/let/named-let\ncar/cdr/cons\n10-24x faster than CPython" fillcolor="#ff6b6b" fontcolor=white]
}
subgraph cluster_jit_detail {
label="JIT Pipeline (jit.c)"
style=rounded
color="#cc0000"
analyze [label="AST Analysis\ncan_jit_proc()" fillcolor="#ffcccc"]
emit [label="x86_64 Emission\nmov/add/sub/cmp\ncall/ret/jmp" fillcolor="#ffcccc"]
mmap [label="mmap()\nPROT_READ|WRITE|EXEC\nfunction pointer" fillcolor="#ffcccc"]
}
source -> tokenizer
cli -> tokenizer
tokenizer -> parser
parser -> interp [label="default"]
parser -> bytecode [label="--fast"]
parser -> analyze [label="--jit"]
analyze -> emit [label="jittable"]
analyze -> interp [label="fallback" style=dashed]
emit -> mmap
mmap -> jit [label="JitFunc"]
interp -> envs
bytecode -> envs
jit -> nanbox [label="unbox/rebox"]
envs -> nanbox
nanbox -> intern
nanbox -> pairs
{rank=same; interp; bytecode; jit}
{rank=same; analyze; emit; mmap}
}