Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

For CL: Clasp is a Common Lisp implementation on LLVM, and mocl implements a subset of Common Lisp on LLVM.

For Scheme: there's a self-hosting Scheme->LLVM demo and a prototype LLVM backend for Bigloo Scheme.

For Clojure: there's Rhine, which is a Clojure-inspired lisp.

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

Maybe I'm completely misunderstanding the question or context, but I believe that you could use ECL, which is a Common Lisp that compiles down to C, and use the Clang compiler to target LLVM (instead of GCC).

I'm not sure what (if any) benefit this would give you, but it would give you a Lisp running on LLVM =].

there's not (to my knowledge) a single popular scheme/lisp on LLVM

Currently, llvm-gcc is the nearest thing to a popular implementation of any language on LLVM. In particular, there are no mature LLVM-based language implementations with garbage collection yet. I am sure LLVM will be used as the foundation for lots of exciting next-generation language implementations but that will take a lot of time and effort and it is early days for LLVM in this context.

My own HLVM project is one of the only LLVM-based implementations with garbage collection and its GC is multicore-capable but loosely bound: I used a shadow stack for an "uncooperative environment" rather than hacking the C++ code in LLVM to integrate real stack walking.

CL-LLVM provides Common Lisp bindings for LLVM. It takes the FFI approach, rather than attempting to output LLVM assembly or bitcode directly.

This library is available via Quicklisp.

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top