Danny - thanks for the explanation on how it works and the links to the paper. I will look into them. <div><br></div><div>Appreciated! </div><div>yc</div><div><br><div class="gmail_quote">On Sun, Jan 30, 2011 at 12:11 PM, Danny Yoo <span dir="ltr"><<a href="mailto:dyoo@cs.wpi.edu">dyoo@cs.wpi.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im"><br>
</div>Hi YC,<br>
<br>
The current runtime has an interpreter that's explicitly managing the<br>
control stack, so it can do the tail-call optimization manually.<br>
<br>
<br>
<br>
An approach to get tail calls in JavaScript is described in<br>
"Exceptional Continuations in JavaScript":<br>
<br>
<a href="http://www.schemeworkshop.org/2007/procPaper4.pdf" target="_blank">http://www.schemeworkshop.org/2007/procPaper4.pdf</a><br>
<br>
where the restoration of the continuation skips tail frames (Section<br>
4.2 of that paper). So you could imagine saving and restoring the<br>
continuation every so often, which will clear the control context of<br>
tail call frames.<br>
<br>
<br>
<br>
SICP Chapter 5.5 has a compiler that does the tail-call optimization<br>
in its generated intermediate code. I have a prototype that assembles<br>
to JavaScript:<br>
<br>
<a href="https://github.com/dyoo/js-sicp-5-5/blob/master/cm.rkt" target="_blank">https://github.com/dyoo/js-sicp-5-5/blob/master/cm.rkt</a><br>
<br>
Example:<br>
<br>
<a href="http://hashcollision.org/tmp/gauss.html" target="_blank">http://hashcollision.org/tmp/gauss.html</a><br>
<br>
The new version of the Moby compiler/runtime that I'm working on will<br>
be based on this prototype.<br>
</blockquote></div><br><br>
</div>