aboutsummaryrefslogtreecommitdiff
path: root/compiler/tests/verifier/expr_constexpr.good
blob: 60c816fa39264cef50808d23da976bbc88376d51 (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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

int num_a = -(-1);
int num_b = num_a;
int num_c = -2;
int num_d = +3;
int? none_value = none;
int? makeopt_1_value = makeopt 1;

bool c = :true or :false;
bool d = not :false;
bool e = not c;
int f = :false then 0xBAD else 123;
int g = d and not e then 456 else 0xBAD;

// All these should be true
bool cmp_a = 1 < 2;
bool cmp_b = -3 < 2;
bool cmp_c = 1 > -2;
bool cmp_d = -1 > -2;
bool cmp_e = 10 > 9;
bool cmp_f = 1234 > 999;
bool cmp_g = 999 < 1234;
bool cmp_h = -1234 < -999;
bool cmp_i = -999 > -1234;

// These should also be true
bool cmp_op_a = 1 < 2;
bool cmp_op_b = 1 <= 1;
bool cmp_op_c = 3 > 2;
bool cmp_op_d = 2 >= 2;

// These shohuld be true
bool eq_op_a = 123 == 122+1;
bool eq_op_b = -123 == -124+1;
bool eq_op_c = -123 == -123;
bool eq_op_d = 0-123 == -123;
bool eq_op_e = none_value == none;
bool eq_op_f = makeopt_1_value == makeopt 1;
bool neq_op_a = 123 != 12;
bool neq_op_b = -123 != -45;
bool neq_op_c = none_value != makeopt 1;
bool neq_op_d = none_value != makeopt_1_value;
bool neq_op_e = makeopt_1_value != none;

int add_a = 0 + 0;
int add_b = 0 + 1;
int add_c = 1 + 0;
int add_d = 1 + 1;
int add_e = 01 + 01;
int add_f = 123 + 456;
int add_g = 0123 + 000456;
long add_i = 99999 + 3;
long add_j = 1 + 99999;
long add_k = 12 + 99999;
long add_l = 23457 + 99999;
int add_m = 999 + 0;
int add_n = 999 + 000;
int add_o = 999 + 0001;
long add_p = 000999 + 0001;
int add_q = 00000 + 000;

int sub_a = 0 - 0;
int sub_b = 2 - 2;
int sub_c = 6 - 1;
int sub_d = 02 - 01;
int sub_e = 579 - 456;
int sub_f = 1000 - 1;
int sub_g = 1000 - 877;
int sub_h = 3333 - 4567;
int sub_i = 1 - 999;

int addneg_a = 1 + -1;
int addneg_b = -0 + -0;
int addneg_c = 1 + (-2);
int addneg_d = 3 + (-1);
int addneg_e = (-2) + 5;
int addneg_g = (-6) + 2;
int addneg_h = (-3) + (-2);
int addneg_i = (-2) + (-4);

int subneg_a = 0 - -0;
int subneg_b = -0 - 0;
int subneg_c = 1 - 0;

int subneg_d = 0 - (-2);
int subneg_e = 2 - (-1);
int subneg_f = (-3) - 1;
int subneg_g = (-1) - 4;
int subneg_h = (-9) - (-3);
int subneg_i = (-1) - (-8);

int nested_a = 1+2+3;
int nested_b = -(2+3);
int nested_c = -(-(1+3));
int nested_d = -(-(1+3)) - 1;

uint bitand_a = 1 bitand 2;
uint bitand_b = 0x3 bitand 0x101;
uint16 bitor_a = 0x5678 bitor 0x1234;
uint16 bitor_b = 0x5678 bitor 1234;
uint bitxor_a = 0 bitxor 1;
uint bitxor_b = 0_1 bitxor 0x1;
uint bitxor_c = 1_2 bitxor 0x12__3;
uint16 shiftl_a = 1 << 0;
uint16 shiftl_b = 3 << 14;
uint16 shiftl_d = 0x7fff_ << 1;
uint16 shiftr_a = 1 >> 0;
uint16 shiftr_b = 1 >> 1;
uint16 shiftr_c = 100 >> 1;
uint16 shiftr_d = 0xf__fff_ >> 3;
uint16 shiftr_e = 0xffff >> 1_5;

float float_nan = NaN;
float float_inf = inf;
// TODO more implement calculations with floating point in constexprs

int first = second;
int second = 2;

int#[4] arr_flat = [11, 22, 33, 44];
int#[2,2] arr_nested = [[11, 12], [21, 22]];
int arr_a = arr_flat#[0];
int arr_b = arr_flat#[3];
int arr_c = arr_nested#[0,0];
int arr_d = arr_nested#[0,1];
int arr_e = arr_nested#[1,0];
int arr_f = arr_nested#[1,1];

char+> str = "test\xFF";
char str1 = 1 + str#[0];
char strN = str#[4];

int mixed_a = 2 + num_c;
int mixed_b = add_c;
int mixed_c = add_c + 1;
int mixed_d = add_c - num_c;
int mixed_e = -(1+0) - num_c + 3;
int mixed_f = -add_c - num_c + 4;

typedef EnumType1 = int enum (
    x = 2,
    y,
    z,
);
EnumType1 et1 = :y;
int et2 = enumbase EnumType1:x;

typedef StructType1 = (int x, int y);
StructType1 st1 = (12, 34);
int st2 = st1.x;
int st3 = st1.y;
// TODO more tests

() test() {
    var int changed = 3;
    changed = 5;
    int a = changed; // should not be constexpr-evaluated
}