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