xo-reader2 stack: use NumericDispatch for *,/,+,- ops
This commit is contained in:
parent
43f120dd10
commit
9dca9a8c46
12 changed files with 167 additions and 17 deletions
|
|
@ -27,6 +27,20 @@ namespace xo {
|
|||
return DFloat::box<AGCObject>(rcx.allocator(), x->value() / y->value());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
FloatIntegerOps::add(obj<ARuntimeContext> rcx,
|
||||
DFloat * x, DInteger * y)
|
||||
{
|
||||
return DFloat::box<AGCObject>(rcx.allocator(), x->value() + y->value());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
FloatIntegerOps::subtract(obj<ARuntimeContext> rcx,
|
||||
DFloat * x, DInteger * y)
|
||||
{
|
||||
return DFloat::box<AGCObject>(rcx.allocator(), x->value() - y->value());
|
||||
}
|
||||
|
||||
// ----- Integer op Float -----
|
||||
|
||||
obj<AGCObject>
|
||||
|
|
@ -42,6 +56,21 @@ namespace xo {
|
|||
{
|
||||
return DFloat::box<AGCObject>(rcx.allocator(), x->value() / y->value());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
IntegerFloatOps::add(obj<ARuntimeContext> rcx,
|
||||
DInteger * x, DFloat * y)
|
||||
{
|
||||
return DFloat::box<AGCObject>(rcx.allocator(), x->value() + y->value());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
IntegerFloatOps::subtract(obj<ARuntimeContext> rcx,
|
||||
DInteger * x, DFloat * y)
|
||||
{
|
||||
return DFloat::box<AGCObject>(rcx.allocator(), x->value() - y->value());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,21 @@ namespace xo {
|
|||
return DFloat::box<AGCObject>(rcx.allocator(), x->value() / y->value());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
FloatOps::add(obj<ARuntimeContext> rcx,
|
||||
DFloat * x, DFloat * y)
|
||||
{
|
||||
return DFloat::box<AGCObject>(rcx.allocator(), x->value() + y->value());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
FloatOps::subtract(obj<ARuntimeContext> rcx,
|
||||
DFloat * x, DFloat * y)
|
||||
{
|
||||
return DFloat::box<AGCObject>(rcx.allocator(), x->value() - y->value());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,20 @@ namespace xo {
|
|||
return DInteger::box<AGCObject>(rcx.allocator(), x->value() / y->value());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
IntegerOps::add(obj<ARuntimeContext> rcx,
|
||||
DInteger * x, DInteger * y)
|
||||
{
|
||||
return DInteger::box<AGCObject>(rcx.allocator(), x->value() + y->value());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
IntegerOps::subtract(obj<ARuntimeContext> rcx,
|
||||
DInteger * x, DInteger * y)
|
||||
{
|
||||
return DInteger::box<AGCObject>(rcx.allocator(), x->value() - y->value());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ namespace xo {
|
|||
auto target_fn
|
||||
= NumericDispatch::instance().dispatch_[key].multiply_;
|
||||
|
||||
if (!target_fn)
|
||||
assert(false);
|
||||
|
||||
return (*target_fn)(rcx, x.data(), y.data());
|
||||
}
|
||||
|
||||
|
|
@ -35,23 +38,48 @@ namespace xo {
|
|||
obj<AGCObject> x,
|
||||
obj<AGCObject> y)
|
||||
{
|
||||
scope log(XO_DEBUG(true));
|
||||
|
||||
KeyType key(x._typeseq(), y._typeseq());
|
||||
|
||||
log && log(xtag("x.tseq", x._typeseq().seqno()),
|
||||
xtag("y.tseq", y._typeseq().seqno()));
|
||||
|
||||
auto target_fn
|
||||
= NumericDispatch::instance().dispatch_[key].divide_;
|
||||
|
||||
log && log(xtag("target_fn", target_fn));
|
||||
|
||||
assert(target_fn);
|
||||
if (!target_fn)
|
||||
assert(false);
|
||||
|
||||
return (*target_fn)(rcx, x.data(), y.data());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
NumericDispatch::add(obj<ARuntimeContext> rcx,
|
||||
obj<AGCObject> x,
|
||||
obj<AGCObject> y)
|
||||
{
|
||||
KeyType key(x._typeseq(), y._typeseq());
|
||||
|
||||
auto target_fn
|
||||
= NumericDispatch::instance().dispatch_[key].add_;
|
||||
|
||||
if (!target_fn)
|
||||
assert(false);
|
||||
|
||||
return (*target_fn)(rcx, x.data(), y.data());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
NumericDispatch::subtract(obj<ARuntimeContext> rcx,
|
||||
obj<AGCObject> x,
|
||||
obj<AGCObject> y)
|
||||
{
|
||||
KeyType key(x._typeseq(), y._typeseq());
|
||||
|
||||
auto target_fn
|
||||
= NumericDispatch::instance().dispatch_[key].subtract_;
|
||||
|
||||
if (!target_fn)
|
||||
assert(false);
|
||||
|
||||
return (*target_fn)(rcx, x.data(), y.data());
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
|
|
@ -19,6 +19,14 @@ namespace xo {
|
|||
NumericPrimitives::s_div_gco_gco_pm("_div",
|
||||
&NumericDispatch::divide);
|
||||
|
||||
DPrimitive_gco_2_gco_gco
|
||||
NumericPrimitives::s_add_gco_gco_pm("_add",
|
||||
&NumericDispatch::add);
|
||||
|
||||
DPrimitive_gco_2_gco_gco
|
||||
NumericPrimitives::s_sub_gco_gco_pm("_sub",
|
||||
&NumericDispatch::subtract);
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
|
|
@ -36,19 +36,27 @@ namespace xo {
|
|||
|
||||
NumericDispatch::instance().register_impl<DFloat, DFloat>
|
||||
(&FloatOps::multiply,
|
||||
&FloatOps::divide);
|
||||
&FloatOps::divide,
|
||||
&FloatOps::add,
|
||||
&FloatOps::subtract);
|
||||
|
||||
NumericDispatch::instance().register_impl<DFloat, DInteger>
|
||||
(&FloatIntegerOps::multiply,
|
||||
&FloatIntegerOps::divide);
|
||||
&FloatIntegerOps::divide,
|
||||
&FloatIntegerOps::add,
|
||||
&FloatIntegerOps::subtract);
|
||||
|
||||
NumericDispatch::instance().register_impl<DInteger, DFloat>
|
||||
(&IntegerFloatOps::multiply,
|
||||
&IntegerFloatOps::divide);
|
||||
&IntegerFloatOps::divide,
|
||||
&IntegerFloatOps::add,
|
||||
&IntegerFloatOps::subtract);
|
||||
|
||||
NumericDispatch::instance().register_impl<DInteger, DInteger>
|
||||
(&IntegerOps::multiply,
|
||||
&IntegerOps::divide);
|
||||
&IntegerOps::divide,
|
||||
&IntegerOps::add,
|
||||
&IntegerOps::subtract);
|
||||
|
||||
log && log(xtag("ANumeric.tseq", typeseq::id<ANumeric>()));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue