ReturnNode.st
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--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     1
"
4
f6fd83437415 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
62
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
     3
	      All Rights Reserved
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     4
7ad01559b262 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
7ad01559b262 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
7ad01559b262 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
7ad01559b262 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
7ad01559b262 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
7ad01559b262 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    11
"
7ad01559b262 Initial revision
claus
parents:
diff changeset
    12
1080
bd3f19f6009a category change
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    13
"{ Package: 'stx:libcomp' }"
bd3f19f6009a category change
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    14
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    15
StatementNode subclass:#ReturnNode
393
5dc3fdd2177b moved lineNr instVar up
Claus Gittinger <cg@exept.de>
parents: 380
diff changeset
    16
	instanceVariableNames:'myHome blockHome'
261
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    17
	classVariableNames:''
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    18
	poolDictionaries:''
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    19
	category:'System-Compiler-Support'
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    20
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    21
20
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    22
!ReturnNode class methodsFor:'documentation'!
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    23
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    24
copyright
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    25
"
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    26
 COPYRIGHT (c) 1989 by Claus Gittinger
62
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
    27
	      All Rights Reserved
20
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    28
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    29
 This software is furnished under a license and may be used
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    30
 only in accordance with the terms of that license and with the
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    32
 be provided or otherwise made available to, or used by, any
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    33
 other person.  No title to or ownership of the software is
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    34
 hereby transferred.
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    35
"
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    36
!
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    37
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    38
documentation
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    39
"
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    40
    node for parse-trees, representing return expressions
261
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    41
    This is a helper class for the compiler.
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    42
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    43
    [author:]
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    44
        Claus Gittinger
20
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    45
"
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    46
! !
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    47
7ad01559b262 Initial revision
claus
parents:
diff changeset
    48
!ReturnNode methodsFor:'accessing'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    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
7ad01559b262 Initial revision
claus
parents:
diff changeset
    60
home:someOne blockHome:aBlockNode
7ad01559b262 Initial revision
claus
parents:
diff changeset
    61
    myHome := someOne.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    62
    blockHome := aBlockNode
7ad01559b262 Initial revision
claus
parents:
diff changeset
    63
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
    64
7ad01559b262 Initial revision
claus
parents:
diff changeset
    65
!ReturnNode methodsFor:'code generation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    66
104
claus
parents: 103
diff changeset
    67
codeForSideEffectOn:aStream inBlock:b for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    68
    "redefined - drop not needed since notreached"
7ad01559b262 Initial revision
claus
parents:
diff changeset
    69
104
claus
parents: 103
diff changeset
    70
    ^ self codeOn:aStream inBlock:b for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    71
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    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
claus
parents: 103
diff changeset
    82
codeOn:aStream inBlock:b for:aCompiler
380
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    83
    b isNil ifTrue:[
1381
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    84
        expression isNil ifTrue:[
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    85
            aStream nextPut:#retNil.
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    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
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    92
        ].
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    93
        ^ self.
29
5884a68a6226 new return bytecode semantics
claus
parents: 20
diff changeset
    94
    ].
5884a68a6226 new return bytecode semantics
claus
parents: 20
diff changeset
    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
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    97
    expression codeOn:aStream inBlock:b for:aCompiler.
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    98
374
84e2a53ae12b optionally code the lineNr.
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
    99
    lineNr notNil ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   100
        self codeLineNumber:lineNr on:aStream for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   101
    ].
374
84e2a53ae12b optionally code the lineNr.
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   102
380
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
   103
    aStream nextPut:#homeRetTop.
374
84e2a53ae12b optionally code the lineNr.
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   104
380
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
   105
    "Modified: 21.10.1996 / 14:54:36 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   106
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   107
1035
8848672cb893 category rename
Claus Gittinger <cg@exept.de>
parents: 882
diff changeset
   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
8848672cb893 category rename
Claus Gittinger <cg@exept.de>
parents: 882
diff changeset
   118
!ReturnNode methodsFor:'evaluation'!
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   119
1383
3d485eefbb36 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
   120
evaluateExpressionIn:anEnvironment
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   121
    |val|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   122
1383
3d485eefbb36 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
   123
    val := expression evaluateIn:anEnvironment.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   124
    myHome exitWith:val.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   125
    "when we arrive here, the parser context is already gone
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   126
     - try block-return"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   127
    blockHome notNil ifTrue:[blockHome exitWith:val].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   128
    "well - what else can be done"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   129
    ^ val
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   130
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   131
1080
bd3f19f6009a category change
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   132
!ReturnNode methodsFor:'printing & storing'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   133
7ad01559b262 Initial revision
claus
parents:
diff changeset
   134
printOn:aStream indent:i
7ad01559b262 Initial revision
claus
parents:
diff changeset
   135
    aStream nextPutAll:'^ '.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   136
    expression printOn:aStream
7ad01559b262 Initial revision
claus
parents:
diff changeset
   137
! !
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   138
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   139
!ReturnNode methodsFor:'queries'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   141
isConstant
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   142
    ^ false
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   143
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   144
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   145
isReturnNode
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   146
    ^ true
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   147
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   148
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   149
!ReturnNode class methodsFor:'documentation'!
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   150
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   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
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   153
! !