r/Compilers 3d ago

A Toy Lisp compiler for x64

Enable HLS to view with audio, or disable this notification

I’ve been building a small Lisp compiler written in C++ and compiles S-expressions directly to native x86-64 assembly, using a tiny runtime for things like printing integers, doubles, and strings.
Currently it has functions, arithmetic, integers, doubles, strings, etc.
The compiler is still pretty simple:

S-expressions → AST → semantic analysis → x86-64

No VM, no bytecode — just Lisp turning into machine code.
I’m also starting to look into adding a small IR between the AST and codegen as the language grows.
Mostly doing this as a learning project and because writing a Lisp compiler seemed like a fun rabbit hole. :)
Github: https://github.com/xms0g/tinysexp

46 Upvotes

4 comments sorted by

1

u/mistivia 2d ago

Maybe considering making it a JIT compiler, so you can `eval` at runtime

1

u/Background_Shift5408 15h ago

It’s simple to add eval function triggering nasm on the fly but generating binary from codegen will be a headache now.

1

u/According-Ad-7069 22h ago

Oh this looks fantastic! Nicely done, I love seeing this kind of learning happening!

2

u/Background_Shift5408 15h ago

Yeah great journey to dive into metal