#include "cln/types.h"
#include "cln/modules.h"
-#include <stdlib.h>
+#include <cstdlib>
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__) || defined(__ia64__)
+#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)
#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.
#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)
// 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);
{ \
cl_uint x_word = x.word; \
cl_inc_refcount(x); \
- word = x_word; \
+ this->word = x_word; \
}
// The declaration of a copy constructor.
cl_uint x_word = x.word; \
cl_inc_refcount(x); \
cl_dec_refcount(*this); \
- word = x_word; \
+ this->word = x_word; \
return *this; \
}
// 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
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.
// 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); }
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.
// 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
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.
// 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); }
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.
#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; \
}