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