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