From 4039926d3363162406a0b1ab5cafc881f7dfb065 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Mon, 16 Mar 2026 13:51:51 -0500 Subject: [PATCH] xo-numeric: attach type to numeric primitives --- include/xo/numeric/NumericPrimitives.hpp | 28 +++-- src/numeric/NumericPrimitives.cpp | 114 ++++++++++++++++---- src/numeric/numeric_register_primitives.cpp | 22 ++-- 3 files changed, 127 insertions(+), 37 deletions(-) diff --git a/include/xo/numeric/NumericPrimitives.hpp b/include/xo/numeric/NumericPrimitives.hpp index 8a1cd33d..aec3ae84 100644 --- a/include/xo/numeric/NumericPrimitives.hpp +++ b/include/xo/numeric/NumericPrimitives.hpp @@ -20,26 +20,34 @@ namespace xo { /** polymorphic (in both arguments1) multiply **/ static DPrimitive_gco_2_gco_gco * make_multiply_pm(obj mm, StringTable * stbl); - /** polymorphic (in both arguments) divide **/ - static DPrimitive_gco_2_gco_gco * make_divide_pm(obj mm); + static DPrimitive_gco_2_gco_gco * make_divide_pm(obj mm, + StringTable * stbl); /** polymorphic (in both arguments) add **/ - static DPrimitive_gco_2_gco_gco * make_add_pm(obj mm); + static DPrimitive_gco_2_gco_gco * make_add_pm(obj mm, + StringTable * stbl); /** polymorphic (in both arguments) subtract **/ - static DPrimitive_gco_2_gco_gco * make_subtract_pm(obj mm); + static DPrimitive_gco_2_gco_gco * make_subtract_pm(obj mm, + StringTable * stbl); /** polymorphic (in both arguments) compare (==) **/ - static DPrimitive_gco_2_gco_gco * make_cmpeq_pm(obj mm); + static DPrimitive_gco_2_gco_gco * make_cmpeq_pm(obj mm, + StringTable * stbl); /** polymorphic (in both arguments) compare (!=) **/ - static DPrimitive_gco_2_gco_gco * make_cmpne_pm(obj mm); + static DPrimitive_gco_2_gco_gco * make_cmpne_pm(obj mm, + StringTable * stbl); /** polymorphic (in both arguments) compare (<) **/ - static DPrimitive_gco_2_gco_gco * make_cmplt_pm(obj mm); + static DPrimitive_gco_2_gco_gco * make_cmplt_pm(obj mm, + StringTable * stbl); /** polymorphic (in both arguments) compare (<=) **/ - static DPrimitive_gco_2_gco_gco * make_cmple_pm(obj mm); + static DPrimitive_gco_2_gco_gco * make_cmple_pm(obj mm, + StringTable * stbl); /** polymorphic (in both arguments) compare (>) **/ - static DPrimitive_gco_2_gco_gco * make_cmpgt_pm(obj mm); + static DPrimitive_gco_2_gco_gco * make_cmpgt_pm(obj mm, + StringTable * stbl); /** polymorphic (in both arguments) compare (>=) **/ - static DPrimitive_gco_2_gco_gco * make_cmpge_pm(obj mm); + static DPrimitive_gco_2_gco_gco * make_cmpge_pm(obj mm, + StringTable * stbl); }; } } diff --git a/src/numeric/NumericPrimitives.cpp b/src/numeric/NumericPrimitives.cpp index aeb7d8fb..decc8d60 100644 --- a/src/numeric/NumericPrimitives.cpp +++ b/src/numeric/NumericPrimitives.cpp @@ -34,65 +34,143 @@ namespace xo { } DPrimitive_gco_2_gco_gco * - NumericPrimitives::make_divide_pm(obj mm) + NumericPrimitives::make_divide_pm(obj mm, + StringTable * stbl) { - return DPrimitive_gco_2_gco_gco::_make(mm, "_div", + (void)stbl; + + auto numeric_ty = DAtomicType::make(mm, Metatype::t_numeric()); + // #op+: numeric x numeric -> numeric + auto pm_ty = obj + (DFunctionType::_make(mm, numeric_ty, numeric_ty, numeric_ty)); + + return DPrimitive_gco_2_gco_gco::_make(mm, "_div", pm_ty, &NumericDispatch::divide); } DPrimitive_gco_2_gco_gco * - NumericPrimitives::make_add_pm(obj mm) + NumericPrimitives::make_add_pm(obj mm, + StringTable * stbl) { - return DPrimitive_gco_2_gco_gco::_make(mm, "_add", + (void)stbl; + + auto numeric_ty = DAtomicType::make(mm, Metatype::t_numeric()); + // #op+: numeric x numeric -> numeric + auto pm_ty = obj + (DFunctionType::_make(mm, numeric_ty, numeric_ty, numeric_ty)); + + return DPrimitive_gco_2_gco_gco::_make(mm, "_add", pm_ty, &NumericDispatch::add); } DPrimitive_gco_2_gco_gco * - NumericPrimitives::make_subtract_pm(obj mm) + NumericPrimitives::make_subtract_pm(obj mm, + StringTable * stbl) { - return DPrimitive_gco_2_gco_gco::_make(mm, "_sub", + (void)stbl; + + auto numeric_ty = DAtomicType::make(mm, Metatype::t_numeric()); + // #op+: numeric x numeric -> numeric + auto pm_ty = obj + (DFunctionType::_make(mm, numeric_ty, numeric_ty, numeric_ty)); + + return DPrimitive_gco_2_gco_gco::_make(mm, "_sub", pm_ty, &NumericDispatch::subtract); } DPrimitive_gco_2_gco_gco * - NumericPrimitives::make_cmpeq_pm(obj mm) + NumericPrimitives::make_cmpeq_pm(obj mm, + StringTable * stbl) { - return DPrimitive_gco_2_gco_gco::_make(mm, "_cmpeq", + (void)stbl; + + auto booleic_ty = DAtomicType::make(mm, Metatype::t_booleic()); + auto numeric_ty = DAtomicType::make(mm, Metatype::t_numeric()); + // #op==: numeric x numeric -> booleic + auto pm_ty = obj + (DFunctionType::_make(mm, booleic_ty, numeric_ty, numeric_ty)); + + return DPrimitive_gco_2_gco_gco::_make(mm, "_cmpeq", pm_ty, &NumericDispatch::cmp_equal); } DPrimitive_gco_2_gco_gco * - NumericPrimitives::make_cmpne_pm(obj mm) + NumericPrimitives::make_cmpne_pm(obj mm, + StringTable * stbl) { - return DPrimitive_gco_2_gco_gco::_make(mm, "_cmpne", + (void)stbl; + + auto booleic_ty = DAtomicType::make(mm, Metatype::t_booleic()); + auto numeric_ty = DAtomicType::make(mm, Metatype::t_numeric()); + // #op!=: numeric x numeric -> booleic + auto pm_ty = obj + (DFunctionType::_make(mm, booleic_ty, numeric_ty, numeric_ty)); + + return DPrimitive_gco_2_gco_gco::_make(mm, "_cmpne", pm_ty, &NumericDispatch::cmp_notequal); } DPrimitive_gco_2_gco_gco * - NumericPrimitives::make_cmplt_pm(obj mm) + NumericPrimitives::make_cmplt_pm(obj mm, + StringTable * stbl) { - return DPrimitive_gco_2_gco_gco::_make(mm, "_cmplt", + (void)stbl; + + auto booleic_ty = DAtomicType::make(mm, Metatype::t_booleic()); + auto numeric_ty = DAtomicType::make(mm, Metatype::t_numeric()); + // #op!=: numeric x numeric -> booleic + auto pm_ty = obj + (DFunctionType::_make(mm, booleic_ty, numeric_ty, numeric_ty)); + + return DPrimitive_gco_2_gco_gco::_make(mm, "_cmplt", pm_ty, &NumericDispatch::cmp_less); } DPrimitive_gco_2_gco_gco * - NumericPrimitives::make_cmple_pm(obj mm) + NumericPrimitives::make_cmple_pm(obj mm, + StringTable * stbl) { - return DPrimitive_gco_2_gco_gco::_make(mm, "_cmple", + (void)stbl; + + auto booleic_ty = DAtomicType::make(mm, Metatype::t_booleic()); + auto numeric_ty = DAtomicType::make(mm, Metatype::t_numeric()); + // #op!=: numeric x numeric -> booleic + auto pm_ty = obj + (DFunctionType::_make(mm, booleic_ty, numeric_ty, numeric_ty)); + + return DPrimitive_gco_2_gco_gco::_make(mm, "_cmple", pm_ty, &NumericDispatch::cmp_lessequal); } DPrimitive_gco_2_gco_gco * - NumericPrimitives::make_cmpgt_pm(obj mm) + NumericPrimitives::make_cmpgt_pm(obj mm, + StringTable * stbl) { - return DPrimitive_gco_2_gco_gco::_make(mm, "_cmpgt", + (void)stbl; + + auto booleic_ty = DAtomicType::make(mm, Metatype::t_booleic()); + auto numeric_ty = DAtomicType::make(mm, Metatype::t_numeric()); + // #op!=: numeric x numeric -> booleic + auto pm_ty = obj + (DFunctionType::_make(mm, booleic_ty, numeric_ty, numeric_ty)); + + return DPrimitive_gco_2_gco_gco::_make(mm, "_cmpgt", pm_ty, &NumericDispatch::cmp_greater); } DPrimitive_gco_2_gco_gco * - NumericPrimitives::make_cmpge_pm(obj mm) + NumericPrimitives::make_cmpge_pm(obj mm, + StringTable * stbl) { - return DPrimitive_gco_2_gco_gco::_make(mm, "_cmpge", + (void)stbl; + + auto booleic_ty = DAtomicType::make(mm, Metatype::t_booleic()); + auto numeric_ty = DAtomicType::make(mm, Metatype::t_numeric()); + // #op!=: numeric x numeric -> booleic + auto pm_ty = obj + (DFunctionType::_make(mm, booleic_ty, numeric_ty, numeric_ty)); + + return DPrimitive_gco_2_gco_gco::_make(mm, "_cmpge", pm_ty, &NumericDispatch::cmp_greatequal); } diff --git a/src/numeric/numeric_register_primitives.cpp b/src/numeric/numeric_register_primitives.cpp index 20eb5967..6150df9f 100644 --- a/src/numeric/numeric_register_primitives.cpp +++ b/src/numeric/numeric_register_primitives.cpp @@ -29,6 +29,7 @@ namespace xo { } } +#ifdef OBSOLETE bool install_aux(InstallSink sink, obj mm, std::string_view name, @@ -46,6 +47,7 @@ namespace xo { return true; } } +#endif } bool @@ -62,30 +64,32 @@ namespace xo { NumericPrimitives::make_multiply_pm(mm, stbl), flags & InstallFlags::f_essential); ok = ok & install_aux(sink, - NumericPrimitives::make_divide_pm(mm), + NumericPrimitives::make_divide_pm(mm, stbl), flags & InstallFlags::f_essential); ok = ok & install_aux(sink, - NumericPrimitives::make_add_pm(mm), + NumericPrimitives::make_add_pm(mm, stbl), flags & InstallFlags::f_essential); ok = ok & install_aux(sink, - NumericPrimitives::make_subtract_pm(mm), + NumericPrimitives::make_subtract_pm(mm, stbl), flags & InstallFlags::f_essential); ok = ok & install_aux(sink, - NumericPrimitives::make_cmpeq_pm(mm), + NumericPrimitives::make_cmpeq_pm(mm, stbl), flags & InstallFlags::f_essential); ok = ok & install_aux(sink, - NumericPrimitives::make_cmpne_pm(mm), + NumericPrimitives::make_cmpne_pm(mm, stbl), flags & InstallFlags::f_essential); ok = ok & install_aux(sink, - NumericPrimitives::make_cmplt_pm(mm), + NumericPrimitives::make_cmplt_pm(mm, stbl), flags & InstallFlags::f_essential); ok = ok & install_aux(sink, - NumericPrimitives::make_cmple_pm(mm), + NumericPrimitives::make_cmple_pm(mm, stbl), flags & InstallFlags::f_essential); - ok = ok & install_aux(sink, mm, "_cmpgt", &NumericDispatch::cmp_greater, + ok = ok & install_aux(sink, + NumericPrimitives::make_cmpgt_pm(mm, stbl), flags & InstallFlags::f_essential); - ok = ok & install_aux(sink, mm, "_cmpge", &NumericDispatch::cmp_greatequal, + ok = ok & install_aux(sink, + NumericPrimitives::make_cmpge_pm(mm, stbl), flags & InstallFlags::f_essential); return ok;