xo-numeric: + cmple for op<=

This commit is contained in:
Roland Conybeare 2026-03-12 20:54:23 -05:00
commit 1a60284861
12 changed files with 86 additions and 56 deletions

View file

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

View file

@ -60,6 +60,13 @@ namespace xo {
{
return DBoolean::box<AGCObject>(rcx.allocator(), x->value() < y->value());
}
obj<AGCObject>
FloatOps::cmp_lessequal(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(), x->value() <= y->value());
}
}
}

View file

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

View file

@ -99,18 +99,6 @@ namespace xo {
"incomparable types in x+y",
&AnonymizedNumericOps::add_,
x, y);
#ifdef OBSOLETE
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());
#endif
}
obj<AGCObject>
@ -123,18 +111,6 @@ namespace xo {
"incomparable types in x-y",
&AnonymizedNumericOps::subtract_,
x, y);
#ifdef OBSOLETE
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());
#endif
}
obj<AGCObject>
@ -148,27 +124,6 @@ namespace xo {
&AnonymizedNumericOps::cmpeq_,
x, y);
#ifdef OBSOLETE
KeyType key(x._typeseq(), y._typeseq());
auto target_fn
= NumericDispatch::instance().dispatch_[key].cmpeq_;
if (!target_fn) {
// FIXME: use {fmt} here
std::stringstream ss;
tosn(ss,
"incomparable types in x==y",
xtag("x.type", TypeRegistry::id2name(x._typeseq())),
xtag("y.type", TypeRegistry::id2name(y._typeseq())));
return DRuntimeError::make(rcx.allocator(),
"NumericDispatch::cmp_equal",
ss.str().c_str());
}
return (*target_fn)(rcx, x.data(), y.data());
#endif
}
obj<AGCObject>
@ -195,6 +150,18 @@ namespace xo {
x, y);
}
obj<AGCObject>
NumericDispatch::cmp_lessequal(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y)
{
return dispatch(rcx,
"NumericDispatch::cmp_lessequal",
"incomparable types in x<=y",
&AnonymizedNumericOps::cmple_,
x, y);
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -61,6 +61,13 @@ namespace xo {
&NumericDispatch::cmp_less);
}
DPrimitive_gco_2_gco_gco *
NumericPrimitives::make_cmple_pm(obj<AAllocator> mm)
{
return DPrimitive_gco_2_gco_gco::_make(mm, "_cmple",
&NumericDispatch::cmp_lessequal);
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -41,7 +41,8 @@ namespace xo {
&FloatOps::subtract,
&FloatOps::cmp_equal,
&FloatOps::cmp_notequal,
&FloatOps::cmp_less);
&FloatOps::cmp_less,
&FloatOps::cmp_lessequal);
NumericDispatch::instance().register_impl<DFloat, DInteger>
(&FloatIntegerOps::multiply,
@ -50,7 +51,8 @@ namespace xo {
&FloatIntegerOps::subtract,
&FloatIntegerOps::cmp_equal,
&FloatIntegerOps::cmp_notequal,
&FloatIntegerOps::cmp_less);
&FloatIntegerOps::cmp_less,
&FloatIntegerOps::cmp_lessequal);
NumericDispatch::instance().register_impl<DInteger, DFloat>
(&IntegerFloatOps::multiply,
@ -59,7 +61,8 @@ namespace xo {
&IntegerFloatOps::subtract,
&IntegerFloatOps::cmp_equal,
&IntegerFloatOps::cmp_notequal,
&IntegerFloatOps::cmp_less);
&IntegerFloatOps::cmp_less,
&IntegerFloatOps::cmp_lessequal);
NumericDispatch::instance().register_impl<DInteger, DInteger>
(&IntegerOps::multiply,
@ -68,7 +71,8 @@ namespace xo {
&IntegerOps::subtract,
&IntegerOps::cmp_equal,
&IntegerOps::cmp_notequal,
&IntegerOps::cmp_less);
&IntegerOps::cmp_less,
&IntegerOps::cmp_lessequal);
log && log(xtag("ANumeric.tseq", typeseq::id<ANumeric>()));