author | Claus Gittinger <cg@exept.de> |
Wed, 19 May 2010 16:00:21 +0200 | |
changeset 2398 | f4fb7f5746dd |
parent 2397 | 6aea7415db4f |
child 2530 | 246794569e0c |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
1982
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
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 |
" |
|
1080 | 12 |
"{ Package: 'stx:libcomp' }" |
13 |
||
0 | 14 |
StatementNode subclass:#ReturnNode |
2101 | 15 |
instanceVariableNames:'myHome blockHome' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'System-Compiler-Support' |
|
0 | 19 |
! |
20 |
||
20 | 21 |
!ReturnNode class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
1982
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
26 |
All Rights Reserved |
20 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
node for parse-trees, representing return expressions |
|
261 | 40 |
This is a helper class for the compiler. |
263 | 41 |
|
42 |
[author:] |
|
43 |
Claus Gittinger |
|
20 | 44 |
" |
45 |
! ! |
|
0 | 46 |
|
47 |
!ReturnNode methodsFor:'accessing'! |
|
48 |
||
882
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
49 |
expression:e |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
50 |
super expression:e. |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
51 |
|
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
52 |
"/ any block, which is returned cannot be inlined. |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
53 |
e isBlockNode ifTrue:[ |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
54 |
e possiblyInlined:false |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
55 |
] |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
56 |
|
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
57 |
! |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
58 |
|
2398
f4fb7f5746dd
care for block vs. method return.
Claus Gittinger <cg@exept.de>
parents:
2397
diff
changeset
|
59 |
home |
f4fb7f5746dd
care for block vs. method return.
Claus Gittinger <cg@exept.de>
parents:
2397
diff
changeset
|
60 |
^ myHome |
f4fb7f5746dd
care for block vs. method return.
Claus Gittinger <cg@exept.de>
parents:
2397
diff
changeset
|
61 |
|
f4fb7f5746dd
care for block vs. method return.
Claus Gittinger <cg@exept.de>
parents:
2397
diff
changeset
|
62 |
"Created: / 19-05-2010 / 15:46:55 / cg" |
f4fb7f5746dd
care for block vs. method return.
Claus Gittinger <cg@exept.de>
parents:
2397
diff
changeset
|
63 |
! |
f4fb7f5746dd
care for block vs. method return.
Claus Gittinger <cg@exept.de>
parents:
2397
diff
changeset
|
64 |
|
0 | 65 |
home:someOne blockHome:aBlockNode |
66 |
myHome := someOne. |
|
67 |
blockHome := aBlockNode |
|
1945
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
68 |
! |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
69 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
70 |
lineNumber:something |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
71 |
"set lineNr" |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
72 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
73 |
lineNr := something. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
74 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
75 |
"Created: / 16-11-2006 / 14:38:51 / cg" |
0 | 76 |
! ! |
77 |
||
78 |
!ReturnNode methodsFor:'code generation'! |
|
79 |
||
1945
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
80 |
basicCodeOn:aStream inBlock:b for:aCompiler |
1593 | 81 |
b isNil ifTrue:[ |
82 |
self codeLocalReturnOn:aStream inBlock:b for:aCompiler. |
|
83 |
^ self. |
|
29 | 84 |
]. |
85 |
||
1593 | 86 |
"return from homeContext in a block" |
87 |
expression isNil ifTrue:[ |
|
88 |
"/ nil-expression is not possible in smalltalk; |
|
89 |
"/ however, it might be in a subclass (i.e. JavaScript) |
|
90 |
aStream nextPut:#pushNil. |
|
91 |
] ifFalse:[ |
|
92 |
expression codeOn:aStream inBlock:b for:aCompiler. |
|
93 |
]. |
|
374 | 94 |
lineNr notNil ifTrue:[ |
817 | 95 |
self codeLineNumber:lineNr on:aStream for:aCompiler |
0 | 96 |
]. |
380 | 97 |
aStream nextPut:#homeRetTop. |
374 | 98 |
|
1945
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
99 |
"Created: / 16-11-2006 / 14:05:27 / cg" |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
100 |
! |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
101 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
102 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
103 |
"redefined - drop not needed since notreached" |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
104 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
105 |
^ self basicCodeOn:aStream inBlock:b for:aCompiler |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
106 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
107 |
"Modified: / 16-11-2006 / 14:05:32 / cg" |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
108 |
! |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
109 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
110 |
codeForSimpleReturnOn:aStream inBlock:b lineNumber:lineNrOrNil for:aCompiler |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
111 |
"generate code to return myself as a simple method return" |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
112 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
113 |
self basicCodeOn:aStream inBlock:b for:aCompiler. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
114 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
115 |
"as a ReturnNode, I did return, so retTop is not needed" |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
116 |
"/ aStream nextPut:#retTop. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
117 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
118 |
"Modified: / 16-11-2006 / 14:05:35 / cg" |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
119 |
! |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
120 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
121 |
codeLocalReturnOn:aStream inBlock:b for:aCompiler |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
122 |
expression isNil ifTrue:[ |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
123 |
aStream nextPut:#retNil. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
124 |
^ self. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
125 |
]. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
126 |
expression |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
127 |
codeForSimpleReturnOn:aStream |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
128 |
inBlock:b |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
129 |
lineNumber:lineNr |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
130 |
for:aCompiler. |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
131 |
! |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
132 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
133 |
codeOn:aStream inBlock:b for:aCompiler |
1982
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
134 |
"/ aCompiler parserFlags allowPossibleSTCCompilationProblems ifFalse:[ |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
135 |
"/ aCompiler |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
136 |
"/ parseError:'stc will not compile return within a return' |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
137 |
"/ line:lineNr. |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
138 |
"/ ] ifTrue:[ |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
139 |
"/ aCompiler parserFlags warnAboutPossibleSTCCompilationProblems ifTrue:[ |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
140 |
"/ aCompiler |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
141 |
"/ warning:'stc will not compile return within a return' |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
142 |
"/ line:lineNr. |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
143 |
"/ ]. |
2098c5e965ce
changed #codeOn:inBlock:for:
Claus Gittinger <cg@exept.de>
parents:
1980
diff
changeset
|
144 |
"/ ]. |
1945
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
145 |
self basicCodeOn:aStream inBlock:b for:aCompiler |
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
146 |
|
5c08a14f6269
warn about stc-uncompilable code
Claus Gittinger <cg@exept.de>
parents:
1726
diff
changeset
|
147 |
"Modified: / 16-11-2006 / 14:34:15 / cg" |
0 | 148 |
! ! |
149 |
||
1035 | 150 |
!ReturnNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
151 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
152 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
153 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
154 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
155 |
^ anEnumerator doReturn:self value:expression |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
156 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
157 |
"Modified: 19.6.1997 / 16:42:40 / cg" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
158 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
159 |
|
1035 | 160 |
!ReturnNode methodsFor:'evaluation'! |
140 | 161 |
|
1383 | 162 |
evaluateExpressionIn:anEnvironment |
140 | 163 |
|val| |
164 |
||
1594 | 165 |
expression notNil ifTrue:[ |
166 |
val := expression evaluateIn:anEnvironment. |
|
167 |
]. |
|
140 | 168 |
myHome exitWith:val. |
169 |
"when we arrive here, the parser context is already gone |
|
170 |
- try block-return" |
|
171 |
blockHome notNil ifTrue:[blockHome exitWith:val]. |
|
172 |
"well - what else can be done" |
|
173 |
^ val |
|
174 |
! ! |
|
175 |
||
1080 | 176 |
!ReturnNode methodsFor:'printing & storing'! |
0 | 177 |
|
178 |
printOn:aStream indent:i |
|
179 |
aStream nextPutAll:'^ '. |
|
180 |
expression printOn:aStream |
|
181 |
! ! |
|
140 | 182 |
|
183 |
!ReturnNode methodsFor:'queries'! |
|
184 |
||
185 |
isConstant |
|
186 |
^ false |
|
187 |
! |
|
188 |
||
2397
6aea7415db4f
added: #isJavaScriptReturnNode
Claus Gittinger <cg@exept.de>
parents:
2101
diff
changeset
|
189 |
isJavaScriptReturnNode |
6aea7415db4f
added: #isJavaScriptReturnNode
Claus Gittinger <cg@exept.de>
parents:
2101
diff
changeset
|
190 |
^ false |
6aea7415db4f
added: #isJavaScriptReturnNode
Claus Gittinger <cg@exept.de>
parents:
2101
diff
changeset
|
191 |
|
6aea7415db4f
added: #isJavaScriptReturnNode
Claus Gittinger <cg@exept.de>
parents:
2101
diff
changeset
|
192 |
"Created: / 19-05-2010 / 15:14:46 / cg" |
6aea7415db4f
added: #isJavaScriptReturnNode
Claus Gittinger <cg@exept.de>
parents:
2101
diff
changeset
|
193 |
! |
6aea7415db4f
added: #isJavaScriptReturnNode
Claus Gittinger <cg@exept.de>
parents:
2101
diff
changeset
|
194 |
|
140 | 195 |
isReturnNode |
196 |
^ true |
|
2101 | 197 |
! |
198 |
||
199 |
isSimpleConstant |
|
200 |
^ false |
|
201 |
! |
|
202 |
||
203 |
isSimpleExpression |
|
204 |
^ false |
|
205 |
! |
|
206 |
||
207 |
isSimpleVariable |
|
208 |
^ false |
|
140 | 209 |
! ! |
210 |
||
148 | 211 |
!ReturnNode class methodsFor:'documentation'! |
212 |
||
213 |
version |
|
2398
f4fb7f5746dd
care for block vs. method return.
Claus Gittinger <cg@exept.de>
parents:
2397
diff
changeset
|
214 |
^ '$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.40 2010-05-19 14:00:21 cg Exp $' |
2397
6aea7415db4f
added: #isJavaScriptReturnNode
Claus Gittinger <cg@exept.de>
parents:
2101
diff
changeset
|
215 |
! |
6aea7415db4f
added: #isJavaScriptReturnNode
Claus Gittinger <cg@exept.de>
parents:
2101
diff
changeset
|
216 |
|
6aea7415db4f
added: #isJavaScriptReturnNode
Claus Gittinger <cg@exept.de>
parents:
2101
diff
changeset
|
217 |
version_CVS |
2398
f4fb7f5746dd
care for block vs. method return.
Claus Gittinger <cg@exept.de>
parents:
2397
diff
changeset
|
218 |
^ '$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.40 2010-05-19 14:00:21 cg Exp $' |
148 | 219 |
! ! |