From 1c0b4c8ea8e32dddef0da99bbac546952bb20e44 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 26 Dec 2019 13:31:23 -0800 Subject: wip --- starts/meaning-vm/level-0/baseref.hpp | 2 +- starts/meaning-vm/level-0/concept.cpp | 2 +- starts/meaning-vm/level-0/concept.hpp | 2 +- starts/meaning-vm/level-0/memorystore.cpp | 1 + starts/meaning-vm/level-0/ref.cpp | 11 +++++++---- starts/meaning-vm/level-2/funcs.cpp | 1 + starts/meaning-vm/level-2/habits.cpp | 6 +++--- starts/meaning-vm/level0.cpp | 29 +++++++++++++++++++++++++++-- starts/meaning-vm/makefile | 2 +- 9 files changed, 43 insertions(+), 13 deletions(-) (limited to 'starts') diff --git a/starts/meaning-vm/level-0/baseref.hpp b/starts/meaning-vm/level-0/baseref.hpp index b6e98e8..90c33e1 100644 --- a/starts/meaning-vm/level-0/baseref.hpp +++ b/starts/meaning-vm/level-0/baseref.hpp @@ -149,7 +149,7 @@ public: decltype(concept::links) & links; }; - void unlink(typename links_t::iterator & it) { p->unlink(it.underlying()); } + void unlink(typename links_t::iterator it) { p->unlink(it.underlying()); } bool crucial(typename links_t::iterator it) { return self.p->crucial(it.underlying()); } void setcrucial(typename links_t::iterator it) { self.p->setcrucial(it.underlying()); } }; diff --git a/starts/meaning-vm/level-0/concept.cpp b/starts/meaning-vm/level-0/concept.cpp index 373b3b7..66e5af1 100644 --- a/starts/meaning-vm/level-0/concept.cpp +++ b/starts/meaning-vm/level-0/concept.cpp @@ -75,7 +75,7 @@ void concept::unlink(concept* type) unlink(ls.first); } -void concept::unlink(decltype(links)::iterator & it) +void concept::unlink(decltype(links)::iterator it) { if (crucialparts.count(it)) { throw crucial_link_type_target(selfref, it->first, it->second); diff --git a/starts/meaning-vm/level-0/concept.hpp b/starts/meaning-vm/level-0/concept.hpp index e885ccf..833e417 100644 --- a/starts/meaning-vm/level-0/concept.hpp +++ b/starts/meaning-vm/level-0/concept.hpp @@ -24,7 +24,7 @@ struct concept void link(concept* type, concept* target); void unlink(concept* type, concept* target); void unlink(concept* type); - void unlink(decltype(links)::iterator & it); + void unlink(decltype(links)::iterator it); bool crucial() { return iscrucial || crucialparts.size(); } bool crucial(concept* type, concept* target); diff --git a/starts/meaning-vm/level-0/memorystore.cpp b/starts/meaning-vm/level-0/memorystore.cpp index 1d9e9f6..24e91b0 100644 --- a/starts/meaning-vm/level-0/memorystore.cpp +++ b/starts/meaning-vm/level-0/memorystore.cpp @@ -155,6 +155,7 @@ void dealloc(ref r, ref source) if (r.linked(concepts::allocator())) { return; } try { + if (r.crucial()) { throw crucial_concept(r); } dealloc_from(r); concept * referenced = intellect::level0::referenced(r, source); if (referenced) { diff --git a/starts/meaning-vm/level-0/ref.cpp b/starts/meaning-vm/level-0/ref.cpp index 87e911a..513d3ce 100644 --- a/starts/meaning-vm/level-0/ref.cpp +++ b/starts/meaning-vm/level-0/ref.cpp @@ -3,7 +3,9 @@ #include "errors.hpp" #include "memorystore.hpp" +#include #include +#include using namespace intellect::level0; using namespace concepts; @@ -13,10 +15,11 @@ std::string ref::dump(ref skipmarkertype, ref skipmarkertarget) if (self.linked(skipmarkertype, skipmarkertarget)) { return {}; } - std::string ret = std::to_string((unsigned long)ptr()) + ":\n"; + std::stringstream ss; + ss << std::hex << (size_t)ptr() << ":" << std::endl; for (auto & link : self.links()) { if (link.first.linked(allocator(), level0allocations())) { continue; } - ret += " " + std::to_string((unsigned long)link.first.ptr()) + ": " + std::to_string((unsigned long)link.second.ptr()) + "\n"; + ss << " " << (size_t)link.first.ptr() << ": " << (size_t)link.second.ptr() << std::endl; } self.link(skipmarkertype, skipmarkertarget); for (auto & link : self.links()) { @@ -24,7 +27,7 @@ std::string ref::dump(ref skipmarkertype, ref skipmarkertarget) if (link.first == skipmarkertype && link.second == skipmarkertarget) { continue; } - ret += link.second.dump(skipmarkertype, skipmarkertarget); + ss << link.second.dump(skipmarkertype, skipmarkertarget); } - return ret; + return ss.str(); } diff --git a/starts/meaning-vm/level-2/funcs.cpp b/starts/meaning-vm/level-2/funcs.cpp index 3ecedb3..b11413f 100644 --- a/starts/meaning-vm/level-2/funcs.cpp +++ b/starts/meaning-vm/level-2/funcs.cpp @@ -21,6 +21,7 @@ ref makehabit(ref name, std::initializer_list argnames, std::function>(codelink)(); std::cout << allocated() << " allocated" << std::endl; + + a.get(codelink).setcrucial(); + try { + dealloc(a.get(codelink), a); + throw "deallocd crucial concept"; + } catch (crucial_concept e) { + realloc(a.get(codelink), concepts::level0allocations()); + } + a.setcrucial(codelink, a.get(codelink)); + try { + a.unlink(codelink); + throw "unlinkd crucial link"; + } catch (crucial_link_type_target e) { + realloc(a, concepts::level0allocations()); + realloc(codelink, concepts::level0allocations()); + } + + for (auto c : { a, a.get(codelink) } ) + for (auto it = c.links().begin(); it != c.links().end();) { + if (!c.crucial(it) && !it->first.linked(concepts::allocator(), concepts::level0allocations())) { + c.unlink(it++); + } else { + ++ it; + } + } e.unlink(b, a); - dealloc(a, store); + //dealloc(a, store); dealloc(store, concepts::allocations()); std::cout << allocated() << " allocated" << std::endl; diff --git a/starts/meaning-vm/makefile b/starts/meaning-vm/makefile index 243ab85..0a9738c 100644 --- a/starts/meaning-vm/makefile +++ b/starts/meaning-vm/makefile @@ -24,7 +24,7 @@ level-1/%.ii: $(wildcard level-0/*.hpp) $(wildcard level-1/*.hpp) level-2/%.ii: $(wildcard level-0/*.hpp) $(wildcard level-1/*.hpp) $(wildcard level-2/*.hpp) %.a: - ar ru $@ $^ + ar cr $@ $^ ranlib $@ clean: -- cgit v1.2.3