-- Stack.mesa Edited by Sweet, December 6, 1979 11:47 AM DIRECTORY AltoDefs: FROM "altodefs" USING [BYTE], CodeDefs: FROM "codedefs" USING [ StackIndex, StackLocRec, StackPos, TempAddr, VarComponent], Symbols: FROM "symbols" USING [ContextLevel, lZ]; Stack: DEFINITIONS = BEGIN OPEN CodeDefs; -- Interface Items StackImpl: PROGRAM; StackModelingError: SIGNAL; Above: PROCEDURE [ s: StackIndex, count: CARDINAL ← 1, nullOk: BOOLEAN ← FALSE] RETURNS [StackIndex]; -- the index of the word "count" above that at "s" Also: PROCEDURE [ n: CARDINAL ← 1, inLink: BOOLEAN ← FALSE, 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: PROCEDURE [b: AltoDefs.BYTE]; -- if stack in "On", assure that operands are loaded, reflect changes -- due to execution of instruction byte "b", check for overflow Clear: PROCEDURE; -- pop off all remaining words Decr: PROCEDURE [count: CARDINAL ← 1]; -- remove the "count" top words from the stack model DeleteToMark: PROCEDURE; -- ResetToMark, UnMark Depth: PROCEDURE RETURNS [d: StackPos]; -- number of words actually on stack Dump: PROCEDURE; -- empty the stack into temporaries Dup: PROCEDURE [load: BOOLEAN ← FALSE]; -- duplicate the top element on the stack -- if "load", load if top is in temp Exchange: PROCEDURE; -- exchange the top two elements on the stack Forget: PROCEDURE [s: StackIndex, count: CARDINAL ← 1]; -- remove "count" words beginning at "a" from the stack model Incr: PROCEDURE [count: CARDINAL ← 1]; -- add "count" words to the stack model Init: PROCEDURE; KeepOnly: PROCEDURE [s: StackIndex, count: CARDINAL]; -- pop off anything above the "count" words at "s" Load: PROCEDURE [s: StackIndex, count: CARDINAL ← 1]; -- put the "count" words beginning at "s" on top Loc: PROCEDURE [s: StackIndex, count: CARDINAL ← 1] RETURNS [StackLocRec]; -- where are the "count" words beginning at "s" Mark: PROCEDURE; -- insert a mark, also a label for dumping previous contents New: PROCEDURE RETURNS [old: StackIndex]; Off: PROCEDURE; On: PROCEDURE; Pop: PROCEDURE [count: CARDINAL ← 1]; -- pop off the top "count" words (unless they are already in temps) Prefix: PROCEDURE [sti: StackIndex]; -- link saved away stack item on front of model Require: PROCEDURE [count: StackPos]; -- empty all but the top "count" words into temporaries -- the top "count" words may also be dumped if necessary Reset: PROCEDURE; ResetToMark: PROCEDURE; -- load items back to the first mark, remove from model Restore: PROCEDURE [s: StackIndex]; TempStore: PROCEDURE [count: CARDINAL ← 1] RETURNS [VarComponent]; -- store the top "count" words into a temp Top: PROCEDURE [count: CARDINAL ← 1] RETURNS [StackIndex]; -- the index of the word "count" down from the top UnMark: PROCEDURE; -- remove the topmost mark VDepth: PUBLIC PROCEDURE RETURNS [StackPos]; -- the current depth of the virtual stack VDepthOf: PROCEDURE [s: StackIndex] RETURNS [d: StackPos]; -- the virtual depth of the word at "s" END.