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

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

Issue 8429027: Add an external array type to support typed arrays. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: wrap another native, tweak whitespace Created 9 years, 1 month 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) 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 2776 matching lines...) Expand 10 before | Expand all | Expand 10 after
2787 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew) { 2787 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew) {
2788 return reinterpret_cast<RawImmutableArray*>(Array::New(len, true, space)); 2788 return reinterpret_cast<RawImmutableArray*>(Array::New(len, true, space));
2789 } 2789 }
2790 2790
2791 private: 2791 private:
2792 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); 2792 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array);
2793 friend class Class; 2793 friend class Class;
2794 }; 2794 };
2795 2795
2796 2796
2797 class ByteBuffer : public Instance {
2798 public:
2799 intptr_t Length() const {
2800 ASSERT(!IsNull());
2801 return Smi::Value(raw_ptr()->length_);
2802 }
2803
2804 template<typename T>
2805 T At(intptr_t byte_offset) const {
2806 ASSERT(Utils::IsAligned(byte_offset, sizeof(T)));
Ivan Posva 2011/11/16 22:50:01 Shouldn't this check for (base_address + byte_offs
cshapiro 2011/11/17 03:17:02 It depends on whether the base address will ever b
2807 return *Addr<T>(byte_offset);
2808 }
2809 template<typename T>
2810 void SetAt(intptr_t byte_offset, T value) const {
2811 ASSERT(Utils::IsAligned(byte_offset, sizeof(T)));
Ivan Posva 2011/11/16 22:50:01 ditto
cshapiro 2011/11/17 03:17:02 Done.
2812 *Addr<T>(byte_offset) = value;
2813 }
2814
2815 template<typename T>
2816 T UnalignedAt(intptr_t byte_offset) const {
2817 T result;
2818 memmove(&result, Addr<T>(byte_offset), sizeof(T));
2819 return result;
2820 }
2821 template<typename T>
2822 void SetUnalignedAt(intptr_t byte_offset, T value) const {
2823 memmove(Addr<T>(byte_offset), &value, sizeof(T));
2824 }
2825
2826 virtual bool Equals(const Instance& other) const;
2827
2828 static intptr_t InstanceSize() {
2829 return RoundedAllocationSize(sizeof(RawByteBuffer));
2830 }
2831
2832 static RawByteBuffer* New(uint8_t* data,
2833 intptr_t len,
2834 Heap::Space space = Heap::kNew);
2835
2836 private:
2837 template<typename T>
2838 T* Addr(intptr_t byte_offset) const {
2839 intptr_t limit = byte_offset + sizeof(T);
2840 // TODO(iposva): Determine if we should throw an exception here.
2841 ASSERT((byte_offset >= 0) && (limit <= Length()));
2842 uint8_t* addr = &raw_ptr()->data_[byte_offset];
2843 return reinterpret_cast<T*>(addr);
2844 }
2845
2846 void SetLength(intptr_t value) {
2847 raw_ptr()->length_ = Smi::New(value);
2848 }
2849
2850 void SetData(uint8_t* data) const {
2851 raw_ptr()->data_ = data;
2852 }
2853
2854 HEAP_OBJECT_IMPLEMENTATION(ByteBuffer, Instance);
2855 friend class Class;
2856 };
2857
2858
2797 class Closure : public Instance { 2859 class Closure : public Instance {
2798 public: 2860 public:
2799 RawFunction* function() const { return raw_ptr()->function_; } 2861 RawFunction* function() const { return raw_ptr()->function_; }
2800 static intptr_t function_offset() { 2862 static intptr_t function_offset() {
2801 return OFFSET_OF(RawClosure, function_); 2863 return OFFSET_OF(RawClosure, function_);
2802 } 2864 }
2803 2865
2804 RawContext* context() const { return raw_ptr()->context_; } 2866 RawContext* context() const { return raw_ptr()->context_; }
2805 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); } 2867 static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); }
2806 2868
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
3000 } 3062 }
3001 3063
3002 3064
3003 void Context::SetAt(intptr_t index, const Instance& value) const { 3065 void Context::SetAt(intptr_t index, const Instance& value) const {
3004 StorePointer(InstanceAddr(index), value.raw()); 3066 StorePointer(InstanceAddr(index), value.raw());
3005 } 3067 }
3006 3068
3007 } // namespace dart 3069 } // namespace dart
3008 3070
3009 #endif // VM_OBJECT_H_ 3071 #endif // VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698