| 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 // TODO(srdjan): fix limitations. | 5 // TODO(srdjan): fix limitations. |
| 6 // - shift amount must be a Smi. | 6 // - shift amount must be a Smi. |
| 7 class _IntegerImplementation { | 7 class _IntegerImplementation { |
| 8 factory _IntegerImplementation._uninstantiable() { | 8 factory _IntegerImplementation._uninstantiable() { |
| 9 throw new UnsupportedError( | 9 throw new UnsupportedError( |
| 10 "_IntegerImplementation can only be allocated by the VM"); | 10 "_IntegerImplementation can only be allocated by the VM"); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 } | 224 } |
| 225 int get hashCode { | 225 int get hashCode { |
| 226 return this; | 226 return this; |
| 227 } | 227 } |
| 228 int operator ~() native "Smi_bitNegate"; | 228 int operator ~() native "Smi_bitNegate"; |
| 229 int get bitLength native "Smi_bitLength"; | 229 int get bitLength native "Smi_bitLength"; |
| 230 | 230 |
| 231 int _shrFromInt(int other) native "Smi_shrFromInt"; | 231 int _shrFromInt(int other) native "Smi_shrFromInt"; |
| 232 int _shlFromInt(int other) native "Smi_shlFromInt"; | 232 int _shlFromInt(int other) native "Smi_shlFromInt"; |
| 233 | 233 |
| 234 String toString() { | 234 String toString() native "Smi_toString"; |
| 235 if (this == 0) return "0"; | |
| 236 var reversed = new List(); | |
| 237 var val = this < 0 ? -this : this; | |
| 238 while (val > 0) { | |
| 239 reversed.add((val % 10) + 0x30); | |
| 240 val = val ~/ 10; | |
| 241 } | |
| 242 final int numDigits = reversed.length; | |
| 243 List digits; | |
| 244 int i; | |
| 245 if (this < 0) { | |
| 246 digits = new List(numDigits + 1); | |
| 247 digits[0] = 0x2D; // '-'. | |
| 248 i = 1; | |
| 249 } else { | |
| 250 digits = new List(numDigits); | |
| 251 i = 0; | |
| 252 } | |
| 253 int ri = reversed.length - 1; | |
| 254 for (; i < digits.length; i++, ri--) { | |
| 255 digits[i] = reversed[ri]; | |
| 256 } | |
| 257 return _StringBase.createFromCharCodes(digits); | |
| 258 } | |
| 259 } | 235 } |
| 260 | 236 |
| 261 // Represents integers that cannot be represented by Smi but fit into 64bits. | 237 // Represents integers that cannot be represented by Smi but fit into 64bits. |
| 262 class _Mint extends _IntegerImplementation implements int { | 238 class _Mint extends _IntegerImplementation implements int { |
| 263 factory _Mint._uninstantiable() { | 239 factory _Mint._uninstantiable() { |
| 264 throw new UnsupportedError( | 240 throw new UnsupportedError( |
| 265 "_Mint can only be allocated by the VM"); | 241 "_Mint can only be allocated by the VM"); |
| 266 } | 242 } |
| 267 int get hashCode { | 243 int get hashCode { |
| 268 return this; | 244 return this; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 } else { | 277 } else { |
| 302 return 0; | 278 return 0; |
| 303 } | 279 } |
| 304 } | 280 } |
| 305 int _shlFromInt(int other) native "Bigint_shlFromInt"; | 281 int _shlFromInt(int other) native "Bigint_shlFromInt"; |
| 306 | 282 |
| 307 int pow(int exponent) { | 283 int pow(int exponent) { |
| 308 throw "Bigint.pow not implemented"; | 284 throw "Bigint.pow not implemented"; |
| 309 } | 285 } |
| 310 } | 286 } |
| OLD | NEW |