summaryrefslogtreecommitdiff
path: root/test.toc
blob: 0cb937533adb8d111f653ffdfa57b7a8a959f838 (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
puti ::= fn(x: int) {
	 #C("printf(\"%ld\\n\", (long)x);
");
};
// putf ::= fn(x: float) {
// 	 #C("printf(\"%f\\n\", (double)x);
// ");
// };

Arr ::= fn (t :: Type) Type {
	struct {
		   data : []t;
		   len, cap : int;
	}
};

// todo: test that t :: type doesn't cause problems 
arr_add ::= fn(t :: Type, a : &Arr(t), x : t) {
		if a.len >= a.cap {
		   a.cap = a.cap * 2 + 2;
		   new_data := new(t, a.cap);
		   each i := 0..a.len-1 {
		   		new_data[i] = a.data[i];
		   }
		   a.data = new_data;
		}
		a.data[a.len] = x;
		a.len += 1;
};



main ::= fn() {
	 arr : Arr(int);
	 each i := 1..100 {
	  arr_add(int, &arr,	i*i);
	 }
	 each i := 0..arr.len - 1 {
	 	  puti(arr.data[i]);
	 }
};

// t ::= fn(x :: Type) Type { struct { t: x; } };
// // pass the wrong thing to t, and the error is in the wrong place

// f ::= fn(x: t(int)) {};

// f ::= fn(t :: Type, x : t) {
// };

// main ::= fn() {
// 	 f(int,3);
// };