Drake Stapleton has released a new compiler chain, omega-mv, that bootstraps itself from a hand-written seed of 102 lines of hex code. The project, featured on Hacker News, aims to eliminate the historical accumulation of errors and inefficiencies found in traditional toolchains like GCC. By treating existing C compilers strictly as a 'referee' to verify outputs rather than as the builder, Stapleton ensures the entire chain is derived from first principles, culminating in a self-hosting compiler for the Omegese language.

The Ladder Approach

The bootstrap process is structured as a 'ladder' of six rungs, where each stage builds the next using only the capabilities of the previous stage. It begins with Rung 0, defined by a file of 102 lines of 8 hex digits (which compiles to a 408-byte binary). The very first binary is generated by a 24-line shell script using only the shell's own printf command, after which seed-0 builds itself. This evolves through Rung 1, which adds label support to handle jump distances, and Rung 2, an assembler that translates named instructions into machine code using a public reference manual. Each rung must rebuild itself byte-for-byte identically to prove consistency, with all instruction bits verified against the Arm Architecture Reference Manual (DDI 0487).

Efficiency Over Legacy Design

A key differentiator of the omega-mv chain is its code generation efficiency. The project explicitly contrasts its output with the 'OSC IR' path used by the existing C compiler, which is criticized for keeping every value in memory rather than using registers. In benchmark tests across ten practice tasks, the seed chain generated 164 machine words compared to the C path's 600. This 73% reduction in code size is attributed to the seed chain's use of registers for as long as possible, avoiding the documented 'no register allocation' design choice of the C path.

Self-Hosting and Verification

The chain culminates in Rung R5, where the Omega compiler (omc) is written in Omegese and built by the previous stage (om4). At commit e5b32567, the compiler source spans 12,040 lines. The build process involves three stages of self-translation to ensure stability, with the final binary verified against published SHA-256 hashes. The project supports multiple backends, including WebAssembly MVP and SPIR-V 1.0, all compiled by this seeded omc. Strict type casting rules are enforced, with errors triggered for invalid conversions, ensuring the compiler remains robust against undefined behavior.

Key Takeaways

  • The bootstrap seed consists of 102 lines of hex text (408 bytes binary), initially built by a shell script before self-hosting begins.
  • The C compiler and GNU tools are used exclusively as verification oracles, not as build tools, to avoid inheriting legacy bugs.
  • The seed chain produces 73% fewer machine words than the C path on average due to superior register allocation.
  • Instruction encodings are verified against the Arm Architecture Reference Manual; automated checks show zero disagreements, though 3 SVC instructions are validated via objdump and manual comments due to decoder limitations.

The Bottom Line

This project is a masterclass in minimalism and verification, proving that you don't need a massive legacy toolchain to build a robust, efficient compiler from scratch, provided you use external tools strictly as referees.