From 8172f109ed55b8a02e7e498566b7ba12e346f7e2 Mon Sep 17 00:00:00 2001 From: olpc user Date: Mon, 25 Nov 2019 17:35:09 -0800 Subject: add vset --- starts/meaning-vm/level-0/baseref.hpp | 3 +++ starts/meaning-vm/level-0/memorystore.hpp | 1 - starts/meaning-vm/level0.cpp | 24 ++++++++++++------------ 3 files changed, 15 insertions(+), 13 deletions(-) (limited to 'starts/meaning-vm') 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 #include @@ -37,6 +38,8 @@ public: template T& vget(ref const & type) const { return p->vget(type.p)->data; } + template + void vset(ref const & type, T const & v) { p->set(type.p, valloc(v)); } template T& val() { return p->val()->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(3); - ref code = valloc>([](){ - 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(numlink, 3); + a.vset>(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(numlink) << std::endl; std::cout << "Code: "; a.vget>(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; -- cgit v1.2.3