You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TCO is important. It would allow some iterations that can be expressed via recursion to be used that way without exhausting the stack (which is dynamically allocated, but still, without wasting memory).
The optimization looks simple to do, in execute.c, in the handling of CALL_JQ. If
the called function has no arguments, and
the next instruction is a RET
then instead of pushing a new frame just:
save the current frame's retaddr and retdata
pop the current frame
push a new frame
set the new frame's retaddr and retdata to be the same as the old one's
It looks like this ought to work. However, the closure passed to frame_push() makes this tricky. The following patch provides TCO (passes all tests, and demonstrably applies TCO to a tail-recursive test case), but only for self-recursion, not co-recursion:
TCO is important. It would allow some iterations that can be expressed via recursion to be used that way without exhausting the stack (which is dynamically allocated, but still, without wasting memory).
The optimization looks simple to do, in
execute.c
, in the handling ofCALL_JQ
. IfRET
then instead of pushing a new frame just:
retaddr
andretdata
retaddr
andretdata
to be the same as the old one'sIt looks like this ought to work. However, the closure passed to
frame_push()
makes this tricky. The following patch provides TCO (passes all tests, and demonstrably applies TCO to a tail-recursive test case), but only for self-recursion, not co-recursion:The text was updated successfully, but these errors were encountered: