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