The compiler is a 6-stage Python pipeline (lexer → parser → analyzer → IR gen → optimizer → C emitter) driven by a formal EBNF grammar and an algebraic AST spec (Zephyr ASDL). The generated C is readable and linkable with any C11 compiler. It ships with a VS Code extension (LSP with completions, diagnostics, go-to-def, hover) and 930 tests.
I've wanted to build something like this for about 10 years, but it was always too ambitious of a project to do on the side. With AI, I was able to build it over a handful of evenings after work, which is really wild.
Some things worth noting:
A few things that I find fun / interesting / noteworthy:
- The EBNF grammar and ASDL spec are the single source of truth — the lexer, parser, and AST node classes are all derived from them, not hardcoded
- Generics are monomorphized (like C++ templates / Rust), so zero runtime overhead but binary size grows per type combination
- ARC handles most memory management including cycle detection and cleanup on exceptions — no GC, deterministic destruction
- The entire stdlib (collections, math, datetime, IO, threading) is written in btrc itself
- @gpu functions transpile to WGSL compute shaders with auto-generated WebGPU boilerplate — array params become storage buffers, scalars become uniforms
- The generated C is meant to be readable — you can step through it in gdb/lldb and it mostly makes sense (just verbose with lots of underscores)
- There's a 3D game engine example (ball + WASD + jump + shadows + raymarching) that's ~570 lines of btrc across 11 small modules
- The VS Code extension reuses the compiler's own lexer, parser, and analyzer — diagnostics match exactly what the compiler reports
- btrc inherits C's memory model wholesale — no borrow checker, no lifetime analysis. You can absolutely still shoot yourself in the foot
- The whole thing was built in a few evenings after work with heavy AI assistance, which felt like the most interesting part of the project honestly
rohandas•1h ago