What you are looking for is the โright tail callsโ. The JVM does not support them, so you need trampolines .
A proper tail call clears the memory of its own function (parameters, local variables) before jumping (instead of calling) into a function called the tail. Thus, a function called a tail can return directly to its calling function-calling. Infinite mutual recursion is possible. (In functional languages, this is one of the most important functions.)
To enable the correct tail calls in assembler, you need a command to geto to a routine / method called through a pointer. OOP needs calls (storage location to go back to the stack and then go) to the procedure / method that is referenced through a pointer.
You can emulate the right tail calls with a trampoline design pattern, maybe there is some support through the library. A trampoline is a while loop that calls a function that returns a link to the next function, which returns a link to the next ...
comonad
source share