48

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?

Community
  • 1
  • 1
anon
  • 41,035
  • 53
  • 197
  • 293
  • 19
    Is this question asking for real answers -- like, problems with LLVM and/or Scheme, either technical or social, that are keeping this implementation from being done? Or is it just complaining rhetorically, like, "Why hasn't anyone done the dishes?" or "Why is this bus so late?" – Evan P. Feb 04 '11 at 17:42

10 Answers10

27

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.

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
  • 1
    As far a I can tell, HLVM is dead. – dfeuer Jan 12 '15 at 05:35
  • 2
    I'm not sure, but are you saying that a garbage collector [in general] is why it's hard for LLVM, or just a [garbage collector for LISP] is too hard? Because I'm pretty sure there are languages in LLVM with Garbage collectors. The LLVM docs even **specifically mention Scheme.** http://llvm.org/docs/GarbageCollection.html – Katastic Voyage Feb 07 '17 at 02:58
  • 1
    @KatasticVoyage I mean that an efficient garbage collector is hard, because it's something that cannot simply be tacked on a code-generation framework such as LLVM. It's not impossible, and while it had not been done in 2010, it has been done several times over at this point. I'm not sure what to do with this answer now. – Pascal Cuoq Feb 07 '17 at 10:22
19

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.

dystopium
  • 3
  • 3
Wilfred Hughes
  • 29,846
  • 15
  • 139
  • 192
13

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.

Evan P.
  • 979
  • 1
  • 10
  • 17
9

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 =].

andrew
  • 2,819
  • 24
  • 33
8

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

Pillsy
  • 9,781
  • 1
  • 43
  • 70
5

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.

masukomi
  • 10,313
  • 10
  • 40
  • 49
4

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

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
3

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.

J D
  • 48,105
  • 13
  • 171
  • 274
  • 2
    Update: there is one now, namely Mono. – SK-logic Feb 04 '11 at 17:59
  • 3
    There's also Clang nowadays, and Haskell has an LLVM implementation. Still no Lisps AFAIK. (Not saying Jon was wrong. Just providing an update.) – Chuck Apr 15 '11 at 19:50
  • @SK-logic: AFAIK, last I looked (Nov 2010) Mono still didn't have a working garbage collector and I'm not sure what the state of Mono is since its developers were laid off. http://flyingfrogblog.blogspot.com/2010/11/mono-28-step-closer-to-reliable.html – J D Jun 18 '11 at 15:15
  • This statement was inaccurate even in 2010 -- unless of course you somehow consider C, C++ and Objective-C to be a single unified language. ARC also existed on LLVM in 2010. – ctpenrose Jan 21 '16 at 07:31
1

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".

MWB
  • 11,740
  • 6
  • 46
  • 91
0

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.

Golias
  • 25
  • 1