summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/helpers.cpp
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-22 16:56:03 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-22 16:56:03 -0800
commitc699a8913c5c1e53e0b701109dabe2b8fc70b644 (patch)
treeb8e9d21a28c3ce310ce78ab91a9ce5bdb34ea1c2 /starts/meaning-vm/helpers.cpp
parent8565b47b9e8a59ac06e4f739d63218b0f1e5cb05 (diff)
downloadstandingwithresilience-c699a8913c5c1e53e0b701109dabe2b8fc70b644.tar.gz
standingwithresilience-c699a8913c5c1e53e0b701109dabe2b8fc70b644.zip
while wip, moved concept storage off of helpers
Diffstat (limited to 'starts/meaning-vm/helpers.cpp')
-rw-r--r--starts/meaning-vm/helpers.cpp46
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)
{