summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/level-1
diff options
context:
space:
mode:
Diffstat (limited to 'starts/meaning-vm/level-1')
-rw-r--r--starts/meaning-vm/level-1/baseref.hpp30
-rw-r--r--starts/meaning-vm/level-1/common.hpp7
-rw-r--r--starts/meaning-vm/level-1/concepts.cpp1
-rw-r--r--starts/meaning-vm/level-1/funcs.cpp81
-rw-r--r--starts/meaning-vm/level-1/funcs.hpp23
-rw-r--r--starts/meaning-vm/level-1/level-1.hpp1
-rw-r--r--starts/meaning-vm/level-1/ref.cpp68
-rw-r--r--starts/meaning-vm/level-1/ref.hpp22
-rw-r--r--starts/meaning-vm/level-1/sugar.hpp13
-rw-r--r--starts/meaning-vm/level-1/vref.hpp38
10 files changed, 155 insertions, 129 deletions
diff --git a/starts/meaning-vm/level-1/baseref.hpp b/starts/meaning-vm/level-1/baseref.hpp
new file mode 100644
index 0000000..2f072b6
--- /dev/null
+++ b/starts/meaning-vm/level-1/baseref.hpp
@@ -0,0 +1,30 @@
+#pragma once
+
+#include "common.hpp"
+#include "funcs.hpp"
+
+namespace intellect {
+namespace level1 {
+
+template <typename ref>
+struct baseref : public level0::baseref<ref>
+{
+ baseref(concept * p) : level0::baseref<ref>(p) { }
+ baseref(level0::ref const & other) : baseref(other.ptr()) { }
+ baseref(std::string const & name) : baseref(getnamed(name)) { }
+ baseref(const char *name) : baseref(std::string(name)) { }
+ baseref(bool b) : baseref(b ? "true" : "false") { }
+ baseref() : baseref("nothing") { }
+
+ bool isa(ref group) const { return level1::isa(self, group); }
+ bool isan(ref group) const { return isa(group); }
+
+ std::string const & name() const { return getname(self)->data; }
+ operator std::string const &() const { return getname(self)->data; }
+ operator char const *() const { return getname(self)->data.c_str(); }
+
+ std::string dump(ref skipmarkertype, ref skipmarkertarget);
+};
+
+}
+}
diff --git a/starts/meaning-vm/level-1/common.hpp b/starts/meaning-vm/level-1/common.hpp
index 2977077..2c9297b 100644
--- a/starts/meaning-vm/level-1/common.hpp
+++ b/starts/meaning-vm/level-1/common.hpp
@@ -1,10 +1,15 @@
#pragma once
+#include "../level-0/common.hpp"
+
namespace intellect {
namespace level1 {
+using level0::concept;
+using level0::value;
+
+template <typename T> struct baseref;
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
index 4c098de..5a3dfaf 100644
--- a/starts/meaning-vm/level-1/concepts.cpp
+++ b/starts/meaning-vm/level-1/concepts.cpp
@@ -7,6 +7,7 @@ namespace concepts {
ref is("is");
ref anonymous("anonymous");
ref link("link");
+ref name("name");
}
}
diff --git a/starts/meaning-vm/level-1/funcs.cpp b/starts/meaning-vm/level-1/funcs.cpp
new file mode 100644
index 0000000..c9cca37
--- /dev/null
+++ b/starts/meaning-vm/level-1/funcs.cpp
@@ -0,0 +1,81 @@
+#include "funcs.hpp"
+
+#include "../level-0/errors.hpp"
+#include "../level-0/memorystore.hpp"
+#include "concepts.hpp"
+
+#include <unordered_map>
+
+namespace intellect {
+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<std::string,ref,std::hash<std::string>,std::equal_to<std::string>> conceptsByName;
+ ref nameref;
+ name_t()
+ : nameref(level0::alloc())
+ {
+ auto namestr = valloc<std::string>("name");
+ nameref.set(nameref, namestr);
+ conceptsByName.emplace(namestr->data, nameref);
+ }
+ } namestruct;
+ return namestruct;
+}
+
+concept* getnamed(std::string const & name)
+{
+ auto & ns = namestruct();
+ auto res = ns.conceptsByName.find(name);
+ if (res != ns.conceptsByName.end()) {
+ return res->second;
+ } else {
+ level1::ref con = level0::alloc();
+ level0::value<std::string>* namestr = level0::valloc(name);
+ ns.conceptsByName.emplace(namestr->data, con);
+ con.set(ns.nameref.r0(), namestr);
+ return con.ptr();
+ }
+}
+
+value<std::string>* getname(concept* r)
+{
+ try {
+ return r->vget<std::string>(namestruct().nameref);
+ } catch(level0::no_such_link_type&) {
+ return getname(ref("UNNAMED"));
+ }
+}
+
+bool isa(concept* member, concept* group)
+{
+ for (auto & g : member->getAll(is)) {
+ if (g == group) return true;
+ if (g == member) continue;
+ if (isa(g, group)) return true;
+ }
+ return false;
+}
+
+template <typename T>
+value<T>* valloc(T const & val)
+{
+ auto ret = level0::valloc<T>(val);
+ std::stringstream ss;
+ // << val is making recursion
+ ss << typeid(T).name() << "(" << val << ")";
+ ret->link(concepts::name, level0::valloc(ss.str()));
+ return ret;
+}
+
+template value<std::string>* valloc<std::string>(std::string const & val);
+template value<int>* valloc<int>(int const & val);
+
+}
+}
diff --git a/starts/meaning-vm/level-1/funcs.hpp b/starts/meaning-vm/level-1/funcs.hpp
new file mode 100644
index 0000000..55a28f2
--- /dev/null
+++ b/starts/meaning-vm/level-1/funcs.hpp
@@ -0,0 +1,23 @@
+#pragma once
+
+#include "common.hpp"
+
+#include "../level-0/memorystore.hpp"
+
+#include <string>
+#include <sstream>
+#include <typeinfo>
+
+namespace intellect {
+namespace level1 {
+
+concept* getnamed(std::string const & name);
+value<std::string>* getname(concept* r);
+
+bool isa(concept* member, concept* group);
+
+template <typename T>
+value<T>* valloc(T const & val);
+
+}
+}
diff --git a/starts/meaning-vm/level-1/level-1.hpp b/starts/meaning-vm/level-1/level-1.hpp
index d13ba9f..e34d86a 100644
--- a/starts/meaning-vm/level-1/level-1.hpp
+++ b/starts/meaning-vm/level-1/level-1.hpp
@@ -4,4 +4,3 @@
#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
index b593f81..8d74b50 100644
--- a/starts/meaning-vm/level-1/ref.cpp
+++ b/starts/meaning-vm/level-1/ref.cpp
@@ -1,72 +1,12 @@
#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)
-: baseref(getnamed(name).ptr())
-{ }
-
-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)) {
@@ -74,11 +14,11 @@ std::string ref::dump(ref skipmarkertype, ref skipmarkertarget)
}
std::string ret;
for (auto & link : links()) {
- if (link.first == namestruct().nameref) { continue; }
+ if (link.first == concepts::name) { continue; }
if (ret.size() == 0) {
- ret = name().val() + ":\n";
+ ret = name() + ":\n";
}
- ret += " " + link.first.name().val() + ": " + link.second.name().val() + "\n";
+ ret += " " + link.first.name() + ": " + link.second.name() + "\n";
}
link(skipmarkertype, skipmarkertarget);
for (auto & link : links()) {
diff --git a/starts/meaning-vm/level-1/ref.hpp b/starts/meaning-vm/level-1/ref.hpp
index 8a7394e..3f2214d 100644
--- a/starts/meaning-vm/level-1/ref.hpp
+++ b/starts/meaning-vm/level-1/ref.hpp
@@ -1,30 +1,14 @@
#pragma once
#include "common.hpp"
-#include "../level-0/baseref.hpp"
-#include "../level-0/ref.hpp"
+#include "baseref.hpp"
namespace intellect {
namespace level1 {
-struct ref : public level0::baseref<ref,vref,level0::concept>
+struct ref : public baseref<ref>
{
- using level0::baseref<ref,vref,level0::concept>::baseref;
- ref(level0::concept * p) : baseref(p) { }
- ref(level0::ref const & other) : baseref(other.ptr()) { }
- 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 *reinterpret_cast<level0::ref*>(this); }
- ref & l1() { return self; }
- ref const & l1() const { return self; }
+ using baseref<ref>::baseref;
std::string dump(ref skipmarkertype, ref skipmarkertarget);
};
diff --git a/starts/meaning-vm/level-1/sugar.hpp b/starts/meaning-vm/level-1/sugar.hpp
index 9d439e5..c34f013 100644
--- a/starts/meaning-vm/level-1/sugar.hpp
+++ b/starts/meaning-vm/level-1/sugar.hpp
@@ -2,7 +2,6 @@
#include "common.hpp"
#include "ref.hpp"
-#include "vref.hpp"
#include <string>
#include <sstream>
@@ -10,10 +9,17 @@
namespace intellect {
namespace level1 {
+ref a(ref group);
+ref an(ref group);
+ref a(ref group, ref name);
+ref an(ref group, ref name);
+
+/*
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>
@@ -38,10 +44,5 @@ namespace internal {
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
deleted file mode 100644
index fb7ba5d..0000000
--- a/starts/meaning-vm/level-1/vref.hpp
+++ /dev/null
@@ -1,38 +0,0 @@
-#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); }
-};
-
-
-}
-}