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