]> www.ginac.de Git - cln.git/blobdiff - include/cln/object.h
Finalize CLN 1.3.7 release.
[cln.git] / include / cln / object.h
index 169a6aaca20439b8179dc7de37abe9bdc31ee973..61a614eb5239d969f3ccdad231fe26e062863280 100644 (file)
@@ -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__) || defined(__s390__)
-  #define cl_word_alignment  4
-#endif
-#if defined(__alpha__) || defined(__mips64__) || defined(__sparc64__) || defined(__ia64__) || defined(__x86_64__)
-  #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);
 
@@ -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,11 +311,7 @@ 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.
@@ -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,11 +357,7 @@ 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.
@@ -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,11 +403,7 @@ 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.
@@ -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,11 +449,7 @@ 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.
@@ -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;                    \
     }