| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/dart.h" | 9 #include "vm/dart.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| (...skipping 2759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2770 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew) { | 2770 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew) { |
| 2771 return reinterpret_cast<RawImmutableArray*>(Array::New(len, true, space)); | 2771 return reinterpret_cast<RawImmutableArray*>(Array::New(len, true, space)); |
| 2772 } | 2772 } |
| 2773 | 2773 |
| 2774 private: | 2774 private: |
| 2775 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); | 2775 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); |
| 2776 friend class Class; | 2776 friend class Class; |
| 2777 }; | 2777 }; |
| 2778 | 2778 |
| 2779 | 2779 |
| 2780 class ByteBuffer : public Instance { |
| 2781 public: |
| 2782 intptr_t Length() const { |
| 2783 ASSERT(!IsNull()); |
| 2784 return Smi::Value(raw_ptr()->length_); |
| 2785 } |
| 2786 |
| 2787 template<typename T> |
| 2788 T At(intptr_t index) const { |
| 2789 return *Addr<T>(index); |
| 2790 } |
| 2791 template<typename T> |
| 2792 void SetAt(intptr_t index, T value) const { |
| 2793 *Addr<T>(index) = value; |
| 2794 } |
| 2795 |
| 2796 virtual bool Equals(const Instance& other) const; |
| 2797 |
| 2798 static intptr_t InstanceSize() { |
| 2799 return RoundedAllocationSize(sizeof(RawByteBuffer)); |
| 2800 } |
| 2801 |
| 2802 static RawByteBuffer* New(uint8_t* data, |
| 2803 intptr_t len, |
| 2804 Heap::Space space = Heap::kNew); |
| 2805 |
| 2806 private: |
| 2807 template<typename T> |
| 2808 T* Addr(intptr_t index) const { |
| 2809 intptr_t base = index * sizeof(T); |
| 2810 intptr_t limit = base + sizeof(T); |
| 2811 // TODO(iposva): Determine if we should throw an exception here. |
| 2812 ASSERT((base >= 0) && (limit <= Length())); |
| 2813 uint8_t* addr = &raw_ptr()->data_[base]; |
| 2814 return reinterpret_cast<T*>(addr); |
| 2815 } |
| 2816 |
| 2817 void SetLength(intptr_t value) { |
| 2818 raw_ptr()->length_ = Smi::New(value); |
| 2819 } |
| 2820 |
| 2821 void SetData(uint8_t* data) const { |
| 2822 raw_ptr()->data_ = data; |
| 2823 } |
| 2824 |
| 2825 HEAP_OBJECT_IMPLEMENTATION(ByteBuffer, Instance); |
| 2826 friend class Class; |
| 2827 }; |
| 2828 |
| 2829 |
| 2780 class Closure : public Instance { | 2830 class Closure : public Instance { |
| 2781 public: | 2831 public: |
| 2782 RawFunction* function() const { return raw_ptr()->function_; } | 2832 RawFunction* function() const { return raw_ptr()->function_; } |
| 2783 static intptr_t function_offset() { | 2833 static intptr_t function_offset() { |
| 2784 return OFFSET_OF(RawClosure, function_); | 2834 return OFFSET_OF(RawClosure, function_); |
| 2785 } | 2835 } |
| 2786 | 2836 |
| 2787 RawContext* context() const { return raw_ptr()->context_; } | 2837 RawContext* context() const { return raw_ptr()->context_; } |
| 2788 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); } | 2838 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); } |
| 2789 | 2839 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2983 } | 3033 } |
| 2984 | 3034 |
| 2985 | 3035 |
| 2986 void Context::SetAt(intptr_t index, const Instance& value) const { | 3036 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 2987 StorePointer(InstanceAddr(index), value.raw()); | 3037 StorePointer(InstanceAddr(index), value.raw()); |
| 2988 } | 3038 } |
| 2989 | 3039 |
| 2990 } // namespace dart | 3040 } // namespace dart |
| 2991 | 3041 |
| 2992 #endif // VM_OBJECT_H_ | 3042 #endif // VM_OBJECT_H_ |
| OLD | NEW |