X-Git-Url: https://ginac.de/CLN/cln.git//cln.git?a=blobdiff_plain;ds=sidebyside;f=include%2Fcln%2Fobject.h;h=61a614eb5239d969f3ccdad231fe26e062863280;hb=HEAD;hp=fb509bd67594ffc153b30f973112b8f525c87386;hpb=f57f23a99a4ec8ded1faf4d61e0fb4fc6127419a;p=cln.git diff --git a/include/cln/object.h b/include/cln/object.h index fb509bd..61a614e 100644 --- a/include/cln/object.h +++ b/include/cln/object.h @@ -5,7 +5,7 @@ #include "cln/types.h" #include "cln/modules.h" -#include +#include namespace cln { @@ -13,25 +13,8 @@ namespace cln { // is sufficient. Is also has the advantage of being mostly non-interrupting. -// An object is either a pointer to heap allocated data -// or immediate data. - +// An object is either a pointer to heap allocated data or immediate data. // It is possible to distinguish these because pointers are aligned. -// cl_uint_alignment is the guaranteed alignment of a `void*' or `long' -// in memory. Must be > 1. -#if defined(__m68k__) - #define cl_word_alignment 2 -#endif -#if defined(__i386__) || defined(__mips__) || defined(__sparc__) || defined(__hppa__) || defined(__arm__) || defined(__rs6000__) || defined(__m88k__) || defined(__convex__) - #define cl_word_alignment 4 -#endif -#if defined(__alpha__) || defined(__mips64__) || defined(__sparc64__) || defined(__ia64__) - #define cl_word_alignment 8 -#endif -#if !defined(cl_word_alignment) - #error "Define cl_word_alignment for your CPU!" -#endif - // Four basic classes are introduced: // @@ -71,13 +54,13 @@ typedef uintP cl_uint; // This ought to be called `cl_word'. #endif // Distinguish immediate data from pointers. -inline cl_boolean cl_pointer_p (cl_uint word) +inline bool cl_pointer_p (cl_uint word) { - return (cl_boolean)((word & (cl_word_alignment-1)) == 0); + return (word & (cl_word_alignment-1)) == 0; } -inline cl_boolean cl_immediate_p (cl_uint word) +inline bool cl_immediate_p (cl_uint word) { - return (cl_boolean)((word & (cl_word_alignment-1)) != 0); + return (word & (cl_word_alignment-1)) != 0; } // Immediate data: Fixnum, Short Float, maybe Single Float. @@ -92,14 +75,10 @@ inline cl_boolean cl_immediate_p (cl_uint word) #define cl_tag_len 3 #endif #define cl_tag_shift 0 -#if (cl_pointer_size == 64) - #define cl_value_shift 32 -#else - #define cl_value_shift (cl_tag_len+cl_tag_shift) -#endif +#define cl_value_shift (cl_tag_len+cl_tag_shift) #define cl_value_len (cl_pointer_size - cl_value_shift) -#define cl_tag_mask (((1UL << cl_tag_len) - 1) << cl_tag_shift) -#define cl_value_mask (((1UL << cl_value_len) - 1) << cl_value_shift) +#define cl_tag_mask ((((cl_uint)1 << cl_tag_len) - 1) << cl_tag_shift) +#define cl_value_mask ((((cl_uint)1 << cl_value_len) - 1) << cl_value_shift) // Return the tag of a word. inline cl_uint cl_tag (cl_uint word) @@ -115,26 +94,27 @@ inline cl_uint cl_value (cl_uint word) } // Return a word, combining a value and a tag. -inline cl_uint cl_combine (cl_uint tag, cl_uint value) +inline cl_uint cl_combine_impl (cl_uint tag, cl_uint value) { return (value << cl_value_shift) + (tag << cl_tag_shift); } -inline cl_uint cl_combine (cl_uint tag, cl_sint value) +inline cl_uint cl_combine_impl (cl_uint tag, cl_sint value) { // This assumes cl_value_shift + cl_value_len == cl_pointer_size. return (value << cl_value_shift) + (tag << cl_tag_shift); } -// Keep the compiler happy. inline cl_uint cl_combine (cl_uint tag, unsigned int value) -{ return cl_combine(tag, (cl_uint)value); } +{ return cl_combine_impl(tag, (cl_uint)value); } inline cl_uint cl_combine (cl_uint tag, int value) -{ return cl_combine(tag, (cl_sint)value); } -#ifdef HAVE_LONGLONG +{ return cl_combine_impl(tag, (cl_sint)value); } +inline cl_uint cl_combine (cl_uint tag, unsigned long value) +{ return cl_combine_impl(tag, (cl_uint)value); } +inline cl_uint cl_combine (cl_uint tag, long value) +{ return cl_combine_impl(tag, (cl_sint)value); } inline cl_uint cl_combine (cl_uint tag, unsigned long long value) -{ return cl_combine(tag, (cl_uint)value); } +{ return cl_combine_impl(tag, (cl_uint)value); } inline cl_uint cl_combine (cl_uint tag, long long value) -{ return cl_combine(tag, (cl_uint)value); } -#endif +{ return cl_combine_impl(tag, (cl_uint)value); } // Definition of the tags. #if !defined(CL_WIDE_POINTERS) @@ -168,13 +148,17 @@ struct cl_heap { // Function to destroy the contents of a heap object. typedef void (*cl_heap_destructor_function) (cl_heap* pointer); -// Flags, to be ORed together. +// Flags, may be ORed together. #define cl_class_flags_subclass_complex 1 // all instances belong to cl_N #define cl_class_flags_subclass_real 2 // all instances belong to cl_R #define cl_class_flags_subclass_float 4 // all instances belong to cl_F #define cl_class_flags_subclass_rational 8 // all instances belong to cl_RA #define cl_class_flags_number_ring 16 // all instances are rings whose // elements belong to cl_number +#define cl_class_flags_modint_ring 32 // all instances are rings whose + // elements belong to cl_MI +#define cl_class_flags_univpoly_ring 64 // all instances are rings whose + // elements belong to cl_UP // Function to print an object for debugging, to cerr. typedef void (*cl_heap_dprint_function) (cl_heap* pointer); @@ -243,7 +227,7 @@ inline _class_::_classname_ (const _class_& x) \ { \ cl_uint x_word = x.word; \ cl_inc_refcount(x); \ - word = x_word; \ + this->word = x_word; \ } // The declaration of a copy constructor. @@ -263,7 +247,7 @@ inline dest_class& dest_class::operator= (const src_class& x) \ cl_uint x_word = x.word; \ cl_inc_refcount(x); \ cl_dec_refcount(*this); \ - word = x_word; \ + this->word = x_word; \ return *this; \ } @@ -310,7 +294,7 @@ public: // Assignment operator. cl_gcobject& operator= (const cl_gcobject&); // Distinguish immediate data from pointer. - cl_boolean pointer_p() const + bool pointer_p() const { return cl_pointer_p(word); } // Reference counting. void inc_pointer_refcount () const @@ -327,15 +311,11 @@ public: cl_private_thing _as_cl_private_thing () const; // Private constructor. cl_gcobject (cl_private_thing p) - #if !(defined(__alpha__) && !defined(__GNUC__)) : pointer (p) {} - #else - { pointer = p; } - #endif // Debugging output. void debug_print () const; // Ability to place an object at a given address. - void* operator new (size_t size, cl_gcobject* ptr) { (void)size; return ptr; } + void* operator new (size_t size, void* ptr) { (void)size; return ptr; } void* operator new (size_t size) { return ::operator new (size); } }; inline cl_gcobject::cl_gcobject () {} @@ -360,8 +340,8 @@ public: // Assignment operator. cl_gcpointer& operator= (const cl_gcpointer&); // Distinguish immediate data from pointer. - cl_boolean pointer_p() const - { return cl_true; } + bool pointer_p() const + { return true; } // Reference counting. void inc_pointer_refcount () const { cl_inc_pointer_refcount(heappointer); } @@ -377,15 +357,11 @@ public: cl_private_thing _as_cl_private_thing () const; // Private constructor. cl_gcpointer (cl_private_thing p) - #if !(defined(__alpha__) && !defined(__GNUC__)) : pointer (p) {} - #else - { pointer = p; } - #endif // Debugging output. void debug_print () const; // Ability to place an object at a given address. - void* operator new (size_t size, cl_gcpointer* ptr) { (void)size; return ptr; } + void* operator new (size_t size, void* ptr) { (void)size; return ptr; } void* operator new (size_t size) { return ::operator new (size); } }; inline cl_gcpointer::cl_gcpointer () {} @@ -410,7 +386,7 @@ public: // Assignment operator. cl_rcobject& operator= (const cl_rcobject&); // Distinguish immediate data from pointer. - cl_boolean pointer_p() const + bool pointer_p() const { return cl_pointer_p(word); } // Reference counting. void inc_pointer_refcount () const @@ -427,15 +403,11 @@ public: cl_private_thing _as_cl_private_thing () const; // Private constructor. cl_rcobject (cl_private_thing p) - #if !(defined(__alpha__) && !defined(__GNUC__)) : pointer (p) {} - #else - { pointer = p; } - #endif // Debugging output. void debug_print () const; // Ability to place an object at a given address. - void* operator new (size_t size, cl_rcobject* ptr) { (void)size; return ptr; } + void* operator new (size_t size, void* ptr) { (void)size; return ptr; } void* operator new (size_t size) { return ::operator new (size); } }; inline cl_rcobject::cl_rcobject () {} @@ -460,8 +432,8 @@ public: // Assignment operator. cl_rcpointer& operator= (const cl_rcpointer&); // Distinguish immediate data from pointer. - cl_boolean pointer_p() const - { return cl_true; } + bool pointer_p() const + { return true; } // Reference counting. void inc_pointer_refcount () const { cl_inc_pointer_refcount(heappointer); } @@ -477,15 +449,11 @@ public: cl_private_thing _as_cl_private_thing () const; // Private constructor. cl_rcpointer (cl_private_thing p) - #if !(defined(__alpha__) && !defined(__GNUC__)) : pointer (p) {} - #else - { pointer = p; } - #endif // Debugging output. void debug_print () const; // Ability to place an object at a given address. - void* operator new (size_t size, cl_rcpointer* ptr) { (void)size; return ptr; } + void* operator new (size_t size, void* ptr) { (void)size; return ptr; } void* operator new (size_t size) { return ::operator new (size); } }; inline cl_rcpointer::cl_rcpointer () {} @@ -554,7 +522,7 @@ inline cl_private_thing as_cl_private_thing (const cl_rcpointer& x) #define CL_DEFINE_CONVERTER(target_class) \ operator const target_class & () const \ { \ - if (sizeof(*this) != sizeof(target_class)) cl_abort(); \ + int (*dummy1)(int assert1 [2*(sizeof(target_class)==sizeof(*this))-1]); (void)dummy1; \ return * (const target_class *) (void*) this; \ }