summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/level0.cpp
blob: 6ff0102ea182279021cc488a2ca467a20284f146 (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
55
56
#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();
	auto numlink = alloc();
	auto codelink = alloc();

	ref skip = alloc();
	
	a.link(
		b, c,
		d, e
	);
	e.set(b, a);
	c.link(b, e);
	a.vset<int>(numlink, 3);
	a.vset<std::function<void()>>(codelink, [](){
		std::cout << "Hello, world." << std::endl;
	});

	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)();

	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(skip);

	std::cout << allocated() << " allocated" << std::endl;

	return 0;
}