// Fixnum integer definition. // // File: fixnum.h // Author: course // Version: 3 #ifndef FIXNUM_H #define FIXNUM_H #include "object.h" class fixnum : public object { public: // Create a fixnum with a given value. // friend fixnum * make_fixnum (long value); // Get the value of a fixnum. The unchecked version // may be used when you know you have a fixnum and // do not need to do type checking. // friend long value (fixnum * fx); friend long unchecked_value (object * ob); private: long value; // Virtuals to be implemented by subclasses. virtual ostream& print (ostream& s); // Print object. virtual void scavenge(); // Scavenge object during garbage collection. }; // Other fixnum functions: // Return true iff object is a fixnum. // bool fixnump (object * ob); // Convert a pointer to an object to a pointer to a // fixnum (which is the same as the object) if the // object is a fixnum, or return NULL if the object // is not a fixnum. // fixnum * may_be_fixnum (object * ob); // Convert a pointer to an object to a pointer to a // fixnum (which is the same as the object) if the // object is a fixnum, or call error if the object is // not a fixnum. // fixnum * must_be_fixnum (object * ob); // Convert a pointer to an object to a pointer to a // fixnum (which is the same as the object) if the // object is a fixnum. Produces undefined results if // object is not a fixnum, but is the most efficient // conversion because it does no checking. // fixnum * unchecked_must_be_fixnum (object * ob); // Object type for fixnum. // extern object_type * FIXNUM_TYPE; // Inline implementations of above. See above for // documentation. // inline long value (fixnum * fx) { return fx->value; } inline long unchecked_value (object * ob) { return ((fixnum *) ob)->value; } inline bool fixnump (object * ob) { return type_of (ob) == FIXNUM_TYPE; } inline fixnum * may_be_fixnum (object * ob) { return fixnump(ob) ? (fixnum *) ob : (fixnum *) NULL; } inline fixnum * must_be_fixnum (object * ob) { if ( ob == NULL || ! fixnump (ob) ) type_error (ob, FIXNUM_TYPE); return (fixnum *) ob; } inline fixnum * unchecked_must_be_fixnum (object * ob) { return (fixnum *) ob; } #endif // FIXNUM_H