[LLVMdev] Scheme compiler.

Chris Lattner sabre at nondot.org
Sat Jul 17 11:55:44 PDT 2004

On Sat, 17 Jul 2004, Tobias Nurmiranta wrote:

> Hi, now I've had some free coding time.
> On Mon, 14 Jun 2004, Chris Lattner wrote:
> > Writing a scheme front-end for LLVM sounds like a great project: please
> > keep us informed how it goes, and when it gets mostly functional, let us
> > know so we can add a link on the web site.  :)
> >
> > -Chris
> Just to keep you informed. My small scheme compiler[1] of 1K lines is now
> self applicable, with the types fixnum, symbols, strings, functions and
> vectors (cons cells are seen as vectors of size 2).

That is wonderful!  Wow, you did this just ~1 month?  :)

> You can for example do:
>  cat compile.ss|mzscheme --script compile.ss|llvm-as -o=ccomp.bc
>  echo '(display "hello")'|lli ccomp.bc|llvm-as -o=hello2.bc

You're right, it does work even :)

> But be warned, the resulting programs are painfully slow :). Next step is
> to implement garbage collection for it, since it right now just joyfully
> mallocs away :). (It actually runs out of memory if I try to compile
> compile.ss with ccomp.bc, i.e "cat compile.ss|lli ccomp.bc".)

Cool, ok.  Have you seen the LLVM GC support that is already available:

It should be able to support scheme well, though there may be some missing

> A question: would it be difficult to make my compiled compiler
> (ccomp.bc) call functions in llvm for creation of basic blocks and
> instructions, instead of using text format? (See under "LLVM primitives"
> in the scheme code.). I'll try to read up on how to use the JIT
> facilities, but I won't say no to any hints :).

Actually we were just talking about this recently.  I believe that Patrick
(among other things) is working on a C API to the LLVM IR classes.  Given
a C-style API, it will definitely be callable from LLVM code (that's kinda
the point of Patrick's work).  Maybe he can say some more about where this

> [1] http://www.ida.liu.se/~tobnu/compile.ss

This is very neat.  If you put together a little web page for it, and send
me a blurb, I would be very happy to add this to the projects page. :)

As you continue development on it, would you be interested in integrating
this into the LLVM tree?



More information about the llvm-dev mailing list