author | Claus Gittinger <cg@exept.de> |
Mon, 09 May 2005 09:15:48 +0200 | |
changeset 1594 | d99ea853d052 |
parent 1593 | 40c32bd334d9 |
child 1726 | 7338ad3dfc05 |
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 |
||
1080 | 13 |
"{ Package: 'stx:libcomp' }" |
14 |
||
0 | 15 |
StatementNode subclass:#ReturnNode |
393 | 16 |
instanceVariableNames:'myHome blockHome' |
261 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
19 |
category:'System-Compiler-Support' |
|
0 | 20 |
! |
21 |
||
20 | 22 |
!ReturnNode class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
62 | 27 |
All Rights Reserved |
20 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
node for parse-trees, representing return expressions |
|
261 | 41 |
This is a helper class for the compiler. |
263 | 42 |
|
43 |
[author:] |
|
44 |
Claus Gittinger |
|
20 | 45 |
" |
46 |
! ! |
|
0 | 47 |
|
48 |
!ReturnNode methodsFor:'accessing'! |
|
49 |
||
882
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
50 |
expression:e |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
51 |
super expression:e. |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
52 |
|
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
53 |
"/ 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
|
54 |
e isBlockNode ifTrue:[ |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
55 |
e possiblyInlined:false |
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 |
! |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
59 |
|
0 | 60 |
home:someOne blockHome:aBlockNode |
61 |
myHome := someOne. |
|
62 |
blockHome := aBlockNode |
|
63 |
! ! |
|
64 |
||
65 |
!ReturnNode methodsFor:'code generation'! |
|
66 |
||
104 | 67 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
0 | 68 |
"redefined - drop not needed since notreached" |
69 |
||
104 | 70 |
^ self codeOn:aStream inBlock:b for:aCompiler |
0 | 71 |
! |
72 |
||
1403
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
73 |
codeForSimpleReturnOn:aStream inBlock:b lineNumber:lineNrOrNil for:aCompiler |
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
74 |
"generate code to return myself as a simple method return" |
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
75 |
|
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
76 |
self codeOn:aStream inBlock:b for:aCompiler. |
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
77 |
|
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
78 |
"as a ReturnNode, I did return, so retTop is not needed" |
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
79 |
"/ aStream nextPut:#retTop. |
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
80 |
! |
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
81 |
|
1593 | 82 |
codeLocalReturnOn:aStream inBlock:b for:aCompiler |
83 |
expression isNil ifTrue:[ |
|
84 |
aStream nextPut:#retNil. |
|
85 |
^ self. |
|
86 |
]. |
|
87 |
expression |
|
88 |
codeForSimpleReturnOn:aStream |
|
89 |
inBlock:b |
|
90 |
lineNumber:lineNr |
|
91 |
for:aCompiler. |
|
92 |
! |
|
93 |
||
104 | 94 |
codeOn:aStream inBlock:b for:aCompiler |
1593 | 95 |
b isNil ifTrue:[ |
96 |
self codeLocalReturnOn:aStream inBlock:b for:aCompiler. |
|
97 |
^ self. |
|
29 | 98 |
]. |
99 |
||
1593 | 100 |
"return from homeContext in a block" |
101 |
expression isNil ifTrue:[ |
|
102 |
"/ nil-expression is not possible in smalltalk; |
|
103 |
"/ however, it might be in a subclass (i.e. JavaScript) |
|
104 |
aStream nextPut:#pushNil. |
|
105 |
] ifFalse:[ |
|
106 |
expression codeOn:aStream inBlock:b for:aCompiler. |
|
107 |
]. |
|
374 | 108 |
lineNr notNil ifTrue:[ |
817 | 109 |
self codeLineNumber:lineNr on:aStream for:aCompiler |
0 | 110 |
]. |
374 | 111 |
|
380 | 112 |
aStream nextPut:#homeRetTop. |
374 | 113 |
|
380 | 114 |
"Modified: 21.10.1996 / 14:54:36 / cg" |
0 | 115 |
! ! |
116 |
||
1035 | 117 |
!ReturnNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
118 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
119 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
120 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
121 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
122 |
^ anEnumerator doReturn:self value:expression |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
123 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
124 |
"Modified: 19.6.1997 / 16:42:40 / cg" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
125 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
126 |
|
1035 | 127 |
!ReturnNode methodsFor:'evaluation'! |
140 | 128 |
|
1383 | 129 |
evaluateExpressionIn:anEnvironment |
140 | 130 |
|val| |
131 |
||
1594 | 132 |
expression notNil ifTrue:[ |
133 |
val := expression evaluateIn:anEnvironment. |
|
134 |
]. |
|
140 | 135 |
myHome exitWith:val. |
136 |
"when we arrive here, the parser context is already gone |
|
137 |
- try block-return" |
|
138 |
blockHome notNil ifTrue:[blockHome exitWith:val]. |
|
139 |
"well - what else can be done" |
|
140 |
^ val |
|
141 |
! ! |
|
142 |
||
1080 | 143 |
!ReturnNode methodsFor:'printing & storing'! |
0 | 144 |
|
145 |
printOn:aStream indent:i |
|
146 |
aStream nextPutAll:'^ '. |
|
147 |
expression printOn:aStream |
|
148 |
! ! |
|
140 | 149 |
|
150 |
!ReturnNode methodsFor:'queries'! |
|
151 |
||
152 |
isConstant |
|
153 |
^ false |
|
154 |
! |
|
155 |
||
156 |
isReturnNode |
|
157 |
^ true |
|
158 |
! ! |
|
159 |
||
148 | 160 |
!ReturnNode class methodsFor:'documentation'! |
161 |
||
162 |
version |
|
1594 | 163 |
^ '$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.33 2005-05-09 07:15:48 cg Exp $' |
148 | 164 |
! ! |