From 6f89c10ac6f57cc6fe2ed5d8c63d81bce1ac9639 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 27 Feb 2026 22:55:14 +1100 Subject: [PATCH] xo-numeric: + less than dispatch (also in schematika parser) --- .../include/xo/numeric/FloatIntegerOps.hpp | 4 ++++ xo-numeric/include/xo/numeric/FloatOps.hpp | 2 ++ xo-numeric/include/xo/numeric/IntegerOps.hpp | 2 ++ .../include/xo/numeric/NumericDispatch.hpp | 11 +++++++++-- xo-numeric/include/xo/numeric/NumericOps.hpp | 17 +++++++++++------ .../include/xo/numeric/NumericPrimitives.hpp | 2 ++ xo-numeric/src/numeric/FloatIntegerOps.cpp | 16 ++++++++++++++++ xo-numeric/src/numeric/FloatOps.cpp | 7 ++++++- xo-numeric/src/numeric/IntegerOps.cpp | 7 +++++++ xo-numeric/src/numeric/NumericDispatch.cpp | 12 ++++++++++++ xo-numeric/src/numeric/NumericPrimitives.cpp | 4 ++++ .../src/numeric/numeric_register_facets.cpp | 12 ++++++++---- xo-reader2/src/reader2/DProgressSsm.cpp | 14 ++++++++++---- 13 files changed, 93 insertions(+), 17 deletions(-) diff --git a/xo-numeric/include/xo/numeric/FloatIntegerOps.hpp b/xo-numeric/include/xo/numeric/FloatIntegerOps.hpp index 0ee99710..35827e6c 100644 --- a/xo-numeric/include/xo/numeric/FloatIntegerOps.hpp +++ b/xo-numeric/include/xo/numeric/FloatIntegerOps.hpp @@ -32,6 +32,8 @@ namespace xo { DFloat * x, DInteger * y); static obj cmp_notequal(obj rcx, DFloat * x, DInteger * y); + static obj cmp_less(obj rcx, + DFloat * x, DInteger * y); }; class IntegerFloatOps { @@ -52,6 +54,8 @@ namespace xo { DInteger * x, DFloat * y); static obj cmp_notequal(obj rcx, DInteger * x, DFloat * y); + static obj cmp_less(obj rcx, + DInteger * x, DFloat * y); }; } diff --git a/xo-numeric/include/xo/numeric/FloatOps.hpp b/xo-numeric/include/xo/numeric/FloatOps.hpp index 88b56442..dd088f90 100644 --- a/xo-numeric/include/xo/numeric/FloatOps.hpp +++ b/xo-numeric/include/xo/numeric/FloatOps.hpp @@ -31,6 +31,8 @@ namespace xo { DFloat * x, DFloat * y); static obj cmp_notequal(obj rcx, DFloat * x, DFloat * y); + static obj cmp_less(obj rcx, + DFloat * x, DFloat * y); }; } diff --git a/xo-numeric/include/xo/numeric/IntegerOps.hpp b/xo-numeric/include/xo/numeric/IntegerOps.hpp index 09306522..b5a8fba8 100644 --- a/xo-numeric/include/xo/numeric/IntegerOps.hpp +++ b/xo-numeric/include/xo/numeric/IntegerOps.hpp @@ -33,6 +33,8 @@ namespace xo { DInteger * x, DInteger * y); static obj cmp_notequal(obj rcx, DInteger * x, DInteger * y); + static obj cmp_less(obj rcx, + DInteger * x, DInteger * y); }; diff --git a/xo-numeric/include/xo/numeric/NumericDispatch.hpp b/xo-numeric/include/xo/numeric/NumericDispatch.hpp index c40f8155..9de42160 100644 --- a/xo-numeric/include/xo/numeric/NumericDispatch.hpp +++ b/xo-numeric/include/xo/numeric/NumericDispatch.hpp @@ -103,6 +103,11 @@ namespace xo { obj x, obj y); + /** compare two numeric values for inequality **/ + static obj cmp_less(obj rcx, + obj x, + obj y); + /** report memory use for owned arenas to @p visitor **/ void visit_pools(const MemorySizeVisitor & visitor); @@ -117,7 +122,8 @@ namespace xo { typename NumericOps::BinaryOp_Impl add_fn, typename NumericOps::BinaryOp_Impl sub_fn, typename NumericOps::BinaryOp_Impl cmpeq_fn, - typename NumericOps::BinaryOp_Impl cmpne_fn) { + typename NumericOps::BinaryOp_Impl cmpne_fn, + typename NumericOps::BinaryOp_Impl cmplt_fn) { KeyType key(typeseq::id().seqno(), typeseq::id().seqno()); @@ -129,7 +135,8 @@ namespace xo { add_fn, sub_fn, cmpeq_fn, - cmpne_fn); + cmpne_fn, + cmplt_fn); } private: diff --git a/xo-numeric/include/xo/numeric/NumericOps.hpp b/xo-numeric/include/xo/numeric/NumericOps.hpp index 6d888434..b69a0338 100644 --- a/xo-numeric/include/xo/numeric/NumericOps.hpp +++ b/xo-numeric/include/xo/numeric/NumericOps.hpp @@ -27,19 +27,22 @@ namespace xo { BinaryOp add, BinaryOp subtract, BinaryOp cmpeq, - BinaryOp cmpne) + BinaryOp cmpne, + BinaryOp cmplt) : multiply_{multiply}, divide_{divide}, add_{add}, subtract_{subtract}, - cmpeq_{cmpeq}, cmpne_{cmpne} {} + cmpeq_{cmpeq}, cmpne_{cmpne}, cmplt_{cmplt} {} BinaryOp multiply_ = nullptr; BinaryOp divide_ = nullptr; BinaryOp add_ = nullptr; BinaryOp subtract_ = nullptr; - /** compare numerics for equality **/ + /** compare numerics (==) **/ BinaryOp cmpeq_ = nullptr; - /** compare numerics for inequality **/ + /** compare numerics (!=) **/ BinaryOp cmpne_ = nullptr; + /** compare numerics (<) **/ + BinaryOp cmplt_ = nullptr; }; template @@ -56,13 +59,15 @@ namespace xo { BinaryOp_Impl add, BinaryOp_Impl subtract, BinaryOp_Impl cmpeq, - BinaryOp_Impl cmpne) { + BinaryOp_Impl cmpne, + BinaryOp_Impl cmplt) { return AnonymizedNumericOps(reinterpret_cast(multiply), reinterpret_cast(divide), reinterpret_cast(add), reinterpret_cast(subtract), reinterpret_cast(cmpeq), - reinterpret_cast(cmpne)); + reinterpret_cast(cmpne), + reinterpret_cast(cmplt)); } }; diff --git a/xo-numeric/include/xo/numeric/NumericPrimitives.hpp b/xo-numeric/include/xo/numeric/NumericPrimitives.hpp index a2cc3cdb..b67ec911 100644 --- a/xo-numeric/include/xo/numeric/NumericPrimitives.hpp +++ b/xo-numeric/include/xo/numeric/NumericPrimitives.hpp @@ -27,6 +27,8 @@ namespace xo { static DPrimitive_gco_2_gco_gco s_cmpeq_gco_gco_pm; /** polymorphic (in both arguments) compare (!=) **/ static DPrimitive_gco_2_gco_gco s_cmpne_gco_gco_pm; + /** polymorphic (in both arguments) compare (<) **/ + static DPrimitive_gco_2_gco_gco s_cmplt_gco_gco_pm; }; } } diff --git a/xo-numeric/src/numeric/FloatIntegerOps.cpp b/xo-numeric/src/numeric/FloatIntegerOps.cpp index f82e10dc..c601a2bf 100644 --- a/xo-numeric/src/numeric/FloatIntegerOps.cpp +++ b/xo-numeric/src/numeric/FloatIntegerOps.cpp @@ -58,6 +58,14 @@ namespace xo { x->value() != DFloat::value_type(y->value())); } + obj + FloatIntegerOps::cmp_less(obj rcx, + DFloat * x, DInteger * y) + { + return DBoolean::box(rcx.allocator(), + x->value() < DFloat::value_type(y->value())); + } + // ----- Integer op Float ----- obj @@ -104,6 +112,14 @@ namespace xo { DFloat::value_type(x->value()) != y->value()); } + obj + IntegerFloatOps::cmp_less(obj rcx, + DInteger * x, DFloat * y) + { + return DBoolean::box(rcx.allocator(), + DFloat::value_type(x->value()) < y->value()); + } + } } diff --git a/xo-numeric/src/numeric/FloatOps.cpp b/xo-numeric/src/numeric/FloatOps.cpp index 6f984728..8fbefc59 100644 --- a/xo-numeric/src/numeric/FloatOps.cpp +++ b/xo-numeric/src/numeric/FloatOps.cpp @@ -54,7 +54,12 @@ namespace xo { return DBoolean::box(rcx.allocator(), x->value() != y->value()); } - + obj + FloatOps::cmp_less(obj rcx, + DFloat * x, DFloat * y) + { + return DBoolean::box(rcx.allocator(), x->value() < y->value()); + } } } diff --git a/xo-numeric/src/numeric/IntegerOps.cpp b/xo-numeric/src/numeric/IntegerOps.cpp index 31f9110d..52c9596c 100644 --- a/xo-numeric/src/numeric/IntegerOps.cpp +++ b/xo-numeric/src/numeric/IntegerOps.cpp @@ -55,6 +55,13 @@ namespace xo { return DBoolean::box(rcx.allocator(), x->value() != y->value()); } + obj + IntegerOps::cmp_less(obj rcx, + DInteger * x, DInteger * y) + { + return DBoolean::box(rcx.allocator(), x->value() < y->value()); + } + } } diff --git a/xo-numeric/src/numeric/NumericDispatch.cpp b/xo-numeric/src/numeric/NumericDispatch.cpp index b0738342..9220207e 100644 --- a/xo-numeric/src/numeric/NumericDispatch.cpp +++ b/xo-numeric/src/numeric/NumericDispatch.cpp @@ -191,6 +191,18 @@ namespace xo { x, y); } + obj + NumericDispatch::cmp_less(obj rcx, + obj x, + obj y) + { + return dispatch(rcx, + "NumericDispatch::cmp_less", + "incomparable types in x (&FloatIntegerOps::multiply, @@ -48,7 +49,8 @@ namespace xo { &FloatIntegerOps::add, &FloatIntegerOps::subtract, &FloatIntegerOps::cmp_equal, - &FloatIntegerOps::cmp_notequal); + &FloatIntegerOps::cmp_notequal, + &FloatIntegerOps::cmp_less); NumericDispatch::instance().register_impl (&IntegerFloatOps::multiply, @@ -56,7 +58,8 @@ namespace xo { &IntegerFloatOps::add, &IntegerFloatOps::subtract, &IntegerFloatOps::cmp_equal, - &IntegerFloatOps::cmp_notequal); + &IntegerFloatOps::cmp_notequal, + &IntegerFloatOps::cmp_less); NumericDispatch::instance().register_impl (&IntegerOps::multiply, @@ -64,7 +67,8 @@ namespace xo { &IntegerOps::add, &IntegerOps::subtract, &IntegerOps::cmp_equal, - &IntegerOps::cmp_notequal); + &IntegerOps::cmp_notequal, + &IntegerOps::cmp_less); log && log(xtag("ANumeric.tseq", typeseq::id())); diff --git a/xo-reader2/src/reader2/DProgressSsm.cpp b/xo-reader2/src/reader2/DProgressSsm.cpp index 371c7e88..4954dc49 100644 --- a/xo-reader2/src/reader2/DProgressSsm.cpp +++ b/xo-reader2/src/reader2/DProgressSsm.cpp @@ -121,9 +121,9 @@ namespace xo { switch (tktype) { case tokentype::tk_assign: return optype::op_assign; - case tokentype::tk_plus: // [+] + case tokentype::tk_plus: // [+] return optype::op_add; - case tokentype::tk_minus: // [-] + case tokentype::tk_minus: // [-] return optype::op_subtract; case tokentype::tk_star: // [*] return optype::op_multiply; @@ -133,7 +133,7 @@ namespace xo { return optype::op_equal; case tokentype::tk_cmpne: // [!=] return optype::op_not_equal; - case tokentype::tk_leftangle: + case tokentype::tk_leftangle: // [<] return optype::op_less; case tokentype::tk_lessequal: return optype::op_less_equal; @@ -288,7 +288,6 @@ namespace xo { case tokentype::tk_leftbracket: case tokentype::tk_rightbracket: case tokentype::tk_leftbrace: - case tokentype::tk_leftangle: case tokentype::tk_rightangle: case tokentype::tk_lessequal: case tokentype::tk_greatequal: @@ -304,6 +303,7 @@ namespace xo { case tokentype::tk_minus: case tokentype::tk_cmpeq: case tokentype::tk_cmpne: + case tokentype::tk_leftangle: this->on_operator_token(tk, p_psm); return; @@ -1316,6 +1316,12 @@ namespace xo { lhs_, rhs_); case optype::op_less: + return assemble_numeric_expr_aux + (p_psm->expr_alloc(), + TypeRef::prefix_type::from_chars("_cmplt_gco"), + &NumericPrimitives::s_cmplt_gco_gco_pm, + lhs_, rhs_); + case optype::op_less_equal: case optype::op_great: case optype::op_great_equal: