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