xo-procedure2: + GCObject support for Primitive + misc

This commit is contained in:
Roland Conybeare 2026-01-26 15:34:53 -05:00
commit d7e2ea79b8
9 changed files with 177 additions and 1 deletions

View file

@ -58,6 +58,7 @@ namespace xo {
template <typename Fn>
class Primitive {
public:
using ACollector = xo::mm::ACollector;
using AAllocator = xo::mm::AAllocator;
using AGCObject = xo::mm::AGCObject;
using DArray = xo::scm::DArray;
@ -74,6 +75,13 @@ namespace xo {
std::make_index_sequence<Traits::n_args>{});
}
/** @defgroup scm-primitive-gcobject-facet **/
///@{
std::size_t shallow_size() const noexcept;
Primitive * shallow_copy(obj<AAllocator> mm) const noexcept;
std::size_t forward_children(obj<ACollector> gc) noexcept;
///@}
private:
template <std::size_t... Is>
obj<AGCObject> _apply_nocheck(obj<ARuntimeContext> rcx,
@ -103,6 +111,31 @@ namespace xo {
Fn fn_;
}; /*Primitive*/
template <typename Fn>
std::size_t
Primitive<Fn>::shallow_size() const noexcept {
return sizeof(*this);
}
template <typename Fn>
Primitive<Fn> *
Primitive<Fn>::shallow_copy(obj<AAllocator> mm) const noexcept {
void * mem = mm.alloc_copy((std::byte *)this);
if (mem) {
return new (mem) Primitive(*this);
}
return nullptr;
}
template <typename Fn>
std::size_t
Primitive<Fn>::forward_children(obj<ACollector>) noexcept {
// Primitive holds no GC refs (just string_view + function pointer)
return this->shallow_size();
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -0,0 +1,67 @@
/** @file IGCObject_DPrimitive_gco_2_gco_gco.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IGCObject_DPrimitive_gco_2_gco_gco.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_repr.hpp.j2]
* 3. idl for facet methods
* [idl/IGCObject_DPrimitive_gco_2_gco_gco.json5]
**/
#pragma once
#include "GCObject.hpp"
#include <xo/gc/GCObject.hpp>
#include <xo/alloc2/Allocator.hpp>
#include "DPrimitive_gco_2_gco_gco.hpp"
namespace xo { namespace scm { class IGCObject_DPrimitive_gco_2_gco_gco; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::mm::AGCObject,
xo::scm::DPrimitive_gco_2_gco_gco>
{
using ImplType = xo::mm::IGCObject_Xfer
<xo::scm::DPrimitive_gco_2_gco_gco,
xo::scm::IGCObject_DPrimitive_gco_2_gco_gco>;
};
}
}
namespace xo {
namespace scm {
/** @class IGCObject_DPrimitive_gco_2_gco_gco
**/
class IGCObject_DPrimitive_gco_2_gco_gco {
public:
/** @defgroup scm-gcobject-dprimitive_gco_2_gco_gco-type-traits **/
///@{
using size_type = xo::mm::AGCObject::size_type;
using AAllocator = xo::mm::AGCObject::AAllocator;
using ACollector = xo::mm::AGCObject::ACollector;
using Copaque = xo::mm::AGCObject::Copaque;
using Opaque = xo::mm::AGCObject::Opaque;
///@}
/** @defgroup scm-gcobject-dprimitive_gco_2_gco_gco-methods **/
///@{
// const methods
/** memory consumption for this instance **/
static size_type shallow_size(const DPrimitive_gco_2_gco_gco & self) noexcept;
/** copy instance using allocator **/
static Opaque shallow_copy(const DPrimitive_gco_2_gco_gco & self, obj<AAllocator> mm) noexcept;
// non-const methods
/** during GC: forward immdiate children **/
static size_type forward_children(DPrimitive_gco_2_gco_gco & self, obj<ACollector> gc) noexcept;
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -7,12 +7,19 @@
namespace xo {
namespace scm {
/** TODO: move this into xo-reader2 ? **/
#ifdef NOT_YET
using Primitive_f64_1_f64 = Primitive<double (*)(double)>;
using Primitive_f64_2_f64_f64 = Primitive<double (*)(double, double)>;
#endif
struct Primitives {
/** polymorphich multiply
*
* TODO: this will want to move to xo-numeric/
* so we can dispatch on vector, matrix, function types
**/
static DPrimitive_gco_2_gco_gco s_mul_gco_gco_pm;
#ifdef NOT_YET