ReturnNode.st
author claus
Thu, 10 Aug 1995 20:13:01 +0200
changeset 102 77e4d1119ff2
parent 71 2aac7fbb5be0
child 103 f4a69d7dd387
permissions -rw-r--r--
.

"
 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.
"

StatementNode subclass:#ReturnNode
       instanceVariableNames:'myHome blockHome'
       classVariableNames:''
       poolDictionaries:''
       category:'System-Compiler-Support'
!

ReturnNode comment:'
COPYRIGHT (c) 1989 by Claus Gittinger
	      All Rights Reserved

$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.9 1995-08-10 18:12:18 claus Exp $
'!

!ReturnNode 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.
"
!

version
"
$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.9 1995-08-10 18:12:18 claus Exp $
$Revision: 1.9 $
"
!

documentation
"
    node for parse-trees, representing return expressions
"
! !

!ReturnNode methodsFor:'accessing'!

home:someOne blockHome:aBlockNode
    myHome := someOne.
    blockHome := aBlockNode
! !

!ReturnNode methodsFor:'queries'!

isConstant
    ^ false
!

isReturnNode
    ^ true
! !

!ReturnNode methodsFor:'evaluating'!

evaluateExpression
    |val|

    val := expression evaluate.
    myHome exitWith:val.
    "when we arrive here, the parser context is already gone
     - try block-return"
    blockHome notNil ifTrue:[blockHome exitWith:val].
    "well - what else can be done"
    ^ val
! !

!ReturnNode methodsFor:'code generation'!

codeForSideEffectOn:aStream inBlock:b
    "redefined - drop not needed since notreached"

    ^ self codeOn:aStream inBlock:b
!

codeOn:aStream inBlock:b
    |type value index|

    "/ after 2.10
    b notNil ifTrue:[
	expression codeOn:aStream inBlock:b.
	aStream nextPut:#homeRetTop.
	^ self
    ].

    expression isPrimary ifTrue:[
	type := expression type.
	(type == #Nil) ifTrue:[
	    aStream nextPut:#retNil. ^ self
	].
	(type == #True) ifTrue:[
	    aStream nextPut:#retTrue. ^ self
	].
	(type == #False) ifTrue:[
	    aStream nextPut:#retFalse. ^ self
	].
	(type == #Self) ifTrue:[
	    aStream nextPut:#retSelf. ^ self
	].
	(type == #Integer) ifTrue:[
	    value := expression evaluate.
	    (value between: -128 and:127) ifTrue:[
		(value == 0) ifTrue:[
		    aStream nextPut:#ret0. ^ self
		].
		aStream nextPut:#retNum.
		aStream nextPut:value. ^ self
	    ]
	].
	(type == #InstanceVariable) ifTrue:[
	    index := expression index.
	    (index <= 8) ifTrue:[
		aStream nextPut:(#(retInstVar1
				   retInstVar2
				   retInstVar3
				   retInstVar4
				   retInstVar5
				   retInstVar6
				   retInstVar7
				   retInstVar8) at:index). ^ self
	    ]
	].
	(type == #MethodVariable) ifTrue:[
	    index := expression index.
	    (index <= 6) ifTrue:[
		aStream nextPut:(#(retMethodVar1
				   retMethodVar2
				   retMethodVar3
				   retMethodVar4
				   retMethodVar5
				   retMethodVar6) at:index). ^ self
	    ]
	].
	(type == #MethodArg) ifTrue:[
	    index := expression index.
	    (index <= 2) ifTrue:[
		aStream nextPut:(#(retMethodArg1
				   retMethodArg2) at:index). ^ self
	    ]
	]
    ].
    expression codeOn:aStream inBlock:b.
    aStream nextPut:#retTop
! !

!ReturnNode methodsFor:'printing'!

printOn:aStream indent:i
    aStream nextPutAll:'^ '.
    expression printOn:aStream
! !