0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
47
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
ParseNode subclass:#MessageNode
|
140
|
14 |
instanceVariableNames:'receiver selector argArray lineNr'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'System-Compiler-Support'
|
0
|
18 |
!
|
|
19 |
|
20
|
20 |
!MessageNode class methodsFor:'documentation'!
|
|
21 |
|
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
47
|
25 |
All Rights Reserved
|
20
|
26 |
|
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
|
34 |
!
|
|
35 |
|
|
36 |
documentation
|
|
37 |
"
|
|
38 |
node for parse-trees, representing message sends
|
|
39 |
"
|
|
40 |
! !
|
0
|
41 |
|
|
42 |
!MessageNode class methodsFor:'instance creation'!
|
|
43 |
|
|
44 |
receiver:recNode selector:selectorString
|
|
45 |
^ (self basicNew) receiver:recNode selector:selectorString args:nil lineno:0
|
|
46 |
!
|
|
47 |
|
140
|
48 |
receiver:recNode selector:selectorString arg1:argNode1 arg2:argNode2 fold:folding
|
|
49 |
|result recVal argVal selector|
|
|
50 |
|
|
51 |
"
|
|
52 |
This is just a demonstration - of how complex constants can be folded.
|
|
53 |
This was inspired by some discussion in c.l.s about enhancing the language - I prefer
|
|
54 |
enhancing the compiler ....
|
|
55 |
The following optimization will convert '#(...) with:#(...) collect:[...]' into an array constant,
|
|
56 |
allowing a constant arrays of complex objects.
|
|
57 |
|
|
58 |
Notice: this method is normally disabled - its just a demo after all.
|
|
59 |
"
|
|
60 |
folding ifTrue:[
|
|
61 |
"do constant folding ..."
|
|
62 |
(recNode isConstant and:[argNode1 isConstant]) ifTrue:[
|
|
63 |
"check if we can do it ..."
|
|
64 |
selector := selectorString asSymbolIfInterned.
|
|
65 |
selector notNil ifTrue:[
|
|
66 |
recVal := recNode evaluate.
|
|
67 |
(recVal respondsTo:selector) ifTrue:[
|
|
68 |
"
|
|
69 |
we could do much more here - but then, we need a dependency from
|
|
70 |
the folded selectors method to the method we generate code for ...
|
|
71 |
limit optimizations to those that will never change
|
|
72 |
(or - if you change them - you will crash so bad ...)
|
|
73 |
"
|
|
74 |
argVal := argNode1 evaluate.
|
|
75 |
((recVal isMemberOf:Array) and:[argVal isMemberOf:Array]) ifTrue:[
|
|
76 |
(selector == #with:collect:) ifTrue:[
|
|
77 |
(argNode2 isMemberOf:BlockNode) ifTrue:[
|
|
78 |
(SignalSet anySignal catch:[
|
|
79 |
result := recVal perform:selector with:argVal with:(argNode2 evaluate).
|
|
80 |
]) ifTrue:[
|
|
81 |
^ 'error in constant expression'
|
|
82 |
].
|
|
83 |
^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result
|
|
84 |
]
|
|
85 |
]
|
|
86 |
]
|
|
87 |
]
|
|
88 |
]
|
|
89 |
]
|
|
90 |
].
|
|
91 |
^ (self basicNew) receiver:recNode selector:selectorString args:(Array with:argNode1 with:argNode2) lineno:0
|
|
92 |
!
|
|
93 |
|
0
|
94 |
receiver:recNode selector:selectorString arg:argNode
|
|
95 |
^ self receiver:recNode selector:selectorString arg:argNode fold:true
|
|
96 |
!
|
|
97 |
|
|
98 |
receiver:recNode selector:selectorString arg:argNode fold:folding
|
53
|
99 |
|result recVal argVal selector canFold|
|
0
|
100 |
|
20
|
101 |
"
|
|
102 |
The constant folding code can usually not optimize much
|
|
103 |
- this may change when some kind of constant/macro declaration is added to smalltalk.
|
|
104 |
"
|
0
|
105 |
folding ifTrue:[
|
47
|
106 |
"do constant folding ..."
|
|
107 |
(recNode isConstant and:[argNode isConstant]) ifTrue:[
|
|
108 |
"check if we can do it ..."
|
63
|
109 |
selector := selectorString asSymbolIfInterned.
|
|
110 |
selector notNil ifTrue:[
|
47
|
111 |
recVal := recNode evaluate.
|
|
112 |
(recVal respondsTo:selector) ifTrue:[
|
53
|
113 |
canFold := false.
|
47
|
114 |
"
|
|
115 |
we could do much more here - but then, we need a dependency from
|
|
116 |
the folded selectors method to the method we generate code for ...
|
|
117 |
limit optimizations to those that will never change
|
|
118 |
(or - if you change them - you will crash so bad ...)
|
|
119 |
"
|
|
120 |
argVal := argNode evaluate.
|
|
121 |
(recVal respondsToArithmetic and:[argVal respondsToArithmetic]) ifTrue:[
|
|
122 |
(#( @ + - * / // \\ min: max: quo:) includes:selector) ifTrue:[
|
|
123 |
(#( / // \\ ) includes:selector) ifTrue:[
|
|
124 |
argVal = 0 ifTrue:[
|
|
125 |
^ 'division by zero in constant expression'
|
|
126 |
].
|
|
127 |
].
|
53
|
128 |
canFold := true
|
47
|
129 |
]
|
|
130 |
].
|
|
131 |
(recVal isMemberOf:String) ifTrue:[
|
53
|
132 |
(argVal isInteger and:[selector == #at:]) ifTrue:[
|
|
133 |
canFold := true
|
47
|
134 |
].
|
53
|
135 |
((argVal isMemberOf:String) and:[selector == #',']) ifTrue:[
|
|
136 |
canFold := true
|
47
|
137 |
]
|
53
|
138 |
].
|
|
139 |
canFold ifTrue:[
|
|
140 |
(SignalSet anySignal catch:[
|
|
141 |
result := recVal perform:selector with:argVal.
|
|
142 |
]) ifTrue:[
|
|
143 |
^ 'error in constant expression'
|
|
144 |
].
|
|
145 |
^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result
|
47
|
146 |
]
|
|
147 |
]
|
|
148 |
]
|
53
|
149 |
].
|
|
150 |
"
|
|
151 |
the folloing optimization cannot be done (although it would be nice)
|
|
152 |
since the array may be modified later.
|
|
153 |
"
|
|
154 |
"/ (recNode isGlobal and:[argNode isConstant])ifTrue:[
|
|
155 |
"/ selectorString knownAsSymbol ifTrue:[
|
|
156 |
"/ selector := selectorString asSymbol.
|
|
157 |
"/ recVal := recNode evaluate.
|
|
158 |
"/ (recVal respondsTo:selector) ifTrue:[
|
|
159 |
"/ (recVal == FloatArray) ifTrue:[
|
|
160 |
"/ argVal := argNode evaluate.
|
|
161 |
"/ (argVal isMemberOf:Array) ifTrue:[
|
|
162 |
"/ (SignalSet anySignal catch:[
|
|
163 |
"/ result := recVal perform:selector with:argVal with:argVal.
|
|
164 |
"/ ]) ifTrue:[
|
|
165 |
"/ ^ 'error in constant expression'
|
|
166 |
"/ ].
|
|
167 |
"/ ^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result
|
|
168 |
"/ ]
|
|
169 |
"/ ]
|
|
170 |
"/ ]
|
|
171 |
"/ ]
|
|
172 |
"/ ]
|
0
|
173 |
].
|
|
174 |
^ (self basicNew) receiver:recNode selector:selectorString args:(Array with:argNode) lineno:0
|
|
175 |
!
|
|
176 |
|
|
177 |
receiver:recNode selector:selectorString args:anArray
|
|
178 |
^ self receiver:recNode selector:selectorString args:anArray fold:true
|
|
179 |
!
|
|
180 |
|
|
181 |
receiver:recNode selector:selectorString args:argArray fold:folding
|
117
|
182 |
|numArgs|
|
|
183 |
|
|
184 |
numArgs := argArray size.
|
20
|
185 |
folding ifTrue:[
|
117
|
186 |
(numArgs == 1) ifTrue:[
|
47
|
187 |
^ self receiver:recNode selector:selectorString arg:(argArray at:1) fold:true
|
|
188 |
].
|
20
|
189 |
|
47
|
190 |
"uncomment the follwoing for a nice array initializer optimization ..."
|
117
|
191 |
"/ (numArgs == 2) ifTrue:[
|
20
|
192 |
"/ ^ self receiver:recNode selector:selectorString arg1:(argArray at:1) arg2:(argArray at:2) fold:true
|
|
193 |
"/ ].
|
117
|
194 |
numArgs > Method maxNumberOfArguments ifTrue:[
|
|
195 |
^ 'too many arguments for current VM implementation'.
|
|
196 |
].
|
0
|
197 |
].
|
117
|
198 |
|
0
|
199 |
^ (self basicNew) receiver:recNode selector:selectorString args:argArray lineno:0
|
117
|
200 |
|
|
201 |
"Modified: 3.9.1995 / 16:41:39 / claus"
|
0
|
202 |
! !
|
|
203 |
|
3
|
204 |
!MessageNode class methodsFor:'queries'!
|
0
|
205 |
|
6
|
206 |
hasLineNumber:sel
|
|
207 |
"return true, if special send code needs lineNr"
|
|
208 |
|
|
209 |
(sel == #==) ifTrue:[^ false].
|
|
210 |
(sel == #~~) ifTrue:[^ false].
|
|
211 |
(sel == #class) ifTrue:[^ false].
|
76
|
212 |
(sel == #isNil) ifTrue:[^ false].
|
|
213 |
(sel == #notNil) ifTrue:[^ false].
|
6
|
214 |
^ true
|
|
215 |
!
|
|
216 |
|
140
|
217 |
isBuiltIn1ArgSelector:sel
|
|
218 |
"return true, if selector sel is built-in.
|
|
219 |
(i.e. there is a single bytecode for it)"
|
|
220 |
|
|
221 |
(sel == #at:) ifTrue:[^ true].
|
|
222 |
(sel == #value:) ifTrue:[^ true].
|
|
223 |
(sel == #bitAnd:) ifTrue:[^ true].
|
|
224 |
(sel == #bitOr:) ifTrue:[^ true].
|
|
225 |
(sel == #new:) ifTrue:[^ true].
|
|
226 |
(sel == #basicNew:) ifTrue:[^ true].
|
|
227 |
^ false
|
|
228 |
!
|
|
229 |
|
|
230 |
isBuiltIn2ArgSelector:sel
|
|
231 |
"return true, if selector sel is built-in.
|
|
232 |
(i.e. there is a single bytecode for it)"
|
|
233 |
|
|
234 |
(sel == #at:put:) ifTrue:[^ true].
|
|
235 |
^ false
|
|
236 |
!
|
|
237 |
|
0
|
238 |
isBuiltInUnarySelector:sel
|
19
|
239 |
"return true, if unary selector sel is built-in.
|
|
240 |
(i.e. there is a single bytecode for it)"
|
0
|
241 |
|
|
242 |
(sel == #peek) ifTrue:[^ true].
|
|
243 |
(sel == #value) ifTrue:[^ true].
|
|
244 |
(sel == #next) ifTrue:[^ true].
|
|
245 |
(sel == #class) ifTrue:[^ true].
|
|
246 |
(sel == #size) ifTrue:[^ true].
|
|
247 |
(sel == #x) ifTrue:[^ true].
|
|
248 |
(sel == #y) ifTrue:[^ true].
|
|
249 |
(sel == #width) ifTrue:[^ true].
|
|
250 |
(sel == #height) ifTrue:[^ true].
|
|
251 |
(sel == #origin) ifTrue:[^ true].
|
|
252 |
(sel == #extent) ifTrue:[^ true].
|
6
|
253 |
(sel == #asInteger) ifTrue:[^ true].
|
|
254 |
(sel == #rounded) ifTrue:[^ true].
|
76
|
255 |
(sel == #isNil) ifTrue:[^ true].
|
|
256 |
(sel == #notNil) ifTrue:[^ true].
|
|
257 |
(sel == #not) ifTrue:[^ true].
|
106
|
258 |
(sel == #new) ifTrue:[^ true].
|
|
259 |
(sel == #basicNew) ifTrue:[^ true].
|
0
|
260 |
^ false
|
|
261 |
! !
|
|
262 |
|
140
|
263 |
!MessageNode methodsFor:'accessing'!
|
0
|
264 |
|
140
|
265 |
arg1
|
|
266 |
^ argArray at:1
|
|
267 |
!
|
0
|
268 |
|
140
|
269 |
args
|
|
270 |
^ argArray
|
|
271 |
!
|
0
|
272 |
|
140
|
273 |
lineNumber
|
|
274 |
^ lineNr
|
0
|
275 |
!
|
|
276 |
|
140
|
277 |
lineNumber:num
|
|
278 |
lineNr := num
|
|
279 |
!
|
0
|
280 |
|
140
|
281 |
receiver
|
|
282 |
^ receiver
|
|
283 |
!
|
0
|
284 |
|
140
|
285 |
receiver:r selector:s args:a lineno:l
|
|
286 |
receiver := r.
|
|
287 |
selector := s asSymbol.
|
|
288 |
argArray := a.
|
|
289 |
lineNr := l
|
|
290 |
!
|
|
291 |
|
|
292 |
selector
|
|
293 |
^ selector
|
0
|
294 |
! !
|
|
295 |
|
|
296 |
!MessageNode methodsFor:'checks'!
|
|
297 |
|
|
298 |
plausibilityCheck
|
|
299 |
|rec arg operand|
|
|
300 |
|
3
|
301 |
"
|
|
302 |
it once took me almost an hour, to find a '==' which
|
|
303 |
should have been an '=' (you cannot compare floats with ==)
|
19
|
304 |
(well, I looked at the '==' at least 50 times -
|
|
305 |
- but didn't think about it ...).
|
|
306 |
thats reason enough to add this check here.
|
|
307 |
I will add more as heuristic knowledge increases ...
|
|
308 |
(send me comments on common programming errors ...)
|
|
309 |
"
|
|
310 |
|
|
311 |
"
|
|
312 |
check #== appled to Floats, Strings or Fractions
|
0
|
313 |
"
|
|
314 |
((selector == #==) or:[selector == #~~]) ifTrue:[
|
47
|
315 |
receiver isConstant ifTrue:[
|
|
316 |
rec := receiver evaluate.
|
|
317 |
((rec isMemberOf:String) or:[
|
|
318 |
(rec isMemberOf:Float) or:[
|
|
319 |
(rec isMemberOf:Fraction)]]) ifTrue:[
|
|
320 |
operand := rec
|
|
321 |
].
|
|
322 |
].
|
|
323 |
(argArray at:1) isConstant ifTrue:[
|
|
324 |
arg := (argArray at:1) evaluate.
|
|
325 |
((arg isMemberOf:String) or:[
|
|
326 |
(arg isMemberOf:Float) or:[
|
|
327 |
(arg isMemberOf:Fraction)]]) ifTrue:[
|
|
328 |
operand := arg
|
|
329 |
].
|
|
330 |
].
|
|
331 |
operand notNil ifTrue:[
|
|
332 |
(selector == #==) ifTrue:[
|
|
333 |
^ 'identity compare is unsafe here'
|
|
334 |
].
|
|
335 |
^ 'identity compare will usually return true here'
|
|
336 |
]
|
0
|
337 |
].
|
3
|
338 |
|
|
339 |
"
|
19
|
340 |
[...] ifTrue:...
|
3
|
341 |
an error often occuring when you are a beginner ...
|
|
342 |
"
|
|
343 |
((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[
|
47
|
344 |
receiver isBlock ifTrue:[
|
|
345 |
(Block canUnderstand:selector) ifFalse:[
|
|
346 |
^ 'blocks usually do not respond to ' , selector , ' messages'
|
|
347 |
].
|
|
348 |
].
|
|
349 |
(argArray at:1) isBlock ifFalse:[
|
|
350 |
^ 'will fail at runtime, if argument to ' , selector , ' does not evaluate to a block'
|
|
351 |
]
|
3
|
352 |
].
|
19
|
353 |
((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[
|
47
|
354 |
receiver isBlock ifTrue:[
|
|
355 |
(Block canUnderstand:selector) ifFalse:[
|
|
356 |
^ 'blocks usually do not respond to ' , selector , ' messages'
|
|
357 |
].
|
|
358 |
].
|
|
359 |
(argArray at:1) isBlock ifFalse:[
|
|
360 |
^ 'will fail at runtime, if 1st. argument to ' , selector , ' does not evaluate to a block'
|
|
361 |
].
|
|
362 |
(argArray at:2) isBlock ifFalse:[
|
|
363 |
^ 'will fail at runtime, if 2nd. argument to ' , selector , ' does not evaluate to a block'
|
|
364 |
]
|
3
|
365 |
].
|
19
|
366 |
|
|
367 |
"
|
|
368 |
(...) whileTrue:[
|
|
369 |
"
|
3
|
370 |
((selector == #whileTrue:) or:[selector == #whileFalse:]) ifTrue:[
|
47
|
371 |
receiver isBlock ifFalse:[
|
|
372 |
"
|
|
373 |
only warn, if code was originally parenthized
|
|
374 |
"
|
|
375 |
receiver parenthized ifTrue:[
|
|
376 |
^ 'will fail at runtime, if receiver of ' , selector , ' does not evaluate to a block'
|
|
377 |
]
|
|
378 |
].
|
|
379 |
(argArray at:1) isBlock ifFalse:[
|
|
380 |
^ 'will fail at runtime, if argument to ' , selector , ' does not evaluate to a block'
|
|
381 |
].
|
3
|
382 |
].
|
0
|
383 |
^ nil
|
|
384 |
! !
|
|
385 |
|
|
386 |
!MessageNode methodsFor:'code generation'!
|
|
387 |
|
106
|
388 |
XXcodeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
|
|
389 |
"generate code for [...] whilexxx:[ ... ]"
|
|
390 |
|
|
391 |
|pos pos2 theReceiver theArg theByteCode optByteCode|
|
|
392 |
|
|
393 |
(selector == #whileTrue:) ifTrue:[
|
47
|
394 |
theByteCode := #falseJump
|
0
|
395 |
] ifFalse:[
|
47
|
396 |
theByteCode := #trueJump
|
0
|
397 |
].
|
|
398 |
|
|
399 |
theReceiver := receiver.
|
|
400 |
optByteCode := self optimizedConditionFor:theReceiver with:theByteCode.
|
|
401 |
optByteCode notNil ifTrue:[
|
47
|
402 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
|
|
403 |
theArg := receiver statements expression arg1
|
|
404 |
].
|
|
405 |
theReceiver := receiver statements expression receiver.
|
|
406 |
theByteCode := optByteCode
|
0
|
407 |
].
|
|
408 |
|
|
409 |
valueNeeded ifTrue:[aStream nextPut:#pushNil].
|
|
410 |
pos := aStream position.
|
|
411 |
optByteCode notNil ifTrue:[
|
104
|
412 |
theReceiver codeOn:aStream inBlock:b for:aCompiler.
|
47
|
413 |
theArg notNil ifTrue:[
|
104
|
414 |
theArg codeOn:aStream inBlock:b for:aCompiler
|
47
|
415 |
]
|
0
|
416 |
] ifFalse:[
|
104
|
417 |
theReceiver codeInlineOn:aStream inBlock:b for:aCompiler
|
0
|
418 |
].
|
53
|
419 |
|
|
420 |
(lineNr between:1 and:255) ifTrue:[
|
95
|
421 |
aStream nextPut:#lineno; nextPut:lineNr.
|
53
|
422 |
].
|
|
423 |
|
0
|
424 |
aStream nextPut:theByteCode.
|
|
425 |
pos2 := aStream position.
|
|
426 |
aStream nextPut:0.
|
|
427 |
valueNeeded ifTrue:[aStream nextPut:#drop].
|
104
|
428 |
(argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
95
|
429 |
aStream nextPut:#jump; nextPut:pos.
|
106
|
430 |
(aStream contents) at:pos2 put:(aStream position).
|
0
|
431 |
!
|
|
432 |
|
140
|
433 |
codeAndIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
|
|
434 |
"generate code for (x and:[y]) ifxxx:[ ... ]"
|
|
435 |
|
|
436 |
|theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp|
|
|
437 |
|
|
438 |
|
|
439 |
theByteCode := #falseJump.
|
|
440 |
theReceiver := receiver receiver.
|
0
|
441 |
|
140
|
442 |
optByteCode := self optimizedConditionFor:theReceiver
|
|
443 |
with:theByteCode.
|
|
444 |
optByteCode notNil ifTrue:[
|
|
445 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
|
|
446 |
theArg := theReceiver arg1
|
|
447 |
].
|
|
448 |
theReceiver := theReceiver receiver.
|
|
449 |
theByteCode := optByteCode
|
|
450 |
].
|
104
|
451 |
theReceiver codeOn:aStream inBlock:b for:aCompiler.
|
140
|
452 |
theArg notNil ifTrue:[
|
|
453 |
theArg codeOn:aStream inBlock:b for:aCompiler
|
|
454 |
].
|
|
455 |
aStream nextPut:theByteCode.
|
|
456 |
pos1 := aStream position.
|
|
457 |
aStream nextPut:0.
|
0
|
458 |
|
140
|
459 |
theReceiver := receiver arg1.
|
|
460 |
theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
|
|
461 |
(selector == #ifTrue:) ifTrue:[
|
|
462 |
jmp := #falseJump
|
|
463 |
] ifFalse:[
|
|
464 |
jmp := #trueJump
|
|
465 |
].
|
|
466 |
aStream nextPut:jmp.
|
0
|
467 |
pos2 := aStream position.
|
|
468 |
aStream nextPut:0.
|
|
469 |
|
140
|
470 |
code := aStream contents.
|
|
471 |
(selector == #ifFalse:) ifTrue:[
|
|
472 |
code at:pos1 put:(aStream position)
|
|
473 |
].
|
|
474 |
(argArray at: 1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
|
475 |
|
|
476 |
valueNeeded ifTrue:[
|
|
477 |
aStream nextPut:#jump.
|
|
478 |
pos3 := aStream position.
|
|
479 |
aStream nextPut:0.
|
|
480 |
here := aStream position.
|
|
481 |
(selector == #ifTrue:) ifTrue:[
|
|
482 |
code at:pos1 put:here
|
|
483 |
].
|
|
484 |
code at:pos2 put:here.
|
|
485 |
aStream nextPut:#pushNil.
|
|
486 |
code at:pos3 put:(aStream position)
|
|
487 |
] ifFalse:[
|
|
488 |
here := aStream position.
|
|
489 |
(selector == #ifTrue:) ifTrue:[
|
|
490 |
code at:pos1 put:here
|
|
491 |
].
|
|
492 |
code at:pos2 put:here
|
|
493 |
]
|
|
494 |
!
|
|
495 |
|
|
496 |
codeAndOrOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
|
|
497 |
"generate code for x and/or:[y] - but not in an if"
|
|
498 |
|
|
499 |
|pos theReceiver theByteCode|
|
|
500 |
|
|
501 |
self halt.
|
|
502 |
theReceiver := receiver.
|
|
503 |
(selector == #and:) ifTrue:[
|
|
504 |
theByteCode := #falseJump
|
|
505 |
] ifFalse:[
|
|
506 |
theByteCode := #trueJump
|
|
507 |
].
|
|
508 |
"
|
|
509 |
(self canOptimizeConditionFor:receiver) ifTrue:[
|
|
510 |
theByteCode := self optimizedConditionFor:theReceiver
|
|
511 |
with:theByteCode.
|
|
512 |
theReceiver := theReceiver receiver
|
|
513 |
].
|
|
514 |
"
|
|
515 |
theReceiver codeOn:aStream inBlock:b for:aCompiler.
|
|
516 |
aStream nextPut:theByteCode.
|
|
517 |
pos := aStream position.
|
|
518 |
aStream nextPut:0.
|
|
519 |
(argArray at: 1) codeInlineOn:aStream inBlock:b for:aCompiler.
|
|
520 |
(aStream contents) at:pos put:(aStream position).
|
|
521 |
valueNeeded ifFalse:[aStream nextPut:#drop]
|
|
522 |
!
|
|
523 |
|
|
524 |
codeForCascadeOn:aStream inBlock:b for:aCompiler
|
|
525 |
"like codeOn, but always leave the receiver instead of the result"
|
|
526 |
|
|
527 |
|nargs isBuiltIn code litIndex|
|
|
528 |
|
|
529 |
argArray isNil ifTrue:[
|
|
530 |
nargs := 0
|
|
531 |
] ifFalse:[
|
|
532 |
nargs := argArray size
|
|
533 |
].
|
|
534 |
|
|
535 |
isBuiltIn := false.
|
0
|
536 |
|
140
|
537 |
(nargs == 0) ifTrue:[
|
|
538 |
isBuiltIn := self class isBuiltInUnarySelector:selector
|
|
539 |
].
|
|
540 |
(nargs == 1) ifTrue:[
|
|
541 |
isBuiltIn := self class isBuiltIn1ArgSelector:selector
|
|
542 |
].
|
|
543 |
(nargs == 2) ifTrue:[
|
|
544 |
isBuiltIn := self class isBuiltIn2ArgSelector:selector
|
|
545 |
].
|
|
546 |
|
|
547 |
receiver codeOn:aStream inBlock:b for:aCompiler.
|
|
548 |
aStream nextPut:#dup.
|
|
549 |
|
|
550 |
"can we use a send-bytecode ?"
|
|
551 |
isBuiltIn ifTrue:[
|
|
552 |
receiver isSuper ifFalse:[
|
|
553 |
(nargs > 0) ifTrue:[
|
|
554 |
(argArray at:1) codeOn:aStream inBlock:b for:aCompiler.
|
|
555 |
(nargs > 1) ifTrue:[
|
|
556 |
(argArray at:2) codeOn:aStream inBlock:b for:aCompiler
|
|
557 |
]
|
|
558 |
].
|
|
559 |
aStream nextPut:selector.
|
|
560 |
(self class hasLineNumber:selector) ifTrue:[
|
|
561 |
aStream nextPut:lineNr.
|
|
562 |
].
|
|
563 |
aStream nextPut:#drop.
|
|
564 |
^ self
|
|
565 |
]
|
|
566 |
].
|
|
567 |
|
|
568 |
"no - generate a send"
|
|
569 |
argArray notNil ifTrue:[
|
|
570 |
argArray do:[:arg |
|
|
571 |
arg codeOn:aStream inBlock:b for:aCompiler
|
|
572 |
]
|
|
573 |
].
|
|
574 |
litIndex := aCompiler addLiteral:selector.
|
|
575 |
litIndex <= 255 ifTrue:[
|
|
576 |
receiver isSuper ifTrue:[
|
|
577 |
receiver isHere ifTrue:[
|
|
578 |
code := #hereSend
|
|
579 |
] ifFalse:[
|
|
580 |
code := #superSend.
|
|
581 |
].
|
|
582 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs; nextPut:nil; nextPut:#drop.
|
|
583 |
^ self
|
|
584 |
].
|
|
585 |
(nargs <= 3) ifTrue:[
|
|
586 |
code := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3) at:(nargs+1).
|
|
587 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex.
|
|
588 |
^ self
|
|
589 |
].
|
|
590 |
|
|
591 |
aStream nextPut:#sendDrop; nextPut:lineNr; nextPut:litIndex; nextPut:nargs.
|
|
592 |
^ self
|
|
593 |
].
|
|
594 |
"need 16bit litIndex"
|
|
595 |
receiver isSuper ifTrue:[
|
|
596 |
receiver isHere ifTrue:[
|
|
597 |
code := #hereSendL
|
|
598 |
] ifFalse:[
|
|
599 |
code := #superSendL.
|
|
600 |
].
|
|
601 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs; nextPut:nil; nextPut:#drop.
|
|
602 |
^ self
|
|
603 |
].
|
|
604 |
aStream nextPut:#sendDropL; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs
|
|
605 |
!
|
|
606 |
|
|
607 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler
|
|
608 |
self codeOn:aStream inBlock:b valueNeeded:false for:aCompiler
|
0
|
609 |
!
|
|
610 |
|
104
|
611 |
codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
|
0
|
612 |
"generate code for x ifxxx:[ ... ] yyy:[ ...]"
|
|
613 |
|
76
|
614 |
|pos pos2 theReceiver theArg theByteCode optByteCode subsel code|
|
0
|
615 |
|
|
616 |
theReceiver := receiver.
|
76
|
617 |
|
|
618 |
"
|
|
619 |
(theReceiver isMessage) ifTrue:[
|
|
620 |
subsel := theReceiver selector.
|
|
621 |
(subsel == #and:) ifTrue:[
|
104
|
622 |
self codeAndIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
76
|
623 |
^ self
|
|
624 |
].
|
|
625 |
(subsel == #or:) ifTrue:[
|
104
|
626 |
self codeOrIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
76
|
627 |
^ self
|
|
628 |
]
|
|
629 |
].
|
|
630 |
"
|
0
|
631 |
(selector == #ifTrue:ifFalse:) ifTrue:[
|
47
|
632 |
theByteCode := #falseJump
|
0
|
633 |
] ifFalse:[
|
47
|
634 |
(selector == #ifFalse:ifTrue:) ifTrue:[
|
|
635 |
theByteCode := #trueJump
|
|
636 |
]
|
0
|
637 |
].
|
|
638 |
optByteCode := self optimizedConditionFor:theReceiver
|
47
|
639 |
with:theByteCode.
|
0
|
640 |
optByteCode notNil ifTrue:[
|
47
|
641 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
|
|
642 |
theArg := theReceiver arg1
|
|
643 |
].
|
|
644 |
theReceiver := theReceiver receiver.
|
|
645 |
theByteCode := optByteCode
|
0
|
646 |
].
|
|
647 |
theByteCode notNil ifTrue:[
|
104
|
648 |
theReceiver codeOn:aStream inBlock:b for:aCompiler.
|
47
|
649 |
theArg notNil ifTrue:[
|
104
|
650 |
theArg codeOn:aStream inBlock:b for:aCompiler
|
47
|
651 |
].
|
53
|
652 |
|
|
653 |
(lineNr between:1 and:255) ifTrue:[
|
95
|
654 |
aStream nextPut:#lineno; nextPut:lineNr.
|
53
|
655 |
].
|
|
656 |
|
47
|
657 |
aStream nextPut:theByteCode.
|
|
658 |
pos := aStream position.
|
|
659 |
aStream nextPut:0.
|
104
|
660 |
(argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
47
|
661 |
aStream nextPut:#jump.
|
|
662 |
pos2 := aStream position.
|
|
663 |
aStream nextPut:0.
|
76
|
664 |
code := aStream contents.
|
|
665 |
code at:pos put:(aStream position).
|
104
|
666 |
(argArray at:2) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
76
|
667 |
code at:pos2 put:(aStream position)
|
0
|
668 |
]
|
|
669 |
!
|
|
670 |
|
104
|
671 |
codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
|
0
|
672 |
"generate code for x ifxxx:[ ... ]"
|
|
673 |
|
103
|
674 |
|pos pos2 theReceiver theArg theByteCode optByteCode subsel code
|
|
675 |
needLineNr|
|
0
|
676 |
|
|
677 |
theReceiver := receiver.
|
|
678 |
|
76
|
679 |
(theReceiver isMessage) ifTrue:[
|
47
|
680 |
subsel := theReceiver selector.
|
|
681 |
(subsel == #and:) ifTrue:[
|
104
|
682 |
self codeAndIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
47
|
683 |
^ self
|
|
684 |
].
|
|
685 |
(subsel == #or:) ifTrue:[
|
104
|
686 |
self codeOrIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
47
|
687 |
^ self
|
|
688 |
]
|
0
|
689 |
].
|
|
690 |
(selector == #ifTrue:) ifTrue:[
|
47
|
691 |
theByteCode := #falseJump
|
0
|
692 |
] ifFalse:[
|
47
|
693 |
theByteCode := #trueJump
|
0
|
694 |
].
|
|
695 |
optByteCode := self optimizedConditionFor:theReceiver
|
47
|
696 |
with:theByteCode.
|
0
|
697 |
optByteCode notNil ifTrue:[
|
47
|
698 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
|
|
699 |
theArg := theReceiver arg1
|
|
700 |
].
|
|
701 |
theReceiver := theReceiver receiver.
|
|
702 |
theByteCode := optByteCode
|
0
|
703 |
].
|
|
704 |
|
104
|
705 |
theReceiver codeOn:aStream inBlock:b for:aCompiler.
|
0
|
706 |
theArg notNil ifTrue:[
|
104
|
707 |
theArg codeOn:aStream inBlock:b for:aCompiler
|
0
|
708 |
].
|
53
|
709 |
|
103
|
710 |
needLineNr := true.
|
|
711 |
theArg isNil ifTrue:[
|
|
712 |
theReceiver isMessage ifTrue:[
|
|
713 |
(self class hasLineNumber:(theReceiver selector)) ifTrue:[
|
|
714 |
theReceiver lineNumber == lineNr ifTrue:[
|
|
715 |
needLineNr := false
|
|
716 |
]
|
|
717 |
]
|
|
718 |
]
|
|
719 |
].
|
|
720 |
|
|
721 |
needLineNr ifTrue:[
|
|
722 |
(lineNr between:1 and:255) ifTrue:[
|
|
723 |
aStream nextPut:#lineno; nextPut:lineNr.
|
|
724 |
]
|
53
|
725 |
].
|
|
726 |
|
0
|
727 |
aStream nextPut:theByteCode.
|
|
728 |
pos := aStream position.
|
|
729 |
aStream nextPut:0.
|
104
|
730 |
(argArray at: 1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
76
|
731 |
|
|
732 |
code := aStream contents.
|
0
|
733 |
valueNeeded ifTrue:[
|
47
|
734 |
aStream nextPut:#jump.
|
|
735 |
pos2 := aStream position.
|
|
736 |
aStream nextPut:0.
|
76
|
737 |
code at:pos put:(aStream position).
|
47
|
738 |
aStream nextPut:#pushNil.
|
76
|
739 |
code at:pos2 put:(aStream position)
|
0
|
740 |
] ifFalse:[
|
76
|
741 |
code at:pos put:(aStream position)
|
0
|
742 |
]
|
|
743 |
!
|
|
744 |
|
140
|
745 |
codeOn:aStream inBlock:b for:aCompiler
|
|
746 |
self codeOn:aStream inBlock:b valueNeeded:true for:aCompiler
|
0
|
747 |
!
|
|
748 |
|
104
|
749 |
codeOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
|
117
|
750 |
|recType nargs isBuiltIn litIndex cls clsLitIndex code|
|
0
|
751 |
|
|
752 |
argArray isNil ifTrue:[
|
47
|
753 |
nargs := 0
|
0
|
754 |
] ifFalse:[
|
47
|
755 |
nargs := argArray size
|
0
|
756 |
].
|
|
757 |
|
|
758 |
isBuiltIn := false.
|
117
|
759 |
recType := receiver type.
|
0
|
760 |
|
|
761 |
(nargs == 0) ifTrue:[
|
117
|
762 |
(recType == #ThisContext) ifTrue:[
|
47
|
763 |
valueNeeded ifFalse:[
|
|
764 |
"for now, only do it in methods"
|
|
765 |
b isNil ifTrue:[
|
|
766 |
(selector == #restart) ifTrue:[
|
95
|
767 |
aStream nextPut:#jump; nextPut:1. "jump to start"
|
47
|
768 |
^ self
|
|
769 |
].
|
|
770 |
].
|
|
771 |
(selector == #return) ifTrue:[ "^ nil"
|
|
772 |
aStream nextPut:#retNil.
|
|
773 |
^ self
|
|
774 |
].
|
|
775 |
]
|
|
776 |
].
|
52
|
777 |
|
|
778 |
receiver isBlock ifTrue:[
|
|
779 |
selector == #value ifTrue:[
|
104
|
780 |
receiver codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
52
|
781 |
^ self
|
|
782 |
].
|
|
783 |
].
|
47
|
784 |
isBuiltIn := self class isBuiltInUnarySelector:selector
|
0
|
785 |
].
|
|
786 |
|
|
787 |
(nargs == 1) ifTrue:[
|
117
|
788 |
(recType == #ThisContext) ifTrue:[
|
47
|
789 |
valueNeeded ifFalse:[
|
|
790 |
(selector == #return:) ifTrue:[
|
104
|
791 |
(argArray at:1) codeOn:aStream inBlock:b for:aCompiler. "^ value"
|
47
|
792 |
aStream nextPut:#retTop.
|
|
793 |
^ self
|
|
794 |
].
|
|
795 |
].
|
|
796 |
].
|
19
|
797 |
|
47
|
798 |
((argArray at:1) isBlock) ifTrue:[
|
|
799 |
((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[
|
55
|
800 |
receiver isBlock ifFalse:[
|
104
|
801 |
self codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
55
|
802 |
^ self
|
|
803 |
].
|
47
|
804 |
].
|
0
|
805 |
"
|
47
|
806 |
((selector == #and:) or:[selector == #or:]) ifTrue:[
|
104
|
807 |
self codeAndOrOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
47
|
808 |
^ self
|
|
809 |
].
|
0
|
810 |
"
|
47
|
811 |
(selector == #timesRepeat:) ifTrue:[
|
|
812 |
(receiver isConstant and:[receiver evaluate isNumber]) ifTrue:[
|
104
|
813 |
self codeTimesRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
47
|
814 |
^ self
|
|
815 |
]
|
|
816 |
].
|
0
|
817 |
|
47
|
818 |
((selector == #whileTrue:) or:[selector == #whileFalse:]) ifTrue:[
|
|
819 |
(receiver isBlock) ifTrue:[
|
104
|
820 |
self codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
47
|
821 |
^ self
|
|
822 |
]
|
|
823 |
]
|
|
824 |
].
|
|
825 |
isBuiltIn := self class isBuiltIn1ArgSelector:selector
|
0
|
826 |
].
|
|
827 |
|
|
828 |
(nargs == 2) ifTrue:[
|
47
|
829 |
((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[
|
55
|
830 |
receiver isBlock ifFalse:[
|
|
831 |
(argArray at:1) isBlock ifTrue:[
|
|
832 |
(argArray at:2) isBlock ifTrue:[
|
104
|
833 |
self codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
55
|
834 |
^ self
|
|
835 |
]
|
47
|
836 |
]
|
|
837 |
]
|
|
838 |
].
|
|
839 |
isBuiltIn := self class isBuiltIn2ArgSelector:selector
|
0
|
840 |
].
|
|
841 |
|
|
842 |
"can we use a send-bytecode ?"
|
|
843 |
isBuiltIn ifTrue:[
|
48
|
844 |
receiver isSuper ifFalse:[
|
104
|
845 |
receiver codeOn:aStream inBlock:b for:aCompiler.
|
47
|
846 |
(nargs > 0) ifTrue:[
|
104
|
847 |
(argArray at:1) codeOn:aStream inBlock:b for:aCompiler.
|
47
|
848 |
(nargs > 1) ifTrue:[
|
104
|
849 |
(argArray at:2) codeOn:aStream inBlock:b for:aCompiler
|
47
|
850 |
]
|
|
851 |
].
|
|
852 |
aStream nextPut:selector.
|
|
853 |
(self class hasLineNumber:selector) ifTrue:[
|
|
854 |
aStream nextPut:lineNr.
|
|
855 |
].
|
|
856 |
valueNeeded ifFalse:[
|
|
857 |
aStream nextPut:#drop
|
|
858 |
].
|
|
859 |
^ self
|
|
860 |
]
|
0
|
861 |
].
|
|
862 |
|
|
863 |
((nargs == 0) and:[selector == #yourself]) ifTrue:[
|
47
|
864 |
"yourself is often added to get the receiver -
|
|
865 |
we get it without the yourself-message"
|
0
|
866 |
|
47
|
867 |
valueNeeded ifTrue:[
|
104
|
868 |
receiver codeOn:aStream inBlock:b for:aCompiler
|
47
|
869 |
].
|
|
870 |
^ self
|
0
|
871 |
].
|
|
872 |
|
|
873 |
"no - generate a send"
|
117
|
874 |
|
|
875 |
receiver isSuper ifTrue:[
|
|
876 |
cls := aCompiler targetClass.
|
|
877 |
receiver isHere ifTrue:[
|
|
878 |
code := #hereSend.
|
|
879 |
] ifFalse:[
|
|
880 |
code := #superSend.
|
|
881 |
cls := cls superclass.
|
|
882 |
].
|
|
883 |
clsLitIndex := aCompiler addLiteral:cls.
|
|
884 |
] ifFalse:[
|
|
885 |
clsLitIndex := 0.
|
0
|
886 |
].
|
106
|
887 |
|
117
|
888 |
litIndex := aCompiler addLiteral:selector.
|
|
889 |
(litIndex <= 255 and:[clsLitIndex <= 255]) ifTrue:[
|
|
890 |
(recType ~~ #Self) ifTrue:[
|
|
891 |
receiver codeOn:aStream inBlock:b for:aCompiler
|
|
892 |
].
|
|
893 |
argArray notNil ifTrue:[
|
|
894 |
argArray do:[:arg |
|
|
895 |
arg codeOn:aStream inBlock:b for:aCompiler
|
|
896 |
]
|
|
897 |
].
|
|
898 |
|
106
|
899 |
receiver isSuper ifTrue:[
|
117
|
900 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs; nextPut:clsLitIndex.
|
106
|
901 |
valueNeeded ifFalse:[
|
|
902 |
aStream nextPut:#drop
|
|
903 |
].
|
|
904 |
^ self
|
|
905 |
].
|
|
906 |
|
|
907 |
(nargs <= 3) ifTrue:[
|
|
908 |
|codes|
|
|
909 |
|
|
910 |
valueNeeded ifTrue:[
|
|
911 |
(receiver type == #Self) ifTrue:[
|
|
912 |
codes := #(sendSelf0 sendSelf1 sendSelf2 sendSelf3)
|
|
913 |
] ifFalse:[
|
|
914 |
codes := #(send0 send1 send2 send3)
|
|
915 |
]
|
|
916 |
] ifFalse:[
|
|
917 |
(receiver type == #Self) ifTrue:[
|
|
918 |
codes := #(sendSelfDrop0 sendSelfDrop1 sendSelfDrop2 sendSelfDrop3)
|
|
919 |
] ifFalse:[
|
|
920 |
codes := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3)
|
|
921 |
]
|
|
922 |
].
|
117
|
923 |
aStream nextPut:(codes at:(nargs + 1)); nextPut:lineNr; nextPut:litIndex.
|
106
|
924 |
^ self
|
|
925 |
].
|
|
926 |
|
117
|
927 |
(recType == #Self) ifTrue:[
|
|
928 |
code := #sendSelf
|
106
|
929 |
] ifFalse:[
|
117
|
930 |
valueNeeded ifTrue:[
|
|
931 |
code := #send
|
|
932 |
] ifFalse:[
|
|
933 |
code := #sendDrop
|
|
934 |
]
|
106
|
935 |
].
|
117
|
936 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs.
|
|
937 |
valueNeeded ifFalse:[
|
|
938 |
(recType == #Self) ifTrue:[
|
|
939 |
aStream nextPut:#drop
|
|
940 |
]
|
|
941 |
].
|
106
|
942 |
^ self
|
|
943 |
].
|
|
944 |
|
|
945 |
"needs 16bit literal index"
|
117
|
946 |
|
48
|
947 |
receiver isSuper ifTrue:[
|
117
|
948 |
argArray notNil ifTrue:[
|
|
949 |
argArray do:[:arg |
|
|
950 |
arg codeOn:aStream inBlock:b for:aCompiler
|
|
951 |
]
|
|
952 |
].
|
49
|
953 |
receiver isHere ifTrue:[
|
106
|
954 |
code := #hereSendL
|
49
|
955 |
] ifFalse:[
|
106
|
956 |
code := #superSendL.
|
49
|
957 |
].
|
117
|
958 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs; nextPut:clsLitIndex; nextPut:0.
|
|
959 |
] ifFalse:[
|
|
960 |
recType ~~ #Self ifTrue:[
|
|
961 |
receiver codeOn:aStream inBlock:b for:aCompiler.
|
47
|
962 |
].
|
117
|
963 |
argArray notNil ifTrue:[
|
|
964 |
argArray do:[:arg |
|
|
965 |
arg codeOn:aStream inBlock:b for:aCompiler
|
|
966 |
]
|
|
967 |
].
|
|
968 |
|
|
969 |
recType == #Self ifTrue:[
|
|
970 |
code := #sendSelfL
|
|
971 |
] ifFalse:[
|
|
972 |
code := #sendL
|
|
973 |
].
|
|
974 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs.
|
0
|
975 |
].
|
117
|
976 |
valueNeeded ifFalse:[
|
|
977 |
aStream nextPut:#drop
|
0
|
978 |
].
|
117
|
979 |
|
|
980 |
"Modified: 3.9.1995 / 12:55:42 / claus"
|
0
|
981 |
!
|
|
982 |
|
140
|
983 |
codeOrIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
|
|
984 |
"generate code for (x or:[y]) ifxxx:[ ... ]"
|
|
985 |
|
|
986 |
|theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp|
|
|
987 |
|
|
988 |
theByteCode := #trueJump.
|
|
989 |
theReceiver := receiver receiver.
|
|
990 |
|
|
991 |
optByteCode := self optimizedConditionFor:theReceiver with:theByteCode.
|
|
992 |
optByteCode notNil ifTrue:[
|
|
993 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
|
|
994 |
theArg := theReceiver arg1
|
|
995 |
].
|
|
996 |
theReceiver := theReceiver receiver.
|
|
997 |
theByteCode := optByteCode
|
|
998 |
].
|
|
999 |
theReceiver codeOn:aStream inBlock:b for:aCompiler.
|
|
1000 |
theArg notNil ifTrue:[
|
|
1001 |
theArg codeOn:aStream inBlock:b for:aCompiler
|
|
1002 |
].
|
|
1003 |
aStream nextPut:theByteCode.
|
|
1004 |
pos1 := aStream position.
|
|
1005 |
aStream nextPut:0.
|
|
1006 |
|
|
1007 |
|
|
1008 |
theReceiver := receiver arg1.
|
|
1009 |
|
|
1010 |
"new:"
|
|
1011 |
(selector == #ifTrue:) ifTrue:[
|
|
1012 |
theByteCode := #falseJump
|
|
1013 |
] ifFalse:[
|
|
1014 |
theByteCode := #trueJump
|
|
1015 |
].
|
|
1016 |
optByteCode := self optimizedConditionFor:theReceiver with:theByteCode.
|
|
1017 |
optByteCode notNil ifTrue:[
|
|
1018 |
theReceiver isBlock ifTrue:[
|
|
1019 |
theReceiver := theReceiver statements expression
|
|
1020 |
].
|
|
1021 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
|
|
1022 |
theArg := theReceiver arg1
|
|
1023 |
].
|
|
1024 |
theReceiver := theReceiver receiver.
|
|
1025 |
theByteCode := optByteCode.
|
|
1026 |
|
|
1027 |
theReceiver codeOn:aStream inBlock:b for:aCompiler.
|
|
1028 |
theArg notNil ifTrue:[
|
|
1029 |
theArg codeOn:aStream inBlock:b for:aCompiler
|
|
1030 |
].
|
|
1031 |
aStream nextPut:theByteCode.
|
|
1032 |
|
|
1033 |
] ifFalse:[
|
|
1034 |
"org"
|
|
1035 |
theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
|
|
1036 |
(selector == #ifTrue:) ifTrue:[
|
|
1037 |
jmp := #falseJump
|
|
1038 |
] ifFalse:[
|
|
1039 |
jmp := #trueJump
|
|
1040 |
].
|
|
1041 |
aStream nextPut:jmp
|
|
1042 |
].
|
|
1043 |
pos2 := aStream position.
|
|
1044 |
aStream nextPut:0.
|
|
1045 |
(selector == #ifTrue:) ifTrue:[
|
|
1046 |
(aStream contents) at:pos1 put:(aStream position)
|
|
1047 |
].
|
|
1048 |
(argArray at: 1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
|
1049 |
|
|
1050 |
code := aStream contents.
|
|
1051 |
valueNeeded ifTrue:[
|
|
1052 |
aStream nextPut:#jump.
|
|
1053 |
pos3 := aStream position.
|
|
1054 |
aStream nextPut:0.
|
|
1055 |
here := aStream position.
|
|
1056 |
(selector == #ifFalse:) ifTrue:[
|
|
1057 |
code at:pos1 put:here
|
|
1058 |
].
|
|
1059 |
code at:pos2 put:here.
|
|
1060 |
aStream nextPut:#pushNil.
|
|
1061 |
code at:pos3 put:(aStream position)
|
|
1062 |
] ifFalse:[
|
|
1063 |
here := aStream position.
|
|
1064 |
(selector == #ifFalse:) ifTrue:[
|
|
1065 |
code at:pos1 put:here
|
|
1066 |
].
|
|
1067 |
code at:pos2 put:here
|
|
1068 |
]
|
|
1069 |
!
|
|
1070 |
|
104
|
1071 |
codeSendOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
|
0
|
1072 |
"like code on, but assumes that receiver has already been
|
|
1073 |
coded onto stack - needed for cascade"
|
|
1074 |
|
117
|
1075 |
|nargs isBuiltIn code litIndex|
|
0
|
1076 |
|
|
1077 |
argArray isNil ifTrue:[
|
47
|
1078 |
nargs := 0
|
0
|
1079 |
] ifFalse:[
|
47
|
1080 |
nargs := argArray size
|
0
|
1081 |
].
|
|
1082 |
|
|
1083 |
isBuiltIn := false.
|
|
1084 |
|
|
1085 |
(nargs == 0) ifTrue:[
|
47
|
1086 |
isBuiltIn := self class isBuiltInUnarySelector:selector
|
0
|
1087 |
].
|
|
1088 |
(nargs == 1) ifTrue:[
|
47
|
1089 |
isBuiltIn := self class isBuiltIn1ArgSelector:selector
|
0
|
1090 |
].
|
|
1091 |
(nargs == 2) ifTrue:[
|
47
|
1092 |
isBuiltIn := self class isBuiltIn2ArgSelector:selector
|
0
|
1093 |
].
|
|
1094 |
|
|
1095 |
"can we use a send-bytecode ?"
|
|
1096 |
isBuiltIn ifTrue:[
|
48
|
1097 |
receiver isSuper ifFalse:[
|
47
|
1098 |
(nargs > 0) ifTrue:[
|
104
|
1099 |
(argArray at:1) codeOn:aStream inBlock:b for:aCompiler.
|
47
|
1100 |
(nargs > 1) ifTrue:[
|
104
|
1101 |
(argArray at:2) codeOn:aStream inBlock:b for:aCompiler
|
47
|
1102 |
]
|
|
1103 |
].
|
|
1104 |
aStream nextPut:selector.
|
|
1105 |
(self class hasLineNumber:selector) ifTrue:[
|
|
1106 |
aStream nextPut:lineNr.
|
|
1107 |
].
|
|
1108 |
valueNeeded ifFalse:[
|
|
1109 |
aStream nextPut:#drop
|
|
1110 |
].
|
|
1111 |
^ self
|
|
1112 |
]
|
0
|
1113 |
].
|
|
1114 |
|
|
1115 |
argArray notNil ifTrue:[
|
47
|
1116 |
argArray do:[:arg |
|
104
|
1117 |
arg codeOn:aStream inBlock:b for:aCompiler
|
47
|
1118 |
]
|
0
|
1119 |
].
|
|
1120 |
|
48
|
1121 |
receiver isSuper ifTrue:[
|
117
|
1122 |
litIndex := aCompiler addLiteral:selector.
|
|
1123 |
litIndex <= 255 ifTrue:[
|
106
|
1124 |
receiver isHere ifTrue:[
|
|
1125 |
code := #hereSend
|
|
1126 |
] ifFalse:[
|
|
1127 |
code := #superSend.
|
|
1128 |
].
|
117
|
1129 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs; nextPut:nil.
|
49
|
1130 |
] ifFalse:[
|
106
|
1131 |
receiver isHere ifTrue:[
|
|
1132 |
code := #hereSendL
|
|
1133 |
] ifFalse:[
|
|
1134 |
code := #superSendL.
|
|
1135 |
].
|
117
|
1136 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs; nextPut:nil.
|
49
|
1137 |
].
|
47
|
1138 |
valueNeeded ifFalse:[
|
|
1139 |
aStream nextPut:#drop
|
|
1140 |
].
|
|
1141 |
^ self
|
0
|
1142 |
].
|
|
1143 |
(nargs == 0) ifTrue:[
|
47
|
1144 |
(selector == #yourself) ifTrue:[
|
|
1145 |
"yourself is often added to get the receiver -
|
|
1146 |
we get it without the yourself-message"
|
0
|
1147 |
|
47
|
1148 |
valueNeeded ifFalse:[
|
|
1149 |
aStream nextPut:#drop
|
|
1150 |
].
|
|
1151 |
^ self
|
|
1152 |
].
|
49
|
1153 |
].
|
0
|
1154 |
|
117
|
1155 |
litIndex := aCompiler addLiteral:selector.
|
|
1156 |
litIndex <= 255 ifTrue:[
|
106
|
1157 |
(nargs <= 3) ifTrue:[
|
|
1158 |
valueNeeded ifTrue:[
|
|
1159 |
code := #(send0 send1 send2 send3) at:(nargs+1).
|
|
1160 |
] ifFalse:[
|
|
1161 |
code := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3) at:(nargs+1).
|
|
1162 |
].
|
117
|
1163 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex.
|
106
|
1164 |
^ self
|
|
1165 |
].
|
|
1166 |
|
47
|
1167 |
valueNeeded ifTrue:[
|
106
|
1168 |
code := #send
|
47
|
1169 |
] ifFalse:[
|
106
|
1170 |
code := #sendDrop
|
47
|
1171 |
].
|
117
|
1172 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs.
|
47
|
1173 |
^ self
|
0
|
1174 |
].
|
49
|
1175 |
|
0
|
1176 |
valueNeeded ifTrue:[
|
106
|
1177 |
code := #sendL
|
0
|
1178 |
] ifFalse:[
|
106
|
1179 |
code := #sendDropL
|
0
|
1180 |
].
|
117
|
1181 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs
|
0
|
1182 |
!
|
|
1183 |
|
140
|
1184 |
codeTimesRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
|
|
1185 |
"generate code for n timesRepeat:[ ... ]"
|
|
1186 |
|
|
1187 |
|pos pos2 theReceiver|
|
|
1188 |
|
|
1189 |
theReceiver := receiver.
|
|
1190 |
theReceiver codeOn:aStream inBlock:b for:aCompiler.
|
|
1191 |
valueNeeded ifTrue:[aStream nextPut:#dup].
|
96
|
1192 |
|
140
|
1193 |
pos := aStream position.
|
|
1194 |
"/ aStream nextPut:#dup; nextPut:#push0; nextPut:#>; nextPut:lineNr; nextPut:#falseJump.
|
|
1195 |
"/ aStream nextPut:#dup; nextPut:#gt0; nextPut:lineNr; nextPut:#falseJump.
|
|
1196 |
aStream nextPut:#pushgt0; nextPut:lineNr; nextPut:#falseJump.
|
|
1197 |
pos2 := aStream position.
|
|
1198 |
aStream nextPut:0.
|
|
1199 |
|
|
1200 |
(argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
|
|
1201 |
aStream nextPut:#minus1; nextPut:lineNr; nextPut:#jump; nextPut:pos.
|
|
1202 |
|
|
1203 |
(aStream contents) at:pos2 put:(aStream position).
|
|
1204 |
aStream nextPut:#drop.
|
|
1205 |
!
|
|
1206 |
|
|
1207 |
codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
|
|
1208 |
"generate code for [...] whilexxx:[ ... ]"
|
|
1209 |
|
|
1210 |
|pos pos2 theReceiver theArg theByteCode optByteCode|
|
0
|
1211 |
|
140
|
1212 |
(selector == #whileTrue:) ifTrue:[
|
|
1213 |
theByteCode := #falseJump
|
0
|
1214 |
] ifFalse:[
|
140
|
1215 |
theByteCode := #trueJump
|
|
1216 |
].
|
|
1217 |
|
|
1218 |
theReceiver := receiver.
|
|
1219 |
optByteCode := self optimizedConditionFor:theReceiver with:theByteCode.
|
|
1220 |
optByteCode notNil ifTrue:[
|
|
1221 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
|
|
1222 |
theArg := receiver statements expression arg1
|
|
1223 |
].
|
|
1224 |
theReceiver := receiver statements expression receiver.
|
|
1225 |
theByteCode := optByteCode
|
|
1226 |
].
|
|
1227 |
|
|
1228 |
"/ OLD:
|
|
1229 |
"/ valueNeeded ifTrue:[aStream nextPut:#pushNil].
|
|
1230 |
"/
|
|
1231 |
pos := aStream position.
|
|
1232 |
optByteCode notNil ifTrue:[
|
|
1233 |
theReceiver codeOn:aStream inBlock:b for:aCompiler.
|
|
1234 |
theArg notNil ifTrue:[
|
|
1235 |
theArg codeOn:aStream inBlock:b for:aCompiler
|
|
1236 |
]
|
|
1237 |
] ifFalse:[
|
|
1238 |
theReceiver codeInlineOn:aStream inBlock:b for:aCompiler
|
|
1239 |
].
|
|
1240 |
|
|
1241 |
(lineNr between:1 and:255) ifTrue:[
|
|
1242 |
aStream nextPut:#lineno; nextPut:lineNr.
|
0
|
1243 |
].
|
|
1244 |
|
140
|
1245 |
aStream nextPut:theByteCode.
|
|
1246 |
pos2 := aStream position.
|
|
1247 |
aStream nextPut:0.
|
|
1248 |
"/ OLD:
|
|
1249 |
"/ valueNeeded ifTrue:[aStream nextPut:#drop].
|
|
1250 |
"/
|
|
1251 |
"/ OLD:
|
|
1252 |
"/ (argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
|
|
1253 |
"/ NEW:
|
|
1254 |
(argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
|
|
1255 |
aStream nextPut:#jump; nextPut:pos.
|
|
1256 |
(aStream contents) at:pos2 put:(aStream position).
|
|
1257 |
"/ NEW:
|
|
1258 |
valueNeeded ifTrue:[aStream nextPut:#pushNil].
|
|
1259 |
!
|
|
1260 |
|
|
1261 |
optimizedConditionFor:aReceiver with:aByteCode
|
|
1262 |
|rec sel|
|
0
|
1263 |
|
140
|
1264 |
rec := aReceiver.
|
|
1265 |
(rec isBlock) ifTrue:[
|
|
1266 |
rec statements nextStatement isNil ifTrue:[
|
|
1267 |
rec := rec statements expression
|
|
1268 |
]
|
|
1269 |
].
|
|
1270 |
(rec isUnaryMessage) ifTrue:[
|
|
1271 |
sel := rec selector.
|
|
1272 |
(sel == #isNil) ifTrue:[
|
|
1273 |
"/
|
|
1274 |
"/ isNil trueJmp -> nilJump
|
|
1275 |
"/ isNil falseJmp -> notNilJump
|
|
1276 |
"/
|
|
1277 |
(aByteCode == #trueJump) ifTrue:[^ #nilJump].
|
|
1278 |
(aByteCode == #falseJump) ifTrue:[^ #notNilJump]
|
|
1279 |
].
|
|
1280 |
(sel == #notNil) ifTrue:[
|
|
1281 |
"/
|
|
1282 |
"/ notNil trueJmp -> notNilJump
|
|
1283 |
"/ notNil falseJmp -> nilJump
|
|
1284 |
"/
|
|
1285 |
(aByteCode == #trueJump) ifTrue:[^ #notNilJump].
|
|
1286 |
(aByteCode == #falseJump) ifTrue:[^ #nilJump]
|
|
1287 |
].
|
|
1288 |
(sel == #not) ifTrue:[
|
|
1289 |
"/
|
|
1290 |
"/ not trueJmp -> falseJump
|
|
1291 |
"/ not falseJmp -> trueJump
|
|
1292 |
"/
|
|
1293 |
(aByteCode == #trueJump) ifTrue:[^ #falseJump].
|
|
1294 |
(aByteCode == #falseJump) ifTrue:[^ #trueJump]
|
|
1295 |
].
|
|
1296 |
^ nil
|
0
|
1297 |
].
|
140
|
1298 |
(rec isBinaryMessage) ifTrue:[
|
|
1299 |
sel := rec selector.
|
|
1300 |
rec arg1 isConstant ifTrue:[
|
|
1301 |
(rec arg1 value == 0) ifTrue:[
|
|
1302 |
"/
|
|
1303 |
"/ ==0 trueJmp -> zeroJump
|
|
1304 |
"/ ==0 falseJmp -> notZeroJump
|
|
1305 |
"/
|
|
1306 |
(sel == #==) ifTrue:[
|
|
1307 |
(aByteCode == #trueJump) ifTrue:[^ #zeroJump].
|
|
1308 |
(aByteCode == #falseJump) ifTrue:[^ #notZeroJump]
|
|
1309 |
].
|
|
1310 |
"/
|
|
1311 |
"/ ~~0 trueJmp -> notZeroJump
|
|
1312 |
"/ ~~0 falseJmp -> zeroJump
|
|
1313 |
"/
|
|
1314 |
(sel == #~~) ifTrue:[
|
|
1315 |
(aByteCode == #falseJump) ifTrue:[^ #zeroJump].
|
|
1316 |
(aByteCode == #trueJump) ifTrue:[^ #notZeroJump]
|
|
1317 |
].
|
|
1318 |
^ nil
|
|
1319 |
]
|
|
1320 |
].
|
|
1321 |
(sel == #==) ifTrue:[
|
|
1322 |
"/
|
|
1323 |
"/ == trueJmp -> eqJump
|
|
1324 |
"/ == falseJmp -> notEqJump
|
|
1325 |
"/
|
|
1326 |
(aByteCode == #trueJump) ifTrue:[^ #eqJump].
|
|
1327 |
(aByteCode == #falseJump) ifTrue:[^ #notEqJump]
|
|
1328 |
].
|
|
1329 |
(sel == #~~) ifTrue:[
|
|
1330 |
"/
|
|
1331 |
"/ ~~ trueJmp -> notEqJump
|
|
1332 |
"/ ~~ falseJmp -> eqJump
|
|
1333 |
"/
|
|
1334 |
(aByteCode == #falseJump) ifTrue:[^ #eqJump].
|
|
1335 |
(aByteCode == #trueJump) ifTrue:[^ #notEqJump]
|
|
1336 |
]
|
|
1337 |
].
|
|
1338 |
^ nil
|
|
1339 |
! !
|
|
1340 |
|
|
1341 |
!MessageNode methodsFor:'evaluating'!
|
|
1342 |
|
|
1343 |
evaluate
|
|
1344 |
|r nargs argValueArray class|
|
|
1345 |
|
|
1346 |
receiver isSuper ifTrue:[
|
|
1347 |
r := receiver value.
|
|
1348 |
receiver isHere ifTrue:[
|
|
1349 |
class := receiver definingClass.
|
|
1350 |
] ifFalse:[
|
|
1351 |
class := receiver definingClass superclass.
|
|
1352 |
].
|
|
1353 |
argArray notNil ifTrue:[
|
|
1354 |
argValueArray := argArray collect:[:arg | arg evaluate].
|
|
1355 |
] ifFalse:[
|
|
1356 |
argValueArray := #()
|
|
1357 |
].
|
|
1358 |
^ r perform:selector inClass:class withArguments:argValueArray
|
|
1359 |
].
|
|
1360 |
|
|
1361 |
|
|
1362 |
argArray isNil ifTrue:[
|
|
1363 |
^ (receiver evaluate) perform:selector
|
|
1364 |
].
|
|
1365 |
nargs := argArray size.
|
0
|
1366 |
(nargs == 1) ifTrue:[
|
140
|
1367 |
^ (receiver evaluate) perform:selector with:(argArray at:1) evaluate
|
0
|
1368 |
].
|
|
1369 |
(nargs == 2) ifTrue:[
|
140
|
1370 |
^ (receiver evaluate) perform:selector
|
|
1371 |
with:(argArray at:1) evaluate
|
|
1372 |
with:(argArray at:2) evaluate
|
|
1373 |
].
|
|
1374 |
(nargs == 3) ifTrue:[
|
|
1375 |
^ (receiver evaluate) perform:selector
|
|
1376 |
with:(argArray at:1) evaluate
|
|
1377 |
with:(argArray at:2) evaluate
|
|
1378 |
with:(argArray at:3) evaluate
|
|
1379 |
].
|
|
1380 |
r := receiver evaluate.
|
|
1381 |
argValueArray := argArray collect:[:arg | arg evaluate].
|
|
1382 |
^ r perform:selector withArguments:argValueArray
|
|
1383 |
!
|
|
1384 |
|
|
1385 |
evaluateForCascade
|
|
1386 |
|r nargs argValueArray class|
|
|
1387 |
|
|
1388 |
receiver isSuper ifTrue:[
|
|
1389 |
r := receiver value.
|
|
1390 |
class := receiver definingClass.
|
|
1391 |
receiver isHere ifFalse:[
|
|
1392 |
class := class superclass.
|
|
1393 |
].
|
|
1394 |
argArray notNil ifTrue:[
|
|
1395 |
argValueArray := argArray collect:[:arg | arg evaluate].
|
|
1396 |
] ifFalse:[
|
|
1397 |
argValueArray := #()
|
|
1398 |
].
|
|
1399 |
r perform:selector inClass:class withArguments:argValueArray.
|
|
1400 |
^ r
|
0
|
1401 |
].
|
|
1402 |
|
140
|
1403 |
r := receiver evaluate.
|
|
1404 |
argArray isNil ifTrue:[
|
|
1405 |
r perform:selector.
|
|
1406 |
^ r
|
|
1407 |
].
|
|
1408 |
nargs := argArray size.
|
|
1409 |
(nargs == 1) ifTrue:[
|
|
1410 |
r perform:selector with:(argArray at:1) evaluate.
|
|
1411 |
^ r
|
|
1412 |
].
|
|
1413 |
(nargs == 2) ifTrue:[
|
|
1414 |
r perform:selector with:(argArray at:1) evaluate
|
|
1415 |
with:(argArray at:2) evaluate.
|
|
1416 |
^ r
|
|
1417 |
].
|
|
1418 |
(nargs == 3) ifTrue:[
|
|
1419 |
r perform:selector with:(argArray at:1) evaluate
|
|
1420 |
with:(argArray at:2) evaluate
|
|
1421 |
with:(argArray at:3) evaluate.
|
|
1422 |
^ r
|
|
1423 |
].
|
|
1424 |
argValueArray := argArray collect:[:arg | arg evaluate].
|
|
1425 |
r perform:selector withArguments:argValueArray.
|
|
1426 |
^ r
|
|
1427 |
! !
|
|
1428 |
|
|
1429 |
!MessageNode methodsFor:'printing'!
|
|
1430 |
|
|
1431 |
printOn:aStream indent:i
|
|
1432 |
|needParen selectorParts index index2 arg|
|
|
1433 |
|
|
1434 |
(#(whileTrue: whileFalse:) includes:selector) ifTrue:[
|
|
1435 |
receiver isBlock ifTrue:[
|
|
1436 |
^ self printWhileOn:aStream indent:i
|
|
1437 |
].
|
|
1438 |
].
|
0
|
1439 |
|
140
|
1440 |
index := 1.
|
|
1441 |
selectorParts := OrderedCollection new.
|
|
1442 |
[index == 0] whileFalse:[
|
|
1443 |
index2 := selector indexOf:$: startingAt:index.
|
|
1444 |
index2 ~~ 0 ifTrue:[
|
|
1445 |
selectorParts add:(selector copyFrom:index to:index2).
|
|
1446 |
index2 := index2 + 1
|
|
1447 |
].
|
|
1448 |
index := index2
|
|
1449 |
].
|
|
1450 |
|
|
1451 |
needParen := false.
|
|
1452 |
receiver isMessage ifTrue:[
|
|
1453 |
receiver isUnaryMessage ifFalse:[
|
|
1454 |
receiver isBinaryMessage ifFalse:[
|
|
1455 |
needParen := true
|
|
1456 |
].
|
|
1457 |
].
|
|
1458 |
].
|
|
1459 |
needParen ifTrue:[
|
|
1460 |
aStream nextPutAll:'('
|
|
1461 |
].
|
|
1462 |
receiver printOn:aStream indent:i.
|
|
1463 |
needParen ifTrue:[
|
|
1464 |
aStream nextPutAll:')'
|
|
1465 |
].
|
|
1466 |
|
|
1467 |
1 to:(argArray size) do:[:argIndex |
|
|
1468 |
aStream space.
|
|
1469 |
(selectorParts at:argIndex) printOn:aStream.
|
|
1470 |
aStream space.
|
|
1471 |
arg := argArray at:argIndex.
|
|
1472 |
needParen := false.
|
|
1473 |
arg isMessage ifTrue:[
|
|
1474 |
arg isBinaryMessage ifFalse:[
|
|
1475 |
arg isUnaryMessage ifFalse:[
|
|
1476 |
needParen := true
|
47
|
1477 |
]
|
|
1478 |
].
|
140
|
1479 |
].
|
|
1480 |
needParen ifTrue:[
|
|
1481 |
aStream nextPutAll:'('
|
|
1482 |
].
|
|
1483 |
arg printOn:aStream indent:i.
|
|
1484 |
needParen ifTrue:[
|
|
1485 |
aStream nextPutAll:') '
|
|
1486 |
].
|
|
1487 |
]
|
|
1488 |
!
|
|
1489 |
|
|
1490 |
printWhileOn:aStream indent:i
|
|
1491 |
|needParen arg|
|
0
|
1492 |
|
140
|
1493 |
"special handling of whileTrue/whileFalse"
|
|
1494 |
|
|
1495 |
aStream nextPutAll:'['.
|
|
1496 |
receiver statements printOn:aStream indent:i.
|
|
1497 |
aStream nextPutAll:'] whileTrue: '.
|
|
1498 |
|
|
1499 |
arg := argArray at:1.
|
|
1500 |
needParen := false.
|
|
1501 |
arg isMessage ifTrue:[
|
|
1502 |
arg isBinaryMessage ifFalse:[
|
|
1503 |
arg isUnaryMessage ifFalse:[
|
|
1504 |
needParen := true
|
|
1505 |
]
|
|
1506 |
].
|
0
|
1507 |
].
|
140
|
1508 |
needParen ifTrue:[
|
|
1509 |
aStream nextPutAll:'('
|
|
1510 |
].
|
|
1511 |
arg printOn:aStream indent:i.
|
|
1512 |
needParen ifTrue:[
|
|
1513 |
aStream nextPutAll:') '
|
|
1514 |
].
|
|
1515 |
! !
|
106
|
1516 |
|
140
|
1517 |
!MessageNode methodsFor:'queries'!
|
|
1518 |
|
|
1519 |
isMessage
|
|
1520 |
^ true
|
0
|
1521 |
! !
|
140
|
1522 |
|
148
|
1523 |
!MessageNode class methodsFor:'documentation'!
|
|
1524 |
|
|
1525 |
version
|
|
1526 |
^ '$Header: /cvs/stx/stx/libcomp/Attic/MessageNd.st,v 1.33 1995-12-03 12:16:52 cg Exp $'
|
|
1527 |
! !
|