author | Claus Gittinger <cg@exept.de> |
Fri, 06 Nov 2009 20:29:24 +0100 | |
changeset 2270 | 3fbda756040e |
parent 2268 | adf79f6f4e06 |
child 2273 | d952d08cf43c |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
1727 | 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 |
" |
|
1045 | 12 |
"{ Package: 'stx:libcomp' }" |
13 |
||
0 | 14 |
ParseNode subclass:#MessageNode |
1791 | 15 |
instanceVariableNames:'receiver selector argArray lineNr selectorPosition' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'System-Compiler-Support' |
|
0 | 19 |
! |
20 |
||
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
21 |
!MessageNode class methodsFor:'documentation'! |
20 | 22 |
|
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
1727 | 26 |
All Rights Reserved |
20 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
node for parse-trees, representing message sends |
|
261 | 40 |
This is a helper class for the compiler. |
263 | 41 |
|
42 |
[author:] |
|
1727 | 43 |
Claus Gittinger |
20 | 44 |
" |
45 |
! ! |
|
0 | 46 |
|
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
47 |
!MessageNode class methodsFor:'instance creation'! |
0 | 48 |
|
49 |
receiver:recNode selector:selectorString |
|
50 |
^ (self basicNew) receiver:recNode selector:selectorString args:nil lineno:0 |
|
51 |
! |
|
52 |
||
1266 | 53 |
receiver:recNode selector:selectorString arg1:arg1Node arg2:arg2Node |
54 |
^ self receiver:recNode selector:selectorString arg1:arg1Node arg2:arg2Node fold:nil |
|
55 |
! |
|
56 |
||
140 | 57 |
receiver:recNode selector:selectorString arg1:argNode1 arg2:argNode2 fold:folding |
58 |
|result recVal argVal selector| |
|
59 |
||
60 |
" |
|
61 |
This is just a demonstration - of how complex constants can be folded. |
|
62 |
This was inspired by some discussion in c.l.s about enhancing the language - I prefer |
|
63 |
enhancing the compiler .... |
|
64 |
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
|
65 |
allowing constant arrays of complex objects. |
140 | 66 |
|
67 |
Notice: this method is normally disabled - its just a demo after all. |
|
68 |
" |
|
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
69 |
folding notNil ifTrue:[ |
1397 | 70 |
"/ |
71 |
"/ do constant folding ... |
|
72 |
"/ |
|
73 |
(recNode isConstant and:[argNode1 isConstant]) ifTrue:[ |
|
74 |
"check if we can do it ..." |
|
75 |
selector := selectorString asSymbolIfInterned. |
|
76 |
selector notNil ifTrue:[ |
|
77 |
recVal := recNode evaluate. |
|
78 |
(recVal respondsTo:selector) ifTrue:[ |
|
79 |
" |
|
80 |
we could do much more here - but then, we need a dependency from |
|
81 |
the folded selectors method to the method we generate code for ... |
|
82 |
limit optimizations to those that will never change |
|
83 |
(or - if you change them - you will crash so bad ...) |
|
84 |
" |
|
85 |
argVal := argNode1 evaluate. |
|
86 |
((recVal isMemberOf:Array) and:[argVal isMemberOf:Array]) ifTrue:[ |
|
87 |
folding == #full ifTrue:[ |
|
88 |
(selector == #with:collect:) ifTrue:[ |
|
89 |
(argNode2 isBlock) ifTrue:[ |
|
90 |
SignalSet anySignal handle:[:ex | |
|
1533 | 91 |
^ ParseErrorNode errorString:'error in constant expression (' , ex description , ')' |
1397 | 92 |
] do:[ |
93 |
result := recVal perform:selector with:argVal with:(argNode2 evaluate). |
|
94 |
]. |
|
95 |
^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result |
|
96 |
] |
|
97 |
] |
|
98 |
] |
|
99 |
] |
|
100 |
] |
|
101 |
] |
|
102 |
] |
|
140 | 103 |
]. |
104 |
^ (self basicNew) receiver:recNode selector:selectorString args:(Array with:argNode1 with:argNode2) lineno:0 |
|
570 | 105 |
|
106 |
"Modified: 28.6.1997 / 15:16:01 / cg" |
|
140 | 107 |
! |
108 |
||
0 | 109 |
receiver:recNode selector:selectorString arg:argNode |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
110 |
^ self receiver:recNode selector:selectorString arg:argNode fold:nil |
0 | 111 |
! |
112 |
||
113 |
receiver:recNode selector:selectorString arg:argNode fold:folding |
|
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
114 |
|result recVal argVal selector globalName canFold| |
0 | 115 |
|
20 | 116 |
" |
117 |
The constant folding code can usually not optimize much |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
118 |
- this may change when some kind of constant/macro declaration is added to smalltalk, |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
119 |
so that constant classVars can be inlined. |
20 | 120 |
" |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
121 |
folding notNil ifTrue:[ |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
122 |
selector := selectorString asSymbolIfInterned. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
123 |
selector notNil ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
124 |
|
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
125 |
"/ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
126 |
"/ do constant folding ... |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
127 |
"/ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
128 |
canFold := false. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
129 |
|
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
130 |
(recNode isGlobal and:[argNode isConstant]) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
131 |
globalName := recNode name. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
132 |
recVal := recNode evaluate. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
133 |
|
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
134 |
(globalName = 'SmallInteger') ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
135 |
( #( bitMaskFor: ) includes:selector) |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
136 |
ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
137 |
canFold := true |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
138 |
] |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
139 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
140 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
141 |
|
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
142 |
(recNode isConstant and:[argNode isConstant]) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
143 |
"check if we can do it ..." |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
144 |
recVal := recNode evaluate. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
145 |
" |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
146 |
we could do much more here - but then, we need a dependency from |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
147 |
the folded selectors method to the method we generate code for ... |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
148 |
limit optimizations to those that will never change |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
149 |
(or - if you change them - you will crash so bad ...) |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
150 |
" |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
151 |
argVal := argNode evaluate. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
152 |
(recVal respondsToArithmetic and:[argVal respondsToArithmetic]) ifTrue:[ |
2197 | 153 |
( #( + - * / // \\ min: max: quo: raisedTo:) includes:selector) ifTrue:[ |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
154 |
(#( / // \\ ) includes:selector) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
155 |
argVal = 0 ifTrue:[ |
1533 | 156 |
^ ParseErrorNode errorString:'division by zero in constant expression' |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
157 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
158 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
159 |
canFold := true |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
160 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
161 |
( #( @ ) includes:selector) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
162 |
canFold := (folding == #full) |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
163 |
] |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
164 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
165 |
(recVal isInteger and:[argVal isInteger]) ifTrue:[ |
1017 | 166 |
( #( bitShift: bitOr: bitAnd: ) includes:selector) ifTrue:[ |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
167 |
canFold := true |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
168 |
] |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
169 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
170 |
(recVal isMemberOf:String) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
171 |
(argVal isInteger and:[selector == #at:]) ifTrue:[ |
993
902eec8d132b
oops - folding argument is not always a symbol.
Claus Gittinger <cg@exept.de>
parents:
992
diff
changeset
|
172 |
canFold := folding isSymbol |
902eec8d132b
oops - folding argument is not always a symbol.
Claus Gittinger <cg@exept.de>
parents:
992
diff
changeset
|
173 |
and:[(folding >= #level2) or:[folding == #full]]. |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
174 |
]. |
1093 | 175 |
selector == #',' ifTrue:[ |
176 |
(argVal isMemberOf:String) ifTrue:[ |
|
177 |
canFold := folding isSymbol |
|
178 |
and:[(folding >= #level2) or:[folding == #full]]. |
|
179 |
]. |
|
180 |
(argVal isMemberOf:Character) ifTrue:[ |
|
181 |
canFold := folding isSymbol |
|
182 |
and:[(folding >= #level2) or:[folding == #full]]. |
|
183 |
]. |
|
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
184 |
] |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
185 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
186 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
187 |
|
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
188 |
canFold ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
189 |
(recVal respondsTo:selector) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
190 |
SignalSet anySignal handle:[:ex | |
1533 | 191 |
^ ParseErrorNode errorString:'error in constant expression (' , ex description , ')' |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
192 |
] do:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
193 |
result := recVal perform:selector with:argVal. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
194 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
195 |
^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
196 |
] |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
197 |
] |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
198 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
199 |
|
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
200 |
"/ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
201 |
"/ #perform with a constant selector |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
202 |
"/ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
203 |
(selector == #perform: |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
204 |
and:[argNode isConstant]) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
205 |
argVal := argNode evaluate. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
206 |
argVal isSymbol ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
207 |
^ UnaryNode receiver:recNode selector:argVal fold:folding |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
208 |
] |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
209 |
]. |
0 | 210 |
]. |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
211 |
|
0 | 212 |
^ (self basicNew) receiver:recNode selector:selectorString args:(Array with:argNode) lineno:0 |
576 | 213 |
|
993
902eec8d132b
oops - folding argument is not always a symbol.
Claus Gittinger <cg@exept.de>
parents:
992
diff
changeset
|
214 |
"Modified: / 16.11.1999 / 21:50:33 / cg" |
0 | 215 |
! |
216 |
||
217 |
receiver:recNode selector:selectorString args:anArray |
|
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
218 |
^ self receiver:recNode selector:selectorString args:anArray fold:nil |
0 | 219 |
! |
220 |
||
221 |
receiver:recNode selector:selectorString args:argArray fold:folding |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
222 |
|numArgs arg1 arg1Val| |
117 | 223 |
|
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
224 |
folding notNil ifTrue:[ |
715
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
225 |
numArgs := argArray size. |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
226 |
numArgs > 0 ifTrue:[ |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
227 |
arg1 := (argArray at:1). |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
228 |
(numArgs == 1) ifTrue:[ |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
229 |
^ self receiver:recNode selector:selectorString arg:arg1 fold:folding |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
230 |
]. |
20 | 231 |
|
715
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
232 |
"/ |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
233 |
"/ #perform:... with a constant selector |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
234 |
"/ |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
235 |
numArgs <= 6 ifTrue:[ |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
236 |
(#(nil |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
237 |
#'perform:with:' |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
238 |
#'perform:with:with:' |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
239 |
#'perform:with:with:with:' |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
240 |
#'perform:with:with:with:with:' |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
241 |
#'perform:with:with:with:with:with:' |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
242 |
#'perform:with:with:with:with:with:with:' |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
243 |
) at:numArgs) = selectorString |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
244 |
ifTrue:[ |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
245 |
arg1 isConstant ifTrue:[ |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
246 |
arg1Val := arg1 evaluate. |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
247 |
arg1Val isSymbol ifTrue:[ |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
248 |
^ MessageNode |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
249 |
receiver:recNode |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
250 |
selector:arg1Val |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
251 |
args:(argArray copyFrom:2) |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
252 |
fold:folding |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
253 |
] |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
254 |
] |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
255 |
] |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
256 |
]. |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
257 |
]. |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
258 |
|
715
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
259 |
(numArgs == 2) ifTrue:[ |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
260 |
^ self receiver:recNode selector:selectorString arg1:arg1 arg2:(argArray at:2) fold:folding |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
261 |
]. |
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
262 |
numArgs > Method maxNumberOfArguments ifTrue:[ |
1533 | 263 |
^ ParseErrorNode errorString:'too many arguments for current VM implementation'. |
715
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
264 |
]. |
0 | 265 |
]. |
117 | 266 |
|
0 | 267 |
^ (self basicNew) receiver:recNode selector:selectorString args:argArray lineno:0 |
117 | 268 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
269 |
"Modified: / 3.9.1995 / 16:41:39 / claus" |
715
408ac886ffc1
allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents:
676
diff
changeset
|
270 |
"Modified: / 15.5.1998 / 15:32:05 / cg" |
0 | 271 |
! ! |
272 |
||
140 | 273 |
!MessageNode methodsFor:'accessing'! |
0 | 274 |
|
140 | 275 |
arg1 |
276 |
^ argArray at:1 |
|
277 |
! |
|
0 | 278 |
|
1639 | 279 |
arg2 |
280 |
^ argArray at:2 |
|
281 |
! |
|
282 |
||
140 | 283 |
args |
284 |
^ argArray |
|
285 |
! |
|
0 | 286 |
|
543
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
287 |
arguments |
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
288 |
^ argArray ? #() |
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
289 |
|
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
290 |
"Created: 19.6.1997 / 17:31:14 / cg" |
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
291 |
"Modified: 19.6.1997 / 17:32:25 / cg" |
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
292 |
! |
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
293 |
|
140 | 294 |
lineNumber |
295 |
^ lineNr |
|
0 | 296 |
! |
297 |
||
140 | 298 |
lineNumber:num |
299 |
lineNr := num |
|
300 |
! |
|
0 | 301 |
|
140 | 302 |
receiver |
303 |
^ receiver |
|
304 |
! |
|
0 | 305 |
|
140 | 306 |
receiver:r selector:s args:a lineno:l |
307 |
receiver := r. |
|
1500
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
308 |
|
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
309 |
"/ create the symbol only, if the symbol is already known in the system. |
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
310 |
"/ otherwise a lot of partial symbols will be created by the SyntaxHighlighter |
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
311 |
"/ during typing |
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
312 |
"/ selector := s asSymbol. |
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
313 |
|
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
314 |
selector := s asSymbolIfInterned ? s. |
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
315 |
|
140 | 316 |
argArray := a. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
317 |
lineNr := l. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
318 |
self checkInlinability. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
319 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
320 |
"Modified: 2.7.1997 / 17:01:24 / cg" |
140 | 321 |
! |
322 |
||
323 |
selector |
|
324 |
^ selector |
|
595
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
325 |
! |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
326 |
|
1384 | 327 |
selector:s |
1500
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
328 |
"/ create the symbol only, if the symbol is already known in the system. |
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
329 |
"/ otherwise a lot of partial symbols will be created by the SyntaxHighlighter |
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
330 |
"/ during typing |
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
331 |
"/ selector := s asSymbol. |
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
332 |
|
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
333 |
selector := s asSymbolIfInterned ? s. |
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
334 |
"/ selector := s asSymbol. |
1384 | 335 |
! |
336 |
||
595
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
337 |
selectorPosition |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
338 |
"return the value of the instance variable 'selectorPosition' (automatically generated)" |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
339 |
|
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
340 |
^ selectorPosition |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
341 |
|
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
342 |
"Created: 5.8.1997 / 02:49:27 / cg" |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
343 |
! |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
344 |
|
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
345 |
selectorPosition:something |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
346 |
"set the value of the instance variable 'selectorPosition' (automatically generated)" |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
347 |
|
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
348 |
selectorPosition := something. |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
349 |
|
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
350 |
"Created: 5.8.1997 / 02:49:27 / cg" |
0 | 351 |
! ! |
352 |
||
353 |
!MessageNode methodsFor:'checks'! |
|
354 |
||
1626
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
355 |
checkCondition |
2102 | 356 |
|args lastArg receiverSelector or1 or2| |
1626
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
357 |
|
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
358 |
receiver isBlock ifTrue:[ |
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
359 |
(Block canUnderstand:selector) ifFalse:[ |
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
360 |
^ 'blocks usually do not respond to ' , selector , ' messages' |
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
361 |
]. |
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
362 |
]. |
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
363 |
|
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
364 |
"/ (rr keyw:ra = a) ifTrue:[ ...] |
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
365 |
|
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
366 |
receiver isMessage ifTrue:[ |
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
367 |
(receiver numArgs > 0) ifTrue:[ |
2102 | 368 |
receiverSelector := receiver selector asSymbol. |
369 |
(receiverSelector isKeyword) ifTrue:[ |
|
1626
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
370 |
(args := receiver arguments) notEmptyOrNil ifTrue:[ |
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
371 |
(lastArg := args last) isMessage ifTrue:[ |
1989
e6a763ac2587
oops - parenthesized was written with typo
Claus Gittinger <cg@exept.de>
parents:
1809
diff
changeset
|
372 |
lastArg parenthesized ifFalse:[ |
1626
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
373 |
(#( #'=' #'~=' #'==' #'~~' '>' '<' '>=' '<=') |
1629 | 374 |
includes:(lastArg selector asSymbol)) ifTrue:[ |
1628
9641d61e717f
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1627
diff
changeset
|
375 |
^ 'possible precedence error in condition (missing parenthesis ?)' |
1626
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
376 |
] |
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
377 |
] |
2102 | 378 |
]. |
379 |
]. |
|
380 |
||
381 |
(selector == #ifFalse: or:[ selector == #ifFalse:ifTrue: ]) ifTrue:[ |
|
382 |
receiverSelector == #or: ifTrue:[ |
|
383 |
or1 := receiver receiver. |
|
384 |
or2 := receiver arg1. |
|
385 |
(or1 isMessage and:[or1 selector = '~~']) ifTrue:[ |
|
386 |
(or2 isBlock |
|
387 |
and:[ or2 isSingleExpressionBlock |
|
388 |
and:[ or2 statements expression isMessage |
|
389 |
and:[ or2 statements expression selector = '~~']]]) ifTrue:[ |
|
390 |
^ 'please use "((...==...) and:[...==...]) ifTrue:" here\\(are you obfuscating by purpose ?)' |
|
391 |
]. |
|
392 |
]. |
|
393 |
]. |
|
394 |
]. |
|
1626
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
395 |
] |
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
396 |
]. |
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
397 |
]. |
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
398 |
|
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
399 |
^ nil |
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
400 |
! |
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
401 |
|
2208
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
402 |
checkGlobalFromNameSpaceConflictFor:aNode |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
403 |
"check if aNode is a local-nameSpace's variable, |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
404 |
which hides a global from Smalltalk with the same name. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
405 |
This is especially bad for Error handle: do:... " |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
406 |
|
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
407 |
|fullName shortName| |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
408 |
|
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
409 |
aNode isGlobalVariable ifTrue:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
410 |
fullName := aNode name. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
411 |
shortName := Class nameWithoutPrefix:fullName. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
412 |
shortName ~= fullName ifTrue:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
413 |
(Smalltalk includesKey:shortName) ifTrue:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
414 |
^ 'Possible name conflict (local ',shortName,' vs. Smalltalk::',shortName,')' |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
415 |
]. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
416 |
]. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
417 |
]. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
418 |
|
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
419 |
^ nil. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
420 |
! |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
421 |
|
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
422 |
checkIdentityCompare |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
423 |
|rec arg1 arg1Value operand| |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
424 |
|
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
425 |
" |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
426 |
check #== applied to Floats, Strings or Fractions |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
427 |
" |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
428 |
((selector == #==) or:[selector == #~~]) ifTrue:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
429 |
(argArray size > 0) ifTrue:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
430 |
arg1 := argArray at:1 |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
431 |
]. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
432 |
|
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
433 |
" |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
434 |
it once took me almost an hour, to find a '==' which |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
435 |
should have been an '=' (you cannot compare floats with ==) |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
436 |
(well, I looked at the '==' at least 50 times - |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
437 |
- but didn't think about it ...). |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
438 |
that's reason enough to add this check here. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
439 |
I will add more as heuristic knowledge increases ... |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
440 |
(send me comments on common programming errors...) |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
441 |
" |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
442 |
|
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
443 |
receiver isConstant ifTrue:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
444 |
rec := receiver evaluate. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
445 |
((rec isMemberOf:String) or:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
446 |
(rec isMemberOf:Float) or:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
447 |
(rec isMemberOf:Fraction)]]) ifTrue:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
448 |
operand := rec |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
449 |
]. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
450 |
]. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
451 |
arg1 isConstant ifTrue:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
452 |
arg1Value := arg1 evaluate. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
453 |
((arg1Value isMemberOf:String) or:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
454 |
(arg1Value isMemberOf:Float) or:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
455 |
(arg1Value isMemberOf:Fraction)]]) ifTrue:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
456 |
operand := arg1Value |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
457 |
]. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
458 |
]. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
459 |
operand notNil ifTrue:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
460 |
(selector == #==) ifTrue:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
461 |
^ 'identity compare is unsafe here' |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
462 |
]. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
463 |
^ 'identity compare will usually return true here' |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
464 |
] |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
465 |
]. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
466 |
|
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
467 |
^ nil |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
468 |
! |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
469 |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
470 |
checkInlinability |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
471 |
"early check for possible inlinability" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
472 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
473 |
|numArgs arg1 arg2 arg3| |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
474 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
475 |
(numArgs := argArray size) >= 1 ifTrue:[ |
676 | 476 |
arg1 := argArray at:1. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
477 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
478 |
numArgs == 0 ifTrue:[ |
676 | 479 |
(selector == #whileTrue |
480 |
or:[selector == #whileFalse]) ifTrue:[ |
|
481 |
receiver isBlock ifTrue:[ |
|
482 |
receiver possiblyInlined:true |
|
483 |
]. |
|
484 |
]. |
|
485 |
(selector == #value) ifTrue:[ |
|
486 |
receiver isBlock ifTrue:[ |
|
487 |
receiver possiblyInlined:true |
|
488 |
]. |
|
489 |
]. |
|
1425 | 490 |
((selector == #repeat) or:[selector == #loop]) ifTrue:[ |
676 | 491 |
receiver isBlock ifTrue:[ |
492 |
receiver possiblyInlined:true |
|
493 |
]. |
|
494 |
]. |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
495 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
496 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
497 |
numArgs == 1 ifTrue:[ |
676 | 498 |
(selector == #or: |
499 |
or:[selector == #and:]) ifTrue:[ |
|
500 |
arg1 isBlock ifTrue:[ |
|
501 |
arg1 possiblyInlined:true |
|
502 |
]. |
|
503 |
]. |
|
576 | 504 |
|
676 | 505 |
(selector == #ifTrue: |
898 | 506 |
or:[selector == #ifFalse: |
507 |
or:[selector == #ifNil: |
|
508 |
or:[selector == #ifNotNil:]]]) ifTrue:[ |
|
676 | 509 |
arg1 isBlock ifTrue:[ |
510 |
arg1 possiblyInlined:true |
|
511 |
]. |
|
512 |
]. |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
513 |
|
676 | 514 |
(selector == #whileTrue: |
515 |
or:[selector == #whileFalse:]) ifTrue:[ |
|
516 |
arg1 isBlock ifTrue:[ |
|
517 |
arg1 possiblyInlined:true |
|
518 |
]. |
|
519 |
receiver isBlock ifTrue:[ |
|
520 |
receiver possiblyInlined:true |
|
521 |
]. |
|
522 |
]. |
|
523 |
selector == #timesRepeat: ifTrue:[ |
|
524 |
arg1 isBlock ifTrue:[ |
|
525 |
arg1 possiblyInlined:true withSelector:selector. |
|
526 |
] |
|
527 |
]. |
|
528 |
^ self |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
529 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
530 |
numArgs >= 2 ifTrue:[ |
676 | 531 |
arg2 := argArray at:2. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
532 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
533 |
numArgs == 2 ifTrue:[ |
676 | 534 |
(selector == #ifTrue:ifFalse: |
898 | 535 |
or:[selector == #ifFalse:ifTrue: |
536 |
or:[selector == #ifNil:ifNotNil: |
|
537 |
or:[selector == #ifNotNil:ifNil:]]]) ifTrue:[ |
|
676 | 538 |
(arg1 isBlock |
539 |
and:[arg2 isBlock]) ifTrue:[ |
|
540 |
arg1 possiblyInlined:true. |
|
541 |
arg2 possiblyInlined:true. |
|
542 |
]. |
|
543 |
]. |
|
544 |
selector == #to:do: ifTrue:[ |
|
545 |
arg2 isBlock ifTrue:[ |
|
546 |
arg2 possiblyInlined:true withSelector:selector. |
|
547 |
]. |
|
548 |
]. |
|
549 |
^ self |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
550 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
551 |
numArgs >= 3 ifTrue:[ |
676 | 552 |
arg3 := argArray at:3. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
553 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
554 |
numArgs == 3 ifTrue:[ |
676 | 555 |
selector == #to:by:do: ifTrue:[ |
556 |
arg3 isBlock ifTrue:[ |
|
557 |
arg3 possiblyInlined:true withSelector:selector. |
|
558 |
]. |
|
559 |
]. |
|
560 |
^ self |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
561 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
562 |
^ self |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
563 |
|
676 | 564 |
"Created: / 2.7.1997 / 17:01:10 / cg" |
565 |
"Modified: / 2.4.1998 / 19:08:54 / cg" |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
566 |
! |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
567 |
|
2096 | 568 |
plausibilityCheckIn:aParser |
2208
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
569 |
|arg1 msg| |
902 | 570 |
|
571 |
(argArray size > 0) ifTrue:[ |
|
572 |
arg1 := argArray at:1 |
|
573 |
]. |
|
0 | 574 |
|
3 | 575 |
" |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
576 |
check #== applied to Floats, Strings or Fractions |
0 | 577 |
" |
578 |
((selector == #==) or:[selector == #~~]) ifTrue:[ |
|
2208
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
579 |
(msg := self checkIdentityCompare) notNil ifTrue:[^ msg]. |
0 | 580 |
]. |
3 | 581 |
|
582 |
" |
|
19 | 583 |
[...] ifTrue:... |
3 | 584 |
an error often occuring when you are a beginner ... |
585 |
" |
|
586 |
((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[ |
|
1626
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
587 |
(msg := self checkCondition) notNil ifTrue:[^ msg]. |
3 | 588 |
]. |
19 | 589 |
((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[ |
1626
6addd73f7d47
precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents:
1588
diff
changeset
|
590 |
(msg := self checkCondition) notNil ifTrue:[^ msg]. |
3 | 591 |
]. |
19 | 592 |
|
593 |
" |
|
594 |
(...) whileTrue:[ |
|
595 |
" |
|
3 | 596 |
((selector == #whileTrue:) or:[selector == #whileFalse:]) ifTrue:[ |
2028 | 597 |
(receiver isBlock not and:[ receiver parenthesized ]) ifTrue:[ |
598 |
"/ only warn, if code was originally parenthized |
|
599 |
^ 'will fail at runtime, if receiver of ' , selector , ' does not evaluate to a block or respond reasonable to #value' |
|
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
600 |
]. |
902 | 601 |
arg1 isBlock ifFalse:[ |
1059 | 602 |
^ 'will fail at runtime, if argument to ' , selector , ' does not evaluate to a block or respond reasonable to #value' |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
603 |
]. |
3 | 604 |
]. |
902 | 605 |
|
2028 | 606 |
" |
607 |
[...] ensure:[...] |
|
608 |
" |
|
609 |
((selector == #ensure:) or:[(selector == #ifCurtailed:)]) ifTrue:[ |
|
610 |
(receiver isBlock not and:[ receiver parenthesized ]) ifTrue:[ |
|
611 |
"/ only warn, if code was originally parenthized |
|
612 |
^ 'will fail at runtime, if receiver of ' , selector , ' does not evaluate to a block or respond reasonable to #value' |
|
613 |
]. |
|
614 |
(arg1 isBlock not and:[ arg1 parenthesized ]) ifTrue:[ |
|
615 |
^ 'will fail at runtime, if receiver of ' , selector , ' does not evaluate to a block or respond reasonable to #value' |
|
616 |
]. |
|
617 |
(arg1 isBlock and:[arg1 isEmptyBlock]) ifTrue:[ |
|
618 |
^ 'useless ensure (empty block)' |
|
619 |
]. |
|
620 |
]. |
|
621 |
||
905 | 622 |
argArray size > 0 ifTrue:[ |
623 |
"/ check for a beginners error (using super as arg) |
|
624 |
"/ as in (something ? super) foo |
|
625 |
||
626 |
argArray do:[:arg | arg isSuper ifTrue:[ |
|
1192 | 627 |
^ 'super special semantic only with receiver of message sends' |
905 | 628 |
] |
629 |
]. |
|
630 |
]. |
|
1154 | 631 |
|
2208
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
632 |
(selector = #'handle:do:' |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
633 |
or:[ selector = #'handle:from:do:' |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
634 |
or:[ selector = #'ignoreIn:' |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
635 |
or:[ selector = #'catch:' ]]]) ifTrue:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
636 |
(msg := self checkGlobalFromNameSpaceConflictFor:receiver) notNil ifTrue:[^ msg]. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
637 |
]. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
638 |
(selector = #'on:do:' |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
639 |
or:[ selector = #'on:do:ensure:' |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
640 |
or:[ selector = #'on:do:on:do:' ]]) ifTrue:[ |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
641 |
(msg := self checkGlobalFromNameSpaceConflictFor:arg1) notNil ifTrue:[^ msg]. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
642 |
]. |
334c127f8586
possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
643 |
|
1154 | 644 |
"/ receiver isBlock ifTrue:[ |
645 |
"/ ([] respondsTo:selector) ifFalse:[ |
|
646 |
"/ ^ 'blocks do not respond to ' , selector , '; Missing ''.'' between statements ?' |
|
647 |
"/ ]. |
|
648 |
"/ ]. |
|
649 |
||
0 | 650 |
^ nil |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
651 |
|
2028 | 652 |
"Modified: / 28-03-2007 / 14:14:28 / cg" |
0 | 653 |
! ! |
654 |
||
655 |
!MessageNode methodsFor:'code generation'! |
|
656 |
||
1691 | 657 |
codeOn:aStream inBlock:b for:aCompiler |
658 |
self codeOn:aStream inBlock:b valueNeeded:true for:aCompiler |
|
659 |
! |
|
660 |
||
661 |
codeOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
|
662 |
|recType nargs isBuiltIn litIndex cls clsLitIndex code isSpecial |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
663 |
specialCode stackTop arg1 arg2 arg3 isSuper realReceiver |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
664 |
noSendDrop alreadyDropped |
1994
4094e1eb3399
preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents:
1989
diff
changeset
|
665 |
useSelfSend usedSelector| |
4094e1eb3399
preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents:
1989
diff
changeset
|
666 |
|
1691 | 667 |
selector := selector asSymbol. |
1994
4094e1eb3399
preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents:
1989
diff
changeset
|
668 |
usedSelector := aCompiler nameSpaceSelectorFor:selector. |
4094e1eb3399
preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents:
1989
diff
changeset
|
669 |
|
4094e1eb3399
preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents:
1989
diff
changeset
|
670 |
"/ must be added for browsers-search to work on optimized nodes |
4094e1eb3399
preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents:
1989
diff
changeset
|
671 |
usedSelector ~~ selector ifTrue:[ aCompiler addLiteral:selector ]. |
4094e1eb3399
preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents:
1989
diff
changeset
|
672 |
litIndex := aCompiler addLiteral:usedSelector. |
1691 | 673 |
|
674 |
noSendDrop := aCompiler class newCodeSet == true. |
|
675 |
||
676 |
realReceiver := self realReceiver. |
|
677 |
isSuper := realReceiver isSuper. |
|
678 |
||
679 |
argArray isNil ifTrue:[ |
|
680 |
nargs := 0 |
|
681 |
] ifFalse:[ |
|
682 |
nargs := argArray size. |
|
683 |
nargs > 0 ifTrue:[ |
|
684 |
arg1 := argArray at:1. |
|
685 |
nargs > 1 ifTrue:[ |
|
686 |
arg2 := argArray at:2. |
|
687 |
nargs > 2 ifTrue:[ |
|
688 |
arg3 := argArray at:3. |
|
689 |
] |
|
690 |
] |
|
691 |
]. |
|
692 |
]. |
|
693 |
||
694 |
recType := receiver type. |
|
695 |
||
696 |
(nargs == 0) ifTrue:[ |
|
697 |
(recType == #ThisContext) ifTrue:[ |
|
698 |
valueNeeded ifFalse:[ |
|
699 |
"for now, only do it in methods" |
|
700 |
b isNil ifTrue:[ |
|
701 |
(selector == #restart) ifTrue:[ |
|
702 |
aStream nextPut:#jump; nextPut:1. "jump to start" |
|
703 |
^ self |
|
704 |
]. |
|
705 |
]. |
|
706 |
(selector == #return) ifTrue:[ "^ nil" |
|
707 |
aStream nextPut:#retNil. |
|
708 |
^ self |
|
709 |
]. |
|
710 |
] |
|
711 |
]. |
|
712 |
||
713 |
(receiver isBlock |
|
714 |
and:[receiver numArgs == 0 |
|
715 |
and:[receiver isInlinable]]) ifTrue:[ |
|
716 |
selector == #value ifTrue:[ |
|
717 |
receiver codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
718 |
^ self |
|
719 |
]. |
|
720 |
((selector == #whileTrue) or:[selector == #whileFalse]) ifTrue:[ |
|
721 |
^ self codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
722 |
]. |
|
723 |
((selector == #repeat) or:[selector == #loop]) ifTrue:[ |
|
724 |
valueNeeded ifFalse:[ |
|
725 |
^ self codeRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
726 |
] |
|
727 |
]. |
|
728 |
]. |
|
729 |
]. |
|
730 |
||
731 |
(nargs == 1) ifTrue:[ |
|
732 |
(recType == #ThisContext) ifTrue:[ |
|
733 |
valueNeeded ifFalse:[ |
|
734 |
(selector == #return:) ifTrue:[ |
|
735 |
arg1 codeOn:aStream inBlock:b for:aCompiler. "^ value" |
|
736 |
aStream nextPut:#retTop. |
|
737 |
^ self |
|
738 |
]. |
|
739 |
]. |
|
740 |
]. |
|
741 |
||
742 |
((selector == #ifNil:) or:[selector == #ifNotNil:]) ifTrue:[ |
|
743 |
receiver isBlock ifFalse:[ |
|
744 |
(arg1 isBlock not |
|
745 |
or:[arg1 numArgs == 0]) ifTrue:[ |
|
746 |
^ self codeIfNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
747 |
]. |
|
748 |
(arg1 isConstant or:[arg1 isVariable]) ifTrue:[ |
|
749 |
^ self codeIfNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
750 |
]. |
|
751 |
||
752 |
]. |
|
753 |
]. |
|
754 |
||
755 |
(arg1 isBlock |
|
756 |
and:[arg1 isInlinable |
|
757 |
and:[arg1 numArgs == 0]]) ifTrue:[ |
|
758 |
((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[ |
|
759 |
receiver isBlock ifFalse:[ |
|
760 |
^ self codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
761 |
]. |
|
762 |
]. |
|
763 |
||
764 |
(selector == #or:) ifTrue:[ |
|
765 |
^ self codeOrOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
766 |
]. |
|
767 |
||
768 |
(selector == #and:) ifTrue:[ |
|
769 |
^ self codeAndOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
770 |
]. |
|
771 |
||
772 |
(selector == #timesRepeat:) ifTrue:[ |
|
773 |
"/ now, always inline #timesRepeat:; |
|
774 |
"/ the receiver must understand #> and #- |
|
775 |
||
776 |
^ self codeTimesRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
777 |
]. |
|
778 |
||
779 |
((selector == #whileTrue:) or:[selector == #whileFalse:]) ifTrue:[ |
|
780 |
(receiver isBlock |
|
781 |
and:[receiver isInlinable |
|
782 |
and:[receiver numArgs == 0]]) ifTrue:[ |
|
783 |
^ self codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
784 |
] |
|
785 |
] |
|
786 |
]. |
|
787 |
||
788 |
((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[ |
|
789 |
(arg1 isConstant or:[arg1 isVariable]) ifTrue:[ |
|
790 |
^ self codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
791 |
]. |
|
792 |
]. |
|
793 |
||
1994
4094e1eb3399
preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents:
1989
diff
changeset
|
794 |
usedSelector == #? ifTrue:[ |
1691 | 795 |
"/ only do short-circuit optimization, if arg is not a message; |
796 |
"/ (could have side-effects) |
|
797 |
"/ |
|
798 |
arg1 isMessage ifFalse:[ |
|
799 |
^ self codeQuestOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
800 |
] |
|
801 |
]. |
|
802 |
]. |
|
803 |
||
804 |
(nargs == 2) ifTrue:[ |
|
805 |
receiver isBlock ifFalse:[ |
|
806 |
(arg1 isBlock |
|
807 |
and:[arg1 isInlinable |
|
808 |
and:[arg1 numArgs == 0 |
|
809 |
and:[arg2 isBlock |
|
810 |
and:[arg2 isInlinable |
|
811 |
and:[arg2 numArgs == 0]]]]]) ifTrue:[ |
|
812 |
((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[ |
|
813 |
^ self codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
814 |
]. |
|
815 |
((selector == #ifNil:ifNotNil:) or:[selector == #ifNotNil:ifNil:]) ifTrue:[ |
|
816 |
^ self codeIfNilNotNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
817 |
] |
|
818 |
]. |
|
819 |
||
820 |
((arg1 isConstant or:[arg1 isVariable]) |
|
821 |
and:[arg2 isConstant or:[arg2 isVariable]]) ifTrue:[ |
|
822 |
((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[ |
|
823 |
^ self codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
824 |
]. |
|
825 |
((selector == #ifNil:ifNotNil:) or:[selector == #ifNotNil:ifNil:]) ifTrue:[ |
|
826 |
^ self codeIfNilNotNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
827 |
] |
|
828 |
]. |
|
829 |
]. |
|
830 |
selector == #to:do: ifTrue:[ |
|
831 |
(arg2 isBlock |
|
832 |
and:[arg2 isInlinable |
|
833 |
and:[arg2 numArgs == 1]]) ifTrue:[ |
|
834 |
^ self codeToDoOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
|
835 |
] |
|
836 |
]. |
|
837 |
]. |
|
838 |
||
839 |
(nargs == 3) ifTrue:[ |
|
840 |
selector == #to:by:do: ifTrue:[ |
|
841 |
"/ step must be a constant (need to know how to compare) |
|
842 |
(arg2 isConstant |
|
843 |
and:[arg2 type == #Integer |
|
844 |
and:[arg3 isBlock |
|
845 |
and:[arg3 isInlinable |
|
846 |
and:[arg3 numArgs == 1]]]]) ifTrue:[ |
|
847 |
^ self codeToByDoOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
|
848 |
] |
|
849 |
]. |
|
850 |
]. |
|
851 |
||
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
852 |
isBuiltIn := isSpecial := false. |
1691 | 853 |
isSuper ifFalse:[ |
1994
4094e1eb3399
preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents:
1989
diff
changeset
|
854 |
isBuiltIn := aCompiler isBuiltInSelector:usedSelector forReceiver:receiver. |
1691 | 855 |
isBuiltIn ifFalse:[ |
1994
4094e1eb3399
preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents:
1989
diff
changeset
|
856 |
specialCode := aCompiler specialSendCodeFor:usedSelector. |
1691 | 857 |
isSpecial := specialCode notNil. |
858 |
]. |
|
859 |
]. |
|
860 |
||
861 |
||
862 |
"can we use a send-bytecode ?" |
|
863 |
(isBuiltIn or:[isSpecial]) ifTrue:[ |
|
864 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
|
865 |
(nargs > 0) ifTrue:[ |
|
866 |
arg1 codeOn:aStream inBlock:b for:aCompiler. |
|
867 |
(nargs > 1) ifTrue:[ |
|
868 |
arg2 codeOn:aStream inBlock:b for:aCompiler |
|
869 |
] |
|
870 |
]. |
|
1994
4094e1eb3399
preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents:
1989
diff
changeset
|
871 |
aStream nextPut:usedSelector. |
4094e1eb3399
preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents:
1989
diff
changeset
|
872 |
(aCompiler hasLineNumber:usedSelector) ifTrue:[ |
1691 | 873 |
aStream nextPut:lineNr. |
874 |
]. |
|
875 |
isSpecial ifTrue:[ |
|
876 |
aStream nextPut:specialCode |
|
877 |
]. |
|
878 |
valueNeeded ifFalse:[ |
|
879 |
aStream nextPut:#drop |
|
880 |
]. |
|
881 |
^ self |
|
882 |
]. |
|
883 |
||
884 |
((nargs == 0) and:[selector == #yourself]) ifTrue:[ |
|
885 |
"yourself is often added to get the receiver - |
|
886 |
we get it without the yourself-message" |
|
887 |
||
888 |
valueNeeded ifTrue:[ |
|
889 |
receiver codeOn:aStream inBlock:b for:aCompiler |
|
890 |
]. |
|
891 |
^ self |
|
892 |
]. |
|
893 |
||
894 |
"no - generate a send" |
|
895 |
||
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
896 |
stackTop := nil. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
897 |
|
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
898 |
useSelfSend := isSuper not and:[ recType == #Self and:[ litIndex <= 16rFFFF ] ]. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
899 |
useSelfSend ifFalse:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
900 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
901 |
receiver isConstant ifTrue:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
902 |
stackTop := receiver |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
903 |
]. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
904 |
]. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
905 |
argArray notNil ifTrue:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
906 |
argArray do:[:arg | |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
907 |
(stackTop notNil and:[arg canReuseAsArg:stackTop]) ifTrue:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
908 |
aStream nextPut:#dup. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
909 |
"/ 'reuse:' print. stackTop print. ' in ' print. aCompiler selector printNL. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
910 |
] ifFalse:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
911 |
arg codeOn:aStream inBlock:b for:aCompiler. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
912 |
stackTop := arg. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
913 |
] |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
914 |
] |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
915 |
]. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
916 |
|
1691 | 917 |
isSuper ifTrue:[ |
918 |
cls := aCompiler targetClass. |
|
919 |
realReceiver isHere ifTrue:[ |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
920 |
"/ same code as supersend, but targetClass starts search |
1691 | 921 |
] ifFalse:[ |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
922 |
"/ targetClasses superclass starts search |
1691 | 923 |
cls := cls superclass. |
924 |
]. |
|
925 |
clsLitIndex := aCompiler addLiteral:cls. |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
926 |
self emitSuperSendLiteralIndex:litIndex classLiteralIndex:clsLitIndex numArgs:nargs line:lineNr on:aStream. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
927 |
valueNeeded ifFalse:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
928 |
aStream nextPut:#drop |
1691 | 929 |
]. |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
930 |
^ self. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
931 |
]. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
932 |
|
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
933 |
valueNeeded ifTrue:[ noSendDrop := true ]. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
934 |
alreadyDropped := false. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
935 |
|
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
936 |
(litIndex <= 255) ifTrue:[ |
1691 | 937 |
(nargs <= 3) ifTrue:[ |
938 |
|codes| |
|
939 |
||
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
940 |
noSendDrop ifTrue:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
941 |
useSelfSend ifTrue:[ |
1691 | 942 |
codes := #(sendSelf0 sendSelf1 sendSelf2 sendSelf3) |
943 |
] ifFalse:[ |
|
944 |
codes := #(send0 send1 send2 send3) |
|
945 |
] |
|
946 |
] ifFalse:[ |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
947 |
useSelfSend ifTrue:[ |
1691 | 948 |
codes := #(sendSelfDrop0 sendSelfDrop1 sendSelfDrop2 sendSelfDrop3) |
949 |
] ifFalse:[ |
|
950 |
codes := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3) |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
951 |
]. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
952 |
alreadyDropped := true. |
1691 | 953 |
]. |
954 |
aStream nextPut:(codes at:(nargs + 1)); nextPut:lineNr; nextPut:litIndex. |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
955 |
valueNeeded ifFalse:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
956 |
alreadyDropped ifFalse:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
957 |
aStream nextPut:#drop |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
958 |
]. |
1691 | 959 |
]. |
960 |
^ self |
|
961 |
]. |
|
962 |
||
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
963 |
useSelfSend ifTrue:[ |
1691 | 964 |
code := #sendSelf |
965 |
] ifFalse:[ |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
966 |
noSendDrop ifTrue:[ |
1691 | 967 |
code := #send |
968 |
] ifFalse:[ |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
969 |
code := #sendDrop. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
970 |
alreadyDropped := true. |
1691 | 971 |
] |
972 |
]. |
|
973 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs. |
|
974 |
valueNeeded ifFalse:[ |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
975 |
alreadyDropped ifFalse:[ |
1691 | 976 |
aStream nextPut:#drop |
977 |
]. |
|
978 |
]. |
|
979 |
^ self |
|
980 |
]. |
|
981 |
||
982 |
"needs 16bit literal index" |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
983 |
(litIndex <= 16rFFFF) ifTrue:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
984 |
useSelfSend ifTrue:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
985 |
aStream nextPut:#sendSelfL; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs. |
1801 | 986 |
] ifFalse:[ |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
987 |
self emitSendLiteralIndex:litIndex numArgs:nargs line:lineNr on:aStream. |
1801 | 988 |
]. |
989 |
] ifFalse:[ |
|
990 |
"needs 32bit literal index" |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
991 |
self emitSendLiteralIndex:litIndex numArgs:nargs line:lineNr on:aStream. |
1691 | 992 |
]. |
1801 | 993 |
|
1691 | 994 |
valueNeeded ifFalse:[ |
995 |
aStream nextPut:#drop |
|
996 |
]. |
|
997 |
||
1994
4094e1eb3399
preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents:
1989
diff
changeset
|
998 |
"Modified: / 03-09-1995 / 12:55:42 / claus" |
4094e1eb3399
preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents:
1989
diff
changeset
|
999 |
"Modified: / 05-03-2007 / 13:32:17 / cg" |
1691 | 1000 |
! ! |
1001 |
||
1002 |
!MessageNode methodsFor:'enumerating'! |
|
1003 |
||
1004 |
messagesDo:aBlock |
|
1005 |
aBlock value:self. |
|
1006 |
receiver messagesDo:aBlock. |
|
1007 |
argArray notNil ifTrue:[ |
|
1008 |
argArray do:[:arg | arg messagesDo:aBlock]. |
|
1009 |
] |
|
1010 |
! |
|
1011 |
||
1012 |
nodeDo:anEnumerator |
|
1013 |
"helper for parse tree walking" |
|
1014 |
||
1015 |
|args| |
|
1016 |
||
1017 |
args := argArray ? #(). |
|
1018 |
^ anEnumerator doMessage:self receiver:receiver selector:selector arguments:args |
|
1019 |
||
1020 |
"Created: 19.6.1997 / 16:46:39 / cg" |
|
1021 |
"Modified: 19.6.1997 / 17:08:28 / cg" |
|
1022 |
! ! |
|
1023 |
||
1024 |
!MessageNode methodsFor:'evaluation'! |
|
1025 |
||
1026 |
evaluateForCascadeIn:anEnvironment |
|
1027 |
^ self evaluateIn:anEnvironment forCascade:true |
|
1028 |
||
1029 |
"Modified: / 20-04-2005 / 12:12:01 / cg" |
|
1030 |
! |
|
1031 |
||
1032 |
evaluateIn:anEnvironment |
|
1033 |
^ self evaluateIn:anEnvironment forCascade:false |
|
1034 |
||
1035 |
"Modified: / 20-04-2005 / 12:11:55 / cg" |
|
1036 |
! |
|
1037 |
||
1038 |
evaluateIn:anEnvironment forCascade:forCascade |
|
1039 |
|retVal r a1 a2 a3 nargs argValueArray class sel| |
|
1040 |
||
1041 |
sel := self evaluationSelector. |
|
1042 |
receiver isSuper ifTrue:[ |
|
1043 |
r := receiver value. |
|
1044 |
receiver isHere ifTrue:[ |
|
1045 |
class := receiver definingClass. |
|
1046 |
] ifFalse:[ |
|
1047 |
class := receiver definingClass superclass. |
|
1048 |
]. |
|
1049 |
argArray notNil ifTrue:[ |
|
1050 |
argValueArray := argArray collect:[:arg | arg evaluateIn:anEnvironment]. |
|
1051 |
] ifFalse:[ |
|
1052 |
argValueArray := #() |
|
1053 |
]. |
|
1054 |
retVal := r perform:sel inClass:class withArguments:argValueArray. |
|
1055 |
] ifFalse:[ |
|
1056 |
r := receiver evaluateIn:anEnvironment. |
|
1057 |
||
1058 |
argArray isNil ifTrue:[ |
|
1059 |
retVal := r perform:sel |
|
1060 |
] ifFalse:[ |
|
1061 |
nargs := argArray size. |
|
1062 |
(nargs == 0) ifTrue:[ |
|
1063 |
retVal := r perform:sel |
|
1064 |
] ifFalse:[ |
|
1065 |
a1 := (argArray at:1) evaluateIn:anEnvironment. |
|
1066 |
(nargs == 1) ifTrue:[ |
|
1067 |
retVal := r perform:sel with:a1 |
|
1068 |
] ifFalse:[ |
|
1069 |
a2 := (argArray at:2) evaluateIn:anEnvironment. |
|
1070 |
(nargs == 2) ifTrue:[ |
|
1071 |
retVal := r perform:sel with:a1 with:a2 |
|
1072 |
] ifFalse:[ |
|
1073 |
a3 := (argArray at:3) evaluateIn:anEnvironment. |
|
1074 |
(nargs == 3) ifTrue:[ |
|
1075 |
retVal := r perform:sel with:a1 with:a2 with:a3 |
|
1076 |
] ifFalse:[ |
|
1077 |
argValueArray := Array new:nargs. |
|
1078 |
argValueArray at:1 put:a1. |
|
1079 |
argValueArray at:2 put:a2. |
|
1080 |
argValueArray at:3 put:a3. |
|
1081 |
4 to:nargs do:[:idx | argValueArray at:idx put:((argArray at:idx) evaluateIn:anEnvironment)]. |
|
1082 |
retVal := r perform:sel withArguments:argValueArray. |
|
1083 |
]. |
|
1084 |
]. |
|
1085 |
]. |
|
1086 |
]. |
|
1087 |
]. |
|
1088 |
]. |
|
1089 |
^ forCascade ifTrue:[r] ifFalse:[retVal] |
|
1090 |
||
1091 |
"Created: / 20-04-2005 / 12:11:39 / cg" |
|
1092 |
! |
|
1093 |
||
1094 |
evaluationSelector |
|
1095 |
^ selector asSymbol |
|
1096 |
! ! |
|
1097 |
||
1098 |
!MessageNode methodsFor:'optimized code generation'! |
|
1099 |
||
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1100 |
codeAndIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1101 |
"generate code for (x and:[y]) ifxxx:[ ... ] ifyyy:[ ... ]" |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1102 |
|
1059 | 1103 |
|theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp |
1104 |
block1 block2| |
|
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1105 |
|
1464
fa19f86d1ef4
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
1106 |
aCompiler addLiteral:#and:. |
fa19f86d1ef4
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
1107 |
|
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1108 |
theByteCode := #falseJump. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1109 |
theReceiver := receiver receiver. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1110 |
|
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
1111 |
optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler. |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1112 |
optByteCode notNil ifTrue:[ |
1058 | 1113 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
1114 |
theArg := theReceiver arg1 |
|
1115 |
]. |
|
1116 |
theReceiver := theReceiver receiver. |
|
1117 |
theByteCode := optByteCode |
|
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1118 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1119 |
"/ code the left-of the and-part |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1120 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1121 |
theArg notNil ifTrue:[ |
1058 | 1122 |
theArg codeOn:aStream inBlock:b for:aCompiler |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1123 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1124 |
aStream nextPut:theByteCode. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1125 |
pos1 := aStream position1Based. "/ remember branch target of left-fail branch |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1126 |
aStream nextPut:0. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1127 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1128 |
"/ code the right of the and-part |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1129 |
theReceiver := receiver arg1. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1130 |
theReceiver codeInlineOn:aStream inBlock:b for:aCompiler. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1131 |
(selector == #ifTrue:ifFalse:) ifTrue:[ |
1058 | 1132 |
jmp := #falseJump |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1133 |
] ifFalse:[ |
1058 | 1134 |
jmp := #trueJump |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1135 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1136 |
aStream nextPut:jmp. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1137 |
pos2 := aStream position1Based. "/ remember branch target of right-fail branch |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1138 |
aStream nextPut:0. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1139 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1140 |
code := aStream contents. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1141 |
(selector == #ifFalse:ifTrue:) ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1142 |
code at:pos1 put:(aStream position1Based) |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1143 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1144 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1145 |
"/ code the if-block |
1059 | 1146 |
block1 := argArray at: 1. |
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1147 |
self codeBlockEvaluation:block1 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1148 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1149 |
aStream nextPut:#jump. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1150 |
pos3 := aStream position1Based. |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1151 |
aStream nextPut:0. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1152 |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1153 |
here := aStream position1Based. |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1154 |
(selector == #ifTrue:ifFalse:) ifTrue:[ |
1058 | 1155 |
code at:pos1 put:here |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1156 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1157 |
code at:pos2 put:here. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1158 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1159 |
"/ code the else-block |
1059 | 1160 |
block2 := argArray at: 2. |
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1161 |
self codeBlockEvaluation:block2 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1162 |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1163 |
code at:pos3 put:(aStream position1Based) |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1164 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1165 |
"Created: 6.9.1996 / 12:56:23 / cg" |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1166 |
! |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1167 |
|
140 | 1168 |
codeAndIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
1169 |
"generate code for (x and:[y]) ifxxx:[ ... ]" |
|
1170 |
||
812
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1171 |
|theByteCode optByteCode andBlock theArg pos1 pos2 pos3 code here jmp |
1059 | 1172 |
receiver1 receiver2 optByteCode2 theArg2 block| |
140 | 1173 |
|
1464
fa19f86d1ef4
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
1174 |
aCompiler addLiteral:#and:. |
fa19f86d1ef4
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
1175 |
|
140 | 1176 |
theByteCode := #falseJump. |
812
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1177 |
receiver1 := receiver receiver. |
0 | 1178 |
|
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
1179 |
optByteCode := self optimizedConditionFor:receiver1 with:theByteCode for:aCompiler. |
812
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1180 |
|
140 | 1181 |
optByteCode notNil ifTrue:[ |
812
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1182 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1183 |
theArg := receiver1 arg1 |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1184 |
]. |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1185 |
receiver1 := receiver1 receiver. |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1186 |
theByteCode := optByteCode |
140 | 1187 |
]. |
812
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1188 |
receiver1 codeOn:aStream inBlock:b for:aCompiler. |
140 | 1189 |
theArg notNil ifTrue:[ |
812
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1190 |
theArg codeOn:aStream inBlock:b for:aCompiler |
140 | 1191 |
]. |
1192 |
aStream nextPut:theByteCode. |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1193 |
pos1 := aStream position1Based. |
140 | 1194 |
aStream nextPut:0. |
0 | 1195 |
|
812
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1196 |
andBlock := receiver arg1. "/ the and:-block |
140 | 1197 |
(selector == #ifTrue:) ifTrue:[ |
812
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1198 |
jmp := #falseJump |
140 | 1199 |
] ifFalse:[ |
812
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1200 |
jmp := #trueJump |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1201 |
]. |
1719 | 1202 |
(andBlock statements isNil or:[andBlock statements nextStatement]) isNil ifTrue:[ |
812
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1203 |
"/ simple - one statement |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1204 |
receiver2 := andBlock statements expression. |
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
1205 |
optByteCode2 := self optimizedConditionFor:receiver2 with:jmp for:aCompiler. |
812
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1206 |
]. |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1207 |
optByteCode2 notNil ifTrue:[ |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1208 |
((optByteCode2 == #eqJump) or:[optByteCode2 == #notEqJump]) ifTrue:[ |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1209 |
theArg2 := receiver2 arg1 |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1210 |
]. |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1211 |
receiver2 := receiver2 receiver. |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1212 |
receiver2 codeOn:aStream inBlock:b for:aCompiler. |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1213 |
theArg2 notNil ifTrue:[ |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1214 |
theArg2 codeOn:aStream inBlock:b for:aCompiler |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1215 |
]. |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1216 |
jmp := optByteCode2. |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1217 |
] ifFalse:[ |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1218 |
andBlock codeInlineOn:aStream inBlock:b for:aCompiler. |
140 | 1219 |
]. |
1220 |
aStream nextPut:jmp. |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1221 |
pos2 := aStream position1Based. |
0 | 1222 |
aStream nextPut:0. |
1223 |
||
140 | 1224 |
code := aStream contents. |
1225 |
(selector == #ifFalse:) ifTrue:[ |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1226 |
code at:pos1 put:(aStream position1Based) |
140 | 1227 |
]. |
1059 | 1228 |
block := argArray at: 1. |
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1229 |
self codeBlockEvaluation:block on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
140 | 1230 |
|
1231 |
valueNeeded ifTrue:[ |
|
812
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1232 |
aStream nextPut:#jump. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1233 |
pos3 := aStream position1Based. |
812
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1234 |
aStream nextPut:0. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1235 |
here := aStream position1Based. |
812
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1236 |
(selector == #ifTrue:) ifTrue:[ |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1237 |
code at:pos1 put:here |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1238 |
]. |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1239 |
code at:pos2 put:here. |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1240 |
aStream nextPut:#pushNil. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1241 |
code at:pos3 put:(aStream position1Based) |
140 | 1242 |
] ifFalse:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1243 |
here := aStream position1Based. |
812
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1244 |
(selector == #ifTrue:) ifTrue:[ |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1245 |
code at:pos1 put:here |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1246 |
]. |
367d2e8eb499
slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
1247 |
code at:pos2 put:here |
140 | 1248 |
] |
1249 |
! |
|
1250 |
||
289 | 1251 |
codeAndOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
1252 |
"generate code for (x and:[y])" |
|
140 | 1253 |
|
289 | 1254 |
|pos1 rightExpr| |
1255 |
||
1464
fa19f86d1ef4
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
1256 |
aCompiler addLiteral:#and:. |
fa19f86d1ef4
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
1257 |
|
289 | 1258 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
1259 |
valueNeeded ifTrue:[ |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1260 |
aStream nextPut:#dup. |
140 | 1261 |
]. |
289 | 1262 |
aStream nextPut:#falseJump. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1263 |
pos1 := aStream position1Based. |
289 | 1264 |
aStream nextPut:0. |
1265 |
valueNeeded ifTrue:[ |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1266 |
aStream nextPut:#drop. |
140 | 1267 |
]. |
289 | 1268 |
rightExpr := argArray at:1. |
1269 |
rightExpr codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
163 | 1270 |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1271 |
(aStream contents) at:pos1 put:(aStream position1Based) |
289 | 1272 |
|
1273 |
"Created: 17.6.1996 / 15:46:42 / cg" |
|
1274 |
"Modified: 17.6.1996 / 15:47:44 / cg" |
|
140 | 1275 |
! |
1276 |
||
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1277 |
codeBlockEvaluation:aBlock on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1278 |
"gen code to evaluate a block" |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1279 |
|
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1280 |
(aBlock isBlock and:[aBlock isInlinable]) ifTrue:[ |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1281 |
aBlock codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1282 |
] ifFalse:[ |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1283 |
aBlock codeOn:aStream inBlock:b for:aCompiler. |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1284 |
aBlock isConstant ifFalse:[ |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1285 |
self codeValueSendOn:aStream for:aCompiler. |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1286 |
]. |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1287 |
valueNeeded ifFalse:[ |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1288 |
aStream nextPut:#drop |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1289 |
]. |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1290 |
]. |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1291 |
! |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1292 |
|
140 | 1293 |
codeForCascadeOn:aStream inBlock:b for:aCompiler |
1294 |
"like codeOn, but always leave the receiver instead of the result" |
|
1295 |
||
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1296 |
|nargs isBuiltIn code litIndex cls clsLitIndex isSuper realReceiver noSendDrop| |
1048 | 1297 |
|
1500
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
1298 |
selector := selector asSymbol. |
1048 | 1299 |
noSendDrop := aCompiler class newCodeSet == true. |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1300 |
|
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1301 |
realReceiver := self realReceiver. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1302 |
isSuper := realReceiver isSuper. |
140 | 1303 |
|
1304 |
argArray isNil ifTrue:[ |
|
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1305 |
nargs := 0 |
140 | 1306 |
] ifFalse:[ |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1307 |
nargs := argArray size |
140 | 1308 |
]. |
1309 |
||
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1310 |
isBuiltIn := isSuper not and:[ aCompiler isBuiltInSelector:selector forReceiver:receiver ]. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1311 |
|
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1312 |
litIndex := aCompiler addLiteral:selector. |
140 | 1313 |
|
1314 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
|
1315 |
aStream nextPut:#dup. |
|
1316 |
||
1317 |
"can we use a send-bytecode ?" |
|
1318 |
isBuiltIn ifTrue:[ |
|
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1319 |
(nargs > 0) ifTrue:[ |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1320 |
(argArray at:1) codeOn:aStream inBlock:b for:aCompiler. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1321 |
(nargs > 1) ifTrue:[ |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1322 |
(argArray at:2) codeOn:aStream inBlock:b for:aCompiler |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1323 |
] |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1324 |
]. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1325 |
aStream nextPut:selector. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1326 |
(aCompiler hasLineNumber:selector) ifTrue:[ |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1327 |
aStream nextPut:lineNr. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1328 |
]. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1329 |
aStream nextPut:#drop. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1330 |
^ self |
140 | 1331 |
]. |
1332 |
||
1333 |
"no - generate a send" |
|
1334 |
argArray notNil ifTrue:[ |
|
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1335 |
argArray do:[:arg | |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1336 |
arg codeOn:aStream inBlock:b for:aCompiler |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1337 |
] |
140 | 1338 |
]. |
189
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
1339 |
|
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1340 |
isSuper ifTrue:[ |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1341 |
cls := aCompiler targetClass. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1342 |
realReceiver isHere ifTrue:[ |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1343 |
"/ same code as supersend, but targetClass starts search |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1344 |
] ifFalse:[ |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1345 |
"/ targetClasses superclass starts search |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1346 |
cls := cls superclass. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1347 |
]. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1348 |
clsLitIndex := aCompiler addLiteral:cls. |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1349 |
self emitSuperSendLiteralIndex:litIndex classLiteralIndex:clsLitIndex numArgs:nargs line:lineNr on:aStream. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1350 |
aStream nextPut:#drop. |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1351 |
^ self |
189
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
1352 |
]. |
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
1353 |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1354 |
noSendDrop ifFalse:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1355 |
litIndex <= 255 ifTrue:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1356 |
(nargs <= 3) ifTrue:[ |
1046 | 1357 |
code := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3) at:(nargs+1). |
1358 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex. |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1359 |
^ self |
1046 | 1360 |
]. |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1361 |
aStream nextPut:#sendDrop; nextPut:lineNr; nextPut:litIndex; nextPut:nargs. |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1362 |
^ self |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1363 |
]. |
140 | 1364 |
]. |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1365 |
|
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1366 |
self emitSendLiteralIndex:litIndex numArgs:nargs line:lineNr on:aStream. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1367 |
aStream nextPut:#drop. |
189
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
1368 |
|
886 | 1369 |
"Modified: / 4.7.1999 / 19:06:53 / cg" |
140 | 1370 |
! |
1371 |
||
1372 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
1373 |
self codeOn:aStream inBlock:b valueNeeded:false for:aCompiler |
|
0 | 1374 |
! |
1375 |
||
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1376 |
codeForSimpleReturnOn:aStream inBlock:b lineNumber:lineNrOrNil for:aCompiler |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1377 |
|arg1 rightExpr pos1| |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1378 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1379 |
(selector == #and: |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1380 |
or:[selector == #or:]) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1381 |
arg1 := argArray at:1. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1382 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1383 |
"/ for now: |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1384 |
"/ only do it for non-blocks, since |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1385 |
"/ the JIT compiler is smart enough to |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1386 |
"/ specially optimize the resulting code |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1387 |
"/ (and not smart enough to optimized the |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1388 |
"/ other - actually more efficient - code) |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1389 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1390 |
(arg1 isBlock not |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1391 |
"/ or:[arg1 isInlinable] |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1392 |
) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1393 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1394 |
"/ encode #and: as: |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1395 |
"/ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1396 |
"/ eLeft |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1397 |
"/ jmp_false LBL |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1398 |
"/ eRight |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1399 |
"/ retTop |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1400 |
"/ LBL: |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1401 |
"/ retFalse |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1402 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1403 |
"/ encode #or: as: |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1404 |
"/ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1405 |
"/ eLeft |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1406 |
"/ jmp_true LBL |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1407 |
"/ eRight |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1408 |
"/ retTop |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1409 |
"/ LBL: |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1410 |
"/ retTrue |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1411 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1412 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1413 |
selector == #and: ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1414 |
aStream nextPut:#falseJump. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1415 |
] ifFalse:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1416 |
aStream nextPut:#trueJump. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1417 |
]. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1418 |
pos1 := aStream position1Based. |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1419 |
aStream nextPut:0. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1420 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1421 |
rightExpr := argArray at:1. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1422 |
rightExpr isBlock ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1423 |
rightExpr codeInlineOn:aStream inBlock:b valueNeeded:true for:aCompiler. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1424 |
] ifFalse:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1425 |
rightExpr codeOn:aStream inBlock:b for:aCompiler. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1426 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1427 |
aStream nextPut:#retTop. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1428 |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1429 |
(aStream contents) at:pos1 put:(aStream position1Based). |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1430 |
selector == #and: ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1431 |
aStream nextPut:#retFalse. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1432 |
] ifFalse:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1433 |
aStream nextPut:#retTrue |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1434 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1435 |
^ self. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1436 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1437 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1438 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1439 |
super |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1440 |
codeForSimpleReturnOn:aStream |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1441 |
inBlock:b |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1442 |
lineNumber:lineNrOrNil |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1443 |
for:aCompiler |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1444 |
! |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
1445 |
|
104 | 1446 |
codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
0 | 1447 |
"generate code for x ifxxx:[ ... ] yyy:[ ...]" |
1448 |
||
334
cd7491b7ad33
dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1449 |
|pos pos2 theReceiver theArg theByteCode optByteCode subsel code needLineNr |
1059 | 1450 |
needJump block1 block2| |
0 | 1451 |
|
1452 |
theReceiver := receiver. |
|
76 | 1453 |
|
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1454 |
theReceiver isConstant ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1455 |
(self tryFoldedIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1456 |
^ self |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1457 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1458 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1459 |
|
76 | 1460 |
(theReceiver isMessage) ifTrue:[ |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1461 |
subsel := theReceiver selector. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1462 |
(subsel == #and:) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1463 |
self codeAndIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1464 |
^ self |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1465 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1466 |
(subsel == #or:) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1467 |
self codeOrIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1468 |
^ self |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1469 |
] |
76 | 1470 |
]. |
0 | 1471 |
(selector == #ifTrue:ifFalse:) ifTrue:[ |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1472 |
theByteCode := #falseJump |
0 | 1473 |
] ifFalse:[ |
1059 | 1474 |
theByteCode := #trueJump |
0 | 1475 |
]. |
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
1476 |
optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler. |
0 | 1477 |
optByteCode notNil ifTrue:[ |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1478 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1479 |
theArg := theReceiver arg1 |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1480 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1481 |
theReceiver := theReceiver receiver. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1482 |
theByteCode := optByteCode |
0 | 1483 |
]. |
1059 | 1484 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
1485 |
||
1486 |
needLineNr := true. |
|
1487 |
theArg isNil ifTrue:[ |
|
1488 |
theReceiver isMessage ifTrue:[ |
|
1489 |
(aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[ |
|
1490 |
theReceiver lineNumber == lineNr ifTrue:[ |
|
1491 |
needLineNr := false |
|
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1492 |
] |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1493 |
] |
1059 | 1494 |
] |
1495 |
] ifFalse:[ |
|
1496 |
theArg codeOn:aStream inBlock:b for:aCompiler |
|
1497 |
]. |
|
1498 |
||
1499 |
needLineNr ifTrue:[ |
|
1500 |
(lineNr between:1 and:255) ifTrue:[ |
|
1501 |
aStream nextPut:#lineno; nextPut:lineNr. |
|
1502 |
] |
|
1503 |
]. |
|
1504 |
||
1505 |
aStream nextPut:theByteCode. |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1506 |
pos := aStream position1Based. |
1059 | 1507 |
aStream nextPut:0. |
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1508 |
block1 := argArray at:1. |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1509 |
self codeBlockEvaluation:block1 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1510 |
|
1059 | 1511 |
needJump := true. |
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1512 |
(block1 isBlock and:[block1 endsWithReturn]) ifTrue:[ |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1513 |
needJump := false |
1059 | 1514 |
]. |
1515 |
needJump ifTrue:[ |
|
1516 |
aStream nextPut:#jump. |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1517 |
pos2 := aStream position1Based. |
1059 | 1518 |
aStream nextPut:0. |
1519 |
]. |
|
1520 |
code := aStream contents. |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1521 |
code at:pos put:(aStream position1Based). |
1059 | 1522 |
block2 := (argArray at:2). |
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1523 |
self codeBlockEvaluation:block2 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
1059 | 1524 |
needJump ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1525 |
code at:pos2 put:(aStream position1Based) |
0 | 1526 |
] |
166
9f6c57a3bce1
no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents:
163
diff
changeset
|
1527 |
|
434
c48a356d8a34
oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents:
429
diff
changeset
|
1528 |
"Modified: 9.11.1996 / 19:53:52 / cg" |
0 | 1529 |
! |
1530 |
||
898 | 1531 |
codeIfNilNotNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
1034
d4f1640f1aad
better code for #ifNil:ifNotNil:, if args are non-block consts
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
1532 |
"generate code for x ifNil:[ ... ] ifNotNil:[...] |
d4f1640f1aad
better code for #ifNil:ifNotNil:, if args are non-block consts
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
1533 |
or: x ifNil:const1 ifNotNil:const2" |
898 | 1534 |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1535 |
|pos pos2 theReceiver theArg theByteCode code |
1059 | 1536 |
needLineNr block1 block2| |
898 | 1537 |
|
1538 |
theReceiver := receiver. |
|
1539 |
||
1540 |
(selector == #ifNil:ifNotNil:) ifTrue:[ |
|
1541 |
theByteCode := #notNilJump |
|
1542 |
] ifFalse:[ |
|
1543 |
theByteCode := #nilJump |
|
1544 |
]. |
|
1545 |
||
1546 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
|
1547 |
||
1548 |
needLineNr := true. |
|
1549 |
theArg isNil ifTrue:[ |
|
1550 |
theReceiver isMessage ifTrue:[ |
|
1551 |
(aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[ |
|
1552 |
theReceiver lineNumber == lineNr ifTrue:[ |
|
1553 |
needLineNr := false |
|
1554 |
] |
|
1555 |
] |
|
1556 |
] |
|
1557 |
]. |
|
1558 |
||
1559 |
needLineNr ifTrue:[ |
|
1560 |
(lineNr between:1 and:255) ifTrue:[ |
|
1561 |
aStream nextPut:#lineno; nextPut:lineNr. |
|
1562 |
] |
|
1563 |
]. |
|
1564 |
||
1565 |
aStream nextPut:theByteCode. |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1566 |
pos := aStream position1Based. |
898 | 1567 |
aStream nextPut:0. |
1059 | 1568 |
block1 := argArray at: 1. |
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1569 |
self codeBlockEvaluation:block1 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
898 | 1570 |
aStream nextPut:#jump. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1571 |
pos2 := aStream position1Based. |
898 | 1572 |
aStream nextPut:0. |
1573 |
||
1574 |
code := aStream contents. |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1575 |
code at:pos put:(aStream position1Based). |
1059 | 1576 |
block2 := argArray at: 2. |
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1577 |
self codeBlockEvaluation:block2 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
898 | 1578 |
|
1579 |
code := aStream contents. |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1580 |
code at:pos2 put:(aStream position1Based) |
898 | 1581 |
|
1034
d4f1640f1aad
better code for #ifNil:ifNotNil:, if args are non-block consts
Claus Gittinger <cg@exept.de>
parents:
1017
diff
changeset
|
1582 |
"Modified: / 11.2.2000 / 12:50:36 / cg" |
898 | 1583 |
! |
1584 |
||
1585 |
codeIfNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
|
1586 |
"generate code for x ifNil:[ ... ]" |
|
1587 |
||
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1588 |
|pos theReceiver theByteCode code needLineNr| |
898 | 1589 |
|
1590 |
theReceiver := receiver. |
|
1591 |
||
1592 |
(selector == #ifNil:) ifTrue:[ |
|
1593 |
theByteCode := #notNilJump |
|
1594 |
] ifFalse:[ |
|
1595 |
theByteCode := #nilJump |
|
1596 |
]. |
|
1597 |
||
1598 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
|
1599 |
||
1600 |
needLineNr := true. |
|
899
fb678b9e18a7
also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1601 |
|
fb678b9e18a7
also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1602 |
theReceiver isMessage ifTrue:[ |
fb678b9e18a7
also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1603 |
(aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[ |
fb678b9e18a7
also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1604 |
theReceiver lineNumber == lineNr ifTrue:[ |
fb678b9e18a7
also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1605 |
needLineNr := false |
898 | 1606 |
] |
1607 |
] |
|
1608 |
]. |
|
1609 |
||
1610 |
needLineNr ifTrue:[ |
|
1611 |
(lineNr between:1 and:255) ifTrue:[ |
|
1612 |
aStream nextPut:#lineno; nextPut:lineNr. |
|
1613 |
] |
|
1614 |
]. |
|
1615 |
||
1616 |
valueNeeded ifTrue:[ |
|
1617 |
aStream nextPut:#dup. |
|
1618 |
]. |
|
1619 |
aStream nextPut:theByteCode. |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1620 |
pos := aStream position1Based. |
898 | 1621 |
aStream nextPut:0. |
1622 |
valueNeeded ifTrue:[ |
|
1623 |
aStream nextPut:#drop. |
|
1624 |
]. |
|
899
fb678b9e18a7
also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents:
898
diff
changeset
|
1625 |
|
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1626 |
self codeBlockEvaluation:(argArray at: 1) on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
898 | 1627 |
|
1628 |
code := aStream contents. |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1629 |
code at:pos put:(aStream position1Based) |
898 | 1630 |
|
1631 |
"Modified: / 28.10.1997 / 18:33:42 / cg" |
|
1632 |
! |
|
1633 |
||
104 | 1634 |
codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
0 | 1635 |
"generate code for x ifxxx:[ ... ]" |
1636 |
||
103 | 1637 |
|pos pos2 theReceiver theArg theByteCode optByteCode subsel code |
1059 | 1638 |
needLineNr block| |
0 | 1639 |
|
1640 |
theReceiver := receiver. |
|
1641 |
||
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1642 |
theReceiver isConstant ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1643 |
(self tryFoldedIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1644 |
^ self |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1645 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1646 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1647 |
|
76 | 1648 |
(theReceiver isMessage) ifTrue:[ |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1649 |
subsel := theReceiver selector. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1650 |
|
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1651 |
(subsel == #and:) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1652 |
theReceiver arg1 isBlock ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1653 |
self codeAndIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1654 |
^ self |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1655 |
] |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1656 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1657 |
(subsel == #or:) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1658 |
theReceiver arg1 isBlock ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1659 |
self codeOrIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1660 |
^ self |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1661 |
] |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1662 |
]. |
0 | 1663 |
]. |
1664 |
(selector == #ifTrue:) ifTrue:[ |
|
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1665 |
theByteCode := #falseJump |
0 | 1666 |
] ifFalse:[ |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1667 |
theByteCode := #trueJump |
0 | 1668 |
]. |
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
1669 |
optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler. |
0 | 1670 |
optByteCode notNil ifTrue:[ |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1671 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1672 |
theArg := theReceiver arg1 |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1673 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1674 |
theReceiver := theReceiver receiver. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1675 |
theByteCode := optByteCode |
0 | 1676 |
]. |
1677 |
||
104 | 1678 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
0 | 1679 |
theArg notNil ifTrue:[ |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1680 |
theArg codeOn:aStream inBlock:b for:aCompiler |
0 | 1681 |
]. |
53 | 1682 |
|
103 | 1683 |
needLineNr := true. |
1684 |
theArg isNil ifTrue:[ |
|
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1685 |
theReceiver isMessage ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1686 |
(aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1687 |
theReceiver lineNumber == lineNr ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1688 |
needLineNr := false |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1689 |
] |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1690 |
] |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1691 |
] |
103 | 1692 |
]. |
1693 |
||
1694 |
needLineNr ifTrue:[ |
|
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1695 |
(lineNr between:1 and:255) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1696 |
aStream nextPut:#lineno; nextPut:lineNr. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1697 |
] |
53 | 1698 |
]. |
1699 |
||
0 | 1700 |
aStream nextPut:theByteCode. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1701 |
pos := aStream position1Based. |
0 | 1702 |
aStream nextPut:0. |
1059 | 1703 |
block := (argArray at:1). |
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1704 |
|
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1705 |
self codeBlockEvaluation:block on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
76 | 1706 |
|
1707 |
code := aStream contents. |
|
0 | 1708 |
valueNeeded ifTrue:[ |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1709 |
aStream nextPut:#jump. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1710 |
pos2 := aStream position1Based. |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1711 |
aStream nextPut:0. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1712 |
code at:pos put:(aStream position1Based). |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
1713 |
aStream nextPut:#pushNil. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1714 |
code at:pos2 put:(aStream position1Based) |
0 | 1715 |
] ifFalse:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1716 |
code at:pos put:(aStream position1Based) |
0 | 1717 |
] |
308
fe3b95e6d9c0
oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents:
289
diff
changeset
|
1718 |
|
627 | 1719 |
"Modified: / 28.10.1997 / 18:33:42 / cg" |
0 | 1720 |
! |
1721 |
||
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1722 |
codeOrIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1723 |
"generate code for (x or:[y]) ifxxx:[ ... ] ifyyy:[ ... ]" |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1724 |
|
1057 | 1725 |
|theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp |
1059 | 1726 |
block1 block2 optJmp blockExpr| |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1727 |
|
1464
fa19f86d1ef4
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
1728 |
aCompiler addLiteral:#or:. |
fa19f86d1ef4
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
1729 |
|
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1730 |
theByteCode := #trueJump. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1731 |
theReceiver := receiver receiver. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1732 |
|
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
1733 |
optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler. |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1734 |
optByteCode notNil ifTrue:[ |
1057 | 1735 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
1736 |
theArg := theReceiver arg1 |
|
1737 |
]. |
|
1738 |
theReceiver := theReceiver receiver. |
|
1739 |
theByteCode := optByteCode |
|
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1740 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1741 |
"/ code the left-of the or-part |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1742 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1743 |
theArg notNil ifTrue:[ |
1057 | 1744 |
theArg codeOn:aStream inBlock:b for:aCompiler |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1745 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1746 |
aStream nextPut:theByteCode. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1747 |
pos1 := aStream position1Based. "/ remember branch target of left-ok branch |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1748 |
aStream nextPut:0. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1749 |
|
1057 | 1750 |
"/ code the right of the or-part |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1751 |
(selector == #ifTrue:ifFalse:) ifTrue:[ |
1057 | 1752 |
jmp := #falseJump |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1753 |
] ifFalse:[ |
1057 | 1754 |
jmp := #trueJump |
1755 |
]. |
|
1756 |
theReceiver := receiver arg1. |
|
1757 |
theArg := nil. |
|
1758 |
optJmp := nil. |
|
1759 |
||
1760 |
(theReceiver isBlock |
|
1761 |
and:[theReceiver statements notNil |
|
1762 |
and:[theReceiver statements nextStatement isNil]]) ifTrue:[ |
|
1763 |
blockExpr := theReceiver statements expression. |
|
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
1764 |
optJmp := self optimizedConditionFor:blockExpr with:jmp for:aCompiler. |
1057 | 1765 |
optJmp notNil ifTrue:[ |
1766 |
((optJmp == #eqJump) or:[optJmp == #notEqJump]) ifTrue:[ |
|
1767 |
theArg := blockExpr arg1 |
|
1768 |
]. |
|
1769 |
theReceiver := blockExpr receiver. |
|
1770 |
jmp := optJmp |
|
1771 |
]. |
|
1772 |
]. |
|
1773 |
||
1774 |
optJmp notNil ifTrue:[ |
|
1775 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
|
1058 | 1776 |
theArg notNil ifTrue:[ |
1777 |
theArg codeOn:aStream inBlock:b for:aCompiler |
|
1778 |
] |
|
1057 | 1779 |
] ifFalse:[ |
1780 |
theReceiver codeInlineOn:aStream inBlock:b for:aCompiler. |
|
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1781 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1782 |
aStream nextPut:jmp. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1783 |
pos2 := aStream position1Based. "/ remember branch target of right-fail branch |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1784 |
aStream nextPut:0. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1785 |
|
1057 | 1786 |
|
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1787 |
code := aStream contents. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1788 |
(selector == #ifTrue:ifFalse:) ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1789 |
code at:pos1 put:(aStream position1Based) |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1790 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1791 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1792 |
"/ code the if-block |
1059 | 1793 |
block1 := argArray at: 1. |
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1794 |
self codeBlockEvaluation:block1 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1795 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1796 |
aStream nextPut:#jump. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1797 |
pos3 := aStream position1Based. |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1798 |
aStream nextPut:0. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1799 |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1800 |
here := aStream position1Based. |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1801 |
(selector == #ifFalse:ifTrue:) ifTrue:[ |
1057 | 1802 |
code at:pos1 put:here |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1803 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1804 |
code at:pos2 put:here. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1805 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1806 |
"/ code the else-block |
1059 | 1807 |
block2 := argArray at: 2. |
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1808 |
self codeBlockEvaluation:block2 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1809 |
code at:pos3 put:(aStream position1Based) |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1810 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1811 |
"Created: 6.9.1996 / 13:08:52 / cg" |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1812 |
! |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1813 |
|
140 | 1814 |
codeOrIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
1815 |
"generate code for (x or:[y]) ifxxx:[ ... ]" |
|
1816 |
||
1059 | 1817 |
|theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp |
1818 |
block| |
|
140 | 1819 |
|
1464
fa19f86d1ef4
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
1820 |
aCompiler addLiteral:#or:. |
fa19f86d1ef4
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
1821 |
|
140 | 1822 |
theByteCode := #trueJump. |
1823 |
theReceiver := receiver receiver. |
|
1824 |
||
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
1825 |
optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler. |
140 | 1826 |
optByteCode notNil ifTrue:[ |
1059 | 1827 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
1828 |
theArg := theReceiver arg1 |
|
1829 |
]. |
|
1830 |
theReceiver := theReceiver receiver. |
|
1831 |
theByteCode := optByteCode |
|
140 | 1832 |
]. |
1833 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
|
1834 |
theArg notNil ifTrue:[ |
|
1059 | 1835 |
theArg codeOn:aStream inBlock:b for:aCompiler |
140 | 1836 |
]. |
1837 |
aStream nextPut:theByteCode. |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1838 |
pos1 := aStream position1Based. |
140 | 1839 |
aStream nextPut:0. |
1840 |
||
1841 |
||
1842 |
theReceiver := receiver arg1. |
|
434
c48a356d8a34
oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents:
429
diff
changeset
|
1843 |
theArg := nil. |
140 | 1844 |
|
1845 |
"new:" |
|
1846 |
(selector == #ifTrue:) ifTrue:[ |
|
1059 | 1847 |
theByteCode := #falseJump |
140 | 1848 |
] ifFalse:[ |
1059 | 1849 |
theByteCode := #trueJump |
140 | 1850 |
]. |
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
1851 |
optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler. |
140 | 1852 |
optByteCode notNil ifTrue:[ |
1059 | 1853 |
theReceiver isBlock ifTrue:[ |
1854 |
theReceiver := theReceiver statements expression |
|
1855 |
]. |
|
1856 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
|
1857 |
theArg := theReceiver arg1 |
|
1858 |
]. |
|
1859 |
theReceiver := theReceiver receiver. |
|
1860 |
theByteCode := optByteCode. |
|
1861 |
||
1862 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
|
1863 |
theArg notNil ifTrue:[ |
|
1864 |
theArg codeOn:aStream inBlock:b for:aCompiler |
|
1865 |
]. |
|
1866 |
aStream nextPut:theByteCode. |
|
140 | 1867 |
|
1868 |
] ifFalse:[ |
|
1869 |
"org" |
|
1059 | 1870 |
theReceiver codeInlineOn:aStream inBlock:b for:aCompiler. |
1871 |
(selector == #ifTrue:) ifTrue:[ |
|
1872 |
jmp := #falseJump |
|
1873 |
] ifFalse:[ |
|
1874 |
jmp := #trueJump |
|
1875 |
]. |
|
1876 |
aStream nextPut:jmp |
|
140 | 1877 |
]. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1878 |
pos2 := aStream position1Based. |
140 | 1879 |
aStream nextPut:0. |
1880 |
(selector == #ifTrue:) ifTrue:[ |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1881 |
(aStream contents) at:pos1 put:(aStream position1Based) |
140 | 1882 |
]. |
1059 | 1883 |
block := argArray at: 1. |
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
1884 |
self codeBlockEvaluation:block on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
140 | 1885 |
|
1886 |
code := aStream contents. |
|
1887 |
valueNeeded ifTrue:[ |
|
1059 | 1888 |
aStream nextPut:#jump. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1889 |
pos3 := aStream position1Based. |
1059 | 1890 |
aStream nextPut:0. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1891 |
here := aStream position1Based. |
1059 | 1892 |
(selector == #ifFalse:) ifTrue:[ |
1893 |
code at:pos1 put:here |
|
1894 |
]. |
|
1895 |
code at:pos2 put:here. |
|
1896 |
aStream nextPut:#pushNil. |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1897 |
code at:pos3 put:(aStream position1Based) |
140 | 1898 |
] ifFalse:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1899 |
here := aStream position1Based. |
1059 | 1900 |
(selector == #ifFalse:) ifTrue:[ |
1901 |
code at:pos1 put:here |
|
1902 |
]. |
|
1903 |
code at:pos2 put:here |
|
140 | 1904 |
] |
434
c48a356d8a34
oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents:
429
diff
changeset
|
1905 |
|
c48a356d8a34
oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents:
429
diff
changeset
|
1906 |
"Modified: 9.11.1996 / 19:52:26 / cg" |
140 | 1907 |
! |
1908 |
||
289 | 1909 |
codeOrOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
1910 |
"generate code for (x or:[y])" |
|
1911 |
||
1912 |
|pos1 rightExpr| |
|
1913 |
||
1464
fa19f86d1ef4
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
1914 |
aCompiler addLiteral:#or:. |
fa19f86d1ef4
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
1915 |
|
289 | 1916 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
1917 |
valueNeeded ifTrue:[ |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1918 |
aStream nextPut:#dup. |
289 | 1919 |
]. |
1920 |
aStream nextPut:#trueJump. |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1921 |
pos1 := aStream position1Based. |
289 | 1922 |
aStream nextPut:0. |
1923 |
valueNeeded ifTrue:[ |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1924 |
aStream nextPut:#drop. |
289 | 1925 |
]. |
1926 |
rightExpr := argArray at:1. |
|
1927 |
rightExpr codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
1928 |
||
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1929 |
(aStream contents) at:pos1 put:(aStream position1Based) |
289 | 1930 |
|
1931 |
"Created: 17.6.1996 / 15:40:22 / cg" |
|
1932 |
"Modified: 17.6.1996 / 15:47:22 / cg" |
|
1933 |
! |
|
1934 |
||
436 | 1935 |
codeQuestOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
627 | 1936 |
"generate code for x ? y. |
1937 |
However, this is only done for non-send args." |
|
436 | 1938 |
|
1939 |
|pos code| |
|
1940 |
||
1464
fa19f86d1ef4
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
1941 |
aCompiler addLiteral:#'?'. |
fa19f86d1ef4
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1463
diff
changeset
|
1942 |
|
436 | 1943 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
1944 |
aStream nextPut:#dup. |
|
1945 |
aStream nextPut:#notNilJump. |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1946 |
pos := aStream position1Based. |
437 | 1947 |
aStream nextPut:0. |
436 | 1948 |
|
1949 |
aStream nextPut:#drop. |
|
1950 |
(argArray at: 1) codeOn:aStream inBlock:b for:aCompiler. |
|
1951 |
||
1952 |
code := aStream contents. |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1953 |
code at:pos put:(aStream position1Based). |
909
4917ac8408fb
oops - inlined ? for-effect left value on top of stack
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
1954 |
|
4917ac8408fb
oops - inlined ? for-effect left value on top of stack
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
1955 |
valueNeeded ifFalse:[ |
4917ac8408fb
oops - inlined ? for-effect left value on top of stack
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
1956 |
aStream nextPut:#drop. |
4917ac8408fb
oops - inlined ? for-effect left value on top of stack
Claus Gittinger <cg@exept.de>
parents:
908
diff
changeset
|
1957 |
]. |
436 | 1958 |
|
627 | 1959 |
"Created: / 10.11.1996 / 18:28:57 / cg" |
1960 |
"Modified: / 28.10.1997 / 18:16:20 / cg" |
|
436 | 1961 |
! |
1962 |
||
602 | 1963 |
codeRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
1425 | 1964 |
"generate code for |
1965 |
[ ... ] repeat |
|
1966 |
and: |
|
1967 |
[ ... ] loop |
|
1968 |
" |
|
602 | 1969 |
|
1970 |
|pos| |
|
1971 |
||
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
1972 |
pos := aStream position1Based. |
602 | 1973 |
receiver codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler. |
1974 |
aStream nextPut:#jump; nextPut:pos. |
|
1975 |
||
1976 |
"Created: 29.8.1997 / 08:14:58 / cg" |
|
1977 |
! |
|
1978 |
||
104 | 1979 |
codeSendOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
0 | 1980 |
"like code on, but assumes that receiver has already been |
1981 |
coded onto stack - needed for cascade" |
|
1982 |
||
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1983 |
|nargs isBuiltIn code litIndex cls clsLitIndex isSuper realReceiver |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1984 |
noSendDrop alreadyDropped| |
1045 | 1985 |
|
1500
3c4cb012b24b
Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents:
1480
diff
changeset
|
1986 |
selector := selector asSymbol. |
1048 | 1987 |
noSendDrop := aCompiler class newCodeSet == true. |
861
ccaa0ba5e7af
generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents:
856
diff
changeset
|
1988 |
|
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1989 |
realReceiver := self realReceiver. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1990 |
isSuper := realReceiver isSuper. |
0 | 1991 |
|
1992 |
argArray isNil ifTrue:[ |
|
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1993 |
nargs := 0 |
0 | 1994 |
] ifFalse:[ |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
1995 |
nargs := argArray size |
0 | 1996 |
]. |
1997 |
||
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1998 |
litIndex := aCompiler addLiteral:selector. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
1999 |
|
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2000 |
isBuiltIn := isSuper not and:[ aCompiler isBuiltInSelector:selector forReceiver:receiver ]. |
0 | 2001 |
|
2002 |
"can we use a send-bytecode ?" |
|
2003 |
isBuiltIn ifTrue:[ |
|
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2004 |
(nargs > 0) ifTrue:[ |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2005 |
(argArray at:1) codeOn:aStream inBlock:b for:aCompiler. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2006 |
(nargs > 1) ifTrue:[ |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2007 |
(argArray at:2) codeOn:aStream inBlock:b for:aCompiler |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2008 |
] |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2009 |
]. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2010 |
aStream nextPut:selector. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2011 |
(aCompiler hasLineNumber:selector) ifTrue:[ |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2012 |
aStream nextPut:lineNr. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2013 |
]. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2014 |
valueNeeded ifFalse:[ |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2015 |
aStream nextPut:#drop |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2016 |
]. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2017 |
^ self |
0 | 2018 |
]. |
2019 |
||
2020 |
argArray notNil ifTrue:[ |
|
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2021 |
argArray do:[:arg | |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2022 |
arg codeOn:aStream inBlock:b for:aCompiler |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2023 |
] |
0 | 2024 |
]. |
2025 |
||
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2026 |
isSuper ifTrue:[ |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2027 |
cls := aCompiler targetClass. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2028 |
realReceiver isHere ifTrue:[ |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2029 |
"/ same code as supersend, but targetClass starts search |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2030 |
] ifFalse:[ |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2031 |
"/ targetClasses superclass starts search |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2032 |
cls := cls superclass. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2033 |
]. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2034 |
clsLitIndex := aCompiler addLiteral:cls. |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2035 |
self emitSuperSendLiteralIndex:litIndex classLiteralIndex:clsLitIndex numArgs:nargs line:lineNr on:aStream. |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2036 |
valueNeeded ifFalse:[ |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2037 |
aStream nextPut:#drop |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2038 |
]. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2039 |
^ self |
0 | 2040 |
]. |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2041 |
|
0 | 2042 |
(nargs == 0) ifTrue:[ |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2043 |
(selector == #yourself) ifTrue:[ |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2044 |
"yourself is often added to get the receiver - |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2045 |
we get it without the yourself-message" |
0 | 2046 |
|
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2047 |
valueNeeded ifFalse:[ |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2048 |
aStream nextPut:#drop |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2049 |
]. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2050 |
^ self |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2051 |
]. |
49 | 2052 |
]. |
0 | 2053 |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2054 |
alreadyDropped := false. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2055 |
valueNeeded ifTrue:[ noSendDrop := true ]. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2056 |
|
117 | 2057 |
litIndex <= 255 ifTrue:[ |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2058 |
(nargs <= 3) ifTrue:[ |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2059 |
noSendDrop ifTrue:[ |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2060 |
code := #(send0 send1 send2 send3) at:(nargs+1). |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2061 |
] ifFalse:[ |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2062 |
code := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3) at:(nargs+1). |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2063 |
alreadyDropped := true. |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2064 |
]. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2065 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex. |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2066 |
valueNeeded ifFalse:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2067 |
alreadyDropped ifFalse:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2068 |
aStream nextPut:#drop |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2069 |
]. |
1045 | 2070 |
]. |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2071 |
^ self |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2072 |
]. |
106 | 2073 |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2074 |
noSendDrop ifTrue:[ |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2075 |
code := #send |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2076 |
] ifFalse:[ |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2077 |
code := #sendDrop. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2078 |
alreadyDropped := true. |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2079 |
]. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2080 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs. |
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2081 |
valueNeeded ifFalse:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2082 |
alreadyDropped ifFalse:[ |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2083 |
aStream nextPut:#drop |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2084 |
]. |
1045 | 2085 |
]. |
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2086 |
^ self |
0 | 2087 |
]. |
49 | 2088 |
|
1809
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2089 |
self emitSendLiteralIndex:litIndex numArgs:nargs line:lineNr on:aStream. |
007cb2a08623
some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents:
1801
diff
changeset
|
2090 |
valueNeeded ifFalse:[ |
1045 | 2091 |
aStream nextPut:#drop |
2092 |
]. |
|
189
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
2093 |
|
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2094 |
"Modified: / 16.7.1998 / 20:26:52 / cg" |
0 | 2095 |
! |
2096 |
||
140 | 2097 |
codeTimesRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
2098 |
"generate code for n timesRepeat:[ ... ]" |
|
2099 |
||
908
294e131f2f6d
oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents:
905
diff
changeset
|
2100 |
|pos1 pos2 lateEval loopCount| |
349
7632e597a3df
no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
2101 |
|
7632e597a3df
no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
2102 |
lateEval := false. |
528
0a35ed44989f
oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents:
437
diff
changeset
|
2103 |
|
908
294e131f2f6d
oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents:
905
diff
changeset
|
2104 |
receiver isConstant ifTrue:[ |
294e131f2f6d
oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents:
905
diff
changeset
|
2105 |
loopCount := receiver evaluate. |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2106 |
(loopCount isMemberOf:SmallInteger) ifFalse:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2107 |
loopCount := nil. |
908
294e131f2f6d
oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents:
905
diff
changeset
|
2108 |
] ifTrue:[ |
294e131f2f6d
oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents:
905
diff
changeset
|
2109 |
loopCount <= 0 ifTrue:[ |
294e131f2f6d
oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents:
905
diff
changeset
|
2110 |
"/ thats it - all we need is the receiver on the stack |
294e131f2f6d
oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents:
905
diff
changeset
|
2111 |
valueNeeded ifTrue:[ |
294e131f2f6d
oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents:
905
diff
changeset
|
2112 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
294e131f2f6d
oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents:
905
diff
changeset
|
2113 |
]. |
294e131f2f6d
oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents:
905
diff
changeset
|
2114 |
^ self |
294e131f2f6d
oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents:
905
diff
changeset
|
2115 |
] |
294e131f2f6d
oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents:
905
diff
changeset
|
2116 |
]. |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2117 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2118 |
|
908
294e131f2f6d
oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents:
905
diff
changeset
|
2119 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
294e131f2f6d
oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents:
905
diff
changeset
|
2120 |
|
349
7632e597a3df
no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
2121 |
valueNeeded ifTrue:[ |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2122 |
"/ easily reconstructable - no need to keep on stack |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2123 |
loopCount notNil ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2124 |
lateEval := true. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2125 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2126 |
lateEval ifFalse:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2127 |
aStream nextPut:#dup |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2128 |
]. |
349
7632e597a3df
no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
2129 |
]. |
96 | 2130 |
|
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2131 |
loopCount isNil ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2132 |
aStream nextPut:#pushgt0; nextPut:lineNr; nextPut:#falseJump. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2133 |
pos2 := aStream position1Based. |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2134 |
aStream nextPut:0. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2135 |
]. |
140 | 2136 |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2137 |
pos1 := aStream position1Based. |
140 | 2138 |
(argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler. |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2139 |
aStream nextPut:#minus1; nextPut:lineNr. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2140 |
aStream nextPut:#pushgt0; nextPut:lineNr. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2141 |
aStream nextPut:#trueJump; nextPut:pos1. |
140 | 2142 |
|
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2143 |
pos2 notNil ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2144 |
(aStream contents) at:pos2 put:(aStream position1Based). |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2145 |
]. |
528
0a35ed44989f
oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents:
437
diff
changeset
|
2146 |
aStream nextPut:#drop. "/ drop run variable |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2147 |
|
349
7632e597a3df
no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
2148 |
lateEval ifTrue:[ |
908
294e131f2f6d
oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents:
905
diff
changeset
|
2149 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
349
7632e597a3df
no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
2150 |
] |
7632e597a3df
no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
2151 |
|
528
0a35ed44989f
oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents:
437
diff
changeset
|
2152 |
"Modified: 27.5.1997 / 14:28:49 / cg" |
140 | 2153 |
! |
2154 |
||
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2155 |
codeToByDoOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2156 |
"generate code for a to:b by:c do:[:arg | ... ]" |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2157 |
|
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2158 |
|pos pos2 start stop step lateEval theBlock loopVarIndex |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2159 |
stepVal stopVarIndex| |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2160 |
|
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2161 |
"/ NOTICE: could compile it as a timesRepeat-like loop, if |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2162 |
"/ the loop-counter is not accessed within the loop-block. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2163 |
"/ This generates somewhat (15%) faster code, but makes |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2164 |
"/ debugging somewhat difficult (no loop-value seen in debugger). |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2165 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2166 |
start := receiver. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2167 |
stop := (argArray at:1). |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2168 |
step := (argArray at:2). |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2169 |
|
1397 | 2170 |
"/ stop isConstant ifFalse:[self error:'should not happen' mayProceed:true]. |
2171 |
"/ (stop evaluate isMemberOf:SmallInteger) ifFalse:[self error:'should not happen' mayProceed:true]. |
|
2172 |
||
2173 |
step isConstant ifFalse:[self error:'should not happen' mayProceed:true]. |
|
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2174 |
stepVal := step evaluate. |
1397 | 2175 |
(stepVal isMemberOf:SmallInteger) ifFalse:[ |
2176 |
self error:'should not happen' mayProceed:true |
|
2177 |
]. |
|
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2178 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2179 |
start codeOn:aStream inBlock:b for:aCompiler. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2180 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2181 |
lateEval := false. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2182 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2183 |
valueNeeded ifTrue:[ |
1281
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2184 |
"/ easily reconstructable - no need to keep on stack |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2185 |
start isConstant ifTrue:[ |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2186 |
(start evaluate isMemberOf:SmallInteger) ifTrue:[ |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2187 |
lateEval := true. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2188 |
] |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2189 |
]. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2190 |
lateEval ifFalse:[ |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2191 |
aStream nextPut:#dup |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2192 |
]. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2193 |
]. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2194 |
|
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2195 |
"/ if stop is not constant, and not an argVar, |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2196 |
"/ evaluate it into a temp slot ... |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2197 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2198 |
(stop isConstant and:[stop type == #Integer]) ifFalse:[ |
1281
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2199 |
"/ a method/blockArg is constant as well ... |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2200 |
(stop isVariable and:[stop isArgument]) ifFalse:[ |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2201 |
stop codeOn:aStream inBlock:b for:aCompiler. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2202 |
|
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2203 |
b isNil ifTrue:[ |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2204 |
stopVarIndex := aCompiler addTempVar. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2205 |
aStream nextPut:#storeMethodVar; nextPut:stopVarIndex. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2206 |
] ifFalse:[ |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2207 |
stopVarIndex := b addTempVar. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2208 |
aStream nextPut:#storeBlockVar; nextPut:stopVarIndex. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2209 |
]. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2210 |
] |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2211 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2212 |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2213 |
pos := aStream position1Based. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2214 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2215 |
aStream nextPut:#dup. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2216 |
stopVarIndex notNil ifTrue:[ |
1281
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2217 |
b isNil ifTrue:[ |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2218 |
aStream nextPut:#pushMethodVar; nextPut:stopVarIndex. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2219 |
] ifFalse:[ |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2220 |
aStream nextPut:#pushBlockVar; nextPut:stopVarIndex. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2221 |
] |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2222 |
] ifFalse:[ |
1281
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2223 |
stop codeOn:aStream inBlock:b for:aCompiler. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2224 |
]. |
1281
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2225 |
stepVal >= 0 ifTrue:[ |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2226 |
aStream nextPut:#>. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2227 |
] ifFalse:[ |
1281
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2228 |
aStream nextPut:#<. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2229 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2230 |
(aCompiler hasLineNumber:selector) ifTrue:[ |
1281
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2231 |
aStream nextPut:lineNr. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2232 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2233 |
aStream nextPut:#trueJump. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2234 |
pos2 := aStream position1Based. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2235 |
aStream nextPut:0. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2236 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2237 |
theBlock := argArray at:3. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2238 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2239 |
"/ need a temporary in the outer context for |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2240 |
"/ the loop ... |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2241 |
b isNil ifTrue:[ |
1281
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2242 |
loopVarIndex := aCompiler addTempVar. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2243 |
aStream nextPut:#dup. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2244 |
aStream nextPut:#storeMethodVar; nextPut:loopVarIndex. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2245 |
] ifFalse:[ |
1281
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2246 |
loopVarIndex := b addTempVar. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2247 |
aStream nextPut:#dup. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2248 |
aStream nextPut:#storeBlockVar; nextPut:loopVarIndex. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2249 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2250 |
theBlock indexOfFirstTemp:loopVarIndex. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2251 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2252 |
theBlock codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2253 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2254 |
"/ increment/decrement counter & jump back. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2255 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2256 |
stepVal == 1 ifTrue:[ |
1281
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2257 |
aStream nextPut:#plus1; nextPut:lineNr. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2258 |
] ifFalse:[ |
1281
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2259 |
stepVal == -1 ifTrue:[ |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2260 |
aStream nextPut:#minus1; nextPut:lineNr. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2261 |
] ifFalse:[ |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2262 |
step codeOn:aStream inBlock:b for:aCompiler. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2263 |
aStream nextPut:#+. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2264 |
(aCompiler hasLineNumber:#+) ifTrue:[ |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2265 |
aStream nextPut:lineNr. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2266 |
]. |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2267 |
] |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2268 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2269 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2270 |
aStream nextPut:#jump; nextPut:pos. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2271 |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2272 |
(aStream contents) at:pos2 put:(aStream position1Based). |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2273 |
aStream nextPut:#drop. "/ drop run variable |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2274 |
lateEval ifTrue:[ |
1281
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2275 |
start codeOn:aStream inBlock:b for:aCompiler. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2276 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2277 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2278 |
"/ no need to nil-out loop-tempVar to help GC |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2279 |
"/ (its integer, anyway). |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2280 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2281 |
b isNil ifTrue:[ |
1281
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2282 |
aCompiler removeTempVar |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2283 |
] ifFalse:[ |
1281
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2284 |
b removeTempVar |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2285 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2286 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2287 |
stopVarIndex notNil ifTrue:[ |
1281
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2288 |
b isNil ifTrue:[ |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2289 |
aCompiler removeTempVar |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2290 |
] ifFalse:[ |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2291 |
b removeTempVar |
e70c494950b2
ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
2292 |
] |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2293 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2294 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2295 |
"Created: 27.6.1997 / 12:48:18 / cg" |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2296 |
"Modified: 27.6.1997 / 13:43:06 / cg" |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2297 |
! |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2298 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2299 |
codeToDoOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2300 |
"generate code for n to:n do:[:unusedArg | ... ]" |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2301 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2302 |
|pos pos2 start stop lateEval theBlock loopVarIndex |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2303 |
stopVarIndex| |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2304 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2305 |
"/ NOTICE: could compile it as a timesRepeat, if |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2306 |
"/ the loop-counter is not accessed within the loop-block. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2307 |
"/ This generates somewhat (15%) faster code, but makes |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2308 |
"/ debugging somewhat difficult (no loop-value seen in debugger). |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2309 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2310 |
start := receiver. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2311 |
stop := (argArray at:1). |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2312 |
"/ stop isConstant ifFalse:[self halt:'should not happen']. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2313 |
"/ (stop evaluate isMemberOf:SmallInteger) ifFalse:[self halt:'should not happen']. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2314 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2315 |
start codeOn:aStream inBlock:b for:aCompiler. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2316 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2317 |
lateEval := false. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2318 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2319 |
valueNeeded ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2320 |
"/ easily reconstructable - no need to keep on stack |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2321 |
start isConstant ifTrue:[ |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2322 |
(start evaluate isMemberOf:SmallInteger) ifTrue:[ |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2323 |
lateEval := true. |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2324 |
] |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2325 |
]. |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2326 |
lateEval ifFalse:[ |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2327 |
aStream nextPut:#dup |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2328 |
]. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2329 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2330 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2331 |
"/ if stop is not constant, and not an argVar, |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2332 |
"/ evaluate it into a temp slot ... |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2333 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2334 |
(stop isConstant and:[stop type == #Integer]) ifFalse:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2335 |
"/ a method/blockArg is constant as well ... |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2336 |
(stop isVariable and:[stop isArgument]) ifFalse:[ |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2337 |
stop codeOn:aStream inBlock:b for:aCompiler. |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2338 |
|
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2339 |
b isNil ifTrue:[ |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2340 |
stopVarIndex := aCompiler addTempVar. |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2341 |
aStream nextPut:#storeMethodVar; nextPut:stopVarIndex. |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2342 |
] ifFalse:[ |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2343 |
stopVarIndex := b addTempVar. |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2344 |
aStream nextPut:#storeBlockVar; nextPut:stopVarIndex. |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2345 |
]. |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2346 |
] |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2347 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2348 |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2349 |
pos := aStream position1Based. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2350 |
|
624 | 2351 |
aStream nextPut:#lineno; nextPut:lineNr. |
2352 |
||
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2353 |
aStream nextPut:#dup. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2354 |
stopVarIndex notNil ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2355 |
b isNil ifTrue:[ |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2356 |
aStream nextPut:#pushMethodVar; nextPut:stopVarIndex. |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2357 |
] ifFalse:[ |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2358 |
aStream nextPut:#pushBlockVar; nextPut:stopVarIndex. |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2359 |
] |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2360 |
] ifFalse:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2361 |
stop codeOn:aStream inBlock:b for:aCompiler. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2362 |
]. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2363 |
aStream nextPut:#>. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2364 |
(aCompiler hasLineNumber:selector) ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2365 |
aStream nextPut:lineNr. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2366 |
]. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2367 |
aStream nextPut:#trueJump. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2368 |
pos2 := aStream position1Based. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2369 |
aStream nextPut:0. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2370 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2371 |
theBlock := argArray at:2. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2372 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2373 |
"/ need a temporary in the outer context for |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2374 |
"/ the loop ... |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2375 |
b isNil ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2376 |
loopVarIndex := aCompiler addTempVar. |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2377 |
aStream nextPut:#dup. |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2378 |
aStream nextPut:#storeMethodVar; nextPut:loopVarIndex. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2379 |
] ifFalse:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2380 |
loopVarIndex := b addTempVar. |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2381 |
aStream nextPut:#dup. |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2382 |
aStream nextPut:#storeBlockVar; nextPut:loopVarIndex. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2383 |
]. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2384 |
theBlock indexOfFirstTemp:loopVarIndex. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2385 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2386 |
theBlock codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2387 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2388 |
"/ increment counter & jump back. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2389 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2390 |
aStream nextPut:#plus1; nextPut:lineNr; nextPut:#jump; nextPut:pos. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2391 |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2392 |
(aStream contents) at:pos2 put:(aStream position1Based). |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2393 |
aStream nextPut:#drop. "/ drop run variable |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2394 |
lateEval ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2395 |
start codeOn:aStream inBlock:b for:aCompiler. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2396 |
]. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2397 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2398 |
"/ no need to nil-out loop-tempVar to help GC |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2399 |
"/ (its integer, anyway). |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2400 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2401 |
b isNil ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2402 |
aCompiler removeTempVar |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2403 |
] ifFalse:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2404 |
b removeTempVar |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2405 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2406 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2407 |
stopVarIndex notNil ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2408 |
b isNil ifTrue:[ |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2409 |
aCompiler removeTempVar |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2410 |
] ifFalse:[ |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2411 |
b removeTempVar |
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2412 |
] |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
2413 |
]. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2414 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2415 |
"Created: 26.6.1997 / 10:58:47 / cg" |
624 | 2416 |
"Modified: 19.10.1997 / 01:31:40 / cg" |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2417 |
! |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
2418 |
|
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
2419 |
codeValueSendOn:aStream for:aCompiler |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
2420 |
"/ send #value to the top of the stack ... |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
2421 |
aStream nextPut:#value. |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
2422 |
(aCompiler hasLineNumber:#value) ifTrue:[ |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
2423 |
aStream nextPut:lineNr. |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
2424 |
] |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
2425 |
! |
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
2426 |
|
140 | 2427 |
codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
200
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
2428 |
"generate code for |
817 | 2429 |
[...] whileXXX:[ ... ] |
200
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
2430 |
and also |
817 | 2431 |
[...] whileXXX |
200
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
2432 |
" |
140 | 2433 |
|
200
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
2434 |
|pos pos2 theReceiver theArg theByteCode optByteCode needLineNr blockExpr |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2435 |
hasLoopBlock fastReceiver condStats constCondition| |
0 | 2436 |
|
200
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
2437 |
hasLoopBlock := true. |
140 | 2438 |
(selector == #whileTrue:) ifTrue:[ |
817 | 2439 |
theByteCode := #falseJump. |
0 | 2440 |
] ifFalse:[ |
817 | 2441 |
(selector == #whileFalse:) ifTrue:[ |
2442 |
theByteCode := #trueJump |
|
2443 |
] ifFalse:[ |
|
2444 |
hasLoopBlock := false. |
|
2445 |
(selector == #whileTrue) ifTrue:[ |
|
2446 |
theByteCode := #trueJump |
|
2447 |
] ifFalse:[ |
|
2448 |
theByteCode := #falseJump |
|
2449 |
]. |
|
2450 |
] |
|
140 | 2451 |
]. |
2452 |
||
2453 |
theReceiver := receiver. |
|
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2454 |
|
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2455 |
(receiver isBlock |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2456 |
and:[(condStats := receiver statements) notNil |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2457 |
and:[condStats nextStatement isNil |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2458 |
and:[condStats expression notNil]]]) |
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2459 |
ifTrue:[ |
817 | 2460 |
fastReceiver := receiver statements expression. |
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2461 |
optByteCode := self optimizedConditionFor:fastReceiver with:theByteCode for:aCompiler. |
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2462 |
] ifFalse:[ |
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2463 |
optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler. |
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2464 |
]. |
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2465 |
|
140 | 2466 |
optByteCode notNil ifTrue:[ |
817 | 2467 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
2468 |
theArg := receiver statements expression arg1 |
|
2469 |
]. |
|
2470 |
theReceiver := receiver statements expression receiver. |
|
2471 |
theByteCode := optByteCode |
|
140 | 2472 |
]. |
2473 |
||
2474 |
"/ OLD: |
|
2475 |
"/ valueNeeded ifTrue:[aStream nextPut:#pushNil]. |
|
2476 |
"/ |
|
167 | 2477 |
needLineNr := true. |
2478 |
||
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2479 |
pos := aStream position1Based. |
386 | 2480 |
|
389
8aa5f9f08139
care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
2481 |
"/ aCompiler lineNumberInfo == #full ifTrue:[ |
817 | 2482 |
self codeLineNumber:lineNr on:aStream for:aCompiler. |
2483 |
needLineNr := false. |
|
389
8aa5f9f08139
care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
2484 |
"/ ]. |
386 | 2485 |
|
140 | 2486 |
optByteCode notNil ifTrue:[ |
817 | 2487 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
2488 |
theArg notNil ifTrue:[ |
|
2489 |
theArg codeOn:aStream inBlock:b for:aCompiler |
|
2490 |
] |
|
140 | 2491 |
] ifFalse:[ |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2492 |
(fastReceiver notNil |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2493 |
and:[fastReceiver isConstant]) ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2494 |
constCondition := fastReceiver evaluate. |
817 | 2495 |
theByteCode == #trueJump ifTrue:[ |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2496 |
constCondition == true ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2497 |
theByteCode := #jump |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2498 |
] ifFalse:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2499 |
constCondition == false ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2500 |
theByteCode := #never |
817 | 2501 |
] |
2502 |
] |
|
2503 |
] ifFalse:[ |
|
2504 |
theByteCode == #falseJump ifTrue:[ |
|
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2505 |
constCondition == false ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2506 |
theByteCode := #jump |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2507 |
] ifFalse:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2508 |
constCondition == true ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2509 |
theByteCode := #never |
817 | 2510 |
] |
2511 |
] |
|
2512 |
] |
|
2513 |
] |
|
2514 |
]. |
|
167 | 2515 |
|
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2516 |
(theByteCode ~~ #jump and:[theByteCode ~~ #never]) ifTrue:[ |
817 | 2517 |
theReceiver codeInlineOn:aStream inBlock:b for:aCompiler. |
2518 |
]. |
|
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2519 |
|
817 | 2520 |
"/ |
2521 |
"/ cannot enable code below |
|
2522 |
"/ (tiny loops would not be debuggable with next, since lineNo remains the same) |
|
2523 |
"/ think about it ... |
|
2524 |
"/ |
|
2525 |
blockExpr := theReceiver simpleSendBlockExpression. |
|
2526 |
blockExpr notNil ifTrue:[ |
|
2527 |
blockExpr isMessage ifTrue:[ |
|
2528 |
(aCompiler hasLineNumber:(blockExpr selector)) ifTrue:[ |
|
2529 |
blockExpr lineNumber == lineNr ifTrue:[ |
|
2530 |
needLineNr := false |
|
2531 |
] |
|
2532 |
] |
|
2533 |
] |
|
2534 |
]. |
|
140 | 2535 |
]. |
2536 |
||
167 | 2537 |
needLineNr ifTrue:[ |
817 | 2538 |
ParseNode codeLineNumber:lineNr on:aStream for:aCompiler. |
0 | 2539 |
]. |
2540 |
||
200
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
2541 |
hasLoopBlock ifFalse:[ |
817 | 2542 |
"/ simple [...] whileXXX |
2543 |
theByteCode ~~ #never ifTrue:[ |
|
2544 |
aStream nextPut:theByteCode; nextPut:pos. |
|
2545 |
]. |
|
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2546 |
|
817 | 2547 |
valueNeeded ifTrue:[aStream nextPut:#pushNil]. |
2548 |
^ self |
|
200
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
2549 |
]. |
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
2550 |
|
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
2551 |
"/ [...] whileXXX:[...] |
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
2552 |
|
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2553 |
theByteCode ~~ #never ifTrue:[ |
817 | 2554 |
aStream nextPut:theByteCode. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2555 |
pos2 := aStream position1Based. |
817 | 2556 |
aStream nextPut:0. |
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2557 |
]. |
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2558 |
|
140 | 2559 |
(argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler. |
2560 |
aStream nextPut:#jump; nextPut:pos. |
|
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2561 |
theByteCode ~~ #never ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2562 |
(aStream contents) at:pos2 put:(aStream position1Based). |
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2563 |
]. |
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2564 |
|
140 | 2565 |
valueNeeded ifTrue:[aStream nextPut:#pushNil]. |
167 | 2566 |
|
389
8aa5f9f08139
care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
2567 |
"Modified: 22.10.1996 / 21:34:37 / cg" |
140 | 2568 |
! |
2569 |
||
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2570 |
new_codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2571 |
"generate code for |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2572 |
[...] whileXXX:[ ... ] |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2573 |
and also |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2574 |
[...] whileXXX |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2575 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2576 |
This generates the check at the end and should generate better |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2577 |
code (only 1 conditional-branch at the end instead of 2 branches). |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2578 |
However, for now, it is disabled, since the JIT has special provisions |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2579 |
to detect loops and actually generates better machine code for the |
910 | 2580 |
old bytecode sequence ... (sigh) |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2581 |
" |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2582 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2583 |
|pos pos0 theReceiver theArg theByteCode optByteCode needLineNr blockExpr |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2584 |
hasLoopBlock fastReceiver condStats constCondition| |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2585 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2586 |
hasLoopBlock := true. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2587 |
(selector == #whileTrue:) ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2588 |
theByteCode := #trueJump. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2589 |
] ifFalse:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2590 |
(selector == #whileFalse:) ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2591 |
theByteCode := #falseJump |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2592 |
] ifFalse:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2593 |
hasLoopBlock := false. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2594 |
(selector == #whileTrue) ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2595 |
theByteCode := #trueJump |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2596 |
] ifFalse:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2597 |
theByteCode := #falseJump |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2598 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2599 |
] |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2600 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2601 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2602 |
theReceiver := receiver. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2603 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2604 |
(receiver isBlock |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2605 |
and:[(condStats := receiver statements) notNil |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2606 |
and:[condStats nextStatement isNil |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2607 |
and:[(fastReceiver := condStats expression) notNil]]]) |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2608 |
ifTrue:[ |
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2609 |
optByteCode := self optimizedConditionFor:fastReceiver with:theByteCode for:aCompiler. |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2610 |
] ifFalse:[ |
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2611 |
optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler. |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2612 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2613 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2614 |
optByteCode notNil ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2615 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2616 |
theArg := receiver statements expression arg1 |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2617 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2618 |
theReceiver := receiver statements expression receiver. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2619 |
theByteCode := optByteCode |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2620 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2621 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2622 |
needLineNr := true. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2623 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2624 |
hasLoopBlock ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2625 |
(argArray at:1) isEmptyBlock ifFalse:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2626 |
aStream nextPut:#jump. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2627 |
pos0 := aStream position1Based. |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2628 |
aStream nextPut:0. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2629 |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2630 |
pos := aStream position1Based. |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2631 |
(argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2632 |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2633 |
(aStream contents) at:pos0 put:(aStream position1Based). |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2634 |
] |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2635 |
] ifFalse:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
2636 |
pos := aStream position1Based. |
856
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2637 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2638 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2639 |
optByteCode isNil ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2640 |
blockExpr := theReceiver simpleSendBlockExpression. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2641 |
blockExpr notNil ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2642 |
blockExpr isMessage ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2643 |
(aCompiler hasLineNumber:(blockExpr selector)) ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2644 |
blockExpr lineNumber == lineNr ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2645 |
needLineNr := false |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2646 |
] |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2647 |
] |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2648 |
] |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2649 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2650 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2651 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2652 |
needLineNr ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2653 |
self codeLineNumber:lineNr on:aStream for:aCompiler. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2654 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2655 |
needLineNr := false. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2656 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2657 |
optByteCode notNil ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2658 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2659 |
theArg notNil ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2660 |
theArg codeOn:aStream inBlock:b for:aCompiler |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2661 |
] |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2662 |
] ifFalse:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2663 |
(fastReceiver notNil |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2664 |
and:[fastReceiver isConstant]) ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2665 |
constCondition := fastReceiver evaluate. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2666 |
theByteCode == #trueJump ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2667 |
constCondition == true ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2668 |
theByteCode := #jump |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2669 |
] ifFalse:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2670 |
constCondition == false ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2671 |
theByteCode := #never |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2672 |
] |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2673 |
] |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2674 |
] ifFalse:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2675 |
theByteCode == #falseJump ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2676 |
constCondition == false ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2677 |
theByteCode := #jump |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2678 |
] ifFalse:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2679 |
constCondition == true ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2680 |
theByteCode := #never |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2681 |
] |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2682 |
] |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2683 |
] |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2684 |
] |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2685 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2686 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2687 |
(theByteCode ~~ #jump and:[theByteCode ~~ #never]) ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2688 |
theReceiver codeInlineOn:aStream inBlock:b for:aCompiler. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2689 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2690 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2691 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2692 |
hasLoopBlock ifFalse:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2693 |
"/ simple [...] whileXXX |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2694 |
theByteCode ~~ #never ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2695 |
aStream nextPut:theByteCode; nextPut:pos. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2696 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2697 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2698 |
valueNeeded ifTrue:[aStream nextPut:#pushNil]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2699 |
^ self |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2700 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2701 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2702 |
"/ [...] whileXXX:[...] |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2703 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2704 |
theByteCode ~~ #never ifTrue:[ |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2705 |
aStream nextPut:theByteCode. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2706 |
aStream nextPut:pos. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2707 |
]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2708 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2709 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2710 |
valueNeeded ifTrue:[aStream nextPut:#pushNil]. |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2711 |
|
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2712 |
"Modified: 22.10.1996 / 21:34:37 / cg" |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2713 |
! |
bcc52caf1192
timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents:
851
diff
changeset
|
2714 |
|
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2715 |
optimizedConditionFor:aReceiver with:aByteCode for:aCompiler |
186 | 2716 |
|rec sel stats| |
0 | 2717 |
|
140 | 2718 |
rec := aReceiver. |
2719 |
(rec isBlock) ifTrue:[ |
|
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2720 |
(stats := rec statements) notNil ifTrue:[ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2721 |
stats nextStatement isNil ifTrue:[ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2722 |
rec := rec statements expression |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2723 |
] |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2724 |
] |
140 | 2725 |
]. |
2726 |
(rec isUnaryMessage) ifTrue:[ |
|
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2727 |
sel := rec selector. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2728 |
(sel == #isNil) ifTrue:[ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2729 |
"/ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2730 |
"/ isNil trueJmp -> nilJump |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2731 |
"/ isNil falseJmp -> notNilJump |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2732 |
"/ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2733 |
aCompiler addLiteral:#isNil. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2734 |
(aByteCode == #trueJump) ifTrue:[^ #nilJump]. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2735 |
(aByteCode == #falseJump) ifTrue:[^ #notNilJump] |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2736 |
]. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2737 |
(sel == #notNil) ifTrue:[ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2738 |
"/ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2739 |
"/ notNil trueJmp -> notNilJump |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2740 |
"/ notNil falseJmp -> nilJump |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2741 |
"/ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2742 |
aCompiler addLiteral:#notNil. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2743 |
(aByteCode == #trueJump) ifTrue:[^ #notNilJump]. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2744 |
(aByteCode == #falseJump) ifTrue:[^ #nilJump] |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2745 |
]. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2746 |
(sel == #not) ifTrue:[ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2747 |
"/ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2748 |
"/ not trueJmp -> falseJump |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2749 |
"/ not falseJmp -> trueJump |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2750 |
"/ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2751 |
aCompiler addLiteral:#not. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2752 |
(aByteCode == #trueJump) ifTrue:[^ #falseJump]. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2753 |
(aByteCode == #falseJump) ifTrue:[^ #trueJump] |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2754 |
]. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2755 |
^ nil |
0 | 2756 |
]. |
140 | 2757 |
(rec isBinaryMessage) ifTrue:[ |
1463
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2758 |
sel := rec selector. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2759 |
rec arg1 isConstant ifTrue:[ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2760 |
(rec arg1 value == 0) ifTrue:[ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2761 |
"/ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2762 |
"/ ==0 trueJmp -> zeroJump |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2763 |
"/ ==0 falseJmp -> notZeroJump |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2764 |
"/ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2765 |
(sel == #==) ifTrue:[ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2766 |
aCompiler addLiteral:#==. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2767 |
(aByteCode == #trueJump) ifTrue:[^ #zeroJump]. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2768 |
(aByteCode == #falseJump) ifTrue:[^ #notZeroJump] |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2769 |
]. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2770 |
"/ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2771 |
"/ ~~0 trueJmp -> notZeroJump |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2772 |
"/ ~~0 falseJmp -> zeroJump |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2773 |
"/ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2774 |
(sel == #~~) ifTrue:[ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2775 |
aCompiler addLiteral:#~~. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2776 |
(aByteCode == #falseJump) ifTrue:[^ #zeroJump]. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2777 |
(aByteCode == #trueJump) ifTrue:[^ #notZeroJump] |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2778 |
]. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2779 |
^ nil |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2780 |
] |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2781 |
]. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2782 |
(sel == #==) ifTrue:[ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2783 |
"/ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2784 |
"/ == trueJmp -> eqJump |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2785 |
"/ == falseJmp -> notEqJump |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2786 |
"/ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2787 |
aCompiler addLiteral:#==. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2788 |
(aByteCode == #trueJump) ifTrue:[^ #eqJump]. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2789 |
(aByteCode == #falseJump) ifTrue:[^ #notEqJump] |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2790 |
]. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2791 |
(sel == #~~) ifTrue:[ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2792 |
"/ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2793 |
"/ ~~ trueJmp -> notEqJump |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2794 |
"/ ~~ falseJmp -> eqJump |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2795 |
"/ |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2796 |
aCompiler addLiteral:#~~. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2797 |
(aByteCode == #falseJump) ifTrue:[^ #eqJump]. |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2798 |
(aByteCode == #trueJump) ifTrue:[^ #notEqJump] |
14c0b5d19e13
make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents:
1435
diff
changeset
|
2799 |
] |
140 | 2800 |
]. |
2801 |
^ nil |
|
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2802 |
! |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2803 |
|
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2804 |
tryFoldedIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2805 |
|rVal branch| |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2806 |
|
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2807 |
receiver isConstant ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2808 |
rVal := receiver evaluate. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2809 |
rVal == true ifTrue:[ |
1248
ba526cbb348a
fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
2810 |
(selector == #ifFalse:) ifTrue:[ |
1422
cdee45eb0303
oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
2811 |
valueNeeded ifTrue:[ |
cdee45eb0303
oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
2812 |
"/ true ifFalse:[] - evaluates to nil. |
cdee45eb0303
oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
2813 |
aStream nextPut:#pushNil |
cdee45eb0303
oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
2814 |
]. |
1248
ba526cbb348a
fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
2815 |
^ true. |
ba526cbb348a
fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
2816 |
]. |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2817 |
((selector == #ifTrue:) or:[selector == #ifTrue:ifFalse:]) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2818 |
branch := (argArray at: 1). |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2819 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2820 |
(selector == #ifFalse:ifTrue:) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2821 |
branch := (argArray at: 2). |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2822 |
]. |
1248
ba526cbb348a
fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
2823 |
]. |
ba526cbb348a
fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
2824 |
rVal == false ifTrue:[ |
ba526cbb348a
fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
2825 |
(selector == #ifTrue:) ifTrue:[ |
1422
cdee45eb0303
oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
2826 |
valueNeeded ifTrue:[ |
cdee45eb0303
oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
2827 |
"/ false ifTrue:[] - evaluates to nil. |
cdee45eb0303
oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
2828 |
aStream nextPut:#pushNil |
cdee45eb0303
oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
2829 |
]. |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2830 |
^ true. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2831 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2832 |
((selector == #ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2833 |
branch := (argArray at: 1). |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2834 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2835 |
(selector == #ifTrue:ifFalse:) ifTrue:[ |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2836 |
branch := (argArray at: 2). |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2837 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2838 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2839 |
branch notNil ifTrue:[ |
1435
be9680c6145c
factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
2840 |
self codeBlockEvaluation:branch on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
992
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2841 |
^ true. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2842 |
] |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2843 |
]. |
7e8ef3583a43
do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents:
910
diff
changeset
|
2844 |
^ false |
140 | 2845 |
! ! |
2846 |
||
1080 | 2847 |
!MessageNode methodsFor:'printing & storing'! |
140 | 2848 |
|
1588 | 2849 |
printOn:aStream indent:i |
2850 |
|selectorParts| |
|
2851 |
||
2852 |
(#( whileTrue: whileFalse: ) includes:selector) ifTrue:[ |
|
888 | 2853 |
receiver isBlock ifTrue:[ |
2854 |
^ self printWhileOn:aStream indent:i |
|
2855 |
]. |
|
140 | 2856 |
]. |
1588 | 2857 |
selectorParts := selector asCollectionOfSubstringsSeparatedBy:$:. |
2858 |
receiver printOn:aStream indent:i parenthized:(receiver precedence <= self precedence). |
|
1791 | 2859 |
argArray notNil ifTrue:[ |
2860 |
argArray with:selectorParts |
|
2861 |
do:[:arg :selPart | |
|
2862 |
aStream |
|
2863 |
cr; |
|
2864 |
spaces:i + 4; |
|
2865 |
nextPutAll:(selPart , ':'). |
|
2866 |
arg printOn:aStream indent:i + 4 parenthized:(arg precedence <= self precedence). |
|
2867 |
] |
|
2868 |
]. |
|
2869 |
||
2870 |
"Modified: / 06-08-2006 / 12:38:44 / cg" |
|
140 | 2871 |
! |
2872 |
||
2873 |
printWhileOn:aStream indent:i |
|
2874 |
"special handling of whileTrue/whileFalse" |
|
2875 |
||
1588 | 2876 |
|arg| |
2877 |
||
140 | 2878 |
aStream nextPutAll:'['. |
2879 |
receiver statements printOn:aStream indent:i. |
|
1588 | 2880 |
aStream nextPutAll:'] ',selector,' '. |
140 | 2881 |
|
2882 |
arg := argArray at:1. |
|
1588 | 2883 |
arg printOn:aStream indent:i parenthized:(arg precedence <= self precedence). |
140 | 2884 |
! ! |
106 | 2885 |
|
140 | 2886 |
!MessageNode methodsFor:'queries'! |
2887 |
||
1565
9388e72e2dff
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1533
diff
changeset
|
2888 |
argumentCount |
9388e72e2dff
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1533
diff
changeset
|
2889 |
"VisualAge/ANSI compatibility - same as numArgs" |
9388e72e2dff
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1533
diff
changeset
|
2890 |
|
9388e72e2dff
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1533
diff
changeset
|
2891 |
^ argArray size |
9388e72e2dff
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1533
diff
changeset
|
2892 |
! |
9388e72e2dff
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1533
diff
changeset
|
2893 |
|
395 | 2894 |
collectBlocksInto:aCollection |
2895 |
receiver collectBlocksInto:aCollection. |
|
2896 |
argArray size > 0 ifTrue:[ |
|
1727 | 2897 |
argArray do:[:arg | |
2898 |
arg collectBlocksInto:aCollection. |
|
2899 |
] |
|
395 | 2900 |
]. |
2901 |
||
2902 |
"Created: 23.10.1996 / 15:44:49 / cg" |
|
2903 |
"Modified: 23.10.1996 / 16:03:46 / cg" |
|
2904 |
! |
|
2905 |
||
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2906 |
isCascade |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2907 |
^ false |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2908 |
|
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2909 |
"Created: / 16.7.1998 / 20:03:42 / cg" |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2910 |
! |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2911 |
|
140 | 2912 |
isMessage |
2913 |
^ true |
|
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2914 |
! |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2915 |
|
1384 | 2916 |
numArgs |
2917 |
^ argArray size |
|
2918 |
! |
|
2919 |
||
1588 | 2920 |
precedence |
2921 |
^ 10 |
|
2922 |
||
2923 |
"Created: / 20-04-2005 / 14:10:59 / cg" |
|
2924 |
! |
|
2925 |
||
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2926 |
realReceiver |
746 | 2927 |
receiver isCascade ifTrue:[ |
2928 |
^ receiver realReceiver |
|
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2929 |
]. |
746 | 2930 |
self isCascade ifTrue:[ |
2931 |
^ receiver receiver |
|
744
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2932 |
]. |
e871f9f072f8
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
715
diff
changeset
|
2933 |
|
746 | 2934 |
^ receiver |
2935 |
||
2936 |
"Modified: / 17.7.1998 / 02:09:05 / cg" |
|
2268 | 2937 |
! |
2938 |
||
2939 |
withConstantValueDo:aBlock |
|
2940 |
"return true, if this evaluates to a constant value |
|
2941 |
and evaluate aBlock with it" |
|
2942 |
||
2943 |
|recVal argValues allArgsConstant| |
|
2944 |
||
2945 |
(receiver withConstantValueDo:[:val | recVal := val]) ifTrue:[ |
|
2946 |
argValues := Array new:argArray size. |
|
2947 |
allArgsConstant := true. |
|
2270 | 2948 |
argArray notNil ifTrue:[ |
2949 |
argArray doWithIndex:[:arg :index | |
|
2950 |
allArgsConstant := allArgsConstant |
|
2268 | 2951 |
and:[ arg withConstantValueDo:[:val | argValues at:index put:val] ] |
2270 | 2952 |
]. |
2268 | 2953 |
]. |
2954 |
allArgsConstant ifTrue:[ |
|
2955 |
"/ only a few messages are checked: |
|
2956 |
recVal isNumber ifTrue:[ |
|
2957 |
(#(positive negative abs negated + - * == = ~= ~~) includes:selector) ifFalse:[ |
|
2958 |
^ false |
|
2959 |
]. |
|
2960 |
]. |
|
2961 |
recVal isBoolean ifTrue:[ |
|
2962 |
(#(not && || ) includes:selector) ifFalse:[ |
|
2963 |
^ false |
|
2964 |
]. |
|
2965 |
]. |
|
2966 |
aBlock value:(recVal perform:selector withArguments:argValues). |
|
2967 |
^ true |
|
2968 |
]. |
|
2969 |
]. |
|
2970 |
^ false |
|
0 | 2971 |
! ! |
140 | 2972 |
|
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2973 |
!MessageNode class methodsFor:'documentation'! |
148 | 2974 |
|
2975 |
version |
|
2270 | 2976 |
^ '$Header: /cvs/stx/stx/libcomp/MessageNode.st,v 1.167 2009-11-06 19:29:24 cg Exp $' |
2268 | 2977 |
! |
2978 |
||
2979 |
version_CVS |
|
2270 | 2980 |
^ '$Header: /cvs/stx/stx/libcomp/MessageNode.st,v 1.167 2009-11-06 19:29:24 cg Exp $' |
148 | 2981 |
! ! |