ReturnNode.st
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--
evaluate -> evaluateIn:
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
1114
9f897a9a872b category rename.
Claus Gittinger <cg@exept.de>
parents: 1080
diff changeset
    48
!ReturnNode class methodsFor:'code generation helpers'!
380
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    49
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    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
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    57
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    58
    "Created: 21.10.1996 / 14:37:35 / cg"
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    59
    "Modified: 21.10.1996 / 14:43:11 / cg"
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    60
! !
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    61
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    62
!ReturnNode methodsFor:'accessing'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    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
7ad01559b262 Initial revision
claus
parents:
diff changeset
    74
home:someOne blockHome:aBlockNode
7ad01559b262 Initial revision
claus
parents:
diff changeset
    75
    myHome := someOne.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    76
    blockHome := aBlockNode
7ad01559b262 Initial revision
claus
parents:
diff changeset
    77
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
    78
7ad01559b262 Initial revision
claus
parents:
diff changeset
    79
!ReturnNode methodsFor:'code generation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    80
104
claus
parents: 103
diff changeset
    81
codeForSideEffectOn:aStream inBlock:b for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    82
    "redefined - drop not needed since notreached"
7ad01559b262 Initial revision
claus
parents:
diff changeset
    83
104
claus
parents: 103
diff changeset
    84
    ^ self codeOn:aStream inBlock:b for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    85
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    86
104
claus
parents: 103
diff changeset
    87
codeOn:aStream inBlock:b for:aCompiler
380
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    88
    b isNil ifTrue:[
1381
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    89
        expression isNil ifTrue:[
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    90
            aStream nextPut:#retNil.
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    91
        ] ifFalse:[
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    92
            self class
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    93
                codeSimpleReturnFor:expression 
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    94
                inBlock:nil 
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    95
                on:aStream 
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    96
                inLine:lineNr 
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    97
                for:aCompiler.
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    98
        ].
695fa03a5795 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1114
diff changeset
    99
        ^ self.
29
5884a68a6226 new return bytecode semantics
claus
parents: 20
diff changeset
   100
    ].
5884a68a6226 new return bytecode semantics
claus
parents: 20
diff changeset
   101
380
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
   102
    expression codeOn:aStream inBlock:b for:aCompiler.
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
   103
374
84e2a53ae12b optionally code the lineNr.
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   104
    lineNr notNil ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   105
        self codeLineNumber:lineNr on:aStream for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   106
    ].
374
84e2a53ae12b optionally code the lineNr.
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   107
380
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
   108
    aStream nextPut:#homeRetTop.
374
84e2a53ae12b optionally code the lineNr.
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   109
380
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
   110
    "Modified: 21.10.1996 / 14:54:36 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   111
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   112
1035
8848672cb893 category rename
Claus Gittinger <cg@exept.de>
parents: 882
diff changeset
   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
8848672cb893 category rename
Claus Gittinger <cg@exept.de>
parents: 882
diff changeset
   123
!ReturnNode methodsFor:'evaluation'!
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   124
1383
3d485eefbb36 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
   125
evaluateExpressionIn:anEnvironment
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   126
    |val|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   127
1383
3d485eefbb36 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
   128
    val := expression evaluateIn:anEnvironment.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   129
    myHome exitWith:val.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   130
    "when we arrive here, the parser context is already gone
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   131
     - try block-return"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   132
    blockHome notNil ifTrue:[blockHome exitWith:val].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   133
    "well - what else can be done"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   134
    ^ val
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   135
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   136
1080
bd3f19f6009a category change
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   137
!ReturnNode methodsFor:'printing & storing'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   138
7ad01559b262 Initial revision
claus
parents:
diff changeset
   139
printOn:aStream indent:i
7ad01559b262 Initial revision
claus
parents:
diff changeset
   140
    aStream nextPutAll:'^ '.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   141
    expression printOn:aStream
7ad01559b262 Initial revision
claus
parents:
diff changeset
   142
! !
140
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
!ReturnNode methodsFor:'queries'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   145
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   146
isConstant
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   147
    ^ false
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   148
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   149
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   150
isReturnNode
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   151
    ^ true
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   152
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   153
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   154
!ReturnNode class methodsFor:'documentation'!
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   155
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   156
version
1383
3d485eefbb36 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1381
diff changeset
   157
    ^ '$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.28 2003-03-28 14:39:23 cg Exp $'
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   158
! !