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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
program terecs6;
{$mode delphi}
{$apptype console}
uses
SysUtils;
type
TFoo = record
F: Integer;
class operator Explicit(a: TFoo): Integer;
class operator Implicit(a: TFoo): Integer;
class operator Equal(a, b: TFoo): Boolean;
class operator NotEqual(a, b: TFoo): Boolean;
class operator In(a, b: TFoo): Boolean;
class operator GreaterThan(a, b: TFoo): Boolean;
class operator GreaterThanOrEqual(a, b: TFoo): Boolean;
class operator LessThan(a, b: TFoo): Boolean;
class operator LessThanOrEqual(a, b: TFoo): Boolean;
class operator Add(a, b: TFoo): Integer;
class operator Subtract(a, b: TFoo): Integer;
class operator Multiply(a, b: TFoo): Integer;
class operator Divide(a, b: TFoo): Integer;
class operator IntDivide(a, b: TFoo): Integer;
class operator Modulus(a, b: TFoo): Integer;
class operator LeftShift(a, b: TFoo): Integer;
class operator RightShift(a, b: TFoo): Integer;
class operator LogicalOr(a, b: TFoo): Boolean;
class operator LogicalAnd(a, b: TFoo): Boolean;
class operator LogicalXor(a, b: TFoo): Boolean;
class operator LogicalNot(a: TFoo): TFoo;
class operator BitwiseOr(a, b: TFoo): TFoo;
class operator BitwiseAnd(a, b: TFoo): TFoo;
class operator BitwiseXor(a, b: TFoo): TFoo;
class operator Inc(a: TFoo): TFoo;
class operator Dec(a: TFoo): TFoo;
end;
class operator TFoo.Explicit(a: TFoo): Integer;
begin
// to check the difference with implicit
Result := a.F + 1;
end;
class operator TFoo.Implicit(a: TFoo): Integer;
begin
Result := a.F;
end;
class operator TFoo.Equal(a, b: TFoo): Boolean;
begin
Result := a.F = b.F;
end;
class operator TFoo.NotEqual(a, b: TFoo): Boolean;
begin
Result := a.F <> b.F;
end;
class operator TFoo.In(a, b: TFoo): Boolean;
begin
Result := a.F in [0..b.F];
end;
class operator TFoo.GreaterThan(a, b: TFoo): Boolean;
begin
Result := a.F > b.F;
end;
class operator TFoo.GreaterThanOrEqual(a, b: TFoo): Boolean;
begin
Result := a.F >= b.F;
end;
class operator TFoo.LessThan(a, b: TFoo): Boolean;
begin
Result := a.F < b.F;
end;
class operator TFoo.LessThanOrEqual(a, b: TFoo): Boolean;
begin
Result := a.F <= b.F;
end;
class operator TFoo.Add(a, b: TFoo): Integer;
begin
Result := a.F + b.F;
end;
class operator TFoo.Subtract(a, b: TFoo): Integer;
begin
Result := a.F - b.F;
end;
class operator TFoo.Multiply(a, b: TFoo): Integer;
begin
Result := a.F * b.F;
end;
class operator TFoo.Divide(a, b: TFoo): Integer;
begin
Result := Round(a.F / b.F);
end;
class operator TFoo.IntDivide(a, b: TFoo): Integer;
begin
Result := a.F div b.F;
end;
class operator TFoo.Modulus(a, b: TFoo): Integer;
begin
Result := a.F mod b.F;
end;
class operator TFoo.LeftShift(a, b: TFoo): Integer;
begin
Result := a.F shl b.F;
end;
class operator TFoo.RightShift(a, b: TFoo): Integer;
begin
Result := a.F shr b.F;
end;
class operator TFoo.LogicalOr(a, b: TFoo): Boolean;
begin
Result := (a.F or b.F) <> 0;
end;
class operator TFoo.LogicalAnd(a, b: TFoo): Boolean;
begin
Result := (a.F and b.F) <> 0;
end;
class operator TFoo.LogicalXor(a, b: TFoo): Boolean;
begin
Result := (a.F xor b.F) <> 0;
end;
class operator TFoo.LogicalNot(a: TFoo): TFoo;
begin
Result.F := not a.F;
end;
class operator TFoo.BitwiseOr(a, b: TFoo): TFoo;
begin
Result.F := a.F or b.F;
end;
class operator TFoo.BitwiseAnd(a, b: TFoo): TFoo;
begin
Result.F := a.F and b.F;
end;
class operator TFoo.BitwiseXor(a, b: TFoo): TFoo;
begin
Result.F := a.F xor b.F;
end;
class operator TFoo.Inc(a: TFoo): TFoo;
begin
Result.F := a.F + 1;
end;
class operator TFoo.Dec(a: TFoo): TFoo;
begin
Result.F := a.F - 1;
end;
var
a, b: TFoo;
i: integer;
begin
a.F := 1;
b.F := 2;
if a = b then
halt(1);
if not (a <> b) then
halt(2);
if not (a in b) then
halt(3);
if (b in a) then
halt(4);
if a > b then
halt(5);
if a >= b then
halt(6);
if not (a < b) then
halt(7);
if not (a <= b) then
halt(8);
if a * b <> 2 then
halt(9);
if a / b <> 0 then
halt(10);
if a div b <> 0 then
halt(11);
if a mod b <> 1 then
halt(12);
if a shl b <> 4 then
halt(13);
if b shr a <> 1 then
halt(14);
if a + b <> 3 then
halt(15);
if a - b <> -1 then
halt(16);
if not (a or b) then
halt(17);
if a and b then
halt(18);
if not (a xor b) then
halt(19);
if (not a).F <> (not 1) then
halt(20);
{ bitwise operators current does not work if logical are defined
if (a or b).F <> (a.F or b.F) then
halt(21);
if (a and b).F <> (a.F and b.F) then
halt(22);
if (a xor b).F <> (a.F xor b.F) then
halt(23);
}
inc(a);
if a.F <> 2 then
halt(24);
dec(b);
if b.F <> 1 then
halt(25);
i := b;
if i <> 1 then
halt(26);
if Integer(b) <> 2 then
halt(27);
WriteLn('ok');
end.
|