1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of JITCraft.
7 * JITCraft is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * JITCraft. If not, see http://www.gnu.org/licenses/.
20 #include "TypeManager.h"
27 TypeManager::TypeManager(Zone *zone)
33 TypeManager::initialize()
35 Local<String> floatTag(zone_, zone_->makeSymbol("Float"));
39 Local<String> stringTag(zone_, zone_->makeSymbol("String"));
43 Local<String> nullTag(zone_);
45 if ((primitiveTypes_[PrimitiveType_Int32] = Type::NewPrimitive(zone_, nullTag)) == NULL)
47 if ((primitiveTypes_[PrimitiveType_Float] = Type::NewPrimitive(zone_, floatTag)) == NULL)
49 if ((primitiveTypes_[PrimitiveType_Native] = Type::NewPrimitive(zone_, PrimitiveType_Native)) == NULL)
51 if ((primitiveTypes_[PrimitiveType_Char] = Type::NewPrimitive(zone_, stringTag)) == NULL)
54 Local<Type> type(zone_);
55 for (unsigned i = 0; i < PrimitiveTypes_Total; i++) {
56 type = primitiveTypes_[i];
57 if ((referenceTypes_[i] = Type::NewReference(zone_, type)) == NULL)
65 TypeManager::getPrimitiveForTag(Handle<String> tag)
68 return getPrimitive(PrimitiveType_Int32);
69 if (strcmp(tag->chars(), "Float") == 0)
70 return getPrimitive(PrimitiveType_Float);
71 if (strcmp(tag->chars(), "String") == 0)
72 return getPrimitive(PrimitiveType_Char);
77 TypeManager::unsafeArray(Handle<Type> contained, int elements)
80 return Type::NewArray(zone_, contained, elements, false);
84 TypeManager::getReference(Handle<Type> type)
86 if (type->isFloat() || (type->isInt32() && !type->tag()))
87 return referenceTypes_[type->primitive()];
90 return Type::NewReference(zone_, type);
94 TypeManager::newFunction(Handle<Type> returnType, Handle<FixedArray> args)
97 return Type::NewFunction(zone_, returnType, args);
101 TypeManager::accept(VirtualObjectVisitor *visitor)
103 for (unsigned i = 0; i < PrimitiveTypes_Total; i++) {
104 visitor->visit(primitiveTypes_[i].address());
105 visitor->visit(referenceTypes_[i].address());