summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/helpers.cpp
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-21 13:37:18 -0500
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-21 13:37:18 -0500
commit6e81ffa9f5baabe8d4b16fa927ce423fbe26771e (patch)
tree3abbf34ccf1cb05d26f4a83a8dcf3455aebe1c90 /starts/meaning-vm/helpers.cpp
parent302fc80f638783d17cd3b496284a535044241297 (diff)
downloadstandingwithresilience-6e81ffa9f5baabe8d4b16fa927ce423fbe26771e.tar.gz
standingwithresilience-6e81ffa9f5baabe8d4b16fa927ce423fbe26771e.zip
direct cast concept from string
Diffstat (limited to 'starts/meaning-vm/helpers.cpp')
-rw-r--r--starts/meaning-vm/helpers.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/starts/meaning-vm/helpers.cpp b/starts/meaning-vm/helpers.cpp
new file mode 100644
index 0000000..e4a7689
--- /dev/null
+++ b/starts/meaning-vm/helpers.cpp
@@ -0,0 +1,28 @@
+#include "helpers.hpp"
+
+#include <unordered_map>
+
+// these 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;
+
+ref::ref(std::string 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);
+ ptr = con;
+ }
+}
+
+ref::operator std::string()
+{
+ return value<std::string>::of(namesByConcept.get(*this));
+}