Skip to content
A compiler for a lisp-like language targeting LLVM IR, x86 assembly
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
scripts
src
tests
.eslintrc.js
.eslintrc.json
.gitignore
README.md
package.json
yarn.lock

README.md

ulisp

A compiler for a lisp-like language written in JavaScript targeting LLVM, x86 assembly.

Tutorials

  1. Lisp to assembly
  2. User-defined functions and variables
  3. LLVM

Example

The following program:

$ cat tests/function_definition.lisp
(def plus-two (a b)
     (+ a (+ b 2)))
	 
(def main ()
     (plus-two 3 (plus-two 1 1)))

Returns 9 as its exit code when compiled:

$ node src/ulisp.js tests/function_definition.lisp
$ ./build/prog
$ echo $?
9

By generating this LLVM IR:

define i32 @plus_two(i32 %a, i32 %b) {
  %sym7 = add i32 %a, 0
  %sym9 = add i32 %b, 0
  %sym10 = add i32 2, 0
  %sym8 = add i32 %sym9, %sym10
  %sym6 = add i32 %sym7, %sym8
  ret i32 %sym6
}

define i32 @main() {
  %sym6 = add i32 3, 0
  %sym8 = add i32 1, 0
  %sym9 = add i32 1, 0
  %sym7 = call i32 @plus_two(i32 %sym8, i32 %sym9)
  %sym5 = call i32 @plus_two(i32 %sym6, i32 %sym7)
  ret i32 %sym5
}
You can’t perform that action at this time.