diff options
author | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-11-24 19:23:37 -0800 |
---|---|---|
committer | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-11-24 19:23:37 -0800 |
commit | cd03e291664cb102bde61d86a15f0add11809766 (patch) | |
tree | 9afb4bc872236b95debd5e20daf00797c563c666 /starts/meaning-vm/level-0 | |
parent | dbbed1e4e1d4b3f268c71236c89f1d673fa0c165 (diff) | |
download | standingwithresilience-cd03e291664cb102bde61d86a15f0add11809766.tar.gz standingwithresilience-cd03e291664cb102bde61d86a15f0add11809766.zip |
messy but works. rushing to get this done with may have been a poor investment.
Diffstat (limited to 'starts/meaning-vm/level-0')
-rw-r--r-- | starts/meaning-vm/level-0/concept.cpp | 6 | ||||
-rw-r--r-- | starts/meaning-vm/level-0/level-0.hpp | 1 | ||||
-rw-r--r-- | starts/meaning-vm/level-0/memorystore.cpp | 6 | ||||
-rw-r--r-- | starts/meaning-vm/level-0/ref-mixin.hpp | 27 | ||||
-rw-r--r-- | starts/meaning-vm/level-0/ref.cpp | 4 | ||||
-rw-r--r-- | starts/meaning-vm/level-0/ref.hpp | 13 | ||||
-rw-r--r-- | starts/meaning-vm/level-0/vref.hpp | 3 |
7 files changed, 36 insertions, 24 deletions
diff --git a/starts/meaning-vm/level-0/concept.cpp b/starts/meaning-vm/level-0/concept.cpp index 579cca8..dace7df 100644 --- a/starts/meaning-vm/level-0/concept.cpp +++ b/starts/meaning-vm/level-0/concept.cpp @@ -12,7 +12,7 @@ ref concept::id() void concept::link(ref const & type, ref const & target) { - links.insert({type.ptr, target.ptr}); + links.insert({type, target}); } void concept::unlink(ref const & type, ref const & target) @@ -43,7 +43,7 @@ void concept::unlink(ref const & type) bool concept::linked(ref const & type) const { - return links.count(type.ptr) > 0; + return links.count(type) > 0; } bool concept::linked(ref const & type, ref const & target) const @@ -71,7 +71,7 @@ concept::array concept::getAll(ref const & type) const ref concept::get(ref const & type) const { - auto result = links.equal_range(type.ptr); + auto result = links.equal_range(type); if (result.first == result.second) { throw no_such_link_type(selfref, type); } diff --git a/starts/meaning-vm/level-0/level-0.hpp b/starts/meaning-vm/level-0/level-0.hpp index 10df5b7..b44b6e0 100644 --- a/starts/meaning-vm/level-0/level-0.hpp +++ b/starts/meaning-vm/level-0/level-0.hpp @@ -5,6 +5,5 @@ #include "errors.hpp" #include "memorystore.hpp" #include "ref.hpp" -#include "ref-mixin.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 0a4f0cc..7ff5e42 100644 --- a/starts/meaning-vm/level-0/memorystore.cpp +++ b/starts/meaning-vm/level-0/memorystore.cpp @@ -26,10 +26,10 @@ static concept* referenced(ref r) { } for (auto & l : r2->links) { if (ref(l.first) == r) { - return r2.ptr; + return r2; } if (ref(l.second) == r) { - return r2.ptr; + return r2; } } } @@ -48,7 +48,7 @@ void dealloc(ref r) { { if (ref(*it) == r) { concepts().erase(it); - delete r.ptr; + delete (concept*)r; return; } } diff --git a/starts/meaning-vm/level-0/ref-mixin.hpp b/starts/meaning-vm/level-0/ref-mixin.hpp index ba5fe09..15e5abe 100644 --- a/starts/meaning-vm/level-0/ref-mixin.hpp +++ b/starts/meaning-vm/level-0/ref-mixin.hpp @@ -1,5 +1,6 @@ #pragma once +#include <map> #include <vector> namespace intellect { @@ -7,25 +8,33 @@ namespace level0 { template <typename ref, template<typename> typename vref> struct refmixin { + using links_t = std::multimap<ref, ref>; using array = std::vector<ref>; - void link(ref const & type, ref const & target) { ptr()->link(type, target); } - void unlink(ref const & type, ref const & target) { ptr()->unlink(type, target); } - void unlink(ref const & type) { ptr()->unlink(type); } + void link(ref const & type, ref const & target) { p()->link(conv<r>(type), conv<r>(target)); } + void unlink(ref const & type, ref const & target) { p()->unlink(conv<r>(type), conv<r>(target)); } + void unlink(ref const & type) { p()->unlink(conv<r>(type)); } - bool linked(ref const & type) const { return ptr()->linked(type); } - bool linked(ref const & type, ref const & target) const { return ptr()->linked(type, target); } + bool linked(ref const & type) const { return p()->linked(conv<r>(type)); } + bool linked(ref const & type, ref const & target) const { return p()->linked(conv<r>(type), conv<r>(target)); } - array getAll(ref const & type) const { return conv<array>(ptr()->getAll(type)); } + array getAll(ref const & type) const { return conv<array>(p()->getAll(conv<r>(type))); } - ref get(ref const & type) const { return conv<ref>(ptr()->get(type)); } - void set(ref const & type, ref const & target) { ptr()->set(type, target); } + links_t & links() const { return *(links_t*)&(p()->links); } + + ref get(ref const & type) const { return conv<ref>(p()->get(conv<r>(type))); } + void set(ref const & type, ref const & target) { p()->set(conv<r>(type), conv<r>(target)); } template <typename T> vref<T> vget(ref const & type) const { return conv<vref<T>>(get(type)); } + 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(); } + private: - inline concept * ptr() const { return conv<ref*>(this)->ptr; } + inline concept * p() const { return *conv<concept**>(this); } + using r = level0::ref; template <typename OUT, typename IN> static inline OUT conv(IN r) { return *(OUT*)&r; } }; diff --git a/starts/meaning-vm/level-0/ref.cpp b/starts/meaning-vm/level-0/ref.cpp index 7e10528..f468456 100644 --- a/starts/meaning-vm/level-0/ref.cpp +++ b/starts/meaning-vm/level-0/ref.cpp @@ -14,7 +14,7 @@ ref::ref(concept *p) } } -std::string ref::dump(ref skipmarkertype, ref skipmarkertarget) const +std::string ref::dump(ref skipmarkertype, ref skipmarkertarget) { if (self->linked(skipmarkertype, skipmarkertarget)) { return {}; @@ -25,7 +25,7 @@ std::string ref::dump(ref skipmarkertype, ref skipmarkertarget) const } self->link(skipmarkertype, skipmarkertarget); for (auto & link : self->links) { - if (link.first == skipmarkertype && link.second == skipmarkertype) { + if (link.first == skipmarkertype && link.second == skipmarkertarget) { continue; } ret += link.second.dump(skipmarkertype, skipmarkertarget); diff --git a/starts/meaning-vm/level-0/ref.hpp b/starts/meaning-vm/level-0/ref.hpp index c1fa7fa..abe3897 100644 --- a/starts/meaning-vm/level-0/ref.hpp +++ b/starts/meaning-vm/level-0/ref.hpp @@ -11,16 +11,19 @@ namespace level0 { struct ref : public refmixin<ref, vref> { ref(concept *p); + ref(ref const & other) : ref(other.ptr) { } + ref & operator=(ref const & other) { self.ptr = other.ptr; return self; } operator concept*() const { return ptr; } concept* operator->() const { return ptr; } - bool operator==(ref const & other) const { return self.ptr == other.ptr; } - bool operator!=(ref const & other) const { return self.ptr != other.ptr; } - bool operator<(ref const & other) const { return self.ptr < other.ptr; } concept & deref() { return *ptr; } - std::string dump(ref skipmarkertype, ref skipmarkertarget) const; + ref & l0() { return self; } + ref const & l0() const { return self; } - concept * const ptr; + std::string dump(ref skipmarkertype, ref skipmarkertarget); + +private: + concept * ptr; }; } diff --git a/starts/meaning-vm/level-0/vref.hpp b/starts/meaning-vm/level-0/vref.hpp index cffc8f5..1eb701d 100644 --- a/starts/meaning-vm/level-0/vref.hpp +++ b/starts/meaning-vm/level-0/vref.hpp @@ -17,13 +17,14 @@ struct vref vref(T const & val) : vref(alloc(new value<T>(val))) { } - vref(ref const & other) : ptr(static_cast<value<T>*>(other.ptr)) { } + 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; }; |