xo-interpreter2 stack: refactor + bugfix operator expr

This commit is contained in:
Roland Conybeare 2026-03-12 20:26:08 -05:00
commit 6c7216ed7d
7 changed files with 195 additions and 200 deletions

View file

@ -34,10 +34,9 @@ xo_install_include_tree3(include/xo/procedure2)
# NOTE: dependency set here must be kept consistent with
# xo-procedure2/cmake/xo_procedure2Config.cmake.in
xo_dependency(${SELF_LIB} xo_type)
xo_dependency(${SELF_LIB} xo_object2)
#xo_dependency(${SELF_LIB} xo_gc)
xo_dependency(${SELF_LIB} subsys)
#xo_dependency(${SELF_LIB} xo_indentlog)
xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets)

View file

@ -0,0 +1,49 @@
/** @file PrimitiveRegistry.cpp
*
* @author Roland Conybeare, Mar 2026
**/
#include "PrimitiveRegistry.hpp"
#include <xo/indentlog/scope.hpp>
namespace xo {
namespace scm {
PrimitiveRegistry &
PrimitiveRegistry::instance()
{
static PrimitiveRegistry s_instance;
return s_instance;
}
void
PrimitiveRegistry::register_primitives(InstallSource factory)
{
scope log(XO_DEBUG(true));
init_seq_v_.push_back(factory);
}
bool
PrimitiveRegistry::install_primitives(obj<AAllocator> mm,
InstallSink sink,
InstallFlags flags)
{
scope log(XO_DEBUG(true));
bool ok = true;
size_t i = 0;
size_t n = init_seq_v_.size();
log && log("run n init steps", xtag("n", n));
for (const auto & fn : init_seq_v_) {
log && log("do install fn (", i+1, "/", n, ")");
ok = ok & fn(mm, sink, flags);
}
return ok;
}
}
} /*namespace xo*/

View file

@ -37,187 +37,6 @@ namespace xo {
}
#endif
#ifdef OBSOLETE // see xo-numeric/xo/numeric/NumericPrimitives.cpp
obj<AGCObject>
mul_gco_gco(obj<ARuntimeContext> rcx,
obj<AGCObject> x_gco,
obj<AGCObject> y_gco)
{
using xo::reflect::typeseq;
obj<AAllocator> mm = rcx.allocator();
// PLACEHOLDER
// TODO:
// 1. move this to xo-numeric2/ when available
// 2. at that point will require polymorphic dispatch
// on argument representations, analogous to dispatch
// in FacetRegistry
typeseq x_tseq = x_gco._typeseq();
typeseq y_tseq = y_gco._typeseq();
// FOR NOW: just test runtime values
//
if (x_tseq == typeseq::id<DInteger>()) {
// i64 * ..
long x = GCObjectConversion<long>::from_gco(mm, x_gco);
if (y_tseq == typeseq::id<DInteger>()) {
// i64 * i64
long y = GCObjectConversion<long>::from_gco(mm, y_gco);
return DInteger::box<AGCObject>(mm, x * y);
} else if (y_tseq == typeseq::id<DFloat>()) {
// i64 * f64
double y = GCObjectConversion<double>::from_gco(mm, y_gco);
return DFloat::box<AGCObject>(mm, x * y);
}
} else if (x_tseq == typeseq::id<DFloat>()) {
if (y_tseq == typeseq::id<DInteger>()) {
// f64 * i64.
double x = GCObjectConversion<double>::from_gco(mm, x_gco);
long y = GCObjectConversion<long>::from_gco(mm, y_gco);
return DFloat::box<AGCObject>(mm, x * y);
} else if (y_tseq == typeseq::id<DFloat>()) {
// f64 * f64.
double x = GCObjectConversion<double>::from_gco(mm, x_gco);
double y = GCObjectConversion<double>::from_gco(mm, y_gco);
return DFloat::box<AGCObject>(mm, x * y);
}
}
// here: error
throw std::runtime_error(tostr("mul_gco_gco: unexpected argument types xt,yt",
xtag("x.tseq", x_tseq),
xtag("y.tseq", y_tseq)));
return obj<AGCObject>();
}
obj<AGCObject>
sub_gco_gco(obj<ARuntimeContext> rcx,
obj<AGCObject> x_gco,
obj<AGCObject> y_gco)
{
using xo::reflect::typeseq;
obj<AAllocator> mm = rcx.allocator();
// PLACEHOLDER
// TODO:
// 1. move this to xo-numeric2/ when available
// 2. at that point will require polymorphic dispatch
// on argument representations, analogous to dispatch
// in FacetRegistry
typeseq x_tseq = x_gco._typeseq();
typeseq y_tseq = y_gco._typeseq();
// FOR NOW: just test runtime values
//
if (x_tseq == typeseq::id<DInteger>()) {
// i64 * ..
long x = GCObjectConversion<long>::from_gco(mm, x_gco);
if (y_tseq == typeseq::id<DInteger>()) {
// i64 * i64
long y = GCObjectConversion<long>::from_gco(mm, y_gco);
return DInteger::box<AGCObject>(mm, x - y);
} else if (y_tseq == typeseq::id<DFloat>()) {
// i64 * f64
double y = GCObjectConversion<double>::from_gco(mm, y_gco);
return DFloat::box<AGCObject>(mm, x - y);
}
} else if (x_tseq == typeseq::id<DFloat>()) {
if (y_tseq == typeseq::id<DInteger>()) {
// f64 * i64.
double x = GCObjectConversion<double>::from_gco(mm, x_gco);
long y = GCObjectConversion<long>::from_gco(mm, y_gco);
return DFloat::box<AGCObject>(mm, x - y);
} else if (y_tseq == typeseq::id<DFloat>()) {
// f64 * f64.
double x = GCObjectConversion<double>::from_gco(mm, x_gco);
double y = GCObjectConversion<double>::from_gco(mm, y_gco);
return DFloat::box<AGCObject>(mm, x - y);
}
}
// here: error
throw std::runtime_error(tostr("sub_gco_gco: unexpected argument types xt,yt",
xtag("x.tseq", x_tseq),
xtag("y.tseq", y_tseq)));
return obj<AGCObject>();
}
obj<AGCObject>
equal_gco_gco(obj<ARuntimeContext> rcx,
obj<AGCObject> x_gco,
obj<AGCObject> y_gco)
{
using xo::reflect::typeseq;
obj<AAllocator> mm = rcx.allocator();
// PLACEHOLDER
// TODO
// 1. move this to xo-numeric2/ when available
// 2. at that point will require polymorphic dispatch on argument representations.
//
typeseq x_tseq = x_gco._typeseq();
typeseq y_tseq = y_gco._typeseq();
// FOR NOW: just test runtime values
//
if (x_tseq == typeseq::id<DInteger>()) {
// i64 * ..
long x = GCObjectConversion<long>::from_gco(mm, x_gco);
if (y_tseq == typeseq::id<DInteger>()) {
// i64 == i64
long y = GCObjectConversion<long>::from_gco(mm, y_gco);
return DBoolean::box<AGCObject>(mm, x == y);
} else if (y_tseq == typeseq::id<DFloat>()) {
// i64 == f64
double y = GCObjectConversion<double>::from_gco(mm, y_gco);
return DFloat::box<AGCObject>(mm, static_cast<double>(x) == y);
}
} else if (x_tseq == typeseq::id<DFloat>()) {
if (y_tseq == typeseq::id<DInteger>()) {
// f64 == i64.
double x = GCObjectConversion<double>::from_gco(mm, x_gco);
long y = GCObjectConversion<long>::from_gco(mm, y_gco);
return DFloat::box<AGCObject>(mm, x == static_cast<double>(y));
} else if (y_tseq == typeseq::id<DFloat>()) {
// f64 * f64.
double x = GCObjectConversion<double>::from_gco(mm, x_gco);
double y = GCObjectConversion<double>::from_gco(mm, y_gco);
return DFloat::box<AGCObject>(mm, x == y);
}
}
// here: error
throw std::runtime_error(tostr("mul_gco_gco: unexpected argument types xt,yt",
xtag("x.tseq", x_tseq),
xtag("y.tseq", y_tseq)));
return obj<AGCObject>();
}
#endif
#ifdef NOT_YET
double
mul_f64_f64(double x, double y) {
@ -255,17 +74,6 @@ namespace xo {
}
#endif
#ifdef OSOLETE
DPrimitive_gco_2_gco_gco
Primitives::s_mul_gco_gco_pm("_mul", &mul_gco_gco);
DPrimitive_gco_2_gco_gco
Primitives::s_sub_gco_gco_pm("_sub", &sub_gco_gco);
DPrimitive_gco_2_gco_gco
Primitives::s_equal_gco_gco_pm("_equal", &equal_gco_gco);
#endif
#ifdef NOT_YET
Primitive_f64_1_f64
Primitives::s_neg_f64_pm("_neg_d",