summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/helpers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'starts/meaning-vm/helpers.cpp')
-rw-r--r--starts/meaning-vm/helpers.cpp55
1 files changed, 53 insertions, 2 deletions
diff --git a/starts/meaning-vm/helpers.cpp b/starts/meaning-vm/helpers.cpp
index fb17f6c..99c83dd 100644
--- a/starts/meaning-vm/helpers.cpp
+++ b/starts/meaning-vm/helpers.cpp
@@ -2,10 +2,35 @@
#include <unordered_map>
-// these concept names are for bootstrapping convenience,
+ref operator-(ref a, ref b)
+{
+ return ref(a.name() + "-" + b.name());
+}
+
+concept ref::operator=(ref other)
+{
+ // if this is link-type, make new concept
+ concept ret;
+ ret.link(*this, other);
+ return ret;
+}
+
+ref ref::operator[](concept links) {
+ ptr->links.insert(links.links.begin(), links.links.end());
+ return *this;
+}
+
+concept operator,(concept a, concept b)
+{
+ concept ret;
+ ret.links.insert(a.links.begin(), a.links.end());
+ ret.links.insert(b.links.begin(), b.links.end());
+ return ret;
+}
+
+// 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;
@@ -30,3 +55,29 @@ value<std::string> & ref::name() const
ref::operator const char *() const {
return name().c_str();
}
+
+ref a(ref what)
+{
+ static unsigned long long gid = 0;
+ declrefs(is);
+ return ref(what.name() + "-" + std::to_string(gid++))[is = what];
+}
+ref an(ref what)
+{
+ return a(what);
+}
+
+bool ref::isa(ref what) const
+{
+ declrefs(is);
+ for (auto group : ptr->getAll(is)) {
+ if (group == what) return true;
+ if (group.isa(what)) return true;
+ }
+ return false;
+}
+
+bool ref::isan(ref what) const
+{
+ return isa(what);
+}