Progress towards eliminating arithmetic operators on a per-type basis
This commit is contained in:
parent
bba1ffde38
commit
1845114d36
@ -97,21 +97,6 @@ namespace chaiscript
|
|||||||
throw exception::bad_boxed_cast("&= only valid for integer types");
|
throw exception::bad_boxed_cast("&= only valid for integer types");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Performs an assign difference (-=) on the given object with the given Boxed_Numeric
|
|
||||||
/// \param[in,out] p1 object to difference assign to
|
|
||||||
/// \param[in] r Boxed_Numeric to assign from
|
|
||||||
/// \returns Reference to p1, to support normal C assignment semantics
|
|
||||||
template<typename P1>
|
|
||||||
P1 &assign_difference_pod(P1 &p1, Boxed_Numeric r)
|
|
||||||
{
|
|
||||||
if (r.isfloat)
|
|
||||||
{
|
|
||||||
return p1 -= P1(r.d);
|
|
||||||
} else {
|
|
||||||
return p1 -= P1(r.i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Performs an assign shift left (<<=) on the given object with the given Boxed_Numeric
|
/// \brief Performs an assign shift left (<<=) on the given object with the given Boxed_Numeric
|
||||||
/// \param[in,out] p1 object to assign shift left to
|
/// \param[in,out] p1 object to assign shift left to
|
||||||
/// \param[in] r Boxed_Numeric to assign from
|
/// \param[in] r Boxed_Numeric to assign from
|
||||||
@ -128,36 +113,6 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// \brief Performs an assign product (*=) on the given object with the given Boxed_Numeric
|
|
||||||
/// \param[in,out] p1 object to assign product to
|
|
||||||
/// \param[in] r Boxed_Numeric to assign from
|
|
||||||
/// \returns Reference to p1, to support normal C assignment semantics
|
|
||||||
template<typename P1>
|
|
||||||
P1 &assign_product_pod(P1 &p1, Boxed_Numeric r)
|
|
||||||
{
|
|
||||||
if (r.isfloat)
|
|
||||||
{
|
|
||||||
return p1 *= P1(r.d);
|
|
||||||
} else {
|
|
||||||
return p1 *= P1(r.i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Performs an assign quotient (/=) on the given object with the given Boxed_Numeric
|
|
||||||
/// \param[in,out] p1 object to assign quotient to
|
|
||||||
/// \param[in] r Boxed_Numeric to assign from
|
|
||||||
/// \returns Reference to p1, to support normal C assignment semantics
|
|
||||||
template<typename P1>
|
|
||||||
P1 &assign_quotient_pod(P1 &p1, Boxed_Numeric r)
|
|
||||||
{
|
|
||||||
if (r.isfloat)
|
|
||||||
{
|
|
||||||
return p1 /= P1(r.d);
|
|
||||||
} else {
|
|
||||||
return p1 /= P1(r.i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief Performs an assign remainder (%=) on the given object with the given Boxed_Numeric
|
/// \brief Performs an assign remainder (%=) on the given object with the given Boxed_Numeric
|
||||||
/// \param[in,out] p1 object to assign remainder to
|
/// \param[in,out] p1 object to assign remainder to
|
||||||
/// \param[in] r Boxed_Numeric to assign from
|
/// \param[in] r Boxed_Numeric to assign from
|
||||||
@ -189,20 +144,6 @@ namespace chaiscript
|
|||||||
throw exception::bad_boxed_cast(">>= only valid for integer types");
|
throw exception::bad_boxed_cast(">>= only valid for integer types");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Performs an assign sum (+=) on the given object with the given Boxed_Numeric
|
|
||||||
/// \param[in,out] p1 object to sum assign to
|
|
||||||
/// \param[in] r Boxed_Numeric to assign from
|
|
||||||
/// \returns Reference to p1, to support normal C assignment semantics
|
|
||||||
template<typename P1>
|
|
||||||
P1 &assign_sum_pod(P1 &p1, Boxed_Numeric r)
|
|
||||||
{
|
|
||||||
if (r.isfloat)
|
|
||||||
{
|
|
||||||
return p1 += P1(r.d);
|
|
||||||
} else {
|
|
||||||
return p1 += P1(r.i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,27 +175,27 @@ namespace chaiscript
|
|||||||
operators::assign_bitwise_and<T>(m);
|
operators::assign_bitwise_and<T>(m);
|
||||||
operators::assign_xor<T>(m);
|
operators::assign_xor<T>(m);
|
||||||
operators::assign_bitwise_or<T>(m);
|
operators::assign_bitwise_or<T>(m);
|
||||||
operators::assign_difference<T>(m);
|
// operators::assign_difference<T>(m);
|
||||||
operators::assign_left_shift<T>(m);
|
operators::assign_left_shift<T>(m);
|
||||||
operators::assign_product<T>(m);
|
// operators::assign_product<T>(m);
|
||||||
operators::assign_quotient<T>(m);
|
// operators::assign_quotient<T>(m);
|
||||||
operators::assign_remainder<T>(m);
|
// operators::assign_remainder<T>(m);
|
||||||
operators::assign_right_shift<T>(m);
|
operators::assign_right_shift<T>(m);
|
||||||
operators::assign_sum<T>(m);
|
// operators::assign_sum<T>(m);
|
||||||
|
|
||||||
operators::prefix_decrement<T>(m);
|
// operators::prefix_decrement<T>(m);
|
||||||
operators::prefix_increment<T>(m);
|
// operators::prefix_increment<T>(m);
|
||||||
operators::addition<T>(m);
|
// operators::addition<T>(m);
|
||||||
operators::unary_plus<T>(m);
|
operators::unary_plus<T>(m);
|
||||||
operators::subtraction<T>(m);
|
// operators::subtraction<T>(m);
|
||||||
operators::unary_minus<T>(m);
|
operators::unary_minus<T>(m);
|
||||||
operators::bitwise_and<T>(m);
|
operators::bitwise_and<T>(m);
|
||||||
operators::bitwise_compliment<T>(m);
|
operators::bitwise_compliment<T>(m);
|
||||||
operators::bitwise_xor<T>(m);
|
operators::bitwise_xor<T>(m);
|
||||||
operators::bitwise_or<T>(m);
|
operators::bitwise_or<T>(m);
|
||||||
operators::division<T>(m);
|
// operators::division<T>(m);
|
||||||
operators::left_shift<T>(m);
|
operators::left_shift<T>(m);
|
||||||
operators::multiplication<T>(m);
|
// operators::multiplication<T>(m);
|
||||||
operators::remainder<T>(m);
|
operators::remainder<T>(m);
|
||||||
operators::right_shift<T>(m);
|
operators::right_shift<T>(m);
|
||||||
return m;
|
return m;
|
||||||
@ -268,17 +209,17 @@ namespace chaiscript
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
ModulePtr opers_float_arithmetic(ModulePtr m = ModulePtr(new Module()))
|
ModulePtr opers_float_arithmetic(ModulePtr m = ModulePtr(new Module()))
|
||||||
{
|
{
|
||||||
operators::assign_difference<T>(m);
|
// operators::assign_difference<T>(m);
|
||||||
operators::assign_product<T>(m);
|
// operators::assign_product<T>(m);
|
||||||
operators::assign_quotient<T>(m);
|
// operators::assign_quotient<T>(m);
|
||||||
operators::assign_sum<T>(m);
|
// operators::assign_sum<T>(m);
|
||||||
|
|
||||||
operators::addition<T>(m);
|
// operators::addition<T>(m);
|
||||||
operators::unary_plus<T>(m);
|
operators::unary_plus<T>(m);
|
||||||
operators::subtraction<T>(m);
|
// operators::subtraction<T>(m);
|
||||||
operators::unary_minus<T>(m);
|
operators::unary_minus<T>(m);
|
||||||
operators::division<T>(m);
|
// operators::division<T>(m);
|
||||||
operators::multiplication<T>(m);
|
// operators::multiplication<T>(m);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,10 +306,10 @@ namespace chaiscript
|
|||||||
oper_assign_pod<T>(m);
|
oper_assign_pod<T>(m);
|
||||||
construct_pod<T>(name, m);
|
construct_pod<T>(name, m);
|
||||||
|
|
||||||
m->add(fun(&detail::assign_sum_pod<T>), "+=");
|
// m->add(fun(&detail::assign_sum_pod<T>), "+=");
|
||||||
m->add(fun(&detail::assign_difference_pod<T>), "-=");
|
// m->add(fun(&detail::assign_difference_pod<T>), "-=");
|
||||||
m->add(fun(&detail::assign_product_pod<T>), "*=");
|
// m->add(fun(&detail::assign_product_pod<T>), "*=");
|
||||||
m->add(fun(&detail::assign_quotient_pod<T>), "/=");
|
// m->add(fun(&detail::assign_quotient_pod<T>), "/=");
|
||||||
|
|
||||||
m->add(fun(&to_string<T>), "to_string");
|
m->add(fun(&to_string<T>), "to_string");
|
||||||
m->add(fun(&parse_string<T>), "to_" + name);
|
m->add(fun(&parse_string<T>), "to_" + name);
|
||||||
@ -495,6 +436,12 @@ namespace chaiscript
|
|||||||
m->add(fun(&operators::multiplication<Boxed_Value, Boxed_Numeric, Boxed_Numeric>), "*");
|
m->add(fun(&operators::multiplication<Boxed_Value, Boxed_Numeric, Boxed_Numeric>), "*");
|
||||||
m->add(fun(&operators::remainder<Boxed_Value, Boxed_Numeric, Boxed_Numeric>), "%");
|
m->add(fun(&operators::remainder<Boxed_Value, Boxed_Numeric, Boxed_Numeric>), "%");
|
||||||
m->add(fun(&operators::right_shift<Boxed_Value, Boxed_Numeric, Boxed_Numeric>), ">>");
|
m->add(fun(&operators::right_shift<Boxed_Value, Boxed_Numeric, Boxed_Numeric>), ">>");
|
||||||
|
m->add(fun(&Boxed_Numeric::operator*=), "*=");
|
||||||
|
m->add(fun(&Boxed_Numeric::operator/=), "/=");
|
||||||
|
m->add(fun(&Boxed_Numeric::operator+=), "+=");
|
||||||
|
m->add(fun(&Boxed_Numeric::operator-=), "-=");
|
||||||
|
m->add(fun(&Boxed_Numeric::operator--), "--");
|
||||||
|
m->add(fun(&Boxed_Numeric::operator++), "++");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,17 +20,200 @@ namespace chaiscript
|
|||||||
/// \brief Represents any numeric type, generically. Used internally for generic operations between POD values
|
/// \brief Represents any numeric type, generically. Used internally for generic operations between POD values
|
||||||
class Boxed_Numeric
|
class Boxed_Numeric
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
template<typename T, bool Const>
|
||||||
|
struct choose_const
|
||||||
|
{
|
||||||
|
typedef T& type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct choose_const<T, true>
|
||||||
|
{
|
||||||
|
typedef const T& type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename O, typename T>
|
||||||
|
struct lhs_type
|
||||||
|
{
|
||||||
|
typedef typename choose_const<T, O::lhs_const>::type type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct equals
|
||||||
|
{
|
||||||
|
static const bool lhs_const = true;
|
||||||
|
template<typename T, typename U>
|
||||||
|
static bool go(const T &t, const U &u) { return t == u; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct add
|
||||||
|
{
|
||||||
|
static const bool lhs_const = true;
|
||||||
|
template<typename T, typename U>
|
||||||
|
static Boxed_Value go(const T &t, const U &u) { return const_var(t + u); }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct subtract
|
||||||
|
{
|
||||||
|
static const bool lhs_const = true;
|
||||||
|
template<typename T, typename U>
|
||||||
|
static Boxed_Value go(const T &t, const U &u) { return const_var(t - u); }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct multiply
|
||||||
|
{
|
||||||
|
static const bool lhs_const = true;
|
||||||
|
template<typename T, typename U>
|
||||||
|
static Boxed_Value go(const T &t, const U &u) { return const_var(t * u); }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct divide
|
||||||
|
{
|
||||||
|
static const bool lhs_const = true;
|
||||||
|
template<typename T, typename U>
|
||||||
|
static Boxed_Value go(const T &t, const U &u) { return const_var(t / u); }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct assign_product
|
||||||
|
{
|
||||||
|
static const bool lhs_const = false;
|
||||||
|
template<typename T, typename U>
|
||||||
|
static Boxed_Value go(T &t, const U &u) { return var(&(t *= u)); }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct assign_quotient
|
||||||
|
{
|
||||||
|
static const bool lhs_const = false;
|
||||||
|
template<typename T, typename U>
|
||||||
|
static Boxed_Value go(T &t, const U &u) { return var(&(t /= u)); }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct assign_sum
|
||||||
|
{
|
||||||
|
static const bool lhs_const = false;
|
||||||
|
template<typename T, typename U>
|
||||||
|
static Boxed_Value go(T &t, const U &u) { return var(&(t += u)); }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct assign_difference
|
||||||
|
{
|
||||||
|
static const bool lhs_const = false;
|
||||||
|
template<typename T, typename U>
|
||||||
|
static Boxed_Value go(T &t, const U &u) { return var(&(t -= u)); }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct pre_increment
|
||||||
|
{
|
||||||
|
static const bool lhs_const = false;
|
||||||
|
template<typename T, typename U>
|
||||||
|
static Boxed_Value go(T &t, const U) { return var(&++t); }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct pre_decrement
|
||||||
|
{
|
||||||
|
static const bool lhs_const = false;
|
||||||
|
|
||||||
|
template<typename U>
|
||||||
|
static Boxed_Value go(boost::reference_wrapper<bool>, const U) { std::cout<< "why where?"<< std::endl; throw boost::bad_any_cast(); }
|
||||||
|
|
||||||
|
template<typename T, typename U>
|
||||||
|
static Boxed_Value go(T &t, const U) { return var(&--t); }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Ret, typename O, typename L>
|
||||||
|
static Ret oper_lhs(L l, const Boxed_Numeric &r)
|
||||||
|
{
|
||||||
|
const Type_Info &inp_ = r.bv.get_type_info();
|
||||||
|
|
||||||
|
if (inp_ == typeid(double))
|
||||||
|
{
|
||||||
|
return O::go(l, boxed_cast<const double &>(r.bv));
|
||||||
|
} else if (inp_ == typeid(float)) {
|
||||||
|
return O::go(l, boxed_cast<const float&>(r.bv));
|
||||||
|
} else if (inp_ == typeid(bool)) {
|
||||||
|
return O::go(l, boxed_cast<const bool&>(r.bv));
|
||||||
|
} else if (inp_ == typeid(char)) {
|
||||||
|
return O::go(l, boxed_cast<const char&>(r.bv));
|
||||||
|
} else if (inp_ == typeid(int)) {
|
||||||
|
return O::go(l, boxed_cast<const int&>(r.bv));
|
||||||
|
} else if (inp_ == typeid(unsigned int)) {
|
||||||
|
return O::go(l, boxed_cast<const unsigned int&>(r.bv));
|
||||||
|
} else if (inp_ == typeid(long)) {
|
||||||
|
return O::go(l, boxed_cast<const long&>(r.bv));
|
||||||
|
} else if (inp_ == typeid(unsigned long)) {
|
||||||
|
return O::go(l, boxed_cast<const unsigned long&>(r.bv));
|
||||||
|
} else if (inp_ == typeid(boost::int8_t)) {
|
||||||
|
return O::go(l, boxed_cast<const boost::int8_t &>(r.bv));
|
||||||
|
} else if (inp_ == typeid(boost::int16_t)) {
|
||||||
|
return O::go(l, boxed_cast<const boost::int16_t &>(r.bv));
|
||||||
|
} else if (inp_ == typeid(boost::int32_t)) {
|
||||||
|
return O::go(l, boxed_cast<const boost::int32_t &>(r.bv));
|
||||||
|
} else if (inp_ == typeid(boost::int64_t)) {
|
||||||
|
return O::go(l, boxed_cast<const boost::int64_t &>(r.bv));
|
||||||
|
} else if (inp_ == typeid(boost::uint8_t)) {
|
||||||
|
return O::go(l, boxed_cast<const boost::uint8_t &>(r.bv));
|
||||||
|
} else if (inp_ == typeid(boost::uint16_t)) {
|
||||||
|
return O::go(l, boxed_cast<const boost::uint16_t &>(r.bv));
|
||||||
|
} else if (inp_ == typeid(boost::uint32_t)) {
|
||||||
|
return O::go(l, boxed_cast<const boost::uint32_t &>(r.bv));
|
||||||
|
} else {
|
||||||
|
throw boost::bad_any_cast();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Ret, typename O>
|
||||||
|
static Ret oper(const Boxed_Numeric &l, const Boxed_Numeric &r)
|
||||||
|
{
|
||||||
|
const Type_Info &inp_ = l.bv.get_type_info();
|
||||||
|
|
||||||
|
if (inp_ == typeid(double))
|
||||||
|
{
|
||||||
|
return oper_lhs<Ret, O>(boxed_cast<typename lhs_type<O, double>::type>(l.bv), r);
|
||||||
|
} else if (inp_ == typeid(float)) {
|
||||||
|
return oper_lhs<Ret, O>(boxed_cast<typename lhs_type<O, float>::type>(l.bv), r);
|
||||||
|
} else if (inp_ == typeid(bool)) {
|
||||||
|
return oper_lhs<Ret, O>(boxed_cast<typename lhs_type<O, bool>::type>(l.bv), r);
|
||||||
|
} else if (inp_ == typeid(char)) {
|
||||||
|
return oper_lhs<Ret, O>(boxed_cast<typename lhs_type<O, char>::type>(l.bv), r);
|
||||||
|
} else if (inp_ == typeid(int)) {
|
||||||
|
return oper_lhs<Ret, O>(boxed_cast<typename lhs_type<O, int>::type>(l.bv), r);
|
||||||
|
} else if (inp_ == typeid(unsigned int)) {
|
||||||
|
return oper_lhs<Ret, O>(boxed_cast<typename lhs_type<O, unsigned int>::type>(l.bv), r);
|
||||||
|
} else if (inp_ == typeid(long)) {
|
||||||
|
return oper_lhs<Ret, O>(boxed_cast<typename lhs_type<O, long>::type>(l.bv), r);
|
||||||
|
} else if (inp_ == typeid(unsigned long)) {
|
||||||
|
return oper_lhs<Ret, O>(boxed_cast<typename lhs_type<O, unsigned long>::type>(l.bv), r);
|
||||||
|
} else if (inp_ == typeid(boost::int8_t)) {
|
||||||
|
return oper_lhs<Ret, O>(boxed_cast<typename lhs_type<O, boost::int8_t>::type>(l.bv), r);
|
||||||
|
} else if (inp_ == typeid(boost::int16_t)) {
|
||||||
|
return oper_lhs<Ret, O>(boxed_cast<typename lhs_type<O, boost::int32_t>::type>(l.bv), r);
|
||||||
|
} else if (inp_ == typeid(boost::int32_t)) {
|
||||||
|
return oper_lhs<Ret, O>(boxed_cast<typename lhs_type<O, boost::int32_t>::type>(l.bv), r);
|
||||||
|
} else if (inp_ == typeid(boost::int64_t)) {
|
||||||
|
return oper_lhs<Ret, O>(boxed_cast<typename lhs_type<O, boost::int64_t>::type>(l.bv), r);
|
||||||
|
} else if (inp_ == typeid(boost::uint8_t)) {
|
||||||
|
return oper_lhs<Ret, O>(boxed_cast<typename lhs_type<O, boost::uint8_t>::type>(l.bv), r);
|
||||||
|
} else if (inp_ == typeid(boost::uint16_t)) {
|
||||||
|
return oper_lhs<Ret, O>(boxed_cast<typename lhs_type<O, boost::uint16_t>::type>(l.bv), r);
|
||||||
|
} else if (inp_ == typeid(boost::uint32_t)) {
|
||||||
|
return oper_lhs<Ret, O>(boxed_cast<typename lhs_type<O, boost::uint32_t>::type>(l.bv), r);
|
||||||
|
} else {
|
||||||
|
throw boost::bad_any_cast();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Boxed_Numeric(const Boxed_Value &v)
|
Boxed_Numeric(const Boxed_Value &v)
|
||||||
: d(0), i(0), isfloat(false)
|
: bv(v), d(0), i(0), isfloat(false)
|
||||||
{
|
{
|
||||||
if (v.get_type_info().is_undef())
|
const Type_Info &inp_ = v.get_type_info();
|
||||||
|
|
||||||
|
if (!inp_.is_arithmetic())
|
||||||
{
|
{
|
||||||
throw boost::bad_any_cast();
|
throw boost::bad_any_cast();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Type_Info &inp_ = v.get_type_info();
|
|
||||||
|
|
||||||
if (inp_ == typeid(double))
|
if (inp_ == typeid(double))
|
||||||
{
|
{
|
||||||
d = boxed_cast<double>(v);
|
d = boxed_cast<double>(v);
|
||||||
@ -71,7 +254,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
bool operator==(const Boxed_Numeric &r) const
|
bool operator==(const Boxed_Numeric &r) const
|
||||||
{
|
{
|
||||||
return ((isfloat)?d:i) == ((r.isfloat)?r.d:r.i);
|
return oper<bool, equals>(*this, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<(const Boxed_Numeric &r) const
|
bool operator<(const Boxed_Numeric &r) const
|
||||||
@ -99,24 +282,24 @@ namespace chaiscript
|
|||||||
return ((isfloat)?d:i) != ((r.isfloat)?r.d:r.i);
|
return ((isfloat)?d:i) != ((r.isfloat)?r.d:r.i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Boxed_Value operator--() const
|
||||||
|
{
|
||||||
|
return oper<Boxed_Value, pre_decrement>(*this, var(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Value operator++() const
|
||||||
|
{
|
||||||
|
return oper<Boxed_Value, pre_increment>(*this, var(0));
|
||||||
|
}
|
||||||
|
|
||||||
Boxed_Value operator+(const Boxed_Numeric &r) const
|
Boxed_Value operator+(const Boxed_Numeric &r) const
|
||||||
{
|
{
|
||||||
if (!isfloat && !r.isfloat)
|
return oper<Boxed_Value, add>(*this, r);
|
||||||
{
|
|
||||||
return smart_size(i + r.i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Boxed_Value(((isfloat)?d:i) + ((r.isfloat)?r.d:r.i));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxed_Value operator-(const Boxed_Numeric &r) const
|
Boxed_Value operator-(const Boxed_Numeric &r) const
|
||||||
{
|
{
|
||||||
if (!isfloat && !r.isfloat)
|
return oper<Boxed_Value, subtract>(*this, r);
|
||||||
{
|
|
||||||
return smart_size(i - r.i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Boxed_Value(((isfloat)?d:i) - ((r.isfloat)?r.d:r.i));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxed_Value operator&(const Boxed_Numeric &r) const
|
Boxed_Value operator&(const Boxed_Numeric &r) const
|
||||||
@ -149,14 +332,26 @@ namespace chaiscript
|
|||||||
throw exception::bad_boxed_cast("| only valid for integer types");
|
throw exception::bad_boxed_cast("| only valid for integer types");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Boxed_Value operator*=(const Boxed_Numeric &r) const
|
||||||
|
{
|
||||||
|
return oper<Boxed_Value, assign_product>(*this, r);
|
||||||
|
}
|
||||||
|
Boxed_Value operator/=(const Boxed_Numeric &r) const
|
||||||
|
{
|
||||||
|
return oper<Boxed_Value, assign_quotient>(*this, r);
|
||||||
|
}
|
||||||
|
Boxed_Value operator+=(const Boxed_Numeric &r) const
|
||||||
|
{
|
||||||
|
return oper<Boxed_Value, assign_sum>(*this, r);
|
||||||
|
}
|
||||||
|
Boxed_Value operator-=(const Boxed_Numeric &r) const
|
||||||
|
{
|
||||||
|
return oper<Boxed_Value, assign_difference>(*this, r);
|
||||||
|
}
|
||||||
|
|
||||||
Boxed_Value operator/(const Boxed_Numeric &r) const
|
Boxed_Value operator/(const Boxed_Numeric &r) const
|
||||||
{
|
{
|
||||||
if (!isfloat && !r.isfloat)
|
return oper<Boxed_Value, divide>(*this, r);
|
||||||
{
|
|
||||||
return smart_size(i / r.i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Boxed_Value(((isfloat)?d:i) / ((r.isfloat)?r.d:r.i));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Boxed_Value operator<<(const Boxed_Numeric &r) const
|
Boxed_Value operator<<(const Boxed_Numeric &r) const
|
||||||
@ -172,12 +367,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
Boxed_Value operator*(const Boxed_Numeric &r) const
|
Boxed_Value operator*(const Boxed_Numeric &r) const
|
||||||
{
|
{
|
||||||
if (!isfloat && !r.isfloat)
|
return oper<Boxed_Value, multiply>(*this, r);
|
||||||
{
|
|
||||||
return smart_size(i * r.i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Boxed_Value(((isfloat)?d:i) * ((r.isfloat)?r.d:r.i));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -213,6 +403,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Boxed_Value bv;
|
||||||
double d;
|
double d;
|
||||||
boost::int64_t i;
|
boost::int64_t i;
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <boost/type_traits/is_void.hpp>
|
#include <boost/type_traits/is_void.hpp>
|
||||||
#include <boost/type_traits/is_reference.hpp>
|
#include <boost/type_traits/is_reference.hpp>
|
||||||
#include <boost/type_traits/is_pointer.hpp>
|
#include <boost/type_traits/is_pointer.hpp>
|
||||||
|
#include <boost/type_traits/is_arithmetic.hpp>
|
||||||
#include <boost/type_traits/remove_const.hpp>
|
#include <boost/type_traits/remove_const.hpp>
|
||||||
#include <boost/type_traits/remove_reference.hpp>
|
#include <boost/type_traits/remove_reference.hpp>
|
||||||
#include <boost/type_traits/remove_pointer.hpp>
|
#include <boost/type_traits/remove_pointer.hpp>
|
||||||
@ -36,9 +37,9 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void,
|
Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void,
|
||||||
const std::type_info *t_ti, const std::type_info *t_bareti)
|
bool t_is_arithmetic, const std::type_info *t_ti, const std::type_info *t_bareti)
|
||||||
: m_is_const(t_is_const), m_is_reference(t_is_reference), m_is_pointer(t_is_pointer),
|
: m_is_const(t_is_const), m_is_reference(t_is_reference), m_is_pointer(t_is_pointer),
|
||||||
m_is_void(t_is_void),
|
m_is_void(t_is_void), m_is_arithmetic(t_is_arithmetic),
|
||||||
m_type_info(t_ti), m_bare_type_info(t_bareti),
|
m_type_info(t_ti), m_bare_type_info(t_bareti),
|
||||||
m_is_undef(false)
|
m_is_undef(false)
|
||||||
{
|
{
|
||||||
@ -46,7 +47,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
Type_Info()
|
Type_Info()
|
||||||
: m_is_const(false), m_is_reference(false), m_is_pointer(false),
|
: m_is_const(false), m_is_reference(false), m_is_pointer(false),
|
||||||
m_is_void(false), m_type_info(0), m_bare_type_info(0),
|
m_is_void(false), m_is_arithmetic(false), m_type_info(0), m_bare_type_info(0),
|
||||||
m_is_undef(true)
|
m_is_undef(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -54,7 +55,8 @@ namespace chaiscript
|
|||||||
Type_Info(const Type_Info &ti)
|
Type_Info(const Type_Info &ti)
|
||||||
: m_is_const(ti.m_is_const), m_is_reference(ti.m_is_reference),
|
: m_is_const(ti.m_is_const), m_is_reference(ti.m_is_reference),
|
||||||
m_is_pointer(ti.m_is_pointer),
|
m_is_pointer(ti.m_is_pointer),
|
||||||
m_is_void(ti.m_is_void), m_type_info(ti.m_type_info),
|
m_is_void(ti.m_is_void), m_is_arithmetic(ti.m_is_arithmetic),
|
||||||
|
m_type_info(ti.m_type_info),
|
||||||
m_bare_type_info(ti.m_bare_type_info),
|
m_bare_type_info(ti.m_bare_type_info),
|
||||||
m_is_undef(ti.m_is_undef)
|
m_is_undef(ti.m_is_undef)
|
||||||
{
|
{
|
||||||
@ -66,6 +68,7 @@ namespace chaiscript
|
|||||||
m_is_reference = ti.m_is_reference;
|
m_is_reference = ti.m_is_reference;
|
||||||
m_is_pointer = ti.m_is_pointer;
|
m_is_pointer = ti.m_is_pointer;
|
||||||
m_is_void = ti.m_is_void;
|
m_is_void = ti.m_is_void;
|
||||||
|
m_is_arithmetic = ti.m_is_arithmetic;
|
||||||
m_type_info = ti.m_type_info;
|
m_type_info = ti.m_type_info;
|
||||||
m_bare_type_info = ti.m_bare_type_info;
|
m_bare_type_info = ti.m_bare_type_info;
|
||||||
m_is_undef = ti.m_is_undef;
|
m_is_undef = ti.m_is_undef;
|
||||||
@ -97,6 +100,7 @@ namespace chaiscript
|
|||||||
bool is_const() const { return m_is_const; }
|
bool is_const() const { return m_is_const; }
|
||||||
bool is_reference() const { return m_is_reference; }
|
bool is_reference() const { return m_is_reference; }
|
||||||
bool is_void() const { return m_is_void; }
|
bool is_void() const { return m_is_void; }
|
||||||
|
bool is_arithmetic() const { return m_is_arithmetic; }
|
||||||
bool is_undef() const { return m_is_undef || m_bare_type_info == 0; }
|
bool is_undef() const { return m_is_undef || m_bare_type_info == 0; }
|
||||||
bool is_pointer() const { return m_is_pointer; }
|
bool is_pointer() const { return m_is_pointer; }
|
||||||
|
|
||||||
@ -125,6 +129,7 @@ namespace chaiscript
|
|||||||
bool m_is_reference;
|
bool m_is_reference;
|
||||||
bool m_is_pointer;
|
bool m_is_pointer;
|
||||||
bool m_is_void;
|
bool m_is_void;
|
||||||
|
bool m_is_arithmetic;
|
||||||
const std::type_info *m_type_info;
|
const std::type_info *m_type_info;
|
||||||
const std::type_info *m_bare_type_info;
|
const std::type_info *m_bare_type_info;
|
||||||
bool m_is_undef;
|
bool m_is_undef;
|
||||||
@ -144,6 +149,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
return Type_Info(boost::is_const<typename boost::remove_pointer<typename boost::remove_reference<T>::type>::type>::value, boost::is_reference<T>::value, boost::is_pointer<T>::value,
|
return Type_Info(boost::is_const<typename boost::remove_pointer<typename boost::remove_reference<T>::type>::type>::value, boost::is_reference<T>::value, boost::is_pointer<T>::value,
|
||||||
boost::is_void<T>::value,
|
boost::is_void<T>::value,
|
||||||
|
boost::is_arithmetic<T>::value,
|
||||||
&typeid(T),
|
&typeid(T),
|
||||||
&typeid(typename Bare_Type<T>::type));
|
&typeid(typename Bare_Type<T>::type));
|
||||||
}
|
}
|
||||||
@ -158,6 +164,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
return Type_Info(boost::is_const<T>::value, boost::is_reference<T>::value, boost::is_pointer<T>::value,
|
return Type_Info(boost::is_const<T>::value, boost::is_reference<T>::value, boost::is_pointer<T>::value,
|
||||||
boost::is_void<T>::value,
|
boost::is_void<T>::value,
|
||||||
|
boost::is_arithmetic<T>::value,
|
||||||
&typeid(boost::shared_ptr<T> ),
|
&typeid(boost::shared_ptr<T> ),
|
||||||
&typeid(typename Bare_Type<T>::type));
|
&typeid(typename Bare_Type<T>::type));
|
||||||
}
|
}
|
||||||
@ -172,6 +179,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
return Type_Info(boost::is_const<T>::value, boost::is_reference<T>::value, boost::is_pointer<T>::value,
|
return Type_Info(boost::is_const<T>::value, boost::is_reference<T>::value, boost::is_pointer<T>::value,
|
||||||
boost::is_void<T>::value,
|
boost::is_void<T>::value,
|
||||||
|
boost::is_arithmetic<T>::value,
|
||||||
&typeid(const boost::shared_ptr<T> &),
|
&typeid(const boost::shared_ptr<T> &),
|
||||||
&typeid(typename Bare_Type<T>::type));
|
&typeid(typename Bare_Type<T>::type));
|
||||||
}
|
}
|
||||||
@ -186,6 +194,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
return Type_Info(boost::is_const<T>::value, boost::is_reference<T>::value, boost::is_pointer<T>::value,
|
return Type_Info(boost::is_const<T>::value, boost::is_reference<T>::value, boost::is_pointer<T>::value,
|
||||||
boost::is_void<T>::value,
|
boost::is_void<T>::value,
|
||||||
|
boost::is_arithmetic<T>::value,
|
||||||
&typeid(boost::reference_wrapper<T> ),
|
&typeid(boost::reference_wrapper<T> ),
|
||||||
&typeid(typename Bare_Type<T>::type));
|
&typeid(typename Bare_Type<T>::type));
|
||||||
}
|
}
|
||||||
@ -200,6 +209,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
return Type_Info(boost::is_const<T>::value, boost::is_reference<T>::value, boost::is_pointer<T>::value,
|
return Type_Info(boost::is_const<T>::value, boost::is_reference<T>::value, boost::is_pointer<T>::value,
|
||||||
boost::is_void<T>::value,
|
boost::is_void<T>::value,
|
||||||
|
boost::is_arithmetic<T>::value,
|
||||||
&typeid(const boost::reference_wrapper<T> &),
|
&typeid(const boost::reference_wrapper<T> &),
|
||||||
&typeid(typename Bare_Type<T>::type));
|
&typeid(typename Bare_Type<T>::type));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user