logoalt Hacker News

kazinatorlast Sunday at 11:07 PM0 repliesview on HN

Working on tail calls for TXR Lisp. Current release provides self tail calls only; and certain cases don't work, like applying in tail position. Plus there is a shadowing bug. These issues are addressed already.

Tail calls between different VM functions are the next challenge. I'm going to somehow have it allocate the VM instance in the same space (if the frame size of the target is larger than the source, "alloca" the difference). The arguments have to be smuggled somehow while we are reinitializing the frame in-place.

I might have a prefix instruction called tail which immediately precedes a call, apply, gcall or gapply. The vm dispatch loop will terminate when it encounters tail similarly to the end instructions. The caller will notice that a tail instruction had been executed, and then precipitate into the tail call logic which will interpret the prefixed instruction in a special way. The calling instruction has to pull out the argument values from whatever registers it refers to. They have to survive the in-place execution somehow.