author | Claus Gittinger <cg@exept.de> |
Tue, 25 Feb 2020 13:40:16 +0100 | |
changeset 4643 | e305b814a348 |
parent 4603 | 3a51687ca153 |
child 4723 | 524785227024 |
permissions | -rw-r--r-- |
4577 | 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. |
|
4556 | 373 |
self argumentCount == 0 ifTrue:[ |
4074 | 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 |
|
4575 | 634 |
allMessageSelectorsDo:aBlock |
635 |
"evaluate aBlock for each message-selector sent by this statement and all followup statements" |
|
636 |
||
4603 | 637 |
statements notEmptyOrNil ifTrue:[ |
638 |
statements allMessageSelectorsDo:aBlock |
|
639 |
] |
|
4575 | 640 |
! |
641 |
||
642 |
allMessagesDo:aBlock |
|
643 |
"evaluate aBlock for each message-node sent by this statement and all followup statements" |
|
644 |
||
4603 | 645 |
statements notEmptyOrNil ifTrue:[ |
646 |
statements allMessagesDo:aBlock |
|
647 |
]. |
|
4575 | 648 |
! |
649 |
||
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
650 |
allSubBlocksDo:aBlock |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
651 |
"recursively enumerate all of my subblocks" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
652 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
653 |
subBlocks notNil ifTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
654 |
subBlocks do:[:aSubBlockNode | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
655 |
aBlock value:aSubBlockNode. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
656 |
aSubBlockNode allSubBlocksDo:aBlock. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
657 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
658 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
659 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
660 |
"Created: 2.7.1997 / 10:51:59 / cg" |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
661 |
! |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
662 |
|
4577 | 663 |
messageSelectorsDo:aBlock |
664 |
"evaluate aBlock for each message-selector sent by this statement and all followup statements" |
|
665 |
||
666 |
statements allMessageSelectorsDo:aBlock |
|
667 |
! |
|
668 |
||
669 |
messagesDo:aBlock |
|
670 |
"evaluate aBlock for each message-node sent by this statement and all followup statements" |
|
671 |
||
4603 | 672 |
statements notEmptyOrNil ifTrue:[ |
673 |
statements allMessagesDo:aBlock |
|
674 |
] |
|
4577 | 675 |
! |
676 |
||
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
677 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
678 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
679 |
|
544
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
680 |
|args| |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
681 |
|
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
682 |
args := blockArgs ? #(). |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
683 |
args := args collect:[:var | |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
684 |
|p| |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
685 |
|
1933 | 686 |
p := Variable name:var. |
687 |
"/ p := ParameterNode new. |
|
688 |
"/ p variable:var |
|
544
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
689 |
]. |
fcfff6f8bc31
more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents:
539
diff
changeset
|
690 |
^ anEnumerator doBlock:self arguments:args body:statements |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
691 |
|
1933 | 692 |
"Created: / 19-06-1997 / 16:38:30 / cg" |
693 |
"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
|
694 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
534
diff
changeset
|
695 |
|
3893 | 696 |
|
1035 | 697 |
!BlockNode methodsFor:'evaluation'! |
0 | 698 |
|
1384 | 699 |
evaluateIn:anEnvironment |
140 | 700 |
^ self |
701 |
! |
|
702 |
||
0 | 703 |
exitWith:something |
704 |
"return via return-statement" |
|
705 |
||
706 |
home notNil ifTrue:[ |
|
45 | 707 |
home exitWith:something |
0 | 708 |
]. |
709 |
exitBlock value:something. |
|
710 |
^ something |
|
711 |
! |
|
712 |
||
713 |
value |
|
714 |
(blockArgs size ~~ 0) ifTrue:[ |
|
1390 | 715 |
^ self wrongNumberOfArguments:0 |
0 | 716 |
]. |
717 |
statements isNil ifTrue:[^ nil]. |
|
718 |
exitBlock := [:val | ^ val]. |
|
719 |
^ statements evaluate |
|
720 |
! |
|
721 |
||
722 |
value:anArg |
|
723 |
|oldValue val| |
|
724 |
||
725 |
(blockArgs size ~~ 1) ifTrue:[ |
|
1390 | 726 |
^ self wrongNumberOfArguments:1 |
0 | 727 |
]. |
728 |
statements isNil ifTrue:[^ nil]. |
|
729 |
||
730 |
oldValue := (blockArgs at:1) value. |
|
731 |
(blockArgs at:1) value:anArg. |
|
732 |
||
15 | 733 |
exitBlock := [:v | |
1390 | 734 |
(blockArgs at:1) value:oldValue. |
735 |
^ v |
|
0 | 736 |
]. |
737 |
||
738 |
val := statements evaluate. |
|
739 |
||
740 |
(blockArgs at:1) value:oldValue. |
|
741 |
^ val |
|
742 |
! |
|
743 |
||
744 |
value:arg1 value:arg2 |
|
745 |
|oldValue1 oldValue2 val| |
|
746 |
||
747 |
(blockArgs size ~~ 2) ifTrue:[ |
|
1390 | 748 |
^ self wrongNumberOfArguments:2 |
0 | 749 |
]. |
750 |
statements isNil ifTrue:[^ nil]. |
|
751 |
||
752 |
oldValue1 := (blockArgs at:1) value. |
|
753 |
oldValue2 := (blockArgs at:2) value. |
|
754 |
(blockArgs at:1) value:arg1. |
|
755 |
(blockArgs at:2) value:arg2. |
|
756 |
||
15 | 757 |
exitBlock := [:v | |
1390 | 758 |
(blockArgs at:1) value:oldValue1. |
759 |
(blockArgs at:2) value:oldValue2. |
|
760 |
^ v |
|
0 | 761 |
]. |
762 |
||
763 |
val := statements evaluate. |
|
764 |
||
765 |
(blockArgs at:1) value:oldValue1. |
|
766 |
(blockArgs at:2) value:oldValue2. |
|
767 |
^ val |
|
768 |
! |
|
769 |
||
770 |
value:arg1 value:arg2 value:arg3 |
|
771 |
|oldValue1 oldValue2 oldValue3 val| |
|
772 |
||
773 |
(blockArgs size ~~ 3) ifTrue:[ |
|
1390 | 774 |
^ self wrongNumberOfArguments:3 |
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 |
(blockArgs at:1) value:arg1. |
|
782 |
(blockArgs at:2) value:arg2. |
|
783 |
(blockArgs at:3) value:arg3. |
|
784 |
||
15 | 785 |
exitBlock := [:v | |
1390 | 786 |
(blockArgs at:1) value:oldValue1. |
787 |
(blockArgs at:2) value:oldValue2. |
|
788 |
(blockArgs at:3) value:oldValue3. |
|
789 |
^ v |
|
0 | 790 |
]. |
791 |
||
792 |
val := statements evaluate. |
|
793 |
||
794 |
(blockArgs at:1) value:oldValue1. |
|
795 |
(blockArgs at:2) value:oldValue2. |
|
796 |
(blockArgs at:3) value:oldValue3. |
|
797 |
^ val |
|
798 |
! |
|
799 |
||
800 |
value:arg1 value:arg2 value:arg3 value:arg4 |
|
801 |
|oldValue1 oldValue2 oldValue3 oldValue4 val| |
|
802 |
||
803 |
(blockArgs size ~~ 4) ifTrue:[ |
|
1390 | 804 |
^ self wrongNumberOfArguments:4 |
0 | 805 |
]. |
806 |
statements isNil ifTrue:[^ nil]. |
|
807 |
||
808 |
oldValue1 := (blockArgs at:1) value. |
|
809 |
oldValue2 := (blockArgs at:2) value. |
|
810 |
oldValue3 := (blockArgs at:3) value. |
|
811 |
oldValue4 := (blockArgs at:4) value. |
|
812 |
(blockArgs at:1) value:arg1. |
|
813 |
(blockArgs at:2) value:arg2. |
|
814 |
(blockArgs at:3) value:arg3. |
|
815 |
(blockArgs at:4) value:arg4. |
|
816 |
||
15 | 817 |
exitBlock := [:v | |
1390 | 818 |
(blockArgs at:1) value:oldValue1. |
819 |
(blockArgs at:2) value:oldValue2. |
|
820 |
(blockArgs at:3) value:oldValue3. |
|
821 |
(blockArgs at:4) value:oldValue4. |
|
822 |
^ v |
|
0 | 823 |
]. |
824 |
||
825 |
val := statements evaluate. |
|
826 |
||
827 |
(blockArgs at:1) value:oldValue1. |
|
828 |
(blockArgs at:2) value:oldValue2. |
|
829 |
(blockArgs at:3) value:oldValue3. |
|
830 |
(blockArgs at:4) value:oldValue4. |
|
831 |
^ val |
|
140 | 832 |
! |
3 | 833 |
|
834 |
valueWithArguments:argArray |
|
835 |
|oldValues val| |
|
836 |
||
837 |
(blockArgs size ~~ argArray size) ifTrue:[ |
|
1390 | 838 |
^ self wrongNumberOfArguments:argArray size |
3 | 839 |
]. |
840 |
statements isNil ifTrue:[^ nil]. |
|
841 |
||
842 |
oldValues := Array new:(argArray size). |
|
843 |
1 to:argArray size do:[:i | |
|
1390 | 844 |
oldValues at:i put:(blockArgs at:i) value. |
845 |
(blockArgs at:i) value:(argArray at:i). |
|
3 | 846 |
]. |
15 | 847 |
exitBlock := [:v | |
1390 | 848 |
1 to:argArray size do:[:i | |
849 |
( blockArgs at:i) value:(oldValues at:i) |
|
850 |
]. |
|
851 |
^ v |
|
3 | 852 |
]. |
853 |
||
854 |
val := statements evaluate. |
|
855 |
||
856 |
1 to:argArray size do:[:i | |
|
1390 | 857 |
(blockArgs at:i) value:(oldValues at:i) |
3 | 858 |
]. |
859 |
^ val |
|
140 | 860 |
! |
861 |
||
1390 | 862 |
wrongNumberOfArguments:numArgsGiven |
584
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
863 |
"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
|
864 |
|
1390 | 865 |
WrongNumberOfArgumentsError |
584
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
866 |
raiseRequestWith:self |
2077
127ac6e095ad
wrongNumberOfArguments: error message
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
867 |
errorString:('block got %1 arg(s) where %2 expected' |
127ac6e095ad
wrongNumberOfArguments: error message
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
868 |
bindWith:numArgsGiven |
127ac6e095ad
wrongNumberOfArguments: error message
Claus Gittinger <cg@exept.de>
parents:
2056
diff
changeset
|
869 |
with:blockArgs size) |
584
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
870 |
|
23b2124d7765
Fix spelling for wrongNumberOfArguments message.
Stefan Vogel <sv@exept.de>
parents:
579
diff
changeset
|
871 |
"Modified: 8.7.1997 / 01:04:27 / stefan" |
0 | 872 |
! ! |
873 |
||
874 |
!BlockNode methodsFor:'looping'! |
|
875 |
||
876 |
whileFalse:aBlock |
|
26 | 877 |
self value ifTrue:[^ nil]. |
878 |
aBlock value. |
|
879 |
thisContext restart |
|
0 | 880 |
! |
881 |
||
140 | 882 |
whileTrue:aBlock |
1853 | 883 |
"evaluate the argument, aBlock while the receiver evaluates to true." |
884 |
||
140 | 885 |
self value ifFalse:[^ nil]. |
886 |
aBlock value. |
|
887 |
thisContext restart |
|
1853 | 888 |
|
889 |
"Modified: / 22-08-2006 / 14:40:48 / cg" |
|
0 | 890 |
! ! |
891 |
||
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
892 |
!BlockNode methodsFor:'misc'! |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
893 |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
894 |
rememberOuterBlockVarAccess:aVariableNode |
579 | 895 |
accessedOuterBlockVars isNil ifTrue:[ |
896 |
accessedOuterBlockVars := OrderedCollection new. |
|
897 |
]. |
|
898 |
accessedOuterBlockVars add:aVariableNode |
|
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
899 |
|
579 | 900 |
"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
|
901 |
! |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
902 |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
903 |
rememberSubBlock:aBlockNode |
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
904 |
subBlocks isNil ifTrue:[ |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
905 |
subBlocks := OrderedCollection new. |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
906 |
]. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
907 |
subBlocks add:aBlockNode |
569
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
908 |
|
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
909 |
"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
|
910 |
"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
|
911 |
! ! |
88a1b1d118fd
preps to remember used args/vars
Claus Gittinger <cg@exept.de>
parents:
562
diff
changeset
|
912 |
|
1079 | 913 |
!BlockNode methodsFor:'printing & storing'! |
0 | 914 |
|
915 |
printOn:aStream indent:i |
|
98 | 916 |
|n "{Class: SmallInteger }"| |
917 |
||
0 | 918 |
aStream nextPut:$[. |
98 | 919 |
(n := blockArgs size) > 0 ifTrue:[ |
1723 | 920 |
1 to:n do:[:index | |
921 |
aStream nextPut:$:. |
|
922 |
aStream nextPutAll:(blockArgs at:index) name. |
|
923 |
aStream space. |
|
924 |
]. |
|
925 |
aStream nextPutAll:'| '. |
|
98 | 926 |
]. |
927 |
(n := blockVars size) > 0 ifTrue:[ |
|
1723 | 928 |
aStream nextPut:$|. |
929 |
1 to:n do:[:index | |
|
930 |
aStream nextPutAll:(blockVars at:index) name. |
|
931 |
aStream space. |
|
932 |
]. |
|
933 |
aStream nextPut:$|. |
|
0 | 934 |
]. |
935 |
statements notNil ifTrue:[ |
|
1723 | 936 |
aStream cr. |
937 |
statements printAllOn:aStream indent:i + 4. |
|
938 |
aStream cr. |
|
939 |
aStream spaces:i. |
|
0 | 940 |
]. |
941 |
aStream nextPut:$] |
|
942 |
! ! |
|
140 | 943 |
|
1415 | 944 |
!BlockNode methodsFor:'private-accessing'! |
140 | 945 |
|
3602 | 946 |
setArguments:argList home:h |
947 |
inlineBlock := false. |
|
948 |
needsHome := false. |
|
949 |
blockArgs := argList. |
|
950 |
home := h. |
|
951 |
numTemp := maxNumTemp := 0. |
|
952 |
! |
|
953 |
||
140 | 954 |
setArguments:argList home:h variables:vars |
955 |
inlineBlock := false. |
|
956 |
needsHome := false. |
|
957 |
blockArgs := argList. |
|
958 |
home := h. |
|
557
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
959 |
blockVars := vars. |
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
960 |
numTemp := maxNumTemp := 0. |
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
961 |
|
8202a13be88b
preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents:
555
diff
changeset
|
962 |
"Modified: 25.6.1997 / 15:07:52 / cg" |
3602 | 963 |
! |
964 |
||
965 |
setHome:h |
|
966 |
inlineBlock := false. |
|
967 |
needsHome := false. |
|
968 |
home := h. |
|
969 |
numTemp := maxNumTemp := 0. |
|
140 | 970 |
! ! |
971 |
||
972 |
!BlockNode methodsFor:'queries'! |
|
973 |
||
1566
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
974 |
argumentCount |
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
975 |
"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
|
976 |
expects for evaluation" |
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
977 |
|
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
978 |
^ blockArgs size |
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
979 |
! |
e53724995493
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
1513
diff
changeset
|
980 |
|
394 | 981 |
collectBlocksInto:aCollection |
982 |
aCollection add:self. |
|
458 | 983 |
statements notNil ifTrue:[statements collectBlocksInto:aCollection] |
394 | 984 |
|
985 |
"Created: 23.10.1996 / 15:45:16 / cg" |
|
986 |
"Modified: 23.10.1996 / 16:02:57 / cg" |
|
987 |
! |
|
988 |
||
2383 | 989 |
containsReturn |
990 |
statements isNil ifTrue:[ |
|
991 |
^ false |
|
992 |
]. |
|
993 |
^ statements containsReturnInAnyStatement |
|
994 |
! |
|
995 |
||
333
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
996 |
endsWithReturn |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
997 |
statements isNil ifTrue:[ |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
998 |
^ false |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
999 |
]. |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
1000 |
^ statements listEndsWithReturn |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
1001 |
|
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
1002 |
"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
|
1003 |
! |
96bb5c3dab61
added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
1004 |
|
559 | 1005 |
indexOfFirstTemp |
3182 | 1006 |
indexOfFirstTemp isNil ifTrue:[ ^ self numVars ]. |
559 | 1007 |
^ indexOfFirstTemp |
1008 |
||
1009 |
"Created: 25.6.1997 / 15:39:11 / cg" |
|
1010 |
! |
|
1011 |
||
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1012 |
isInlinable |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1013 |
"return true, if the receiver is inlinable. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1014 |
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
|
1015 |
which are accessed by subblocks, which are themself |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1016 |
not inlinable. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1017 |
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
|
1018 |
1 to:10 do:[:i | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1019 |
.... [ something with i ] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1020 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1021 |
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
|
1022 |
(which is the old ST/V behavior)" |
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 |
possiblyInlined == true ifFalse:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1025 |
^ false |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1026 |
]. |
2152 | 1027 |
inlined == true ifTrue:[ |
1028 |
^ true |
|
1029 |
]. |
|
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1030 |
|
4074 | 1031 |
(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
|
1032 |
"/ 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
|
1033 |
self allSubBlocksDo:[:aSubBlockNode | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1034 |
aSubBlockNode accessedOuterBlockVars do:[:aVarNode | |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1035 |
|b| |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1036 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1037 |
aVarNode block == self ifTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1038 |
"/ all-inbetween inlinable ? |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1039 |
b := aSubBlockNode. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1040 |
[b ~~ self] whileTrue:[ |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1041 |
b isInlinable ifFalse:[ |
575 | 1042 |
"/ '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
|
1043 |
^ false |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1044 |
]. |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1045 |
b := b home |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1046 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1047 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1048 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1049 |
] |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1050 |
]. |
2152 | 1051 |
inlined := true. |
574
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1052 |
^ true |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1053 |
|
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1054 |
"Created: 2.7.1997 / 10:43:37 / cg" |
579 | 1055 |
"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
|
1056 |
! |
993d1182782b
fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents:
569
diff
changeset
|
1057 |
|
394 | 1058 |
numArgs |
4556 | 1059 |
<resource: #obsolete> |
1060 |
||
522 | 1061 |
"return the number of arguments the block represented by myself |
4073 | 1062 |
expects for evaluation. |
1063 |
Please use argumentCount, which is ANSI" |
|
1064 |
||
1065 |
"/ <resource: #obsolete> |
|
522 | 1066 |
|
394 | 1067 |
^ blockArgs size |
1068 |
||
1069 |
"Created: 23.10.1996 / 15:57:04 / cg" |
|
522 | 1070 |
"Modified: 7.5.1997 / 15:34:35 / cg" |
394 | 1071 |
! |
1072 |
||
1073 |
numVars |
|
4074 | 1074 |
"return the number of block local variables." |
1075 |
||
394 | 1076 |
^ blockVars size |
1077 |
||
1078 |
"Created: 23.10.1996 / 16:17:07 / cg" |
|
1079 |
! |
|
1080 |
||
169 | 1081 |
simpleSendBlockExpression |
1082 |
blockVars notNil ifTrue:[^ nil]. |
|
1083 |
statements isNil ifTrue:[^ nil]. |
|
1084 |
statements nextStatement notNil ifTrue:[^ nil]. |
|
1085 |
^ statements expression |
|
1086 |
||
1087 |
"Created: 13.12.1995 / 20:06:09 / cg" |
|
140 | 1088 |
! ! |
1089 |
||
3479 | 1090 |
!BlockNode methodsFor:'statistics'! |
1091 |
||
1092 |
modifiedLocalVars |
|
1093 |
^ modifiedBlockVars |
|
1094 |
! |
|
1095 |
||
1096 |
rememberLocalModified:name |
|
1097 |
modifiedBlockVars isNil ifTrue:[ |
|
1098 |
modifiedBlockVars := Set new. |
|
1099 |
]. |
|
1100 |
modifiedBlockVars add:name. |
|
1101 |
! ! |
|
1102 |
||
2325 | 1103 |
!BlockNode methodsFor:'testing'! |
1104 |
||
1105 |
isBlock |
|
1106 |
"a kludge, to have blocknodes mimic blocks" |
|
1107 |
||
1108 |
^ true |
|
1109 |
! |
|
1110 |
||
1111 |
isBlockNode |
|
1112 |
^ true |
|
1113 |
! |
|
1114 |
||
4161 | 1115 |
isBlockWithArgumentCount:numArgsExpected |
1116 |
"a kludge, to have blocknodes mimic blocks" |
|
1117 |
||
4556 | 1118 |
^ self argumentCount == numArgsExpected |
4161 | 1119 |
|
1120 |
"Created: / 11-07-2017 / 18:28:59 / cg" |
|
1121 |
! |
|
1122 |
||
2325 | 1123 |
isEmptyBlock |
1124 |
^ statements isNil |
|
1125 |
! |
|
1126 |
||
3270 | 1127 |
isInlinedInto: blockNode assumeStcCompiled: assumeStc |
1128 |
"Returns true, if the receiver is inlined into given `blockNode`. |
|
1129 |
If `assumeStc` is true. then assume the code is compiled by stc, |
|
1130 |
otherwise assume that the code is compiled by the bytecode compiler" |
|
1131 |
||
4481 | 1132 |
| enclosingBlock selector| |
3270 | 1133 |
|
1134 |
self == blockNode ifTrue:[ ^ false ]. |
|
1135 |
enclosingBlock := self enclosingBlock. |
|
1136 |
(enclosingBlock ~~ blockNode |
|
1137 |
and:[ (enclosingBlock isInlinedInto: blockNode assumeStcCompiled: assumeStc) not ]) |
|
1138 |
ifTrue:[ ^ false ]. |
|
1139 |
||
4481 | 1140 |
parent isMessage ifFalse:[ ^ false ]. |
1141 |
||
1142 |
selector := parent selector. |
|
3270 | 1143 |
^ assumeStc ifTrue:[ |
1144 |
#( |
|
1145 |
ifTrue: |
|
1146 |
ifTrue:ifFalse: |
|
1147 |
ifFalse: |
|
1148 |
whileTrue |
|
1149 |
whileTrue: |
|
1150 |
whileFalse |
|
1151 |
whileFalse: |
|
1152 |
"/ Add more here... |
|
1153 |
) includes: selector |
|
1154 |
] ifFalse:[ |
|
1155 |
#( |
|
1156 |
ifTrue: |
|
1157 |
ifTrue:ifFalse: |
|
1158 |
ifFalse: |
|
1159 |
whileTrue |
|
1160 |
whileTrue: |
|
1161 |
whileFalse |
|
1162 |
whileFalse: |
|
1163 |
"/ Add more here... |
|
1164 |
) includes: selector |
|
1165 |
] |
|
1166 |
||
1167 |
"Created: / 19-08-2013 / 12:00:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1168 |
! |
|
1169 |
||
2325 | 1170 |
isJavaScriptBlock |
1171 |
^ false |
|
1172 |
! |
|
1173 |
||
1174 |
isSingleExpressionBlock |
|
1175 |
^ statements notNil |
|
1176 |
and:[ statements nextStatement isNil |
|
1177 |
and:[ statements isSimpleExpression ]] |
|
1178 |
! ! |
|
1179 |
||
2596 | 1180 |
!BlockNode methodsFor:'visiting'! |
1181 |
||
1182 |
acceptVisitor:aVisitor |
|
1183 |
"Double dispatch back to the visitor, passing my type encoded in |
|
1184 |
the selector (visitor pattern)" |
|
1185 |
||
1186 |
"stub code automatically generated - please change if required" |
|
1187 |
||
1188 |
^ aVisitor visitBlockNode:self |
|
4510 | 1189 |
! |
1190 |
||
1191 |
childrenDo:aBlock |
|
1192 |
self statements:statements do:aBlock |
|
2596 | 1193 |
! ! |
1194 |
||
366 | 1195 |
!BlockNode class methodsFor:'documentation'! |
148 | 1196 |
|
2750 | 1197 |
version |
3893 | 1198 |
^ '$Header$' |
2750 | 1199 |
! |
1200 |
||
2501 | 1201 |
version_CVS |
3893 | 1202 |
^ '$Header$' |
2325 | 1203 |
! |
1204 |
||
2501 | 1205 |
version_SVN |
3182 | 1206 |
^ '$ Id $' |
148 | 1207 |
! ! |
3182 | 1208 |