14
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
PrimaryNode subclass:#VariableNode
|
|
14 |
instanceVariableNames:'name token selfValue selfClass index block'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'System-Compiler-Support'
|
|
18 |
!
|
|
19 |
|
|
20 |
VariableNode comment:'
|
|
21 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
22 |
All Rights Reserved
|
31
|
23 |
|
|
24 |
$Header: /cvs/stx/stx/libcomp/Attic/VarNode.st,v 1.3 1994-08-11 23:28:32 claus Exp $
|
20
|
25 |
'!
|
14
|
26 |
|
20
|
27 |
!VariableNode class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
31
|
45 |
$Header: /cvs/stx/stx/libcomp/Attic/VarNode.st,v 1.3 1994-08-11 23:28:32 claus Exp $
|
20
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
node for parse-trees, representing variables
|
|
52 |
"
|
|
53 |
! !
|
14
|
54 |
|
|
55 |
!VariableNode class methodsFor:'instance creation'!
|
|
56 |
|
|
57 |
type:t token:tok
|
|
58 |
^ (self basicNew) type:t token:tok
|
|
59 |
!
|
|
60 |
|
|
61 |
type:t name:n
|
|
62 |
^ (self basicNew) type:t name:n
|
|
63 |
!
|
|
64 |
|
|
65 |
type:t index:i selfValue:s
|
|
66 |
^ (self basicNew) type:t index:i selfValue:s
|
|
67 |
!
|
|
68 |
|
|
69 |
type:t name:n value:val
|
|
70 |
^ (self basicNew) type:t name:n value:val
|
|
71 |
!
|
|
72 |
|
|
73 |
type:t name:n token:tok index:i
|
|
74 |
^ (self basicNew) type:t name:n token:tok index:i
|
|
75 |
!
|
|
76 |
|
|
77 |
type:t name:n index:i selfValue:s
|
|
78 |
^ (self basicNew) type:t name:n index:i selfValue:s
|
|
79 |
!
|
|
80 |
|
|
81 |
type:t name:n index:i selfClass:s
|
|
82 |
^ (self basicNew) type:t name:n index:i selfClass:s
|
|
83 |
!
|
|
84 |
|
|
85 |
type:t name:n token:tok index:i block:b
|
|
86 |
^ (self basicNew) type:t name:n token:tok index:i block:b
|
|
87 |
!
|
|
88 |
|
|
89 |
type:t token:tok index:i
|
|
90 |
^ (self basicNew) type:t token:tok index:i
|
|
91 |
!
|
|
92 |
|
|
93 |
type:t token:tok index:i block:b
|
|
94 |
^ (self basicNew) type:t token:tok index:i block:b
|
|
95 |
! !
|
|
96 |
|
|
97 |
!VariableNode methodsFor:'accessing'!
|
|
98 |
|
|
99 |
type:t token:tok
|
|
100 |
type := t.
|
|
101 |
token := tok
|
|
102 |
!
|
|
103 |
|
|
104 |
type:t token:tok index:i
|
|
105 |
type := t.
|
|
106 |
index := i.
|
|
107 |
token := tok
|
|
108 |
!
|
|
109 |
|
|
110 |
type:t token:tok index:i block:b
|
|
111 |
type := t.
|
|
112 |
index := i.
|
|
113 |
block := b.
|
|
114 |
token := tok
|
|
115 |
!
|
|
116 |
|
|
117 |
type:t name:n
|
|
118 |
type := t.
|
|
119 |
value := nil.
|
|
120 |
name := n
|
|
121 |
!
|
|
122 |
|
|
123 |
type:t index:i selfValue:s
|
|
124 |
type := t.
|
|
125 |
value := nil.
|
|
126 |
index := i.
|
|
127 |
selfValue := s
|
|
128 |
!
|
|
129 |
|
|
130 |
type:t name:n value:val
|
|
131 |
type := t.
|
|
132 |
name := n.
|
|
133 |
value := val
|
|
134 |
!
|
|
135 |
|
|
136 |
type:t name:n index:i selfValue:s
|
|
137 |
type := t.
|
|
138 |
value := nil.
|
|
139 |
index := i.
|
|
140 |
selfValue := s.
|
|
141 |
name := n
|
|
142 |
!
|
|
143 |
|
|
144 |
type:t name:n index:i selfClass:s
|
|
145 |
type := t.
|
|
146 |
value := nil.
|
|
147 |
index := i.
|
|
148 |
selfClass := s.
|
|
149 |
name := n
|
|
150 |
!
|
|
151 |
|
|
152 |
type:t name:n token:tok index:i
|
|
153 |
type := t.
|
|
154 |
index := i.
|
|
155 |
token := tok.
|
|
156 |
name := n
|
|
157 |
!
|
|
158 |
|
|
159 |
type:t name:n token:tok index:i block:b
|
|
160 |
type := t.
|
|
161 |
index := i.
|
|
162 |
block := b.
|
|
163 |
token := tok.
|
|
164 |
name := n
|
|
165 |
!
|
|
166 |
|
|
167 |
name
|
|
168 |
^ name
|
|
169 |
!
|
|
170 |
|
|
171 |
index
|
|
172 |
^ index
|
|
173 |
! !
|
|
174 |
|
|
175 |
!VariableNode methodsFor:'evaluating'!
|
|
176 |
|
|
177 |
evaluate
|
|
178 |
(type == #MethodVariable) ifTrue:[
|
31
|
179 |
^ token variableValue
|
14
|
180 |
].
|
|
181 |
(type == #InstanceVariable) ifTrue:[
|
|
182 |
^ selfValue instVarAt:index
|
|
183 |
].
|
|
184 |
(type == #BlockArg) ifTrue:[
|
31
|
185 |
^ token variableValue
|
14
|
186 |
].
|
|
187 |
(type == #GlobalVariable) ifTrue:[
|
|
188 |
(Smalltalk includesKey:name) ifTrue:[
|
|
189 |
^ Smalltalk at:name
|
|
190 |
].
|
|
191 |
"
|
|
192 |
self error:('global ' , name , ' is undefined').
|
|
193 |
"
|
|
194 |
|
|
195 |
^ UndefinedVariable name:name.
|
|
196 |
^ nil
|
|
197 |
].
|
|
198 |
(type == #BlockVariable) ifTrue:[
|
31
|
199 |
^ token variableValue
|
14
|
200 |
].
|
|
201 |
(type == #ClassVariable) ifTrue:[
|
|
202 |
^ Smalltalk at:name
|
|
203 |
].
|
|
204 |
(type == #ClassInstanceVariable) ifTrue:[
|
|
205 |
^ selfClass instVarAt:index
|
|
206 |
].
|
|
207 |
(type == #ThisContext) ifTrue:[
|
|
208 |
^ thisContext
|
|
209 |
].
|
|
210 |
"not reached"
|
|
211 |
self halt:'bad type'.
|
|
212 |
^ value
|
|
213 |
!
|
|
214 |
|
|
215 |
store:aValue
|
|
216 |
(type == #MethodVariable) ifTrue:[
|
|
217 |
token value:aValue. ^ aValue
|
|
218 |
].
|
|
219 |
(type == #InstanceVariable) ifTrue:[
|
|
220 |
^ selfValue instVarAt:index put:aValue
|
|
221 |
].
|
|
222 |
(type == #GlobalVariable) ifTrue:[
|
|
223 |
^ Smalltalk at:name put:aValue
|
|
224 |
].
|
|
225 |
(type == #ClassVariable) ifTrue:[
|
|
226 |
^ Smalltalk at:name put:aValue
|
|
227 |
].
|
|
228 |
(type == #BlockVariable) ifTrue:[
|
|
229 |
token value:aValue. ^ aValue
|
|
230 |
].
|
|
231 |
(type == #ClassInstanceVariable) ifTrue:[
|
|
232 |
^ selfClass instVarAt:index put:aValue
|
|
233 |
].
|
|
234 |
"not reached"
|
|
235 |
self halt:'bad type'.
|
|
236 |
^ aValue
|
|
237 |
! !
|
|
238 |
|
|
239 |
!VariableNode methodsFor:'code generation'!
|
|
240 |
|
|
241 |
codeForSideEffectOn:aStream inBlock:b
|
|
242 |
"no code at all"
|
|
243 |
^ self
|
|
244 |
!
|
|
245 |
|
|
246 |
codeOn:aStream inBlock:codeBlock
|
|
247 |
|theCode b deltaLevel|
|
|
248 |
|
|
249 |
(type == #MethodArg) ifTrue:[
|
|
250 |
(index <= 4) ifTrue:[
|
|
251 |
aStream nextPut:(#(pushMethodArg1
|
|
252 |
pushMethodArg2
|
|
253 |
pushMethodArg3
|
|
254 |
pushMethodArg4) at:index).
|
|
255 |
^ self
|
|
256 |
].
|
|
257 |
aStream nextPut:#pushMethodArg.
|
|
258 |
aStream nextPut:index.
|
|
259 |
^ self
|
|
260 |
].
|
|
261 |
(type == #MethodVariable) ifTrue:[
|
|
262 |
(index <= 6) ifTrue:[
|
|
263 |
aStream nextPut:(#(pushMethodVar1
|
|
264 |
pushMethodVar2
|
|
265 |
pushMethodVar3
|
|
266 |
pushMethodVar4
|
|
267 |
pushMethodVar5
|
|
268 |
pushMethodVar6) at:index).
|
|
269 |
^ self
|
|
270 |
].
|
|
271 |
aStream nextPut:#pushMethodVar.
|
|
272 |
aStream nextPut:index.
|
|
273 |
^ self
|
|
274 |
].
|
|
275 |
(type == #InstanceVariable) ifTrue:[
|
|
276 |
(index <= 10) ifTrue:[
|
|
277 |
theCode := #(pushInstVar1 pushInstVar2 pushInstVar3
|
|
278 |
pushInstVar4 pushInstVar5 pushInstVar6
|
|
279 |
pushInstVar7 pushInstVar8 pushInstVar9
|
|
280 |
pushInstVar10) at:index.
|
|
281 |
aStream nextPut:theCode.
|
|
282 |
^ self
|
|
283 |
].
|
|
284 |
aStream nextPut:#pushInstVar.
|
|
285 |
aStream nextPut:index.
|
|
286 |
^ self
|
|
287 |
].
|
|
288 |
(type == #BlockArg) ifTrue:[
|
|
289 |
"find deltaLevel to block, where argument was defined"
|
|
290 |
b := codeBlock.
|
|
291 |
deltaLevel := 0.
|
|
292 |
[b notNil and:[b ~~ block]] whileTrue:[
|
|
293 |
b inlineBlock ifFalse:[
|
|
294 |
deltaLevel := deltaLevel + 1
|
|
295 |
].
|
|
296 |
b := b home
|
|
297 |
].
|
|
298 |
(deltaLevel == 0) ifTrue:[
|
|
299 |
(index <= 4) ifTrue:[
|
|
300 |
theCode := #(pushBlockArg1 pushBlockArg2 pushBlockArg3
|
|
301 |
pushBlockArg4) at:index.
|
|
302 |
aStream nextPut:theCode.
|
|
303 |
^ self
|
|
304 |
].
|
|
305 |
aStream nextPut:#pushBlockArg.
|
|
306 |
aStream nextPut:index
|
|
307 |
] ifFalse:[
|
|
308 |
(deltaLevel == 1) ifTrue:[
|
|
309 |
aStream nextPut:#pushOuter1BlockArg
|
|
310 |
] ifFalse:[
|
|
311 |
(deltaLevel == 2) ifTrue:[
|
|
312 |
aStream nextPut:#pushOuter2BlockArg
|
|
313 |
] ifFalse:[
|
|
314 |
aStream nextPut:#pushOuterBlockArg.
|
|
315 |
aStream nextPut:deltaLevel
|
|
316 |
]
|
|
317 |
].
|
|
318 |
aStream nextPut:index
|
|
319 |
].
|
|
320 |
^ self
|
|
321 |
].
|
|
322 |
(type == #GlobalVariable) ifTrue:[
|
|
323 |
aStream nextPut:#pushGlobal.
|
|
324 |
aStream nextPut:name.
|
|
325 |
aStream nextPut:0. "slot for generation "
|
|
326 |
aStream nextPut:0. "slot for cell address (4 byte) "
|
|
327 |
aStream nextPut:0.
|
|
328 |
aStream nextPut:0.
|
|
329 |
aStream nextPut:0.
|
|
330 |
^ self
|
|
331 |
].
|
|
332 |
(type == #ClassVariable) ifTrue:[
|
|
333 |
aStream nextPut:#pushClassVar.
|
|
334 |
aStream nextPut:name.
|
|
335 |
aStream nextPut:0. "slot for generation "
|
|
336 |
aStream nextPut:0. "slot for cell address (4 byte) "
|
|
337 |
aStream nextPut:0.
|
|
338 |
aStream nextPut:0.
|
|
339 |
aStream nextPut:0.
|
|
340 |
^ self
|
|
341 |
].
|
|
342 |
(type == #BlockVariable) ifTrue:[
|
|
343 |
"find deltaLevel to block, where variable was defined"
|
|
344 |
b := codeBlock.
|
|
345 |
deltaLevel := 0.
|
|
346 |
[b notNil and:[b ~~ block]] whileTrue:[
|
|
347 |
b inlineBlock ifFalse:[
|
|
348 |
deltaLevel := deltaLevel + 1
|
|
349 |
].
|
|
350 |
b := b home
|
|
351 |
].
|
|
352 |
|
|
353 |
(deltaLevel == 0) ifTrue:[
|
|
354 |
aStream nextPut:#pushBlockVar.
|
|
355 |
aStream nextPut:index
|
|
356 |
] ifFalse:[
|
|
357 |
aStream nextPut:#pushOuterBlockVar.
|
|
358 |
aStream nextPut:deltaLevel.
|
|
359 |
aStream nextPut:index
|
|
360 |
].
|
|
361 |
^ self
|
|
362 |
].
|
|
363 |
(type == #ClassInstanceVariable) ifTrue:[
|
|
364 |
aStream nextPut:#pushClassInstVar.
|
|
365 |
aStream nextPut:index.
|
|
366 |
^ self
|
|
367 |
].
|
|
368 |
(type == #ThisContext) ifTrue:[
|
|
369 |
aStream nextPut:#pushThisContext. ^ self
|
|
370 |
].
|
|
371 |
|
|
372 |
"can this be reached ?"
|
|
373 |
|
|
374 |
"not reached"
|
|
375 |
self halt:'bad type'.
|
|
376 |
|
|
377 |
aStream nextPut:#pushLit.
|
|
378 |
aStream nextPut:value
|
|
379 |
!
|
|
380 |
|
|
381 |
codeStoreOn:aStream inBlock:codeBlock valueNeeded:valueNeeded
|
|
382 |
|theCode b deltaLevel|
|
|
383 |
|
|
384 |
valueNeeded ifTrue:[
|
|
385 |
aStream nextPut:#dup
|
|
386 |
].
|
|
387 |
(type == #MethodVariable) ifTrue:[
|
|
388 |
(index <= 6) ifTrue:[
|
|
389 |
theCode := #(storeMethodVar1 storeMethodVar2
|
|
390 |
storeMethodVar3 storeMethodVar4
|
|
391 |
storeMethodVar5 storeMethodVar6) at:index.
|
|
392 |
aStream nextPut:theCode.
|
|
393 |
^ self
|
|
394 |
].
|
|
395 |
aStream nextPut:#storeMethodVar.
|
|
396 |
aStream nextPut:index.
|
|
397 |
^ self
|
|
398 |
].
|
|
399 |
(type == #InstanceVariable) ifTrue:[
|
|
400 |
(index <= 10) ifTrue:[
|
|
401 |
theCode := #(storeInstVar1 storeInstVar2
|
|
402 |
storeInstVar3 storeInstVar4
|
|
403 |
storeInstVar5 storeInstVar6
|
|
404 |
storeInstVar7 storeInstVar8
|
|
405 |
storeInstVar9 storeInstVar10) at:index.
|
|
406 |
aStream nextPut:theCode.
|
|
407 |
^ self
|
|
408 |
].
|
|
409 |
aStream nextPut:#storeInstVar.
|
|
410 |
aStream nextPut:index.
|
|
411 |
^ self
|
|
412 |
].
|
|
413 |
(type == #GlobalVariable) ifTrue:[
|
|
414 |
aStream nextPut:#storeGlobal.
|
|
415 |
aStream nextPut:name.
|
|
416 |
aStream nextPut:0. "slot for generation "
|
|
417 |
aStream nextPut:0. "slot for cell address (4 byte) "
|
|
418 |
aStream nextPut:0.
|
|
419 |
aStream nextPut:0.
|
|
420 |
aStream nextPut:0.
|
|
421 |
^ self
|
|
422 |
].
|
|
423 |
(type == #BlockVariable) ifTrue:[
|
|
424 |
"find deltaLevel to block, where variable was defined"
|
|
425 |
b := codeBlock.
|
|
426 |
deltaLevel := 0.
|
|
427 |
[b notNil and:[b ~~ block]] whileTrue:[
|
|
428 |
b inlineBlock ifFalse:[
|
|
429 |
deltaLevel := deltaLevel + 1
|
|
430 |
].
|
|
431 |
b := b home
|
|
432 |
].
|
|
433 |
|
|
434 |
(deltaLevel == 0) ifTrue:[
|
|
435 |
aStream nextPut:#storeBlockVar.
|
|
436 |
aStream nextPut:index
|
|
437 |
] ifFalse:[
|
|
438 |
aStream nextPut:#storeOuterBlockVar.
|
|
439 |
aStream nextPut:deltaLevel.
|
|
440 |
aStream nextPut:index
|
|
441 |
].
|
|
442 |
^ self
|
|
443 |
].
|
|
444 |
(type == #ClassVariable) ifTrue:[
|
|
445 |
aStream nextPut:#storeClassVar.
|
|
446 |
aStream nextPut:name.
|
|
447 |
aStream nextPut:0. "slot for generation "
|
|
448 |
aStream nextPut:0. "slot for cell address (4 byte) "
|
|
449 |
aStream nextPut:0.
|
|
450 |
aStream nextPut:0.
|
|
451 |
aStream nextPut:0.
|
|
452 |
^ self
|
|
453 |
].
|
|
454 |
(type == #ClassInstanceVariable) ifTrue:[
|
|
455 |
aStream nextPut:#storeClassInstVar.
|
|
456 |
aStream nextPut:index.
|
|
457 |
^ self
|
|
458 |
].
|
|
459 |
"cannot be reached"
|
|
460 |
^ self error:'bad assignment'
|
|
461 |
! !
|
|
462 |
|
|
463 |
!VariableNode methodsFor:'printing'!
|
|
464 |
|
|
465 |
displayString
|
|
466 |
^ 'InterpreterVariable(' , self printString , ')'
|
|
467 |
!
|
|
468 |
|
|
469 |
printOn:aStream indent:i
|
|
470 |
(type == #MethodArg) ifTrue:[
|
|
471 |
aStream nextPutAll:name. ^ self
|
|
472 |
].
|
|
473 |
(type == #MethodVariable) ifTrue:[
|
|
474 |
aStream nextPutAll:name. ^ self
|
|
475 |
].
|
|
476 |
(type == #InstanceVariable) ifTrue:[
|
|
477 |
aStream nextPutAll:name. ^ self
|
|
478 |
].
|
|
479 |
(type == #BlockArg) ifTrue:[
|
|
480 |
aStream nextPutAll:name. ^ self
|
|
481 |
].
|
|
482 |
(type == #GlobalVariable) ifTrue:[
|
|
483 |
aStream nextPutAll:name.^ self
|
|
484 |
].
|
|
485 |
(type == #ClassVariable) ifTrue:[
|
|
486 |
aStream nextPutAll:name. ^ self
|
|
487 |
].
|
|
488 |
(type == #BlockVariable) ifTrue:[
|
|
489 |
aStream nextPutAll:name. ^ self
|
|
490 |
].
|
|
491 |
(type == #ClassInstanceVariable) ifTrue:[
|
|
492 |
aStream nextPutAll:name. ^ self
|
|
493 |
].
|
|
494 |
(type == #ThisContext) ifTrue:[
|
|
495 |
aStream nextPutAll:'thisContext'. ^ self
|
|
496 |
].
|
|
497 |
"not reached"
|
|
498 |
self halt:'bad type'.
|
|
499 |
! !
|