summaryrefslogtreecommitdiff
path: root/starts/meaning-vm/level0.cpp
blob: 6beb789a19a3a663310bc2412ddb7ac22bb3430b (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "level-0/level-0.hpp"

#include <functional>
#include <iostream>

using namespace intellect::level0;

#define out(name) std::cout << " " #name ":" << std::hex << (size_t)name.ptr() << std::dec

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;
	
	a.get(codelink).setcrucial();
	try {
		dealloc(a.get(codelink), a);
		throw "deallocd crucial concept";
	} catch (crucial_concept e) {
		realloc(a.get(codelink), concepts::level0allocations());
	}
	a.setcrucial(codelink, a.get(codelink));
	try {
		a.unlink(codelink);
		throw "unlinkd crucial link";
	} catch (crucial_link_type_target e) {
		realloc(a, concepts::level0allocations());
		realloc(codelink, concepts::level0allocations());
	}

	for (auto c : { a, a.get(codelink) } )
	for (auto it = c.links().begin(); it != c.links().end();) {
		if (!c.crucial(it) && !it->first.linked(concepts::allocator(), concepts::level0allocations())) {
			c.unlink(it++);
		} else {
			++ it;
		}
	}

	e.unlink(b, a);
	//dealloc(a, store);
	dealloc(store, concepts::allocations());

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

	std::cout << "=== (feel free to move the below to its most effective spot) ===" << std::endl;
	std::cout << "Please support Karl working on this intelligence framework." << std::endl;
      	std::cout << "The framework needs to be quality, so that the rest may function." << std::endl;
	std::cout << "=== === === === === === === ===  === === === === === === === ===" << std::endl;

	return 0;
}