blob: c85a94aa0dcc4f35e5b56ec974a7aa417732bc71 (
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
|
Point ::= struct {
x, y: float;
}
sqrt ::= fn(x: float) a := x/2 {
for _ := 0..20 {
a = (x + a * a) / (2 * a);
}
}
normalize ::= fn(use p: &Point) {
sqdist := x * x + y * y;
one_over_dist := 1/sqrt(sqdist);
x *= one_over_dist;
y *= one_over_dist;
}
printf ::= #foreign("printf", "libc.so.6") fn(#C &"const char", #C ..);
main ::= fn() {
use p: Point;
x = 10;
y = 20;
normalize(&p);
fmt := "%f %f\n\0";
printf(&fmt[0], p.x, p.y);
ps: [10]Point;
ps[0].x = 12;
ps[7].y = 13;
for p := &ps {
use p;
printf(&fmt[0], x, y);
}
}
|