-- JaMDictionaryDefs.mesa
-- Last changed by Doug Wyatt, March 29, 1980 1:27 PM

-- Administers dictionaries in VM
-- A dictionary is a type of Object, however additional information
-- is held in a DictDesc, which also lives in VM
-- A Dictionary is a set of <key,value> tuples, in which both
-- key and value are Objects (key is not necessarily a string)
-- Present implementation:
-- Dictionary is allocated as a contiguous vector of <object,object> tuples
-- Hash coding is used to access tuples

DIRECTORY
JaMMasterDefs: FROM "JaMMasterDefs" USING [Object, Stack];

JaMDictionaryDefs: DEFINITIONS =
BEGIN OPEN JaMMasterDefs;

JaMDictionary: PROGRAM;

--*** CREATION ***

Dictionary: PUBLIC PROCEDURE[maxLen: CARDINAL]
RETURNS[dict: DictType Object];
-- Return a new dictionary for up to maxlen tuples
-- Generates DictNoRoom:

--*** ATTRIBUTES ***

Length: PUBLIC PROCEDURE[dict: DictType Object]
RETURNS[length: CARDINAL];
-- Return current length of dictionary dict

MaxLength: PUBLIC PROCEDURE[dict: DictType Object]
RETURNS[length: CARDINAL];
-- Return maximum allowable length of dictionary dict

--*** ACCESS ***

Known: PUBLIC PROCEDURE[dict: DictType Object, key: Object]
RETURNS[known: BOOLEAN];

Where: PUBLIC PROCEDURE[dictstk: JaMMasterDefs.Stack, key: Object]
RETURNS[known: BOOLEAN, dict: DictType Object];

Get: PUBLIC PROCEDURE[dict: DictType Object, key: Object]
RETURNS[value: Object];
-- Generates DictLookUpError

Put: PUBLIC PROCEDURE[dict: DictType Object, key,value: Object];
-- Generates DictFull:

Define: PUBLIC PROCEDURE[dictstk: JaMMasterDefs.Stack, key,value: Object];
-- Enters <key,value> into dictionary on top of dictstk,
-- Generates dictfull:

Load: PUBLIC PROCEDURE[dictstk: JaMMasterDefs.Stack, key: Object]
RETURNS[value: Object];
-- Return value looked up in highest dictionary having key in dictstk
-- Generates DictLookUpError

Store: PUBLIC PROCEDURE[dictstk: JaMMasterDefs.Stack, key,value: Object];
-- Enters <key,value> into highest dictionary having key in dictstk,
--
or into dict on top of dictstk
-- Generates DictFull:

Delete: PUBLIC PROCEDURE[dict: DictType Object, key: Object];
-- Deletes object key from dictionary
-- Generates DictDeleteFail if object not found:

Clear: PUBLIC PROCEDURE[dict: DictType Object];
-- Deletes all objects from dictionary dict

NextTuple: PUBLIC PROCEDURE[dict: DictType Object, oldtupleptr: LONG POINTER]
RETURNS[key,value: Object, tupleptr: LONG POINTER];
-- Increments oldtupleptr to next non-null tuple and returns it together
--
with the key and object of the tuple
-- Initial call should have oldtupleptr=NIL
-- Returns tupleptr=NIL if no more tuples

Begin: PUBLIC PROCEDURE[dictstk: JaMMasterDefs.Stack,
dict: DictType Object];
-- Push dictionary dict onto stack dictstk, dealing with cache

End: PUBLIC PROCEDURE[dictstk: JaMMasterDefs.Stack];
-- Pop stack dictstk, dealing with cache

--*** JaM INTRINSICS ***

DictDict: PUBLIC PROCEDURE;
-- Expects stk: (maxLength)
-- Returns stk: (new dictionary to hold up to maxLength objects)

--"DictLength" is handled in JaMAttributes

DictMaxLength: PUBLIC PROCEDURE;
-- Expects stk: (dictionary)
-- Returns stk: (maximum number of objects in dictionary)

DictKnown: PUBLIC PROCEDURE;
-- Expects opstk: (dictionary, key)
-- Returns opstk: (boolean)

DictWhere: PUBLIC PROCEDURE;
-- Expects opstk: (key), dictstk: a dictionary stack
-- Returns opstk: (boolean("known"), dictionary(if key known))
--
dictstk: unchanged

DictGet: PUBLIC PROCEDURE;
-- Expects stk: (dictionary, key)
-- Returns stk: (value looked up in dictionary)

DictPut: PUBLIC PROCEDURE;
-- Expects stk: (dictionary, key, value)
-- Enters <key,value> into dictionary
-- Returns stk: ()
-- No indication of whether an object with that key already existed.

DictDefine: PUBLIC PROCEDURE;
-- Expects stk: (key, value), dictstk: (dictionary)
-- Enters <key,value> into dictionary
-- Returns stk: (), dictstk: (dictionary)
-- No indication of whether an object with that key already existed.

DictLoad: PUBLIC PROCEDURE;
-- Expects stk: (key), dictstk: a dictionary stack
-- Returns stk: (value looked up in highest dictionary having key in dictstk),
--
dictstk: unchanged

DictStore: PUBLIC PROCEDURE;
-- Expects stk: (key, value), dictstk: a dictionary stack
-- Enters <key,value> into highest dictionary having key in dictstk,
--
or into dict on top of dictstk
-- Returns stk: (), dictstk: unchanged

DictDelete: PUBLIC PROCEDURE;
-- Expects stk: (dictionary, key)
-- Deletes object key from dictionary
-- Returns stk: ()

DictClear: PUBLIC PROCEDURE;
-- Expects stk: (dictionary)
-- Deletes all objects from dictionary
-- Returns stk: ()

DictForall: PUBLIC PROCEDURE;
-- Expects opstk: (dictionary)(object)
-- For each tuple in dictionary put (key)(value) onto opstk and execute object
-- Returns opstk: ();

DictBegin: PUBLIC PROCEDURE;
-- Expects stk: (dictionary), dictstk: ()
-- Returns stk: (), dictstk: (dictionary)

DictEnd: PUBLIC PROCEDURE;
-- Expects dictstk: (dictionary)
-- Returns dictstk: ()

END.

DKW March 27, 1980 6:14 PM
added JaMDictionary: PROGRAM;