summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/level0.cpp
blob: 4ed9e22ddad440f0872da4629def7950ce619f56 (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
#include "level-0/level-0.hpp"

#include <functional>
#include <iostream>

using namespace intellect::level0;

#define out(name) std::cout << " " #name ":" << (long)name.ptr()

int main()
{
	std::cout << allocated() << " allocated" << std::endl;

	ref store = alloc(concepts::allocations()); out(store);
	ref a = alloc(store); out(a);
	ref b = alloc(store); out(b);
	ref c = alloc(store); out(c);
	ref d = alloc(store); out(d);
	ref e = alloc(store); out(e);
	auto numlink = alloc(a); out(numlink);
	auto codelink = alloc(a); out(codelink);

	ref skip = alloc(store); out(skip);
	std::cout << std::endl;
	
	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);
	dealloc(a, store);
	dealloc(store, concepts::allocations());

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

	return 0;
}