author | Claus Gittinger <cg@exept.de> |
Sun, 08 Sep 2019 00:17:45 +0200 | |
changeset 4547 | 3596e4bcee1b |
parent 4511 | 3649ce5c5127 |
child 4588 | f080c93ec4e8 |
permissions | -rw-r--r-- |
4547 | 1 |
"{ Encoding: utf8 }" |
2 |
||
0 | 3 |
" |
4 | 4 |
COPYRIGHT (c) 1989 by Claus Gittinger |
47 | 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 |
" |
|
1080 | 14 |
"{ Package: 'stx:libcomp' }" |
15 |
||
3811 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
0 | 18 |
PrimaryNode subclass:#ConstantNode |
4351 | 19 |
instanceVariableNames:'originalString' |
3246 | 20 |
classVariableNames:'TrueNode FalseNode NilNode Const0Node Const1Node Float0Node' |
242
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
21 |
poolDictionaries:'' |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
22 |
category:'System-Compiler-Support' |
0 | 23 |
! |
24 |
||
20 | 25 |
!ConstantNode class methodsFor:'documentation'! |
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
47 | 30 |
All Rights Reserved |
20 | 31 |
|
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
43 |
node for parse-trees, representing literal constants |
|
261 | 44 |
This is a helper class for the compiler. |
263 | 45 |
|
46 |
[author:] |
|
47 |
Claus Gittinger |
|
20 | 48 |
" |
0 | 49 |
! ! |
50 |
||
51 |
!ConstantNode class methodsFor:'instance creation'! |
|
52 |
||
53 |
type:t value:val |
|
2608 | 54 |
|
55 |
"/JV@2011-07-19: Changed not to share the nodes |
|
56 |
||
0 | 57 |
^ (self basicNew) type:t value:val |
2608 | 58 |
|
59 |
"/ Old code |
|
60 |
"/ "some constant nodes are used so often, its worth caching them" |
|
61 |
"/ |
|
62 |
"/ (t == #True) ifTrue:[ |
|
63 |
"/ TrueNode isNil ifTrue:[ |
|
64 |
"/ TrueNode := (self basicNew) type:t value:val |
|
65 |
"/ ]. |
|
66 |
"/ ^ TrueNode |
|
67 |
"/ ]. |
|
68 |
"/ (t == #False) ifTrue:[ |
|
69 |
"/ FalseNode isNil ifTrue:[ |
|
70 |
"/ FalseNode := (self basicNew) type:t value:val |
|
71 |
"/ ]. |
|
72 |
"/ ^ FalseNode |
|
73 |
"/ ]. |
|
74 |
"/ (t == #Nil) ifTrue:[ |
|
75 |
"/ NilNode isNil ifTrue:[ |
|
76 |
"/ NilNode := (self basicNew) type:t value:val |
|
77 |
"/ ]. |
|
78 |
"/ ^ NilNode |
|
79 |
"/ ]. |
|
80 |
"/ (t == #Integer) ifTrue:[ |
|
81 |
"/ (val == 0) ifTrue:[ |
|
82 |
"/ Const0Node isNil ifTrue:[ |
|
83 |
"/ Const0Node := (self basicNew) type:t value:val |
|
84 |
"/ ]. |
|
85 |
"/ ^ Const0Node |
|
86 |
"/ ]. |
|
87 |
"/ (val == 1) ifTrue:[ |
|
88 |
"/ Const1Node isNil ifTrue:[ |
|
89 |
"/ Const1Node := (self basicNew) type:t value:val |
|
90 |
"/ ]. |
|
91 |
"/ ^ Const1Node |
|
92 |
"/ ] |
|
93 |
"/ ]. |
|
94 |
"/ (t == #Float) ifTrue:[ |
|
95 |
"/ (val = 0.0) ifTrue:[ |
|
96 |
"/ "/ care for negative0 (which compares = to 0.0) |
|
97 |
"/ val isNegativeZero ifFalse:[ |
|
98 |
"/ Float0Node isNil ifTrue:[ |
|
99 |
"/ Float0Node := (self basicNew) type:t value:val |
|
100 |
"/ ]. |
|
101 |
"/ ^ Float0Node |
|
102 |
"/ ] |
|
103 |
"/ ] |
|
104 |
"/ ]. |
|
105 |
"/ ^ (self basicNew) type:t value:val |
|
106 |
||
107 |
"Modified: / 19-07-2011 / 17:24:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
140 | 108 |
! |
109 |
||
4351 | 110 |
type:t value:val from:startPos to:endPos |
2566
a39e9ce2610f
- parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2500
diff
changeset
|
111 |
|
4351 | 112 |
^ (self basicNew) |
113 |
type:t value:val; |
|
114 |
startPosition:startPos endPosition:endPos; |
|
2566
a39e9ce2610f
- parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2500
diff
changeset
|
115 |
yourself |
a39e9ce2610f
- parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2500
diff
changeset
|
116 |
|
a39e9ce2610f
- parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2500
diff
changeset
|
117 |
"Created: / 19-07-2011 / 17:50:07 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
4351 | 118 |
"Modified (format): / 15-02-2019 / 14:50:59 / Claus Gittinger" |
2566
a39e9ce2610f
- parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2500
diff
changeset
|
119 |
! |
a39e9ce2610f
- parse tree nodes are no longer shared
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2500
diff
changeset
|
120 |
|
140 | 121 |
value:val |
122 |
^ self type:(self typeOfConstant:val) value:val |
|
123 |
! ! |
|
124 |
||
125 |
!ConstantNode class methodsFor:'queries'! |
|
126 |
||
127 |
typeOfConstant:anObject |
|
128 |
"return the constantNode type for an object" |
|
129 |
||
130 |
"the most common case first ..." |
|
131 |
||
132 |
(anObject isMemberOf:SmallInteger) ifTrue:[ |
|
1381 | 133 |
^ #Integer |
140 | 134 |
]. |
135 |
||
136 |
anObject isNil ifTrue:[ |
|
1381 | 137 |
^ #Nil |
140 | 138 |
]. |
139 |
||
140 |
anObject isNumber ifTrue:[ |
|
1381 | 141 |
"the most common case first ..." |
142 |
(anObject isMemberOf:Float) ifTrue:[ |
|
143 |
^ #Float |
|
144 |
]. |
|
145 |
anObject isInteger ifTrue:[ |
|
146 |
^ #Integer |
|
147 |
]. |
|
140 | 148 |
]. |
149 |
(anObject == true) ifTrue:[ |
|
1381 | 150 |
^ #True |
140 | 151 |
]. |
152 |
(anObject == false) ifTrue:[ |
|
1381 | 153 |
^ #False |
140 | 154 |
]. |
155 |
^ #Literal |
|
0 | 156 |
! ! |
157 |
||
4473 | 158 |
!ConstantNode methodsFor:'RBParser compatibility'! |
159 |
||
160 |
token |
|
161 |
"for RB compatibility, I implement some of its protocol" |
|
162 |
||
163 |
^ self |
|
164 |
! ! |
|
165 |
||
13 | 166 |
!ConstantNode methodsFor:'accessing'! |
167 |
||
711 | 168 |
lineNumber:ignoredLineNumber |
710 | 169 |
|
711 | 170 |
"Created: / 14.5.1998 / 19:31:48 / cg" |
4351 | 171 |
! |
172 |
||
173 |
originalString |
|
174 |
^ originalString |
|
175 |
! |
|
176 |
||
177 |
originalString:aString |
|
178 |
"to remember the original string from scanning |
|
179 |
(in case of a radix-number or a c-string)" |
|
180 |
||
181 |
originalString := aString. |
|
182 |
||
183 |
"Modified (comment): / 15-02-2019 / 14:35:50 / Claus Gittinger" |
|
4511 | 184 |
! |
185 |
||
186 |
radix |
|
187 |
value isInteger ifFalse:[ |
|
188 |
self error. |
|
189 |
^ nil. |
|
190 |
]. |
|
191 |
originalString isNil ifTrue:[ |
|
192 |
^ 10 |
|
193 |
]. |
|
194 |
originalString size < 2 ifTrue:[^ 10]. |
|
195 |
(originalString at:2) == $r ifTrue:[ |
|
196 |
^ Integer readFrom:originalString readStream. |
|
197 |
]. |
|
198 |
originalString size < 3 ifTrue:[^ 10]. |
|
199 |
(originalString at:3) == $r ifTrue:[ |
|
200 |
^ Integer readFrom:originalString readStream. |
|
201 |
]. |
|
202 |
(originalString startsWith:'0x') ifTrue:[^ 16]. |
|
203 |
(originalString startsWith:'0b') ifTrue:[^ 2]. |
|
204 |
(originalString startsWith:'0o') ifTrue:[^ 8]. |
|
205 |
^ 10 |
|
206 |
||
13 | 207 |
! ! |
208 |
||
0 | 209 |
!ConstantNode methodsFor:'code generation'! |
210 |
||
1560
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
211 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
212 |
"no code at all" |
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
213 |
|
1995 | 214 |
"/ but remember symbolic literals (such as #TODO) |
1560
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
215 |
value isSymbol ifTrue:[ |
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
216 |
aCompiler addLiteral:value. |
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
217 |
]. |
4547 | 218 |
aCompiler |
219 |
warning:'Useless constant reference' |
|
220 |
position:startPosition to:endPosition. |
|
221 |
||
1560
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
222 |
^ self |
1995 | 223 |
|
224 |
"Modified: / 04-03-2007 / 15:29:54 / cg" |
|
1560
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
225 |
! |
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
226 |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
227 |
codeForSimpleReturnOn:aStream inBlock:b lineNumber:lineNrOrNil for:aCompiler |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
228 |
lineNrOrNil notNil ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
229 |
self codeLineNumber:lineNrOrNil on:aStream for:aCompiler |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
230 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
231 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
232 |
(type == #Nil) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
233 |
aStream nextPut:#retNil. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
234 |
^self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
235 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
236 |
(type == #True) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
237 |
aStream nextPut:#retTrue. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
238 |
^self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
239 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
240 |
(type == #False) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
241 |
aStream nextPut:#retFalse. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
242 |
^self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
243 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
244 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
245 |
(type == #Integer) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
246 |
(value between: -128 and:127) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
247 |
(value == 0) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
248 |
aStream nextPut:#ret0. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
249 |
^ self. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
250 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
251 |
aStream nextPut:#retNum; nextPut:value. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
252 |
^ self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
253 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
254 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
255 |
|
1401 | 256 |
"/ anything else must be pushed, then top returned |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
257 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
258 |
self codeOn:aStream inBlock:b for:aCompiler. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
259 |
aStream nextPut:#retTop |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
260 |
! |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
261 |
|
104 | 262 |
codeOn:aStream inBlock:b for:aCompiler |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
263 |
"generate code for the constant" |
0 | 264 |
|
104 | 265 |
|code index| |
96 | 266 |
|
0 | 267 |
(type == #Integer) ifTrue:[ |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
268 |
(value between: -128 and:127) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
269 |
(value == 0) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
270 |
code := #push0 |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
271 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
272 |
(value == 1) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
273 |
code := #push1. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
274 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
275 |
(value == 2) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
276 |
code := #push2. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
277 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
278 |
(value == -1) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
279 |
code := #pushMinus1. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
280 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
281 |
code notNil ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
282 |
aStream nextPut:code. ^ self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
283 |
]. |
96 | 284 |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
285 |
aStream nextPut:#pushNum; nextPut:value. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
286 |
^ self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
287 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
288 |
(value between:16r-8000 and:16r7FFF) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
289 |
aStream nextPut:#pushNum16; nextPut:value; nextPut:0. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
290 |
^ self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
291 |
] |
0 | 292 |
]. |
293 |
(type == #Nil) ifTrue:[ |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
294 |
code := #pushNil. |
0 | 295 |
]. |
296 |
(type == #True) ifTrue:[ |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
297 |
code := #pushTrue. |
0 | 298 |
]. |
299 |
(type == #False) ifTrue:[ |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
300 |
code := #pushFalse. |
0 | 301 |
]. |
96 | 302 |
code notNil ifTrue:[ |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
303 |
aStream nextPut:code. ^ self |
96 | 304 |
]. |
106 | 305 |
|
306 |
"/ kludge for backward compatibility |
|
307 |
aCompiler isNil ifTrue:[ |
|
2118 | 308 |
self halt:'strange literal constant'. |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
309 |
aStream nextPut:#pushLit; nextPut:value. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
310 |
^ self. |
106 | 311 |
]. |
312 |
||
1805
d8f8075615dc
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1797
diff
changeset
|
313 |
self emitPushLiteral:value on:aStream for:aCompiler |
0 | 314 |
! |
315 |
||
104 | 316 |
codeStoreOn:aStream inBlock:codeBlock valueNeeded:valueNeeded for:aCompiler |
13 | 317 |
"not sent - parser checks for this" |
0 | 318 |
|
319 |
^ self error:'assignment to literals not allowed' |
|
320 |
! ! |
|
321 |
||
1035 | 322 |
!ConstantNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
323 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
324 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
325 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
326 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
327 |
^ anEnumerator doLiteral:self value:value |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
328 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
329 |
"Modified: 19.6.1997 / 16:40:59 / cg" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
330 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
331 |
|
1035 | 332 |
!ConstantNode methodsFor:'evaluation'! |
140 | 333 |
|
334 |
evaluate |
|
1384 | 335 |
"exists for performance only" |
336 |
^ value |
|
337 |
! |
|
338 |
||
339 |
evaluateIn:anEnvironment |
|
140 | 340 |
^ value |
341 |
! |
|
342 |
||
343 |
store:aValue |
|
344 |
"not reached - parser checks for this" |
|
345 |
||
346 |
self error:'store not allowed'. |
|
347 |
^ aValue |
|
3811 | 348 |
! |
349 |
||
350 |
value |
|
351 |
"for compatibility with RB-AST" |
|
352 |
^ value |
|
140 | 353 |
! ! |
354 |
||
1080 | 355 |
!ConstantNode methodsFor:'printing & storing'! |
0 | 356 |
|
2895
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
357 |
displayOn:aGCOrStream |
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
358 |
"Compatibility |
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
359 |
append a printed desription on some stream (Dolphin, Squeak) |
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
360 |
OR: |
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
361 |
display the receiver in a graphicsContext at 0@0 (ST80). |
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
362 |
This method allows for any object to be displayed in some view |
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
363 |
(although the fallBack is to display its printString ...)" |
612 | 364 |
|
2895
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
365 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
4132 | 366 |
"/ old ST80 means: draw-yourself on a GC. |
2895
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
367 |
aGCOrStream isStream ifFalse:[ |
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
368 |
^ super displayOn:aGCOrStream. |
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
369 |
]. |
612 | 370 |
|
4132 | 371 |
value displayOn:aGCOrStream. |
372 |
||
373 |
"Modified (comment): / 22-02-2017 / 16:50:02 / cg" |
|
13 | 374 |
! |
375 |
||
0 | 376 |
printOn:aStream indent:i |
4351 | 377 |
originalString notNil ifTrue:[ |
378 |
aStream nextPutAll:originalString. |
|
379 |
^ self. |
|
380 |
]. |
|
0 | 381 |
value storeOn:aStream |
4351 | 382 |
|
383 |
"Modified: / 15-02-2019 / 14:37:33 / Claus Gittinger" |
|
0 | 384 |
! ! |
140 | 385 |
|
386 |
!ConstantNode methodsFor:'queries'! |
|
387 |
||
242
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
388 |
canReuseAsArg:anotherNode |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
389 |
|otherValue| |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
390 |
|
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
391 |
anotherNode isConstant ifTrue:[ |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
392 |
anotherNode type ~~ type ifTrue:[^ false]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
393 |
|
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
394 |
otherValue := anotherNode evaluate. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
395 |
(value isMemberOf:SmallInteger) ifTrue:[ |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
396 |
(value == 0) ifTrue:[^ false]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
397 |
(value == 1) ifTrue:[^ false]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
398 |
(value == 2) ifTrue:[^ false]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
399 |
(value == -1) ifTrue:[^ false]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
400 |
^ otherValue == value |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
401 |
]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
402 |
(value isMemberOf:Float) ifTrue:[ |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
403 |
^ (otherValue isMemberOf:Float) |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
404 |
and:[otherValue = value] |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
405 |
]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
406 |
(value isMemberOf:Symbol) ifTrue:[ |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
407 |
^ otherValue == value |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
408 |
]. |
3503 | 409 |
(value isSingleByteString) ifTrue:[ |
410 |
^ (otherValue isSingleByteString) |
|
242
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
411 |
and:[otherValue = value] |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
412 |
]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
413 |
]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
414 |
^ false |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
415 |
|
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
416 |
"Created: 14.4.1996 / 00:43:14 / cg" |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
417 |
"Modified: 14.4.1996 / 01:00:29 / cg" |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
418 |
! |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
419 |
|
2266 | 420 |
withConstantValueDo:aBlock |
421 |
"return true, if this evaluates to a constant value |
|
422 |
and evaluate aBlock with it" |
|
423 |
||
424 |
aBlock value:value. |
|
425 |
^ true |
|
140 | 426 |
! ! |
427 |
||
2320 | 428 |
!ConstantNode methodsFor:'testing'! |
429 |
||
430 |
isConstant |
|
431 |
^ true |
|
4278 | 432 |
! |
433 |
||
434 |
isConstantNumber |
|
435 |
^ value isNumber |
|
436 |
||
437 |
"Created: / 16-06-2018 / 08:46:53 / Claus Gittinger" |
|
4473 | 438 |
! |
439 |
||
440 |
isLiteralArray |
|
441 |
^ value isArray |
|
442 |
||
443 |
"Created: / 16-06-2018 / 08:46:53 / Claus Gittinger" |
|
444 |
! |
|
445 |
||
446 |
isLiteralCString |
|
447 |
^ value isString and:[originalString notNil and:[originalString startsWith:'c''']] |
|
448 |
||
449 |
"Created: / 16-06-2018 / 08:46:53 / Claus Gittinger" |
|
2320 | 450 |
! ! |
451 |
||
2608 | 452 |
!ConstantNode methodsFor:'visiting'! |
453 |
||
454 |
acceptVisitor:aVisitor |
|
455 |
"Double dispatch back to the visitor, passing my type encoded in |
|
456 |
the selector (visitor pattern)" |
|
457 |
||
458 |
"stub code automatically generated - please change if required" |
|
459 |
||
460 |
^ aVisitor visitConstantNode:self |
|
461 |
! ! |
|
462 |
||
148 | 463 |
!ConstantNode class methodsFor:'documentation'! |
464 |
||
2500 | 465 |
version_CVS |
3811 | 466 |
^ '$Header$' |
2266 | 467 |
! |
468 |
||
2500 | 469 |
version_SVN |
3246 | 470 |
^ '$ Id $' |
148 | 471 |
! ! |
3246 | 472 |