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