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

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

Issue 842033005: Make Bigint instances immutable by removing all setters. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 10 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
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 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 5561 matching lines...) Expand 10 before | Expand all | Expand 10 after
5572 5572
5573 virtual bool FitsIntoSmi() const; 5573 virtual bool FitsIntoSmi() const;
5574 bool FitsIntoInt64() const; 5574 bool FitsIntoInt64() const;
5575 bool FitsIntoUint64() const; 5575 bool FitsIntoUint64() const;
5576 uint64_t AsUint64Value() const; 5576 uint64_t AsUint64Value() const;
5577 5577
5578 static intptr_t InstanceSize() { 5578 static intptr_t InstanceSize() {
5579 return RoundedAllocationSize(sizeof(RawBigint)); 5579 return RoundedAllocationSize(sizeof(RawBigint));
5580 } 5580 }
5581 5581
5582 // Offsets of fields accessed directly by optimized code.
5583 static intptr_t neg_offset() { return OFFSET_OF(RawBigint, neg_); }
5584 static intptr_t used_offset() { return OFFSET_OF(RawBigint, used_); }
5585 static intptr_t digits_offset() { return OFFSET_OF(RawBigint, digits_); }
5586
5582 // Accessors used by native calls from Dart. 5587 // Accessors used by native calls from Dart.
5583 RawBool* neg() const { return raw_ptr()->neg_; } 5588 RawBool* neg() const { return raw_ptr()->neg_; }
5584 void set_neg(const Bool& value) const;
5585 static intptr_t neg_offset() { return OFFSET_OF(RawBigint, neg_); }
5586 RawSmi* used() const { return raw_ptr()->used_; } 5589 RawSmi* used() const { return raw_ptr()->used_; }
5587 void set_used(const Smi& value) const;
5588 static intptr_t used_offset() { return OFFSET_OF(RawBigint, used_); }
5589 RawTypedData* digits() const { return raw_ptr()->digits_; } 5590 RawTypedData* digits() const { return raw_ptr()->digits_; }
5590 void set_digits(const TypedData& value) const;
5591 static intptr_t digits_offset() { return OFFSET_OF(RawBigint, digits_); }
5592 5591
5593 // Accessors used by runtime calls from C++. 5592 // Accessors used by runtime calls from C++.
5594 bool Neg() const; 5593 bool Neg() const;
5595 void SetNeg(bool value) const;
5596 intptr_t Used() const; 5594 intptr_t Used() const;
5597 void SetUsed(intptr_t value) const;
5598 uint32_t DigitAt(intptr_t index) const; 5595 uint32_t DigitAt(intptr_t index) const;
5599 void SetDigitAt(intptr_t index, uint32_t value) const;
5600 5596
5601 const char* ToDecCString(uword (*allocator)(intptr_t size)) const; 5597 const char* ToDecCString(uword (*allocator)(intptr_t size)) const;
5602 const char* ToHexCString(uword (*allocator)(intptr_t size)) const; 5598 const char* ToHexCString(uword (*allocator)(intptr_t size)) const;
5603 5599
5604 static const intptr_t kExtraDigits = 4; // Same as _Bigint.EXTRA_DIGITS 5600 static const intptr_t kBitsPerDigit = 32; // Same as _Bigint._DIGIT_BITS
5605 static const intptr_t kBitsPerDigit = 32; // Same as _Bigint.DIGIT_BITS
5606 static const intptr_t kBytesPerDigit = 4; 5601 static const intptr_t kBytesPerDigit = 4;
5607 static const int64_t kDigitBase = 1LL << kBitsPerDigit; 5602 static const int64_t kDigitBase = 1LL << kBitsPerDigit;
5608 static const int64_t kDigitMask = kDigitBase - 1; 5603 static const int64_t kDigitMask = kDigitBase - 1;
5609 5604
5610 static RawBigint* New(Heap::Space space = Heap::kNew); 5605 static RawBigint* New(Heap::Space space = Heap::kNew); // For snapshots.
5606
5607 static RawBigint* New(bool neg, intptr_t used, const TypedData& digits,
5608 Heap::Space space = Heap::kNew);
5611 5609
5612 static RawBigint* NewFromInt64(int64_t value, 5610 static RawBigint* NewFromInt64(int64_t value,
5613 Heap::Space space = Heap::kNew); 5611 Heap::Space space = Heap::kNew);
5614 5612
5615 static RawBigint* NewFromUint64(uint64_t value, 5613 static RawBigint* NewFromUint64(uint64_t value,
5616 Heap::Space space = Heap::kNew); 5614 Heap::Space space = Heap::kNew);
5617 5615
5618 static RawBigint* NewFromShiftedInt64(int64_t value, intptr_t shift, 5616 static RawBigint* NewFromShiftedInt64(int64_t value, intptr_t shift,
5619 Heap::Space space = Heap::kNew); 5617 Heap::Space space = Heap::kNew);
5620 5618
5621 static RawBigint* NewFromCString(const char* str, 5619 static RawBigint* NewFromCString(const char* str,
5622 Heap::Space space = Heap::kNew); 5620 Heap::Space space = Heap::kNew);
5623 5621
5624 // Returns a canonical Bigint object allocated in the old gen space. 5622 // Returns a canonical Bigint object allocated in the old gen space.
5625 static RawBigint* NewCanonical(const String& str); 5623 static RawBigint* NewCanonical(const String& str);
5626 5624
5627 private: 5625 private:
5628 static RawBigint* NewFromHexCString(const char* str, 5626 void SetNeg(bool value) const;
5629 Heap::Space space = Heap::kNew); 5627 void SetUsed(intptr_t value) const;
5630 static RawBigint* NewFromDecCString(const char* str, 5628 void set_digits(const TypedData& value) const;
5631 Heap::Space space = Heap::kNew);
5632 5629
5633 // Make sure at least 'length' _digits are allocated. 5630 // Convenience helpers.
5634 // Copy existing _digits if reallocation is necessary. 5631 static RawTypedData* NewDigits(intptr_t length,
5635 void EnsureLength(intptr_t length, Heap::Space space = Heap::kNew) const; 5632 Heap::Space space = Heap::kNew);
5633 static uint32_t DigitAt(const TypedData& digits, intptr_t index);
5634 static void SetDigitAt(const TypedData& digits,
5635 intptr_t index,
5636 uint32_t value);
5636 5637
5637 // Do not count zero high digits as used. 5638 static RawTypedData* NewDigitsFromHexCString(const char* str, intptr_t* used,
5638 void Clamp() const; 5639 Heap::Space space = Heap::kNew);
5639 5640
5640 bool IsClamped() const; 5641 static RawTypedData* NewDigitsFromDecCString(const char* str, intptr_t* used,
5642 Heap::Space space = Heap::kNew);
5641 5643
5642 static RawBigint* Allocate(intptr_t length, Heap::Space space = Heap::kNew); 5644 static RawBigint* Allocate(intptr_t length, Heap::Space space = Heap::kNew);
5643 5645
5644 FINAL_HEAP_OBJECT_IMPLEMENTATION(Bigint, Integer); 5646 FINAL_HEAP_OBJECT_IMPLEMENTATION(Bigint, Integer);
5645 friend class Class; 5647 friend class Class;
5646 }; 5648 };
5647 5649
5648 5650
5649 // Class Double represents class Double in corelib_impl, which implements 5651 // Class Double represents class Double in corelib_impl, which implements
5650 // abstract class double in corelib. 5652 // abstract class double in corelib.
(...skipping 2112 matching lines...) Expand 10 before | Expand all | Expand 10 after
7763 7765
7764 7766
7765 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 7767 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
7766 intptr_t index) { 7768 intptr_t index) {
7767 return array.At((index * kEntryLength) + kTargetFunctionIndex); 7769 return array.At((index * kEntryLength) + kTargetFunctionIndex);
7768 } 7770 }
7769 7771
7770 } // namespace dart 7772 } // namespace dart
7771 7773
7772 #endif // VM_OBJECT_H_ 7774 #endif // VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698