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