summaryrefslogtreecommitdiff
path: root/starts
diff options
context:
space:
mode:
Diffstat (limited to 'starts')
-rw-r--r--starts/meaning-vm/level-0/baseref.hpp2
-rw-r--r--starts/meaning-vm/level-0/concept.cpp2
-rw-r--r--starts/meaning-vm/level-0/concept.hpp2
-rw-r--r--starts/meaning-vm/level-0/memorystore.cpp1
-rw-r--r--starts/meaning-vm/level-0/ref.cpp11
-rw-r--r--starts/meaning-vm/level-2/funcs.cpp1
-rw-r--r--starts/meaning-vm/level-2/habits.cpp6
-rw-r--r--starts/meaning-vm/level0.cpp29
-rw-r--r--starts/meaning-vm/makefile2
9 files changed, 43 insertions, 13 deletions
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 <iomanip>
#include <ostream>
+#include <sstream>
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<ref> argnames, std::function<void(
ref habit = level1::a(concepts::habit, name);
ref infn = a(habit-information-needed);
habit.set(information-needed, infn);
+ //habit.set(concepts::habit, concepts::habit);
ref posinf = infn;
for (auto argname : argnames) {
ref nextinf = a(habit-information);
diff --git a/starts/meaning-vm/level-2/habits.cpp b/starts/meaning-vm/level-2/habits.cpp
index dfb9014..4900daf 100644
--- a/starts/meaning-vm/level-2/habits.cpp
+++ b/starts/meaning-vm/level-2/habits.cpp
@@ -189,12 +189,12 @@ int createhabits()
ahabit(list-entry-unmake, ((list-entry, le)),
{
ref prev = (list-entry-previous)(le);
- ref next = (list-entry-next)(le);
+ ref n = (list-entry-next)(le);
if (prev != nothing) {
- set(prev, "next", next);
+ set(prev, next, n);
}
if (next != nothing) {
- set(next, "previous", prev);
+ set(n, previous, prev);
}
(concept-unmake)(le);
});
diff --git a/starts/meaning-vm/level0.cpp b/starts/meaning-vm/level0.cpp
index add6689..6beb789 100644
--- a/starts/meaning-vm/level0.cpp
+++ b/starts/meaning-vm/level0.cpp
@@ -5,7 +5,7 @@
using namespace intellect::level0;
-#define out(name) std::cout << " " #name ":" << (long)name.ptr()
+#define out(name) std::cout << " " #name ":" << std::hex << (size_t)name.ptr() << std::dec
int main()
{
@@ -41,9 +41,34 @@ int main()
std::cout << "Code: "; a.vget<std::function<void()>>(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: