author | Claus Gittinger <cg@exept.de> |
Thu, 25 Feb 1999 15:49:27 +0100 | |
changeset 817 | 8de90dbed4bb |
parent 677 | 14997f5d177a |
child 855 | e3b3d4e9a17f |
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 |
||
506
3dc049d3a2d7
care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
234 |
|cheapy e val code stackSize| |
140 | 235 |
|
236 |
statements isNil ifTrue:[ |
|
366 | 237 |
"a []-block" |
140 | 238 |
|
366 | 239 |
val := nil |
140 | 240 |
] ifFalse:[ |
366 | 241 |
statements nextStatement notNil ifTrue:[^ nil]. |
242 |
(statements isMemberOf:StatementNode) ifFalse:[^ nil]. |
|
140 | 243 |
|
366 | 244 |
e := statements expression. |
245 |
e isConstant ifFalse:[^ nil]. |
|
140 | 246 |
|
366 | 247 |
val := e value. |
140 | 248 |
]. |
249 |
||
506
3dc049d3a2d7
care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
250 |
stackSize := 0. |
3dc049d3a2d7
care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
251 |
|
140 | 252 |
val == 0 ifTrue:[ |
366 | 253 |
"a [0]-block" |
140 | 254 |
|
366 | 255 |
code := ByteArray with:(ByteCodeCompiler byteCodeFor:#ret0). |
140 | 256 |
]. |
257 |
val == 1 ifTrue:[ |
|
366 | 258 |
"a [1]-block" |
140 | 259 |
|
506
3dc049d3a2d7
care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
260 |
stackSize := 1. |
366 | 261 |
code := ByteArray with:(ByteCodeCompiler byteCodeFor:#push1) |
262 |
with:(ByteCodeCompiler byteCodeFor:#retTop). |
|
140 | 263 |
]. |
264 |
||
265 |
val == true ifTrue:[ |
|
366 | 266 |
"a [true]-block" |
140 | 267 |
|
366 | 268 |
code := ByteArray with:(ByteCodeCompiler byteCodeFor:#retTrue). |
140 | 269 |
]. |
270 |
||
271 |
val == false ifTrue:[ |
|
366 | 272 |
"a [false]-block" |
140 | 273 |
|
366 | 274 |
code := ByteArray with:(ByteCodeCompiler byteCodeFor:#retFalse). |
140 | 275 |
]. |
276 |
||
277 |
val == nil ifTrue:[ |
|
366 | 278 |
"a [nil]-block" |
140 | 279 |
|
366 | 280 |
code := ByteArray with:(ByteCodeCompiler byteCodeFor:#retNil). |
140 | 281 |
]. |
282 |
||
283 |
code notNil ifTrue:[ |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
284 |
cheapy := CheapBlock |
366 | 285 |
byteCode:code |
286 |
numArgs:(blockArgs size) |
|
506
3dc049d3a2d7
care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
287 |
numStack:stackSize |
366 | 288 |
sourcePosition:nil |
289 |
initialPC:nil |
|
290 |
literals:nil. |
|
291 |
^ ConstantNode type:#Block value:cheapy |
|
140 | 292 |
]. |
293 |
||
294 |
^ nil |
|
366 | 295 |
|
506
3dc049d3a2d7
care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
296 |
"Modified: 13.4.1997 / 00:05:29 / cg" |
140 | 297 |
! |
298 |
||
299 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
300 |
"generate code for this statement - value not needed. |
|
301 |
For blocks, no code is generated at all." |
|
302 |
||
303 |
^ self |
|
304 |
! |
|
305 |
||
306 |
codeInlineOn:aStream inBlock:b for:aCompiler |
|
307 |
self codeInlineOn:aStream inBlock:b valueNeeded:true for:aCompiler |
|
308 |
! |
|
309 |
||
310 |
codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
|
588 | 311 |
|thisStatement nextStatement tmpIndex firstTempIndex codeBlock subAccess| |
140 | 312 |
|
313 |
blockVars notNil ifTrue:[ |
|
559 | 314 |
"/ have to move blockvars into surrounding context |
0 | 315 |
|
559 | 316 |
"/ find the first non-inlined block |
317 |
codeBlock := b. |
|
318 |
[codeBlock notNil and:[codeBlock isInlineBlock]] whileTrue:[ |
|
319 |
codeBlock := codeBlock home. |
|
553 | 320 |
]. |
321 |
||
559 | 322 |
blockVars do:[:aBlockVar | |
323 |
codeBlock isNil ifTrue:[ |
|
324 |
"/ in method - add more temps to the method |
|
325 |
tmpIndex := aCompiler addTempVar. |
|
326 |
] ifFalse:[ |
|
327 |
"/ in another block - add more temps to the block |
|
328 |
tmpIndex := codeBlock addTempVar |
|
329 |
]. |
|
330 |
||
331 |
firstTempIndex isNil ifTrue:[ |
|
332 |
firstTempIndex := tmpIndex. |
|
333 |
indexOfFirstTemp isNil ifTrue:[ |
|
334 |
indexOfFirstTemp := tmpIndex |
|
335 |
]. |
|
336 |
]. |
|
337 |
||
338 |
"/ block vars must be nilled |
|
339 |
"/ (in case the previous block left some value there). |
|
340 |
"/ This nilling should be optimized away, if |
|
341 |
"/ the variable gets a value assigned before the first send. |
|
342 |
||
343 |
aStream nextPut:#pushNil. |
|
344 |
codeBlock isNil ifTrue:[ |
|
345 |
"/ in method |
|
346 |
(tmpIndex <= 6) ifTrue:[ |
|
347 |
aStream nextPut:(#(storeMethodVar1 storeMethodVar2 |
|
348 |
storeMethodVar3 storeMethodVar4 |
|
349 |
storeMethodVar5 storeMethodVar6) at:tmpIndex). |
|
350 |
] ifFalse:[ |
|
351 |
aStream nextPut:#storeMethodVar; nextPut:tmpIndex. |
|
352 |
] |
|
353 |
] ifFalse:[ |
|
354 |
"/ in another block |
|
355 |
aStream nextPut:#storeBlockVar; nextPut:tmpIndex. |
|
356 |
] |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
357 |
]. |
140 | 358 |
]. |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
359 |
|
140 | 360 |
inlineBlock := true. |
555 | 361 |
|
140 | 362 |
statements isNil ifTrue:[ |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
363 |
valueNeeded ifTrue:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
364 |
aStream nextPut:#pushNil |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
365 |
] |
140 | 366 |
] ifFalse:[ |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
367 |
thisStatement := statements. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
368 |
[thisStatement notNil] whileTrue:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
369 |
nextStatement := thisStatement nextStatement. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
370 |
(nextStatement notNil or:[valueNeeded not]) ifTrue:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
371 |
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
|
372 |
] ifFalse:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
373 |
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
|
374 |
]. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
375 |
thisStatement := nextStatement |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
376 |
] |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
377 |
]. |
559 | 378 |
|
386 | 379 |
"/ endLineNr notNil ifTrue:[ |
380 |
"/ ParseNode codeLineNumber:endLineNr on:aStream for:aCompiler |
|
381 |
"/ ]. |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
382 |
|
559 | 383 |
"/ pop off temps (blockVars). |
384 |
"/ also, they are nilled to prevent any temp stuff |
|
385 |
"/ from NOT being garbage collected. |
|
386 |
"/ could optimize here, temps are reused soon. |
|
387 |
||
388 |
blockVars notNil ifTrue:[ |
|
588 | 389 |
"/ if any subblock refers to locals or args, |
390 |
"/ do not nil out ... |
|
391 |
subAccess := false. |
|
392 |
self allSubBlocksDo:[:aSubBlockNode | |
|
393 |
aSubBlockNode accessedOuterBlockVars do:[:aVarNode | |
|
394 |
|b| |
|
395 |
||
396 |
aVarNode block == self ifTrue:[ |
|
397 |
subAccess := true |
|
398 |
] |
|
399 |
] |
|
400 |
]. |
|
401 |
subAccess ifFalse:[ |
|
402 |
tmpIndex := firstTempIndex. |
|
403 |
||
559 | 404 |
blockVars do:[:dummy | |
405 |
aStream nextPut:#pushNil. |
|
588 | 406 |
codeBlock isNil ifTrue:[ |
407 |
aStream nextPut:#storeMethodVar; nextPut:tmpIndex. |
|
593
41a1c4554d83
oops - nilling of inlined subBlock vars ...
Claus Gittinger <cg@exept.de>
parents:
588
diff
changeset
|
408 |
aCompiler removeTempVar. |
588 | 409 |
] ifFalse:[ |
410 |
aStream nextPut:#storeBlockVar; nextPut:tmpIndex. |
|
593
41a1c4554d83
oops - nilling of inlined subBlock vars ...
Claus Gittinger <cg@exept.de>
parents:
588
diff
changeset
|
411 |
codeBlock removeTempVar. |
588 | 412 |
]. |
413 |
tmpIndex := tmpIndex + 1. |
|
414 |
]. |
|
415 |
]. |
|
559 | 416 |
]. |
417 |
||
593
41a1c4554d83
oops - nilling of inlined subBlock vars ...
Claus Gittinger <cg@exept.de>
parents:
588
diff
changeset
|
418 |
"Modified: 30.7.1997 / 12:21:07 / cg" |
140 | 419 |
! |
420 |
||
421 |
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
|
422 |
|thisStatement nextStatement lastStatement pos code cheapy p0| |
140 | 423 |
|
424 |
cheapy := self checkForSimpleBlock. |
|
425 |
cheapy notNil ifTrue:[ |
|
333
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
426 |
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
|
427 |
^ self |
140 | 428 |
]. |
429 |
||
430 |
pos := aStream position. |
|
62 | 431 |
|
555 | 432 |
aStream nextPut:#makeBlock. "+0" |
433 |
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
|
434 |
aStream nextPut:(blockVars size + maxNumTemp). "+2" |
555 | 435 |
aStream nextPut:(blockArgs size). "+3" |
436 |
"+4" |
|
394 | 437 |
p0 := pos+4. |
438 |
||
140 | 439 |
statements isNil ifTrue:[ |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
440 |
endLineNr notNil ifTrue:[ |
817 | 441 |
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
|
442 |
]. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
443 |
aStream nextPut:#pushNil. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
444 |
aStream nextPut:#retTop. |
140 | 445 |
] ifFalse:[ |
333
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
446 |
thisStatement := statements. |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
447 |
[thisStatement notNil] whileTrue:[ |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
448 |
nextStatement := thisStatement nextStatement. |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
449 |
nextStatement notNil ifTrue:[ |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
450 |
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
|
451 |
] ifFalse:[ |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
452 |
lastStatement := thisStatement |
333
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
453 |
]. |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
454 |
thisStatement := nextStatement |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
455 |
]. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
456 |
|
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
457 |
lastStatement isPrimary ifTrue:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
458 |
ReturnNode |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
459 |
codeSimpleReturnFor:lastStatement expression |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
460 |
inBlock:nil |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
461 |
on:aStream |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
462 |
inLine:endLineNr |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
463 |
for:aCompiler |
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 |
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
|
466 |
endLineNr notNil ifTrue:[ |
817 | 467 |
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
|
468 |
]. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
469 |
aStream nextPut:#retTop. |
140 | 470 |
]. |
471 |
||
562
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
472 |
code := (aStream contents). |
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
473 |
|
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
474 |
|
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
475 |
"/ 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
|
476 |
"/ tempVars; patch the nvar byte ... |
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
477 |
|
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
478 |
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
|
479 |
|
140 | 480 |
"check for [0]-block; |
481 |
these are sometimes used as in ... ifAbsent:[0] |
|
482 |
" |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
483 |
(code at:p0) == #lineno ifTrue:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
484 |
p0 := p0 + 2 |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
485 |
] ifFalse:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
486 |
(code at:p0) == #lineno16 ifTrue:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
487 |
p0 := p0 + 3 |
333
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
488 |
] |
140 | 489 |
]. |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
490 |
|
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
491 |
(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
|
492 |
aStream position:pos. |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
493 |
code grow:pos. |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
494 |
aStream nextPut:#mk0Block. |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
495 |
^ self |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
496 |
]. |
140 | 497 |
|
498 |
"check for [nil]-block; |
|
499 |
these come to play when code in blocks is commented |
|
500 |
out, or as dummy exception blocks |
|
501 |
" |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
502 |
(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
|
503 |
aStream position:pos. |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
504 |
code grow:pos. |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
505 |
aStream nextPut:#mkNilBlock. |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
506 |
^ self |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
507 |
]. |
140 | 508 |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
509 |
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
|
510 |
|
562
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
511 |
"Modified: 26.6.1997 / 10:48:56 / cg" |
555 | 512 |
! ! |
513 |
||
514 |
!BlockNode methodsFor:'code generation helpers'! |
|
515 |
||
516 |
addTempVar |
|
517 |
"add a temporary variable; return its position (1-based). |
|
518 |
Used when a block with args/locals is inlined." |
|
519 |
||
585 | 520 |
inlineBlock ifTrue:[ |
521 |
self halt:'addTempVar to inlineBlock - should not happen' |
|
522 |
]. |
|
559 | 523 |
|
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
524 |
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
|
525 |
numTemp := numTemp + 1. |
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
526 |
maxNumTemp := maxNumTemp max:numTemp. |
559 | 527 |
^ numTemp + self numVars |
555 | 528 |
|
559 | 529 |
"Modified: 26.6.1997 / 09:52:23 / cg" |
555 | 530 |
! |
531 |
||
532 |
removeTempVar |
|
533 |
"remove a temporary variable" |
|
534 |
||
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
535 |
numTemp := numTemp - 1. |
555 | 536 |
|
537 |
"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
|
538 |
"Modified: 25.6.1997 / 15:07:07 / cg" |
0 | 539 |
! ! |
540 |
||
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
541 |
!BlockNode methodsFor:'enumeration'! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
542 |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
543 |
allSubBlocksDo:aBlock |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
544 |
"recursively enumerate all of my subblocks" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
545 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
546 |
subBlocks notNil ifTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
547 |
subBlocks do:[:aSubBlockNode | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
548 |
aBlock value:aSubBlockNode. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
549 |
aSubBlockNode allSubBlocksDo:aBlock. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
550 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
551 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
552 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
553 |
"Created: 2.7.1997 / 10:51:59 / cg" |
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 |
|
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
556 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
557 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
558 |
|
544
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
559 |
|args| |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
560 |
|
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
561 |
args := blockArgs ? #(). |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
562 |
args := args collect:[:var | |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
563 |
|p| |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
564 |
|
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
565 |
p := ParameterNode new. |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
566 |
p variable:var |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
567 |
]. |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
568 |
^ anEnumerator doBlock:self arguments:args body:statements |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
569 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
570 |
"Created: 19.6.1997 / 16:38:30 / cg" |
544
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
571 |
"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
|
572 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
573 |
|
0 | 574 |
!BlockNode methodsFor:'evaluating'! |
575 |
||
140 | 576 |
evaluate |
577 |
^ self |
|
578 |
! |
|
579 |
||
0 | 580 |
exitWith:something |
581 |
"return via return-statement" |
|
582 |
||
583 |
home notNil ifTrue:[ |
|
45 | 584 |
home exitWith:something |
0 | 585 |
]. |
586 |
exitBlock value:something. |
|
587 |
^ something |
|
588 |
! |
|
589 |
||
590 |
value |
|
591 |
(blockArgs size ~~ 0) ifTrue:[ |
|
45 | 592 |
^ self wrongNumberOfArguments:0 |
0 | 593 |
]. |
594 |
statements isNil ifTrue:[^ nil]. |
|
595 |
exitBlock := [:val | ^ val]. |
|
596 |
^ statements evaluate |
|
597 |
! |
|
598 |
||
599 |
value:anArg |
|
600 |
|oldValue val| |
|
601 |
||
602 |
(blockArgs size ~~ 1) ifTrue:[ |
|
45 | 603 |
^ self wrongNumberOfArguments:1 |
0 | 604 |
]. |
605 |
statements isNil ifTrue:[^ nil]. |
|
606 |
||
607 |
oldValue := (blockArgs at:1) value. |
|
608 |
(blockArgs at:1) value:anArg. |
|
609 |
||
15 | 610 |
exitBlock := [:v | |
45 | 611 |
(blockArgs at:1) value:oldValue. |
612 |
^ v |
|
0 | 613 |
]. |
614 |
||
615 |
val := statements evaluate. |
|
616 |
||
617 |
(blockArgs at:1) value:oldValue. |
|
618 |
^ val |
|
619 |
! |
|
620 |
||
621 |
value:arg1 value:arg2 |
|
622 |
|oldValue1 oldValue2 val| |
|
623 |
||
624 |
(blockArgs size ~~ 2) ifTrue:[ |
|
45 | 625 |
^ self wrongNumberOfArguments:2 |
0 | 626 |
]. |
627 |
statements isNil ifTrue:[^ nil]. |
|
628 |
||
629 |
oldValue1 := (blockArgs at:1) value. |
|
630 |
oldValue2 := (blockArgs at:2) value. |
|
631 |
(blockArgs at:1) value:arg1. |
|
632 |
(blockArgs at:2) value:arg2. |
|
633 |
||
15 | 634 |
exitBlock := [:v | |
45 | 635 |
(blockArgs at:1) value:oldValue1. |
636 |
(blockArgs at:2) value:oldValue2. |
|
637 |
^ v |
|
0 | 638 |
]. |
639 |
||
640 |
val := statements evaluate. |
|
641 |
||
642 |
(blockArgs at:1) value:oldValue1. |
|
643 |
(blockArgs at:2) value:oldValue2. |
|
644 |
^ val |
|
645 |
! |
|
646 |
||
647 |
value:arg1 value:arg2 value:arg3 |
|
648 |
|oldValue1 oldValue2 oldValue3 val| |
|
649 |
||
650 |
(blockArgs size ~~ 3) ifTrue:[ |
|
45 | 651 |
^ self wrongNumberOfArguments:3 |
0 | 652 |
]. |
653 |
statements isNil ifTrue:[^ nil]. |
|
654 |
||
655 |
oldValue1 := (blockArgs at:1) value. |
|
656 |
oldValue2 := (blockArgs at:2) value. |
|
657 |
oldValue3 := (blockArgs at:3) value. |
|
658 |
(blockArgs at:1) value:arg1. |
|
659 |
(blockArgs at:2) value:arg2. |
|
660 |
(blockArgs at:3) value:arg3. |
|
661 |
||
15 | 662 |
exitBlock := [:v | |
45 | 663 |
(blockArgs at:1) value:oldValue1. |
664 |
(blockArgs at:2) value:oldValue2. |
|
665 |
(blockArgs at:3) value:oldValue3. |
|
666 |
^ v |
|
0 | 667 |
]. |
668 |
||
669 |
val := statements evaluate. |
|
670 |
||
671 |
(blockArgs at:1) value:oldValue1. |
|
672 |
(blockArgs at:2) value:oldValue2. |
|
673 |
(blockArgs at:3) value:oldValue3. |
|
674 |
^ val |
|
675 |
! |
|
676 |
||
677 |
value:arg1 value:arg2 value:arg3 value:arg4 |
|
678 |
|oldValue1 oldValue2 oldValue3 oldValue4 val| |
|
679 |
||
680 |
(blockArgs size ~~ 4) ifTrue:[ |
|
45 | 681 |
^ self wrongNumberOfArguments:4 |
0 | 682 |
]. |
683 |
statements isNil ifTrue:[^ nil]. |
|
684 |
||
685 |
oldValue1 := (blockArgs at:1) value. |
|
686 |
oldValue2 := (blockArgs at:2) value. |
|
687 |
oldValue3 := (blockArgs at:3) value. |
|
688 |
oldValue4 := (blockArgs at:4) value. |
|
689 |
(blockArgs at:1) value:arg1. |
|
690 |
(blockArgs at:2) value:arg2. |
|
691 |
(blockArgs at:3) value:arg3. |
|
692 |
(blockArgs at:4) value:arg4. |
|
693 |
||
15 | 694 |
exitBlock := [:v | |
45 | 695 |
(blockArgs at:1) value:oldValue1. |
696 |
(blockArgs at:2) value:oldValue2. |
|
697 |
(blockArgs at:3) value:oldValue3. |
|
698 |
(blockArgs at:4) value:oldValue4. |
|
699 |
^ v |
|
0 | 700 |
]. |
701 |
||
702 |
val := statements evaluate. |
|
703 |
||
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 |
^ val |
|
140 | 709 |
! |
3 | 710 |
|
711 |
valueWithArguments:argArray |
|
712 |
|oldValues val| |
|
713 |
||
714 |
(blockArgs size ~~ argArray size) ifTrue:[ |
|
45 | 715 |
^ self wrongNumberOfArguments:argArray size |
3 | 716 |
]. |
717 |
statements isNil ifTrue:[^ nil]. |
|
718 |
||
719 |
oldValues := Array new:(argArray size). |
|
720 |
1 to:argArray size do:[:i | |
|
45 | 721 |
oldValues at:i put:(blockArgs at:i) value. |
722 |
(blockArgs at:i) value:(argArray at:i). |
|
3 | 723 |
]. |
15 | 724 |
exitBlock := [:v | |
45 | 725 |
1 to:argArray size do:[:i | |
726 |
( blockArgs at:i) value:(oldValues at:i) |
|
727 |
]. |
|
728 |
^ v |
|
3 | 729 |
]. |
730 |
||
731 |
val := statements evaluate. |
|
732 |
||
733 |
1 to:argArray size do:[:i | |
|
45 | 734 |
(blockArgs at:i) value:(oldValues at:i) |
3 | 735 |
]. |
736 |
^ val |
|
140 | 737 |
! |
738 |
||
739 |
wrongNumberOfArguments:numberGiven |
|
584
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
740 |
"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
|
741 |
|
140 | 742 |
Block argumentSignal |
584
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
743 |
raiseRequestWith:self |
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
744 |
errorString:('block got ' , numberGiven printString , |
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
745 |
' args where ' , blockArgs size printString , ' expected') |
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
746 |
|
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
747 |
"Modified: 8.7.1997 / 01:04:27 / stefan" |
0 | 748 |
! ! |
749 |
||
750 |
!BlockNode methodsFor:'looping'! |
|
751 |
||
752 |
whileFalse:aBlock |
|
26 | 753 |
self value ifTrue:[^ nil]. |
754 |
aBlock value. |
|
755 |
thisContext restart |
|
0 | 756 |
! |
757 |
||
140 | 758 |
whileTrue:aBlock |
759 |
self value ifFalse:[^ nil]. |
|
760 |
aBlock value. |
|
761 |
thisContext restart |
|
0 | 762 |
! ! |
763 |
||
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
764 |
!BlockNode methodsFor:'misc'! |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
765 |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
766 |
rememberOuterBlockVarAccess:aVariableNode |
579 | 767 |
accessedOuterBlockVars isNil ifTrue:[ |
768 |
accessedOuterBlockVars := OrderedCollection new. |
|
769 |
]. |
|
770 |
accessedOuterBlockVars add:aVariableNode |
|
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
771 |
|
579 | 772 |
"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
|
773 |
! |
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 |
rememberSubBlock:aBlockNode |
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
776 |
subBlocks isNil ifTrue:[ |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
777 |
subBlocks := OrderedCollection new. |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
778 |
]. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
779 |
subBlocks add:aBlockNode |
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
780 |
|
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
781 |
"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
|
782 |
"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
|
783 |
! ! |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
784 |
|
0 | 785 |
!BlockNode methodsFor:'printing'! |
786 |
||
787 |
printOn:aStream indent:i |
|
98 | 788 |
|n "{Class: SmallInteger }"| |
789 |
||
0 | 790 |
aStream nextPut:$[. |
98 | 791 |
(n := blockArgs size) > 0 ifTrue:[ |
792 |
1 to:n do:[:index | |
|
96 | 793 |
aStream nextPut:$:. |
794 |
aStream nextPutAll:(blockArgs at:index) name. |
|
795 |
aStream space. |
|
796 |
]. |
|
98 | 797 |
aStream nextPut:$|. |
798 |
aStream space. |
|
799 |
]. |
|
800 |
(n := blockVars size) > 0 ifTrue:[ |
|
801 |
aStream nextPut:$|. |
|
802 |
1 to:n do:[:index | |
|
803 |
aStream nextPutAll:(blockVars at:index) name. |
|
804 |
aStream space. |
|
805 |
]. |
|
806 |
aStream nextPut:$|. |
|
0 | 807 |
]. |
808 |
statements notNil ifTrue:[ |
|
45 | 809 |
aStream cr. |
810 |
statements printAllOn:aStream indent:i + 4. |
|
811 |
aStream cr. |
|
812 |
aStream spaces:i. |
|
0 | 813 |
]. |
814 |
aStream nextPut:$] |
|
815 |
! ! |
|
140 | 816 |
|
817 |
!BlockNode methodsFor:'private accessing'! |
|
818 |
||
819 |
setArguments:argList home:h variables:vars |
|
820 |
inlineBlock := false. |
|
821 |
needsHome := false. |
|
822 |
blockArgs := argList. |
|
823 |
home := h. |
|
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
824 |
blockVars := vars. |
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
825 |
numTemp := maxNumTemp := 0. |
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
826 |
|
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
827 |
"Modified: 25.6.1997 / 15:07:52 / cg" |
140 | 828 |
! ! |
829 |
||
830 |
!BlockNode methodsFor:'queries'! |
|
831 |
||
394 | 832 |
collectBlocksInto:aCollection |
833 |
aCollection add:self. |
|
458 | 834 |
statements notNil ifTrue:[statements collectBlocksInto:aCollection] |
394 | 835 |
|
836 |
"Created: 23.10.1996 / 15:45:16 / cg" |
|
837 |
"Modified: 23.10.1996 / 16:02:57 / cg" |
|
838 |
! |
|
839 |
||
333
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
840 |
endsWithReturn |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
841 |
statements isNil ifTrue:[ |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
842 |
^ false |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
843 |
]. |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
844 |
^ statements listEndsWithReturn |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
845 |
|
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
846 |
"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
|
847 |
! |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
848 |
|
559 | 849 |
indexOfFirstTemp |
850 |
^ indexOfFirstTemp |
|
851 |
||
852 |
"Created: 25.6.1997 / 15:39:11 / cg" |
|
853 |
! |
|
854 |
||
140 | 855 |
isBlock |
856 |
"a kludge, to have blocknodes mimic blocks" |
|
857 |
||
858 |
^ true |
|
168 | 859 |
! |
860 |
||
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
861 |
isInlinable |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
862 |
"return true, if the receiver is inlinable. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
863 |
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
|
864 |
which are accessed by subblocks, which are themself |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
865 |
not inlinable. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
866 |
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
|
867 |
1 to:10 do:[:i | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
868 |
.... [ something with i ] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
869 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
870 |
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
|
871 |
(which is the old ST/V behavior)" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
872 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
873 |
possiblyInlined == true ifFalse:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
874 |
^ false |
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 |
(self numArgs ~~ 0 or:[self numVars ~~ 0]) ifTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
878 |
"/ 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
|
879 |
self allSubBlocksDo:[:aSubBlockNode | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
880 |
aSubBlockNode accessedOuterBlockVars do:[:aVarNode | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
881 |
|b| |
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 |
aVarNode block == self ifTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
884 |
"/ all-inbetween inlinable ? |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
885 |
b := aSubBlockNode. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
886 |
[b ~~ self] whileTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
887 |
b isInlinable ifFalse:[ |
575 | 888 |
"/ '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
|
889 |
^ false |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
890 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
891 |
b := b home |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
892 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
893 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
894 |
] |
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 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
897 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
898 |
^ true |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
899 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
900 |
"Created: 2.7.1997 / 10:43:37 / cg" |
579 | 901 |
"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
|
902 |
! |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
903 |
|
394 | 904 |
numArgs |
522 | 905 |
"return the number of arguments the block represented by myself |
906 |
expects for evaluation" |
|
907 |
||
394 | 908 |
^ blockArgs size |
909 |
||
910 |
"Created: 23.10.1996 / 15:57:04 / cg" |
|
522 | 911 |
"Modified: 7.5.1997 / 15:34:35 / cg" |
394 | 912 |
! |
913 |
||
914 |
numVars |
|
915 |
^ blockVars size |
|
916 |
||
917 |
"Created: 23.10.1996 / 16:17:07 / cg" |
|
918 |
! |
|
919 |
||
169 | 920 |
simpleSendBlockExpression |
921 |
blockVars notNil ifTrue:[^ nil]. |
|
922 |
statements isNil ifTrue:[^ nil]. |
|
923 |
statements nextStatement notNil ifTrue:[^ nil]. |
|
924 |
^ statements expression |
|
925 |
||
926 |
"Created: 13.12.1995 / 20:06:09 / cg" |
|
140 | 927 |
! ! |
928 |
||
366 | 929 |
!BlockNode class methodsFor:'documentation'! |
148 | 930 |
|
931 |
version |
|
817 | 932 |
^ '$Header: /cvs/stx/stx/libcomp/BlockNode.st,v 1.54 1999-02-25 14:49:18 cg Exp $' |
148 | 933 |
! ! |