summaryrefslogtreecommitdiff
path: root/starts/meaning-vm
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-25 17:35:09 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-25 17:35:09 -0800
commit8172f109ed55b8a02e7e498566b7ba12e346f7e2 (patch)
treed23b6279d34b03d7cebc987808c74a3cf49cecf8 /starts/meaning-vm
parent684ac69af192670bb6547ec01df19a3159e7d8e6 (diff)
downloadstandingwithresilience-8172f109ed55b8a02e7e498566b7ba12e346f7e2.tar.gz
standingwithresilience-8172f109ed55b8a02e7e498566b7ba12e346f7e2.zip
add vset
Diffstat (limited to 'starts/meaning-vm')
-rw-r--r--starts/meaning-vm/level-0/baseref.hpp3
-rw-r--r--starts/meaning-vm/level-0/memorystore.hpp1
-rw-r--r--starts/meaning-vm/level0.cpp24
3 files changed, 15 insertions, 13 deletions
diff --git a/starts/meaning-vm/level-0/baseref.hpp b/starts/meaning-vm/level-0/baseref.hpp
index bdfd065..b68de24 100644
--- a/starts/meaning-vm/level-0/baseref.hpp
+++ b/starts/meaning-vm/level-0/baseref.hpp
@@ -2,6 +2,7 @@
#include "common.hpp"
#include "errors.hpp"
+#include "memorystore.hpp"
#include <map>
#include <vector>
@@ -37,6 +38,8 @@ public:
template <typename T>
T& vget(ref const & type) const { return p->vget<T>(type.p)->data; }
+ template <typename T>
+ void vset(ref const & type, T const & v) { p->set(type.p, valloc<T>(v)); }
template <typename T>
T& val() { return p->val<T>()->data; }
diff --git a/starts/meaning-vm/level-0/memorystore.hpp b/starts/meaning-vm/level-0/memorystore.hpp
index cdd7462..8958ae7 100644
--- a/starts/meaning-vm/level-0/memorystore.hpp
+++ b/starts/meaning-vm/level-0/memorystore.hpp
@@ -1,7 +1,6 @@
#pragma once
#include "common.hpp"
-#include "ref.hpp"
#include "value.hpp"
namespace intellect {
diff --git a/starts/meaning-vm/level0.cpp b/starts/meaning-vm/level0.cpp
index 1efd33e..1dcc4f7 100644
--- a/starts/meaning-vm/level0.cpp
+++ b/starts/meaning-vm/level0.cpp
@@ -12,10 +12,6 @@ int main()
ref c = alloc();
ref d = alloc();
ref e = alloc();
- ref num = valloc<int>(3);
- ref code = valloc<std::function<void()>>([](){
- std::cout << "Hello, world." << std::endl;
- });
auto numlink = alloc();
auto codelink = alloc();
@@ -25,11 +21,13 @@ int main()
a.link(d, e);
e.link(b, a);
c.link(b, e);
- a.link(numlink, num);
- a.link(codelink, code);
+ a.vset<int>(numlink, 3);
+ a.vset<std::function<void()>>(codelink, [](){
+ std::cout << "Hello, world." << std::endl;
+ });
- std::cout << "Num: " << ref(num).dump(skip, skip);
- std::cout << "Code: " << ref(code).dump(skip, skip);
+ std::cout << "Num: " << a.get(numlink).dump(skip, skip);
+ std::cout << "Code: " << a.get(codelink).dump(skip, skip);
std::cout << a.dump(skip, skip);
std::cout << "Num: " << a.vget<int>(numlink) << std::endl;
std::cout << "Code: "; a.vget<std::function<void()>>(codelink)();
@@ -37,15 +35,17 @@ int main()
std::cout << allocated() << " allocated" << std::endl;
e.unlink(b, a);
+ auto num = a.get(numlink);
+ auto code = a.get(codelink);
dealloc(a);
+ dealloc(num);
+ dealloc(code);
+ dealloc(numlink);
+ dealloc(codelink);
dealloc(c);
dealloc(e);
dealloc(b);
dealloc(d);
- dealloc(numlink);
- dealloc(codelink);
- dealloc(num);
- dealloc(code);
dealloc(skip);
std::cout << allocated() << " allocated" << std::endl;