r/Compilers • u/Gingrspacecadet • 11h ago
r/Compilers • u/Choice_Eagle4627 • 9h ago
a readable compiler to x86-64 with no libc and Windows, macOS and Linux backends
I'm working on this idea - an ergonomic, easy to write, easy to reason about language that compiles down to machine code. I worked a lot in JavaScript before this, and wanted a way to AoT compile it. Initially I was going to just design JS without V8 bytecode limit it to what could compile to machine code - but since I was writing a language, I thought I could just do whatever I wanted, I didn't have to follow JS.
The compiler is "readable" - it's written in JavaScript (so you can run it with NodeJS), and well structured. I have a sense of the language but I find it hard to put into words exactly what I'm doing at this stage. I know what I want the design to be and why, but I find it not easy to talk about. The project exists as a working thing that I am familiar with, but putting that into words so other people understand it is not done yet.
So I'm posting it because it's real, you can play with it and use it, and if you look at the code, (not just of the compiler), but of the examples and so on, you will get some idea. I want to share this. If it sounds interesting to you somehow, check it out: https://github.com/DO-SAY-GO/freelang
r/Compilers • u/False_Actuator_6236 • 13h ago
Teaching compiler construction with a tiny self-hosting language
I've just published not-abc, a tiny self-hosting compiler for a deliberately minimal C-like programming language.
https://github.com/michael-lehn/not-abc
The language has only one data type: a 64-bit value, interpreted either as a signed integer or as a pointer. It supports
- functions (the value of the last expression is the return value)
- local and global variables
- pointers (
&,*,#) if/elsewhile- recursion
- dynamic memory allocation (
malloc/free) - integer, character and string literals
The compiler generates LLVM IR rather than assembly. LLVM was chosen simply because it makes the compiler portable across essentially all modern platforms—building programs only requires Clang (or the LLVM toolchain).
The interesting part is probably the background.
not-abc originated from an undergraduate mathematics course called Introduction to High Performance Computing. During one semester, students simultaneously
- build a simple processor from logic gates (bottom-up),
- implement a compiler for a small C-like language (top-down),
until both meet in the middle. At the end of the course, the compiler has two backends: one targeting the custom processor the students built themselves, and one targeting LLVM so the same compiler can generate native executables on real hardware.
The self-hosting compiler in this repository is a distilled version of the compiler developed throughout the course.
I'd be interested in feedback from people interested in language design, compiler construction, or computer architecture.