author | Claus Gittinger <cg@exept.de> |
Sat, 25 May 2019 23:47:38 +0200 | |
changeset 4420 | eee7da6ae1e2 |
parent 4166 | 107243939f2b |
child 4259 | c707f9aa7015 |
child 4481 | 7a96e0ee9932 |
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 |
||
3602 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
0 | 16 |
ParseNode subclass:#BlockNode |
168 | 17 |
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
|
18 |
needsHome lineNr endLineNr blockArgAccessedInBlock numTemp |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
19 |
maxNumTemp indexOfFirstTemp subBlocks accessedOuterBlockVars |
2501 | 20 |
possiblyInlined invocationSelector charStartIndex charEndIndex |
3479 | 21 |
index inlined endPointIndex modifiedBlockVars' |
168 | 22 |
classVariableNames:'' |
23 |
poolDictionaries:'' |
|
24 |
category:'System-Compiler-Support' |
|
0 | 25 |
! |
26 |
||
366 | 27 |
!BlockNode class methodsFor:'documentation'! |
20 | 28 |
|
29 |
copyright |
|
30 |
" |
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
45 | 32 |
All Rights Reserved |
0 | 33 |
|
20 | 34 |
This software is furnished under a license and may be used |
35 |
only in accordance with the terms of that license and with the |
|
36 |
inclusion of the above copyright notice. This software may not |
|
37 |
be provided or otherwise made available to, or used by, any |
|
38 |
other person. No title to or ownership of the software is |
|
39 |
hereby transferred. |
|
40 |
" |
|
41 |
! |
|
0 | 42 |
|
20 | 43 |
documentation |
44 |
" |
|
45 |
node for parse-trees, representing blocks |
|
261 | 46 |
This is a helper class for the compiler. |
263 | 47 |
|
48 |
[author:] |
|
49 |
Claus Gittinger |
|
20 | 50 |
" |
51 |
! ! |
|
0 | 52 |
|
366 | 53 |
!BlockNode class methodsFor:'instance creation'! |
0 | 54 |
|
3602 | 55 |
arguments:argList home:homeBlock |
56 |
|newBlock| |
|
57 |
||
58 |
newBlock := (self basicNew) setArguments:argList home:homeBlock. |
|
59 |
homeBlock notNil ifTrue:[ |
|
60 |
homeBlock rememberSubBlock:newBlock |
|
61 |
]. |
|
62 |
^ newBlock |
|
63 |
||
64 |
"Modified: 28.6.1997 / 15:14:45 / cg" |
|
65 |
! |
|
66 |
||
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
67 |
arguments:argList home:homeBlock variables:vars |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
68 |
|newBlock| |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
69 |
|
3602 | 70 |
newBlock := self arguments:argList home:homeBlock. |
71 |
newBlock variables:vars. |
|
72 |
^ newBlock |
|
73 |
! |
|
74 |
||
75 |
home:homeBlock |
|
76 |
|newBlock| |
|
77 |
||
78 |
newBlock := (self basicNew) setHome:homeBlock. |
|
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
79 |
homeBlock notNil ifTrue:[ |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
80 |
homeBlock rememberSubBlock:newBlock |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
81 |
]. |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
82 |
^ newBlock |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
83 |
|
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
84 |
"Modified: 28.6.1997 / 15:14:45 / cg" |
2750 | 85 |
! |
86 |
||
87 |
withExpression:exprNode in:home |
|
88 |
"a utility function for code generators" |
|
89 |
||
90 |
^ (self arguments:#() home:home variables:#()) |
|
91 |
statements:(StatementNode new expression:exprNode) |
|
92 |
||
93 |
"Created: / 25-10-2011 / 17:44:05 / cg" |
|
0 | 94 |
! ! |
95 |
||
96 |
!BlockNode methodsFor:'accessing'! |
|
97 |
||
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
98 |
accessedOuterBlockVars |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
99 |
"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
|
100 |
in this block" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
101 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
102 |
^ accessedOuterBlockVars ? #() |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
103 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
104 |
"Modified: 18.6.1997 / 12:06:31 / cg" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
105 |
"Created: 2.7.1997 / 17:29:56 / cg" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
106 |
! |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
107 |
|
0 | 108 |
arguments |
109 |
^ blockArgs |
|
110 |
! |
|
111 |
||
26 | 112 |
arguments:argList |
113 |
blockArgs := argList |
|
114 |
! |
|
115 |
||
534 | 116 |
blockArgAccessed |
117 |
"return true if any block argument is accessed in the block" |
|
118 |
||
119 |
^ blockArgAccessedInBlock ? false |
|
120 |
||
121 |
"Modified: 18.6.1997 / 12:06:31 / cg" |
|
122 |
! |
|
123 |
||
124 |
blockArgAccessed:aBoolen |
|
125 |
"set/clear the flag stating if any block argument is accessed in the block" |
|
126 |
||
127 |
blockArgAccessedInBlock := aBoolen |
|
128 |
||
129 |
"Created: 18.6.1997 / 11:35:00 / cg" |
|
130 |
"Modified: 18.6.1997 / 12:06:43 / cg" |
|
131 |
! |
|
132 |
||
2501 | 133 |
charEndIndex |
134 |
^ charEndIndex |
|
135 |
! |
|
136 |
||
137 |
charEndIndex:something |
|
138 |
charEndIndex := something. |
|
139 |
! |
|
140 |
||
141 |
charStartIndex |
|
142 |
^ charStartIndex |
|
143 |
! |
|
144 |
||
145 |
charStartIndex:something |
|
146 |
charStartIndex := something. |
|
147 |
! |
|
148 |
||
394 | 149 |
endLineNumber |
150 |
^ endLineNr |
|
151 |
||
152 |
"Created: 23.10.1996 / 15:51:32 / cg" |
|
153 |
! |
|
154 |
||
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
155 |
endLineNumber:aNumber |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
156 |
endLineNr := aNumber |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
157 |
|
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
158 |
"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
|
159 |
! |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
160 |
|
2501 | 161 |
endPointIndex |
162 |
^ endPointIndex |
|
2129 | 163 |
! |
164 |
||
2501 | 165 |
endPointIndex:something |
166 |
endPointIndex := something. |
|
2129 | 167 |
! |
168 |
||
3340 | 169 |
firstStatement |
170 |
statements isNil ifTrue:[^ nil]. |
|
171 |
^ statements "sigh - its a linked list" |
|
172 |
! |
|
173 |
||
140 | 174 |
home |
175 |
^ home |
|
0 | 176 |
! |
177 |
||
178 |
home:aBlock |
|
179 |
home := aBlock |
|
180 |
! |
|
181 |
||
559 | 182 |
indexOfFirstTemp:index |
183 |
indexOfFirstTemp := index |
|
184 |
||
185 |
"Created: 25.6.1997 / 17:24:27 / cg" |
|
186 |
! |
|
187 |
||
555 | 188 |
inlineBlock:aBoolean |
189 |
inlineBlock := aBoolean |
|
0 | 190 |
! |
191 |
||
2354 | 192 |
invocationSelector |
193 |
"the selector, by which this block is invoked" |
|
194 |
||
195 |
^ invocationSelector |
|
677 | 196 |
|
2354 | 197 |
"Created: / 27-04-2010 / 11:56:22 / cg" |
198 |
! |
|
677 | 199 |
|
2354 | 200 |
invokationSelector |
201 |
<resource: #obsolete> |
|
202 |
^ invocationSelector |
|
203 |
||
204 |
"Created: / 02-04-1998 / 15:00:06 / cg" |
|
205 |
"Modified: / 27-04-2010 / 11:56:44 / cg" |
|
677 | 206 |
! |
207 |
||
555 | 208 |
isInlineBlock |
2749 | 209 |
^ (inlineBlock == true) |
555 | 210 |
|
2749 | 211 |
"Created: / 25-06-1997 / 14:11:33 / cg" |
0 | 212 |
! |
213 |
||
3340 | 214 |
lastStatement |
215 |
statements isNil ifTrue:[^ nil]. |
|
216 |
^ statements last "sigh - its a linked list" |
|
217 |
! |
|
218 |
||
394 | 219 |
lineNumber |
220 |
^ lineNr |
|
221 |
||
222 |
"Created: 23.10.1996 / 15:51:50 / cg" |
|
223 |
! |
|
224 |
||
140 | 225 |
lineNumber:aNumber |
226 |
lineNr := aNumber |
|
227 |
! |
|
228 |
||
1505 | 229 |
lineNumberOfFirstMessage |
230 |
^ statements lineNumberOfFirstMessage |
|
231 |
||
232 |
"Created: 23.10.1996 / 15:51:50 / cg" |
|
233 |
! |
|
234 |
||
0 | 235 |
needsHome |
236 |
^ needsHome |
|
237 |
! |
|
238 |
||
239 |
needsHome:aBoolean |
|
240 |
needsHome := aBoolean |
|
6 | 241 |
! |
242 |
||
2056 | 243 |
nestingLevel |
244 |
^ home isNil ifTrue:[ 0 ] ifFalse:[ home nestingLevel + 1] |
|
245 |
||
246 |
"Created: / 15-01-2008 / 11:54:57 / cg" |
|
247 |
! |
|
248 |
||
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
249 |
possiblyInlined:aBoolean |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
250 |
possiblyInlined := aBoolean |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
251 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
252 |
"Created: 2.7.1997 / 11:32:00 / cg" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
253 |
! |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
254 |
|
677 | 255 |
possiblyInlined:aBoolean withSelector:selector |
256 |
possiblyInlined := aBoolean. |
|
2354 | 257 |
invocationSelector := selector. |
677 | 258 |
|
2354 | 259 |
"Created: / 02-04-1998 / 19:07:53 / cg" |
260 |
"Modified: / 27-04-2010 / 11:56:51 / cg" |
|
677 | 261 |
! |
262 |
||
140 | 263 |
statements |
264 |
^ statements |
|
265 |
! |
|
266 |
||
267 |
statements:s |
|
2596 | 268 |
|
269 |
statements notNil ifTrue:[statements parent: nil]. |
|
270 |
statements := s. |
|
271 |
statements notNil ifTrue:[statements parent: self]. |
|
272 |
||
273 |
"Modified: / 20-07-2011 / 19:49:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
140 | 274 |
! |
275 |
||
276 |
variables |
|
277 |
^ blockVars |
|
278 |
! |
|
279 |
||
280 |
variables:varList |
|
281 |
blockVars := varList |
|
3270 | 282 |
! |
283 |
||
284 |
variablesIncludingInlined: forStcCompiledCode |
|
285 |
"Returns all my local variables including those of block inlined into |
|
286 |
the receiver. If `forStcCompiledCode` is true then assume |
|
287 |
the code is compiled by stc, otherwise assume the code is |
|
288 |
compiled by bytecode compiler" |
|
289 |
||
290 |
| myBlocks | |
|
291 |
||
292 |
myBlocks := OrderedCollection new. |
|
293 |
self collectBlocksInto: myBlocks. |
|
3272 | 294 |
myBlocks := myBlocks select:[:block | block isInlinedInto: self assumeStcCompiled: forStcCompiledCode. ]. |
3270 | 295 |
^ myBlocks notEmpty ifTrue:[ |
296 |
OrderedCollection streamContents:[:s| |
|
297 |
s nextPutAll: blockVars ? #(). |
|
298 |
myBlocks do:[:block | s nextPutAll: block variables ? #() ]. |
|
299 |
] |
|
300 |
] ifFalse:[ |
|
301 |
blockVars |
|
302 |
]. |
|
303 |
||
304 |
"Created: / 19-08-2013 / 11:37:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
140 | 305 |
! ! |
306 |
||
307 |
!BlockNode methodsFor:'block messages'! |
|
308 |
||
309 |
doesNotUnderstand:aMessage |
|
310 |
|numArgs kludgeBlock| |
|
311 |
||
1251
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
312 |
(Block includesSelector:(aMessage selector)) ifTrue:[ |
3893 | 313 |
"/ mhmh - a message which I don't understand, but Block implements |
1251
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
314 |
"/ 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
|
315 |
|
1251
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
316 |
numArgs := blockArgs size. |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
317 |
numArgs == 0 ifTrue:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
318 |
kludgeBlock := [self value] |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
319 |
] ifFalse:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
320 |
numArgs == 1 ifTrue:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
321 |
kludgeBlock := [:a1 | self value:a1]. |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
322 |
] ifFalse:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
323 |
numArgs == 2 ifTrue:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
324 |
kludgeBlock := [:a1 :a2 | self value:a1 value:a2]. |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
325 |
] ifFalse:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
326 |
numArgs == 3 ifTrue:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
327 |
kludgeBlock := [:a1 :a2 :a3| self value:a1 value:a2 value:a3]. |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
328 |
] ifFalse:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
329 |
numArgs == 4 ifTrue:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
330 |
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
|
331 |
] ifFalse:[ |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
332 |
^ self error:'only support blocks with up-to 4 args' |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
333 |
] |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
334 |
] |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
335 |
] |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
336 |
] |
e5d27409e4f2
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
1135
diff
changeset
|
337 |
]. |
3893 | 338 |
^ aMessage sendTo:kludgeBlock. |
140 | 339 |
]. |
340 |
^ super doesNotUnderstand:aMessage |
|
0 | 341 |
! ! |
342 |
||
140 | 343 |
!BlockNode methodsFor:'code generation'! |
344 |
||
1401 | 345 |
checkForSimpleBlockCodeOn:aStream for:aCompiler |
140 | 346 |
"simple things can be made cheap blocks right now - |
1305 | 347 |
resulting in a simple pushLit instruction ... |
348 |
Return: |
|
349 |
true -- bytecodes are on aStream |
|
350 |
aParseNode -- Parsenode creating the cheap block |
|
351 |
nil -- cheap block not possible |
|
352 |
" |
|
140 | 353 |
|
4166 | 354 |
<ignore: RBReturnsBooleanAndOtherRule rationale: 'done by purpose' author: 'cg'> |
355 |
||
1401 | 356 |
|cheapy val isConstRet singleInsn code stackSize| |
140 | 357 |
|
932 | 358 |
isConstRet := false. |
1305 | 359 |
|
140 | 360 |
statements isNil ifTrue:[ |
4074 | 361 |
self argumentCount == 0 ifTrue:[ |
1305 | 362 |
"a []-block" |
363 |
aStream nextPut:#mkNilBlock. |
|
364 |
^ true. |
|
365 |
]. |
|
932 | 366 |
val := nil. |
367 |
isConstRet := true. |
|
4074 | 368 |
] ifFalse:[ |
369 |
statements isConstant ifTrue:[ |
|
370 |
val := statements expression value. |
|
371 |
self numArgs == 0 ifTrue:[ |
|
372 |
val == 0 ifTrue:[ |
|
373 |
aStream nextPut:#mk0Block. |
|
374 |
^ true. |
|
375 |
]. |
|
376 |
val isNil ifTrue:[ |
|
377 |
aStream nextPut:#mkNilBlock. |
|
378 |
^ true. |
|
379 |
]. |
|
380 |
]. |
|
381 |
isConstRet := true. |
|
382 |
] |
|
383 |
]. |
|
140 | 384 |
|
932 | 385 |
isConstRet ifTrue:[ |
386 |
stackSize := 0. |
|
506
3dc049d3a2d7
care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
387 |
|
1305 | 388 |
(val isInteger and:[val between:-128 and:127]) ifTrue:[ |
389 |
"a [-128..127]-block" |
|
390 |
val < 0 ifTrue:[val := val + 256]. |
|
391 |
code := ByteArray with:(ByteCodeCompiler byteCodeFor:#retNum) |
|
392 |
with:val. |
|
393 |
] ifFalse:[val == true ifTrue:[ |
|
394 |
"a [true]-block" |
|
395 |
singleInsn := #retTrue |
|
396 |
] ifFalse:[val == false ifTrue:[ |
|
397 |
"a [false]-block" |
|
398 |
singleInsn := #retFalse |
|
399 |
] ifFalse:[val isNil ifTrue:[ |
|
400 |
"a [nil]-block" |
|
401 |
singleInsn := #retNil |
|
402 |
]]]]. |
|
932 | 403 |
singleInsn notNil ifTrue:[ |
404 |
code := ByteArray with:(ByteCodeCompiler byteCodeFor:singleInsn). |
|
405 |
]. |
|
140 | 406 |
]. |
407 |
||
408 |
code notNil ifTrue:[ |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
409 |
cheapy := CheapBlock |
366 | 410 |
byteCode:code |
411 |
numArgs:(blockArgs size) |
|
1135
7708c6a185a2
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
412 |
numVars:0 |
506
3dc049d3a2d7
care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
413 |
numStack:stackSize |
366 | 414 |
sourcePosition:nil |
415 |
initialPC:nil |
|
416 |
literals:nil. |
|
1305 | 417 |
^ ConstantNode type:#Block value:cheapy. |
140 | 418 |
]. |
419 |
||
420 |
^ nil |
|
366 | 421 |
|
4166 | 422 |
"Modified: / 16-07-2017 / 13:30:41 / cg" |
140 | 423 |
! |
424 |
||
425 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
426 |
"generate code for this statement - value not needed. |
|
427 |
For blocks, no code is generated at all." |
|
428 |
||
2129 | 429 |
aCompiler |
2130 | 430 |
warning:(statements isNil |
431 |
ifTrue:[ 'useless empty block.' ] |
|
432 |
ifFalse:[ 'useless block - the statement(s) inside will not be evaluated.' ]) |
|
2129 | 433 |
position:startPosition to:endPosition. |
140 | 434 |
^ self |
435 |
! |
|
436 |
||
437 |
codeInlineOn:aStream inBlock:b for:aCompiler |
|
438 |
self codeInlineOn:aStream inBlock:b valueNeeded:true for:aCompiler |
|
439 |
! |
|
440 |
||
441 |
codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
|
588 | 442 |
|thisStatement nextStatement tmpIndex firstTempIndex codeBlock subAccess| |
140 | 443 |
|
444 |
blockVars notNil ifTrue:[ |
|
559 | 445 |
"/ have to move blockvars into surrounding context |
0 | 446 |
|
559 | 447 |
"/ find the first non-inlined block |
448 |
codeBlock := b. |
|
449 |
[codeBlock notNil and:[codeBlock isInlineBlock]] whileTrue:[ |
|
450 |
codeBlock := codeBlock home. |
|
553 | 451 |
]. |
452 |
||
559 | 453 |
blockVars do:[:aBlockVar | |
454 |
codeBlock isNil ifTrue:[ |
|
455 |
"/ in method - add more temps to the method |
|
456 |
tmpIndex := aCompiler addTempVar. |
|
457 |
] ifFalse:[ |
|
458 |
"/ in another block - add more temps to the block |
|
459 |
tmpIndex := codeBlock addTempVar |
|
460 |
]. |
|
461 |
||
462 |
firstTempIndex isNil ifTrue:[ |
|
463 |
firstTempIndex := tmpIndex. |
|
464 |
indexOfFirstTemp isNil ifTrue:[ |
|
465 |
indexOfFirstTemp := tmpIndex |
|
466 |
]. |
|
467 |
]. |
|
468 |
||
469 |
"/ block vars must be nilled |
|
470 |
"/ (in case the previous block left some value there). |
|
471 |
"/ This nilling should be optimized away, if |
|
472 |
"/ the variable gets a value assigned before the first send. |
|
473 |
||
474 |
aStream nextPut:#pushNil. |
|
475 |
codeBlock isNil ifTrue:[ |
|
476 |
"/ in method |
|
477 |
(tmpIndex <= 6) ifTrue:[ |
|
478 |
aStream nextPut:(#(storeMethodVar1 storeMethodVar2 |
|
479 |
storeMethodVar3 storeMethodVar4 |
|
480 |
storeMethodVar5 storeMethodVar6) at:tmpIndex). |
|
481 |
] ifFalse:[ |
|
482 |
aStream nextPut:#storeMethodVar; nextPut:tmpIndex. |
|
483 |
] |
|
484 |
] ifFalse:[ |
|
485 |
"/ in another block |
|
486 |
aStream nextPut:#storeBlockVar; nextPut:tmpIndex. |
|
487 |
] |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
488 |
]. |
140 | 489 |
]. |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
490 |
|
140 | 491 |
inlineBlock := true. |
555 | 492 |
|
140 | 493 |
statements isNil ifTrue:[ |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
494 |
valueNeeded ifTrue:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
495 |
aStream nextPut:#pushNil |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
496 |
] |
140 | 497 |
] ifFalse:[ |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
498 |
thisStatement := statements. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
499 |
[thisStatement notNil] whileTrue:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
500 |
nextStatement := thisStatement nextStatement. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
501 |
(nextStatement notNil or:[valueNeeded not]) ifTrue:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
502 |
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
|
503 |
] ifFalse:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
504 |
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
|
505 |
]. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
506 |
thisStatement := nextStatement |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
507 |
] |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
508 |
]. |
559 | 509 |
|
386 | 510 |
"/ endLineNr notNil ifTrue:[ |
511 |
"/ ParseNode codeLineNumber:endLineNr on:aStream for:aCompiler |
|
512 |
"/ ]. |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
513 |
|
559 | 514 |
"/ pop off temps (blockVars). |
515 |
"/ also, they are nilled to prevent any temp stuff |
|
516 |
"/ from NOT being garbage collected. |
|
517 |
"/ could optimize here, temps are reused soon. |
|
518 |
||
519 |
blockVars notNil ifTrue:[ |
|
588 | 520 |
"/ if any subblock refers to locals or args, |
521 |
"/ do not nil out ... |
|
522 |
subAccess := false. |
|
523 |
self allSubBlocksDo:[:aSubBlockNode | |
|
524 |
aSubBlockNode accessedOuterBlockVars do:[:aVarNode | |
|
525 |
|b| |
|
526 |
||
527 |
aVarNode block == self ifTrue:[ |
|
528 |
subAccess := true |
|
529 |
] |
|
530 |
] |
|
531 |
]. |
|
532 |
subAccess ifFalse:[ |
|
533 |
tmpIndex := firstTempIndex. |
|
534 |
||
559 | 535 |
blockVars do:[:dummy | |
536 |
aStream nextPut:#pushNil. |
|
588 | 537 |
codeBlock isNil ifTrue:[ |
538 |
aStream nextPut:#storeMethodVar; nextPut:tmpIndex. |
|
593
41a1c4554d83
oops - nilling of inlined subBlock vars ...
Claus Gittinger <cg@exept.de>
parents:
588
diff
changeset
|
539 |
aCompiler removeTempVar. |
588 | 540 |
] ifFalse:[ |
541 |
aStream nextPut:#storeBlockVar; nextPut:tmpIndex. |
|
593
41a1c4554d83
oops - nilling of inlined subBlock vars ...
Claus Gittinger <cg@exept.de>
parents:
588
diff
changeset
|
542 |
codeBlock removeTempVar. |
588 | 543 |
]. |
544 |
tmpIndex := tmpIndex + 1. |
|
545 |
]. |
|
546 |
]. |
|
559 | 547 |
]. |
548 |
||
593
41a1c4554d83
oops - nilling of inlined subBlock vars ...
Claus Gittinger <cg@exept.de>
parents:
588
diff
changeset
|
549 |
"Modified: 30.7.1997 / 12:21:07 / cg" |
140 | 550 |
! |
551 |
||
552 |
codeOn:aStream inBlock:b for:aCompiler |
|
1305 | 553 |
|thisStatement nextStatement lastStatement pos code cheapy| |
140 | 554 |
|
1401 | 555 |
cheapy := self checkForSimpleBlockCodeOn:aStream for:aCompiler. |
140 | 556 |
cheapy notNil ifTrue:[ |
1305 | 557 |
"if result == true - code is already on aStream" |
558 |
cheapy ~~ true ifTrue:[ |
|
559 |
cheapy codeOn:aStream inBlock:b for:aCompiler. |
|
560 |
]. |
|
333
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
561 |
^ self |
140 | 562 |
]. |
563 |
||
1305 | 564 |
"cheap block detection filters out blocks with no statements" |
565 |
||
3265 | 566 |
pos := aStream position. |
62 | 567 |
|
555 | 568 |
aStream nextPut:#makeBlock. "+0" |
569 |
aStream nextPut:0. "+1" |
|
1723 | 570 |
aStream nextPut:(blockVars size + (maxNumTemp?0)). "+2" |
555 | 571 |
aStream nextPut:(blockArgs size). "+3" |
572 |
"+4" |
|
1305 | 573 |
thisStatement := statements. |
574 |
[thisStatement notNil] whileTrue:[ |
|
575 |
nextStatement := thisStatement nextStatement. |
|
576 |
nextStatement notNil ifTrue:[ |
|
577 |
thisStatement codeForSideEffectOn:aStream inBlock:self for:aCompiler |
|
578 |
] ifFalse:[ |
|
579 |
lastStatement := thisStatement |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
580 |
]. |
1305 | 581 |
thisStatement := nextStatement |
140 | 582 |
]. |
583 |
||
1305 | 584 |
lastStatement |
585 |
codeForSimpleReturnOn:aStream |
|
586 |
inBlock:self |
|
587 |
lineNumber:endLineNr |
|
588 |
for:aCompiler. |
|
589 |
||
3262 | 590 |
code := aStream contents. |
562
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
591 |
|
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
592 |
"/ 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
|
593 |
"/ tempVars; patch the nvar byte ... |
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
594 |
|
3262 | 595 |
code at:pos+3 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
|
596 |
|
1305 | 597 |
"set the end of the block's code" |
3265 | 598 |
code at:pos+2 put:(aStream position + 1) |
333
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
599 |
|
562
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
600 |
"Modified: 26.6.1997 / 10:48:56 / cg" |
555 | 601 |
! ! |
602 |
||
603 |
!BlockNode methodsFor:'code generation helpers'! |
|
604 |
||
605 |
addTempVar |
|
606 |
"add a temporary variable; return its position (1-based). |
|
607 |
Used when a block with args/locals is inlined." |
|
608 |
||
2749 | 609 |
(inlineBlock == true) ifTrue:[ |
1319 | 610 |
self error:'addTempVar to inlineBlock - should not happen' |
585 | 611 |
]. |
559 | 612 |
|
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
613 |
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
|
614 |
numTemp := numTemp + 1. |
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
615 |
maxNumTemp := maxNumTemp max:numTemp. |
559 | 616 |
^ numTemp + self numVars |
555 | 617 |
|
2749 | 618 |
"Modified: / 25-10-2011 / 16:49:50 / cg" |
555 | 619 |
! |
620 |
||
621 |
removeTempVar |
|
622 |
"remove a temporary variable" |
|
623 |
||
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
624 |
numTemp := numTemp - 1. |
555 | 625 |
|
626 |
"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
|
627 |
"Modified: 25.6.1997 / 15:07:07 / cg" |
0 | 628 |
! ! |
629 |
||
1035 | 630 |
!BlockNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
631 |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
632 |
allSubBlocksDo:aBlock |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
633 |
"recursively enumerate all of my subblocks" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
634 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
635 |
subBlocks notNil ifTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
636 |
subBlocks do:[:aSubBlockNode | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
637 |
aBlock value:aSubBlockNode. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
638 |
aSubBlockNode allSubBlocksDo:aBlock. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
639 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
640 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
641 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
642 |
"Created: 2.7.1997 / 10:51:59 / cg" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
643 |
! |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
644 |
|
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
645 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
646 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
647 |
|
544
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
648 |
|args| |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
649 |
|
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
650 |
args := blockArgs ? #(). |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
651 |
args := args collect:[:var | |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
652 |
|p| |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
653 |
|
1933 | 654 |
p := Variable name:var. |
655 |
"/ p := ParameterNode new. |
|
656 |
"/ p variable:var |
|
544
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
657 |
]. |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
658 |
^ anEnumerator doBlock:self arguments:args body:statements |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
659 |
|
1933 | 660 |
"Created: / 19-06-1997 / 16:38:30 / cg" |
661 |
"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
|
662 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
663 |
|
3893 | 664 |
|
1035 | 665 |
!BlockNode methodsFor:'evaluation'! |
0 | 666 |
|
1384 | 667 |
evaluateIn:anEnvironment |
140 | 668 |
^ self |
669 |
! |
|
670 |
||
0 | 671 |
exitWith:something |
672 |
"return via return-statement" |
|
673 |
||
674 |
home notNil ifTrue:[ |
|
45 | 675 |
home exitWith:something |
0 | 676 |
]. |
677 |
exitBlock value:something. |
|
678 |
^ something |
|
679 |
! |
|
680 |
||
681 |
value |
|
682 |
(blockArgs size ~~ 0) ifTrue:[ |
|
1390 | 683 |
^ self wrongNumberOfArguments:0 |
0 | 684 |
]. |
685 |
statements isNil ifTrue:[^ nil]. |
|
686 |
exitBlock := [:val | ^ val]. |
|
687 |
^ statements evaluate |
|
688 |
! |
|
689 |
||
690 |
value:anArg |
|
691 |
|oldValue val| |
|
692 |
||
693 |
(blockArgs size ~~ 1) ifTrue:[ |
|
1390 | 694 |
^ self wrongNumberOfArguments:1 |
0 | 695 |
]. |
696 |
statements isNil ifTrue:[^ nil]. |
|
697 |
||
698 |
oldValue := (blockArgs at:1) value. |
|
699 |
(blockArgs at:1) value:anArg. |
|
700 |
||
15 | 701 |
exitBlock := [:v | |
1390 | 702 |
(blockArgs at:1) value:oldValue. |
703 |
^ v |
|
0 | 704 |
]. |
705 |
||
706 |
val := statements evaluate. |
|
707 |
||
708 |
(blockArgs at:1) value:oldValue. |
|
709 |
^ val |
|
710 |
! |
|
711 |
||
712 |
value:arg1 value:arg2 |
|
713 |
|oldValue1 oldValue2 val| |
|
714 |
||
715 |
(blockArgs size ~~ 2) ifTrue:[ |
|
1390 | 716 |
^ self wrongNumberOfArguments:2 |
0 | 717 |
]. |
718 |
statements isNil ifTrue:[^ nil]. |
|
719 |
||
720 |
oldValue1 := (blockArgs at:1) value. |
|
721 |
oldValue2 := (blockArgs at:2) value. |
|
722 |
(blockArgs at:1) value:arg1. |
|
723 |
(blockArgs at:2) value:arg2. |
|
724 |
||
15 | 725 |
exitBlock := [:v | |
1390 | 726 |
(blockArgs at:1) value:oldValue1. |
727 |
(blockArgs at:2) value:oldValue2. |
|
728 |
^ v |
|
0 | 729 |
]. |
730 |
||
731 |
val := statements evaluate. |
|
732 |
||
733 |
(blockArgs at:1) value:oldValue1. |
|
734 |
(blockArgs at:2) value:oldValue2. |
|
735 |
^ val |
|
736 |
! |
|
737 |
||
738 |
value:arg1 value:arg2 value:arg3 |
|
739 |
|oldValue1 oldValue2 oldValue3 val| |
|
740 |
||
741 |
(blockArgs size ~~ 3) ifTrue:[ |
|
1390 | 742 |
^ self wrongNumberOfArguments:3 |
0 | 743 |
]. |
744 |
statements isNil ifTrue:[^ nil]. |
|
745 |
||
746 |
oldValue1 := (blockArgs at:1) value. |
|
747 |
oldValue2 := (blockArgs at:2) value. |
|
748 |
oldValue3 := (blockArgs at:3) value. |
|
749 |
(blockArgs at:1) value:arg1. |
|
750 |
(blockArgs at:2) value:arg2. |
|
751 |
(blockArgs at:3) value:arg3. |
|
752 |
||
15 | 753 |
exitBlock := [:v | |
1390 | 754 |
(blockArgs at:1) value:oldValue1. |
755 |
(blockArgs at:2) value:oldValue2. |
|
756 |
(blockArgs at:3) value:oldValue3. |
|
757 |
^ v |
|
0 | 758 |
]. |
759 |
||
760 |
val := statements evaluate. |
|
761 |
||
762 |
(blockArgs at:1) value:oldValue1. |
|
763 |
(blockArgs at:2) value:oldValue2. |
|
764 |
(blockArgs at:3) value:oldValue3. |
|
765 |
^ val |
|
766 |
! |
|
767 |
||
768 |
value:arg1 value:arg2 value:arg3 value:arg4 |
|
769 |
|oldValue1 oldValue2 oldValue3 oldValue4 val| |
|
770 |
||
771 |
(blockArgs size ~~ 4) ifTrue:[ |
|
1390 | 772 |
^ self wrongNumberOfArguments:4 |
0 | 773 |
]. |
774 |
statements isNil ifTrue:[^ nil]. |
|
775 |
||
776 |
oldValue1 := (blockArgs at:1) value. |
|
777 |
oldValue2 := (blockArgs at:2) value. |
|
778 |
oldValue3 := (blockArgs at:3) value. |
|
779 |
oldValue4 := (blockArgs at:4) value. |
|
780 |
(blockArgs at:1) value:arg1. |
|
781 |
(blockArgs at:2) value:arg2. |
|
782 |
(blockArgs at:3) value:arg3. |
|
783 |
(blockArgs at:4) value:arg4. |
|
784 |
||
15 | 785 |
exitBlock := [:v | |
1390 | 786 |
(blockArgs at:1) value:oldValue1. |
787 |
(blockArgs at:2) value:oldValue2. |
|
788 |
(blockArgs at:3) value:oldValue3. |
|
789 |
(blockArgs at:4) value:oldValue4. |
|
790 |
^ v |
|
0 | 791 |
]. |
792 |
||
793 |
val := statements evaluate. |
|
794 |
||
795 |
(blockArgs at:1) value:oldValue1. |
|
796 |
(blockArgs at:2) value:oldValue2. |
|
797 |
(blockArgs at:3) value:oldValue3. |
|
798 |
(blockArgs at:4) value:oldValue4. |
|
799 |
^ val |
|
140 | 800 |
! |
3 | 801 |
|
802 |
valueWithArguments:argArray |
|
803 |
|oldValues val| |
|
804 |
||
805 |
(blockArgs size ~~ argArray size) ifTrue:[ |
|
1390 | 806 |
^ self wrongNumberOfArguments:argArray size |
3 | 807 |
]. |
808 |
statements isNil ifTrue:[^ nil]. |
|
809 |
||
810 |
oldValues := Array new:(argArray size). |
|
811 |
1 to:argArray size do:[:i | |
|
1390 | 812 |
oldValues at:i put:(blockArgs at:i) value. |
813 |
(blockArgs at:i) value:(argArray at:i). |
|
3 | 814 |
]. |
15 | 815 |
exitBlock := [:v | |
1390 | 816 |
1 to:argArray size do:[:i | |
817 |
( blockArgs at:i) value:(oldValues at:i) |
|
818 |
]. |
|
819 |
^ v |
|
3 | 820 |
]. |
821 |
||
822 |
val := statements evaluate. |
|
823 |
||
824 |
1 to:argArray size do:[:i | |
|
1390 | 825 |
(blockArgs at:i) value:(oldValues at:i) |
3 | 826 |
]. |
827 |
^ val |
|
140 | 828 |
! |
829 |
||
1390 | 830 |
wrongNumberOfArguments:numArgsGiven |
584
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
831 |
"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
|
832 |
|
1390 | 833 |
WrongNumberOfArgumentsError |
584
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
834 |
raiseRequestWith:self |
2077
127ac6e095ad
wrongNumberOfArguments: error message
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
835 |
errorString:('block got %1 arg(s) where %2 expected' |
127ac6e095ad
wrongNumberOfArguments: error message
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
836 |
bindWith:numArgsGiven |
127ac6e095ad
wrongNumberOfArguments: error message
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
837 |
with:blockArgs size) |
584
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
838 |
|
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
839 |
"Modified: 8.7.1997 / 01:04:27 / stefan" |
0 | 840 |
! ! |
841 |
||
842 |
!BlockNode methodsFor:'looping'! |
|
843 |
||
844 |
whileFalse:aBlock |
|
26 | 845 |
self value ifTrue:[^ nil]. |
846 |
aBlock value. |
|
847 |
thisContext restart |
|
0 | 848 |
! |
849 |
||
140 | 850 |
whileTrue:aBlock |
1853 | 851 |
"evaluate the argument, aBlock while the receiver evaluates to true." |
852 |
||
140 | 853 |
self value ifFalse:[^ nil]. |
854 |
aBlock value. |
|
855 |
thisContext restart |
|
1853 | 856 |
|
857 |
"Modified: / 22-08-2006 / 14:40:48 / cg" |
|
0 | 858 |
! ! |
859 |
||
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
860 |
!BlockNode methodsFor:'misc'! |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
861 |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
862 |
rememberOuterBlockVarAccess:aVariableNode |
579 | 863 |
accessedOuterBlockVars isNil ifTrue:[ |
864 |
accessedOuterBlockVars := OrderedCollection new. |
|
865 |
]. |
|
866 |
accessedOuterBlockVars add:aVariableNode |
|
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
867 |
|
579 | 868 |
"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
|
869 |
! |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
870 |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
871 |
rememberSubBlock:aBlockNode |
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
872 |
subBlocks isNil ifTrue:[ |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
873 |
subBlocks := OrderedCollection new. |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
874 |
]. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
875 |
subBlocks add:aBlockNode |
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
876 |
|
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
877 |
"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
|
878 |
"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
|
879 |
! ! |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
880 |
|
1079 | 881 |
!BlockNode methodsFor:'printing & storing'! |
0 | 882 |
|
883 |
printOn:aStream indent:i |
|
98 | 884 |
|n "{Class: SmallInteger }"| |
885 |
||
0 | 886 |
aStream nextPut:$[. |
98 | 887 |
(n := blockArgs size) > 0 ifTrue:[ |
1723 | 888 |
1 to:n do:[:index | |
889 |
aStream nextPut:$:. |
|
890 |
aStream nextPutAll:(blockArgs at:index) name. |
|
891 |
aStream space. |
|
892 |
]. |
|
893 |
aStream nextPutAll:'| '. |
|
98 | 894 |
]. |
895 |
(n := blockVars size) > 0 ifTrue:[ |
|
1723 | 896 |
aStream nextPut:$|. |
897 |
1 to:n do:[:index | |
|
898 |
aStream nextPutAll:(blockVars at:index) name. |
|
899 |
aStream space. |
|
900 |
]. |
|
901 |
aStream nextPut:$|. |
|
0 | 902 |
]. |
903 |
statements notNil ifTrue:[ |
|
1723 | 904 |
aStream cr. |
905 |
statements printAllOn:aStream indent:i + 4. |
|
906 |
aStream cr. |
|
907 |
aStream spaces:i. |
|
0 | 908 |
]. |
909 |
aStream nextPut:$] |
|
910 |
! ! |
|
140 | 911 |
|
1415 | 912 |
!BlockNode methodsFor:'private-accessing'! |
140 | 913 |
|
3602 | 914 |
setArguments:argList home:h |
915 |
inlineBlock := false. |
|
916 |
needsHome := false. |
|
917 |
blockArgs := argList. |
|
918 |
home := h. |
|
919 |
numTemp := maxNumTemp := 0. |
|
920 |
! |
|
921 |
||
140 | 922 |
setArguments:argList home:h variables:vars |
923 |
inlineBlock := false. |
|
924 |
needsHome := false. |
|
925 |
blockArgs := argList. |
|
926 |
home := h. |
|
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
927 |
blockVars := vars. |
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
928 |
numTemp := maxNumTemp := 0. |
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
929 |
|
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
930 |
"Modified: 25.6.1997 / 15:07:52 / cg" |
3602 | 931 |
! |
932 |
||
933 |
setHome:h |
|
934 |
inlineBlock := false. |
|
935 |
needsHome := false. |
|
936 |
home := h. |
|
937 |
numTemp := maxNumTemp := 0. |
|
140 | 938 |
! ! |
939 |
||
940 |
!BlockNode methodsFor:'queries'! |
|
941 |
||
1566
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
942 |
argumentCount |
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
943 |
"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
|
944 |
expects for evaluation" |
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
945 |
|
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
946 |
^ blockArgs size |
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
947 |
! |
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
948 |
|
394 | 949 |
collectBlocksInto:aCollection |
950 |
aCollection add:self. |
|
458 | 951 |
statements notNil ifTrue:[statements collectBlocksInto:aCollection] |
394 | 952 |
|
953 |
"Created: 23.10.1996 / 15:45:16 / cg" |
|
954 |
"Modified: 23.10.1996 / 16:02:57 / cg" |
|
955 |
! |
|
956 |
||
2383 | 957 |
containsReturn |
958 |
statements isNil ifTrue:[ |
|
959 |
^ false |
|
960 |
]. |
|
961 |
^ statements containsReturnInAnyStatement |
|
962 |
! |
|
963 |
||
333
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
964 |
endsWithReturn |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
965 |
statements isNil ifTrue:[ |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
966 |
^ false |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
967 |
]. |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
968 |
^ statements listEndsWithReturn |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
969 |
|
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
970 |
"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
|
971 |
! |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
972 |
|
559 | 973 |
indexOfFirstTemp |
3182 | 974 |
indexOfFirstTemp isNil ifTrue:[ ^ self numVars ]. |
559 | 975 |
^ indexOfFirstTemp |
976 |
||
977 |
"Created: 25.6.1997 / 15:39:11 / cg" |
|
978 |
! |
|
979 |
||
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
980 |
isInlinable |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
981 |
"return true, if the receiver is inlinable. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
982 |
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
|
983 |
which are accessed by subblocks, which are themself |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
984 |
not inlinable. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
985 |
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
|
986 |
1 to:10 do:[:i | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
987 |
.... [ something with i ] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
988 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
989 |
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
|
990 |
(which is the old ST/V behavior)" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
991 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
992 |
possiblyInlined == true ifFalse:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
993 |
^ false |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
994 |
]. |
2152 | 995 |
inlined == true ifTrue:[ |
996 |
^ true |
|
997 |
]. |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
998 |
|
4074 | 999 |
(self argumentCount ~~ 0 or:[self numVars ~~ 0]) ifTrue:[ |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1000 |
"/ 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
|
1001 |
self allSubBlocksDo:[:aSubBlockNode | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1002 |
aSubBlockNode accessedOuterBlockVars do:[:aVarNode | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1003 |
|b| |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1004 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1005 |
aVarNode block == self ifTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1006 |
"/ all-inbetween inlinable ? |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1007 |
b := aSubBlockNode. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1008 |
[b ~~ self] whileTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1009 |
b isInlinable ifFalse:[ |
575 | 1010 |
"/ '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
|
1011 |
^ false |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1012 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1013 |
b := b home |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1014 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1015 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1016 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1017 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1018 |
]. |
2152 | 1019 |
inlined := true. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1020 |
^ true |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1021 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1022 |
"Created: 2.7.1997 / 10:43:37 / cg" |
579 | 1023 |
"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
|
1024 |
! |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1025 |
|
394 | 1026 |
numArgs |
522 | 1027 |
"return the number of arguments the block represented by myself |
4073 | 1028 |
expects for evaluation. |
1029 |
Please use argumentCount, which is ANSI" |
|
1030 |
||
1031 |
"/ <resource: #obsolete> |
|
522 | 1032 |
|
394 | 1033 |
^ blockArgs size |
1034 |
||
1035 |
"Created: 23.10.1996 / 15:57:04 / cg" |
|
522 | 1036 |
"Modified: 7.5.1997 / 15:34:35 / cg" |
394 | 1037 |
! |
1038 |
||
1039 |
numVars |
|
4074 | 1040 |
"return the number of block local variables." |
1041 |
||
394 | 1042 |
^ blockVars size |
1043 |
||
1044 |
"Created: 23.10.1996 / 16:17:07 / cg" |
|
1045 |
! |
|
1046 |
||
169 | 1047 |
simpleSendBlockExpression |
1048 |
blockVars notNil ifTrue:[^ nil]. |
|
1049 |
statements isNil ifTrue:[^ nil]. |
|
1050 |
statements nextStatement notNil ifTrue:[^ nil]. |
|
1051 |
^ statements expression |
|
1052 |
||
1053 |
"Created: 13.12.1995 / 20:06:09 / cg" |
|
140 | 1054 |
! ! |
1055 |
||
3479 | 1056 |
!BlockNode methodsFor:'statistics'! |
1057 |
||
1058 |
modifiedLocalVars |
|
1059 |
^ modifiedBlockVars |
|
1060 |
! |
|
1061 |
||
1062 |
rememberLocalModified:name |
|
1063 |
modifiedBlockVars isNil ifTrue:[ |
|
1064 |
modifiedBlockVars := Set new. |
|
1065 |
]. |
|
1066 |
modifiedBlockVars add:name. |
|
1067 |
! ! |
|
1068 |
||
2325 | 1069 |
!BlockNode methodsFor:'testing'! |
1070 |
||
1071 |
isBlock |
|
1072 |
"a kludge, to have blocknodes mimic blocks" |
|
1073 |
||
1074 |
^ true |
|
1075 |
! |
|
1076 |
||
1077 |
isBlockNode |
|
1078 |
^ true |
|
1079 |
! |
|
1080 |
||
4161 | 1081 |
isBlockWithArgumentCount:numArgsExpected |
1082 |
"a kludge, to have blocknodes mimic blocks" |
|
1083 |
||
1084 |
^ self numArgs == numArgsExpected |
|
1085 |
||
1086 |
"Created: / 11-07-2017 / 18:28:59 / cg" |
|
1087 |
! |
|
1088 |
||
2325 | 1089 |
isEmptyBlock |
1090 |
^ statements isNil |
|
1091 |
! |
|
1092 |
||
3270 | 1093 |
isInlinedInto: blockNode assumeStcCompiled: assumeStc |
1094 |
"Returns true, if the receiver is inlined into given `blockNode`. |
|
1095 |
If `assumeStc` is true. then assume the code is compiled by stc, |
|
1096 |
otherwise assume that the code is compiled by the bytecode compiler" |
|
1097 |
||
1098 |
| enclosingBlock selector | |
|
1099 |
||
1100 |
self == blockNode ifTrue:[ ^ false ]. |
|
1101 |
enclosingBlock := self enclosingBlock. |
|
1102 |
(enclosingBlock ~~ blockNode |
|
1103 |
and:[ (enclosingBlock isInlinedInto: blockNode assumeStcCompiled: assumeStc) not ]) |
|
1104 |
ifTrue:[ ^ false ]. |
|
1105 |
||
1106 |
self parent isMessage ifFalse:[ ^ false ]. |
|
1107 |
selector := self parent selector. |
|
1108 |
^ assumeStc ifTrue:[ |
|
1109 |
#( |
|
1110 |
ifTrue: |
|
1111 |
ifTrue:ifFalse: |
|
1112 |
ifFalse: |
|
1113 |
whileTrue |
|
1114 |
whileTrue: |
|
1115 |
whileFalse |
|
1116 |
whileFalse: |
|
1117 |
"/ Add more here... |
|
1118 |
) includes: selector |
|
1119 |
] ifFalse:[ |
|
1120 |
#( |
|
1121 |
ifTrue: |
|
1122 |
ifTrue:ifFalse: |
|
1123 |
ifFalse: |
|
1124 |
whileTrue |
|
1125 |
whileTrue: |
|
1126 |
whileFalse |
|
1127 |
whileFalse: |
|
1128 |
"/ Add more here... |
|
1129 |
) includes: selector |
|
1130 |
] |
|
1131 |
||
1132 |
"Created: / 19-08-2013 / 12:00:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1133 |
! |
|
1134 |
||
2325 | 1135 |
isJavaScriptBlock |
1136 |
^ false |
|
1137 |
! |
|
1138 |
||
1139 |
isSingleExpressionBlock |
|
1140 |
^ statements notNil |
|
1141 |
and:[ statements nextStatement isNil |
|
1142 |
and:[ statements isSimpleExpression ]] |
|
1143 |
! ! |
|
1144 |
||
2596 | 1145 |
!BlockNode methodsFor:'visiting'! |
1146 |
||
1147 |
acceptVisitor:aVisitor |
|
1148 |
"Double dispatch back to the visitor, passing my type encoded in |
|
1149 |
the selector (visitor pattern)" |
|
1150 |
||
1151 |
"stub code automatically generated - please change if required" |
|
1152 |
||
1153 |
^ aVisitor visitBlockNode:self |
|
1154 |
! ! |
|
1155 |
||
366 | 1156 |
!BlockNode class methodsFor:'documentation'! |
148 | 1157 |
|
2750 | 1158 |
version |
3893 | 1159 |
^ '$Header$' |
2750 | 1160 |
! |
1161 |
||
2501 | 1162 |
version_CVS |
3893 | 1163 |
^ '$Header$' |
2325 | 1164 |
! |
1165 |
||
2501 | 1166 |
version_SVN |
3182 | 1167 |
^ '$ Id $' |
148 | 1168 |
! ! |
3182 | 1169 |