ReturnNode.st
author Claus Gittinger <cg@exept.de>
Tue, 29 Oct 2002 10:39:37 +0100
changeset 1322 da25e31f423c
parent 1114 9f897a9a872b
child 1381 695fa03a5795
permissions -rw-r--r--
autodefine workspace variables
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:[
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    89
        ^ self class
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    90
            codeSimpleReturnFor:expression 
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    91
            inBlock:nil 
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    92
            on:aStream 
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    93
            inLine:lineNr 
6bfa4056f202 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 374
diff changeset
    94
            for:aCompiler
29
5884a68a6226 new return bytecode semantics
claus
parents: 20
diff changeset
    95
    ].
5884a68a6226 new return bytecode semantics
claus
parents: 20
diff changeset
    96
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
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   120
evaluateExpression
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
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   123
    val := expression evaluate.
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
1114
9f897a9a872b category rename.
Claus Gittinger <cg@exept.de>
parents: 1080
diff changeset
   152
    ^ '$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.26 2000-11-21 20:22:32 cg Exp $'
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   153
! !