-- Stack.mesa
-- last edited by Sweet, February 27, 1980 3:26 PM
-- last edited by Satterthwaite, November 2, 1982 3:53 pm

DIRECTORY
Alloc: TYPE USING [Notifier],
CodeDefs: TYPE USING [Byte, StackIndex, StackLocRec, StackPos, TempAddr, VarComponent],
Symbols: TYPE USING [ContextLevel, lZ];

Stack: DEFINITIONS = {
OPEN CodeDefs;

-- Interface Items

StackModelingError: SIGNAL;

Above: PROC [s: StackIndex, count: CARDINAL𡤁, nullOk: BOOL�LSE] RETURNS [StackIndex];
 -- the index of the word "count" above that at "s"
Also: PROC [
n: CARDINAL𡤁, inLink: BOOL�LSE, tOffset: TempAddr,
tLevel: Symbols.ContextLevel←Symbols.lZ];
 -- record that the top "n" words on the stack are also in temps
 -- starting at "tOffset", at lexical level "tLevel"
 -- requires that top "n" words are already onStack
Check: PROC [b: Byte];
 -- if stack in "On", assure that operands are loaded, reflect changes
 -- due to execution of instruction byte "b", check for overflow
Clear: PROC;
 -- pop off all remaining words
Decr: PROC [count: CARDINAL𡤁];
 -- remove the "count" top words from the stack model
DeleteToMark: PROC;
 -- ResetToMark, UnMark
Depth: PROC RETURNS [d: StackPos];
 -- number of words actually on stack
Dump: PROC;
 -- empty the stack into temporaries
Dup: PROC [load: BOOL�LSE];
 -- duplicate the top element on the stack
 -- if "load", load if top is in temp
Exchange: PROC;
 -- exchange the top two elements on the stack
Forget: PROC [s: StackIndex, count: CARDINAL𡤁];
 -- remove "count" words beginning at "a" from the stack model
Incr: PROC [count: CARDINAL𡤁];
 -- add "count" words to the stack model
Init: PROC;

KeepOnly: PROC [s: StackIndex, count: CARDINAL];
-- pop off anything above the "count" words at "s"
Load: PROC [s: StackIndex, count: CARDINAL𡤁];
 -- put the "count" words beginning at "s" on top
Loc: PROC [s: StackIndex, count: CARDINAL𡤁] RETURNS [StackLocRec];
 -- where are the "count" words beginning at "s"
Mark: PROC;
 -- insert a mark, also a label for dumping previous contents
MoveToTemp: PROC [firstIndex: StackIndex, count: CARDINAL𡤁]
RETURNS [VarComponent];
-- store "count" words from stack into contiguous temps
New: PROC RETURNS [old: StackIndex];

Off: PROC;

On: PROC;

Pop: PROC [count: CARDINAL𡤁];
 -- pop off the top "count" words (unless they are already in temps)
Prefix: PROC [sti: StackIndex];
 -- link saved away stack item on front of model
Require: PROC [count: StackPos];
 -- empty all but the top "count" words into temporaries
 -- the top "count" words may also be dumped if necessary
Reset: PROC;

ResetToMark: PROC;
 -- load items back to the first mark, remove from model
Restore: PROC [s: StackIndex];
RoomFor: PROC [n: CARDINAL] RETURNS [BOOL];
 -- will the stack overflow if n more words are loaded
TempStore: PROC [count: CARDINAL𡤁] RETURNS [VarComponent];
 -- store the top "count" words into a temp
Top: PROC [count: CARDINAL𡤁] RETURNS [StackIndex];
 -- the index of the word "count" down from the top
UnMark: PROC;
 -- remove the topmost mark
VDepth: PUBLIC PROC RETURNS [StackPos];
 -- the current depth of the virtual stack
VDepthOf: PROC [s: StackIndex] RETURNS [d: StackPos];
 -- the virtual depth of the word at "s"

StackImplNotify: Alloc.Notifier;

}.