aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/test2.cff
blob: c9ef3c9f2d1886fa6eb00d352c57df1e7c4547af (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import "libc.hff";

struct Node<T> {
   link *Node,
   value T,

   fn ok(self Node) void {
   }
}

struct Array<T, N usize> {
   m [N]T,
}

def X = 7 + 2;

struct Bit<T> {
   def Z = 3;
   fn foo(x T) T { return (~x ^ X) + Z; }
   // fn foo(x T) T { return ~x + Y; }
}

defmacro def2(x, v) [static x = (v)]

def2(Y, 3.3);

enum union Value {
   None,
   Int i32,
   Flo f32,
}

enum union Option<T> {
   None,
   Some T
}

extern fn main() void {
   let n Node<int> = {#null, 0};
   let n Node<int> = {&n, 1};
   let x Array<int, 10> = {};
   let x Array<int, 0xB - 1> = x;

   let x int #?;
   x = X + 1 + Y;

   let const v= Value:None;
   switch v {
   case None;
   case Int i;
      i;
   case Flo *f;
      let x f32 = *f;
   }
   let t = v.#tag;
   let i = v.Int;
   // v.#tag++;

   #'outer for let i = 0; i++ < 10; {
      printf("%d\n", i);
      while #t {
         if i < 2 {
            continue #'outer;
         }
         break #'outer;
      }
   }

   let x = Option<f32>:None;
   let x = Option<int>:Some(42);
   switch (do x;) {
   case None;
      printf("x empty\n");
   case Some i;
      printf("x by value %d\n", i);
   }
   switch x {
   case None;
      printf("x empty\n");
   case Some *i;
      printf("x by ptr %d\n", *i);
   }

   printf("n %d\n", n.value);
   printf("n li"
          "nk %d\n", n.link.value);


   let x Node<f32> = {};
   n->ok();
   x->ok();

   Bit<i32>:foo(3);
   Bit<i64>:foo(3);
}