Added support for arbitrary expression references.
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/.
26 ArrayMap::New(Zone *zone, Type *type, ArrayMap *contained)
29 Map *obj = zone->allocateMap(MapKind_Array, sizeof(ArrayMap), MapKind_MetaArray);
33 ArrayMap *map = ArrayMap::cast(obj);
35 map->contained_ = contained;
40 SizeFor(Type *type, unsigned elements)
42 if (type->levels() > 1)
43 return sizeof(Array) + elements * sizeof(jc::Object *);
44 if (type->contained()->isInt())
45 return sizeof(Array) + elements * sizeof(int);
46 assert(type->contained()->isFloat());
47 return sizeof(Array) + elements * sizeof(float);
51 Array::New(Zone *zone, ArrayMap *map, uint32 elements, Heap::Tenure tenure)
54 size_t bytes = SizeFor(map->type(), elements);
55 Object *obj = zone->allocate(map, bytes, tenure);
59 Array *array = Array::cast(obj);
60 array->nelements_ = elements;
61 array->elements_ = VoidPtr(array + 1);
62 return Array::cast(obj);