[oops; forgot the link I meant to post, so here's a 2nd attempt

On Sun, Jul 4, 2010 at 1:26 AM, Stefan Marr <pharo@stefan-marr.de> wrote:
Hello Pharo:

What would it take to implement tail-call optimization?

My goal is to have an Erlang-like framework, which allows to port existing Erlang code as straight forward as possible.
But this requires to have tail-call optimization, since Erlang provides no loops.


But the system will run for a long time before it runs out of stack. �Don't get hung up on this. �Continue with the rest of the problem.
However, I am not going for implementing the whole language and all its semantics, but only the basics I am interested in.

So, a possible solution would also be a pragma/hint to the compiler to apply the optimization.



When you come to deal with tail calls you may find that the obvious case, namely spotting recursive sends to self, is adequate, in which case the compiler implementation is relatively trivial; one maps a tail-recursive send to self to a set of assignments to the arguments (*) followed by any necessary pops to level the stack, followed by a jump to the start.

(* Assignment to arguments legal in the bytecode; the compiler prevents explicit assignment to arguments but args and temps are the same �at the bytecode level).
Has anyone done something like this before, or has some hints where to start digging?


Various people, myself included, have done context-based hacks for fun, but they're merely parlour tricks; they have abysmal performance (certainly for loops, which is where we came in), no safety and don't integrate with the debugger. �You'll want to look at Scheme and Java implementations.

There's an excellent discussion in Gilad Bracha's blog which has some good starting points. �If Newspeak gets ported to Cog (or rather vice verse, if Cog is extended to run Newspeak) and Gilad doesn't dismount from the TCO hobby horse then I expect TCO will be implemented in Cog in a more complete manner. �But as Gilad says, "one can cheat for a very long time though.".

best
Eliot
Thanks
Stefan


--
Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
http://soft.vub.ac.be/~smarr
Phone: +32 2 629 2974
Fax: � +32 2 629 3525


_______________________________________________
Pharo-project mailing list
Pharo-project@lists.gforge.inria.fr
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project