aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/test.cff
blob: be6cb95a73550bc4c6aaf366ed1dff08bcd2221a (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import "libc.hff";
import "libc.hff";
union Val {
   x i64,
   lo i32,
   y f64,
}

enum Color {
   Red, Green, Blue
}

defmacro arraylength(ary) [ (sizeof(ary)/sizeof(ary[0])) ] 
defmacro each(i, x, arr, ...body) [
   for let i = 0; i < arraylength(arr); ++i {
      let x = arr[i];
      { body }
   }
]

static xs *void = {},
      ok = 6;

fn isort(xs *int, n usize) void  {
   fn icmp(lhs *const void, rhs *const void, _ *void) int {
      let lhs = *as(*int)lhs,
          rhs = *as(*int)rhs;
      return lhs - rhs;
   }
   qsort(xs, n, 4, &icmp);

   fn foo() void {}
   let x= &foo;
   x();
}

struct Vec2f;
struct Vec2f {
   x f32,
   y f32,

   fn mag(v Vec2f) f32 {
      extern fn sqrtf(_ f32) f32;
      return sqrtf((v.x * v.x) + (v.y * v.y));
   }
   fn zero(v *Vec2f) void {
      v.x = 0;
      v.y = 0;
   }
}

extern fn main (argc int, argv **u8) int {

   let colors [3]Color = { :Red, :Green, :Blue } ;
   let x = Vec2f { .y: 1, .x: 2.4 };
   let p *const Vec2f = &x;
   printf("v = { %g, %g }\n", x.x, p.y);
   printf("mag = %g\n", x->mag());
   x->zero();
   printf("mag = %g\n", (&x)->mag());

   let is []int = { [4] = 1, 2, [1 - 1] = 3 };
   isort(is, arraylength(is));
   each(i, x, is,
      printf("%d\n", x);
   )

   printf("sizeof(is) = %zu\n", sizeof(is));
   printf("sizeof *void = %zu\n", sizeof *void);


   return 0;
}