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
|
linkname "";
import int memset(var any ^obj, int value, count len);
var int state = 0;
byte runonce(byte expected)
{
if state != 0 return 99;
state = 1;
return expected;
}
() without_temporaries() {
// These should not require temporaries
var int mixed;
int i = 123;
byte b = 1;
mixed = i + b;
assert mixed == 124;
}
int main()
{
int#[2,3] arr1 = [[11,12,13], [24,25,26]];
var int#[2,3] arr2;
without_temporaries();
{
// just a check that temporaries are allocated
// correctly in nested statements
arr2 = arr1;
}
arr2 = arr1;
assert arr2#[0,0] == 11;
assert arr2#[1,2] == 26;
assert arr1 == arr2; // tests both equality and the comparison operator
assert not (arr1 != arr2);
{
state = 0;
byte#[3]? a = makeopt [1,runonce(2),3];
state = 0;
byte#[3]? b = makeopt [1,runonce(2),3];
assert a?#[0] == 1;
assert a?#[1] == 2;
assert a?#[2] == 3;
assert a != none;
assert not a == none;
assert a == b;
assert not a != b;
assert a? == b?;
assert not a? != b?;
}
{
var (byte x, int y, (int zz) z, int#[3] arr) value;
typedef Struct1 = (byte x, int, (int zz) z, int#[3]);
var (byte, int y, (int zz), int#[3]) a;
var (byte, int y, (int zz), int#[3]) b;
var Struct1 c;
// Use memset to make two different struct values with
// different data in the padding
memset(@value, 0xFF, sizeof value);
value.x = 123;
value.y = 456;
value.z = (678,);
value.arr = [1111,2222,3333];
a = value;
memset(@value, 0x00, sizeof value);
value.x = 123;
value.y = 456;
value.z = (678,);
value.arr = [1111,2222,3333];
b = value;
// Comparison with exactly the same type
assert a == a;
assert not a != a;
assert a == b;
assert b == a;
assert not a != b;
assert not b != a;
// Comparison with a compatible type
c = value;
assert a == c;
assert c == a;
assert not a != c;
assert not c != a;
}
// TODO test zero-length arrays and empty structs also?
return 0;
}
|