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 |
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
|
0
|
22 |
All Rights Reserved
|
|
23 |
|
13
|
24 |
$Header: /cvs/stx/stx/libcomp/BinaryNode.st,v 1.5 1994-01-16 03:51:32 claus Exp $
|
0
|
25 |
'!
|
|
26 |
|
|
27 |
!BinaryNode methodsFor:'queries'!
|
|
28 |
|
|
29 |
isBinaryMessage
|
|
30 |
^ true
|
|
31 |
! !
|
|
32 |
|
|
33 |
!BinaryNode methodsFor:'accessing'!
|
|
34 |
|
|
35 |
arg
|
|
36 |
^ argArray at:1
|
|
37 |
! !
|
|
38 |
|
|
39 |
!BinaryNode methodsFor:'evaluating'!
|
|
40 |
|
|
41 |
evaluate
|
13
|
42 |
receiver isSuper ifTrue:[
|
|
43 |
^ super evaluate
|
|
44 |
].
|
0
|
45 |
^ (receiver evaluate) perform:selector with:(argArray at:1) evaluate
|
|
46 |
! !
|
|
47 |
|
|
48 |
!BinaryNode methodsFor:'code generation'!
|
|
49 |
|
|
50 |
codeOn:aStream inBlock:b
|
|
51 |
|arg1|
|
|
52 |
|
|
53 |
(receiver type == #Super) ifFalse:[
|
|
54 |
( #(== ~~ = ~= + - < <= > >=) includes:selector) ifTrue:[
|
|
55 |
receiver codeOn:aStream inBlock:b.
|
|
56 |
arg1 := argArray at:1.
|
|
57 |
arg1 isConstant ifTrue:[
|
|
58 |
(arg1 type == #Integer) ifTrue:[
|
|
59 |
((selector == #==) or:[selector == #~~]) ifTrue:[
|
|
60 |
(arg1 value == 0) ifTrue:[
|
|
61 |
(selector == #==) ifTrue:[
|
|
62 |
aStream nextPut:#eq0
|
|
63 |
] ifFalse:[
|
|
64 |
aStream nextPut:#ne0
|
|
65 |
].
|
|
66 |
^ self
|
|
67 |
]
|
|
68 |
].
|
|
69 |
((selector == #+) or:[selector == #-]) ifTrue:[
|
|
70 |
(arg1 value == 1) ifTrue:[
|
|
71 |
(selector == #+) ifTrue:[
|
|
72 |
aStream nextPut:#plus1
|
|
73 |
] ifFalse:[
|
|
74 |
aStream nextPut:#minus1
|
|
75 |
].
|
13
|
76 |
aStream nextPut:lineNr.
|
0
|
77 |
^ self
|
|
78 |
]
|
|
79 |
]
|
|
80 |
]
|
|
81 |
].
|
|
82 |
arg1 codeOn:aStream inBlock:b.
|
|
83 |
aStream nextPut:selector.
|
13
|
84 |
(self class hasLineNumber:selector) ifTrue:[
|
|
85 |
aStream nextPut:lineNr.
|
|
86 |
].
|
0
|
87 |
^ self
|
|
88 |
]
|
|
89 |
].
|
|
90 |
^ super codeOn:aStream inBlock:b
|
|
91 |
! !
|
|
92 |
|
|
93 |
!BinaryNode methodsFor:'printing'!
|
|
94 |
|
|
95 |
printOn:aStream indent:i
|
|
96 |
|needParen|
|
|
97 |
|
|
98 |
needParen := false.
|
|
99 |
receiver isMessage ifTrue:[
|
|
100 |
receiver isUnaryMessage ifFalse:[
|
|
101 |
needParen := true
|
|
102 |
].
|
|
103 |
].
|
|
104 |
needParen ifTrue:[
|
|
105 |
aStream nextPutAll:'('
|
|
106 |
].
|
|
107 |
receiver printOn:aStream.
|
|
108 |
needParen ifTrue:[
|
|
109 |
aStream nextPutAll:') '
|
|
110 |
].
|
|
111 |
|
|
112 |
aStream space.
|
|
113 |
selector printString printOn:aStream.
|
|
114 |
aStream space.
|
|
115 |
|
|
116 |
needParen := false.
|
|
117 |
self arg isMessage ifTrue:[
|
|
118 |
self arg isUnaryMessage ifFalse:[
|
|
119 |
needParen := true
|
|
120 |
].
|
|
121 |
].
|
|
122 |
needParen ifTrue:[
|
|
123 |
aStream nextPutAll:'('
|
|
124 |
].
|
|
125 |
self arg printOn:aStream.
|
|
126 |
needParen ifTrue:[
|
|
127 |
aStream nextPutAll:') '
|
|
128 |
].
|
|
129 |
! !
|