Call stack

From Esolang
Jump to: navigation, search

In computer proramming, the Call stack is a low-level data structure, taking the form of a stack (of course), which contains information about the current subroutines. The call stack's primary purpose is to store the order of subroutine calling, in order to inform the computer program as to which subroutine the current subroutine returns to. Some languages employ separate stacks for data and calls while others use the same stack for both purposes (notably the x86-architecture).


The call stack can be esotericized in a various ways. One of the most easy-to-comprehend languages that took this concept and rand with it was Call Queue, which is (or will (or would) be) a fairly standard language, except the call structure is a queue instead of a stack- functions return on a loop, to the top called function and down from there instead of to their caller (if the author understands correctly)

In more traditional programming, specifically in many LISPy languages, there are first-class continuations. These replace the traditional, linear stack with a parent-pointer tree, or spaghetti stack. No more can be said on the subject, because the author finds call/cc and its ilk really confusing.

Another way to esotericize call stacks is to allow direct interaction with them, as was set out on Call stack/Manipulation. This allows the user to mess with the logical structure of returns to make the language more confusing than it really has to be.

Other kinds of call stacks

Buffering Calls

Some languages employ call stacks to 'buffer' calls rather than immediately carrying them out. This technique is usually only used when interpreting languages though. Such languages tend to employ two different kind of stacks: A call stack (sometimes also called function stack) and a data stack. If the interpreter encounters a value it is pushed to the data stack, if it encounters a call to a function it is pushed to the call stack. If the interpreter encounters a special operator (may be a newline as well) it executes all calls currently on the stack. The main purpose of this technique is to allow for prefix, postfix and infix notation at the same time (all the following lines are semantically equal):

5 5 squ add;
squ 5 add 5;
squ 5 add 5;
squ add 5 5;
squ 5 5 add;