Common Lisp LLVM Frontend

I am currently working on a Common Lisp compiler frontend for LLVM. It is still in its beginning, but as soon as it can do anything useful, I will publish it on github.

Does any interest about this topic exist out there?

Some more details:

  • Technically, I am currently building the compiler to write LLVM-IR directly. However, in the long run it will probably be more maintainable to use some kind of abstraction layer. Candidates are either cl-llvm (haven’t looked into that one in detail yet) or using the llvm libs directly via FFI, since I am not sure whether cl-llvm is still an active project – the last commit has been a while ago…
  • My major motivation in the long run is to be able to compile Lisp code into JavaScript via LLVM / emscripten. I find the idea of only having to deal with ONE language very attractive. And yes… I know about clojure & clojurescript and also about parenscript, however, these are not the ones I currently want to use. I also like the idea of creating a general purpose solution, since with this Lisp LLVM frontend, you will be able to compile into anything that LLVM offers a backend for 😉
  • I have also taken a look at gcl & ecl, two common lisp compilers that compile CL to C, but I find these somewhat clumsy when trying to NOT compile into native object files

I have been playing with this idea for quite some time, and now I have decided to just give it a try. It also opens some nice options for me regarding some ideas about missing language features in Lisp like currying, continuations, algebraic datatypes etc. Of course most (if not all) of these can be implemented with Lisp & its macro system itself, but maybe it will be fun to implement these as native features.

Another reason is that I’d love to mess around with LLVM some. I like the powerful & flexible features & possibilities of LLVM.

I have also been taking a look at the new Perl VM called “parrot”. This one has especially been designed for dynamic languages (like Lisp), so writing a compiler for this one would probably be easier. However, it does not offer the features that I am striving at, like exchangable backends, especially one targetting JavaScript.

We’ll see how many obstacles the optimization for statically typed languages LLVM will cause while trying to implement a frontend for a dynamically typed language like Common Lisp.

Comments, ideas & questions are very welcome 🙂

Stay tuned…