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