UnaryNode.st
changeset 3936 68f3c2d9d417
parent 3333 fb37a7b53ed6
child 4038 11950ee05d24
equal deleted inserted replaced
3935:e5a0b5e13d5d 3936:68f3c2d9d417
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 "{ Package: 'stx:libcomp' }"
    12 "{ Package: 'stx:libcomp' }"
       
    13 
       
    14 "{ NameSpace: Smalltalk }"
    13 
    15 
    14 MessageNode subclass:#UnaryNode
    16 MessageNode subclass:#UnaryNode
    15 	instanceVariableNames:''
    17 	instanceVariableNames:''
    16 	classVariableNames:''
    18 	classVariableNames:''
    17 	poolDictionaries:''
    19 	poolDictionaries:''
    72             "/
    74             "/
    73             "/ do constant folding ...
    75             "/ do constant folding ...
    74             "/ evaluate at compile time:
    76             "/ evaluate at compile time:
    75             "/      Character tab
    77             "/      Character tab
    76             "/      Character cr
    78             "/      Character cr
    77             "/          ... 
    79             "/          ...
    78             "/      Float pi
    80             "/      Float pi
    79             "/      Float e
    81             "/      Float e
    80             "/          ... 
    82             "/          ...
    81             "/      String cr
    83             "/      String cr
    82             "/      String crlf
    84             "/      String crlf
    83             "/          ... 
    85             "/          ...
    84             "/      #(...) asFloatArray
    86             "/      #(...) asFloatArray
    85 
    87 
    86             r isGlobal ifTrue:[
    88             r isGlobal ifTrue:[
    87                 globalName := r name.
    89                 globalName := r name.
    88                 recVal := r evaluate.
    90                 recVal := r evaluate.
   113 "/ no, this 'optimization' is not good -
   115 "/ no, this 'optimization' is not good -
   114 "/ if bytecode is transported to another machine.
   116 "/ if bytecode is transported to another machine.
   115 "/ However, the JIT compiler compensates for this ;-)
   117 "/ However, the JIT compiler compensates for this ;-)
   116 "/                (globalName = 'Smalltalk') ifTrue:[
   118 "/                (globalName = 'Smalltalk') ifTrue:[
   117 "/                    ( #( isSmalltalkX isVisualWorks isSqueak
   119 "/                    ( #( isSmalltalkX isVisualWorks isSqueak
   118 "/                         isSmalltalkMT isDolphinSmalltalk isVisualAge 
   120 "/                         isSmalltalkMT isDolphinSmalltalk isVisualAge
   119 "/                         isSmalltalkV) includes:selector)
   121 "/                         isSmalltalkV) includes:selector)
   120 "/                    ifTrue:[
   122 "/                    ifTrue:[
   121 "/                        (recVal respondsTo:selector) ifTrue:[
   123 "/                        (recVal respondsTo:selector) ifTrue:[
   122 "/                            canFold := true
   124 "/                            canFold := true
   123 "/                        ]
   125 "/                        ]
   142                 recVal := r evaluate.
   144                 recVal := r evaluate.
   143 
   145 
   144                 "
   146                 "
   145                  we could do much more here - but then, we need a dependency from
   147                  we could do much more here - but then, we need a dependency from
   146                  the folded selectors method to the method we generate code for ...
   148                  the folded selectors method to the method we generate code for ...
   147                  limit optimizations to those that will never change 
   149                  limit optimizations to those that will never change
   148                  (or, if you change them, it will crash badly anyway ...)
   150                  (or, if you change them, it will crash badly anyway ...)
   149                 "
   151                 "
   150                 recVal respondsToArithmetic ifTrue:[
   152                 recVal respondsToArithmetic ifTrue:[
   151                     (#( negated abs asPoint degreesToRadians radiansToDegrees
   153                     (#( negated abs asPoint degreesToRadians radiansToDegrees
   152                         exp ln log sqrt reciprocal 
   154                         exp ln log sqrt reciprocal
   153                         arcCos arcSin arcTan sin cos tan) includes:selector)
   155                         arcCos arcSin arcTan sin cos tan) includes:selector)
   154                     ifTrue:[
   156                     ifTrue:[
   155                         canFold := true
   157                         canFold := true
   156                     ]
   158                     ]
   157                 ].
   159                 ].
   158                 recVal isCharacter ifTrue:[
   160                 recVal isCharacter ifTrue:[
   159                     (#( asciiValue asInteger digitValue asString) includes:selector) 
   161                     (#( asciiValue asInteger digitValue asString) includes:selector)
   160                     ifTrue:[
   162                     ifTrue:[
   161                         canFold := true
   163                         canFold := true
   162                     ]
   164                     ]
   163                 ].
   165                 ].
   164                 recVal isString ifTrue:[
   166                 recVal isString ifTrue:[
   192                 ] do:[
   194                 ] do:[
   193                     result := recVal perform:selector.
   195                     result := recVal perform:selector.
   194                     ^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result
   196                     ^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result
   195                 ].
   197                 ].
   196                 "when we reach here, something went wrong (something like 0.0 log)"
   198                 "when we reach here, something went wrong (something like 0.0 log)"
   197                 ^ ParseErrorNode errorString:'error occured while evaluating constant expression'
   199                 ^ ParseErrorNode errorString:'error occurred while evaluating constant expression'
   198             ].
   200             ].
   199         ].
   201         ].
   200     ].
   202     ].
   201 
   203 
   202     ^ (self basicNew) receiver:r selector:selectorString args:nil lineno:0
   204     ^ (self basicNew) receiver:r selector:selectorString args:nil lineno:0
   379 ! !
   381 ! !
   380 
   382 
   381 !UnaryNode class methodsFor:'documentation'!
   383 !UnaryNode class methodsFor:'documentation'!
   382 
   384 
   383 version
   385 version
   384     ^ '$Header: /cvs/stx/stx/libcomp/UnaryNode.st,v 1.60 2013-10-19 23:05:27 vrany Exp $'
   386     ^ '$Header$'
   385 !
   387 !
   386 
   388 
   387 version_CVS
   389 version_CVS
   388     ^ '$Header: /cvs/stx/stx/libcomp/UnaryNode.st,v 1.60 2013-10-19 23:05:27 vrany Exp $'
   390     ^ '$Header$'
   389 ! !
   391 ! !
   390 
   392