Architecture Overview
BRIK-64 is a Digital Circuitality architecture — software that works like hardware. Every program is a Printed Circuit Description (PCD), compiled through a formally verified pipeline into a standalone native binary. The compiler is self-hosting: it compiles itself, and the output hash is immutable and reproducible.The Full Pipeline
Compiler Layers
Layer 1: hand_parser — Lexer + Recursive Descent Parser
Layer 1: hand_parser — Lexer + Recursive Descent Parser
The parser is entirely hand-written — no
nom, no pest, no lalrpop. This is a deliberate
architectural decision: parser generators introduce a dependency that is outside the formally
verified perimeter.Key properties:MAX_DEPTH = 256— hard limit on recursion depth, preventing stack exhaustion- No binary literals (
0b...) — all integers are decimal or hexadecimal - No implicit type coercions in the grammar — all conversions are explicit monomer calls
- Single-pass: the parser does not backtrack
- Whitespace-insensitive (tokens are delimited by the grammar, not layout)
Expr: literals, binops, unops, calls, monomer calls, array/struct literalsStmt: let-bindings, assignments, if/else, while, loop(N), return, break, continueFnDef: function definitions with typed parameters and return typeProgram: list of top-level definitions (functions + imports)
Layer 2: planner — SSA Form + Type Inference
Layer 2: planner — SSA Form + Type Inference
The planner transforms the AST into CPF (Canonical Plan Format), a JSON-based intermediate
representation in Static Single Assignment form.SSA rules:
- Every variable assignment creates a new versioned slot:
x_0,x_1,x_2, … loop(N)loop-carried variables: all rebindings use version 0 (same slot). This is the critical invariant that makes the BIR bootstrap work — the planner andbrikc.pcdmust agree.whileloops: SSA captures the version before the body (known limitation, useloop(N)withifguard as workaround in self-hosting code)bind_letalways assigns version 0 for loop-carried vars
- All monomers have fixed input/output types (specified in Coq proofs)
- The planner infers the type of every SSA variable by propagation
- Type errors are hard errors — no implicit coercions
- The planner classifies every composition: sequential
⊗, parallel∥, conditional⊕ - This classification is embedded in the CPF and later verified by the TCE
Layer 3: CPF — Canonical Plan Format
Layer 3: CPF — Canonical Plan Format
CPF is the universal intermediate representation shared by all backends. It is a JSON document
with a stable schema (versioned). Any backend consumes CPF; the pipeline from source to CPF is
backend-agnostic.CPF is designed to be:
- Deterministic: same source always produces the same CPF (no random IDs, no timestamps)
- Diffable: human-readable JSON, suitable for version control
- Complete: contains all type information, EVA algebra annotations, and TCE pre-images
Layer 4: Backends
Layer 4: Backends
Native x86-64 ELF (primary):
Produces a fully standalone ELF binary. No libc, no dynamic linker, no runtime. The binary contains only: startup stub + monomer implementations + EVA router + program logic.BIR Bytecode:
BRIK IR — a stack-less, register-based bytecode interpreted by the BIR interpreter (Rust). Used during bootstrap: Gen0 compiles brikc.pcd to BIR, BIR executes to produce Gen1.Rust / JS / Python:
Transpilation backends that emit idiomatic code in each target language. Each monomer maps to a verified library function in the target language. Used for interoperability.WebAssembly:
All 22 CPF
Produces a fully standalone ELF binary. No libc, no dynamic linker, no runtime. The binary contains only: startup stub + monomer implementations + EVA router + program logic.BIR Bytecode:
BRIK IR — a stack-less, register-based bytecode interpreted by the BIR interpreter (Rust). Used during bootstrap: Gen0 compiles brikc.pcd to BIR, BIR executes to produce Gen1.Rust / JS / Python:
Transpilation backends that emit idiomatic code in each target language. Each monomer maps to a verified library function in the target language. Used for interoperability.WebAssembly:
All 22 CPF
PlanNode variants are covered. Produces .wasm modules that run in any WASM runtime.
Sandboxed — no filesystem access by default.The 14 Rust Crates
brik_parser
software/system/brik_parser/The hand-written recursive descent parser. Produces AST from
.pcd source text.
MAX_DEPTH=256 enforced here.brik_planner
software/system/brik_planner/SSA transformation, type inference, EVA algebra classification. Produces CPF.
brik_tce
software/system/brik_tce/Thermodynamic Coherence Engine. Computes all 7 metrics and Φ_c. Blocks compilation if Φ_c ≠ 1.
brik_codegen
software/system/brik_codegen/Native x86-64 code generator. Emits raw machine code bytes from CPF.
brik_linker
software/system/brik_linker/ELF linker. Assembles
.text, .rodata, .bss sections into a valid ELF64 executable.
rodata-aware: string constants are placed in .rodata, referenced by RIP-relative addressing.brik_bir
software/system/brik_bir/BIR compiler: CPF → BIR bytecode. BIR interpreter: executes BIR at ~28M instructions/second.
brik_native
software/system/brik_native/Native runtime: startup stub, monomer implementations, EVA router, system call wrappers.
brik_eva
software/system/brik_eva/EVA Algebra runtime: ⊗ ∥ ⊕ combinators, compatibility checker, composition verifier.
brik_monomers
software/system/brik_monomers/All 64 Core monomer implementations (MC_00–MC_63) + Coq proof bindings.
brik_stdlib
software/system/brik_stdlib/Standard library in PCD:
math.pcd, string.pcd, array.pcd, io.pcd, fmt.pcd, json.pcd.brik_wasm
software/system/brik_wasm/WebAssembly backend. All 22 PlanNode variants implemented.
brik_transpile
software/system/brik_transpile/Rust/JS/Python transpilation backends. Monomer-to-stdlib mappings for each target.
brik_cli
software/system/brik_cli/CLI frontend:
brikc build, brikc check, brikc fmt, brikc repl, brikc lsp, brikc wasm32.brik_self
software/system/brik_self/Self-compilation driver: bootstrap chain, Ralph loop, fixpoint verifier.
Native x86-64 ELF: Startup Stub
Every BRIK-64 native binary begins with a 197-byte startup stub that establishes the runtime environment before the first monomer executes. The stub uses dedicated registers as global pointers:| Register | Purpose | Size |
|---|---|---|
R15 | vstack base pointer | 4 MB |
R13 | ASCII scratch buffer | 512 bytes |
R12 | heap base pointer | 16 MB |
RSP | call stack (64 MB mmap) | 64 MB |
The startup stub is not linked from a
.o file — it is emitted as raw bytes by brik_linker
directly into the ELF .text section header. This eliminates any dependency on system assemblers
or linkers (ld, as). The entire toolchain is self-contained.Self-Compilation Fixpoint
The most important property of BRIK-64: the compiler compiles itself and produces an identical hash across all generations. This is the 4-stage fixpoint, verified on 2026-03-10.Stage 0 — Bootstrap Generation
The Rust-implemented bootstrap (
brik_self) compiles brikc.pcd using the BIR interpreter.
This produces Gen1 BIR: 285,978 bytes, 109 functions, 20,709 BIR instructions.
Duration: ~348 seconds on ECO server.Stage 1 — Gen1 Compiles brikc.pcd
Gen1 BIR executes under the BIR interpreter to compile
brikc.pcd again.
Produces Gen2 BIR. Duration: ~178 seconds additional.Stage 2 — Gen2 Compiles brikc.pcd
Gen2 BIR compiles
brikc.pcd → Gen3 BIR. Duration: ~155 seconds additional.
Total elapsed: ~681 seconds.The fixpoint is not a property of the hash algorithm. It is a mathematical consequence of
EVA Algebra’s closure theorem: if every monomer is verified (Φ_c = 1) and every composition
preserves Φ_c = 1, then the compiler’s output is determined solely by its input — there is no
hidden state, no non-determinism, no timestamp. The hash is therefore stable across machines,
operating systems, and time.
Trust Layer Diagram
Test Suite Statistics
| Suite | Tests | Status |
|---|---|---|
| Workspace total | 1,900+ | All green |
| Integration (fixpoint) | 34 suites | 0 FAILED |
| Stage1 bootstrap | 11 | PASS (13s) |
| Coq proofs (admitted) | 0 | All replaced with DEFERRED comments |