CDValueImpl.mesa (part of ChipNDale)
Copyright © 1983, 1986, 1987 by Xerox Corporation. All rights reserved.
Created by: Christian Jacobi, August 16, 1983 4:09 pm
Last edited by: Christian Jacobi, April 1, 1987 3:13:44 pm PST
DIRECTORY
CDValue,
CD,
CDEvents,
RefTab;
CDValueImpl:
CEDAR
MONITOR
IMPORTS CD, CDEvents, RefTab
EXPORTS CD, CDValue =
BEGIN
Propagation: TYPE = CDValue.Propagation;
PrivateValueDRep:
PUBLIC
TYPE =
RECORD [
values: RefTab.Ref
];
PrivateValueTRep:
PUBLIC
TYPE =
RECORD [
registration: RefTab.Ref,
values: RefTab.Ref
];
globalTab: RefTab.Ref = RefTab.Create[];
registerTab: RefTab.Ref = RefTab.Create[];
registeredWithTechnology:
REF ←
NEW[
INT];
DesignCreateEvent: CDEvents.EventProc = {
design.cdValuePriv ← NEW[PrivateValueDRep ← [values: RefTab.Create[]]]
};
TechnologyCreateEvent: CDEvents.EventProc = {
tech: CD.Technology = NARROW[x];
tech.cdValuePriv ← NEW[PrivateValueTRep ← [registration: RefTab.Create[], values: RefTab.Create[]]]
};
RegisterKey:
PUBLIC
ENTRY
PROC [key:
REF, boundTo:
CD.Technology, registrationKey:
REF] = {
ENABLE UNWIND => NULL;
Register:
PROC [regTab: RefTab.Ref, key:
REF, registrationKey:
REF]
RETURNS [ok:
BOOL] = {
oldRegistrationKey: REF ← RefTab.Fetch[regTab, key].val;
IF oldRegistrationKey=NIL THEN ok ← RefTab.Insert[regTab, key, registrationKey]
ELSE IF oldRegistrationKey=$nil OR oldRegistrationKey#registrationKey THEN ok ← FALSE
ELSE ok ← TRUE
};
done: BOOL ← FALSE;
IF registrationKey=NIL THEN registrationKey ← $nil;
IF boundTo=NIL THEN done ← Register[registerTab, key, registrationKey]
ELSE {
done ← Register[registerTab, key, registeredWithTechnology];
IF done
THEN {
tem: REF PrivateValueTRep = boundTo.cdValuePriv;
IF tem=
NIL
THEN
RETURN
WITH
ERROR CD.Error[ec: calling, explanation: "technology had not been registered"];
done ← Register[tem.registration, key, registrationKey]
};
};
IF ~done THEN RETURN WITH ERROR CD.Error[doubleRegistration]
};
Fetch:
PUBLIC
ENTRY
PROC [boundTo:
REF, key:
REF, propagation: Propagation]
RETURNS [
REF] = {
ENABLE UNWIND => NULL;
val: RefTab.Val; found: BOOL;
DO
WITH boundTo
SELECT
FROM
d:
CD.Design => {
[found: found, val: val] ← RefTab.Fetch[d.cdValuePriv.values, key];
IF found THEN RETURN [val];
IF propagation>design THEN boundTo𡤍.technology ELSE RETURN [NIL]
};
t:
CD.Technology => {
[found: found, val: val] ← RefTab.Fetch[t.cdValuePriv.values, key];
IF found THEN RETURN [val];
IF propagation>technology THEN boundTo←NIL ELSE RETURN [NIL]
};
ENDCASE => {
IF boundTo#
NIL
THEN
RETURN WITH ERROR CD.Error[calling, "CDValue.Fetch: bad boundTo type"]
ELSE {
[found: found, val: val] ← RefTab.Fetch[globalTab, key];
IF found THEN RETURN [val];
RETURN [NIL]
};
};
ENDLOOP
};
GetTab:
PROC [boundTo:
REF]
RETURNS [ref: RefTab.Ref] =
INLINE {
WITH boundTo
SELECT
FROM
t: CD.Technology => RETURN [t.cdValuePriv.values];
d: CD.Design => RETURN [d.cdValuePriv.values];
ENDCASE => {
IF boundTo#
NIL
THEN RETURN WITH ERROR CD.Error[calling, "CDValue.Store: bad boundTo type"]
ELSE RETURN [globalTab]
};
};
Store:
PUBLIC
PROC [boundTo:
REF, key:
REF, value:
REF] = {
ref: RefTab.Ref = GetTab[boundTo];
IF value#
NIL
THEN [] ← RefTab.Store[ref, key, value]
ELSE [] ← RefTab.Delete[ref, key];
};
StoreConditional:
PUBLIC
PROC [boundTo:
REF, key:
REF, value:
REF]
RETURNS [done:
BOOL] = {
ref: RefTab.Ref = GetTab[boundTo];
IF value#
NIL
THEN done ← RefTab.Insert[ref, key, value]
ELSE done ← RefTab.Delete[ref, key];
};
FetchInt:
PUBLIC
PROC [boundTo:
REF, key:
REF, propagation: Propagation, ifNotFound:
INT]
RETURNS [
INT] = {
WITH Fetch[boundTo, key, propagation]
SELECT
FROM
r: REF INT => RETURN [r^]
ENDCASE => RETURN [ifNotFound]
};
StoreInt:
PUBLIC
PROC [boundTo:
REF, key:
REF, value:
INT] = {
Store[boundTo, key, NEW[INT ← value]]
};
CDEvents.RegisterEventProc[$CreateNewDesign, DesignCreateEvent];
CDEvents.RegisterEventProc[$RegisterTechnology, TechnologyCreateEvent];
END.