summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/level-1
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-24 19:23:37 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-24 19:23:37 -0800
commitcd03e291664cb102bde61d86a15f0add11809766 (patch)
tree9afb4bc872236b95debd5e20daf00797c563c666 /starts/meaning-vm/level-1
parentdbbed1e4e1d4b3f268c71236c89f1d673fa0c165 (diff)
downloadstandingwithresilience-cd03e291664cb102bde61d86a15f0add11809766.tar.gz
standingwithresilience-cd03e291664cb102bde61d86a15f0add11809766.zip
messy but works. rushing to get this done with may have been a poor investment.
Diffstat (limited to 'starts/meaning-vm/level-1')
-rw-r--r--starts/meaning-vm/level-1/common.hpp10
-rw-r--r--starts/meaning-vm/level-1/concepts.cpp13
-rw-r--r--starts/meaning-vm/level-1/concepts.hpp20
-rw-r--r--starts/meaning-vm/level-1/level-1.hpp7
-rw-r--r--starts/meaning-vm/level-1/ref.cpp91
-rw-r--r--starts/meaning-vm/level-1/ref.hpp34
-rw-r--r--starts/meaning-vm/level-1/sugar.cpp41
-rw-r--r--starts/meaning-vm/level-1/sugar.hpp47
-rw-r--r--starts/meaning-vm/level-1/vref.hpp38
9 files changed, 301 insertions, 0 deletions
diff --git a/starts/meaning-vm/level-1/common.hpp b/starts/meaning-vm/level-1/common.hpp
new file mode 100644
index 0000000..2977077
--- /dev/null
+++ b/starts/meaning-vm/level-1/common.hpp
@@ -0,0 +1,10 @@
+#pragma once
+
+namespace intellect {
+namespace level1 {
+
+struct ref;
+template <typename T> struct vref;
+
+}
+}
diff --git a/starts/meaning-vm/level-1/concepts.cpp b/starts/meaning-vm/level-1/concepts.cpp
new file mode 100644
index 0000000..4c098de
--- /dev/null
+++ b/starts/meaning-vm/level-1/concepts.cpp
@@ -0,0 +1,13 @@
+#include "concepts.hpp"
+
+namespace intellect {
+namespace level1 {
+namespace concepts {
+
+ref is("is");
+ref anonymous("anonymous");
+ref link("link");
+
+}
+}
+}
diff --git a/starts/meaning-vm/level-1/concepts.hpp b/starts/meaning-vm/level-1/concepts.hpp
new file mode 100644
index 0000000..7aa7394
--- /dev/null
+++ b/starts/meaning-vm/level-1/concepts.hpp
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "ref.hpp"
+#include "sugar.hpp"
+
+namespace intellect {
+namespace level1 {
+
+namespace concepts {
+
+extern ref name; // used as the link to value<std::string> naming each concept
+extern ref is; // a link to define group relationships, links to the more general class
+extern ref anonymous; // a group given concepts with generated names
+extern ref link; // TODO: for concepts that are links, link them with is=link
+//extern ref true, false; <-- casting provides as if these were declared
+
+}
+
+}
+}
diff --git a/starts/meaning-vm/level-1/level-1.hpp b/starts/meaning-vm/level-1/level-1.hpp
new file mode 100644
index 0000000..d13ba9f
--- /dev/null
+++ b/starts/meaning-vm/level-1/level-1.hpp
@@ -0,0 +1,7 @@
+#pragma once
+
+#include "common.hpp"
+#include "concepts.hpp"
+#include "ref.hpp"
+#include "sugar.hpp"
+#include "vref.hpp"
diff --git a/starts/meaning-vm/level-1/ref.cpp b/starts/meaning-vm/level-1/ref.cpp
new file mode 100644
index 0000000..045e879
--- /dev/null
+++ b/starts/meaning-vm/level-1/ref.cpp
@@ -0,0 +1,91 @@
+#include "ref.hpp"
+#include "../level-0/errors.hpp"
+#include "../level-0/memorystore.hpp"
+#include "../level-0/vref.hpp"
+#include "concepts.hpp"
+#include "vref.hpp"
+
+#include <unordered_map>
+
+using namespace intellect;
+using namespace level1;
+using namespace concepts;
+
+// ensure name link and backing structure are created prior to first use
+static auto & namestruct()
+{
+ static struct name_t
+ {
+ std::unordered_map<level0::vref<std::string>,level0::ref,std::hash<std::string>,std::equal_to<std::string>> conceptsByName;
+ ref nameref;
+ name_t()
+ : nameref(level0::alloc())
+ {
+ level0::vref namestr(std::string("name"));
+ nameref.set(nameref, (level0::ref)namestr);
+ conceptsByName.emplace(namestr, nameref.l0());
+ }
+ } namestruct;
+ return namestruct;
+}
+
+level0::ref getnamed(std::string const & name)
+{
+ auto & ns = namestruct();
+ auto res = ns.conceptsByName.find(name);
+ if (res != ns.conceptsByName.end()) {
+ return res->second;
+ } else {
+ level0::ref con = level0::alloc();
+ level0::vref namestr(name);
+ ns.conceptsByName.emplace(namestr, con);
+ con.set(ns.nameref.l0(), namestr);
+ return con;
+ }
+}
+
+ref::ref(std::string const & name)
+: ref0((level0::concept*)getnamed(name))
+{ }
+
+vref<std::string> ref::name() const
+{
+ try {
+ return vget<std::string>(namestruct().nameref);
+ } catch(level0::no_such_link_type&) {
+ return ref("UNNAMED").name();
+ }
+}
+
+bool ref::isa(ref group) const
+{
+ for (auto & g : getAll(is)) {
+ if (g == group) return true;
+ if (g == self) continue;
+ if (g.isa(group)) return true;
+ }
+ return false;
+}
+
+std::string ref::dump(ref skipmarkertype, ref skipmarkertarget)
+{
+ if (linked(skipmarkertype, skipmarkertarget)) {
+ return {};
+ }
+ std::string ret;
+ for (auto & link : links()) {
+ if (link.first == namestruct().nameref) { continue; }
+ if (ret.size() == 0) {
+ ret = name().val() + ":\n";
+ }
+ ret += " " + link.first.name().val() + ": " + link.second.name().val() + "\n";
+ }
+ link(skipmarkertype, skipmarkertarget);
+ for (auto & link : links()) {
+ if (link.first == skipmarkertype && link.second == skipmarkertarget) {
+ continue;
+ }
+ ret += link.second.dump(skipmarkertype, skipmarkertarget);
+ }
+ return ret;
+}
diff --git a/starts/meaning-vm/level-1/ref.hpp b/starts/meaning-vm/level-1/ref.hpp
new file mode 100644
index 0000000..40eee20
--- /dev/null
+++ b/starts/meaning-vm/level-1/ref.hpp
@@ -0,0 +1,34 @@
+#pragma once
+
+#include "common.hpp"
+#include "../level-0/ref.hpp"
+#include "../level-0/ref-mixin.hpp"
+
+namespace intellect {
+namespace level1 {
+
+struct ref : public level0::refmixin<ref,vref>
+{
+ ref(level0::ref const & other) : ref0(other) { }
+ ref(std::string const & name);
+ ref(const char *name) : ref(std::string(name)) { }
+ ref(bool b) : ref(b ? "true" : "false") { }
+ ref() : ref("nothing") { }
+
+ bool isa(ref group) const;
+ bool isan(ref group) const { return isa(group); }
+
+ vref<std::string> name() const;
+
+ level0::ref & l0() { return ref0; }
+ ref & l1() { return self; }
+ ref const & l1() const { return self; }
+
+ std::string dump(ref skipmarkertype, ref skipmarkertarget);
+private:
+
+ level0::ref ref0;
+};
+
+}
+}
diff --git a/starts/meaning-vm/level-1/sugar.cpp b/starts/meaning-vm/level-1/sugar.cpp
new file mode 100644
index 0000000..eeb2eb0
--- /dev/null
+++ b/starts/meaning-vm/level-1/sugar.cpp
@@ -0,0 +1,41 @@
+#include "sugar.hpp"
+
+#include "concepts.hpp"
+
+using namespace intellect::level1;
+using namespace concepts;
+
+namespace intellect {
+namespace level1 {
+
+ref operator-(ref a, ref b)
+{
+ return ref(a.name() + "-" + b.name());
+}
+
+ref a(ref group)
+{
+ static unsigned long long gid = 0;
+ ref ret(group.name() + "-" + std::to_string(gid++));
+ ret.link(is, group);
+ ret.link(is, anonymous);
+ return ret;
+}
+ref a(ref group, ref name)
+{
+ if (!name.isa(group)) {
+ name.link(is, group);
+ }
+ return name;
+}
+ref an(ref group)
+{
+ return a(group);
+}
+ref an(ref group, ref name)
+{
+ return a(group, name);
+}
+
+}
+}
diff --git a/starts/meaning-vm/level-1/sugar.hpp b/starts/meaning-vm/level-1/sugar.hpp
new file mode 100644
index 0000000..c2fa4f9
--- /dev/null
+++ b/starts/meaning-vm/level-1/sugar.hpp
@@ -0,0 +1,47 @@
+#pragma once
+
+#include "common.hpp"
+#include "ref.hpp"
+#include "vref.hpp"
+
+#include <string>
+#include <sstream>
+
+namespace intellect {
+namespace level1 {
+
+inline std::string operator+(vref<std::string> a, char const * b) { return std::string(a) + b; }
+inline std::string operator+(vref<std::string> a, std::string b) { return std::string(a) + b; }
+inline std::string operator+(char const * a, vref<std::string> b) { return a + std::string(b); }
+inline std::string operator+(std::string a, vref<std::string> b) { return a + std::string(b); }
+
+namespace internal {
+ template <typename... T>
+ void init_ref_names(std::string names, T &... refrefs)
+ {
+ std::stringstream ss(names);
+ ref* refptrs[] = {&refrefs...};
+ for (std::size_t i = 0; i < sizeof...(refrefs); ++ i) {
+ std::string name;
+ ss >> name;
+ if (name[name.size() - 1] == ',') {
+ name = name.substr(0, name.size() - 1);
+ }
+ refptrs[i]->l0() = ref(name).l0();
+ }
+ }
+}
+
+#define decl(...) \
+ intellect::level1::ref __VA_ARGS__; \
+ intellect::level1::internal::init_ref_names(#__VA_ARGS__, __VA_ARGS__)
+
+ref operator-(ref a, ref b);
+
+ref a(ref group);
+ref an(ref group);
+ref a(ref group, ref name);
+ref an(ref group, ref name);
+
+}
+}
diff --git a/starts/meaning-vm/level-1/vref.hpp b/starts/meaning-vm/level-1/vref.hpp
new file mode 100644
index 0000000..fb7ba5d
--- /dev/null
+++ b/starts/meaning-vm/level-1/vref.hpp
@@ -0,0 +1,38 @@
+#pragma once
+
+#include "../level-0/vref.hpp"
+#include "ref.hpp"
+
+#include <sstream>
+
+namespace intellect {
+namespace level1 {
+
+template <typename T>
+struct vref : public level0::vref<T>
+{
+ vref(level0::vref<T> other) : level0::vref<T>((level0::concept*)other.ref) { }
+ vref(level0::value<T> *p) : level0::vref<T>(p) { }
+ vref(ref const & other) : level0::vref<T>(other) { }
+ vref(T const & val)
+ : level0::vref<T>(val)
+ {
+ std::stringstream ss;
+ ss << "v:" << val;
+ ref(self).set(ref("name"), (level0::ref)level0::vref<std::string>(ss.str()));
+ }
+
+ using level0::vref<T>::operator->;
+ using level0::vref<T>::operator T const &;
+
+ vref<std::string> name()
+ {
+ return ref(self).name();
+ }
+
+ operator ref() { return level0::ref(level0::vref<T>::ptr); }
+};
+
+
+}
+}