"
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 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 return expressions
"
! !
!ReturnNode methodsFor:'accessing'!
home:someOne blockHome:aBlockNode
myHome := someOne.
blockHome := aBlockNode
! !
!ReturnNode methodsFor:'code generation'!
codeForSideEffectOn:aStream inBlock:b for:aCompiler
"redefined - drop not needed since notreached"
^ self codeOn:aStream inBlock:b for:aCompiler
!
codeOn:aStream inBlock:b for:aCompiler
|type value index|
"/ after 2.10
b notNil ifTrue:[
expression codeOn:aStream inBlock:b for:aCompiler.
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 for:aCompiler.
aStream nextPut:#retTop
! !
!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:'printing'!
printOn:aStream indent:i
aStream nextPutAll:'^ '.
expression printOn:aStream
! !
!ReturnNode methodsFor:'queries'!
isConstant
^ false
!
isReturnNode
^ true
! !
!ReturnNode class methodsFor:'documentation'!
version
^ '$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.14 1995-12-03 12:17:14 cg Exp $'
! !