-- CTCompImpl.Mesa, last edit May 13, 1983 3:14 pm DIRECTORY BcdDefs: TYPE USING [Base, FTIndex, MTIndex, NameRecord], BcdOps: TYPE USING [BcdBase, FTHandle, MTHandle, NameString, ProcessFiles], CompilerOps: TYPE USING [AppendHerald, DefaultSwitches, DoTransaction, LetterSwitches, Start, Stop, StreamId, Transaction], ConvertUnsafe: TYPE USING[ToRope], CS: TYPE USING [Confirm, EndsIn, EquivalentRope, MakeTS, NewFile, NewStream, ReadWrite, SetPFCodes, Write], CT: TYPE USING[BcdTab, BcdTabRecord, Global, MI, ModuleList], CTLoad: TYPE USING[ReplaceResult], Directory: TYPE USING [DeleteFile, Error, ignore, Lookup, Rename, UpdateDates], File: TYPE USING[Capability, nullCapability, read], FileParms: TYPE USING [ActualId, BindingProc, Name, nullActual, nullSymbolSpace, SymbolSpace], FileStream: TYPE USING[Create, GetLeaderPropertiesForCapability], Heap: TYPE USING[systemZone], IO: TYPE USING[card, Close, CreateProcsStream, CreateRefStreamProcs, Handle, PutChar, PutF, PutFR, STREAM, string, rope, UserAbort, UserAborted], List: TYPE USING[DRemove], LongString: TYPE USING [SubString, SubStringDescriptor], Rope: TYPE USING[Cat, Flatten, FromChar, IsEmpty, Length, ROPE, Text], RopeInline: TYPE USING[InlineFlatten], RTOS: TYPE USING[CheckForModuleReplacement], Space: TYPE USING [Create, CreateUniformSwapUnits, Delete, Handle, LongPointer, -- MakeReadOnly, -- Map, Unmap, virtualMemory], Stream: TYPE USING[Handle, Delete, PutChar], Time: TYPE USING[Current], TimeStamp: TYPE USING [Null, Stamp], ViewerClasses: TYPE USING [Viewer], ViewerOps: TYPE USING [CreateViewer, FindViewer, OpenIcon, RestoreViewer], WindowManager: TYPE USING[WaitCursor, UnWaitCursor]; CTCompImpl: CEDAR MONITOR IMPORTS BcdOps, CompilerOps, ConvertUnsafe, CS, Directory, FileStream, Heap, IO, List, Rope, RopeInline, RTOS, Space, Stream, Time, ViewerOps, WindowManager EXPORTS CT = { -- MDS usage -- all these variables are protected by the monitor compilerIsLocked: BOOL _ FALSE; compilerWait: CONDITION; logsh: IO.Handle _ NIL; -- out stream to Compiler.Log logpilotsh: Stream.Handle; g: CT.Global; sourcesh: Stream.Handle; -- in stream to source file good, warn, err: CARDINAL _ 0; compilerStarted: BOOL _ FALSE; timeCompilerStarted: LONG CARDINAL _ 0; onePageSpace: Space.Handle; -- this is used for getting version stamps manyPageSpace: Space.Handle; -- used to map in the entire Bcd manyPageSize: CARDINAL; -- number of pages in manyPageSpace -- endof MDS DetermineCompilation: PUBLIC SAFE PROC[gToUse: CT.Global, modRepl: BOOL] RETURNS[errors: BOOL] = TRUSTED { ENABLE UNWIND => ReleaseCompilerLock[]; time: LONG CARDINAL; gToUse.ttyout.PutF["Compilation Phase.\n"]; AcquireCompilerLock[gToUse]; g _ gToUse; time _ Time.Current[]; -- g.msgout.PutF["\n\n"]; errors _ CompileIfNecessary[g, modRepl ! UNWIND => [] _ StopBatchCompile[]]; g.ttyout.PutF["Elapsed time for compile: %r\n", IO.card[Time.Current[] - time]]; g.ttyout.PutF["--------------------------------\n"]; ReleaseCompilerLock[]; }; CompileIfNecessary: PROC[g: CT.Global, modRepl: BOOL] RETURNS[errors: BOOL] = TRUSTED { numberSuccessful, numberOfWarnings, numberOfErrors: CARDINAL; onePageSpace _ Space.Create[size: 1, parent: Space.virtualMemory]; manyPageSize _ 20; manyPageSpace _ Space.Create[size: manyPageSize, parent: Space.virtualMemory]; Space.CreateUniformSwapUnits[parent: manyPageSpace, size: 8]; -- Space.MakeReadOnly[manyPageSpace]; FOR l: CT.ModuleList _ g.moduleList, l.rest UNTIL l = NIL DO IF l.first.srcFileName = NIL THEN LOOP; IF g.ttyout.UserAbort[] THEN ERROR ABORTED; IF modRepl AND NOT l.first.possiblyBad AND l.first.bcdValid THEN g.ttyout.PutF["Skipping %s.\n", IO.rope[l.first.srcFileName]] ELSE IF l.first.dependencyBad THEN g.ttyout.PutF["Skipping %s, something failed before it.\n", IO.rope[l.first.srcFileName]] ELSE IF BcdNoGood[l.first] THEN { g.ttyout.PutF["%s needs to be recompiled.\n", IO.rope[l.first.srcFileName]]; ArrangeForCompile[l.first ! UNWIND => [] _ StopBatchCompile[]]; IF l.first.bcdValid THEN SetPossiblyBadAndValid[l.first]; RemoveBcdTabFile[l.first.bcdFileName]; } ELSE { l.first.possiblyBad _ FALSE; g.ttyout.PutF["%s does not need to be recompiled.\n", IO.rope[l.first.srcFileName]]; }; ENDLOOP; [numberSuccessful, numberOfWarnings, numberOfErrors] _ StopBatchCompile[]; IF numberSuccessful = 0 AND numberOfErrors = 0 AND numberOfWarnings = 0 THEN g.ttyout.PutF["Nothing was compiled.\n"] ELSE { g.ttyout.PutF["%d successful; ", IO.card[numberSuccessful]]; IF numberOfErrors > 0 THEN g.ttyout.PutF["%d w/errors; ", IO.card[numberOfErrors]]; IF numberOfWarnings > 0 THEN g.ttyout.PutF["%d w/warnings; ", IO.card[numberOfWarnings]]; g.ttyout.PutF["\n"]; }; Space.Delete[onePageSpace]; Space.Delete[manyPageSpace]; errors _ numberOfErrors > 0; }; BcdNoGood: PROC[mi: CT.MI] RETURNS[badBcd: BOOL] = TRUSTED { namestring: BcdOps.NameString; innerBcdBase: BcdOps.BcdBase; ForEachDirectory: PROC[fth: BcdOps.FTHandle, fti: BcdDefs.FTIndex] RETURNS[stop: BOOL _ FALSE] = TRUSTED { bcdTab: CT.BcdTab; innerCap: File.Capability; name: Rope.Text _ NameToRope[fth.name, namestring]; stop _ FALSE; name _ AppendExtension[name, ".bcd"L]; AddDependsInfo[mi, name]; bcdTab _ LookupBcdTabFile[name]; IF bcdTab ~= NIL THEN { IF bcdTab.bcdVers ~= fth.version THEN badBcd _ TRUE; g.dout.PutF["Hit on %s\n", IO.rope[name]]; RETURN; }; -- must look on disk innerCap _ Directory.Lookup[fileName: LOOPHOLE[name], permissions: Directory.ignore ! Directory.Error => GOTO fileNotFound]; Space.Map[space: onePageSpace, window: [file: innerCap, base: 1]]; AddToBcdTabFile[name, innerCap, innerBcdBase.version]; IF innerBcdBase.version ~= fth.version THEN { badBcd _ TRUE; Space.Unmap[onePageSpace]; RETURN[TRUE]; }; Space.Unmap[onePageSpace]; EXITS fileNotFound => NULL; -- can't tell if needs to be recompiled }; { bcdBase: BcdOps.BcdBase; npages: CARDINAL; mth: BcdOps.MTHandle; badBcd _ FALSE; mi.srcCap _ Directory.Lookup[fileName: LOOPHOLE[mi.srcFileName], permissions: Directory.ignore ! Directory.Error => GOTO srcNotFound]; [create: mi.srcCreate] _ FileStream.GetLeaderPropertiesForCapability[mi.srcCap]; mi.bcdCap _ Directory.Lookup[fileName: LOOPHOLE[mi.bcdFileName], permissions: Directory.ignore ! Directory.Error => GOTO bad]; Space.Map[space: onePageSpace, window: [file: mi.bcdCap, base: 1]]; bcdBase _ Space.LongPointer[onePageSpace]; IF bcdBase.sourceVersion.time ~= mi.srcCreate THEN badBcd _ TRUE; npages _ bcdBase.nPages; Space.Unmap[onePageSpace]; -- now map in the right number of pages IF npages > manyPageSize THEN { Space.Delete[manyPageSpace]; manyPageSize _ npages + 10; manyPageSpace _ Space.Create[size: manyPageSize, parent: Space.virtualMemory]; Space.CreateUniformSwapUnits[parent: manyPageSpace, size: 8]; -- Space.MakeReadOnly[manyPageSpace]; }; Space.Map[space: manyPageSpace, window: [file: mi.bcdCap, base: 1]]; bcdBase _ Space.LongPointer[manyPageSpace]; mth _ @(LOOPHOLE[bcdBase, BcdDefs.Base] + bcdBase.mtOffset)[FIRST[BcdDefs.MTIndex]]; IF NOT bcdBase.definitions AND (mi.switches['b] ~= mth.boundsChecks -- there are some omissions here OR mi.switches['c] ~= mth.long -- encoded in the old l OR mi.switches['j] ~= mth.crossJumped OR mi.switches['l] ~= (mth.linkLoc = code) -- new interp. of /l OR mi.switches['n] ~= mth.nilChecks OR ((mi.switches['s] = mth.initial) AND mi.explicitSortSwitch)) THEN badBcd _ TRUE; -- remember /s switch, initial = FALSE is /s, initial = TRUE is /-s -- if not explicitSortSwitch then set switches to whatever old bcd had IF NOT mi.explicitSortSwitch THEN mi.switches['s] _ NOT mth.initial; IF badBcd THEN { Space.Unmap[manyPageSpace]; GOTO bad; -- down here to make sure /s switch is known }; namestring _ LOOPHOLE[bcdBase + bcdBase.ssOffset]; innerBcdBase _ Space.LongPointer[onePageSpace]; [] _ BcdOps.ProcessFiles[bcdBase, ForEachDirectory]; IF NOT badBcd THEN { AddToBcdTabFile[mi.bcdFileName, mi.bcdCap, bcdBase.version]; mi.bcdVers _ bcdBase.version; mi.definitions _ bcdBase.definitions; }; Space.Unmap[manyPageSpace]; EXITS bad => badBcd _ TRUE; srcNotFound => g.ttyout.PutF["Cannot open %s.\n", IO.rope[mi.srcFileName]]; -- what to do? }}; ArrangeForCompile: PROC[mi: CT.MI] = TRUSTED { errors, warnings, replaceable, declined: BOOL; IF mi.loadInfoSeq ~= NIL AND mi.loadInfoSeq.size = 1 THEN { -- try for replacement oldBcdFileName: Rope.Text; replaceResult: CTLoad.ReplaceResult; oldBcdFileName _ GenUniqueBcdName[mi.bcdFileName]; SELECT TRUE FROM CS.EquivalentRope[oldBcdFileName, mi.bcdFileName] => replaceResult _ cantCopyOldBcd; NOT RTOS.CheckForModuleReplacement[mi.loadInfoSeq[0].frame] => replaceResult _ checkForMRFailed; ENDCASE => replaceResult _ ok; IF replaceResult ~= ok THEN { g.ttyout.PutF["%s cannot be replaced because %s.\n", IO.rope[mi.bcdFileName], IO.rope[SELECT replaceResult FROM cantCopyOldBcd => "can't copy old bcd", checkForMRFailed => "RT check for module replacement failed", ENDCASE => ERROR]]; declined _ TRUE; GOTO skip; }; Directory.Rename[newName: LOOPHOLE[oldBcdFileName], oldName: LOOPHOLE[mi.bcdFileName]]; RemoveBcdTabFile[mi.bcdFileName]; mi.bcdCap _ File.nullCapability; g.ttyout.PutF["Old version of %s renamed to %s.\n", IO.rope[mi.bcdFileName], IO.rope[oldBcdFileName]]; [errors, warnings, replaceable, declined] _ CompileIt[mi, TRUE, oldBcdFileName]; IF NOT replaceable THEN replaceResult _ compilerSaysNo; IF replaceable AND NOT errors AND NOT declined THEN { g.ttyout.PutF["%s passes compiler's test for replaceability.\n", IO.rope[mi.bcdFileName]]; mi.loadInfoSeq.mustreplace _ TRUE; } ELSE { mi.loadInfoSeq.mustreplace _ FALSE; IF declined OR errors THEN { -- new version has to be deleted Directory.Rename[newName: LOOPHOLE[mi.bcdFileName], oldName: LOOPHOLE[oldBcdFileName]]; g.ttyout.PutF["Old, loaded version of %s has been left on disk.\n", IO.rope[mi.bcdFileName]]; } ELSE g.ttyout.PutF["%s is not replaceable%s, new version has been left on disk, \n\told loaded version is called %s.\n", IO.rope[mi.bcdFileName], IO.rope[IF replaceResult = compilerSaysNo THEN " (Compiler refuses)" ELSE ""], IO.rope[oldBcdFileName]]; }; EXITS skip => NULL; } ELSE { [errors, warnings, , declined] _ CompileIt[mi, FALSE, NIL]; }; mi.bcdValid _ NOT errors; }; CompileIt: PROC[mi: CT.MI, tryreplacement: BOOL, oldBcdFileName: Rope.Text] RETURNS[errors, warnings, replaceable, declined: BOOL] = TRUSTED { inx: CARDINAL _ 1; t: CompilerOps.Transaction; cap: File.Capability; onestarttime: LONG CARDINAL; DirectoryBinding: PROC[formalId, formalType: FileParms.Name, defaultLocator: LONG STRING, binder: FileParms.BindingProc] = TRUSTED { idname: Rope.Text _ SubStringToRope[@formalId]; ref: REF ReturnRecord; ref _ GetActualIdForFile[idname, ConvertUnsafe.ToRope[defaultLocator]]; AddDependsInfo[mi, ref.bcdFileName]; IF ref.found THEN { actual: FileParms.ActualId _ [version: ref.version, locator: [base: LOOPHOLE[ref.bcdFileName], offset: 0, length: ref.bcdFileName.Length[]]]; binder[actual]; g.dout.PutF["match %g with %g of %v\n", IO.rope[idname], IO.rope[ref.bcdFileName], CS.MakeTS[ref.version]]; } ELSE g.ttyout.PutF["Error - %s not found.\n", IO.rope[ref.bcdFileName]]; }; -- called after DirectoryBinding, except for hidden directory entries DirectoryAcquire: PROC[type: LongString.SubStringDescriptor, actual: FileParms.ActualId] RETURNS[symbolSpace: FileParms.SymbolSpace] = TRUSTED { ref: REF ReturnRecord; ref _ GetActualIdForFile[SubStringToRope[@type], SubStringToRope[@actual.locator]]; IF ref.found THEN RETURN[ref.symbolSpace]; g.ttyout.PutF["%s of %v not found.\n", IO.rope[ref.bcdFileName], CS.MakeTS[actual.version]]; RETURN[FileParms.nullSymbolSpace]; }; DeleteBadBcd: PROC = TRUSTED { IF t.objectName ~= NIL THEN Directory.DeleteFile[t.objectName]; t.objectName _ NIL; RemoveBcdTabFile[mi.bcdFileName]; }; Cleanup: PROC = TRUSTED { IF t.sourceStream ~= NIL THEN Stream.Delete[t.sourceStream]; t.sourceStream _ NIL; sourcesh _ NIL; }; { ENABLE UNWIND => { DeleteBadBcd[]; Cleanup[]; }; errors _ warnings _ declined _ TRUE; replaceable _ FALSE; t.sourceStream _ NIL; t.objectName _ NIL; IF AskTheUser[mi.srcFileName, mi.switches] THEN RETURN; declined _ FALSE; -- make sure the compiler is loaded, etc. IF NOT compilerStarted THEN StartBatchCompile[]; -- set up Transaction record contents t.op _ IF tryreplacement THEN replace ELSE compile; t.source _ [version: [net: 0, host: 0, time: mi.srcCreate], locator: [base: LOOPHOLE[mi.srcFileName], offset: 0, length: mi.srcFileName.Length[]]]; cap _ Directory.UpdateDates[mi.srcCap, File.read]; sourcesh _ t.sourceStream _ FileStream.Create[cap]; t.fileParms _ [DirectoryBinding, DirectoryAcquire, DirectoryRelease, DirectoryForget]; t.switches _ mi.switches; t.switches['s] _ mi.explicitSortSwitch; IF tryreplacement THEN { IF mi.bcdVers = TimeStamp.Null THEN ERROR; t.pattern _ [version: mi.bcdVers, locator: [base: LOOPHOLE[oldBcdFileName], offset: 0, length: oldBcdFileName.Length[]]]; -- if this is replacement, try to set sorting the same as the old bcd IF NOT mi.explicitSortSwitch THEN t.switches['s] _ mi.switches['s] } ELSE t.pattern _ FileParms.nullActual; t.objectName _ LOOPHOLE[mi.bcdFileName]; mi.bcdCap _ t.objectFile _ CS.NewFile[mi.bcdFileName, CS.ReadWrite, 10]; t.debugPass _ LAST[CARDINAL]; t.getStream _ LogGetStream; t.startPass _ CompilerPass; PrintStartOne[@t]; onestarttime _ Time.Current[]; -- these are here to hide them from the user t.switches['d] _ TRUE; -- debugging t.switches['g] _ FALSE; -- log is always Compiler.Log -- actually call the Compiler! CompilerOps.DoTransaction[@t]; PrintStopOne[@t, onestarttime]; replaceable _ tryreplacement AND t.matched; errors _ t.nErrors # 0; warnings _ t.nWarnings # 0; IF errors THEN err _ err + 1; IF warnings THEN warn _ warn + 1; IF NOT errors AND NOT warnings THEN good _ good + 1; IF NOT errors THEN { mi.bcdVers _ t.objectVersion; mi.definitions _ (t.objectBytes = 0); -- kludge to tell if it is a Defs file } ELSE DeleteBadBcd[]; Cleanup[]; }}; -- local procedures AddDependsInfo: PROC[mi: CT.MI, bcdName: Rope.Text] = { FOR l: CT.ModuleList _ g.moduleList, l.rest UNTIL l = NIL DO IF CS.EquivalentRope[l.first.bcdFileName, bcdName] THEN { -- add to l.first the information that mi depends on it l.first.dependedBy _ CONS[mi.bcdFileName, l.first.dependedBy]; -- always set to TRUE, reset in SetPossiblyBadAndValid l.first.dependencyBad _ TRUE; RETURN; }; ENDLOOP; -- may not be able to add because this is a defs file not in the system -- e.g. Rope.bcd, IO.Bcd }; SetPossiblyBadAndValid: PUBLIC SAFE PROC[mi: CT.MI] = CHECKED { found: BOOL; FOR l: LIST OF Rope.Text _ mi.dependedBy, l.rest UNTIL l = NIL DO found _ FALSE; FOR ml: CT.ModuleList _ g.moduleList, ml.rest UNTIL ml = NIL DO IF CS.EquivalentRope[l.first, ml.first.bcdFileName] THEN { ml.first.possiblyBad _ TRUE; ml.first.dependencyBad _ FALSE; found _ TRUE; EXIT; }; ENDLOOP; IF NOT found THEN g.ttyout.PutF["Error - SetPossiblyBad: Can't find entry for %s.\n", IO.rope[l.first]]; ENDLOOP; }; FlushOldBcd: PROC[mi: CT.MI] = { RemoveBcdTabFile[mi.bcdFileName]; mi.bcdCap _ File.nullCapability; mi.bcdVers _ TimeStamp.Null; mi.bcdValid _ FALSE; }; StartBatchCompile: PROC = TRUSTED { herald: STRING _ [100]; good _ warn _ err _ 0; logsh _ NIL; timeCompilerStarted _ Time.Current[]; Directory.DeleteFile["Compiler.Log"L ! Directory.Error => CONTINUE]; [] _ LogGetStream[log]; -- creates new log CompilerOps.AppendHerald[herald]; g.ttyout.PutF["%s\n%t\n", IO.string[herald], IO.card[timeCompilerStarted]]; logsh.PutF["%s\n%t\n", IO.string[herald], IO.card[timeCompilerStarted]]; CompilerOps.Start[Heap.systemZone]; compilerStarted _ TRUE; }; StopBatchCompile: PROC RETURNS[nOk, nWarn, nErr: CARDINAL] = TRUSTED { log: ViewerClasses.Viewer; IF NOT compilerStarted THEN RETURN[0, 0, 0]; -- noop call; compiler not running IF good # 0 THEN logsh.PutF[" %d successful; ", IO.card[good]]; IF warn # 0 THEN logsh.PutF[" %d w/warnings; ", IO.card[warn]]; IF err # 0 THEN logsh.PutF[" %d w/errors; ", IO.card[err]]; timeCompilerStarted _ Time.Current[] - timeCompilerStarted; logsh.PutF["\nTotal elapsed time: %y\n", IO.card[timeCompilerStarted]]; Stream.Delete[logpilotsh]; logsh _ NIL; CompilerOps.Stop[]; compilerStarted _ FALSE; log _ ViewerOps.FindViewer["Compiler.Log"]; IF log ~= NIL THEN ViewerOps.RestoreViewer[log]; IF warn > 0 OR err > 0 THEN { IF log ~= NIL THEN ViewerOps.OpenIcon[log] ELSE { g.msgout.PutChar['\n]; CreateANewViewer["Compiler.log", g.ttyout]; }; }; g.ttyout.PutF["End of compilation\n"]; RETURN[good, warn, err]; }; DirectoryRelease: PROC[ss: FileParms.SymbolSpace] = {}; DirectoryForget: PROC[actual: FileParms.ActualId] = {}; PrintStartOne: PROC[t: POINTER TO CompilerOps.Transaction] = TRUSTED { first: BOOL _ TRUE; standardSwitches: CompilerOps.LetterSwitches _ CompilerOps.DefaultSwitches[]; g.msgout.PutF["Compiling: %s", IO.string[t.source.locator.base]]; logsh.PutF["\nCommand: %s", IO.string[t.source.locator.base]]; FOR c: CHAR IN ['a .. 'z] DO sd: BOOL _ IF c = 'p THEN FALSE ELSE standardSwitches[c]; IF t.switches[c] ~= sd THEN { IF first THEN { first _ FALSE; g.msgout.PutChar['/]; logsh.PutChar['/]; }; IF sd THEN { g.msgout.PutChar['-]; logsh.PutChar['-]; }; g.msgout.PutChar[c]; logsh.PutChar[c]; }; ENDLOOP; logsh.PutChar['\n]; }; PrintStopOne: PROC[t: POINTER TO CompilerOps.Transaction, oneStartTime: LONG CARDINAL] = TRUSTED { -- first MsgSW IF t.nErrors > 0 THEN g.msgout.PutF["%d errors", IO.card[t.nErrors]] ELSE g.msgout.PutF["no errors"]; IF t.nWarnings > 0 THEN g.msgout.PutF[", %d warnings", IO.card[t.nWarnings]]; g.msgout.PutChar['\n]; -- now log logsh.PutF["%s -- ", IO.string[t.source.locator.base]]; IF t.nErrors > 0 THEN { logsh.PutF[" aborted, %d errors", IO.card[t.nErrors]]; IF t.nWarnings > 0 THEN logsh.PutF[" and %d warnings", IO.card[t.nWarnings]]; oneStartTime _ Time.Current[] - oneStartTime; logsh.PutF[", time: %y.\n\n", IO.card[oneStartTime]]; } ELSE { oneStartTime _ Time.Current[] - oneStartTime; logsh.PutF["source tokens: %d, time: %y", IO.card[t.sourceTokens], IO.card[oneStartTime]]; IF t.objectBytes > 0 THEN logsh.PutF["\n code bytes: %d, links: %d, global frame words: %d", IO.card[t.objectBytes], IO.card[t.linkCount], IO.card[t.objectFrameSize]]; IF t.nWarnings > 0 THEN logsh.PutF["\n%d warnings", IO.card[t.nWarnings]]; logsh.PutF["\n\n"]; }; }; CreateANewViewer: PROC [name: Rope.Text, out: IO.Handle] = { viewer: ViewerClasses.Viewer; WindowManager.WaitCursor[]; viewer _ ViewerOps.CreateViewer[flavor: $Text, info: [name: name, file: name, iconic: FALSE, column: left]]; out.PutF["Created Viewer: %s\n", IO.rope[name]]; -- ViewerOps.SetNewFile[viewer]; WindowManager.UnWaitCursor[]; }; AskTheUser: PROC[filename: Rope.Text, wantsw: CompilerOps.LetterSwitches] RETURNS[declined: BOOL] = { ch: CHAR; dif: Rope.ROPE; declined _ TRUE; -- ask the user if he really wants it compiled g.ttyout.PutF["Compile %s", IO.rope[filename]]; dif _ ProduceDifferentialSwitches[wantsw]; IF NOT Rope.IsEmpty[dif] THEN g.ttyout.PutF["/%s", IO.rope[dif]]; g.ttyout.PutF[" ... "]; ch _ IF NOT g.confirmCompiles THEN 'y ELSE 'n; IF ch = 'n THEN ch _ CS.Confirm['y, g.ttyin, g.ttyout] ; IF ch = 'q THEN { g.ttyout.PutF["Quit.\n"]; ERROR IO.UserAborted[]; }; IF ch = 'a THEN { declined _ FALSE; g.confirmCompiles _ FALSE; g.ttyout.PutF["All Yes.\n"]; } ELSE IF ch = 'y THEN { declined _ FALSE; g.ttyout.PutF["Yes.\n"]; } ELSE g.ttyout.PutF["No.\n"]; }; ProduceDifferentialSwitches: PROC[sw: CompilerOps.LetterSwitches] RETURNS[dif: Rope.ROPE] = TRUSTED { standardSwitches: CompilerOps.LetterSwitches _ CompilerOps.DefaultSwitches[]; FOR c: CHAR IN ['a .. 'z] DO sd: BOOL _ IF c = 'p THEN FALSE ELSE standardSwitches[c]; IF sw[c] ~= sd THEN { IF sd THEN dif _ Rope.Cat[dif, Rope.FromChar['-]]; dif _ Rope.Cat[dif, Rope.FromChar[c]]; }; ENDLOOP; }; LogGetStream: PROC[sid: CompilerOps.StreamId] RETURNS[sh: Stream.Handle] = { IF sid = source THEN RETURN[sourcesh]; -- temporary IF sid ~= log THEN ERROR; IF logsh = NIL THEN TRUSTED { logpilotsh _ CS.NewStream["Compiler.Log", CS.Write]; logsh _ IO.CreateProcsStream[IO.CreateRefStreamProcs[putChar: LogStreamPutChar], NIL]; CS.SetPFCodes[logsh]; }; sh _ logpilotsh; }; LogStreamPutChar: SAFE PROC[self: IO.STREAM, char: CHAR] = TRUSTED { Stream.PutChar[logpilotsh, char]; }; CompilerPass: PROC[p: CARDINAL] RETURNS[goOn: BOOL] = { goOn _ NOT g.ttyin.UserAbort[]; g.msgout.PutF[". "]; }; NameToRope: PROC[name: BcdDefs.NameRecord, namestring: BcdOps.NameString] RETURNS[rope: Rope.Text] = TRUSTED { r: Rope.ROPE _ NIL; FOR i: CARDINAL IN [0 .. namestring.size[name]) DO r _ r.Cat[Rope.FromChar[namestring.string.text[name + i]]]; ENDLOOP; rope _ Rope.Flatten[r]; }; AcquireCompilerLock: ENTRY PROC[g: CT.Global] = { ENABLE UNWIND => NULL; p: BOOL _ TRUE; WHILE compilerIsLocked DO IF p THEN { g.ttyout.PutF["Waiting for free Compiler ... "]; p _ FALSE; }; WAIT compilerWait; ENDLOOP; compilerIsLocked _ TRUE; IF NOT p THEN g.ttyout.PutF["ok\n"]; }; ReleaseCompilerLock: ENTRY PROC = { ENABLE UNWIND => NULL; compilerIsLocked _ FALSE; NOTIFY compilerWait; }; GenUniqueBcdName: PUBLIC SAFE PROC[bcdFileName: Rope.Text] RETURNS[newName: Rope.Text] = TRUSTED { inx: CARDINAL _ 1; newName _ bcdFileName; DO newName _ RopeInline.InlineFlatten[ IO.PutFR["%s.%d.Bcd$", IO.rope[bcdFileName], IO.card[inx]]]; [] _ Directory.Lookup[fileName: LOOPHOLE[newName], permissions: Directory.ignore ! Directory.Error => GOTO out]; inx _ inx + 1; ENDLOOP; EXITS out => NULL; }; AddToBcdTabFile: PROC[bcdFileName: Rope.Text, cap: File.Capability, version: TimeStamp.Stamp] = { g.bcdTabList _ CONS[NEW[CT.BcdTabRecord _ [bcdFileName: bcdFileName, bcdCap: cap, bcdVers: version]], g.bcdTabList]; }; -- there may already be an entry for bcdFileName w/o a symbolSpace AddToBcdTabSymbolSpace: PROC[bcdFileName: Rope.Text, cap: File.Capability, version: TimeStamp.Stamp, symbolSpace: FileParms.SymbolSpace] = { g.bcdTabList _ CONS[NEW[CT.BcdTabRecord _ [bcdFileName: bcdFileName, bcdCap: cap, bcdVers: version, symbolSpace: symbolSpace]], g.bcdTabList]; }; LookupBcdTabFile: PROC[bcdFileName: Rope.Text] RETURNS [bcdTab: CT.BcdTab] = { FOR l: LIST OF CT.BcdTab _ g.bcdTabList, l.rest UNTIL l = NIL DO IF CS.EquivalentRope[l.first.bcdFileName, bcdFileName] THEN RETURN[l.first]; ENDLOOP; RETURN[NIL]; }; RemoveBcdTabFile: PROC[bcdFileName: Rope.Text] = TRUSTED { bcdTab: CT.BcdTab; WHILE (bcdTab _ LookupBcdTabFile[bcdFileName]) ~= NIL DO g.bcdTabList _ LOOPHOLE[List.DRemove[bcdTab, LOOPHOLE[g.bcdTabList]]]; ENDLOOP; }; SubStringToRope: PROC[lp: LongString.SubString] RETURNS[rope: Rope.Text] = TRUSTED { r: Rope.ROPE _ NIL; FOR i: CARDINAL IN [0 .. lp.length) DO r _ r.Cat[Rope.FromChar[lp.base[lp.offset+i]]]; ENDLOOP; rope _ Rope.Flatten[r]; }; AppendExtension: PUBLIC SAFE PROC[name: Rope.ROPE, ext: LONG STRING] RETURNS[r: Rope.Text] = TRUSTED { r _ RopeInline.InlineFlatten[name]; RETURN[ IF NOT CS.EndsIn[r, ext] THEN RopeInline.InlineFlatten[Rope.Cat[name, ConvertUnsafe.ToRope[ext]]] ELSE r]; }; -- to avoid long-ref containing unsafe warning message from compiler ReturnRecord: TYPE = RECORD[ found: BOOL _ FALSE, version: TimeStamp.Stamp _ TimeStamp.Null, bcdFileName: Rope.Text _ NIL, symbolSpace: FileParms.SymbolSpace _ FileParms.nullSymbolSpace ]; GetActualIdForFile: PROC[typename: Rope.Text, fileNameHint: Rope.Text] RETURNS[ref: REF ReturnRecord] = TRUSTED { bcdBase: BcdOps.BcdBase; sgb: BcdDefs.Base; firstMth: BcdOps.MTHandle; cap: File.Capability; namestring: BcdOps.NameString; bcdTab: CT.BcdTab; ref _ NEW[ReturnRecord _ []]; ref.bcdFileName _ fileNameHint; IF ref.bcdFileName.Length[] = 0 THEN ref.bcdFileName _ typename; IF NOT CS.EndsIn[ref.bcdFileName, "$"L] THEN ref.bcdFileName _ AppendExtension[ref.bcdFileName, ".Bcd"L]; bcdTab _ LookupBcdTabFile[ref.bcdFileName]; IF bcdTab ~= NIL AND bcdTab.symbolSpace ~= FileParms.nullSymbolSpace THEN { g.dout.PutF["Hit on %s\n", IO.rope[ref.bcdFileName]]; ref^ _ [TRUE, bcdTab.bcdVers, ref.bcdFileName, bcdTab.symbolSpace]; RETURN; }; IF bcdTab = NIL THEN cap _ Directory.Lookup[fileName: LOOPHOLE[ref.bcdFileName], permissions: Directory.ignore ! Directory.Error => GOTO notFound] ELSE cap _ bcdTab.bcdCap; bcdBase _ LoadUpBcd[cap]; namestring _ LOOPHOLE[bcdBase + bcdBase.ssOffset]; firstMth _ @(LOOPHOLE[bcdBase,BcdDefs.Base] + bcdBase.mtOffset)[FIRST[BcdDefs.MTIndex]]; sgb _ LOOPHOLE[bcdBase, BcdDefs.Base] + bcdBase.sgOffset; ref.version _ bcdBase.version; ref.found _ TRUE; ref.symbolSpace _ [file: cap, span: [base: sgb[firstMth.sseg].base, pages: sgb[firstMth.sseg].pages]]; AddToBcdTabSymbolSpace[ref.bcdFileName, cap, ref.version, ref.symbolSpace]; Space.Unmap[manyPageSpace]; EXITS notFound => ref.found _ FALSE; }; LoadUpBcd: PROC[cap: File.Capability] RETURNS[bcdBase: BcdOps.BcdBase] = TRUSTED { npages: CARDINAL; IF cap = File.nullCapability THEN ERROR; Space.Map[space: manyPageSpace, window: [file: cap, base: 1]]; bcdBase _ Space.LongPointer[manyPageSpace]; npages _ bcdBase.nPages; IF npages > manyPageSize THEN { Space.Delete[manyPageSpace]; -- now map in the right number of pages manyPageSize _ npages + 10; manyPageSpace _ Space.Create[size: manyPageSize, parent: Space.virtualMemory]; Space.Map[space: manyPageSpace, window: [file: cap, base: 1]]; bcdBase _ Space.LongPointer[manyPageSpace]; Space.CreateUniformSwapUnits[parent: manyPageSpace, size: 8]; -- Space.MakeReadOnly[manyPageSpace]; }; }; }.