| 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 11498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11509 } | 11509 } |
| 11510 | 11510 |
| 11511 | 11511 |
| 11512 // dart2js represents integers as double precision floats, which can represent | 11512 // dart2js represents integers as double precision floats, which can represent |
| 11513 // anything in the range -2^53 ... 2^53. | 11513 // anything in the range -2^53 ... 2^53. |
| 11514 static bool IsJavascriptInt(int64_t value) { | 11514 static bool IsJavascriptInt(int64_t value) { |
| 11515 return ((-0x20000000000000LL <= value) && (value <= 0x20000000000000LL)); | 11515 return ((-0x20000000000000LL <= value) && (value <= 0x20000000000000LL)); |
| 11516 } | 11516 } |
| 11517 | 11517 |
| 11518 | 11518 |
| 11519 RawInteger* Integer::New(int64_t value, Heap::Space space) { | 11519 RawInteger* Integer::New(int64_t value, Heap::Space space, const bool silent) { |
| 11520 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { | 11520 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { |
| 11521 return Smi::New(value); | 11521 return Smi::New(value); |
| 11522 } | 11522 } |
| 11523 if (FLAG_throw_on_javascript_int_overflow && !IsJavascriptInt(value)) { | 11523 if (!silent && |
| 11524 FLAG_throw_on_javascript_int_overflow && |
| 11525 !IsJavascriptInt(value)) { |
| 11524 const Integer &i = Integer::Handle(Mint::New(value)); | 11526 const Integer &i = Integer::Handle(Mint::New(value)); |
| 11525 ThrowJavascriptIntegerOverflow(i); | 11527 ThrowJavascriptIntegerOverflow(i); |
| 11526 } | 11528 } |
| 11527 return Mint::New(value, space); | 11529 return Mint::New(value, space); |
| 11528 } | 11530 } |
| 11529 | 11531 |
| 11530 | 11532 |
| 11531 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) { | 11533 RawInteger* Integer::NewFromUint64(uint64_t value, Heap::Space space) { |
| 11532 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { | 11534 if (value > static_cast<uint64_t>(Mint::kMaxValue)) { |
| 11533 if (FLAG_throw_on_javascript_int_overflow) { | 11535 if (FLAG_throw_on_javascript_int_overflow) { |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11756 return BigintOperations::BitXor(op1, op2); | 11758 return BigintOperations::BitXor(op1, op2); |
| 11757 default: | 11759 default: |
| 11758 UNIMPLEMENTED(); | 11760 UNIMPLEMENTED(); |
| 11759 } | 11761 } |
| 11760 } | 11762 } |
| 11761 return Integer::null(); | 11763 return Integer::null(); |
| 11762 } | 11764 } |
| 11763 | 11765 |
| 11764 | 11766 |
| 11765 // TODO(srdjan): Clarify handling of negative right operand in a shift op. | 11767 // TODO(srdjan): Clarify handling of negative right operand in a shift op. |
| 11766 RawInteger* Smi::ShiftOp(Token::Kind kind, const Smi& other) const { | 11768 RawInteger* Smi::ShiftOp(Token::Kind kind, |
| 11769 const Smi& other, |
| 11770 const bool silent) const { |
| 11767 intptr_t result = 0; | 11771 intptr_t result = 0; |
| 11768 const intptr_t left_value = Value(); | 11772 const intptr_t left_value = Value(); |
| 11769 const intptr_t right_value = other.Value(); | 11773 const intptr_t right_value = other.Value(); |
| 11770 ASSERT(right_value >= 0); | 11774 ASSERT(right_value >= 0); |
| 11771 switch (kind) { | 11775 switch (kind) { |
| 11772 case Token::kSHL: { | 11776 case Token::kSHL: { |
| 11773 if ((left_value == 0) || (right_value == 0)) { | 11777 if ((left_value == 0) || (right_value == 0)) { |
| 11774 return raw(); | 11778 return raw(); |
| 11775 } | 11779 } |
| 11776 { // Check for overflow. | 11780 { // Check for overflow. |
| 11777 int cnt = Utils::HighestBit(left_value); | 11781 int cnt = Utils::HighestBit(left_value); |
| 11778 if ((cnt + right_value) >= Smi::kBits) { | 11782 if ((cnt + right_value) >= Smi::kBits) { |
| 11779 if ((cnt + right_value) >= Mint::kBits) { | 11783 if ((cnt + right_value) >= Mint::kBits) { |
| 11780 return BigintOperations::ShiftLeft( | 11784 return BigintOperations::ShiftLeft( |
| 11781 Bigint::Handle(BigintOperations::NewFromSmi(*this)), | 11785 Bigint::Handle(BigintOperations::NewFromSmi(*this)), |
| 11782 right_value); | 11786 right_value); |
| 11783 } else { | 11787 } else { |
| 11784 int64_t left_64 = left_value; | 11788 int64_t left_64 = left_value; |
| 11785 return Integer::New(left_64 << right_value); | 11789 return Integer::New(left_64 << right_value, Heap::kNew, silent); |
| 11786 } | 11790 } |
| 11787 } | 11791 } |
| 11788 } | 11792 } |
| 11789 result = left_value << right_value; | 11793 result = left_value << right_value; |
| 11790 break; | 11794 break; |
| 11791 } | 11795 } |
| 11792 case Token::kSHR: { | 11796 case Token::kSHR: { |
| 11793 const intptr_t shift_amount = | 11797 const intptr_t shift_amount = |
| 11794 (right_value >= kBitsPerWord) ? (kBitsPerWord - 1) : right_value; | 11798 (right_value >= kBitsPerWord) ? (kBitsPerWord - 1) : right_value; |
| 11795 result = left_value >> shift_amount; | 11799 result = left_value >> shift_amount; |
| (...skipping 2823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14619 } | 14623 } |
| 14620 | 14624 |
| 14621 | 14625 |
| 14622 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 14626 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 14623 stream->OpenObject(); | 14627 stream->OpenObject(); |
| 14624 stream->CloseObject(); | 14628 stream->CloseObject(); |
| 14625 } | 14629 } |
| 14626 | 14630 |
| 14627 | 14631 |
| 14628 } // namespace dart | 14632 } // namespace dart |
| OLD | NEW |