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 16246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16257 StorePointer(&raw_ptr()->neg_, value.raw()); | 16257 StorePointer(&raw_ptr()->neg_, value.raw()); |
16258 } | 16258 } |
16259 | 16259 |
16260 | 16260 |
16261 void Bigint::set_used(const Smi& value) const { | 16261 void Bigint::set_used(const Smi& value) const { |
16262 raw_ptr()->used_ = value.raw(); | 16262 raw_ptr()->used_ = value.raw(); |
16263 } | 16263 } |
16264 | 16264 |
16265 | 16265 |
16266 void Bigint::set_digits(const TypedData& value) const { | 16266 void Bigint::set_digits(const TypedData& value) const { |
| 16267 // The VM expects digits_ to be a Uint32List (not null). |
| 16268 ASSERT(!value.IsNull() && (value.GetClassId() == kTypedDataUint32ArrayCid)); |
16267 StorePointer(&raw_ptr()->digits_, value.raw()); | 16269 StorePointer(&raw_ptr()->digits_, value.raw()); |
16268 } | 16270 } |
16269 | 16271 |
16270 | 16272 |
16271 bool Bigint::Neg() const { | 16273 bool Bigint::Neg() const { |
16272 return Bool::Handle(neg()).value(); | 16274 return Bool::Handle(neg()).value(); |
16273 } | 16275 } |
16274 | 16276 |
16275 | 16277 |
16276 void Bigint::SetNeg(bool value) const { | 16278 void Bigint::SetNeg(bool value) const { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16334 // Bool field neg should always be canonical. | 16336 // Bool field neg should always be canonical. |
16335 ASSERT(Bool::Handle(neg()).IsCanonical()); | 16337 ASSERT(Bool::Handle(neg()).IsCanonical()); |
16336 // Smi field used is canonical by definition. | 16338 // Smi field used is canonical by definition. |
16337 if (Used() > 0) { | 16339 if (Used() > 0) { |
16338 // Canonicalize TypedData field digits. | 16340 // Canonicalize TypedData field digits. |
16339 TypedData& digits_ = TypedData::Handle(digits()); | 16341 TypedData& digits_ = TypedData::Handle(digits()); |
16340 digits_ ^= digits_.CheckAndCanonicalize(NULL); | 16342 digits_ ^= digits_.CheckAndCanonicalize(NULL); |
16341 ASSERT(!digits_.IsNull()); | 16343 ASSERT(!digits_.IsNull()); |
16342 set_digits(digits_); | 16344 set_digits(digits_); |
16343 } else { | 16345 } else { |
16344 ASSERT(digits() == TypedData::null()); | 16346 ASSERT(digits() == TypedData::EmptyUint32Array(Isolate::Current())); |
16345 } | 16347 } |
16346 return true; | 16348 return true; |
16347 } | 16349 } |
16348 | 16350 |
16349 | 16351 |
16350 RawBigint* Bigint::New(Heap::Space space) { | 16352 RawBigint* Bigint::New(Heap::Space space) { |
16351 ASSERT(Isolate::Current()->object_store()->bigint_class() != Class::null()); | 16353 Isolate* isolate = Isolate::Current(); |
16352 Bigint& result = Bigint::Handle(); | 16354 ASSERT(isolate->object_store()->bigint_class() != Class::null()); |
| 16355 Bigint& result = Bigint::Handle(isolate); |
16353 { | 16356 { |
16354 RawObject* raw = Object::Allocate(Bigint::kClassId, | 16357 RawObject* raw = Object::Allocate(Bigint::kClassId, |
16355 Bigint::InstanceSize(), | 16358 Bigint::InstanceSize(), |
16356 space); | 16359 space); |
16357 NoGCScope no_gc; | 16360 NoGCScope no_gc; |
16358 result ^= raw; | 16361 result ^= raw; |
16359 } | 16362 } |
16360 result.set_neg(Bool::Get(false)); | 16363 result.set_neg(Bool::Get(false)); |
16361 result.set_used(Smi::Handle(Smi::New(0))); | 16364 result.set_used(Smi::Handle(isolate, Smi::New(0))); |
| 16365 result.set_digits( |
| 16366 TypedData::Handle(isolate, TypedData::EmptyUint32Array(isolate))); |
16362 return result.raw(); | 16367 return result.raw(); |
16363 } | 16368 } |
16364 | 16369 |
16365 | 16370 |
16366 RawBigint* Bigint::NewFromInt64(int64_t value, Heap::Space space) { | 16371 RawBigint* Bigint::NewFromInt64(int64_t value, Heap::Space space) { |
16367 const Bigint& result = Bigint::Handle(New(space)); | 16372 const Bigint& result = Bigint::Handle(New(space)); |
16368 result.EnsureLength(2, space); | 16373 result.EnsureLength(2, space); |
16369 result.SetUsed(2); | 16374 result.SetUsed(2); |
16370 if (value < 0) { | 16375 if (value < 0) { |
16371 result.SetNeg(true); | 16376 result.SetNeg(true); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16416 (bit_shift == 0) ? 0 | 16421 (bit_shift == 0) ? 0 |
16417 : static_cast<uint32_t>(abs_value >> (64 - bit_shift))); | 16422 : static_cast<uint32_t>(abs_value >> (64 - bit_shift))); |
16418 result.Clamp(); | 16423 result.Clamp(); |
16419 return result.raw(); | 16424 return result.raw(); |
16420 } | 16425 } |
16421 | 16426 |
16422 | 16427 |
16423 void Bigint::EnsureLength(intptr_t length, Heap::Space space) const { | 16428 void Bigint::EnsureLength(intptr_t length, Heap::Space space) const { |
16424 ASSERT(length >= 0); | 16429 ASSERT(length >= 0); |
16425 TypedData& old_digits = TypedData::Handle(digits()); | 16430 TypedData& old_digits = TypedData::Handle(digits()); |
16426 if ((length > 0) && (old_digits.IsNull() || (length > old_digits.Length()))) { | 16431 if ((length > 0) && (length > old_digits.Length())) { |
16427 TypedData& new_digits = TypedData::Handle( | 16432 TypedData& new_digits = TypedData::Handle( |
16428 TypedData::New(kTypedDataUint32ArrayCid, length + kExtraDigits, space)); | 16433 TypedData::New(kTypedDataUint32ArrayCid, length + kExtraDigits, space)); |
16429 if (!old_digits.IsNull()) { | 16434 if (old_digits.Length() > 0) { |
16430 TypedData::Copy(new_digits, TypedData::data_offset(), | 16435 TypedData::Copy(new_digits, TypedData::data_offset(), |
16431 old_digits, TypedData::data_offset(), | 16436 old_digits, TypedData::data_offset(), |
16432 old_digits.LengthInBytes()); | 16437 old_digits.LengthInBytes()); |
16433 } | 16438 } |
16434 set_digits(new_digits); | 16439 set_digits(new_digits); |
16435 } | 16440 } |
16436 } | 16441 } |
16437 | 16442 |
16438 | 16443 |
16439 void Bigint::Clamp() const { | 16444 void Bigint::Clamp() const { |
(...skipping 3188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19628 result ^= raw; | 19633 result ^= raw; |
19629 result.SetLength(len); | 19634 result.SetLength(len); |
19630 if (len > 0) { | 19635 if (len > 0) { |
19631 memset(result.DataAddr(0), 0, lengthInBytes); | 19636 memset(result.DataAddr(0), 0, lengthInBytes); |
19632 } | 19637 } |
19633 } | 19638 } |
19634 return result.raw(); | 19639 return result.raw(); |
19635 } | 19640 } |
19636 | 19641 |
19637 | 19642 |
| 19643 RawTypedData* TypedData::EmptyUint32Array(Isolate* isolate) { |
| 19644 ASSERT(isolate != NULL); |
| 19645 ASSERT(isolate->object_store() != NULL); |
| 19646 if (isolate->object_store()->empty_uint32_array() != TypedData::null()) { |
| 19647 // Already created. |
| 19648 return isolate->object_store()->empty_uint32_array(); |
| 19649 } |
| 19650 const TypedData& array = TypedData::Handle(isolate, |
| 19651 TypedData::New(kTypedDataUint32ArrayCid, 0, Heap::kOld)); |
| 19652 isolate->object_store()->set_empty_uint32_array(array); |
| 19653 return array.raw(); |
| 19654 } |
| 19655 |
| 19656 |
19638 const char* TypedData::ToCString() const { | 19657 const char* TypedData::ToCString() const { |
19639 return "TypedData"; | 19658 return "TypedData"; |
19640 } | 19659 } |
19641 | 19660 |
19642 | 19661 |
19643 void TypedData::PrintJSONImpl(JSONStream* stream, bool ref) const { | 19662 void TypedData::PrintJSONImpl(JSONStream* stream, bool ref) const { |
19644 Instance::PrintJSONImpl(stream, ref); | 19663 Instance::PrintJSONImpl(stream, ref); |
19645 } | 19664 } |
19646 | 19665 |
19647 | 19666 |
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20402 return tag_label.ToCString(); | 20421 return tag_label.ToCString(); |
20403 } | 20422 } |
20404 | 20423 |
20405 | 20424 |
20406 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20425 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
20407 Instance::PrintJSONImpl(stream, ref); | 20426 Instance::PrintJSONImpl(stream, ref); |
20408 } | 20427 } |
20409 | 20428 |
20410 | 20429 |
20411 } // namespace dart | 20430 } // namespace dart |
OLD | NEW |