xo-reader2 stack: + xo-numeric + setup multi dispatch for *,/
This commit is contained in:
parent
b8fd087319
commit
ac1395ce98
28 changed files with 912 additions and 70 deletions
25
src/numeric/CMakeLists.txt
Normal file
25
src/numeric/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# numeric/CMakeLists.txt
|
||||
|
||||
set(SELF_LIB xo_numeric)
|
||||
set(SELF_SRCS
|
||||
init_numeric.cpp
|
||||
numeric_register_facets.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)
|
||||
48
src/numeric/FloatIntegerOps.cpp
Normal file
48
src/numeric/FloatIntegerOps.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/** @file FloatIntegerOps.cp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2206
|
||||
**/
|
||||
|
||||
#include "FloatIntegerOps.hpp"
|
||||
#include "float/INumeric_DFloat.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());
|
||||
}
|
||||
|
||||
// ----- 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* end FloatIntegerOps.cpp */
|
||||
31
src/numeric/FloatOps.cpp
Normal file
31
src/numeric/FloatOps.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/** @file FloatOps.cp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2206
|
||||
**/
|
||||
|
||||
#include "FloatOps.hpp"
|
||||
#include "float/INumeric_DFloat.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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* end FloatOps.cpp */
|
||||
22
src/numeric/INumeric_DFloat.cpp
Normal file
22
src/numeric/INumeric_DFloat.cpp
Normal 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 */
|
||||
22
src/numeric/INumeric_DInteger.cpp
Normal file
22
src/numeric/INumeric_DInteger.cpp
Normal 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 */
|
||||
31
src/numeric/IntegerOps.cpp
Normal file
31
src/numeric/IntegerOps.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/** @file IntegerOps.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#include "IntegerOps.hpp"
|
||||
#include "integer/INumeric_DInteger.hpp"
|
||||
|
||||
namespace xo {
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* end IntegerOps.cpp */
|
||||
59
src/numeric/NumericDispatch.cpp
Normal file
59
src/numeric/NumericDispatch.cpp
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/** @file NumericDispatch.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#include "NumericDispatch.hpp"
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AGCObject;
|
||||
|
||||
namespace scm {
|
||||
|
||||
void
|
||||
NumericDispatch::visit_pools(const MemorySizeVisitor & visitor)
|
||||
{
|
||||
dispatch_.visit_pools(visitor);
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
NumericDispatch::multiply(obj<ARuntimeContext> rcx,
|
||||
obj<AGCObject> x,
|
||||
obj<AGCObject> y)
|
||||
{
|
||||
KeyType key(x._typeseq(), y._typeseq());
|
||||
|
||||
auto target_fn
|
||||
= NumericDispatch::instance().dispatch_[key].multiply_;
|
||||
|
||||
return (*target_fn)(rcx, x.data(), y.data());
|
||||
}
|
||||
|
||||
obj<AGCObject>
|
||||
NumericDispatch::divide(obj<ARuntimeContext> rcx,
|
||||
obj<AGCObject> x,
|
||||
obj<AGCObject> y)
|
||||
{
|
||||
scope log(XO_DEBUG(true));
|
||||
|
||||
KeyType key(x._typeseq(), y._typeseq());
|
||||
|
||||
log && log(xtag("x.tseq", x._typeseq().seqno()),
|
||||
xtag("y.tseq", y._typeseq().seqno()));
|
||||
|
||||
auto target_fn
|
||||
= NumericDispatch::instance().dispatch_[key].divide_;
|
||||
|
||||
log && log(xtag("target_fn", target_fn));
|
||||
|
||||
assert(target_fn);
|
||||
|
||||
return (*target_fn)(rcx, x.data(), y.data());
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end NumericDispatch.cpp **/
|
||||
22
src/numeric/NumericPrimitives.cpp
Normal file
22
src/numeric/NumericPrimitives.cpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/** @file NumericPrimitives.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#include "NumericPrimitives.hpp"
|
||||
#include "NumericDispatch.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AGCObject;
|
||||
|
||||
namespace scm {
|
||||
|
||||
DPrimitive_gco_2_gco_gco
|
||||
NumericPrimitives::s_div_gco_gco_pm("_div",
|
||||
&NumericDispatch::divide);
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end NumericDispatch.cpp */
|
||||
36
src/numeric/init_numeric.cpp
Normal file
36
src/numeric/init_numeric.cpp
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/** @file init_numeric.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#include "init_numeric.hpp"
|
||||
#include <xo/procedure2/init_procedure2.hpp>
|
||||
#include "Subsystem.hpp"
|
||||
#include "numeric_register_facets.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::scm::numeric_register_facets;
|
||||
|
||||
void
|
||||
InitSubsys<S_numeric_tag>::init()
|
||||
{
|
||||
numeric_register_facets();
|
||||
}
|
||||
|
||||
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 */
|
||||
61
src/numeric/numeric_register_facets.cpp
Normal file
61
src/numeric/numeric_register_facets.cpp
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/** @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 <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::facet::FacetRegistry;
|
||||
using xo::reflect::typeseq;
|
||||
|
||||
namespace scm {
|
||||
|
||||
bool
|
||||
numeric_register_facets()
|
||||
{
|
||||
scope log(XO_DEBUG(true));
|
||||
|
||||
FacetRegistry::register_impl<ANumeric, DInteger>();
|
||||
|
||||
NumericDispatch::instance().register_impl<DFloat, DFloat>
|
||||
(&FloatOps::multiply,
|
||||
&FloatOps::divide);
|
||||
|
||||
NumericDispatch::instance().register_impl<DFloat, DInteger>
|
||||
(&FloatIntegerOps::multiply,
|
||||
&FloatIntegerOps::divide);
|
||||
|
||||
NumericDispatch::instance().register_impl<DInteger, DFloat>
|
||||
(&IntegerFloatOps::multiply,
|
||||
&IntegerFloatOps::divide);
|
||||
|
||||
NumericDispatch::instance().register_impl<DInteger, DInteger>
|
||||
(&IntegerOps::multiply,
|
||||
&IntegerOps::divide);
|
||||
|
||||
log && log(xtag("ANumeric.tseq", typeseq::id<ANumeric>()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end numeric_register_facets.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue