--NutsDictionary.mesa
-- Implements NutsDictDefs.mesa
--
January 12, 1982 5:01 PM by Pasco

DIRECTORY

NutsDictDefs: FROM "NutsDictDefs",
IntStorageDefs: FROM "IntStorageDefs" USING [ObjectName],
Storage: FROM "Storage" USING [Words, FreeWords];

NutsDictionary: PROGRAM IMPORTS Storage EXPORTS NutsDictDefs =

BEGIN

dictEntries: CARDINAL;
dictionary: POINTER TO ARRAY [0..0) OF IntStorageDefs.ObjectName;

AllocateDict: PUBLIC PROCEDURE [entries: CARDINAL] =
BEGIN
i: CARDINAL;
dictEntries ← entries;
dictionary ← Storage.Words[(entries+1)*SIZE[IntStorageDefs.ObjectName]];
FOR i IN [0..dictEntries] DO dictionary↑[i] ← 0; ENDLOOP;
END;

Record: PUBLIC PROCEDURE [number: CARDINAL, symbol: IntStorageDefs.ObjectName] =
BEGIN
dictionary↑[number] ← symbol;
END;

Lookup: PUBLIC PROCEDURE [symbol: IntStorageDefs.ObjectName] RETURNS [number: CARDINAL] =
BEGIN
i: CARDINAL;
FOR i IN [1..dictEntries] DO
IF dictionary↑[i] = symbol THEN RETURN[i];
ENDLOOP;
RETURN[0];-- not found
END;

What: PUBLIC PROCEDURE [number: CARDINAL] RETURNS [symbol: IntStorageDefs.ObjectName] =
BEGIN
symbol ← dictionary↑[number];
END;

FreeDict: PUBLIC PROCEDURE =
BEGIN
dictEntries ← 0;
Storage.FreeWords[dictionary];
dictionary ← NIL;
END;

END.