#include "cln/malloc.h"
#include "cln/proplist.h"
#include "cln/number.h"
+#include "cln/exception.h"
#include "cln/io.h"
namespace cln {
// print
void (* fprint) (cl_heap_ring* R, std::ostream& stream, const _cl_ring_element& x);
// equality
- cl_boolean (* equal) (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y);
+ bool (* equal) (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y);
// ...
};
struct _cl_ring_addops {
// 0
const _cl_ring_element (* zero) (cl_heap_ring* R);
- cl_boolean (* zerop) (cl_heap_ring* R, const _cl_ring_element& x);
+ bool (* zerop) (cl_heap_ring* R, const _cl_ring_element& x);
// x+y
const _cl_ring_element (* plus) (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y);
// x-y
// Low-level operations.
void _fprint (std::ostream& stream, const _cl_ring_element& x)
{ setops->fprint(this,stream,x); }
- cl_boolean _equal (const _cl_ring_element& x, const _cl_ring_element& y)
+ bool _equal (const _cl_ring_element& x, const _cl_ring_element& y)
{ return setops->equal(this,x,y); }
const _cl_ring_element _zero ()
{ return addops->zero(this); }
- cl_boolean _zerop (const _cl_ring_element& x)
+ bool _zerop (const _cl_ring_element& x)
{ return addops->zerop(this,x); }
const _cl_ring_element _plus (const _cl_ring_element& x, const _cl_ring_element& y)
{ return addops->plus(this,x,y); }
// High-level operations.
void fprint (std::ostream& stream, const cl_ring_element& x)
{
- if (!(x.ring() == this)) cl_abort();
+ if (!(x.ring() == this)) throw runtime_exception();
_fprint(stream,x);
}
- cl_boolean equal (const cl_ring_element& x, const cl_ring_element& y)
+ bool equal (const cl_ring_element& x, const cl_ring_element& y)
{
- if (!(x.ring() == this)) cl_abort();
- if (!(y.ring() == this)) cl_abort();
+ if (!(x.ring() == this)) throw runtime_exception();
+ if (!(y.ring() == this)) throw runtime_exception();
return _equal(x,y);
}
const cl_ring_element zero ()
{
return cl_ring_element(this,_zero());
}
- cl_boolean zerop (const cl_ring_element& x)
+ bool zerop (const cl_ring_element& x)
{
- if (!(x.ring() == this)) cl_abort();
+ if (!(x.ring() == this)) throw runtime_exception();
return _zerop(x);
}
const cl_ring_element plus (const cl_ring_element& x, const cl_ring_element& y)
{
- if (!(x.ring() == this)) cl_abort();
- if (!(y.ring() == this)) cl_abort();
+ if (!(x.ring() == this)) throw runtime_exception();
+ if (!(y.ring() == this)) throw runtime_exception();
return cl_ring_element(this,_plus(x,y));
}
const cl_ring_element minus (const cl_ring_element& x, const cl_ring_element& y)
{
- if (!(x.ring() == this)) cl_abort();
- if (!(y.ring() == this)) cl_abort();
+ if (!(x.ring() == this)) throw runtime_exception();
+ if (!(y.ring() == this)) throw runtime_exception();
return cl_ring_element(this,_minus(x,y));
}
const cl_ring_element uminus (const cl_ring_element& x)
{
- if (!(x.ring() == this)) cl_abort();
+ if (!(x.ring() == this)) throw runtime_exception();
return cl_ring_element(this,_uminus(x));
}
const cl_ring_element one ()
}
const cl_ring_element mul (const cl_ring_element& x, const cl_ring_element& y)
{
- if (!(x.ring() == this)) cl_abort();
- if (!(y.ring() == this)) cl_abort();
+ if (!(x.ring() == this)) throw runtime_exception();
+ if (!(y.ring() == this)) throw runtime_exception();
return cl_ring_element(this,_mul(x,y));
}
const cl_ring_element square (const cl_ring_element& x)
{
- if (!(x.ring() == this)) cl_abort();
+ if (!(x.ring() == this)) throw runtime_exception();
return cl_ring_element(this,_square(x));
}
const cl_ring_element expt_pos (const cl_ring_element& x, const cl_I& y)
{
- if (!(x.ring() == this)) cl_abort();
+ if (!(x.ring() == this)) throw runtime_exception();
return cl_ring_element(this,_expt_pos(x,y));
}
// Property operations.
{ return !x.ring()->equal(x,y); }
// Compare against 0.
-inline cl_boolean zerop (const cl_ring_element& x)
+inline bool zerop (const cl_ring_element& x)
{ return x.ring()->zerop(x); }
// Multiply.
// Ring of uninitialized elements.
-// Any operation results in a run-time error.
+// Any operation results in an exception being thrown.
+
+// Thrown when an attempt is made to perform an operation on an uninitialized ring.
+class uninitialized_ring_exception : public runtime_exception {
+public:
+ uninitialized_ring_exception ();
+};
+
+// Thrown when a ring element is uninitialized.
+class uninitialized_exception : public runtime_exception {
+public:
+ explicit uninitialized_exception (const _cl_ring_element& obj);
+ uninitialized_exception (const _cl_ring_element& obj_x, const _cl_ring_element& obj_y);
+};
extern const cl_ring cl_no_ring;
extern cl_class cl_class_no_ring;
-CL_REQUIRE(cl_no_ring)
+
+class cl_no_ring_init_helper
+{
+ static int count;
+public:
+ cl_no_ring_init_helper();
+ ~cl_no_ring_init_helper();
+};
+static cl_no_ring_init_helper cl_no_ring_init_helper_instance;
inline cl_ring::cl_ring ()
: cl_rcpointer (as_cl_private_thing(cl_no_ring)) {}
template <class T>
struct cl_number_ring_ops {
- cl_boolean (* contains) (const cl_number&);
- cl_boolean (* equal) (const T&, const T&);
- cl_boolean (* zerop) (const T&);
+ bool (* contains) (const cl_number&);
+ bool (* equal) (const T&, const T&);
+ bool (* zerop) (const T&);
const T (* plus) (const T&, const T&);
const T (* minus) (const T&, const T&);
const T (* uminus) (const T&);
};
// Type test.
-inline cl_boolean instanceof (const cl_number& x, const cl_number_ring& R)
+inline bool instanceof (const cl_number& x, const cl_number_ring& R)
{
return ((cl_heap_number_ring*) R.heappointer)->ops->contains(x);
}
// Debugging support.
#ifdef CL_DEBUG
extern int cl_ring_debug_module;
-static void* const cl_ring_debug_dummy[] = { &cl_ring_debug_dummy,
- &cl_ring_debug_module
-};
+CL_FORCE_LINK(cl_ring_debug_dummy, cl_ring_debug_module)
#endif
} // namespace cln