Clyne 5c14bb190f | 2 years ago | |
---|---|---|
.gitignore | 2 years ago | |
LICENSE | 2 years ago | |
Makefile | 2 years ago | |
README.md | 2 years ago | |
ast.cpp | 2 years ago | |
ast.hpp | 2 years ago | |
main.cpp | 2 years ago | |
parser.cpp | 2 years ago | |
parser.hpp | 2 years ago | |
state.hpp | 2 years ago |
README.md
lisp-compiler
This is an experimental implementation of a LISP dialect, using LLVM to produce executable binaries. The objective of this project is to allow for the use of LISP in compiled contexts, accompanying other compiled code from languages like C and C++.
In particular, this would allow for the use of LISP in embedded or other low-resource applications that require native execution speed.
The compiler is being designed according to the R7RS-small standard for the Scheme dialect of LISP. Complete compliance is the goal, though the priority of producing compiled binaries with low overhead may require some deviations from the standard.
Compilation
This project requires the LLVM development libraries and a compiler that supports C++20. Simply run make
to produce the compiler binary main
.
Usage
main
takes the LISP code in its arguments and attempts to compile it. If successful, an out.o
object file will be produced; this can be executed if linked using a compiler like gcc
: gcc out.o -o out
.
Statements are processed in order, and command statements are placed inside a main
function. For example:
./main "(define myvariable 13) (define getmyvariable (lambda () myvariable)) (getmyvariable)"
The above code defines a global variable, a function that returns that variable's value, and then puts a call to that function in main
. Soon, that return value will be returned through main
as one would expect.
Support for reading source code from files or stdin will be added in the future.