]> www.ginac.de Git - cln.git/blobdiff - include/cln/object.h
Added e2k arch support.
[cln.git] / include / cln / object.h
index 12857d9cf6f43ebc38506edf8a1603ee1880637e..15c13593f4aa98b2b4d29d597444590238eab400 100644 (file)
@@ -5,7 +5,7 @@
 
 #include "cln/types.h"
 #include "cln/modules.h"
-#include <stdlib.h>
+#include <cstdlib>
 
 namespace cln {
 
@@ -17,15 +17,15 @@ namespace cln {
 //              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'
+// cl_word_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__)
+#if defined(__i386__) || (defined(__mips__) && !defined(__LP64__)) || (defined(__sparc__) && !defined(__arch64__)) || defined(__hppa__) || defined(__arm__) || defined(__rs6000__) || defined(__m88k__) || defined(__convex__) || (defined(__s390__) && !defined(__s390x__)) || defined(__sh__) || (defined(__x86_64__) && defined(__ILP32__))
   #define cl_word_alignment  4
 #endif
-#if defined(__alpha__) || defined(__mips64__) || defined(__sparc64__)
+#if defined(__alpha__) || defined(__ia64__) || defined(__mips64__) || defined(__powerpc64__) || (defined(__sparc__) && defined(__arch64__)) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(__s390x__) || defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) || defined(__e2k__)
   #define cl_word_alignment  8
 #endif
 #if !defined(cl_word_alignment)
@@ -71,13 +71,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,11 +92,7 @@ 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)
@@ -126,9 +122,15 @@ inline cl_uint cl_combine (cl_uint tag, cl_sint value)
 }
 // 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(tag, (cl_uint)value); }
 inline cl_uint cl_combine (cl_uint tag, int value)
-{ return cl_combine(tag,(cl_sint)value); }
+{ return cl_combine(tag, (cl_sint)value); }
+#ifdef HAVE_LONGLONG
+inline cl_uint cl_combine (cl_uint tag, unsigned long long value)
+{ return cl_combine(tag, (cl_uint)value); }
+inline cl_uint cl_combine (cl_uint tag, long long value)
+{ return cl_combine(tag, (cl_uint)value); }
+#endif
 
 // Definition of the tags.
 #if !defined(CL_WIDE_POINTERS)
@@ -162,14 +164,18 @@ 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
-// Function to print an object for debugging, to stderr.
+#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);
 
 struct cl_class {
@@ -237,7 +243,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.
@@ -257,7 +263,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;                                           \
 }
 
@@ -304,7 +310,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
@@ -321,15 +327,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 () {}
@@ -354,8 +356,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); }
@@ -371,15 +373,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 () {}
@@ -404,7 +402,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
@@ -421,15 +419,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 () {}
@@ -454,8 +448,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); }
@@ -471,15 +465,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 () {}
@@ -548,7 +538,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();           \
+      typedef int assert1 [2*(sizeof(target_class)==sizeof(*this))-1]; \
       return * (const target_class *) (void*) this;                    \
     }