Call stack/Manipulation
Call Stack Manipulation is a language construct where the language itself contains built-in features to allow the user to interfere with the logical and intuitive methods in which functions call other functions and get their return value.
Call Stack Overview
To understand manipulation of the call stack, one must first understand the call stack itself. This section lays out a high-level explanation of how it works, or at least how the author is about 90% sure it works.
When a function is called, the language pushes that function onto the call stack, a stack representing the order of calling. When a function calls another function, the new function is pushed. When a function returns, it is poped off the top of the call stack and its value is returned to the new top of the call stack. This ensures that functions are called in the logical order.
Call Stack Manipulation
Now, what if the user could mess with the call stack? Control its behavior? That is what call stack manipulation allows. Call Stack Manipulation is like a stripped-down version of normal stack manipulation, but it allows the user to change the order of function calls from within functions. There are two types of call stack primitives: Call primitives and execution primitives. Call primitives are an alternative way to call a function, generally a first-order function that changes the way the function is added to the call stack. Execution primitives are keywords that mess with the call stack during execution.
The first execution primitive is leer;
(all of these keywords are in anglicized German, because why the hell not). leer;
pushes a special function, the general identity function, onto the stack. This seems useless, until you remember that it gets popped off when the current function returns. This means that the current function gets repeated instead of returning to its caller, and serves as a sort of secretive recursion-based loop.
One I thought of (different author here) is swap
. This is borrowed straight from typical stack manipulation functions, but it swaps the top two frames on the call stack. The instruction pointer is "returned" automatically to where the new top frame was. The function "returns" but sneakily captures the caller's return result for itself, and it can decide what to do with it.
Feel free to add your own, I guess.