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