From 0a9e019f082578895e4ebc88e4b89188da17947f Mon Sep 17 00:00:00 2001 From: olpc user Date: Tue, 26 Nov 2019 03:15:09 -0800 Subject: removed braces from multilink call, normalized memorystore ref usage per proposal --- starts/meaning-vm/level-0/baseref.hpp | 16 +++++++++------- starts/meaning-vm/level-0/memorystore.cpp | 7 ++++--- starts/meaning-vm/level-0/memorystore.hpp | 6 +++--- 3 files changed, 16 insertions(+), 13 deletions(-) (limited to 'starts/meaning-vm/level-0') diff --git a/starts/meaning-vm/level-0/baseref.hpp b/starts/meaning-vm/level-0/baseref.hpp index b4ceb02..849e205 100644 --- a/starts/meaning-vm/level-0/baseref.hpp +++ b/starts/meaning-vm/level-0/baseref.hpp @@ -36,8 +36,10 @@ public: array getAll(ref const & type) const; links_t links() const; - ref link(std::initializer_list refs) + template + ref link(Ref... refspack) { + std::initializer_list refs{refspack...}; for (auto it = refs.begin(); it != refs.end();) { ref type = *it++; ref target = *it++; @@ -58,12 +60,12 @@ public: concept*& ptr() { return p; } concept* const & ptr() const { return p; } - level0::ref & r0() { return *reinterpret_cast(this); } - level1::ref & r1() { return *reinterpret_cast(this); } - level2::ref & r2() { return *reinterpret_cast(this); } - level3::ref & r3() { return *reinterpret_cast(this); } - level4::ref & r4() { return *reinterpret_cast(this); } - level5::ref & r5() { return *reinterpret_cast(this); } + operator level0::ref &() { return *reinterpret_cast(this); } + operator level1::ref &() { return *reinterpret_cast(this); } + operator level2::ref &() { return *reinterpret_cast(this); } + operator level3::ref &() { return *reinterpret_cast(this); } + operator level4::ref &() { return *reinterpret_cast(this); } + operator level5::ref &() { return *reinterpret_cast(this); } bool operator==(ref const & other) const { return self.p == other.p; } bool operator!=(ref const & other) const { return self.p == other.p; } diff --git a/starts/meaning-vm/level-0/memorystore.cpp b/starts/meaning-vm/level-0/memorystore.cpp index d3e4f95..b092ca0 100644 --- a/starts/meaning-vm/level-0/memorystore.cpp +++ b/starts/meaning-vm/level-0/memorystore.cpp @@ -1,6 +1,7 @@ #include "memorystore.hpp" #include "concept.hpp" #include "errors.hpp" +#include "ref.hpp" #include @@ -9,11 +10,11 @@ namespace level0 { static auto & concepts() { - static std::unordered_set> concepts; + static std::unordered_set> concepts; return concepts; } -concept* alloc(concept * moved) { +ref alloc(concept * moved) { ref r = moved ? moved : new concept(); concepts().insert(r); return r; @@ -36,7 +37,7 @@ static concept* referenced(ref r) { return 0; } -void dealloc(concept * r) { +void dealloc(ref r) { concept * referenced = intellect::level0::referenced(r); if (referenced) { throw still_referenced_by(r, referenced); diff --git a/starts/meaning-vm/level-0/memorystore.hpp b/starts/meaning-vm/level-0/memorystore.hpp index 8958ae7..fd752a0 100644 --- a/starts/meaning-vm/level-0/memorystore.hpp +++ b/starts/meaning-vm/level-0/memorystore.hpp @@ -6,10 +6,10 @@ namespace intellect { namespace level0 { -concept * alloc(concept * moved = 0); +ref alloc(concept * moved = 0); template -value * valloc(T const & v) { return static_cast*>(alloc(new value(v))); } -void dealloc(concept*); +value * valloc(T const & v) { return static_cast*>(alloc(new value(v)).ptr()); } +void dealloc(ref); std::size_t allocated(); } -- cgit v1.2.3