diff -r a350c2cc736a -r 75e385f68b7e jitcraft/FixedArray.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jitcraft/FixedArray.cpp Sat Jun 30 19:38:53 2012 -0700 @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2012 David Anderson + * + * This file is part of JITCraft. + * + * JITCraft is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * JITCraft. If not, see http://www.gnu.org/licenses/. + */ +#include +#include "FixedArray.h" +#include "Zone.h" + +using namespace jc; + +static const unsigned kMaxFixedArrayLength = ((INT_MAX - sizeof(FixedArray)) / sizeof(jc::Object *)); + +void +FixedArray::init(unsigned length) +{ + WRITE_FIELD(length, length); +} + +FixedArray * +FixedArray::New(Zone *zone, unsigned length, Heap::Tenure tenure) +{ + // :TODO: error... + if (length >= kMaxFixedArrayLength) { + assert(false); + return NULL; + } + + Object *obj = zone->allocate(MapKind_FixedArray, SizeFor(length), tenure); + if (!obj) + return NULL; + + FixedArray *array = FixedArray::cast(obj); + array->init(length); + return array; +} + +void +ByteArray::init(unsigned length) +{ + WRITE_FIELD(length, length); +} + +ByteArray * +ByteArray::New(Zone *zone, unsigned length, Heap::Tenure tenure) +{ + // :TODO: error... + if (length >= kMaxFixedArrayLength) { + assert(false); + return NULL; + } + + Object *obj = zone->allocate(MapKind_ByteArray, SizeFor(length), tenure); + if (!obj) + return NULL; + + ByteArray *array = ByteArray::cast(obj); + array->init(length); + return array; +} +