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 "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
(...skipping 7661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7672 | 7672 |
7673 | 7673 |
7674 const char* Integer::ToCString() const { | 7674 const char* Integer::ToCString() const { |
7675 // Integer is an interface. No instances of Integer should exist. | 7675 // Integer is an interface. No instances of Integer should exist. |
7676 UNREACHABLE(); | 7676 UNREACHABLE(); |
7677 return "Integer"; | 7677 return "Integer"; |
7678 } | 7678 } |
7679 | 7679 |
7680 | 7680 |
7681 RawInteger* Integer::New(const String& str, Heap::Space space) { | 7681 RawInteger* Integer::New(const String& str, Heap::Space space) { |
7682 // TODO(iposva): If returning a big integer it will not necessarily be in the | 7682 if (str.IsOneByteString()) { |
7683 // requested space. | 7683 const OneByteString& onestr = OneByteString::Cast(str); |
7684 const Bigint& big = Bigint::Handle(Bigint::New(str)); | 7684 int64_t value; |
7685 if (BigintOperations::FitsIntoSmi(big)) { | 7685 if (!OS::Strtoll(onestr.ToCString(), &value)) { |
7686 return BigintOperations::ToSmi(big); | 7686 const Bigint& big = Bigint::Handle(Bigint::New(onestr, space)); |
7687 } else if (BigintOperations::FitsIntoMint(big)) { | 7687 ASSERT(!BigintOperations::FitsIntoSmi(big)); |
7688 return Mint::New(BigintOperations::ToMint(big), space); | 7688 ASSERT(!BigintOperations::FitsIntoMint(big)); |
7689 return big.raw(); | |
7690 } | |
7691 return Integer::New(value, space); | |
7689 } else { | 7692 } else { |
7690 return big.raw(); | 7693 // We are not supposed to have integers represented as two byte or |
cshapiro
2012/07/11 22:11:02
Why isn't this just an ASSERT(str.IsOneByteString(
siva
2012/07/12 18:28:23
Done.
| |
7694 // four byte strings. | |
7695 UNREACHABLE(); | |
7696 return Integer::null(); | |
7691 } | 7697 } |
7692 } | 7698 } |
7693 | 7699 |
7694 | 7700 |
7695 RawInteger* Integer::New(int64_t value, Heap::Space space) { | 7701 RawInteger* Integer::New(int64_t value, Heap::Space space) { |
7696 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { | 7702 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { |
7697 return Smi::New(value); | 7703 return Smi::New(value); |
7698 } | 7704 } |
7699 return Mint::New(value, space); | 7705 return Mint::New(value, space); |
7700 } | 7706 } |
(...skipping 2951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10652 const String& str = String::Handle(pattern()); | 10658 const String& str = String::Handle(pattern()); |
10653 const char* format = "JSRegExp: pattern=%s flags=%s"; | 10659 const char* format = "JSRegExp: pattern=%s flags=%s"; |
10654 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 10660 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
10655 char* chars = reinterpret_cast<char*>( | 10661 char* chars = reinterpret_cast<char*>( |
10656 Isolate::Current()->current_zone()->Allocate(len + 1)); | 10662 Isolate::Current()->current_zone()->Allocate(len + 1)); |
10657 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 10663 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
10658 return chars; | 10664 return chars; |
10659 } | 10665 } |
10660 | 10666 |
10661 } // namespace dart | 10667 } // namespace dart |
OLD | NEW |