RefStack: CEDAR DEFINITIONS = BEGIN Ref: TYPE = REF Rep; Rep: TYPE; --Opaque Index: TYPE = [1..LAST[INTEGER]]; --NB: Index starts at 1 SizeHint: NAT = 8; --%Default initial size = 8 EachItemAction: TYPE = PROC[item: REF] RETURNS [quit: BOOL _ FALSE]; RStackUnderflow: ERROR; RStackRangeFault: ERROR; Create: PROC [hint: Index _ SizeHint] RETURNS [Ref]; Push: PROC[rStack: Ref, item: REF]; Pop1: PROC[rStack: Ref] RETURNS [REF]; -- ! ERROR RStackUnderflow if rStack is empty Pop: PROC[rStack: Ref, n: NAT, p: EachItemAction]; --! ERROR RStackUnderflow-- Copy: PROC[rStack: Ref, after: NAT _ 0] RETURNS [LIST OF REF]; Items: PROC[rStack: Ref, p: EachItemAction, topDown: BOOL _ TRUE]; ItemAt: PROC[rStack: Ref, index: Index] RETURNS [REF]; --! ERROR RStackRangeFault if index is not in [1..rStackSize]. Size: PROC[rStack: Ref] RETURNS [NAT]; Reset: PROC[rStack: Ref]; Empty: PROC[rStack: Ref] RETURNS [BOOL]; END. Ò--File: RefStack.mesa Last Edited by: CSChow, February 1, 1985 0:06:54 am PST --Intro: This is a stack (of REF ANY's) abstraction. The numbering of elements of the stack -- are from 1 to stack's size (bottom to top) with the oldest element at the bottom and -- the most recent at the top. --Impl: Implemented by Sequence that doubles in size when size is exceeded. Size of sequence -- does not reduce. -- hint is starting size of Rep -- push item onto top of rStack -- Returns and removes item at top of stack -- = {THROUGH [0..n) DO IF p[Pop1[rStack]] THEN EXIT ENDLOOP}; --Returns elements of rStack in the order bottom to top of rStack -- ie. items in list are ordered oldest to newest -- Return list consist of item numbered after+1 to size of rStack -- eg. after = 0 <=> copy from 1 to stack's size --Enumerates items. -- Direct access --Returns number of elements in rStack -- Empties rStack by resetting top-of-stack pointer -- Returns true <=> rStack is empty Ê3˜J™J™7J™šœ Ïkœ œ˜#J˜J™\J™WJ™J™J™\J™J˜Jšœœœ˜JšœœÏc˜J˜Jšœœœœž˜:Icode˜Kšœ œž˜0K˜KšÏnœœœœœœœ˜DJ˜Jšœœ˜Kšœœ˜K˜šŸœœœ˜4K™—K˜šŸœœœ˜#Kšœ™—K˜šŸœœœœ˜&K™+Kšž-˜-—K˜šŸœœœ˜3Kšœœœœ™>Kšž˜—K˜šŸœœœœœœœ˜>KšœA™AK™1KšœA™AK™0—K˜šŸœœ*œœ˜BK™—K˜šŸœœœœ˜7K™Kšœž<˜>—K˜šŸœœœœ˜&Kšœ&™&—K˜šŸœœ˜K™3—K˜šŸœœœœ˜(K™#—K˜Jšœ˜——…—¨ ­