Basic support for parsing and creating types from structure syntax.
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/.
20 #include "FixedArray.h"
26 static const unsigned kMaxFixedArrayLength = ((INT_MAX - sizeof(FixedArray)) / sizeof(ke::Object *));
29 FixedArray::New(Zone *zone, unsigned length, Heap::Tenure tenure)
31 if (length >= kMaxFixedArrayLength) {
32 zone->reportError(Message_ArrayTooBig);
36 Local<FixedArray> array(zone, FixedArray::cast(zone->allocate(MapKind_FixedArray, SizeFor(length), tenure)));
40 array->length_ = length;
41 memset(array->vec(), 0, length * sizeof(Object *));
46 ByteArray::New(Zone *zone, unsigned length, Heap::Tenure tenure)
48 if (length >= kMaxFixedArrayLength) {
49 zone->reportError(Message_ArrayTooBig);
53 Local<ByteArray> array(zone, ByteArray::cast(zone->allocate(MapKind_ByteArray, SizeFor(length), tenure)));
57 array->length_ = length;
58 memset(array->raw(), 0, length);
63 ByteArray::New(Zone *zone, Handle<Map> map, unsigned length, Heap::Tenure tenure)
65 if (length >= kMaxFixedArrayLength) {
66 zone->reportError(Message_ArrayTooBig);
70 Local<ByteArray> array(zone, ByteArray::cast(zone->allocate(map, SizeFor(length), tenure)));
74 array->length_ = length;
75 memset(array->raw(), 0, length);