0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
StatementNode subclass:#ReturnNode
|
|
14 |
instanceVariableNames:'myHome blockHome'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'System-Compiler-Support'
|
|
18 |
!
|
|
19 |
|
|
20 |
ReturnNode comment:'
|
4
|
21 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
22 |
All Rights Reserved
|
20
|
23 |
'!
|
0
|
24 |
|
20
|
25 |
!ReturnNode class methodsFor:'documentation'!
|
|
26 |
|
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
30 |
All Rights Reserved
|
|
31 |
|
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
!
|
|
40 |
|
|
41 |
version
|
|
42 |
"
|
|
43 |
$Header: /cvs/stx/stx/libcomp/Attic/RetNode.st,v 1.5 1994-06-02 20:26:14 claus Exp $
|
|
44 |
"
|
|
45 |
!
|
|
46 |
|
|
47 |
documentation
|
|
48 |
"
|
|
49 |
node for parse-trees, representing return expressions
|
|
50 |
"
|
|
51 |
! !
|
0
|
52 |
|
|
53 |
!ReturnNode methodsFor:'accessing'!
|
|
54 |
|
|
55 |
home:someOne blockHome:aBlockNode
|
|
56 |
myHome := someOne.
|
|
57 |
blockHome := aBlockNode
|
|
58 |
! !
|
|
59 |
|
13
|
60 |
!ReturnNode methodsFor:'queries'!
|
|
61 |
|
|
62 |
isReturnNode
|
|
63 |
^ true
|
|
64 |
! !
|
|
65 |
|
0
|
66 |
!ReturnNode methodsFor:'evaluating'!
|
|
67 |
|
|
68 |
evaluateExpression
|
|
69 |
|val|
|
|
70 |
|
|
71 |
val := expression evaluate.
|
|
72 |
myHome exitWith:val.
|
|
73 |
"when we arrive here, the parser context is already gone
|
|
74 |
- try block-return"
|
|
75 |
blockHome notNil ifTrue:[blockHome exitWith:val].
|
|
76 |
"well - what else can be done"
|
|
77 |
^ val
|
|
78 |
! !
|
|
79 |
|
|
80 |
!ReturnNode methodsFor:'code generation'!
|
|
81 |
|
|
82 |
codeForSideEffectOn:aStream inBlock:b
|
|
83 |
"redefined - drop not needed since notreached"
|
|
84 |
|
|
85 |
^ self codeOn:aStream inBlock:b
|
|
86 |
!
|
|
87 |
|
|
88 |
codeOn:aStream inBlock:b
|
|
89 |
|type value index|
|
|
90 |
|
|
91 |
(expression isKindOf:PrimaryNode) ifTrue:[
|
|
92 |
type := expression type.
|
|
93 |
(type == #Nil) ifTrue:[
|
|
94 |
aStream nextPut:#retNil. ^ self
|
|
95 |
].
|
|
96 |
(type == #True) ifTrue:[
|
|
97 |
aStream nextPut:#retTrue. ^ self
|
|
98 |
].
|
|
99 |
(type == #False) ifTrue:[
|
|
100 |
aStream nextPut:#retFalse. ^ self
|
|
101 |
].
|
|
102 |
(type == #Self) ifTrue:[
|
|
103 |
aStream nextPut:#retSelf. ^ self
|
|
104 |
].
|
|
105 |
(type == #Integer) ifTrue:[
|
|
106 |
value := expression evaluate.
|
|
107 |
(value between: -128 and:127) ifTrue:[
|
|
108 |
(value == 0) ifTrue:[
|
|
109 |
aStream nextPut:#ret0. ^ self
|
|
110 |
].
|
|
111 |
aStream nextPut:#retNum.
|
|
112 |
aStream nextPut:value. ^ self
|
|
113 |
]
|
|
114 |
].
|
|
115 |
(type == #InstanceVariable) ifTrue:[
|
|
116 |
index := expression index.
|
|
117 |
(index <= 8) ifTrue:[
|
|
118 |
aStream nextPut:(#(retInstVar1
|
|
119 |
retInstVar2
|
|
120 |
retInstVar3
|
|
121 |
retInstVar4
|
|
122 |
retInstVar5
|
|
123 |
retInstVar6
|
|
124 |
retInstVar7
|
|
125 |
retInstVar8) at:index). ^ self
|
|
126 |
]
|
|
127 |
].
|
|
128 |
(type == #MethodVariable) ifTrue:[
|
|
129 |
index := expression index.
|
|
130 |
(index <= 6) ifTrue:[
|
|
131 |
aStream nextPut:(#(retMethodVar1
|
|
132 |
retMethodVar2
|
|
133 |
retMethodVar3
|
|
134 |
retMethodVar4
|
|
135 |
retMethodVar5
|
|
136 |
retMethodVar6) at:index). ^ self
|
|
137 |
]
|
|
138 |
].
|
|
139 |
(type == #MethodArg) ifTrue:[
|
|
140 |
index := expression index.
|
|
141 |
(index <= 2) ifTrue:[
|
|
142 |
aStream nextPut:(#(retMethodArg1
|
|
143 |
retMethodArg2) at:index). ^ self
|
|
144 |
]
|
|
145 |
]
|
|
146 |
].
|
|
147 |
expression codeOn:aStream inBlock:b.
|
|
148 |
aStream nextPut:#retTop
|
|
149 |
! !
|
|
150 |
|
|
151 |
!ReturnNode methodsFor:'printing'!
|
|
152 |
|
|
153 |
printOn:aStream indent:i
|
|
154 |
aStream nextPutAll:'^ '.
|
|
155 |
expression printOn:aStream
|
|
156 |
! !
|