xo-interpreter2 stack: + RuntimeContext.visit_pools() method

This commit is contained in:
Roland Conybeare 2026-02-28 13:26:10 +11:00
commit c99ac53c72
10 changed files with 65 additions and 3 deletions

View file

@ -5,7 +5,8 @@
output_impl_subdir: "detail",
// includes in ARuntimeContext.hpp
includes: [
"<xo/alloc2/Allocator.hpp>"
"<xo/alloc2/Allocator.hpp>",
"<xo/arena/MemorySizeInfo.hpp>"
],
// extra includes in RuntimeContext.hpp, if any
user_hpp_includes: [
@ -29,6 +30,11 @@
definition: "xo::mm::AAllocator",
doc: [ "xo memory allocator" ],
},
{
name: "MemorySizeVisitor",
definition: "xo::mm::MemorySizeVisitor",
doc: [ "function to visit memory pools" ],
},
],
const_methods: [
{
@ -40,6 +46,17 @@
noexcept: true,
attributes: [],
},
{
name: "visit_pools",
doc: [ "invoke visitor for each distinct memory pool" ],
return_type: "void",
args: [
{type: "MemorySizeVisitor", name: "visitor"}
],
const: true,
noexcept: false,
attributes: [],
},
],
nonconst_methods: [
],

View file

@ -18,11 +18,13 @@ namespace xo {
class DSimpleRcx {
public:
using AAllocator = xo::mm::AAllocator;
using MemorySizeVisitor = xo::mm::MemorySizeVisitor;
public:
DSimpleRcx(obj<AAllocator> mm) : allocator_{mm} {}
obj<AAllocator> allocator() const noexcept { return allocator_; }
void visit_pools(const MemorySizeVisitor & visitor) const;
private:
obj<AAllocator> allocator_;

View file

@ -15,6 +15,7 @@
// includes (via {facet_includes})
#include <xo/alloc2/Allocator.hpp>
#include <xo/arena/MemorySizeInfo.hpp>
#include <xo/facet/obj.hpp>
#include <xo/facet/facet_implementation.hpp>
#include <xo/facet/typeseq.hpp>
@ -40,6 +41,8 @@ public:
using Opaque = void *;
/** xo memory allocator **/
using AAllocator = xo::mm::AAllocator;
/** function to visit memory pools **/
using MemorySizeVisitor = xo::mm::MemorySizeVisitor;
///@}
/** @defgroup scm-runtimecontext-methods **/
@ -51,6 +54,8 @@ public:
virtual void _drop(Opaque d) const noexcept = 0;
/** default allocator to use for objects **/
virtual obj<AAllocator> allocator(Copaque data) const noexcept = 0;
/** invoke visitor for each distinct memory pool **/
virtual void visit_pools(Copaque data, MemorySizeVisitor visitor) const = 0;
// nonconst methods
///@}

View file

@ -45,6 +45,7 @@ namespace scm {
/** integer identifying a type **/
using typeseq = xo::facet::typeseq;
using AAllocator = ARuntimeContext::AAllocator;
using MemorySizeVisitor = ARuntimeContext::MemorySizeVisitor;
///@}
/** @defgroup scm-runtimecontext-any-methods **/
@ -60,6 +61,7 @@ namespace scm {
// const methods
[[noreturn]] obj<AAllocator> allocator(Copaque) const noexcept override { _fatal(); }
[[noreturn]] void visit_pools(Copaque, MemorySizeVisitor) const override { _fatal(); }
// nonconst methods

View file

@ -40,6 +40,7 @@ namespace xo {
/** @defgroup scm-runtimecontext-dsimplercx-type-traits **/
///@{
using AAllocator = xo::scm::ARuntimeContext::AAllocator;
using MemorySizeVisitor = xo::scm::ARuntimeContext::MemorySizeVisitor;
using Copaque = xo::scm::ARuntimeContext::Copaque;
using Opaque = xo::scm::ARuntimeContext::Opaque;
///@}
@ -48,6 +49,8 @@ namespace xo {
// const methods
/** default allocator to use for objects **/
static obj<AAllocator> allocator(const DSimpleRcx & self) noexcept;
/** invoke visitor for each distinct memory pool **/
static void visit_pools(const DSimpleRcx & self, MemorySizeVisitor visitor);
// non-const methods
///@}

View file

@ -14,6 +14,7 @@
#pragma once
#include <xo/alloc2/Allocator.hpp>
#include <xo/arena/MemorySizeInfo.hpp>
namespace xo {
namespace scm {
@ -29,6 +30,7 @@ namespace scm {
/** integer identifying a type **/
using typeseq = ARuntimeContext::typeseq;
using AAllocator = ARuntimeContext::AAllocator;
using MemorySizeVisitor = ARuntimeContext::MemorySizeVisitor;
///@}
/** @defgroup scm-runtimecontext-xfer-methods **/
@ -47,6 +49,9 @@ namespace scm {
obj<AAllocator> allocator(Copaque data) const noexcept override {
return I::allocator(_dcast(data));
}
void visit_pools(Copaque data, MemorySizeVisitor visitor) const override {
return I::visit_pools(_dcast(data), visitor);
}
// non-const methods

View file

@ -32,6 +32,7 @@ public:
using DataPtr = Object::DataPtr;
using typeseq = xo::reflect::typeseq;
using AAllocator = ARuntimeContext::AAllocator;
using MemorySizeVisitor = ARuntimeContext::MemorySizeVisitor;
///@}
/** @defgroup scm-runtimecontext-router-ctors **/
@ -56,6 +57,9 @@ public:
obj<AAllocator> allocator() const noexcept {
return O::iface()->allocator(O::data());
}
void visit_pools(MemorySizeVisitor visitor) const {
return O::iface()->visit_pools(O::data(), visitor);
}
// non-const methods (still const in router!)

View file

@ -6,6 +6,7 @@ set(SELF_SRCS
init_primitives.cpp
procedure2_register_types.cpp
procedure2_register_facets.cpp
DSimpleRcx.cpp
IRuntimeContext_Any.cpp
IRuntimeContext_DSimpleRcx.cpp
IProcedure_Any.cpp
@ -13,8 +14,6 @@ set(SELF_SRCS
IGCObject_DPrimitive_gco_2_gco_gco.cpp
IProcedure_DPrimitive_gco_2_gco_gco.cpp
IPrintable_DPrimitive_gco_2_gco_gco.cpp
# Add source files here, e.g.:
# procedure2.cpp
)
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})

View file

@ -0,0 +1,19 @@
/** @file DSimpleRcx.cpp
*
* @author Roland Conybeare, Feb 2026
**/
#include "DSimpleRcx.hpp"
namespace xo {
namespace scm {
void
DSimpleRcx::visit_pools(const MemorySizeVisitor & visitor) const
{
allocator_.visit_pools(visitor);
}
}
}
/* end DSimpleRcx.cpp */

View file

@ -21,6 +21,12 @@ namespace xo {
return self.allocator();
}
auto
IRuntimeContext_DSimpleRcx::visit_pools(const DSimpleRcx & self, MemorySizeVisitor visitor) -> void
{
self.visit_pools(visitor);
}
} /*namespace scm*/
} /*namespace xo*/