From cd03e291664cb102bde61d86a15f0add11809766 Mon Sep 17 00:00:00 2001 From: olpc user Date: Sun, 24 Nov 2019 19:23:37 -0800 Subject: messy but works. rushing to get this done with may have been a poor investment. --- starts/meaning-vm/level-0/concept.cpp | 6 +++--- starts/meaning-vm/level-0/level-0.hpp | 1 - starts/meaning-vm/level-0/memorystore.cpp | 6 +++--- starts/meaning-vm/level-0/ref-mixin.hpp | 27 ++++++++++++++++++--------- starts/meaning-vm/level-0/ref.cpp | 4 ++-- starts/meaning-vm/level-0/ref.hpp | 13 ++++++++----- starts/meaning-vm/level-0/vref.hpp | 3 ++- 7 files changed, 36 insertions(+), 24 deletions(-) (limited to 'starts/meaning-vm/level-0') 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 #include namespace intellect { @@ -7,25 +8,33 @@ namespace level0 { template typename vref> struct refmixin { + using links_t = std::multimap; using array = std::vector; - 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(type), conv(target)); } + void unlink(ref const & type, ref const & target) { p()->unlink(conv(type), conv(target)); } + void unlink(ref const & type) { p()->unlink(conv(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(type)); } + bool linked(ref const & type, ref const & target) const { return p()->linked(conv(type), conv(target)); } - array getAll(ref const & type) const { return conv(ptr()->getAll(type)); } + array getAll(ref const & type) const { return conv(p()->getAll(conv(type))); } - ref get(ref const & type) const { return conv(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(p()->get(conv(type))); } + void set(ref const & type, ref const & target) { p()->set(conv(type), conv(target)); } template vref vget(ref const & type) const { return conv>(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(this)->ptr; } + inline concept * p() const { return *conv(this); } + using r = level0::ref; template 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(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(val))) { } - vref(ref const & other) : ptr(static_cast*>(other.ptr)) { } + 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