| 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 // This marker interface represents 64-bit integers in the compiler for type | 
|  | 6 // propagation and range analysis.  It is implemented by _Smi and _Mint. | 
|  | 7 abstract class _int64 implements int {} | 
|  | 8 | 
| 5 abstract class _IntegerImplementation { | 9 abstract class _IntegerImplementation { | 
| 6   // The Dart class _Bigint extending _IntegerImplementation requires a | 10   // The Dart class _Bigint extending _IntegerImplementation requires a | 
| 7   // default constructor. | 11   // default constructor. | 
| 8 | 12 | 
| 9   num operator +(num other) { | 13   num operator +(num other) { | 
| 10     var result = other._addFromInteger(this); | 14     var result = other._addFromInteger(this); | 
| 11     if (result != null) return result; | 15     if (result != null) return result; | 
| 12     return other._toBigint()._addFromInteger(this); | 16     return other._toBigint()._addFromInteger(this); | 
| 13   } | 17   } | 
| 14 | 18 | 
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 447     if (x == 0) return y; | 451     if (x == 0) return y; | 
| 448     if (y == 0) return x; | 452     if (y == 0) return x; | 
| 449     if ((x == 1) || (y == 1)) return 1; | 453     if ((x == 1) || (y == 1)) return 1; | 
| 450     if (y is _Bigint) { | 454     if (y is _Bigint) { | 
| 451       return x._toBigint().gcd(y); | 455       return x._toBigint().gcd(y); | 
| 452     } | 456     } | 
| 453     return _binaryGcd(x, y, false); | 457     return _binaryGcd(x, y, false); | 
| 454   } | 458   } | 
| 455 } | 459 } | 
| 456 | 460 | 
| 457 class _Smi extends _IntegerImplementation implements int { | 461 class _Smi extends _IntegerImplementation implements int, _int64 { | 
| 458   factory _Smi._uninstantiable() { | 462   factory _Smi._uninstantiable() { | 
| 459     throw new UnsupportedError("_Smi can only be allocated by the VM"); | 463     throw new UnsupportedError("_Smi can only be allocated by the VM"); | 
| 460   } | 464   } | 
| 461   int get hashCode => this; | 465   int get hashCode => this; | 
| 462   int get _identityHashCode => this; | 466   int get _identityHashCode => this; | 
| 463   int operator ~() native "Smi_bitNegate"; | 467   int operator ~() native "Smi_bitNegate"; | 
| 464   int get bitLength native "Smi_bitLength"; | 468   int get bitLength native "Smi_bitLength"; | 
| 465 | 469 | 
| 466   int operator &(int other) => other._bitAndFromSmi(this); | 470   int operator &(int other) => other._bitAndFromSmi(this); | 
| 467 | 471 | 
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 647       // No remainder necessary for this case. | 651       // No remainder necessary for this case. | 
| 648       int digitIndex = -negSmi * 2; | 652       int digitIndex = -negSmi * 2; | 
| 649       result._setAt(index, _digitTable[digitIndex + 1]); | 653       result._setAt(index, _digitTable[digitIndex + 1]); | 
| 650       result._setAt(index - 1, _digitTable[digitIndex]); | 654       result._setAt(index - 1, _digitTable[digitIndex]); | 
| 651     } | 655     } | 
| 652     return result; | 656     return result; | 
| 653   } | 657   } | 
| 654 } | 658 } | 
| 655 | 659 | 
| 656 // Represents integers that cannot be represented by Smi but fit into 64bits. | 660 // Represents integers that cannot be represented by Smi but fit into 64bits. | 
| 657 class _Mint extends _IntegerImplementation implements int { | 661 class _Mint extends _IntegerImplementation implements int, _int64 { | 
| 658   factory _Mint._uninstantiable() { | 662   factory _Mint._uninstantiable() { | 
| 659     throw new UnsupportedError("_Mint can only be allocated by the VM"); | 663     throw new UnsupportedError("_Mint can only be allocated by the VM"); | 
| 660   } | 664   } | 
| 661   int get hashCode => this; | 665   int get hashCode => this; | 
| 662   int get _identityHashCode => this; | 666   int get _identityHashCode => this; | 
| 663   int operator ~() native "Mint_bitNegate"; | 667   int operator ~() native "Mint_bitNegate"; | 
| 664   int get bitLength native "Mint_bitLength"; | 668   int get bitLength native "Mint_bitLength"; | 
| 665 | 669 | 
| 666   int _bitAndFromSmi(int other) => _bitAndFromInteger(other); | 670   int _bitAndFromSmi(int other) => _bitAndFromInteger(other); | 
| 667 | 671 | 
| 668   // Shift by mint exceeds range that can be handled by the VM. | 672   // Shift by mint exceeds range that can be handled by the VM. | 
| 669   int _shrFromInt(int other) { | 673   int _shrFromInt(int other) { | 
| 670     if (other < 0) { | 674     if (other < 0) { | 
| 671       return -1; | 675       return -1; | 
| 672     } else { | 676     } else { | 
| 673       return 0; | 677       return 0; | 
| 674     } | 678     } | 
| 675   } | 679   } | 
| 676 | 680 | 
| 677   int _shlFromInt(int other) native "Mint_shlFromInt"; | 681   int _shlFromInt(int other) native "Mint_shlFromInt"; | 
| 678 } | 682 } | 
| OLD | NEW | 
|---|