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