| 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 #include "vm/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 10326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10337 } | 10337 } |
| 10338 | 10338 |
| 10339 | 10339 |
| 10340 RawInteger* Integer::New(const String& str, Heap::Space space) { | 10340 RawInteger* Integer::New(const String& str, Heap::Space space) { |
| 10341 // We are not supposed to have integers represented as two byte strings. | 10341 // We are not supposed to have integers represented as two byte strings. |
| 10342 ASSERT(str.IsOneByteString()); | 10342 ASSERT(str.IsOneByteString()); |
| 10343 int64_t value; | 10343 int64_t value; |
| 10344 if (!OS::StringToInt64(str.ToCString(), &value)) { | 10344 if (!OS::StringToInt64(str.ToCString(), &value)) { |
| 10345 const Bigint& big = Bigint::Handle(Bigint::New(str, space)); | 10345 const Bigint& big = Bigint::Handle(Bigint::New(str, space)); |
| 10346 ASSERT(!BigintOperations::FitsIntoSmi(big)); | 10346 ASSERT(!BigintOperations::FitsIntoSmi(big)); |
| 10347 ASSERT(!BigintOperations::FitsIntoMint(big)); | 10347 ASSERT(!BigintOperations::FitsIntoInt64(big)); |
| 10348 return big.raw(); | 10348 return big.raw(); |
| 10349 } | 10349 } |
| 10350 return Integer::New(value, space); | 10350 return Integer::New(value, space); |
| 10351 } | 10351 } |
| 10352 | 10352 |
| 10353 | 10353 |
| 10354 RawInteger* Integer::NewCanonical(const String& str) { | 10354 RawInteger* Integer::NewCanonical(const String& str) { |
| 10355 // We are not supposed to have integers represented as two byte strings. | 10355 // We are not supposed to have integers represented as two byte strings. |
| 10356 ASSERT(str.IsOneByteString()); | 10356 ASSERT(str.IsOneByteString()); |
| 10357 int64_t value; | 10357 int64_t value; |
| 10358 if (!OS::StringToInt64(str.ToCString(), &value)) { | 10358 if (!OS::StringToInt64(str.ToCString(), &value)) { |
| 10359 const Bigint& big = Bigint::Handle(Bigint::NewCanonical(str)); | 10359 const Bigint& big = Bigint::Handle(Bigint::NewCanonical(str)); |
| 10360 ASSERT(!BigintOperations::FitsIntoSmi(big)); | 10360 ASSERT(!BigintOperations::FitsIntoSmi(big)); |
| 10361 ASSERT(!BigintOperations::FitsIntoMint(big)); | 10361 ASSERT(!BigintOperations::FitsIntoInt64(big)); |
| 10362 return big.raw(); | 10362 return big.raw(); |
| 10363 } | 10363 } |
| 10364 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { | 10364 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { |
| 10365 return Smi::New(value); | 10365 return Smi::New(value); |
| 10366 } | 10366 } |
| 10367 return Mint::NewCanonical(value); | 10367 return Mint::NewCanonical(value); |
| 10368 } | 10368 } |
| 10369 | 10369 |
| 10370 | 10370 |
| 10371 RawInteger* Integer::New(int64_t value, Heap::Space space) { | 10371 RawInteger* Integer::New(int64_t value, Heap::Space space) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10403 return Smi::New(mint.value()); | 10403 return Smi::New(mint.value()); |
| 10404 } else { | 10404 } else { |
| 10405 return raw(); | 10405 return raw(); |
| 10406 } | 10406 } |
| 10407 } | 10407 } |
| 10408 ASSERT(IsBigint()); | 10408 ASSERT(IsBigint()); |
| 10409 Bigint& big_value = Bigint::Handle(); | 10409 Bigint& big_value = Bigint::Handle(); |
| 10410 big_value ^= raw(); | 10410 big_value ^= raw(); |
| 10411 if (BigintOperations::FitsIntoSmi(big_value)) { | 10411 if (BigintOperations::FitsIntoSmi(big_value)) { |
| 10412 return BigintOperations::ToSmi(big_value); | 10412 return BigintOperations::ToSmi(big_value); |
| 10413 } else if (BigintOperations::FitsIntoMint(big_value)) { | 10413 } else if (BigintOperations::FitsIntoInt64(big_value)) { |
| 10414 return Mint::New(BigintOperations::ToMint(big_value)); | 10414 return Mint::New(BigintOperations::ToInt64(big_value)); |
| 10415 } else { | 10415 } else { |
| 10416 return big_value.raw(); | 10416 return big_value.raw(); |
| 10417 } | 10417 } |
| 10418 } | 10418 } |
| 10419 | 10419 |
| 10420 | 10420 |
| 10421 RawInteger* Integer::ArithmeticOp(Token::Kind operation, | 10421 RawInteger* Integer::ArithmeticOp(Token::Kind operation, |
| 10422 const Integer& other) const { | 10422 const Integer& other) const { |
| 10423 // In 32-bit mode, the result of any operation between two Smis will fit in a | 10423 // In 32-bit mode, the result of any operation between two Smis will fit in a |
| 10424 // 32-bit signed result, except the product of two Smis, which will be 64-bit. | 10424 // 32-bit signed result, except the product of two Smis, which will be 64-bit. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10505 } | 10505 } |
| 10506 default: | 10506 default: |
| 10507 UNIMPLEMENTED(); | 10507 UNIMPLEMENTED(); |
| 10508 } | 10508 } |
| 10509 } | 10509 } |
| 10510 } | 10510 } |
| 10511 } | 10511 } |
| 10512 const Bigint& left_big = Bigint::Handle(AsBigint()); | 10512 const Bigint& left_big = Bigint::Handle(AsBigint()); |
| 10513 const Bigint& right_big = Bigint::Handle(other.AsBigint()); | 10513 const Bigint& right_big = Bigint::Handle(other.AsBigint()); |
| 10514 const Bigint& result = | 10514 const Bigint& result = |
| 10515 Bigint::Handle(left_big.ArithmeticOp(operation, right_big)); | 10515 Bigint::Handle(left_big.BigArithmeticOp(operation, right_big)); |
| 10516 return Integer::Handle(result.AsValidInteger()).raw(); | 10516 return Integer::Handle(result.AsValidInteger()).raw(); |
| 10517 } | 10517 } |
| 10518 | 10518 |
| 10519 | 10519 |
| 10520 static bool Are64bitOperands(const Integer& op1, const Integer& op2) { | 10520 static bool Are64bitOperands(const Integer& op1, const Integer& op2) { |
| 10521 return !op1.IsBigint() && !op2.IsBigint(); | 10521 return !op1.IsBigint() && !op2.IsBigint(); |
| 10522 } | 10522 } |
| 10523 | 10523 |
| 10524 | 10524 |
| 10525 RawInteger* Integer::BitOp(Token::Kind kind, const Integer& other) const { | 10525 RawInteger* Integer::BitOp(Token::Kind kind, const Integer& other) const { |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10769 int64_t b = other.AsInt64Value(); | 10769 int64_t b = other.AsInt64Value(); |
| 10770 if (a < b) { | 10770 if (a < b) { |
| 10771 return -1; | 10771 return -1; |
| 10772 } else if (a > b) { | 10772 } else if (a > b) { |
| 10773 return 1; | 10773 return 1; |
| 10774 } else { | 10774 } else { |
| 10775 return 0; | 10775 return 0; |
| 10776 } | 10776 } |
| 10777 } | 10777 } |
| 10778 if (other.IsBigint()) { | 10778 if (other.IsBigint()) { |
| 10779 ASSERT(!BigintOperations::FitsIntoMint(Bigint::Cast(other))); | 10779 ASSERT(!BigintOperations::FitsIntoInt64(Bigint::Cast(other))); |
| 10780 if (this->IsNegative() == other.IsNegative()) { | 10780 if (this->IsNegative() == other.IsNegative()) { |
| 10781 return this->IsNegative() ? 1 : -1; | 10781 return this->IsNegative() ? 1 : -1; |
| 10782 } | 10782 } |
| 10783 return this->IsNegative() ? -1 : 1; | 10783 return this->IsNegative() ? -1 : 1; |
| 10784 } | 10784 } |
| 10785 UNREACHABLE(); | 10785 UNREACHABLE(); |
| 10786 return 0; | 10786 return 0; |
| 10787 } | 10787 } |
| 10788 | 10788 |
| 10789 | 10789 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10911 } else { | 10911 } else { |
| 10912 ASSERT(IsBigint()); | 10912 ASSERT(IsBigint()); |
| 10913 Bigint& big = Bigint::Handle(); | 10913 Bigint& big = Bigint::Handle(); |
| 10914 big ^= raw(); | 10914 big ^= raw(); |
| 10915 ASSERT(!BigintOperations::FitsIntoSmi(big)); | 10915 ASSERT(!BigintOperations::FitsIntoSmi(big)); |
| 10916 return big.raw(); | 10916 return big.raw(); |
| 10917 } | 10917 } |
| 10918 } | 10918 } |
| 10919 | 10919 |
| 10920 | 10920 |
| 10921 RawBigint* Bigint::ArithmeticOp(Token::Kind operation, | 10921 RawBigint* Bigint::BigArithmeticOp(Token::Kind operation, |
| 10922 const Bigint& other) const { | 10922 const Bigint& other) const { |
| 10923 switch (operation) { | 10923 switch (operation) { |
| 10924 case Token::kADD: | 10924 case Token::kADD: |
| 10925 return BigintOperations::Add(*this, other); | 10925 return BigintOperations::Add(*this, other); |
| 10926 case Token::kSUB: | 10926 case Token::kSUB: |
| 10927 return BigintOperations::Subtract(*this, other); | 10927 return BigintOperations::Subtract(*this, other); |
| 10928 case Token::kMUL: | 10928 case Token::kMUL: |
| 10929 return BigintOperations::Multiply(*this, other); | 10929 return BigintOperations::Multiply(*this, other); |
| 10930 case Token::kTRUNCDIV: | 10930 case Token::kTRUNCDIV: |
| 10931 return BigintOperations::Divide(*this, other); | 10931 return BigintOperations::Divide(*this, other); |
| 10932 case Token::kMOD: | 10932 case Token::kMOD: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10964 return false; | 10964 return false; |
| 10965 } | 10965 } |
| 10966 } | 10966 } |
| 10967 return true; | 10967 return true; |
| 10968 } | 10968 } |
| 10969 | 10969 |
| 10970 | 10970 |
| 10971 RawBigint* Bigint::New(const String& str, Heap::Space space) { | 10971 RawBigint* Bigint::New(const String& str, Heap::Space space) { |
| 10972 const Bigint& result = Bigint::Handle( | 10972 const Bigint& result = Bigint::Handle( |
| 10973 BigintOperations::NewFromCString(str.ToCString(), space)); | 10973 BigintOperations::NewFromCString(str.ToCString(), space)); |
| 10974 ASSERT(!BigintOperations::FitsIntoMint(result)); | 10974 ASSERT(!BigintOperations::FitsIntoInt64(result)); |
| 10975 return result.raw(); | 10975 return result.raw(); |
| 10976 } | 10976 } |
| 10977 | 10977 |
| 10978 | 10978 |
| 10979 RawBigint* Bigint::NewCanonical(const String& str) { | 10979 RawBigint* Bigint::NewCanonical(const String& str) { |
| 10980 const Bigint& value = Bigint::Handle( | 10980 const Bigint& value = Bigint::Handle( |
| 10981 BigintOperations::NewFromCString(str.ToCString(), Heap::kOld)); | 10981 BigintOperations::NewFromCString(str.ToCString(), Heap::kOld)); |
| 10982 ASSERT(!BigintOperations::FitsIntoMint(value)); | 10982 ASSERT(!BigintOperations::FitsIntoInt64(value)); |
| 10983 const Class& cls = | 10983 const Class& cls = |
| 10984 Class::Handle(Isolate::Current()->object_store()->bigint_class()); | 10984 Class::Handle(Isolate::Current()->object_store()->bigint_class()); |
| 10985 const Array& constants = Array::Handle(cls.constants()); | 10985 const Array& constants = Array::Handle(cls.constants()); |
| 10986 const intptr_t constants_len = constants.Length(); | 10986 const intptr_t constants_len = constants.Length(); |
| 10987 // Linear search to see whether this value is already present in the | 10987 // Linear search to see whether this value is already present in the |
| 10988 // list of canonicalized constants. | 10988 // list of canonicalized constants. |
| 10989 Bigint& canonical_value = Bigint::Handle(); | 10989 Bigint& canonical_value = Bigint::Handle(); |
| 10990 intptr_t index = 0; | 10990 intptr_t index = 0; |
| 10991 while (index < constants_len) { | 10991 while (index < constants_len) { |
| 10992 canonical_value ^= constants.At(index); | 10992 canonical_value ^= constants.At(index); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 11005 return value.raw(); | 11005 return value.raw(); |
| 11006 } | 11006 } |
| 11007 | 11007 |
| 11008 | 11008 |
| 11009 double Bigint::AsDoubleValue() const { | 11009 double Bigint::AsDoubleValue() const { |
| 11010 return Double::Handle(BigintOperations::ToDouble(*this)).value(); | 11010 return Double::Handle(BigintOperations::ToDouble(*this)).value(); |
| 11011 } | 11011 } |
| 11012 | 11012 |
| 11013 | 11013 |
| 11014 int64_t Bigint::AsInt64Value() const { | 11014 int64_t Bigint::AsInt64Value() const { |
| 11015 if (!BigintOperations::FitsIntoMint(*this)) { | 11015 if (!BigintOperations::FitsIntoInt64(*this)) { |
| 11016 UNREACHABLE(); | 11016 UNREACHABLE(); |
| 11017 } | 11017 } |
| 11018 return BigintOperations::ToMint(*this); | 11018 return BigintOperations::ToInt64(*this); |
| 11019 } | 11019 } |
| 11020 | 11020 |
| 11021 | 11021 |
| 11022 // For positive values: Smi < Mint < Bigint. | 11022 // For positive values: Smi < Mint < Bigint. |
| 11023 int Bigint::CompareWith(const Integer& other) const { | 11023 int Bigint::CompareWith(const Integer& other) const { |
| 11024 ASSERT(!FitsIntoSmi(*this)); | 11024 ASSERT(!FitsIntoSmi(*this)); |
| 11025 ASSERT(!BigintOperations::FitsIntoMint(*this)); | 11025 ASSERT(!BigintOperations::FitsIntoInt64(*this)); |
| 11026 if (other.IsBigint()) { | 11026 if (other.IsBigint()) { |
| 11027 return BigintOperations::Compare(*this, Bigint::Cast(other)); | 11027 return BigintOperations::Compare(*this, Bigint::Cast(other)); |
| 11028 } | 11028 } |
| 11029 if (this->IsNegative() == other.IsNegative()) { | 11029 if (this->IsNegative() == other.IsNegative()) { |
| 11030 return this->IsNegative() ? -1 : 1; | 11030 return this->IsNegative() ? -1 : 1; |
| 11031 } | 11031 } |
| 11032 return this->IsNegative() ? -1 : 1; | 11032 return this->IsNegative() ? -1 : 1; |
| 11033 } | 11033 } |
| 11034 | 11034 |
| 11035 | 11035 |
| (...skipping 2221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13257 } | 13257 } |
| 13258 return result.raw(); | 13258 return result.raw(); |
| 13259 } | 13259 } |
| 13260 | 13260 |
| 13261 | 13261 |
| 13262 const char* WeakProperty::ToCString() const { | 13262 const char* WeakProperty::ToCString() const { |
| 13263 return "_WeakProperty"; | 13263 return "_WeakProperty"; |
| 13264 } | 13264 } |
| 13265 | 13265 |
| 13266 } // namespace dart | 13266 } // namespace dart |
| OLD | NEW |