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