diff --git a/idl/RuntimeContext.json5 b/idl/RuntimeContext.json5 index 46623b4..fe1254b 100644 --- a/idl/RuntimeContext.json5 +++ b/idl/RuntimeContext.json5 @@ -5,6 +5,7 @@ output_impl_subdir: "detail", // includes in ARuntimeContext.hpp includes: [ + "", "", "" ], @@ -46,6 +47,15 @@ noexcept: true, attributes: [], }, + { + name: "stringtable", + doc: [ "stringtable for unique symbols" ], + return_type: "StringTable *", + args: [], + const: true, + noexcept: true, + attributes: [], + }, { name: "visit_pools", doc: [ "invoke visitor for each distinct memory pool" ], diff --git a/include/xo/procedure2/DPrimitive.hpp b/include/xo/procedure2/DPrimitive.hpp index 07c19c4..4331057 100644 --- a/include/xo/procedure2/DPrimitive.hpp +++ b/include/xo/procedure2/DPrimitive.hpp @@ -87,27 +87,36 @@ namespace xo { /** @defgroup scm-primitive-ctors constructors **/ ///@{ - Primitive(std::string_view name, Fn fn) + Primitive(std::string_view name, obj type, Fn fn) : name_{name}, + type_{type}, fn_td_{Reflect::require()}, fn_{fn} {} static Primitive * _make(obj mm, std::string_view name, Fn fn) { void * mem = mm.alloc_for(); - return new (mem) Primitive(name, fn); + return new (mem) Primitive(name, obj(), fn); } + static Primitive * _make(obj mm, + std::string_view name, + obj type, + Fn fn) + { + void * mem = mm.alloc_for(); + + 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 apply_nocheck(obj rcx, const DArray * args) { diff --git a/include/xo/procedure2/DSimpleRcx.hpp b/include/xo/procedure2/DSimpleRcx.hpp index 1efb802..6a7163d 100644 --- a/include/xo/procedure2/DSimpleRcx.hpp +++ b/include/xo/procedure2/DSimpleRcx.hpp @@ -5,6 +5,7 @@ #pragma once +#include #include namespace xo { @@ -21,13 +22,16 @@ namespace xo { using MemorySizeVisitor = xo::mm::MemorySizeVisitor; public: - DSimpleRcx(obj mm) : allocator_{mm} {} + DSimpleRcx(obj mm, StringTable * st) + : allocator_{mm}, stringtable_{st} {} obj allocator() const noexcept { return allocator_; } + StringTable * stringtable() const noexcept { return stringtable_; } void visit_pools(const MemorySizeVisitor & visitor) const; private: obj allocator_; + StringTable * stringtable_ = nullptr; }; } /*namespace scm*/ diff --git a/include/xo/procedure2/detail/ARuntimeContext.hpp b/include/xo/procedure2/detail/ARuntimeContext.hpp index 820dd8d..716463d 100644 --- a/include/xo/procedure2/detail/ARuntimeContext.hpp +++ b/include/xo/procedure2/detail/ARuntimeContext.hpp @@ -14,6 +14,7 @@ #pragma once // includes (via {facet_includes}) +#include #include #include #include @@ -54,6 +55,8 @@ public: virtual void _drop(Opaque d) const noexcept = 0; /** default allocator to use for objects **/ virtual obj 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; diff --git a/include/xo/procedure2/detail/IRuntimeContext_Any.hpp b/include/xo/procedure2/detail/IRuntimeContext_Any.hpp index 2caa9d3..b72f934 100644 --- a/include/xo/procedure2/detail/IRuntimeContext_Any.hpp +++ b/include/xo/procedure2/detail/IRuntimeContext_Any.hpp @@ -61,6 +61,7 @@ namespace scm { // const methods [[noreturn]] obj 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 diff --git a/include/xo/procedure2/detail/IRuntimeContext_DSimpleRcx.hpp b/include/xo/procedure2/detail/IRuntimeContext_DSimpleRcx.hpp index 62d3e12..82ab521 100644 --- a/include/xo/procedure2/detail/IRuntimeContext_DSimpleRcx.hpp +++ b/include/xo/procedure2/detail/IRuntimeContext_DSimpleRcx.hpp @@ -49,6 +49,8 @@ namespace xo { // const methods /** default allocator to use for objects **/ static obj 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); diff --git a/include/xo/procedure2/detail/IRuntimeContext_Xfer.hpp b/include/xo/procedure2/detail/IRuntimeContext_Xfer.hpp index 6257abb..5dc9de5 100644 --- a/include/xo/procedure2/detail/IRuntimeContext_Xfer.hpp +++ b/include/xo/procedure2/detail/IRuntimeContext_Xfer.hpp @@ -13,6 +13,7 @@ #pragma once +#include #include #include @@ -49,6 +50,9 @@ namespace scm { obj 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); } diff --git a/include/xo/procedure2/detail/RRuntimeContext.hpp b/include/xo/procedure2/detail/RRuntimeContext.hpp index 5840743..6553648 100644 --- a/include/xo/procedure2/detail/RRuntimeContext.hpp +++ b/include/xo/procedure2/detail/RRuntimeContext.hpp @@ -57,6 +57,9 @@ public: obj 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); } diff --git a/src/procedure2/ObjectPrimitives.cpp b/src/procedure2/ObjectPrimitives.cpp index fcb8ba2..c247ab8 100644 --- a/src/procedure2/ObjectPrimitives.cpp +++ b/src/procedure2/ObjectPrimitives.cpp @@ -75,6 +75,8 @@ namespace xo { auto cdr_list = obj::from(cdr); + //auto T = DTypeVarRef::_make(rcx.allocator(), "T"); + return DList::cons(rcx.allocator(), car, cdr_list.data()); diff --git a/src/procedure2/facet/IRuntimeContext_DSimpleRcx.cpp b/src/procedure2/facet/IRuntimeContext_DSimpleRcx.cpp index 2331b7c..82dd310 100644 --- a/src/procedure2/facet/IRuntimeContext_DSimpleRcx.cpp +++ b/src/procedure2/facet/IRuntimeContext_DSimpleRcx.cpp @@ -21,6 +21,12 @@ namespace xo { return self.allocator(); } + auto + IRuntimeContext_DSimpleRcx::stringtable(const DSimpleRcx & self) noexcept -> StringTable * + { + return self.stringtable(); + } + auto IRuntimeContext_DSimpleRcx::visit_pools(const DSimpleRcx & self, MemorySizeVisitor visitor) -> void { diff --git a/utest/DSimpleRcx.test.cpp b/utest/DSimpleRcx.test.cpp index cab1362..365bd3f 100644 --- a/utest/DSimpleRcx.test.cpp +++ b/utest/DSimpleRcx.test.cpp @@ -6,12 +6,14 @@ #include #include #include +#include #include #include namespace xo { using xo::scm::DSimpleRcx; using xo::scm::ARuntimeContext; + using xo::scm::StringTable; using xo::mm::AAllocator; using xo::mm::DArena; using xo::mm::ArenaConfig; @@ -30,12 +32,17 @@ namespace xo { { ArenaConfig cfg { .name_ = "testarena", .size_ = 4*1024 }; + DArena arena = DArena::map(cfg); auto alloc = with_facet::mkobj(&arena); - DSimpleRcx rcx(alloc); + auto stbl = StringTable(1024 /*hint_max_capacity*/, + false /*!debug_flag*/); + + DSimpleRcx rcx(alloc, &stbl); REQUIRE((void*)rcx.allocator().data() == (void*)alloc.data()); + REQUIRE(rcx.stringtable() == &stbl); } TEST_CASE("DSimpleRcx-as-ARuntimeContext", "[procedure2][DSimpleRcx]") @@ -44,8 +51,10 @@ namespace xo { .size_ = 4*1024 }; DArena arena = DArena::map(cfg); auto alloc = with_facet::mkobj(&arena); + auto stbl = StringTable(1024 /*hint_max_capacity*/, + false /*!debug_flag*/); - DSimpleRcx rcx(alloc); + DSimpleRcx rcx(alloc, &stbl); obj rcx_obj = with_facet::mkobj(&rcx); // verify we can recover allocator from obj