summaryrefslogtreecommitdiff
path: root/starts
diff options
context:
space:
mode:
Diffstat (limited to 'starts')
-rw-r--r--starts/meaning-vm/DESIGN.txt13
-rw-r--r--starts/meaning-vm/level-0/baseref.hpp6
-rw-r--r--starts/meaning-vm/level-0/common.hpp2
-rw-r--r--starts/meaning-vm/level-0/concept.hpp8
-rw-r--r--starts/meaning-vm/level-0/level-0.hpp1
-rw-r--r--starts/meaning-vm/level-0/memorystore.cpp5
-rw-r--r--starts/meaning-vm/level-0/memorystore.hpp7
-rw-r--r--starts/meaning-vm/level-0/value.hpp25
-rw-r--r--starts/meaning-vm/level-1/baseref.hpp4
-rw-r--r--starts/meaning-vm/level-1/common.hpp1
-rw-r--r--starts/meaning-vm/level-1/funcs.cpp37
-rw-r--r--starts/meaning-vm/level-1/funcs.hpp5
-rw-r--r--starts/meaning-vm/makefile4
13 files changed, 53 insertions, 65 deletions
diff --git a/starts/meaning-vm/DESIGN.txt b/starts/meaning-vm/DESIGN.txt
index 80e446f..295a7f2 100644
--- a/starts/meaning-vm/DESIGN.txt
+++ b/starts/meaning-vm/DESIGN.txt
@@ -32,6 +32,15 @@ Level-1 introduce the concept of groups, using the "is" link, and uses it to cat
concepts that have an autogenerated name in the "anonymous" group.
# LEVEL 2
-Level 2 will introdue syntax sugar for quickly instantiating conceptual relationships
-using operators. This is handled by creating syntax expression concepts.
+Whatever gets implemented next. Maybe expression operators, maybe structure promises,
+maybe infrastructure for moving implementation onto ref code objects.
+# FUTURE
+## Relevence pattern matching
+ This is important and core.
+ This appears similar to graph structure matching, except that code creatively relevent to
+ the parts of the structure must be continually run so as to generate new information,
+ new structural parts.
+ At its simplest, this solves (A is not a dog), (A is a cat), (cats are never dogs),
+ with logical habits relevent to 'not', 'never', 'is', using one single matching interface,
+ but with more relevence could do more.
diff --git a/starts/meaning-vm/level-0/baseref.hpp b/starts/meaning-vm/level-0/baseref.hpp
index 849e205..205b422 100644
--- a/starts/meaning-vm/level-0/baseref.hpp
+++ b/starts/meaning-vm/level-0/baseref.hpp
@@ -49,12 +49,12 @@ public:
}
template <typename T>
- T& vget(ref const & type) const { return p->vget<T>(type.p)->data; }
+ T& vget(ref const & type) const { return p->vget<T>(type.p); }
template <typename T>
- void vset(ref const & type, T const & v) { p->set(type.p, valloc<T>(v)); }
+ void vset(ref const & type, T const & v) { p->set(type.p, alloc(v)); }
template <typename T>
- T& val() { return p->val<T>()->data; }
+ T& val() { return p->val<T>(); }
operator concept*() const { return p; }
concept*& ptr() { return p; }
diff --git a/starts/meaning-vm/level-0/common.hpp b/starts/meaning-vm/level-0/common.hpp
index 74031cc..6e86907 100644
--- a/starts/meaning-vm/level-0/common.hpp
+++ b/starts/meaning-vm/level-0/common.hpp
@@ -7,8 +7,6 @@ namespace level0 {
struct concept;
struct ref;
-template <typename T> struct value;
-template <typename T> struct vref;
}
namespace level1 { struct ref; template <typename> struct vref; }
diff --git a/starts/meaning-vm/level-0/concept.hpp b/starts/meaning-vm/level-0/concept.hpp
index 3bd1609..d57ccfc 100644
--- a/starts/meaning-vm/level-0/concept.hpp
+++ b/starts/meaning-vm/level-0/concept.hpp
@@ -2,6 +2,7 @@
#include "common.hpp"
+#include <any>
#include <map>
#include <vector>
@@ -12,6 +13,9 @@ struct concept
{
// a concept is made of concept-typed links to other concepts
std::multimap<concept*,concept*> links;
+ // and optional associated arbitrary data
+ std::any data;
+
using array = std::vector<concept*>;
concept* id();
@@ -30,10 +34,10 @@ struct concept
void set(concept* type, concept* target);
template <typename T>
- value<T>* vget(concept* type) const { return static_cast<value<T>*>(get(type)); }
+ T & vget(concept* type) const { return get(type)->val<T>(); }
template <typename T>
- value<T>* val() { return this; }
+ T & val() { return std::any_cast<T&>(data); }
};
}
diff --git a/starts/meaning-vm/level-0/level-0.hpp b/starts/meaning-vm/level-0/level-0.hpp
index 7062be0..56cd7dd 100644
--- a/starts/meaning-vm/level-0/level-0.hpp
+++ b/starts/meaning-vm/level-0/level-0.hpp
@@ -5,4 +5,3 @@
#include "errors.hpp"
#include "memorystore.hpp"
#include "ref.hpp"
-#include "value.hpp"
diff --git a/starts/meaning-vm/level-0/memorystore.cpp b/starts/meaning-vm/level-0/memorystore.cpp
index b092ca0..adae8b2 100644
--- a/starts/meaning-vm/level-0/memorystore.cpp
+++ b/starts/meaning-vm/level-0/memorystore.cpp
@@ -14,8 +14,9 @@ static auto & concepts()
return concepts;
}
-ref alloc(concept * moved) {
- ref r = moved ? moved : new concept();
+ref alloc(std::any data) {
+ concept * r = new concept();
+ r->data = data;
concepts().insert(r);
return r;
}
diff --git a/starts/meaning-vm/level-0/memorystore.hpp b/starts/meaning-vm/level-0/memorystore.hpp
index fd752a0..7843513 100644
--- a/starts/meaning-vm/level-0/memorystore.hpp
+++ b/starts/meaning-vm/level-0/memorystore.hpp
@@ -1,14 +1,13 @@
#pragma once
#include "common.hpp"
-#include "value.hpp"
+
+#include <any>
namespace intellect {
namespace level0 {
-ref alloc(concept * moved = 0);
-template <typename T>
-value<T> * valloc(T const & v) { return static_cast<value<T>*>(alloc(new value<T>(v)).ptr()); }
+ref alloc(std::any data = {});
void dealloc(ref);
std::size_t allocated();
diff --git a/starts/meaning-vm/level-0/value.hpp b/starts/meaning-vm/level-0/value.hpp
deleted file mode 100644
index ff704bf..0000000
--- a/starts/meaning-vm/level-0/value.hpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#pragma once
-
-#include "common.hpp"
-
-#include "concept.hpp"
-
-namespace intellect {
-namespace level0 {
-
-template <typename T>
-struct value : public concept
-{
- value(T const & val) : data(val) { }
-
- value(value<T> const & val) = default;
-
- operator T&() { return data; }
- operator T const &() const { return data; }
-
- T data;
-};
-
-
-}
-}
diff --git a/starts/meaning-vm/level-1/baseref.hpp b/starts/meaning-vm/level-1/baseref.hpp
index 8c358cc..e8bdcb9 100644
--- a/starts/meaning-vm/level-1/baseref.hpp
+++ b/starts/meaning-vm/level-1/baseref.hpp
@@ -21,8 +21,8 @@ struct baseref : public level0::baseref<ref>
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; }
+ std::string const & name() const { return getname(self); }
+ operator std::string const &() const { return getname(self); }
operator char const *() const { return getname(self)->data.c_str(); }
ref operator-(ref other) { return hyphenate(self.ptr(), other.ptr()); }
diff --git a/starts/meaning-vm/level-1/common.hpp b/starts/meaning-vm/level-1/common.hpp
index 2c9297b..73de3b4 100644
--- a/starts/meaning-vm/level-1/common.hpp
+++ b/starts/meaning-vm/level-1/common.hpp
@@ -6,7 +6,6 @@ namespace intellect {
namespace level1 {
using level0::concept;
-using level0::value;
template <typename T> struct baseref;
struct ref;
diff --git a/starts/meaning-vm/level-1/funcs.cpp b/starts/meaning-vm/level-1/funcs.cpp
index 3d0d88d..07f0eba 100644
--- a/starts/meaning-vm/level-1/funcs.cpp
+++ b/starts/meaning-vm/level-1/funcs.cpp
@@ -21,9 +21,9 @@ static auto & namestruct()
name_t()
: nameref(level0::alloc())
{
- auto namestr = valloc<std::string>("name");
+ level0::ref namestr = alloc((std::string)("name"));
nameref.set(nameref, namestr);
- conceptsByName.emplace(namestr->data, nameref);
+ conceptsByName.emplace(namestr.val<std::string>(), nameref);
}
} namestruct;
return namestruct;
@@ -37,14 +37,14 @@ concept* getnamed(std::string const & name)
return res->second;
} else {
level1::ref con = level0::alloc();
- level0::value<std::string>* namestr = level0::valloc(name);
- ns.conceptsByName.emplace(namestr->data, con);
+ level0::ref namestr = level0::alloc(name);
+ ns.conceptsByName.emplace(namestr.val<std::string>(), con);
con.set(ns.nameref, namestr);
return con.ptr();
}
}
-value<std::string>* getname(concept* r)
+std::string& getname(concept* r)
{
try {
return r->vget<std::string>(namestruct().nameref);
@@ -63,24 +63,31 @@ bool isa(concept* member, concept* group)
return false;
}
-template <typename T>
-value<T>* valloc(T const & val)
+concept* alloc(std::any val)
{
- auto ret = level0::valloc<T>(val);
+
+ ref ret = level0::alloc(val);
std::stringstream ss;
- // << val is making recursion
- ss << typeid(T).name() << "(" << val << ")";
- ret->link(concepts::name, level0::valloc(ss.str()));
+ ss << val.type().name() << "(";
+ if (false);
+#define t(T) \
+ else if (val.type() == typeid(T)) { \
+ ss << ret.val<T>(); \
+ }
+ t(uint8_t) t(int8_t) t(uint16_t) t(int16_t)
+ t(uint32_t) t(int32_t) t(uint64_t) t(int64_t)
+ t(bool) t(float) t(double) t(std::string) t(char const *)
+#undef t
+ else { ss << "?"; }
+ ss << ")";
+ ret.link(concepts::name, level0::alloc(ss.str()));
return ret;
}
concept* hyphenate(concept* a, concept* b)
{
- return getnamed(getname(a)->data + "-" + getname(b)->data);
+ return getnamed(getname(a) + "-" + getname(b));
}
-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
index eab37e5..741a5af 100644
--- a/starts/meaning-vm/level-1/funcs.hpp
+++ b/starts/meaning-vm/level-1/funcs.hpp
@@ -12,14 +12,13 @@ namespace intellect {
namespace level1 {
concept* getnamed(std::string const & name);
-value<std::string>* getname(concept* r);
+std::string& getname(concept* r);
bool isa(concept* member, concept* group);
concept* hyphenate(concept* a, concept* b);
-template <typename T>
-value<T>* valloc(T const & val);
+concept* alloc(std::any val);
}
}
diff --git a/starts/meaning-vm/makefile b/starts/meaning-vm/makefile
index f1b4b12..920987a 100644
--- a/starts/meaning-vm/makefile
+++ b/starts/meaning-vm/makefile
@@ -11,7 +11,5 @@ liblevel%.a: level-%/*.hpp
ar ru $@ $^
ranlib $@
-#main: main.o concept.o helpers.o memorystore.o meaning.o
-#*.o: *.hpp */*.hpp
clean:
- -rm *.o main level0 level1 level2 *.a */*.o
+ -rm *.o level? *.a */*.o