#include "cln/types.h"
#include "cln/modules.h"
-#include <stdlib.h>
+#include <cstdlib>
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:
//
#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)
+#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)
}
// 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)
// 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(); \
+ int (*dummy1)(int assert1 [2*(sizeof(target_class)==sizeof(*this))-1]); (void)dummy1; \
return * (const target_class *) (void*) this; \
}