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