An open API service indexing awesome lists of open source software.

https://github.com/ashton314/christmas-compiler

An experimental lambda calculus compiling to the LLVM
https://github.com/ashton314/christmas-compiler

compiler lambda-calculus linear-types lisp llvm racket type-checking type-inference

Last synced: 6 days ago
JSON representation

An experimental lambda calculus compiling to the LLVM

Awesome Lists containing this project

README

          

#+TITLE: The Christmas Compiler

#+begin_quote
Oh syntax tree, oh syntax tree,
How lovely are thy derivations!
#+end_quote

Christmas break is coming up soon, and I all I want for Christmas is a compiler that:

- Implements a small typed lambda calculus
- Includes Hindley-Milner type inference
- Replaces a garbage collector runtime with linear typing
- Supports continuations
- Is built with a nanopass framework so I can swap layers out to my liking

I know Santa's busy this year, so I don't know if he'll get around to all those things, but we're going to try. This will be a victory if I learn something.

It will also be a good outlet for some Christmas-related puns.

I am so sorry.

#+begin_quote
Write yourself, some merry little IR,
If the types will check
From now on, this variable is out of scope
And build yourself, a merry little compiler now
#+end_quote

* Synopsis

Requires [[https://racket-lang.org/][The Racket Programming Language]], which is available for free for all major (and plenty of obscure!) platforms.

Also requires the LLVM. (At time of writing, this doesn't do any code generation, so you don't need this /right now/, but it will soon be a requirement.)

** TODO Add link to documentation on how to get the LLVM toolkit

** Tests

Run Racket tests:

#+begin_example
make test-racket
#+end_example

* Description

The compiler works in a series of small passes over the code/abstract syntax tree (AST), each of which performs small modifications to the AST or provides some insight into what the AST is doing. The first pass parses the raw source langauge into an AST. The defintions of the AST nodes can be found in [[file:passes/ast.rkt][passes/ast.rkt]]. Once all the passes have finished, the final pass converts the AST into LLVM IR. The LLVM then turns this into machine code.

Inspiration for the "nanopass" architecture came from /Educational Pearl: A Nanopass Framework for Compiler Education/ [fn:1], with some inspiration from a more minimal guide /An Incremental Approach to Compiler Construction/ [fn:2].

** Rationale

I decided to use the LLVM because it handles the hard work of machine-specific assembly/machine code generation, and I wanted a compiler that would work both on my desktop (which uses an Intel processor) and my Raspberry Pi (which is an ARM architecture).

* Language

** Description

The compiler implements a simple lambda calculus. At time of writing, this language is untyped, but static typing with type inference will come at a later step.

*** TODO Fill out this section

** TODO Examples

* Author

Ashton Wiersdorf

* Footnotes

[fn:1] D. Sarkar, O. Waddell, and R. K. Dybvig, “Educational Pearl: A Nanopass Framework for Compiler Education,” J. Funct. Prog., vol. 15, no. 05, p. 653, Jun. 2005, doi: 10.1017/S0956796805005605. http://www.pup.si/files/pdf_file/nano-jfp.pdf

[fn:2] A. Ghuloum, “An Incremental Approach to Compiler Construction,” p. 11, 2006. http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.88.170&rep=rep1&type=pdf