MessageNode.st
changeset 1397 969f505b6111
parent 1389 1ab6eba611d3
child 1422 cdee45eb0303
equal deleted inserted replaced
1396:5306bf9b9174 1397:969f505b6111
    66      allowing constant arrays of complex objects.
    66      allowing constant arrays of complex objects.
    67 
    67 
    68      Notice: this method is normally disabled - its just a demo after all.
    68      Notice: this method is normally disabled - its just a demo after all.
    69     "
    69     "
    70     folding notNil ifTrue:[
    70     folding notNil ifTrue:[
    71 	"/
    71         "/
    72 	"/ do constant folding ...
    72         "/ do constant folding ...
    73 	"/
    73         "/
    74 	(recNode isConstant and:[argNode1 isConstant]) ifTrue:[
    74         (recNode isConstant and:[argNode1 isConstant]) ifTrue:[
    75 	    "check if we can do it ..."
    75             "check if we can do it ..."
    76 	    selector := selectorString asSymbolIfInterned.
    76             selector := selectorString asSymbolIfInterned.
    77 	    selector notNil ifTrue:[
    77             selector notNil ifTrue:[
    78 		recVal := recNode evaluate.
    78                 recVal := recNode evaluate.
    79 		(recVal respondsTo:selector) ifTrue:[
    79                 (recVal respondsTo:selector) ifTrue:[
    80 		    "
    80                     "
    81 		     we could do much more here - but then, we need a dependency from
    81                      we could do much more here - but then, we need a dependency from
    82 		     the folded selectors method to the method we generate code for ...
    82                      the folded selectors method to the method we generate code for ...
    83 		     limit optimizations to those that will never change
    83                      limit optimizations to those that will never change
    84 		     (or - if you change them - you will crash so bad ...)
    84                      (or - if you change them - you will crash so bad ...)
    85 		    "
    85                     "
    86 		    argVal := argNode1 evaluate.
    86                     argVal := argNode1 evaluate.
    87 		    ((recVal isMemberOf:Array) and:[argVal isMemberOf:Array]) ifTrue:[
    87                     ((recVal isMemberOf:Array) and:[argVal isMemberOf:Array]) ifTrue:[
    88 			folding == #full ifTrue:[
    88                         folding == #full ifTrue:[
    89 			    (selector == #with:collect:) ifTrue:[
    89                             (selector == #with:collect:) ifTrue:[
    90 				(argNode2 isBlock) ifTrue:[
    90                                 (argNode2 isBlock) ifTrue:[
    91 				    SignalSet anySignal handle:[:ex |
    91                                     SignalSet anySignal handle:[:ex |
    92 					^ 'error in constant expression (' , ex errorString , ')'
    92                                         ^ 'error in constant expression (' , ex description , ')'
    93 				    ] do:[
    93                                     ] do:[
    94 					result := recVal perform:selector with:argVal with:(argNode2 evaluate).
    94                                         result := recVal perform:selector with:argVal with:(argNode2 evaluate).
    95 				    ].
    95                                     ].
    96 				    ^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result
    96                                     ^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result
    97 				]
    97                                 ]
    98 			    ]
    98                             ]
    99 			]
    99                         ]
   100 		    ]
   100                     ]
   101 		]
   101                 ]
   102 	    ]
   102             ]
   103 	]
   103         ]
   104     ].
   104     ].
   105     ^ (self basicNew) receiver:recNode selector:selectorString args:(Array with:argNode1 with:argNode2) lineno:0
   105     ^ (self basicNew) receiver:recNode selector:selectorString args:(Array with:argNode1 with:argNode2) lineno:0
   106 
   106 
   107     "Modified: 28.6.1997 / 15:16:01 / cg"
   107     "Modified: 28.6.1997 / 15:16:01 / cg"
   108 !
   108 !
   187             ].
   187             ].
   188 
   188 
   189             canFold ifTrue:[
   189             canFold ifTrue:[
   190                 (recVal respondsTo:selector) ifTrue:[
   190                 (recVal respondsTo:selector) ifTrue:[
   191                     SignalSet anySignal handle:[:ex |
   191                     SignalSet anySignal handle:[:ex |
   192                         ^ 'error in constant expression (' , ex errorString , ')'
   192                         ^ 'error in constant expression (' , ex description , ')'
   193                     ] do:[
   193                     ] do:[
   194                         result := recVal perform:selector with:argVal.
   194                         result := recVal perform:selector with:argVal.
   195                     ].
   195                     ].
   196                     ^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result
   196                     ^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result
   197                 ]
   197                 ]
  2166 
  2166 
  2167     start := receiver.
  2167     start := receiver.
  2168     stop := (argArray at:1).
  2168     stop := (argArray at:1).
  2169     step := (argArray at:2).
  2169     step := (argArray at:2).
  2170 
  2170 
  2171 "/    stop isConstant ifFalse:[self halt:'should not happen'].
  2171 "/    stop isConstant ifFalse:[self error:'should not happen' mayProceed:true].
  2172 "/    (stop evaluate isMemberOf:SmallInteger) ifFalse:[self halt:'should not happen'].
  2172 "/    (stop evaluate isMemberOf:SmallInteger) ifFalse:[self error:'should not happen' mayProceed:true].
  2173 
  2173 
  2174     step isConstant ifFalse:[self halt:'should not happen'].
  2174     step isConstant ifFalse:[self error:'should not happen' mayProceed:true].
  2175     stepVal := step evaluate.
  2175     stepVal := step evaluate.
  2176     (stepVal isMemberOf:SmallInteger) ifFalse:[self halt:'should not happen'].
  2176     (stepVal isMemberOf:SmallInteger) ifFalse:[
       
  2177         self error:'should not happen' mayProceed:true
       
  2178     ].
  2177 
  2179 
  2178     start codeOn:aStream inBlock:b for:aCompiler.
  2180     start codeOn:aStream inBlock:b for:aCompiler.
  2179 
  2181 
  2180     lateEval := false.
  2182     lateEval := false.
  2181 
  2183 
  3083 ! !
  3085 ! !
  3084 
  3086 
  3085 !MessageNode class methodsFor:'documentation'!
  3087 !MessageNode class methodsFor:'documentation'!
  3086 
  3088 
  3087 version
  3089 version
  3088     ^ '$Header: /cvs/stx/stx/libcomp/MessageNode.st,v 1.129 2003-03-28 18:54:17 cg Exp $'
  3090     ^ '$Header: /cvs/stx/stx/libcomp/MessageNode.st,v 1.130 2003-04-11 17:58:08 stefan Exp $'
  3089 ! !
  3091 ! !