CDBottomUpImpl.mesa
Copyright © 1985, 1986 by Xerox Corporation. All rights reserved.
Jacobi, December 13, 1985 5:49:59 pm PST
Jacobi, December 13, 1985 5:50:01 pm PST
DIRECTORY
CD,
CDBottomUp,
CDDirectory,
CDProperties;
CDBottomUpImpl:
CEDAR
MONITOR
IMPORTS CDDirectory, CDProperties
EXPORTS CDBottomUp =
BEGIN OPEN CDBottomUp;
PrivateRec:
TYPE =
RECORD [lastInvocation:
REF←
NIL, lastVal:
REF←
NIL, originalInvocation:
REF←
NIL];
--passed through invocations are never NIL: a NIL invocation means value not yet computed
MakeHandle:
PUBLIC
PROC [class: Class, design:
CD.Design, data:
REF←
NIL, invocation:
REF←
NIL]
RETURNS [handle: Handle] =
BEGIN
handle ←
NEW[HandleRec←[
class: class,
design: design,
data: data,
invocation: IF invocation#NIL THEN invocation ELSE NEW[INT]
]];
END;
Register:
PUBLIC
PROC[do: DoProc, reUse: ReUseProc, key:
REF, reRegistrationKey:
REF, classData
: REF]
RETURNS [class: Class] =
BEGIN
IF key=NIL THEN key ← NEW[INT];
class ← NEW[ClassRec ← [do, reUse, key, classData]];
[] ← CDProperties.RegisterAndInstall[key, [autoRem: TRUE], reRegistrationKey];
END;
Peek:
PUBLIC PROC [key:
REF, ob:
CD.Object]
RETURNS [val:
REF←
NIL] =
BEGIN
WITH CDProperties.GetObjectProp[ob, key]
SELECT
FROM
p: REF PrivateRec => val ← p.lastVal;
ENDCASE => NULL;
END;
StartRecurse:
PUBLIC PROC [class: Class, design:
CD.Design, ob:
CD.Object, data:
REF←
NIL]
RETURNS [val:
REF, new:
BOOL, handle: Handle] =
BEGIN
handle ← MakeHandle[class, design, data];
[val, new] ← DoRecurse[handle, ob];
END;
DoRecurse:
PUBLIC
PROC [handle: Handle, ob:
CD.Object]
RETURNS [val:
REF←
NIL, new:
BOOL←
FALSE] =
BEGIN
GetPrivate:
PROC [key:
REF, ob:
CD.Object]
RETURNS [h:
REF PrivateRec] =
INLINE {
WITH CDProperties.GetObjectProp[ob, key]
SELECT
FROM
p: REF PrivateRec => h ← p;
ENDCASE => CDProperties.PutObjectProp[ob, key, (h←NEW[PrivateRec])];
};
EachChild: CDDirectory.EnumerateObjectsProc = {
IF me.class.inDirectory
THEN
IF DoRecurse[handle, me].new THEN new ← TRUE;
};
p: REF PrivateRec;
IF ob=
NIL
THEN --
copy, so will not find property again ?
ob ← NEW[CD.ObjectRep←handle.design.actual.first.dummyCell.ob^];
p ← GetPrivate[handle.class.key, ob];
IF handle.invocation=p.lastInvocation
THEN
RETURN[p.lastVal, handle.invocation=p.originalInvocation];
CDDirectory.EnumerateChildObjects[me: ob, p: EachChild, x: handle];
new ← new OR p.lastInvocation=NIL;
IF ~new
AND handle.class.reUse#
NIL
THEN {
new ← handle.class.reUse[handle, ob, p.lastVal].shouldDoAain
};
IF new
THEN {
p.lastVal ← handle.class.do[handle, ob];
p.originalInvocation ← handle.invocation;
};
p.lastInvocation ← handle.invocation;
RETURN[p.lastVal, new];
END;
END.