DIRECTORY
BasicTime USING [GMT, nullGMT],
DFUtilities
USING
[Date, DateToStream, DifferenceOfUsingLists, DirectoryItem, FileItem, Filter, ImportsItem, IncludeItem, ParseFromStream, ProcessItemProc, RemoveVersionNumber, SortUsingList, SyntaxError, UsingForm, UsingList],
FS USING [Error, FileInfo, GetInfo, GetName, Open, OpenFile, StreamFromOpenFile],
GenerateDFClosure USING [ActionKind, ActionProc, ClosureInfo, Options],
IO USING [Close, PutRope, STREAM],
MessagesOut USING [PutMsg, PutRopes],
Process USING [Detach],
ProcessExtras USING [CheckForAbort],
Rope USING [Concat, Equal, Fetch, Length, ROPE],
SafeStorage USING [ReclaimCollectibleObjects],
SymTab USING [Create, EachPairAction, Fetch, Pairs, Ref, Store];
T Y P E S
ActionKind: TYPE = GenerateDFClosure.ActionKind;
ActionProc: TYPE = GenerateDFClosure.ActionProc;
ClosureInfo: TYPE = GenerateDFClosure.ClosureInfo;
Date: TYPE = DFUtilities.Date;
DirectoryItem: TYPE = DFUtilities.DirectoryItem;
FileItem: TYPE = DFUtilities.FileItem;
FileItemList: TYPE = LIST OF FileItem;
Filter:
TYPE = DFUtilities.Filter;
AllFilter: Filter = [FALSE, all, all, all, NIL];
FutureImportsItem: TYPE = RECORD [imp: REF ImportsItem, from: REF];
ImportsItem: TYPE = DFUtilities.ImportsItem;
IncludeItem: TYPE = DFUtilities.IncludeItem;
LORA: TYPE = LIST OF REF ANY;
Options: TYPE = GenerateDFClosure.Options;
ROPE: TYPE = Rope.ROPE;
RopeList: TYPE = LIST OF ROPE;
STREAM: TYPE = IO.STREAM;
UsingForm: TYPE = DFUtilities.UsingForm;
UsingList: TYPE = DFUtilities.UsingList;
ImportsPair:
TYPE =
RECORD [
from: ROPE, -- the original source of this import
needed: REF ImportsItem, -- the imports not yet done for this DF file
doing: REF ImportsItem -- the imports in progress (or done) for this DF file
];
InclDefList: TYPE = LIST OF InclDefItem;
InclDefItem: TYPE = RECORD[incl: REF, from: REF, filter: Filter];
ImpDefList: TYPE = LIST OF ImpDefItem;
ImpDefItem: TYPE = RECORD[imp: REF ImportsItem, from: REF, filter: Filter];
State: TYPE = REF StateRep;
StateRep:
TYPE =
MONITORED
RECORD [
head,tail: LORA ← NIL, -- head and tail of file list
inclHead,inclTail: InclDefList ← NIL, -- head&tail for deferred include processing
impHead,impTail: ImpDefList ← NIL, -- head&tail for deferred imports processing
errs: STREAM ← NIL, -- error reporting stream (can be NIL)
action: ActionProc ← NIL, -- the client's callback proc
actionData: REF ← NIL, -- the data for the client's callback proc
tab: SymTab.Ref ← NIL, -- table of DF files (ImportsPair & IncludeItem objects)
forked,started,finished: INT ← 0, -- counts associated with forked processes
files: INT ← 0, -- files in the closure (including DF files)
dfFiles: INT ← 0, -- DF files examined
notFound: INT ← 0, -- # of DF files not found
maxProcesses: NAT ← 16, -- # of forked processes besides main process
serverRetries: NAT ← 10, -- # of times to retry when server is unavailable
abortRequested: BOOL ← FALSE, -- TRUE if an abort was requested
messages: BOOL ← FALSE, -- TRUE if debug info goes in message window
ProcessStarted: CONDITION, -- BROADCAST for every forked process start
ProcessFinished: CONDITION -- BROADCAST for every forked process finish
];
Include processing
ProcessInclude:
ENTRY
PROC
[state: State, incl: REF, from: REF, filter: Filter] = TRUSTED {
ENABLE UNWIND => state.abortRequested ← TRUE;
new: InclDefList = LIST[[incl, from, filter]];
CheckAbortInternal[state];
IF state.inclHead =
NIL
THEN state.inclHead ← new
ELSE state.inclTail.rest ← new;
state.inclTail ← new;
IF state.forked-state.finished < state.maxProcesses
THEN {
state.forked ← state.forked + 1;
Process.Detach[FORK ProcessIncludeBase[state]];
WHILE state.forked > state.started
DO
CheckAbortInternal[state];
WAIT state.ProcessStarted;
ENDLOOP;
};
};
ProcessIncludeBase:
PROC [state: State] = {
ENABLE {
UNWIND => Unwind[state];
ABORTED => {Unwind[state]; GO TO abort};
};
Base of forked process to process an included DF file
BumpStarted[state];
DO
list: InclDefList ← RemInclude[state, TRUE];
IF list = NIL THEN RETURN;
DoProcessInclude[state, list.first.incl, list.first.from, list.first.filter];
ENDLOOP;
EXITS abort => {};
};
WaitForIncludesDone:
PROC [state: State] = {
DO
Whether or not there are other processes to help us, the current process can help make progress towards removing some of the queued imports processing.
list: InclDefList = RemInclude[state];
IF list = NIL THEN EXIT;
DoProcessInclude[state, list.first.incl, list.first.from, list.first.filter];
ENDLOOP;
WaitForForkedDoneOrAbort[state];
};
RemInclude:
ENTRY
PROC
[state: State, finish: BOOL ← FALSE] RETURNS [list: InclDefList ← NIL] = {
... removes an entry from the deferred includes list. NIL will be returned if there are no more entries. To avoid races between testing for no entries and insertion of new entries, if finish is TRUE, then the customary finish processing is performed when the returned value is NIL.
ENABLE UNWIND => state.abortRequested ← TRUE;
CheckAbortInternal[state];
list ← state.inclHead;
IF list #
NIL
THEN {
IF (state.inclHead ← list.rest) = NIL THEN state.inclTail ← NIL;
list.rest ← NIL;
RETURN;
};
IF finish THEN BumpFinishedInternal[state];
};
DoProcessInclude:
PROC [state: State, incl:
REF, from:
REF, filter: Filter] = {
... processes an include or imports item under the given filter. For each item found in the given file under the filter, we take the following actions:
DirectoryItem => set current directory (within this invocation of DoProcessInclude)
FileItem => add file to the list
ImportsItem => add the ImportsItem to the list (for more processing)
IncludeItem => recursively process the inclusion
subHead: LORA ← LIST[incl];
subTail: LORA ← subHead;
currentDirectory: REF DirectoryItem ← NIL;
inStream: STREAM ← NIL;
nFiles: INT ← 0;
selfSeen: BOOL ← FALSE;
anySeen: BOOL ← FALSE;
processItem: DFUtilities.ProcessItemProc = {
[item: REF ANY] RETURNS [stop: BOOL ← FALSE]
CheckAbort[state];
WITH item
SELECT
FROM
dir:
REF DirectoryItem => {
currentDirectory ← dir;
};
file:
REF FileItem => {
IF currentDirectory #
NIL
THEN
file.name ← Rope.Concat[currentDirectory.path1, file.name];
IF state.action =
NIL
THEN {
subTail.rest ← LIST[file];
subTail ← subTail.rest;
}
ELSE {
state.action[state.actionData, file, file.name, file.date, fullName];
};
nFiles ← nFiles + 1;
anySeen ← TRUE;
IF Rope.Equal[file.name, fullName,
FALSE]
OR Rope.Equal[file.name, initName,
FALSE]
THEN selfSeen ← TRUE;
};
imp:
REF ImportsItem => {
SELECT
TRUE
FROM
filter.filterB = public AND NOT imp.exported => RETURN;
filter.list # NIL => {imp.form ← list; imp.list ← filter.list};
ENDCASE;
subTail.rest ← LIST[NEW[FutureImportsItem ← [imp: imp, from: incl]]];
subTail ← subTail.rest;
};
inclP:
REF IncludeItem => {
ProcessInclude[state, inclP, incl, filter];
};
ENDCASE;
};
initName, fullName: ROPE ← NIL;
kind: ROPE;
tab: SymTab.Ref ← state.tab;
date: Date;
isIncluded: BOOL ← FALSE;
checkRemote: BOOL ← FALSE;
WITH incl
SELECT
FROM
incl1: REF IncludeItem => {date ← incl1.date; initName ← incl1.path1; isIncluded ← TRUE};
imp1: REF ImportsItem => {date ← imp1.date; initName ← imp1.path1};
ENDCASE => RETURN;
IF date.format # explicit
THEN {
The version number is a hint, but we don't really want that hint stored. In this case we can check for a previous inclusion of the file.
checkRemote ← TRUE;
initName ← DFUtilities.RemoveVersionNumber[initName];
IF CheckPreviousInclusion[state, initName] THEN RETURN;
};
Try to open the file for reading. At the same time, we get the REAL full name for the file.
[inStream, fullName, date] ← OpenRead[state, initName, date];
IF inStream =
NIL
THEN {
Complain about the file not being there!
BumpNotFound[state];
PutMsg[state, initName, " (not found)"];
IF state.action #
NIL
THEN
state.action[state.actionData, notFound, initName, date, ParentName[from]];
RETURN;
};
Try for a previous inclusion of this file.
IF CheckPreviousInclusion[state, fullName] THEN RETURN;
WITH incl
SELECT
FROM
incl1: REF IncludeItem => {incl1.path1 ← fullName};
imp1: REF ImportsItem => {imp1.path1 ← fullName};
ENDCASE => RETURN;
SELECT
TRUE
FROM
isIncluded => {
For a full inclusion of this file, we enter the inclusion into the table to cut off further unnecessary inclusions and imports of this file.
kind ← " (all)";
[] ← SymTab.Store[tab, fullName, incl];
IF checkRemote
THEN
we will find this file under the initial name whenever we try for it
[] ← SymTab.Store[tab, initName, incl];
};
filter.filterB = public => kind ← " (public)";
filter.list # NIL => kind ← " (list)";
ENDCASE => kind ← " ??";
PutMsg[state, fullName, kind];
initName ← DFUtilities.RemoveVersionNumber[fullName];
DFUtilities.ParseFromStream[inStream, processItem, filter
! DFUtilities.SyntaxError => {
PutRopes[state, "Syntax error in ", fullName, "\n ", reason];
IF state.action #
NIL
THEN
state.action[state.actionData, syntaxError, fullName, date, ParentName[from]];
CONTINUE;
}];
IO.Close[inStream];
SpliceFileList[state, subHead, subTail, nFiles, 1];
};
Imports processing
ProcessImport:
ENTRY
PROC
[state: State, imp: REF ImportsItem, from: REF, filter: Filter] = TRUSTED {
ENABLE UNWIND => state.abortRequested ← TRUE;
new: ImpDefList = LIST[[imp, from, filter]];
CheckAbortInternal[state];
IF state.impHead =
NIL
THEN state.impHead ← new
ELSE state.impTail.rest ← new;
state.impTail ← new;
IF state.forked-state.finished < state.maxProcesses
THEN {
state.forked ← state.forked + 1;
Process.Detach[FORK ProcessImportBase[state]];
WHILE state.forked > state.started
DO
CheckAbortInternal[state];
WAIT state.ProcessStarted;
ENDLOOP;
};
};
ProcessImportBase:
PROC [state: State] = {
ENABLE {
UNWIND => Unwind[state];
ABORTED => {Unwind[state]; GO TO abort};
};
Base of forked process to process an imported DF file
BumpStarted[state];
DO
list: ImpDefList ← RemImport[state, TRUE];
IF list = NIL THEN RETURN;
DoProcessImport[state, list.first.imp, list.first.from, list.first.filter];
ENDLOOP;
EXITS abort => {};
};
WaitForImportsDone:
PROC [state: State] = {
DO
Whether or not there are other processes to help us, the current process can help make progress towards removing some of the queued imports processing.
list: ImpDefList = RemImport[state];
IF list = NIL THEN EXIT;
DoProcessImport[state, list.first.imp, list.first.from, list.first.filter];
ENDLOOP;
The imports processing may have added some new includes. So we wait for it to have subsided.
WaitForIncludesDone[state];
};
RemImport:
ENTRY
PROC
[state: State, finish: BOOL ← FALSE] RETURNS [list: ImpDefList ← NIL] = {
... removes an entry from the deferred includes list. NIL will be returned if there are no more entries. To avoid races between testing for no entries and insertion of new entries, if finish is TRUE, then the customary finish processing is performed when the returned value is NIL.
ENABLE UNWIND => state.abortRequested ← TRUE;
list ← state.impHead;
CheckAbortInternal[state];
IF list #
NIL
THEN {
IF (state.impHead ← list.rest) = NIL THEN state.impTail ← NIL;
list.rest ← NIL;
RETURN;
};
IF finish THEN BumpFinishedInternal[state];
};
DoProcessImport:
PROC [state: State, imp:
REF ImportsItem, from:
REF, filter: Filter] = {
initName: ROPE ← imp.path1;
fullName: ROPE ← initName;
attached: ROPE;
created: BasicTime.GMT ← imp.date.gmt;
ok: BOOL ← TRUE;
checkRemote: BOOL ← imp.date.format # explicit;
tab: SymTab.Ref = state.tab;
ExcludeFilterAndMerge:
PROC [impP:
REF ImportsPair] = {
Now we toss out whatever we can due to the filter given us.
SELECT
TRUE
FROM
imp.form = list AND (imp.list = NIL OR imp.list.nEntries = 0) => RETURN;
filter.list #
NIL => {
IF imp.form = list
THEN {
common: REF UsingList ← filter.list;
diff: REF UsingList ← DFUtilities.DifferenceOfUsingLists[common, imp.list];
IF diff # NIL THEN common ← DFUtilities.DifferenceOfUsingLists[filter.list, diff];
IF common = NIL OR common.nEntries = 0 THEN RETURN;
imp ← NEW[ImportsItem ← imp^];
imp.list ← common;
};
};
filter.filterB = public AND NOT imp.exported => RETURN;
ENDCASE;
Now, merge the using lists.
MergeUsingLists[state, impP, imp];
};
IF imp.list # NIL THEN DFUtilities.SortUsingList[imp.list, TRUE];
IF checkRemote
THEN {
The version number is useless, so let's strip it off so we don't have further problems.
imp.path1 ← initName ← fullName ← DFUtilities.RemoveVersionNumber[initName];
created ← BasicTime.nullGMT;
WITH SymTab.Fetch[tab, initName].val
SELECT
FROM
incl:
REF IncludeItem => {
In this case, the imported file has already been included.
RETURN;
};
impP:
REF ImportsPair => {
In this case, the imported file has been previously imported, so we just merge the using lists.
ExcludeFilterAndMerge[impP];
RETURN;
};
ENDCASE;
};
The file must be checked for explicit version number. Therefore, we first get the real name from the file system. This includes following what the file is attached to.
{
ENABLE
FS.Error =>
IF error.group # bug
THEN
GO
TO noGot;
PutMsg[state, "Checking ", fullName];
[fullFName: fullName, attachedTo: attached, created: created] ←
FS.FileInfo[fullName, created, checkRemote];
IF attached # NIL THEN fullName ← attached;
imp.path1 ← fullName;
WITH SymTab.Fetch[tab, fullName].val
SELECT
FROM
incl:
REF IncludeItem => {
In this case, the imported file has already been included, so we do not need to further process it. However, we do note that it has been already processed.
RETURN;
};
impP:
REF ImportsPair => {
In this case, the imported file has been previously imported, so we just merge the using lists.
ExcludeFilterAndMerge[impP];
RETURN;
};
ENDCASE;
{
-- create the imports pair for table insertion
needed: REF ImportsItem ← NEW[ImportsItem ← imp^];
doing: REF ImportsItem ← NEW[ImportsItem ← imp^];
impPair:
REF ImportsPair ←
NEW[ImportsPair ← [from: ParentName[from], needed: needed, doing: doing]];
doing.list ← NIL;
doing.form ← list;
[] ← SymTab.Store[tab, fullName, impPair];
IF checkRemote THEN [] ← SymTab.Store[tab, initName, impPair];
};
EXITS noGot => {
PutRopes[state, "Import not found: ", fullName, "\n from: ", ParentName[from]];
};
};
};
Utilities
SpliceFileList:
ENTRY
PROC
[state: State, subHead,subTail: LORA, nFiles,ndfFiles: INT ← 0] = {
ENABLE UNWIND => state.abortRequested ← TRUE;
IF state.head = NIL THEN state.head ← subHead ELSE state.tail.rest ← subHead;
state.tail ← subTail;
state.files ← state.files + nFiles;
state.dfFiles ← state.dfFiles + ndfFiles;
};
BumpStarted:
ENTRY
PROC [state: State] = {
ENABLE UNWIND => state.abortRequested ← TRUE;
state.started ← state.started + 1;
BROADCAST state.ProcessStarted;
CheckAbortInternal[state];
};
BumpFinished:
ENTRY
PROC [state: State] = {
ENABLE UNWIND => state.abortRequested ← TRUE;
BumpFinishedInternal[state];
};
BumpNotFound:
ENTRY
PROC [state: State] = {
ENABLE UNWIND => state.abortRequested ← TRUE;
state.notFound ← state.notFound + 1;
};
BumpFinishedInternal:
INTERNAL
PROC [state: State] = {
state.finished ← state.finished + 1;
BROADCAST state.ProcessFinished;
CheckAbortInternal[state]
};
WaitForForkedDone:
ENTRY
PROC [state: State] = {
... waits for all forked processes to complete. Aborts are not recognized.
WHILE state.forked > state.finished DO WAIT state.ProcessFinished; ENDLOOP;
};
WaitForForkedDoneOrAbort:
ENTRY
PROC [state: State] = {
... waits for all forked processes to complete OR for an abort to be requested.
ENABLE UNWIND => state.abortRequested ← TRUE;
WHILE state.forked > state.finished
DO
CheckAbortInternal[state];
WAIT state.ProcessFinished;
ENDLOOP;
};
Unwind:
ENTRY
PROC [state: State] = {
state.abortRequested ← TRUE;
state.finished ← state.finished + 1;
BROADCAST state.ProcessFinished;
WHILE state.forked > state.finished DO WAIT state.ProcessFinished; ENDLOOP;
};
OpenRead:
PROC
[state: State, name: ROPE, date: Date]
RETURNS [in: STREAM ← NIL, fullName: ROPE ← NIL, realDate: Date] = {
... opens the given name with the given date, and returns an open stream (or NIL if the file could not be opened) and the real full name of the file.
attached: ROPE ← NIL;
created: BasicTime.GMT ← BasicTime.nullGMT;
checkRemote: BOOL ← date.format # explicit;
why: ROPE ← NIL;
retries: NAT ← 0;
file: FS.OpenFile;
realDate ← date;
IF checkRemote
THEN fullName ← DFUtilities.RemoveVersionNumber[name]
ELSE {fullName ← name; created ← date.gmt};
DO
file ← FS.Open[fullName, $read, created, checkRemote
!
FS.Error => {
SELECT error.code
FROM
$serverInaccessible => {
PutRopes[state, "Server glitch: ", fullName];
retries ← retries + 1;
IF retries <= state.serverRetries THEN LOOP;
};
ENDCASE;
PutRopes[state, "Can't open ", fullName, "\n ", error.explanation];
IF error.group # bug THEN GO TO noGot;
}];
in ← FS.StreamFromOpenFile[file, $read];
EXIT;
ENDLOOP;
[fullFName: fullName, attachedTo: attached] ← FS.GetName[file];
created ← FS.GetInfo[file].created;
IF attached # NIL THEN fullName ← attached;
IF created # BasicTime.nullGMT THEN realDate ← [format: explicit, gmt: created];
EXITS noGot => {};
};
MergeUsingLists:
ENTRY
PROC [state: State, impP:
REF ImportsPair, imp:
REF ImportsItem] = {
This is an entry procedure to keep from blundering into multiple merges of using lists. The using list of impP.needed is modified to include the using list of imp (minus the current lists of impP.needed and impP.doing). We assume that imp.list # NIL <=> imp.form = list.
ENABLE UNWIND => state.abortRequested ← TRUE;
needed: REF ImportsItem ← impP.needed;
doing: REF ImportsItem ← impP.doing;
impList: REF UsingList ← CopyUsingList[imp.list];
CheckAbortInternal[state];
IF impList #
NIL
THEN {
Cast out the entries from the USING lists of both the known need and the known doing imports items. If we are left with no new items, then return.
IF needed.list #
NIL
THEN
impList ← DFUtilities.DifferenceOfUsingLists[impList, needed.list];
IF doing.list #
NIL
AND impList #
NIL
THEN
impList ← DFUtilities.DifferenceOfUsingLists[impList, doing.list];
IF impList = NIL OR impList.nEntries = 0 THEN RETURN;
};
SELECT imp.form
FROM
all => {needed.form ← all; needed.list ← NIL};
exports => IF needed.form = list THEN needed.form ← exports;
list => {
nList: REF UsingList = impList;
oList: REF UsingList = needed.list;
SELECT
TRUE
FROM
nList = NIL => {};
oList = NIL => needed.list ← nList;
ENDCASE => {
diff: REF UsingList = DFUtilities.DifferenceOfUsingLists[nList, oList];
IF diff #
NIL
THEN {
dLen: NAT = diff.nEntries;
oLen: NAT = oList.nEntries;
SELECT
TRUE
FROM
dLen = 0 => {};
oLen = 0 => needed.list ← diff;
ENDCASE => {
Merge the new and old lists.
nnlist: REF UsingList ← needed.list ← NEW[UsingList[oLen+dLen]];
nnlist.nEntries ← oLen+dLen;
FOR i: NAT IN [0..oLen) DO nnlist[i] ← oList[i]; ENDLOOP;
FOR j: NAT IN [0..dLen) DO nnlist[j+oLen] ← diff[j]; ENDLOOP;
DFUtilities.SortUsingList[nnlist, oLen > dLen];
};
};
};
};
ENDCASE => ERROR;
};
NoteDoing:
ENTRY
PROC
[state: State, impP: REF ImportsPair] RETURNS [REF ImportsItem ← NIL] = {
... transfers the using list from impP.needed to impP.doing. We return a new ImportsItem if there is something to do. NoteDoing is an entry procedure to keep from blundering into multiple merges of using lists.
ENABLE UNWIND => state.abortRequested ← TRUE;
needed: REF ImportsItem ← impP.needed;
nList: REF UsingList ← needed.list;
nLen: NAT ← IF nList = NIL THEN 0 ELSE nList.nEntries;
nForm: UsingForm ← needed.form;
doing: REF ImportsItem ← impP.doing;
dList: REF UsingList ← doing.list;
dLen: NAT ← IF dList = NIL THEN 0 ELSE dList.nEntries;
Copy:
PROC
RETURNS [toDo:
REF ImportsItem ←
NIL] = {
toDo ← NEW[ImportsItem ← needed^];
toDo.list ← nList;
toDo.form ← nForm;
};
needed.list ← NIL;
needed.form ← list;
Do various quick kill tests to determine if there is something new to do.
SELECT doing.form
FROM
all => RETURN;
exports => {
SELECT nForm
FROM
all => {
doing.form ← all; doing.list ← NIL;
RETURN [doing];
};
ENDCASE => {
nForm ← list;
IF nLen = 0 THEN RETURN;
};
};
list => {
SELECT nForm
FROM
all => {
doing.form ← all; doing.list ← NIL;
RETURN [doing];
};
exports => {
doing.form ← exports;
IF nLen = 0 THEN RETURN [Copy[]];
};
list => {
IF nLen = 0 THEN RETURN;
};
ENDCASE;
};
ENDCASE;
IF dLen = 0
THEN
Nothing was happening for this import, so just move the needed list.
doing.list ← nList
ELSE {
Sigh, there are items in the doing using list. We need to merge in the non-common items from the needed using list (provided that there are non-common items).
diff: REF UsingList = DFUtilities.DifferenceOfUsingLists[nList, dList];
delta: NAT = IF diff = NIL THEN 0 ELSE dList.nEntries;
IF delta = 0 THEN RETURN;
Merge the new and old lists. Remember that we have to keep the new list sorted.
nLen ← dLen+delta;
nList ← doing.list ← NEW[UsingList[nLen]];
nList.nEntries ← nLen;
FOR i: NAT IN [0..dLen) DO nList[i] ← dList[i]; ENDLOOP;
FOR j: NAT IN [0..delta) DO nList[j+dLen] ← diff[j]; ENDLOOP;
DFUtilities.SortUsingList[nList, delta <= dLen];
};
RETURN [Copy[]];
};
CopyUsingList:
PROC [old:
REF UsingList]
RETURNS [new:
REF UsingList ←
NIL] = {
IF old #
NIL
THEN {
size: NAT = old.nEntries;
new ← NEW[UsingList[size]];
new.nEntries ← size;
FOR i: NAT IN [0..size) DO new[i] ← old[i]; ENDLOOP;
};
};
ParentName:
PROC [from:
REF]
RETURNS [parent:
ROPE] = {
parent ← "??";
WITH from
SELECT
FROM
rope: ROPE => parent ← rope;
imp: REF ImportsItem => parent ← imp.path1;
inclP: REF IncludeItem => parent ← inclP.path1;
ENDCASE;
};
CheckPreviousInclusion:
PROC
[state: State, name: ROPE, msg: BOOL ← FALSE] RETURNS [BOOL] = {
... checks the table for previous inclusion of the given name. If msg, then put out a message if this file was included.
WITH SymTab.Fetch[state.tab, name].val
SELECT
FROM
incl:
REF IncludeItem => {
IF msg THEN PutMsg[state, name, " (skipped)"];
RETURN [TRUE];
};
ENDCASE => RETURN [FALSE];
};
NoteAborting:
PROC [state: State] = {
state.abortRequested ← TRUE;
PutRopes[state, "Aborting...\n\n"];
WaitForForkedDone[state];
SmashTheState[state];
};
SmashTheState:
ENTRY
PROC [state: State] = {
This procedure vigorously throws away the file list and the DF table. It helps in recovering storage, since it is likely that the conservative scan will hold onto some cell in the list, thereby causing numerous others to be held.
ENABLE UNWIND => NULL;
list: LORA ← state.head;
WHILE list #
NIL
DO
rest: LORA ← list.rest;
list.rest ← NIL;
list ← rest;
ENDLOOP;
state.head ← NIL;
state.tail ← NIL;
state.tab ← NIL;
SafeStorage.ReclaimCollectibleObjects[];
};
PutRopes:
ENTRY
PROC [state: State, r1,r2,r3,r4:
ROPE ←
NIL] = {
.. puts out the given ropes to the command output stream. This is an entry procedure to keep from confusing the STREAM abstraction, which is not protected against concurrent access.
ENABLE UNWIND => state.abortRequested ← TRUE;
IF state.abortRequested THEN RETURN WITH ERROR ABORTED;
MessagesOut.PutRopes[state.errs, r1,r2,r3,r4];
};
PutMsg:
ENTRY
PROC [state: State, r1,r2,r3,r4:
ROPE ←
NIL] = {
... puts out the given ropes to the MessageWindow. This is an entry procedure to keep the message in the MessageWindow consistent.
ENABLE UNWIND => state.abortRequested ← TRUE;
IF state.abortRequested THEN RETURN WITH ERROR ABORTED;
MessagesOut.PutMsg[r1,r2,r3,r4];
};
CheckAbort:
ENTRY
PROC [state: State] = {
... puts out the given ropes to the MessageWindow. This is an entry procedure to keep the message in the MessageWindow consistent.
ENABLE UNWIND => NULL;
CheckAbortInternal[state];
};
CheckAbortInternal:
INTERNAL
PROC [state: State] = {
... puts out the given ropes to the MessageWindow. This is an entry procedure to keep the message in the MessageWindow consistent.
ENABLE
UNWIND => {
state.abortRequested ← TRUE;
BROADCAST state.ProcessFinished;
BROADCAST state.ProcessStarted;
};
IF state.abortRequested
THEN {
BROADCAST state.ProcessFinished;
BROADCAST state.ProcessStarted;
RETURN WITH ERROR ABORTED;
};
ProcessExtras.CheckForAbort[];
};
ScanName:
PROC [name:
ROPE]
RETURNS [pos,bang,dot:
INT] = {
len: INT = Rope.Length[name];
pos ← bang ← dot ← len;
WHILE pos > 0
DO
posM: INT = pos-1;
SELECT Rope.Fetch[name, posM]
FROM
'! => bang ← dot ← posM;
'. => dot ← posM;
'>, '/, '] => RETURN;
ENDCASE;
pos ← posM;
ENDLOOP;
};