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