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