Rosary.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Michael Plass, April 1, 1985 10:11:09 am PST
Provides the analogy for ROPEs, with REF ANYs in place of CHARs. A Rosary.ROSARY 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 RosaryRep;
Item: TYPE ~ REF ANY;
Segment: TYPE ~ RECORD [base: ROSARY, start: INT ← 0, size: INTINT.LAST];
nullSegment: Segment ~ [NIL, 0, 0];
Size: PROC [r: ROSARY] RETURNS [INT];
Fetch: PROC [base: ROSARY, index: INT] RETURNS [Item];
FromItem: PROC [item: Item, repeat: INT ← 1] RETURNS [ROSARY];
Substr: PROC [base: ROSARY, start: INT ← 0, len: INTINT.LAST] RETURNS [ROSARY];
Concat: PROC [base, rest: ROSARY] RETURNS [ROSARY];
Cat: PROC [r0, r1, r2, r3, r4: ROSARYNIL] RETURNS [ROSARY];
CatSegments: PROC [s0, s1, s2: Segment ← nullSegment] RETURNS [ROSARY];
FromProc: PROC [size: INT, proc: PROC RETURNS[Item]] RETURNS [ROSARY];
The proc is called size times, to get the contents for the new ROSARY.
FromProcProc: PROC [p: PROC[q: PROC[item: Item, repeat: INT ← 1]]] RETURNS [ROSARY];
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: ROSARY, index: INT] RETURNS [Run];
bufferSize: NAT ~ 32;
Buffer: TYPE ~ RECORD [count: NAT, a: ARRAY [0..bufferSize) OF Item];
FetchBuffer: PROC [base: ROSARY, index: INT, maxCount: [0..bufferSize] ← bufferSize]
RETURNS [Buffer];
FromList: PROC [list: LIST OF REF] RETURNS [ROSARY];
ToList: PROC [r: ROSARY] RETURNS [LIST OF REF];
FromObject: PROC [size: INT, data: REF ANY, mapRuns: MapRunsProc, substr: SubstrProc ← NIL]
RETURNS [ROSARY];
MapRunsProc: TYPE ~ PROC [s: Segment, action: RunActionType] RETURNS [quit: BOOLEAN];
SubstrProc: TYPE ~ PROC [base: ROSARY, start: INT ← 0, len: INTINT.LAST] RETURNS [ROSARY];
Malformed: ERROR;
maxHeight: NAT ~ 48;
RosaryRep: TYPE ~ RECORD [
size: INT,
height: [0..maxHeight],
var: SELECT tag: * FROM
leaf => [item: Item],
concat => [base, rest: ROSARY],
object => [data: REF ANY, mapRuns: MapRunsProc, substr: SubstrProc]
ENDCASE
];
END.