File: [Thyme]<Thyme>Cedar5.2>System>spMain.mesa
Last Edited by: SChen, October 16, 1984 7:46:24 pm PDT
Last Edited by: Gasbarro October 17, 1985 11:24:25 am PDT
DIRECTORY
CommandTool USING [Run],
IO USING [PutF, rope, STREAM],
Process USING [Abort],
RefText USING [New],
Rope USING [ROPE, Equal, Find, FromRefText, IsEmpty, Substr],
spGlobals USING [Aborted, bomb, CircuitRec, CloseNil, defineCircuit, error, fileStackSeq, FuncTableBlk, FuncTablePtr, function, Handle, keys, maxInclude, model, ModelTableBlk, ModelTablePtr, nameBlk, namePtr, next, output, RefUnReal, searchKey, ThymeToolRec, Variables],
ThymeParser;
spMain: CEDAR MONITOR
IMPORTS CommandTool, IO, Process, RefText, Rope, spGlobals
EXPORTS spGlobals, ThymeParser =
{ OPEN spGlobals, ThymeParser;
refUnReal: PUBLIC RefUnReal;
modelTable: PUBLIC ModelTablePtr ← NIL;
functionTable: PUBLIC FuncTablePtr ← NIL;
Canned: PUBLIC ENTRY PROC[handle: Handle] RETURNS[BOOL]= {
ENABLE UNWIND => NULL;
IF handle.vars.stopValue # NIL
THEN IF handle.vars.stopValue^ THEN RETURN [TRUE];
RETURN[handle.vars.canned]};
EnterModels: PUBLIC ENTRY PROC[name: Rope.ROPE, proc: model,
numArgs, numParms, numResults: NAT]= {
ENABLE UNWIND => NULL;
m: ModelTablePtr;
FOR m← modelTable, m.next UNTIL m=NIL DO
IF Rope.Equal[m.name, name] THEN {
m^← [
next: m.next,
name: name,
proc: proc,
numArgs: numArgs,
numParms: numParms,
numResults: numResults];
RETURN;
};
ENDLOOP;
m← NEW[ModelTableBlk←
[next: modelTable,
name: name,
proc: proc,
numArgs: numArgs,
numParms: numParms,
numResults: numResults]];
modelTable← m;
}; -- EnterModels
findModel: PUBLIC ENTRY PROC[name: Rope.ROPE] RETURNS[model, NAT, NAT, NAT]= {
ENABLE UNWIND => NULL;
m: ModelTablePtr;
find the model named newString from ModelTable
FOR m← modelTable, m.next UNTIL m=NIL DO
IF Rope.Equal[m.name, name] THEN
RETURN[m.proc, m.numArgs, m.numParms, m.numResults];
ENDLOOP;
RETURN[NIL, 0, 0, 0];
}; -- findModel
EnterFunctions: PUBLIC ENTRY PROC[name: Rope.ROPE, proc: function,
numArgs, numParms: NAT]= {
ENABLE UNWIND => NULL;
f: FuncTablePtr;
FOR f← functionTable, f.next UNTIL f=NIL DO
IF Rope.Equal[f.name, name] THEN {
f^← [f.next, name, proc, numArgs, numParms];
RETURN;
};
ENDLOOP;
f← NEW[FuncTableBlk← [functionTable, name, proc, numArgs, numParms]];
functionTable← f;
}; -- EnterFunctions
findFunction: PUBLIC ENTRY PROC[name: Rope.ROPE]
RETURNS[function, NAT, NAT]= {
ENABLE UNWIND => NULL;
f: FuncTablePtr;
FOR f← functionTable, f.next UNTIL f=NIL DO
IF Rope.Equal[f.name, name] THEN
RETURN[f.proc, f.numArgs, f.numParms];
ENDLOOP;
RETURN[NIL, 0, 0];
}; -- findFunction
CleanUp: ENTRY PROC[handle: Handle]= {OPEN handle;
ENABLE UNWIND => NULL;
IF checkProcess # NIL THEN {
TRUSTED {Process.Abort[LOOPHOLE[checkProcess, UNSPECIFIED]]};
checkProcess← NIL;
};
IF vars.canned THEN msgStream.PutF["\n...... Aborted.\n"];
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.inStream ← CloseNil[vars.inStream];
simulation← NIL;
}; -- CleanUp

AddLibrary: PROC[handle: Handle]= {
next[handle];
IF handle.vars.item=leftB THEN next[handle] ELSE error[handle, 801, TRUE];
IF handle.vars.item=name THEN {
originalName, nameRoot, errMsg: Rope.ROPE;
dotPosition: INT;
originalName← Rope.FromRefText[handle.vars.newString];
dotPosition← Rope.Find[originalName, "."];
nameRoot← IF dotPosition=-1 THEN originalName
ELSE Rope.Substr[originalName, 0, dotPosition-1];
IF NOT (Rope.Equal[nameRoot, "MosModels", FALSE] OR
Rope.Equal[nameRoot, "StdFunctions", FALSE] OR
Rope.Equal[nameRoot, "Level2Model", FALSE]) THEN {
[errMsg, ]← CommandTool.Run[originalName];
IF NOT Rope.IsEmpty[errMsg] THEN IO.PutF[handle.msgStream, "%s\n",
IO.rope[errMsg]];
};
next[handle];
}
ELSE error[handle, 804, TRUE];
IF handle.vars.item=rightB THEN next[handle] ELSE error[handle, 802, FALSE];
IF handle.vars.item=semi THEN next[handle] ELSE error[handle, 800, FALSE];
}; -- AddLibrary
ReadFile: PUBLIC PROC[inStream, errorStream:IO.STREAM, table: TypeList ← NIL, resProc: ResistorProc ← NIL, capProc: CapacitorProc ← NIL, fetProc: TransistorProc ← NIL, attProc: AttributeProc ← NIL, nodeProc: NodeProc ← NIL, clientData: REF ANYNIL, stopValue: REF BOOLNIL]
RETURNS [nodes, fets, caps, res: INT] = {
handle: Handle ← NEW[ThymeToolRec ← []];
{
ENABLE {
Aborted => GOTO stop;
ABORTED => {handle.vars.canned ← TRUE; GOTO stop};
};
InitVars[handle];
handle.msgStream ← errorStream;
handle.vars.inStream ← inStream;
handle.vars.fetTable ← table;
handle.vars.resProc ← resProc;
handle.vars.capProc ← capProc;
handle.vars.fetProc ← fetProc;
handle.vars.attProc ← attProc;
handle.vars.nodeProc ← nodeProc;
handle.vars.clientData ← clientData;
handle.vars.stopValue ← stopValue;
next[handle];
libraries
WHILE handle.vars.item=name DO
IF Canned[handle] THEN GOTO stop;
IF searchKey[handle]=libraryKey THEN AddLibrary[handle] ELSE EXIT;
ENDLOOP;
circuit definition
IF handle.vars.item=name AND searchKey[handle]=circuitKey THEN {
theRoot: namePtr← NEW[nameBlk←
[name: "Main Circuit", details: NEW[CircuitRec← []]] ];
defineCircuit[handle: handle, ckt: theRoot, root: TRUE]; -- may signal Aborted
}
ELSE error[handle, 820, TRUE];
IF handle.vars.item=slash AND handle.vars.errCount <= 0 THEN {
next[handle];
output[handle, handle.vars.cktRoot, 0];
};
explode
IF handle.vars.item#semi THEN error[handle, 800,, FALSE]
ELSE IF handle.vars.errCount <= 0 THEN {
bomb[handle]; -- may signal Aborted
};
GOTO stop;
EXITS
stop=> RETURN[handle.vars.nodeCount, handle.vars.fetCount, handle.vars.capCount, handle.vars.resCount];
}}; -- Simulate
SkipToSemi: PROC[handle: Handle] = {
WHILE handle.vars.item # semi DO
next[handle];
ENDLOOP;
next[handle];
};
InitVars: PROC[handle: Handle]= {
handle.vars← NEW[Variables← [ ]];
{OPEN handle.vars;
line← RefText.New[256];
newString← RefText.New[256];
line.length← 0;
newString.length← 0;
fileStack← NEW[fileStackSeq[maxInclude]];
};
}; -- InitVars
}.
CHANGE LOG
Wilhelm, April 27, 1982 4:07 PM
Barth, 7-May-82 14:41:52 PDT
Chen, April 19, 1983 6:45 PM, changed the version name for openSysWindow.
Barth, July 11, 1983 12:46 PM
Chen, June 12, 1984 11:37:19 am PDT, cedarized.