On Dec 29, 2007 9:05 AM, Ola Bini <[EMAIL PROTECTED]> wrote:

> I'm looking at implementing a language that would be best represented
> using CPS. Now, I can't really find any references to full CPS
> implementations on the JVM anywhere. I'm looking at using the technique
> Kawa is planning for compiled code (see the last part at
> http://www.gnu.org/software/kawa/internals/complications.html). Has
> anyone else done this?

If you haven't already, I recommend reading Henry Baker's classic
paper "Cheney on the MTA"
<http://home.pipeline.com/~hbaker1/CheneyMTA.html>, which is about
compiling full Scheme to the C "virtual machine", which is close
enough to the JVM as far as control issues are concerned.
Essentially, you compile all functions into CPS, and then each
function calls its successor using an ordinary C function call, never
returning from it.  When the C stack gets too full[*], all the data
structures are evicted to the GCed heap, and all the control frames
are discarded by a longjmp back to the beginning.  This provides
*amortized* TCO automatically; that is, although stack is pushed, it
gets recycled rapidly --  in essence, the C stack doubles as the first
generation of the Scheme heap.

[*]The size of the C stack is measured by subtracting a pointer to a
local variable from a global pointer to a variable kept in the main
procedure; on the JVM, you'd presumably keep a global count of
procedures invoked as a rough measure.

 > It seems one of the natural side effects of
> something like this would be a need to have almost all primitives
> implemented in the language itself, since writing this kind of code by
> hand is a bit of a pain.

It's no problem in such a system to call ordinary C functions,
provided they don't call back into Scheme or consume too much stack.

The Chicken Scheme implementation
<http://www.call-with-current-continuation.org> is an actual
implementation of this idea for Scheme-to-C (I'm involved in the
community in my copious spare time).  I'd look there next.  The
community is helpful and friendly, and may well have good ideas about
how to adapt Cheney-style operations to the JVM.

-- 
GMail doesn't have rotating .sigs, but you can see mine at
http://www.ccil.org/~cowan/signatures

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to