summaryrefslogtreecommitdiff
path: root/starts/meaning-vm
diff options
context:
space:
mode:
Diffstat (limited to 'starts/meaning-vm')
-rw-r--r--starts/meaning-vm/level-0/baseref.hpp4
-rw-r--r--starts/meaning-vm/level-0/concept.hpp3
-rw-r--r--starts/meaning-vm/level-1/baseref.hpp33
-rw-r--r--starts/meaning-vm/level-1/common.hpp2
-rw-r--r--starts/meaning-vm/level-1/concepts.hpp1
-rw-r--r--starts/meaning-vm/level1.cpp23
6 files changed, 64 insertions, 2 deletions
diff --git a/starts/meaning-vm/level-0/baseref.hpp b/starts/meaning-vm/level-0/baseref.hpp
index 205b422..77c783d 100644
--- a/starts/meaning-vm/level-0/baseref.hpp
+++ b/starts/meaning-vm/level-0/baseref.hpp
@@ -51,10 +51,12 @@ public:
template <typename T>
T& vget(ref const & type) const { return p->vget<T>(type.p); }
template <typename T>
- void vset(ref const & type, T const & v) { p->set(type.p, alloc(v)); }
+ void vset(ref const & type, T const & v) { p->set(type.p, level0::alloc(v)); }
template <typename T>
T& val() { return p->val<T>(); }
+ template <typename T>
+ void val(T const & v) { p->val<T>(v); }
operator concept*() const { return p; }
concept*& ptr() { return p; }
diff --git a/starts/meaning-vm/level-0/concept.hpp b/starts/meaning-vm/level-0/concept.hpp
index d57ccfc..d42d36b 100644
--- a/starts/meaning-vm/level-0/concept.hpp
+++ b/starts/meaning-vm/level-0/concept.hpp
@@ -38,6 +38,9 @@ struct concept
template <typename T>
T & val() { return std::any_cast<T&>(data); }
+
+ template <typename T>
+ void val(T const & v) { data = v; }
};
}
diff --git a/starts/meaning-vm/level-1/baseref.hpp b/starts/meaning-vm/level-1/baseref.hpp
index e8bdcb9..63045fa 100644
--- a/starts/meaning-vm/level-1/baseref.hpp
+++ b/starts/meaning-vm/level-1/baseref.hpp
@@ -5,6 +5,8 @@
#include "../level-0/ref.hpp"
+#include <functional>
+
namespace intellect {
namespace level1 {
@@ -27,7 +29,38 @@ struct baseref : public level0::baseref<ref>
ref operator-(ref other) { return hyphenate(self.ptr(), other.ptr()); }
+ template <typename T>
+ void vset(ref const & type, T const & v) { self.set(type, level1::alloc(v)); }
+
+ template <typename... Ref>
+ std::function<ref(Ref...)> & fun() { return self.template val<std::function<ref(Ref...)>>(); }
+ template <typename... Ref>
+ void fun(std::function<ref(Ref...)> const & f) { val(f); }
+ template <typename... Ref>
+ void fun(std::function<void(Ref...)> const & f) { val(voidtoret(f)); }
+ template <typename... Ref>
+ void fget(ref const & type) { return self.template vget<std::function<ref(Ref...)>>(type); }
+ template <typename... Ref>
+ void fset(ref const & type, std::function<ref(Ref...)> f) { self.vset(type, f); }
+ template <typename... Ref>
+ void fset(ref const & type, std::function<void(Ref...)> f) { fset(type, voidtoret(f)); }
+
+ template <typename... Ref>
+ ref operator()(Ref... args) { return self.template fun<Ref...>()(args...); }
+
std::string dump(ref skipmarkertype, ref skipmarkertarget);
+
+private:
+ template <typename... Refs>
+ std::function<ref(Refs...)> voidtoret(std::function<void(Refs...)> f)
+ {
+ return [f](Refs... args) -> ref
+ {
+ std::initializer_list<ref const *>({&args...});
+ f(args...);
+ return concepts::nothing;
+ };
+ }
};
}
diff --git a/starts/meaning-vm/level-1/common.hpp b/starts/meaning-vm/level-1/common.hpp
index 73de3b4..5dd2840 100644
--- a/starts/meaning-vm/level-1/common.hpp
+++ b/starts/meaning-vm/level-1/common.hpp
@@ -10,5 +10,7 @@ using level0::concept;
template <typename T> struct baseref;
struct ref;
+namespace concepts { extern ref nothing; }
+
}
}
diff --git a/starts/meaning-vm/level-1/concepts.hpp b/starts/meaning-vm/level-1/concepts.hpp
index 3f49eca..6dfc64b 100644
--- a/starts/meaning-vm/level-1/concepts.hpp
+++ b/starts/meaning-vm/level-1/concepts.hpp
@@ -1,7 +1,6 @@
#pragma once
#include "ref.hpp"
-#include "sugar.hpp"
namespace intellect {
namespace level1 {
diff --git a/starts/meaning-vm/level1.cpp b/starts/meaning-vm/level1.cpp
index ae70b5a..2e005e2 100644
--- a/starts/meaning-vm/level1.cpp
+++ b/starts/meaning-vm/level1.cpp
@@ -14,6 +14,7 @@ int main()
decls(source, type, target);
decls(structure, function, argument, position);
decls(variable, provide);
+ decls(act);
(make-linked).link(
is, habit,
@@ -35,8 +36,30 @@ int main()
assumes, not-A-B-C-linked,
makes, A-B-C-linked
);
+ (make-linked).fset(
+ act,
+ (std::function<void(ref)>)[](ref args)
+ {
+ ref source = args.get("A");
+ ref type = args.get("B");
+ ref target = args.get("C");
+ std::cout << "Linking " << source.name() << " by " << type.name() << " to " << target.name() << std::endl;
+ source.link(type, target);
+ }
+ );
std::cout << (make-linked).dump("dumped", true) << std::endl;
+ decls(apple, fruit);
+ (make-linked).get(act)
+ (a(function-argument)
+ .link(
+ A, apple,
+ B, is,
+ C, fruit
+ ));
+
+ std::cout << apple.dump("dumped", true) << std::endl;
+
return 0;
}