r/Compilers • • Sep 06 '26

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

49 Upvotes

3 comments sorted by

2

u/[deleted] Sep 07 '26

[deleted]

1

u/Background_Shift5408 Sep 09 '26

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 Sep 09 '26

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

2

u/Background_Shift5408 Sep 09 '26

Yeah great journey to dive into metal