ReturnNode.st
changeset 843 522c116f86d9
parent 817 8de90dbed4bb
child 882 0bc2a6ecdfad
equal deleted inserted replaced
842:b1184649edb3 843:522c116f86d9
    44 ! !
    44 ! !
    45 
    45 
    46 !ReturnNode class methodsFor:'code generation helper'!
    46 !ReturnNode class methodsFor:'code generation helper'!
    47 
    47 
    48 codeSimpleReturnFor:expression inBlock:b on:aStream inLine:lineNrOrNil for:aCompiler
    48 codeSimpleReturnFor:expression inBlock:b on:aStream inLine:lineNrOrNil for:aCompiler
    49     |type value index code code2|
    49     "/ let expression decide how to do it efficiently.
    50 
    50     expression
    51     expression isPrimary ifTrue:[
    51         codeForSimpleReturnOn:aStream 
    52         type := expression type.
    52         inBlock:b 
    53         (type == #Nil) ifTrue:[
    53         lineNumber:lineNrOrNil 
    54             code := #retNil
    54         for:aCompiler
    55         ] ifFalse:[
       
    56             (type == #True) ifTrue:[
       
    57                 code := #retTrue
       
    58             ] ifFalse:[
       
    59                 (type == #False) ifTrue:[
       
    60                     code := #retFalse
       
    61                 ] ifFalse:[
       
    62                     (type == #Self) ifTrue:[
       
    63                         code := #retSelf
       
    64                     ] ifFalse:[
       
    65                         (type == #Integer) ifTrue:[
       
    66                             value := expression evaluate.
       
    67                             (value between: -128 and:127) ifTrue:[
       
    68                                 (value == 0) ifTrue:[
       
    69                                     code := #ret0
       
    70                                 ] ifFalse:[
       
    71                                     code := #retNum.
       
    72                                     code2 := value. 
       
    73                                 ]
       
    74                             ]
       
    75                         ] ifFalse:[
       
    76                             (type == #InstanceVariable) ifTrue:[
       
    77                                 index := expression index.
       
    78                                 (index <= 8) ifTrue:[
       
    79                                     code := #( retInstVar1
       
    80                                                retInstVar2
       
    81                                                retInstVar3
       
    82                                                retInstVar4
       
    83                                                retInstVar5
       
    84                                                retInstVar6
       
    85                                                retInstVar7
       
    86                                                retInstVar8) at:index
       
    87                                 ]
       
    88                             ] ifFalse:[
       
    89                                 (type == #MethodVariable) ifTrue:[
       
    90                                     index := expression index.
       
    91                                     (index <= 6) ifTrue:[
       
    92                                         code := #( retMethodVar1
       
    93                                                    retMethodVar2
       
    94                                                    retMethodVar3
       
    95                                                    retMethodVar4
       
    96                                                    retMethodVar5
       
    97                                                    retMethodVar6) at:index
       
    98                                     ]
       
    99                                 ] ifFalse:[
       
   100                                     (type == #MethodArg) ifTrue:[
       
   101                                         index := expression index.
       
   102                                         (index <= 2) ifTrue:[
       
   103                                             code := #(retMethodArg1
       
   104                                                       retMethodArg2) at:index
       
   105                                         ]
       
   106                                     ]
       
   107                                 ]
       
   108                             ]
       
   109                         ]
       
   110                     ]
       
   111                 ]
       
   112             ]
       
   113         ]
       
   114     ].
       
   115 
       
   116     code isNil ifTrue:[
       
   117         expression codeOn:aStream inBlock:b for:aCompiler.
       
   118         code := #retTop
       
   119     ].
       
   120 
       
   121     lineNrOrNil notNil ifTrue:[
       
   122         self codeLineNumber:lineNrOrNil on:aStream for:aCompiler
       
   123     ].
       
   124 
       
   125     aStream nextPut:code.
       
   126     code2 notNil ifTrue:[
       
   127         aStream nextPut:code2
       
   128     ].
       
   129 
    55 
   130     "Created: 21.10.1996 / 14:37:35 / cg"
    56     "Created: 21.10.1996 / 14:37:35 / cg"
   131     "Modified: 21.10.1996 / 14:43:11 / cg"
    57     "Modified: 21.10.1996 / 14:43:11 / cg"
   132 ! !
    58 ! !
   133 
    59 
   209 ! !
   135 ! !
   210 
   136 
   211 !ReturnNode class methodsFor:'documentation'!
   137 !ReturnNode class methodsFor:'documentation'!
   212 
   138 
   213 version
   139 version
   214     ^ '$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.21 1999-02-25 14:49:00 cg Exp $'
   140     ^ '$Header: /cvs/stx/stx/libcomp/ReturnNode.st,v 1.22 1999-04-24 21:38:55 cg Exp $'
   215 ! !
   141 ! !