summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/level-1
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2019-12-12 07:38:19 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-12-12 07:38:19 -0800
commitdf58c6cd5c26120a985cca74243fc7978457ff2e (patch)
tree0a61ca17a83dc3484c9a2b1c69c83b64849d958f /starts/meaning-vm/level-1
parent931c924ed0b23fea8179644e5f7f1da866c7c07e (diff)
downloadstandingwithresilience-df58c6cd5c26120a985cca74243fc7978457ff2e.tar.gz
standingwithresilience-df58c6cd5c26120a985cca74243fc7978457ff2e.zip
tried to use allocations with level1 ... messy, works, for some reason name of function is output in dump, shows internal problem
Diffstat (limited to 'starts/meaning-vm/level-1')
-rw-r--r--starts/meaning-vm/level-1/baseref.hpp7
-rw-r--r--starts/meaning-vm/level-1/concepts.cpp26
-rw-r--r--starts/meaning-vm/level-1/concepts.hpp4
-rw-r--r--starts/meaning-vm/level-1/funcs.cpp106
-rw-r--r--starts/meaning-vm/level-1/funcs.hpp5
-rw-r--r--starts/meaning-vm/level-1/sugar.cpp6
6 files changed, 104 insertions, 50 deletions
diff --git a/starts/meaning-vm/level-1/baseref.hpp b/starts/meaning-vm/level-1/baseref.hpp
index 5055d44..59550dd 100644
--- a/starts/meaning-vm/level-1/baseref.hpp
+++ b/starts/meaning-vm/level-1/baseref.hpp
@@ -15,16 +15,15 @@ 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(std::string const & name, concept* allocator = nullptr) : baseref(getnamed(name, allocator)) { }
+ baseref(const char *name, concept* allocator = nullptr) : baseref(std::string(name), allocator) { }
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); }
- operator std::string const &() const { return getname(self); }
+ std::string name() const { return getname(self); }
explicit operator char const *() const { return getname(self)->data.c_str(); }
ref operator-(ref other) const { return hyphenate(self, other); }
diff --git a/starts/meaning-vm/level-1/concepts.cpp b/starts/meaning-vm/level-1/concepts.cpp
index 890d8b2..be643a9 100644
--- a/starts/meaning-vm/level-1/concepts.cpp
+++ b/starts/meaning-vm/level-1/concepts.cpp
@@ -1,15 +1,29 @@
#include "concepts.hpp"
+#include "funcs.hpp"
+#include "../level-0/memorystore.hpp"
+
namespace intellect {
namespace level1 {
namespace concepts {
-ref nothing("nothing");
-ref is("is");
-ref anonymous("anonymous");
-ref link("link");
-ref name("name");
-ref allocation("allocation"), part("part"), group("group");
+static struct init { init() {
+ givename(intellect::level0::concepts::allocator(), "allocator");
+ givename(intellect::level0::concepts::allocates(), "allocates");
+ givename(intellect::level0::concepts::allocations(), "allocations");
+ givename(intellect::level0::concepts::level0allocations(), "level0-allocations");
+} } __init;
+
+ref level1("level1"), allocations("allocations");
+ref is("is", level1-allocations);
+ref name("name", level1-allocations);
+ref nothing("nothing", level1-allocations);
+ref anonymous("anonymous", level1-allocations);
+ref link("link", level1-allocations);
+ref level0("level0", level1-allocations) , level2("level2", level1-allocations) , level3("level3", level1-allocations) , level4("level4", level1-allocations) , level5("level5", level1-allocations) , level6("level6", level1-allocations) , level7("level7", level1-allocations) , level8("level8", level1-allocations) , level9("level9", level1-allocations);
+ref allocator("allocator"), allocates("allocates");
+
+ref _false("false", level1-allocations), _true("true", level1-allocations);
}
}
diff --git a/starts/meaning-vm/level-1/concepts.hpp b/starts/meaning-vm/level-1/concepts.hpp
index b75133e..cd92f26 100644
--- a/starts/meaning-vm/level-1/concepts.hpp
+++ b/starts/meaning-vm/level-1/concepts.hpp
@@ -12,7 +12,9 @@ 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 allocation, part, group; // links structuring allocation groups
+extern ref level0, level1, level2, level3, level4, level5, level6, level7, level8, level9, level10;
+extern ref allocator, allocates, allocations;
+
//extern ref true, false; <-- casting provides as if these were declared
}
diff --git a/starts/meaning-vm/level-1/funcs.cpp b/starts/meaning-vm/level-1/funcs.cpp
index cfb44b7..1e6bd9d 100644
--- a/starts/meaning-vm/level-1/funcs.cpp
+++ b/starts/meaning-vm/level-1/funcs.cpp
@@ -17,13 +17,26 @@ 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;
+ ref level1allocationsref, nameref, isref;
+ ref level1ref;
name_t()
- : nameref(level0::alloc(level0::concepts::allocations()))
+ : level1allocationsref(level0::basic_alloc()),
+ nameref(level0::alloc(level1allocationsref)),
+ isref(level0::alloc(level1allocationsref)),
+ level1ref(level0::alloc(level1allocationsref))
{
- level0::ref namestr = level0::alloc(nameref.ptr(), (std::string)("name"));
- nameref.set(nameref, namestr);
- conceptsByName.emplace(namestr.val<std::string>(), nameref);
+ give(level1allocationsref, "level1-allocations");
+ give(nameref, "name");
+ give(isref, "is");
+ give(level1ref, "level1");
+ }
+ void give(concept* con, std::string const & name)
+ {
+ if (conceptsByName.count(name)) { throw std::logic_error(name + " already uniquely specified"); }
+ level0::ref namestr = level0::alloc(con, name);
+ namestr.link(isref, nameref);
+ conceptsByName.emplace(namestr.val<std::string>(), con);
+ con->set(nameref, namestr);
}
} namestruct;
return namestruct;
@@ -32,30 +45,64 @@ static auto & namestruct()
void givename(concept* con, std::string const & name)
{
auto & ns = namestruct();
- level0::ref namestr = level0::alloc(con, name);
- ns.conceptsByName.emplace(namestr.val<std::string>(), con);
- con->set(ns.nameref, namestr);
+ ns.give(con, name);
}
-concept* getnamed(std::string const & name)
+concept* getnamed(std::string const & name, concept* allocator)
{
auto & ns = namestruct();
auto res = ns.conceptsByName.find(name);
if (res != ns.conceptsByName.end()) {
return res->second;
} else {
- level1::ref con = level0::alloc(level0::concepts::allocations());
+ if (allocator == nullptr) { allocator = level0::concepts::allocations(); }
+ level1::ref con = level0::alloc(allocator);
givename(con, name);
return con.ptr();
}
}
-std::string& getname(concept* r)
+std::string nameforany(concept* c)
+{
+ using namespace std;
+ stringstream ss;
+ static int fn_counter = 0;
+ if (false);
+#define t(T) \
+ else if (c->data.type() == typeid(T)) { \
+ ss << #T "(" << std::any_cast<T>(c->data) << ")"; \
+ }
+ 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(string) t(char const *)
+#undef t
+#define t(T) \
+ else if (c->data.type() == typeid(T)) { \
+ ss << #T "(" << (fn_counter++) << ")"; \
+ }
+ t(function<void(void)>)
+ t(function<level0::ref(level0::ref)>)
+ t(function<level1::ref(level1::ref)>)
+ t(function<level2::ref(level2::ref)>)
+ t(function<level3::ref(level3::ref)>)
+ t(function<level4::ref(level4::ref)>)
+ t(function<level5::ref(level5::ref)>)
+ t(function<level6::ref(level6::ref)>)
+ t(function<level7::ref(level7::ref)>)
+ t(function<level8::ref(level8::ref)>)
+ t(function<level9::ref(level9::ref)>)
+#undef t
+ else { ss << "?"; }
+ return ss.str();
+}
+
+std::string getname(concept* r)
{
try {
return r->vget<std::string>(namestruct().nameref);
} catch(level0::no_such_link_type&) {
- return getname(ref("UNNAMED"));
+ if (r->data.has_value()) { return nameforany(r); }
+ return "UNNAMED";
}
}
@@ -72,20 +119,9 @@ bool isa(concept* member, concept* group)
concept* alloc(concept* allocator, std::any val)
{
ref ret = level0::alloc(allocator, val);
- std::stringstream ss;
- 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(ret, ss.str()));
+ ref namestr = level0::alloc(ret, nameforany(ret));
+ namestr.link(concepts::is, concepts::name);
+ ret.link(concepts::name, level0::alloc(ret, nameforany(ret)));
return ret;
}
@@ -96,27 +132,29 @@ concept* hyphenate(concept* a, concept* b)
std::string dump(concept* what, concept* skipmarkertype, concept* skipmarkertarget)
{
+ std::stringstream ss;
if (what->linked(skipmarkertype, skipmarkertarget)) {
return {};
}
- std::string ret;
for (auto & link : ref(what).links()) {
if (link.first.linked(level0::concepts::allocator(), level0::concepts::level0allocations())) { continue; }
- if (link.first == concepts::name) { continue; }
- if (ret.size() == 0) {
- ret = ref(what).name() + ":\n";
+ if (link.second.isa(concepts::name)) { continue; }
+ if (ss.str().size() == 0) {
+ ss << ref(what).name() << " " << (void*) what << ":\n";
}
- ret += " " + link.first.name() + ": " + link.second.name() + "\n";
+ ss << " " << link.first.name() << ": " << link.second.name() << "\n";
}
what->link(skipmarkertype, skipmarkertarget);
for (auto & link : ref(what).links()) {
- if (link.first.linked(level0::concepts::allocator(), level0::concepts::level0allocations())) { continue; }
+ if (link.first.linked(allocator, level0-allocations)) { continue; }
+ if (link.second.linked(allocator, level1-allocations)) { continue; }
if (link.first.ptr() == skipmarkertype && link.second.ptr() == skipmarkertarget) {
continue;
}
- ret += dump(link.second, skipmarkertype, skipmarkertarget);
+ if (link.second.isa(concepts::name)) { continue; }
+ ss << dump(link.second, skipmarkertype, skipmarkertarget);
}
- return ret;
+ return ss.str();
}
}
diff --git a/starts/meaning-vm/level-1/funcs.hpp b/starts/meaning-vm/level-1/funcs.hpp
index 9361917..d70a868 100644
--- a/starts/meaning-vm/level-1/funcs.hpp
+++ b/starts/meaning-vm/level-1/funcs.hpp
@@ -11,8 +11,9 @@
namespace intellect {
namespace level1 {
-concept* getnamed(std::string const & name);
-std::string& getname(concept* r);
+concept* getnamed(std::string const & name, concept* allocator = nullptr);
+std::string getname(concept* r);
+void givename(concept* con, std::string const & name);
bool isa(concept* member, concept* group);
diff --git a/starts/meaning-vm/level-1/sugar.cpp b/starts/meaning-vm/level-1/sugar.cpp
index 21f4001..accad6c 100644
--- a/starts/meaning-vm/level-1/sugar.cpp
+++ b/starts/meaning-vm/level-1/sugar.cpp
@@ -50,16 +50,16 @@ ref movetoname(ref anonymous, ref name)
bool nonempty = false;
for (auto & l : name.links()) {
if (l.first.linked(level0::concepts::allocator(), level0::concepts::level0allocations())) { continue; }
- if (l.first == concepts::name) { continue; }
+ if (l.second.isa(concepts::name)) { continue; }
nonempty = true;
}
if (nonempty) {
for (auto & link : anonymous.links()) {
if (link.first == concepts::is && link.second == concepts::anonymous) { continue; }
if (link.first.linked(level0::concepts::allocator(), level0::concepts::level0allocations())) { continue; }
- if (link.first == concepts::name) { continue; }
+ if (link.second.isa(concepts::name)) { continue; }
if (!name.linked(link.first, link.second)) {
- throw std::logic_error(name.name() + " already defined otherwise from " + anonymous.getAll(concepts::is).begin()->name());
+ throw std::logic_error(name.name() + " already defined otherwise from " + anonymous.getAll(concepts::is).begin()->name());// + ": \n" + dump(name, ref("dump"), ref(true)) + dump(anonymous, ref("dump"), ref(true)));
}
}
}