Why isn't there a good scheme/lisp on llvm?

Viewed 25632

There is Gambit Scheme, MIT Scheme, PLT Scheme, Chicken Scheme, Bigloo, Larceny, ...; then there are all the lisps.

Yet, there's not (to my knowledge) a single popular scheme/lisp on LLVM, even though LLVM provides lots of nice things like:

  • easier to generate code than x86
  • easy to make C FFI calls ...

So why is it that there isn't a good scheme/lisp on LLVM?

10 Answers

LLVM provides a lot, but it's still only a small part of the runtime a functional language needs. And C FFI calls are uncomplicated because LLVM leaves memory management to be handled by someone else. Interacting the Garbage Collector is what makes FFI calls difficult in languages such as Scheme.

You might be interested in HLVM, but it's still more than experimental at this point.

There's a very small and apparently unoptimised Scheme compiler here:

http://www.ida.liu.se/~tobnu/scheme2llvm/

Taking your question literally,

  • Writing compilers is hard.
  • A poor implementation like the one linked above can block new implementations. People going to the LLVM page see that there's a Scheme already, and don't bother writing one.
  • There's a limited number of people who write and use Scheme (I'm one, not a hater, btw).
  • There are lots of existing Scheme intepreters and compilers and there's not a screaming need to have a new one.
  • There's not an immediate, clear benefit to writing a new interpreter using LLVM. Would it be faster, easier, more flexible, better in some way than the other dozens of Scheme implementations?
  • The LLVM project went with another language (C) to demo their technology, and haven't seen a need to implement a lot of others.

I think that it could be a lot of fun for someone to build an LLVM-based Scheme compiler. The Scheme compilers in SICP and PAIP are both good examples.

One thing to keep in mind is that many of these implementations have C FFIs and native-code compilers that significantly predate LLVM.

mocl is a compiler for a relatively static subset of Common Lisp. It compiles via LLVM/Clang.

There is a Scheme2LLVM, apparently based on SICP:

The code is quite similar to the code in the book SICP (Structure and Interpretation of Computer Programs), chapter five, with the difference that it implements the extra functionality that SICP assumes that the explicit control evaluator (virtual machine) already have. Much functionality of the compiler is implemented in a subset of scheme, llvm-defines, which are compiled to llvm functions.

I don't know if it's "good".

GHC is experimenting with a scheme backend and getting really exciting preliminary results over their native code compiler. Granted, that's haskell. But they've recently pushed new changes into LLVM making tail calls easier IIRC. This could be good for some scheme implementation.

Related