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:'' |
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 |