From f80b3ce2b52f568bb04005c24ad11c3a05cf7a15 Mon Sep 17 00:00:00 2001 From: olpc user Date: Sun, 24 Nov 2019 14:09:27 -0800 Subject: level0 few more checks --- starts/meaning-vm/level-0/memorystore.cpp | 5 +++++ starts/meaning-vm/level-0/memorystore.hpp | 1 + starts/meaning-vm/level-0/vref.hpp | 3 ++- starts/meaning-vm/level0.cpp | 31 ++++++++++++++++++++++++++++++- 4 files changed, 38 insertions(+), 2 deletions(-) (limited to 'starts/meaning-vm') diff --git a/starts/meaning-vm/level-0/memorystore.cpp b/starts/meaning-vm/level-0/memorystore.cpp index 6cf71df..0a4f0cc 100644 --- a/starts/meaning-vm/level-0/memorystore.cpp +++ b/starts/meaning-vm/level-0/memorystore.cpp @@ -55,5 +55,10 @@ void dealloc(ref r) { throw no_such_concept(r); } +std::size_t allocated() +{ + return concepts().size(); +} + } } diff --git a/starts/meaning-vm/level-0/memorystore.hpp b/starts/meaning-vm/level-0/memorystore.hpp index 4e0a2bd..a86ccea 100644 --- a/starts/meaning-vm/level-0/memorystore.hpp +++ b/starts/meaning-vm/level-0/memorystore.hpp @@ -8,6 +8,7 @@ namespace level0 { ref alloc(concept * moved = 0); void dealloc(ref); +std::size_t allocated(); } } diff --git a/starts/meaning-vm/level-0/vref.hpp b/starts/meaning-vm/level-0/vref.hpp index 7fe2045..cffc8f5 100644 --- a/starts/meaning-vm/level-0/vref.hpp +++ b/starts/meaning-vm/level-0/vref.hpp @@ -15,10 +15,11 @@ struct vref value* operator->() { return ptr; } operator T const &() const { return *ptr; } - vref(T const & val) : ptr(alloc(new value(val))) { } + vref(T const & val) : vref(alloc(new value(val))) { } vref(ref const & other) : ptr(static_cast*>(other.ptr)) { } operator ref() { return ptr; } + T const & val() { return *ptr; } // for use by containers bool operator<(vref const & other) const { return self.ptr < other.ptr; } diff --git a/starts/meaning-vm/level0.cpp b/starts/meaning-vm/level0.cpp index 71c18b7..8cb60f9 100644 --- a/starts/meaning-vm/level0.cpp +++ b/starts/meaning-vm/level0.cpp @@ -1,5 +1,6 @@ #include "level-0/level-0.hpp" +#include #include using namespace intellect::level0; @@ -11,6 +12,12 @@ int main() ref c = alloc(); ref d = alloc(); ref e = alloc(); + vref num(3); + vref> code([](){ + std::cout << "Hello, world." << std::endl; + }); + auto numlink = alloc(); + auto codelink = alloc(); ref skip = alloc(); @@ -18,8 +25,30 @@ int main() a->link(d, e); e->link(b, a); c->link(b, e); + a->link(numlink, num); + a->link(codelink, code); - std::cout << a.dump(skip, skip) << std::endl; + std::cout << "Num: " << ref(num).dump(skip, skip); + std::cout << "Code: " << ref(code).dump(skip, skip); + std::cout << a.dump(skip, skip); + std::cout << "Num: " << a->vget(numlink).val() << std::endl; + std::cout << "Code: "; a->vget>(codelink).val()(); + + std::cout << allocated() << " allocated" << std::endl; + + e->unlink(b, a); + dealloc(a); + dealloc(c); + dealloc(e); + dealloc(b); + dealloc(d); + dealloc(numlink); + dealloc(codelink); + dealloc(num); + dealloc(code); + dealloc(skip); + + std::cout << allocated() << " allocated" << std::endl; return 0; } -- cgit v1.2.3