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