[racket] moby/wescheme & TCO

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Sun Jan 30 15:11:47 EST 2011

>> I am wondering if there are documentations on how moby/wescheme solve the tail call optimization issue to compile down to javascript.  My google'fu is failing me.

Hi YC,

The current runtime has an interpreter that's explicitly managing the
control stack, so it can do the tail-call optimization manually.

An approach to get tail calls in JavaScript is described in
"Exceptional Continuations in JavaScript":


where the restoration of the continuation skips tail frames (Section
4.2 of that paper).  So you could imagine saving and restoring the
continuation every so often, which will clear the control context of
tail call frames.

SICP Chapter 5.5 has a compiler that does the tail-call optimization
in its generated intermediate code.  I have a prototype that assembles
to JavaScript:




The new version of the Moby compiler/runtime that I'm working on will
be based on this prototype.

Posted on the users mailing list.