xo-procedure2 xo-object2: + polymorphic primitive support

This commit is contained in:
Roland Conybeare 2026-01-26 12:38:17 -05:00
commit d39e13593c
18 changed files with 129 additions and 42 deletions

25
doc/implementation.rst Normal file
View file

@ -0,0 +1,25 @@
.. _implementation:
.. toctree::
:maxdepth: 2
Components
==========
Library dependency tower for *xo-procedure2*
.. ditaa::
+--------------------------------+
| xo_gc |
+--------------------------------+
| xo_alloc2 |
+--------------------------------+
| xo_facet |
+----------------+---------------+
| xo_reflectutil | xo_indentlog |
+----------------+---------------+
| xo_cmake |
+--------------------------------+
Expect to have xo_facet depending on xo_arena instead of using std::unordered_map

View file

@ -56,7 +56,6 @@
doc: ["invoke procedure; assume arguments satisfy type system" ],
return_type: "obj<AGCObject>",
args: [
{type: "obj<ARuntimeContext>", name: "rcx"},
{type: "const DArray *", name: "args"},
]
}

View file

@ -10,6 +10,7 @@
#include <xo/gc/GCObjectConversion.hpp>
#include <xo/gc/GCObject.hpp>
#include <xo/alloc2/Allocator.hpp>
#include <xo/facet/FacetRegistry.hpp>
#include <tuple>
#include <type_traits>
@ -62,24 +63,29 @@ namespace xo {
bool is_nary() const noexcept { return false; }
static constexpr std::int32_t n_args() noexcept { return Traits::n_args; }
obj<AGCObject> apply_nocheck(obj<ARuntimeContext> rcx, const DArray * args) {
return _apply_nocheck(rcx, args,
obj<AGCObject> apply_nocheck(const DArray * args) {
return _apply_nocheck(args,
std::make_index_sequence<Traits::n_args>{});
}
private:
template <std::size_t... Is>
obj<AGCObject> _apply_nocheck(obj<ARuntimeContext> rcx,
const DArray * args,
obj<AGCObject> _apply_nocheck(const DArray * args,
std::index_sequence<Is...>)
{
using xo::facet::FacetRegistry;
using R = typename Traits::return_type;
assert(args);
assert(args->size() > 0);
obj<ARuntimeContext> rcx
= FacetRegistry::instance().variant<ARuntimeContext>(args->at(0));
obj<AAllocator> mm = rcx.allocator();
R result
= fn_(rcx,
GCObjectConversion<typename Traits::template arg_type<Is>>::from_gco(mm, args->at(Is))... );
= fn_(GCObjectConversion<typename Traits::template arg_type<Is>>::from_gco(mm, args->at(Is))... );
return GCObjectConversion<R>::to_gco(mm, result);
}

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Procedure.json5]
* 2. jinja2 template for facet .hpp file:

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/RuntimeContext.json5]
* 2. jinja2 template for facet .hpp file:

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Procedure.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -56,7 +56,7 @@ public:
// nonconst methods
/** invoke procedure; assume arguments satisfy type system **/
virtual obj<AGCObject> apply_nocheck(Opaque data, obj<ARuntimeContext> rcx, const DArray * args) = 0;
virtual obj<AGCObject> apply_nocheck(Opaque data, const DArray * args) = 0;
///@}
}; /*AProcedure*/

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/RuntimeContext.json5]
* 2. jinja2 template for abstract facet .hpp file:

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Procedure.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -60,7 +60,7 @@ namespace scm {
[[noreturn]] std::int32_t n_args(Copaque) const noexcept override { _fatal(); }
// nonconst methods
[[noreturn]] obj<AGCObject> apply_nocheck(Opaque, obj<ARuntimeContext>, const DArray *) override;
[[noreturn]] obj<AGCObject> apply_nocheck(Opaque, const DArray *) override;
///@}

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IProcedure_DPrimitive_gco_2_gco_gco.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -57,7 +57,7 @@ namespace xo {
// non-const methods
/** invoke procedure; assume arguments satisfy type system **/
static obj<AGCObject> apply_nocheck(DPrimitive_gco_2_gco_gco & self, obj<ARuntimeContext> rcx, const DArray * args);
static obj<AGCObject> apply_nocheck(DPrimitive_gco_2_gco_gco & self, const DArray * args);
///@}
};

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Procedure.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -50,8 +50,8 @@ namespace scm {
}
// non-const methods
obj<AGCObject> apply_nocheck(Opaque data, obj<ARuntimeContext> rcx, const DArray * args) override {
return I::apply_nocheck(_dcast(data), rcx, args);
obj<AGCObject> apply_nocheck(Opaque data, const DArray * args) override {
return I::apply_nocheck(_dcast(data), args);
}
///@}

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/RuntimeContext.json5]
* 2. jinja2 template for abstract facet .hpp file:

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/RuntimeContext.json5]
* 2. jinja2 template for abstract facet .hpp file:

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Procedure.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -56,8 +56,8 @@ public:
}
// non-const methods (still const in router!)
obj<AGCObject> apply_nocheck(obj<ARuntimeContext> rcx, const DArray * args) {
return O::iface()->apply_nocheck(O::data(), rcx, args);
obj<AGCObject> apply_nocheck(const DArray * args) {
return O::iface()->apply_nocheck(O::data(), args);
}
///@}

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/RuntimeContext.json5]
* 2. jinja2 template for abstract facet .hpp file:

View file

@ -3,13 +3,19 @@
#pragma once
#include "DPrimitive.hpp"
#include "DPrimitive_gco_2_gco_gco.hpp"
namespace xo {
namespace scm {
#ifdef NOT_YET
using Primitive_f64_1_f64 = Primitive<double (*)(double)>;
using Primitive_f64_2_f64_f64 = Primitive<double (*)(double, double)>;
#endif
struct Primitives {
static DPrimitive_gco_2_gco_gco s_mul_gco_gco_pm;
#ifdef NOT_YET
static Primitive_f64_1_f64 s_neg_f64_pm;
static Primitive_f64_2_f64_f64 s_add_f64_f64_pm;
@ -22,6 +28,7 @@ namespace xo {
static Primitive_f64_1_f64 s_sin_f64_pm;
static Primitive_f64_1_f64 s_cos_f64_pm;
static Primitive_f64_1_f64 s_tan_f64_pm;
#endif
};
}
}

View file

@ -35,7 +35,7 @@ IProcedure_Any::_valid
// nonconst methods
auto
IProcedure_Any::apply_nocheck(Opaque, obj<ARuntimeContext>, const DArray *) -> obj<AGCObject>
IProcedure_Any::apply_nocheck(Opaque, const DArray *) -> obj<AGCObject>
{
_fatal();
}

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IProcedure_DPrimitive_gco_2_gco_gco.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -28,9 +28,9 @@ namespace xo {
}
auto
IProcedure_DPrimitive_gco_2_gco_gco::apply_nocheck(DPrimitive_gco_2_gco_gco & self, obj<ARuntimeContext> rcx, const DArray * args) -> obj<AGCObject>
IProcedure_DPrimitive_gco_2_gco_gco::apply_nocheck(DPrimitive_gco_2_gco_gco & self, const DArray * args) -> obj<AGCObject>
{
return self.apply_nocheck(rcx, args);
return self.apply_nocheck(args);
}
} /*namespace scm*/

View file

@ -5,10 +5,23 @@
#include "init_primitives.hpp"
#include "DPrimitive.hpp"
#include <xo/object2/DFloat.hpp>
#include <xo/object2/number/IGCObject_DFloat.hpp>
#include <xo/object2/DInteger.hpp>
#include <xo/object2/number/IGCObject_DInteger.hpp>
#include <xo/gc/GCObjectConversion.hpp>
#include <xo/object2/number/GCObjectConversion_DFloat.hpp>
#include <xo/object2/number/GCObjectConversion_DInteger.hpp>
#include <xo/facet/facet.hpp>
#include <cmath>
namespace xo {
using xo::mm::AAllocator;
using xo::scm::DFloat;
using xo::facet::with_facet;
namespace scm {
#ifdef NOT_YET
double
neg_f64(double x) {
return -x;
@ -23,11 +36,17 @@ namespace xo {
sub_f64_f64(double x, double y) {
return x - y;
}
#endif
#ifdef NOT_YET
obj<AGCObject>
mul_any_any(obj<AGCObject> x_gco, obj<AGCObject> y_gco)
mul_gco_gco(obj<ARuntimeContext> rcx,
obj<AGCObject> x_gco,
obj<AGCObject> y_gco)
{
using xo::reflect::typeseq;
obj<AAllocator> mm = rcx.allocator();
// PLACEHOLDER
// TODO:
@ -44,20 +63,45 @@ namespace xo {
// FOR NOW: just test runtime values
//
if (x_tseq == typeseq::id<DFloat>()) {
if (y_tseq == typeseq::id<DFloat>()) {
// unusable placeholder allocator;
obj<AAllocator> placeholder_mm;
// f64 * f64.
double x = GCObjectConversion<double>::from_gco(placeholder_mm, x_gco);
double y = GCObjectConversion<double>::from_gco(placeholder_mm, y_gco);
if (x_tseq == typeseq::id<DInteger>()) {
// i64 * ..
long x = GCObjectConversion<long>::from_gco(mm, x_gco);
if (y_tseq == typeseq::id<DInteger>()) {
// i64 * i64
long y = GCObjectConversion<long>::from_gco(mm, y_gco);
return DInteger::box<AGCObject>(mm, x * y);
} else if (y_tseq == typeseq::id<DFloat>()) {
// i64 * f64
double y = GCObjectConversion<double>::from_gco(mm, y_gco);
return DFloat::box<AGCObject>(mm, x * y);
}
#endif
} else if (x_tseq == typeseq::id<DFloat>()) {
if (y_tseq == typeseq::id<DInteger>()) {
// f64 * i64.
double x = GCObjectConversion<double>::from_gco(mm, x_gco);
long y = GCObjectConversion<long>::from_gco(mm, y_gco);
return DFloat::box<AGCObject>(mm, x * y);
} else if (y_tseq == typeseq::id<DFloat>()) {
// f64 * f64.
double x = GCObjectConversion<double>::from_gco(mm, x_gco);
double y = GCObjectConversion<double>::from_gco(mm, y_gco);
return DFloat::box<AGCObject>(mm, x * y);
}
}
// here: error
throw std::runtime_error(tostr("mul_gco_gco: unexpected argument types xt,yt",
xtag("x.tseq", x_tseq),
xtag("y.tseq", y_tseq)));
return obj<AGCObject>();
}
#ifdef NOT_YET
double
mul_f64_f64(double x, double y) {
return x * y;
@ -92,7 +136,12 @@ namespace xo {
tan_f64(double x) {
return ::tan(x);
}
#endif
DPrimitive_gco_2_gco_gco
Primitives::s_mul_gco_gco_pm("_mul", &mul_gco_gco);
#ifdef NOT_YET
Primitive_f64_1_f64
Primitives::s_neg_f64_pm("_neg_d",
&neg_f64);
@ -123,6 +172,7 @@ namespace xo {
Primitive_f64_1_f64
Primitives::s_tan_f64_pm("_tan_d", &tan_f64);
#endif
} /*namespace scm*/
} /*namespace xo*/