ReturnNode.st
author claus
Fri, 11 Aug 1995 18:04:27 +0200
changeset 103 f4a69d7dd387
parent 102 77e4d1119ff2
child 104 2016bfa4cd45
permissions -rw-r--r--
.
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
7ad01559b262 Initial revision
claus
parents:
diff changeset
    13
StatementNode subclass:#ReturnNode
7ad01559b262 Initial revision
claus
parents:
diff changeset
    14
       instanceVariableNames:'myHome blockHome'
7ad01559b262 Initial revision
claus
parents:
diff changeset
    15
       classVariableNames:''
7ad01559b262 Initial revision
claus
parents:
diff changeset
    16
       poolDictionaries:''
7ad01559b262 Initial revision
claus
parents:
diff changeset
    17
       category:'System-Compiler-Support'
7ad01559b262 Initial revision
claus
parents:
diff changeset
    18
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    19
7ad01559b262 Initial revision
claus
parents:
diff changeset
    20
ReturnNode comment:'
4
f6fd83437415 *** empty log message ***
claus
parents: 3
diff changeset
    21
COPYRIGHT (c) 1989 by Claus Gittinger
62
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
    22
	      All Rights Reserved
29
5884a68a6226 new return bytecode semantics
claus
parents: 20
diff changeset
    23
103
claus
parents: 102
diff changeset
    24
$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.10 1995-08-11 16:03:51 claus Exp $
20
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    25
'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    26
20
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    27
!ReturnNode class methodsFor:'documentation'!
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    28
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    29
copyright
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    30
"
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    31
 COPYRIGHT (c) 1989 by Claus Gittinger
62
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
    32
	      All Rights Reserved
20
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    33
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    34
 This software is furnished under a license and may be used
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    35
 only in accordance with the terms of that license and with the
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    36
 inclusion of the above copyright notice.   This software may not
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    37
 be provided or otherwise made available to, or used by, any
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    38
 other person.  No title to or ownership of the software is
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    39
 hereby transferred.
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    40
"
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    41
!
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    42
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    43
version
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    44
"
103
claus
parents: 102
diff changeset
    45
$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.10 1995-08-11 16:03:51 claus Exp $
20
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    46
"
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    47
!
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    48
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    49
documentation
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    50
"
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    51
    node for parse-trees, representing return expressions
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    52
"
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    53
! !
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    54
7ad01559b262 Initial revision
claus
parents:
diff changeset
    55
!ReturnNode methodsFor:'accessing'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    56
7ad01559b262 Initial revision
claus
parents:
diff changeset
    57
home:someOne blockHome:aBlockNode
7ad01559b262 Initial revision
claus
parents:
diff changeset
    58
    myHome := someOne.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    59
    blockHome := aBlockNode
7ad01559b262 Initial revision
claus
parents:
diff changeset
    60
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
    61
13
30e69e21d1d1 *** empty log message ***
claus
parents: 4
diff changeset
    62
!ReturnNode methodsFor:'queries'!
30e69e21d1d1 *** empty log message ***
claus
parents: 4
diff changeset
    63
71
2aac7fbb5be0 *** empty log message ***
claus
parents: 62
diff changeset
    64
isConstant
2aac7fbb5be0 *** empty log message ***
claus
parents: 62
diff changeset
    65
    ^ false
2aac7fbb5be0 *** empty log message ***
claus
parents: 62
diff changeset
    66
!
2aac7fbb5be0 *** empty log message ***
claus
parents: 62
diff changeset
    67
13
30e69e21d1d1 *** empty log message ***
claus
parents: 4
diff changeset
    68
isReturnNode
30e69e21d1d1 *** empty log message ***
claus
parents: 4
diff changeset
    69
    ^ true
30e69e21d1d1 *** empty log message ***
claus
parents: 4
diff changeset
    70
! !
30e69e21d1d1 *** empty log message ***
claus
parents: 4
diff changeset
    71
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    72
!ReturnNode methodsFor:'evaluating'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    73
7ad01559b262 Initial revision
claus
parents:
diff changeset
    74
evaluateExpression
7ad01559b262 Initial revision
claus
parents:
diff changeset
    75
    |val|
7ad01559b262 Initial revision
claus
parents:
diff changeset
    76
7ad01559b262 Initial revision
claus
parents:
diff changeset
    77
    val := expression evaluate.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    78
    myHome exitWith:val.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    79
    "when we arrive here, the parser context is already gone
7ad01559b262 Initial revision
claus
parents:
diff changeset
    80
     - try block-return"
7ad01559b262 Initial revision
claus
parents:
diff changeset
    81
    blockHome notNil ifTrue:[blockHome exitWith:val].
7ad01559b262 Initial revision
claus
parents:
diff changeset
    82
    "well - what else can be done"
7ad01559b262 Initial revision
claus
parents:
diff changeset
    83
    ^ val
7ad01559b262 Initial revision
claus
parents:
diff changeset
    84
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
    85
7ad01559b262 Initial revision
claus
parents:
diff changeset
    86
!ReturnNode methodsFor:'code generation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    87
7ad01559b262 Initial revision
claus
parents:
diff changeset
    88
codeForSideEffectOn:aStream inBlock:b
7ad01559b262 Initial revision
claus
parents:
diff changeset
    89
    "redefined - drop not needed since notreached"
7ad01559b262 Initial revision
claus
parents:
diff changeset
    90
7ad01559b262 Initial revision
claus
parents:
diff changeset
    91
    ^ self codeOn:aStream inBlock:b
7ad01559b262 Initial revision
claus
parents:
diff changeset
    92
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    93
7ad01559b262 Initial revision
claus
parents:
diff changeset
    94
codeOn:aStream inBlock:b
7ad01559b262 Initial revision
claus
parents:
diff changeset
    95
    |type value index|
7ad01559b262 Initial revision
claus
parents:
diff changeset
    96
29
5884a68a6226 new return bytecode semantics
claus
parents: 20
diff changeset
    97
    "/ after 2.10
5884a68a6226 new return bytecode semantics
claus
parents: 20
diff changeset
    98
    b notNil ifTrue:[
62
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
    99
	expression codeOn:aStream inBlock:b.
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   100
	aStream nextPut:#homeRetTop.
29
5884a68a6226 new return bytecode semantics
claus
parents: 20
diff changeset
   101
	^ self
5884a68a6226 new return bytecode semantics
claus
parents: 20
diff changeset
   102
    ].
5884a68a6226 new return bytecode semantics
claus
parents: 20
diff changeset
   103
62
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   104
    expression isPrimary ifTrue:[
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   105
	type := expression type.
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   106
	(type == #Nil) ifTrue:[
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   107
	    aStream nextPut:#retNil. ^ self
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   108
	].
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   109
	(type == #True) ifTrue:[
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   110
	    aStream nextPut:#retTrue. ^ self
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   111
	].
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   112
	(type == #False) ifTrue:[
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   113
	    aStream nextPut:#retFalse. ^ self
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   114
	].
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   115
	(type == #Self) ifTrue:[
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   116
	    aStream nextPut:#retSelf. ^ self
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   117
	].
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   118
	(type == #Integer) ifTrue:[
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   119
	    value := expression evaluate.
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   120
	    (value between: -128 and:127) ifTrue:[
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   121
		(value == 0) ifTrue:[
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   122
		    aStream nextPut:#ret0. ^ self
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   123
		].
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   124
		aStream nextPut:#retNum.
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   125
		aStream nextPut:value. ^ self
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   126
	    ]
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   127
	].
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   128
	(type == #InstanceVariable) ifTrue:[
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   129
	    index := expression index.
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   130
	    (index <= 8) ifTrue:[
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   131
		aStream nextPut:(#(retInstVar1
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   132
				   retInstVar2
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   133
				   retInstVar3
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   134
				   retInstVar4
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   135
				   retInstVar5
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   136
				   retInstVar6
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   137
				   retInstVar7
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   138
				   retInstVar8) at:index). ^ self
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   139
	    ]
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   140
	].
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   141
	(type == #MethodVariable) ifTrue:[
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   142
	    index := expression index.
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   143
	    (index <= 6) ifTrue:[
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   144
		aStream nextPut:(#(retMethodVar1
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   145
				   retMethodVar2
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   146
				   retMethodVar3
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   147
				   retMethodVar4
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   148
				   retMethodVar5
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   149
				   retMethodVar6) at:index). ^ self
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   150
	    ]
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   151
	].
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   152
	(type == #MethodArg) ifTrue:[
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   153
	    index := expression index.
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   154
	    (index <= 2) ifTrue:[
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   155
		aStream nextPut:(#(retMethodArg1
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   156
				   retMethodArg2) at:index). ^ self
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   157
	    ]
a8e1828867a8 *** empty log message ***
claus
parents: 29
diff changeset
   158
	]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   159
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   160
    expression codeOn:aStream inBlock:b.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   161
    aStream nextPut:#retTop
7ad01559b262 Initial revision
claus
parents:
diff changeset
   162
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   163
7ad01559b262 Initial revision
claus
parents:
diff changeset
   164
!ReturnNode methodsFor:'printing'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   165
7ad01559b262 Initial revision
claus
parents:
diff changeset
   166
printOn:aStream indent:i
7ad01559b262 Initial revision
claus
parents:
diff changeset
   167
    aStream nextPutAll:'^ '.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   168
    expression printOn:aStream
7ad01559b262 Initial revision
claus
parents:
diff changeset
   169
! !