r/Compilers • u/isuckatcs_was_taken • Sep 15 '26
How to Compile Your Language - An introduction to language design through building a compiler frontend on top of LLVM
Recently I extended an educational compiler project I started two years ago.
The goal is to bring together several major features found in production languages into Your Language, a small programming language, and explain how to implement them in its compiler.
Your Language currently supports:
- Native code generation with LLVM
- Hindley–Milner type inference
- Traits and type extensions
- Tracing garbage collection
- Heap-allocated closures
- Monomorphized generics
- Dynamic dispatch
- Data-flow analysis
- Compile-time expression evaluation
The implementation is now finished, but the accompanying guide is still a work in progress.
If you're interested, you can find the project here:
77
Upvotes
6
u/wzx89 Sep 15 '26
Will the accompanying guide cover how Hindley–Milner type inference interacts with monomorphized generics?
3
u/kidsiddidlit Sep 15 '26
Cool. Will follow it after completing crafting interpreters. Btw till when are u planning to finish the guide?
1
u/c-cul Sep 16 '26
what to do if I want allow inline asm?
1
u/CarefulHamster7184 Sep 16 '26
This looks unusually substantial for an educational compiler. The README already demonstrates several features composing, so one thing I’d love to see in the guide is an end-to-end trace of a single program across chapter boundaries—not just each feature in isolation.
For example, take a generic higher-order function whose heap-allocated closure captures a GC-managed struct and whose result crosses a trait-object boundary, then follow it through inference, closure conversion, monomorphization, GC root placement, vtable construction, and LLVM lowering. The individual mechanisms are teachable; their interfaces are where real compiler implementations become difficult, and where most educational material stops.
Is a capstone like that part of the plan?
1
u/Opposite_Yam_562 Sep 16 '26
I have also started working on frontend part.
1
u/nirlahori Sep 16 '26
Great content! Looking forward to learning from it.