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