-
Notifications
You must be signed in to change notification settings - Fork 4
/
structureDeclarationTest.aec
162 lines (144 loc) · 4.59 KB
/
structureDeclarationTest.aec
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
159
160
161
162
/*
* This is a nonsense program to test whether structures are compiled
* correctly.
*/
Structure Point Consists Of {
Integer16 dimensions : = 3;
Decimal32 x, y, z;
}
EndStructure;
Integer32 a : = 0;
InstantiateStructure Point points[12];
Integer32 b : = 1;
Structure String Consists Of {
Integer32 length;
Character string[16];
}
EndStructure;
InstantiateStructure String helloWorld;
Integer32 c : = 2;
Function foo() Which Returns Integer16 Does {
// Should return 3.
Return points[c].dimensions;
}
EndFunction;
Function strlen(CharacterPointer string) Which Returns Integer32 Does {
Return(ValueAt(string) = 0) ? (0) : (1 + strlen(string + 1));
}
EndFunction;
Function strcpy(CharacterPointer dest,
CharacterPointer src) Which Returns Nothing Does {
While ValueAt(src) Loop {
ValueAt(dest) : = ValueAt(src);
dest += 1;
src += 1;
}
EndWhile;
ValueAt(dest) : = 0;
}
EndFunction;
Function bar() Which Returns Integer32 Does {
// Should return 12.
CharacterPointer hw : = "Hello world!";
strcpy(AddressOf(helloWorld.string[0]), hw);
helloWorld.length : = strlen(hw);
Return helloWorld.length;
}
EndFunction;
Function spam() Which Returns Integer32 Does {
// Should return 3.
InstantiateStructure Point localPoints[3];
Return localPoints[b].dimensions;
}
EndFunction;
Function eggs() Which Returns Integer32 Does {
// Should return 3.
InstantiateStructure Point localPoint;
Return localPoint.dimensions;
}
EndFunction;
Structure innerStructure Consists Of { Integer32 innerNumber : = 1; }
EndStructure;
Structure outerStructure Consists Of {
Integer32 outerNumber : = 2;
innerStructure structureWithInnerNumber;
innerStructure arrayOfInnerStructures[2];
innerStructurePointer structurePointer;
}
EndStructure;
InstantiateStructure outerStructure globalNestedStructure;
Function onion() Which Returns Integer32 Does {
// Should return 1.
InstantiateStructure outerStructure nestedStructure,
copyOfTheNestedStructure : = nestedStructure;
Return(nestedStructure.structureWithInnerNumber.innerNumber =
globalNestedStructure.structureWithInnerNumber
.innerNumber and nestedStructure.outerNumber =
2 and globalNestedStructure.outerNumber =
2 and copyOfTheNestedStructure.structureWithInnerNumber
.innerNumber = 1 and copyOfTheNestedStructure
.arrayOfInnerStructures[1]
.innerNumber = 1);
}
EndFunction;
Function copyString(StringPointer destination,
StringPointer source) Which Returns Nothing Does {
ValueAt(destination).length : = ValueAt(source).length;
Integer32 i : = 0;
While i < ValueAt(source).length Loop {
ValueAt(destination).string[i] : = ValueAt(source).string[i];
i += 1;
}
EndWhile;
}
EndFunction;
Function pomegranate() Which Returns Integer32 Does {
// Should return 12.
CharacterPointer hw : = "Hello world!";
strcpy(AddressOf(helloWorld.string[0]), hw);
helloWorld.length : = strlen(hw);
InstantiateStructure String localString;
copyString(AddressOf(localString), AddressOf(helloWorld));
InstantiateStructure String copyOfLocalString : = localString;
Return copyOfLocalString.length;
}
EndFunction;
Structure ListNode Consists Of {
ListNodePointer next;
Integer32 value;
}
EndStructure;
Function spaghetti() Which Returns Integer32 Does {
// https://stackoverflow.com/questions/63951270/using-default-copy-constructor-corrupts-a-tree-in-c
// By common sense, this should return 2. By C++ semantics, this should
// return 3.
InstantiateStructure ListNode list[3];
list[0].value : = 1;
list[1].value : = 2;
list[2].value : = 3;
list[0].next : = AddressOf(list[1]);
list[1].next : = AddressOf(list[2]);
list[0] : = ValueAt(list[0].next);
CharacterPointer pointer : = AddressOf(list[0]);
Return ValueAt(ListNodePointer(pointer)).value;
}
EndFunction;
Function elephant() Which Returns Integer32 Does {
// Should return 1.
Return(SizeOf(outerStructure) = SizeOf(Integer32) +
3 * SizeOf(innerStructure) +
SizeOf(innerStructurePointer));
}
EndFunction;
ListNodePointer globalStructurePointer, globalStructurePointerArray[2];
Function arrow() Which Returns Integer32 Does {
// Should return 2.
InstantiateStructure ListNode node[2];
node[0].value : = 1;
node[0].next : = AddressOf(node[1]);
node[1].value : = 2;
ListNodePointer ptr : = AddressOf(node[0]), localPointerArray[2];
ptr += 1;
Return(ptr->value);
}
EndFunction