author | Claus Gittinger <cg@exept.de> |
Thu, 19 Jun 1997 16:58:23 +0200 | |
changeset 539 | 69a1cd05c7d6 |
parent 393 | 5dc3fdd2177b |
child 817 | 8de90dbed4bb |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
62 | 3 |
All Rights Reserved |
0 | 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 |
|
393 | 14 |
instanceVariableNames:'myHome blockHome' |
261 | 15 |
classVariableNames:'' |
16 |
poolDictionaries:'' |
|
17 |
category:'System-Compiler-Support' |
|
0 | 18 |
! |
19 |
||
20 | 20 |
!ReturnNode class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
62 | 25 |
All Rights Reserved |
20 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
node for parse-trees, representing return expressions |
|
261 | 39 |
This is a helper class for the compiler. |
263 | 40 |
|
41 |
[author:] |
|
42 |
Claus Gittinger |
|
20 | 43 |
" |
44 |
! ! |
|
0 | 45 |
|
380 | 46 |
!ReturnNode class methodsFor:'code generation helper'! |
47 |
||
48 |
codeSimpleReturnFor:expression inBlock:b on:aStream inLine:lineNrOrNil for:aCompiler |
|
49 |
|type value index code code2| |
|
50 |
||
51 |
expression isPrimary ifTrue:[ |
|
52 |
type := expression type. |
|
53 |
(type == #Nil) ifTrue:[ |
|
54 |
code := #retNil |
|
55 |
] ifFalse:[ |
|
56 |
(type == #True) ifTrue:[ |
|
57 |
code := #retTrue |
|
58 |
] ifFalse:[ |
|
59 |
(type == #False) ifTrue:[ |
|
60 |
code := #retFalse |
|
61 |
] ifFalse:[ |
|
62 |
(type == #Self) ifTrue:[ |
|
63 |
code := #retSelf |
|
64 |
] ifFalse:[ |
|
65 |
(type == #Integer) ifTrue:[ |
|
66 |
value := expression evaluate. |
|
67 |
(value between: -128 and:127) ifTrue:[ |
|
68 |
(value == 0) ifTrue:[ |
|
69 |
code := #ret0 |
|
70 |
] ifFalse:[ |
|
71 |
code := #retNum. |
|
72 |
code2 := value. |
|
73 |
] |
|
74 |
] |
|
75 |
] ifFalse:[ |
|
76 |
(type == #InstanceVariable) ifTrue:[ |
|
77 |
index := expression index. |
|
78 |
(index <= 8) ifTrue:[ |
|
79 |
code := #( retInstVar1 |
|
80 |
retInstVar2 |
|
81 |
retInstVar3 |
|
82 |
retInstVar4 |
|
83 |
retInstVar5 |
|
84 |
retInstVar6 |
|
85 |
retInstVar7 |
|
86 |
retInstVar8) at:index |
|
87 |
] |
|
88 |
] ifFalse:[ |
|
89 |
(type == #MethodVariable) ifTrue:[ |
|
90 |
index := expression index. |
|
91 |
(index <= 6) ifTrue:[ |
|
92 |
code := #( retMethodVar1 |
|
93 |
retMethodVar2 |
|
94 |
retMethodVar3 |
|
95 |
retMethodVar4 |
|
96 |
retMethodVar5 |
|
97 |
retMethodVar6) at:index |
|
98 |
] |
|
99 |
] ifFalse:[ |
|
100 |
(type == #MethodArg) ifTrue:[ |
|
101 |
index := expression index. |
|
102 |
(index <= 2) ifTrue:[ |
|
103 |
code := #(retMethodArg1 |
|
104 |
retMethodArg2) at:index |
|
105 |
] |
|
106 |
] |
|
107 |
] |
|
108 |
] |
|
109 |
] |
|
110 |
] |
|
111 |
] |
|
112 |
] |
|
113 |
] |
|
114 |
]. |
|
115 |
||
116 |
code isNil ifTrue:[ |
|
117 |
expression codeOn:aStream inBlock:b for:aCompiler. |
|
118 |
code := #retTop |
|
119 |
]. |
|
120 |
||
121 |
lineNrOrNil notNil ifTrue:[ |
|
122 |
ParseNode codeLineNumber:lineNrOrNil on:aStream for:aCompiler |
|
123 |
]. |
|
124 |
||
125 |
aStream nextPut:code. |
|
126 |
code2 notNil ifTrue:[ |
|
127 |
aStream nextPut:code2 |
|
128 |
]. |
|
129 |
||
130 |
"Created: 21.10.1996 / 14:37:35 / cg" |
|
131 |
"Modified: 21.10.1996 / 14:43:11 / cg" |
|
132 |
! ! |
|
133 |
||
0 | 134 |
!ReturnNode methodsFor:'accessing'! |
135 |
||
136 |
home:someOne blockHome:aBlockNode |
|
137 |
myHome := someOne. |
|
138 |
blockHome := aBlockNode |
|
139 |
! ! |
|
140 |
||
141 |
!ReturnNode methodsFor:'code generation'! |
|
142 |
||
104 | 143 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
0 | 144 |
"redefined - drop not needed since notreached" |
145 |
||
104 | 146 |
^ self codeOn:aStream inBlock:b for:aCompiler |
0 | 147 |
! |
148 |
||
104 | 149 |
codeOn:aStream inBlock:b for:aCompiler |
380 | 150 |
b isNil ifTrue:[ |
151 |
^ self class |
|
152 |
codeSimpleReturnFor:expression |
|
153 |
inBlock:nil |
|
154 |
on:aStream |
|
155 |
inLine:lineNr |
|
156 |
for:aCompiler |
|
29 | 157 |
]. |
158 |
||
380 | 159 |
expression codeOn:aStream inBlock:b for:aCompiler. |
160 |
||
374 | 161 |
lineNr notNil ifTrue:[ |
380 | 162 |
ParseNode codeLineNumber:lineNr on:aStream for:aCompiler |
0 | 163 |
]. |
374 | 164 |
|
380 | 165 |
aStream nextPut:#homeRetTop. |
374 | 166 |
|
380 | 167 |
"Modified: 21.10.1996 / 14:54:36 / cg" |
0 | 168 |
! ! |
169 |
||
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
170 |
!ReturnNode methodsFor:'enumeration'! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
171 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
172 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
173 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
174 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
175 |
^ anEnumerator doReturn:self value:expression |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
176 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
177 |
"Modified: 19.6.1997 / 16:42:40 / cg" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
178 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
179 |
|
140 | 180 |
!ReturnNode methodsFor:'evaluating'! |
181 |
||
182 |
evaluateExpression |
|
183 |
|val| |
|
184 |
||
185 |
val := expression evaluate. |
|
186 |
myHome exitWith:val. |
|
187 |
"when we arrive here, the parser context is already gone |
|
188 |
- try block-return" |
|
189 |
blockHome notNil ifTrue:[blockHome exitWith:val]. |
|
190 |
"well - what else can be done" |
|
191 |
^ val |
|
192 |
! ! |
|
193 |
||
0 | 194 |
!ReturnNode methodsFor:'printing'! |
195 |
||
196 |
printOn:aStream indent:i |
|
197 |
aStream nextPutAll:'^ '. |
|
198 |
expression printOn:aStream |
|
199 |
! ! |
|
140 | 200 |
|
201 |
!ReturnNode methodsFor:'queries'! |
|
202 |
||
203 |
isConstant |
|
204 |
^ false |
|
205 |
! |
|
206 |
||
207 |
isReturnNode |
|
208 |
^ true |
|
209 |
! ! |
|
210 |
||
148 | 211 |
!ReturnNode class methodsFor:'documentation'! |
212 |
||
213 |
version |
|
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
214 |
^ '$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.20 1997-06-19 14:57:29 cg Exp $' |
148 | 215 |
! ! |