From cd38931c9d0dbbfde8bbf35280a623ba21eda6c6 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 13 Feb 2026 17:24:23 -0500 Subject: [PATCH] xo-reader2 stack: handle comparison expression (x == y) --- include/xo/procedure2/init_primitives.hpp | 6 ++ src/procedure2/init_primitives.cpp | 74 ++++++++++++++++++++--- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/include/xo/procedure2/init_primitives.hpp b/include/xo/procedure2/init_primitives.hpp index 48b733d..d2d51a5 100644 --- a/include/xo/procedure2/init_primitives.hpp +++ b/include/xo/procedure2/init_primitives.hpp @@ -22,6 +22,12 @@ namespace xo { **/ static DPrimitive_gco_2_gco_gco s_mul_gco_gco_pm; + /** polymorphic equality comparison + * + * TODO: this will want to move to x-numeric/ + **/ + static DPrimitive_gco_2_gco_gco s_equal_gco_gco_pm; + #ifdef NOT_YET static Primitive_f64_1_f64 s_neg_f64_pm; diff --git a/src/procedure2/init_primitives.cpp b/src/procedure2/init_primitives.cpp index dbcb3b3..c1ecead 100644 --- a/src/procedure2/init_primitives.cpp +++ b/src/procedure2/init_primitives.cpp @@ -5,10 +5,11 @@ #include "init_primitives.hpp" #include "DPrimitive.hpp" -#include -#include -#include -#include +#include +//#include +#include +//#include +#include #include #include #include @@ -54,9 +55,6 @@ namespace xo { // 2. at that point will require polymorphic dispatch // on argument representations, analogous to dispatch // in FacetRegistry - // 3. Need concept of a 'runtime context'. - // This will need to be part of the AProcedure api - // e.g. passed to apply_nocheck typeseq x_tseq = x_gco._typeseq(); typeseq y_tseq = y_gco._typeseq(); @@ -101,6 +99,65 @@ namespace xo { return obj(); } + obj + equal_gco_gco(obj rcx, + obj x_gco, + obj y_gco) + { + using xo::reflect::typeseq; + + obj 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()) { + // i64 * .. + long x = GCObjectConversion::from_gco(mm, x_gco); + + if (y_tseq == typeseq::id()) { + // i64 == i64 + long y = GCObjectConversion::from_gco(mm, y_gco); + + return DBoolean::box(mm, x == y); + } else if (y_tseq == typeseq::id()) { + // i64 == f64 + double y = GCObjectConversion::from_gco(mm, y_gco); + + return DFloat::box(mm, static_cast(x) == y); + } + } else if (x_tseq == typeseq::id()) { + if (y_tseq == typeseq::id()) { + // f64 == i64. + double x = GCObjectConversion::from_gco(mm, x_gco); + long y = GCObjectConversion::from_gco(mm, y_gco); + + return DFloat::box(mm, x == static_cast(y)); + } else if (y_tseq == typeseq::id()) { + // f64 * f64. + double x = GCObjectConversion::from_gco(mm, x_gco); + double y = GCObjectConversion::from_gco(mm, y_gco); + + return DFloat::box(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(); + } + #ifdef NOT_YET double mul_f64_f64(double x, double y) { @@ -141,6 +198,9 @@ namespace xo { DPrimitive_gco_2_gco_gco Primitives::s_mul_gco_gco_pm("_mul", &mul_gco_gco); + DPrimitive_gco_2_gco_gco + Primitives::s_equal_gco_gco_pm("_equal", &equal_gco_gco); + #ifdef NOT_YET Primitive_f64_1_f64 Primitives::s_neg_f64_pm("_neg_d",