| 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 const UnsupportedOperationException( | 9 throw new UnsupportedError( |
| 10 "_IntegerImplementation can only be allocated by the VM"); | 10 "_IntegerImplementation can only be allocated by the VM"); |
| 11 } | 11 } |
| 12 num operator +(num other) { | 12 num operator +(num other) { |
| 13 return other._addFromInteger(this); | 13 return other._addFromInteger(this); |
| 14 } | 14 } |
| 15 num operator -(num other) { | 15 num operator -(num other) { |
| 16 return other._subFromInteger(this); | 16 return other._subFromInteger(this); |
| 17 } | 17 } |
| 18 num operator *(num other) { | 18 num operator *(num other) { |
| 19 return other._mulFromInteger(this); | 19 return other._mulFromInteger(this); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 if (isNegative) buffer.add("-"); | 175 if (isNegative) buffer.add("-"); |
| 176 for (int i = temp.length - 1; i >= 0; i--) { | 176 for (int i = temp.length - 1; i >= 0; i--) { |
| 177 buffer.add(table[temp[i]]); | 177 buffer.add(table[temp[i]]); |
| 178 } | 178 } |
| 179 return buffer.toString(); | 179 return buffer.toString(); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 class _Smi extends _IntegerImplementation implements int { | 183 class _Smi extends _IntegerImplementation implements int { |
| 184 factory _Smi._uninstantiable() { | 184 factory _Smi._uninstantiable() { |
| 185 throw const UnsupportedOperationException( | 185 throw new UnsupportedError( |
| 186 "_Smi can only be allocated by the VM"); | 186 "_Smi can only be allocated by the VM"); |
| 187 } | 187 } |
| 188 int get hashCode { | 188 int get hashCode { |
| 189 return this; | 189 return this; |
| 190 } | 190 } |
| 191 int operator ~() native "Smi_bitNegate"; | 191 int operator ~() native "Smi_bitNegate"; |
| 192 int _shrFromInt(int other) native "Smi_shrFromInt"; | 192 int _shrFromInt(int other) native "Smi_shrFromInt"; |
| 193 int _shlFromInt(int other) native "Smi_shlFromInt"; | 193 int _shlFromInt(int other) native "Smi_shlFromInt"; |
| 194 } | 194 } |
| 195 | 195 |
| 196 // Represents integers that cannot be represented by Smi but fit into 64bits. | 196 // Represents integers that cannot be represented by Smi but fit into 64bits. |
| 197 class _Mint extends _IntegerImplementation implements int { | 197 class _Mint extends _IntegerImplementation implements int { |
| 198 factory _Mint._uninstantiable() { | 198 factory _Mint._uninstantiable() { |
| 199 throw const UnsupportedOperationException( | 199 throw new UnsupportedError( |
| 200 "_Mint can only be allocated by the VM"); | 200 "_Mint can only be allocated by the VM"); |
| 201 } | 201 } |
| 202 int get hashCode { | 202 int get hashCode { |
| 203 return this; | 203 return this; |
| 204 } | 204 } |
| 205 int operator ~() native "Mint_bitNegate"; | 205 int operator ~() native "Mint_bitNegate"; |
| 206 | 206 |
| 207 // Shift by mint exceeds range that can be handled by the VM. | 207 // Shift by mint exceeds range that can be handled by the VM. |
| 208 int _shrFromInt(int other) { | 208 int _shrFromInt(int other) { |
| 209 if (other < 0) { | 209 if (other < 0) { |
| 210 return -1; | 210 return -1; |
| 211 } else { | 211 } else { |
| 212 return 0; | 212 return 0; |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 int _shlFromInt(int other) { | 215 int _shlFromInt(int other) { |
| 216 throw const OutOfMemoryError(); | 216 throw const OutOfMemoryError(); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 // A number that can be represented as Smi or Mint will never be represented as | 220 // A number that can be represented as Smi or Mint will never be represented as |
| 221 // Bigint. | 221 // Bigint. |
| 222 class _Bigint extends _IntegerImplementation implements int { | 222 class _Bigint extends _IntegerImplementation implements int { |
| 223 factory _Bigint._uninstantiable() { | 223 factory _Bigint._uninstantiable() { |
| 224 throw const UnsupportedOperationException( | 224 throw new UnsupportedError( |
| 225 "_Bigint can only be allocated by the VM"); | 225 "_Bigint can only be allocated by the VM"); |
| 226 } | 226 } |
| 227 int get hashCode { | 227 int get hashCode { |
| 228 return this; | 228 return this; |
| 229 } | 229 } |
| 230 int operator ~() native "Bigint_bitNegate"; | 230 int operator ~() native "Bigint_bitNegate"; |
| 231 | 231 |
| 232 // Shift by bigint exceeds range that can be handled by the VM. | 232 // Shift by bigint exceeds range that can be handled by the VM. |
| 233 int _shrFromInt(int other) { | 233 int _shrFromInt(int other) { |
| 234 if (other < 0) { | 234 if (other < 0) { |
| 235 return -1; | 235 return -1; |
| 236 } else { | 236 } else { |
| 237 return 0; | 237 return 0; |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 int _shlFromInt(int other) { | 240 int _shlFromInt(int other) { |
| 241 throw const OutOfMemoryError(); | 241 throw const OutOfMemoryError(); |
| 242 } | 242 } |
| 243 | 243 |
| 244 int pow(int exponent) { | 244 int pow(int exponent) { |
| 245 throw "Bigint.pow not implemented"; | 245 throw "Bigint.pow not implemented"; |
| 246 } | 246 } |
| 247 } | 247 } |
| OLD | NEW |