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.hpp16
-rw-r--r--starts/meaning-vm/level-0/memorystore.cpp7
-rw-r--r--starts/meaning-vm/level-0/memorystore.hpp6
-rw-r--r--starts/meaning-vm/level-1/funcs.cpp2
-rw-r--r--starts/meaning-vm/level0.cpp4
-rw-r--r--starts/meaning-vm/level1.cpp16
6 files changed, 27 insertions, 24 deletions
diff --git a/starts/meaning-vm/level-0/baseref.hpp b/starts/meaning-vm/level-0/baseref.hpp
index b4ceb02..849e205 100644
--- a/starts/meaning-vm/level-0/baseref.hpp
+++ b/starts/meaning-vm/level-0/baseref.hpp
@@ -36,8 +36,10 @@ public:
array getAll(ref const & type) const;
links_t links() const;
- ref link(std::initializer_list<ref> refs)
+ template <typename... Ref>
+ ref link(Ref... refspack)
{
+ std::initializer_list<ref> refs{refspack...};
for (auto it = refs.begin(); it != refs.end();) {
ref type = *it++;
ref target = *it++;
@@ -58,12 +60,12 @@ public:
concept*& ptr() { return p; }
concept* const & ptr() const { return p; }
- level0::ref & r0() { return *reinterpret_cast<level0::ref*>(this); }
- level1::ref & r1() { return *reinterpret_cast<level1::ref*>(this); }
- level2::ref & r2() { return *reinterpret_cast<level2::ref*>(this); }
- level3::ref & r3() { return *reinterpret_cast<level3::ref*>(this); }
- level4::ref & r4() { return *reinterpret_cast<level4::ref*>(this); }
- level5::ref & r5() { return *reinterpret_cast<level5::ref*>(this); }
+ operator level0::ref &() { return *reinterpret_cast<level0::ref*>(this); }
+ operator level1::ref &() { return *reinterpret_cast<level1::ref*>(this); }
+ operator level2::ref &() { return *reinterpret_cast<level2::ref*>(this); }
+ operator level3::ref &() { return *reinterpret_cast<level3::ref*>(this); }
+ operator level4::ref &() { return *reinterpret_cast<level4::ref*>(this); }
+ operator level5::ref &() { return *reinterpret_cast<level5::ref*>(this); }
bool operator==(ref const & other) const { return self.p == other.p; }
bool operator!=(ref const & other) const { return self.p == other.p; }
diff --git a/starts/meaning-vm/level-0/memorystore.cpp b/starts/meaning-vm/level-0/memorystore.cpp
index d3e4f95..b092ca0 100644
--- a/starts/meaning-vm/level-0/memorystore.cpp
+++ b/starts/meaning-vm/level-0/memorystore.cpp
@@ -1,6 +1,7 @@
#include "memorystore.hpp"
#include "concept.hpp"
#include "errors.hpp"
+#include "ref.hpp"
#include <unordered_set>
@@ -9,11 +10,11 @@ namespace level0 {
static auto & concepts()
{
- static std::unordered_set<concept*, std::hash<concept*>> concepts;
+ static std::unordered_set<ref, std::hash<concept*>> concepts;
return concepts;
}
-concept* alloc(concept * moved) {
+ref alloc(concept * moved) {
ref r = moved ? moved : new concept();
concepts().insert(r);
return r;
@@ -36,7 +37,7 @@ static concept* referenced(ref r) {
return 0;
}
-void dealloc(concept * r) {
+void dealloc(ref r) {
concept * referenced = intellect::level0::referenced(r);
if (referenced) {
throw still_referenced_by(r, referenced);
diff --git a/starts/meaning-vm/level-0/memorystore.hpp b/starts/meaning-vm/level-0/memorystore.hpp
index 8958ae7..fd752a0 100644
--- a/starts/meaning-vm/level-0/memorystore.hpp
+++ b/starts/meaning-vm/level-0/memorystore.hpp
@@ -6,10 +6,10 @@
namespace intellect {
namespace level0 {
-concept * alloc(concept * moved = 0);
+ref alloc(concept * moved = 0);
template <typename T>
-value<T> * valloc(T const & v) { return static_cast<value<T>*>(alloc(new value<T>(v))); }
-void dealloc(concept*);
+value<T> * valloc(T const & v) { return static_cast<value<T>*>(alloc(new value<T>(v)).ptr()); }
+void dealloc(ref);
std::size_t allocated();
}
diff --git a/starts/meaning-vm/level-1/funcs.cpp b/starts/meaning-vm/level-1/funcs.cpp
index 0a481e9..3d0d88d 100644
--- a/starts/meaning-vm/level-1/funcs.cpp
+++ b/starts/meaning-vm/level-1/funcs.cpp
@@ -39,7 +39,7 @@ concept* getnamed(std::string const & name)
level1::ref con = level0::alloc();
level0::value<std::string>* namestr = level0::valloc(name);
ns.conceptsByName.emplace(namestr->data, con);
- con.set(ns.nameref.r0(), namestr);
+ con.set(ns.nameref, namestr);
return con.ptr();
}
}
diff --git a/starts/meaning-vm/level0.cpp b/starts/meaning-vm/level0.cpp
index fa33d71..6ff0102 100644
--- a/starts/meaning-vm/level0.cpp
+++ b/starts/meaning-vm/level0.cpp
@@ -17,10 +17,10 @@ int main()
ref skip = alloc();
- a.link({
+ a.link(
b, c,
d, e
- });
+ );
e.set(b, a);
c.link(b, e);
a.vset<int>(numlink, 3);
diff --git a/starts/meaning-vm/level1.cpp b/starts/meaning-vm/level1.cpp
index 9dee4a7..ae70b5a 100644
--- a/starts/meaning-vm/level1.cpp
+++ b/starts/meaning-vm/level1.cpp
@@ -15,26 +15,26 @@ int main()
decls(structure, function, argument, position);
decls(variable, provide);
- (make-linked).link({
+ (make-linked).link(
is, habit,
- needs, a(structure).link({
+ needs, a(structure).link(
is, function-argument,
argument-position, ref(1),
a(variable, A), provide,
a(variable, B), provide,
a(variable, C), provide
- })
- });
- movetoname(a(link), A-B-C-linked).link({
+ )
+ );
+ movetoname(a(link), A-B-C-linked).link(
link-source, A,
link-type, B,
link-target, C
- });
+ );
a(not, not-A-B-C-linked).set(topic, A-B-C-linked);
- (make-linked).link({
+ (make-linked).link(
assumes, not-A-B-C-linked,
makes, A-B-C-linked
- });
+ );
std::cout << (make-linked).dump("dumped", true) << std::endl;