diff options
author | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-11-26 03:15:09 -0800 |
---|---|---|
committer | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-11-26 03:15:09 -0800 |
commit | 0a9e019f082578895e4ebc88e4b89188da17947f (patch) | |
tree | 2a2017bec3d0450deb086fa6ad92d44b9e025e3b /starts/meaning-vm/level-0 | |
parent | d5e8c913a0c3b63ef7eadea41ec1818548f5f4cf (diff) | |
download | standingwithresilience-0a9e019f082578895e4ebc88e4b89188da17947f.tar.gz standingwithresilience-0a9e019f082578895e4ebc88e4b89188da17947f.zip |
removed braces from multilink call, normalized memorystore ref usage per proposal
Diffstat (limited to 'starts/meaning-vm/level-0')
-rw-r--r-- | starts/meaning-vm/level-0/baseref.hpp | 16 | ||||
-rw-r--r-- | starts/meaning-vm/level-0/memorystore.cpp | 7 | ||||
-rw-r--r-- | starts/meaning-vm/level-0/memorystore.hpp | 6 |
3 files changed, 16 insertions, 13 deletions
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<ref> refs) + template <typename... Ref> + ref link(Ref... refspack) { + std::initializer_list<ref> 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<level0::ref*>(this); } - level1::ref & r1() { return *reinterpret_cast<level1::ref*>(this); } - level2::ref & r2() { return *reinterpret_cast<level2::ref*>(this); } - level3::ref & r3() { return *reinterpret_cast<level3::ref*>(this); } - level4::ref & r4() { return *reinterpret_cast<level4::ref*>(this); } - level5::ref & r5() { return *reinterpret_cast<level5::ref*>(this); } + operator level0::ref &() { return *reinterpret_cast<level0::ref*>(this); } + operator level1::ref &() { return *reinterpret_cast<level1::ref*>(this); } + operator level2::ref &() { return *reinterpret_cast<level2::ref*>(this); } + operator level3::ref &() { return *reinterpret_cast<level3::ref*>(this); } + operator level4::ref &() { return *reinterpret_cast<level4::ref*>(this); } + operator level5::ref &() { return *reinterpret_cast<level5::ref*>(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 <unordered_set> @@ -9,11 +10,11 @@ namespace level0 { static auto & concepts() { - static std::unordered_set<concept*, std::hash<concept*>> concepts; + static std::unordered_set<ref, std::hash<concept*>> 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 <typename T> -value<T> * valloc(T const & v) { return static_cast<value<T>*>(alloc(new value<T>(v))); } -void dealloc(concept*); +value<T> * valloc(T const & v) { return static_cast<value<T>*>(alloc(new value<T>(v)).ptr()); } +void dealloc(ref); std::size_t allocated(); } |