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