9 other person. No title to or ownership of the software is |
9 other person. No title to or ownership of the software is |
10 hereby transferred. |
10 hereby transferred. |
11 " |
11 " |
12 |
12 |
13 PrimaryNode subclass:#ConstantNode |
13 PrimaryNode subclass:#ConstantNode |
14 instanceVariableNames:'' |
14 instanceVariableNames:'' |
15 classVariableNames:'TrueNode FalseNode NilNode Const0Node Const1Node |
15 classVariableNames:'TrueNode FalseNode NilNode Const0Node Const1Node Float0Node' |
16 Float0Node' |
16 poolDictionaries:'' |
17 poolDictionaries:'' |
17 category:'System-Compiler-Support' |
18 category:'System-Compiler-Support' |
|
19 ! |
18 ! |
20 |
19 |
21 !ConstantNode class methodsFor:'documentation'! |
20 !ConstantNode class methodsFor:'documentation'! |
22 |
21 |
23 copyright |
22 copyright |
32 other person. No title to or ownership of the software is |
31 other person. No title to or ownership of the software is |
33 hereby transferred. |
32 hereby transferred. |
34 " |
33 " |
35 ! |
34 ! |
36 |
35 |
|
36 documentation |
|
37 " |
|
38 node for parse-trees, representing literal constants |
|
39 " |
|
40 ! |
|
41 |
37 version |
42 version |
38 ^ '$Header: /cvs/stx/stx/libcomp/ConstantNode.st,v 1.17 1995-11-11 15:30:17 cg Exp $' |
43 ^ '$Header: /cvs/stx/stx/libcomp/ConstantNode.st,v 1.18 1995-11-23 02:12:53 cg Exp $' |
39 ! |
|
40 |
|
41 documentation |
|
42 " |
|
43 node for parse-trees, representing literal constants |
|
44 " |
|
45 ! ! |
|
46 |
|
47 !ConstantNode class methodsFor:'queries'! |
|
48 |
|
49 typeOfConstant:anObject |
|
50 "return the constantNode type for an object" |
|
51 |
|
52 "the most common case first ..." |
|
53 |
|
54 (anObject isMemberOf:SmallInteger) ifTrue:[ |
|
55 ^ #Integer |
|
56 ]. |
|
57 |
|
58 anObject isNil ifTrue:[ |
|
59 ^ #Nil |
|
60 ]. |
|
61 |
|
62 anObject isNumber ifTrue:[ |
|
63 "the most common case first ..." |
|
64 (anObject isMemberOf:Float) ifTrue:[ |
|
65 ^ #Float |
|
66 ]. |
|
67 anObject isInteger ifTrue:[ |
|
68 ^ #Integer |
|
69 ]. |
|
70 ]. |
|
71 (anObject == true) ifTrue:[ |
|
72 ^ #True |
|
73 ]. |
|
74 (anObject == false) ifTrue:[ |
|
75 ^ #False |
|
76 ]. |
|
77 ^ #Literal |
|
78 ! ! |
44 ! ! |
79 |
45 |
80 !ConstantNode class methodsFor:'instance creation'! |
46 !ConstantNode class methodsFor:'instance creation'! |
81 |
|
82 value:val |
|
83 ^ self type:(self typeOfConstant:val) value:val |
|
84 ! |
|
85 |
47 |
86 type:t value:val |
48 type:t value:val |
87 "some constant nodes are used so often, its worth caching them" |
49 "some constant nodes are used so often, its worth caching them" |
88 (t == #True) ifTrue:[ |
50 (t == #True) ifTrue:[ |
89 TrueNode isNil ifTrue:[ |
51 TrueNode isNil ifTrue:[ |
124 ]. |
86 ]. |
125 ^ Float0Node |
87 ^ Float0Node |
126 ] |
88 ] |
127 ]. |
89 ]. |
128 ^ (self basicNew) type:t value:val |
90 ^ (self basicNew) type:t value:val |
|
91 ! |
|
92 |
|
93 value:val |
|
94 ^ self type:(self typeOfConstant:val) value:val |
|
95 ! ! |
|
96 |
|
97 !ConstantNode class methodsFor:'queries'! |
|
98 |
|
99 typeOfConstant:anObject |
|
100 "return the constantNode type for an object" |
|
101 |
|
102 "the most common case first ..." |
|
103 |
|
104 (anObject isMemberOf:SmallInteger) ifTrue:[ |
|
105 ^ #Integer |
|
106 ]. |
|
107 |
|
108 anObject isNil ifTrue:[ |
|
109 ^ #Nil |
|
110 ]. |
|
111 |
|
112 anObject isNumber ifTrue:[ |
|
113 "the most common case first ..." |
|
114 (anObject isMemberOf:Float) ifTrue:[ |
|
115 ^ #Float |
|
116 ]. |
|
117 anObject isInteger ifTrue:[ |
|
118 ^ #Integer |
|
119 ]. |
|
120 ]. |
|
121 (anObject == true) ifTrue:[ |
|
122 ^ #True |
|
123 ]. |
|
124 (anObject == false) ifTrue:[ |
|
125 ^ #False |
|
126 ]. |
|
127 ^ #Literal |
129 ! ! |
128 ! ! |
130 |
129 |
131 !ConstantNode methodsFor:'accessing'! |
130 !ConstantNode methodsFor:'accessing'! |
132 |
131 |
133 type:t value:val |
132 type:t value:val |
134 type := t. |
133 type := t. |
135 value := val |
134 value := val |
136 ! ! |
|
137 |
|
138 !ConstantNode methodsFor:'queries'! |
|
139 |
|
140 isConstant |
|
141 ^ true |
|
142 ! ! |
|
143 |
|
144 !ConstantNode methodsFor:'evaluating'! |
|
145 |
|
146 evaluate |
|
147 ^ value |
|
148 ! |
|
149 |
|
150 store:aValue |
|
151 "not reached - parser checks for this" |
|
152 |
|
153 self error:'store not allowed'. |
|
154 ^ aValue |
|
155 ! ! |
135 ! ! |
156 |
136 |
157 !ConstantNode methodsFor:'code generation'! |
137 !ConstantNode methodsFor:'code generation'! |
158 |
138 |
159 codeOn:aStream inBlock:b for:aCompiler |
139 codeOn:aStream inBlock:b for:aCompiler |
223 "not sent - parser checks for this" |
203 "not sent - parser checks for this" |
224 |
204 |
225 ^ self error:'assignment to literals not allowed' |
205 ^ self error:'assignment to literals not allowed' |
226 ! ! |
206 ! ! |
227 |
207 |
|
208 !ConstantNode methodsFor:'evaluating'! |
|
209 |
|
210 evaluate |
|
211 ^ value |
|
212 ! |
|
213 |
|
214 store:aValue |
|
215 "not reached - parser checks for this" |
|
216 |
|
217 self error:'store not allowed'. |
|
218 ^ aValue |
|
219 ! ! |
|
220 |
228 !ConstantNode methodsFor:'printing'! |
221 !ConstantNode methodsFor:'printing'! |
229 |
222 |
230 displayString |
223 displayString |
231 ^ value displayString |
224 ^ value displayString |
232 ! |
225 ! |
233 |
226 |
234 printOn:aStream indent:i |
227 printOn:aStream indent:i |
235 value storeOn:aStream |
228 value storeOn:aStream |
236 ! ! |
229 ! ! |
|
230 |
|
231 !ConstantNode methodsFor:'queries'! |
|
232 |
|
233 isConstant |
|
234 ^ true |
|
235 ! ! |
|
236 |