From 684ac69af192670bb6547ec01df19a3159e7d8e6 Mon Sep 17 00:00:00 2001 From: olpc user Date: Mon, 25 Nov 2019 08:42:45 -0800 Subject: separate functionality out a bit --- starts/meaning-vm/level-0/baseref.hpp | 24 ++++++++++++++-------- starts/meaning-vm/level-0/common.hpp | 5 +++++ starts/meaning-vm/level-0/level-0.hpp | 1 - starts/meaning-vm/level-0/memorystore.cpp | 8 ++++---- starts/meaning-vm/level-0/memorystore.hpp | 7 +++++-- starts/meaning-vm/level-0/ref.hpp | 6 +----- starts/meaning-vm/level-0/vref.hpp | 33 ------------------------------- 7 files changed, 31 insertions(+), 53 deletions(-) delete mode 100644 starts/meaning-vm/level-0/vref.hpp (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 c888021..bdfd065 100644 --- a/starts/meaning-vm/level-0/baseref.hpp +++ b/starts/meaning-vm/level-0/baseref.hpp @@ -9,8 +9,9 @@ namespace intellect { namespace level0 { -template typename vref, typename concept> -class baseref { +template +class baseref +{ struct array; struct links_t; public: baseref(concept *p) @@ -35,15 +36,22 @@ public: links_t links() const; template - vref vget(ref const & type) const { return p->template vget(type.p); } + T& vget(ref const & type) const { return p->vget(type.p)->data; } template - vref val() { return p->template val(); } + T& val() { return p->val()->data; } operator concept*() const { return p; } 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); } + bool operator==(ref const & other) const { return self.p == other.p; } bool operator!=(ref const & other) const { return self.p == other.p; } bool operator<(ref const & other) const { return self.p < other.p; } @@ -90,13 +98,13 @@ private: }; }; -template typename vref, typename concept> -typename baseref::array baseref::getAll(ref const & type) const +template +typename baseref::array baseref::getAll(ref const & type) const { return {p->getAll(type.p)}; } -template typename vref, typename concept> -typename baseref::links_t baseref::links() const +template +typename baseref::links_t baseref::links() const { return {p->links}; } diff --git a/starts/meaning-vm/level-0/common.hpp b/starts/meaning-vm/level-0/common.hpp index 4c36a04..74031cc 100644 --- a/starts/meaning-vm/level-0/common.hpp +++ b/starts/meaning-vm/level-0/common.hpp @@ -11,4 +11,9 @@ template struct value; template struct vref; } +namespace level1 { struct ref; template struct vref; } +namespace level2 { struct ref; template struct vref; } +namespace level3 { struct ref; template struct vref; } +namespace level4 { struct ref; template struct vref; } +namespace level5 { struct ref; template struct vref; } } diff --git a/starts/meaning-vm/level-0/level-0.hpp b/starts/meaning-vm/level-0/level-0.hpp index b44b6e0..7062be0 100644 --- a/starts/meaning-vm/level-0/level-0.hpp +++ b/starts/meaning-vm/level-0/level-0.hpp @@ -6,4 +6,3 @@ #include "memorystore.hpp" #include "ref.hpp" #include "value.hpp" -#include "vref.hpp" diff --git a/starts/meaning-vm/level-0/memorystore.cpp b/starts/meaning-vm/level-0/memorystore.cpp index 7018418..d3e4f95 100644 --- a/starts/meaning-vm/level-0/memorystore.cpp +++ b/starts/meaning-vm/level-0/memorystore.cpp @@ -9,11 +9,11 @@ namespace level0 { static auto & concepts() { - static std::unordered_set> concepts; + static std::unordered_set> concepts; return concepts; } -ref alloc(concept * moved) { +concept* alloc(concept * moved) { ref r = moved ? moved : new concept(); concepts().insert(r); return r; @@ -36,7 +36,7 @@ static concept* referenced(ref r) { return 0; } -void dealloc(ref r) { +void dealloc(concept * r) { concept * referenced = intellect::level0::referenced(r); if (referenced) { throw still_referenced_by(r, referenced); @@ -46,7 +46,7 @@ void dealloc(ref r) { it != concepts().end(); ++ it) { - if (ref(*it) == r) { + if (*it == r) { concepts().erase(it); delete (concept*)r; return; diff --git a/starts/meaning-vm/level-0/memorystore.hpp b/starts/meaning-vm/level-0/memorystore.hpp index a86ccea..cdd7462 100644 --- a/starts/meaning-vm/level-0/memorystore.hpp +++ b/starts/meaning-vm/level-0/memorystore.hpp @@ -2,12 +2,15 @@ #include "common.hpp" #include "ref.hpp" +#include "value.hpp" namespace intellect { namespace level0 { -ref alloc(concept * moved = 0); -void dealloc(ref); +concept * alloc(concept * moved = 0); +template +value * valloc(T const & v) { return static_cast*>(alloc(new value(v))); } +void dealloc(concept*); std::size_t allocated(); } diff --git a/starts/meaning-vm/level-0/ref.hpp b/starts/meaning-vm/level-0/ref.hpp index 87a37c6..ff55355 100644 --- a/starts/meaning-vm/level-0/ref.hpp +++ b/starts/meaning-vm/level-0/ref.hpp @@ -8,13 +8,9 @@ namespace intellect { namespace level0 { -struct ref : public baseref +struct ref : public baseref { ref(concept *p) : baseref(p) { } - ref & operator=(ref const & other) { self.p = other.p; return self; } - - ref & l0() { return self; } - ref const & l0() const { return self; } std::string dump(ref skipmarkertype, ref skipmarkertarget); }; diff --git a/starts/meaning-vm/level-0/vref.hpp b/starts/meaning-vm/level-0/vref.hpp deleted file mode 100644 index 1eb701d..0000000 --- a/starts/meaning-vm/level-0/vref.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "common.hpp" -#include "memorystore.hpp" -#include "ref.hpp" -#include "value.hpp" - -namespace intellect { -namespace level0 { - -template -struct vref -{ - vref(value *p) : ptr(p) { } - value* operator->() { return ptr; } - operator T const &() const { return *ptr; } - - vref(T const & val) : vref(alloc(new value(val))) { } - - vref(ref const & other) : ptr(static_cast*>((concept*)other)) { } - operator ref() { return ptr; } - T const & val() { return *ptr; } - - // for use by containers - bool operator<(vref const & other) const { return self.ptr < other.ptr; } - -protected: - value * const ptr; -}; - - -} -} -- cgit v1.2.3