summaryrefslogtreecommitdiff
path: root/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/funcs.cpp
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2020-01-10 14:56:27 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2020-01-10 14:56:27 -0800
commit26c980d302adce8e3d802cb8db8ab1c69d58ce1a (patch)
treee296225f17370c9e472660396b3a51539f76ff28 /intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/funcs.cpp
parent2e01fed206e46a669ba56f57b4b943cfe661a0f1 (diff)
parentc8bb547bea279af2bb48c13260f98aa8add07131 (diff)
downloadstandingwithresilience-26c980d302adce8e3d802cb8db8ab1c69d58ce1a.tar.gz
standingwithresilience-26c980d302adce8e3d802cb8db8ab1c69d58ce1a.zip
Merge branch 'intellect-framework-from-internet'
Diffstat (limited to 'intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/funcs.cpp')
-rw-r--r--intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/funcs.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/funcs.cpp b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/funcs.cpp
new file mode 100644
index 0000000..d746f13
--- /dev/null
+++ b/intellect-framework-from-internet/starts/meaning-vm/level-2-wip-stmtexprs/funcs.cpp
@@ -0,0 +1,69 @@
+#include "funcs.hpp"
+
+using namespace intellect;
+using namespace level2;
+using namespace concepts;
+
+static ref refassigned(ref expr)
+{
+ ref lhs = ref.get(left-operand);
+ ref rhs = ref.get(right-operand);
+ if (lhs.isa(link) && lhs.get(link-target) == unknown) {
+ // completes the target of a link, for a[b] = c
+ lhs.unlink(link-target, unknown);
+ lhs.set(link-target, rhs);
+ ref.unlink(right-operand, rhs);
+ ref src = lhs.get(link-source);
+ if (lhs.get(link-type) != unknown && src != unknown) {
+ src.set(lhs.get(link-type), rhs);
+ return src;
+ } else {
+ throw std::logic_error("not sure what to do with incomplete link assignment");
+ }
+ } else if (isanonymous(rhs) && !isanonymous(lhs)) {
+ // assignment of anonymous content to empty named concept
+ ref.unlink(left-operand, lhs);
+ return level1::movetoname(rhs, lhs);
+ } else {
+ throw std::logic_error("unexpected bare assignment");
+ }
+}
+// maybe later we can have ref class itself do operators completely based on its own
+// ref content.
+
+statementref assignop(ref self, ref other)
+{
+ return statementref::makebinary(
+ self, concepts::assign, other,
+ refassigned, refassigned
+ );
+}
+statementref commaop(ref self, ref other)
+{
+ if (self.isa(comma-expression)) {
+ if (other.isa(comma-expression)) {
+ for (auto & l : other.links()) { self.insert(l.first, l.second); }
+ dealloc(other);
+ } else {
+ self.link(topic, other);
+ }
+ return self;
+ } else if (other.isa(comma-expression)) {
+ other.link(topic, self);
+ return other;
+ } else {
+ return statementcallref::makebinary(
+ self, comma, other,
+ [](ref)->ref { return ref; },
+ // um when we pass the comma-expression to
+ // the [] operator that takes a ref
+ // the destructor of statementref will deallocate it.
+ [](ref) { throw std::logic_error("bare comma-expression"); }
+ // something is wrong here. some approach is wrong.
+ // would it be better to have ref itself do it all?
+ );
+ }
+}
+ref subop(ref self, ref other)
+{
+}