xo-numeric: + less than dispatch (also in schematika parser)

This commit is contained in:
Roland Conybeare 2026-02-27 22:55:14 +11:00
commit 5791cd59ce
12 changed files with 83 additions and 13 deletions

View file

@ -32,6 +32,8 @@ namespace xo {
DFloat * x, DInteger * y);
static obj<AGCObject> cmp_notequal(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y);
static obj<AGCObject> cmp_less(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y);
};
class IntegerFloatOps {
@ -52,6 +54,8 @@ namespace xo {
DInteger * x, DFloat * y);
static obj<AGCObject> cmp_notequal(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y);
static obj<AGCObject> cmp_less(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y);
};
}

View file

@ -31,6 +31,8 @@ namespace xo {
DFloat * x, DFloat * y);
static obj<AGCObject> cmp_notequal(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y);
static obj<AGCObject> cmp_less(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y);
};
}

View file

@ -33,6 +33,8 @@ namespace xo {
DInteger * x, DInteger * y);
static obj<AGCObject> cmp_notequal(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y);
static obj<AGCObject> cmp_less(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y);
};

View file

@ -103,6 +103,11 @@ namespace xo {
obj<AGCObject> x,
obj<AGCObject> y);
/** compare two numeric values for inequality **/
static obj<AGCObject> cmp_less(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y);
/** report memory use for owned arenas to @p visitor **/
void visit_pools(const MemorySizeVisitor & visitor);
@ -117,7 +122,8 @@ namespace xo {
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl add_fn,
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl sub_fn,
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl cmpeq_fn,
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl cmpne_fn) {
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl cmpne_fn,
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl cmplt_fn) {
KeyType key(typeseq::id<DRepr1>().seqno(),
typeseq::id<DRepr2>().seqno());
@ -129,7 +135,8 @@ namespace xo {
add_fn,
sub_fn,
cmpeq_fn,
cmpne_fn);
cmpne_fn,
cmplt_fn);
}
private:

View file

@ -27,19 +27,22 @@ namespace xo {
BinaryOp add,
BinaryOp subtract,
BinaryOp cmpeq,
BinaryOp cmpne)
BinaryOp cmpne,
BinaryOp cmplt)
: multiply_{multiply}, divide_{divide}, add_{add}, subtract_{subtract},
cmpeq_{cmpeq}, cmpne_{cmpne} {}
cmpeq_{cmpeq}, cmpne_{cmpne}, cmplt_{cmplt} {}
BinaryOp multiply_ = nullptr;
BinaryOp divide_ = nullptr;
BinaryOp add_ = nullptr;
BinaryOp subtract_ = nullptr;
/** compare numerics for equality **/
/** compare numerics (==) **/
BinaryOp cmpeq_ = nullptr;
/** compare numerics for inequality **/
/** compare numerics (!=) **/
BinaryOp cmpne_ = nullptr;
/** compare numerics (<) **/
BinaryOp cmplt_ = nullptr;
};
template <typename DRepr1, typename DRepr2>
@ -56,13 +59,15 @@ namespace xo {
BinaryOp_Impl add,
BinaryOp_Impl subtract,
BinaryOp_Impl cmpeq,
BinaryOp_Impl cmpne) {
BinaryOp_Impl cmpne,
BinaryOp_Impl cmplt) {
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>(cmpeq),
reinterpret_cast<BinaryOp_Anon>(cmpne));
reinterpret_cast<BinaryOp_Anon>(cmpne),
reinterpret_cast<BinaryOp_Anon>(cmplt));
}
};

View file

@ -27,6 +27,8 @@ namespace xo {
static DPrimitive_gco_2_gco_gco s_cmpeq_gco_gco_pm;
/** polymorphic (in both arguments) compare (!=) **/
static DPrimitive_gco_2_gco_gco s_cmpne_gco_gco_pm;
/** polymorphic (in both arguments) compare (<) **/
static DPrimitive_gco_2_gco_gco s_cmplt_gco_gco_pm;
};
}
}

View file

@ -58,6 +58,14 @@ namespace xo {
x->value() != DFloat::value_type(y->value()));
}
obj<AGCObject>
FloatIntegerOps::cmp_less(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>
@ -104,6 +112,14 @@ namespace xo {
DFloat::value_type(x->value()) != y->value());
}
obj<AGCObject>
IntegerFloatOps::cmp_less(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
DFloat::value_type(x->value()) < y->value());
}
}
}

View file

@ -54,7 +54,12 @@ namespace xo {
return DBoolean::box<AGCObject>(rcx.allocator(), x->value() != y->value());
}
obj<AGCObject>
FloatOps::cmp_less(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(), x->value() < y->value());
}
}
}

View file

@ -55,6 +55,13 @@ namespace xo {
return DBoolean::box<AGCObject>(rcx.allocator(), x->value() != y->value());
}
obj<AGCObject>
IntegerOps::cmp_less(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(), x->value() < y->value());
}
}
}

View file

@ -191,6 +191,18 @@ namespace xo {
x, y);
}
obj<AGCObject>
NumericDispatch::cmp_less(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y)
{
return dispatch(rcx,
"NumericDispatch::cmp_less",
"incomparable types in x<y",
&AnonymizedNumericOps::cmplt_,
x, y);
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -35,6 +35,10 @@ namespace xo {
NumericPrimitives::s_cmpne_gco_gco_pm("_cmpne",
&NumericDispatch::cmp_notequal);
DPrimitive_gco_2_gco_gco
NumericPrimitives::s_cmplt_gco_gco_pm("_cmplt",
&NumericDispatch::cmp_less);
} /*namespace scm*/
} /*namespace xo*/

View file

@ -40,7 +40,8 @@ namespace xo {
&FloatOps::add,
&FloatOps::subtract,
&FloatOps::cmp_equal,
&FloatOps::cmp_notequal);
&FloatOps::cmp_notequal,
&FloatOps::cmp_less);
NumericDispatch::instance().register_impl<DFloat, DInteger>
(&FloatIntegerOps::multiply,
@ -48,7 +49,8 @@ namespace xo {
&FloatIntegerOps::add,
&FloatIntegerOps::subtract,
&FloatIntegerOps::cmp_equal,
&FloatIntegerOps::cmp_notequal);
&FloatIntegerOps::cmp_notequal,
&FloatIntegerOps::cmp_less);
NumericDispatch::instance().register_impl<DInteger, DFloat>
(&IntegerFloatOps::multiply,
@ -56,7 +58,8 @@ namespace xo {
&IntegerFloatOps::add,
&IntegerFloatOps::subtract,
&IntegerFloatOps::cmp_equal,
&IntegerFloatOps::cmp_notequal);
&IntegerFloatOps::cmp_notequal,
&IntegerFloatOps::cmp_less);
NumericDispatch::instance().register_impl<DInteger, DInteger>
(&IntegerOps::multiply,
@ -64,7 +67,8 @@ namespace xo {
&IntegerOps::add,
&IntegerOps::subtract,
&IntegerOps::cmp_equal,
&IntegerOps::cmp_notequal);
&IntegerOps::cmp_notequal,
&IntegerOps::cmp_less);
log && log(xtag("ANumeric.tseq", typeseq::id<ANumeric>()));