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