author | sr |
Tue, 21 Feb 2017 16:54:14 +0100 | |
branch | expecco_2_11_0 |
changeset 4129 | c690dec12b7e |
parent 4074 | 504a5c28e9be |
child 4075 | f7fe0ee65732 |
child 4161 | 01a629e181c4 |
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 |
|
1401 | 354 |
|cheapy val isConstRet singleInsn code stackSize| |
140 | 355 |
|
932 | 356 |
isConstRet := false. |
1305 | 357 |
|
140 | 358 |
statements isNil ifTrue:[ |
4074 | 359 |
self argumentCount == 0 ifTrue:[ |
1305 | 360 |
"a []-block" |
361 |
aStream nextPut:#mkNilBlock. |
|
362 |
^ true. |
|
363 |
]. |
|
932 | 364 |
val := nil. |
365 |
isConstRet := true. |
|
4074 | 366 |
] ifFalse:[ |
367 |
statements isConstant ifTrue:[ |
|
368 |
val := statements expression value. |
|
369 |
self numArgs == 0 ifTrue:[ |
|
370 |
val == 0 ifTrue:[ |
|
371 |
aStream nextPut:#mk0Block. |
|
372 |
^ true. |
|
373 |
]. |
|
374 |
val isNil ifTrue:[ |
|
375 |
aStream nextPut:#mkNilBlock. |
|
376 |
^ true. |
|
377 |
]. |
|
378 |
]. |
|
379 |
isConstRet := true. |
|
380 |
] |
|
381 |
]. |
|
140 | 382 |
|
932 | 383 |
isConstRet ifTrue:[ |
384 |
stackSize := 0. |
|
506
3dc049d3a2d7
care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
385 |
|
1305 | 386 |
(val isInteger and:[val between:-128 and:127]) ifTrue:[ |
387 |
"a [-128..127]-block" |
|
388 |
val < 0 ifTrue:[val := val + 256]. |
|
389 |
code := ByteArray with:(ByteCodeCompiler byteCodeFor:#retNum) |
|
390 |
with:val. |
|
391 |
] ifFalse:[val == true ifTrue:[ |
|
392 |
"a [true]-block" |
|
393 |
singleInsn := #retTrue |
|
394 |
] ifFalse:[val == false ifTrue:[ |
|
395 |
"a [false]-block" |
|
396 |
singleInsn := #retFalse |
|
397 |
] ifFalse:[val isNil ifTrue:[ |
|
398 |
"a [nil]-block" |
|
399 |
singleInsn := #retNil |
|
400 |
]]]]. |
|
932 | 401 |
singleInsn notNil ifTrue:[ |
402 |
code := ByteArray with:(ByteCodeCompiler byteCodeFor:singleInsn). |
|
403 |
]. |
|
140 | 404 |
]. |
405 |
||
406 |
code notNil ifTrue:[ |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
407 |
cheapy := CheapBlock |
366 | 408 |
byteCode:code |
409 |
numArgs:(blockArgs size) |
|
1135
7708c6a185a2
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
410 |
numVars:0 |
506
3dc049d3a2d7
care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
411 |
numStack:stackSize |
366 | 412 |
sourcePosition:nil |
413 |
initialPC:nil |
|
414 |
literals:nil. |
|
1305 | 415 |
^ ConstantNode type:#Block value:cheapy. |
140 | 416 |
]. |
417 |
||
418 |
^ nil |
|
366 | 419 |
|
506
3dc049d3a2d7
care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
420 |
"Modified: 13.4.1997 / 00:05:29 / cg" |
140 | 421 |
! |
422 |
||
423 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
|
424 |
"generate code for this statement - value not needed. |
|
425 |
For blocks, no code is generated at all." |
|
426 |
||
2129 | 427 |
aCompiler |
2130 | 428 |
warning:(statements isNil |
429 |
ifTrue:[ 'useless empty block.' ] |
|
430 |
ifFalse:[ 'useless block - the statement(s) inside will not be evaluated.' ]) |
|
2129 | 431 |
position:startPosition to:endPosition. |
140 | 432 |
^ self |
433 |
! |
|
434 |
||
435 |
codeInlineOn:aStream inBlock:b for:aCompiler |
|
436 |
self codeInlineOn:aStream inBlock:b valueNeeded:true for:aCompiler |
|
437 |
! |
|
438 |
||
439 |
codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler |
|
588 | 440 |
|thisStatement nextStatement tmpIndex firstTempIndex codeBlock subAccess| |
140 | 441 |
|
442 |
blockVars notNil ifTrue:[ |
|
559 | 443 |
"/ have to move blockvars into surrounding context |
0 | 444 |
|
559 | 445 |
"/ find the first non-inlined block |
446 |
codeBlock := b. |
|
447 |
[codeBlock notNil and:[codeBlock isInlineBlock]] whileTrue:[ |
|
448 |
codeBlock := codeBlock home. |
|
553 | 449 |
]. |
450 |
||
559 | 451 |
blockVars do:[:aBlockVar | |
452 |
codeBlock isNil ifTrue:[ |
|
453 |
"/ in method - add more temps to the method |
|
454 |
tmpIndex := aCompiler addTempVar. |
|
455 |
] ifFalse:[ |
|
456 |
"/ in another block - add more temps to the block |
|
457 |
tmpIndex := codeBlock addTempVar |
|
458 |
]. |
|
459 |
||
460 |
firstTempIndex isNil ifTrue:[ |
|
461 |
firstTempIndex := tmpIndex. |
|
462 |
indexOfFirstTemp isNil ifTrue:[ |
|
463 |
indexOfFirstTemp := tmpIndex |
|
464 |
]. |
|
465 |
]. |
|
466 |
||
467 |
"/ block vars must be nilled |
|
468 |
"/ (in case the previous block left some value there). |
|
469 |
"/ This nilling should be optimized away, if |
|
470 |
"/ the variable gets a value assigned before the first send. |
|
471 |
||
472 |
aStream nextPut:#pushNil. |
|
473 |
codeBlock isNil ifTrue:[ |
|
474 |
"/ in method |
|
475 |
(tmpIndex <= 6) ifTrue:[ |
|
476 |
aStream nextPut:(#(storeMethodVar1 storeMethodVar2 |
|
477 |
storeMethodVar3 storeMethodVar4 |
|
478 |
storeMethodVar5 storeMethodVar6) at:tmpIndex). |
|
479 |
] ifFalse:[ |
|
480 |
aStream nextPut:#storeMethodVar; nextPut:tmpIndex. |
|
481 |
] |
|
482 |
] ifFalse:[ |
|
483 |
"/ in another block |
|
484 |
aStream nextPut:#storeBlockVar; nextPut:tmpIndex. |
|
485 |
] |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
486 |
]. |
140 | 487 |
]. |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
488 |
|
140 | 489 |
inlineBlock := true. |
555 | 490 |
|
140 | 491 |
statements isNil ifTrue:[ |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
492 |
valueNeeded ifTrue:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
493 |
aStream nextPut:#pushNil |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
494 |
] |
140 | 495 |
] ifFalse:[ |
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
496 |
thisStatement := statements. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
497 |
[thisStatement notNil] whileTrue:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
498 |
nextStatement := thisStatement nextStatement. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
499 |
(nextStatement notNil or:[valueNeeded not]) ifTrue:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
500 |
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
|
501 |
] ifFalse:[ |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
502 |
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
|
503 |
]. |
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
504 |
thisStatement := nextStatement |
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 |
]. |
559 | 507 |
|
386 | 508 |
"/ endLineNr notNil ifTrue:[ |
509 |
"/ ParseNode codeLineNumber:endLineNr on:aStream for:aCompiler |
|
510 |
"/ ]. |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
511 |
|
559 | 512 |
"/ pop off temps (blockVars). |
513 |
"/ also, they are nilled to prevent any temp stuff |
|
514 |
"/ from NOT being garbage collected. |
|
515 |
"/ could optimize here, temps are reused soon. |
|
516 |
||
517 |
blockVars notNil ifTrue:[ |
|
588 | 518 |
"/ if any subblock refers to locals or args, |
519 |
"/ do not nil out ... |
|
520 |
subAccess := false. |
|
521 |
self allSubBlocksDo:[:aSubBlockNode | |
|
522 |
aSubBlockNode accessedOuterBlockVars do:[:aVarNode | |
|
523 |
|b| |
|
524 |
||
525 |
aVarNode block == self ifTrue:[ |
|
526 |
subAccess := true |
|
527 |
] |
|
528 |
] |
|
529 |
]. |
|
530 |
subAccess ifFalse:[ |
|
531 |
tmpIndex := firstTempIndex. |
|
532 |
||
559 | 533 |
blockVars do:[:dummy | |
534 |
aStream nextPut:#pushNil. |
|
588 | 535 |
codeBlock isNil ifTrue:[ |
536 |
aStream nextPut:#storeMethodVar; nextPut:tmpIndex. |
|
593
41a1c4554d83
oops - nilling of inlined subBlock vars ...
Claus Gittinger <cg@exept.de>
parents:
588
diff
changeset
|
537 |
aCompiler removeTempVar. |
588 | 538 |
] ifFalse:[ |
539 |
aStream nextPut:#storeBlockVar; nextPut:tmpIndex. |
|
593
41a1c4554d83
oops - nilling of inlined subBlock vars ...
Claus Gittinger <cg@exept.de>
parents:
588
diff
changeset
|
540 |
codeBlock removeTempVar. |
588 | 541 |
]. |
542 |
tmpIndex := tmpIndex + 1. |
|
543 |
]. |
|
544 |
]. |
|
559 | 545 |
]. |
546 |
||
593
41a1c4554d83
oops - nilling of inlined subBlock vars ...
Claus Gittinger <cg@exept.de>
parents:
588
diff
changeset
|
547 |
"Modified: 30.7.1997 / 12:21:07 / cg" |
140 | 548 |
! |
549 |
||
550 |
codeOn:aStream inBlock:b for:aCompiler |
|
1305 | 551 |
|thisStatement nextStatement lastStatement pos code cheapy| |
140 | 552 |
|
1401 | 553 |
cheapy := self checkForSimpleBlockCodeOn:aStream for:aCompiler. |
140 | 554 |
cheapy notNil ifTrue:[ |
1305 | 555 |
"if result == true - code is already on aStream" |
556 |
cheapy ~~ true ifTrue:[ |
|
557 |
cheapy codeOn:aStream inBlock:b for:aCompiler. |
|
558 |
]. |
|
333
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
559 |
^ self |
140 | 560 |
]. |
561 |
||
1305 | 562 |
"cheap block detection filters out blocks with no statements" |
563 |
||
3265 | 564 |
pos := aStream position. |
62 | 565 |
|
555 | 566 |
aStream nextPut:#makeBlock. "+0" |
567 |
aStream nextPut:0. "+1" |
|
1723 | 568 |
aStream nextPut:(blockVars size + (maxNumTemp?0)). "+2" |
555 | 569 |
aStream nextPut:(blockArgs size). "+3" |
570 |
"+4" |
|
1305 | 571 |
thisStatement := statements. |
572 |
[thisStatement notNil] whileTrue:[ |
|
573 |
nextStatement := thisStatement nextStatement. |
|
574 |
nextStatement notNil ifTrue:[ |
|
575 |
thisStatement codeForSideEffectOn:aStream inBlock:self for:aCompiler |
|
576 |
] ifFalse:[ |
|
577 |
lastStatement := thisStatement |
|
379
24399d5c465c
optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents:
366
diff
changeset
|
578 |
]. |
1305 | 579 |
thisStatement := nextStatement |
140 | 580 |
]. |
581 |
||
1305 | 582 |
lastStatement |
583 |
codeForSimpleReturnOn:aStream |
|
584 |
inBlock:self |
|
585 |
lineNumber:endLineNr |
|
586 |
for:aCompiler. |
|
587 |
||
3262 | 588 |
code := aStream contents. |
562
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
589 |
|
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
590 |
"/ 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
|
591 |
"/ tempVars; patch the nvar byte ... |
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
592 |
|
3262 | 593 |
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
|
594 |
|
1305 | 595 |
"set the end of the block's code" |
3265 | 596 |
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
|
597 |
|
562
36bd00734940
care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents:
559
diff
changeset
|
598 |
"Modified: 26.6.1997 / 10:48:56 / cg" |
555 | 599 |
! ! |
600 |
||
601 |
!BlockNode methodsFor:'code generation helpers'! |
|
602 |
||
603 |
addTempVar |
|
604 |
"add a temporary variable; return its position (1-based). |
|
605 |
Used when a block with args/locals is inlined." |
|
606 |
||
2749 | 607 |
(inlineBlock == true) ifTrue:[ |
1319 | 608 |
self error:'addTempVar to inlineBlock - should not happen' |
585 | 609 |
]. |
559 | 610 |
|
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
611 |
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
|
612 |
numTemp := numTemp + 1. |
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
613 |
maxNumTemp := maxNumTemp max:numTemp. |
559 | 614 |
^ numTemp + self numVars |
555 | 615 |
|
2749 | 616 |
"Modified: / 25-10-2011 / 16:49:50 / cg" |
555 | 617 |
! |
618 |
||
619 |
removeTempVar |
|
620 |
"remove a temporary variable" |
|
621 |
||
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
622 |
numTemp := numTemp - 1. |
555 | 623 |
|
624 |
"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
|
625 |
"Modified: 25.6.1997 / 15:07:07 / cg" |
0 | 626 |
! ! |
627 |
||
1035 | 628 |
!BlockNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
629 |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
630 |
allSubBlocksDo:aBlock |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
631 |
"recursively enumerate all of my subblocks" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
632 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
633 |
subBlocks notNil ifTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
634 |
subBlocks do:[:aSubBlockNode | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
635 |
aBlock value:aSubBlockNode. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
636 |
aSubBlockNode allSubBlocksDo:aBlock. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
637 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
638 |
] |
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 |
"Created: 2.7.1997 / 10:51:59 / cg" |
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 |
|
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
643 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
644 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
645 |
|
544
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
646 |
|args| |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
647 |
|
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
648 |
args := blockArgs ? #(). |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
649 |
args := args collect:[:var | |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
650 |
|p| |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
651 |
|
1933 | 652 |
p := Variable name:var. |
653 |
"/ p := ParameterNode new. |
|
654 |
"/ p variable:var |
|
544
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
655 |
]. |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
656 |
^ anEnumerator doBlock:self arguments:args body:statements |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
657 |
|
1933 | 658 |
"Created: / 19-06-1997 / 16:38:30 / cg" |
659 |
"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
|
660 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
661 |
|
3893 | 662 |
|
1035 | 663 |
!BlockNode methodsFor:'evaluation'! |
0 | 664 |
|
1384 | 665 |
evaluateIn:anEnvironment |
140 | 666 |
^ self |
667 |
! |
|
668 |
||
0 | 669 |
exitWith:something |
670 |
"return via return-statement" |
|
671 |
||
672 |
home notNil ifTrue:[ |
|
45 | 673 |
home exitWith:something |
0 | 674 |
]. |
675 |
exitBlock value:something. |
|
676 |
^ something |
|
677 |
! |
|
678 |
||
679 |
value |
|
680 |
(blockArgs size ~~ 0) ifTrue:[ |
|
1390 | 681 |
^ self wrongNumberOfArguments:0 |
0 | 682 |
]. |
683 |
statements isNil ifTrue:[^ nil]. |
|
684 |
exitBlock := [:val | ^ val]. |
|
685 |
^ statements evaluate |
|
686 |
! |
|
687 |
||
688 |
value:anArg |
|
689 |
|oldValue val| |
|
690 |
||
691 |
(blockArgs size ~~ 1) ifTrue:[ |
|
1390 | 692 |
^ self wrongNumberOfArguments:1 |
0 | 693 |
]. |
694 |
statements isNil ifTrue:[^ nil]. |
|
695 |
||
696 |
oldValue := (blockArgs at:1) value. |
|
697 |
(blockArgs at:1) value:anArg. |
|
698 |
||
15 | 699 |
exitBlock := [:v | |
1390 | 700 |
(blockArgs at:1) value:oldValue. |
701 |
^ v |
|
0 | 702 |
]. |
703 |
||
704 |
val := statements evaluate. |
|
705 |
||
706 |
(blockArgs at:1) value:oldValue. |
|
707 |
^ val |
|
708 |
! |
|
709 |
||
710 |
value:arg1 value:arg2 |
|
711 |
|oldValue1 oldValue2 val| |
|
712 |
||
713 |
(blockArgs size ~~ 2) ifTrue:[ |
|
1390 | 714 |
^ self wrongNumberOfArguments:2 |
0 | 715 |
]. |
716 |
statements isNil ifTrue:[^ nil]. |
|
717 |
||
718 |
oldValue1 := (blockArgs at:1) value. |
|
719 |
oldValue2 := (blockArgs at:2) value. |
|
720 |
(blockArgs at:1) value:arg1. |
|
721 |
(blockArgs at:2) value:arg2. |
|
722 |
||
15 | 723 |
exitBlock := [:v | |
1390 | 724 |
(blockArgs at:1) value:oldValue1. |
725 |
(blockArgs at:2) value:oldValue2. |
|
726 |
^ v |
|
0 | 727 |
]. |
728 |
||
729 |
val := statements evaluate. |
|
730 |
||
731 |
(blockArgs at:1) value:oldValue1. |
|
732 |
(blockArgs at:2) value:oldValue2. |
|
733 |
^ val |
|
734 |
! |
|
735 |
||
736 |
value:arg1 value:arg2 value:arg3 |
|
737 |
|oldValue1 oldValue2 oldValue3 val| |
|
738 |
||
739 |
(blockArgs size ~~ 3) ifTrue:[ |
|
1390 | 740 |
^ self wrongNumberOfArguments:3 |
0 | 741 |
]. |
742 |
statements isNil ifTrue:[^ nil]. |
|
743 |
||
744 |
oldValue1 := (blockArgs at:1) value. |
|
745 |
oldValue2 := (blockArgs at:2) value. |
|
746 |
oldValue3 := (blockArgs at:3) value. |
|
747 |
(blockArgs at:1) value:arg1. |
|
748 |
(blockArgs at:2) value:arg2. |
|
749 |
(blockArgs at:3) value:arg3. |
|
750 |
||
15 | 751 |
exitBlock := [:v | |
1390 | 752 |
(blockArgs at:1) value:oldValue1. |
753 |
(blockArgs at:2) value:oldValue2. |
|
754 |
(blockArgs at:3) value:oldValue3. |
|
755 |
^ v |
|
0 | 756 |
]. |
757 |
||
758 |
val := statements evaluate. |
|
759 |
||
760 |
(blockArgs at:1) value:oldValue1. |
|
761 |
(blockArgs at:2) value:oldValue2. |
|
762 |
(blockArgs at:3) value:oldValue3. |
|
763 |
^ val |
|
764 |
! |
|
765 |
||
766 |
value:arg1 value:arg2 value:arg3 value:arg4 |
|
767 |
|oldValue1 oldValue2 oldValue3 oldValue4 val| |
|
768 |
||
769 |
(blockArgs size ~~ 4) ifTrue:[ |
|
1390 | 770 |
^ self wrongNumberOfArguments:4 |
0 | 771 |
]. |
772 |
statements isNil ifTrue:[^ nil]. |
|
773 |
||
774 |
oldValue1 := (blockArgs at:1) value. |
|
775 |
oldValue2 := (blockArgs at:2) value. |
|
776 |
oldValue3 := (blockArgs at:3) value. |
|
777 |
oldValue4 := (blockArgs at:4) value. |
|
778 |
(blockArgs at:1) value:arg1. |
|
779 |
(blockArgs at:2) value:arg2. |
|
780 |
(blockArgs at:3) value:arg3. |
|
781 |
(blockArgs at:4) value:arg4. |
|
782 |
||
15 | 783 |
exitBlock := [:v | |
1390 | 784 |
(blockArgs at:1) value:oldValue1. |
785 |
(blockArgs at:2) value:oldValue2. |
|
786 |
(blockArgs at:3) value:oldValue3. |
|
787 |
(blockArgs at:4) value:oldValue4. |
|
788 |
^ v |
|
0 | 789 |
]. |
790 |
||
791 |
val := statements evaluate. |
|
792 |
||
793 |
(blockArgs at:1) value:oldValue1. |
|
794 |
(blockArgs at:2) value:oldValue2. |
|
795 |
(blockArgs at:3) value:oldValue3. |
|
796 |
(blockArgs at:4) value:oldValue4. |
|
797 |
^ val |
|
140 | 798 |
! |
3 | 799 |
|
800 |
valueWithArguments:argArray |
|
801 |
|oldValues val| |
|
802 |
||
803 |
(blockArgs size ~~ argArray size) ifTrue:[ |
|
1390 | 804 |
^ self wrongNumberOfArguments:argArray size |
3 | 805 |
]. |
806 |
statements isNil ifTrue:[^ nil]. |
|
807 |
||
808 |
oldValues := Array new:(argArray size). |
|
809 |
1 to:argArray size do:[:i | |
|
1390 | 810 |
oldValues at:i put:(blockArgs at:i) value. |
811 |
(blockArgs at:i) value:(argArray at:i). |
|
3 | 812 |
]. |
15 | 813 |
exitBlock := [:v | |
1390 | 814 |
1 to:argArray size do:[:i | |
815 |
( blockArgs at:i) value:(oldValues at:i) |
|
816 |
]. |
|
817 |
^ v |
|
3 | 818 |
]. |
819 |
||
820 |
val := statements evaluate. |
|
821 |
||
822 |
1 to:argArray size do:[:i | |
|
1390 | 823 |
(blockArgs at:i) value:(oldValues at:i) |
3 | 824 |
]. |
825 |
^ val |
|
140 | 826 |
! |
827 |
||
1390 | 828 |
wrongNumberOfArguments:numArgsGiven |
584
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
829 |
"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
|
830 |
|
1390 | 831 |
WrongNumberOfArgumentsError |
584
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
832 |
raiseRequestWith:self |
2077
127ac6e095ad
wrongNumberOfArguments: error message
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
833 |
errorString:('block got %1 arg(s) where %2 expected' |
127ac6e095ad
wrongNumberOfArguments: error message
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
834 |
bindWith:numArgsGiven |
127ac6e095ad
wrongNumberOfArguments: error message
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
835 |
with:blockArgs size) |
584
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
836 |
|
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
837 |
"Modified: 8.7.1997 / 01:04:27 / stefan" |
0 | 838 |
! ! |
839 |
||
840 |
!BlockNode methodsFor:'looping'! |
|
841 |
||
842 |
whileFalse:aBlock |
|
26 | 843 |
self value ifTrue:[^ nil]. |
844 |
aBlock value. |
|
845 |
thisContext restart |
|
0 | 846 |
! |
847 |
||
140 | 848 |
whileTrue:aBlock |
1853 | 849 |
"evaluate the argument, aBlock while the receiver evaluates to true." |
850 |
||
140 | 851 |
self value ifFalse:[^ nil]. |
852 |
aBlock value. |
|
853 |
thisContext restart |
|
1853 | 854 |
|
855 |
"Modified: / 22-08-2006 / 14:40:48 / cg" |
|
0 | 856 |
! ! |
857 |
||
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
858 |
!BlockNode methodsFor:'misc'! |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
859 |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
860 |
rememberOuterBlockVarAccess:aVariableNode |
579 | 861 |
accessedOuterBlockVars isNil ifTrue:[ |
862 |
accessedOuterBlockVars := OrderedCollection new. |
|
863 |
]. |
|
864 |
accessedOuterBlockVars add:aVariableNode |
|
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
865 |
|
579 | 866 |
"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
|
867 |
! |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
868 |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
869 |
rememberSubBlock:aBlockNode |
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
870 |
subBlocks isNil ifTrue:[ |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
871 |
subBlocks := OrderedCollection new. |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
872 |
]. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
873 |
subBlocks add:aBlockNode |
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
874 |
|
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
875 |
"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
|
876 |
"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
|
877 |
! ! |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
878 |
|
1079 | 879 |
!BlockNode methodsFor:'printing & storing'! |
0 | 880 |
|
881 |
printOn:aStream indent:i |
|
98 | 882 |
|n "{Class: SmallInteger }"| |
883 |
||
0 | 884 |
aStream nextPut:$[. |
98 | 885 |
(n := blockArgs size) > 0 ifTrue:[ |
1723 | 886 |
1 to:n do:[:index | |
887 |
aStream nextPut:$:. |
|
888 |
aStream nextPutAll:(blockArgs at:index) name. |
|
889 |
aStream space. |
|
890 |
]. |
|
891 |
aStream nextPutAll:'| '. |
|
98 | 892 |
]. |
893 |
(n := blockVars size) > 0 ifTrue:[ |
|
1723 | 894 |
aStream nextPut:$|. |
895 |
1 to:n do:[:index | |
|
896 |
aStream nextPutAll:(blockVars at:index) name. |
|
897 |
aStream space. |
|
898 |
]. |
|
899 |
aStream nextPut:$|. |
|
0 | 900 |
]. |
901 |
statements notNil ifTrue:[ |
|
1723 | 902 |
aStream cr. |
903 |
statements printAllOn:aStream indent:i + 4. |
|
904 |
aStream cr. |
|
905 |
aStream spaces:i. |
|
0 | 906 |
]. |
907 |
aStream nextPut:$] |
|
908 |
! ! |
|
140 | 909 |
|
1415 | 910 |
!BlockNode methodsFor:'private-accessing'! |
140 | 911 |
|
3602 | 912 |
setArguments:argList home:h |
913 |
inlineBlock := false. |
|
914 |
needsHome := false. |
|
915 |
blockArgs := argList. |
|
916 |
home := h. |
|
917 |
numTemp := maxNumTemp := 0. |
|
918 |
! |
|
919 |
||
140 | 920 |
setArguments:argList home:h variables:vars |
921 |
inlineBlock := false. |
|
922 |
needsHome := false. |
|
923 |
blockArgs := argList. |
|
924 |
home := h. |
|
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
925 |
blockVars := vars. |
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
926 |
numTemp := maxNumTemp := 0. |
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
927 |
|
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
928 |
"Modified: 25.6.1997 / 15:07:52 / cg" |
3602 | 929 |
! |
930 |
||
931 |
setHome:h |
|
932 |
inlineBlock := false. |
|
933 |
needsHome := false. |
|
934 |
home := h. |
|
935 |
numTemp := maxNumTemp := 0. |
|
140 | 936 |
! ! |
937 |
||
938 |
!BlockNode methodsFor:'queries'! |
|
939 |
||
1566
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
940 |
argumentCount |
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
941 |
"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
|
942 |
expects for evaluation" |
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
943 |
|
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
944 |
^ blockArgs size |
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 |
|
394 | 947 |
collectBlocksInto:aCollection |
948 |
aCollection add:self. |
|
458 | 949 |
statements notNil ifTrue:[statements collectBlocksInto:aCollection] |
394 | 950 |
|
951 |
"Created: 23.10.1996 / 15:45:16 / cg" |
|
952 |
"Modified: 23.10.1996 / 16:02:57 / cg" |
|
953 |
! |
|
954 |
||
2383 | 955 |
containsReturn |
956 |
statements isNil ifTrue:[ |
|
957 |
^ false |
|
958 |
]. |
|
959 |
^ statements containsReturnInAnyStatement |
|
960 |
! |
|
961 |
||
333
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
962 |
endsWithReturn |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
963 |
statements isNil ifTrue:[ |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
964 |
^ false |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
965 |
]. |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
966 |
^ statements listEndsWithReturn |
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 |
"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
|
969 |
! |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
970 |
|
559 | 971 |
indexOfFirstTemp |
3182 | 972 |
indexOfFirstTemp isNil ifTrue:[ ^ self numVars ]. |
559 | 973 |
^ indexOfFirstTemp |
974 |
||
975 |
"Created: 25.6.1997 / 15:39:11 / cg" |
|
976 |
! |
|
977 |
||
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
978 |
isInlinable |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
979 |
"return true, if the receiver is inlinable. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
980 |
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
|
981 |
which are accessed by subblocks, which are themself |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
982 |
not inlinable. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
983 |
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
|
984 |
1 to:10 do:[:i | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
985 |
.... [ something with i ] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
986 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
987 |
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
|
988 |
(which is the old ST/V behavior)" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
989 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
990 |
possiblyInlined == true ifFalse:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
991 |
^ false |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
992 |
]. |
2152 | 993 |
inlined == true ifTrue:[ |
994 |
^ true |
|
995 |
]. |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
996 |
|
4074 | 997 |
(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
|
998 |
"/ 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
|
999 |
self allSubBlocksDo:[:aSubBlockNode | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1000 |
aSubBlockNode accessedOuterBlockVars do:[:aVarNode | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1001 |
|b| |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1002 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1003 |
aVarNode block == self ifTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1004 |
"/ all-inbetween inlinable ? |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1005 |
b := aSubBlockNode. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1006 |
[b ~~ self] whileTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1007 |
b isInlinable ifFalse:[ |
575 | 1008 |
"/ '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
|
1009 |
^ false |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1010 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1011 |
b := b home |
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 |
] |
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 |
]. |
2152 | 1017 |
inlined := true. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1018 |
^ true |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1019 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1020 |
"Created: 2.7.1997 / 10:43:37 / cg" |
579 | 1021 |
"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
|
1022 |
! |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1023 |
|
394 | 1024 |
numArgs |
522 | 1025 |
"return the number of arguments the block represented by myself |
4073 | 1026 |
expects for evaluation. |
1027 |
Please use argumentCount, which is ANSI" |
|
1028 |
||
1029 |
"/ <resource: #obsolete> |
|
522 | 1030 |
|
394 | 1031 |
^ blockArgs size |
1032 |
||
1033 |
"Created: 23.10.1996 / 15:57:04 / cg" |
|
522 | 1034 |
"Modified: 7.5.1997 / 15:34:35 / cg" |
394 | 1035 |
! |
1036 |
||
1037 |
numVars |
|
4074 | 1038 |
"return the number of block local variables." |
1039 |
||
394 | 1040 |
^ blockVars size |
1041 |
||
1042 |
"Created: 23.10.1996 / 16:17:07 / cg" |
|
1043 |
! |
|
1044 |
||
169 | 1045 |
simpleSendBlockExpression |
1046 |
blockVars notNil ifTrue:[^ nil]. |
|
1047 |
statements isNil ifTrue:[^ nil]. |
|
1048 |
statements nextStatement notNil ifTrue:[^ nil]. |
|
1049 |
^ statements expression |
|
1050 |
||
1051 |
"Created: 13.12.1995 / 20:06:09 / cg" |
|
140 | 1052 |
! ! |
1053 |
||
3479 | 1054 |
!BlockNode methodsFor:'statistics'! |
1055 |
||
1056 |
modifiedLocalVars |
|
1057 |
^ modifiedBlockVars |
|
1058 |
! |
|
1059 |
||
1060 |
rememberLocalModified:name |
|
1061 |
modifiedBlockVars isNil ifTrue:[ |
|
1062 |
modifiedBlockVars := Set new. |
|
1063 |
]. |
|
1064 |
modifiedBlockVars add:name. |
|
1065 |
! ! |
|
1066 |
||
2325 | 1067 |
!BlockNode methodsFor:'testing'! |
1068 |
||
1069 |
isBlock |
|
1070 |
"a kludge, to have blocknodes mimic blocks" |
|
1071 |
||
1072 |
^ true |
|
1073 |
! |
|
1074 |
||
1075 |
isBlockNode |
|
1076 |
^ true |
|
1077 |
! |
|
1078 |
||
1079 |
isEmptyBlock |
|
1080 |
^ statements isNil |
|
1081 |
! |
|
1082 |
||
3270 | 1083 |
isInlinedInto: blockNode assumeStcCompiled: assumeStc |
1084 |
"Returns true, if the receiver is inlined into given `blockNode`. |
|
1085 |
If `assumeStc` is true. then assume the code is compiled by stc, |
|
1086 |
otherwise assume that the code is compiled by the bytecode compiler" |
|
1087 |
||
1088 |
| enclosingBlock selector | |
|
1089 |
||
1090 |
self == blockNode ifTrue:[ ^ false ]. |
|
1091 |
enclosingBlock := self enclosingBlock. |
|
1092 |
(enclosingBlock ~~ blockNode |
|
1093 |
and:[ (enclosingBlock isInlinedInto: blockNode assumeStcCompiled: assumeStc) not ]) |
|
1094 |
ifTrue:[ ^ false ]. |
|
1095 |
||
1096 |
self parent isMessage ifFalse:[ ^ false ]. |
|
1097 |
selector := self parent selector. |
|
1098 |
^ assumeStc ifTrue:[ |
|
1099 |
#( |
|
1100 |
ifTrue: |
|
1101 |
ifTrue:ifFalse: |
|
1102 |
ifFalse: |
|
1103 |
whileTrue |
|
1104 |
whileTrue: |
|
1105 |
whileFalse |
|
1106 |
whileFalse: |
|
1107 |
"/ Add more here... |
|
1108 |
) includes: selector |
|
1109 |
] ifFalse:[ |
|
1110 |
#( |
|
1111 |
ifTrue: |
|
1112 |
ifTrue:ifFalse: |
|
1113 |
ifFalse: |
|
1114 |
whileTrue |
|
1115 |
whileTrue: |
|
1116 |
whileFalse |
|
1117 |
whileFalse: |
|
1118 |
"/ Add more here... |
|
1119 |
) includes: selector |
|
1120 |
] |
|
1121 |
||
1122 |
"Created: / 19-08-2013 / 12:00:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1123 |
! |
|
1124 |
||
2325 | 1125 |
isJavaScriptBlock |
1126 |
^ false |
|
1127 |
! |
|
1128 |
||
1129 |
isSingleExpressionBlock |
|
1130 |
^ statements notNil |
|
1131 |
and:[ statements nextStatement isNil |
|
1132 |
and:[ statements isSimpleExpression ]] |
|
1133 |
! ! |
|
1134 |
||
2596 | 1135 |
!BlockNode methodsFor:'visiting'! |
1136 |
||
1137 |
acceptVisitor:aVisitor |
|
1138 |
"Double dispatch back to the visitor, passing my type encoded in |
|
1139 |
the selector (visitor pattern)" |
|
1140 |
||
1141 |
"stub code automatically generated - please change if required" |
|
1142 |
||
1143 |
^ aVisitor visitBlockNode:self |
|
1144 |
! ! |
|
1145 |
||
366 | 1146 |
!BlockNode class methodsFor:'documentation'! |
148 | 1147 |
|
2750 | 1148 |
version |
3893 | 1149 |
^ '$Header$' |
2750 | 1150 |
! |
1151 |
||
2501 | 1152 |
version_CVS |
3893 | 1153 |
^ '$Header$' |
2325 | 1154 |
! |
1155 |
||
2501 | 1156 |
version_SVN |
3182 | 1157 |
^ '$ Id $' |
148 | 1158 |
! ! |
3182 | 1159 |