🌈💀👑 Rainbow Array Machine
An array machine whose source language is UTF-8 emoji and whose
execution target is WebAssembly. Every program compiles to
its own standalone WASM module — parser, typed FLAT stages,
and code generator are C11; Clang's wasm32 target produces the
module; the operations and the assertions execute inside it. 🕸️
🌀 BQN · 🔺 APL · ⚡ K · 🐺 Wolfram · 📐 geometry · 🎨 Piet
(the pipeline executes a bounded, explicitly defined subset per
namespace; the full semantic definitions — a BQN transformer,
the KCL binary ground, a Wolfram literature package, the Piet
painting layer — live in semantics/, and the host toolchain
is lowered to assembly by the verified CompCert compiler)
▶️ A program, executing
One program, five instructions — vectors, matmul, geometry, an
inverse, and the affine — compiled into a single module:
🌀 📏 ➕ 3 1 2 3 4 5 6 >>>>>>>€ 5 7 9
🌀 🟦 🧲 2 3 2 1 2 3 4 5 6 7 8 9 10 11 12 >>>>>>>€ 58 64 139 154
🌀 📐 @@ ROTATE_Z 2 1 1 0 0 0 1 0 >>>>>>>€ 0 1 0 -1 0 0
↶ 🌀 📐 @@ ROTATE_Z 1 1 0 1 0 >>>>>>>€ 1 0 0
🐺 🔹 📜 2 3 7 4 >>>>>>>€ 27
make -C core modules # ramc → flat_check → flat_lower
# → ram_codegen → clang wasm32
$ run showcase.wasm
PASS standalone WASM: 17 outputs
[5,7,9, 58,64,139,154, 0,1,0,-1,0,0, 1,0,0, 27]
run() returns 0 only when every operation and every
assertion inside the module passes. A false assertion returns
a nonzero code from the WASM itself — the host computes nothing. 🛡️
The symbolic core generalizes the affine. ✨ takes a
polynomial as (coefficient, power) pairs, normalizes it at
compile time — like terms collected, zero terms dropped,
canonical ascending form — and evaluates it in-module:
🐺 🔹 ✨ 2 2 1 3 1 5 0 0 3 -1 2 >>>>>>>€ 11
The terms (2,1)+(3,1)+(5,0)+(0,3)+(−1,2) canonicalize to
−x² + 5x + 5; at x = 2 the module computes 11, and the
compiler writes a 🛡️ certificate of the normalization next to
the IR:
CERT v1: line 2; rules=collect_like_terms,drop_zero_terms,canonical_ascending; terms=(2,1)+(3,1)+(5,0)+(0,3)+(-1,2); canonical deg=2 coeffs=5 5 -1; status=NORMALIZED
🏗️ Pipeline
🌈 emoji source (.ram)
→ ramc C11 strict parser → RAMIR1
→ flat_check C11 shape/op validation → FLAT1 metadata
→ flat_lower C11 metadata + payload → FLAT2
→ ram_codegen C11 standalone lowering → C source
→ clang wasm32 → 📦 program.wasm
→ run() operations + assertions execute in-module
💀👑 .skull reversible serialization of the .wasm bytes
🖼️ Gallery
The seal, rendered. All 208 rows of crypto/seal_recursion
— 2070 descending by 10s to 0, each row a 12-bit 💀👑 word
(👑 gold, 💀 dark), drawn from the program's own output:

Geometry, plotted. The two transforms of
core/examples/geometry.ram, drawn from their declared values —
a quarter turn, and a translation by (3, 4, 5):

A Piet painting. The 🎨 layer's discipline: a painting of
blocks in the 18 Piet colors, one Genmoji per block. The glyph
is the surface; the color geometry is the code (the full
semantics are in semantics/piet.md):

📊 Benchmarks
Measured by execution (2026-11-05, AMD EPYC 9D25 VM, Clang 23,
Node 24; medians of 5 runs). Reproduce with make test and the
timing method in STATUS.
Compile pipeline — the showcase program, source → module:
| Stage |
Median |
| ramc (parse → RAMIR1) |
1.08 ms |
| flat_check (→ FLAT1) |
1.43 ms |
| flat_lower (→ FLAT2) |
1.43 ms |
| ram_codegen (FLAT2 → C) |
2.87 ms |
| clang (C → wasm32) |
234.26 ms |
| Total |
≈ 241 ms |
Modules and execution (sizes and medians re-measured
2026-11-05 with the polynomial kernel included; run() medians
over 2,000 calls):
| Module |
Instructions |
Size |
Instantiate |
run() median |
| array.wasm |
5 (vectors, matmul, transpose) |
3,354 B |
0.83 ms |
0.441 µs |
| geometry.wasm |
5 (rotate, translate, inverses) |
3,245 B |
0.48 ms |
0.321 µs |
| symbolic.wasm |
1 (affine 📜) |
2,559 B |
0.41 ms |
0.150 µs |
| showcase.wasm |
5 (the program above) |
3,236 B |
0.38 ms |
0.360 µs |
| polynomial.wasm |
1 (✨ −x² + 5x + 5) |
2,566 B |
0.42 ms |
0.161 µs |
Serialization: the 3,354-byte array.wasm encodes to a
110,682-byte .skull file — the symbol stream itself is
exactly 32× (8 symbols per byte × 4 UTF-8 bytes per symbol);
the repo codec's newline-per-byte framing makes the file 33×.
Byte-for-byte reversible in both directions. 💀👑
CompCert assembly (the verified compiler's output for the
host toolchain; see the CompCert section):
| Program |
Assembly |
| seal_recursion |
305 lines · 6,761 B |
| core ramc |
1,628 lines · 33,352 B |
| core flat_check |
779 lines · 15,266 B |
| core flat_lower |
235 lines · 4,853 B |
| core ram_codegen |
1,268 lines · 27,663 B |
| v0.1 ram |
1,989 lines · 42,217 B |
| v0.1 ramc (typed) |
11,136 lines · 250,530 B |
| v0.1 flat |
1,181 lines · 21,966 B |
| v0.1 skull |
513 lines · 9,106 B |
| v0.1 array runtime |
1,742 lines · 35,842 B |
🔒 Invariants
These hold by construction and are exercised by the test suites:
- Per-program modules. Each program compiles to its own
standalone
.wasm. There is no instruction interpreter and
no shared dispatcher in the execution path.
- Assertions execute in WASM.
>>>>>>>€ expectations are
compiled into the module and checked by the kernel's
assert_equal (tolerance 1e-10) inside run(); failure
returns a nonzero code identifying the instruction.
- The host computes nothing. A harness instantiates the
module, calls
run(), and reads exported linear memory.
- Division by zero is refused — the elementwise kernel
returns an error code, never an infinity.
- Kernel bounds are enforced in-module: elementwise
n ≤ 4096, matmul dimensions ≤ 64, geometry points ≤ 1024.
Violations return an error code; nothing is clamped silently.
- FLAT2 integrity. Every executable payload line travels
paired with its validated FLAT1 metadata line. A missing
payload or a count mismatch is refused before code generation.
- The frontend fails closed. Unknown namespaces or
opcodes, missing operands, non-finite numbers, and trailing
input are rejected with a nonzero exit — no partial program
is ever lowered.
- ↶ is exact for geometry. Inverses are the parse-time
negation of quarter turns and translation deltas; a transform
followed by its inverse returns the declared points exactly.
- 💀👑 is serialization, never execution. A
.skull is
decoded to bytes before any runtime loads the module.
- No scripting languages in the build path. Parser, FLAT
stages, and code generator are C11; the compiler target is
Clang wasm32.
📜 Theorems
proofs/Arithmetic.lean — mathematical specifications of the
kernels, kernel-checked with lake build (Lean v4.9.0,
Mathlib v4.9.0; build exit 0, no sorry):
def affineSpec (a b c x : ℤ) : ℤ := (a + b) * x + c
theorem affine_expand (a b c x : ℤ) :
affineSpec a b c x = a * x + b * x + c
theorem inverse_translation (x delta : ℤ) :
(x + delta) - delta = x
theorem transpose_index_roundtrip (m n i j : ℕ)
(hi : i < m) (hj : j < n) :
(j * m + i) / m = j ∧ (j * m + i) % m = i
Scope, stated plainly: these theorems specify the mathematics
the kernels implement — the affine law, translation inversion,
and the row-major transpose index decode (both axes recovered).
They do not claim instruction-level equivalence between the
specification and the emitted WASM; that requires a formal WASM
semantics and a simulation proof, and it is not claimed here. 🧾
proofs/Polynomial.lean — the obligations of the ✨ symbolic
core, lake-checked in the same project (build exit 0):
theorem collect_like_terms (a b x : ℤ) (p : ℕ) :
a * x ^ p + b * x ^ p = (a + b) * x ^ p
theorem drop_zero_term (x : ℤ) (p : ℕ) :
0 * x ^ p = 0
theorem horner_step (a b c x : ℤ) :
a * x * x + b * x + c = (a * x + b) * x + c
collect_like_terms and drop_zero_term are the two rules the
compiler's normalization applies; horner_step is the
evaluation order the kernel's poly_eval implements. Same
scope as above: mathematics over ℤ, not WASM equivalence.
🧩 Components
| Piece |
Role |
core/src/ramc.c |
🌐 Strict UTF-8 emoji parser → RAMIR1 (↶ geometry inverses at parse) |
core/src/flat_check.c |
🏷️ RAMIR1 validation → FLAT1 typed metadata (rank, shape, elements, assert flag) |
core/src/flat_lower.c |
📐 FLAT1 + payload → FLAT2, count-checked pairing |
core/src/ram_codegen.c |
⚙️ FLAT2 → standalone C module source |
core/src/kernel.c |
🕸️ The WASM kernel — elementwise (➕➖✖️➗), matmul, transpose, reduce_sum, affine, rotate, translate, assert_equal — compiled by Clang to wasm32 |
src/skull.c |
💀👑 Skull/Crown encode/decode/invert — the repo codec; it frames the same MSB-first symbol stream with a newline per byte |
core/proofs/Arithmetic.lean |
📜 The theorems above |
The core pipeline, program by program
core/src/ramc.c — the compiler front end. Reads a .ram
source file line by line. Each line is a namespace tag, a type
tag, an operator, and operands; anything unrecognized —
namespace, opcode, operand count, a non-finite number, trailing
input — is a hard error with the line number, and no partial IR
is emitted. Geometry inverses (↶) are computed here, at parse
time, by negating quarter turns and translation deltas. For
🐺 ✨ statements it also performs the polynomial normalization
and writes the 🛡️ certificate sidecar (<program>.ir.cert).
Output: RAMIR1, a normalized typed instruction list.
core/src/flat_check.c — the validator. Reads RAMIR1 and
checks every instruction: opcode known, dimensions in range,
operand count exactly matching the shape the opcode declares,
every operand finite, and — when an assertion is present — the
expected-value count exactly matching the instruction's output
shape. Output: FLAT1, one metadata line per instruction (OP n NAME F64 RANK r dims… ELEMENTS e ASSERT a) describing what the
payload line must be.
core/src/flat_lower.c — the pairing stage. Interleaves
each FLAT1 metadata line with its RAMIR1 payload line into
FLAT2, verifying the pairing as it goes. A FLAT2 file is
therefore self-describing: every executable line travels with
the validated description of its own shape.
core/src/ram_codegen.c — the lowering. Reads FLAT2 (or
bare RAMIR1) and emits a complete, standalone C program: the
operands as static constant arrays, one kernel call per
instruction writing into a shared output[] buffer, one
assert_equal per declared assertion, and the three exports
(run, result_ptr, result_len). There is no interpreter in
the output — the generated code is the program.
core/src/kernel.c — the WASM kernel. The operation set
every module links: elementwise (➕➖✖️➗ over f64 vectors,
division by zero refused), matmul, transpose,
reduce_sum, affine ((a+b)·x + c), poly_eval (Horner over
canonical coefficients), rotate_z_quarter,
translate, and assert_equal (tolerance 1e-10). Bounds are
checked in-kernel and reported as error codes.
The v0.1 line (src/)
The first-generation toolchain, kept complete and working:
src/ram.c — the interpreter. Executes .ram source
directly. Fourteen namespaces are registered; 🌀 BQN, 🔺 APL
and ⚡ K share one elementwise + matmul engine, and 🐺 carries
the original affine subset with its ✨ simplify, 📜 FLAT v1
lowering and 🛡️ certificate printers. Unimplemented namespaces
fail closed with a named error rather than a guess.
src/ramc.c — the typed IR compiler. Lowers source to a
typed SSA-style IR (%2 = bqn.add %0, %1 : vector[3] @L2) with
NAME ← bindings and @NAME references, the reversible
algebra (>>>>>>>€ assertions, ↶ inverses, ⟲ round trips,
🛡️ certificates, ⚖️ verdicts), and the geometry compiler.
Unbound references, duplicate bindings and shape mismatches
are refused at IR-build time.
src/flat.c — the FLAT v1 executor. Parses the textual
FLAT v1 the interpreter's 📜 emits (t0=mul_i64(x,5); …