3 ms·
A loop which dispatches closures can implement cross module tail recursion (absent of continuations). Function A wants to call B. Instead of a direct call, it p
by kazinator 9y ago
A loop which dispatches closures can implement cross module tail recursion (absent of continuations). Function A wants to call B. Instead of a direct call, it performs a dynamic return to the loop, passing it B and the arguments to be applied to B (wrapped up as a closure, or other object).
This shouldn't be called a trampoline; it's just a dispatch loop.
Trampolines are a technique for turning function pointers into closures. GCC uses trampolines for pointers to nested functions.
The trampoline mechanism constructs a piece of machine code on the stack (or possibly elsewhere). Next to that machine code at some fixed offset, there is the closure info: the real function plus context. The trampoline is referenced by the pointer to the code: a low level function pointer, compatible with C function pointers and the like. When that is called, it retrieves the closure info (via instruction-pointer-relative addressing) and calls the real target function.
- cryptonector 9y agoYes. I said the same sort of thing below. Trampolines are also used in signal handling and other such things. The common thread is a need to adjust the stack, so to speak, to handle a strange situation (signal handling, calling GCC-style local function closures, ...). I think TFA just misues terminology, though it's possible that those uses are common in some communities, so maybe they aren't really misuses. Having to carry a mental dictionary for translating terminology in the world of CS seems to be... a requirement that will never go away. It's OK.