0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
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 |
"
|
|
12 |
|
|
13 |
PrimaryNode subclass:#ConstantNode
|
|
14 |
instanceVariableNames:''
|
10
|
15 |
classVariableNames:'TrueNode FalseNode NilNode Const0Node Const1Node
|
|
16 |
Float0Node'
|
0
|
17 |
poolDictionaries:''
|
|
18 |
category:'System-Compiler-Support'
|
|
19 |
!
|
|
20 |
|
|
21 |
ConstantNode comment:'
|
|
22 |
|
4
|
23 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
24 |
All Rights Reserved
|
|
25 |
|
10
|
26 |
$Header: /cvs/stx/stx/libcomp/Attic/ConstNode.st,v 1.5 1994-01-08 17:05:08 claus Exp $
|
0
|
27 |
'!
|
|
28 |
|
|
29 |
!ConstantNode class methodsFor:'queries'!
|
|
30 |
|
|
31 |
typeOfConstant:anObject
|
6
|
32 |
anObject isNumber ifTrue:[
|
|
33 |
(anObject isKindOf:SmallInteger) ifTrue:[
|
|
34 |
^ #Integer
|
|
35 |
].
|
|
36 |
(anObject isKindOf:Float) ifTrue:[
|
|
37 |
^ #Float
|
|
38 |
].
|
0
|
39 |
].
|
|
40 |
anObject isNil ifTrue:[
|
|
41 |
^ #Nil
|
|
42 |
].
|
|
43 |
(anObject == true) ifTrue:[
|
|
44 |
^ #True
|
|
45 |
].
|
|
46 |
(anObject == false) ifTrue:[
|
|
47 |
^ #False
|
|
48 |
].
|
|
49 |
^ #Literal
|
|
50 |
! !
|
|
51 |
|
|
52 |
!ConstantNode class methodsFor:'instance creation'!
|
|
53 |
|
|
54 |
type:t value:val
|
|
55 |
"some constant nodes are use so often, its worth caching them"
|
|
56 |
(t == #True) ifTrue:[
|
10
|
57 |
TrueNode isNil ifTrue:[
|
|
58 |
TrueNode := super type:t value:val
|
0
|
59 |
].
|
10
|
60 |
^ TrueNode
|
0
|
61 |
].
|
|
62 |
(t == #False) ifTrue:[
|
10
|
63 |
FalseNode isNil ifTrue:[
|
|
64 |
FalseNode := super type:t value:val
|
0
|
65 |
].
|
10
|
66 |
^ FalseNode
|
0
|
67 |
].
|
|
68 |
(t == #Nil) ifTrue:[
|
10
|
69 |
NilNode isNil ifTrue:[
|
|
70 |
NilNode := super type:t value:val
|
0
|
71 |
].
|
10
|
72 |
^ NilNode
|
0
|
73 |
].
|
|
74 |
(t == #Integer) ifTrue:[
|
|
75 |
(val == 0) ifTrue:[
|
10
|
76 |
Const0Node isNil ifTrue:[
|
|
77 |
Const0Node := super type:t value:val
|
0
|
78 |
].
|
10
|
79 |
^ Const0Node
|
0
|
80 |
].
|
|
81 |
(val == 1) ifTrue:[
|
10
|
82 |
Const1Node isNil ifTrue:[
|
|
83 |
Const1Node := super type:t value:val
|
0
|
84 |
].
|
10
|
85 |
^ Const1Node
|
0
|
86 |
]
|
|
87 |
].
|
|
88 |
(t == #Float) ifTrue:[
|
|
89 |
(val = 0.0) ifTrue:[
|
10
|
90 |
Float0Node isNil ifTrue:[
|
|
91 |
Float0Node := super type:t value:val
|
0
|
92 |
].
|
10
|
93 |
^ Float0Node
|
0
|
94 |
]
|
|
95 |
].
|
|
96 |
^ (self basicNew) type:t value:val
|
|
97 |
! !
|
|
98 |
|
|
99 |
!ConstantNode methodsFor:'queries'!
|
|
100 |
|
|
101 |
isConstant
|
|
102 |
^ true
|
|
103 |
! !
|
|
104 |
|
|
105 |
!ConstantNode methodsFor:'evaluating'!
|
|
106 |
|
|
107 |
evaluate
|
|
108 |
^ value
|
|
109 |
!
|
|
110 |
|
|
111 |
store:aValue
|
|
112 |
self error:'store not allowed'.
|
|
113 |
^ aValue
|
|
114 |
! !
|
|
115 |
|
|
116 |
!ConstantNode methodsFor:'code generation'!
|
|
117 |
|
|
118 |
codeOn:aStream inBlock:b
|
|
119 |
"generated code for the constant"
|
|
120 |
|
|
121 |
(type == #Integer) ifTrue:[
|
|
122 |
(value between: -128 and:127) ifTrue:[
|
|
123 |
(value == 0) ifTrue:[
|
|
124 |
aStream nextPut:#push0. ^ self
|
|
125 |
].
|
|
126 |
(value == 1) ifTrue:[
|
|
127 |
aStream nextPut:#push1. ^ self
|
|
128 |
].
|
3
|
129 |
(value == 2) ifTrue:[
|
|
130 |
aStream nextPut:#push2. ^ self
|
|
131 |
].
|
0
|
132 |
(value == -1) ifTrue:[
|
|
133 |
aStream nextPut:#pushMinus1. ^ self
|
|
134 |
].
|
|
135 |
aStream nextPut:#pushNum.
|
|
136 |
aStream nextPut:value.
|
|
137 |
^ self
|
|
138 |
]
|
|
139 |
].
|
|
140 |
(type == #Nil) ifTrue:[
|
|
141 |
aStream nextPut:#pushNil. ^ self
|
|
142 |
].
|
|
143 |
(type == #True) ifTrue:[
|
|
144 |
aStream nextPut:#pushTrue. ^ self
|
|
145 |
].
|
|
146 |
(type == #False) ifTrue:[
|
|
147 |
aStream nextPut:#pushFalse. ^ self
|
|
148 |
].
|
|
149 |
aStream nextPut:#pushLit.
|
|
150 |
aStream nextPut:value
|
|
151 |
!
|
|
152 |
|
|
153 |
codeStoreOn:aStream
|
|
154 |
"should never be sent"
|
|
155 |
|
|
156 |
^ self error:'assignment to literals not allowed'
|
|
157 |
! !
|
|
158 |
|
|
159 |
!ConstantNode methodsFor:'printing'!
|
|
160 |
|
|
161 |
printOn:aStream indent:i
|
|
162 |
value storeOn:aStream
|
|
163 |
! !
|