UnaryNode.st
changeset 11 60691e5007e3
parent 4 f6fd83437415
child 13 30e69e21d1d1
equal deleted inserted replaced
10:73e97b6175c4 11:60691e5007e3
    20 UnaryNode comment:'
    20 UnaryNode comment:'
    21 
    21 
    22 COPYRIGHT (c) 1989 by Claus Gittinger
    22 COPYRIGHT (c) 1989 by Claus Gittinger
    23               All Rights Reserved
    23               All Rights Reserved
    24 
    24 
    25 $Header: /cvs/stx/stx/libcomp/UnaryNode.st,v 1.3 1993-10-13 02:41:50 claus Exp $
    25 $Header: /cvs/stx/stx/libcomp/UnaryNode.st,v 1.4 1994-01-09 21:30:25 claus Exp $
    26 '!
    26 '!
    27 
    27 
    28 !UnaryNode class methodsFor:'instance creation'!
    28 !UnaryNode class methodsFor:'instance creation'!
    29 
    29 
    30 receiver:r selector:s
    30 receiver:r selector:s
       
    31     "return a new UnaryNode for sending selector s to receiver r.
       
    32      Fold constants."
       
    33 
    31     ^ self receiver:r selector:s fold:true
    34     ^ self receiver:r selector:s fold:true
    32 !
    35 !
    33 
    36 
    34 receiver:r selector:s fold:folding
    37 receiver:r selector:s fold:folding
       
    38     "return a new UnaryNode for sending selector s to receiver r.
       
    39      If folding is true, fold constant expressions."
       
    40 
    35     |result recVal sym|
    41     |result recVal sym|
    36 
    42 
    37 "
    43 "
    38     The constant folding code can usually not optimize things - this may change
    44     The constant folding code can usually not optimize things - this may change
    39     when some kind of constant declaration is added to smalltalk.
    45     when some kind of constant declaration is added to smalltalk.
    92 ! !
    98 ! !
    93 
    99 
    94 !UnaryNode methodsFor:'queries'!
   100 !UnaryNode methodsFor:'queries'!
    95 
   101 
    96 isUnaryMessage
   102 isUnaryMessage
       
   103     "return true, if this node is one for a unary message"
    97     ^ true
   104     ^ true
    98 ! !
   105 ! !
    99 
   106 
   100 !UnaryNode methodsFor:'checks'!
   107 !UnaryNode methodsFor:'checks'!
   101 
   108 
   115 ! !
   122 ! !
   116 
   123 
   117 !UnaryNode methodsFor:'evaluating'!
   124 !UnaryNode methodsFor:'evaluating'!
   118 
   125 
   119 evaluate
   126 evaluate
       
   127     "evaluate the expression represented by the receiver"
       
   128 
   120     ^ (receiver evaluate) perform:selector
   129     ^ (receiver evaluate) perform:selector
   121 ! !
   130 ! !
   122 
   131 
   123 !UnaryNode methodsFor:'code generation'!
   132 !UnaryNode methodsFor:'code generation'!
   124 
   133 
   125 codeOn:aStream inBlock:b
   134 codeOn:aStream inBlock:b
   126     "optimize 
   135     "append bytecode for the receiver to aStream."
       
   136 
       
   137     "
       
   138      optimize 
   127         (a == b) not -> (a ~~ b)
   139         (a == b) not -> (a ~~ b)
   128         (a ~~ b) not -> (a == b)
   140         (a ~~ b) not -> (a == b)
   129     "
   141     "
   130     (selector == #not) ifTrue:[
   142     (selector == #not) ifTrue:[
   131         (receiver class == BinaryNode) ifTrue:[
   143         (receiver class == BinaryNode) ifTrue:[
   148 ! !
   160 ! !
   149 
   161 
   150 !UnaryNode methodsFor:'printing'!
   162 !UnaryNode methodsFor:'printing'!
   151 
   163 
   152 printOn:aStream indent:i
   164 printOn:aStream indent:i
       
   165     "prettyprint the expression represented by the receiver"
       
   166 
   153     |needParen|
   167     |needParen|
   154 
   168 
   155     needParen := false.
   169     needParen := false.
   156     receiver isMessage ifTrue:[
   170     receiver isMessage ifTrue:[
   157         receiver isUnaryMessage ifFalse:[
   171         receiver isUnaryMessage ifFalse:[