aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/o3push.zc
blob: acb9fab4d1a47a4c9306cc196ac9e3c2f475730e (plain) (blame)
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
namespace;
include rt;

// push in o3 code: the quick path when there is room, dpush when there is not
o3 int fill(int[?] a, int n) {
	for (int i = 0; i < n; i++) push(a, i * 3);
	return len(a);
}
o3 int sum(int[?] a) {
	int s = 0;
	for (int i = 0; i < len(a); i++) s += a[i];
	return s;
}
o3 float fsum(float[?] a) {
	float s = 0.0;
	for (int i = 0; i < len(a); i++) s += a[i];
	return s;
}
o3 int ffill(float[?] a, int n) {
	for (int i = 0; i < n; i++) push(a, 0.5 * i);
	return len(a);
}
int main() {
	int[?] a = rt.new(int[?], 0);
	rt.put_n(fill(a, 1000)); rt.put_c(' ');
	rt.put_n(sum(a)); rt.put_c(' ');
	rt.put_n(a[999]); rt.put_c(' ');
	rt.put_n(fill(a, 5)); rt.put_c(' ');
	rt.put_n(cap(a) >= 1005); rt.put_c(' ');
	float[?] f = rt.new(float[?], 0);
	ffill(f, 10);
	rt.put_n(len(f)); rt.put_c(' '); rt.put_n(fsum(f) == 22.5); rt.put_c(' ');
	rt.put_n(drain(a)); rt.put_c(' '); rt.put_n(len(a)); rt.put_c(10);
	rt.free(d*a); rt.free(d*f);
	return 0;
}
o3 int drain(int[?] a) {
	int s = 0;
	while (len(a) > 0) s += pop(a);
	return s;
}