CoreDirectoryImpl.mesa
Copyright Ó 1986, 1987 by Xerox Corporation. All rights reversed.
Created by Christian Jacobi, July 14, 1986 9:50:03 am PDT
Last Edited by: Jacobi July 15, 1986 9:53:01 am PDT
Bertrand Serlet March 28, 1987 11:19:36 pm PST
Mike Spreitzer February 27, 1987 2:52:13 pm PST
DIRECTORY
Core USING [CellType],
CoreDirectory,
Rope USING [ROPE, FromRefText],
SymTab;
CoreDirectoryImpl: CEDAR PROGRAM
IMPORTS SymTab, Rope
EXPORTS CoreDirectory =
BEGIN OPEN CoreDirectory;
LibraryNotFound: PUBLIC SIGNAL [name: ROPE] = CODE;
libraries: SymTab.Ref ~ SymTab.Create[case: TRUE];
The global name space of library names
RegisterLibrary: PUBLIC PROC [library: Library, name: ROPE] RETURNS [sameLibrary: Library] = {
sameLibrary ← library;
[] ← SymTab.Store[x: libraries, key: name, val: sameLibrary];
};
FetchLibrary: PUBLIC PROC [name: ROPE] RETURNS [library: Library] = {
WITH SymTab.Fetch[libraries, name].val SELECT FROM
lib: Library => RETURN [lib];
ENDCASE => NULL;
SIGNAL LibraryNotFound[name];
};
ForgetLibrary: PUBLIC PROC [name: ROPE] = {
[] ← SymTab.Delete[libraries, name];
};
CreateLibrary: PUBLIC PROC [] RETURNS [library: Library] = {
library ← SymTab.Create[case: TRUE];
};
GetLib: PROC [library: REF] RETURNS [lib: Library ← NIL] = INLINE {
Internal proc to converts Library union ROPE to Library
Either returns good Library or SIGNALS and returns NIL
WITH library SELECT FROM
lb: Library => RETURN [lb];
r: ROPE => {
WITH SymTab.Fetch[libraries, r].val SELECT FROM
lb: Library => RETURN [lb];
ENDCASE => SIGNAL LibraryNotFound[r];
};
rt: REF TEXT =>
WITH SymTab.Fetch[libraries, Rope.FromRefText[rt]].val SELECT FROM
lb: Library => RETURN [lb];
ENDCASE => SIGNAL LibraryNotFound[Rope.FromRefText[rt]];
ENDCASE =>
IF library=NIL THEN SIGNAL LibraryNotFound[NIL] ELSE ERROR;
};
Fetch: PUBLIC PROC [library: REF, key: ROPE] RETURNS [ct: CellType ← NIL] = {
lib: Library ~ GetLib[library];
IF lib#NIL THEN ct ← NARROW [SymTab.Fetch[lib, key].val];
};
Insert: PUBLIC PROC [library: Library, key: ROPE, ct: CellType, overWrite: BOOLFALSE] RETURNS [first: BOOLFALSE] = {
IF library=NIL THEN ERROR;
IF overWrite THEN {
IF ct#NIL THEN first ← SymTab.Store[library, key, ct]
ELSE first ← SymTab.Delete[library, key]
}
ELSE IF ct#NIL THEN first ← SymTab.Insert[library, key, ct]
};
END.