// Primitive and Special Function Object Code. // // File: function.cc // Author: {your name} <{your e-mail address}> // Assignment: 9 #include "function.h" #include "obtype.h" #include "gc.h" #include "symbol.h" class function_type : public object_type { public: function_type () : object_type ("FUNCTION") {} // Construct object type with simple free and // used lists and the name "FUNCTION". virtual void initialize(); // Initialize LAMBDA, LAMBDA_CLOSURE, MACRO, // etc. friend function * make_function (c_function cfun, bool special); }; object_type * FUNCTION_TYPE = (object_type *) new function_type; // Create a function with a C++ function and special // indicator. // function * make_function (c_function cfun, bool special) { function * f; // ***** Put gc code here for assignment 9 ***** object * ob; if (ob = FUNCTION_TYPE->get_free()) f = (function *) ob; else f = new function; f->init_object (FUNCTION_TYPE); f->cfun = cfun; f->special = special; FUNCTION_TYPE->put_used (f); return f; } object * LAMBDA; object * LAMBDA_CLOSURE; object * MACRO; object * REST; object * OPTIONAL; // Initialize LAMBDA, LAMBDA_CLOSURE, MACRO, etc. // void function_type::initialize() { LAMBDA = make_symbol ("LAMBDA"); LAMBDA_CLOSURE = make_symbol ("LAMBDA-CLOSURE"); MACRO = make_symbol ("MACRO"); REST = make_symbol ("&REST"); OPTIONAL = make_symbol ("&OPTIONAL"); } // Print function. // ostream& function::print (ostream& s) { return s << ( specialp(this) ? "#" : "#" ); } // Scavenge function. // void function::scavenge() {}