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