Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: runtime/vm/object.cc

Issue 10937030: Make some static helpers into member functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 8734 matching lines...) Expand 10 before | Expand all | Expand 10 after
8745 return 0; 8745 return 0;
8746 } 8746 }
8747 8747
8748 8748
8749 int Integer::CompareWith(const Integer& other) const { 8749 int Integer::CompareWith(const Integer& other) const {
8750 UNIMPLEMENTED(); 8750 UNIMPLEMENTED();
8751 return 0; 8751 return 0;
8752 } 8752 }
8753 8753
8754 8754
8755 // Return the most compact presentation of an integer. 8755 RawInteger* Integer::AsInteger() const {
8756 RawInteger* Integer::AsInteger(const Integer& value) { 8756 if (IsSmi()) return raw();
8757 if (value.IsSmi()) return value.raw(); 8757 if (IsMint()) {
8758 if (value.IsMint()) {
8759 Mint& mint = Mint::Handle(); 8758 Mint& mint = Mint::Handle();
8760 mint ^= value.raw(); 8759 mint ^= raw();
8761 if (Smi::IsValid64(mint.value())) { 8760 if (Smi::IsValid64(mint.value())) {
8762 return Smi::New(mint.value()); 8761 return Smi::New(mint.value());
8763 } else { 8762 } else {
8764 return value.raw(); 8763 return raw();
8765 } 8764 }
8766 } 8765 }
8767 ASSERT(value.IsBigint()); 8766 ASSERT(IsBigint());
8768 Bigint& big_value = Bigint::Handle(); 8767 Bigint& big_value = Bigint::Handle();
8769 big_value ^= value.raw(); 8768 big_value ^= raw();
8770 if (BigintOperations::FitsIntoSmi(big_value)) { 8769 if (BigintOperations::FitsIntoSmi(big_value)) {
8771 return BigintOperations::ToSmi(big_value); 8770 return BigintOperations::ToSmi(big_value);
8772 } else if (BigintOperations::FitsIntoMint(big_value)) { 8771 } else if (BigintOperations::FitsIntoMint(big_value)) {
8773 return Mint::New(BigintOperations::ToMint(big_value)); 8772 return Mint::New(BigintOperations::ToMint(big_value));
8774 } else { 8773 } else {
8775 return big_value.raw(); 8774 return big_value.raw();
8776 } 8775 }
8777 } 8776 }
8778 8777
8779 8778
8780 RawInteger* Integer::BinaryOp(Token::Kind operation, 8779 RawInteger* Integer::BinaryOp(Token::Kind operation,
8781 const Integer& left, 8780 const Integer& other) const {
8782 const Integer& right) {
8783 // In 32-bit mode, the result of any operation between two Smis will fit in a 8781 // In 32-bit mode, the result of any operation between two Smis will fit in a
8784 // 32-bit signed result, except the product of two Smis, which will be 64-bit. 8782 // 32-bit signed result, except the product of two Smis, which will be 64-bit.
8785 // In 64-bit mode, the result of any operation between two Smis will fit in a 8783 // In 64-bit mode, the result of any operation between two Smis will fit in a
8786 // 64-bit signed result, except the product of two Smis (unless the Smis are 8784 // 64-bit signed result, except the product of two Smis (unless the Smis are
8787 // 32-bit or less). 8785 // 32-bit or less).
8788 if (left.IsSmi() && right.IsSmi()) { 8786 if (IsSmi() && other.IsSmi()) {
8789 Smi& left_smi = Smi::Handle(); 8787 Smi& left_smi = Smi::Handle();
8790 Smi& right_smi = Smi::Handle(); 8788 Smi& right_smi = Smi::Handle();
8791 left_smi ^= left.raw(); 8789 left_smi ^= raw();
8792 right_smi ^= right.raw(); 8790 right_smi ^= other.raw();
8793 const intptr_t left_value = left_smi.Value(); 8791 const intptr_t left_value = left_smi.Value();
8794 const intptr_t right_value = right_smi.Value(); 8792 const intptr_t right_value = right_smi.Value();
8795 switch (operation) { 8793 switch (operation) {
8796 case Token::kADD: 8794 case Token::kADD:
8797 return Integer::New(left_value + right_value); 8795 return Integer::New(left_value + right_value);
8798 case Token::kSUB: 8796 case Token::kSUB:
8799 return Integer::New(left_value - right_value); 8797 return Integer::New(left_value - right_value);
8800 case Token::kMUL: { 8798 case Token::kMUL: {
8801 if (Smi::kBits < 32) { 8799 if (Smi::kBits < 32) {
8802 // In 32-bit mode, the product of two Smis fits in a 64-bit result. 8800 // In 32-bit mode, the product of two Smis fits in a 64-bit result.
(...skipping 23 matching lines...) Expand all
8826 } 8824 }
8827 return Integer::New(remainder); 8825 return Integer::New(remainder);
8828 } 8826 }
8829 default: 8827 default:
8830 UNIMPLEMENTED(); 8828 UNIMPLEMENTED();
8831 } 8829 }
8832 } 8830 }
8833 // In 32-bit mode, the result of any operation between two 63-bit signed 8831 // In 32-bit mode, the result of any operation between two 63-bit signed
8834 // integers (or 32-bit for multiplication) will fit in a 64-bit signed result. 8832 // integers (or 32-bit for multiplication) will fit in a 64-bit signed result.
8835 // In 64-bit mode, 63-bit signed integers are Smis, already processed above. 8833 // In 64-bit mode, 63-bit signed integers are Smis, already processed above.
8836 if ((Smi::kBits < 32) && !left.IsBigint() && !right.IsBigint()) { 8834 if ((Smi::kBits < 32) && !IsBigint() && !other.IsBigint()) {
8837 const int64_t left_value = left.AsInt64Value(); 8835 const int64_t left_value = AsInt64Value();
8838 if (Utils::IsInt(63, left_value)) { 8836 if (Utils::IsInt(63, left_value)) {
8839 const int64_t right_value = right.AsInt64Value(); 8837 const int64_t right_value = other.AsInt64Value();
8840 if (Utils::IsInt(63, right_value)) { 8838 if (Utils::IsInt(63, right_value)) {
8841 switch (operation) { 8839 switch (operation) {
8842 case Token::kADD: 8840 case Token::kADD:
8843 return Integer::New(left_value + right_value); 8841 return Integer::New(left_value + right_value);
8844 case Token::kSUB: 8842 case Token::kSUB:
8845 return Integer::New(left_value - right_value); 8843 return Integer::New(left_value - right_value);
8846 case Token::kMUL: { 8844 case Token::kMUL: {
8847 if (Utils::IsInt(32, left_value) && Utils::IsInt(32, right_value)) { 8845 if (Utils::IsInt(32, left_value) && Utils::IsInt(32, right_value)) {
8848 return Integer::New(left_value * right_value); 8846 return Integer::New(left_value * right_value);
8849 } 8847 }
(...skipping 12 matching lines...) Expand all
8862 } 8860 }
8863 } 8861 }
8864 return Integer::New(remainder); 8862 return Integer::New(remainder);
8865 } 8863 }
8866 default: 8864 default:
8867 UNIMPLEMENTED(); 8865 UNIMPLEMENTED();
8868 } 8866 }
8869 } 8867 }
8870 } 8868 }
8871 } 8869 }
8872 const Bigint& left_big = Bigint::Handle(Bigint::AsBigint(left)); 8870 const Bigint& left_big = Bigint::Handle(AsBigint());
8873 const Bigint& right_big = Bigint::Handle(Bigint::AsBigint(right)); 8871 const Bigint& right_big = Bigint::Handle(other.AsBigint());
8874 const Bigint& result = 8872 const Bigint& result =
8875 Bigint::Handle(Bigint::BinaryOp(operation, left_big, right_big)); 8873 Bigint::Handle(left_big.BinaryOp(operation, right_big));
8876 return Integer::Handle(AsInteger(result)).raw(); 8874 return Integer::Handle(result.AsInteger()).raw();
8877 } 8875 }
8878 8876
8879 8877
8880 bool Smi::Equals(const Instance& other) const { 8878 bool Smi::Equals(const Instance& other) const {
8881 if (other.IsNull() || !other.IsSmi()) { 8879 if (other.IsNull() || !other.IsSmi()) {
8882 return false; 8880 return false;
8883 } 8881 }
8884 return (this->Value() == Smi::Cast(other).Value()); 8882 return (this->Value() == Smi::Cast(other).Value());
8885 } 8883 }
8886 8884
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
9172 return value() < 0 ? "-Infinity" : "Infinity"; 9170 return value() < 0 ? "-Infinity" : "Infinity";
9173 } 9171 }
9174 const int kBufferSize = 128; 9172 const int kBufferSize = 128;
9175 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(kBufferSize); 9173 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(kBufferSize);
9176 buffer[kBufferSize - 1] = '\0'; 9174 buffer[kBufferSize - 1] = '\0';
9177 DoubleToCString(value(), buffer, kBufferSize); 9175 DoubleToCString(value(), buffer, kBufferSize);
9178 return buffer; 9176 return buffer;
9179 } 9177 }
9180 9178
9181 9179
9182 // Returns value in form of a RawBigint. 9180 RawBigint* Integer::AsBigint() const {
9183 RawBigint* Bigint::AsBigint(const Integer& value) { 9181 ASSERT(!IsNull());
9184 ASSERT(!value.IsNull()); 9182 if (IsSmi()) {
9185 if (value.IsSmi()) {
9186 Smi& smi = Smi::Handle(); 9183 Smi& smi = Smi::Handle();
9187 smi ^= value.raw(); 9184 smi ^= raw();
9188 return BigintOperations::NewFromSmi(smi); 9185 return BigintOperations::NewFromSmi(smi);
9189 } else if (value.IsMint()) { 9186 } else if (IsMint()) {
9190 Mint& mint = Mint::Handle(); 9187 Mint& mint = Mint::Handle();
9191 mint ^= value.raw(); 9188 mint ^= raw();
9192 return BigintOperations::NewFromInt64(mint.value()); 9189 return BigintOperations::NewFromInt64(mint.value());
9193 } else { 9190 } else {
9194 ASSERT(value.IsBigint()); 9191 ASSERT(IsBigint());
9195 Bigint& big = Bigint::Handle(); 9192 Bigint& big = Bigint::Handle();
9196 big ^= value.raw(); 9193 big ^= raw();
9197 ASSERT(!BigintOperations::FitsIntoSmi(big)); 9194 ASSERT(!BigintOperations::FitsIntoSmi(big));
9198 return big.raw(); 9195 return big.raw();
9199 } 9196 }
9200 } 9197 }
9201 9198
9202 9199
9203 RawBigint* Bigint::BinaryOp(Token::Kind operation, 9200 RawBigint* Bigint::BinaryOp(Token::Kind operation, const Bigint& other) const {
9204 const Bigint& left,
9205 const Bigint& right) {
9206 switch (operation) { 9201 switch (operation) {
9207 case Token::kADD: 9202 case Token::kADD:
9208 return BigintOperations::Add(left, right); 9203 return BigintOperations::Add(*this, other);
9209 case Token::kSUB: 9204 case Token::kSUB:
9210 return BigintOperations::Subtract(left, right); 9205 return BigintOperations::Subtract(*this, other);
9211 case Token::kMUL: 9206 case Token::kMUL:
9212 return BigintOperations::Multiply(left, right); 9207 return BigintOperations::Multiply(*this, other);
9213 case Token::kTRUNCDIV: 9208 case Token::kTRUNCDIV:
9214 return BigintOperations::Divide(left, right); 9209 return BigintOperations::Divide(*this, other);
9215 case Token::kMOD: 9210 case Token::kMOD:
9216 return BigintOperations::Modulo(left, right); 9211 return BigintOperations::Modulo(*this, other);
9217 default: 9212 default:
9218 UNIMPLEMENTED(); 9213 UNIMPLEMENTED();
9219 return Bigint::null(); 9214 return Bigint::null();
9220 } 9215 }
9221 } 9216 }
9222 9217
9223 9218
9224 bool Bigint::Equals(const Instance& other) const { 9219 bool Bigint::Equals(const Instance& other) const {
9225 if (this->raw() == other.raw()) { 9220 if (this->raw() == other.raw()) {
9226 // Both handles point to the same raw instance. 9221 // Both handles point to the same raw instance.
(...skipping 2580 matching lines...) Expand 10 before | Expand all | Expand 10 after
11807 } 11802 }
11808 return result.raw(); 11803 return result.raw();
11809 } 11804 }
11810 11805
11811 11806
11812 const char* WeakProperty::ToCString() const { 11807 const char* WeakProperty::ToCString() const {
11813 return "_WeakProperty"; 11808 return "_WeakProperty";
11814 } 11809 }
11815 11810
11816 } // namespace dart 11811 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698