-- 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 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 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 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 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 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 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 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;(648)\578b18B42b13B32b10B169b6B115b9B143b5B82b5B112b3B110b3B86b6B150b4B187b5B197b6B144b5B88b9B323b5B138b3B119b8B158b13B108b9B85b9B159b7B103b7B188b10B222b8B174b9B222b10B112b9B108b10B161b9B105b7B