I built Forge to explore the absolute fundamentals of software construction and bootstrapping. By writing Stage 0 entirely in x86-64 assembly, I wanted to understand how compiler infrastructures can be established without relying on pre-existing compilers.
Designing the bootstrapping sequence and writing code generators targeting the direct hardware instruction set provided a solid foundation in low-level systems architecture and execution mechanics.
Forge is a multi-tier bootstrapping compiler. It translates Imperium, a structured, type-safe systems language, directly to Linux x86-64 assembly instructions:
The language compiled by Forge evolves across the stages, ultimately supporting a structured, type-safe programming model:
The main obstacle was the bootstrap validation loop. A single code-generator bug compiles forward, corrupting subsequent compiler binary generations hours later, which makes tracking down errors extremely difficult. I resolved this by designing strict generation-to-generation output comparisons and compiling modular self-host segments.
Another blocker was ensuring full compliance with the System V AMD64 ABI calling conventions. Passing arguments in specific registers, preserving required states, and maintaining 16-byte stack alignment boundaries for external library calls required mapping functions exactly to hardware assembly templates.
The compiler translates Imperium code through structured compiler stages:
Lexical Analysis & Parsing process source characters into tokens, assembling them into an Abstract Syntax Tree (AST). Type Checking & Mutability verification validate syntax structures, constant rules, and type layouts. Code Generation emits low-level NASM assembly instructions mapping structures and functions to hardware registers.
Regression tests and validation checks verify that code compilation is correct. Timings are checked against a performance warm baseline via benchmarking suites writing out to JSON logs.
Currently, register assignment is simple and stack-heavy. I plan to implement a graph-coloring register allocation algorithm to optimize register reuse and reduce CPU memory transactions.
I would also like to enhance parsing diagnosis. Providing detailed compiler error highlights with source file coordinates, line displays, and correction hints would improve the development workflow.
Detailed post-mortem analysis and the bootstrap script pipeline files are documented in the repository README .