author | Claus Gittinger <cg@exept.de> |
Wed, 29 Oct 2003 11:45:21 +0100 | |
changeset 1472 | d69fc5970cd7 |
parent 1403 | 1bc763430b94 |
child 1578 | 1eb1feb57888 |
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 |
|
104 | 82 |
codeOn:aStream inBlock:b for:aCompiler |
380 | 83 |
b isNil ifTrue:[ |
1381 | 84 |
expression isNil ifTrue:[ |
85 |
aStream nextPut:#retNil. |
|
86 |
] ifFalse:[ |
|
1403
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
87 |
expression |
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
88 |
codeForSimpleReturnOn:aStream |
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
89 |
inBlock:b |
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
90 |
lineNumber:lineNr |
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
91 |
for:aCompiler |
1381 | 92 |
]. |
93 |
^ self. |
|
29 | 94 |
]. |
95 |
||
1403
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
96 |
"special: return from homeContext in a block" |
380 | 97 |
expression codeOn:aStream inBlock:b for:aCompiler. |
98 |
||
374 | 99 |
lineNr notNil ifTrue:[ |
817 | 100 |
self codeLineNumber:lineNr on:aStream for:aCompiler |
0 | 101 |
]. |
374 | 102 |
|
380 | 103 |
aStream nextPut:#homeRetTop. |
374 | 104 |
|
380 | 105 |
"Modified: 21.10.1996 / 14:54:36 / cg" |
0 | 106 |
! ! |
107 |
||
1035 | 108 |
!ReturnNode methodsFor:'enumerating'! |
539
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
109 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
110 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
111 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
112 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
113 |
^ anEnumerator doReturn:self value:expression |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
114 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
115 |
"Modified: 19.6.1997 / 16:42:40 / cg" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
116 |
! ! |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
117 |
|
1035 | 118 |
!ReturnNode methodsFor:'evaluation'! |
140 | 119 |
|
1383 | 120 |
evaluateExpressionIn:anEnvironment |
140 | 121 |
|val| |
122 |
||
1383 | 123 |
val := expression evaluateIn:anEnvironment. |
140 | 124 |
myHome exitWith:val. |
125 |
"when we arrive here, the parser context is already gone |
|
126 |
- try block-return" |
|
127 |
blockHome notNil ifTrue:[blockHome exitWith:val]. |
|
128 |
"well - what else can be done" |
|
129 |
^ val |
|
130 |
! ! |
|
131 |
||
1080 | 132 |
!ReturnNode methodsFor:'printing & storing'! |
0 | 133 |
|
134 |
printOn:aStream indent:i |
|
135 |
aStream nextPutAll:'^ '. |
|
136 |
expression printOn:aStream |
|
137 |
! ! |
|
140 | 138 |
|
139 |
!ReturnNode methodsFor:'queries'! |
|
140 |
||
141 |
isConstant |
|
142 |
^ false |
|
143 |
! |
|
144 |
||
145 |
isReturnNode |
|
146 |
^ true |
|
147 |
! ! |
|
148 |
||
148 | 149 |
!ReturnNode class methodsFor:'documentation'! |
150 |
||
151 |
version |
|
1403
1bc763430b94
Save a byte when returning from a block
Stefan Vogel <sv@exept.de>
parents:
1383
diff
changeset
|
152 |
^ '$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.29 2003-04-25 16:52:21 stefan Exp $' |
148 | 153 |
! ! |