with FUNDAMENTALS; use FUNDAMENTALS; with FUNCT; use FUNCT; package environment_pkg is type activation; type activation_ptr is access activation; type environment; type environment_ptr is access environment; --------------------------- type ACTIVATION ----------------------------- -- for activation records. A name field is provided solely -- for debugging purposes. Control links and activation links are -- provided. Activation records must also contain the values bound to -- both the parameters and function names used by the function being -- activated. -- No functions are defined explicitly for activation records, but -- several functions defined on environments (see below) have the -- effect of processing activation records. type activation is record name:symbol_type_ptr; -- just for debugging control_ptr:activation_ptr; access_ptr:activation_ptr; actuals:list_of_offsets_ptr; functs:list_of_functions_ptr; end record; --------------------------- type ENVIRONMENT ----------------------------- -- An environment object is just a linked list of activation records. -- Since these records are linked both by control links and by -- activation links, the links are stored in the activation records, -- so that the only field of an environment object is a -- pointer to the first activation record. -- Nonetheless, many useful functions take an ENVIRONMENT argument, -- e.g., the functions that PUSH and POP activation records to or from -- the environment. The PUSH function takes an integer argument -- describing how far back to link the access pointer. The POP -- function returns nothing since the value popped is not needed. -- Another example is the function that runs a compiled "program". Actually -- there are two such functions -- one that handles a top level function -- (taking only a pointer to a function object as parameter) and one that -- handles all other functions (also taking a representation of the call). -- Other such functions look up the bodies of functions in the -- environment, look up the values of variables in the -- environment, and bind formals to actuals in the environment. type environment is record first:activation_ptr; end record; procedure push(e:environment_ptr; a:activation_ptr; i:integer); procedure pop(e:environment_ptr); procedure run(e:environment_ptr; f:function_ptr); procedure run(e:environment_ptr; call:list_of_offsets_ptr; f:function_ptr); function get_function(e:environment_ptr; o:offset_ptr) return function_ptr; function eval(e:environment_ptr; o:offset_ptr) return offset_ptr; procedure bind(e:environment_ptr; call:list_of_offsets_ptr; actuals:list_of_offsets_ptr); end environment_pkg;