author | Claus Gittinger <cg@exept.de> |
Thu, 25 Nov 2004 15:30:33 +0100 | |
changeset 1561 | 175735dcd732 |
parent 1513 | 737203071b87 |
child 1566 | e53724995493 |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
45 | 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 |
||
1079 | 13 |
"{ Package: 'stx:libcomp' }" |
14 |
||
0 | 15 |
ParseNode subclass:#BlockNode |
168 | 16 |
instanceVariableNames:'blockArgs statements home inlineBlock exitBlock blockVars |
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
17 |
needsHome lineNr endLineNr blockArgAccessedInBlock numTemp |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
18 |
maxNumTemp indexOfFirstTemp subBlocks accessedOuterBlockVars |
677 | 19 |
possiblyInlined invokationSelector' |
168 | 20 |
classVariableNames:'' |
21 |
poolDictionaries:'' |
|
22 |
category:'System-Compiler-Support' |
|
0 | 23 |
! |
24 |
||
366 | 25 |
!BlockNode class methodsFor:'documentation'! |
20 | 26 |
|
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
45 | 30 |
All Rights Reserved |
0 | 31 |
|
20 | 32 |
This software is furnished under a license and may be used |
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
0 | 40 |
|
20 | 41 |
documentation |
42 |
" |
|
43 |
node for parse-trees, representing blocks |
|
261 | 44 |
This is a helper class for the compiler. |
263 | 45 |
|
46 |
[author:] |
|
47 |
Claus Gittinger |
|
20 | 48 |
" |
49 |
! ! |
|
0 | 50 |
|
366 | 51 |
!BlockNode class methodsFor:'instance creation'! |
0 | 52 |
|
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
53 |
arguments:argList home:homeBlock variables:vars |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
54 |
|newBlock| |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
55 |
|
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
56 |
newBlock := (self basicNew) setArguments:argList home:homeBlock variables:vars. |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
57 |
homeBlock notNil ifTrue:[ |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
58 |
homeBlock rememberSubBlock:newBlock |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
59 |
]. |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
60 |
^ newBlock |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
61 |
|
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
62 |
"Modified: 28.6.1997 / 15:14:45 / cg" |
0 | 63 |
! ! |
64 |
||
65 |
!BlockNode methodsFor:'accessing'! |
|
66 |
||
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
67 |
accessedOuterBlockVars |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
68 |
"return a collection of outer blockVars/args which are accessed |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
69 |
in this block" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
70 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
71 |
^ accessedOuterBlockVars ? #() |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
72 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
73 |
"Modified: 18.6.1997 / 12:06:31 / cg" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
74 |
"Created: 2.7.1997 / 17:29:56 / cg" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
75 |
! |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
76 |
|
0 | 77 |
arguments |
78 |
^ blockArgs |
|
79 |
! |
|
80 |
||
26 | 81 |
arguments:argList |
82 |
blockArgs := argList |
|
83 |
! |
|
84 |
||
534 | 85 |
blockArgAccessed |
86 |
"return true if any block argument is accessed in the block" |
|
87 |
||
88 |
^ blockArgAccessedInBlock ? false |
|
89 |
||
90 |
"Modified: 18.6.1997 / 12:06:31 / cg" |
|
91 |
! |
|
92 |
||
93 |
blockArgAccessed:aBoolen |
|
94 |
"set/clear the flag stating if any block argument is accessed in the block" |
|
95 |
||
96 |
blockArgAccessedInBlock := aBoolen |
|
97 |
||
98 |
"Created: 18.6.1997 / 11:35:00 / cg" |
|
99 |
"Modified: 18.6.1997 / 12:06:43 / cg" |
|
100 |
! |
|
101 |
||
394 | 102 |
endLineNumber |
103 |
^ endLineNr |
|
104 |
||
105 |
"Created: 23.10.1996 / 15:51:32 / cg" |
|
106 |
! |
|
107 |
||
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
108 |
endLineNumber:aNumber |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
109 |
endLineNr := aNumber |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
110 |
|
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
111 |
"Created: 21.10.1996 / 14:17:57 / cg" |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
112 |
! |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
113 |
|
140 | 114 |
home |
115 |
^ home |
|
0 | 116 |
! |
117 |
||
118 |
home:aBlock |
|
119 |
home := aBlock |
|
120 |
! |
|
121 |
||
559 | 122 |
indexOfFirstTemp:index |
123 |
indexOfFirstTemp := index |
|
124 |
||
125 |
"Created: 25.6.1997 / 17:24:27 / cg" |
|
126 |
! |
|
127 |
||
555 | 128 |
inlineBlock:aBoolean |
129 |
inlineBlock := aBoolean |
|
0 | 130 |
! |
131 |
||
677 | 132 |
invokationSelector |
133 |
"return the value of the instance variable 'invokationSelector' (automatically generated)" |
|
134 |
||
135 |
^ invokationSelector |
|
136 |
||
137 |
"Created: / 2.4.1998 / 15:00:06 / cg" |
|
138 |
! |
|
139 |
||
555 | 140 |
isInlineBlock |
141 |
^ inlineBlock |
|
142 |
||
143 |
"Created: 25.6.1997 / 14:11:33 / cg" |
|
0 | 144 |
! |
145 |
||
394 | 146 |
lineNumber |
147 |
^ lineNr |
|
148 |
||
149 |
"Created: 23.10.1996 / 15:51:50 / cg" |
|
150 |
! |
|
151 |
||
140 | 152 |
lineNumber:aNumber |
153 |
lineNr := aNumber |
|
154 |
! |
|
155 |
||
1505 | 156 |
lineNumberOfFirstMessage |
157 |
^ statements lineNumberOfFirstMessage |
|
158 |
||
159 |
"Created: 23.10.1996 / 15:51:50 / cg" |
|
160 |
! |
|
161 |
||
0 | 162 |
needsHome |
163 |
^ needsHome |
|
164 |
! |
|
165 |
||
166 |
needsHome:aBoolean |
|
167 |
needsHome := aBoolean |
|
6 | 168 |
! |
169 |
||
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
170 |
possiblyInlined:aBoolean |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
171 |
possiblyInlined := aBoolean |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
172 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
173 |
"Created: 2.7.1997 / 11:32:00 / cg" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
174 |
! |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
175 |
|
677 | 176 |
possiblyInlined:aBoolean withSelector:selector |
177 |
possiblyInlined := aBoolean. |
|
178 |
invokationSelector := selector. |
|
179 |
||
180 |
"Created: / 2.4.1998 / 19:07:53 / cg" |
|
181 |
! |
|
182 |
||
140 | 183 |
statements |
184 |
^ statements |
|
185 |
! |
|
186 |
||
187 |
statements:s |
|
188 |
statements := s |
|
189 |
! |
|
190 |
||
191 |
variables |
|
192 |
^ blockVars |
|
193 |
! |
|
194 |
||
195 |
variables:varList |
|
196 |
blockVars := varList |
|
197 |
! ! |
|
198 |
||
199 |
!BlockNode methodsFor:'block messages'! |
|
200 |
||
201 |
doesNotUnderstand:aMessage |
|
202 |
|numArgs kludgeBlock| |
|
203 |
||
1251
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
204 |
(Block includesSelector:(aMessage selector)) ifTrue:[ |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
205 |
|
1251
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
206 |
"/ mhmh - a message which I dont understand, but Block implements |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
207 |
"/ send it to a kludgeblock, which will evaluate me again ..." |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
199
diff
changeset
|
208 |
|
1251
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
209 |
numArgs := blockArgs size. |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
210 |
numArgs == 0 ifTrue:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
211 |
kludgeBlock := [self value] |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
212 |
] ifFalse:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
213 |
numArgs == 1 ifTrue:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
214 |
kludgeBlock := [:a1 | self value:a1]. |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
215 |
] ifFalse:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
216 |
numArgs == 2 ifTrue:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
217 |
kludgeBlock := [:a1 :a2 | self value:a1 value:a2]. |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
218 |
] ifFalse:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
219 |
numArgs == 3 ifTrue:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
220 |
kludgeBlock := [:a1 :a2 :a3| self value:a1 value:a2 value:a3]. |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
221 |
] ifFalse:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
222 |
numArgs == 4 ifTrue:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
223 |
kludgeBlock := [:a1 :a2 :a3 :a4| self value:a1 value:a2 value:a3 value:a4]. |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
224 |
] ifFalse:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
225 |
^ self error:'only support blocks with up-to 4 args' |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
226 |
] |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
227 |
] |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
228 |
] |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
229 |
] |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
230 |
]. |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
231 |
^ kludgeBlock perform:aMessage selector withArguments:aMessage arguments |
140 | 232 |
]. |
233 |
^ super doesNotUnderstand:aMessage |
|
0 | 234 |
! ! |
235 |
||
140 | 236 |
!BlockNode methodsFor:'code generation'! |
237 |
||
1401 | 238 |
checkForSimpleBlockCodeOn:aStream for:aCompiler |
140 | 239 |
"simple things can be made cheap blocks right now - |
1305 | 240 |
resulting in a simple pushLit instruction ... |
241 |
Return: |
|
242 |
true -- bytecodes are on aStream |
|
243 |
aParseNode -- Parsenode creating the cheap block |
|
244 |
nil -- cheap block not possible |
|
245 |
" |
|
140 | 246 |
|
1401 | 247 |
|cheapy val isConstRet singleInsn code stackSize| |
140 | 248 |
|
932 | 249 |
isConstRet := false. |
1305 | 250 |
|
140 | 251 |
statements isNil ifTrue:[ |
1305 | 252 |
self numArgs == 0 ifTrue:[ |
253 |
"a []-block" |
|
254 |
aStream nextPut:#mkNilBlock. |
|
255 |
^ true. |
|
256 |
]. |
|
932 | 257 |
val := nil. |
258 |
isConstRet := true. |
|
1401 | 259 |
] ifFalse:[statements isConstant ifTrue:[ |
260 |
val := statements expression value. |
|
261 |
self numArgs == 0 ifTrue:[ |
|
262 |
val == 0 ifTrue:[ |
|
263 |
aStream nextPut:#mk0Block. |
|
264 |
^ true. |
|
265 |
]. |
|
266 |
val isNil ifTrue:[ |
|
267 |
aStream nextPut:#mkNilBlock. |
|
268 |
^ true. |
|
269 |
]. |
|
270 |
]. |
|
271 |
isConstRet := true. |
|
272 |
]]. |
|
140 | 273 |
|
932 | 274 |
isConstRet ifTrue:[ |
275 |
stackSize := 0. |
|
506
3dc049d3a2d7
care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
276 |
|
1305 | 277 |
(val isInteger and:[val between:-128 and:127]) ifTrue:[ |
278 |
"a [-128..127]-block" |
|
279 |
val < 0 ifTrue:[val := val + 256]. |
|
280 |
code := ByteArray with:(ByteCodeCompiler byteCodeFor:#retNum) |
|
281 |
with:val. |
|
282 |
] ifFalse:[val == true ifTrue:[ |
|
283 |
"a [true]-block" |
|
284 |
singleInsn := #retTrue |
|
285 |
] ifFalse:[val == false ifTrue:[ |
|
286 |
"a [false]-block" |
|
287 |
singleInsn := #retFalse |
|
288 |
] ifFalse:[val isNil ifTrue:[ |
|
289 |
"a [nil]-block" |
|
290 |
singleInsn := #retNil |
|
291 |
]]]]. |
|
932 | 292 |
singleInsn notNil ifTrue:[ |
293 |
code := ByteArray with:(ByteCodeCompiler byteCodeFor:singleInsn). |
|
294 |
]. |
|
140 | 295 |
]. |
296 |
||
297 |
code notNil ifTrue:[ |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
298 |
cheapy := CheapBlock |
366 | 299 |
byteCode:code |
300 |
numArgs:(blockArgs size) |
|
1135
7708c6a185a2
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
301 |
numVars:0 |
506
3dc049d3a2d7
care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
302 |
numStack:stackSize |
366 | 303 |
sourcePosition:nil |
304 |
initialPC:nil |
|
305 |
literals:nil. |
|
1305 | 306 |
^ ConstantNode type:#Block value:cheapy. |
140 | 307 |
]. |
308 |
||
309 |
^ nil |
|
366 | 310 |
|
506
3dc049d3a2d7
care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
311 |
"Modified: 13.4.1997 / 00:05:29 / cg" |
140 | 312 |
! |
313 |
||
314 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
315 |
"generate code for this statement - value not needed. |
|
316 |
For blocks, no code is generated at all." |
|
317 |
||
318 |
^ self |
|
319 |
! |
|
320 |
||
321 |
codeInlineOn:aStream inBlock:b for:aCompiler |
|
322 |
self codeInlineOn:aStream inBlock:b valueNeeded:true for:aCompiler |
|
323 |
! |
|
324 |
||
325 |
codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
|
588 | 326 |
|thisStatement nextStatement tmpIndex firstTempIndex codeBlock subAccess| |
140 | 327 |
|
328 |
blockVars notNil ifTrue:[ |
|
559 | 329 |
"/ have to move blockvars into surrounding context |
0 | 330 |
|
559 | 331 |
"/ find the first non-inlined block |
332 |
codeBlock := b. |
|
333 |
[codeBlock notNil and:[codeBlock isInlineBlock]] whileTrue:[ |
|
334 |
codeBlock := codeBlock home. |
|
553 | 335 |
]. |
336 |
||
559 | 337 |
blockVars do:[:aBlockVar | |
338 |
codeBlock isNil ifTrue:[ |
|
339 |
"/ in method - add more temps to the method |
|
340 |
tmpIndex := aCompiler addTempVar. |
|
341 |
] ifFalse:[ |
|
342 |
"/ in another block - add more temps to the block |
|
343 |
tmpIndex := codeBlock addTempVar |
|
344 |
]. |
|
345 |
||
346 |
firstTempIndex isNil ifTrue:[ |
|
347 |
firstTempIndex := tmpIndex. |
|
348 |
indexOfFirstTemp isNil ifTrue:[ |
|
349 |
indexOfFirstTemp := tmpIndex |
|
350 |
]. |
|
351 |
]. |
|
352 |
||
353 |
"/ block vars must be nilled |
|
354 |
"/ (in case the previous block left some value there). |
|
355 |
"/ This nilling should be optimized away, if |
|
356 |
"/ the variable gets a value assigned before the first send. |
|
357 |
||
358 |
aStream nextPut:#pushNil. |
|
359 |
codeBlock isNil ifTrue:[ |
|
360 |
"/ in method |
|
361 |
(tmpIndex <= 6) ifTrue:[ |
|
362 |
aStream nextPut:(#(storeMethodVar1 storeMethodVar2 |
|
363 |
storeMethodVar3 storeMethodVar4 |
|
364 |
storeMethodVar5 storeMethodVar6) at:tmpIndex). |
|
365 |
] ifFalse:[ |
|
366 |
aStream nextPut:#storeMethodVar; nextPut:tmpIndex. |
|
367 |
] |
|
368 |
] ifFalse:[ |
|
369 |
"/ in another block |
|
370 |
aStream nextPut:#storeBlockVar; nextPut:tmpIndex. |
|
371 |
] |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
372 |
]. |
140 | 373 |
]. |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
374 |
|
140 | 375 |
inlineBlock := true. |
555 | 376 |
|
140 | 377 |
statements isNil ifTrue:[ |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
378 |
valueNeeded ifTrue:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
379 |
aStream nextPut:#pushNil |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
380 |
] |
140 | 381 |
] ifFalse:[ |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
382 |
thisStatement := statements. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
383 |
[thisStatement notNil] whileTrue:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
384 |
nextStatement := thisStatement nextStatement. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
385 |
(nextStatement notNil or:[valueNeeded not]) ifTrue:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
386 |
thisStatement codeForSideEffectOn:aStream inBlock:b for:aCompiler |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
387 |
] ifFalse:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
388 |
thisStatement codeOn:aStream inBlock:b for:aCompiler |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
389 |
]. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
390 |
thisStatement := nextStatement |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
391 |
] |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
392 |
]. |
559 | 393 |
|
386 | 394 |
"/ endLineNr notNil ifTrue:[ |
395 |
"/ ParseNode codeLineNumber:endLineNr on:aStream for:aCompiler |
|
396 |
"/ ]. |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
397 |
|
559 | 398 |
"/ pop off temps (blockVars). |
399 |
"/ also, they are nilled to prevent any temp stuff |
|
400 |
"/ from NOT being garbage collected. |
|
401 |
"/ could optimize here, temps are reused soon. |
|
402 |
||
403 |
blockVars notNil ifTrue:[ |
|
588 | 404 |
"/ if any subblock refers to locals or args, |
405 |
"/ do not nil out ... |
|
406 |
subAccess := false. |
|
407 |
self allSubBlocksDo:[:aSubBlockNode | |
|
408 |
aSubBlockNode accessedOuterBlockVars do:[:aVarNode | |
|
409 |
|b| |
|
410 |
||
411 |
aVarNode block == self ifTrue:[ |
|
412 |
subAccess := true |
|
413 |
] |
|
414 |
] |
|
415 |
]. |
|
416 |
subAccess ifFalse:[ |
|
417 |
tmpIndex := firstTempIndex. |
|
418 |
||
559 | 419 |
blockVars do:[:dummy | |
420 |
aStream nextPut:#pushNil. |
|
588 | 421 |
codeBlock isNil ifTrue:[ |
422 |
aStream nextPut:#storeMethodVar; nextPut:tmpIndex. |
|
593
41a1c4554d83
oops - nilling of inlined subBlock vars ...
Claus Gittinger <cg@exept.de>
parents:
588
diff
changeset
|
423 |
aCompiler removeTempVar. |
588 | 424 |
] ifFalse:[ |
425 |
aStream nextPut:#storeBlockVar; nextPut:tmpIndex. |
|
593
41a1c4554d83
oops - nilling of inlined subBlock vars ...
Claus Gittinger <cg@exept.de>
parents:
588
diff
changeset
|
426 |
codeBlock removeTempVar. |
588 | 427 |
]. |
428 |
tmpIndex := tmpIndex + 1. |
|
429 |
]. |
|
430 |
]. |
|
559 | 431 |
]. |
432 |
||
593
41a1c4554d83
oops - nilling of inlined subBlock vars ...
Claus Gittinger <cg@exept.de>
parents:
588
diff
changeset
|
433 |
"Modified: 30.7.1997 / 12:21:07 / cg" |
140 | 434 |
! |
435 |
||
436 |
codeOn:aStream inBlock:b for:aCompiler |
|
1305 | 437 |
|thisStatement nextStatement lastStatement pos code cheapy| |
140 | 438 |
|
1401 | 439 |
cheapy := self checkForSimpleBlockCodeOn:aStream for:aCompiler. |
140 | 440 |
cheapy notNil ifTrue:[ |
1305 | 441 |
"if result == true - code is already on aStream" |
442 |
cheapy ~~ true ifTrue:[ |
|
443 |
cheapy codeOn:aStream inBlock:b for:aCompiler. |
|
444 |
]. |
|
333
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
445 |
^ self |
140 | 446 |
]. |
447 |
||
1305 | 448 |
"cheap block detection filters out blocks with no statements" |
449 |
||
1372
3aef25b07d7a
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1319
diff
changeset
|
450 |
pos := aStream position1Based. |
62 | 451 |
|
555 | 452 |
aStream nextPut:#makeBlock. "+0" |
453 |
aStream nextPut:0. "+1" |
|
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
454 |
aStream nextPut:(blockVars size + maxNumTemp). "+2" |
555 | 455 |
aStream nextPut:(blockArgs size). "+3" |
456 |
"+4" |
|
1305 | 457 |
thisStatement := statements. |
458 |
[thisStatement notNil] whileTrue:[ |
|
459 |
nextStatement := thisStatement nextStatement. |
|
460 |
nextStatement notNil ifTrue:[ |
|
461 |
thisStatement codeForSideEffectOn:aStream inBlock:self for:aCompiler |
|
462 |
] ifFalse:[ |
|
463 |
lastStatement := thisStatement |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
464 |
]. |
1305 | 465 |
thisStatement := nextStatement |
140 | 466 |
]. |
467 |
||
1305 | 468 |
lastStatement |
469 |
codeForSimpleReturnOn:aStream |
|
470 |
inBlock:self |
|
471 |
lineNumber:endLineNr |
|
472 |
for:aCompiler. |
|
473 |
||
562
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
474 |
code := (aStream contents). |
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
475 |
|
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
476 |
"/ sigh - during coding, inlined subBlocks may have added more |
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
477 |
"/ tempVars; patch the nvar byte ... |
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
478 |
|
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
479 |
code at:pos+2 put:(blockVars size + maxNumTemp). |
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
480 |
|
1305 | 481 |
"set the end of the block's code" |
1372
3aef25b07d7a
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1319
diff
changeset
|
482 |
code at:pos+1 put:(aStream position1Based) |
333
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
483 |
|
562
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
484 |
"Modified: 26.6.1997 / 10:48:56 / cg" |
555 | 485 |
! ! |
486 |
||
487 |
!BlockNode methodsFor:'code generation helpers'! |
|
488 |
||
489 |
addTempVar |
|
490 |
"add a temporary variable; return its position (1-based). |
|
491 |
Used when a block with args/locals is inlined." |
|
492 |
||
585 | 493 |
inlineBlock ifTrue:[ |
1319 | 494 |
self error:'addTempVar to inlineBlock - should not happen' |
585 | 495 |
]. |
559 | 496 |
|
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
497 |
numTemp isNil ifTrue:[numTemp := maxNumTemp := 0]. |
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
498 |
numTemp := numTemp + 1. |
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
499 |
maxNumTemp := maxNumTemp max:numTemp. |
559 | 500 |
^ numTemp + self numVars |
555 | 501 |
|
559 | 502 |
"Modified: 26.6.1997 / 09:52:23 / cg" |
555 | 503 |
! |
504 |
||
505 |
removeTempVar |
|
506 |
"remove a temporary variable" |
|
507 |
||
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
508 |
numTemp := numTemp - 1. |
555 | 509 |
|
510 |
"Created: 25.6.1997 / 14:04:20 / cg" |
|
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
511 |
"Modified: 25.6.1997 / 15:07:07 / cg" |
0 | 512 |
! ! |
513 |
||
1035 | 514 |
!BlockNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
515 |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
516 |
allSubBlocksDo:aBlock |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
517 |
"recursively enumerate all of my subblocks" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
518 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
519 |
subBlocks notNil ifTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
520 |
subBlocks do:[:aSubBlockNode | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
521 |
aBlock value:aSubBlockNode. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
522 |
aSubBlockNode allSubBlocksDo:aBlock. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
523 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
524 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
525 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
526 |
"Created: 2.7.1997 / 10:51:59 / cg" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
527 |
! |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
528 |
|
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
529 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
530 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
531 |
|
544
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
532 |
|args| |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
533 |
|
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
534 |
args := blockArgs ? #(). |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
535 |
args := args collect:[:var | |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
536 |
|p| |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
537 |
|
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
538 |
p := ParameterNode new. |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
539 |
p variable:var |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
540 |
]. |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
541 |
^ anEnumerator doBlock:self arguments:args body:statements |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
542 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
543 |
"Created: 19.6.1997 / 16:38:30 / cg" |
544
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
544 |
"Modified: 19.6.1997 / 17:17:57 / cg" |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
545 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
546 |
|
1035 | 547 |
!BlockNode methodsFor:'evaluation'! |
0 | 548 |
|
1384 | 549 |
evaluateIn:anEnvironment |
140 | 550 |
^ self |
551 |
! |
|
552 |
||
0 | 553 |
exitWith:something |
554 |
"return via return-statement" |
|
555 |
||
556 |
home notNil ifTrue:[ |
|
45 | 557 |
home exitWith:something |
0 | 558 |
]. |
559 |
exitBlock value:something. |
|
560 |
^ something |
|
561 |
! |
|
562 |
||
563 |
value |
|
564 |
(blockArgs size ~~ 0) ifTrue:[ |
|
1390 | 565 |
^ self wrongNumberOfArguments:0 |
0 | 566 |
]. |
567 |
statements isNil ifTrue:[^ nil]. |
|
568 |
exitBlock := [:val | ^ val]. |
|
569 |
^ statements evaluate |
|
570 |
! |
|
571 |
||
572 |
value:anArg |
|
573 |
|oldValue val| |
|
574 |
||
575 |
(blockArgs size ~~ 1) ifTrue:[ |
|
1390 | 576 |
^ self wrongNumberOfArguments:1 |
0 | 577 |
]. |
578 |
statements isNil ifTrue:[^ nil]. |
|
579 |
||
580 |
oldValue := (blockArgs at:1) value. |
|
581 |
(blockArgs at:1) value:anArg. |
|
582 |
||
15 | 583 |
exitBlock := [:v | |
1390 | 584 |
(blockArgs at:1) value:oldValue. |
585 |
^ v |
|
0 | 586 |
]. |
587 |
||
588 |
val := statements evaluate. |
|
589 |
||
590 |
(blockArgs at:1) value:oldValue. |
|
591 |
^ val |
|
592 |
! |
|
593 |
||
594 |
value:arg1 value:arg2 |
|
595 |
|oldValue1 oldValue2 val| |
|
596 |
||
597 |
(blockArgs size ~~ 2) ifTrue:[ |
|
1390 | 598 |
^ self wrongNumberOfArguments:2 |
0 | 599 |
]. |
600 |
statements isNil ifTrue:[^ nil]. |
|
601 |
||
602 |
oldValue1 := (blockArgs at:1) value. |
|
603 |
oldValue2 := (blockArgs at:2) value. |
|
604 |
(blockArgs at:1) value:arg1. |
|
605 |
(blockArgs at:2) value:arg2. |
|
606 |
||
15 | 607 |
exitBlock := [:v | |
1390 | 608 |
(blockArgs at:1) value:oldValue1. |
609 |
(blockArgs at:2) value:oldValue2. |
|
610 |
^ v |
|
0 | 611 |
]. |
612 |
||
613 |
val := statements evaluate. |
|
614 |
||
615 |
(blockArgs at:1) value:oldValue1. |
|
616 |
(blockArgs at:2) value:oldValue2. |
|
617 |
^ val |
|
618 |
! |
|
619 |
||
620 |
value:arg1 value:arg2 value:arg3 |
|
621 |
|oldValue1 oldValue2 oldValue3 val| |
|
622 |
||
623 |
(blockArgs size ~~ 3) ifTrue:[ |
|
1390 | 624 |
^ self wrongNumberOfArguments:3 |
0 | 625 |
]. |
626 |
statements isNil ifTrue:[^ nil]. |
|
627 |
||
628 |
oldValue1 := (blockArgs at:1) value. |
|
629 |
oldValue2 := (blockArgs at:2) value. |
|
630 |
oldValue3 := (blockArgs at:3) value. |
|
631 |
(blockArgs at:1) value:arg1. |
|
632 |
(blockArgs at:2) value:arg2. |
|
633 |
(blockArgs at:3) value:arg3. |
|
634 |
||
15 | 635 |
exitBlock := [:v | |
1390 | 636 |
(blockArgs at:1) value:oldValue1. |
637 |
(blockArgs at:2) value:oldValue2. |
|
638 |
(blockArgs at:3) value:oldValue3. |
|
639 |
^ v |
|
0 | 640 |
]. |
641 |
||
642 |
val := statements evaluate. |
|
643 |
||
644 |
(blockArgs at:1) value:oldValue1. |
|
645 |
(blockArgs at:2) value:oldValue2. |
|
646 |
(blockArgs at:3) value:oldValue3. |
|
647 |
^ val |
|
648 |
! |
|
649 |
||
650 |
value:arg1 value:arg2 value:arg3 value:arg4 |
|
651 |
|oldValue1 oldValue2 oldValue3 oldValue4 val| |
|
652 |
||
653 |
(blockArgs size ~~ 4) ifTrue:[ |
|
1390 | 654 |
^ self wrongNumberOfArguments:4 |
0 | 655 |
]. |
656 |
statements isNil ifTrue:[^ nil]. |
|
657 |
||
658 |
oldValue1 := (blockArgs at:1) value. |
|
659 |
oldValue2 := (blockArgs at:2) value. |
|
660 |
oldValue3 := (blockArgs at:3) value. |
|
661 |
oldValue4 := (blockArgs at:4) value. |
|
662 |
(blockArgs at:1) value:arg1. |
|
663 |
(blockArgs at:2) value:arg2. |
|
664 |
(blockArgs at:3) value:arg3. |
|
665 |
(blockArgs at:4) value:arg4. |
|
666 |
||
15 | 667 |
exitBlock := [:v | |
1390 | 668 |
(blockArgs at:1) value:oldValue1. |
669 |
(blockArgs at:2) value:oldValue2. |
|
670 |
(blockArgs at:3) value:oldValue3. |
|
671 |
(blockArgs at:4) value:oldValue4. |
|
672 |
^ v |
|
0 | 673 |
]. |
674 |
||
675 |
val := statements evaluate. |
|
676 |
||
677 |
(blockArgs at:1) value:oldValue1. |
|
678 |
(blockArgs at:2) value:oldValue2. |
|
679 |
(blockArgs at:3) value:oldValue3. |
|
680 |
(blockArgs at:4) value:oldValue4. |
|
681 |
^ val |
|
140 | 682 |
! |
3 | 683 |
|
684 |
valueWithArguments:argArray |
|
685 |
|oldValues val| |
|
686 |
||
687 |
(blockArgs size ~~ argArray size) ifTrue:[ |
|
1390 | 688 |
^ self wrongNumberOfArguments:argArray size |
3 | 689 |
]. |
690 |
statements isNil ifTrue:[^ nil]. |
|
691 |
||
692 |
oldValues := Array new:(argArray size). |
|
693 |
1 to:argArray size do:[:i | |
|
1390 | 694 |
oldValues at:i put:(blockArgs at:i) value. |
695 |
(blockArgs at:i) value:(argArray at:i). |
|
3 | 696 |
]. |
15 | 697 |
exitBlock := [:v | |
1390 | 698 |
1 to:argArray size do:[:i | |
699 |
( blockArgs at:i) value:(oldValues at:i) |
|
700 |
]. |
|
701 |
^ v |
|
3 | 702 |
]. |
703 |
||
704 |
val := statements evaluate. |
|
705 |
||
706 |
1 to:argArray size do:[:i | |
|
1390 | 707 |
(blockArgs at:i) value:(oldValues at:i) |
3 | 708 |
]. |
709 |
^ val |
|
140 | 710 |
! |
711 |
||
1390 | 712 |
wrongNumberOfArguments:numArgsGiven |
584
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
713 |
"report that the number of arguments given does not match the number expected" |
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
714 |
|
1390 | 715 |
WrongNumberOfArgumentsError |
584
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
716 |
raiseRequestWith:self |
1390 | 717 |
errorString:('block got ' , numArgsGiven printString , |
718 |
' arg(s) where ' , blockArgs size printString , ' expected') |
|
584
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
719 |
|
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
720 |
"Modified: 8.7.1997 / 01:04:27 / stefan" |
0 | 721 |
! ! |
722 |
||
723 |
!BlockNode methodsFor:'looping'! |
|
724 |
||
725 |
whileFalse:aBlock |
|
26 | 726 |
self value ifTrue:[^ nil]. |
727 |
aBlock value. |
|
728 |
thisContext restart |
|
0 | 729 |
! |
730 |
||
140 | 731 |
whileTrue:aBlock |
732 |
self value ifFalse:[^ nil]. |
|
733 |
aBlock value. |
|
734 |
thisContext restart |
|
0 | 735 |
! ! |
736 |
||
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
737 |
!BlockNode methodsFor:'misc'! |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
738 |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
739 |
rememberOuterBlockVarAccess:aVariableNode |
579 | 740 |
accessedOuterBlockVars isNil ifTrue:[ |
741 |
accessedOuterBlockVars := OrderedCollection new. |
|
742 |
]. |
|
743 |
accessedOuterBlockVars add:aVariableNode |
|
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
744 |
|
579 | 745 |
"Modified: 2.7.1997 / 18:52:49 / cg" |
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
746 |
! |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
747 |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
748 |
rememberSubBlock:aBlockNode |
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
749 |
subBlocks isNil ifTrue:[ |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
750 |
subBlocks := OrderedCollection new. |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
751 |
]. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
752 |
subBlocks add:aBlockNode |
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
753 |
|
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
754 |
"Created: 28.6.1997 / 15:13:20 / cg" |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
755 |
"Modified: 2.7.1997 / 11:11:26 / cg" |
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
756 |
! ! |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
757 |
|
1079 | 758 |
!BlockNode methodsFor:'printing & storing'! |
0 | 759 |
|
760 |
printOn:aStream indent:i |
|
98 | 761 |
|n "{Class: SmallInteger }"| |
762 |
||
0 | 763 |
aStream nextPut:$[. |
98 | 764 |
(n := blockArgs size) > 0 ifTrue:[ |
765 |
1 to:n do:[:index | |
|
96 | 766 |
aStream nextPut:$:. |
767 |
aStream nextPutAll:(blockArgs at:index) name. |
|
768 |
aStream space. |
|
769 |
]. |
|
98 | 770 |
aStream nextPut:$|. |
771 |
aStream space. |
|
772 |
]. |
|
773 |
(n := blockVars size) > 0 ifTrue:[ |
|
774 |
aStream nextPut:$|. |
|
775 |
1 to:n do:[:index | |
|
776 |
aStream nextPutAll:(blockVars at:index) name. |
|
777 |
aStream space. |
|
778 |
]. |
|
779 |
aStream nextPut:$|. |
|
0 | 780 |
]. |
781 |
statements notNil ifTrue:[ |
|
45 | 782 |
aStream cr. |
783 |
statements printAllOn:aStream indent:i + 4. |
|
784 |
aStream cr. |
|
785 |
aStream spaces:i. |
|
0 | 786 |
]. |
787 |
aStream nextPut:$] |
|
788 |
! ! |
|
140 | 789 |
|
1415 | 790 |
!BlockNode methodsFor:'private-accessing'! |
140 | 791 |
|
792 |
setArguments:argList home:h variables:vars |
|
793 |
inlineBlock := false. |
|
794 |
needsHome := false. |
|
795 |
blockArgs := argList. |
|
796 |
home := h. |
|
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
797 |
blockVars := vars. |
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
798 |
numTemp := maxNumTemp := 0. |
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
799 |
|
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
800 |
"Modified: 25.6.1997 / 15:07:52 / cg" |
140 | 801 |
! ! |
802 |
||
803 |
!BlockNode methodsFor:'queries'! |
|
804 |
||
394 | 805 |
collectBlocksInto:aCollection |
806 |
aCollection add:self. |
|
458 | 807 |
statements notNil ifTrue:[statements collectBlocksInto:aCollection] |
394 | 808 |
|
809 |
"Created: 23.10.1996 / 15:45:16 / cg" |
|
810 |
"Modified: 23.10.1996 / 16:02:57 / cg" |
|
811 |
! |
|
812 |
||
333
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
813 |
endsWithReturn |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
814 |
statements isNil ifTrue:[ |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
815 |
^ false |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
816 |
]. |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
817 |
^ statements listEndsWithReturn |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
818 |
|
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
819 |
"Created: 19.8.1996 / 14:36:32 / cg" |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
820 |
! |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
821 |
|
559 | 822 |
indexOfFirstTemp |
823 |
^ indexOfFirstTemp |
|
824 |
||
825 |
"Created: 25.6.1997 / 15:39:11 / cg" |
|
826 |
! |
|
827 |
||
140 | 828 |
isBlock |
829 |
"a kludge, to have blocknodes mimic blocks" |
|
830 |
||
831 |
^ true |
|
168 | 832 |
! |
833 |
||
1513 | 834 |
isBlockNode |
835 |
^ true |
|
836 |
! |
|
837 |
||
855 | 838 |
isEmptyBlock |
839 |
^ statements isNil |
|
840 |
! |
|
841 |
||
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
842 |
isInlinable |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
843 |
"return true, if the receiver is inlinable. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
844 |
For now, do NOT inline a block, if it has args/vars |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
845 |
which are accessed by subblocks, which are themself |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
846 |
not inlinable. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
847 |
This limitation is needed for the following piece of code to work: |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
848 |
1 to:10 do:[:i | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
849 |
.... [ something with i ] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
850 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
851 |
If this block was inlined, each subblock would get the same i |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
852 |
(which is the old ST/V behavior)" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
853 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
854 |
possiblyInlined == true ifFalse:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
855 |
^ false |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
856 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
857 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
858 |
(self numArgs ~~ 0 or:[self numVars ~~ 0]) ifTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
859 |
"/ any subblock, which accesses a var/arg of myself ? |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
860 |
self allSubBlocksDo:[:aSubBlockNode | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
861 |
aSubBlockNode accessedOuterBlockVars do:[:aVarNode | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
862 |
|b| |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
863 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
864 |
aVarNode block == self ifTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
865 |
"/ all-inbetween inlinable ? |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
866 |
b := aSubBlockNode. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
867 |
[b ~~ self] whileTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
868 |
b isInlinable ifFalse:[ |
575 | 869 |
"/ 'not inlined due to access: ' print. aVarNode displayString printCR. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
870 |
^ false |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
871 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
872 |
b := b home |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
873 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
874 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
875 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
876 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
877 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
878 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
879 |
^ true |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
880 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
881 |
"Created: 2.7.1997 / 10:43:37 / cg" |
579 | 882 |
"Modified: 2.7.1997 / 18:55:36 / cg" |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
883 |
! |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
884 |
|
394 | 885 |
numArgs |
522 | 886 |
"return the number of arguments the block represented by myself |
887 |
expects for evaluation" |
|
888 |
||
394 | 889 |
^ blockArgs size |
890 |
||
891 |
"Created: 23.10.1996 / 15:57:04 / cg" |
|
522 | 892 |
"Modified: 7.5.1997 / 15:34:35 / cg" |
394 | 893 |
! |
894 |
||
895 |
numVars |
|
896 |
^ blockVars size |
|
897 |
||
898 |
"Created: 23.10.1996 / 16:17:07 / cg" |
|
899 |
! |
|
900 |
||
169 | 901 |
simpleSendBlockExpression |
902 |
blockVars notNil ifTrue:[^ nil]. |
|
903 |
statements isNil ifTrue:[^ nil]. |
|
904 |
statements nextStatement notNil ifTrue:[^ nil]. |
|
905 |
^ statements expression |
|
906 |
||
907 |
"Created: 13.12.1995 / 20:06:09 / cg" |
|
140 | 908 |
! ! |
909 |
||
366 | 910 |
!BlockNode class methodsFor:'documentation'! |
148 | 911 |
|
912 |
version |
|
1513 | 913 |
^ '$Header: /cvs/stx/stx/libcomp/BlockNode.st,v 1.69 2004-05-18 14:13:21 cg Exp $' |
148 | 914 |
! ! |