xo-interpreter2 stack: support op!= + trial numeric refactor

This commit is contained in:
Roland Conybeare 2026-02-19 11:56:06 -08:00
commit 77c5f625ff
12 changed files with 161 additions and 14 deletions

View file

@ -50,6 +50,14 @@ namespace xo {
x->value() == DFloat::value_type(y->value()));
}
obj<AGCObject>
FloatIntegerOps::cmp_notequal(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>
@ -84,8 +92,16 @@ namespace xo {
IntegerFloatOps::cmp_equal(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y)
{
return DFloat::box<AGCObject>(rcx.allocator(),
DFloat::value_type(x->value() == y->value()));
return DBoolean::box<AGCObject>(rcx.allocator(),
DFloat::value_type(x->value()) == y->value());
}
obj<AGCObject>
IntegerFloatOps::cmp_notequal(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
DFloat::value_type(x->value()) != y->value());
}
}

View file

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

View file

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

View file

@ -4,10 +4,13 @@
**/
#include "NumericDispatch.hpp"
#include <xo/object2/RuntimeError.hpp>
#include <xo/facet/TypeRegistry.hpp>
#include <xo/indentlog/scope.hpp>
namespace xo {
using xo::mm::AGCObject;
using xo::facet::TypeRegistry;
namespace scm {
@ -17,6 +20,35 @@ namespace xo {
dispatch_.visit_pools(visitor);
}
obj<AGCObject>
NumericDispatch::dispatch(obj<ARuntimeContext> rcx,
const char * caller,
const char * error_headline,
BinaryOp AnonymizedNumericOps::* member_ptr,
obj<AGCObject> x,
obj<AGCObject> y)
{
KeyType key(x._typeseq(), y._typeseq());
auto target_fn
= NumericDispatch::instance().dispatch_[key].*member_ptr;
if (!target_fn) {
// FIXME: use {fmt} here
std::stringstream ss;
tosn(ss,
error_headline,
xtag("x.type", TypeRegistry::id2name(x._typeseq())),
xtag("y.type", TypeRegistry::id2name(y._typeseq())));
return DRuntimeError::make(rcx.allocator(),
caller,
ss.str().c_str());
}
return (*target_fn)(rcx, x.data(), y.data());
}
obj<AGCObject>
NumericDispatch::multiply(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
@ -91,12 +123,56 @@ namespace xo {
auto target_fn
= NumericDispatch::instance().dispatch_[key].cmpeq_;
if (!target_fn)
assert(false);
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());
}
obj<AGCObject>
NumericDispatch::cmp_notequal(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y)
{
return dispatch(rcx,
"NumericDispatch::cmp_notequal",
"incomparable types in x!=y",
&AnonymizedNumericOps::cmpne_,
x, y);
#ifdef OBSOLETE
KeyType key(x._typeseq(), y._typeseq());
auto target_fn
= NumericDispatch::instance().dispatch_[key].cmpne_;
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_notequal",
ss.str().c_str());
}
return (*target_fn)(rcx, x.data(), y.data());
#endif
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -31,6 +31,10 @@ namespace xo {
NumericPrimitives::s_cmpeq_gco_gco_pm("_cmpeq",
&NumericDispatch::cmp_equal);
DPrimitive_gco_2_gco_gco
NumericPrimitives::s_cmpne_gco_gco_pm("_cmpne",
&NumericDispatch::cmp_notequal);
} /*namespace scm*/
} /*namespace xo*/

View file

@ -39,28 +39,32 @@ namespace xo {
&FloatOps::divide,
&FloatOps::add,
&FloatOps::subtract,
&FloatOps::cmp_equal);
&FloatOps::cmp_equal,
&FloatOps::cmp_notequal);
NumericDispatch::instance().register_impl<DFloat, DInteger>
(&FloatIntegerOps::multiply,
&FloatIntegerOps::divide,
&FloatIntegerOps::add,
&FloatIntegerOps::subtract,
&FloatIntegerOps::cmp_equal);
&FloatIntegerOps::cmp_equal,
&FloatIntegerOps::cmp_notequal);
NumericDispatch::instance().register_impl<DInteger, DFloat>
(&IntegerFloatOps::multiply,
&IntegerFloatOps::divide,
&IntegerFloatOps::add,
&IntegerFloatOps::subtract,
&IntegerFloatOps::cmp_equal);
&IntegerFloatOps::cmp_equal,
&IntegerFloatOps::cmp_notequal);
NumericDispatch::instance().register_impl<DInteger, DInteger>
(&IntegerOps::multiply,
&IntegerOps::divide,
&IntegerOps::add,
&IntegerOps::subtract,
&IntegerOps::cmp_equal);
&IntegerOps::cmp_equal,
&IntegerOps::cmp_notequal);
log && log(xtag("ANumeric.tseq", typeseq::id<ANumeric>()));