diff options
Diffstat (limited to 'starts/meaning-vm/helpers.cpp')
-rw-r--r-- | starts/meaning-vm/helpers.cpp | 46 |
1 files changed, 33 insertions, 13 deletions
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 <unordered_map> 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<value<std::string>,concept,std::hash<std::string>> conceptsByName; +std::unordered_map<vref<std::string>,ref,std::hash<std::string>,std::equal_to<std::string>> 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<std::string>(s)); - } catch (std::out_of_range) { - auto insertion = conceptsByName.emplace(value<std::string>(s), concept()); - ref con = &insertion.first->second; - ref nam = const_cast<concept *>((concept const *)&insertion.first->first); - namesByConcept.link(con, nam); + value<std::string> str(s); + auto res = conceptsByName.find(&str); + if (res != conceptsByName.end()) { + ptr = res->second.ptr; + } else { + ref con = alloc(); + auto nam = valloc<std::string>(s); + conceptsByName.emplace(nam, con); + con->link(::name, nam); ptr = con.ptr; } } value<std::string> & ref::name() const { - return value<std::string>::of(namesByConcept.get(*this)); + return *ptr->vget<std::string>(::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) { |