-- TextLooksSupport.mesa
-- written by Bill Paxton, February 1981
-- last edit by Bill Paxton, December 22, 1981 1:57 pm
-- Internal support interface for TextLooks
Last Edited by: Maxwell, January 5, 1983 12:48 pm
DIRECTORY
Inline,
Mopcodes,
TextLooks;
TextLooksSupport: CEDAR DEFINITIONS
IMPORTS Inline, Mopcodes
SHARES TextLooks =
BEGIN OPEN TextLooks;
-- support procedures
BaseRun: PROC
[x: BaseRuns, index: Offset, lower: NAT ← 0, upper: NATLAST[NAT]]
RETURNS [NAT];
ExtractRuns: PROC
[base: BaseRuns, ref: Runs, start, len: Offset, index: NAT ← 0]
RETURNS [NAT]; -- value is next index
CountRunsAfterChanges: PROC
[ref: Runs, start, len: Offset, limit: Offset ← MaxOffset,
remove, add: Looks, merge: BOOLEANFALSE, firstLooks: Looks ← noLooks]
RETURNS [count: NAT, nonempty: BOOLEAN, lastLooks: Looks];
ExtractRunsAfterChanges: PROC
[base: BaseRuns, ref: Runs, remove, add: Looks,
start: Offset, len: Offset, index: NAT ← 0]
RETURNS [NAT]; -- value is next index
CopyRuns: PROC [to, from: BaseRuns, toLoc, fromLoc, nRuns: NAT];
MakeRun: PROC [len: Offset] RETURNS [new: Runs];
TryFlatSubstr: PROC
[base: Runs, start, len: Offset, limit: Offset ← FlatMax]
RETURNS [BaseRuns];
TryFlatConcat: PROC
[base, rest: Runs, baseLen, restLen: Offset]
RETURNS [new: BaseRuns];
TryFlatConcatRest: PROC
[base, rest: Runs, baseLen, restLen, numRuns: Offset,
merge: BOOLEAN, looks: Looks]
RETURNS [BaseRuns];
ModifyLooks: PROC [old, remove, add: Looks] RETURNS [Looks];
-- modified looks are == (old & ~remove) v add
MergeChanges: PROC [oldrem, oldadd, rem, add: Looks]
RETURNS [newrem, newadd: Looks];
-- ((lks & ~oldrem) v oldadd) & ~rem) v add ==
--  lks & ~(oldrem v rem)) v ((oldadd & ~rem) v add
-- thus, newrem ← oldrem v rem, newadd ← (oldadd & ~rem) v add
LooksAND: PROC [looks1, looks2: Looks] RETURNS [Looks];
-- compute looks1 & looks2
LooksOR: PROC [looks1, looks2: Looks] RETURNS [Looks];
-- compute looks1 v looks2
LooksNOT: PROC [looks: Looks] RETURNS [Looks];
-- compute ~looks
-- inlines
TbaseSize: PROC [x: BaseRuns] RETURNS [Offset] = INLINE {
RETURN [IF x.length=0 THEN 0 ELSE x[x.length-1].after] };
InsertRun: PROC [base: BaseRuns, len: Offset, looks: Looks, index: NAT] RETURNS [NAT];
NewBase: PROC [runs: NAT] RETURNS [BaseRuns];
FindBaseRuns: PROC [x: BaseRuns, start, len: Offset]
RETURNS [first, last: NAT];
BaseRunLengths: PROC [x: BaseRuns, start, len: Offset, first, last: NAT]
RETURNS [firstLen, lastLen: Offset];
-- miscellaneous support routines
Pair: TYPE = MACHINE DEPENDENT RECORD [low,high: CARDINAL];
Short: PROC [x: Offset] RETURNS [NAT] = TRUSTED MACHINE CODE {
-- quick range check and shortening
Mopcodes.zLI1; Mopcodes.zBNDCK; Mopcodes.zPOP; Mopcodes.zLINI; Mopcodes.zBNDCK};
CheckLongSub: PROC [x,y: Offset] RETURNS [Offset] = INLINE {
RETURN [NonNeg[x-y]] };
NonNeg: PROC [x: Offset] RETURNS [Offset] = TRUSTED MACHINE CODE {
Mopcodes.zLINI; Mopcodes.zBNDCK};
-- ***** Initialization
StartTextLooksSupport: PROC; -- for initialization only
END.