CDAtomicObjectsImpl.mesa (part of ChipNDale)
Copyright © 1985 by Xerox Corporation. All rights reserved.
by Christian Jacobi, March 13, 1985 9:49:28 am PST
last edited by Christian Jacobi, March 25, 1986 1:37:13 pm PST
DIRECTORY
CD,
CDAtomicObjects,
CDBasics,
CDCallSpecific,
CDIO,
CDLRUCache,
CDOrient,
RefTab,
Rope,
RuntimeError,
TokenIO;
CDAtomicObjectsImpl:
CEDAR
MONITOR
IMPORTS CD, CDBasics, CDCallSpecific, CDIO, CDLRUCache, CDOrient, RefTab, RuntimeError, TokenIO
EXPORTS CDAtomicObjects
SHARES CD = --want access technology of ObjectClass
BEGIN
--This module helps the implementation of a wide class of atomic ChipNDale
--objects, which do not have children and are shared between designs. Despite
--its name this are not the only atomic object classes.
DrawRec:
TYPE = CDAtomicObjects
.DrawRec
;
--RECORD [r: CD.Rect, lev: CD.Layer ← CD.errorLayer];
DrawList:
TYPE = CDAtomicObjects
.DrawList
;
--LIST OF DrawRec;
AtomicObsPtr:
TYPE = CDAtomicObjects
.AtomicObsPtr;
--REF AtomicObsRec;
AtomicObsRec:
TYPE = CDAtomicObjects.AtomicObsRec;
--RECORD [
-- rList: DrawList←NIL, --do not change directly
-- ir: CD.Rect, --do not change directly
-- ];
FillObjectProc:
TYPE = CDAtomicObjects.FillObjectProc;
--PROC [ob: CD.Object] RETURNS [mustFail: BOOL ← FALSE];
--read (and even rewrite) size, layer
--calls IncorporateRect
--do not read or write ir
--rList will be initialized to NIL
------------
classTable: RefTab.Ref = RefTab.Create[41];
ClassEntry:
TYPE =
RECORD[
tech: CD.Technology,
fillProc: FillObjectProc,
class: CD.ObjectClass←NIL
];
GetClassEntry:
PROC [classKey:
ATOM, tech:
CD.Technology]
RETURNS [ce:
REF ClassEntry←
NIL] =
INLINE BEGIN
class: CD.ObjectClass = CD.FetchObjectClass[classKey, tech];
IF class#NIL THEN ce ← NARROW[ classTable.Fetch[class].val ]
END;
------------
cache1: CDLRUCache.LRUCache = CDLRUCache.Create[size: 37, aequivalenceProc: AequivalenceAO];
cache2: CDLRUCache.LRUCache = CDLRUCache.Create[size: 37, aequivalenceProc: AequivalenceAO];
cache3: CDLRUCache.LRUCache = CDLRUCache.Create[size: 37, aequivalenceProc: AequivalenceAO];
myRectPtr: CD.RectPtr = NEW[CD.RectRep];
AequivalenceAO:
PROC [mySpecific, other:
REF
ANY]
RETURNS [
BOOL] = {
--Insider info: mySpecific is already in the cache; other is the one to be inserted
RETURN [~ISTYPE[mySpecific, CD.RectPtr]]
};
------------
Create
AtomicOb:
PUBLIC PROC [classKey:
ATOM, size:
CD.Position, tech:
CD.Technology, lev:
CD.Layer←
CD.undefLayer]
RETURNS [ob:
CD.Object←
NIL] =
--NIL if not done
BEGIN
ENABLE UNWIND => NULL;
ce: REF ClassEntry = GetClassEntry[classKey, tech];
size ← CDBasics.MaxPoint[size, [1, 1]];
IF ce#
NIL
THEN {
cache: CDLRUCache.LRUCache ←
SELECT size.x+size.y
FROM
<=30 => cache1, --any minimal size ndiff construct
<=60 => cache2, --any minimal size pdiff construct
ENDCASE => cache3; --long crazy stuff
aop: AtomicObsPtr = NEW[AtomicObsRec ← [ir: CDBasics.empty]];
ob1: CD.Object ← cache.UnusedOrNew[];
ob1.class ← ce.class;
ob1.size ← size;
ob1.layer ← lev;
ob1.specificRef ← aop;
IF ce.fillProc[ob1 ! RuntimeError.UNCAUGHT => GOTO xx].mustFail THEN RETURN [NIL];
ob ← cache.ReplaceByAequivalent[ob1];
--as efficiencyhack, the object is now already in the lru cache, inspite
--of not yet beeing checked.
--If object is bad, however, the technology implementing code is bad, and therefore
--we do not really feel responsible for the design...
IF ob=ob1
THEN {
--new entry
IF ~CDBasics.Inside[aop.ir, CDBasics.RectAt[[0, 0], ob.size]]
OR CDBasics.empty=aop.ir
OR aop.rList=NIL THEN GOTO xx;
--now check if we should change the objectprocs to be more general
IF aop.ir#CDBasics.RectAt[[0, 0], ob.size]
THEN {
IF aop.ir.x1<0 OR aop.ir.y1<0 OR aop.ir.x2>ob.size.x OR aop.ir.y2>ob.size.y THEN GOTO xx;
IF ce.class.showMeSelected=XShowSelectedAO
THEN {
class: CD.ObjectClass = ob.class;
class.showMeSelected ← ShowSelectedAO;
}
};
};
};
EXITS xx =>
RETURN
WITH
ERROR
CD.Error[other, "Error in technology, implementing creation of atomic object"];
END;
Register
AtomicObClass:
PUBLIC
PROC [classKey:
ATOM,
fillProc: FillObjectProc,
description: Rope.ROPE←NIL,
tech: CD.Technology←NIL] RETURNS [type: CD.ObjectClass ← NIL] =
--drawMe, quickDrawMe are considered variables and should not
--be changed by class implementor.
BEGIN
ce:
REF ClassEntry ←
NEW[ClassEntry←[
tech: tech,
fillProc: fillProc
]];
done: BOOL←TRUE;
ce.class ← type ←
CD.RegisterObjectClass[classKey, [
technology: tech,
drawMe: DrawAO,
quickDrawMe: DrawAO,
internalRead: ReadAO,
internalWrite: WriteAO,
interestRect: InsideAO,
showMeSelected: XShowSelectedAO,
wireTyped: FALSE,
description: description] ! CD.Error => {done ← FALSE; CONTINUE}];
IF ~done
THEN
RETURN WITH ERROR CD.Error[doubleRegistration];
done ← RefTab.Insert[classTable, type, ce];
CDCallSpecific.Register[$Lengthen, type, LengthenAO];
END;
Incorporate:
PUBLIC PROC [ob:
CD.Object, r:
CD.Rect, lev:
CD.Layer,
inside: BOOL ← TRUE] =
BEGIN
aop: AtomicObsPtr = NARROW[ob.specificRef];
IF inside THEN aop.ir ← CDBasics.Surround[aop.ir, r];
aop.rList ← CONS[[r, lev], aop.rList];
END;
--------------
ReadAO:
CD.InternalReadProc
--PROC [] RETURNS [Object]-- =
BEGIN
sz: CD.Position ← CDIO.ReadPos[];
code: ATOM = TokenIO.ReadAtom[];
lev: CD.Layer = CDIO.ReadLayer[];
tech: CD.Technology = CDIO.DesignInReadOperation[].technology;
ob: CD.Object ← CreateAtomicOb[code, sz, tech, lev];
IF
CDIO.VersionKey[]<10
THEN {
--The old way had the size instead the interest rect in the file
ob ← CreateAtomicOb[code, [sz.x - (ob.size.x-sz.x), sz.y - (ob.size.y-sz.y)], tech, lev];
};
RETURN [ob]
END;
WriteAO:
CD.InternalWriteProc
-- PROC [me: Object] -- =
BEGIN
CDIO.WritePos[CD.InterestSize[me]];
TokenIO.WriteAtom[me.class.objectType];
CDIO.WriteLayer[me.layer];
END;
DrawAO:
PROC [inst:
CD.Instance, pos:
CD.Position, orient:
CD.Orientation, pr:
CD.DrawRef] =
BEGIN
FOR class: DrawList ←
NARROW[inst.ob.specificRef, AtomicObsPtr].rList, class.rest
WHILE class#
NIL
DO
pr.drawRect[
CDOrient.MapRect[
itemInCell: class.first.r,
cellSize: inst.ob.size,
cellInstOrient: orient,
cellInstPos: pos],
class.first.lev,
pr]
ENDLOOP;
END;
ShowSelectedAO:
PROC [inst:
CD.Instance, pos:
CD.Position,
orient: CD.Orientation, pr: CD.DrawRef] =
BEGIN
aop: AtomicObsPtr = NARROW[inst.ob.specificRef];
pr.drawOutLine[
CDOrient.MapRect[
itemInCell: aop.ir,
cellSize: inst.ob.size,
cellInstOrient: orient,
cellInstPos: pos],
CD.selectionLayer,
pr]
END;
XShowSelectedAO:
PROC [inst:
CD.Instance, pos:
CD.Position, orient:
CD.Orientation, pr:
CD.DrawRef] =
BEGIN
pr.drawOutLine[CDOrient.RectAt[pos, inst.ob.size, orient], CD.selectionLayer, pr]
END;
InsideAO:
PROC [ob:
CD.Object]
RETURNS [
CD.Rect] =
BEGIN
RETURN [NARROW[ob.specificRef, AtomicObsPtr].ir]
END;
LengthenAO: CDCallSpecific.CallProc =
--PROC [design: CD.Design, inst: CD.Instance, x: REF]
--RETURNS [done: BOOL←TRUE, removeMe: BOOL←FALSE, include: CD.InstanceList←NIL,
--repaintMe: BOOL←FALSE, repaintInclude: BOOL←FALSE]
BEGIN
ToPosition:
PROC [x:
REF]
RETURNS [class:
CD.Position] =
--y field defaults to lambda, x field defaults to 0
--[0, 0] if not done
BEGIN
IF x=NIL THEN class ← [0, design.technology.lambda]
ELSE
WITH x
SELECT
FROM
rp: REF CD.Position => class ← rp^;
rn: REF CD.Number => class ← [0, rn^];
ENDCASE => class ← [0, 0];
END;
--LengthenAO
amount: CD.Position = ToPosition[x];
IF amount.y=0 AND amount.x=0 THEN done ← FALSE
ELSE {
sz: CD.Position ← CDBasics.AddPoints[CD.InterestSize[inst.ob], amount];
new: CD.Object ← CreateAtomicOb[size: sz, classKey: inst.ob.class.objectType, lev: inst.ob.layer, tech: inst.ob.class.technology];
done ← new#NIL AND new#inst.ob AND new.size#inst.ob.size;
IF done
THEN {
inst.ob ← new;
repaintMe ← TRUE;
}
};
END;
END.