From c699a8913c5c1e53e0b701109dabe2b8fc70b644 Mon Sep 17 00:00:00 2001 From: olpc user Date: Fri, 22 Nov 2019 16:56:03 -0800 Subject: while wip, moved concept storage off of helpers --- starts/meaning-vm/helpers.cpp | 46 +++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'starts/meaning-vm/helpers.cpp') diff --git a/starts/meaning-vm/helpers.cpp b/starts/meaning-vm/helpers.cpp index 99c83dd..1d6d498 100644 --- a/starts/meaning-vm/helpers.cpp +++ b/starts/meaning-vm/helpers.cpp @@ -1,5 +1,7 @@ #include "helpers.hpp" +#include "memorystore.hpp" + #include ref operator-(ref a, ref b) @@ -9,7 +11,12 @@ ref operator-(ref a, ref b) concept ref::operator=(ref other) { - // if this is link-type, make new concept + // if this is not anonymous, and other is, then we are naming it + /*declrefs(anonymous); + if (other->linked(anonymous, true) && !ptr->linked(anonymous, true)) { + return; + }*/ + // if this is link-type, make new concept [not checked, might want to assume] concept ret; ret.link(*this, other); return ret; @@ -31,25 +38,38 @@ concept operator,(concept a, concept b) // concept names are for bootstrapping convenience, // to make hardcoding structures easier. // hence there is just one single list of them -concept namesByConcept; -std::unordered_map,concept,std::hash> conceptsByName; +std::unordered_map,ref,std::hash,std::equal_to> conceptsByName; + +struct name_t : public ref +{ + name_t(); +} name; +name_t::name_t() +: ref(alloc()) +{ + auto nam = valloc(std::string("name")); + ptr->link(::name, nam); + conceptsByName.emplace(nam, *this); +} ref::ref(std::string const & s) { - try { - ptr = &conceptsByName.at(value(s)); - } catch (std::out_of_range) { - auto insertion = conceptsByName.emplace(value(s), concept()); - ref con = &insertion.first->second; - ref nam = const_cast((concept const *)&insertion.first->first); - namesByConcept.link(con, nam); + value str(s); + auto res = conceptsByName.find(&str); + if (res != conceptsByName.end()) { + ptr = res->second.ptr; + } else { + ref con = alloc(); + auto nam = valloc(s); + conceptsByName.emplace(nam, con); + con->link(::name, nam); ptr = con.ptr; } } value & ref::name() const { - return value::of(namesByConcept.get(*this)); + return *ptr->vget(::name).ptr; } ref::operator const char *() const { @@ -59,8 +79,8 @@ ref::operator const char *() const { ref a(ref what) { static unsigned long long gid = 0; - declrefs(is); - return ref(what.name() + "-" + std::to_string(gid++))[is = what]; + declrefs(is, anonymous); + return ref(what.name() + "-" + std::to_string(gid++))[is = what, anonymous = true]; } ref an(ref what) { -- cgit v1.2.3