summaryrefslogtreecommitdiff
path: root/starts/meaning-vm
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2020-01-05 13:19:08 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2020-01-05 13:19:08 -0800
commit2434ac8c0da3151c4c72ce8c86a9fecbdfcb1f8d (patch)
treefaa284d8332caa83613d5886b4c66963a08aecf4 /starts/meaning-vm
parent028c06b452f45df329116c0d0017ad2cd8ee2acc (diff)
downloadstandingwithresilience-2434ac8c0da3151c4c72ce8c86a9fecbdfcb1f8d.tar.gz
standingwithresilience-2434ac8c0da3151c4c72ce8c86a9fecbdfcb1f8d.zip
runs without crashing, runtime errors next
Diffstat (limited to 'starts/meaning-vm')
-rw-r--r--starts/meaning-vm/level-2/habits.cpp36
-rw-r--r--starts/meaning-vm/level2.cpp2
2 files changed, 27 insertions, 11 deletions
diff --git a/starts/meaning-vm/level-2/habits.cpp b/starts/meaning-vm/level-2/habits.cpp
index 814bd58..ea492a5 100644
--- a/starts/meaning-vm/level-2/habits.cpp
+++ b/starts/meaning-vm/level-2/habits.cpp
@@ -79,15 +79,23 @@ ref settranslationmap(ref c, ref m, ref k = nothing)
// means accessing every condition. no need to rewrite whole structure, just look up how to access. faster than rewriting.
// make a function to wire to end
-void contextmapinto(ref c1, ref m, ref c2)
+void contextmapinto(ref c1, ref m, ref c2, bool reverse = false)
{
decl(translation); decl(known); decl(nothing);
for (auto link : m.get(translation).links()) {
- c2.set(link.first, c1.get(link.second));
+ if (reverse) {
+ c2.set(link.second, c1.get(link.first));
+ } else {
+ c2.set(link.first, c1.get(link.second));
+ }
}
if (m.linked(known) && m.get(known) != nothing) {
for (auto link : m.get(known).links()) {
- c2.set(link.first, link.second);
+ if (reverse) {
+ c2.set(link.second, link.first);
+ } else {
+ c2.set(link.first, link.second);
+ }
}
}
}
@@ -143,7 +151,7 @@ void _steps(ref s, ref ctx)
subctx.set("self", s.get(action));
s.get(action).fun<ref>()(subctx); // <-- maybe we should check arguments
if (s.linked(made-map)) {
- contextmapinto(subctx, s.get(made-map), c);
+ contextmapinto(subctx, s.get(made-map), c, true);
}
if (s.linked(needed-map)) {
c = subctx.get(outer-context);
@@ -292,12 +300,16 @@ void createhabits()
decl(entry);
ahabit(first-link-entry, ((target, le), (concept, c)),
{
- if (le.hasval()) { throw makeconcept().link(
+ if (le.hasval() && !le.hasvalof<links_it>()) {
+ throw makeconcept().link(
is, "already-has-value",
concept, le,
- context, ctx); }
+ context, ctx);
+ }
//ref le = makeconcept();
- le.link(is, link-entry);
+ if (!le.isa(link-entry)) {
+ le.link(is, link-entry);
+ }
le.val<links_it>(c.links().begin());
le.set(source, c);
poplinkentry(le);
@@ -305,11 +317,15 @@ void createhabits()
});
ahabit(last-link-entry, ((target, le), (concept, c)),
{
- if (le.hasval()) { throw makeconcept().link(
+ if (le.hasval() && !le.hasvalof<links_it>()) {
+ throw makeconcept().link(
is, "already-has-value",
concept, le,
- context, ctx); }
- le.link(is, link-entry);
+ context, ctx);
+ }
+ if (!link.isa(link-entry)) {
+ le.link(is, link-entry);
+ }
le.val<links_it>(--c.links().end());
le.set(source, c);
poplinkentry(le);
diff --git a/starts/meaning-vm/level2.cpp b/starts/meaning-vm/level2.cpp
index e3a7ab9..c8080e6 100644
--- a/starts/meaning-vm/level2.cpp
+++ b/starts/meaning-vm/level2.cpp
@@ -575,7 +575,7 @@ void parse(ref stream)
if (values.count(argname.name())) {
neededmap.link(arg, argname);
} else {
- knownmap.link(arg, lookup(argname.get("name")));
+ knownmap.link(arg, lookup(argname));
}
}
dealloc(stream2, intellect::level0::concepts::allocations());