diff -r eaa43f765cbd -r 06a0015b6a5c jitcraft/Structures.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jitcraft/Structures.cpp Mon Jul 23 01:19:44 2012 -0700 @@ -0,0 +1,46 @@ +/* vim: set ts=4 sw=4 tw=99 et + * + * 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 "Structures.h" +#include "Types.h" + +using namespace ke; + +StructureBufferBuilder::StructureBufferBuilder() + : size_(0) +{ +} + +bool +StructureBufferBuilder::add(Handle type, unsigned *offset) +{ + *offset = size_; + + if (!type->isTraceable()) { + // For now, assume the size of primitives is 4-byte. + assert(type->isInt32() || type->isFloat()); + size_ += 4; + return true; + } + + if (!offsets_.append(size_)) + return false; + + size_ += sizeof(Object *); + return true; +}