Zezaye is a Smol Lisp™ that compiles to x86-64 binary code. It is based on A. Ghuloum's "An Incremental Approach to Compiler Construction" and Max Bernstein's excellent tutorial built on top of it.
My implementation is slightly different from theirs:
- the compiler is written in Rust instead of Scheme/C;
- objects are represented with NaN boxing, because I want fast floats;
- I don't plan to implement Scheme, because what's the point of writing a compiler if you don't make up a pet language to go with it?
With Rust installed, simply clone this repo and execute cargo run
to start a (very basic) REPL. Exit with CTRL+D
.
$ cargo run
zezaye> (let ((x (sub1 3))) (+ (+ 1 2) x))
Int(5)
zezaye>
bye!
Many things aren't implemented yet and will crash the REPL. Can you find them all?
The project is split into several modules:
src/object.rs
describes the AST, as well as each atom's encoding as a boxed NaN.src/program_buffer.rs
containsProgramBuffer
, a byte buffer with methods for emitting x86 assembly into it. The buffer can be converted into anExecutableProgramBuffer
, which can be run as a function.src/compiler.rs
implements methods for compiling an AST using aProgramBuffer
as a backend.src/reader.rs
implements a reader that parses text into an AST.
- Vectors
- Handle non-ASCII character literals (make Char a Unicode scalar value)
- Refactor
panic
s into compiler errors - [ ]