author | Claus Gittinger <cg@exept.de> |
Fri, 28 Mar 2003 15:39:23 +0100 | |
changeset 1383 | 3d485eefbb36 |
parent 1381 | 695fa03a5795 |
child 1403 | 1bc763430b94 |
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 |
|
1114 | 48 |
!ReturnNode class methodsFor:'code generation helpers'! |
380 | 49 |
|
50 |
codeSimpleReturnFor:expression inBlock:b on:aStream inLine:lineNrOrNil for:aCompiler |
|
843
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
51 |
"/ let expression decide how to do it efficiently. |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
52 |
expression |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
53 |
codeForSimpleReturnOn:aStream |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
54 |
inBlock:b |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
55 |
lineNumber:lineNrOrNil |
522c116f86d9
boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
56 |
for:aCompiler |
380 | 57 |
|
58 |
"Created: 21.10.1996 / 14:37:35 / cg" |
|
59 |
"Modified: 21.10.1996 / 14:43:11 / cg" |
|
60 |
! ! |
|
61 |
||
0 | 62 |
!ReturnNode methodsFor:'accessing'! |
63 |
||
882
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
64 |
expression:e |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
65 |
super expression:e. |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
66 |
|
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
67 |
"/ 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
|
68 |
e isBlockNode ifTrue:[ |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
69 |
e possiblyInlined:false |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
70 |
] |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
71 |
|
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
72 |
! |
0bc2a6ecdfad
oops - cannot inline blocks which are assigned or returned.
Claus Gittinger <cg@exept.de>
parents:
843
diff
changeset
|
73 |
|
0 | 74 |
home:someOne blockHome:aBlockNode |
75 |
myHome := someOne. |
|
76 |
blockHome := aBlockNode |
|
77 |
! ! |
|
78 |
||
79 |
!ReturnNode methodsFor:'code generation'! |
|
80 |
||
104 | 81 |
codeForSideEffectOn:aStream inBlock:b for:aCompiler |
0 | 82 |
"redefined - drop not needed since notreached" |
83 |
||
104 | 84 |
^ self codeOn:aStream inBlock:b for:aCompiler |
0 | 85 |
! |
86 |
||
104 | 87 |
codeOn:aStream inBlock:b for:aCompiler |
380 | 88 |
b isNil ifTrue:[ |
1381 | 89 |
expression isNil ifTrue:[ |
90 |
aStream nextPut:#retNil. |
|
91 |
] ifFalse:[ |
|
92 |
self class |
|
93 |
codeSimpleReturnFor:expression |
|
94 |
inBlock:nil |
|
95 |
on:aStream |
|
96 |
inLine:lineNr |
|
97 |
for:aCompiler. |
|
98 |
]. |
|
99 |
^ self. |
|
29 | 100 |
]. |
101 |
||
380 | 102 |
expression codeOn:aStream inBlock:b for:aCompiler. |
103 |
||
374 | 104 |
lineNr notNil ifTrue:[ |
817 | 105 |
self codeLineNumber:lineNr on:aStream for:aCompiler |
0 | 106 |
]. |
374 | 107 |
|
380 | 108 |
aStream nextPut:#homeRetTop. |
374 | 109 |
|
380 | 110 |
"Modified: 21.10.1996 / 14:54:36 / cg" |
0 | 111 |
! ! |
112 |
||
1035 | 113 |
!ReturnNode methodsFor:'enumerating'! |
539
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 |
nodeDo:anEnumerator |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
116 |
"helper for parse tree walking" |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
117 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
118 |
^ anEnumerator doReturn:self value:expression |
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
119 |
|
69a1cd05c7d6
added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
393
diff
changeset
|
120 |
"Modified: 19.6.1997 / 16:42:40 / cg" |
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 |
|
1035 | 123 |
!ReturnNode methodsFor:'evaluation'! |
140 | 124 |
|
1383 | 125 |
evaluateExpressionIn:anEnvironment |
140 | 126 |
|val| |
127 |
||
1383 | 128 |
val := expression evaluateIn:anEnvironment. |
140 | 129 |
myHome exitWith:val. |
130 |
"when we arrive here, the parser context is already gone |
|
131 |
- try block-return" |
|
132 |
blockHome notNil ifTrue:[blockHome exitWith:val]. |
|
133 |
"well - what else can be done" |
|
134 |
^ val |
|
135 |
! ! |
|
136 |
||
1080 | 137 |
!ReturnNode methodsFor:'printing & storing'! |
0 | 138 |
|
139 |
printOn:aStream indent:i |
|
140 |
aStream nextPutAll:'^ '. |
|
141 |
expression printOn:aStream |
|
142 |
! ! |
|
140 | 143 |
|
144 |
!ReturnNode methodsFor:'queries'! |
|
145 |
||
146 |
isConstant |
|
147 |
^ false |
|
148 |
! |
|
149 |
||
150 |
isReturnNode |
|
151 |
^ true |
|
152 |
! ! |
|
153 |
||
148 | 154 |
!ReturnNode class methodsFor:'documentation'! |
155 |
||
156 |
version |
|
1383 | 157 |
^ '$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.28 2003-03-28 14:39:23 cg Exp $' |
148 | 158 |
! ! |