xo-interpreter2 stack: + stringtable() in RuntimeContext api
This commit is contained in:
parent
f1594aab13
commit
0e12e2644e
11 changed files with 62 additions and 9 deletions
|
|
@ -87,27 +87,36 @@ namespace xo {
|
|||
/** @defgroup scm-primitive-ctors constructors **/
|
||||
///@{
|
||||
|
||||
Primitive(std::string_view name, Fn fn)
|
||||
Primitive(std::string_view name, obj<AType> type, Fn fn)
|
||||
: name_{name},
|
||||
type_{type},
|
||||
fn_td_{Reflect::require<Fn>()},
|
||||
fn_{fn} {}
|
||||
|
||||
static Primitive * _make(obj<AAllocator> mm, std::string_view name, Fn fn) {
|
||||
void * mem = mm.alloc_for<Primitive>();
|
||||
|
||||
return new (mem) Primitive(name, fn);
|
||||
return new (mem) Primitive(name, obj<AType>(), fn);
|
||||
}
|
||||
|
||||
static Primitive * _make(obj<AAllocator> mm,
|
||||
std::string_view name,
|
||||
obj<AType> type,
|
||||
Fn fn)
|
||||
{
|
||||
void * mem = mm.alloc_for<Primitive>();
|
||||
|
||||
return new (mem) Primitive(name, type, fn);
|
||||
}
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-primitive-methods general methods **/
|
||||
///@{
|
||||
|
||||
TypeDescr fn_td() const noexcept { return fn_td_; }
|
||||
|
||||
std::string_view name() const noexcept { return name_; }
|
||||
|
||||
static constexpr std::int32_t n_args() noexcept { return Traits::n_args; }
|
||||
|
||||
TypeDescr fn_td() const noexcept { return fn_td_; }
|
||||
std::string_view name() const noexcept { return name_; }
|
||||
bool is_nary() const noexcept { return false; }
|
||||
|
||||
obj<AGCObject> apply_nocheck(obj<ARuntimeContext> rcx, const DArray * args) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <xo/stringtable2/StringTable.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
|
||||
namespace xo {
|
||||
|
|
@ -21,13 +22,16 @@ namespace xo {
|
|||
using MemorySizeVisitor = xo::mm::MemorySizeVisitor;
|
||||
|
||||
public:
|
||||
DSimpleRcx(obj<AAllocator> mm) : allocator_{mm} {}
|
||||
DSimpleRcx(obj<AAllocator> mm, StringTable * st)
|
||||
: allocator_{mm}, stringtable_{st} {}
|
||||
|
||||
obj<AAllocator> allocator() const noexcept { return allocator_; }
|
||||
StringTable * stringtable() const noexcept { return stringtable_; }
|
||||
void visit_pools(const MemorySizeVisitor & visitor) const;
|
||||
|
||||
private:
|
||||
obj<AAllocator> allocator_;
|
||||
StringTable * stringtable_ = nullptr;
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#pragma once
|
||||
|
||||
// includes (via {facet_includes})
|
||||
#include <xo/stringtable2/StringTable.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <xo/arena/MemorySizeInfo.hpp>
|
||||
#include <xo/facet/obj.hpp>
|
||||
|
|
@ -54,6 +55,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;
|
||||
/** stringtable for unique symbols **/
|
||||
virtual StringTable * stringtable(Copaque data) const noexcept = 0;
|
||||
/** invoke visitor for each distinct memory pool **/
|
||||
virtual void visit_pools(Copaque data, MemorySizeVisitor visitor) const = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ namespace scm {
|
|||
|
||||
// const methods
|
||||
[[noreturn]] obj<AAllocator> allocator(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] StringTable * stringtable(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] void visit_pools(Copaque, MemorySizeVisitor) const override { _fatal(); }
|
||||
|
||||
// nonconst methods
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ namespace xo {
|
|||
// const methods
|
||||
/** default allocator to use for objects **/
|
||||
static obj<AAllocator> allocator(const DSimpleRcx & self) noexcept;
|
||||
/** stringtable for unique symbols **/
|
||||
static StringTable * stringtable(const DSimpleRcx & self) noexcept;
|
||||
/** invoke visitor for each distinct memory pool **/
|
||||
static void visit_pools(const DSimpleRcx & self, MemorySizeVisitor visitor);
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <xo/stringtable2/StringTable.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <xo/arena/MemorySizeInfo.hpp>
|
||||
|
||||
|
|
@ -49,6 +50,9 @@ namespace scm {
|
|||
obj<AAllocator> allocator(Copaque data) const noexcept override {
|
||||
return I::allocator(_dcast(data));
|
||||
}
|
||||
StringTable * stringtable(Copaque data) const noexcept override {
|
||||
return I::stringtable(_dcast(data));
|
||||
}
|
||||
void visit_pools(Copaque data, MemorySizeVisitor visitor) const override {
|
||||
return I::visit_pools(_dcast(data), visitor);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,9 @@ public:
|
|||
obj<AAllocator> allocator() const noexcept {
|
||||
return O::iface()->allocator(O::data());
|
||||
}
|
||||
StringTable * stringtable() const noexcept {
|
||||
return O::iface()->stringtable(O::data());
|
||||
}
|
||||
void visit_pools(MemorySizeVisitor visitor) const {
|
||||
return O::iface()->visit_pools(O::data(), visitor);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue