"
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
This is a helper class for the compiler.
[author:]
Claus Gittinger
"
! !
!ReturnNode class methodsFor:'code generation helper'!
codeSimpleReturnFor:expression inBlock:b on:aStream inLine:lineNrOrNil for:aCompiler
|type value index code code2|
expression isPrimary ifTrue:[
type := expression type.
(type == #Nil) ifTrue:[
code := #retNil
] ifFalse:[
(type == #True) ifTrue:[
code := #retTrue
] ifFalse:[
(type == #False) ifTrue:[
code := #retFalse
] ifFalse:[
(type == #Self) ifTrue:[
code := #retSelf
] ifFalse:[
(type == #Integer) ifTrue:[
value := expression evaluate.
(value between: -128 and:127) ifTrue:[
(value == 0) ifTrue:[
code := #ret0
] ifFalse:[
code := #retNum.
code2 := value.
]
]
] ifFalse:[
(type == #InstanceVariable) ifTrue:[
index := expression index.
(index <= 8) ifTrue:[
code := #( retInstVar1
retInstVar2
retInstVar3
retInstVar4
retInstVar5
retInstVar6
retInstVar7
retInstVar8) at:index
]
] ifFalse:[
(type == #MethodVariable) ifTrue:[
index := expression index.
(index <= 6) ifTrue:[
code := #( retMethodVar1
retMethodVar2
retMethodVar3
retMethodVar4
retMethodVar5
retMethodVar6) at:index
]
] ifFalse:[
(type == #MethodArg) ifTrue:[
index := expression index.
(index <= 2) ifTrue:[
code := #(retMethodArg1
retMethodArg2) at:index
]
]
]
]
]
]
]
]
]
].
code isNil ifTrue:[
expression codeOn:aStream inBlock:b for:aCompiler.
code := #retTop
].
lineNrOrNil notNil ifTrue:[
ParseNode codeLineNumber:lineNrOrNil on:aStream for:aCompiler
].
aStream nextPut:code.
code2 notNil ifTrue:[
aStream nextPut:code2
].
"Created: 21.10.1996 / 14:37:35 / cg"
"Modified: 21.10.1996 / 14:43:11 / cg"
! !
!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
b isNil ifTrue:[
^ self class
codeSimpleReturnFor:expression
inBlock:nil
on:aStream
inLine:lineNr
for:aCompiler
].
expression codeOn:aStream inBlock:b for:aCompiler.
lineNr notNil ifTrue:[
ParseNode codeLineNumber:lineNr on:aStream for:aCompiler
].
aStream nextPut:#homeRetTop.
"Modified: 21.10.1996 / 14:54:36 / cg"
! !
!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.19 1996-10-23 15:31:02 cg Exp $'
! !