author | Stefan Vogel <sv@exept.de> |
Tue, 17 Apr 2012 14:06:09 +0200 | |
changeset 660 | ef75857fce73 |
parent 659 | 2d1c408743da |
child 668 | 9481f512e9b8 |
permissions | -rw-r--r-- |
69 | 1 |
"{ Package: 'exept:regression' }" |
61 | 2 |
|
70 | 3 |
"{ NameSpace: RegressionTests }" |
4 |
||
113 | 5 |
TestCase subclass:#CompilerTest |
61 | 6 |
instanceVariableNames:'value' |
47 | 7 |
classVariableNames:'' |
8 |
poolDictionaries:'' |
|
181 | 9 |
category:'tests-Regression' |
47 | 10 |
! |
11 |
||
188 | 12 |
Object subclass:#DummyClass |
13 |
instanceVariableNames:'applicationModel service request' |
|
14 |
classVariableNames:'' |
|
15 |
poolDictionaries:'' |
|
16 |
privateIn:CompilerTest |
|
17 |
! |
|
18 |
||
577 | 19 |
Object subclass:#Schedule |
20 |
instanceVariableNames:'state' |
|
21 |
classVariableNames:'' |
|
22 |
poolDictionaries:'' |
|
23 |
privateIn:CompilerTest |
|
24 |
! |
|
25 |
||
26 |
Object subclass:#State |
|
27 |
instanceVariableNames:'state' |
|
28 |
classVariableNames:'' |
|
29 |
poolDictionaries:'' |
|
30 |
privateIn:CompilerTest::Schedule |
|
31 |
! |
|
32 |
||
33 |
||
34 |
!CompilerTest class methodsFor:'helpers'! |
|
35 |
||
36 |
compile:code |
|
37 |
Error handle:[:ex | |
|
648 | 38 |
^ #Error |
577 | 39 |
] do:[ |
648 | 40 |
^ super compile:code |
577 | 41 |
] |
42 |
! ! |
|
47 | 43 |
|
88 | 44 |
!CompilerTest class methodsFor:'tests - constants'! |
45 |
||
46 |
test_int1024 |
|
47 |
^ 1024 |
|
48 |
||
49 |
" |
|
50 |
self test_int1024 |
|
51 |
" |
|
52 |
||
53 |
! |
|
54 |
||
55 |
test_int1048576 |
|
56 |
^ 1048576 |
|
57 |
! |
|
58 |
||
59 |
test_int128 |
|
60 |
^ 128 |
|
61 |
||
62 |
" |
|
63 |
self test_int128 |
|
64 |
" |
|
65 |
! |
|
66 |
||
67 |
test_int131072 |
|
68 |
^ 131072 |
|
69 |
! |
|
70 |
||
71 |
test_int16384 |
|
72 |
^ 16384 |
|
73 |
||
74 |
" |
|
75 |
self test_int16384 |
|
76 |
" |
|
77 |
||
78 |
! |
|
79 |
||
80 |
test_int2048 |
|
81 |
^ 2048 |
|
82 |
||
83 |
" |
|
84 |
self test_int2048 |
|
85 |
" |
|
86 |
||
87 |
! |
|
88 |
||
89 |
test_int2097152 |
|
90 |
^ 2097152 |
|
91 |
! |
|
92 |
||
93 |
test_int256 |
|
94 |
^ 256 |
|
95 |
||
96 |
" |
|
97 |
self test_int256 |
|
98 |
" |
|
99 |
||
100 |
! |
|
101 |
||
102 |
test_int262144 |
|
103 |
^ 262144 |
|
104 |
! |
|
105 |
||
106 |
test_int32768 |
|
107 |
^ 32768 |
|
108 |
||
109 |
" |
|
110 |
self test_int32768 |
|
111 |
" |
|
112 |
||
113 |
! |
|
114 |
||
115 |
test_int4096 |
|
116 |
^ 4096 |
|
117 |
||
118 |
" |
|
119 |
self test_int4096 |
|
120 |
" |
|
121 |
||
122 |
! |
|
123 |
||
124 |
test_int512 |
|
125 |
^ 512 |
|
126 |
||
127 |
" |
|
128 |
self test_int512 |
|
129 |
" |
|
130 |
||
131 |
! |
|
132 |
||
133 |
test_int524288 |
|
134 |
^ 524288 |
|
135 |
! |
|
136 |
||
137 |
test_int65536 |
|
138 |
^ 65536 |
|
139 |
||
140 |
" |
|
141 |
self test_int65536 |
|
142 |
" |
|
143 |
||
144 |
! |
|
145 |
||
146 |
test_int8192 |
|
147 |
^ 8192 |
|
148 |
||
149 |
" |
|
150 |
self test_int8192 |
|
151 |
" |
|
152 |
||
153 |
! |
|
154 |
||
155 |
test_intM128 |
|
156 |
^ -128 |
|
157 |
! ! |
|
158 |
||
77 | 159 |
!CompilerTest class methodsFor:'tests argument passing'! |
160 |
||
161 |
ret0 |
|
162 |
^ 0 |
|
163 |
||
164 |
" |
|
165 |
self ret0 |
|
648 | 166 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self ret0] ] |
77 | 167 |
" |
168 |
! |
|
169 |
||
170 |
ret1 |
|
171 |
^ 1 |
|
172 |
||
173 |
" |
|
174 |
self ret1 |
|
78 | 175 |
1000000 timesRepeat:[self ret1] |
648 | 176 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self ret1] ] |
78 | 177 |
" |
178 |
! |
|
179 |
||
180 |
retArg1:arg |
|
181 |
^ arg |
|
182 |
||
183 |
" |
|
184 |
self retArg1:1 |
|
185 |
1000000 timesRepeat:[self retArg1:1] |
|
186 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retArg1:1] ] |
|
187 |
" |
|
188 |
! |
|
189 |
||
190 |
retArg2:arg1 _:arg2 |
|
191 |
^ arg2 |
|
192 |
||
193 |
" |
|
648 | 194 |
self retArg2:1 _:2 |
78 | 195 |
1000000 timesRepeat:[self retArg2:1 _:2] |
648 | 196 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retArg2:1 _:2] ] |
78 | 197 |
" |
198 |
! |
|
199 |
||
200 |
retArg3:arg1 _:arg2 _:arg3 |
|
201 |
^ arg3 |
|
202 |
||
203 |
" |
|
648 | 204 |
self retArg3:1 _:2 _:3 |
205 |
1000000 timesRepeat:[self retArg3:1 _:2 _:3] |
|
206 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retArg3:1 _:2 _:3] ] |
|
78 | 207 |
" |
208 |
! |
|
209 |
||
210 |
retArg4:arg1 _:arg2 _:arg3 _:arg4 |
|
211 |
^ arg4 |
|
212 |
||
213 |
" |
|
648 | 214 |
self retArg4:1 _:2 _:3 _:4 |
215 |
1000000 timesRepeat:[self retArg4:1 _:2 _:3 _:4] |
|
216 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retArg4:1 _:2 _:3 _:4] ] |
|
78 | 217 |
" |
218 |
! |
|
219 |
||
79 | 220 |
retArg5:arg1 _:arg2 _:arg3 _:arg4 _:arg5 |
221 |
^ arg5 |
|
222 |
||
223 |
" |
|
648 | 224 |
self retArg5:1 _:2 _:3 _:4 _:5 |
225 |
1000000 timesRepeat:[self retArg5:1 _:2 _:3 _:4 _:5] |
|
226 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retArg5:1 _:2 _:3 _:4 _:5] ] |
|
79 | 227 |
" |
228 |
! |
|
229 |
||
78 | 230 |
retLiteral1 |
231 |
^ 'hello' |
|
232 |
||
233 |
" |
|
234 |
self retLiteral1 |
|
235 |
1000000 timesRepeat:[self retLiteral1] |
|
236 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retLiteral1] ] |
|
77 | 237 |
" |
238 |
! |
|
239 |
||
240 |
retM1 |
|
241 |
^ -1 |
|
242 |
||
243 |
" |
|
244 |
self retM1 |
|
78 | 245 |
1000000 timesRepeat:[self retM1] |
648 | 246 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retM1] ] |
77 | 247 |
" |
248 |
! |
|
249 |
||
250 |
retSelf |
|
251 |
^ self |
|
252 |
||
253 |
" |
|
254 |
self retSelf |
|
78 | 255 |
1000000 timesRepeat:[self retSelf] |
648 | 256 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self retSelf] ] |
77 | 257 |
" |
258 |
! ! |
|
259 |
||
587 | 260 |
!CompilerTest methodsFor:'cleanup'! |
261 |
||
262 |
tearDown |
|
263 |
self class removeSelector:#foo:. |
|
264 |
||
265 |
"Created: / 05-07-2011 / 18:20:08 / cg" |
|
266 |
! ! |
|
267 |
||
61 | 268 |
!CompilerTest methodsFor:'helpers'! |
269 |
||
568 | 270 |
callEnsureWith2Returns |
271 |
[ |
|
648 | 272 |
^ false |
568 | 273 |
] ensure:[ |
648 | 274 |
^ true |
568 | 275 |
]. |
276 |
^ nil |
|
277 |
||
278 |
"Created: / 24-08-2010 / 12:51:50 / cg" |
|
279 |
! |
|
280 |
||
569
e16012b59e29
added: #callEnsureWithException
Claus Gittinger <cg@exept.de>
parents:
568
diff
changeset
|
281 |
callEnsureWithException |
e16012b59e29
added: #callEnsureWithException
Claus Gittinger <cg@exept.de>
parents:
568
diff
changeset
|
282 |
[ |
660 | 283 |
ProceedableError raiseRequest |
569
e16012b59e29
added: #callEnsureWithException
Claus Gittinger <cg@exept.de>
parents:
568
diff
changeset
|
284 |
] ensure:[ |
660 | 285 |
^ true |
569
e16012b59e29
added: #callEnsureWithException
Claus Gittinger <cg@exept.de>
parents:
568
diff
changeset
|
286 |
]. |
e16012b59e29
added: #callEnsureWithException
Claus Gittinger <cg@exept.de>
parents:
568
diff
changeset
|
287 |
^ nil |
e16012b59e29
added: #callEnsureWithException
Claus Gittinger <cg@exept.de>
parents:
568
diff
changeset
|
288 |
|
e16012b59e29
added: #callEnsureWithException
Claus Gittinger <cg@exept.de>
parents:
568
diff
changeset
|
289 |
"Created: / 24-08-2010 / 12:54:07 / cg" |
e16012b59e29
added: #callEnsureWithException
Claus Gittinger <cg@exept.de>
parents:
568
diff
changeset
|
290 |
! |
e16012b59e29
added: #callEnsureWithException
Claus Gittinger <cg@exept.de>
parents:
568
diff
changeset
|
291 |
|
81 | 292 |
size |
293 |
^ 1 |
|
294 |
! |
|
295 |
||
61 | 296 |
value:something |
297 |
value := something |
|
298 |
! ! |
|
299 |
||
48 | 300 |
!CompilerTest methodsFor:'tests - booleans'! |
301 |
||
113 | 302 |
_testAnd:arg1 _:arg2 |
50 | 303 |
^ arg1 & arg2 |
304 |
||
305 |
" |
|
648 | 306 |
self new _testAnd:true _:true. |
307 |
self new _testAnd:true _:false. |
|
308 |
self new _testAnd:false _:true. |
|
309 |
self new _testAnd:false _:false. |
|
310 |
self new _testAnd:false _:nil. |
|
311 |
self new _testAnd:true _:nil. |
|
113 | 312 |
self new _testAnd:nil _:false. |
313 |
self new _testAnd:nil _:true. |
|
314 |
self new _testAnd:1234 _:true. |
|
315 |
self new _testAnd:1234 _:false. |
|
648 | 316 |
self new _testAnd:true _:1234. |
317 |
self new _testAnd:false _:1234. |
|
113 | 318 |
" |
319 |
! |
|
320 |
||
321 |
_testNot1:arg |
|
322 |
^ arg not |
|
323 |
||
324 |
" |
|
648 | 325 |
self new _testNot1:true. |
113 | 326 |
self new _testNot1:false. |
327 |
self new _testNot1:1234. |
|
50 | 328 |
" |
329 |
! |
|
330 |
||
113 | 331 |
_testNot2:arg1 _:arg2 |
332 |
^ arg1 not & arg2 not |
|
48 | 333 |
|
334 |
" |
|
648 | 335 |
self new _testNot2:true _:true. |
113 | 336 |
self new _testNot2:false _:true. |
337 |
self new _testNot2:true _:false. |
|
338 |
self new _testNot2:false _:false. |
|
339 |
||
340 |
self new _testNot2:false _:1234. |
|
341 |
self new _testNot2:true _:1234. |
|
342 |
self new _testNot2:1234 _:true. |
|
343 |
self new _testNot2:1234 _:false. |
|
344 |
self new _testNot2:1234 _:2345. |
|
345 |
" |
|
346 |
! |
|
347 |
||
348 |
_testNot3:arg1 _:arg2 |
|
349 |
^ arg1 not | arg2 not |
|
350 |
||
351 |
" |
|
648 | 352 |
self new _testNot3:true _:true. |
113 | 353 |
self new _testNot3:false _:true. |
354 |
self new _testNot3:true _:false. |
|
355 |
self new _testNot3:false _:false. |
|
356 |
||
357 |
self new _testNot3:false _:1234. |
|
358 |
self new _testNot3:true _:1234. |
|
359 |
self new _testNot3:1234 _:true. |
|
360 |
self new _testNot3:1234 _:false. |
|
361 |
self new _testNot3:1234 _:2345. |
|
48 | 362 |
" |
363 |
! |
|
364 |
||
113 | 365 |
_testOr:arg1 _:arg2 |
366 |
^ arg1 | arg2 |
|
48 | 367 |
|
368 |
" |
|
648 | 369 |
self new _testOr:true _:true. |
370 |
self new _testOr:true _:false. |
|
371 |
self new _testOr:false _:true. |
|
372 |
self new _testOr:false _:false. |
|
373 |
self new _testOr:false _:nil. |
|
374 |
self new _testOr:true _:nil. |
|
113 | 375 |
self new _testOr:nil _:false. |
376 |
self new _testOr:nil _:true. |
|
377 |
self new _testOr:1234 _:true. |
|
378 |
self new _testOr:1234 _:false. |
|
648 | 379 |
self new _testOr:true _:1234. |
380 |
self new _testOr:false _:1234. |
|
113 | 381 |
" |
382 |
! |
|
48 | 383 |
|
113 | 384 |
testAnd |
385 |
self assert:( ( self _testAnd:true _:true ) == true ). |
|
386 |
self assert:( ( self _testAnd:true _:false ) == false ). |
|
387 |
self assert:( ( self _testAnd:false _:true ) == false ). |
|
388 |
self assert:( ( self _testAnd:false _:false ) == false ). |
|
389 |
||
390 |
self assert:( ( self _testAnd:false _:nil ) == false ). |
|
391 |
self assert:( ( self _testAnd:true _:nil ) == nil ). |
|
392 |
self assert:( ( self _testAnd:false _:1234 ) == false ). |
|
393 |
self assert:( ( self _testAnd:true _:1234 ) == 1234 ). |
|
394 |
self should:[ self _testAnd:nil _:false ] raise:Error. |
|
395 |
self should:[ self _testAnd:nil _:true ] raise:Error. |
|
396 |
self should:[ self _testAnd:1234 _:false ] raise:Error. |
|
397 |
self should:[ self _testAnd:1234 _:true ] raise:Error. |
|
398 |
||
399 |
" |
|
400 |
self new testAnd |
|
48 | 401 |
" |
50 | 402 |
! |
403 |
||
113 | 404 |
testNot |
405 |
self assert:( ( self _testNot1:true ) == false ). |
|
406 |
self assert:( ( self _testNot1:false ) == true ). |
|
407 |
||
408 |
self should:[ self _testNot1:nil ] raise:Error. |
|
409 |
self should:[ self _testNot1:1234 ] raise:Error. |
|
410 |
||
411 |
||
412 |
self assert:( ( self _testNot2:true _:true) == false ). |
|
413 |
self assert:( ( self _testNot2:false _:true) == false ). |
|
414 |
self assert:( ( self _testNot2:true _:false) == false ). |
|
415 |
self assert:( ( self _testNot2:false _:false) == true ). |
|
416 |
||
417 |
self should:[ self _testNot2:false _:1234] raise:Error. |
|
418 |
self should:[ self _testNot2:true _:1234] raise:Error. |
|
419 |
self should:[ self _testNot2:1234 _:false] raise:Error. |
|
420 |
self should:[ self _testNot2:1234 _:true] raise:Error. |
|
421 |
self should:[ self _testNot2:1234 _:1234] raise:Error. |
|
422 |
self should:[ self _testNot2:nil _:false] raise:Error. |
|
423 |
self should:[ self _testNot2:nil _:true] raise:Error. |
|
424 |
self should:[ self _testNot2:nil _:1234] raise:Error. |
|
425 |
||
426 |
self assert:( ( self _testNot3:true _:true) == false ). |
|
427 |
self assert:( ( self _testNot3:false _:true) == true ). |
|
428 |
self assert:( ( self _testNot3:true _:false) == true ). |
|
429 |
self assert:( ( self _testNot3:false _:false) == true ). |
|
430 |
||
431 |
self should:[ self _testNot3:false _:1234] raise:Error. |
|
432 |
self should:[ self _testNot3:true _:1234] raise:Error. |
|
433 |
self should:[ self _testNot3:1234 _:false] raise:Error. |
|
434 |
self should:[ self _testNot3:1234 _:true] raise:Error. |
|
435 |
self should:[ self _testNot3:1234 _:1234] raise:Error. |
|
436 |
self should:[ self _testNot3:nil _:false] raise:Error. |
|
437 |
self should:[ self _testNot3:nil _:true] raise:Error. |
|
438 |
self should:[ self _testNot3:nil _:1234] raise:Error. |
|
50 | 439 |
|
440 |
" |
|
113 | 441 |
self new testNot |
442 |
" |
|
443 |
! |
|
444 |
||
445 |
testOr |
|
446 |
self assert:( ( self _testOr:true _:true ) == true ). |
|
447 |
self assert:( ( self _testOr:true _:false ) == true ). |
|
448 |
self assert:( ( self _testOr:false _:true ) == true ). |
|
449 |
self assert:( ( self _testOr:false _:false ) == false ). |
|
450 |
||
451 |
self assert:( ( self _testOr:false _:nil ) == nil ). |
|
452 |
self assert:( ( self _testOr:true _:nil ) == true ). |
|
453 |
self assert:( ( self _testOr:false _:1234 ) == 1234 ). |
|
454 |
self assert:( ( self _testOr:true _:1234 ) == true ). |
|
455 |
self should:[ self _testOr:nil _:false ] raise:Error. |
|
456 |
self should:[ self _testOr:nil _:true ] raise:Error. |
|
457 |
self should:[ self _testOr:1234 _:false ] raise:Error. |
|
458 |
self should:[ self _testOr:1234 _:true ] raise:Error. |
|
459 |
||
460 |
" |
|
461 |
self new testOr |
|
50 | 462 |
" |
48 | 463 |
! ! |
464 |
||
62 | 465 |
!CompilerTest methodsFor:'tests - conditions'! |
466 |
||
113 | 467 |
_testIf1:val |
62 | 468 |
|x| |
469 |
||
65 | 470 |
x := #foo. |
471 |
x := (val == #CursorRight or:[val == #CursorDown]) ifTrue:[1]. |
|
62 | 472 |
^ x |
473 |
||
474 |
" |
|
113 | 475 |
self new _testIf1:#CursorRight |
476 |
self new _testIf1:#CursorDown |
|
648 | 477 |
self new _testIf1:#Foo |
478 |
self new _testIf1:#CursorUp |
|
479 |
self new _testIf1:nil |
|
480 |
self new _testIf1:1 |
|
62 | 481 |
" |
63 | 482 |
! |
483 |
||
648 | 484 |
_testIf2:val |
63 | 485 |
|x| |
486 |
||
65 | 487 |
x := #foo. |
488 |
x := (val == #CursorRight or:[val == #CursorDown]) ifTrue:1. |
|
63 | 489 |
^ x |
490 |
||
491 |
" |
|
113 | 492 |
self new _testIf2:#CursorRight |
493 |
self new _testIf2:#CursorDown |
|
648 | 494 |
self new _testIf2:#Foo |
495 |
self new _testIf2:#CursorUp |
|
496 |
self new _testIf2:nil |
|
497 |
self new _testIf2:1 |
|
63 | 498 |
" |
65 | 499 |
! |
500 |
||
648 | 501 |
_testIf3:val |
65 | 502 |
|x| |
503 |
||
504 |
x := #foo. |
|
113 | 505 |
x := val isInteger ifTrue:1. |
65 | 506 |
^ x |
507 |
||
508 |
" |
|
113 | 509 |
self new _testIf3:#CursorRight |
510 |
self new _testIf3:#CursorDown |
|
648 | 511 |
self new _testIf3:#Foo |
512 |
self new _testIf3:#CursorUp |
|
513 |
self new _testIf3:nil |
|
514 |
self new _testIf3:1 |
|
65 | 515 |
" |
516 |
! |
|
517 |
||
648 | 518 |
_testIf4:val |
67 | 519 |
^ val isNil |
520 |
||
521 |
" |
|
648 | 522 |
self new _testIf4:#CursorRight |
523 |
self new _testIf4:1 |
|
524 |
self new _testIf4:nil |
|
67 | 525 |
" |
526 |
! |
|
527 |
||
648 | 528 |
_testIf4:val1 with:val2 |
113 | 529 |
^ val1 == nil and:[val2 == nil] |
66 | 530 |
|
531 |
" |
|
648 | 532 |
self new _testIf4:#CursorRight with:#CursorDown |
533 |
self new _testIf4:#CursorRight with:nil |
|
113 | 534 |
self new _testIf4:nil with:#CursorDown |
535 |
self new _testIf4:nil with:nil |
|
66 | 536 |
" |
537 |
! |
|
538 |
||
648 | 539 |
_testIf5:val |
113 | 540 |
^ val isNil ifTrue:[ |
648 | 541 |
1 |
113 | 542 |
] |
67 | 543 |
|
544 |
" |
|
648 | 545 |
self new _testIf5:#CursorRight |
546 |
self new _testIf5:1 |
|
547 |
self new _testIf5:nil |
|
67 | 548 |
" |
549 |
! |
|
550 |
||
648 | 551 |
_testIf5:val1 with:val2 |
113 | 552 |
^ val1 isNil and:[val2 isNil] |
66 | 553 |
|
554 |
" |
|
648 | 555 |
self new _testIf5:#CursorRight with:#CursorDown |
556 |
self new _testIf5:#CursorRight with:nil |
|
113 | 557 |
self new _testIf5:nil with:#CursorDown |
558 |
self new _testIf5:nil with:nil |
|
66 | 559 |
" |
560 |
! |
|
561 |
||
648 | 562 |
_testIf6:val |
67 | 563 |
^ val isNil ifTrue:1 |
564 |
||
565 |
" |
|
648 | 566 |
self new _testIf6:#CursorRight |
567 |
self new _testIf6:1 |
|
568 |
self new _testIf6:nil |
|
67 | 569 |
" |
570 |
! |
|
571 |
||
648 | 572 |
_testIf6b:val |
68 | 573 |
val isNil ifTrue:1 |
574 |
||
575 |
" |
|
648 | 576 |
self new _testIf6b:#CursorRight |
577 |
self new _testIf6b:1 |
|
578 |
self new _testIf6b:nil |
|
68 | 579 |
" |
580 |
! |
|
581 |
||
648 | 582 |
_testIf6c:val |
113 | 583 |
val isNil ifTrue:[ |
648 | 584 |
1 |
585 |
||
586 |
" |
|
587 |
self new _testIf6c:#CursorRight |
|
588 |
self new _testIf6c:1 |
|
589 |
self new _testIf6c:nil |
|
590 |
" |
|
113 | 591 |
] |
68 | 592 |
! |
593 |
||
648 | 594 |
_testIf6d:val |
68 | 595 |
^ val isNil ifTrue:val |
596 |
||
597 |
" |
|
648 | 598 |
self new _testIf6d:#CursorRight |
599 |
self new _testIf6d:1 |
|
600 |
self new _testIf6d:nil |
|
68 | 601 |
" |
602 |
! |
|
603 |
||
648 | 604 |
_testIf6e:val |
68 | 605 |
^ val isNil ifFalse:val |
606 |
||
607 |
" |
|
648 | 608 |
self new _testIf6e:['hello'] |
609 |
self new _testIf6e:('hello' asValue) |
|
610 |
self new _testIf6e:#CursorRight |
|
611 |
self new _testIf6e:1 |
|
612 |
self new _testIf6e:nil |
|
68 | 613 |
" |
614 |
! |
|
615 |
||
648 | 616 |
_testIf7:val |
67 | 617 |
^ val ? 1 |
618 |
||
619 |
" |
|
648 | 620 |
self new _testIf7:#CursorRight |
621 |
self new _testIf7:1 |
|
622 |
self new _testIf7:nil |
|
67 | 623 |
" |
624 |
! |
|
625 |
||
648 | 626 |
_testIfElse1:val |
65 | 627 |
|x| |
628 |
||
113 | 629 |
x := (val == #CursorRight or:[val == #CursorDown]) ifTrue:[ |
648 | 630 |
1 |
631 |
] ifFalse:[-1]. |
|
65 | 632 |
^ x |
633 |
||
634 |
" |
|
113 | 635 |
self new _testIfElse1:#CursorRight |
636 |
self new _testIfElse1:#CursorDown |
|
648 | 637 |
self new _testIfElse1:#Foo |
638 |
self new _testIfElse1:#CursorUp |
|
639 |
self new _testIfElse1:nil |
|
640 |
self new _testIfElse1:1 |
|
65 | 641 |
" |
642 |
! |
|
643 |
||
648 | 644 |
_testIfElse2:val |
65 | 645 |
|x| |
646 |
||
647 |
x := (val == #CursorRight or:[val == #CursorDown]) ifTrue:1 ifFalse:-1. |
|
648 |
^ x |
|
649 |
||
650 |
" |
|
113 | 651 |
self new _testIfElse2:#CursorRight |
652 |
self new _testIfElse2:#CursorDown |
|
648 | 653 |
self new _testIfElse2:#Foo |
654 |
self new _testIfElse2:#CursorUp |
|
655 |
self new _testIfElse2:nil |
|
656 |
self new _testIfElse2:1 |
|
65 | 657 |
" |
658 |
! |
|
659 |
||
648 | 660 |
_testIfElse3:val |
65 | 661 |
|x| |
662 |
||
663 |
x := (val == #CursorRight or:[val isInteger]) ifTrue:1 ifFalse:-1. |
|
664 |
^ x |
|
665 |
||
666 |
" |
|
648 | 667 |
self new _testIfElse3:#CursorRight |
668 |
self new _testIfElse3:#CursorDown |
|
669 |
self new _testIfElse3:#Foo |
|
670 |
self new _testIfElse3:#CursorUp |
|
671 |
self new _testIfElse3:nil |
|
672 |
self new _testIfElse3:1 |
|
65 | 673 |
" |
674 |
! |
|
675 |
||
648 | 676 |
_testIfElse4:val |
65 | 677 |
|x| |
678 |
||
679 |
x := #foo. |
|
113 | 680 |
x := val isInteger ifTrue:1 ifFalse:-1. |
65 | 681 |
^ x |
682 |
||
683 |
" |
|
648 | 684 |
self new _testIfElse4:#CursorRight |
685 |
self new _testIfElse4:#CursorDown |
|
686 |
self new _testIfElse4:#Foo |
|
687 |
self new _testIfElse4:#CursorUp |
|
688 |
self new _testIfElse4:nil |
|
689 |
self new _testIfElse4:1 |
|
65 | 690 |
" |
68 | 691 |
! |
692 |
||
648 | 693 |
_testIfElse5:val |
68 | 694 |
|x| |
695 |
||
696 |
x := #foo. |
|
697 |
x := val ifNil:1 ifNotNil:-1. |
|
698 |
^ x |
|
699 |
||
700 |
" |
|
648 | 701 |
self new _testIfElse5:#CursorUp |
702 |
self new _testIfElse5:nil |
|
703 |
self new _testIfElse5:1 |
|
68 | 704 |
" |
705 |
! |
|
706 |
||
648 | 707 |
_testIfElse6:val |
68 | 708 |
|x| |
709 |
||
710 |
x := #foo. |
|
711 |
x := val ifNil:[1] ifNotNil:[-1]. |
|
712 |
^ x |
|
713 |
||
714 |
" |
|
648 | 715 |
self new _testIfElse6:#CursorUp |
716 |
self new _testIfElse6:nil |
|
717 |
self new _testIfElse6:1 |
|
68 | 718 |
" |
719 |
! |
|
720 |
||
648 | 721 |
_testIfElse7:val with:val1 with:val2 |
68 | 722 |
|x| |
723 |
||
724 |
x := #foo. |
|
725 |
x := val ifNil:val1 ifNotNil:val2. |
|
726 |
^ x |
|
727 |
||
728 |
" |
|
648 | 729 |
self new _testIfElse7:#CursorUp with:1 with:2 |
730 |
self new _testIfElse7:nil with:1 with:2 |
|
731 |
self new _testIfElse7:1 with:1 with:2 |
|
113 | 732 |
" |
733 |
! |
|
734 |
||
735 |
testIf |
|
736 |
self assert:(self _testIf1:#CursorRight) == 1. |
|
737 |
self assert:(self _testIf1:#CursorDown) == 1. |
|
738 |
self assert:(self _testIf1:#Foo) == nil. |
|
739 |
self assert:(self _testIf1:#CursorUp) == nil. |
|
740 |
self assert:(self _testIf1:nil) == nil. |
|
741 |
self assert:(self _testIf1:1) == nil. |
|
742 |
||
743 |
self assert:(self _testIf2:#CursorRight) == 1. |
|
744 |
self assert:(self _testIf2:#CursorDown) == 1. |
|
745 |
self assert:(self _testIf2:#Foo) == nil. |
|
746 |
self assert:(self _testIf2:#CursorUp) == nil. |
|
747 |
self assert:(self _testIf2:nil) == nil. |
|
748 |
self assert:(self _testIf2:1) == nil. |
|
749 |
||
750 |
self assert:(self _testIf3:#CursorRight) == nil. |
|
751 |
self assert:(self _testIf3:#CursorDown) == nil. |
|
752 |
self assert:(self _testIf3:#Foo) == nil. |
|
753 |
self assert:(self _testIf3:#CursorUp) == nil. |
|
754 |
self assert:(self _testIf3:nil) == nil. |
|
755 |
self assert:(self _testIf3:1) == 1. |
|
756 |
||
757 |
self assert:(self _testIf4:#CursorRight) == false. |
|
758 |
self assert:(self _testIf4:nil) == true. |
|
759 |
self assert:(self _testIf4:1) == false. |
|
760 |
||
761 |
self assert:(self _testIf4:#CursorRight with:#CursorDown) == false. |
|
762 |
self assert:(self _testIf4:#CursorRight with:nil) == false. |
|
763 |
self assert:(self _testIf4:nil with:#CursorDown) == false. |
|
764 |
self assert:(self _testIf4:nil with:nil) == true. |
|
765 |
||
766 |
self assert:(self _testIf5:#CursorRight) == nil. |
|
767 |
self assert:(self _testIf5:nil) == 1. |
|
768 |
self assert:(self _testIf5:1) == nil. |
|
769 |
||
770 |
self assert:(self _testIf5:#CursorRight with:#CursorDown) == false. |
|
771 |
self assert:(self _testIf5:#CursorRight with:nil) == false. |
|
772 |
self assert:(self _testIf5:nil with:#CursorDown) == false. |
|
773 |
self assert:(self _testIf5:nil with:nil) == true. |
|
774 |
||
775 |
self assert:(self _testIf6:#CursorRight) == nil. |
|
776 |
self assert:(self _testIf6:nil) == 1. |
|
777 |
self assert:(self _testIf6:1) == nil. |
|
778 |
self assert:(self _testIf6d:#CursorRight) == nil. |
|
779 |
self assert:(self _testIf6d:nil) == nil. |
|
780 |
self assert:(self _testIf6d:1) == nil. |
|
781 |
self assert:(self _testIf6e:#CursorRight) == #CursorRight. |
|
782 |
self assert:(self _testIf6e:nil) == nil. |
|
783 |
self assert:(self _testIf6e:1) == 1. |
|
784 |
self assert:(self _testIf7:#CursorRight) == #CursorRight. |
|
785 |
self assert:(self _testIf7:nil) == 1. |
|
786 |
self assert:(self _testIf7:1) == 1. |
|
787 |
||
788 |
self assert:(self _testIfElse1:#CursorRight) == 1. |
|
789 |
self assert:(self _testIfElse1:#CursorDown) == 1. |
|
790 |
self assert:(self _testIfElse1:#Foo) == -1. |
|
791 |
self assert:(self _testIfElse1:#CursorUp) == -1. |
|
792 |
self assert:(self _testIfElse1:nil) == -1. |
|
793 |
self assert:(self _testIfElse1:1) == -1. |
|
794 |
||
795 |
self assert:(self _testIfElse2:#CursorRight) == 1. |
|
796 |
self assert:(self _testIfElse2:#CursorDown) == 1. |
|
797 |
self assert:(self _testIfElse2:#Foo) == -1. |
|
798 |
self assert:(self _testIfElse2:#CursorUp) == -1. |
|
799 |
self assert:(self _testIfElse2:nil) == -1. |
|
800 |
self assert:(self _testIfElse2:1) == -1. |
|
801 |
||
802 |
self assert:(self _testIfElse3:#CursorRight) == 1. |
|
803 |
self assert:(self _testIfElse3:#CursorDown) == -1. |
|
804 |
self assert:(self _testIfElse3:#Foo) == -1. |
|
805 |
self assert:(self _testIfElse3:#CursorUp) == -1. |
|
806 |
self assert:(self _testIfElse3:nil) == -1. |
|
807 |
self assert:(self _testIfElse3:1) == 1. |
|
808 |
||
809 |
self assert:(self _testIfElse4:#CursorRight) == -1. |
|
810 |
self assert:(self _testIfElse4:#CursorDown) == -1. |
|
811 |
self assert:(self _testIfElse4:#Foo) == -1. |
|
812 |
self assert:(self _testIfElse4:#CursorUp) == -1. |
|
813 |
self assert:(self _testIfElse4:nil) == -1. |
|
814 |
self assert:(self _testIfElse4:1) == 1. |
|
815 |
||
816 |
self assert:(self _testIfElse5:#CursorUp) == -1. |
|
817 |
self assert:(self _testIfElse5:nil) == 1. |
|
818 |
self assert:(self _testIfElse5:1) == -1. |
|
819 |
||
820 |
self assert:(self _testIfElse6:#CursorUp) == -1. |
|
821 |
self assert:(self _testIfElse6:nil) == 1. |
|
822 |
self assert:(self _testIfElse6:1) == -1. |
|
823 |
||
824 |
self assert:(self _testIfElse7:#CursorUp with:1 with:2) == 2. |
|
825 |
self assert:(self _testIfElse7:nil with:1 with:2) == 1. |
|
826 |
self assert:(self _testIfElse7:1 with:1 with:2) == 2. |
|
827 |
||
828 |
" |
|
829 |
self basicNew testIf |
|
68 | 830 |
" |
62 | 831 |
! ! |
832 |
||
47 | 833 |
!CompilerTest methodsFor:'tests - constant folding'! |
834 |
||
113 | 835 |
_testFloat_pi |
47 | 836 |
^ Float pi |
837 |
! |
|
838 |
||
113 | 839 |
_testFloat_unity |
47 | 840 |
^ Float unity |
841 |
! |
|
842 |
||
113 | 843 |
_testFloat_zero |
47 | 844 |
^ Float zero |
845 |
! |
|
846 |
||
113 | 847 |
_testSmalltalk_if_else_isSmalltalkX |
47 | 848 |
Smalltalk isSmalltalkX ifTrue:[ |
648 | 849 |
^ 'yes' |
113 | 850 |
] ifFalse:[^ 'no'] |
47 | 851 |
! |
852 |
||
113 | 853 |
_testSmalltalk_if_else_isVisualWorks |
47 | 854 |
Smalltalk isVisualWorks ifTrue:[ |
648 | 855 |
^ 'yes' |
113 | 856 |
] ifFalse:[^ 'no'] |
47 | 857 |
! |
858 |
||
113 | 859 |
_testSmalltalk_if_isSmalltalkX |
47 | 860 |
Smalltalk isSmalltalkX ifTrue:[ |
648 | 861 |
^ 'yes' |
113 | 862 |
]. |
863 |
^ 'no' |
|
864 |
! |
|
865 |
||
866 |
_testSmalltalk_if_isSqueak |
|
867 |
Smalltalk isSqueak ifTrue:[ |
|
648 | 868 |
^ 'yes' |
47 | 869 |
]. |
870 |
^ 'no' |
|
871 |
! |
|
872 |
||
113 | 873 |
_testSmalltalk_if_isVisualWorks |
47 | 874 |
Smalltalk isVisualWorks ifTrue:[ |
648 | 875 |
^ 'yes' |
47 | 876 |
]. |
877 |
^ 'no' |
|
878 |
! |
|
879 |
||
113 | 880 |
_testSmalltalk_isSmalltalkX |
47 | 881 |
^ Smalltalk isSmalltalkX |
882 |
! |
|
883 |
||
113 | 884 |
_testSmalltalk_isSqueak |
47 | 885 |
^ Smalltalk isSqueak |
886 |
! |
|
887 |
||
113 | 888 |
_testSmalltalk_isVisualAge |
47 | 889 |
^ Smalltalk isVisualAge |
890 |
! |
|
891 |
||
113 | 892 |
_testSmalltalk_isVisualWorks |
47 | 893 |
^ Smalltalk isVisualWorks |
894 |
! |
|
895 |
||
113 | 896 |
_testUnaryFolding |
897 |
self _testFloat_pi ~= (Float perform:#pi) ifTrue:[ |
|
648 | 898 |
self halt |
113 | 899 |
]. |
900 |
self _testFloat_unity ~= (Float perform:#unity) ifTrue:[ |
|
648 | 901 |
self halt |
113 | 902 |
]. |
903 |
self _testFloat_zero ~= (Float perform:#zero) ifTrue:[ |
|
648 | 904 |
self halt |
113 | 905 |
]. |
906 |
self _testSmalltalk_isSmalltalkX ~= (Smalltalk perform:#isSmalltalkX) ifTrue:[ |
|
648 | 907 |
self halt |
113 | 908 |
]. |
909 |
self _testSmalltalk_isSqueak ~= (Smalltalk perform:#isSqueak) ifTrue:[ |
|
648 | 910 |
self halt |
113 | 911 |
]. |
912 |
self _testSmalltalk_isVisualWorks ~= (Smalltalk perform:#isVisualWorks) ifTrue:[ |
|
648 | 913 |
self halt |
113 | 914 |
]. |
915 |
self _testSmalltalk_isVisualAge ~= (Smalltalk perform:#isVisualAge) ifTrue:[ |
|
648 | 916 |
self halt |
113 | 917 |
] |
47 | 918 |
|
919 |
" |
|
113 | 920 |
self basicNew _testUnaryFolding |
47 | 921 |
" |
922 |
! ! |
|
923 |
||
568 | 924 |
!CompilerTest methodsFor:'tests - context setup'! |
925 |
||
926 |
_testContextA |
|
927 |
ObjectMemory dumpObject:thisContext |
|
928 |
||
929 |
" |
|
648 | 930 |
self new _testContextA |
568 | 931 |
" |
932 |
! |
|
933 |
||
934 |
_testContextB |
|
935 |
ObjectMemory dumpObject:thisContext sender |
|
936 |
||
937 |
" |
|
648 | 938 |
self new _testContextB |
568 | 939 |
" |
940 |
! |
|
941 |
||
942 |
_testContextC |
|
943 |
thisContext fullPrintAll |
|
944 |
||
945 |
" |
|
648 | 946 |
self new _testContextC |
568 | 947 |
" |
948 |
! |
|
949 |
||
950 |
_testContextD |
|
951 |
self _testContextB |
|
952 |
||
953 |
" |
|
648 | 954 |
self new _testContextD |
568 | 955 |
" |
956 |
! |
|
957 |
||
958 |
_testContextE |
|
959 |
^ thisContext sender |
|
960 |
||
961 |
" |
|
648 | 962 |
self new _testContextE |
568 | 963 |
" |
964 |
! |
|
965 |
||
966 |
_testContextF |
|
967 |
^ self _testContextE |
|
968 |
||
969 |
" |
|
648 | 970 |
self new _testContextF |
568 | 971 |
" |
972 |
! |
|
973 |
||
974 |
_testSend0 |
|
975 |
^ 9999 |
|
976 |
! |
|
977 |
||
648 | 978 |
_testSend0B:arg |
568 | 979 |
^ arg |
980 |
! |
|
981 |
||
982 |
_testSend1 |
|
983 |
^ self _testSend0 |
|
984 |
||
985 |
" |
|
648 | 986 |
self new testSend1 |
568 | 987 |
" |
988 |
! |
|
989 |
||
990 |
_testSend1B |
|
991 |
^ self _testSend0B:1234 |
|
992 |
||
993 |
" |
|
648 | 994 |
self new testSend1B |
568 | 995 |
" |
996 |
! |
|
997 |
||
648 | 998 |
_testSend1C:arg |
568 | 999 |
^ self _testSend0B:arg |
1000 |
||
1001 |
" |
|
648 | 1002 |
self new testSend1C:9998 |
568 | 1003 |
" |
1004 |
! |
|
1005 |
||
1006 |
_testSend2 |
|
1007 |
self _testContextB |
|
1008 |
||
1009 |
" |
|
648 | 1010 |
self new testSend2 |
568 | 1011 |
" |
1012 |
! |
|
1013 |
||
1014 |
_testSend3 |
|
1015 |
self _testContextC |
|
1016 |
||
1017 |
" |
|
648 | 1018 |
self new testSend3 |
568 | 1019 |
" |
1020 |
! |
|
1021 |
||
1022 |
retArgWithFrameA:arg |
|
1023 |
|a b c| |
|
1024 |
||
1025 |
a := 0. |
|
1026 |
b := 1. |
|
1027 |
c := 2. |
|
1028 |
^ arg |
|
1029 |
||
1030 |
" |
|
648 | 1031 |
self new retArgWithFrameA:999 |
568 | 1032 |
" |
1033 |
! |
|
1034 |
||
1035 |
retArgWithFrameB:arg |
|
1036 |
|a b c| |
|
1037 |
||
1038 |
a := 0. |
|
1039 |
b := 1. |
|
1040 |
c := 2. |
|
1041 |
self retSelf. |
|
1042 |
||
1043 |
^ arg |
|
1044 |
||
1045 |
" |
|
648 | 1046 |
self new retArgWithFrameB:9999 |
568 | 1047 |
" |
1048 |
! |
|
1049 |
||
1050 |
retLocal |
|
1051 |
|a| |
|
1052 |
||
1053 |
a := 0. |
|
1054 |
^ a |
|
1055 |
||
1056 |
" |
|
648 | 1057 |
self new retLocal |
1058 |
1000000 timesRepeat:[self new retInstVar] |
|
1059 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new retInstVar] ] |
|
568 | 1060 |
" |
1061 |
||
1062 |
" |
|
1063 |
|i| |
|
1064 |
||
1065 |
i := self new. |
|
1066 |
i instVarAt:1 put:12345. |
|
648 | 1067 |
i retInstVar |
568 | 1068 |
" |
1069 |
||
1070 |
" |
|
1071 |
|i| |
|
1072 |
i := self new. |
|
1073 |
i instVarAt:1 put:12345. |
|
648 | 1074 |
1000000 timesRepeat:[i retInstVar] |
568 | 1075 |
" |
1076 |
||
1077 |
" |
|
1078 |
|i| |
|
1079 |
i := self new. |
|
1080 |
i instVarAt:1 put:12345. |
|
648 | 1081 |
Time millisecondsToRun:[ 1000000 timesRepeat:[i retInstVar] ] |
568 | 1082 |
" |
1083 |
||
1084 |
||
1085 |
! |
|
1086 |
||
1087 |
retLocalB |
|
1088 |
|a b c| |
|
1089 |
||
1090 |
a := 0. |
|
1091 |
b := 1. |
|
1092 |
c := 2. |
|
1093 |
^ a |
|
1094 |
||
1095 |
" |
|
648 | 1096 |
self new retLocalB |
1097 |
1000000 timesRepeat:[self new retLocalB] |
|
1098 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new retInstVar] ] |
|
1099 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new retLocalB] ] |
|
568 | 1100 |
" |
1101 |
||
1102 |
" |
|
1103 |
|i| |
|
1104 |
||
1105 |
i := self new. |
|
1106 |
i instVarAt:1 put:12345. |
|
648 | 1107 |
i retInstVar |
568 | 1108 |
" |
1109 |
||
1110 |
" |
|
1111 |
|i| |
|
1112 |
i := self new. |
|
1113 |
i instVarAt:1 put:12345. |
|
648 | 1114 |
1000000 timesRepeat:[i retInstVar] |
568 | 1115 |
" |
1116 |
||
1117 |
" |
|
1118 |
|i| |
|
1119 |
i := self new. |
|
1120 |
i instVarAt:1 put:12345. |
|
648 | 1121 |
Time millisecondsToRun:[ 1000000 timesRepeat:[i retInstVar] ] |
568 | 1122 |
" |
1123 |
||
1124 |
||
1125 |
! |
|
1126 |
||
1127 |
retLocalC |
|
1128 |
|a b c| |
|
1129 |
||
1130 |
a := 0. |
|
1131 |
b := 1. |
|
1132 |
c := 2. |
|
1133 |
^ b |
|
1134 |
||
1135 |
" |
|
648 | 1136 |
self new retLocalC |
1137 |
1000000 timesRepeat:[self new retInstVar] |
|
1138 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new retInstVar] ] |
|
568 | 1139 |
" |
1140 |
||
1141 |
" |
|
1142 |
|i| |
|
1143 |
||
1144 |
i := self new. |
|
1145 |
i instVarAt:1 put:12345. |
|
648 | 1146 |
i retInstVar |
568 | 1147 |
" |
1148 |
||
1149 |
" |
|
1150 |
|i| |
|
1151 |
i := self new. |
|
1152 |
i instVarAt:1 put:12345. |
|
648 | 1153 |
1000000 timesRepeat:[i retInstVar] |
568 | 1154 |
" |
1155 |
||
1156 |
" |
|
1157 |
|i| |
|
1158 |
i := self new. |
|
1159 |
i instVarAt:1 put:12345. |
|
648 | 1160 |
Time millisecondsToRun:[ 1000000 timesRepeat:[i retInstVar] ] |
568 | 1161 |
" |
1162 |
||
1163 |
||
1164 |
! |
|
1165 |
||
1166 |
retLocalD |
|
1167 |
|a b c| |
|
1168 |
||
1169 |
a := 0. |
|
1170 |
b := 1. |
|
1171 |
c := 2. |
|
1172 |
^ c |
|
1173 |
||
1174 |
" |
|
648 | 1175 |
self new retLocalD |
1176 |
1000000 timesRepeat:[self new retInstVar] |
|
1177 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new retInstVar] ] |
|
568 | 1178 |
" |
1179 |
||
1180 |
" |
|
1181 |
|i| |
|
1182 |
||
1183 |
i := self new. |
|
1184 |
i instVarAt:1 put:12345. |
|
648 | 1185 |
i retInstVar |
568 | 1186 |
" |
1187 |
||
1188 |
" |
|
1189 |
|i| |
|
1190 |
i := self new. |
|
1191 |
i instVarAt:1 put:12345. |
|
648 | 1192 |
1000000 timesRepeat:[i retInstVar] |
568 | 1193 |
" |
1194 |
||
1195 |
" |
|
1196 |
|i| |
|
1197 |
i := self new. |
|
1198 |
i instVarAt:1 put:12345. |
|
648 | 1199 |
Time millisecondsToRun:[ 1000000 timesRepeat:[i retInstVar] ] |
568 | 1200 |
" |
1201 |
||
1202 |
||
1203 |
! |
|
1204 |
||
1205 |
retLocalE |
|
1206 |
|a b c| |
|
1207 |
||
1208 |
a := 0. |
|
1209 |
b := 1. |
|
1210 |
c := 2. |
|
1211 |
^ self |
|
1212 |
||
1213 |
" |
|
648 | 1214 |
self new retLocalE |
1215 |
1000000 timesRepeat:[self new retInstVar] |
|
1216 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new retInstVar] ] |
|
568 | 1217 |
" |
1218 |
||
1219 |
" |
|
1220 |
|i| |
|
1221 |
||
1222 |
i := self new. |
|
1223 |
i instVarAt:1 put:12345. |
|
648 | 1224 |
i retInstVar |
568 | 1225 |
" |
1226 |
||
1227 |
" |
|
1228 |
|i| |
|
1229 |
i := self new. |
|
1230 |
i instVarAt:1 put:12345. |
|
648 | 1231 |
1000000 timesRepeat:[i retInstVar] |
568 | 1232 |
" |
1233 |
||
1234 |
" |
|
1235 |
|i| |
|
1236 |
i := self new. |
|
1237 |
i instVarAt:1 put:12345. |
|
648 | 1238 |
Time millisecondsToRun:[ 1000000 timesRepeat:[i retInstVar] ] |
568 | 1239 |
" |
1240 |
||
1241 |
||
1242 |
! |
|
1243 |
||
1244 |
retLocalF |
|
1245 |
|a b c| |
|
1246 |
||
1247 |
a := 0. |
|
1248 |
b := 1. |
|
1249 |
c := 2. |
|
1250 |
self retSelf. |
|
1251 |
||
1252 |
^ a |
|
1253 |
||
1254 |
" |
|
648 | 1255 |
self new retLocalF |
568 | 1256 |
" |
1257 |
||
1258 |
||
1259 |
||
1260 |
! |
|
1261 |
||
1262 |
retLocalG |
|
1263 |
|a b c| |
|
1264 |
||
1265 |
a := 0. |
|
1266 |
b := 1. |
|
1267 |
c := 2. |
|
1268 |
self retSelf. |
|
1269 |
||
1270 |
^ b |
|
1271 |
||
1272 |
" |
|
648 | 1273 |
self new retLocalG |
568 | 1274 |
" |
1275 |
||
1276 |
||
1277 |
||
1278 |
! |
|
1279 |
||
1280 |
retLocalH |
|
1281 |
|a b c| |
|
1282 |
||
1283 |
a := 0. |
|
1284 |
b := 1. |
|
1285 |
c := 2. |
|
1286 |
self retSelf. |
|
1287 |
||
1288 |
^ c |
|
1289 |
||
1290 |
" |
|
648 | 1291 |
self new retLocalH |
568 | 1292 |
" |
1293 |
||
1294 |
||
1295 |
||
1296 |
! |
|
1297 |
||
1298 |
retSelf |
|
1299 |
||
1300 |
||
1301 |
! ! |
|
1302 |
||
1303 |
!CompilerTest methodsFor:'tests - entry'! |
|
1304 |
||
1305 |
ilcMissCheck |
|
1306 |
||
1307 |
||
1308 |
||
1309 |
" |
|
648 | 1310 |
(Array with:self new with:nil) do:[:el | el size printCR.]. |
568 | 1311 |
" |
1312 |
||
1313 |
||
1314 |
||
1315 |
! ! |
|
1316 |
||
87 | 1317 |
!CompilerTest methodsFor:'tests - inlined'! |
1318 |
||
648 | 1319 |
_test_even:arg |
87 | 1320 |
^ arg even |
1321 |
||
1322 |
" |
|
648 | 1323 |
self new _test_even:nil |
113 | 1324 |
self new _test_even:123 |
1325 |
self new _test_even:122 |
|
1326 |
self new _test_even:(100 factorial) |
|
87 | 1327 |
" |
1328 |
! |
|
1329 |
||
648 | 1330 |
_test_isInteger:arg |
87 | 1331 |
^ arg isInteger |
1332 |
||
1333 |
" |
|
648 | 1334 |
self new _test_isInteger:nil |
113 | 1335 |
self new _test_isInteger:123 |
1336 |
self new _test_isInteger:(100 factorial) |
|
87 | 1337 |
" |
1338 |
! |
|
1339 |
||
648 | 1340 |
_test_isNotInteger:arg |
87 | 1341 |
^ arg isInteger not |
1342 |
||
1343 |
" |
|
648 | 1344 |
self new _test_isNotInteger:nil |
113 | 1345 |
self new _test_isNotInteger:123 |
1346 |
self new _test_isNotInteger:(100 factorial) |
|
87 | 1347 |
" |
1348 |
! |
|
1349 |
||
648 | 1350 |
_test_max1:arg1 _:arg2 |
87 | 1351 |
^ arg1 max:arg2 |
1352 |
||
1353 |
" |
|
648 | 1354 |
self new _test_max1:nil _:nil |
1355 |
self new _test_max1:1 _:nil |
|
1356 |
self new _test_max1:nil _:1 |
|
1357 |
self new _test_max1:1 _:2 |
|
1358 |
self new _test_max1:2 _:1 |
|
1359 |
||
1360 |
self new _test_max1:1.0 _:nil |
|
1361 |
self new _test_max1:nil _:1.0 |
|
1362 |
self new _test_max1:1.0 _:2.0 |
|
1363 |
self new _test_max1:2.0 _:1.0 |
|
1364 |
||
1365 |
self new _test_max1:1.0 _:2 |
|
1366 |
self new _test_max1:2.0 _:1 |
|
1367 |
self new _test_max1:1 _:2.0 |
|
1368 |
self new _test_max1:2 _:1.0 |
|
87 | 1369 |
" |
1370 |
! |
|
1371 |
||
648 | 1372 |
_test_max2:arg |
87 | 1373 |
^ 1 max:arg |
1374 |
||
1375 |
" |
|
648 | 1376 |
self new _test_max2:nil |
1377 |
self new _test_max2:0 |
|
1378 |
self new _test_max2:1 |
|
1379 |
self new _test_max2:2 |
|
1380 |
||
1381 |
self new _test_max2:0.0 |
|
1382 |
self new _test_max2:1.0 |
|
1383 |
self new _test_max2:2.0 |
|
87 | 1384 |
" |
1385 |
! |
|
1386 |
||
648 | 1387 |
_test_max3:arg |
87 | 1388 |
|var| |
1389 |
||
1390 |
var := Array new:10. |
|
1391 |
^ 1 max:arg |
|
1392 |
||
1393 |
" |
|
648 | 1394 |
self new _test_max3:nil |
1395 |
self new _test_max3:0 |
|
1396 |
self new _test_max3:1 |
|
1397 |
self new _test_max3:2 |
|
1398 |
||
1399 |
self new _test_max3:0.0 |
|
1400 |
self new _test_max3:1.0 |
|
1401 |
self new _test_max3:2.0 |
|
87 | 1402 |
" |
1403 |
! |
|
1404 |
||
648 | 1405 |
_test_max4:arg |
87 | 1406 |
|var| |
1407 |
||
1408 |
var := Array new:10. |
|
1409 |
^ arg max:1 |
|
1410 |
||
1411 |
" |
|
648 | 1412 |
self new _test_max4:nil |
1413 |
self new _test_max4:0 |
|
1414 |
self new _test_max4:1 |
|
1415 |
self new _test_max4:2 |
|
1416 |
||
1417 |
self new _test_max4:0.0 |
|
1418 |
self new _test_max4:1.0 |
|
1419 |
self new _test_max4:2.0 |
|
87 | 1420 |
" |
1421 |
! |
|
1422 |
||
648 | 1423 |
_test_min1:arg1 _:arg2 |
87 | 1424 |
^ arg1 min:arg2 |
1425 |
||
1426 |
" |
|
648 | 1427 |
self new _test_min1:nil _:nil |
1428 |
self new _test_min1:1 _:nil |
|
1429 |
self new _test_min1:nil _:1 |
|
1430 |
self new _test_min1:1 _:2 |
|
1431 |
self new _test_min1:2 _:1 |
|
1432 |
||
1433 |
self new _test_min1:1.0 _:nil |
|
1434 |
self new _test_min1:nil _:1.0 |
|
1435 |
self new _test_min1:1.0 _:2.0 |
|
1436 |
self new _test_min1:2.0 _:1.0 |
|
1437 |
||
1438 |
self new _test_min1:1.0 _:2 |
|
1439 |
self new _test_min1:2.0 _:1 |
|
1440 |
self new _test_min1:1 _:2.0 |
|
1441 |
self new _test_min1:2 _:1.0 |
|
87 | 1442 |
" |
1443 |
! |
|
1444 |
||
648 | 1445 |
_test_min2:arg |
87 | 1446 |
^ 1 min:arg |
1447 |
||
1448 |
" |
|
648 | 1449 |
self new _test_min2:nil |
1450 |
self new _test_min2:0 |
|
1451 |
self new _test_min2:1 |
|
1452 |
self new _test_min2:2 |
|
1453 |
||
1454 |
self new _test_min2:0.0 |
|
1455 |
self new _test_min2:1.0 |
|
1456 |
self new _test_min2:2.0 |
|
87 | 1457 |
" |
1458 |
! |
|
1459 |
||
648 | 1460 |
_test_min3:arg |
87 | 1461 |
|var| |
1462 |
||
1463 |
var := Array new:10. |
|
1464 |
^ 1 min:arg |
|
1465 |
||
1466 |
" |
|
648 | 1467 |
self new _test_min3:nil |
1468 |
self new _test_min3:0 |
|
1469 |
self new _test_min3:1 |
|
1470 |
self new _test_min3:2 |
|
1471 |
||
1472 |
self new _test_min3:0.0 |
|
1473 |
self new _test_min3:1.0 |
|
1474 |
self new _test_min3:2.0 |
|
87 | 1475 |
" |
1476 |
! |
|
1477 |
||
648 | 1478 |
_test_min4:arg |
87 | 1479 |
|var| |
1480 |
||
1481 |
var := Array new:10. |
|
1482 |
^ arg min:1 |
|
1483 |
||
1484 |
" |
|
648 | 1485 |
self new _test_min4:nil |
1486 |
self new _test_min4:0 |
|
1487 |
self new _test_min4:1 |
|
1488 |
self new _test_min4:2 |
|
1489 |
||
1490 |
self new _test_min4:0.0 |
|
1491 |
self new _test_min4:1.0 |
|
1492 |
self new _test_min4:2.0 |
|
87 | 1493 |
" |
1494 |
! |
|
1495 |
||
648 | 1496 |
_test_odd:arg |
87 | 1497 |
^ arg odd |
1498 |
||
1499 |
" |
|
648 | 1500 |
self new _test_odd:nil |
1501 |
self new _test_odd:123 |
|
1502 |
self new _test_odd:122 |
|
1503 |
self new _test_odd:(100 factorial) |
|
87 | 1504 |
" |
1505 |
! |
|
1506 |
||
113 | 1507 |
_test_size |
87 | 1508 |
^ value size |
1509 |
||
1510 |
" |
|
113 | 1511 |
(self new value:(Array new:2)) _test_size |
1512 |
(self new value:(OrderedCollection new:2)) _test_size |
|
1513 |
" |
|
1514 |
! ! |
|
1515 |
||
568 | 1516 |
!CompilerTest methodsFor:'tests - instvar access'! |
1517 |
||
1518 |
retInstVar |
|
1519 |
^ value |
|
1520 |
||
1521 |
" |
|
648 | 1522 |
self new retInstVar |
1523 |
1000000 timesRepeat:[self new retInstVar] |
|
1524 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new retInstVar] ] |
|
568 | 1525 |
" |
1526 |
||
1527 |
" |
|
1528 |
|i| |
|
1529 |
||
1530 |
i := self new. |
|
1531 |
i instVarAt:1 put:12345. |
|
648 | 1532 |
i retInstVar |
568 | 1533 |
" |
1534 |
||
1535 |
" |
|
1536 |
|i| |
|
1537 |
i := self new. |
|
1538 |
i instVarAt:1 put:12345. |
|
648 | 1539 |
1000000 timesRepeat:[i retInstVar] |
568 | 1540 |
" |
1541 |
||
1542 |
" |
|
1543 |
|i| |
|
1544 |
i := self new. |
|
1545 |
i instVarAt:1 put:12345. |
|
648 | 1546 |
Time millisecondsToRun:[ 1000000 timesRepeat:[i retInstVar] ] |
568 | 1547 |
" |
1548 |
||
1549 |
||
1550 |
! |
|
1551 |
||
1552 |
setInstVarA |
|
1553 |
value := 123 |
|
1554 |
||
1555 |
" |
|
648 | 1556 |
self new setInstVarA; instVarAt:1 |
1557 |
1000000 timesRepeat:[self new setInstVarA] |
|
1558 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new setInstVarA] ] |
|
568 | 1559 |
" |
1560 |
||
1561 |
" |
|
1562 |
|i| |
|
1563 |
||
1564 |
i := self new. |
|
1565 |
i instVarAt:1 put:12345. |
|
1566 |
i setInstVarA. |
|
648 | 1567 |
i instVarAt:1 |
568 | 1568 |
" |
1569 |
||
1570 |
||
1571 |
||
1572 |
! |
|
1573 |
||
1574 |
setInstVarB |
|
1575 |
value := 'hello' |
|
1576 |
||
1577 |
" |
|
648 | 1578 |
self new setInstVarB; instVarAt:1 |
1579 |
1000000 timesRepeat:[self new setInstVarB] |
|
1580 |
Time millisecondsToRun:[ 1000000 timesRepeat:[self new setInstVarB] ] |
|
568 | 1581 |
" |
1582 |
||
1583 |
" |
|
1584 |
|i| |
|
1585 |
||
1586 |
i := self new. |
|
1587 |
i instVarAt:1 put:12345. |
|
1588 |
i setInstVarB. |
|
648 | 1589 |
i instVarAt:1 |
568 | 1590 |
" |
1591 |
||
1592 |
||
1593 |
||
1594 |
! ! |
|
1595 |
||
1596 |
!CompilerTest methodsFor:'tests - literals'! |
|
1597 |
||
1598 |
compile:someCode |
|
1599 |
|m| |
|
1600 |
||
648 | 1601 |
m := Compiler |
1602 |
compile:someCode |
|
1603 |
forClass:nil |
|
1604 |
install:false. |
|
568 | 1605 |
|
1606 |
self assert:(m notNil and:[m ~~ #Error]). |
|
1607 |
^ m |
|
1608 |
! |
|
1609 |
||
1610 |
testLiterals |
|
1611 |
" |
|
1612 |
self new testLiterals |
|
1613 |
" |
|
1614 |
|m| |
|
1615 |
||
1616 |
"/ literals must be present, even if code has been optimized away |
|
1617 |
"/ (otherwise, searches do not work correctly) |
|
1618 |
||
648 | 1619 |
m := self compile:'foo:arg |v| ^ (v ~~ 0) not'. |
568 | 1620 |
self assert:(m literals includesIdentical:#'~~'). |
1621 |
self assert:(m literals includesIdentical:#'not'). |
|
1622 |
||
648 | 1623 |
m := self compile:'foo:arg |v| ^ (v == 0) not'. |
568 | 1624 |
self assert:(m literals includesIdentical:#'=='). |
1625 |
self assert:(m literals includesIdentical:#'not'). |
|
1626 |
||
1627 |
||
648 | 1628 |
m := self compile:'foo:arg ^ arg not'. |
568 | 1629 |
self assert:(m literals includesIdentical:#'not'). |
1630 |
||
648 | 1631 |
m := self compile:'foo:arg ^ arg notNil'. |
568 | 1632 |
self assert:(m literals includesIdentical:#'notNil'). |
648 | 1633 |
m := self compile:'foo:arg ^ arg isNil'. |
568 | 1634 |
self assert:(m literals includesIdentical:#'isNil'). |
1635 |
||
1636 |
||
648 | 1637 |
m := self compile:'foo:arg |v| v := v+1'. |
568 | 1638 |
self assert:(m literals includesIdentical:#'+'). |
1639 |
||
648 | 1640 |
m := self compile:'foo:arg |v| v := v-1'. |
568 | 1641 |
self assert:(m literals includesIdentical:#'-'). |
1642 |
||
1643 |
||
648 | 1644 |
m := self compile:'foo:arg |v| v := v not'. |
568 | 1645 |
self assert:(m literals includesIdentical:#'not'). |
1646 |
||
1647 |
||
648 | 1648 |
m := self compile:'foo:arg ^ arg ifTrue:1'. |
568 | 1649 |
self assert:(m literals includesIdentical:#'ifTrue:'). |
1650 |
||
648 | 1651 |
m := self compile:'foo:arg ^ arg ifFalse:1'. |
568 | 1652 |
self assert:(m literals includesIdentical:#'ifFalse:'). |
1653 |
||
648 | 1654 |
m := self compile:'foo:arg ^ arg ifTrue:1 ifFalse:2'. |
568 | 1655 |
self assert:(m literals includesIdentical:#'ifTrue:ifFalse:'). |
1656 |
||
648 | 1657 |
m := self compile:'foo:arg ^ arg ifFalse:1 ifTrue:2'. |
568 | 1658 |
self assert:(m literals includesIdentical:#'ifFalse:ifTrue:'). |
1659 |
||
1660 |
||
648 | 1661 |
m := self compile:'foo:arg ^ arg isNil ifTrue:1'. |
568 | 1662 |
self assert:(m literals includesIdentical:#'ifTrue:'). |
1663 |
self assert:(m literals includesIdentical:#'isNil'). |
|
1664 |
||
648 | 1665 |
m := self compile:'foo:arg ^ arg isNil ifFalse:1'. |
568 | 1666 |
self assert:(m literals includesIdentical:#'ifFalse:'). |
1667 |
self assert:(m literals includesIdentical:#'isNil'). |
|
1668 |
||
648 | 1669 |
m := self compile:'foo:arg ^ arg isNil ifTrue:1 ifFalse:2'. |
568 | 1670 |
self assert:(m literals includesIdentical:#'ifTrue:ifFalse:'). |
1671 |
self assert:(m literals includesIdentical:#'isNil'). |
|
1672 |
||
648 | 1673 |
m := self compile:'foo:arg ^ arg isNil ifFalse:1 ifTrue:2'. |
568 | 1674 |
self assert:(m literals includesIdentical:#'ifFalse:ifTrue:'). |
1675 |
self assert:(m literals includesIdentical:#'isNil'). |
|
1676 |
||
1677 |
||
648 | 1678 |
m := self compile:'foo:arg ^ arg notNil ifTrue:1'. |
568 | 1679 |
self assert:(m literals includesIdentical:#'ifTrue:'). |
1680 |
self assert:(m literals includesIdentical:#'notNil'). |
|
1681 |
||
648 | 1682 |
m := self compile:'foo:arg ^ arg notNil ifFalse:1'. |
568 | 1683 |
self assert:(m literals includesIdentical:#'ifFalse:'). |
1684 |
self assert:(m literals includesIdentical:#'notNil'). |
|
1685 |
||
648 | 1686 |
m := self compile:'foo:arg ^ arg notNil ifTrue:1 ifFalse:2'. |
568 | 1687 |
self assert:(m literals includesIdentical:#'ifTrue:ifFalse:'). |
1688 |
self assert:(m literals includesIdentical:#'notNil'). |
|
1689 |
||
648 | 1690 |
m := self compile:'foo:arg ^ arg notNil ifFalse:1 ifTrue:2'. |
568 | 1691 |
self assert:(m literals includesIdentical:#'ifFalse:ifTrue:'). |
1692 |
self assert:(m literals includesIdentical:#'notNil'). |
|
1693 |
||
1694 |
||
648 | 1695 |
m := self compile:'foo:arg ^ arg not ifTrue:1'. |
568 | 1696 |
self assert:(m literals includesIdentical:#'ifTrue:'). |
1697 |
self assert:(m literals includesIdentical:#'not'). |
|
1698 |
||
648 | 1699 |
m := self compile:'foo:arg ^ arg not ifFalse:1'. |
568 | 1700 |
self assert:(m literals includesIdentical:#'ifFalse:'). |
1701 |
self assert:(m literals includesIdentical:#'not'). |
|
1702 |
||
648 | 1703 |
m := self compile:'foo:arg ^ arg not ifTrue:1 ifFalse:2'. |
568 | 1704 |
self assert:(m literals includesIdentical:#'ifTrue:ifFalse:'). |
1705 |
self assert:(m literals includesIdentical:#'not'). |
|
1706 |
||
648 | 1707 |
m := self compile:'foo:arg ^ arg not ifFalse:1 ifTrue:2'. |
568 | 1708 |
self assert:(m literals includesIdentical:#'ifFalse:ifTrue:'). |
1709 |
self assert:(m literals includesIdentical:#'not'). |
|
1710 |
||
1711 |
||
648 | 1712 |
m := self compile:'foo:arg ^ arg and:[true]'. |
568 | 1713 |
self assert:(m literals includesIdentical:#'and:'). |
1714 |
||
648 | 1715 |
m := self compile:'foo:arg ^ arg not and:[true]'. |
568 | 1716 |
self assert:(m literals includesIdentical:#'and:'). |
1717 |
self assert:(m literals includesIdentical:#'not'). |
|
1718 |
||
648 | 1719 |
m := self compile:'foo:arg ^ arg or:[true]'. |
568 | 1720 |
self assert:(m literals includesIdentical:#'or:'). |
1721 |
||
648 | 1722 |
m := self compile:'foo:arg ^ arg not or:[true]'. |
568 | 1723 |
self assert:(m literals includesIdentical:#'or:'). |
1724 |
self assert:(m literals includesIdentical:#'not'). |
|
1725 |
||
648 | 1726 |
m := self compile:'foo:arg ^ (arg or:[true]) ifTrue:[1234]'. |
568 | 1727 |
self assert:(m literals includesIdentical:#'or:'). |
1728 |
self assert:(m literals includesIdentical:#'ifTrue:'). |
|
1729 |
||
648 | 1730 |
m := self compile:'foo:arg ^ (arg or:[true]) ifFalse:[1234]'. |
568 | 1731 |
self assert:(m literals includesIdentical:#'or:'). |
1732 |
self assert:(m literals includesIdentical:#'ifFalse:'). |
|
1733 |
||
648 | 1734 |
m := self compile:'foo:arg ^ (arg or:[true]) ifTrue:1 ifFalse:2'. |
568 | 1735 |
self assert:(m literals includesIdentical:#'or:'). |
1736 |
self assert:(m literals includesIdentical:#'ifTrue:ifFalse:'). |
|
1737 |
||
648 | 1738 |
m := self compile:'foo:arg ^ (arg or:[true]) ifFalse:1 ifTrue:2'. |
568 | 1739 |
self assert:(m literals includesIdentical:#'or:'). |
1740 |
self assert:(m literals includesIdentical:#'ifFalse:ifTrue:'). |
|
1741 |
||
1742 |
||
648 | 1743 |
m := self compile:'foo:arg ^ [ ] loop'. |
568 | 1744 |
self assert:(m literals includesIdentical:#'loop'). |
1745 |
||
648 | 1746 |
m := self compile:'foo:arg ^ [ ] repeat'. |
568 | 1747 |
self assert:(m literals includesIdentical:#'repeat'). |
1748 |
||
648 | 1749 |
m := self compile:'foo:arg ^ arg ? 123'. |
568 | 1750 |
self assert:(m literals includesIdentical:#'?'). |
1751 |
||
1752 |
" |
|
1753 |
self new testLiterals |
|
1754 |
" |
|
1755 |
! ! |
|
1756 |
||
188 | 1757 |
!CompilerTest methodsFor:'tests - method calls'! |
1758 |
||
189 | 1759 |
addDumpingMethodForSelfIsLostBug |
1760 |
|code mthd| |
|
1761 |
||
648 | 1762 |
code := |
1763 |
'_x |
|
190 | 1764 |
"/ ObjectMemory dumpSender. |
189 | 1765 |
"/ request nextPutAll: ''a''. |
648 | 1766 |
ObjectMemory garbageCollect. |
189 | 1767 |
ObjectMemory dumpSender. |
1768 |
"/ request nextPutAll: ''b''. |
|
1769 |
'. |
|
1770 |
||
1771 |
Class withoutUpdatingChangesDo:[ |
|
648 | 1772 |
mthd := (Smalltalk at:#Compiler) |
1773 |
compile:code |
|
1774 |
in:DummyClass |
|
1775 |
notifying:nil |
|
1776 |
ifFail:[self error]. |
|
189 | 1777 |
]. |
1778 |
^ mthd |
|
1779 |
! |
|
1780 |
||
1781 |
addHaltingMethodForSelfIsLostBug |
|
1782 |
|code mthd| |
|
1783 |
||
648 | 1784 |
code := |
1785 |
'_x |
|
189 | 1786 |
request nextPutAll: ''a''. |
1787 |
self halt. |
|
648 | 1788 |
ObjectMemory garbageCollect. |
189 | 1789 |
self halt. |
1790 |
request nextPutAll: ''b''. |
|
1791 |
'. |
|
1792 |
||
1793 |
Class withoutUpdatingChangesDo:[ |
|
648 | 1794 |
mthd := (Smalltalk at:#Compiler) |
1795 |
compile:code |
|
1796 |
in:DummyClass |
|
1797 |
notifying:nil |
|
1798 |
ifFail:[self error]. |
|
189 | 1799 |
]. |
1800 |
^ mthd |
|
1801 |
! |
|
1802 |
||
188 | 1803 |
addMethodForSelfIsLostBug |
1804 |
|code mthd| |
|
1805 |
||
648 | 1806 |
code := |
1807 |
'_x |
|
188 | 1808 |
request nextPutAll: ''a''. |
648 | 1809 |
ObjectMemory garbageCollect. |
188 | 1810 |
request nextPutAll: ''b''. |
1811 |
'. |
|
1812 |
||
1813 |
Class withoutUpdatingChangesDo:[ |
|
648 | 1814 |
mthd := (Smalltalk at:#Compiler) |
1815 |
compile:code |
|
1816 |
in:DummyClass |
|
1817 |
notifying:nil |
|
1818 |
ifFail:[self error]. |
|
188 | 1819 |
]. |
1820 |
^ mthd |
|
1821 |
! |
|
1822 |
||
1823 |
removeMethodForSelfIsLostBug |
|
1824 |
Class withoutUpdatingChangesDo:[ |
|
648 | 1825 |
DummyClass removeSelector:#'_x'. |
188 | 1826 |
]. |
1827 |
! |
|
1828 |
||
648 | 1829 |
test_selfIsLost1 |
188 | 1830 |
|mthd rcvr retVal str| |
1831 |
||
1832 |
str := '' writeStream. |
|
1833 |
||
1834 |
mthd := self addMethodForSelfIsLostBug. |
|
1835 |
self removeMethodForSelfIsLostBug. |
|
1836 |
rcvr := DummyClass new. |
|
1837 |
rcvr request:str. |
|
1838 |
retVal := mthd valueWithReceiver:rcvr arguments:#(). |
|
191 | 1839 |
self assert:(retVal == rcvr). |
1840 |
self assert:(str contents = 'ab'). |
|
188 | 1841 |
|
1842 |
" |
|
1843 |
self new test_selfIsLost1 |
|
1844 |
" |
|
1845 |
! |
|
1846 |
||
648 | 1847 |
test_selfIsLost2 |
188 | 1848 |
|mthd rcvr retVal str| |
1849 |
||
1850 |
str := '' writeStream. |
|
1851 |
||
1852 |
mthd := self addMethodForSelfIsLostBug. |
|
1853 |
rcvr := DummyClass new. |
|
1854 |
rcvr request:str. |
|
1855 |
||
1856 |
retVal := rcvr perform:#'_x'. |
|
1857 |
||
1858 |
self removeMethodForSelfIsLostBug. |
|
1859 |
||
191 | 1860 |
self assert:(retVal == rcvr). |
1861 |
self assert:(str contents = 'ab'). |
|
1862 |
||
188 | 1863 |
" |
1864 |
self new test_selfIsLost2 |
|
1865 |
" |
|
1866 |
! |
|
1867 |
||
648 | 1868 |
test_selfIsLost3 |
188 | 1869 |
|mthd rcvr retVal| |
1870 |
||
1871 |
mthd := DummyClass compiledMethodAt:#'_y0'. |
|
1872 |
||
1873 |
rcvr := DummyClass new. |
|
1874 |
||
1875 |
retVal := mthd valueWithReceiver:rcvr arguments:#(). |
|
1876 |
self assert:(retVal == rcvr). |
|
1877 |
||
1878 |
" |
|
1879 |
self new test_selfIsLost3 |
|
1880 |
" |
|
1881 |
! |
|
1882 |
||
648 | 1883 |
test_selfIsLost4 |
188 | 1884 |
|mthd rcvr retVal| |
1885 |
||
1886 |
mthd := DummyClass compiledMethodAt:#'_y1:'. |
|
1887 |
||
1888 |
rcvr := DummyClass new. |
|
1889 |
||
1890 |
retVal := mthd valueWithReceiver:rcvr arguments:(Array with:rcvr). |
|
191 | 1891 |
self assert:(retVal == rcvr). |
188 | 1892 |
|
1893 |
" |
|
1894 |
self new test_selfIsLost4 |
|
1895 |
" |
|
189 | 1896 |
! |
1897 |
||
648 | 1898 |
xtest_selfIsLost5 |
189 | 1899 |
|mthd rcvr retVal str| |
1900 |
||
1901 |
str := '' writeStream. |
|
1902 |
||
1903 |
mthd := self addHaltingMethodForSelfIsLostBug. |
|
1904 |
self removeMethodForSelfIsLostBug. |
|
1905 |
rcvr := DummyClass new. |
|
1906 |
rcvr request:str. |
|
1907 |
retVal := mthd valueWithReceiver:rcvr arguments:#(). |
|
1908 |
||
1909 |
" |
|
1910 |
self new xtest_selfIsLost5 |
|
1911 |
" |
|
1912 |
! |
|
1913 |
||
648 | 1914 |
xtest_selfIsLost6 |
189 | 1915 |
|mthd rcvr retVal str| |
1916 |
||
1917 |
str := '' writeStream. |
|
1918 |
||
1919 |
mthd := self addDumpingMethodForSelfIsLostBug. |
|
1920 |
self removeMethodForSelfIsLostBug. |
|
1921 |
rcvr := DummyClass new. |
|
1922 |
rcvr request:str. |
|
1923 |
retVal := mthd valueWithReceiver:rcvr arguments:#(). |
|
1924 |
||
1925 |
" |
|
1926 |
self new xtest_selfIsLost6 |
|
1927 |
" |
|
188 | 1928 |
! ! |
1929 |
||
113 | 1930 |
!CompilerTest methodsFor:'tests - parsing'! |
1931 |
||
1932 |
testParseBadLiteral |
|
1933 |
self assert:( (self class compile:'foo ^ #( a b ( c d (' ) == #Error ) . |
|
1934 |
self assert:( (self class compile:'foo ^ #( a b ( c d ()' ) == #Error ). |
|
1935 |
self assert:( (self class compile:'foo ^ #( a b ( c d ())' ) == #Error ). |
|
1936 |
self assert:( (self class compile:'foo ^ #( a b ( c d ()))' ) ~~ #Error ). |
|
1937 |
self class removeSelector:#foo. |
|
1938 |
||
1939 |
" |
|
1940 |
self new testParseBadLiteral |
|
87 | 1941 |
" |
318 | 1942 |
! |
1943 |
||
1944 |
testParseExtendedSyntax |
|
1945 |
|compiler val| |
|
1946 |
||
1947 |
compiler := Parser new. |
|
1948 |
val := compiler evaluate:' ''12\t34'' '. |
|
1949 |
self assert:( val = '12\t34' ) . |
|
1950 |
val := compiler evaluate:' ''12\u161634'' '. |
|
1951 |
self assert:( val = '12\u161634' ) . |
|
1952 |
||
1953 |
compiler parserFlags allowExtendedSTXSyntax:true. |
|
1954 |
val := compiler evaluate:' ''12\t34'' '. |
|
1955 |
self assert:( val = ('12' , Character tab , '34' )) . |
|
1956 |
val := compiler evaluate:' ''12\u161634'' '. |
|
1957 |
self assert:( val = ('12' , (Character value:16r1616) , '34' )) . |
|
1958 |
||
1959 |
" |
|
1960 |
self new testParseExtendedSyntax |
|
1961 |
" |
|
87 | 1962 |
! ! |
1963 |
||
328 | 1964 |
!CompilerTest methodsFor:'tests - return'! |
1965 |
||
1966 |
test_bad_return2 |
|
659 | 1967 |
|w a p| |
329 | 1968 |
|
1969 |
w := ParserFlags warnAboutPossibleSTCCompilationProblems. |
|
1970 |
a := ParserFlags allowPossibleSTCCompilationProblems. |
|
659 | 1971 |
p := ParserFlags warnPlausibilityChecks. |
329 | 1972 |
|
1973 |
[ |
|
659 | 1974 |
ParserFlags warnPlausibilityChecks:true. |
1975 |
ParserFlags warnAboutPossibleSTCCompilationProblems:true. |
|
1976 |
ParserFlags allowPossibleSTCCompilationProblems:false. |
|
1977 |
||
1978 |
self should:[ |
|
1979 |
Compiler |
|
1980 |
compile:' |
|
328 | 1981 |
foo:arg |
648 | 1982 |
^ arg |
659 | 1983 |
ifTrue:[^ 1] |
1984 |
ifFalse:[2] |
|
328 | 1985 |
' |
659 | 1986 |
forClass:self class. |
1987 |
] |
|
1988 |
raise:Parser parseErrorSignal |
|
329 | 1989 |
] ensure:[ |
659 | 1990 |
ParserFlags warnAboutPossibleSTCCompilationProblems:w. |
1991 |
ParserFlags allowPossibleSTCCompilationProblems:a. |
|
1992 |
ParserFlags warnPlausibilityChecks:p. |
|
329 | 1993 |
]. |
328 | 1994 |
|
1995 |
"Created: / 16-11-2006 / 14:08:48 / cg" |
|
1996 |
! |
|
1997 |
||
1998 |
test_bad_return3 |
|
329 | 1999 |
|w a setOfSignals| |
2000 |
||
2001 |
w := ParserFlags warnAboutPossibleSTCCompilationProblems. |
|
2002 |
a := ParserFlags allowPossibleSTCCompilationProblems. |
|
2003 |
||
2004 |
[ |
|
648 | 2005 |
ParserFlags warnAboutPossibleSTCCompilationProblems:false. |
2006 |
ParserFlags allowPossibleSTCCompilationProblems:true. |
|
2007 |
||
2008 |
setOfSignals := SignalSet with:(Parser parseErrorSignal) with:(Parser parseWarningSignal). |
|
2009 |
self |
|
2010 |
shouldnt: |
|
2011 |
[ |
|
2012 |
Compiler |
|
2013 |
compile:' |
|
328 | 2014 |
foo:arg |
648 | 2015 |
^ arg |
2016 |
ifTrue:[^ 1] |
|
2017 |
ifFalse:[2] |
|
328 | 2018 |
' |
648 | 2019 |
forClass:self class. |
2020 |
] |
|
2021 |
raise:setOfSignals. |
|
329 | 2022 |
] ensure:[ |
648 | 2023 |
ParserFlags warnAboutPossibleSTCCompilationProblems:w. |
2024 |
ParserFlags allowPossibleSTCCompilationProblems:a. |
|
329 | 2025 |
] |
328 | 2026 |
|
2027 |
"Created: / 16-11-2006 / 14:33:29 / cg" |
|
2028 |
! |
|
2029 |
||
2030 |
test_good_return1 |
|
2031 |
|setOfPossibleExceptions| |
|
2032 |
||
2033 |
setOfPossibleExceptions := SignalSet with:(Parser::ParseWarning) with:(Parser::ParseError). |
|
648 | 2034 |
self |
2035 |
shouldnt: |
|
2036 |
[ |
|
2037 |
Compiler |
|
2038 |
compile:' |
|
328 | 2039 |
foo:arg |
648 | 2040 |
arg |
2041 |
ifTrue:[^ 1] |
|
2042 |
ifFalse:[^ 2] |
|
328 | 2043 |
' |
648 | 2044 |
forClass:self class. |
2045 |
] |
|
2046 |
raise:setOfPossibleExceptions. |
|
328 | 2047 |
|
2048 |
"Created: / 16-11-2006 / 14:16:53 / cg" |
|
2049 |
! |
|
2050 |
||
2051 |
test_good_return2 |
|
2052 |
|setOfPossibleExceptions| |
|
2053 |
||
587 | 2054 |
setOfPossibleExceptions := SignalSet with:(Parser parseWarningSignal) with:(Parser parseErrorSignal). |
648 | 2055 |
self |
2056 |
shouldnt: |
|
2057 |
[ |
|
2058 |
Compiler |
|
2059 |
compile:' |
|
328 | 2060 |
foo:arg |
648 | 2061 |
^ arg |
2062 |
ifTrue:[1] |
|
2063 |
ifFalse:[2] |
|
328 | 2064 |
' |
648 | 2065 |
forClass:self class. |
2066 |
] |
|
2067 |
raise:setOfPossibleExceptions. |
|
328 | 2068 |
|
2069 |
"Created: / 16-11-2006 / 14:41:45 / cg" |
|
2070 |
! ! |
|
2071 |
||
84 | 2072 |
!CompilerTest methodsFor:'tests - sends'! |
2073 |
||
2074 |
m1 |
|
2075 |
^ 123 |
|
2076 |
! |
|
2077 |
||
85 | 2078 |
m10 |
2079 |
^ self m9 |
|
2080 |
||
2081 |
" |
|
2082 |
self new m10 |
|
2083 |
" |
|
2084 |
! |
|
2085 |
||
2086 |
m11 |
|
2087 |
^ self m10 |
|
2088 |
||
2089 |
" |
|
2090 |
self new m11 |
|
2091 |
" |
|
2092 |
! |
|
2093 |
||
2094 |
m12 |
|
2095 |
^ self m11 |
|
2096 |
||
2097 |
" |
|
2098 |
self new m12 |
|
2099 |
" |
|
2100 |
! |
|
2101 |
||
2102 |
m13 |
|
2103 |
^ self m12 |
|
2104 |
||
2105 |
" |
|
2106 |
self new m13 |
|
2107 |
" |
|
2108 |
! |
|
2109 |
||
2110 |
m14 |
|
2111 |
^ self m13 |
|
2112 |
||
2113 |
" |
|
2114 |
self new m14 |
|
2115 |
" |
|
2116 |
! |
|
2117 |
||
2118 |
m15 |
|
2119 |
^ self m14 |
|
2120 |
||
2121 |
" |
|
2122 |
self new m15 |
|
2123 |
" |
|
2124 |
! |
|
2125 |
||
2126 |
m16 |
|
2127 |
^ self m15 |
|
2128 |
||
2129 |
" |
|
2130 |
self new m16 |
|
2131 |
" |
|
2132 |
! |
|
2133 |
||
84 | 2134 |
m2 |
2135 |
^ self m1 |
|
2136 |
! |
|
2137 |
||
2138 |
m3 |
|
2139 |
^ self m2 |
|
2140 |
! |
|
2141 |
||
2142 |
m4 |
|
2143 |
^ self m3 |
|
2144 |
! |
|
2145 |
||
2146 |
m5 |
|
2147 |
^ self m4 |
|
2148 |
! |
|
2149 |
||
2150 |
m6 |
|
2151 |
^ self m5 |
|
2152 |
! |
|
2153 |
||
2154 |
m7 |
|
2155 |
^ self m6 |
|
2156 |
||
2157 |
" |
|
2158 |
self new m7 |
|
2159 |
" |
|
85 | 2160 |
! |
2161 |
||
2162 |
m8 |
|
2163 |
^ self m7 |
|
2164 |
||
2165 |
" |
|
2166 |
self new m8 |
|
2167 |
" |
|
2168 |
! |
|
2169 |
||
2170 |
m9 |
|
2171 |
^ self m8 |
|
2172 |
||
2173 |
" |
|
2174 |
self new m9 |
|
2175 |
" |
|
84 | 2176 |
! ! |
2177 |
||
568 | 2178 |
!CompilerTest methodsFor:'tests - specials'! |
2179 |
||
2180 |
testEnsure |
|
2181 |
self assert:(self callEnsureWith2Returns = true). |
|
2182 |
||
569
e16012b59e29
added: #callEnsureWithException
Claus Gittinger <cg@exept.de>
parents:
568
diff
changeset
|
2183 |
Error handle:[:ex | |
648 | 2184 |
ex proceed |
569
e16012b59e29
added: #callEnsureWithException
Claus Gittinger <cg@exept.de>
parents:
568
diff
changeset
|
2185 |
] do:[ |
648 | 2186 |
self assert:(self callEnsureWithException = true). |
569
e16012b59e29
added: #callEnsureWithException
Claus Gittinger <cg@exept.de>
parents:
568
diff
changeset
|
2187 |
]. |
e16012b59e29
added: #callEnsureWithException
Claus Gittinger <cg@exept.de>
parents:
568
diff
changeset
|
2188 |
|
568 | 2189 |
"Created: / 24-08-2010 / 12:51:27 / cg" |
213
9764b38bebf5
test for all literals to be present in the method
Claus Gittinger <cg@exept.de>
parents:
191
diff
changeset
|
2190 |
! ! |
9764b38bebf5
test for all literals to be present in the method
Claus Gittinger <cg@exept.de>
parents:
191
diff
changeset
|
2191 |
|
577 | 2192 |
!CompilerTest methodsFor:'tests - stc compilation'! |
2193 |
||
2194 |
testCodeForMethodVarAccess |
|
2195 |
"compile this with stc - some gcc versions generate wrong code for it (result is nil)" |
|
2196 |
||
2197 |
|results renderNone allSchedules overallCount passedCount inconclusiveCount failedCount| |
|
2198 |
||
2199 |
self x_executeBlock:[ |
|
648 | 2200 |
|localResults localPassedCount localInconclusiveCount| |
2201 |
||
2202 |
allSchedules := self x_generateSchedules. |
|
2203 |
||
2204 |
overallCount := allSchedules size. |
|
2205 |
(renderNone := (overallCount == 0)) ifFalse:[ |
|
2206 |
results := allSchedules collect:[:ts | ts getStateOfLastRun]. |
|
2207 |
||
2208 |
passedCount := results count:[:state | state isSuccess]. |
|
2209 |
inconclusiveCount := results count:[:state | state isInconclusive]. |
|
2210 |
||
2211 |
failedCount := overallCount - passedCount - inconclusiveCount. |
|
2212 |
] |
|
577 | 2213 |
]. |
2214 |
! |
|
2215 |
||
2216 |
x_executeBlock:aBlock |
|
2217 |
aBlock value |
|
2218 |
! |
|
2219 |
||
2220 |
x_generateSchedules |
|
648 | 2221 |
^ OrderedCollection |
2222 |
with:(Schedule new state:#failed) |
|
2223 |
with:(Schedule new state:#passed) |
|
2224 |
with:(Schedule new state:#passed) |
|
2225 |
with:(Schedule new state:#failed) |
|
2226 |
with:(Schedule new state:#inconclusive) |
|
2227 |
with:(Schedule new state:#inconclusive) |
|
2228 |
with:(Schedule new state:#inconclusive) |
|
2229 |
with:(Schedule new state:#failed) |
|
577 | 2230 |
! ! |
2231 |
||
188 | 2232 |
!CompilerTest::DummyClass methodsFor:'accessing'! |
2233 |
||
2234 |
_y0 |
|
2235 |
ObjectMemory garbageCollect. |
|
2236 |
^ self. |
|
2237 |
! |
|
2238 |
||
2239 |
_y1:arg1 |
|
2240 |
ObjectMemory garbageCollect. |
|
2241 |
^ arg1. |
|
2242 |
! |
|
2243 |
||
2244 |
request:something |
|
2245 |
"set the value of the instance variable 'request' (automatically generated)" |
|
2246 |
||
2247 |
request := something. |
|
2248 |
! ! |
|
2249 |
||
577 | 2250 |
!CompilerTest::Schedule methodsFor:'accessing'! |
2251 |
||
2252 |
getStateOfLastRun |
|
2253 |
^ State new state:state |
|
2254 |
! |
|
2255 |
||
2256 |
state:aSymbol |
|
2257 |
state := aSymbol |
|
2258 |
! ! |
|
2259 |
||
2260 |
!CompilerTest::Schedule::State methodsFor:'accessing'! |
|
2261 |
||
2262 |
state |
|
2263 |
^ state |
|
2264 |
! |
|
2265 |
||
2266 |
state:something |
|
2267 |
state := something. |
|
2268 |
! ! |
|
2269 |
||
2270 |
!CompilerTest::Schedule::State methodsFor:'queries'! |
|
2271 |
||
2272 |
isInconclusive |
|
2273 |
^ state == #inconclusive |
|
2274 |
! |
|
2275 |
||
2276 |
isSuccess |
|
2277 |
^ state == #passed |
|
2278 |
! ! |
|
2279 |
||
47 | 2280 |
!CompilerTest class methodsFor:'documentation'! |
2281 |
||
568 | 2282 |
version_CVS |
2283 |
^ '$Header$' |
|
47 | 2284 |
! ! |