Get preinc working again.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of SourcePawn.
7 * SourcePawn is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * SourcePawn. If not, see http://www.gnu.org/licenses/.
19 #ifndef _include_jitcraft_array_h_
20 #define _include_jitcraft_array_h_
25 #include "FixedArray.h"
31 class Array : public Object
33 friend class ArrayMap;
35 // Note: we do not write barrier |elements_|, since it can be set to
36 // arbitrary pointers.
44 void updateLengthAndElements(Zone *zone, unsigned length, Object *array) {
46 write(zone, &objelements_, array);
50 static Array *NewFixed(Zone *zone, Handle<ArrayMap> map, Heap::Tenure = Heap::Tenure_Default);
51 static Array *NewString(Zone *zone, Handle<ArrayMap> map, Address buffer, size_t length, Heap::Tenure = Heap::Tenure_Default);
52 static Array *NewSized(Zone *zone, Handle<ArrayMap> map, int sizes[MAX_ARRAY_DEPTH], Heap::Tenure = Heap::Tenure_Default);
54 static Array *New1D(Zone *zone, Handle<ArrayMap> map, uint32 elements, Heap::Tenure tenure = Heap::Tenure_Default);
55 static Array *NewEmpty(Zone *zone, Handle<ArrayMap> map, Heap::Tenure tenure = Heap::Tenure_Default);
56 static Array *NewRaw(Zone *zone, Handle<ArrayMap> map, unsigned nelements, Heap::Tenure tenure);
58 static Array *NewExternal(Zone *zone,
62 Heap::Tenure tenure = Heap::Tenure_Default);
68 inline ArrayType *type();
70 inline int *int32Vec();
71 inline float *floatVec();
76 static inline size_t SizeForElement(ArrayType *type) {
77 if (type->contained()->isTraceable())
78 return sizeof(ke::Object *);
79 if (type->contained()->isInt32())
81 if (type->contained()->primitive() == PrimitiveType_Char)
83 assert(type->contained()->isFloat());
87 inline size_t objSize(ArrayMap *map);
89 int readInt32(size_t index) {
90 assert(index < length());
91 return int32Vec()[index];
93 void writeInt32(size_t index, int i) {
94 assert(index < length());
95 int32Vec()[index] = i;
97 char readChar(size_t index) {
98 assert(index < length());
99 return chars()[index];
101 void writeChar(size_t index, char c) {
102 assert(index < length());
105 float readFloat(size_t index) {
106 assert(index < length());
107 return floatVec()[index];
109 void writeFloat(size_t index, float f) {
110 assert(index < length());
111 floatVec()[index] = f;
113 Object *readObject(size_t index) {
114 return FixedArray::cast(objelements_)->at(index);
116 void writeObject(Zone *zone, size_t index, Object *ptr) {
117 FixedArray::cast(objelements_)->set(zone, index, ptr);
121 static inline size_t offsetOfElements() {
122 return offsetof(Array, objelements_);
124 // End GC Descriptor.
126 static Array *cast(Object *obj) {
127 assert(!obj || obj->is(MapKind_Array));
128 return reinterpret_cast<Array *>(obj);
132 class ArrayMap : public Map
134 Barriered<ArrayType> type_;
137 static ArrayMap *New(Zone *zone, Handle<ArrayType> type);
138 static ArrayMap *Attach(Zone *zone, Handle<ArrayType> type);
145 static inline size_t offsetOfType() {
146 return OFFSETOF(ArrayMap, type_);
148 // End GC Descriptor.
150 static ArrayMap *cast(Object *obj) {
151 assert(!obj || obj->is(MapKind_MetaArray));
152 return reinterpret_cast<ArrayMap *>(obj);
159 assert(!type()->contained()->isTraceable());
160 assert(type()->hasInlineElements() ||
161 type()->isExternalArray() ||
163 ByteArray::cast((Object *)elements_));
165 return Address(elements_) + ByteArray::offsetToElements();
171 assert(type()->contained()->isInt32());
172 return reinterpret_cast<int *>(bytes());
178 assert(type()->contained()->isFloat());
179 return reinterpret_cast<float *>(bytes());
185 assert(type()->isCharArray());
186 return reinterpret_cast<char *>(bytes());
192 return ArrayMap::cast(map())->type();
196 Array::objSize(ArrayMap *map)
198 assert(this->map() == map);
199 if (map->type()->hasInlineElements())
200 return sizeof(Array) + Array::SizeForElement(map->type()) * length();
201 return sizeof(Array);
206 #endif // _include_jitcraft_array_h_