forked from c2lang/c2compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
typetest.c2
120 lines (93 loc) · 1.7 KB
/
typetest.c2
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
module type_test;
import utils;
// -- Base types --
public type Number i32;
public type String const u8*;
// -- pointer types --
type PNum i32*;
type PPNum i32**;
type Pnum2 volatile Number*;
// -- array types --
type IntArr i32[20];
type IntArrArr i32[5][5];
type PArr i32*[10];
type Point i32; // TEMP
type Buffer i32; // TEMP
type Coor utils.Point[2];
type MyType utils.Buffer*[2];
// -- struct types --
type Struct struct {
}
type S3 struct {
i32[100] data;
i32[12][12] board;
i32 count;
utils.Buffer bb;
}
type S4 struct {
struct {
i32 a;
i32 b;
}
struct named {
i32 c;
i32 d;
}
}
type S2 struct {
i32 n;
union choice {
i32 b;
}
union oneOf {
i32 a;
}
volatile u32 count;
const i32 D;
}
type Data union {
i32 bla;
const char* text;
u32 number;
}
// -- ENUMS --
type Enum1 enum u8 {
VAR1, VAR2, VAR3,
}
type Enum2 enum i32 {
VARB1 = 1, VARB2 = 5, VARB3 = 10
}
type Enum3 enum u32 {
VARC1 = 1, VARC2 = 5,
}
type Enum4 enum u32 {
VAR1D
, VARD2 = 10
, VARD3,
VARD4
}
f32 pi = 3.1415926;
// -- Function --
type CallBack func i32(i32 a, utils.Point*p);
type CBFunc func void (MyType* mt, ...);
type CBFunc2 func void (const char* buffer, u8 t2, ...);
func void test1(i32 n) {}
func void test2(i32 n) {}
type Func1 func void(i32 a);
type Func2 func void(i32 a);
type Callback struct {
Func1 cb;
}
func void myfunc(i32 a, ...) {}
func void myfunc2(i32 a = 10, i32 b = 20) {}
public func i32 main() {
Func1 f = test1;
Func2 g = test2;
f = g; // ok
Func2 h = test2;
f = h; // ok
f(20);
myfunc(10, 20, 30, 40);
myfunc2();
return 0;
}