DIRECTORY AMBridge, AMTypes, Ascii, Asserting, AssertingIO, Atom, BasicTime, Commander, Convert, FS, IO, IOClasses, OrderedSymbolTableRef, PrintTV, PutGet, Rope, RoseTranslateTypes, RoseTranslateInsides, RuntimeError, SignalTypeRegistration, StructuredStreams, TEditMesaOps, TextNode, TiogaFileOps, TiogaOps, TiogaStreams, UndoEvent, UserCredentials, ViewerClasses, ViewerIO, ViewerOps, ViewerTools; RoseTranslateRandoms: CEDAR PROGRAM IMPORTS AMBridge, Ascii, Asserting, AssertingIO, BasicTime, Commander, Convert, FS, IO, IOClasses, OSTR: OrderedSymbolTableRef, PrintTV, PutGet, Rope, RoseTranslateInsides, RuntimeError, SignalTypeRegistration, SS: StructuredStreams, TEditMesaOps, TextNode, TFO: TiogaFileOps, TS: TiogaStreams, UserCredentials, ViewerIO EXPORTS RoseTranslateTypes, RoseTranslateInsides = BEGIN OPEN RoseTranslateTypes, RoseTranslateInsides; TypeConstructionError: PUBLIC ERROR [msg: ROPE] = CODE; Circularity: PUBLIC ERROR = CODE; viewerLog: PUBLIC IO.STREAM _ ViewerIO.CreateViewerStreams["RoseTranslate.Log"].out; omitted: PUBLIC REF ANY _ NEW [ROPE _ "omitted"]; error: PUBLIC REF ANY _ NEW [ROPE _ "error"]; noDefault: PUBLIC REF ANY _ NEW [ROPE _ "no default"]; AddOpen: PUBLIC PROC [job: Job, name: ROPE] = BEGIN IF job.opened.Lookup[name] # NIL THEN RETURN; job.opened.Insert[name]; IF NOT job.emptyOpen THEN job.openStream.PutRope[", "]; job.openStream.PutRope[name]; job.emptyOpen _ FALSE; AddDirectory[job, name]; END; AddImport: PUBLIC PROC [job: Job, name: ROPE] = BEGIN IF job.imports.Lookup[name] # NIL THEN RETURN; job.imports.Insert[name]; IF NOT job.emptyImports THEN job.importsStream.PutRope[", "]; job.importsStream.PutRope[name]; job.emptyImports _ FALSE; AddDirectory[job, name]; END; AddDirectory: PUBLIC PROC [job: Job, name: ROPE] = BEGIN IF job.directory.Lookup[name] # NIL THEN RETURN; job.directory.Insert[name]; IF NOT job.emptyDirectory THEN job.directoryStream.PutRope[", "]; job.directoryStream.PutRope[name]; job.emptyDirectory _ FALSE; END; AddMesa: PUBLIC PROC [job: Job, m: Mesa] = {rl: RopeList; FOR rl _ m.directory, rl.rest WHILE rl # NIL DO AddDirectory[job, rl.first] ENDLOOP; FOR rl _ m.imports, rl.rest WHILE rl # NIL DO AddImport[job, rl.first] ENDLOOP; }; GetParm: PUBLIC PROC [n: [1..LAST[INTEGER]], name: ROPE, parms: REF ANY, default: REF ANY _ noDefault] RETURNS [it: REF ANY] = BEGIN IF parms = NIL THEN BEGIN IF default # noDefault THEN it _ default ELSE ERROR TypeConstructionError[IO.PutFR["parm %g not found", IO.rope[name]]]; END ELSE WITH parms SELECT FROM bl: BindingList => BEGIN FOR bl _ bl, bl.rest WHILE bl # NIL DO IF bl.first.name.Equal[name, FALSE] THEN RETURN [bl.first.value]; ENDLOOP; IF default # noDefault THEN it _ default ELSE ERROR TypeConstructionError[IO.PutFR["parm %g not found", IO.rope[name]]]; END; a: Args => BEGIN i: INT _ n; FOR l: LIST OF Arg _ a.args, l.rest WHILE l # NIL DO IF i = 1 THEN RETURN [l.first]; i _ i - 1; ENDLOOP; IF default # noDefault THEN it _ default ELSE ERROR TypeConstructionError[IO.PutFR["no %g'th parm", IO.int[i]]]; END; ENDCASE => ERROR; END; ForceMesaType: PUBLIC PROC [mesaType: ROPE, on: NodeType] RETURNS [forced: NodeType] = BEGIN ERROR; --no longer supported END; Close: PUBLIC PROC [job: Job] = BEGIN IF job.errCount < 1 THEN BEGIN WITH job.parseTree SELECT FROM s: Statements => FOR l: LORA _ s.statements, l.rest WHILE l # NIL DO TranslatePiece[job, l.first] ENDLOOP; ENDCASE => TranslatePiece[job, job.parseTree]; END ELSE job.log.PutRope["Translation aborted due to errors\n"]; job.log.PutF["%g error%g, %g warning%g", IO.card[job.errCount], IO.rope[IF job.errCount = 1 THEN "" ELSE "s"], IO.card[job.warnCount], IO.rope[IF job.warnCount = 1 THEN "" ELSE "s"]]; job.log.PutF["; source tokens: %g, time: %g\n", IO.card[job.tokenCount], IO.real[BasicTime.PulsesToSeconds[BasicTime.GetClockPulses[] - job.start]]]; job.directoryStream.PutRope[";"]; job.directoryStream.Close[]; job.importsStream.PutRope[" ="]; job.importsStream.Close[]; job.openStream.PutRope[";"]; job.openStream.Close[]; job.regStream.PutRope["END;"]; job.regStream.Close[]; job.typeStream.Close[]; TS.EndNode[job.to]; job.to.PutRope["RegisterCells[];"]; TS.EndNode[job.to]; TS.EndNode[job.to]; job.to.PutRope["END."]; job.to.Close[]; IF job.errCount < 1 THEN TRUSTED BEGIN destName: ROPE; DoMesaFormatting[job.outRoot]; TFO.Store[job.outRoot, destName _ job.rootName.Concat[".Mesa"]]; --DoMesaFormatting[destName];-- --UserExecExtras.DoIt[job.exec, Rope.Cat["compile ", job.rootName]];-- TFO.Store[job.symbolsRoot, job.rootName.Concat[".RoseSymbols"]]; WriteDeps[job]; END; END; WriteDeps: PROC [job: Job] = BEGIN WriteLoad: PROC [asAny: REF ANY] RETURNS [stop: BOOLEAN] = BEGIN depName: ROPE _ NARROW[asAny]; cmFile.PutF["@%g.roseLoad\n", IO.rope[depName]]; stop _ FALSE; END; cmFile: IO.STREAM _ FS.StreamOpen[fileName: job.rootName.Concat[".roseLoad"], accessOptions: create]; job.libbed.EnumerateIncreasing[WriteLoad]; cmFile.PutF["Run %g\n", IO.rope[job.rootName]]; cmFile.Close[]; END; TranslateCmd: Commander.CommandProc --PROC [cmd: Handle] RETURNS [result: REF _ NIL, msg: Rope.ROPE _ NIL]-- = BEGIN commandLineStream: IO.STREAM _ IO.RIS[cmd.commandLine]; [] _ commandLineStream.SkipWhitespace[flushComments: FALSE]; WHILE NOT commandLineStream.EndOf[] DO name: ROPE _ commandLineStream.GetTokenRope[IO.IDProc].token; errs: CARDINAL _ 1; errs _ Translate[cmd, name, NIL, TranslateJob !Circularity => CONTINUE]; IF errs > 0 THEN RETURN [$Failure]; [] _ commandLineStream.SkipWhitespace[flushComments: FALSE]; ENDLOOP; END; Translate: PUBLIC PROC [exec: Commander.Handle, rootName: ROPE, pathIn: LIST OF ROPE, type: JobType] RETURNS [errCount: CARDINAL] = TRUSTED BEGIN inRoot: TextNode.Ref _ NIL; job: Job _ NEW [JobRep _ [ exec: exec, rootName: rootName, path: CONS[rootName, pathIn], outRoot: TFO.CreateRoot[], symbolsRoot: TFO.CreateRoot[], directory: OSTR.CreateTable[CompareRopes], imports: OSTR.CreateTable[CompareRopes], opened: OSTR.CreateTable[CompareRopes], libbed: OSTR.CreateTable[CompareRopes], things: OSTR.CreateTable[SignalTypeRegistration.CompareSymbolTableEntries], used: OSTR.CreateTable[CompareRefAnies], type: type, start: BasicTime.GetClockPulses[]]]; logFile: IO.STREAM; sourceName, logName: ROPE; inRoot _ PutGet.FromFile[sourceName _ rootName.Concat[".Rose"] !FS.Error => BEGIN viewerLog.PutF["\nOpen failed on %g\n", IO.rope[sourceName]]; inRoot _ NIL; CONTINUE; END]; IF inRoot = NIL THEN RETURN [1]; job.from _ TS.CreateInput[inRoot]; job.to _ TS.CreateOutput[job.outRoot, "code"]; job.symbolsStream _ TS.CreateOutput[job.symbolsRoot]; logFile _ FS.StreamOpen[fileName: logName _ rootName.Concat[".log"], accessOptions: create]; job.log _ IOClasses.CreateDribbleOutputStream[logFile, viewerLog]; Open[job, sourceName]; job.parseTree _ ParseExpression[job]; Close[job]; logFile.Close[]; viewerLog.PutRope["Done.\n\n"]; errCount _ job.errCount; END; Open: PROC [job: Job, sourceName: ROPE] = TRUSTED BEGIN job.log.PutF["\nTranslating %g into %g.Mesa, log on %g.Log\n", IO.rope[sourceName], IO.rope[job.rootName], IO.rope[job.rootName]]; job.to.PutF["--%g.Mesa", IO.rope[job.rootName]]; TS.EndNode[job.to]; job.to.PutF["--created by RoseTranslate from %g of %g for %g at %g", IO.rope[sourceName], IO.time[FS.FileInfo[sourceName].created], IO.rope[UserCredentials.Get[].name], IO.time[]]; TS.EndNode[job.to]; TS.EndNode[job.to]; TS.EndNode[job.to]; job.to.PutRope["DIRECTORY"]; job.directoryStream _ TS.CreateOutput[TS.CurOutNode[job.to], "code"]; TS.EndNode[job.to]; TS.EndNode[job.to]; job.to.PutF["%l%g%l: CEDAR PROGRAM", IO.rope["lb"], IO.rope[job.rootName], IO.rope["LB"]]; job.importsStream _ TS.CreateOutput[TS.CurOutNode[job.to], "code"]; job.importsStream.PutRope["IMPORTS "]; TS.EndNode[job.to]; TS.EndNode[job.to]; job.to.PutRope["BEGIN OPEN"]; job.openStream _ TS.CreateOutput[TS.CurOutNode[job.to], "code"]; TS.EndNode[job.to]; TS.EndNode[job.to]; job.to.PutRope["--Signal Type decls"]; job.typeStream _ TS.CreateOutput[TS.CurOutNode[job.to], "code"]; TS.EndNode[job.to]; TS.EndNode[job.to]; job.to.PutRope["RegisterCells: PROC ="]; job.regStream _ TS.CreateOutput[TS.CurOutNode[job.to], "code"]; TS.EndNode[job.to]; job.regStream.PutRope["BEGIN"]; TS.EndNode[job.regStream]; AddOpen[job, "RoseTypes"]; AddImport[job, "RoseCreate"]; END; TypeCheck: PUBLIC PROC [job: Job, defName: ROPE, args: REF ANY, interface: DigestedInterface, instanceName: ROPE] = BEGIN cName: ROPE _ defName.Cat[".", instanceName]; Check: PROC [sr: SourceRange, keyword: ROPE, match: InterfaceElt, value: REF ANY] = BEGIN Descr: PROC RETURNS [r: ROPE] = { r _ IF keyword = NIL THEN IO.PutFR["%g#%g", IO.rope[cName], IO.card[index]] ELSE IO.PutFR["%g.%g", IO.rope[cName], IO.rope[keyword]]}; ste: SymbolTableEntry; valName: ROPE; valNode: nodeEntry; IF match = NIL AND keyword # NIL THEN BEGIN match _ NARROW[interface.asTable.Lookup[keyword]]; IF match = NIL THEN Whimper[sr, job, "%g not a valid port on cell %g", IO.rope[keyword], IO.rope[cName]]; END; WITH value SELECT FROM id: ID => {valName _ id.rope; IF sr = nullSR THEN sr _ id.sr}; ENDCASE => {Whimper[sr, job, "%g should be bound to an ID, not %g", IO.rope[Descr[]], IO.refAny[value]]; RETURN}; ste _ NARROW[job.things.Lookup[valName]]; WITH ste SELECT FROM ne: nodeEntry => valNode _ ne; ENDCASE => {Whimper[sr, job, "%g was bound to %g, which should have been a node, rather than %g", IO.rope[Descr[]], IO.rope[valName], IO.refAny[ste]]; RETURN}; IF match = NIL THEN RETURN; IF match.spare THEN Whimper[sr, job, "%g.%g specified twice", IO.rope[cName], IO.rope[match.name]] ELSE match.spare _ TRUE; IF match.sti.st # valNode.nodeType THEN BEGIN Whimper[sr, job, "Type mismatch for %g: got %g when expecting %g", IO.rope[Descr[]], IO.rope[valNode.nodeType.procs.UserDescription[valNode.nodeType]], IO.rope[match.sti.st.procs.UserDescription[match.sti.st]]]; END; END; toMatch: InterfaceEltList _ interface.asList; index: CARDINAL _ 0; FOR iel: InterfaceEltList _ interface.asList, iel.rest WHILE iel # NIL DO iel.first.spare _ FALSE; ENDLOOP; WITH args SELECT FROM bl: BindingList => FOR bl _ bl, bl.rest WHILE bl # NIL DO index _ index + 1; Check[bl.first.sr, bl.first.name, NIL, bl.first.value]; ENDLOOP; a: Args => BEGIN l: LIST OF Arg; FOR l _ a.args, l.rest WHILE l # NIL AND toMatch # NIL DO index _ index + 1; Check[nullSR, NIL, toMatch.first, l.first]; toMatch _ toMatch.rest; ENDLOOP; IF l # NIL --OR toMatch # NIL-- THEN Whimper[a.sr, job, "too many parameters to %g", IO.rope[cName]]; END; ENDCASE => ERROR; index _ 0; FOR iel: InterfaceEltList _ interface.asList, iel.rest WHILE iel # NIL DO index _ index + 1; IF NOT iel.first.spare THEN --old: Whimper[job, "%g.%g never specified", IO.rope[cName], IO.rope[iel.first.name]];-- --new:-- Check[nullSR, iel.first.name, iel.first, NEW [IDRep _ [nullSR, iel.first.name]] ]; ENDLOOP; END; DoMesaFormatting: PROC [tfor: TiogaFileOps.Ref] = BEGIN tnr: TextNode.Ref; TRUSTED {tnr _ LOOPHOLE[tfor]}; [] _ TEditMesaOps.SetSpanMesaLooks[ span: [[tnr, 0], TextNode.LastLocWithin[tnr]], event: NIL ]; END; Complain: PUBLIC PROC [sr: SourceRange, context: REF ANY, complaint: ROPE, v1, v2, v3, v4, v5: IO.Value _ [null[]]] RETURNS [reduced: REF ANY] = BEGIN job: Job _ NARROW[context]; IF sr # nullSR THEN job.log.PutF["At [%g..%g]: ", IO.int[sr.first], IO.int[sr.last]] ELSE IF NOT job.from.EndOf[] THEN job.log.PutF["Somewhere before %g: ", IO.int[job.from.GetIndex[]]]; job.log.PutF[complaint.Concat["\n"], v1, v2, v3, v4, v5]; job.errCount _ job.errCount + 1; reduced _ error; END; Whimper: PUBLIC PROC [sr: SourceRange, context: REF ANY, complaint: ROPE, v1, v2, v3, v4, v5: IO.Value _ [null[]]] = BEGIN job: Job _ NARROW[context]; IF sr # nullSR THEN job.log.PutF["At [%g..%g]: ", IO.int[sr.first], IO.int[sr.last]] ELSE IF NOT job.from.EndOf[] THEN job.log.PutF["Somewhere before %g: ", IO.int[job.from.GetIndex[]]]; job.log.PutF[complaint.Concat["\n"], v1, v2, v3, v4, v5]; job.warnCount _ job.warnCount + 1; END; CompareRopes: OSTR.CompareProc = {RETURN [Rope.Compare[NARROW[r1], NARROW[r2]]]}; CompareRefAnies: OSTR.CompareProc = BEGIN c1: LONG CARDINAL _ LOOPHOLE[r1]; c2: LONG CARDINAL _ LOOPHOLE[r2]; RETURN [IF c1 < c2 THEN less ELSE IF c1 > c2 THEN greater ELSE equal]; END; InitialCap: PROC [r: ROPE] RETURNS [R: ROPE] = { l: INT = r.Length[]; IF l = 0 THEN RETURN [r]; R _ Rope.FromChar[Ascii.Upper[r.Fetch[0]]].Concat[r.Substr[start: 1, len: l-1]]}; uppers: ARRAY [1..15] OF CARDINAL _ [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767]; UseSignalType: PROC [job: Job, st: NodeType] = BEGIN c: REF ANY _ st; ce: REF ANY _ NARROW[job.used.Lookup[c]]; IF ce = NIL THEN BEGIN m: Mesa _ IF st.procs.MesaDefinition # NIL THEN st.procs.MesaDefinition[st] ELSE [NIL]; job.used.Insert[c]; IF m # [NIL] THEN {job.typeStream.PutRope[m.mesa]; job.typeStream.PutRope[";"]; TS.EndNode[job.typeStream]; AddMesa[job, m];}; END; END; WriteRegistration: PUBLIC PROC [to: IO.STREAM, result, name: ROPE, cellDef: CellDef] = BEGIN evalGiven: BOOLEAN _ FALSE; to.PutRope[result]; to.PutRope[" _ RoseCreate.RegisterCellType[name: "]; IF cellDef.nameIsLiteral THEN to.PutF["\"%g\",", IO.rope[cellDef.literalName]] ELSE to.PutF["%gName[%g],", IO.rope[name], IO.rope[IF cellDef.forFn # NIL THEN "args" ELSE ""]]; TS.ChangeDepth[to, 1]; IF cellDef.expandGiven THEN to.PutF["expandProc: %gExpand,", IO.rope[name]] ELSE to.PutRope["expandProc: NIL,"]; TS.EndNode[to]; IF (cellDef.interfaceLiteral # NIL AND cellDef.interfaceLiteral.asList # NIL) OR cellDef.ioCreatorGiven THEN to.PutF["ioCreator: Create%gIO, ", IO.rope[name]] ELSE to.PutRope["ioCreator: NIL, "]; IF cellDef.stateGiven OR cellDef.initializerGiven THEN to.PutF["initializer: Initialize%g,", IO.rope[name]] ELSE to.PutRope["initializer: NIL,"]; TS.EndNode[to]; to.PutRope["evals: ["]; FOR et: EvalType IN EvalType DO IF cellDef.evalsGiven[et] THEN { IF evalGiven THEN to.PutRope[", "] ELSE evalGiven _ TRUE; to.PutF["%g: %g%g", IO.rope[etNames[et]], IO.rope[name], IO.rope[etNames[et]]]}; ENDLOOP; to.PutRope["],"]; TS.EndNode[to]; IF cellDef.bbTestGiven THEN to.PutF["blackBox: %gBBTest, ", IO.rope[name]] ELSE to.PutRope["blackBox: NIL, "]; IF cellDef.stTestGiven THEN to.PutF["stateToo: %gSTTest,", IO.rope[name]] ELSE to.PutRope["stateToo: NIL,"]; TS.EndNode[to]; to.PutRope["ports: "]; IF cellDef.interfaceLiteral # NIL AND cellDef.interfaceLiteral.asList = NIL THEN to.PutRope["NEW [PortsRep[0]],"] ELSE to.PutF["Create%gPorts[%g],", IO.rope[name], IO.rope[IF cellDef.forFn # NIL THEN "args" ELSE ""]]; TS.EndNode[to]; IF cellDef.interfaceLiteral # NIL AND cellDef.interfaceLiteral.asList # NIL THEN to.PutF["drivePrototype: NEW [%gDrive]", IO.rope[name]] ELSE to.PutRope["drivePrototype: NIL"]; IF cellDef.forFn # NIL THEN { to.PutRope[","]; TS.EndNode[to]; to.PutF["typeData: NEW [%gArgs _ args]", IO.rope[name]]}; IF cellDef.initCTPropsGiven OR (cellDef.assertions # NIL) THEN { to.PutRope[","]; TS.EndNode[to]; to.PutF["other: Initial%gProps[%g]", IO.rope[name], IO.rope[IF cellDef.forFn # NIL THEN "args" ELSE ""]]}; to.PutRope["];"]; TS.ChangeDepth[to, -1]; END; etNames: PUBLIC ARRAY EvalType OF ROPE _ ["ValsChanged", "InitQ", "PropQ", "InitUD", "PropUD", "FinalUD", "EvalSimple", "FindVicinity"]; WriteInterfaceDecls: PUBLIC PROC [job: Job, name, ioRefTypeName: ROPE, di: DigestedInterface, function: BOOL] RETURNS [iCount: CARDINAL] = BEGIN interface: InterfaceEltList _ di.asList; toIO, toDrive, toPortFile, portConsts: IO.STREAM; firstWord: CARDINAL _ 0; dest: TFO.Ref; portFileName: ROPE _ job.rootName.Cat[".", name, ".rosePorts"]; iCount _ 0; toPortFile _ SS.Create[FS.StreamOpen[portFileName, create]]; TS.EndNode[job.to]; job.to.PutF["Create%gPorts: PROC ", IO.rope[name]]; IF function THEN job.to.PutF["[args: %gArgs] ", IO.rope[name]]; job.to.PutF["RETURNS [ports: Ports] = {ports _ RoseCreate.PortsFromFile[\"%q\"]};", IO.rope[portFileName]]; TS.EndNode[job.to]; TS.EndNode[job.to]; toPortFile.PutF["%g", IO.int[di.asTable.Size[]]]; job.to.PutF["%g: TYPE = REF %gIORec;", IO.rope[ioRefTypeName], IO.rope[name]]; TS.EndNode[job.to]; job.to.PutF["%gIORec: TYPE = MACHINE DEPENDENT RECORD [", IO.rope[name]]; TS.EndNode[job.to]; dest _ TS.CurOutNode[job.to]; TS.EndNode[job.to]; toIO _ TS.CreateOutput[dest, "code"]; job.to.PutRope["-- port indices:"]; TS.EndNode[job.to]; dest _ TS.CurOutNode[job.to]; TS.EndNode[job.to]; portConsts _ TS.CreateOutput[dest, "code"]; job.to.PutF["%gDrive: TYPE = MACHINE DEPENDENT RECORD [", IO.rope[name]]; TS.EndNode[job.to]; dest _ TS.CurOutNode[job.to]; TS.EndNode[job.to]; toDrive _ TS.CreateOutput[dest, "code"]; FOR interface _ interface, interface.rest WHILE interface # NIL DO Finish: PROC [s: IO.STREAM] = {IF interface.rest # NIL THEN {s.PutRope[","]; TS.EndNode[s]}}; ie: InterfaceElt _ interface.first; iename: ROPE _ ie.name; bitWidth, wordWidth, bitRem: CARDINAL; mesaType: Mesa; xPhobic: BOOL _ NOT ie.sti.st.simple; special: BOOLEAN _ FALSE; portTypeStream: IO.STREAM _ IO.ROS[]; otherAssertions: Asserting.Assertions _ NIL; UseSignalType[job, ie.sti.st]; bitWidth _ ie.sti.st.procs.Bits[ie.sti.st]; mesaType _ ie.sti.st.procs.MesaUse[ie.sti.st]; AddMesa[job, mesaType]; wordWidth _ (bitWidth + 15)/16; bitRem _ bitWidth MOD 16; IF bitRem # 0 THEN BEGIN toIO.PutF["fill%g(%g:0..%g): [0..%g],", IO.card[iCount], IO.card[firstWord], IO.int[15 - bitRem], IO.card[uppers[16 - bitRem]]]; TS.EndNode[toIO]; END; toIO.PutF["%g(%g:%g..%g): %g", IO.rope[iename], IO.card[firstWord], IO.card[(16-bitRem) MOD 16], IO.card[16*wordWidth - 1], IO.rope[mesaType.mesa]]; Finish[toIO]; toDrive.PutF["fill%g(%g:0..14): [0 .. 32768),", IO.card[iCount], IO.card[iCount]]; TS.EndNode[toDrive]; toDrive.PutF["%g(%g:15..15): BOOLEAN", IO.rope[iename], IO.card[iCount]]; Finish[toDrive]; FOR ll: Asserting.Assertions _ ie.assertions, ll.rest WHILE ll # NIL DO key: ATOM _ NARROW[Asserting.RelnOf[ll.first]]; SELECT key FROM $XPhobic => xPhobic _ TRUE; $XPhillic => xPhobic _ FALSE; $Special => special _ TRUE; $General => special _ FALSE; ENDCASE => otherAssertions _ CONS[ll.first, otherAssertions]; ENDLOOP; toPortFile.PutF["\n %g %g %g ", IO.card[firstWord], IO.card[wordWidth], IO.rope[Convert.RopeFromRope[iename]]]; WriteInvocation[portTypeStream, ie.sti.invocation]; toPortFile.PutF["\"%q\" %g ", IO.rope[IO.RopeFromROS[portTypeStream]], IO.card[(IF ie.input THEN 1 ELSE 0) + (IF ie.output THEN 2 ELSE 0) + (IF xPhobic THEN 4 ELSE 0) + (IF special THEN 8 ELSE 0)]]; AssertingIO.Write[to: toPortFile, assertions: otherAssertions]; IF NOT ie.sti.st.simple THEN { portConsts.PutF["%g%gPortIndex: CARDINAL = %g;", IO.rope[name], IO.rope[InitialCap[iename]], IO.card[iCount]]; TS.EndNode[portConsts]}; firstWord _ firstWord + wordWidth; iCount _ iCount + 1; ENDLOOP; toIO.PutRope["];"]; toIO.Close[]; toDrive.PutRope["];"]; toDrive.Close[]; SS.CloseThrough[toPortFile]; END; WriteInitializer: PUBLIC PROC [job: Job, name: ROPE, cs: CedarSource, cellDef: CellDef] = BEGIN dest: TiogaFileOps.Ref; opend: ROPE _ ""; TS.EndNode[job.to]; job.to.PutF["Initialize%g: Initializer = {", IO.rope[name]]; TS.ChangeDepth[job.to, 1]; job.to.PutRope["IF leafily THEN"]; TS.ChangeDepth[job.to, 1]; job.to.PutRope["BEGIN"]; TS.EndNode[job.to]; IF cellDef.initializerGiven AND cellDef.ioRefTypeName # NIL THEN BEGIN job.to.PutF["ioRec: %g _ NARROW[cell.realCellStuff.newIO];", IO.rope[cellDef.ioRefTypeName]]; TS.EndNode[job.to]; opend _ opend.Cat["ioRec"]; IF cellDef.stateGiven THEN opend _ opend.Cat[", state"]; END; IF cellDef.forFn # NIL THEN BEGIN opend _ opend.Cat[", args"]; job.to.PutF["args: REF %gArgs _ NARROW [cell.type.typeData];", IO.rope[name]]; TS.EndNode[job.to]; END; IF cellDef.stateGiven THEN BEGIN job.to.PutF["state: %gStateRef _ NEW [%gStateRec", IO.rope[name], IO.rope[name]]; IF cellDef.stateInittable THEN job.to.PutRope[" _ []"]; job.to.PutRope["];"]; TS.EndNode[job.to]; job.to.PutRope["cell.realCellStuff.state _ state;"]; TS.EndNode[job.to]; END; IF cellDef.initializerGiven THEN BEGIN job.to.PutF["BEGIN OPEN %g;", IO.rope[opend]]; dest _ TS.CurOutNode[job.to]; TS.ChangeDepth[job.to, 1]; job.to.PutRope["END;"]; TS.ChangeDepth[job.to, -1]; TS.CopyChildren[from: cs.parent, to: dest]; END; job.to.PutRope["END;"]; TS.ChangeDepth[job.to, -1]; job.to.PutRope["};"]; TS.ChangeDepth[job.to, -1]; END; WriteEval: PUBLIC PROC [job: Job, name: ROPE, et: EvalType, cs: CedarSource, cellDef: CellDef] = BEGIN opend: ROPE _ NIL; AddOpen: PROC [o: ROPE] = { opend _ IF opend = NIL THEN o ELSE (opend.Cat[", ", o])}; dest: TiogaFileOps.Ref; hasIO: BOOL _ cellDef.ioRefTypeName # NIL; doSW: BOOL _ FALSE; TS.EndNode[job.to]; job.to.PutF["%g%g: %g =", IO.rope[name], IO.rope[etNames[et]], IO.rope[IF et = FindVicinity THEN "PROC [cell: Cell, portIndex: CARDINAL, evenIfInput: BOOL _ FALSE]" ELSE "CellProc"]]; TS.ChangeDepth[job.to, 1]; job.to.PutRope["BEGIN"]; TS.EndNode[job.to]; SELECT et FROM FindVicinity => NULL; InitQ, PropQ, InitUD, PropUD, FinalUD, ValsChanged => { IF hasIO THEN {AddOpen["sw"]; doSW _ TRUE}; IF cellDef.interfaceLiteral # NIL AND NOT cellDef.interfaceLiteral.hasSwitchElt THEN Whimper[cellDef.sr, job, "Cell class %g has a %g, but no switch-level interface elements!", IO.rope[name], IO.rope[etNames[et]]]; }; EvalSimple => IF hasIO THEN AddOpen["newIO"]; ENDCASE => ERROR; IF doSW OR (cellDef.interfaceLiteral # NIL AND cellDef.interfaceLiteral.hasSwitchElt) THEN { job.to.PutF["sw: %g _ NARROW[cell.realCellStuff.switchIO];", IO.rope[cellDef.ioRefTypeName]]; TS.EndNode[job.to]; }; IF cellDef.forFn # NIL THEN { job.to.PutF["args: REF %gArgs _ NARROW[cell.type.typeData];", IO.rope[name]]; TS.EndNode[job.to]; AddOpen["args"]; }; IF hasIO THEN job.to.PutF["newIO: %g _ NARROW[cell.realCellStuff.newIO];", IO.rope[cellDef.ioRefTypeName]]; IF cellDef.stateGiven THEN BEGIN TS.EndNode[job.to]; job.to.PutF["state: %gStateRef _ NARROW[cell.realCellStuff.state];", IO.rope[name]]; AddOpen["state"]; END; TS.ChangeDepth[job.to, 1]; job.to.PutRope["BEGIN"]; IF opend # NIL THEN job.to.PutF[" OPEN %g;", IO.rope[opend]]; dest _ TS.CurOutNode[job.to]; TS.EndNode[job.to]; job.to.PutRope["END;"]; TS.ChangeDepth[job.to, -1]; TS.CopyChildren[from: cs.parent, to: dest]; job.to.PutRope["END;"]; TS.ChangeDepth[job.to, -1]; END; InstantiateSignalType: PUBLIC PROC [context: REF ANY, name: ROPE, parms: REF ANY] RETURNS [sti: SignalTypeInvocation] = BEGIN job: Job _ NARROW[context]; stce: stcEntry _ NARROW[SignalTypeRegistration.signalTypes.Lookup[name]]; IF stce = NIL THEN {[] _ Complain[nullSR, context, "Signal Type %g Undefined", IO.rope[name]]; RETURN [NIL]}; sti _ NEW [SignalTypeInvocationRep _ [nullSR, NIL, [nullSR, name, parms]]]; sti.st _ stce.stc[parms ! TypeConstructionError => BEGIN [] _ Complain[nullSR, context, msg]; sti _ NIL; CONTINUE; END; RuntimeError.UNCAUGHT => BEGIN msg: IO.STREAM _ IO.ROS[]; stv: AMTypes.TV; TRUSTED {stv _ AMBridge.TVForSignal[signal]}; PrintTV.Print[tv: stv, put: msg, verbose: TRUE]; [] _ Complain[nullSR, context, "Signal Type construction %g[%g] died horribly (uncaught signal or error: %g)", IO.rope[name], IO.refAny[parms], IO.rope[IO.RopeFromROS[msg]]]; sti _ NIL; CONTINUE; END]; END; Setup: PROC = BEGIN Commander.Register["RoseTranslate", TranslateCmd, "Translates rosemary sources (.Rose) into Mesa files"]; END; Setup[]; END. œRoseTranslateRandoms.Mesa Last Edited by: Spreitzer, September 14, 1984 8:11:04 pm PDT DoMesaFormatting: PROC [fileName: ROPE] = BEGIN vi: ViewerClasses.ViewerRec _ [name: "temp, dammit", file: fileName, inhibitDestroy: TRUE]; v: ViewerClasses.Viewer _ ViewerTools.MakeNewTextViewer[info: vi, paint: FALSE]; Doit: PROC [root: TiogaOps.Ref] = { TiogaOps.SaveSelA[]; TiogaOps.SelectDocument[v]; TiogaOps.MesaFormatting[]; TiogaOps.RestoreSelA[]; }; TiogaOps.CallWithLocks[Doit, TiogaOps.ViewerDoc[v]]; ViewerOps.SaveViewer[v]; ViewerOps.DestroyViewer[v, FALSE]; END; DoMesaFormatting: PROC [fileName: ROPE] = TRUSTED BEGIN check: ATOM _ Atom.MakeAtom[fileName]; asAny: REF ANY _ Atom.GetProp[atom: check, prop: $mjsMesaFmtCheck]; ri: REF INT; v: ViewerClasses.Viewer; viewerName: ROPE; IF asAny = NIL THEN Atom.PutProp[atom: check, prop: $mjsMesaFmtCheck, val: asAny _ ri _ NEW [INT _ 0]] ELSE ri _ NARROW[asAny]; ri^ _ ri^ + 1; viewerName _ IF ri^ = 1 THEN fileName ELSE IO.PutFR["%g!%g", IO.rope[fileName], IO.int[ri^]]; v _ ViewerTools.MakeNewTextViewer[info: [name: viewerName, file: fileName, iconic: FALSE]]; TiogaOps.SelectDocument[v]; TiogaOps.MesaFormatting[]; END; ΚE˜J™J™=J˜IcodešΟk œXœœ¨˜K˜šΠbxœœ˜#KšœIœœ œlœ-œœ)˜ΐKšœ+˜2—K˜Kšœœ*˜4K˜Kš Πblœœœœœ˜7K˜KšŸ œœœœ˜!K˜K˜Kšœ œœœ9˜TK˜Kš œ œœœœœ˜1Kš œœœœœœ ˜-K˜Kš œ œœœœœ˜6K˜K˜šΟnœœœœ˜-Kš˜Kšœœœœ˜-K˜Kšœœœ˜7Kšœ.œ˜4K˜Kšœ˜—K˜š  œœœœ˜/Kš˜Kšœœœœ˜.K˜Kšœœœ!˜=Kšœ4œ˜:K˜Kšœ˜—K˜š  œœœœ˜2Kš˜Kšœœœœ˜0K˜Kšœœœ#˜AKšœ8œ˜>Kšœ˜—K˜š œœœ%˜9Kš œœœœœ˜TKš œœœœœ˜OK˜—K˜š œœœ œœ œ œœ œœœœœ˜~Kš˜šœ œ˜Kš˜Kšœœ ˜(Kšœœœœ˜OKš˜—šœœœ˜šœ˜šœœœ˜&Kšœœœœ˜AKšœ˜—Kšœœ ˜(Kšœœœœ˜OKšœ˜—šœ ˜Kšœœ˜ š œœœœœ˜4Kšœœœ ˜K˜ Kšœ˜—Kšœœ ˜(Kšœœœœ ˜GKšœ˜—Kšœœ˜—Kšœ˜—K˜š   œœœ œœ˜VKš˜KšœΟc˜Kšœ˜—K˜š œœœ ˜Kš˜K˜šœ˜Kš˜šœœ˜Kš œœœœœœœ˜jKšœ'˜.—Kš˜—Kšœ8˜Kšœ=œœœ˜q—Kšœœ˜)šœœ˜K˜Kš œ[œœœœ˜Ÿ—Kšœ œœœ˜Kšœ œ+œœ˜bKšœœ˜šœ!˜'Kš˜šœ˜Kšœ1˜1Kšœ˜Kšœ@˜BKšœ9˜;—Kšœ˜—Kšœ˜—Kšœ-˜-Kšœœ˜šœ4œœ˜IKšœœ˜Kšœ˜—šœœ˜šœœœœ˜9K˜Kšœ"œ˜7Kšœ˜—šœ ˜Kšœœœ˜š œœœœ œ˜9K˜Kšœœ˜+K˜Kšœ˜—Kš œœ‘œœ1œ˜eKšœ˜—Kšœœ˜—Kšœ ˜ šœ4œœ˜IK˜šœœ˜Kš‘X˜XKš‘œ*œ&˜[—Kšœ˜—Kšœ˜—K˜š œœ œ™)Kš™KšœUœ™[KšœIœ™Pš œœ™#K™K™K™K™K™—K™4Kšœ™Kšœœ™"Kšœ™—K˜š œœ˜1Kš˜K˜Kšœœ˜˜#Kšœ.˜.Kšœ˜ K˜—Kšœ˜—K˜š œœ œ™1Kš™Kšœœ™&Kšœœœ5™CKšœœœ™ K™Kšœ œ™Kšœ œœEœœœœ™K™Kš œ œ œ œœœœ ™]KšœSœ™[K™K™Kšœ™—K˜š œœœœœ œœœ œœ˜Kš˜Kšœ œ ˜Kšœ œœœ˜TKš œœœœ'œ˜eK˜9K˜ K˜Kšœ˜—K˜š œœœœœ œœ˜tKš˜Kšœ œ ˜Kšœ œœœ˜TKš œœœœ'œ˜eK˜9K˜"Kšœ˜—K˜Kš   œœœœœ˜QK˜š œœ˜#Kš˜Kšœœœœ˜!Kšœœœœ˜!Kšœœ œœœ œ œ˜FKšœ˜—K˜š   œœœœœœ˜0Kšœœ˜Kšœœœ˜KšœP˜Q—K˜Kšœœ œœN˜oK˜š  œœ˜.Kš˜Kšœœœ˜Kšœœœœ˜)šœœ˜Kš˜Kš œ œœœœœ˜WK˜šœœ˜Kšœ ˜ Kšœ˜Kšœ˜Kšœ˜—Kšœ˜—Kšœ˜—K˜š  œœœœœœ˜VKš˜Kšœ œœ˜K˜Kšœ4˜4šœ˜Kšœœ˜5Kšœœ œœœœœ˜`—Kšœ˜Kšœœ"œ œ ˜pKšœ ˜Kšœœœ#œœœ$œ œ ˜ΓKš œœœ'œ œ!˜‘Kšœ ˜Kšœ˜šœœ ˜šœœ˜ Kšœ œœ œ˜9Kšœœœ œ˜P—Kšœ˜—Kšœ˜Kšœ ˜Kšœœ!œ œ˜nKšœœ œ œ˜lKšœ ˜Kšœ˜šœœœ#˜KKšœ!˜%Kšœœ œœœœœ˜g—Kšœ ˜šœœœ#˜KKšœ*œ ˜œ ˜MKšœ˜K˜K˜—Kšœœ>œ˜kšœ˜Kš˜Kšœ˜KšœEœ ˜TK˜Kšœ˜—Kšœ˜K˜Kšœ œœœ˜=Kšœœ˜Kšœ˜K˜Kšœ˜Kšœ)˜+K˜Kšœ˜Kšœ˜—K˜š œœœ œœœ œœœ˜wKš˜Kšœ œ ˜Kšœœ2˜IKš œœœ=œœœ˜mKšœœ%œ˜Kšœ˜šœ˜Kš˜Kšœ$˜$Kšœœ˜ Kšœ˜ Kšœ˜—šœ œ˜Kš˜Kš œœœœœ˜Kšœ œ˜Kšœ&˜-Kšœ*œ˜0šœ˜KšœO˜OKšœ ˜Kšœ˜Kšœœ˜—Kšœœ˜ Kšœ˜ Kšœ˜——Kšœ˜—K˜š œœ˜ Kš˜K˜K˜iK˜Kšœ˜—K˜K˜K˜Kšœ˜—…—[(}