author | Claus Gittinger <cg@exept.de> |
Tue, 25 Feb 2020 13:40:16 +0100 | |
changeset 4643 | e305b814a348 |
parent 4602 | b422ca3ad101 |
child 4691 | 792a4618488c |
permissions | -rw-r--r-- |
4602 | 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 |
|
4602 | 187 |
"the constant's original radix; |
188 |
remembered so that we can prettyprint it later in the same radix" |
|
189 |
||
4511 | 190 |
value isInteger ifFalse:[ |
191 |
self error. |
|
192 |
^ nil. |
|
193 |
]. |
|
194 |
originalString isNil ifTrue:[ |
|
195 |
^ 10 |
|
196 |
]. |
|
197 |
originalString size < 2 ifTrue:[^ 10]. |
|
198 |
(originalString at:2) == $r ifTrue:[ |
|
199 |
^ Integer readFrom:originalString readStream. |
|
200 |
]. |
|
201 |
originalString size < 3 ifTrue:[^ 10]. |
|
202 |
(originalString at:3) == $r ifTrue:[ |
|
203 |
^ Integer readFrom:originalString readStream. |
|
204 |
]. |
|
205 |
(originalString startsWith:'0x') ifTrue:[^ 16]. |
|
206 |
(originalString startsWith:'0b') ifTrue:[^ 2]. |
|
207 |
(originalString startsWith:'0o') ifTrue:[^ 8]. |
|
208 |
^ 10 |
|
13 | 209 |
! ! |
210 |
||
0 | 211 |
!ConstantNode methodsFor:'code generation'! |
212 |
||
1560
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
213 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
214 |
"no code at all" |
4588 | 215 |
|msg| |
216 |
||
217 |
msg := 'Useless constant reference'. |
|
1560
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
218 |
|
1995 | 219 |
"/ but remember symbolic literals (such as #TODO) |
1560
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
220 |
value isSymbol ifTrue:[ |
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
221 |
aCompiler addLiteral:value. |
4588 | 222 |
|
223 |
((#fixme sameAs:value) or:[#todo sameAs:value]) ifTrue:[ |
|
224 |
msg := 'Reminder in code: ',value |
|
225 |
]. |
|
1560
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
226 |
]. |
4547 | 227 |
|
4588 | 228 |
aCompiler warning:msg position:startPosition to:endPosition. |
1995 | 229 |
|
230 |
"Modified: / 04-03-2007 / 15:29:54 / cg" |
|
1560
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
231 |
! |
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
232 |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
233 |
codeForSimpleReturnOn:aStream inBlock:b lineNumber:lineNrOrNil for:aCompiler |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
234 |
lineNrOrNil notNil ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
235 |
self codeLineNumber:lineNrOrNil on:aStream for:aCompiler |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
236 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
237 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
238 |
(type == #Nil) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
239 |
aStream nextPut:#retNil. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
240 |
^self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
241 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
242 |
(type == #True) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
243 |
aStream nextPut:#retTrue. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
244 |
^self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
245 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
246 |
(type == #False) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
247 |
aStream nextPut:#retFalse. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
248 |
^self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
249 |
]. |
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 |
(type == #Integer) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
252 |
(value between: -128 and:127) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
253 |
(value == 0) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
254 |
aStream nextPut:#ret0. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
255 |
^ self. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
256 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
257 |
aStream nextPut:#retNum; nextPut:value. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
258 |
^ self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
259 |
]. |
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 |
|
1401 | 262 |
"/ anything else must be pushed, then top returned |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
263 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
264 |
self codeOn:aStream inBlock:b for:aCompiler. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
265 |
aStream nextPut:#retTop |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
266 |
! |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
267 |
|
104 | 268 |
codeOn:aStream inBlock:b for:aCompiler |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
269 |
"generate code for the constant" |
0 | 270 |
|
104 | 271 |
|code index| |
96 | 272 |
|
0 | 273 |
(type == #Integer) ifTrue:[ |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
274 |
(value between: -128 and:127) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
275 |
(value == 0) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
276 |
code := #push0 |
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 := #push1. |
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 |
(value == 2) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
282 |
code := #push2. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
283 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
284 |
(value == -1) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
285 |
code := #pushMinus1. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
286 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
287 |
code notNil ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
288 |
aStream nextPut:code. ^ self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
289 |
]. |
96 | 290 |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
291 |
aStream nextPut:#pushNum; nextPut:value. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
292 |
^ self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
293 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
294 |
(value between:16r-8000 and:16r7FFF) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
295 |
aStream nextPut:#pushNum16; nextPut:value; nextPut:0. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
296 |
^ self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
297 |
] |
0 | 298 |
]. |
299 |
(type == #Nil) ifTrue:[ |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
300 |
code := #pushNil. |
0 | 301 |
]. |
302 |
(type == #True) ifTrue:[ |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
303 |
code := #pushTrue. |
0 | 304 |
]. |
305 |
(type == #False) ifTrue:[ |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
306 |
code := #pushFalse. |
0 | 307 |
]. |
96 | 308 |
code notNil ifTrue:[ |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
309 |
aStream nextPut:code. ^ self |
96 | 310 |
]. |
106 | 311 |
|
312 |
"/ kludge for backward compatibility |
|
313 |
aCompiler isNil ifTrue:[ |
|
2118 | 314 |
self halt:'strange literal constant'. |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
315 |
aStream nextPut:#pushLit; nextPut:value. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
316 |
^ self. |
106 | 317 |
]. |
318 |
||
1805
d8f8075615dc
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1797
diff
changeset
|
319 |
self emitPushLiteral:value on:aStream for:aCompiler |
0 | 320 |
! |
321 |
||
104 | 322 |
codeStoreOn:aStream inBlock:codeBlock valueNeeded:valueNeeded for:aCompiler |
13 | 323 |
"not sent - parser checks for this" |
0 | 324 |
|
325 |
^ self error:'assignment to literals not allowed' |
|
326 |
! ! |
|
327 |
||
1035 | 328 |
!ConstantNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
329 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
330 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
331 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
332 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
333 |
^ anEnumerator doLiteral:self value:value |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
334 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
335 |
"Modified: 19.6.1997 / 16:40:59 / cg" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
336 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
337 |
|
1035 | 338 |
!ConstantNode methodsFor:'evaluation'! |
140 | 339 |
|
340 |
evaluate |
|
1384 | 341 |
"exists for performance only" |
342 |
^ value |
|
343 |
! |
|
344 |
||
345 |
evaluateIn:anEnvironment |
|
140 | 346 |
^ value |
347 |
! |
|
348 |
||
349 |
store:aValue |
|
350 |
"not reached - parser checks for this" |
|
351 |
||
352 |
self error:'store not allowed'. |
|
353 |
^ aValue |
|
3811 | 354 |
! |
355 |
||
356 |
value |
|
357 |
"for compatibility with RB-AST" |
|
358 |
^ value |
|
140 | 359 |
! ! |
360 |
||
1080 | 361 |
!ConstantNode methodsFor:'printing & storing'! |
0 | 362 |
|
2895
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
363 |
displayOn:aGCOrStream |
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
364 |
"Compatibility |
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
365 |
append a printed desription on some stream (Dolphin, Squeak) |
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
366 |
OR: |
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
367 |
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
|
368 |
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
|
369 |
(although the fallBack is to display its printString ...)" |
612 | 370 |
|
2895
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
371 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
4132 | 372 |
"/ old ST80 means: draw-yourself on a GC. |
2895
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
373 |
aGCOrStream isStream ifFalse:[ |
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
374 |
^ super displayOn:aGCOrStream. |
fe7143fbfdbe
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
2616
diff
changeset
|
375 |
]. |
612 | 376 |
|
4132 | 377 |
value displayOn:aGCOrStream. |
378 |
||
379 |
"Modified (comment): / 22-02-2017 / 16:50:02 / cg" |
|
13 | 380 |
! |
381 |
||
0 | 382 |
printOn:aStream indent:i |
4351 | 383 |
originalString notNil ifTrue:[ |
384 |
aStream nextPutAll:originalString. |
|
385 |
^ self. |
|
386 |
]. |
|
0 | 387 |
value storeOn:aStream |
4351 | 388 |
|
389 |
"Modified: / 15-02-2019 / 14:37:33 / Claus Gittinger" |
|
0 | 390 |
! ! |
140 | 391 |
|
392 |
!ConstantNode methodsFor:'queries'! |
|
393 |
||
242
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
394 |
canReuseAsArg:anotherNode |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
395 |
|otherValue| |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
396 |
|
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
397 |
anotherNode isConstant ifTrue:[ |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
398 |
anotherNode type ~~ type ifTrue:[^ false]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
399 |
|
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
400 |
otherValue := anotherNode evaluate. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
401 |
(value isMemberOf:SmallInteger) ifTrue:[ |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
402 |
(value == 0) ifTrue:[^ false]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
403 |
(value == 1) ifTrue:[^ false]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
404 |
(value == 2) ifTrue:[^ false]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
405 |
(value == -1) ifTrue:[^ false]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
406 |
^ otherValue == value |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
407 |
]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
408 |
(value isMemberOf:Float) ifTrue:[ |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
409 |
^ (otherValue isMemberOf:Float) |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
410 |
and:[otherValue = value] |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
411 |
]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
412 |
(value isMemberOf:Symbol) ifTrue:[ |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
413 |
^ otherValue == value |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
414 |
]. |
3503 | 415 |
(value isSingleByteString) ifTrue:[ |
416 |
^ (otherValue isSingleByteString) |
|
242
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
417 |
and:[otherValue = value] |
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 |
]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
420 |
^ false |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
421 |
|
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
422 |
"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
|
423 |
"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
|
424 |
! |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
425 |
|
2266 | 426 |
withConstantValueDo:aBlock |
427 |
"return true, if this evaluates to a constant value |
|
428 |
and evaluate aBlock with it" |
|
429 |
||
430 |
aBlock value:value. |
|
431 |
^ true |
|
140 | 432 |
! ! |
433 |
||
2320 | 434 |
!ConstantNode methodsFor:'testing'! |
435 |
||
436 |
isConstant |
|
437 |
^ true |
|
4278 | 438 |
! |
439 |
||
440 |
isConstantNumber |
|
441 |
^ value isNumber |
|
442 |
||
443 |
"Created: / 16-06-2018 / 08:46:53 / Claus Gittinger" |
|
4473 | 444 |
! |
445 |
||
446 |
isLiteralArray |
|
447 |
^ value isArray |
|
448 |
||
449 |
"Created: / 16-06-2018 / 08:46:53 / Claus Gittinger" |
|
450 |
! |
|
451 |
||
452 |
isLiteralCString |
|
453 |
^ value isString and:[originalString notNil and:[originalString startsWith:'c''']] |
|
454 |
||
455 |
"Created: / 16-06-2018 / 08:46:53 / Claus Gittinger" |
|
2320 | 456 |
! ! |
457 |
||
2608 | 458 |
!ConstantNode methodsFor:'visiting'! |
459 |
||
460 |
acceptVisitor:aVisitor |
|
461 |
"Double dispatch back to the visitor, passing my type encoded in |
|
462 |
the selector (visitor pattern)" |
|
463 |
||
464 |
"stub code automatically generated - please change if required" |
|
465 |
||
466 |
^ aVisitor visitConstantNode:self |
|
467 |
! ! |
|
468 |
||
148 | 469 |
!ConstantNode class methodsFor:'documentation'! |
470 |
||
2500 | 471 |
version_CVS |
3811 | 472 |
^ '$Header$' |
2266 | 473 |
! |
474 |
||
2500 | 475 |
version_SVN |
3246 | 476 |
^ '$ Id $' |
148 | 477 |
! ! |
3246 | 478 |