Chromium Code Reviews| 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 2745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2756 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew) { | 2756 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew) { |
| 2757 return reinterpret_cast<RawImmutableArray*>(Array::New(len, true, space)); | 2757 return reinterpret_cast<RawImmutableArray*>(Array::New(len, true, space)); |
| 2758 } | 2758 } |
| 2759 | 2759 |
| 2760 private: | 2760 private: |
| 2761 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); | 2761 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); |
| 2762 friend class Class; | 2762 friend class Class; |
| 2763 }; | 2763 }; |
| 2764 | 2764 |
| 2765 | 2765 |
| 2766 class ExternalArray : public Instance { | |
| 2767 public: | |
| 2768 intptr_t Length() const { | |
| 2769 ASSERT(!IsNull()); | |
| 2770 return Smi::Value(raw_ptr()->length_); | |
| 2771 } | |
| 2772 | |
| 2773 int8_t Int8At(intptr_t index) const { | |
| 2774 return *Addr<int8_t>(index); | |
| 2775 } | |
| 2776 void SetInt8At(intptr_t index, int8_t value) const { | |
| 2777 *Addr<int8_t>(index) = value; | |
| 2778 } | |
| 2779 | |
| 2780 uint8_t Uint8At(intptr_t index) const { | |
| 2781 return *Addr<uint8_t>(index); | |
| 2782 } | |
| 2783 void SetUint8At(intptr_t index, uint8_t value) const { | |
| 2784 *Addr<uint8_t>(index) = value; | |
| 2785 } | |
| 2786 | |
| 2787 int16_t Int16At(intptr_t index) const { | |
| 2788 return *Addr<int16_t>(index); | |
| 2789 } | |
| 2790 void SetInt16At(intptr_t index, int16_t value) const { | |
| 2791 *Addr<int16_t>(index) = value; | |
| 2792 } | |
| 2793 | |
| 2794 uint16_t Uint16At(intptr_t index) const { | |
| 2795 return *Addr<uint16_t>(index); | |
| 2796 } | |
| 2797 void SetUint16At(intptr_t index, uint16_t value) const { | |
| 2798 *Addr<uint16_t>(index) = value; | |
| 2799 } | |
| 2800 | |
| 2801 int32_t Int32At(intptr_t index) const { | |
| 2802 return *Addr<int32_t>(index); | |
| 2803 } | |
| 2804 void SetInt32At(intptr_t index, int32_t value) const { | |
| 2805 *Addr<int32_t>(index) = value; | |
| 2806 } | |
| 2807 | |
| 2808 uint32_t Uint32At(intptr_t index) const { | |
| 2809 return *Addr<uint32_t>(index); | |
| 2810 } | |
| 2811 void SetUint32At(intptr_t index, uint32_t value) const { | |
| 2812 *Addr<uint32_t>(index) = value; | |
| 2813 } | |
| 2814 | |
| 2815 int64_t Int64At(intptr_t index) const { | |
| 2816 return *Addr<int64_t>(index); | |
| 2817 } | |
| 2818 void SetInt64At(intptr_t index, int64_t value) const { | |
| 2819 *Addr<int64_t>(index) = value; | |
| 2820 } | |
| 2821 | |
| 2822 uint64_t Uint64At(intptr_t index) const { | |
| 2823 return *Addr<uint64_t>(index); | |
| 2824 } | |
| 2825 void SetUint64At(intptr_t index, uint64_t value) const { | |
| 2826 *Addr<uint64_t>(index) = value; | |
| 2827 } | |
| 2828 | |
| 2829 float Float32At(intptr_t index) const { | |
| 2830 return *Addr<float>(index); | |
| 2831 } | |
| 2832 void SetFloat32At(intptr_t index, float value) const { | |
| 2833 *Addr<float>(index) = value; | |
| 2834 } | |
| 2835 | |
| 2836 double Float64At(intptr_t index) const { | |
| 2837 return *Addr<double>(index); | |
| 2838 } | |
| 2839 void SetFloat64At(intptr_t index, double value) const { | |
| 2840 *Addr<double>(index) = value; | |
| 2841 } | |
| 2842 | |
| 2843 virtual bool Equals(const Instance& other) const; | |
| 2844 | |
| 2845 static intptr_t InstanceSize() { | |
| 2846 return RoundedAllocationSize(sizeof(RawExternalArray)); | |
| 2847 } | |
| 2848 | |
| 2849 static RawExternalArray* New(uint8_t* data, | |
| 2850 intptr_t len, | |
| 2851 Heap::Space space = Heap::kNew); | |
| 2852 | |
| 2853 private: | |
| 2854 template<typename T> | |
| 2855 T* Addr(intptr_t index) const { | |
| 2856 intptr_t byte_start = index / sizeof(T); | |
|
siva
2011/11/02 17:05:31
is this right:
for instance Addr<int32_t>(1) shou
cshapiro
2011/11/04 18:16:21
No, it was not. I fixed this in the more recent p
| |
| 2857 intptr_t byte_end = byte_start + sizeof(T); | |
| 2858 // TODO(iposva): Determine if we should throw an exception here. | |
| 2859 ASSERT((byte_start >= 0) && (byte_end < Length())); | |
| 2860 uint8_t* addr = &raw_ptr()->data_[byte_start]; | |
| 2861 return reinterpret_cast<T*>(addr); | |
| 2862 } | |
| 2863 | |
| 2864 void SetLength(intptr_t value) { | |
| 2865 raw_ptr()->length_ = Smi::New(value); | |
| 2866 } | |
| 2867 | |
| 2868 void SetData(uint8_t* data) const { | |
| 2869 raw_ptr()->data_ = data; | |
| 2870 } | |
| 2871 | |
| 2872 HEAP_OBJECT_IMPLEMENTATION(ExternalArray, Instance); | |
| 2873 friend class Class; | |
| 2874 }; | |
| 2875 | |
| 2876 | |
| 2766 class Closure : public Instance { | 2877 class Closure : public Instance { |
| 2767 public: | 2878 public: |
| 2768 RawFunction* function() const { return raw_ptr()->function_; } | 2879 RawFunction* function() const { return raw_ptr()->function_; } |
| 2769 static intptr_t function_offset() { | 2880 static intptr_t function_offset() { |
| 2770 return OFFSET_OF(RawClosure, function_); | 2881 return OFFSET_OF(RawClosure, function_); |
| 2771 } | 2882 } |
| 2772 | 2883 |
| 2773 RawContext* context() const { return raw_ptr()->context_; } | 2884 RawContext* context() const { return raw_ptr()->context_; } |
| 2774 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); } | 2885 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); } |
| 2775 | 2886 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2969 } | 3080 } |
| 2970 | 3081 |
| 2971 | 3082 |
| 2972 void Context::SetAt(intptr_t index, const Instance& value) const { | 3083 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 2973 StorePointer(InstanceAddr(index), value.raw()); | 3084 StorePointer(InstanceAddr(index), value.raw()); |
| 2974 } | 3085 } |
| 2975 | 3086 |
| 2976 } // namespace dart | 3087 } // namespace dart |
| 2977 | 3088 |
| 2978 #endif // VM_OBJECT_H_ | 3089 #endif // VM_OBJECT_H_ |
| OLD | NEW |