summaryrefslogtreecommitdiff
path: root/tests/types.toc
blob: 5117906681b9a4d9521eff70e78af7a410b91f21 (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
#include "std/io.toc", io;
#include "std/mem.toc";

main ::= fn() {
	nums := news(int, 10);
	for x, i := &nums {
		*x = i*i;
	}
	l := slice_to_ll(nums);
	p := &l;
	while p {
		io.puti(p.head);
		p = p.tail;
	}
	f: Foo;
	f.k = -173;
	f.b = new(Bar);
	f.b.f.b = new(Bar);
	f.b.f.b.f.k = 9;
	io.puti(f.k);
	io.puti(f.b.f.k);
	io.puti(f.b.f.b.f.k);
}

slice_to_ll ::= fn(t::=, slice: []t) use ll: LinkedList(t) {
	head = slice[0];
	if slice.len == 1 {
		tail = null;
	} else {
		tail = new(LinkedList(t));
		*tail = slice_to_ll(slice[1:]);
	}
}

LinkedList ::= struct (of :: Type) {
	head: of;
	tail: &LinkedList(of);
}

Foo ::= struct {
	k: int;
	b: &Bar;
}

Bar ::= struct {
	f: Foo;
}