Each time a MUF function F calls another function G, Muq must somehow remember remember where it was in F, so as to be able to pick up where it left off after G returns.
In the distant early days of computing, this was done simply by saving a pointer to the appropriate instruction inside of function F itself. This turned out to be a fairly uncool idea, since it meant that F could not call itself repeatedly without completely losing track of where it was supposed to return to. In a multi-user system like Muq, in which many different users may wish to use F at the "same" time, things would be even worse!
Thus, nowadays almost every language uses a stack to hold these return addresses (and most computers now have special instructions for maintaining such stacks.) A code sequence like
: H 1 + ; : G -> x x H x H * ; : F -> y y G 2 * ; 13 F ,
is implemented by a series of loop stack operations which look like this:
Loop stack top -> +------+ ( Loop stack is empty. ) +------+ Loop stack top -> | , | ( Address of ',' saved while calling F ) +------+ +------+ Loop stack top -> | F: 2 | ( Address of '2' in F while calling G ) +------+ | , | +------+ +------+ Loop stack top -> | G: x | ( Address of 'x' in G while calling H ) +------+ | F: 2 | ( Address of '2' in F while calling G ) +------+ | , | +------+ +------+ Loop stack top -> | F: 2 | ( Back in G after 1st call to H ) +------+ | , | +------+ +------+ Loop stack top -> | G: * | ( Address of '*' in G while calling H ) +------+ | F: 2 | ( Address of '2' in F while calling G ) +------+ | , | +------+ +------+ Loop stack top -> | F: 2 | ( Back in G after 2nd call to H ) +------+ | , | +------+ +------+ Loop stack top -> | , | ( Back in F after call to G ) +------+ Loop stack top -> +------+ ( Done, loop stack is again empty. )
We also need some place to keep the values of local variables within a function. It is natural and efficient to keep them on the loop stack as well. Adding them, plus a count of them plus a frame label results in a normal stackframe looking as follows.
Go to the first, previous, next, last section, table of contents.