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
|
namespace;
include rt;
// growable arrays of the sized types and f32: u8[?], i16[?], f32[?]
fn put_f(x) { asm { x @ #1220 } return 0; }
fn sp() { rt.put_c(32); return 0; }
fn main() {
u8[?] b = rt.new(u8[?], 0);
i16[?] h = rt.new(i16[?], 3);
f32[?] f = rt.new(f32[?], 0);
int i = 0, s = 0;
while (i < 100) { push(b, i * 7); i++; }
i = 0;
while (i < 100) { s = s + b[i]; i++; }
rt.put_n(len(b)); sp(); rt.put_n(s); sp(); rt.put_n(b[99]); sp();
b[5] = 300; rt.put_n(b[5]); sp();
rt.put_n(pop(b)); sp(); rt.put_n(len(b)); sp();
h[0] = 40000; h[2] = 0 - 5; push(h, 70000);
rt.put_n(h[0]); sp(); rt.put_n(h[1]); sp(); rt.put_n(h[2]); sp(); rt.put_n(h[3]); sp();
push(f, 0.1); push(f, 2.5); push(f, 1.0);
rt.put_n(f[0] == 0.1); sp(); put_f(f[1]); sp(); put_f(f[0] + f[2]); sp();
resize(b, 3); resize(b, 12);
rt.put_n(b[2]); rt.put_n(b[3]); rt.put_n(b[11]); sp();
rt.put_n(cap(b) >= 12);
rt.put_c(10);
rt.free(d*b); rt.free(d*h); rt.free(d*f);
second();
return 0;
}
o3 int sumv(u8[?] v) {
int s = 0;
for (int i = 0; i < len(v); i++) s += v[i];
return s;
}
fn second() {
u8[?] v = rt.new(u8[?], 0);
int i = 0;
while (i < 300) { push(v, i); i++; }
rt.put_n(sumv(v)); rt.put_c(10);
rt.free(d*v);
return 0;
}
|