Added incdec support for fields.
2 * Copyright (C) 2012 David Anderson
4 * This file is part of JITCraft.
6 * JITCraft is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
11 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * JITCraft. If not, see http://www.gnu.org/licenses/.
27 ArrayMap::New(Zone *zone, Handle<Type> type, Handle<ArrayMap> contained)
29 Local<Map> obj(zone, zone->allocateMap(MapKind_Array, sizeof(ArrayMap), MapKind_MetaArray));
33 Local<ArrayMap> map(zone, ArrayMap::cast(obj));
35 map->contained_ = contained;
40 SizeFor(Type *type, unsigned elements)
42 if (type->levels() > 1)
43 return sizeof(Array) + elements * sizeof(ke::Object *);
44 if (type->contained()->isInt32())
45 return sizeof(Array) + elements * sizeof(int);
46 if (type->contained()->primitive() == PrimitiveType_Char)
47 return sizeof(Array) + elements * sizeof(char);
48 assert(type->contained()->isFloat());
49 return elements * sizeof(float);
53 Array::New(Zone *zone, Handle<ArrayMap> map, uint32 elements, Heap::Tenure tenure)
55 size_t elementBytes = SizeFor(map->type(), elements);
56 size_t bytes = sizeof(Array) + elementBytes;
57 Local<Array> array(zone, Array::cast(zone->allocate(map, bytes, tenure)));
61 array->nelements_ = elements;
62 array->elements_ = (Array *)array + 1;
63 memset(array->elements_, 0, elementBytes);
68 Array::NewExternal(Zone *zone, Handle<ArrayMap> map, uint32 nelements, void *buffer,
71 Local<Array> array(zone, Array::cast(zone->allocate(map, sizeof(Array), tenure)));
75 array->nelements_ = nelements;
76 array->elements_ = buffer;