BinaryNd.st
author Claus Gittinger <cg@exept.de>
Sat, 09 Dec 1995 23:10:33 +0100
changeset 163 9a7dfd547e69
parent 148 ef0e604209ec
child 199 1b3b350a3f59
permissions -rw-r--r--
checkin from browser

"
 COPYRIGHT (c) 1989 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

MessageNode subclass:#BinaryNode
	 instanceVariableNames:''
	 classVariableNames:''
	 poolDictionaries:''
	 category:'System-Compiler-Support'
!

!BinaryNode class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1989 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    node for parse-trees, representing binary message sends
"
! !

!BinaryNode class methodsFor:'queries'!

isBuiltInBinarySelector:sel
    sel == #== ifTrue:[^ true].
    sel == #~~ ifTrue:[^ true].
    sel == #= ifTrue:[^ true].
    sel == #~= ifTrue:[^ true].
    sel == #+ ifTrue:[^ true].
    sel == #- ifTrue:[^ true].
    sel == #< ifTrue:[^ true].
    sel == #<= ifTrue:[^ true].
    sel == #> ifTrue:[^ true].
    sel == #>= ifTrue:[^ true].
    sel == #* ifTrue:[^ true].
    sel == #& ifTrue:[^ true].
    sel == #| ifTrue:[^ true].
    ^ false
! !

!BinaryNode methodsFor:'accessing'!

arg
    ^ argArray at:1
! !

!BinaryNode methodsFor:'code generation'!

codeOn:aStream inBlock:b for:aCompiler
    |arg1 recVal argVal code|

    receiver isSuper ifFalse:[
	(self class isBuiltInBinarySelector:selector) ifTrue:[
	"/ ( #(== ~~ = ~= + - < <= > >=) includes:selector) ifTrue:[
	    arg1 := argArray at:1.

	    receiver isConstant ifTrue:[
		recVal := receiver value.
		(receiver type == #Integer) ifTrue:[
		    ((selector == #==) or:[selector == #~~]) ifTrue:[
			recVal == 0 ifTrue:[
			    arg1 codeOn:aStream inBlock:b for:aCompiler.
			    (selector == #==) ifTrue:[
				code := #eq0
			    ] ifFalse:[
				code := #ne0
			    ].
			    aStream nextPut:code.
			    ^ self
			]
		    ].
		].
		recVal == nil ifTrue:[
		    arg1 codeOn:aStream inBlock:b for:aCompiler.
		    (selector == #==) ifTrue:[
			code := #isNil 
		    ] ifFalse:[
			code := #notNil 
		    ].
		    aStream nextPut:code. 
		    ^ self
		].
		(selector == #+) ifTrue:[
		    (recVal == 1) ifTrue:[
			arg1 codeOn:aStream inBlock:b for:aCompiler.
			(selector == #+) ifTrue:[
			    code := #plus1
			] ifFalse:[
			    code := #minus1
			].
			aStream nextPut:code; nextPut:lineNr.
			^ self
		    ]
		]
	    ].

	    receiver codeOn:aStream inBlock:b for:aCompiler.
	    arg1 isConstant ifTrue:[
		argVal := arg1 value.
		(arg1 type == #Integer) ifTrue:[
		    ((selector == #==) or:[selector == #~~]) ifTrue:[
			(argVal == 0) ifTrue:[
			    (selector == #==) ifTrue:[
				code := #eq0
			    ] ifFalse:[
				code := #ne0
			    ].
			    aStream nextPut:code.
			    ^ self
			]
		    ].
		    selector == #> ifTrue:[
			argVal == 0 ifTrue:[ 
			    aStream nextPut:#gt0; nextPut:lineNr.
			    ^ self
			]
		    ].
		    ((selector == #+) or:[selector == #-]) ifTrue:[
			(argVal == 1) ifTrue:[
			    (selector == #+) ifTrue:[
				code := #plus1
			    ] ifFalse:[
				code := #minus1
			    ].
			    aStream nextPut:code; nextPut:lineNr.
			    ^ self
			]
		    ]
		].
		argVal isNil ifTrue:[
		    (selector == #==) ifTrue:[
			aStream nextPut:#isNil.
			^ self
		    ].
		    (selector == #~~) ifTrue:[
			aStream nextPut:#notNil.
			^ self
		    ].
		]
	    ].
	    arg1 codeOn:aStream inBlock:b for:aCompiler.
	    aStream nextPut:selector.
	    (self class hasLineNumber:selector) ifTrue:[
		aStream nextPut:lineNr.
	    ].
	    ^ self
	]
    ].
    ^ super codeOn:aStream inBlock:b for:aCompiler
! !

!BinaryNode methodsFor:'evaluating'!

evaluate
    receiver isSuper ifTrue:[
	^ super evaluate
    ].
    ^ (receiver evaluate) perform:selector with:(argArray at:1) evaluate
! !

!BinaryNode methodsFor:'printing'!

printOn:aStream indent:i
    |needParen|

    needParen := false.
    receiver isMessage ifTrue:[
	receiver isUnaryMessage ifFalse:[
	    needParen := true
	].
    ].
    needParen ifTrue:[
	aStream nextPutAll:'('
    ].
    receiver printOn:aStream.
    needParen ifTrue:[
	aStream nextPutAll:') '
    ].

    aStream space.
    selector printString printOn:aStream.
    aStream space.

    needParen := false.
    self arg isMessage ifTrue:[
	self arg isUnaryMessage ifFalse:[
	    needParen := true
	].
    ].
    needParen ifTrue:[
	aStream nextPutAll:'('
    ].
    self arg printOn:aStream.
    needParen ifTrue:[
	aStream nextPutAll:') '
    ].
! !

!BinaryNode methodsFor:'queries'!

isBinaryMessage
    ^ true
! !

!BinaryNode class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libcomp/Attic/BinaryNd.st,v 1.19 1995-12-03 12:16:38 cg Exp $'
! !