ReturnNode.st
changeset 0 7ad01559b262
child 3 b63b8a6b71fb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ReturnNode.st	Fri Jul 16 11:38:57 1993 +0200
@@ -0,0 +1,124 @@
+"
+ COPYRIGHT (c) 1989-93 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-93 by Claus Gittinger
+              All Rights Reserved
+
+%W% %E%
+'!
+
+!ReturnNode methodsFor:'accessing'!
+
+home:someOne blockHome:aBlockNode
+    myHome := someOne.
+    blockHome := aBlockNode
+! !
+
+!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|
+
+    (expression isKindOf:PrimaryNode) 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
+! !