RopePrivate.mesa
Copyright Ó 1984, 1985, 1986, 1987, 1988, 1991 by Xerox Corporation. All rights reserved.
Doug Wyatt, November 13, 1986 7:01:24 pm PST
Russ Atkinson (RRA) July 13, 1987 9:56:32 pm PDT
Christian Jacobi, January 12, 1988 5:42:54 pm PST
Willie-s, August 2, 1991 11:41 am PDT
Michael Plass, September 22, 1991 1:53 am PDT
DIRECTORY
Rope USING [ROPE, RopeRep, StringBound, Text, TextBound, UncheckedFlat];
RopePrivate: CEDAR DEFINITIONS
SHARES Rope
= BEGIN OPEN Rope;
Tsubstr: TYPE = substr node RopeRep;
Tconcat: TYPE = concat node RopeRep;
Treplace: TYPE = replace node RopeRep;
Tobject: TYPE = object node RopeRep;
MaxDepth: CARDINAL = 32;
NonNeg: PROC [x: INT] RETURNS [NAT] = INLINE {RETURN [x]};
This routine is used to check that the argument is not negative. This version depends on the compiler for the bounds checking.
Short: PROC [x: INT] RETURNS [TextBound] = INLINE {RETURN [x]};
This routine is used to narrow from an INT to a TextBound. This version depends on the compiler for the bounds checking.
CheckLongAdd: PROC [x,y: INT] RETURNS [NAT] = INLINE {RETURN [x+y]};
This routine is used to add two numbers and fail if the sum is not positive. This version depends on the compiler for the bounds checking.
NodeSize: PROC [base: REF RopeRep.node] RETURNS [INT] = INLINE {
TRUSTED {
Relys on size field being in the same place in all node variants:
RETURN [LOOPHOLE[base, REF Tobject].size];
};
};
SingleSize: PROC [base: ROPE] RETURNS [INT, Text] = INLINE {
WITH base SELECT FROM
text: Text => RETURN [text.length, text];
node: REF RopeRep.node => RETURN [NodeSize[node], NIL];
ENDCASE => RETURN [0, NIL];
};
DoubleSize: PROC [r1, r2: ROPE] RETURNS [s1: INT, s2: INT, both: BOOL] = INLINE {
t1,t2: Text;
[s1,t1] ¬ SingleSize[r1];
[s2,t2] ¬ SingleSize[r2];
both ¬ t1 # NIL AND t2 # NIL;
};
InlineDepth: PROC [r: ROPE] RETURNS [INTEGER] = INLINE {
IF r = NIL THEN RETURN [0];
WITH r SELECT FROM
node: REF RopeRep.node => RETURN [node.depth];
ENDCASE => RETURN [1];
};
QStore: UNSAFE PROC [c: CHAR, base: Text, index: StringBound] = TRUSTED INLINE {
quick store into string for hack purposes, no checking
LOOPHOLE[base, UncheckedFlat][index] ¬ c;
};
QFetch: UNSAFE PROC [base: Text, index: StringBound] RETURNS [CHAR] = TRUSTED INLINE {
quick fetch from string for hack purposes, no checking
RETURN [LOOPHOLE[base, UncheckedFlat][index]];
};
END.