diff --git a/include/xo/numeric/SetupNumeric.hpp b/include/xo/numeric/SetupNumeric.hpp new file mode 100644 index 00000000..b6fecd1f --- /dev/null +++ b/include/xo/numeric/SetupNumeric.hpp @@ -0,0 +1,25 @@ +/** @file SetupNumeric.hpp + * + * @author Roland Conybeare, Feb 2026 + **/ + +#pragma once + +#include "PrimitiveRegistry.hpp" +#include + +namespace xo { + namespace scm { + /** Setup numeric facet dispatch **/ + struct SetupNumeric { + public: + static bool register_facets(); + /** Register primitive factories with primitive registry **/ + static bool register_primitives(obj rcx, + InstallSink sink, + InstallFlags flags); + }; + } +} + +/* end SetupNumeric.hpp */ diff --git a/include/xo/numeric/numeric_register_facets.hpp b/include/xo/numeric/numeric_register_facets.hpp deleted file mode 100644 index 7beeb10e..00000000 --- a/include/xo/numeric/numeric_register_facets.hpp +++ /dev/null @@ -1,16 +0,0 @@ -/** @file numeric_register_facets.hpp - * - * @author Roland Conybeare, Feb 2026 - **/ - -#pragma once - -namespace xo { - namespace scm { - /** Setup numeric facet dispatch **/ - bool numeric_register_facets(); - - } -} - -/* end numeric_register_facets.hpp */ diff --git a/include/xo/numeric/numeric_register_primitives.hpp b/include/xo/numeric/numeric_register_primitives.hpp deleted file mode 100644 index 5c68a51d..00000000 --- a/include/xo/numeric/numeric_register_primitives.hpp +++ /dev/null @@ -1,22 +0,0 @@ -/** @file numeric_register_primitives.hpp - * - * @author Roland Conybeare, Mar 2026 - **/ - -#pragma once - -#include "PrimitiveRegistry.hpp" -#include - -namespace xo { - namespace scm { - /** Register primitive factories with primitive registry **/ - bool numeric_register_primitives(obj rcx, - //obj mm, - //StringTable * stbl, - InstallSink sink, - InstallFlags flags); - } -} - -/* end numeric_register_primitives.hpp */ diff --git a/src/numeric/CMakeLists.txt b/src/numeric/CMakeLists.txt index ca7dd6d5..256f9ad5 100644 --- a/src/numeric/CMakeLists.txt +++ b/src/numeric/CMakeLists.txt @@ -3,8 +3,7 @@ set(SELF_LIB xo_numeric) set(SELF_SRCS init_numeric.cpp - numeric_register_facets.cpp - numeric_register_primitives.cpp + SetupNumeric.cpp NumericPrimitives.cpp NumericDispatch.cpp INumeric_Any.cpp diff --git a/src/numeric/SetupNumeric.cpp b/src/numeric/SetupNumeric.cpp new file mode 100644 index 00000000..c5920505 --- /dev/null +++ b/src/numeric/SetupNumeric.cpp @@ -0,0 +1,159 @@ +/** @file SetupNumeric.cpp + * + * @author Roland Conybeare, Mar 2026 + **/ + +#include "SetupNumeric.hpp" +#include "NumericDispatch.hpp" +#include "Numeric.hpp" +#include "NumericPrimitives.hpp" +#include "NumericDispatch.hpp" + +#include "FloatIntegerOps.hpp" +#include "FloatOps.hpp" +#include "float/INumeric_DFloat.hpp" + +#include "IntegerOps.hpp" +#include "integer/INumeric_DInteger.hpp" + +#include + +#include +#include + +#include +#include +#include + +namespace xo { + using xo::mm::AAllocator; + using xo::facet::FacetRegistry; + using xo::reflect::typeseq; + + namespace scm { + bool + SetupNumeric::register_facets() + { + scope log(XO_DEBUG(true)); + + FacetRegistry::register_impl(); + + NumericDispatch::instance().register_impl + (&FloatOps::multiply, + &FloatOps::divide, + &FloatOps::add, + &FloatOps::subtract, + &FloatOps::cmp_equal, + &FloatOps::cmp_notequal, + &FloatOps::cmp_less, + &FloatOps::cmp_lessequal, + &FloatOps::cmp_greater, + &FloatOps::cmp_greatequal); + + NumericDispatch::instance().register_impl + (&FloatIntegerOps::multiply, + &FloatIntegerOps::divide, + &FloatIntegerOps::add, + &FloatIntegerOps::subtract, + &FloatIntegerOps::cmp_equal, + &FloatIntegerOps::cmp_notequal, + &FloatIntegerOps::cmp_less, + &FloatIntegerOps::cmp_lessequal, + &FloatIntegerOps::cmp_greater, + &FloatIntegerOps::cmp_greatequal); + + NumericDispatch::instance().register_impl + (&IntegerFloatOps::multiply, + &IntegerFloatOps::divide, + &IntegerFloatOps::add, + &IntegerFloatOps::subtract, + &IntegerFloatOps::cmp_equal, + &IntegerFloatOps::cmp_notequal, + &IntegerFloatOps::cmp_less, + &IntegerFloatOps::cmp_lessequal, + &IntegerFloatOps::cmp_greater, + &IntegerFloatOps::cmp_greatequal); + + NumericDispatch::instance().register_impl + (&IntegerOps::multiply, + &IntegerOps::divide, + &IntegerOps::add, + &IntegerOps::subtract, + &IntegerOps::cmp_equal, + &IntegerOps::cmp_notequal, + &IntegerOps::cmp_less, + &IntegerOps::cmp_lessequal, + &IntegerOps::cmp_greater, + &IntegerOps::cmp_greatequal); + + log && log(xtag("ANumeric.tseq", typeseq::id())); + + return true; + } + + namespace { + bool install_aux(InstallSink sink, + DPrimitive_gco_2_gco_gco * pm, + InstallFlags flags) + { + if (flags != InstallFlags::f_none) { + return sink(pm->name(), + pm->fn_td(), + obj(pm), + flags); + } else { + return true; + } + } + } + + bool + SetupNumeric::register_primitives(obj rcx, + InstallSink sink, + InstallFlags flags) + { + obj mm = rcx.allocator(); + StringTable * stbl = rcx.stringtable(); + + scope log(XO_DEBUG(true)); + + bool ok = true; + + ok = ok & install_aux(sink, + NumericPrimitives::make_multiply_pm(mm, stbl), + flags & InstallFlags::f_essential); + ok = ok & install_aux(sink, + NumericPrimitives::make_divide_pm(mm, stbl), + flags & InstallFlags::f_essential); + ok = ok & install_aux(sink, + NumericPrimitives::make_add_pm(mm, stbl), + flags & InstallFlags::f_essential); + ok = ok & install_aux(sink, + NumericPrimitives::make_subtract_pm(mm, stbl), + flags & InstallFlags::f_essential); + + ok = ok & install_aux(sink, + NumericPrimitives::make_cmpeq_pm(mm, stbl), + flags & InstallFlags::f_essential); + ok = ok & install_aux(sink, + NumericPrimitives::make_cmpne_pm(mm, stbl), + flags & InstallFlags::f_essential); + ok = ok & install_aux(sink, + NumericPrimitives::make_cmplt_pm(mm, stbl), + flags & InstallFlags::f_essential); + ok = ok & install_aux(sink, + NumericPrimitives::make_cmple_pm(mm, stbl), + flags & InstallFlags::f_essential); + ok = ok & install_aux(sink, + NumericPrimitives::make_cmpgt_pm(mm, stbl), + flags & InstallFlags::f_essential); + ok = ok & install_aux(sink, + NumericPrimitives::make_cmpge_pm(mm, stbl), + flags & InstallFlags::f_essential); + + return ok; + } + } /*namespace scm*/ +} /*namespace xo*/ + +/* end SetupNumeric.cpp */ diff --git a/src/numeric/init_numeric.cpp b/src/numeric/init_numeric.cpp index faa678a0..86105ec6 100644 --- a/src/numeric/init_numeric.cpp +++ b/src/numeric/init_numeric.cpp @@ -4,22 +4,21 @@ **/ #include "init_numeric.hpp" +#include "SetupNumeric.hpp" #include #include "Subsystem.hpp" -#include "numeric_register_facets.hpp" -#include "numeric_register_primitives.hpp" namespace xo { - using xo::scm::numeric_register_facets; - using xo::scm::numeric_register_primitives; + using xo::scm::SetupNumeric; + //using xo::scm::numeric_register_primitives; using xo::scm::PrimitiveRegistry; void InitSubsys::init() { - numeric_register_facets(); + SetupNumeric::register_facets(); - PrimitiveRegistry::instance().register_primitives(&numeric_register_primitives); + PrimitiveRegistry::instance().register_primitives(&SetupNumeric::register_primitives); } diff --git a/src/numeric/numeric_register_facets.cpp b/src/numeric/numeric_register_facets.cpp deleted file mode 100644 index 7ef2555a..00000000 --- a/src/numeric/numeric_register_facets.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/** @file numeric_register_facets.cpp - * - * @author Roland Conybeare, Feb 2026 - **/ - -#include "numeric_register_facets.hpp" -#include "NumericDispatch.hpp" -#include "Numeric.hpp" - -#include "FloatIntegerOps.hpp" -#include "FloatOps.hpp" -#include "float/INumeric_DFloat.hpp" - -#include "IntegerOps.hpp" -#include "integer/INumeric_DInteger.hpp" - -#include -#include - -#include -#include -#include - -namespace xo { - using xo::facet::FacetRegistry; - using xo::reflect::typeseq; - - namespace scm { - - bool - numeric_register_facets() - { - scope log(XO_DEBUG(true)); - - FacetRegistry::register_impl(); - - NumericDispatch::instance().register_impl - (&FloatOps::multiply, - &FloatOps::divide, - &FloatOps::add, - &FloatOps::subtract, - &FloatOps::cmp_equal, - &FloatOps::cmp_notequal, - &FloatOps::cmp_less, - &FloatOps::cmp_lessequal, - &FloatOps::cmp_greater, - &FloatOps::cmp_greatequal); - - NumericDispatch::instance().register_impl - (&FloatIntegerOps::multiply, - &FloatIntegerOps::divide, - &FloatIntegerOps::add, - &FloatIntegerOps::subtract, - &FloatIntegerOps::cmp_equal, - &FloatIntegerOps::cmp_notequal, - &FloatIntegerOps::cmp_less, - &FloatIntegerOps::cmp_lessequal, - &FloatIntegerOps::cmp_greater, - &FloatIntegerOps::cmp_greatequal); - - NumericDispatch::instance().register_impl - (&IntegerFloatOps::multiply, - &IntegerFloatOps::divide, - &IntegerFloatOps::add, - &IntegerFloatOps::subtract, - &IntegerFloatOps::cmp_equal, - &IntegerFloatOps::cmp_notequal, - &IntegerFloatOps::cmp_less, - &IntegerFloatOps::cmp_lessequal, - &IntegerFloatOps::cmp_greater, - &IntegerFloatOps::cmp_greatequal); - - NumericDispatch::instance().register_impl - (&IntegerOps::multiply, - &IntegerOps::divide, - &IntegerOps::add, - &IntegerOps::subtract, - &IntegerOps::cmp_equal, - &IntegerOps::cmp_notequal, - &IntegerOps::cmp_less, - &IntegerOps::cmp_lessequal, - &IntegerOps::cmp_greater, - &IntegerOps::cmp_greatequal); - - log && log(xtag("ANumeric.tseq", typeseq::id())); - - return true; - } - - } /*namespace scm*/ -} /*namespace xo*/ - -/* end numeric_register_facets.cpp */ diff --git a/src/numeric/numeric_register_primitives.cpp b/src/numeric/numeric_register_primitives.cpp deleted file mode 100644 index 08cb0fc9..00000000 --- a/src/numeric/numeric_register_primitives.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/** @file numeric_register_primitives.cpp - * - * @author Roland Conybeare, Mar 2026 - **/ - -#include "numeric_register_primitives.hpp" -#include "NumericPrimitives.hpp" -#include "NumericDispatch.hpp" -#include -#include - -namespace xo { - using xo::mm::AAllocator; - using xo::scope; - - namespace scm { - namespace { - bool install_aux(InstallSink sink, - DPrimitive_gco_2_gco_gco * pm, - InstallFlags flags) - { - if (flags != InstallFlags::f_none) { - return sink(pm->name(), - pm->fn_td(), - obj(pm), - flags); - } else { - return true; - } - } - -#ifdef OBSOLETE - bool install_aux(InstallSink sink, - obj mm, - std::string_view name, - obj (*impl)(obj rcx, - obj x, - obj y), - InstallFlags flags) - { - if (flags != InstallFlags::f_none) { - auto pm - = DPrimitive_gco_2_gco_gco::_make(mm, name, impl); - - return install_aux(sink, pm, flags); - } else { - return true; - } - } -#endif - } - - bool - numeric_register_primitives(obj rcx, - //obj mm, StringTable * stbl, - InstallSink sink, InstallFlags flags) - { - obj mm = rcx.allocator(); - StringTable * stbl = rcx.stringtable(); - - scope log(XO_DEBUG(true)); - - bool ok = true; - - ok = ok & install_aux(sink, - NumericPrimitives::make_multiply_pm(mm, stbl), - flags & InstallFlags::f_essential); - ok = ok & install_aux(sink, - NumericPrimitives::make_divide_pm(mm, stbl), - flags & InstallFlags::f_essential); - ok = ok & install_aux(sink, - NumericPrimitives::make_add_pm(mm, stbl), - flags & InstallFlags::f_essential); - ok = ok & install_aux(sink, - NumericPrimitives::make_subtract_pm(mm, stbl), - flags & InstallFlags::f_essential); - - ok = ok & install_aux(sink, - NumericPrimitives::make_cmpeq_pm(mm, stbl), - flags & InstallFlags::f_essential); - ok = ok & install_aux(sink, - NumericPrimitives::make_cmpne_pm(mm, stbl), - flags & InstallFlags::f_essential); - ok = ok & install_aux(sink, - NumericPrimitives::make_cmplt_pm(mm, stbl), - flags & InstallFlags::f_essential); - ok = ok & install_aux(sink, - NumericPrimitives::make_cmple_pm(mm, stbl), - flags & InstallFlags::f_essential); - ok = ok & install_aux(sink, - NumericPrimitives::make_cmpgt_pm(mm, stbl), - flags & InstallFlags::f_essential); - ok = ok & install_aux(sink, - NumericPrimitives::make_cmpge_pm(mm, stbl), - flags & InstallFlags::f_essential); - - return ok; - } - } -} /*namespace xo*/ - -/* end numeric_register_primitives.cpp */