diff --git a/xo-interpreter2/include/xo/interpreter2/DVsmRcx.hpp b/xo-interpreter2/include/xo/interpreter2/DVsmRcx.hpp index 1f3a8f57..1ab7e773 100644 --- a/xo-interpreter2/include/xo/interpreter2/DVsmRcx.hpp +++ b/xo-interpreter2/include/xo/interpreter2/DVsmRcx.hpp @@ -22,12 +22,14 @@ namespace xo { public: using StringTable = xo::scm::StringTable; using AAllocator = xo::mm::AAllocator; + using ACollector = xo::mm::ACollector; using MemorySizeVisitor = xo::mm::MemorySizeVisitor; public: DVsmRcx(VirtualSchematikaMachine * vsm); obj allocator() const noexcept; + obj collector() const noexcept; StringTable * stringtable() const noexcept; obj error_allocator() const noexcept; void visit_pools(const MemorySizeVisitor & visitor) const; diff --git a/xo-interpreter2/include/xo/interpreter2/detail/IRuntimeContext_DVsmRcx.hpp b/xo-interpreter2/include/xo/interpreter2/detail/IRuntimeContext_DVsmRcx.hpp index 1b4c1567..1eddf28c 100644 --- a/xo-interpreter2/include/xo/interpreter2/detail/IRuntimeContext_DVsmRcx.hpp +++ b/xo-interpreter2/include/xo/interpreter2/detail/IRuntimeContext_DVsmRcx.hpp @@ -40,6 +40,7 @@ namespace xo { /** @defgroup scm-runtimecontext-dvsmrcx-type-traits **/ ///@{ using AAllocator = xo::scm::ARuntimeContext::AAllocator; + using ACollector = xo::scm::ARuntimeContext::ACollector; using MemorySizeVisitor = xo::scm::ARuntimeContext::MemorySizeVisitor; using Copaque = xo::scm::ARuntimeContext::Copaque; using Opaque = xo::scm::ARuntimeContext::Opaque; @@ -49,6 +50,8 @@ namespace xo { // const methods /** default allocator to use for objects **/ static obj allocator(const DVsmRcx & self) noexcept; + /** collector facet for allocator. If non-null, same data pointer as allocator **/ + static obj collector(const DVsmRcx & self) noexcept; /** stringtable for unique symbols **/ static StringTable * stringtable(const DVsmRcx & self) noexcept; /** invoke visitor for each distinct memory pool **/ diff --git a/xo-interpreter2/src/interpreter2/DVsmRcx.cpp b/xo-interpreter2/src/interpreter2/DVsmRcx.cpp index b7ea4112..856f38e4 100644 --- a/xo-interpreter2/src/interpreter2/DVsmRcx.cpp +++ b/xo-interpreter2/src/interpreter2/DVsmRcx.cpp @@ -5,9 +5,11 @@ #include "DVsmRcx.hpp" #include "VirtualSchematikaMachine.hpp" +#include namespace xo { using xo::mm::AAllocator; + using xo::mm::ACollector; namespace scm { @@ -19,6 +21,12 @@ namespace xo { return vsm_->allocator(); } + obj + DVsmRcx::collector() const noexcept + { + return vsm_->allocator().try_to_facet(); + } + obj DVsmRcx::error_allocator() const noexcept { diff --git a/xo-interpreter2/src/interpreter2/IRuntimeContext_DVsmRcx.cpp b/xo-interpreter2/src/interpreter2/IRuntimeContext_DVsmRcx.cpp index e879d4ed..9b1a73d0 100644 --- a/xo-interpreter2/src/interpreter2/IRuntimeContext_DVsmRcx.cpp +++ b/xo-interpreter2/src/interpreter2/IRuntimeContext_DVsmRcx.cpp @@ -21,6 +21,12 @@ namespace xo { return self.allocator(); } + auto + IRuntimeContext_DVsmRcx::collector(const DVsmRcx & self) noexcept -> obj + { + return self.collector(); + } + auto IRuntimeContext_DVsmRcx::stringtable(const DVsmRcx & self) noexcept -> StringTable * { diff --git a/xo-procedure2/idl/RuntimeContext.json5 b/xo-procedure2/idl/RuntimeContext.json5 index fe1254b0..481d0cbf 100644 --- a/xo-procedure2/idl/RuntimeContext.json5 +++ b/xo-procedure2/idl/RuntimeContext.json5 @@ -31,6 +31,11 @@ definition: "xo::mm::AAllocator", doc: [ "xo memory allocator" ], }, + { + name: "ACollector", + definition: "xo::mm::ACollector", + doc: [ "xo garbage collector" ], + }, { name: "MemorySizeVisitor", definition: "xo::mm::MemorySizeVisitor", @@ -47,6 +52,15 @@ noexcept: true, attributes: [], }, + { + name: "collector", + doc: [ "collector facet for allocator. If non-null, same data pointer as allocator" ], + return_type: "obj", + args: [], + const: true, + noexcept: true, + attributes: [], + }, { name: "stringtable", doc: [ "stringtable for unique symbols" ], diff --git a/xo-procedure2/include/xo/procedure2/DSimpleRcx.hpp b/xo-procedure2/include/xo/procedure2/DSimpleRcx.hpp index 6a7163d1..f6bee0b5 100644 --- a/xo-procedure2/include/xo/procedure2/DSimpleRcx.hpp +++ b/xo-procedure2/include/xo/procedure2/DSimpleRcx.hpp @@ -19,13 +19,15 @@ namespace xo { class DSimpleRcx { public: using AAllocator = xo::mm::AAllocator; + using ACollector = xo::mm::ACollector; using MemorySizeVisitor = xo::mm::MemorySizeVisitor; public: DSimpleRcx(obj mm, StringTable * st) - : allocator_{mm}, stringtable_{st} {} + : allocator_{mm}, stringtable_{st} {} obj allocator() const noexcept { return allocator_; } + obj collector() const noexcept; StringTable * stringtable() const noexcept { return stringtable_; } void visit_pools(const MemorySizeVisitor & visitor) const; diff --git a/xo-procedure2/include/xo/procedure2/detail/ARuntimeContext.hpp b/xo-procedure2/include/xo/procedure2/detail/ARuntimeContext.hpp index 716463d2..626e2ba6 100644 --- a/xo-procedure2/include/xo/procedure2/detail/ARuntimeContext.hpp +++ b/xo-procedure2/include/xo/procedure2/detail/ARuntimeContext.hpp @@ -42,6 +42,8 @@ public: using Opaque = void *; /** xo memory allocator **/ using AAllocator = xo::mm::AAllocator; + /** xo garbage collector **/ + using ACollector = xo::mm::ACollector; /** function to visit memory pools **/ using MemorySizeVisitor = xo::mm::MemorySizeVisitor; ///@} @@ -55,6 +57,8 @@ public: virtual void _drop(Opaque d) const noexcept = 0; /** default allocator to use for objects **/ virtual obj allocator(Copaque data) const noexcept = 0; + /** collector facet for allocator. If non-null, same data pointer as allocator **/ + virtual obj collector(Copaque data) const noexcept = 0; /** stringtable for unique symbols **/ virtual StringTable * stringtable(Copaque data) const noexcept = 0; /** invoke visitor for each distinct memory pool **/ diff --git a/xo-procedure2/include/xo/procedure2/detail/IRuntimeContext_Any.hpp b/xo-procedure2/include/xo/procedure2/detail/IRuntimeContext_Any.hpp index b72f934f..d0789e52 100644 --- a/xo-procedure2/include/xo/procedure2/detail/IRuntimeContext_Any.hpp +++ b/xo-procedure2/include/xo/procedure2/detail/IRuntimeContext_Any.hpp @@ -45,6 +45,7 @@ namespace scm { /** integer identifying a type **/ using typeseq = xo::facet::typeseq; using AAllocator = ARuntimeContext::AAllocator; + using ACollector = ARuntimeContext::ACollector; using MemorySizeVisitor = ARuntimeContext::MemorySizeVisitor; ///@} @@ -61,6 +62,7 @@ namespace scm { // const methods [[noreturn]] obj allocator(Copaque) const noexcept override { _fatal(); } + [[noreturn]] obj collector(Copaque) const noexcept override { _fatal(); } [[noreturn]] StringTable * stringtable(Copaque) const noexcept override { _fatal(); } [[noreturn]] void visit_pools(Copaque, MemorySizeVisitor) const override { _fatal(); } diff --git a/xo-procedure2/include/xo/procedure2/detail/IRuntimeContext_DSimpleRcx.hpp b/xo-procedure2/include/xo/procedure2/detail/IRuntimeContext_DSimpleRcx.hpp index 82ab5219..496b593c 100644 --- a/xo-procedure2/include/xo/procedure2/detail/IRuntimeContext_DSimpleRcx.hpp +++ b/xo-procedure2/include/xo/procedure2/detail/IRuntimeContext_DSimpleRcx.hpp @@ -40,6 +40,7 @@ namespace xo { /** @defgroup scm-runtimecontext-dsimplercx-type-traits **/ ///@{ using AAllocator = xo::scm::ARuntimeContext::AAllocator; + using ACollector = xo::scm::ARuntimeContext::ACollector; using MemorySizeVisitor = xo::scm::ARuntimeContext::MemorySizeVisitor; using Copaque = xo::scm::ARuntimeContext::Copaque; using Opaque = xo::scm::ARuntimeContext::Opaque; @@ -49,6 +50,8 @@ namespace xo { // const methods /** default allocator to use for objects **/ static obj allocator(const DSimpleRcx & self) noexcept; + /** collector facet for allocator. If non-null, same data pointer as allocator **/ + static obj collector(const DSimpleRcx & self) noexcept; /** stringtable for unique symbols **/ static StringTable * stringtable(const DSimpleRcx & self) noexcept; /** invoke visitor for each distinct memory pool **/ diff --git a/xo-procedure2/include/xo/procedure2/detail/IRuntimeContext_Xfer.hpp b/xo-procedure2/include/xo/procedure2/detail/IRuntimeContext_Xfer.hpp index 5dc9de5f..2c4e80e6 100644 --- a/xo-procedure2/include/xo/procedure2/detail/IRuntimeContext_Xfer.hpp +++ b/xo-procedure2/include/xo/procedure2/detail/IRuntimeContext_Xfer.hpp @@ -31,6 +31,7 @@ namespace scm { /** integer identifying a type **/ using typeseq = ARuntimeContext::typeseq; using AAllocator = ARuntimeContext::AAllocator; + using ACollector = ARuntimeContext::ACollector; using MemorySizeVisitor = ARuntimeContext::MemorySizeVisitor; ///@} @@ -50,6 +51,9 @@ namespace scm { obj allocator(Copaque data) const noexcept override { return I::allocator(_dcast(data)); } + obj collector(Copaque data) const noexcept override { + return I::collector(_dcast(data)); + } StringTable * stringtable(Copaque data) const noexcept override { return I::stringtable(_dcast(data)); } diff --git a/xo-procedure2/include/xo/procedure2/detail/RRuntimeContext.hpp b/xo-procedure2/include/xo/procedure2/detail/RRuntimeContext.hpp index 6553648c..b80cfce0 100644 --- a/xo-procedure2/include/xo/procedure2/detail/RRuntimeContext.hpp +++ b/xo-procedure2/include/xo/procedure2/detail/RRuntimeContext.hpp @@ -32,6 +32,7 @@ public: using DataPtr = Object::DataPtr; using typeseq = xo::reflect::typeseq; using AAllocator = ARuntimeContext::AAllocator; + using ACollector = ARuntimeContext::ACollector; using MemorySizeVisitor = ARuntimeContext::MemorySizeVisitor; ///@} @@ -57,6 +58,9 @@ public: obj allocator() const noexcept { return O::iface()->allocator(O::data()); } + obj collector() const noexcept { + return O::iface()->collector(O::data()); + } StringTable * stringtable() const noexcept { return O::iface()->stringtable(O::data()); } diff --git a/xo-procedure2/src/procedure2/DSimpleRcx.cpp b/xo-procedure2/src/procedure2/DSimpleRcx.cpp index 30ec9c95..471cad75 100644 --- a/xo-procedure2/src/procedure2/DSimpleRcx.cpp +++ b/xo-procedure2/src/procedure2/DSimpleRcx.cpp @@ -4,10 +4,20 @@ **/ #include "DSimpleRcx.hpp" +#include +#include namespace xo { + using xo::mm::ACollector; + namespace scm { + obj + DSimpleRcx::collector() const noexcept + { + return allocator_.try_to_facet(); + } + void DSimpleRcx::visit_pools(const MemorySizeVisitor & visitor) const { diff --git a/xo-procedure2/src/procedure2/facet/IRuntimeContext_DSimpleRcx.cpp b/xo-procedure2/src/procedure2/facet/IRuntimeContext_DSimpleRcx.cpp index 82dd310e..ba560969 100644 --- a/xo-procedure2/src/procedure2/facet/IRuntimeContext_DSimpleRcx.cpp +++ b/xo-procedure2/src/procedure2/facet/IRuntimeContext_DSimpleRcx.cpp @@ -21,6 +21,12 @@ namespace xo { return self.allocator(); } + auto + IRuntimeContext_DSimpleRcx::collector(const DSimpleRcx & self) noexcept -> obj + { + return self.collector(); + } + auto IRuntimeContext_DSimpleRcx::stringtable(const DSimpleRcx & self) noexcept -> StringTable * { diff --git a/xo-reader2/CMakeLists.txt b/xo-reader2/CMakeLists.txt index 9c009aab..4675de3c 100644 --- a/xo-reader2/CMakeLists.txt +++ b/xo-reader2/CMakeLists.txt @@ -24,6 +24,17 @@ add_definitions(${PROJECT_CXX_FLAGS}) add_subdirectory(utest) +# ---------------------------------------------------------------- + +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-reader2-facetimpl-gcobject-schematikaparser + FACET_PKG xo_alloc2 + INPUT idl/IGCObject_DSchematikaParser.json5 +) + +# ---------------------------------------------------------------- + # note: manual target; generated code committed to git xo_add_genfacet( TARGET xo-reader2-facet-syntaxstatemachine