author | Claus Gittinger <cg@exept.de> |
Fri, 16 Jan 1998 16:06:45 +0100 | |
changeset 639 | f3dce3a697f0 |
parent 627 | b29a02258247 |
child 676 | 69d1fe23a2b4 |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
47 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
ParseNode subclass:#MessageNode |
|
595
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
14 |
instanceVariableNames:'receiver selector argArray lineNr selectorPosition' |
166
9f6c57a3bce1
no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents:
163
diff
changeset
|
15 |
classVariableNames:'' |
9f6c57a3bce1
no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents:
163
diff
changeset
|
16 |
poolDictionaries:'' |
9f6c57a3bce1
no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents:
163
diff
changeset
|
17 |
category:'System-Compiler-Support' |
0 | 18 |
! |
19 |
||
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
20 |
!MessageNode class methodsFor:'documentation'! |
20 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
47 | 25 |
All Rights Reserved |
20 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
node for parse-trees, representing message sends |
|
261 | 39 |
This is a helper class for the compiler. |
263 | 40 |
|
41 |
[author:] |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
42 |
Claus Gittinger |
20 | 43 |
" |
44 |
! ! |
|
0 | 45 |
|
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
46 |
!MessageNode class methodsFor:'instance creation'! |
0 | 47 |
|
48 |
receiver:recNode selector:selectorString |
|
49 |
^ (self basicNew) receiver:recNode selector:selectorString args:nil lineno:0 |
|
50 |
! |
|
51 |
||
140 | 52 |
receiver:recNode selector:selectorString arg1:argNode1 arg2:argNode2 fold:folding |
53 |
|result recVal argVal selector| |
|
54 |
||
55 |
" |
|
56 |
This is just a demonstration - of how complex constants can be folded. |
|
57 |
This was inspired by some discussion in c.l.s about enhancing the language - I prefer |
|
58 |
enhancing the compiler .... |
|
59 |
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
|
60 |
allowing constant arrays of complex objects. |
140 | 61 |
|
62 |
Notice: this method is normally disabled - its just a demo after all. |
|
63 |
" |
|
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
64 |
folding notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
65 |
"/ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
66 |
"/ do constant folding ... |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
67 |
"/ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
68 |
(recNode isConstant and:[argNode1 isConstant]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
69 |
"check if we can do it ..." |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
70 |
selector := selectorString asSymbolIfInterned. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
71 |
selector notNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
72 |
recVal := recNode evaluate. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
73 |
(recVal respondsTo:selector) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
74 |
" |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
75 |
we could do much more here - but then, we need a dependency from |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
76 |
the folded selectors method to the method we generate code for ... |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
77 |
limit optimizations to those that will never change |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
78 |
(or - if you change them - you will crash so bad ...) |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
79 |
" |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
80 |
argVal := argNode1 evaluate. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
81 |
((recVal isMemberOf:Array) and:[argVal isMemberOf:Array]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
82 |
folding == #full ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
83 |
(selector == #with:collect:) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
84 |
(argNode2 isBlock) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
85 |
SignalSet anySignal handle:[:ex | |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
86 |
^ 'error in constant expression (' , ex errorString , ')' |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
87 |
] do:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
88 |
result := recVal perform:selector with:argVal with:(argNode2 evaluate). |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
89 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
90 |
^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
91 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
92 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
93 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
94 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
95 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
96 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
97 |
] |
140 | 98 |
]. |
99 |
^ (self basicNew) receiver:recNode selector:selectorString args:(Array with:argNode1 with:argNode2) lineno:0 |
|
570 | 100 |
|
101 |
"Modified: 28.6.1997 / 15:16:01 / cg" |
|
140 | 102 |
! |
103 |
||
0 | 104 |
receiver:recNode selector:selectorString arg:argNode |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
105 |
^ self receiver:recNode selector:selectorString arg:argNode fold:nil |
0 | 106 |
! |
107 |
||
108 |
receiver:recNode selector:selectorString arg:argNode fold:folding |
|
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
109 |
|result recVal argVal selector globalName canFold| |
0 | 110 |
|
20 | 111 |
" |
112 |
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
|
113 |
- 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
|
114 |
so that constant classVars can be inlined. |
20 | 115 |
" |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
116 |
folding notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
117 |
selector := selectorString asSymbolIfInterned. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
118 |
selector notNil ifTrue:[ |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
119 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
120 |
"/ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
121 |
"/ do constant folding ... |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
122 |
"/ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
123 |
canFold := false. |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
124 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
125 |
(recNode isGlobal and:[argNode isConstant]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
126 |
globalName := recNode name. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
127 |
recVal := recNode evaluate. |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
128 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
129 |
(globalName = 'SmallInteger') ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
130 |
( #( bitMaskFor: ) includes:selector) |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
131 |
ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
132 |
canFold := true |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
133 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
134 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
135 |
(globalName = 'Float') ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
136 |
( #( pi unity zero ) includes:selector) |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
137 |
ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
138 |
(recVal respondsTo:selector) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
139 |
canFold := true |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
140 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
141 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
142 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
143 |
]. |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
144 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
145 |
(recNode isConstant and:[argNode isConstant]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
146 |
"check if we can do it ..." |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
147 |
recVal := recNode evaluate. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
148 |
" |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
149 |
we could do much more here - but then, we need a dependency from |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
150 |
the folded selectors method to the method we generate code for ... |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
151 |
limit optimizations to those that will never change |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
152 |
(or - if you change them - you will crash so bad ...) |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
153 |
" |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
154 |
argVal := argNode evaluate. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
155 |
(recVal respondsToArithmetic and:[argVal respondsToArithmetic]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
156 |
( #( + - * / // \\ min: max: quo:) includes:selector) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
157 |
(#( / // \\ ) includes:selector) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
158 |
argVal = 0 ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
159 |
^ 'division by zero in constant expression' |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
160 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
161 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
162 |
canFold := true |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
163 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
164 |
( #( @ ) includes:selector) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
165 |
canFold := (folding == #full) |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
166 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
167 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
168 |
(recVal isInteger and:[argVal isInteger]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
169 |
( #( bitShift: bitOr: ) includes:selector) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
170 |
canFold := true |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
171 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
172 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
173 |
(recVal isMemberOf:String) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
174 |
(argVal isInteger and:[selector == #at:]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
175 |
canFold := (folding >= #level2) or:[folding == #full]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
176 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
177 |
((argVal isMemberOf:String) and:[selector == #',']) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
178 |
canFold := (folding >= #level2) or:[folding == #full]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
179 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
180 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
181 |
]. |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
182 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
183 |
canFold ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
184 |
(recVal respondsTo:selector) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
185 |
SignalSet anySignal handle:[:ex | |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
186 |
^ 'error in constant expression (' , ex errorString , ')' |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
187 |
] do:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
188 |
result := recVal perform:selector with:argVal. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
189 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
190 |
^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
191 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
192 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
193 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
194 |
|
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
195 |
"/ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
196 |
"/ #perform with a constant selector |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
197 |
"/ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
198 |
(selector == #perform: |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
199 |
and:[argNode isConstant]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
200 |
argVal := argNode evaluate. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
201 |
argVal isSymbol ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
202 |
^ UnaryNode receiver:recNode selector:argVal fold:folding |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
203 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
204 |
]. |
0 | 205 |
]. |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
206 |
|
0 | 207 |
^ (self basicNew) receiver:recNode selector:selectorString args:(Array with:argNode) lineno:0 |
576 | 208 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
209 |
"Modified: / 15.1.1998 / 15:04:27 / cg" |
0 | 210 |
! |
211 |
||
212 |
receiver:recNode selector:selectorString args:anArray |
|
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
213 |
^ self receiver:recNode selector:selectorString args:anArray fold:nil |
0 | 214 |
! |
215 |
||
216 |
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
|
217 |
|numArgs arg1 arg1Val| |
117 | 218 |
|
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
204
diff
changeset
|
219 |
folding notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
220 |
numArgs := argArray size. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
221 |
arg1 := (argArray at:1). |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
222 |
(numArgs == 1) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
223 |
^ self receiver:recNode selector:selectorString arg:arg1 fold:folding |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
224 |
]. |
20 | 225 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
226 |
"/ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
227 |
"/ #perform:... with a constant selector |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
228 |
"/ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
229 |
numArgs <= 6 ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
230 |
(#(nil |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
231 |
#'perform:with:' |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
232 |
#'perform:with:with:' |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
233 |
#'perform:with:with:with:' |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
234 |
#'perform:with:with:with:with:' |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
235 |
#'perform:with:with:with:with:with:' |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
236 |
#'perform:with:with:with:with:with:with:' |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
237 |
) at:numArgs) = selectorString |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
238 |
ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
239 |
arg1 isConstant ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
240 |
arg1Val := arg1 evaluate. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
241 |
arg1Val isSymbol ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
242 |
^ MessageNode |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
243 |
receiver:recNode |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
244 |
selector:arg1Val |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
245 |
args:(argArray copyFrom:2) |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
246 |
fold:folding |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
247 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
248 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
249 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
250 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
251 |
|
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
252 |
(numArgs == 2) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
253 |
^ self receiver:recNode selector:selectorString arg1:arg1 arg2:(argArray at:2) fold:folding |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
254 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
255 |
numArgs > Method maxNumberOfArguments ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
256 |
^ 'too many arguments for current VM implementation'. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
257 |
]. |
0 | 258 |
]. |
117 | 259 |
|
0 | 260 |
^ (self basicNew) receiver:recNode selector:selectorString args:argArray lineno:0 |
117 | 261 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
262 |
"Modified: / 3.9.1995 / 16:41:39 / claus" |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
263 |
"Modified: / 15.1.1998 / 15:20:00 / cg" |
0 | 264 |
! ! |
265 |
||
140 | 266 |
!MessageNode methodsFor:'accessing'! |
0 | 267 |
|
140 | 268 |
arg1 |
269 |
^ argArray at:1 |
|
270 |
! |
|
0 | 271 |
|
140 | 272 |
args |
273 |
^ argArray |
|
274 |
! |
|
0 | 275 |
|
543
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
276 |
arguments |
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
277 |
^ argArray ? #() |
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
278 |
|
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
279 |
"Created: 19.6.1997 / 17:31:14 / cg" |
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
280 |
"Modified: 19.6.1997 / 17:32:25 / cg" |
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
281 |
! |
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
282 |
|
140 | 283 |
lineNumber |
284 |
^ lineNr |
|
0 | 285 |
! |
286 |
||
140 | 287 |
lineNumber:num |
288 |
lineNr := num |
|
289 |
! |
|
0 | 290 |
|
140 | 291 |
receiver |
292 |
^ receiver |
|
293 |
! |
|
0 | 294 |
|
140 | 295 |
receiver:r selector:s args:a lineno:l |
296 |
receiver := r. |
|
297 |
selector := s asSymbol. |
|
298 |
argArray := a. |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
299 |
lineNr := l. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
300 |
self checkInlinability. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
301 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
302 |
"Modified: 2.7.1997 / 17:01:24 / cg" |
140 | 303 |
! |
304 |
||
305 |
selector |
|
306 |
^ selector |
|
595
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
307 |
! |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
308 |
|
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
309 |
selectorPosition |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
310 |
"return the value of the instance variable 'selectorPosition' (automatically generated)" |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
311 |
|
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
312 |
^ selectorPosition |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
313 |
|
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
314 |
"Created: 5.8.1997 / 02:49:27 / cg" |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
315 |
! |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
316 |
|
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
317 |
selectorPosition:something |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
318 |
"set the value of the instance variable 'selectorPosition' (automatically generated)" |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
319 |
|
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
320 |
selectorPosition := something. |
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
321 |
|
a90e8d8bf417
remember position of selector
Claus Gittinger <cg@exept.de>
parents:
578
diff
changeset
|
322 |
"Created: 5.8.1997 / 02:49:27 / cg" |
0 | 323 |
! ! |
324 |
||
325 |
!MessageNode methodsFor:'checks'! |
|
326 |
||
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
327 |
checkInlinability |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
328 |
"early check for possible inlinability" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
329 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
330 |
|numArgs arg1 arg2 arg3| |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
331 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
332 |
(numArgs := argArray size) >= 1 ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
333 |
arg1 := argArray at:1. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
334 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
335 |
numArgs == 0 ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
336 |
(selector == #whileTrue |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
337 |
or:[selector == #whileFalse]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
338 |
receiver isBlock ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
339 |
receiver possiblyInlined:true |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
340 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
341 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
342 |
(selector == #value) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
343 |
receiver isBlock ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
344 |
receiver possiblyInlined:true |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
345 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
346 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
347 |
(selector == #repeat) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
348 |
receiver isBlock ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
349 |
receiver possiblyInlined:true |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
350 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
351 |
]. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
352 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
353 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
354 |
numArgs == 1 ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
355 |
(selector == #or: |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
356 |
or:[selector == #and:]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
357 |
arg1 isBlock ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
358 |
arg1 possiblyInlined:true |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
359 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
360 |
]. |
576 | 361 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
362 |
(selector == #ifTrue: |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
363 |
or:[selector == #ifFalse:]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
364 |
arg1 isBlock ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
365 |
arg1 possiblyInlined:true |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
366 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
367 |
]. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
368 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
369 |
(selector == #whileTrue: |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
370 |
or:[selector == #whileFalse:]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
371 |
arg1 isBlock ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
372 |
arg1 possiblyInlined:true |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
373 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
374 |
receiver isBlock ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
375 |
receiver possiblyInlined:true |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
376 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
377 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
378 |
selector == #timesRepeat: ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
379 |
arg1 isBlock ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
380 |
arg1 possiblyInlined:true |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
381 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
382 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
383 |
^ self |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
384 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
385 |
numArgs >= 2 ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
386 |
arg2 := argArray at:2. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
387 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
388 |
numArgs == 2 ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
389 |
(selector == #ifTrue:ifFalse: |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
390 |
or:[selector == #ifFalse:ifTrue:]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
391 |
(arg1 isBlock |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
392 |
and:[arg2 isBlock]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
393 |
arg1 possiblyInlined:true. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
394 |
arg2 possiblyInlined:true. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
395 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
396 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
397 |
selector == #to:do: ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
398 |
arg2 isBlock ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
399 |
arg2 possiblyInlined:true. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
400 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
401 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
402 |
^ self |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
403 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
404 |
numArgs >= 3 ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
405 |
arg3 := argArray at:3. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
406 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
407 |
numArgs == 3 ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
408 |
selector == #to:by:do: ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
409 |
arg3 isBlock ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
410 |
arg3 possiblyInlined:true. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
411 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
412 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
413 |
^ self |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
414 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
415 |
^ self |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
416 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
417 |
"Created: 2.7.1997 / 17:01:10 / cg" |
602 | 418 |
"Modified: 29.8.1997 / 08:20:57 / cg" |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
419 |
! |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
570
diff
changeset
|
420 |
|
0 | 421 |
plausibilityCheck |
422 |
|rec arg operand| |
|
423 |
||
3 | 424 |
" |
425 |
it once took me almost an hour, to find a '==' which |
|
426 |
should have been an '=' (you cannot compare floats with ==) |
|
19 | 427 |
(well, I looked at the '==' at least 50 times - |
428 |
- but didn't think about it ...). |
|
429 |
thats reason enough to add this check here. |
|
430 |
I will add more as heuristic knowledge increases ... |
|
431 |
(send me comments on common programming errors ...) |
|
432 |
" |
|
433 |
||
434 |
" |
|
435 |
check #== appled to Floats, Strings or Fractions |
|
0 | 436 |
" |
437 |
((selector == #==) or:[selector == #~~]) ifTrue:[ |
|
47 | 438 |
receiver isConstant ifTrue:[ |
439 |
rec := receiver evaluate. |
|
440 |
((rec isMemberOf:String) or:[ |
|
441 |
(rec isMemberOf:Float) or:[ |
|
442 |
(rec isMemberOf:Fraction)]]) ifTrue:[ |
|
443 |
operand := rec |
|
444 |
]. |
|
445 |
]. |
|
446 |
(argArray at:1) isConstant ifTrue:[ |
|
447 |
arg := (argArray at:1) evaluate. |
|
448 |
((arg isMemberOf:String) or:[ |
|
449 |
(arg isMemberOf:Float) or:[ |
|
450 |
(arg isMemberOf:Fraction)]]) ifTrue:[ |
|
451 |
operand := arg |
|
452 |
]. |
|
453 |
]. |
|
454 |
operand notNil ifTrue:[ |
|
455 |
(selector == #==) ifTrue:[ |
|
456 |
^ 'identity compare is unsafe here' |
|
457 |
]. |
|
458 |
^ 'identity compare will usually return true here' |
|
459 |
] |
|
0 | 460 |
]. |
3 | 461 |
|
462 |
" |
|
19 | 463 |
[...] ifTrue:... |
3 | 464 |
an error often occuring when you are a beginner ... |
465 |
" |
|
466 |
((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[ |
|
47 | 467 |
receiver isBlock ifTrue:[ |
468 |
(Block canUnderstand:selector) ifFalse:[ |
|
469 |
^ 'blocks usually do not respond to ' , selector , ' messages' |
|
470 |
]. |
|
471 |
]. |
|
472 |
(argArray at:1) isBlock ifFalse:[ |
|
473 |
^ 'will fail at runtime, if argument to ' , selector , ' does not evaluate to a block' |
|
474 |
] |
|
3 | 475 |
]. |
19 | 476 |
((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[ |
47 | 477 |
receiver isBlock ifTrue:[ |
478 |
(Block canUnderstand:selector) ifFalse:[ |
|
479 |
^ 'blocks usually do not respond to ' , selector , ' messages' |
|
480 |
]. |
|
481 |
]. |
|
482 |
(argArray at:1) isBlock ifFalse:[ |
|
483 |
^ 'will fail at runtime, if 1st. argument to ' , selector , ' does not evaluate to a block' |
|
484 |
]. |
|
485 |
(argArray at:2) isBlock ifFalse:[ |
|
486 |
^ 'will fail at runtime, if 2nd. argument to ' , selector , ' does not evaluate to a block' |
|
487 |
] |
|
3 | 488 |
]. |
19 | 489 |
|
490 |
" |
|
491 |
(...) whileTrue:[ |
|
492 |
" |
|
3 | 493 |
((selector == #whileTrue:) or:[selector == #whileFalse:]) ifTrue:[ |
47 | 494 |
receiver isBlock ifFalse:[ |
495 |
" |
|
496 |
only warn, if code was originally parenthized |
|
497 |
" |
|
498 |
receiver parenthized ifTrue:[ |
|
499 |
^ 'will fail at runtime, if receiver of ' , selector , ' does not evaluate to a block' |
|
500 |
] |
|
501 |
]. |
|
502 |
(argArray at:1) isBlock ifFalse:[ |
|
503 |
^ 'will fail at runtime, if argument to ' , selector , ' does not evaluate to a block' |
|
504 |
]. |
|
3 | 505 |
]. |
0 | 506 |
^ nil |
507 |
! ! |
|
508 |
||
509 |
!MessageNode methodsFor:'code generation'! |
|
510 |
||
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
511 |
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
|
512 |
"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
|
513 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
514 |
|theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp| |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
515 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
516 |
theByteCode := #falseJump. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
517 |
theReceiver := receiver receiver. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
518 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
519 |
optByteCode := self optimizedConditionFor:theReceiver |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
520 |
with:theByteCode. |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
521 |
optByteCode notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
522 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
523 |
theArg := theReceiver arg1 |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
524 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
525 |
theReceiver := theReceiver receiver. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
526 |
theByteCode := optByteCode |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
527 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
528 |
"/ code the left-of the and-part |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
529 |
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
|
530 |
theArg notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
531 |
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
|
532 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
533 |
aStream nextPut:theByteCode. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
534 |
pos1 := aStream position. "/ remember branch target of left-fail branch |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
535 |
aStream nextPut:0. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
536 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
537 |
"/ 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
|
538 |
theReceiver := receiver arg1. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
539 |
theReceiver codeInlineOn:aStream inBlock:b for:aCompiler. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
540 |
(selector == #ifTrue:ifFalse:) ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
541 |
jmp := #falseJump |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
542 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
543 |
jmp := #trueJump |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
544 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
545 |
aStream nextPut:jmp. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
546 |
pos2 := aStream position. "/ remember branch target of right-fail branch |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
547 |
aStream nextPut:0. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
548 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
549 |
code := aStream contents. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
550 |
(selector == #ifFalse:ifTrue:) ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
551 |
code at:pos1 put:(aStream position) |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
552 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
553 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
554 |
"/ code the if-block |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
555 |
(argArray at: 1) codeInlineOn: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
|
556 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
557 |
aStream nextPut:#jump. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
558 |
pos3 := aStream position. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
559 |
aStream nextPut:0. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
560 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
561 |
here := aStream position. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
562 |
(selector == #ifTrue:ifFalse:) ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
563 |
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
|
564 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
565 |
code at:pos2 put:here. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
566 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
567 |
"/ code the else-block |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
568 |
(argArray at: 2) codeInlineOn: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
|
569 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
570 |
code at:pos3 put:(aStream position) |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
571 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
572 |
"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
|
573 |
! |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
574 |
|
140 | 575 |
codeAndIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
576 |
"generate code for (x and:[y]) ifxxx:[ ... ]" |
|
577 |
||
578 |
|theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp| |
|
579 |
||
580 |
||
581 |
theByteCode := #falseJump. |
|
582 |
theReceiver := receiver receiver. |
|
0 | 583 |
|
140 | 584 |
optByteCode := self optimizedConditionFor:theReceiver |
585 |
with:theByteCode. |
|
586 |
optByteCode notNil ifTrue:[ |
|
587 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
|
588 |
theArg := theReceiver arg1 |
|
589 |
]. |
|
590 |
theReceiver := theReceiver receiver. |
|
591 |
theByteCode := optByteCode |
|
592 |
]. |
|
104 | 593 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
140 | 594 |
theArg notNil ifTrue:[ |
595 |
theArg codeOn:aStream inBlock:b for:aCompiler |
|
596 |
]. |
|
597 |
aStream nextPut:theByteCode. |
|
598 |
pos1 := aStream position. |
|
599 |
aStream nextPut:0. |
|
0 | 600 |
|
140 | 601 |
theReceiver := receiver arg1. |
602 |
theReceiver codeInlineOn:aStream inBlock:b for:aCompiler. |
|
603 |
(selector == #ifTrue:) ifTrue:[ |
|
604 |
jmp := #falseJump |
|
605 |
] ifFalse:[ |
|
606 |
jmp := #trueJump |
|
607 |
]. |
|
608 |
aStream nextPut:jmp. |
|
0 | 609 |
pos2 := aStream position. |
610 |
aStream nextPut:0. |
|
611 |
||
140 | 612 |
code := aStream contents. |
613 |
(selector == #ifFalse:) ifTrue:[ |
|
614 |
code at:pos1 put:(aStream position) |
|
615 |
]. |
|
616 |
(argArray at: 1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
617 |
||
618 |
valueNeeded ifTrue:[ |
|
619 |
aStream nextPut:#jump. |
|
620 |
pos3 := aStream position. |
|
621 |
aStream nextPut:0. |
|
622 |
here := aStream position. |
|
623 |
(selector == #ifTrue:) ifTrue:[ |
|
624 |
code at:pos1 put:here |
|
625 |
]. |
|
626 |
code at:pos2 put:here. |
|
627 |
aStream nextPut:#pushNil. |
|
628 |
code at:pos3 put:(aStream position) |
|
629 |
] ifFalse:[ |
|
630 |
here := aStream position. |
|
631 |
(selector == #ifTrue:) ifTrue:[ |
|
632 |
code at:pos1 put:here |
|
633 |
]. |
|
634 |
code at:pos2 put:here |
|
635 |
] |
|
636 |
! |
|
637 |
||
289 | 638 |
codeAndOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
639 |
"generate code for (x and:[y])" |
|
140 | 640 |
|
289 | 641 |
|pos1 rightExpr| |
642 |
||
643 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
|
644 |
valueNeeded ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
645 |
aStream nextPut:#dup. |
140 | 646 |
]. |
289 | 647 |
aStream nextPut:#falseJump. |
648 |
pos1 := aStream position. |
|
649 |
aStream nextPut:0. |
|
650 |
valueNeeded ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
651 |
aStream nextPut:#drop. |
140 | 652 |
]. |
289 | 653 |
rightExpr := argArray at:1. |
654 |
rightExpr codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
163 | 655 |
|
289 | 656 |
(aStream contents) at:pos1 put:(aStream position) |
657 |
||
658 |
"Created: 17.6.1996 / 15:46:42 / cg" |
|
659 |
"Modified: 17.6.1996 / 15:47:44 / cg" |
|
140 | 660 |
! |
661 |
||
662 |
codeForCascadeOn:aStream inBlock:b for:aCompiler |
|
663 |
"like codeOn, but always leave the receiver instead of the result" |
|
664 |
||
189
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
665 |
|nargs isBuiltIn code codeL litIndex cls clsLitIndex| |
140 | 666 |
|
667 |
argArray isNil ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
668 |
nargs := 0 |
140 | 669 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
670 |
nargs := argArray size |
140 | 671 |
]. |
672 |
||
673 |
isBuiltIn := false. |
|
0 | 674 |
|
140 | 675 |
(nargs == 0) ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
676 |
isBuiltIn := aCompiler isBuiltInUnarySelector:selector forReceiver:receiver |
140 | 677 |
]. |
678 |
(nargs == 1) ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
679 |
isBuiltIn := aCompiler isBuiltIn1ArgSelector:selector forReceiver:receiver |
140 | 680 |
]. |
681 |
(nargs == 2) ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
682 |
isBuiltIn := aCompiler isBuiltIn2ArgSelector:selector forReceiver:receiver |
140 | 683 |
]. |
684 |
||
685 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
|
686 |
aStream nextPut:#dup. |
|
687 |
||
688 |
"can we use a send-bytecode ?" |
|
689 |
isBuiltIn ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
690 |
receiver isSuper ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
691 |
(nargs > 0) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
692 |
(argArray at:1) codeOn:aStream inBlock:b for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
693 |
(nargs > 1) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
694 |
(argArray at:2) codeOn:aStream inBlock:b for:aCompiler |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
695 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
696 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
697 |
aStream nextPut:selector. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
698 |
(aCompiler hasLineNumber:selector) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
699 |
aStream nextPut:lineNr. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
700 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
701 |
aStream nextPut:#drop. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
702 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
703 |
] |
140 | 704 |
]. |
705 |
||
706 |
"no - generate a send" |
|
707 |
argArray notNil ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
708 |
argArray do:[:arg | |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
709 |
arg codeOn:aStream inBlock:b for:aCompiler |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
710 |
] |
140 | 711 |
]. |
712 |
litIndex := aCompiler addLiteral:selector. |
|
189
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
713 |
|
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
714 |
receiver isSuper ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
715 |
cls := aCompiler targetClass. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
716 |
receiver isHere ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
717 |
code := #hereSend. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
718 |
codeL := #hereSendL. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
719 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
720 |
code := #superSend. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
721 |
codeL := #superSendL. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
722 |
cls := cls superclass. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
723 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
724 |
clsLitIndex := aCompiler addLiteral:cls. |
189
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
725 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
726 |
(litIndex <= 255 and:[clsLitIndex <= 255]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
727 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs; nextPut:clsLitIndex; nextPut:#drop. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
728 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
729 |
]. |
189
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
730 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
731 |
"need 16bit litIndex" |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
732 |
aStream nextPut:codeL; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs; nextPut:clsLitIndex; nextPut:0; nextPut:#drop. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
733 |
^ self |
189
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
734 |
]. |
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
735 |
|
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
736 |
litIndex <= 255 ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
737 |
(nargs <= 3) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
738 |
code := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3) at:(nargs+1). |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
739 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
740 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
741 |
]. |
140 | 742 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
743 |
aStream nextPut:#sendDrop; nextPut:lineNr; nextPut:litIndex; nextPut:nargs. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
744 |
^ self |
140 | 745 |
]. |
746 |
"need 16bit litIndex" |
|
747 |
aStream nextPut:#sendDropL; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs |
|
189
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
748 |
|
253
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
245
diff
changeset
|
749 |
"Modified: 17.4.1996 / 22:33:24 / cg" |
140 | 750 |
! |
751 |
||
752 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
753 |
self codeOn:aStream inBlock:b valueNeeded:false for:aCompiler |
|
0 | 754 |
! |
755 |
||
104 | 756 |
codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
0 | 757 |
"generate code for x ifxxx:[ ... ] yyy:[ ...]" |
758 |
||
334
cd7491b7ad33
dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
759 |
|pos pos2 theReceiver theArg theByteCode optByteCode subsel code needLineNr |
cd7491b7ad33
dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
760 |
needJump block1| |
0 | 761 |
|
762 |
theReceiver := receiver. |
|
76 | 763 |
|
764 |
(theReceiver isMessage) ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
765 |
subsel := theReceiver selector. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
766 |
(subsel == #and:) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
767 |
self codeAndIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
768 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
769 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
770 |
(subsel == #or:) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
771 |
self codeOrIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
772 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
773 |
] |
76 | 774 |
]. |
0 | 775 |
(selector == #ifTrue:ifFalse:) ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
776 |
theByteCode := #falseJump |
0 | 777 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
778 |
(selector == #ifFalse:ifTrue:) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
779 |
theByteCode := #trueJump |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
780 |
] |
0 | 781 |
]. |
782 |
optByteCode := self optimizedConditionFor:theReceiver |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
783 |
with:theByteCode. |
0 | 784 |
optByteCode notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
785 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
786 |
theArg := theReceiver arg1 |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
787 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
788 |
theReceiver := theReceiver receiver. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
789 |
theByteCode := optByteCode |
0 | 790 |
]. |
791 |
theByteCode notNil ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
792 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
53 | 793 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
794 |
needLineNr := true. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
795 |
theArg isNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
796 |
theReceiver isMessage ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
797 |
(aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
798 |
theReceiver lineNumber == lineNr ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
799 |
needLineNr := false |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
800 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
801 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
802 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
803 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
804 |
theArg codeOn:aStream inBlock:b for:aCompiler |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
805 |
]. |
53 | 806 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
807 |
needLineNr ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
808 |
(lineNr between:1 and:255) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
809 |
aStream nextPut:#lineno; nextPut:lineNr. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
810 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
811 |
]. |
166
9f6c57a3bce1
no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents:
163
diff
changeset
|
812 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
813 |
aStream nextPut:theByteCode. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
814 |
pos := aStream position. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
815 |
aStream nextPut:0. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
816 |
block1 := argArray at:1. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
817 |
block1 codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
818 |
needJump := true. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
819 |
(block1 isBlock and:[block1 endsWithReturn]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
820 |
needJump := false |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
821 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
822 |
needJump ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
823 |
aStream nextPut:#jump. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
824 |
pos2 := aStream position. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
825 |
aStream nextPut:0. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
826 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
827 |
code := aStream contents. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
828 |
code at:pos put:(aStream position). |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
829 |
(argArray at:2) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
830 |
needJump ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
831 |
code at:pos2 put:(aStream position) |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
832 |
] |
0 | 833 |
] |
166
9f6c57a3bce1
no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents:
163
diff
changeset
|
834 |
|
434
c48a356d8a34
oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents:
429
diff
changeset
|
835 |
"Modified: 9.11.1996 / 19:53:52 / cg" |
0 | 836 |
! |
837 |
||
104 | 838 |
codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
0 | 839 |
"generate code for x ifxxx:[ ... ]" |
840 |
||
103 | 841 |
|pos pos2 theReceiver theArg theByteCode optByteCode subsel code |
842 |
needLineNr| |
|
0 | 843 |
|
844 |
theReceiver := receiver. |
|
845 |
||
76 | 846 |
(theReceiver isMessage) ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
847 |
subsel := theReceiver selector. |
308
fe3b95e6d9c0
oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents:
289
diff
changeset
|
848 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
849 |
(subsel == #and:) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
850 |
theReceiver arg1 isBlock ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
851 |
self codeAndIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
852 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
853 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
854 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
855 |
(subsel == #or:) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
856 |
theReceiver arg1 isBlock ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
857 |
self codeOrIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
858 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
859 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
860 |
]. |
0 | 861 |
]. |
862 |
(selector == #ifTrue:) ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
863 |
theByteCode := #falseJump |
0 | 864 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
865 |
theByteCode := #trueJump |
0 | 866 |
]. |
867 |
optByteCode := self optimizedConditionFor:theReceiver |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
868 |
with:theByteCode. |
0 | 869 |
optByteCode notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
870 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
871 |
theArg := theReceiver arg1 |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
872 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
873 |
theReceiver := theReceiver receiver. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
874 |
theByteCode := optByteCode |
0 | 875 |
]. |
876 |
||
104 | 877 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
0 | 878 |
theArg notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
879 |
theArg codeOn:aStream inBlock:b for:aCompiler |
0 | 880 |
]. |
53 | 881 |
|
103 | 882 |
needLineNr := true. |
883 |
theArg isNil ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
884 |
theReceiver isMessage ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
885 |
(aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
886 |
theReceiver lineNumber == lineNr ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
887 |
needLineNr := false |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
888 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
889 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
890 |
] |
103 | 891 |
]. |
892 |
||
893 |
needLineNr ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
894 |
(lineNr between:1 and:255) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
895 |
aStream nextPut:#lineno; nextPut:lineNr. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
896 |
] |
53 | 897 |
]. |
898 |
||
0 | 899 |
aStream nextPut:theByteCode. |
900 |
pos := aStream position. |
|
901 |
aStream nextPut:0. |
|
104 | 902 |
(argArray at: 1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
76 | 903 |
|
904 |
code := aStream contents. |
|
0 | 905 |
valueNeeded ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
906 |
aStream nextPut:#jump. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
907 |
pos2 := aStream position. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
908 |
aStream nextPut:0. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
909 |
code at:pos put:(aStream position). |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
910 |
aStream nextPut:#pushNil. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
911 |
code at:pos2 put:(aStream position) |
0 | 912 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
913 |
code at:pos put:(aStream position) |
0 | 914 |
] |
308
fe3b95e6d9c0
oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents:
289
diff
changeset
|
915 |
|
627 | 916 |
"Modified: / 28.10.1997 / 18:33:42 / cg" |
0 | 917 |
! |
918 |
||
140 | 919 |
codeOn:aStream inBlock:b for:aCompiler |
920 |
self codeOn:aStream inBlock:b valueNeeded:true for:aCompiler |
|
0 | 921 |
! |
922 |
||
104 | 923 |
codeOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
245
8a78aa886351
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
231
diff
changeset
|
924 |
|recType nargs isBuiltIn litIndex cls clsLitIndex code isSpecial |
576 | 925 |
specialCode stackTop arg1 arg2 arg3| |
0 | 926 |
|
927 |
argArray isNil ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
928 |
nargs := 0 |
0 | 929 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
930 |
nargs := argArray size. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
931 |
nargs > 0 ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
932 |
arg1 := argArray at:1. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
933 |
nargs > 1 ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
934 |
arg2 := argArray at:2. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
935 |
nargs > 2 ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
936 |
arg3 := argArray at:3. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
937 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
938 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
939 |
]. |
0 | 940 |
]. |
941 |
||
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
189
diff
changeset
|
942 |
isBuiltIn := isSpecial := false. |
117 | 943 |
recType := receiver type. |
0 | 944 |
|
945 |
(nargs == 0) ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
946 |
(recType == #ThisContext) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
947 |
valueNeeded ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
948 |
"for now, only do it in methods" |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
949 |
b isNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
950 |
(selector == #restart) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
951 |
aStream nextPut:#jump; nextPut:1. "jump to start" |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
952 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
953 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
954 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
955 |
(selector == #return) ifTrue:[ "^ nil" |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
956 |
aStream nextPut:#retNil. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
957 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
958 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
959 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
960 |
]. |
52 | 961 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
962 |
receiver isBlock ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
963 |
selector == #value ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
964 |
receiver codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
965 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
966 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
967 |
((selector == #whileTrue) or:[selector == #whileFalse]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
968 |
receiver isInlinable ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
969 |
^ self codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
970 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
971 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
972 |
(selector == #repeat) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
973 |
receiver isInlinable ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
974 |
valueNeeded ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
975 |
^ self codeRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
976 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
977 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
978 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
979 |
]. |
436 | 980 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
981 |
isBuiltIn := aCompiler isBuiltInUnarySelector:selector forReceiver:receiver. |
0 | 982 |
]. |
983 |
||
984 |
(nargs == 1) ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
985 |
(recType == #ThisContext) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
986 |
valueNeeded ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
987 |
(selector == #return:) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
988 |
arg1 codeOn:aStream inBlock:b for:aCompiler. "^ value" |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
989 |
aStream nextPut:#retTop. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
990 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
991 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
992 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
993 |
]. |
19 | 994 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
995 |
(arg1 isBlock and:[arg1 isInlinable]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
996 |
((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
997 |
receiver isBlock ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
998 |
^ self codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
999 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1000 |
]. |
289 | 1001 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1002 |
(selector == #or:) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1003 |
^ self codeOrOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1004 |
]. |
289 | 1005 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1006 |
(selector == #and:) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1007 |
^ self codeAndOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1008 |
]. |
289 | 1009 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1010 |
(selector == #timesRepeat:) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1011 |
"/ now, always inline #timesRepeat:; |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1012 |
"/ the receiver must understand #> and #- |
564
ffac5191213f
always inline #timesRepeat: (as #> 0 ... - 1)
Claus Gittinger <cg@exept.de>
parents:
561
diff
changeset
|
1013 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1014 |
^ self codeTimesRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1015 |
]. |
0 | 1016 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1017 |
((selector == #whileTrue:) or:[selector == #whileFalse:]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1018 |
(receiver isBlock and:[receiver isInlinable]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1019 |
^ self codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1020 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1021 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1022 |
]. |
436 | 1023 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1024 |
selector == #? ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1025 |
"/ only do short-circuit optimization, if arg is not a message; |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1026 |
"/ (could have side-effects) |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1027 |
"/ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1028 |
arg1 isMessage ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1029 |
^ self codeQuestOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1030 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1031 |
]. |
436 | 1032 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1033 |
isBuiltIn := aCompiler isBuiltIn1ArgSelector:selector forReceiver:receiver. |
0 | 1034 |
]. |
1035 |
||
1036 |
(nargs == 2) ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1037 |
((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1038 |
receiver isBlock ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1039 |
(arg1 isBlock and:[arg1 isInlinable]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1040 |
(arg2 isBlock and:[arg2 isInlinable]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1041 |
^ self codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1042 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1043 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1044 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1045 |
]. |
536
9fe0b3be6672
better code for <int> to: <int> do:[unusedArg | ...]
Claus Gittinger <cg@exept.de>
parents:
531
diff
changeset
|
1046 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1047 |
selector == #to:do: ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1048 |
(arg2 isBlock and:[arg2 isInlinable and:[arg2 numArgs == 1]]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1049 |
^ self codeToDoOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1050 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1051 |
]. |
536
9fe0b3be6672
better code for <int> to: <int> do:[unusedArg | ...]
Claus Gittinger <cg@exept.de>
parents:
531
diff
changeset
|
1052 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1053 |
isBuiltIn := aCompiler isBuiltIn2ArgSelector:selector forReceiver:receiver. |
531 | 1054 |
]. |
1055 |
||
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1056 |
(nargs == 3) ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1057 |
selector == #to:by:do: ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1058 |
"/ step must be a constant (need to know how to compare) |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1059 |
(arg2 isConstant |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1060 |
and:[arg2 type == #Integer]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1061 |
(arg3 isBlock |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1062 |
and:[arg3 isInlinable |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1063 |
and:[arg3 numArgs == 1]]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1064 |
^ self codeToByDoOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1065 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1066 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1067 |
]. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1068 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1069 |
|
531 | 1070 |
isBuiltIn ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1071 |
specialCode := aCompiler specialSendCodeFor:selector. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1072 |
isSpecial := specialCode notNil. |
0 | 1073 |
]. |
1074 |
||
1075 |
"can we use a send-bytecode ?" |
|
199
1b3b350a3f59
moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents:
189
diff
changeset
|
1076 |
(isBuiltIn or:[isSpecial]) ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1077 |
receiver isSuper ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1078 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1079 |
(nargs > 0) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1080 |
arg1 codeOn:aStream inBlock:b for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1081 |
(nargs > 1) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1082 |
arg2 codeOn:aStream inBlock:b for:aCompiler |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1083 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1084 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1085 |
aStream nextPut:selector. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1086 |
(aCompiler hasLineNumber:selector) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1087 |
aStream nextPut:lineNr. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1088 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1089 |
isSpecial ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1090 |
aStream nextPut:specialCode |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1091 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1092 |
valueNeeded ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1093 |
aStream nextPut:#drop |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1094 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1095 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1096 |
] |
0 | 1097 |
]. |
1098 |
||
1099 |
((nargs == 0) and:[selector == #yourself]) ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1100 |
"yourself is often added to get the receiver - |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1101 |
we get it without the yourself-message" |
0 | 1102 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1103 |
valueNeeded ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1104 |
receiver codeOn:aStream inBlock:b for:aCompiler |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1105 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1106 |
^ self |
0 | 1107 |
]. |
1108 |
||
1109 |
"no - generate a send" |
|
117 | 1110 |
|
1111 |
receiver isSuper ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1112 |
cls := aCompiler targetClass. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1113 |
receiver isHere ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1114 |
code := #hereSend. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1115 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1116 |
code := #superSend. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1117 |
cls := cls superclass. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1118 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1119 |
clsLitIndex := aCompiler addLiteral:cls. |
117 | 1120 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1121 |
clsLitIndex := 0. |
0 | 1122 |
]. |
106 | 1123 |
|
117 | 1124 |
litIndex := aCompiler addLiteral:selector. |
1125 |
(litIndex <= 255 and:[clsLitIndex <= 255]) ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1126 |
stackTop := nil. |
117 | 1127 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1128 |
(recType ~~ #Self) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1129 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1130 |
receiver isConstant ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1131 |
stackTop := receiver |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1132 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1133 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1134 |
argArray notNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1135 |
argArray do:[:arg | |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1136 |
(stackTop notNil |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1137 |
and:[arg canReuseAsArg:stackTop]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1138 |
aStream nextPut:#dup. |
245
8a78aa886351
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
231
diff
changeset
|
1139 |
"/ 'reuse:' print. stackTop print. ' in ' print. aCompiler selector printNL. |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1140 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1141 |
arg codeOn:aStream inBlock:b for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1142 |
stackTop := arg. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1143 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1144 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1145 |
]. |
106 | 1146 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1147 |
receiver isSuper ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1148 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs; nextPut:clsLitIndex. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1149 |
valueNeeded ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1150 |
aStream nextPut:#drop |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1151 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1152 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1153 |
]. |
245
8a78aa886351
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
231
diff
changeset
|
1154 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1155 |
(nargs <= 3) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1156 |
|codes| |
106 | 1157 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1158 |
valueNeeded ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1159 |
(receiver type == #Self) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1160 |
codes := #(sendSelf0 sendSelf1 sendSelf2 sendSelf3) |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1161 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1162 |
codes := #(send0 send1 send2 send3) |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1163 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1164 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1165 |
(receiver type == #Self) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1166 |
codes := #(sendSelfDrop0 sendSelfDrop1 sendSelfDrop2 sendSelfDrop3) |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1167 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1168 |
codes := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3) |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1169 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1170 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1171 |
aStream nextPut:(codes at:(nargs + 1)); nextPut:lineNr; nextPut:litIndex. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1172 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1173 |
]. |
106 | 1174 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1175 |
(recType == #Self) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1176 |
code := #sendSelf |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1177 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1178 |
valueNeeded ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1179 |
code := #send |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1180 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1181 |
code := #sendDrop |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1182 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1183 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1184 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1185 |
valueNeeded ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1186 |
(recType == #Self) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1187 |
aStream nextPut:#drop |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1188 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1189 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1190 |
^ self |
106 | 1191 |
]. |
1192 |
||
1193 |
"needs 16bit literal index" |
|
117 | 1194 |
|
48 | 1195 |
receiver isSuper ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1196 |
argArray notNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1197 |
argArray do:[:arg | |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1198 |
arg codeOn:aStream inBlock:b for:aCompiler |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1199 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1200 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1201 |
receiver isHere ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1202 |
code := #hereSendL |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1203 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1204 |
code := #superSendL. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1205 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1206 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs; nextPut:clsLitIndex; nextPut:0. |
117 | 1207 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1208 |
recType ~~ #Self ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1209 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1210 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1211 |
argArray notNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1212 |
argArray do:[:arg | |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1213 |
arg codeOn:aStream inBlock:b for:aCompiler |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1214 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1215 |
]. |
117 | 1216 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1217 |
recType == #Self ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1218 |
code := #sendSelfL |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1219 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1220 |
code := #sendL |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1221 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1222 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs. |
0 | 1223 |
]. |
117 | 1224 |
valueNeeded ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1225 |
aStream nextPut:#drop |
0 | 1226 |
]. |
117 | 1227 |
|
627 | 1228 |
"Modified: / 3.9.1995 / 12:55:42 / claus" |
1229 |
"Modified: / 28.10.1997 / 18:15:33 / cg" |
|
0 | 1230 |
! |
1231 |
||
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1232 |
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
|
1233 |
"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
|
1234 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1235 |
|theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp| |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1236 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1237 |
theByteCode := #trueJump. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1238 |
theReceiver := receiver receiver. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1239 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1240 |
optByteCode := self optimizedConditionFor:theReceiver |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1241 |
with:theByteCode. |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1242 |
optByteCode notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1243 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1244 |
theArg := theReceiver arg1 |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1245 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1246 |
theReceiver := theReceiver receiver. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1247 |
theByteCode := optByteCode |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1248 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1249 |
"/ 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
|
1250 |
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
|
1251 |
theArg notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1252 |
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
|
1253 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1254 |
aStream nextPut:theByteCode. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1255 |
pos1 := aStream position. "/ remember branch target of left-ok branch |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1256 |
aStream nextPut:0. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1257 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1258 |
"/ 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
|
1259 |
theReceiver := receiver arg1. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1260 |
theReceiver codeInlineOn:aStream inBlock:b for:aCompiler. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1261 |
(selector == #ifTrue:ifFalse:) ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1262 |
jmp := #falseJump |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1263 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1264 |
jmp := #trueJump |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1265 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1266 |
aStream nextPut:jmp. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1267 |
pos2 := aStream position. "/ remember branch target of right-fail branch |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1268 |
aStream nextPut:0. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1269 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1270 |
code := aStream contents. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1271 |
(selector == #ifTrue:ifFalse:) ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1272 |
code at:pos1 put:(aStream position) |
338
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1273 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1274 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1275 |
"/ code the if-block |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1276 |
(argArray at: 1) codeInlineOn: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
|
1277 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1278 |
aStream nextPut:#jump. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1279 |
pos3 := aStream position. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1280 |
aStream nextPut:0. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1281 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1282 |
here := aStream position. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1283 |
(selector == #ifFalse:ifTrue:) ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1284 |
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
|
1285 |
]. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1286 |
code at:pos2 put:here. |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1287 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1288 |
"/ code the else-block |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1289 |
(argArray at: 2) codeInlineOn: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
|
1290 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1291 |
code at:pos3 put:(aStream position) |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1292 |
|
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1293 |
"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
|
1294 |
! |
8ab1a2715ab1
better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents:
334
diff
changeset
|
1295 |
|
140 | 1296 |
codeOrIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
1297 |
"generate code for (x or:[y]) ifxxx:[ ... ]" |
|
1298 |
||
1299 |
|theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp| |
|
1300 |
||
1301 |
theByteCode := #trueJump. |
|
1302 |
theReceiver := receiver receiver. |
|
1303 |
||
1304 |
optByteCode := self optimizedConditionFor:theReceiver with:theByteCode. |
|
1305 |
optByteCode notNil ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1306 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1307 |
theArg := theReceiver arg1 |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1308 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1309 |
theReceiver := theReceiver receiver. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1310 |
theByteCode := optByteCode |
140 | 1311 |
]. |
1312 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
|
1313 |
theArg notNil ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1314 |
theArg codeOn:aStream inBlock:b for:aCompiler |
140 | 1315 |
]. |
1316 |
aStream nextPut:theByteCode. |
|
1317 |
pos1 := aStream position. |
|
1318 |
aStream nextPut:0. |
|
1319 |
||
1320 |
||
1321 |
theReceiver := receiver arg1. |
|
434
c48a356d8a34
oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents:
429
diff
changeset
|
1322 |
theArg := nil. |
140 | 1323 |
|
1324 |
"new:" |
|
1325 |
(selector == #ifTrue:) ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1326 |
theByteCode := #falseJump |
140 | 1327 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1328 |
theByteCode := #trueJump |
140 | 1329 |
]. |
1330 |
optByteCode := self optimizedConditionFor:theReceiver with:theByteCode. |
|
1331 |
optByteCode notNil ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1332 |
theReceiver isBlock ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1333 |
theReceiver := theReceiver statements expression |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1334 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1335 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1336 |
theArg := theReceiver arg1 |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1337 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1338 |
theReceiver := theReceiver receiver. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1339 |
theByteCode := optByteCode. |
140 | 1340 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1341 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1342 |
theArg notNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1343 |
theArg codeOn:aStream inBlock:b for:aCompiler |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1344 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1345 |
aStream nextPut:theByteCode. |
140 | 1346 |
|
1347 |
] ifFalse:[ |
|
1348 |
"org" |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1349 |
theReceiver codeInlineOn:aStream inBlock:b for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1350 |
(selector == #ifTrue:) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1351 |
jmp := #falseJump |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1352 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1353 |
jmp := #trueJump |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1354 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1355 |
aStream nextPut:jmp |
140 | 1356 |
]. |
1357 |
pos2 := aStream position. |
|
1358 |
aStream nextPut:0. |
|
1359 |
(selector == #ifTrue:) ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1360 |
(aStream contents) at:pos1 put:(aStream position) |
140 | 1361 |
]. |
1362 |
(argArray at: 1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
1363 |
||
1364 |
code := aStream contents. |
|
1365 |
valueNeeded ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1366 |
aStream nextPut:#jump. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1367 |
pos3 := aStream position. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1368 |
aStream nextPut:0. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1369 |
here := aStream position. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1370 |
(selector == #ifFalse:) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1371 |
code at:pos1 put:here |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1372 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1373 |
code at:pos2 put:here. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1374 |
aStream nextPut:#pushNil. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1375 |
code at:pos3 put:(aStream position) |
140 | 1376 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1377 |
here := aStream position. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1378 |
(selector == #ifFalse:) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1379 |
code at:pos1 put:here |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1380 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1381 |
code at:pos2 put:here |
140 | 1382 |
] |
434
c48a356d8a34
oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents:
429
diff
changeset
|
1383 |
|
c48a356d8a34
oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents:
429
diff
changeset
|
1384 |
"Modified: 9.11.1996 / 19:52:26 / cg" |
140 | 1385 |
! |
1386 |
||
289 | 1387 |
codeOrOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
1388 |
"generate code for (x or:[y])" |
|
1389 |
||
1390 |
|pos1 rightExpr| |
|
1391 |
||
1392 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
|
1393 |
valueNeeded ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1394 |
aStream nextPut:#dup. |
289 | 1395 |
]. |
1396 |
aStream nextPut:#trueJump. |
|
1397 |
pos1 := aStream position. |
|
1398 |
aStream nextPut:0. |
|
1399 |
valueNeeded ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1400 |
aStream nextPut:#drop. |
289 | 1401 |
]. |
1402 |
rightExpr := argArray at:1. |
|
1403 |
rightExpr codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler. |
|
1404 |
||
1405 |
(aStream contents) at:pos1 put:(aStream position) |
|
1406 |
||
1407 |
"Created: 17.6.1996 / 15:40:22 / cg" |
|
1408 |
"Modified: 17.6.1996 / 15:47:22 / cg" |
|
1409 |
! |
|
1410 |
||
436 | 1411 |
codeQuestOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
627 | 1412 |
"generate code for x ? y. |
1413 |
However, this is only done for non-send args." |
|
436 | 1414 |
|
1415 |
|pos code| |
|
1416 |
||
1417 |
receiver codeOn:aStream inBlock:b for:aCompiler. |
|
1418 |
aStream nextPut:#dup. |
|
1419 |
aStream nextPut:#notNilJump. |
|
1420 |
pos := aStream position. |
|
437 | 1421 |
aStream nextPut:0. |
436 | 1422 |
|
1423 |
aStream nextPut:#drop. |
|
1424 |
(argArray at: 1) codeOn:aStream inBlock:b for:aCompiler. |
|
1425 |
||
1426 |
code := aStream contents. |
|
1427 |
code at:pos put:(aStream position) |
|
1428 |
||
627 | 1429 |
"Created: / 10.11.1996 / 18:28:57 / cg" |
1430 |
"Modified: / 28.10.1997 / 18:16:20 / cg" |
|
436 | 1431 |
! |
1432 |
||
602 | 1433 |
codeRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
1434 |
"generate code for [ ... ] repeat" |
|
1435 |
||
1436 |
|pos| |
|
1437 |
||
1438 |
pos := aStream position. |
|
1439 |
receiver codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler. |
|
1440 |
aStream nextPut:#jump; nextPut:pos. |
|
1441 |
||
1442 |
"Created: 29.8.1997 / 08:14:58 / cg" |
|
1443 |
! |
|
1444 |
||
104 | 1445 |
codeSendOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
0 | 1446 |
"like code on, but assumes that receiver has already been |
1447 |
coded onto stack - needed for cascade" |
|
1448 |
||
189
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
1449 |
|nargs isBuiltIn code codeL litIndex cls clsLitIndex| |
0 | 1450 |
|
1451 |
argArray isNil ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1452 |
nargs := 0 |
0 | 1453 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1454 |
nargs := argArray size |
0 | 1455 |
]. |
1456 |
||
1457 |
isBuiltIn := false. |
|
1458 |
||
1459 |
(nargs == 0) ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1460 |
isBuiltIn := aCompiler isBuiltInUnarySelector:selector forReceiver:receiver |
0 | 1461 |
]. |
1462 |
(nargs == 1) ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1463 |
isBuiltIn := aCompiler isBuiltIn1ArgSelector:selector forReceiver:receiver |
0 | 1464 |
]. |
1465 |
(nargs == 2) ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1466 |
isBuiltIn := aCompiler isBuiltIn2ArgSelector:selector forReceiver:receiver |
0 | 1467 |
]. |
1468 |
||
1469 |
"can we use a send-bytecode ?" |
|
1470 |
isBuiltIn ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1471 |
receiver isSuper ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1472 |
(nargs > 0) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1473 |
(argArray at:1) codeOn:aStream inBlock:b for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1474 |
(nargs > 1) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1475 |
(argArray at:2) codeOn:aStream inBlock:b for:aCompiler |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1476 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1477 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1478 |
aStream nextPut:selector. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1479 |
(aCompiler hasLineNumber:selector) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1480 |
aStream nextPut:lineNr. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1481 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1482 |
valueNeeded ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1483 |
aStream nextPut:#drop |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1484 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1485 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1486 |
] |
0 | 1487 |
]. |
1488 |
||
1489 |
argArray notNil ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1490 |
argArray do:[:arg | |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1491 |
arg codeOn:aStream inBlock:b for:aCompiler |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1492 |
] |
0 | 1493 |
]. |
1494 |
||
48 | 1495 |
receiver isSuper ifTrue:[ |
189
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
1496 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1497 |
cls := aCompiler targetClass. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1498 |
receiver isHere ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1499 |
code := #hereSend. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1500 |
codeL := #hereSendL |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1501 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1502 |
code := #superSend. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1503 |
codeL := #superSend. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1504 |
cls := cls superclass. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1505 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1506 |
clsLitIndex := aCompiler addLiteral:cls. |
189
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
1507 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1508 |
litIndex := aCompiler addLiteral:selector. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1509 |
(litIndex <= 255 and:[clsLitIndex <= 255]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1510 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs; nextPut:clsLitIndex. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1511 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1512 |
aStream nextPut:codeL; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs; nextPut:clsLitIndex; nextPut:0. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1513 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1514 |
valueNeeded ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1515 |
aStream nextPut:#drop |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1516 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1517 |
^ self |
0 | 1518 |
]. |
1519 |
(nargs == 0) ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1520 |
(selector == #yourself) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1521 |
"yourself is often added to get the receiver - |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1522 |
we get it without the yourself-message" |
0 | 1523 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1524 |
valueNeeded ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1525 |
aStream nextPut:#drop |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1526 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1527 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1528 |
]. |
49 | 1529 |
]. |
0 | 1530 |
|
117 | 1531 |
litIndex := aCompiler addLiteral:selector. |
1532 |
litIndex <= 255 ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1533 |
(nargs <= 3) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1534 |
valueNeeded ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1535 |
code := #(send0 send1 send2 send3) at:(nargs+1). |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1536 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1537 |
code := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3) at:(nargs+1). |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1538 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1539 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1540 |
^ self |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1541 |
]. |
106 | 1542 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1543 |
valueNeeded ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1544 |
code := #send |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1545 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1546 |
code := #sendDrop |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1547 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1548 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1549 |
^ self |
0 | 1550 |
]. |
49 | 1551 |
|
0 | 1552 |
valueNeeded ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1553 |
code := #sendL |
0 | 1554 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1555 |
code := #sendDropL |
0 | 1556 |
]. |
117 | 1557 |
aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs |
189
673580572edd
fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents:
186
diff
changeset
|
1558 |
|
253
759ba0ddb672
oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents:
245
diff
changeset
|
1559 |
"Modified: 17.4.1996 / 22:33:35 / cg" |
0 | 1560 |
! |
1561 |
||
140 | 1562 |
codeTimesRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
1563 |
"generate code for n timesRepeat:[ ... ]" |
|
1564 |
||
349
7632e597a3df
no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
1565 |
|pos pos2 theReceiver lateEval| |
140 | 1566 |
|
1567 |
theReceiver := receiver. |
|
1568 |
theReceiver 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
|
1569 |
|
7632e597a3df
no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
1570 |
lateEval := false. |
528
0a35ed44989f
oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents:
437
diff
changeset
|
1571 |
|
349
7632e597a3df
no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
1572 |
valueNeeded ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1573 |
"/ easily reconstructable - no need to keep on stack |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1574 |
theReceiver isConstant ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1575 |
(theReceiver evaluate isMemberOf:SmallInteger) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1576 |
lateEval := true. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1577 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1578 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1579 |
lateEval ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1580 |
aStream nextPut:#dup |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1581 |
]. |
349
7632e597a3df
no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
1582 |
]. |
96 | 1583 |
|
140 | 1584 |
pos := aStream position. |
1585 |
aStream nextPut:#pushgt0; nextPut:lineNr; nextPut:#falseJump. |
|
1586 |
pos2 := aStream position. |
|
1587 |
aStream nextPut:0. |
|
1588 |
||
1589 |
(argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler. |
|
1590 |
aStream nextPut:#minus1; nextPut:lineNr; nextPut:#jump; nextPut:pos. |
|
1591 |
||
1592 |
(aStream contents) at:pos2 put:(aStream position). |
|
528
0a35ed44989f
oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents:
437
diff
changeset
|
1593 |
aStream nextPut:#drop. "/ drop run variable |
349
7632e597a3df
no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
1594 |
lateEval ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1595 |
theReceiver 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
|
1596 |
] |
7632e597a3df
no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
1597 |
|
528
0a35ed44989f
oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents:
437
diff
changeset
|
1598 |
"Modified: 27.5.1997 / 14:28:49 / cg" |
140 | 1599 |
! |
1600 |
||
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1601 |
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
|
1602 |
"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
|
1603 |
|
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1604 |
|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
|
1605 |
stepVal stopVarIndex| |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1606 |
|
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1607 |
"/ 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
|
1608 |
"/ 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
|
1609 |
"/ 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
|
1610 |
"/ 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
|
1611 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1612 |
start := receiver. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1613 |
stop := (argArray at:1). |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1614 |
step := (argArray at:2). |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1615 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1616 |
"/ 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
|
1617 |
"/ (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
|
1618 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1619 |
step 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
|
1620 |
stepVal := step evaluate. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1621 |
(stepVal isMemberOf:SmallInteger) ifFalse:[self halt:'should not happen']. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1622 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1623 |
start codeOn:aStream inBlock:b for:aCompiler. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1624 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1625 |
lateEval := false. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1626 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1627 |
valueNeeded ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1628 |
"/ easily reconstructable - no need to keep on stack |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1629 |
start isConstant ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1630 |
(start evaluate isMemberOf:SmallInteger) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1631 |
lateEval := true. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1632 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1633 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1634 |
lateEval ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1635 |
aStream nextPut:#dup |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1636 |
]. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1637 |
]. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1638 |
|
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1639 |
"/ 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
|
1640 |
"/ 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
|
1641 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1642 |
(stop isConstant and:[stop type == #Integer]) ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1643 |
"/ a method/blockArg is constant as well ... |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1644 |
(stop isVariable and:[stop isArgument]) ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1645 |
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
|
1646 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1647 |
b isNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1648 |
stopVarIndex := aCompiler addTempVar. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1649 |
aStream nextPut:#storeMethodVar; nextPut:stopVarIndex. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1650 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1651 |
stopVarIndex := b addTempVar. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1652 |
aStream nextPut:#storeBlockVar; nextPut:stopVarIndex. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1653 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1654 |
] |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1655 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1656 |
|
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1657 |
pos := aStream position. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1658 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1659 |
aStream nextPut:#dup. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1660 |
stopVarIndex notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1661 |
b isNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1662 |
aStream nextPut:#pushMethodVar; nextPut:stopVarIndex. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1663 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1664 |
aStream nextPut:#pushBlockVar; nextPut:stopVarIndex. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1665 |
] |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1666 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1667 |
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
|
1668 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1669 |
stepVal > 0 ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1670 |
aStream nextPut:#>. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1671 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1672 |
aStream nextPut:#<. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1673 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1674 |
(aCompiler hasLineNumber:selector) ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1675 |
aStream nextPut:lineNr. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1676 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1677 |
aStream nextPut:#trueJump. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1678 |
pos2 := aStream position. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1679 |
aStream nextPut:0. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1680 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1681 |
theBlock := argArray at:3. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1682 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1683 |
"/ 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
|
1684 |
"/ the loop ... |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1685 |
b isNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1686 |
loopVarIndex := aCompiler addTempVar. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1687 |
aStream nextPut:#dup. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1688 |
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
|
1689 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1690 |
loopVarIndex := b addTempVar. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1691 |
aStream nextPut:#dup. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1692 |
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
|
1693 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1694 |
theBlock indexOfFirstTemp:loopVarIndex. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1695 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1696 |
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
|
1697 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1698 |
"/ increment/decrement counter & jump back. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1699 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1700 |
stepVal == 1 ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1701 |
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
|
1702 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1703 |
stepVal == -1 ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1704 |
aStream nextPut:#minus1; nextPut:lineNr. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1705 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1706 |
step codeOn:aStream inBlock:b for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1707 |
aStream nextPut:#+. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1708 |
(aCompiler hasLineNumber:#+) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1709 |
aStream nextPut:lineNr. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1710 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1711 |
] |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1712 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1713 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1714 |
aStream nextPut:#jump; nextPut:pos. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1715 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1716 |
(aStream contents) at:pos2 put:(aStream position). |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1717 |
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
|
1718 |
lateEval ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1719 |
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
|
1720 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1721 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1722 |
"/ 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
|
1723 |
"/ (its integer, anyway). |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1724 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1725 |
b isNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1726 |
aCompiler removeTempVar |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1727 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1728 |
b removeTempVar |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1729 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1730 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1731 |
stopVarIndex notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1732 |
b isNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1733 |
aCompiler removeTempVar |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1734 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1735 |
b removeTempVar |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1736 |
] |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1737 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1738 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1739 |
"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
|
1740 |
"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
|
1741 |
! |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1742 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1743 |
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
|
1744 |
"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
|
1745 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1746 |
|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
|
1747 |
stopVarIndex| |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1748 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1749 |
"/ 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
|
1750 |
"/ 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
|
1751 |
"/ 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
|
1752 |
"/ 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
|
1753 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1754 |
start := receiver. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1755 |
stop := (argArray at:1). |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1756 |
"/ 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
|
1757 |
"/ (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
|
1758 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1759 |
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
|
1760 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1761 |
lateEval := false. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1762 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1763 |
valueNeeded ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1764 |
"/ easily reconstructable - no need to keep on stack |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1765 |
start isConstant ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1766 |
(start evaluate isMemberOf:SmallInteger) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1767 |
lateEval := true. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1768 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1769 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1770 |
lateEval ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1771 |
aStream nextPut:#dup |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1772 |
]. |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1773 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1774 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1775 |
"/ 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
|
1776 |
"/ 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
|
1777 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1778 |
(stop isConstant and:[stop type == #Integer]) ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1779 |
"/ a method/blockArg is constant as well ... |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1780 |
(stop isVariable and:[stop isArgument]) ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1781 |
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
|
1782 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1783 |
b isNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1784 |
stopVarIndex := aCompiler addTempVar. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1785 |
aStream nextPut:#storeMethodVar; nextPut:stopVarIndex. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1786 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1787 |
stopVarIndex := b addTempVar. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1788 |
aStream nextPut:#storeBlockVar; nextPut:stopVarIndex. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1789 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1790 |
] |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1791 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1792 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1793 |
pos := aStream position. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1794 |
|
624 | 1795 |
aStream nextPut:#lineno; nextPut:lineNr. |
1796 |
||
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1797 |
aStream nextPut:#dup. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1798 |
stopVarIndex notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1799 |
b isNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1800 |
aStream nextPut:#pushMethodVar; nextPut:stopVarIndex. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1801 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1802 |
aStream nextPut:#pushBlockVar; nextPut:stopVarIndex. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1803 |
] |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1804 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1805 |
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
|
1806 |
]. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1807 |
aStream nextPut:#>. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1808 |
(aCompiler hasLineNumber:selector) ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1809 |
aStream nextPut:lineNr. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1810 |
]. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1811 |
aStream nextPut:#trueJump. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1812 |
pos2 := aStream position. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1813 |
aStream nextPut:0. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1814 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1815 |
theBlock := argArray at:2. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1816 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1817 |
"/ 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
|
1818 |
"/ the loop ... |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1819 |
b isNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1820 |
loopVarIndex := aCompiler addTempVar. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1821 |
aStream nextPut:#dup. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1822 |
aStream nextPut:#storeMethodVar; nextPut:loopVarIndex. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1823 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1824 |
loopVarIndex := b addTempVar. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1825 |
aStream nextPut:#dup. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1826 |
aStream nextPut:#storeBlockVar; nextPut:loopVarIndex. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1827 |
]. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1828 |
theBlock indexOfFirstTemp:loopVarIndex. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1829 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1830 |
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
|
1831 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1832 |
"/ increment counter & jump back. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1833 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1834 |
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
|
1835 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1836 |
(aStream contents) at:pos2 put:(aStream position). |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1837 |
aStream nextPut:#drop. "/ drop run variable |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1838 |
lateEval ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1839 |
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
|
1840 |
]. |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1841 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1842 |
"/ 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
|
1843 |
"/ (its integer, anyway). |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1844 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1845 |
b isNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1846 |
aCompiler removeTempVar |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1847 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1848 |
b removeTempVar |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1849 |
]. |
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1850 |
|
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1851 |
stopVarIndex notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1852 |
b isNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1853 |
aCompiler removeTempVar |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1854 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1855 |
b removeTempVar |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1856 |
] |
565
00673e9d6edc
more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
1857 |
]. |
561
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1858 |
|
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1859 |
"Created: 26.6.1997 / 10:58:47 / cg" |
624 | 1860 |
"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
|
1861 |
! |
19279079cc9a
inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents:
552
diff
changeset
|
1862 |
|
140 | 1863 |
codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
200
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1864 |
"generate code for |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1865 |
[...] whileXXX:[ ... ] |
200
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1866 |
and also |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1867 |
[...] whileXXX |
200
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1868 |
" |
140 | 1869 |
|
200
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1870 |
|pos pos2 theReceiver theArg theByteCode optByteCode needLineNr blockExpr |
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
1871 |
hasLoopBlock fastReceiver| |
0 | 1872 |
|
200
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1873 |
hasLoopBlock := true. |
140 | 1874 |
(selector == #whileTrue:) ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1875 |
theByteCode := #falseJump. |
0 | 1876 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1877 |
(selector == #whileFalse:) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1878 |
theByteCode := #trueJump |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1879 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1880 |
hasLoopBlock := false. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1881 |
(selector == #whileTrue) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1882 |
theByteCode := #trueJump |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1883 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1884 |
theByteCode := #falseJump |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1885 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1886 |
] |
140 | 1887 |
]. |
1888 |
||
1889 |
theReceiver := receiver. |
|
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
1890 |
|
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
1891 |
(receiver isBlock |
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
1892 |
and:[receiver statements notNil |
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
1893 |
and:[receiver statements nextStatement isNil |
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
1894 |
and:[receiver statements expression notNil]]]) |
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
1895 |
ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1896 |
fastReceiver := receiver statements expression. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1897 |
optByteCode := self optimizedConditionFor:fastReceiver with:theByteCode. |
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
1898 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1899 |
optByteCode := self optimizedConditionFor:theReceiver with:theByteCode. |
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
1900 |
]. |
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
1901 |
|
140 | 1902 |
optByteCode notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1903 |
((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1904 |
theArg := receiver statements expression arg1 |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1905 |
]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1906 |
theReceiver := receiver statements expression receiver. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1907 |
theByteCode := optByteCode |
140 | 1908 |
]. |
1909 |
||
1910 |
"/ OLD: |
|
1911 |
"/ valueNeeded ifTrue:[aStream nextPut:#pushNil]. |
|
1912 |
"/ |
|
167 | 1913 |
needLineNr := true. |
1914 |
||
140 | 1915 |
pos := aStream position. |
386 | 1916 |
|
389
8aa5f9f08139
care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
1917 |
"/ aCompiler lineNumberInfo == #full ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1918 |
ParseNode codeLineNumber:lineNr on:aStream for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1919 |
needLineNr := false. |
389
8aa5f9f08139
care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
1920 |
"/ ]. |
386 | 1921 |
|
140 | 1922 |
optByteCode notNil ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1923 |
theReceiver codeOn:aStream inBlock:b for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1924 |
theArg notNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1925 |
theArg codeOn:aStream inBlock:b for:aCompiler |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1926 |
] |
140 | 1927 |
] ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1928 |
fastReceiver notNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1929 |
theByteCode == #trueJump ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1930 |
fastReceiver isConstant ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1931 |
fastReceiver evaluate == true ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1932 |
theByteCode := #jump |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1933 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1934 |
fastReceiver evaluate == false ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1935 |
theByteCode := #never |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1936 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1937 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1938 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1939 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1940 |
theByteCode == #falseJump ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1941 |
fastReceiver isConstant ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1942 |
fastReceiver evaluate == false ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1943 |
theByteCode := #jump |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1944 |
] ifFalse:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1945 |
fastReceiver evaluate == true ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1946 |
theByteCode := #never |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1947 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1948 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1949 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1950 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1951 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1952 |
]. |
167 | 1953 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1954 |
(theByteCode ~~ #jump |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1955 |
and:[theByteCode ~~ #never]) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1956 |
theReceiver codeInlineOn:aStream inBlock:b for:aCompiler. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1957 |
]. |
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
1958 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1959 |
"/ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1960 |
"/ cannot enable code below |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1961 |
"/ (tiny loops would not be debuggable with next, since lineNo remains the same) |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1962 |
"/ think about it ... |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1963 |
"/ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1964 |
blockExpr := theReceiver simpleSendBlockExpression. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1965 |
blockExpr notNil ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1966 |
blockExpr isMessage ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1967 |
(aCompiler hasLineNumber:(blockExpr selector)) ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1968 |
blockExpr lineNumber == lineNr ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1969 |
needLineNr := false |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1970 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1971 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1972 |
] |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1973 |
]. |
140 | 1974 |
]. |
1975 |
||
167 | 1976 |
needLineNr ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1977 |
ParseNode codeLineNumber:lineNr on:aStream for:aCompiler. |
0 | 1978 |
]. |
1979 |
||
200
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1980 |
hasLoopBlock ifFalse:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1981 |
"/ simple [...] whileXXX |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1982 |
theByteCode ~~ #never ifTrue:[ |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1983 |
aStream nextPut:theByteCode; nextPut:pos. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1984 |
]. |
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
1985 |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1986 |
valueNeeded ifTrue:[aStream nextPut:#pushNil]. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1987 |
^ self |
200
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1988 |
]. |
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1989 |
|
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1990 |
"/ [...] whileXXX:[...] |
b2f77bd77070
inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
1991 |
|
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
1992 |
theByteCode ~~ #never ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1993 |
aStream nextPut:theByteCode. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1994 |
pos2 := aStream position. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
1995 |
aStream nextPut:0. |
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
1996 |
]. |
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
1997 |
|
140 | 1998 |
(argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler. |
1999 |
aStream nextPut:#jump; nextPut:pos. |
|
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2000 |
theByteCode ~~ #never ifTrue:[ |
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
2001 |
(aStream contents) at:pos2 put:(aStream position). |
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2002 |
]. |
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2003 |
|
140 | 2004 |
valueNeeded ifTrue:[aStream nextPut:#pushNil]. |
167 | 2005 |
|
389
8aa5f9f08139
care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents:
386
diff
changeset
|
2006 |
"Modified: 22.10.1996 / 21:34:37 / cg" |
140 | 2007 |
! |
2008 |
||
2009 |
optimizedConditionFor:aReceiver with:aByteCode |
|
186 | 2010 |
|rec sel stats| |
0 | 2011 |
|
140 | 2012 |
rec := aReceiver. |
2013 |
(rec isBlock) ifTrue:[ |
|
186 | 2014 |
(stats := rec statements) notNil ifTrue:[ |
2015 |
stats nextStatement isNil ifTrue:[ |
|
2016 |
rec := rec statements expression |
|
2017 |
] |
|
140 | 2018 |
] |
2019 |
]. |
|
2020 |
(rec isUnaryMessage) ifTrue:[ |
|
2021 |
sel := rec selector. |
|
2022 |
(sel == #isNil) ifTrue:[ |
|
2023 |
"/ |
|
2024 |
"/ isNil trueJmp -> nilJump |
|
2025 |
"/ isNil falseJmp -> notNilJump |
|
2026 |
"/ |
|
2027 |
(aByteCode == #trueJump) ifTrue:[^ #nilJump]. |
|
2028 |
(aByteCode == #falseJump) ifTrue:[^ #notNilJump] |
|
2029 |
]. |
|
2030 |
(sel == #notNil) ifTrue:[ |
|
2031 |
"/ |
|
2032 |
"/ notNil trueJmp -> notNilJump |
|
2033 |
"/ notNil falseJmp -> nilJump |
|
2034 |
"/ |
|
2035 |
(aByteCode == #trueJump) ifTrue:[^ #notNilJump]. |
|
2036 |
(aByteCode == #falseJump) ifTrue:[^ #nilJump] |
|
2037 |
]. |
|
2038 |
(sel == #not) ifTrue:[ |
|
2039 |
"/ |
|
2040 |
"/ not trueJmp -> falseJump |
|
2041 |
"/ not falseJmp -> trueJump |
|
2042 |
"/ |
|
2043 |
(aByteCode == #trueJump) ifTrue:[^ #falseJump]. |
|
2044 |
(aByteCode == #falseJump) ifTrue:[^ #trueJump] |
|
2045 |
]. |
|
2046 |
^ nil |
|
0 | 2047 |
]. |
140 | 2048 |
(rec isBinaryMessage) ifTrue:[ |
2049 |
sel := rec selector. |
|
2050 |
rec arg1 isConstant ifTrue:[ |
|
2051 |
(rec arg1 value == 0) ifTrue:[ |
|
2052 |
"/ |
|
2053 |
"/ ==0 trueJmp -> zeroJump |
|
2054 |
"/ ==0 falseJmp -> notZeroJump |
|
2055 |
"/ |
|
2056 |
(sel == #==) ifTrue:[ |
|
2057 |
(aByteCode == #trueJump) ifTrue:[^ #zeroJump]. |
|
2058 |
(aByteCode == #falseJump) ifTrue:[^ #notZeroJump] |
|
2059 |
]. |
|
2060 |
"/ |
|
2061 |
"/ ~~0 trueJmp -> notZeroJump |
|
2062 |
"/ ~~0 falseJmp -> zeroJump |
|
2063 |
"/ |
|
2064 |
(sel == #~~) ifTrue:[ |
|
2065 |
(aByteCode == #falseJump) ifTrue:[^ #zeroJump]. |
|
2066 |
(aByteCode == #trueJump) ifTrue:[^ #notZeroJump] |
|
2067 |
]. |
|
2068 |
^ nil |
|
2069 |
] |
|
2070 |
]. |
|
2071 |
(sel == #==) ifTrue:[ |
|
2072 |
"/ |
|
2073 |
"/ == trueJmp -> eqJump |
|
2074 |
"/ == falseJmp -> notEqJump |
|
2075 |
"/ |
|
2076 |
(aByteCode == #trueJump) ifTrue:[^ #eqJump]. |
|
2077 |
(aByteCode == #falseJump) ifTrue:[^ #notEqJump] |
|
2078 |
]. |
|
2079 |
(sel == #~~) ifTrue:[ |
|
2080 |
"/ |
|
2081 |
"/ ~~ trueJmp -> notEqJump |
|
2082 |
"/ ~~ falseJmp -> eqJump |
|
2083 |
"/ |
|
2084 |
(aByteCode == #falseJump) ifTrue:[^ #eqJump]. |
|
2085 |
(aByteCode == #trueJump) ifTrue:[^ #notEqJump] |
|
2086 |
] |
|
2087 |
]. |
|
2088 |
^ nil |
|
2089 |
! ! |
|
2090 |
||
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
537
diff
changeset
|
2091 |
!MessageNode methodsFor:'enumeration'! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
537
diff
changeset
|
2092 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
537
diff
changeset
|
2093 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
537
diff
changeset
|
2094 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
537
diff
changeset
|
2095 |
|
543
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
2096 |
|args| |
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
2097 |
|
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
2098 |
args := argArray ? #(). |
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
2099 |
^ anEnumerator doMessage:self receiver:receiver selector:selector arguments:args |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
537
diff
changeset
|
2100 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
537
diff
changeset
|
2101 |
"Created: 19.6.1997 / 16:46:39 / cg" |
543
de47f8969fd9
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
2102 |
"Modified: 19.6.1997 / 17:08:28 / cg" |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
537
diff
changeset
|
2103 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
537
diff
changeset
|
2104 |
|
140 | 2105 |
!MessageNode methodsFor:'evaluating'! |
2106 |
||
2107 |
evaluate |
|
2108 |
|r nargs argValueArray class| |
|
2109 |
||
2110 |
receiver isSuper ifTrue:[ |
|
2111 |
r := receiver value. |
|
2112 |
receiver isHere ifTrue:[ |
|
2113 |
class := receiver definingClass. |
|
2114 |
] ifFalse:[ |
|
2115 |
class := receiver definingClass superclass. |
|
2116 |
]. |
|
2117 |
argArray notNil ifTrue:[ |
|
2118 |
argValueArray := argArray collect:[:arg | arg evaluate]. |
|
2119 |
] ifFalse:[ |
|
2120 |
argValueArray := #() |
|
2121 |
]. |
|
2122 |
^ r perform:selector inClass:class withArguments:argValueArray |
|
2123 |
]. |
|
2124 |
||
2125 |
||
2126 |
argArray isNil ifTrue:[ |
|
2127 |
^ (receiver evaluate) perform:selector |
|
2128 |
]. |
|
2129 |
nargs := argArray size. |
|
0 | 2130 |
(nargs == 1) ifTrue:[ |
140 | 2131 |
^ (receiver evaluate) perform:selector with:(argArray at:1) evaluate |
0 | 2132 |
]. |
2133 |
(nargs == 2) ifTrue:[ |
|
140 | 2134 |
^ (receiver evaluate) perform:selector |
2135 |
with:(argArray at:1) evaluate |
|
2136 |
with:(argArray at:2) evaluate |
|
2137 |
]. |
|
2138 |
(nargs == 3) ifTrue:[ |
|
2139 |
^ (receiver evaluate) perform:selector |
|
2140 |
with:(argArray at:1) evaluate |
|
2141 |
with:(argArray at:2) evaluate |
|
2142 |
with:(argArray at:3) evaluate |
|
2143 |
]. |
|
2144 |
r := receiver evaluate. |
|
2145 |
argValueArray := argArray collect:[:arg | arg evaluate]. |
|
2146 |
^ r perform:selector withArguments:argValueArray |
|
2147 |
! |
|
2148 |
||
2149 |
evaluateForCascade |
|
2150 |
|r nargs argValueArray class| |
|
2151 |
||
2152 |
receiver isSuper ifTrue:[ |
|
2153 |
r := receiver value. |
|
2154 |
class := receiver definingClass. |
|
2155 |
receiver isHere ifFalse:[ |
|
2156 |
class := class superclass. |
|
2157 |
]. |
|
2158 |
argArray notNil ifTrue:[ |
|
2159 |
argValueArray := argArray collect:[:arg | arg evaluate]. |
|
2160 |
] ifFalse:[ |
|
2161 |
argValueArray := #() |
|
2162 |
]. |
|
2163 |
r perform:selector inClass:class withArguments:argValueArray. |
|
2164 |
^ r |
|
0 | 2165 |
]. |
2166 |
||
140 | 2167 |
r := receiver evaluate. |
2168 |
argArray isNil ifTrue:[ |
|
2169 |
r perform:selector. |
|
2170 |
^ r |
|
2171 |
]. |
|
2172 |
nargs := argArray size. |
|
2173 |
(nargs == 1) ifTrue:[ |
|
2174 |
r perform:selector with:(argArray at:1) evaluate. |
|
2175 |
^ r |
|
2176 |
]. |
|
2177 |
(nargs == 2) ifTrue:[ |
|
2178 |
r perform:selector with:(argArray at:1) evaluate |
|
2179 |
with:(argArray at:2) evaluate. |
|
2180 |
^ r |
|
2181 |
]. |
|
2182 |
(nargs == 3) ifTrue:[ |
|
2183 |
r perform:selector with:(argArray at:1) evaluate |
|
2184 |
with:(argArray at:2) evaluate |
|
2185 |
with:(argArray at:3) evaluate. |
|
2186 |
^ r |
|
2187 |
]. |
|
2188 |
argValueArray := argArray collect:[:arg | arg evaluate]. |
|
2189 |
r perform:selector withArguments:argValueArray. |
|
2190 |
^ r |
|
2191 |
! ! |
|
2192 |
||
2193 |
!MessageNode methodsFor:'printing'! |
|
2194 |
||
2195 |
printOn:aStream indent:i |
|
2196 |
|needParen selectorParts index index2 arg| |
|
2197 |
||
2198 |
(#(whileTrue: whileFalse:) includes:selector) ifTrue:[ |
|
2199 |
receiver isBlock ifTrue:[ |
|
2200 |
^ self printWhileOn:aStream indent:i |
|
2201 |
]. |
|
2202 |
]. |
|
0 | 2203 |
|
140 | 2204 |
index := 1. |
2205 |
selectorParts := OrderedCollection new. |
|
2206 |
[index == 0] whileFalse:[ |
|
2207 |
index2 := selector indexOf:$: startingAt:index. |
|
2208 |
index2 ~~ 0 ifTrue:[ |
|
2209 |
selectorParts add:(selector copyFrom:index to:index2). |
|
2210 |
index2 := index2 + 1 |
|
2211 |
]. |
|
2212 |
index := index2 |
|
2213 |
]. |
|
2214 |
||
2215 |
needParen := false. |
|
2216 |
receiver isMessage ifTrue:[ |
|
2217 |
receiver isUnaryMessage ifFalse:[ |
|
2218 |
receiver isBinaryMessage ifFalse:[ |
|
2219 |
needParen := true |
|
2220 |
]. |
|
2221 |
]. |
|
2222 |
]. |
|
2223 |
needParen ifTrue:[ |
|
2224 |
aStream nextPutAll:'(' |
|
2225 |
]. |
|
2226 |
receiver printOn:aStream indent:i. |
|
2227 |
needParen ifTrue:[ |
|
2228 |
aStream nextPutAll:')' |
|
2229 |
]. |
|
2230 |
||
2231 |
1 to:(argArray size) do:[:argIndex | |
|
2232 |
aStream space. |
|
2233 |
(selectorParts at:argIndex) printOn:aStream. |
|
2234 |
aStream space. |
|
2235 |
arg := argArray at:argIndex. |
|
2236 |
needParen := false. |
|
2237 |
arg isMessage ifTrue:[ |
|
2238 |
arg isBinaryMessage ifFalse:[ |
|
2239 |
arg isUnaryMessage ifFalse:[ |
|
2240 |
needParen := true |
|
47 | 2241 |
] |
2242 |
]. |
|
140 | 2243 |
]. |
2244 |
needParen ifTrue:[ |
|
2245 |
aStream nextPutAll:'(' |
|
2246 |
]. |
|
2247 |
arg printOn:aStream indent:i. |
|
2248 |
needParen ifTrue:[ |
|
2249 |
aStream nextPutAll:') ' |
|
2250 |
]. |
|
2251 |
] |
|
2252 |
! |
|
2253 |
||
2254 |
printWhileOn:aStream indent:i |
|
2255 |
|needParen arg| |
|
0 | 2256 |
|
140 | 2257 |
"special handling of whileTrue/whileFalse" |
2258 |
||
2259 |
aStream nextPutAll:'['. |
|
2260 |
receiver statements printOn:aStream indent:i. |
|
2261 |
aStream nextPutAll:'] whileTrue: '. |
|
2262 |
||
2263 |
arg := argArray at:1. |
|
2264 |
needParen := false. |
|
2265 |
arg isMessage ifTrue:[ |
|
2266 |
arg isBinaryMessage ifFalse:[ |
|
2267 |
arg isUnaryMessage ifFalse:[ |
|
2268 |
needParen := true |
|
2269 |
] |
|
2270 |
]. |
|
0 | 2271 |
]. |
140 | 2272 |
needParen ifTrue:[ |
2273 |
aStream nextPutAll:'(' |
|
2274 |
]. |
|
2275 |
arg printOn:aStream indent:i. |
|
2276 |
needParen ifTrue:[ |
|
2277 |
aStream nextPutAll:') ' |
|
2278 |
]. |
|
2279 |
! ! |
|
106 | 2280 |
|
140 | 2281 |
!MessageNode methodsFor:'queries'! |
2282 |
||
395 | 2283 |
collectBlocksInto:aCollection |
2284 |
receiver collectBlocksInto:aCollection. |
|
2285 |
argArray size > 0 ifTrue:[ |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
2286 |
argArray do:[:arg | |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
2287 |
arg collectBlocksInto:aCollection. |
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
2288 |
] |
395 | 2289 |
]. |
2290 |
||
2291 |
"Created: 23.10.1996 / 15:44:49 / cg" |
|
2292 |
"Modified: 23.10.1996 / 16:03:46 / cg" |
|
2293 |
! |
|
2294 |
||
140 | 2295 |
isMessage |
2296 |
^ true |
|
0 | 2297 |
! ! |
140 | 2298 |
|
370
09c13380b03b
slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
2299 |
!MessageNode class methodsFor:'documentation'! |
148 | 2300 |
|
2301 |
version |
|
639
f3dce3a697f0
inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents:
627
diff
changeset
|
2302 |
^ '$Header: /cvs/stx/stx/libcomp/MessageNode.st,v 1.84 1998-01-16 15:06:45 cg Exp $' |
148 | 2303 |
! ! |