author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 09 Jul 2011 22:09:55 +0200 | |
changeset 2547 | 55ec27b3306c |
parent 2500 | 3178ecc11a5e |
child 2566 | a39e9ce2610f |
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 |
||
0 | 14 |
PrimaryNode subclass:#ConstantNode |
242
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
15 |
instanceVariableNames:'' |
2500 | 16 |
classVariableNames:'TrueNode FalseNode NilNode Const0Node Const1Node Float0Node |
17 |
endLineNr endCharIndex' |
|
242
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
18 |
poolDictionaries:'' |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
19 |
category:'System-Compiler-Support' |
0 | 20 |
! |
21 |
||
20 | 22 |
!ConstantNode class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
47 | 27 |
All Rights Reserved |
20 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
node for parse-trees, representing literal constants |
|
261 | 41 |
This is a helper class for the compiler. |
263 | 42 |
|
43 |
[author:] |
|
44 |
Claus Gittinger |
|
20 | 45 |
" |
0 | 46 |
! ! |
47 |
||
48 |
!ConstantNode class methodsFor:'instance creation'! |
|
49 |
||
50 |
type:t value:val |
|
13 | 51 |
"some constant nodes are used so often, its worth caching them" |
0 | 52 |
(t == #True) ifTrue:[ |
1348 | 53 |
TrueNode isNil ifTrue:[ |
54 |
TrueNode := (self basicNew) type:t value:val |
|
55 |
]. |
|
56 |
^ TrueNode |
|
0 | 57 |
]. |
58 |
(t == #False) ifTrue:[ |
|
1348 | 59 |
FalseNode isNil ifTrue:[ |
60 |
FalseNode := (self basicNew) type:t value:val |
|
61 |
]. |
|
62 |
^ FalseNode |
|
0 | 63 |
]. |
64 |
(t == #Nil) ifTrue:[ |
|
1348 | 65 |
NilNode isNil ifTrue:[ |
66 |
NilNode := (self basicNew) type:t value:val |
|
67 |
]. |
|
68 |
^ NilNode |
|
0 | 69 |
]. |
70 |
(t == #Integer) ifTrue:[ |
|
1348 | 71 |
(val == 0) ifTrue:[ |
72 |
Const0Node isNil ifTrue:[ |
|
73 |
Const0Node := (self basicNew) type:t value:val |
|
74 |
]. |
|
75 |
^ Const0Node |
|
76 |
]. |
|
77 |
(val == 1) ifTrue:[ |
|
78 |
Const1Node isNil ifTrue:[ |
|
79 |
Const1Node := (self basicNew) type:t value:val |
|
80 |
]. |
|
81 |
^ Const1Node |
|
82 |
] |
|
0 | 83 |
]. |
84 |
(t == #Float) ifTrue:[ |
|
1348 | 85 |
(val = 0.0) ifTrue:[ |
86 |
"/ care for negative0 (which compares = to 0.0) |
|
87 |
val isNegativeZero ifFalse:[ |
|
88 |
Float0Node isNil ifTrue:[ |
|
89 |
Float0Node := (self basicNew) type:t value:val |
|
90 |
]. |
|
91 |
^ Float0Node |
|
92 |
] |
|
93 |
] |
|
0 | 94 |
]. |
95 |
^ (self basicNew) type:t value:val |
|
140 | 96 |
! |
97 |
||
98 |
value:val |
|
99 |
^ self type:(self typeOfConstant:val) value:val |
|
100 |
! ! |
|
101 |
||
102 |
!ConstantNode class methodsFor:'queries'! |
|
103 |
||
104 |
typeOfConstant:anObject |
|
105 |
"return the constantNode type for an object" |
|
106 |
||
107 |
"the most common case first ..." |
|
108 |
||
109 |
(anObject isMemberOf:SmallInteger) ifTrue:[ |
|
1381 | 110 |
^ #Integer |
140 | 111 |
]. |
112 |
||
113 |
anObject isNil ifTrue:[ |
|
1381 | 114 |
^ #Nil |
140 | 115 |
]. |
116 |
||
117 |
anObject isNumber ifTrue:[ |
|
1381 | 118 |
"the most common case first ..." |
119 |
(anObject isMemberOf:Float) ifTrue:[ |
|
120 |
^ #Float |
|
121 |
]. |
|
122 |
anObject isInteger ifTrue:[ |
|
123 |
^ #Integer |
|
124 |
]. |
|
140 | 125 |
]. |
126 |
(anObject == true) ifTrue:[ |
|
1381 | 127 |
^ #True |
140 | 128 |
]. |
129 |
(anObject == false) ifTrue:[ |
|
1381 | 130 |
^ #False |
140 | 131 |
]. |
132 |
^ #Literal |
|
0 | 133 |
! ! |
134 |
||
13 | 135 |
!ConstantNode methodsFor:'accessing'! |
136 |
||
2500 | 137 |
endCharIndex |
138 |
^endCharIndex. |
|
139 |
||
140 |
"Created: / 23-02-2011 / 20:57:13 / Jakub <zelenja7@fel.cvut.cz>" |
|
141 |
! |
|
142 |
||
143 |
endCharIndex:val |
|
144 |
endCharIndex:=val. |
|
145 |
||
146 |
"Created: / 23-02-2011 / 20:57:23 / Jakub <zelenja7@fel.cvut.cz>" |
|
147 |
! |
|
148 |
||
149 |
endLineNr |
|
150 |
^endLineNr. |
|
151 |
||
152 |
"Created: / 23-02-2011 / 20:53:25 / Jakub <zelenja7@fel.cvut.cz>" |
|
153 |
! |
|
154 |
||
155 |
endLineNr:val |
|
156 |
endLineNr := val. |
|
157 |
||
158 |
"Created: / 23-02-2011 / 20:53:47 / Jakub <zelenja7@fel.cvut.cz>" |
|
159 |
! |
|
160 |
||
711 | 161 |
lineNumber:ignoredLineNumber |
710 | 162 |
|
711 | 163 |
"Created: / 14.5.1998 / 19:31:48 / cg" |
13 | 164 |
! ! |
165 |
||
0 | 166 |
!ConstantNode methodsFor:'code generation'! |
167 |
||
1560
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
168 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
169 |
"no code at all" |
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
170 |
|
1995 | 171 |
"/ but remember symbolic literals (such as #TODO) |
1560
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
172 |
value isSymbol ifTrue:[ |
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
173 |
aCompiler addLiteral:value. |
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
174 |
]. |
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
175 |
^ self |
1995 | 176 |
|
177 |
"Modified: / 04-03-2007 / 15:29:54 / cg" |
|
1560
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
178 |
! |
a3be357f8c4d
symbolic literal constants are remeembered,
Claus Gittinger <cg@exept.de>
parents:
1552
diff
changeset
|
179 |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
180 |
codeForSimpleReturnOn:aStream inBlock:b lineNumber:lineNrOrNil for:aCompiler |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
181 |
lineNrOrNil notNil ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
182 |
self codeLineNumber:lineNrOrNil on:aStream for:aCompiler |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
183 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
184 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
185 |
(type == #Nil) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
186 |
aStream nextPut:#retNil. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
187 |
^self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
188 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
189 |
(type == #True) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
190 |
aStream nextPut:#retTrue. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
191 |
^self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
192 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
193 |
(type == #False) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
194 |
aStream nextPut:#retFalse. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
195 |
^self |
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 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
198 |
(type == #Integer) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
199 |
(value between: -128 and:127) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
200 |
(value == 0) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
201 |
aStream nextPut:#ret0. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
202 |
^ self. |
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 |
aStream nextPut:#retNum; nextPut:value. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
205 |
^ self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
206 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
207 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
208 |
|
1401 | 209 |
"/ anything else must be pushed, then top returned |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
210 |
|
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
211 |
self codeOn:aStream inBlock:b for:aCompiler. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
212 |
aStream nextPut:#retTop |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
213 |
! |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
214 |
|
104 | 215 |
codeOn:aStream inBlock:b for:aCompiler |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
216 |
"generate code for the constant" |
0 | 217 |
|
104 | 218 |
|code index| |
96 | 219 |
|
0 | 220 |
(type == #Integer) ifTrue:[ |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
221 |
(value between: -128 and:127) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
222 |
(value == 0) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
223 |
code := #push0 |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
224 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
225 |
(value == 1) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
226 |
code := #push1. |
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 |
(value == 2) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
229 |
code := #push2. |
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 |
(value == -1) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
232 |
code := #pushMinus1. |
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 |
code notNil ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
235 |
aStream nextPut:code. ^ self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
236 |
]. |
96 | 237 |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
238 |
aStream nextPut:#pushNum; nextPut:value. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
239 |
^ self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
240 |
]. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
241 |
(value between:16r-8000 and:16r7FFF) ifTrue:[ |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
242 |
aStream nextPut:#pushNum16; nextPut:value; nextPut:0. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
243 |
^ self |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
244 |
] |
0 | 245 |
]. |
246 |
(type == #Nil) ifTrue:[ |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
247 |
code := #pushNil. |
0 | 248 |
]. |
249 |
(type == #True) ifTrue:[ |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
250 |
code := #pushTrue. |
0 | 251 |
]. |
252 |
(type == #False) ifTrue:[ |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
253 |
code := #pushFalse. |
0 | 254 |
]. |
96 | 255 |
code notNil ifTrue:[ |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
256 |
aStream nextPut:code. ^ self |
96 | 257 |
]. |
106 | 258 |
|
259 |
"/ kludge for backward compatibility |
|
260 |
aCompiler isNil ifTrue:[ |
|
2118 | 261 |
self halt:'strange literal constant'. |
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
262 |
aStream nextPut:#pushLit; nextPut:value. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
263 |
^ self. |
106 | 264 |
]. |
265 |
||
1805
d8f8075615dc
some code savers for common code-emit
Claus Gittinger <cg@exept.de>
parents:
1797
diff
changeset
|
266 |
self emitPushLiteral:value on:aStream for:aCompiler |
0 | 267 |
! |
268 |
||
104 | 269 |
codeStoreOn:aStream inBlock:codeBlock valueNeeded:valueNeeded for:aCompiler |
13 | 270 |
"not sent - parser checks for this" |
0 | 271 |
|
272 |
^ self error:'assignment to literals not allowed' |
|
273 |
! ! |
|
274 |
||
1035 | 275 |
!ConstantNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
276 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
277 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
278 |
"helper for parse tree walking" |
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 |
^ anEnumerator doLiteral:self value:value |
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 |
"Modified: 19.6.1997 / 16:40:59 / cg" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
283 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
263
diff
changeset
|
284 |
|
1035 | 285 |
!ConstantNode methodsFor:'evaluation'! |
140 | 286 |
|
287 |
evaluate |
|
1384 | 288 |
"exists for performance only" |
289 |
^ value |
|
290 |
! |
|
291 |
||
292 |
evaluateIn:anEnvironment |
|
140 | 293 |
^ value |
294 |
! |
|
295 |
||
296 |
store:aValue |
|
297 |
"not reached - parser checks for this" |
|
298 |
||
299 |
self error:'store not allowed'. |
|
300 |
^ aValue |
|
301 |
! ! |
|
302 |
||
1080 | 303 |
!ConstantNode methodsFor:'printing & storing'! |
0 | 304 |
|
13 | 305 |
displayString |
612 | 306 |
"return a printed representation of the receiver for displaying" |
307 |
||
13 | 308 |
^ value displayString |
612 | 309 |
|
310 |
"Modified: 20.9.1997 / 11:39:07 / cg" |
|
13 | 311 |
! |
312 |
||
0 | 313 |
printOn:aStream indent:i |
314 |
value storeOn:aStream |
|
315 |
! ! |
|
140 | 316 |
|
317 |
!ConstantNode methodsFor:'queries'! |
|
318 |
||
242
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
319 |
canReuseAsArg:anotherNode |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
320 |
|otherValue| |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
321 |
|
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
322 |
anotherNode isConstant ifTrue:[ |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
323 |
anotherNode type ~~ type ifTrue:[^ false]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
324 |
|
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
325 |
otherValue := anotherNode evaluate. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
326 |
(value isMemberOf:SmallInteger) ifTrue:[ |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
327 |
(value == 0) ifTrue:[^ false]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
328 |
(value == 1) ifTrue:[^ false]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
329 |
(value == 2) ifTrue:[^ false]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
330 |
(value == -1) ifTrue:[^ false]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
331 |
^ otherValue == value |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
332 |
]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
333 |
(value isMemberOf:Float) ifTrue:[ |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
334 |
^ (otherValue isMemberOf:Float) |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
335 |
and:[otherValue = value] |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
336 |
]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
337 |
(value isMemberOf:Symbol) ifTrue:[ |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
338 |
^ otherValue == value |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
339 |
]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
340 |
(value isMemberOf:String) ifTrue:[ |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
341 |
^ (otherValue isMemberOf:String) |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
342 |
and:[otherValue = value] |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
343 |
]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
344 |
]. |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
345 |
^ false |
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 |
"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
|
348 |
"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
|
349 |
! |
3cca9ffd2620
use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
350 |
|
2266 | 351 |
withConstantValueDo:aBlock |
352 |
"return true, if this evaluates to a constant value |
|
353 |
and evaluate aBlock with it" |
|
354 |
||
355 |
aBlock value:value. |
|
356 |
^ true |
|
140 | 357 |
! ! |
358 |
||
2320 | 359 |
!ConstantNode methodsFor:'testing'! |
360 |
||
361 |
isConstant |
|
362 |
^ true |
|
363 |
! ! |
|
364 |
||
148 | 365 |
!ConstantNode class methodsFor:'documentation'! |
366 |
||
2500 | 367 |
version_CVS |
368 |
^ '$Header: /cvs/stx/stx/libcomp/ConstantNode.st,v 1.46 2011-06-28 20:00:02 vrany Exp $' |
|
2266 | 369 |
! |
370 |
||
2500 | 371 |
version_SVN |
372 |
^ ' Id ' |
|
148 | 373 |
! ! |