xo-interpreter2: scaffold repl + alloc measurement frameowkr
This commit is contained in:
parent
7028fa49f8
commit
f6aae4190e
42 changed files with 1398 additions and 198 deletions
22
xo-alloc2/include/xo/alloc2/ResourceVisitor.hpp
Normal file
22
xo-alloc2/include/xo/alloc2/ResourceVisitor.hpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/** @file ResourceVisitor.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ResourceVisitor.json5]
|
||||
* 2. jinja2 template for facet .hpp file:
|
||||
* [facet.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ResourceVisitor.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "visitor/AResourceVisitor.hpp"
|
||||
#include "visitor/IResourceVisitor_Any.hpp"
|
||||
#include "visitor/IResourceVisitor_Xfer.hpp"
|
||||
#include "visitor/RResourceVisitor.hpp"
|
||||
|
||||
|
||||
/* end ResourceVisitor.hpp */
|
||||
74
xo-alloc2/include/xo/alloc2/visitor/AResourceVisitor.hpp
Normal file
74
xo-alloc2/include/xo/alloc2/visitor/AResourceVisitor.hpp
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/** @file AResourceVisitor.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ResourceVisitor.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [abstract_facet.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ResourceVisitor.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
// includes (via {facet_includes})
|
||||
#include "Allocator.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <xo/facet/facet_implementation.hpp>
|
||||
#include <xo/facet/typeseq.hpp>
|
||||
|
||||
// {pretext} here
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
||||
using Copaque = const void *;
|
||||
using Opaque = void *;
|
||||
|
||||
/**
|
||||
Visitor to receive measured resource consumption
|
||||
**/
|
||||
class AResourceVisitor {
|
||||
public:
|
||||
/** @defgroup mm-resourcevisitor-type-traits **/
|
||||
///@{
|
||||
// types
|
||||
/** integer identifying a type **/
|
||||
using typeseq = xo::facet::typeseq;
|
||||
using Copaque = const void *;
|
||||
using Opaque = void *;
|
||||
/** type for length of a sequence **/
|
||||
using size_type = std::size_t;
|
||||
///@}
|
||||
|
||||
/** @defgroup mm-resourcevisitor-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** RTTI: unique id# for actual runtime data representation **/
|
||||
virtual typeseq _typeseq() const noexcept = 0;
|
||||
/** report memory consumption **/
|
||||
virtual void on_allocator(Copaque data, obj<AAllocator> mm) const noexcept = 0;
|
||||
|
||||
// nonconst methods
|
||||
///@}
|
||||
}; /*AResourceVisitor*/
|
||||
|
||||
/** Implementation IResourceVisitor_DRepr of AResourceVisitor for state DRepr
|
||||
* should provide a specialization:
|
||||
*
|
||||
* template <>
|
||||
* struct xo::facet::FacetImplementation<AResourceVisitor, DRepr> {
|
||||
* using Impltype = IResourceVisitor_DRepr;
|
||||
* };
|
||||
*
|
||||
* then IResourceVisitor_ImplType<DRepr> --> IResourceVisitor_DRepr
|
||||
**/
|
||||
template <typename DRepr>
|
||||
using IResourceVisitor_ImplType = xo::facet::FacetImplType<AResourceVisitor, DRepr>;
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* AResourceVisitor.hpp */
|
||||
86
xo-alloc2/include/xo/alloc2/visitor/IResourceVisitor_Any.hpp
Normal file
86
xo-alloc2/include/xo/alloc2/visitor/IResourceVisitor_Any.hpp
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/** @file IResourceVisitor_Any.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ResourceVisitor.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ResourceVisitor.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AResourceVisitor.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
|
||||
namespace xo { namespace mm { class IResourceVisitor_Any; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::AResourceVisitor,
|
||||
DVariantPlaceholder>
|
||||
{
|
||||
using ImplType = xo::mm::IResourceVisitor_Any;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
||||
/** @class IResourceVisitor_Any
|
||||
* @brief AResourceVisitor implementation for empty variant instance
|
||||
**/
|
||||
class IResourceVisitor_Any : public AResourceVisitor {
|
||||
public:
|
||||
/** @defgroup mm-resourcevisitor-any-type-traits **/
|
||||
///@{
|
||||
|
||||
/** integer identifying a type **/
|
||||
using typeseq = xo::facet::typeseq;
|
||||
using size_type = AResourceVisitor::size_type;
|
||||
|
||||
///@}
|
||||
/** @defgroup mm-resourcevisitor-any-methods **/
|
||||
///@{
|
||||
|
||||
const AResourceVisitor * iface() const { return std::launder(this); }
|
||||
|
||||
// from AResourceVisitor
|
||||
|
||||
// const methods
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
[[noreturn]] void on_allocator(Copaque, obj<AAllocator>) const noexcept override { _fatal(); }
|
||||
|
||||
// nonconst methods
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** @defgraoup mm-resourcevisitor-any-private-methods **/
|
||||
///@{
|
||||
|
||||
[[noreturn]] static void _fatal();
|
||||
|
||||
///@}
|
||||
|
||||
public:
|
||||
/** @defgroup mm-resourcevisitor-any-member-vars **/
|
||||
///@{
|
||||
|
||||
static typeseq s_typeseq;
|
||||
static bool _valid;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace mm */
|
||||
} /*namespace xo */
|
||||
|
||||
/* IResourceVisitor_Any.hpp */
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/** @file IResourceVisitor_Xfer.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ResourceVisitor.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ResourceVisitor.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Allocator.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
/** @class IResourceVisitor_Xfer
|
||||
**/
|
||||
template <typename DRepr, typename IResourceVisitor_DRepr>
|
||||
class IResourceVisitor_Xfer : public AResourceVisitor {
|
||||
public:
|
||||
/** @defgroup mm-resourcevisitor-xfer-type-traits **/
|
||||
///@{
|
||||
/** actual implementation (not generated; often delegates to DRepr) **/
|
||||
using Impl = IResourceVisitor_DRepr;
|
||||
/** integer identifying a type **/
|
||||
using typeseq = AResourceVisitor::typeseq;
|
||||
using size_type = AResourceVisitor::size_type;
|
||||
///@}
|
||||
|
||||
/** @defgroup mm-resourcevisitor-xfer-methods **/
|
||||
///@{
|
||||
|
||||
static const DRepr & _dcast(Copaque d) { return *(const DRepr *)d; }
|
||||
static DRepr & _dcast(Opaque d) { return *(DRepr *)d; }
|
||||
|
||||
// from AResourceVisitor
|
||||
|
||||
// const methods
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
void on_allocator(Copaque data, obj<AAllocator> mm) const noexcept override {
|
||||
return I::on_allocator(_dcast(data), mm);
|
||||
}
|
||||
|
||||
// non-const methods
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
using I = Impl;
|
||||
|
||||
public:
|
||||
/** @defgroup mm-resourcevisitor-xfer-member-vars **/
|
||||
///@{
|
||||
|
||||
/** typeseq for template parameter DRepr **/
|
||||
static typeseq s_typeseq;
|
||||
/** true iff satisfies facet implementation **/
|
||||
static bool _valid;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
template <typename DRepr, typename IResourceVisitor_DRepr>
|
||||
xo::facet::typeseq
|
||||
IResourceVisitor_Xfer<DRepr, IResourceVisitor_DRepr>::s_typeseq
|
||||
= xo::facet::typeseq::id<DRepr>();
|
||||
|
||||
template <typename DRepr, typename IResourceVisitor_DRepr>
|
||||
bool
|
||||
IResourceVisitor_Xfer<DRepr, IResourceVisitor_DRepr>::_valid
|
||||
= xo::facet::valid_facet_implementation<AResourceVisitor,
|
||||
IResourceVisitor_Xfer>();
|
||||
|
||||
} /*namespace mm */
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IResourceVisitor_Xfer.hpp */
|
||||
80
xo-alloc2/include/xo/alloc2/visitor/RResourceVisitor.hpp
Normal file
80
xo-alloc2/include/xo/alloc2/visitor/RResourceVisitor.hpp
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/** @file RResourceVisitor.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ResourceVisitor.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ResourceVisitor.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AResourceVisitor.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
||||
/** @class RResourceVisitor
|
||||
**/
|
||||
template <typename Object>
|
||||
class RResourceVisitor : public Object {
|
||||
private:
|
||||
using O = Object;
|
||||
|
||||
public:
|
||||
/** @defgroup mm-resourcevisitor-router-type-traits **/
|
||||
///@{
|
||||
using ObjectType = Object;
|
||||
using DataPtr = Object::DataPtr;
|
||||
using typeseq = xo::reflect::typeseq;
|
||||
using size_type = AResourceVisitor::size_type;
|
||||
///@}
|
||||
|
||||
/** @defgroup mm-resourcevisitor-router-ctors **/
|
||||
///@{
|
||||
RResourceVisitor() {}
|
||||
RResourceVisitor(Object::DataPtr data) : Object{std::move(data)} {}
|
||||
RResourceVisitor(const AResourceVisitor * iface, void * data)
|
||||
requires std::is_same_v<typename Object::DataType, xo::facet::DVariantPlaceholder>
|
||||
: Object(iface, data) {}
|
||||
|
||||
///@}
|
||||
/** @defgroup mm-resourcevisitor-router-methods **/
|
||||
///@{
|
||||
|
||||
// const methods
|
||||
typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); }
|
||||
void on_allocator(obj<AAllocator> mm) const noexcept {
|
||||
return O::iface()->on_allocator(O::data(), mm);
|
||||
}
|
||||
|
||||
// non-const methods (still const in router!)
|
||||
|
||||
///@}
|
||||
/** @defgroup mm-resourcevisitor-member-vars **/
|
||||
///@{
|
||||
|
||||
static bool _valid;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
template <typename Object>
|
||||
bool
|
||||
RResourceVisitor<Object>::_valid = xo::facet::valid_object_router<Object>();
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
namespace xo { namespace facet {
|
||||
template <typename Object>
|
||||
struct RoutingFor<xo::mm::AResourceVisitor, Object> {
|
||||
using RoutingType = xo::mm::RResourceVisitor<Object>;
|
||||
};
|
||||
} }
|
||||
|
||||
/* end RResourceVisitor.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue