0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
52
|
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 |
"
|
|
12 |
|
|
13 |
MessageNode subclass:#BinaryNode
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'System-Compiler-Support'
|
|
18 |
!
|
|
19 |
|
|
20 |
BinaryNode comment:'
|
4
|
21 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
52
|
22 |
All Rights Reserved
|
32
|
23 |
|
103
|
24 |
$Header: /cvs/stx/stx/libcomp/BinaryNode.st,v 1.13 1995-08-11 16:02:44 claus Exp $
|
20
|
25 |
'!
|
0
|
26 |
|
20
|
27 |
!BinaryNode class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
52
|
32 |
All Rights Reserved
|
20
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
103
|
45 |
$Header: /cvs/stx/stx/libcomp/BinaryNode.st,v 1.13 1995-08-11 16:02:44 claus Exp $
|
20
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
node for parse-trees, representing binary message sends
|
|
52 |
"
|
|
53 |
! !
|
0
|
54 |
|
|
55 |
!BinaryNode methodsFor:'queries'!
|
|
56 |
|
|
57 |
isBinaryMessage
|
|
58 |
^ true
|
|
59 |
! !
|
|
60 |
|
|
61 |
!BinaryNode methodsFor:'accessing'!
|
|
62 |
|
|
63 |
arg
|
|
64 |
^ argArray at:1
|
|
65 |
! !
|
|
66 |
|
|
67 |
!BinaryNode methodsFor:'evaluating'!
|
|
68 |
|
|
69 |
evaluate
|
13
|
70 |
receiver isSuper ifTrue:[
|
52
|
71 |
^ super evaluate
|
13
|
72 |
].
|
0
|
73 |
^ (receiver evaluate) perform:selector with:(argArray at:1) evaluate
|
|
74 |
! !
|
|
75 |
|
|
76 |
!BinaryNode methodsFor:'code generation'!
|
|
77 |
|
|
78 |
codeOn:aStream inBlock:b
|
96
|
79 |
|arg1 recVal argVal code|
|
0
|
80 |
|
49
|
81 |
receiver isSuper ifFalse:[
|
52
|
82 |
( #(== ~~ = ~= + - < <= > >=) includes:selector) ifTrue:[
|
76
|
83 |
arg1 := argArray at:1.
|
|
84 |
|
|
85 |
receiver isConstant ifTrue:[
|
|
86 |
recVal := receiver value.
|
|
87 |
(receiver type == #Integer) ifTrue:[
|
|
88 |
((selector == #==) or:[selector == #~~]) ifTrue:[
|
|
89 |
recVal == 0 ifTrue:[
|
|
90 |
arg1 codeOn:aStream inBlock:b.
|
|
91 |
(selector == #==) ifTrue:[
|
96
|
92 |
code := #eq0
|
76
|
93 |
] ifFalse:[
|
96
|
94 |
code := #ne0
|
76
|
95 |
].
|
96
|
96 |
aStream nextPut:code.
|
76
|
97 |
^ self
|
|
98 |
]
|
|
99 |
].
|
|
100 |
].
|
|
101 |
recVal == nil ifTrue:[
|
|
102 |
arg1 codeOn:aStream inBlock:b.
|
|
103 |
(selector == #==) ifTrue:[
|
96
|
104 |
code := #isNil
|
76
|
105 |
] ifFalse:[
|
96
|
106 |
code := #notNil
|
76
|
107 |
].
|
96
|
108 |
aStream nextPut:code.
|
76
|
109 |
^ self
|
|
110 |
].
|
|
111 |
(selector == #+) ifTrue:[
|
|
112 |
(recVal == 1) ifTrue:[
|
|
113 |
arg1 codeOn:aStream inBlock:b.
|
|
114 |
(selector == #+) ifTrue:[
|
96
|
115 |
code := #plus1
|
76
|
116 |
] ifFalse:[
|
96
|
117 |
code := #minus1
|
76
|
118 |
].
|
96
|
119 |
aStream nextPut:code; nextPut:lineNr.
|
76
|
120 |
^ self
|
|
121 |
]
|
|
122 |
]
|
|
123 |
].
|
|
124 |
|
52
|
125 |
receiver codeOn:aStream inBlock:b.
|
|
126 |
arg1 isConstant ifTrue:[
|
76
|
127 |
argVal := arg1 value.
|
52
|
128 |
(arg1 type == #Integer) ifTrue:[
|
|
129 |
((selector == #==) or:[selector == #~~]) ifTrue:[
|
76
|
130 |
(argVal == 0) ifTrue:[
|
52
|
131 |
(selector == #==) ifTrue:[
|
96
|
132 |
code := #eq0
|
52
|
133 |
] ifFalse:[
|
96
|
134 |
code := #ne0
|
52
|
135 |
].
|
96
|
136 |
aStream nextPut:code.
|
52
|
137 |
^ self
|
|
138 |
]
|
|
139 |
].
|
103
|
140 |
selector == #> ifTrue:[
|
|
141 |
argVal == 0 ifTrue:[
|
|
142 |
aStream nextPut:#gt0; nextPut:lineNr.
|
|
143 |
^ self
|
|
144 |
]
|
|
145 |
].
|
52
|
146 |
((selector == #+) or:[selector == #-]) ifTrue:[
|
76
|
147 |
(argVal == 1) ifTrue:[
|
52
|
148 |
(selector == #+) ifTrue:[
|
96
|
149 |
code := #plus1
|
52
|
150 |
] ifFalse:[
|
96
|
151 |
code := #minus1
|
52
|
152 |
].
|
96
|
153 |
aStream nextPut:code; nextPut:lineNr.
|
52
|
154 |
^ self
|
|
155 |
]
|
|
156 |
]
|
76
|
157 |
].
|
|
158 |
argVal isNil ifTrue:[
|
|
159 |
(selector == #==) ifTrue:[
|
|
160 |
aStream nextPut:#isNil.
|
|
161 |
^ self
|
|
162 |
].
|
|
163 |
(selector == #~~) ifTrue:[
|
|
164 |
aStream nextPut:#notNil.
|
|
165 |
^ self
|
|
166 |
].
|
52
|
167 |
]
|
|
168 |
].
|
|
169 |
arg1 codeOn:aStream inBlock:b.
|
|
170 |
aStream nextPut:selector.
|
|
171 |
(self class hasLineNumber:selector) ifTrue:[
|
|
172 |
aStream nextPut:lineNr.
|
|
173 |
].
|
|
174 |
^ self
|
|
175 |
]
|
0
|
176 |
].
|
|
177 |
^ super codeOn:aStream inBlock:b
|
|
178 |
! !
|
|
179 |
|
|
180 |
!BinaryNode methodsFor:'printing'!
|
|
181 |
|
|
182 |
printOn:aStream indent:i
|
|
183 |
|needParen|
|
|
184 |
|
|
185 |
needParen := false.
|
|
186 |
receiver isMessage ifTrue:[
|
52
|
187 |
receiver isUnaryMessage ifFalse:[
|
|
188 |
needParen := true
|
|
189 |
].
|
0
|
190 |
].
|
|
191 |
needParen ifTrue:[
|
52
|
192 |
aStream nextPutAll:'('
|
0
|
193 |
].
|
|
194 |
receiver printOn:aStream.
|
|
195 |
needParen ifTrue:[
|
52
|
196 |
aStream nextPutAll:') '
|
0
|
197 |
].
|
|
198 |
|
|
199 |
aStream space.
|
|
200 |
selector printString printOn:aStream.
|
|
201 |
aStream space.
|
|
202 |
|
|
203 |
needParen := false.
|
|
204 |
self arg isMessage ifTrue:[
|
52
|
205 |
self arg isUnaryMessage ifFalse:[
|
|
206 |
needParen := true
|
|
207 |
].
|
0
|
208 |
].
|
|
209 |
needParen ifTrue:[
|
52
|
210 |
aStream nextPutAll:'('
|
0
|
211 |
].
|
|
212 |
self arg printOn:aStream.
|
|
213 |
needParen ifTrue:[
|
52
|
214 |
aStream nextPutAll:') '
|
0
|
215 |
].
|
|
216 |
! !
|