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