Refactored Array, Code to be Objects. Removed Object tagging.
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);
34 map->init(type, contained);
39 SizeFor(Type *type, unsigned elements)
41 if (type->levels() > 1)
42 return sizeof(Array) + elements * sizeof(jc::Object *);
43 if (type->contained()->isInt())
44 return sizeof(Array) + elements * sizeof(int);
45 assert(type->contained()->isFloat());
46 return sizeof(Array) + elements * sizeof(float);
50 Array::init(uint32 nelements)
52 WRITE_FIELD(nelements, nelements);
53 WRITE_FIELD(elements, VoidPtr(this + 1));
57 Array::New(Zone *zone, ArrayMap *map, uint32 elements, Heap::Tenure tenure)
60 size_t bytes = SizeFor(map->type(), elements);
61 Object *obj = zone->allocate(map, bytes, tenure);
65 Array *array = Array::cast(obj);
66 array->init(elements);
67 return Array::cast(obj);