summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/level0.cpp
blob: 8cb60f9099c391b15c4519246a44bf4493bcc5d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "level-0/level-0.hpp"

#include <functional>
#include <iostream>

using namespace intellect::level0;

int main()
{
	ref a = alloc();
	ref b = alloc();
	ref c = alloc();
	ref d = alloc();
	ref e = alloc();
	vref<int> num(3);
	vref<std::function<void()>> code([](){
		std::cout << "Hello, world." << std::endl;
	});
	auto numlink = alloc();
	auto codelink = alloc();

	ref skip = alloc();
	
	a->link(b, c);
	a->link(d, e);
	e->link(b, a);
	c->link(b, e);
	a->link(numlink, num);
	a->link(codelink, code);

	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<int>(numlink).val() << std::endl;
	std::cout << "Code:  "; a->vget<std::function<void()>>(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;
}