summaryrefslogtreecommitdiff
path: root/std/arr.toc
blob: 24fdf9fe3bb1ddfdd5496774873399ed4786c7b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Arr ::= fn (t :: Type) Type {
	struct {
		   data : []t;
		   cap : int;
	}
};
arr_add ::= fn(t ::=, a : &Arr(t), x : t) {
		if a.data.len >= a.cap {
		   a.cap = a.cap * 2 + 2;
		   new_data := new(t, a.cap);
		   new_data.len = a.data.len;
		   for i := 0..a.data.len-1 {
		   		new_data[i] = a.data[i];
		   }
		   a.data = new_data;
		}
		a.data.len += 1;
		a.data[a.data.len-1] = x;
};
arr_len ::= fn(t ::=, a : Arr(t)) int { a.data.len };