Rosary.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Michael Plass, March 11, 1985 4:37:57 pm PST
Provides the analogy for ROPEs, with REF ANYs in place of CHARs. A Rosary.Ref is immutable; clients are encouraged, but not obliged, to treat the objects pointed to by the REF ANYs as immutable as well.
An accelerator is provided for the case where consecutive items are equal.
Rosary: CEDAR DEFINITIONS ~ BEGIN
ROSARY: TYPE ~ Ref;
Ref: TYPE ~ REF Rep;
Item: TYPE ~ REF ANY;
Segment: TYPE ~ RECORD [base: Ref, start: INT ← 0, size: INTINT.LAST];
nullSegment: Segment ~ [NIL, 0, 0];
Size: PROC [r: Ref] RETURNS [INT];
Fetch: PROC [base: Ref, index: INT] RETURNS [Item];
FromItem: PROC [item: Item, repeat: INT ← 1] RETURNS [Ref];
Substr: PROC [base: Ref, start: INT ← 0, len: INTINT.LAST] RETURNS [Ref];
Concat: PROC [base, rest: Ref] RETURNS [Ref];
Cat: PROC [r0, r1, r2, r3, r4: Ref ← NIL] RETURNS [Ref];
CatSegments: PROC [s0, s1, s2: Segment ← nullSegment] RETURNS [Ref];
FromProc: PROC [size: INT, proc: PROC RETURNS[Item]] RETURNS [Ref];
The proc is called size times, to get the contents for the new Ref.
FromProcProc: PROC [p: PROC[q: PROC[item: Item, repeat: INT ← 1]]] RETURNS [Ref];
The client-supplied p is called once; it should call q once for each item.
Map: PROC [s: Segment, action: ActionType] RETURNS [quit: BOOLEAN];
Calls action for each item in s; stops and returns TRUE if action does.
ActionType: TYPE = PROC [item: Item] RETURNS [quit: BOOLEANFALSE];
MapRuns: PROC [s: Segment, action: RunActionType] RETURNS [quit: BOOLEAN];
RunActionType: TYPE = PROC [item: Item, repeat: INT] RETURNS [quit: BOOLEANFALSE];
Run: TYPE ~ RECORD [item: Item, repeat: INT];
FetchRun: PROC [base: Ref, index: INT] RETURNS [Run];
bufferSize: NAT ~ 32;
Buffer: TYPE ~ RECORD [count: NAT, a: ARRAY [0..bufferSize) OF Item];
FetchBuffer: PROC [base: Ref, index: INT, maxCount: [0..bufferSize]𡤋ufferSize] RETURNS [Buffer];
FromList: PROC [list: LIST OF REF] RETURNS [Ref];
ToList: PROC [r: Ref] RETURNS [LIST OF REF];
Malformed: ERROR;
maxHeight: NAT ~ 48;
Rep: TYPE ~ RECORD [
size: INT,
height: [0..maxHeight],
var: SELECT tag: * FROM
leaf => [item: Item],
concat => [base, rest: Ref]
ENDCASE
];
END.