aboutsummaryrefslogtreecommitdiff
path: root/test/3.cff
blob: 7d73db65c67148d757267dc8fe5a28eea9a14da5 (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
import "libc.hff";

bitfield ColorMaskFlags : u32 {
   red 1 bool,
   green 1 bool,
   blue 1 bool,
   alpha 1 bool,
   id (8,3),
};

struct Foo {
   x int,
   y f32,
   z union { p *void, i int },
   h enum union { fa, ga *void },
}
static foo Foo = { .z: { .i: 42 }, .h: :ga(&stderr) };

fn sum(res int, ...) int {
   let ap va_list = {};
   ap->start();
   printf("%d ", res);
   for ;; {
      let n = ap->arg(int);
      printf("+ %d ", n);
      res += n;
      if n == 0 { break; }
   }
   ap->end();
   return res;
}

extern fn main(argc int, argv **u8) int {
   printf("= %d\n", sum(1,2,3,42,-1,0));
   let rgb  = ColorMaskFlags { .red: #t, .blue: #t, .id: 13};
   printf("0x%X\n", rgb.#raw);
   printf("%d %p\n", foo.z.i, foo.h.ga);
}