#ifndef ___ENV #define ___ENV #include "fundls.hpp" #include "functs.hpp" // A class 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 // both the parameters and function names used by the function being // activated. // There are two constructors: one for a top-level call, and one for // all other calls. class function; class list_of_offsets; class list_of_functions; class activation { friend environment; protected: char *name; // just for debugging activation *control; activation *access; list_of_offsets *actuals; list_of_functions *functs; public: activation(void); activation(function *); }; // 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 member object of an environment object is a // pointer to the first activation record. // Nonetheless, many useful functions may be treated as member functions // of the "environment" class, e.g., the functions that "push" and // "pop" activation records to or from the environment. Another // example is the function that runs a compiled "program". Actually // there are two such functions -- one that handles a top level function // (taking a pointer to a function object as parameter) and one that // handles all other functions. // Other member 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. class environment { protected: activation *first; public: environment(void); void push(activation *, int); void pop(); void run(function *); void run(list_of_offsets *, function *); function *get_function(offset *); offset *eval(offset *); void bind(list_of_offsets *, list_of_offsets *); }; #endif