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

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

Issue 11421064: Cleanups and added more checks for valid Integer allocation (must be Smi, Mint or Bigint for their … (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years 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') | runtime/vm/object_test.cc » ('j') | 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 9265 matching lines...) Expand 10 before | Expand all | Expand 10 after
9276 return 0; 9276 return 0;
9277 } 9277 }
9278 9278
9279 9279
9280 int Integer::CompareWith(const Integer& other) const { 9280 int Integer::CompareWith(const Integer& other) const {
9281 UNIMPLEMENTED(); 9281 UNIMPLEMENTED();
9282 return 0; 9282 return 0;
9283 } 9283 }
9284 9284
9285 9285
9286 RawInteger* Integer::AsInteger() const { 9286 RawInteger* Integer::AsValidInteger() const {
9287 if (IsSmi()) return raw(); 9287 if (IsSmi()) return raw();
9288 if (IsMint()) { 9288 if (IsMint()) {
9289 Mint& mint = Mint::Handle(); 9289 Mint& mint = Mint::Handle();
9290 mint ^= raw(); 9290 mint ^= raw();
9291 if (Smi::IsValid64(mint.value())) { 9291 if (Smi::IsValid64(mint.value())) {
9292 return Smi::New(mint.value()); 9292 return Smi::New(mint.value());
9293 } else { 9293 } else {
9294 return raw(); 9294 return raw();
9295 } 9295 }
9296 } 9296 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
9395 default: 9395 default:
9396 UNIMPLEMENTED(); 9396 UNIMPLEMENTED();
9397 } 9397 }
9398 } 9398 }
9399 } 9399 }
9400 } 9400 }
9401 const Bigint& left_big = Bigint::Handle(AsBigint()); 9401 const Bigint& left_big = Bigint::Handle(AsBigint());
9402 const Bigint& right_big = Bigint::Handle(other.AsBigint()); 9402 const Bigint& right_big = Bigint::Handle(other.AsBigint());
9403 const Bigint& result = 9403 const Bigint& result =
9404 Bigint::Handle(left_big.ArithmeticOp(operation, right_big)); 9404 Bigint::Handle(left_big.ArithmeticOp(operation, right_big));
9405 return Integer::Handle(result.AsInteger()).raw(); 9405 return Integer::Handle(result.AsValidInteger()).raw();
9406 } 9406 }
9407 9407
9408 9408
9409 static bool Are64bitOperands(const Integer& op1, const Integer& op2) { 9409 static bool Are64bitOperands(const Integer& op1, const Integer& op2) {
9410 return !op1.IsBigint() && !op2.IsBigint(); 9410 return !op1.IsBigint() && !op2.IsBigint();
9411 } 9411 }
9412 9412
9413 9413
9414 RawInteger* Integer::BitOp(Token::Kind kind, const Integer& other) const { 9414 RawInteger* Integer::BitOp(Token::Kind kind, const Integer& other) const {
9415 if (IsSmi() && other.IsSmi()) { 9415 if (IsSmi() && other.IsSmi()) {
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
9866 for (intptr_t i = 0; i < len; i++) { 9866 for (intptr_t i = 0; i < len; i++) {
9867 if (this->GetChunkAt(i) != other_bgi.GetChunkAt(i)) { 9867 if (this->GetChunkAt(i) != other_bgi.GetChunkAt(i)) {
9868 return false; 9868 return false;
9869 } 9869 }
9870 } 9870 }
9871 return true; 9871 return true;
9872 } 9872 }
9873 9873
9874 9874
9875 RawBigint* Bigint::New(const String& str, Heap::Space space) { 9875 RawBigint* Bigint::New(const String& str, Heap::Space space) {
9876 return BigintOperations::NewFromCString(str.ToCString(), space); 9876 const Bigint& result = Bigint::Handle(
9877 } 9877 BigintOperations::NewFromCString(str.ToCString(), space));
9878 9878 ASSERT(!BigintOperations::FitsIntoMint(result));
9879 9879 return result.raw();
9880 RawBigint* Bigint::New(int64_t value, Heap::Space space) {
9881 return BigintOperations::NewFromInt64(value, space);
9882 } 9880 }
9883 9881
9884 9882
9885 double Bigint::AsDoubleValue() const { 9883 double Bigint::AsDoubleValue() const {
9886 return Double::Handle(BigintOperations::ToDouble(*this)).value(); 9884 return Double::Handle(BigintOperations::ToDouble(*this)).value();
9887 } 9885 }
9888 9886
9889 9887
9890 int64_t Bigint::AsInt64Value() const { 9888 int64_t Bigint::AsInt64Value() const {
9891 if (!BigintOperations::FitsIntoMint(*this)) { 9889 if (!BigintOperations::FitsIntoMint(*this)) {
(...skipping 2304 matching lines...) Expand 10 before | Expand all | Expand 10 after
12196 } 12194 }
12197 return result.raw(); 12195 return result.raw();
12198 } 12196 }
12199 12197
12200 12198
12201 const char* WeakProperty::ToCString() const { 12199 const char* WeakProperty::ToCString() const {
12202 return "_WeakProperty"; 12200 return "_WeakProperty";
12203 } 12201 }
12204 12202
12205 } // namespace dart 12203 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698