StdPairCollections1.Mesa
Last tweaked by Mike Spreitzer on October 16, 1987 10:21:34 am PDT
DIRECTORY Collections, IntFunctions, PairCollections;
StdPairCollections1: CEDAR PROGRAM
IMPORTS Collections, IntFunctions, PairCollections
EXPORTS PairCollections
=
BEGIN OPEN IFs:IntFunctions, Colls:Collections, IntFunctions, Collections, PairCollections;
DefaultInsulate: PUBLIC PROC [pc: PairColl] RETURNS [UWPairColl] ~ {
RETURN [AsUW[IF pc.class.mutability#variable THEN pc ELSE
[insulatorClasses
[pc.class.functional[leftToRight]]
[pc.class.functional[rightToLeft]]
[pc.class.mayDuplicate]
[pc.class.orderStyle],
pc.Refify]]]};
InsulatorClasses: TYPE ~ ARRAY --functional[leftToRight]--BOOL OF ARRAY --functional[rightToLeft]--BOOL OF ARRAY --mayDuplicate--BOOL OF ARRAY OrderStyle OF PairCollClass;
insulatorClasses: REF InsulatorClasses ~ NEW[InsulatorClasses];
InsulatePrimitive: PROC [pc: PairColl, op: ATOM, args: ArgList] RETURNS [PrimitiveAnswer] ~ {
subj: PairColl ~ DeRef[pc.data];
IF subj.QualityOf[op, args]=primitive THEN RETURN [yes];
SELECT op FROM
$Insulate, $Freeze, $Thaw, $AddColl, $RemoveColl, $DeleteColl => RETURN [yes];
ENDCASE => RETURN [no];
};
InsulatedWiden: PROC [pc: PairColl] RETURNS [Collection--of REF Pair--] ~ {
subj: PairColl ~ DeRef[pc.data];
RETURN [subj.Widen[].Insulate[]]};
InsulatedHasPair: PROC [pc: PairColl, pair: Pair] RETURNS [BOOL] ~ {
subj: PairColl ~ DeRef[pc.data];
RETURN subj.HasPair[pair]};
InsulatedImage: PROC [pc: PairColl, coll: Collection, dir: Direction] RETURNS [UWColl] ~ {
subj: PairColl ~ DeRef[pc.data];
RETURN subj.Image[coll, dir]};
InsulatedApply: PROC [pc: PairColl, v: Value, dir: Direction] RETURNS [MaybeValue] ~ {
subj: PairColl ~ DeRef[pc.data];
RETURN subj.Apply[v, dir]};
InsulatedScan: PROC [pc: PairColl, Test: Tester, bkwd: BOOL] RETURNS [MaybePair] ~ {
subj: PairColl ~ DeRef[pc.data];
RETURN subj.Scan[Test, bkwd]};
InsulatedScanHalfRestriction: PROC [pc: PairColl, side: Side, coll: Collection, Test: Tester, bkwd: BOOL] RETURNS [MaybePair] ~ {
subj: PairColl ~ DeRef[pc.data];
RETURN subj.ScanHalfRestriction[coll, Test, side, bkwd]};
InsulatedExtremum: PROC [pc: PairColl, bkwd, remove: BOOL] RETURNS [MaybePair] ~ {
subj: PairColl ~ DeRef[pc.data];
IF remove THEN pc.Complain[notVariable];
RETURN subj.class.Extremum[subj, bkwd, FALSE]};
InsulatedGet3: PROC [pc: PairColl, pair: Pair] RETURNS [prev, same, next: MaybePair] ~ {
subj: PairColl ~ DeRef[pc.data];
RETURN subj.Get3[pair]};
InsulatedSize: PROC [pc: PairColl, limit: LNAT] RETURNS [LNAT] ~ {
subj: PairColl ~ DeRef[pc.data];
RETURN subj.Size[limit]};
InsulatedImageSize: PROC [pc: PairColl, coll: Collection, dir: Direction, limit: LNAT] RETURNS [LNAT] ~ {
subj: PairColl ~ DeRef[pc.data];
RETURN subj.ImageSize[coll, dir, limit]};
InsulatedCopy: PROC [pc: PairColl] RETURNS [VarPairColl] ~ {
subj: PairColl ~ DeRef[pc.data];
RETURN subj.Copy[]};
InsulatedValueOf: PROC [pc: PairColl] RETURNS [ConstPairColl] ~ {
subj: PairColl ~ DeRef[pc.data];
RETURN subj.ValueOf[]};
InsulatedCollectionOn: PROC [pc: PairColl, side: Side] RETURNS [UWColl] ~ {
subj: PairColl ~ DeRef[pc.data];
RETURN subj.CollectionOn[side]};
InsulatedCurSetOn: PROC [pc: PairColl, side: Side] RETURNS [ConstSet] ~ {
subj: PairColl ~ DeRef[pc.data];
RETURN subj.CurSetOn[side]};
InsulatedQuaIntFn: PROC [pc: PairColl, dir: Direction] RETURNS [mv: MaybeValue] ~ {
subj: PairColl ~ DeRef[pc.data];
IF NOT (mv ← subj.QuaIntFn[dir]).found THEN RETURN;
RETURN [[TRUE, IFs.DeRef[mv.val].Insulate.Refify]]};
InsulatedSpaces: PROC [pc: PairColl] RETURNS [SpacePair] ~ {
subj: PairColl ~ DeRef[pc.data];
RETURN subj.Spaces[]};
InsulatedOrderingOf: PROC [pc: PairColl] RETURNS [Ordering] ~ {
subj: PairColl ~ DeRef[pc.data];
RETURN subj.OrderingOf[]};
BeRope: PROC [r: ROPE] RETURNS [ROPE] ~ INLINE {RETURN[r]};
Start: PROC ~ {
FOR lr: BOOL IN BOOL DO FOR rl: BOOL IN BOOL DO FOR mayDuplicate: BOOL IN BOOL DO FOR orderStyle: OrderStyle IN OrderStyle DO
insulatorClasses[lr][rl][mayDuplicate][orderStyle] ← CreateClass[[
Primitive: InsulatePrimitive,
Widen: InsulatedWiden,
HasPair: InsulatedHasPair,
Image: InsulatedImage,
Apply: InsulatedApply,
Scan: InsulatedScan,
ScanHalfRestriction: InsulatedScanHalfRestriction,
Extremum: InsulatedExtremum,
Get3: InsulatedGet3,
Size: InsulatedSize,
ImageSize: InsulatedImageSize,
Copy: InsulatedCopy,
ValueOf: InsulatedValueOf,
CollectionOn: InsulatedCollectionOn,
CurSetOn: InsulatedCurSetOn,
QuaIntFn: InsulatedQuaIntFn,
Spaces: InsulatedSpaces,
OrderingOf: InsulatedOrderingOf,
functional: [lr, rl],
mayDuplicate: mayDuplicate,
orderStyle: orderStyle,
mutability: readonly]];
ENDLOOP ENDLOOP ENDLOOP ENDLOOP;
};
Start[];
END.