MDSymbolsImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Willie-sue, April 14, 1986 6:48:14 pm PST
taken from MicSym.bcpl and (distantly) MicSA.bcpl
DIRECTORY
Atom USING [MakeAtom],
RefTab USING [EachPairAction, Create, Fetch, Pairs, Ref, Store, Val],
IO,
Rope,
MDDefs,
MDOps USING [],
MDUtils;
MDSymbolsImpl: CEDAR PROGRAM
IMPORTS
Atom, RefTab
EXPORTS
MDOps, MDUtils
= BEGIN OPEN MDDefs;
ROPE: TYPE = Rope.ROPE;
symbolTable: RefTab.Ref;
symbolTableSize: NAT = 2047;
AddSym: PUBLIC PROC[symName: ROPE, addIfNew: BOOLTRUE]
RETURNS[symbol: Symbol] = {
found: BOOL;
val: RefTab.Val;
symb: ATOM ← Atom.MakeAtom[symName];
[found, val] ← RefTab.Fetch[symbolTable, symb];
IF found THEN symbol ← NARROW[val];
IF found OR ~addIfNew THEN RETURN[symbol];
symbol ← NEW[SymbolRec ← [atm: symb, name: symName]];
[] ← RefTab.Store[symbolTable, symb, symbol];  -- add to table
};
InitSymbolTable: PUBLIC PROC =
{ symbolTable ← RefTab.Create[symbolTableSize] };  -- easiest
SearchTableProc: TYPE = PROC[sym: MDDefs.Symbol] RETURNS[quit: BOOL];
SearchSymbolTable: PUBLIC PROC[proc: MDUtils.SearchTableProc] = {
LookAt: RefTab.EachPairAction = {
sym: Symbol ← NARROW[val];
quit ← proc[sym];
};
[] ← RefTab.Pairs[symbolTable, LookAt];
};
GS: PROC[symName: ROPE] RETURNS[symbol: Symbol] =
{ RETURN[AddSym[symName, FALSE]] };
END.