summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/level-0
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-25 08:42:45 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-25 08:42:45 -0800
commit684ac69af192670bb6547ec01df19a3159e7d8e6 (patch)
treee6c6762e9fc40cf0ad557e160e9ab6ba7bb99eea /starts/meaning-vm/level-0
parent520119a6f6ed418b8ae45bfde8239bbb532562cd (diff)
downloadstandingwithresilience-684ac69af192670bb6547ec01df19a3159e7d8e6.tar.gz
standingwithresilience-684ac69af192670bb6547ec01df19a3159e7d8e6.zip
separate functionality out a bit
Diffstat (limited to 'starts/meaning-vm/level-0')
-rw-r--r--starts/meaning-vm/level-0/baseref.hpp24
-rw-r--r--starts/meaning-vm/level-0/common.hpp5
-rw-r--r--starts/meaning-vm/level-0/level-0.hpp1
-rw-r--r--starts/meaning-vm/level-0/memorystore.cpp8
-rw-r--r--starts/meaning-vm/level-0/memorystore.hpp7
-rw-r--r--starts/meaning-vm/level-0/ref.hpp6
-rw-r--r--starts/meaning-vm/level-0/vref.hpp33
7 files changed, 31 insertions, 53 deletions
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 ref, template<typename> typename vref, typename concept>
-class baseref {
+template <typename ref>
+class baseref
+{
struct array; struct links_t;
public:
baseref(concept *p)
@@ -35,15 +36,22 @@ public:
links_t links() const;
template <typename T>
- vref<T> vget(ref const & type) const { return p->template vget<T>(type.p); }
+ T& vget(ref const & type) const { return p->vget<T>(type.p)->data; }
template <typename T>
- vref<T> val() { return p->template val<T>(); }
+ T& val() { return p->val<T>()->data; }
operator concept*() const { return p; }
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); }
+
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 ref, template<typename> typename vref, typename concept>
-typename baseref<ref,vref,concept>::array baseref<ref,vref,concept>::getAll(ref const & type) const
+template <typename ref>
+typename baseref<ref>::array baseref<ref>::getAll(ref const & type) const
{
return {p->getAll(type.p)};
}
-template <typename ref, template<typename> typename vref, typename concept>
-typename baseref<ref,vref,concept>::links_t baseref<ref,vref,concept>::links() const
+template <typename ref>
+typename baseref<ref>::links_t baseref<ref>::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 <typename T> struct value;
template <typename T> struct vref;
}
+namespace level1 { struct ref; template <typename> struct vref; }
+namespace level2 { struct ref; template <typename> struct vref; }
+namespace level3 { struct ref; template <typename> struct vref; }
+namespace level4 { struct ref; template <typename> struct vref; }
+namespace level5 { struct ref; template <typename> 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<ref, std::hash<concept*>> concepts;
+ static std::unordered_set<concept*, std::hash<concept*>> 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 <typename T>
+value<T> * valloc(T const & v) { return static_cast<value<T>*>(alloc(new value<T>(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<ref, vref, concept>
+struct ref : public baseref<ref>
{
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 <typename T>
-struct vref
-{
- vref(value<T> *p) : ptr(p) { }
- value<T>* operator->() { return ptr; }
- operator T const &() const { return *ptr; }
-
- vref(T const & val) : vref(alloc(new value<T>(val))) { }
-
- vref(ref const & other) : ptr(static_cast<value<T>*>((concept*)other)) { }
- operator ref() { return ptr; }
- T const & val() { return *ptr; }
-
- // for use by containers
- bool operator<(vref<T> const & other) const { return self.ptr < other.ptr; }
-
-protected:
- value<T> * const ptr;
-};
-
-
-}
-}