diff options
author | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-12-09 20:38:22 -0800 |
---|---|---|
committer | olpc user <olpc@xo-5d-f7-86.localdomain> | 2019-12-09 20:38:22 -0800 |
commit | 1b8c47a8b14f784f6605eee3a73713dbce6ca572 (patch) | |
tree | 9b7034b5e148ee8b0f9fbe0c6e89d7f9a656a27e /starts/meaning-vm/level-1 | |
parent | 3e3aeddec840fed915b0fa748dcd2f56d6f682ef (diff) | |
download | standingwithresilience-1b8c47a8b14f784f6605eee3a73713dbce6ca572.tar.gz standingwithresilience-1b8c47a8b14f784f6605eee3a73713dbce6ca572.zip |
changed level-0 allocation to use groups
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/funcs.cpp | 23 | ||||
-rw-r--r-- | starts/meaning-vm/level-1/funcs.hpp | 2 | ||||
-rw-r--r-- | starts/meaning-vm/level-1/memorystore.cpp | 33 | ||||
-rw-r--r-- | starts/meaning-vm/level-1/memorystore.hpp | 14 | ||||
-rw-r--r-- | starts/meaning-vm/level-1/sugar.cpp | 9 |
6 files changed, 19 insertions, 64 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/funcs.cpp b/starts/meaning-vm/level-1/funcs.cpp index c1cf21a..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); } @@ -32,9 +32,9 @@ static auto & namestruct() void givename(concept* con, std::string const & name) { auto & ns = namestruct(); - level0::ref namestr = level0::alloc(name); + level0::ref namestr = level0::alloc(con, name); ns.conceptsByName.emplace(namestr.val<std::string>(), con); - con.set(ns.nameref, namestr); + con->set(ns.nameref, namestr); } concept* getnamed(std::string const & name) @@ -44,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(); } } @@ -71,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); @@ -88,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; } @@ -104,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"; @@ -112,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/memorystore.cpp b/starts/meaning-vm/level-1/memorystore.cpp deleted file mode 100644 index 0bd109b..0000000 --- a/starts/meaning-vm/level-1/memorystore.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "memorystore.hpp" - -#include "concepts.hpp" - -#include "../level-0/memorystore.hpp" - -namespace intellect { -namespace level1 { - -ref allocation_group("allocation-group"); -ref allocation_part("allocation-part"); - -ref alloc(ref grp, std::any data) -{ - ref res = level0::alloc(data); - keep(res, grp); -} - -void keep(ref allocated, ref grp) -{ - allocated.link(allocation_group, grp); - grp.link(allocation_part, allocated); -} - -void dealloc(ref grp, ref metagroup) -{ - -//} - -std::size_t allocatedgroups(); - -} -} diff --git a/starts/meaning-vm/level-1/memorystore.hpp b/starts/meaning-vm/level-1/memorystore.hpp deleted file mode 100644 index 625dad9..0000000 --- a/starts/meaning-vm/level-1/memorystore.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "common.hpp" - -namespace intellect { -namespace level1 { - -ref alloc(ref group, std::any data = {}); -void keep(ref allocated, ref group); -void dealloc(ref group, ref metagroup = concepts::nothing); -std::size_t allocatedgroups(); - -} -} 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; } |