File: ThymeCleanUp.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited by:
Last Edited by: Jacobi June 10, 1986 6:57:54 pm PDT
Sweetsun Chen, November 24, 1985 3:25:48 pm PST
Christian Jacobi, June 10, 1986 6:57:37 pm PDT
DIRECTORY
Graph USING [GraphHandle],
GraphOps USING [Lock, SaveGraph, Unlock],
GraphPrivate USING [IsGraphViewer, IsLocked],
GraphUtil USING [HandleNotNil],
IO USING [Close, PutF, STREAM],
Labels USING [Set],
MessageWindow USING [Append, Blink],
Process USING [Abort],
Rope USING [ROPE],
spGlobals,
ViewerClasses USING [Viewer];
ThymeCleanUp: CEDAR PROGRAM
IMPORTS
GraphOps, GraphPrivate, GraphUtil, IO, Labels, MessageWindow, Process, spGlobals
EXPORTS spGlobals = {
OPEN spGlobals;
CleanUp: PUBLIC PROC[handle: Handle] = {
checkProcess
msg: IO.STREAM ← handle.msgStream;
IF handle.checkProcess # NIL THEN {
TRUSTED {Process.Abort[LOOPHOLE[handle.checkProcess, UNSPECIFIED]]};
handle.checkProcess← NIL;
};
IF handle.vars.canned THEN msg.PutF["Simulation is aborted.\n"];
close IO
msg.PutF["\nClosing all input and output files ...... "];
CloseIO[handle.vars];
nil other refs on vars
msg.PutF["done.\nReleasing memory space ...... "];
handle.vars ← FreeVars[handle.vars];
reset progress/status
handle.stage← idle;
SetCursor[handle];
Labels.Set[handle.time, ""];
Labels.Set[handle.step, ""];
epilog
msg.PutF["done.\n\nThyme is idle now.\n"];
handle.simulation← NIL;
handle.outer.inhibitDestroy ← FALSE;
}; -- CleanUp
CloseIO: PROC[vars: REF Variables] = {
ReleaseGraph: PROC [gh: Graph.GraphHandle, plottedOnly: BOOLTRUE] RETURNS [Graph.GraphHandle] = {
IF GraphUtil.HandleNotNil[gh] THEN { OPEN gh;
v: ViewerClasses.Viewer ← chart.viewer;
IF NOT GraphPrivate.IsLocked[gh] THEN GraphOps.Lock[gh];
IF v # NIL AND GraphPrivate.IsGraphViewer[v] THEN {
msg: Rope.ROPE ← GraphOps.SaveGraph[gh, plottedOnly];
IF msg # NIL THEN {
MessageWindow.Append[message: msg, clearFirst: TRUE];
MessageWindow.Blink[];
};
v.inhibitDestroy ← FALSE;
};
userEditAllowed ← TRUE;
GraphOps.Unlock[gh];
};
RETURN[NIL];
}; -- ReleaseGraph
IF vars = NIL THEN RETURN;
thyme.errors
vars.thymeDotErrors ← CloseNil[vars.thymeDotErrors];
input file and included files
FOR i: NAT IN [0..vars.fileStackTop) DO
vars.fileStack[vars.fileStackTop] ← CloseNil[vars.fileStack[vars.fileStackTop]];
ENDLOOP;
vars.fileStack ← NIL;
vars.inStream ← CloseNil[vars.inStream];
text outputs
IF vars.prints # NIL THEN FOR i: NAT IN [0..vars.numPrints) DO
vars.prints[i].printStream ← FlushCloseNil[vars.prints[i].printStream];
vars.prints[i].printList ← NilPrintBlkPtr[vars.prints[i].printList];
ENDLOOP;
vars.prints ← NIL;
graph viewers
IF vars.graphHandle # NIL THEN vars.graphHandle ← ReleaseGraph[vars.graphHandle, FALSE];
IF vars.plots # NIL THEN FOR i: NAT IN [0..vars.numPlots) DO
gHandle: Graph.GraphHandle ← vars.plots[i].plotHandle;
IF gHandle # NIL THEN vars.plots[i].plotHandle ReleaseGraph[gHandle];
vars.plots[i].plotList ← NilPlotBlkPtr[vars.plots[i].plotList];
vars.plots[i].title ← NIL;
ENDLOOP;
vars.plots ← NIL;
}; -- CloseIO
CloseNil: PROC[stream: IO.STREAM] RETURNS [IO.STREAMNIL] = {
IF stream # NIL THEN stream.Close[ ];
}; -- CloseNil
FreeVars: PROC[vars: REF Variables] RETURNS [REF Variables] = {
IF vars # NIL THEN {OPEN vars;
line ← NIL;
newString ← NIL;
gndNodeName ← NilNamePtr[gndNodeName];
undefNode ← NilNamePtr[undefNode];
cktRoot ← NilNamePtr[cktRoot];
currentCkt ← NilNamePtr[currentCkt];
treeRoot ← NilInstTreePtr[treeRoot];
unusedNodes ← NilNodePtr[unusedNodes];
IF modelArgs # NIL THEN FOR i: INT IN [0..hashModulus) DO
modelArgs[i] ← NilModelArgsElement[modelArgs[i]];
ENDLOOP;
modelArgs ← NIL;
n ← NilNodePtr[n];
b ← NilBranchPtr[b];
m ← NilModFuncPtr[m];
gndNode ← NilNodePtr[gndNode];
nodeList ← NilNodePtr[nodeList];
capacitorList ← NilBranchPtr[capacitorList];
inductorList ← NilBranchPtr[inductorList];
vSourceList ← NilBranchPtr[vSourceList];
iSourceList ← NilBranchPtr[iSourceList];
functionList ← NilModFuncPtr[functionList];
intNodeList ← NilNodePtr[intNodeList];
intNodeModFunc ← NilModFuncPtr[intNodeModFunc];
otherModFunc ← NilModFuncPtr[otherModFunc];
worstNode ← NilNodePtr[worstNode];
worst nodes
IF worstNodeLog # NIL THEN FOR i: NAT IN [0..maxLog) DO
worstNodeLog[i].node ← NilNodePtr[worstNodeLog[i].node];
ENDLOOP;
worstNodeLog ← NIL;
title ← NIL;
lastRetreatCause ← NIL;
};
RETURN[NIL];
}; -- FreeVars
NilModelArgsElement: PROC[list: LIST OF REF ANY] RETURNS [LIST OF REF ANYNIL] = {
IF list # NIL THEN {
IF list.first # NIL THEN WITH list.first SELECT FROM
x: modFuncPtr => list.first ← NilModFuncPtr[x];
ENDCASE; -- an error.
list.rest ← NilModelArgsElement[list.rest];
};
}; -- NilModelArgsElement
NilNamePtr: PROC[ref: namePtr] RETURNS [namePtr ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
nextName ← NilNamePtr[nextName];
srchLink ← NilNamePtr[srchLink];
name ← NIL;
expExpr ← NilExpressionPtr[expExpr];
realCopy ← NilRealThingPtr[realCopy];
IF details # NIL THEN details ← WITH details SELECT FROM
x: RefBranchRec => NilRefBranchRec[x],
x: RefCircuitRec => NilRefCircuitRec[x],
x: RefParmRec => NilRefParmRec[x],
x: RefCktInstRec => NilRefCktInstRec[x],
x: RefModelRec => NilRefModelRec[x],
x: RefFunctionRec => NilRefFunctionRec[x],
ENDCASE => NIL; -- RefNodeRec, RefConRec, or error.
};
}; -- NilNamePtr
NilRefBranchRec: PROC[ref: RefBranchRec] RETURNS [RefBranchRec ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
posNode ← NilNamePtr[posNode];
negNode ← NilNamePtr[negNode];
controller ← NilNamePtr[controller];
valExpr ← NilExpressionPtr[valExpr];
};
}; -- NilRefBranchRec
NilRefCircuitRec: PROC[ref: RefCircuitRec] RETURNS [RefCircuitRec ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
names ← NilNamePtr[names];
fakeNodes ← NilNamePtr[fakeNodes];
parms ← NilNamePtr[parms];
father ← NilNamePtr[father];
assertions ← NilExpressionPtr[assertions];
};
}; -- NilRefCircuitRec
NilRefParmRec: PROC[ref: RefParmRec] RETURNS [RefParmRec ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
nextParm ← NilNamePtr[nextParm];
};
}; -- NilRefParmRec
NilRefCktInstRec: PROC[ref: RefCktInstRec] RETURNS [RefCktInstRec ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
of ← NilNamePtr[of];
connections ← NilConLinkPtr[connections];
actualParms ← NilExpressionPtr[actualParms];
};
}; -- NilRefCktInstRec
NilConLinkPtr: PROC[ref: conLinkPtr] RETURNS [conLinkPtr ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
nextLink ← NilConLinkPtr[nextLink];
namedNode ← NilNamePtr[namedNode];
};
}; -- NilConLinkPtr
NilRefModelRec: PROC[ref: RefModelRec] RETURNS [RefModelRec ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
modelProc ← NIL;
modelResults ← NilArgList[modelResults];
modelArgs ← NilArgNames[modelArgs];
modelArgVec ← NilArgList[modelArgVec];
modelOldArgVec ← NilArgList[modelOldArgVec];
modelParms ← NilExpressionPtr[modelParms];
data ← NIL;
};
}; -- NilRefModelRec
NilRefFunctionRec: PROC[ref: RefFunctionRec] RETURNS [RefFunctionRec ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
functionProc ← NIL;
funcArgs ← NilArgNames[funcArgs];
funcArgVec ← NilArgList[funcArgVec];
funcParms ← NilExpressionPtr[funcParms];
branch ← NilNamePtr[branch];
data ← NIL;
};
}; -- NilRefFunctionRec
NilArgNames: PROC[ref: argNames] RETURNS [argNames ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
FOR i: NAT IN [0..size) DO
names[i] ← NilNamePtr[names[i]];
ENDLOOP;
};
}; --NilArgNames
NilNodePtr: PROC[ref: nodePtr] RETURNS [nodePtr ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
nextNode ← NilNodePtr[nextNode];
nodeName ← NilNamePtr[nodeName];
treeLevel ← NilInstTreePtr[treeLevel];
brotherNodes ← NilNodePtr[brotherNodes];
branches ← NilBranchLinkPtr[branches];
curPtr ← NilBranchPtr[curPtr];
nextIntNode ← NilNodePtr[nextIntNode];
entity ← NIL;
};
}; -- NilNodePtr
NilBranchLinkPtr: PROC[ref: branchLinkPtr] RETURNS [branchLinkPtr ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
nextLink ← NilBranchLinkPtr[nextLink];
branch ← NilBranchPtr[branch];
otherNode ← NilNodePtr[otherNode];
};
}; -- NilBranchLinkPtr
NilBranchPtr: PROC[ref: branchPtr] RETURNS [branchPtr ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
branchName ← NilNamePtr[branchName];
treeLevel ← NilInstTreePtr[treeLevel];
brotherBranches ← NilBranchPtr[brotherBranches];
posNode ← NilNodePtr[posNode];
negNode ← NilNodePtr[negNode];
controller ← NilModFuncPtr[controller];
entity ← NIL;
IF body # NIL THEN body ← WITH body SELECT FROM
x: RefC => NilRefC[x],
x: RefL => NilRefL[x],
x: RefV => NilRefV[x],
x: RefI => NIlRefI[x],
ENDCASE => NIL; -- RefR or error.
};
}; -- NilBranchPtr
NilRefC: PROC[ref: RefC] RETURNS [RefC ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
nextCapacitor ← NilBranchPtr[nextCapacitor];
};
}; -- NilRefC
NilRefL: PROC[ref: RefL] RETURNS [RefL ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
nextInductor ← NilBranchPtr[nextInductor];
};
}; -- NilRefL
NilRefV: PROC[ref: RefV] RETURNS [RefV ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
nextvSource ← NilBranchPtr[nextvSource];
};
}; -- NilRefV
NIlRefI: PROC[ref: RefI] RETURNS [RefI ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
nextiSource ← NilBranchPtr[nextiSource];
};
}; -- NIlRefI
NilExpressionPtr: PROC[ref: expressionPtr] RETURNS [expressionPtr ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
next ← NilExpressionPtr[next];
WITH ref SELECT FROM
e: REF max expressionNode => [e.leftOp, e.rightOp] ← NilBinary[e.leftOp, e.rightOp];
e: REF min expressionNode => [e.leftOp, e.rightOp] ← NilBinary[e.leftOp, e.rightOp];
e: REF add expressionNode => [e.leftOp, e.rightOp] ← NilBinary[e.leftOp, e.rightOp];
e: REF sub expressionNode => [e.leftOp, e.rightOp] ← NilBinary[e.leftOp, e.rightOp];
e: REF mul expressionNode => [e.leftOp, e.rightOp] ← NilBinary[e.leftOp, e.rightOp];
e: REF div expressionNode => [e.leftOp, e.rightOp] ← NilBinary[e.leftOp, e.rightOp];
e: REF eq expressionNode => [e.leftOp, e.rightOp] ← NilBinary[e.leftOp, e.rightOp];
e: REF neq expressionNode => [e.leftOp, e.rightOp] ← NilBinary[e.leftOp, e.rightOp];
e: REF grt expressionNode => [e.leftOp, e.rightOp] ← NilBinary[e.leftOp, e.rightOp];
e: REF les expressionNode => [e.leftOp, e.rightOp] ← NilBinary[e.leftOp, e.rightOp];
e: REF geq expressionNode => [e.leftOp, e.rightOp] ← NilBinary[e.leftOp, e.rightOp];
e: REF leq expressionNode => [e.leftOp, e.rightOp] ← NilBinary[e.leftOp, e.rightOp];
e: REF and expressionNode => [e.leftOp, e.rightOp] ← NilBinary[e.leftOp, e.rightOp];
e: REF or expressionNode => [e.leftOp, e.rightOp] ← NilBinary[e.leftOp, e.rightOp];
e: REF power expressionNode=> [e.leftOp, e.rightOp] ← NilBinary[e.leftOp, e.rightOp];
e: REF int expressionNode => e.unaryOp ← NilExpressionPtr[e.unaryOp];
e: REF abs expressionNode => e.unaryOp ← NilExpressionPtr[e.unaryOp];
e: REF exp expressionNode => e.unaryOp ← NilExpressionPtr[e.unaryOp];
e: REF log expressionNode => e.unaryOp ← NilExpressionPtr[e.unaryOp];
e: REF sqrt expressionNode => e.unaryOp ← NilExpressionPtr[e.unaryOp];
e: REF neg expressionNode => e.unaryOp ← NilExpressionPtr[e.unaryOp];
e: REF not expressionNode => e.unaryOp ← NilExpressionPtr[e.unaryOp];
e: REF load expressionNode => [e.var, e.expr] ← NilNameAndExpr[e.var, e.expr];
e: REF store expressionNode=> [e.var, e.expr] ← NilNameAndExpr[e.var, e.expr];
ENDCASE; -- num, or an error.
};
}; -- NilExpressionPtr
NilBinary: PROC[left, right: expressionPtr] RETURNS [nLeft, nRight: expressionPtr] = {
nLeft ← NilExpressionPtr[left];
nRight ← NilExpressionPtr[right];
}; -- NilBinary
NilNameAndExpr: PROC[name: namePtr, expr: expressionPtr]
RETURNS [nName: namePtr, nExpr: expressionPtr] = {
nName ← NilNamePtr[nName];
nExpr ← NilExpressionPtr[expr];
}; -- NilNameAndExpr
NilRealThingPtr: PROC[ref: realThingPtr] RETURNS [realThingPtr ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
nextThing ← NilRealThingPtr[nextThing];
WITH thing SELECT FROM
x: RefRealNode => thing ← NilRefRealNode[x];
x: RefRealBranch => thing ← NilRefRealBranch[x];
x: RefRealModel => thing ← NilRefRealModel[x];
ENDCASE => thing ← NIL; -- for RefRealParm, RefUnReal, or an error.
};
}; -- NilRealThingPtr
NilRefRealNode: PROC[ref: RefRealNode] RETURNS [RefRealNode ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
rn ← NilNodePtr[rn];
};
}; -- NilRefRealNode
NilRefRealBranch: PROC[ref: RefRealBranch] RETURNS [RefRealBranch ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
rb ← NilBranchPtr[rb];
};
}; -- NilRefRealBranch
NilRefRealModel: PROC[ref: RefRealModel] RETURNS [RefRealModel ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
rm ← NilModFuncPtr[rm];
};
}; -- NilRefRealModel
NilInstTreePtr: PROC[ref: instTreePtr] RETURNS [instTreePtr ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
father ← NilInstTreePtr[father];
brothers ← NilInstTreePtr[brothers];
sons ← NilInstTreePtr[sons];
instance ← NilNamePtr[instance];
nodes ← NilNodePtr[nodes];
branches ← NilBranchPtr[branches];
};
}; -- NilInstTreePtr
NilModFuncPtr: PROC[ref: modFuncPtr] RETURNS [modFuncPtr ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
nextMFPtr ← NilModFuncPtr[nextMFPtr];
arguments ← NilArgNodes[arguments];
argVector ← NilArgList[argVector];
parmVector ← NilArgList[parmVector];
actualParms ← NilExpressionPtr[actualParms];
data ← NIL;
WITH body SELECT FROM
x: RefFuncBody => body ← NilRefFuncBody[x];
x: RefModBody => body ← NilRefModBody[x];
ENDCASE => body ← NIL; -- an error.
};
}; -- NilModFuncPtr
NilArgNodes: PROC[ref: argNodes] RETURNS [argNodes ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
FOR i: NAT IN [0..size) DO
nodes[i] ← NilNodePtr[nodes[i]];
ENDLOOP;
};
}; -- NilArgNodes
NilRefFuncBody: PROC[ref: RefFuncBody] RETURNS [RefFuncBody ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
functionProc ← NIL;
branch ← NilBranchPtr[branch];
};
}; -- NilRefFuncBody
NilRefModBody: PROC[ref: RefModBody] RETURNS [RefModBody ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
modelProc ← NIL;
modelResults ← NilArgList[modelResults];
modelName ← NilNamePtr[modelName];
oldArgVector ← NilArgList[oldArgVector];
modelBranches ← NilModBrPtr[modelBranches];
};
}; -- NilRefModBody
NilModBrPtr: PROC[ref: modBrPtr] RETURNS [modBrPtr ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
nextBranch ← NilModBrPtr[nextBranch];
b ← NilBranchPtr[b];
};
}; -- NilModBrPtr
NilArgList: PROC[ref: argList] RETURNS [argList ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
handle ← NIL;
modFunc ← NilModFuncPtr[modFunc];
};
}; --NilArgList
NilPlotBlkPtr: PROC[ref: plotBlkPtr] RETURNS [plotBlkPtr ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
nextBlk ← NilPlotBlkPtr[nextBlk];
arg ← NilArgumentPtr[arg];
};
}; -- NilPlotBlkPtr
NilPrintBlkPtr: PROC[ref: printBlkPtr] RETURNS [printBlkPtr ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
nextBlk ← NilPrintBlkPtr[nextBlk];
arg ← NilArgumentPtr[arg];
};
}; -- NilPrintBlkPtr
NilArgumentPtr: PROC[ref: argumentPtr] RETURNS [argumentPtr ← NIL] = {
IF ref = NIL THEN RETURN;
IF ref.visited THEN RETURN ELSE {OPEN ref;
visited ← TRUE;
node ← NilNodePtr[node];
branch ← NilBranchPtr[branch];
};
}; -- NilArgumentPtr
}.
CHANGE LOG
Chen, May 17, 1985 1:09:43 pm PDT, created.
Chen, July 22, 1985 7:51:28 pm PDT => Cedar6.0.
Chen, November 24, 1985 2:54:48 pm PST, modified for Graph package.
Chen, November 24, 1985 2:54:48 pm PST, Messages blink only afterwards.