xo-interpreter2 stack: streamline op== impl + utests
This commit is contained in:
parent
9dca9a8c46
commit
243ad12869
12 changed files with 97 additions and 10 deletions
|
|
@ -27,6 +27,9 @@ namespace xo {
|
|||
DFloat * x, DInteger * y);
|
||||
static obj<AGCObject> subtract(obj<ARuntimeContext> rcx,
|
||||
DFloat * x, DInteger * y);
|
||||
|
||||
static obj<AGCObject> cmp_equal(obj<ARuntimeContext> rcx,
|
||||
DFloat * x, DInteger * y);
|
||||
};
|
||||
|
||||
class IntegerFloatOps {
|
||||
|
|
@ -42,6 +45,9 @@ namespace xo {
|
|||
DInteger * x, DFloat * y);
|
||||
static obj<AGCObject> subtract(obj<ARuntimeContext> rcx,
|
||||
DInteger * x, DFloat * y);
|
||||
|
||||
static obj<AGCObject> cmp_equal(obj<ARuntimeContext> rcx,
|
||||
DInteger * x, DFloat * y);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ namespace xo {
|
|||
DFloat * x, DFloat * y);
|
||||
static obj<AGCObject> subtract(obj<ARuntimeContext> rcx,
|
||||
DFloat * x, DFloat * y);
|
||||
|
||||
static obj<AGCObject> cmp_equal(obj<ARuntimeContext> rcx,
|
||||
DFloat * x, DFloat * y);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ namespace xo {
|
|||
static obj<AGCObject> subtract(obj<ARuntimeContext> rcx,
|
||||
DInteger * x, DInteger * y);
|
||||
|
||||
static obj<AGCObject> cmp_equal(obj<ARuntimeContext> rcx,
|
||||
DInteger * x, DInteger * y);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,6 +82,11 @@ namespace xo {
|
|||
obj<AGCObject> x,
|
||||
obj<AGCObject> y);
|
||||
|
||||
/** compare two numeric values for equality **/
|
||||
static obj<AGCObject> cmp_equal(obj<ARuntimeContext> rcx,
|
||||
obj<AGCObject> x,
|
||||
obj<AGCObject> y);
|
||||
|
||||
/** report memory use for owned arenas to @p visitor **/
|
||||
void visit_pools(const MemorySizeVisitor & visitor);
|
||||
|
||||
|
|
@ -94,7 +99,8 @@ namespace xo {
|
|||
void register_impl(typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl mul_fn,
|
||||
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl div_fn,
|
||||
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl add_fn,
|
||||
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl sub_fn) {
|
||||
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl sub_fn,
|
||||
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl cmpeq_fn) {
|
||||
|
||||
KeyType key(typeseq::id<DRepr1>().seqno(),
|
||||
typeseq::id<DRepr2>().seqno());
|
||||
|
|
@ -104,7 +110,8 @@ namespace xo {
|
|||
= NumericOps<DRepr1, DRepr2>::make(mul_fn,
|
||||
div_fn,
|
||||
add_fn,
|
||||
sub_fn);
|
||||
sub_fn,
|
||||
cmpeq_fn);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -25,13 +25,18 @@ namespace xo {
|
|||
explicit AnonymizedNumericOps(BinaryOp multiply,
|
||||
BinaryOp divide,
|
||||
BinaryOp add,
|
||||
BinaryOp subtract)
|
||||
: multiply_{multiply}, divide_{divide}, add_{add}, subtract_{subtract} {}
|
||||
BinaryOp subtract,
|
||||
BinaryOp cmpeq)
|
||||
: multiply_{multiply}, divide_{divide}, add_{add}, subtract_{subtract},
|
||||
cmpeq_{cmpeq} {}
|
||||
|
||||
BinaryOp multiply_ = nullptr;
|
||||
BinaryOp divide_ = nullptr;
|
||||
BinaryOp add_ = nullptr;
|
||||
BinaryOp subtract_ = nullptr;
|
||||
|
||||
/** compare numerics for equality **/
|
||||
BinaryOp cmpeq_ = nullptr;
|
||||
};
|
||||
|
||||
template <typename DRepr1, typename DRepr2>
|
||||
|
|
@ -46,11 +51,13 @@ namespace xo {
|
|||
static AnonymizedNumericOps make(BinaryOp_Impl multiply,
|
||||
BinaryOp_Impl divide,
|
||||
BinaryOp_Impl add,
|
||||
BinaryOp_Impl subtract) {
|
||||
BinaryOp_Impl subtract,
|
||||
BinaryOp_Impl cmpeq) {
|
||||
return AnonymizedNumericOps(reinterpret_cast<BinaryOp_Anon>(multiply),
|
||||
reinterpret_cast<BinaryOp_Anon>(divide),
|
||||
reinterpret_cast<BinaryOp_Anon>(add),
|
||||
reinterpret_cast<BinaryOp_Anon>(subtract));
|
||||
reinterpret_cast<BinaryOp_Anon>(subtract),
|
||||
reinterpret_cast<BinaryOp_Anon>(cmpeq));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ namespace xo {
|
|||
static DPrimitive_gco_2_gco_gco s_add_gco_gco_pm;
|
||||
/** polymorphic (in both arguments) subtract **/
|
||||
static DPrimitive_gco_2_gco_gco s_sub_gco_gco_pm;
|
||||
|
||||
/** polymorphic (in both arguments) compare (==) **/
|
||||
static DPrimitive_gco_2_gco_gco s_cmpeq_gco_gco_pm;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "FloatIntegerOps.hpp"
|
||||
#include "float/INumeric_DFloat.hpp"
|
||||
#include <xo/object2/Boolean.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AGCObject;
|
||||
|
|
@ -41,6 +42,14 @@ namespace xo {
|
|||
return DFloat::box<AGCObject>(rcx.allocator(), x->value() - y->value());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
FloatIntegerOps::cmp_equal(obj<ARuntimeContext> rcx,
|
||||
DFloat * x, DInteger * y)
|
||||
{
|
||||
return DBoolean::box<AGCObject>(rcx.allocator(),
|
||||
x->value() == DFloat::value_type(y->value()));
|
||||
}
|
||||
|
||||
// ----- Integer op Float -----
|
||||
|
||||
obj<AGCObject>
|
||||
|
|
@ -71,6 +80,14 @@ namespace xo {
|
|||
return DFloat::box<AGCObject>(rcx.allocator(), x->value() - y->value());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
IntegerFloatOps::cmp_equal(obj<ARuntimeContext> rcx,
|
||||
DInteger * x, DFloat * y)
|
||||
{
|
||||
return DFloat::box<AGCObject>(rcx.allocator(),
|
||||
DFloat::value_type(x->value() == y->value()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "FloatOps.hpp"
|
||||
#include "float/INumeric_DFloat.hpp"
|
||||
#include <xo/object2/Boolean.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AGCObject;
|
||||
|
|
@ -39,6 +40,13 @@ namespace xo {
|
|||
return DFloat::box<AGCObject>(rcx.allocator(), x->value() - y->value());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
FloatOps::cmp_equal(obj<ARuntimeContext> rcx,
|
||||
DFloat * x, DFloat * y)
|
||||
{
|
||||
return DBoolean::box<AGCObject>(rcx.allocator(), x->value() == y->value());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,10 @@
|
|||
|
||||
#include "IntegerOps.hpp"
|
||||
#include "integer/INumeric_DInteger.hpp"
|
||||
#include <xo/object2/Boolean.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::scm::DBoolean;
|
||||
using xo::mm::AGCObject;
|
||||
|
||||
namespace scm {
|
||||
|
|
@ -39,6 +41,13 @@ namespace xo {
|
|||
return DInteger::box<AGCObject>(rcx.allocator(), x->value() - y->value());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
IntegerOps::cmp_equal(obj<ARuntimeContext> rcx,
|
||||
DInteger * x, DInteger * y)
|
||||
{
|
||||
return DBoolean::box<AGCObject>(rcx.allocator(), x->value() == y->value());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,6 +81,22 @@ namespace xo {
|
|||
return (*target_fn)(rcx, x.data(), y.data());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
NumericDispatch::cmp_equal(obj<ARuntimeContext> rcx,
|
||||
obj<AGCObject> x,
|
||||
obj<AGCObject> y)
|
||||
{
|
||||
KeyType key(x._typeseq(), y._typeseq());
|
||||
|
||||
auto target_fn
|
||||
= NumericDispatch::instance().dispatch_[key].cmpeq_;
|
||||
|
||||
if (!target_fn)
|
||||
assert(false);
|
||||
|
||||
return (*target_fn)(rcx, x.data(), y.data());
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@ namespace xo {
|
|||
NumericPrimitives::s_sub_gco_gco_pm("_sub",
|
||||
&NumericDispatch::subtract);
|
||||
|
||||
DPrimitive_gco_2_gco_gco
|
||||
NumericPrimitives::s_cmpeq_gco_gco_pm("_cmpeq",
|
||||
&NumericDispatch::cmp_equal);
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
|
|
@ -38,25 +38,29 @@ namespace xo {
|
|||
(&FloatOps::multiply,
|
||||
&FloatOps::divide,
|
||||
&FloatOps::add,
|
||||
&FloatOps::subtract);
|
||||
&FloatOps::subtract,
|
||||
&FloatOps::cmp_equal);
|
||||
|
||||
NumericDispatch::instance().register_impl<DFloat, DInteger>
|
||||
(&FloatIntegerOps::multiply,
|
||||
&FloatIntegerOps::divide,
|
||||
&FloatIntegerOps::add,
|
||||
&FloatIntegerOps::subtract);
|
||||
&FloatIntegerOps::subtract,
|
||||
&FloatIntegerOps::cmp_equal);
|
||||
|
||||
NumericDispatch::instance().register_impl<DInteger, DFloat>
|
||||
(&IntegerFloatOps::multiply,
|
||||
&IntegerFloatOps::divide,
|
||||
&IntegerFloatOps::add,
|
||||
&IntegerFloatOps::subtract);
|
||||
&IntegerFloatOps::subtract,
|
||||
&IntegerFloatOps::cmp_equal);
|
||||
|
||||
NumericDispatch::instance().register_impl<DInteger, DInteger>
|
||||
(&IntegerOps::multiply,
|
||||
&IntegerOps::divide,
|
||||
&IntegerOps::add,
|
||||
&IntegerOps::subtract);
|
||||
&IntegerOps::subtract,
|
||||
&IntegerOps::cmp_equal);
|
||||
|
||||
log && log(xtag("ANumeric.tseq", typeseq::id<ANumeric>()));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue