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