diff options
Diffstat (limited to 'starts/meaning-vm/level-1')
-rw-r--r-- | starts/meaning-vm/level-1/baseref.hpp | 2 | ||||
-rw-r--r-- | starts/meaning-vm/level-1/concepts.cpp | 1 | ||||
-rw-r--r-- | starts/meaning-vm/level-1/concepts.hpp | 1 | ||||
-rw-r--r-- | starts/meaning-vm/level-1/funcs.cpp | 27 | ||||
-rw-r--r-- | starts/meaning-vm/level-1/funcs.hpp | 2 | ||||
-rw-r--r-- | starts/meaning-vm/level-1/sugar.cpp | 9 |
6 files changed, 27 insertions, 15 deletions
diff --git a/starts/meaning-vm/level-1/baseref.hpp b/starts/meaning-vm/level-1/baseref.hpp index e97db2d..5055d44 100644 --- a/starts/meaning-vm/level-1/baseref.hpp +++ b/starts/meaning-vm/level-1/baseref.hpp @@ -31,7 +31,7 @@ struct baseref : public level0::baseref<ref> ref operator[](ref subref) const { return self.get(subref); } template <typename T> - void vset(ref const & type, T const & v) { self.set(type, level1::alloc(v)); } + void vset(ref const & type, T const & v) { self.set(type, level1::alloc(level0::concepts::allocations(), v)); } template <typename... Ref> std::function<ref(Ref...)> & fun() { return self.template val<std::function<ref(Ref...)>>(); } diff --git a/starts/meaning-vm/level-1/concepts.cpp b/starts/meaning-vm/level-1/concepts.cpp index 51cd693..890d8b2 100644 --- a/starts/meaning-vm/level-1/concepts.cpp +++ b/starts/meaning-vm/level-1/concepts.cpp @@ -9,6 +9,7 @@ ref is("is"); ref anonymous("anonymous"); ref link("link"); ref name("name"); +ref allocation("allocation"), part("part"), group("group"); } } diff --git a/starts/meaning-vm/level-1/concepts.hpp b/starts/meaning-vm/level-1/concepts.hpp index 6dfc64b..b75133e 100644 --- a/starts/meaning-vm/level-1/concepts.hpp +++ b/starts/meaning-vm/level-1/concepts.hpp @@ -12,6 +12,7 @@ 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 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 72d3c27..cfb44b7 100644 --- a/starts/meaning-vm/level-1/funcs.cpp +++ b/starts/meaning-vm/level-1/funcs.cpp @@ -19,9 +19,9 @@ static auto & namestruct() std::unordered_map<std::string,ref,std::hash<std::string>,std::equal_to<std::string>> conceptsByName; ref nameref; name_t() - : nameref(level0::alloc()) + : nameref(level0::alloc(level0::concepts::allocations())) { - level0::ref namestr = alloc((std::string)("name")); + level0::ref namestr = level0::alloc(nameref.ptr(), (std::string)("name")); nameref.set(nameref, namestr); conceptsByName.emplace(namestr.val<std::string>(), nameref); } @@ -29,6 +29,14 @@ static auto & namestruct() return 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); +} + concept* getnamed(std::string const & name) { auto & ns = namestruct(); @@ -36,10 +44,8 @@ concept* getnamed(std::string const & name) if (res != ns.conceptsByName.end()) { return res->second; } else { - level1::ref con = level0::alloc(); - level0::ref namestr = level0::alloc(name); - ns.conceptsByName.emplace(namestr.val<std::string>(), con); - con.set(ns.nameref, namestr); + level1::ref con = level0::alloc(level0::concepts::allocations()); + givename(con, name); return con.ptr(); } } @@ -63,10 +69,9 @@ bool isa(concept* member, concept* group) return false; } -concept* alloc(std::any val) +concept* alloc(concept* allocator, std::any val) { - - ref ret = level0::alloc(val); + ref ret = level0::alloc(allocator, val); std::stringstream ss; ss << val.type().name() << "("; if (false); @@ -80,7 +85,7 @@ concept* alloc(std::any val) #undef t else { ss << "?"; } ss << ")"; - ret.link(concepts::name, level0::alloc(ss.str())); + ret.link(concepts::name, level0::alloc(ret, ss.str())); return ret; } @@ -96,6 +101,7 @@ std::string dump(concept* what, concept* skipmarkertype, concept* skipmarkertarg } 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"; @@ -104,6 +110,7 @@ std::string dump(concept* what, concept* skipmarkertype, concept* skipmarkertarg } what->link(skipmarkertype, skipmarkertarget); for (auto & link : ref(what).links()) { + if (link.first.linked(level0::concepts::allocator(), level0::concepts::level0allocations())) { continue; } if (link.first.ptr() == skipmarkertype && link.second.ptr() == skipmarkertarget) { continue; } diff --git a/starts/meaning-vm/level-1/funcs.hpp b/starts/meaning-vm/level-1/funcs.hpp index 4b53ddd..9361917 100644 --- a/starts/meaning-vm/level-1/funcs.hpp +++ b/starts/meaning-vm/level-1/funcs.hpp @@ -18,7 +18,7 @@ bool isa(concept* member, concept* group); concept* hyphenate(concept* a, concept* b); -concept* alloc(std::any val); +concept* alloc(concept* allocator, std::any val); std::string dump(concept * what, concept * skipmarkertype, concept * skipmarkertarget); diff --git a/starts/meaning-vm/level-1/sugar.cpp b/starts/meaning-vm/level-1/sugar.cpp index 24d59be..21f4001 100644 --- a/starts/meaning-vm/level-1/sugar.cpp +++ b/starts/meaning-vm/level-1/sugar.cpp @@ -49,15 +49,17 @@ ref movetoname(ref anonymous, ref name) // information is not available at this level. 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; } 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 (!name.linked(link.first, link.second)) { - throw std::logic_error(name.name() + " already defined otherwise from " + anonymous.get(concepts::is).name()); + throw std::logic_error(name.name() + " already defined otherwise from " + anonymous.getAll(concepts::is).begin()->name()); } } } @@ -66,12 +68,13 @@ ref movetoname(ref anonymous, ref name) anonymous.unlink(concepts::name, nam); if (!nonempty) { for (auto & l : anonymous.links()) { + if (l.first.linked(level0::concepts::allocator(), level0::concepts::level0allocations())) { continue; } name.link(l.first, l.second); } } anonymous.link(concepts::name, nam); - dealloc(anonymous); - dealloc(nam); + dealloc(anonymous, level0::concepts::allocations()); + //dealloc(nam, level0::concepts::allocations()); return name; } |