xo-interpreter2 stack: streamline op== impl + utests

This commit is contained in:
Roland Conybeare 2026-02-19 09:03:02 -08:00
commit 243ad12869
12 changed files with 97 additions and 10 deletions

View file

@ -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()));
}
}
}

View file

@ -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());
}
}
}

View file

@ -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());
}
}
}

View file

@ -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*/

View file

@ -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*/

View file

@ -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>()));