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