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