git subrepo clone git@github.com:Rconybea/xo-numeric.git xo-numeric

subrepo:
  subdir:   "xo-numeric"
  merged:   "7750c868"
upstream:
  origin:   "git@github.com:Rconybea/xo-numeric.git"
  branch:   "main"
  commit:   "7750c868"
git-subrepo:
  version:  "0.4.9"
  origin:   "???"
  commit:   "???"
This commit is contained in:
Roland Conybeare 2026-06-06 22:14:02 -04:00
commit 2d92eec35c
37 changed files with 2429 additions and 0 deletions

12
xo-numeric/.gitrepo Normal file
View file

@ -0,0 +1,12 @@
; DO NOT EDIT (unless you know what you are doing)
;
; This subdirectory is a git "subrepo", and this file is maintained by the
; git-subrepo command. See https://github.com/ingydotnet/git-subrepo#readme
;
[subrepo]
remote = git@github.com:Rconybea/xo-numeric.git
branch = main
commit = 7750c868b6f1fbe7902f27a742596cd4c58b6869
parent = 378b88d8c4a0ed6e3b68196eed6e4eead7ac4841
method = merge
cmdver = 0.4.9

58
xo-numeric/CMakeLists.txt Normal file
View file

@ -0,0 +1,58 @@
# xo-numeric/CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(xo_numeric VERSION 1.0)
enable_language(CXX)
include(GNUInstallDirs)
include(cmake/xo-bootstrap-macros.cmake)
xo_cxx_toplevel_options3()
# ----------------------------------------------------------------
# c++ settings
# one-time project-specific c++ flags. usually empty
set(PROJECT_CXX_FLAGS "")
add_definitions(${PROJECT_CXX_FLAGS})
# ----------------------------------------------------------------
# output targets
# note: manual target; generated code committed to git
xo_add_genfacet(
TARGET xo-numeric-facet-numeric
FACET Numeric
INPUT idl/Numeric.json5
)
# ----------------------------------------------------------------
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-numeric-facetimpl-numeric-float
FACET_PKG xo_numeric
# REPR Float
INPUT idl/INumeric_DFloat.json5
)
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-numeric-facetimpl-numeric-integer
FACET_PKG xo_numeric
# REPR Integer
INPUT idl/INumeric_DInteger.json5
)
# ----------------------------------------------------------------
xo_add_genfacet_all(xo-numeric-genfacet-all)
# ----------------------------------------------------------------
add_subdirectory(src/numeric)
add_subdirectory(utest)
# ----------------------------------------------------------------
# cmake export

1
xo-numeric/README.md Normal file
View file

@ -0,0 +1 @@
# xo-numeric

View file

@ -0,0 +1,41 @@
# ----------------------------------------------------------------
# for example:
# $ PREFIX=/usr/local # for example
# $ cmake -DCMAKE_MODULE_PATH=prefix -DCMAKE_INSTALL_PREFIX=$PREFIX -B .build
#
# will get
# CMAKE_MODULE_PATH
# from xo-cmake-config --cmake-module-path
#
# and expect .cmake macros in
# CMAKE_MODULE_PATH/xo_macros/xo_cxx.cmake
# ----------------------------------------------------------------
find_program(XO_CMAKE_CONFIG_EXECUTABLE NAMES xo-cmake-config REQUIRED)
if ("${XO_CMAKE_CONFIG_EXECUTABLE}" STREQUAL "XO_CMAKE_CONFIG_EXECUTABLE-NOT_FOUND")
message(FATAL "could not find xo-cmake-config executable")
endif()
message(STATUS "XO_CMAKE_CONFIG_EXECUTABLE=${XO_CMAKE_CONFIG_EXECUTABLE}")
if (XO_SUBMODULE_BUILD)
if (("${CMAKE_MODULE_PATH}" STREQUAL "") OR ("${CMAKE_MODULE_PATH}" STREQUAL prefix))
# local version of xo-cmake macros
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/xo-cmake/cmake")
message(STATUS "CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}")
endif()
else()
if (("${CMAKE_MODULE_PATH}" STREQUAL "") OR ("${CMAKE_MODULE_PATH}" STREQUAL prefix))
# default to typical install location for xo-project-macros
execute_process(COMMAND ${XO_CMAKE_CONFIG_EXECUTABLE} --cmake-module-path OUTPUT_VARIABLE CMAKE_MODULE_PATH)
message(STATUS "CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}")
endif()
endif()
# needs to have been installed somewhere on CMAKE_MODULE_PATH,
# (e.g. from xo-cmake with the same value for CMAKE_INSTALL_PREFIX)
#
include(xo_macros/xo_cxx)
xo_cxx_bootstrap_message()

View file

@ -0,0 +1,15 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
# note: changes to find_dependency() calls here
# must coordinate with xo_dependency() calls
# in CMakeLists.txt
#
#find_dependency(xo_gc)
find_dependency(xo_procedure2)
find_dependency(subsys)
#find_dependency(indentlog)
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
check_required_components("@PROJECT_NAME@")

View file

@ -0,0 +1,18 @@
{
mode: "implementation",
output_cpp_dir: "src/numeric",
output_hpp_dir: "include/xo/numeric",
output_impl_subdir: "float",
includes: [
// "<xo/printable2/Printable.hpp>",
// "<xo/printable2/detail/IPrintable_Xfer.hpp>"
],
local_types: [ ],
namespace1: "xo",
namespace2: "scm",
facet_idl: "idl/Numeric.json5",
brief: "provide ANumeric interface for DFloat",
using_doxygen: true,
repr: "DFloat",
doc: [ "implement ANumeric for DFloat" ],
}

View file

@ -0,0 +1,18 @@
{
mode: "implementation",
output_cpp_dir: "src/numeric",
output_hpp_dir: "include/xo/numeric",
output_impl_subdir: "integer",
includes: [
// "<xo/printable2/Printable.hpp>",
// "<xo/printable2/detail/IPrintable_Xfer.hpp>"
],
local_types: [ ],
namespace1: "xo",
namespace2: "scm",
facet_idl: "idl/Numeric.json5",
brief: "provide ANumeric interface for DInteger",
using_doxygen: true,
repr: "DInteger",
doc: [ "implement ANumeric for DInteger" ],
}

View file

@ -0,0 +1,75 @@
// can regenerate downstream .*pp files with either:
// cmake --build -- xo-numeric-facet-procedure
// cmake --build -- xo-numeric-genfacet-all
{
mode: "facet",
output_cpp_dir: "src/numeric",
output_hpp_dir: "include/xo/numeric",
output_impl_subdir: "detail",
// includes in ASyntaxStateMachine.hpp
includes: [
// "\"RuntimeContext.hpp\"",
// "<xo/gc/GCObject.hpp>",
],
// extra includes in Procedure.hpp, if any
user_hpp_includes: [
],
namespace1: "xo",
namespace2: "scm",
// text after includes, before ASyntaxStateMachine
pretext: [
//"namespace xo { namespace scm { class ARuntimeContext; } }",
//"namespace xo { namespace scm { class DArray; } }",
],
facet: "Numeric",
detail_subdir: "detail",
brief: "abstraction for a schematika numeric i.e. something that can participate in arithmetic",
using_doxygen: true,
doc: [
"Abstraction for a schematika numeric"
],
types: [
// {
// name: "AGCObject",
// definition: "xo::mm::AGCObject",
// doc: [ "a gc-aware object" ],
// },
// { name: string, doc: [ string ], definition: string },
],
const_methods: [
// {
// name: "multiply",
// doc: [ "true iff procedure takes n arguments" ],
// return_type: "bool",
// args: [],
// const: true,
// noexcept: true,
// attributes: []
// },
// {
// name: "n_args",
// doc: ["number of arguments. -1 for n-ary" ],
// return_type: "std::int32_t",
// args: [],
// const: true,
// noexcept: true,
// attributes: []
// }
],
nonconst_methods: [
// {
// name: "apply_nocheck",
// doc: ["invoke procedure; assume arguments satisfy type system" ],
// return_type: "obj<AGCObject>",
// args: [
// {type: "obj<ARuntimeContext>", name: "rcx"},
// {type: "const DArray *", name: "args"},
// ]
// }
],
router_facet_explicit_content: [
// this doesn't seem to show up anywhere
"static obj<ANumeric> multiply(obj<ANumeric> lhs, obj<ANumeric> rhs);"
],
}

View file

@ -0,0 +1,76 @@
/** @file FloatIntegerOps.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "Numeric.hpp"
#include <xo/procedure2/RuntimeContext.hpp>
#include <xo/object2/Float.hpp>
#include <xo/object2/Integer.hpp>
namespace xo {
namespace scm {
class FloatIntegerOps {
public:
using AGCObject = xo::mm::AGCObject;
public:
static obj<AGCObject> multiply(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y);
static obj<AGCObject> divide(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y);
static obj<AGCObject> add(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y);
static obj<AGCObject> subtract(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y);
static obj<AGCObject> cmp_equal(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y);
static obj<AGCObject> cmp_notequal(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y);
static obj<AGCObject> cmp_less(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y);
static obj<AGCObject> cmp_lessequal(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y);
static obj<AGCObject> cmp_greater(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y);
static obj<AGCObject> cmp_greatequal(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y);
};
class IntegerFloatOps {
public:
using AGCObject = xo::mm::AGCObject;
public:
static obj<AGCObject> multiply(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y);
static obj<AGCObject> divide(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y);
static obj<AGCObject> add(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y);
static obj<AGCObject> subtract(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y);
static obj<AGCObject> cmp_equal(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y);
static obj<AGCObject> cmp_notequal(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y);
static obj<AGCObject> cmp_less(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y);
static obj<AGCObject> cmp_lessequal(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y);
static obj<AGCObject> cmp_greater(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y);
static obj<AGCObject> cmp_greatequal(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y);
};
}
}
/* end FloatIntegerOps.hpp */

View file

@ -0,0 +1,47 @@
/** @file FloatOps.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "Numeric.hpp"
#include <xo/procedure2/RuntimeContext.hpp>
#include <xo/object2/Float.hpp>
namespace xo {
namespace scm {
class FloatOps {
public:
using AGCObject = xo::mm::AGCObject;
public:
static obj<AGCObject> multiply(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y);
static obj<AGCObject> divide(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y);
static obj<AGCObject> add(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y);
static obj<AGCObject> subtract(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y);
static obj<AGCObject> cmp_equal(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y);
static obj<AGCObject> cmp_notequal(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y);
static obj<AGCObject> cmp_less(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y);
static obj<AGCObject> cmp_lessequal(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y);
static obj<AGCObject> cmp_greater(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y);
static obj<AGCObject> cmp_greatequal(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y);
};
}
}
/* end FloatOps.hpp */

View file

@ -0,0 +1,50 @@
/** @file IntegerOps.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "Numeric.hpp"
#include <xo/procedure2/RuntimeContext.hpp>
#include <xo/object2/Integer.hpp>
namespace xo {
namespace scm {
class IntegerOps {
public:
using AGCObject = xo::mm::AGCObject;
public:
static obj<AGCObject> multiply(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y);
static obj<AGCObject> divide(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y);
static obj<AGCObject> add(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y);
static obj<AGCObject> subtract(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y);
static obj<AGCObject> cmp_equal(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y);
static obj<AGCObject> cmp_notequal(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y);
static obj<AGCObject> cmp_less(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y);
static obj<AGCObject> cmp_lessequal(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y);
static obj<AGCObject> cmp_greater(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y);
static obj<AGCObject> cmp_greatequal(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y);
};
}
}
/* end IntegerOps.hpp */

View file

@ -0,0 +1,22 @@
/** @file Numeric.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Numeric.json5]
* 2. jinja2 template for facet .hpp file:
* [facet.hpp.j2]
* 3. idl for facet methods
* [idl/Numeric.json5]
**/
#pragma once
#include "detail/ANumeric.hpp"
#include "detail/INumeric_Any.hpp"
#include "detail/INumeric_Xfer.hpp"
#include "detail/RNumeric.hpp"
/* end Numeric.hpp */

View file

@ -0,0 +1,171 @@
/** @file NumericDispatch.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "NumericOps.hpp"
#include <xo/procedure2/RuntimeContext.hpp>
#include <xo/alloc2/GCObject.hpp>
#include <xo/arena/DArenaHashMap.hpp>
#include <xo/reflectutil/typeseq.hpp>
namespace xo {
namespace scm {
/** Runtime polymoprhic multimethod dispatch.
* Hash on argument types to get function table
**/
class NumericDispatch {
public:
//using AAllocator = xo::mm::AAllocator;
using AGCObject = xo::mm::AGCObject;
using MemorySizeVisitor = xo::mm::MemorySizeVisitor;
using typeseq = xo::reflect::typeseq;
using KeyType = std::pair<typeseq, typeseq>;
using MappedType = AnonymizedNumericOps;
using BinaryOp = AnonymizedNumericOps::BinaryOp;
/** hash function for key_type **/
struct KeyHash {
std::size_t operator()(const KeyType & k) const noexcept {
// combine the two seqno values
std::size_t h1 = std::hash<int32_t>{}(k.first.seqno());
std::size_t h2 = std::hash<int32_t>{}(k.second.seqno());
return h1 ^ (h2 << 7);
}
};
using MapType = xo::map::DArenaHashMap<KeyType,
MappedType,
KeyHash,
std::equal_to<void>>;
public:
NumericDispatch(uint32_t hint_max_capacity)
: dispatch_{"numeric-dispatch",
hint_max_capacity,
false /*!debug_flag*/} {}
/** @p hint_max_capacity only honored the first time instance()
* is called.
**/
static NumericDispatch & instance(uint32_t hint_max_capacity = 64) {
static NumericDispatch s_instance(hint_max_capacity);
return s_instance;
}
/** multi-dispatch driver.
* Invoke @p member_ptr in AnonymizedNumericOps
**/
static obj<AGCObject> dispatch(obj<ARuntimeContext> rcx,
const char * caller,
const char * error_headline,
BinaryOp AnonymizedNumericOps::* member_ptr,
obj<AGCObject> x,
obj<AGCObject> y);
/** multiply w/ runtime polymorphism (double-dispatch)
**/
static obj<AGCObject> multiply(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y);
/** divide w/ runtime polymorphism (double-dispatch)
**/
static obj<AGCObject> divide(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y);
/** add w/ runtime polymorphism (double-dispatch)
**/
static obj<AGCObject> add(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y);
/** subtract w/ runtime polymorphism (double-dispatch)
**/
static obj<AGCObject> subtract(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y);
/** compare two numeric values for equality (==) **/
static obj<AGCObject> cmp_equal(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y);
/** compare two numeric values for inequality (!~=) **/
static obj<AGCObject> cmp_notequal(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y);
/** compare two numeric values for less (<) **/
static obj<AGCObject> cmp_less(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y);
/** compare two numeric values for less-or-equal (<=) **/
static obj<AGCObject> cmp_lessequal(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y);
/** compare two numeric values for greater (>) **/
static obj<AGCObject> cmp_greater(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y);
/** compare two numeric values for greater-or-equal (>=) **/
static obj<AGCObject> cmp_greatequal(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y);
/** report memory use for owned arenas to @p visitor **/
void visit_pools(const MemorySizeVisitor & visitor);
/** Use:
* Need to have overload
* multiply(obj<AAllocator>, DRepr1, DRepr2) -> obj<ANumeric>
* available
**/
template <typename DRepr1, typename DRepr2>
void register_impl(typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl mul_fn,
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl div_fn,
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl add_fn,
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl sub_fn,
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl cmpeq_fn,
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl cmpne_fn,
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl cmplt_fn,
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl cmple_fn,
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl cmpgt_fn,
typename NumericOps<DRepr1, DRepr2>::BinaryOp_Impl cmpge_fn) {
KeyType key(typeseq::id<DRepr1>().seqno(),
typeseq::id<DRepr2>().seqno());
// note: copying op table so they're in proximity
this->dispatch_[key]
= NumericOps<DRepr1, DRepr2>::make(mul_fn,
div_fn,
add_fn,
sub_fn,
cmpeq_fn,
cmpne_fn,
cmplt_fn,
cmple_fn,
cmpgt_fn,
cmpge_fn);
}
private:
/** 2d dispatch for arithmetic **/
MapType dispatch_;
};
} /*namespace scm*/
} /*namespace xo*/
/* end NumericDispatch.hpp */

View file

@ -0,0 +1,94 @@
/** @file NumericOps.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include <xo/numeric/Numeric.hpp>
#include <xo/procedure2/RuntimeContext.hpp>
#include <xo/alloc2/GCObject.hpp>
#include <xo/facet/obj.hpp>
namespace xo {
namespace scm {
class AnonymizedNumericOps {
public:
using ARuntimeContext = xo::scm::ARuntimeContext;
using AGCObject = xo::mm::AGCObject;
using BinaryOp = obj<AGCObject> (*)(obj<ARuntimeContext> mm, void * x, void * y);
public:
/** note: null ctor load-bearing for membership in DArenaHashTable **/
AnonymizedNumericOps() = default;
/** @p multiply to multiply (x,y); allocate from mm **/
explicit AnonymizedNumericOps(BinaryOp multiply,
BinaryOp divide,
BinaryOp add,
BinaryOp subtract,
BinaryOp cmpeq,
BinaryOp cmpne,
BinaryOp cmplt,
BinaryOp cmple,
BinaryOp cmpgt,
BinaryOp cmpge)
: multiply_{multiply}, divide_{divide}, add_{add}, subtract_{subtract},
cmpeq_{cmpeq}, cmpne_{cmpne},
cmplt_{cmplt}, cmple_{cmple},
cmpgt_{cmpgt}, cmpge_{cmpge} {}
BinaryOp multiply_ = nullptr;
BinaryOp divide_ = nullptr;
BinaryOp add_ = nullptr;
BinaryOp subtract_ = nullptr;
/** compare numerics (==) **/
BinaryOp cmpeq_ = nullptr;
/** compare numerics (!=) **/
BinaryOp cmpne_ = nullptr;
/** compare numerics (<) **/
BinaryOp cmplt_ = nullptr;
/** compare numerics (<=) **/
BinaryOp cmple_ = nullptr;
/** compare numerics (>) **/
BinaryOp cmpgt_ = nullptr;
/** compare numerics (>=) **/
BinaryOp cmpge_ = nullptr;
};
template <typename DRepr1, typename DRepr2>
class NumericOps {
public:
using ARuntimeContext = xo::scm::ARuntimeContext;
using AGCObject = xo::mm::AGCObject;
using BinaryOp_Impl = obj<AGCObject> (*)(obj<ARuntimeContext> rcx, DRepr1 * x, DRepr2 * y);
using BinaryOp_Anon = AnonymizedNumericOps::BinaryOp;
public:
static AnonymizedNumericOps make(BinaryOp_Impl multiply,
BinaryOp_Impl divide,
BinaryOp_Impl add,
BinaryOp_Impl subtract,
BinaryOp_Impl cmpeq,
BinaryOp_Impl cmpne,
BinaryOp_Impl cmplt,
BinaryOp_Impl cmple,
BinaryOp_Impl cmpgt,
BinaryOp_Impl cmpge) {
return AnonymizedNumericOps(reinterpret_cast<BinaryOp_Anon>(multiply),
reinterpret_cast<BinaryOp_Anon>(divide),
reinterpret_cast<BinaryOp_Anon>(add),
reinterpret_cast<BinaryOp_Anon>(subtract),
reinterpret_cast<BinaryOp_Anon>(cmpeq),
reinterpret_cast<BinaryOp_Anon>(cmpne),
reinterpret_cast<BinaryOp_Anon>(cmplt),
reinterpret_cast<BinaryOp_Anon>(cmple),
reinterpret_cast<BinaryOp_Anon>(cmpgt),
reinterpret_cast<BinaryOp_Anon>(cmpge));
}
};
} /*namespace scm*/
} /*namespace xo*/
/* end NumericOps.hpp */

View file

@ -0,0 +1,83 @@
/** @file NumericDispatch.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include <xo/procedure2/DPrimitive_gco_2_gco_gco.hpp>
namespace xo {
namespace scm {
/** @brief primitives using multidispatch
**/
class NumericPrimitives {
public:
using AAllocator = xo::mm::AAllocator;
public:
/** name for multiply primitive. Used for op* **/
static constexpr const char * c_multiply_pm_name = "_mul";
/** polymorphic (in both arguments1) multiply **/
static DPrimitive_gco_2_gco_gco * make_multiply_pm(obj<AAllocator> mm,
StringTable * stbl);
/** name for divide primitives. Used for op/ **/
static constexpr const char * c_divide_pm_name = "_div";
/** polymorphic (in both arguments) divide **/
static DPrimitive_gco_2_gco_gco * make_divide_pm(obj<AAllocator> mm,
StringTable * stbl);
/** name for add primitives. Used for op+ **/
static constexpr const char * c_add_pm_name = "_add";
/** polymorphic (in both arguments) add **/
static DPrimitive_gco_2_gco_gco * make_add_pm(obj<AAllocator> mm,
StringTable * stbl);
/** name for sub primitives. Used for op- **/
static constexpr const char * c_sub_pm_name = "_sub";
/** polymorphic (in both arguments) subtract **/
static DPrimitive_gco_2_gco_gco * make_subtract_pm(obj<AAllocator> mm,
StringTable * stbl);
/** name for equality-comparison primitive. Used for op== **/
static constexpr const char * c_cmpeq_pm_name = "_cmpeq";
/** polymorphic (in both arguments) compare (==) **/
static DPrimitive_gco_2_gco_gco * make_cmpeq_pm(obj<AAllocator> mm,
StringTable * stbl);
/** name for inequality-comparison prmitive. Used for op!= **/
static constexpr const char * c_cmpne_pm_name = "_cmpne";
/** polymorphic (in both arguments) compare (!=) **/
static DPrimitive_gco_2_gco_gco * make_cmpne_pm(obj<AAllocator> mm,
StringTable * stbl);
/** name for less-comparison primitive. Used for op< **/
static constexpr const char * c_cmplt_pm_name = "_cmplt";
/** polymorphic (in both arguments) compare (<) **/
static DPrimitive_gco_2_gco_gco * make_cmplt_pm(obj<AAllocator> mm,
StringTable * stbl);
/** name for lesser-or-equal-comparison primitive. Used for op<= **/
static constexpr const char * c_cmple_pm_name = "_cmple";
/** polymorphic (in both arguments) compare (<=) **/
static DPrimitive_gco_2_gco_gco * make_cmple_pm(obj<AAllocator> mm,
StringTable * stbl);
/** name for greater-comparison primitive. Used for op> **/
static constexpr const char * c_cmpgt_pm_name = "_cmpgt";
/** polymorphic (in both arguments) compare (>) **/
static DPrimitive_gco_2_gco_gco * make_cmpgt_pm(obj<AAllocator> mm,
StringTable * stbl);
/** name for greater-or-equal-comparison primitive. Used for op>= **/
static constexpr const char * c_cmpge_pm_name = "_cmpge";
/** polymorphic (in both arguments) compare (>=) **/
static DPrimitive_gco_2_gco_gco * make_cmpge_pm(obj<AAllocator> mm,
StringTable * stbl);
};
}
}
/* end NumericDispatch.hpp */

View file

@ -0,0 +1,25 @@
/** @file SetupNumeric.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "PrimitiveRegistry.hpp"
#include <xo/alloc2/Collector.hpp>
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<ARuntimeContext> rcx,
InstallSink sink,
InstallFlags flags);
};
}
}
/* end SetupNumeric.hpp */

View file

@ -0,0 +1,75 @@
/** @file ANumeric.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Numeric.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [abstract_facet.hpp.j2]
* 3. idl for facet methods
* [idl/Numeric.json5]
**/
#pragma once
// includes (via {facet_includes})
#include <xo/facet/obj.hpp>
#include <xo/facet/facet_implementation.hpp>
#include <xo/facet/typeseq.hpp>
namespace xo {
namespace scm {
using Copaque = const void *;
using Opaque = void *;
/**
Abstraction for a schematika numeric
**/
class ANumeric {
public:
/** @defgroup scm-numeric-type-traits **/
///@{
// types
/** integer identifying a type **/
using typeseq = xo::facet::typeseq;
using Copaque = const void *;
using Opaque = void *;
///@}
/** @defgroup scm-numeric-methods **/
///@{
// const methods
/** An uninitialized ANumeric instance will have zero vtable pointer (per {linux,osx} abi).
* Use case for this is narrow. We go to some lengths to avoid null vtable pointers. For example
* obj<AFacet> will have non-null vtable (via IFacet_Any) with all methods terminating.
**/
bool _has_null_vptr() const noexcept { return *reinterpret_cast<const void * const *>(this) == nullptr; }
/** RTTI: unique id# for actual runtime data representation **/
virtual typeseq _typeseq() const noexcept = 0;
/** destroy instance @p d; calls c++ dtor only for actual runtime type; does not recover memory **/
virtual void _drop(Opaque d) const noexcept = 0;
// nonconst methods
///@}
}; /*ANumeric*/
/** Implementation INumeric_DRepr of ANumeric for state DRepr
* should provide a specialization:
*
* template <>
* struct xo::facet::FacetImplementation<ANumeric, DRepr> {
* using Impltype = INumeric_DRepr;
* };
*
* then INumeric_ImplType<DRepr> --> INumeric_DRepr
**/
template <typename DRepr>
using INumeric_ImplType = xo::facet::FacetImplType<ANumeric, DRepr>;
} /*namespace scm*/
} /*namespace xo*/
/* ANumeric.hpp */

View file

@ -0,0 +1,87 @@
/** @file INumeric_Any.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Numeric.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/Numeric.json5]
**/
#pragma once
#include "ANumeric.hpp"
#include <xo/facet/obj.hpp>
namespace xo { namespace scm { class INumeric_Any; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::scm::ANumeric,
DVariantPlaceholder>
{
using ImplType = xo::scm::INumeric_Any;
};
}
}
namespace xo {
namespace scm {
/** @class INumeric_Any
* @brief ANumeric implementation for empty variant instance
**/
class INumeric_Any : public ANumeric {
public:
/** @defgroup scm-numeric-any-type-traits **/
///@{
/** integer identifying a type **/
using typeseq = xo::facet::typeseq;
///@}
/** @defgroup scm-numeric-any-methods **/
///@{
const ANumeric * iface() const { return std::launder(this); }
// from ANumeric
// builtin methods
typeseq _typeseq() const noexcept override { return s_typeseq; }
[[noreturn]] void _drop(Opaque) const noexcept override { _fatal(); }
// const methods
// nonconst methods
///@}
private:
/** @defgraoup scm-numeric-any-private-methods **/
///@{
[[noreturn]] static void _fatal();
///@}
public:
/** @defgroup scm-numeric-any-member-vars **/
///@{
static typeseq s_typeseq;
static bool _valid;
///@}
};
} /*namespace scm */
} /*namespace xo */
/* INumeric_Any.hpp */

View file

@ -0,0 +1,87 @@
/** @file INumeric_Xfer.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Numeric.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/Numeric.json5]
*
* variables:
* {facet_hpp_fname} -> Numeric.hpp
* {impl_hpp_subdir} -> detail
* {facet_ns1} -> xo
* {facet_detail_subdir} -> detail
* {abstract_facet_fname} -> ANumeric.hpp
**/
#pragma once
#include "ANumeric.hpp"
namespace xo {
namespace scm {
/** @class INumeric_Xfer
**/
template <typename DRepr, typename INumeric_DRepr>
class INumeric_Xfer : public ANumeric {
public:
/** @defgroup scm-numeric-xfer-type-traits **/
///@{
/** actual implementation (not generated; often delegates to DRepr) **/
using Impl = INumeric_DRepr;
/** integer identifying a type **/
using typeseq = ANumeric::typeseq;
///@}
/** @defgroup scm-numeric-xfer-methods **/
///@{
static const DRepr & _dcast(Copaque d) { return *(const DRepr *)d; }
static DRepr & _dcast(Opaque d) { return *(DRepr *)d; }
// from ANumeric
// builtin methods
typeseq _typeseq() const noexcept override { return s_typeseq; }
void _drop(Opaque d) const noexcept override { _dcast(d).~DRepr(); }
// const methods
// non-const methods
///@}
private:
using I = Impl;
public:
/** @defgroup scm-numeric-xfer-member-vars **/
///@{
/** typeseq for template parameter DRepr **/
static typeseq s_typeseq;
/** true iff satisfies facet implementation **/
static bool _valid;
///@}
};
template <typename DRepr, typename INumeric_DRepr>
xo::facet::typeseq
INumeric_Xfer<DRepr, INumeric_DRepr>::s_typeseq
= xo::facet::typeseq::id<DRepr>();
template <typename DRepr, typename INumeric_DRepr>
bool
INumeric_Xfer<DRepr, INumeric_DRepr>::_valid
= xo::facet::valid_facet_implementation<ANumeric,
INumeric_Xfer>();
} /*namespace scm */
} /*namespace xo*/
/* end INumeric_Xfer.hpp */

View file

@ -0,0 +1,82 @@
/** @file RNumeric.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Numeric.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/Numeric.json5]
**/
#pragma once
#include "ANumeric.hpp"
namespace xo {
namespace scm {
/** @class RNumeric
**/
template <typename Object>
class RNumeric : public Object {
private:
using O = Object;
public:
/** @defgroup scm-numeric-router-type-traits **/
///@{
using ObjectType = Object;
using DataPtr = Object::DataPtr;
using typeseq = xo::reflect::typeseq;
///@}
/** @defgroup scm-numeric-router-ctors **/
///@{
RNumeric() {}
RNumeric(Object::DataPtr data) : Object{std::move(data)} {}
RNumeric(const ANumeric * iface, void * data)
requires std::is_same_v<typename Object::DataType, xo::facet::DVariantPlaceholder>
: Object(iface, data) {}
///@}
/** @defgroup scm-numeric-router-methods **/
///@{
// explicit injected content
static obj<ANumeric> multiply(obj<ANumeric> lhs, obj<ANumeric> rhs);
// builtin methods
typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); }
void _drop() const noexcept { O::iface()->_drop(O::data()); }
// const methods
// non-const methods (still const in router!)
///@}
/** @defgroup scm-numeric-member-vars **/
///@{
static bool _valid;
///@}
};
template <typename Object>
bool
RNumeric<Object>::_valid = xo::facet::valid_object_router<Object>();
} /*namespace scm*/
} /*namespace xo*/
namespace xo { namespace facet {
template <typename Object>
struct RoutingFor<xo::scm::ANumeric, Object> {
using RoutingType = xo::scm::RNumeric<Object>;
};
} }
/* end RNumeric.hpp */

View file

@ -0,0 +1,56 @@
/** @file INumeric_DFloat.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/INumeric_DFloat.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_repr.hpp.j2]
* 3. idl for facet methods
* [idl/INumeric_DFloat.json5]
**/
#pragma once
#include "Numeric.hpp"
#include "DFloat.hpp"
namespace xo { namespace scm { class INumeric_DFloat; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::scm::ANumeric,
xo::scm::DFloat>
{
using ImplType = xo::scm::INumeric_Xfer
<xo::scm::DFloat,
xo::scm::INumeric_DFloat>;
};
}
}
namespace xo {
namespace scm {
/** @class INumeric_DFloat
**/
class INumeric_DFloat {
public:
/** @defgroup scm-numeric-dfloat-type-traits **/
///@{
using Copaque = xo::scm::ANumeric::Copaque;
using Opaque = xo::scm::ANumeric::Opaque;
///@}
/** @defgroup scm-numeric-dfloat-methods **/
///@{
// const methods
// non-const methods
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -0,0 +1,21 @@
/** @file init_numeric.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include <xo/subsys/Subsystem.hpp>
namespace xo {
/* tag to represent the xo-numeric/ subsystem within ordered initialization */
enum S_numeric_tag {};
template <>
struct InitSubsys<S_numeric_tag> {
static void init();
static InitEvidence require();
};
}
/* end init_numeric.hpp */

View file

@ -0,0 +1,56 @@
/** @file INumeric_DInteger.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/INumeric_DInteger.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_repr.hpp.j2]
* 3. idl for facet methods
* [idl/INumeric_DInteger.json5]
**/
#pragma once
#include "Numeric.hpp"
#include "DInteger.hpp"
namespace xo { namespace scm { class INumeric_DInteger; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::scm::ANumeric,
xo::scm::DInteger>
{
using ImplType = xo::scm::INumeric_Xfer
<xo::scm::DInteger,
xo::scm::INumeric_DInteger>;
};
}
}
namespace xo {
namespace scm {
/** @class INumeric_DInteger
**/
class INumeric_DInteger {
public:
/** @defgroup scm-numeric-dinteger-type-traits **/
///@{
using Copaque = xo::scm::ANumeric::Copaque;
using Opaque = xo::scm::ANumeric::Opaque;
///@}
/** @defgroup scm-numeric-dinteger-methods **/
///@{
// const methods
// non-const methods
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -0,0 +1,25 @@
# numeric/CMakeLists.txt
set(SELF_LIB xo_numeric)
set(SELF_SRCS
init_numeric.cpp
SetupNumeric.cpp
NumericPrimitives.cpp
NumericDispatch.cpp
INumeric_Any.cpp
FloatIntegerOps.cpp
FloatOps.cpp
IntegerOps.cpp
)
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})
xo_dependency(${SELF_LIB} xo_procedure2)
xo_dependency(${SELF_LIB} subsys)
xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets)
# ----------------------------------------------------------------
# docs targets depend on other library/utest/exec targets above,
# --> must come after them.
#
#add_subdirectory(docs)

View file

@ -0,0 +1,174 @@
/** @file FloatIntegerOps.cp
*
* @author Roland Conybeare, Feb 2206
**/
#include "FloatIntegerOps.hpp"
#include "float/INumeric_DFloat.hpp"
#include <xo/object2/Boolean.hpp>
namespace xo {
using xo::mm::AGCObject;
namespace scm {
// ----- Float op Integer -----
obj<AGCObject>
FloatIntegerOps::multiply(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y)
{
return DFloat::box<AGCObject>(rcx.allocator(), x->value() * y->value());
}
obj<AGCObject>
FloatIntegerOps::divide(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y)
{
return DFloat::box<AGCObject>(rcx.allocator(), x->value() / y->value());
}
obj<AGCObject>
FloatIntegerOps::add(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y)
{
return DFloat::box<AGCObject>(rcx.allocator(), x->value() + y->value());
}
obj<AGCObject>
FloatIntegerOps::subtract(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y)
{
return DFloat::box<AGCObject>(rcx.allocator(), x->value() - y->value());
}
obj<AGCObject>
FloatIntegerOps::cmp_equal(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
x->value() == DFloat::value_type(y->value()));
}
obj<AGCObject>
FloatIntegerOps::cmp_notequal(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
x->value() != DFloat::value_type(y->value()));
}
obj<AGCObject>
FloatIntegerOps::cmp_less(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
x->value() < DFloat::value_type(y->value()));
}
obj<AGCObject>
FloatIntegerOps::cmp_lessequal(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
x->value() <= DFloat::value_type(y->value()));
}
obj<AGCObject>
FloatIntegerOps::cmp_greater(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
x->value() > DFloat::value_type(y->value()));
}
obj<AGCObject>
FloatIntegerOps::cmp_greatequal(obj<ARuntimeContext> rcx,
DFloat * x, DInteger * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
x->value() >= DFloat::value_type(y->value()));
}
// ----- Integer op Float -----
obj<AGCObject>
IntegerFloatOps::multiply(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y)
{
return DFloat::box<AGCObject>(rcx.allocator(), x->value() * y->value());
}
obj<AGCObject>
IntegerFloatOps::divide(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y)
{
return DFloat::box<AGCObject>(rcx.allocator(), x->value() / y->value());
}
obj<AGCObject>
IntegerFloatOps::add(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y)
{
return DFloat::box<AGCObject>(rcx.allocator(), x->value() + y->value());
}
obj<AGCObject>
IntegerFloatOps::subtract(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y)
{
return DFloat::box<AGCObject>(rcx.allocator(), x->value() - y->value());
}
obj<AGCObject>
IntegerFloatOps::cmp_equal(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
DFloat::value_type(x->value()) == y->value());
}
obj<AGCObject>
IntegerFloatOps::cmp_notequal(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
DFloat::value_type(x->value()) != y->value());
}
obj<AGCObject>
IntegerFloatOps::cmp_less(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
DFloat::value_type(x->value()) < y->value());
}
obj<AGCObject>
IntegerFloatOps::cmp_lessequal(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
DFloat::value_type(x->value()) <= y->value());
}
obj<AGCObject>
IntegerFloatOps::cmp_greater(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
DFloat::value_type(x->value()) > y->value());
}
obj<AGCObject>
IntegerFloatOps::cmp_greatequal(obj<ARuntimeContext> rcx,
DInteger * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
DFloat::value_type(x->value()) >= y->value());
}
}
}
/* end FloatIntegerOps.cpp */

View file

@ -0,0 +1,96 @@
/** @file FloatOps.cp
*
* @author Roland Conybeare, Feb 2206
**/
#include "FloatOps.hpp"
#include "float/INumeric_DFloat.hpp"
#include <xo/object2/Boolean.hpp>
namespace xo {
using xo::mm::AGCObject;
namespace scm {
obj<AGCObject>
FloatOps::multiply(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y)
{
return DFloat::box<AGCObject>(rcx.allocator(), x->value() * y->value());
}
obj<AGCObject>
FloatOps::divide(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y)
{
return DFloat::box<AGCObject>(rcx.allocator(),
x->value() / y->value());
}
obj<AGCObject>
FloatOps::add(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y)
{
return DFloat::box<AGCObject>(rcx.allocator(),
x->value() + y->value());
}
obj<AGCObject>
FloatOps::subtract(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y)
{
return DFloat::box<AGCObject>(rcx.allocator(),
x->value() - y->value());
}
obj<AGCObject>
FloatOps::cmp_equal(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
x->value() == y->value());
}
obj<AGCObject>
FloatOps::cmp_notequal(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
x->value() != y->value());
}
obj<AGCObject>
FloatOps::cmp_less(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
x->value() < y->value());
}
obj<AGCObject>
FloatOps::cmp_lessequal(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
x->value() <= y->value());
}
obj<AGCObject>
FloatOps::cmp_greater(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
x->value() > y->value());
}
obj<AGCObject>
FloatOps::cmp_greatequal(obj<ARuntimeContext> rcx,
DFloat * x, DFloat * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(),
x->value() >= y->value());
}
}
}
/* end FloatOps.cpp */

View file

@ -0,0 +1,42 @@
/** @file INumeric_Any.cpp
*
**/
#include "detail/INumeric_Any.hpp"
#include <iostream>
#include <exception>
namespace xo {
namespace scm {
using xo::facet::DVariantPlaceholder;
using xo::facet::typeseq;
using xo::facet::valid_facet_implementation;
void
INumeric_Any::_fatal()
{
/* control here on uninitialized IAllocator_Any.
* Initialized instance will have specific implementation type
*/
std::cerr << "fatal"
<< ": attempt to call uninitialized"
<< " INumeric_Any method"
<< std::endl;
std::terminate();
}
typeseq
INumeric_Any::s_typeseq = typeseq::id<DVariantPlaceholder>();
bool
INumeric_Any::_valid
= valid_facet_implementation<ANumeric, INumeric_Any>();
// nonconst methods
} /*namespace scm*/
} /*namespace xo*/
/* end INumeric_Any.cpp */

View file

@ -0,0 +1,22 @@
/** @file INumeric_DFloat.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/INumeric_DFloat.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/INumeric_DFloat.json5]
**/
#include "float/INumeric_DFloat.hpp"
namespace xo {
namespace scm {
} /*namespace scm*/
} /*namespace xo*/
/* end INumeric_DFloat.cpp */

View file

@ -0,0 +1,22 @@
/** @file INumeric_DInteger.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/INumeric_DInteger.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/INumeric_DInteger.json5]
**/
#include "integer/INumeric_DInteger.hpp"
namespace xo {
namespace scm {
} /*namespace scm*/
} /*namespace xo*/
/* end INumeric_DInteger.cpp */

View file

@ -0,0 +1,89 @@
/** @file IntegerOps.cpp
*
* @author Roland Conybeare, Feb 2026
**/
#include "IntegerOps.hpp"
#include "integer/INumeric_DInteger.hpp"
#include <xo/object2/Boolean.hpp>
namespace xo {
using xo::scm::DBoolean;
using xo::mm::AGCObject;
namespace scm {
obj<AGCObject>
IntegerOps::multiply(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y)
{
return DInteger::box<AGCObject>(rcx.allocator(), x->value() * y->value());
}
obj<AGCObject>
IntegerOps::divide(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y)
{
return DInteger::box<AGCObject>(rcx.allocator(), x->value() / y->value());
}
obj<AGCObject>
IntegerOps::add(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y)
{
return DInteger::box<AGCObject>(rcx.allocator(), x->value() + y->value());
}
obj<AGCObject>
IntegerOps::subtract(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y)
{
return DInteger::box<AGCObject>(rcx.allocator(), x->value() - y->value());
}
obj<AGCObject>
IntegerOps::cmp_equal(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(), x->value() == y->value());
}
obj<AGCObject>
IntegerOps::cmp_notequal(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(), x->value() != y->value());
}
obj<AGCObject>
IntegerOps::cmp_less(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(), x->value() < y->value());
}
obj<AGCObject>
IntegerOps::cmp_lessequal(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(), x->value() <= y->value());
}
obj<AGCObject>
IntegerOps::cmp_greater(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(), x->value() > y->value());
}
obj<AGCObject>
IntegerOps::cmp_greatequal(obj<ARuntimeContext> rcx,
DInteger * x, DInteger * y)
{
return DBoolean::box<AGCObject>(rcx.allocator(), x->value() >= y->value());
}
}
}
/* end IntegerOps.cpp */

View file

@ -0,0 +1,192 @@
/** @file NumericDispatch.cpp
*
* @author Roland Conybeare, Feb 2026
**/
#include "NumericDispatch.hpp"
#include <xo/object2/RuntimeError.hpp>
#include <xo/facet/TypeRegistry.hpp>
#include <xo/indentlog/scope.hpp>
namespace xo {
using xo::mm::AGCObject;
using xo::facet::TypeRegistry;
namespace scm {
void
NumericDispatch::visit_pools(const MemorySizeVisitor & visitor)
{
dispatch_.visit_pools(visitor);
}
obj<AGCObject>
NumericDispatch::dispatch(obj<ARuntimeContext> rcx,
const char * caller,
const char * error_headline,
BinaryOp AnonymizedNumericOps::* member_ptr,
obj<AGCObject> x,
obj<AGCObject> y)
{
KeyType key(x._typeseq(), y._typeseq());
auto target_fn
= NumericDispatch::instance().dispatch_[key].*member_ptr;
if (!target_fn) {
// FIXME: use {fmt} here
std::stringstream ss;
tosn(ss,
error_headline,
xtag("x.tseq", x._typeseq()),
xtag("x.type", TypeRegistry::id2name(x._typeseq())),
xtag("x.data", x.data()),
xtag("y.tseq", y._typeseq()),
xtag("y.type", TypeRegistry::id2name(y._typeseq())),
xtag("y.data", y.data()));
return DRuntimeError::make(rcx.allocator(),
caller,
ss.str().c_str());
}
return (*target_fn)(rcx, x.data(), y.data());
}
obj<AGCObject>
NumericDispatch::multiply(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y)
{
return dispatch(rcx,
"NumericDispatch::multiply",
"incomparable types in x*y",
&AnonymizedNumericOps::multiply_,
x, y);
}
obj<AGCObject>
NumericDispatch::divide(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y)
{
return dispatch(rcx,
"NumericDispatch::divide",
"incomparable types in x/y",
&AnonymizedNumericOps::divide_,
x, y);
#ifdef OBSOLETE
KeyType key(x._typeseq(), y._typeseq());
auto target_fn
= NumericDispatch::instance().dispatch_[key].divide_;
if (!target_fn)
assert(false);
return (*target_fn)(rcx, x.data(), y.data());
#endif
}
obj<AGCObject>
NumericDispatch::add(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y)
{
return dispatch(rcx,
"NumericDispatch::add",
"incomparable types in x+y",
&AnonymizedNumericOps::add_,
x, y);
}
obj<AGCObject>
NumericDispatch::subtract(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y)
{
return dispatch(rcx,
"NumericDispatch::subtract",
"incomparable types in x-y",
&AnonymizedNumericOps::subtract_,
x, y);
}
obj<AGCObject>
NumericDispatch::cmp_equal(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y)
{
return dispatch(rcx,
"NumericDispatch::cmp_equal",
"incomparable types in x==y",
&AnonymizedNumericOps::cmpeq_,
x, y);
}
obj<AGCObject>
NumericDispatch::cmp_notequal(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y)
{
return dispatch(rcx,
"NumericDispatch::cmp_notequal",
"incomparable types in x!=y",
&AnonymizedNumericOps::cmpne_,
x, y);
}
obj<AGCObject>
NumericDispatch::cmp_less(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y)
{
return dispatch(rcx,
"NumericDispatch::cmp_less",
"incomparable types in x<y",
&AnonymizedNumericOps::cmplt_,
x, y);
}
obj<AGCObject>
NumericDispatch::cmp_lessequal(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y)
{
return dispatch(rcx,
"NumericDispatch::cmp_lessequal",
"incomparable types in x<=y",
&AnonymizedNumericOps::cmple_,
x, y);
}
obj<AGCObject>
NumericDispatch::cmp_greater(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y)
{
return dispatch(rcx,
"NumericDispatch::cmp_greater",
"incomparable types in x>y",
&AnonymizedNumericOps::cmpgt_,
x, y);
}
obj<AGCObject>
NumericDispatch::cmp_greatequal(obj<ARuntimeContext> rcx,
obj<AGCObject> x,
obj<AGCObject> y)
{
return dispatch(rcx,
"NumericDispatch::cmp_greatequal",
"incomparable types in x>=y",
&AnonymizedNumericOps::cmpge_,
x, y);
}
} /*namespace scm*/
} /*namespace xo*/
/* end NumericDispatch.cpp **/

View file

@ -0,0 +1,182 @@
/** @file NumericPrimitives.cpp
*
* @author Roland Conybeare, Feb 2026
**/
#include "NumericPrimitives.hpp"
#include "NumericDispatch.hpp"
#include <xo/type/AtomicType.hpp>
#include <xo/type/FunctionType.hpp>
namespace xo {
using xo::mm::AAllocator;
//using xo::mm::AGCObject;
namespace scm {
DPrimitive_gco_2_gco_gco *
NumericPrimitives::make_multiply_pm(obj<AAllocator> mm,
StringTable * stbl)
{
(void)stbl;
// TODO: want to expand this to record schedule based on argument types.
//
// e.g. f64 x f64 -> f64
auto numeric_ty = DAtomicType::make(mm, Metatype::t_numeric());
// #op+: numeric x numeric -> numeric
auto pm_ty = obj<AType,DFunctionType>
(DFunctionType::_make(mm, numeric_ty, numeric_ty, numeric_ty));
return DPrimitive_gco_2_gco_gco::_make(mm, c_multiply_pm_name, pm_ty,
&NumericDispatch::multiply);
}
DPrimitive_gco_2_gco_gco *
NumericPrimitives::make_divide_pm(obj<AAllocator> mm,
StringTable * stbl)
{
(void)stbl;
auto numeric_ty = DAtomicType::make(mm, Metatype::t_numeric());
// #op+: numeric x numeric -> numeric
auto pm_ty = obj<AType,DFunctionType>
(DFunctionType::_make(mm, numeric_ty, numeric_ty, numeric_ty));
return DPrimitive_gco_2_gco_gco::_make(mm, c_divide_pm_name, pm_ty,
&NumericDispatch::divide);
}
DPrimitive_gco_2_gco_gco *
NumericPrimitives::make_add_pm(obj<AAllocator> mm,
StringTable * stbl)
{
(void)stbl;
auto numeric_ty = DAtomicType::make(mm, Metatype::t_numeric());
// #op+: numeric x numeric -> numeric
auto pm_ty = obj<AType,DFunctionType>
(DFunctionType::_make(mm, numeric_ty, numeric_ty, numeric_ty));
return DPrimitive_gco_2_gco_gco::_make(mm, c_add_pm_name, pm_ty,
&NumericDispatch::add);
}
DPrimitive_gco_2_gco_gco *
NumericPrimitives::make_subtract_pm(obj<AAllocator> mm,
StringTable * stbl)
{
(void)stbl;
auto numeric_ty = DAtomicType::make(mm, Metatype::t_numeric());
// #op+: numeric x numeric -> numeric
auto pm_ty = obj<AType,DFunctionType>
(DFunctionType::_make(mm, numeric_ty, numeric_ty, numeric_ty));
return DPrimitive_gco_2_gco_gco::_make(mm, c_sub_pm_name, pm_ty,
&NumericDispatch::subtract);
}
DPrimitive_gco_2_gco_gco *
NumericPrimitives::make_cmpeq_pm(obj<AAllocator> mm,
StringTable * stbl)
{
(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<AType,DFunctionType>
(DFunctionType::_make(mm, booleic_ty, numeric_ty, numeric_ty));
return DPrimitive_gco_2_gco_gco::_make(mm, c_cmpeq_pm_name, pm_ty,
&NumericDispatch::cmp_equal);
}
DPrimitive_gco_2_gco_gco *
NumericPrimitives::make_cmpne_pm(obj<AAllocator> mm,
StringTable * stbl)
{
(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<AType,DFunctionType>
(DFunctionType::_make(mm, booleic_ty, numeric_ty, numeric_ty));
return DPrimitive_gco_2_gco_gco::_make(mm, c_cmpne_pm_name, pm_ty,
&NumericDispatch::cmp_notequal);
}
DPrimitive_gco_2_gco_gco *
NumericPrimitives::make_cmplt_pm(obj<AAllocator> mm,
StringTable * stbl)
{
(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<AType,DFunctionType>
(DFunctionType::_make(mm, booleic_ty, numeric_ty, numeric_ty));
return DPrimitive_gco_2_gco_gco::_make(mm, c_cmplt_pm_name, pm_ty,
&NumericDispatch::cmp_less);
}
DPrimitive_gco_2_gco_gco *
NumericPrimitives::make_cmple_pm(obj<AAllocator> mm,
StringTable * stbl)
{
(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<AType,DFunctionType>
(DFunctionType::_make(mm, booleic_ty, numeric_ty, numeric_ty));
return DPrimitive_gco_2_gco_gco::_make(mm, c_cmple_pm_name, pm_ty,
&NumericDispatch::cmp_lessequal);
}
DPrimitive_gco_2_gco_gco *
NumericPrimitives::make_cmpgt_pm(obj<AAllocator> mm,
StringTable * stbl)
{
(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<AType,DFunctionType>
(DFunctionType::_make(mm, booleic_ty, numeric_ty, numeric_ty));
return DPrimitive_gco_2_gco_gco::_make(mm, c_cmpgt_pm_name, pm_ty,
&NumericDispatch::cmp_greater);
}
DPrimitive_gco_2_gco_gco *
NumericPrimitives::make_cmpge_pm(obj<AAllocator> mm,
StringTable * stbl)
{
(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<AType,DFunctionType>
(DFunctionType::_make(mm, booleic_ty, numeric_ty, numeric_ty));
return DPrimitive_gco_2_gco_gco::_make(mm, c_cmpge_pm_name, pm_ty,
&NumericDispatch::cmp_greatequal);
}
} /*namespace scm*/
} /*namespace xo*/
/* end NumericDispatch.cpp */

View file

@ -0,0 +1,162 @@
/** @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 <xo/procedure2/Primitive_gco_2_gco_gco.hpp>
#include <xo/object2/DFloat.hpp>
#include <xo/object2/Integer.hpp>
#include <xo/facet/FacetRegistry.hpp>
#include <xo/reflectutil/typeseq.hpp>
#include <xo/indentlog/scope.hpp>
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<ANumeric, DInteger>();
NumericDispatch::instance().register_impl<DFloat, DFloat>
(&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<DFloat, DInteger>
(&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<DInteger, DFloat>
(&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<DInteger, DInteger>
(&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<ANumeric>()));
return true;
}
bool
SetupNumeric::register_primitives(obj<ARuntimeContext> rcx,
InstallSink sink,
InstallFlags flags)
{
obj<AAllocator> mm = rcx.allocator();
StringTable * stbl = rcx.stringtable();
scope log(XO_DEBUG(false));
bool ok = true;
/* "_mul" */
ok = ok & (PrimitiveRegistry::install_aux
(sink,
NumericPrimitives::make_multiply_pm(mm, stbl),
flags & InstallFlags::f_essential));
/* "_div" */
ok = ok & (PrimitiveRegistry::install_aux
(sink,
NumericPrimitives::make_divide_pm(mm, stbl),
flags & InstallFlags::f_essential));
/* "_add" */
ok = ok & (PrimitiveRegistry::install_aux
(sink,
NumericPrimitives::make_add_pm(mm, stbl),
flags & InstallFlags::f_essential));
/* "_sub" */
ok = ok & (PrimitiveRegistry::install_aux
(sink,
NumericPrimitives::make_subtract_pm(mm, stbl),
flags & InstallFlags::f_essential));
/* "_cmpeq" */
ok = ok & (PrimitiveRegistry::install_aux
(sink,
NumericPrimitives::make_cmpeq_pm(mm, stbl),
flags & InstallFlags::f_essential));
/* "_cmpne" */
ok = ok & (PrimitiveRegistry::install_aux
(sink,
NumericPrimitives::make_cmpne_pm(mm, stbl),
flags & InstallFlags::f_essential));
/* "_cmplt" */
ok = ok & (PrimitiveRegistry::install_aux
(sink,
NumericPrimitives::make_cmplt_pm(mm, stbl),
flags & InstallFlags::f_essential));
/* "_cmple" */
ok = ok & (PrimitiveRegistry::install_aux
(sink,
NumericPrimitives::make_cmple_pm(mm, stbl),
flags & InstallFlags::f_essential));
/* "_cmpgt" */
ok = ok & (PrimitiveRegistry::install_aux
(sink,
NumericPrimitives::make_cmpgt_pm(mm, stbl),
flags & InstallFlags::f_essential));
/* "_cmpge" */
ok = ok & (PrimitiveRegistry::install_aux
(sink,
NumericPrimitives::make_cmpge_pm(mm, stbl),
flags & InstallFlags::f_essential));
return ok;
}
} /*namespace scm*/
} /*namespace xo*/
/* end SetupNumeric.cpp */

View file

@ -0,0 +1,41 @@
/** @file init_numeric.cpp
*
* @author Roland Conybeare, Feb 2026
**/
#include "init_numeric.hpp"
#include "SetupNumeric.hpp"
#include <xo/procedure2/init_procedure2.hpp>
#include "Subsystem.hpp"
namespace xo {
using xo::scm::SetupNumeric;
//using xo::scm::numeric_register_primitives;
using xo::scm::PrimitiveRegistry;
void
InitSubsys<S_numeric_tag>::init()
{
SetupNumeric::register_facets();
PrimitiveRegistry::instance().register_primitives(&SetupNumeric::register_primitives);
}
InitEvidence
InitSubsys<S_numeric_tag>::require()
{
InitEvidence retval;
/* direct subsystem deps for xo-numeric/ */
retval ^= InitSubsys<S_procedure2_tag>::require();
/* xo-numeric/'s own initialization code */
retval ^= Subsystem::provide<S_numeric_tag>("numeric", &init);
return retval;
}
} /*namespace xo*/
/* end init_numeric.cpp */

View file

@ -0,0 +1,12 @@
# built unittest xo-numeric/utest
set(UTEST_EXE utest.numeric)
set(UTEST_SRCS
numeric_utest_main.cpp
Numeric.test.cpp
)
xo_add_utest_executable(${UTEST_EXE} ${UTEST_SRCS})
xo_self_dependency(${UTEST_EXE} xo_numeric)
#xo_dependency(${UTEST_EXE} randomgen)
xo_external_target_dependency(${UTEST_EXE} Catch2 Catch2::Catch2)

View file

@ -0,0 +1,76 @@
/** @file Numeric.test.cpp
*
* @author Roland Conybeare, Feb 2026
**/
#include "init_numeric.hpp"
#include "NumericDispatch.hpp"
#include <xo/facet/FacetRegistry.hpp>
#include <xo/facet/TypeRegistry.hpp>
#include <catch2/catch.hpp>
namespace xo {
using xo::scm::NumericDispatch;
//using xo::mm::AAllocator;
using xo::mm::DArena;
using xo::mm::ArenaConfig;;
using xo::mm::MemorySizeInfo;
using xo::facet::FacetRegistry;
using xo::facet::TypeRegistry;
//using xo::facet::with_facet;
//using xo::facet::obj;
namespace ut {
namespace {
struct Fixture {
explicit Fixture(const std::string & testname,
std::size_t aux_arena_size = 16 * 1024)
: aux_arena_(
ArenaConfig().with_name(testname).with_size(aux_arena_size))
{}
bool log_memory_layout(scope * p_log) {
auto visitor = [p_log](const MemorySizeInfo & info) {
*p_log && (*p_log)(xtag("resource", info.resource_name_),
xtag("used", info.used_),
xtag("alloc", info.allocated_),
xtag("commit", info.committed_),
xtag("resv", info.reserved_));
};
aux_arena_.visit_pools(visitor);
TypeRegistry::instance().visit_pools(visitor);
FacetRegistry::instance().visit_pools(visitor);
NumericDispatch::instance().visit_pools(visitor);
return true;
}
DArena aux_arena_;
};
} /*namespace*/
static InitEvidence s_init = (InitSubsys<S_numeric_tag>::require());
TEST_CASE("Numeric-init" "[numeric]")
{
const auto & testname = Catch::getResultCapture().getCurrentTestName();
constexpr bool c_debug_flag = true;
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
Fixture fixture(testname);
{
// real purpose: ensure s_init sutvives static linking
REQUIRE(s_init.evidence());
}
log && fixture.log_memory_layout(&log);
}
} /*namespace ut*/
} /*namespace xo*/
/* end Numeric.test.cpp */

View file

@ -0,0 +1,24 @@
/* file numeric_utest_main.cpp */
#include <xo/subsys/Subsystem.hpp>
#define CATCH_CONFIG_RUNNER
#include "catch2/catch.hpp"
int
main(int argc, char* argv[])
{
using xo::Subsystem;
// Your custom initialization code here
Subsystem::initialize_all();
// Run Catch2's test session
int result = Catch::Session().run(argc, argv);
// cleanup here, if any
return result;
}
/* end numeric_utest_main.cpp */