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