| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library dart2js.constant_system.js; | 5 library dart2js.constant_system.js; |
| 6 | 6 |
| 7 import '../compiler.dart' show Compiler; | 7 import '../compiler.dart' show Compiler; |
| 8 import '../constant_system_dart.dart'; | 8 import '../constant_system_dart.dart'; |
| 9 import '../constants/constant_system.dart'; | 9 import '../constants/constant_system.dart'; |
| 10 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 double leftDouble = leftNum.primitiveValue.toDouble(); | 158 double leftDouble = leftNum.primitiveValue.toDouble(); |
| 159 double rightDouble = rightNum.primitiveValue.toDouble(); | 159 double rightDouble = rightNum.primitiveValue.toDouble(); |
| 160 return new BoolConstantValue(leftDouble == rightDouble); | 160 return new BoolConstantValue(leftDouble == rightDouble); |
| 161 } | 161 } |
| 162 return result; | 162 return result; |
| 163 } | 163 } |
| 164 | 164 |
| 165 apply(left, right) => identical(left, right); | 165 apply(left, right) => identical(left, right); |
| 166 } | 166 } |
| 167 | 167 |
| 168 class JavaScriptRoundOperation implements UnaryOperation { | |
| 169 const JavaScriptRoundOperation(); | |
| 170 String get name => DART_CONSTANT_SYSTEM.round.name; | |
| 171 ConstantValue fold(ConstantValue constant) { | |
| 172 // Be careful to round() only values that do not throw on either the host or | |
| 173 // target platform. | |
| 174 if (constant.isInt) { | |
| 175 IntConstantValue intConstant = constant; | |
| 176 int value = intConstant.primitiveValue; | |
| 177 if (value >= -double.MAX_FINITE && value <= double.MAX_FINITE) { | |
| 178 return JAVA_SCRIPT_CONSTANT_SYSTEM | |
| 179 .convertToJavaScriptConstant(constant); | |
| 180 } | |
| 181 } | |
| 182 if (constant.isDouble) { | |
| 183 DoubleConstantValue doubleConstant = constant; | |
| 184 double value = doubleConstant.primitiveValue; | |
| 185 if (!value.isNaN && value.isFinite) { | |
| 186 return JAVA_SCRIPT_CONSTANT_SYSTEM | |
| 187 .convertToJavaScriptConstant(new IntConstantValue(value.round())); | |
| 188 } | |
| 189 } | |
| 190 return null; | |
| 191 } | |
| 192 } | |
| 193 | |
| 194 /** | 168 /** |
| 195 * Constant system following the semantics for Dart code that has been | 169 * Constant system following the semantics for Dart code that has been |
| 196 * compiled to JavaScript. | 170 * compiled to JavaScript. |
| 197 */ | 171 */ |
| 198 class JavaScriptConstantSystem extends ConstantSystem { | 172 class JavaScriptConstantSystem extends ConstantSystem { |
| 173 final int BITS31 = 0x8FFFFFFF; |
| 199 final int BITS32 = 0xFFFFFFFF; | 174 final int BITS32 = 0xFFFFFFFF; |
| 200 | 175 |
| 201 final add = const JavaScriptAddOperation(); | 176 final add = const JavaScriptAddOperation(); |
| 202 final bitAnd = const JavaScriptBinaryBitOperation(const BitAndOperation()); | 177 final bitAnd = const JavaScriptBinaryBitOperation(const BitAndOperation()); |
| 203 final bitNot = const JavaScriptBitNotOperation(); | 178 final bitNot = const JavaScriptBitNotOperation(); |
| 204 final bitOr = const JavaScriptBinaryBitOperation(const BitOrOperation()); | 179 final bitOr = const JavaScriptBinaryBitOperation(const BitOrOperation()); |
| 205 final bitXor = const JavaScriptBinaryBitOperation(const BitXorOperation()); | 180 final bitXor = const JavaScriptBinaryBitOperation(const BitXorOperation()); |
| 206 final booleanAnd = const BooleanAndOperation(); | 181 final booleanAnd = const BooleanAndOperation(); |
| 207 final booleanOr = const BooleanOrOperation(); | 182 final booleanOr = const BooleanOrOperation(); |
| 208 final divide = | 183 final divide = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 221 final negate = const JavaScriptNegateOperation(); | 196 final negate = const JavaScriptNegateOperation(); |
| 222 final not = const NotOperation(); | 197 final not = const NotOperation(); |
| 223 final shiftLeft = | 198 final shiftLeft = |
| 224 const JavaScriptBinaryBitOperation(const ShiftLeftOperation()); | 199 const JavaScriptBinaryBitOperation(const ShiftLeftOperation()); |
| 225 final shiftRight = const JavaScriptShiftRightOperation(); | 200 final shiftRight = const JavaScriptShiftRightOperation(); |
| 226 final subtract = | 201 final subtract = |
| 227 const JavaScriptBinaryArithmeticOperation(const SubtractOperation()); | 202 const JavaScriptBinaryArithmeticOperation(const SubtractOperation()); |
| 228 final truncatingDivide = const JavaScriptBinaryArithmeticOperation( | 203 final truncatingDivide = const JavaScriptBinaryArithmeticOperation( |
| 229 const TruncatingDivideOperation()); | 204 const TruncatingDivideOperation()); |
| 230 final codeUnitAt = const CodeUnitAtRuntimeOperation(); | 205 final codeUnitAt = const CodeUnitAtRuntimeOperation(); |
| 231 final round = const JavaScriptRoundOperation(); | |
| 232 | 206 |
| 233 const JavaScriptConstantSystem(); | 207 const JavaScriptConstantSystem(); |
| 234 | 208 |
| 235 /** | 209 /** |
| 236 * Returns true if [value] will turn into NaN or infinity | 210 * Returns true if [value] will turn into NaN or infinity |
| 237 * at runtime. | 211 * at runtime. |
| 238 */ | 212 */ |
| 239 bool integerBecomesNanOrInfinity(int value) { | 213 bool integerBecomesNanOrInfinity(int value) { |
| 240 double doubleValue = value.toDouble(); | 214 double doubleValue = value.toDouble(); |
| 241 return doubleValue.isNaN || doubleValue.isInfinite; | 215 return doubleValue.isNaN || doubleValue.isInfinite; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 result.add(keyList); | 400 result.add(keyList); |
| 427 } else { | 401 } else { |
| 428 // Add the keys individually to avoid generating an unused list constant | 402 // Add the keys individually to avoid generating an unused list constant |
| 429 // for the keys. | 403 // for the keys. |
| 430 result.addAll(keys); | 404 result.addAll(keys); |
| 431 } | 405 } |
| 432 result.addAll(values); | 406 result.addAll(values); |
| 433 return result; | 407 return result; |
| 434 } | 408 } |
| 435 } | 409 } |
| OLD | NEW |