Added runtime support for default arguments.
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/.
21 #include "TypeManager.h"
24 #include "Spaces-inl.h"
30 TypeManager::TypeManager(Zone *zone)
36 TypeManager::initialize()
38 voidType_ = Type::NewVoid(zone_);
42 uncheckedType_ = Type::NewUnchecked(zone_);
46 if ((primitiveTypes_[PrimitiveType_Int32] = Type::NewPrimitive(zone_, PrimitiveType_Int32)) == NULL)
48 if ((primitiveTypes_[PrimitiveType_Float] = Type::NewPrimitive(zone_, PrimitiveType_Float)) == NULL)
50 if ((primitiveTypes_[PrimitiveType_Native] = Type::NewPrimitive(zone_, PrimitiveType_Native)) == NULL)
52 if ((primitiveTypes_[PrimitiveType_Char] = Type::NewPrimitive(zone_, PrimitiveType_Char)) == NULL)
54 if ((primitiveTypes_[PrimitiveType_Bool] = Type::NewPrimitive(zone_, PrimitiveType_Bool)) == NULL)
57 Local<Type> type(zone_);
58 for (unsigned i = 0; i < PrimitiveTypes_Total; i++) {
59 type = primitiveTypes_[i];
60 if ((referenceTypes_[i] = Type::NewReference(zone_, type, false)) == NULL)
68 TypeManager::unsafeArray(Handle<Type> contained, int elements, bool isConst)
71 return Type::NewArray(zone_, contained, elements, isConst);
75 TypeManager::getReference(Handle<Type> type, bool isConst)
77 if (!isConst && type->isPrimitive())
78 return referenceTypes_[type->primitive()];
81 return Type::NewReference(zone_, type, isConst);
85 TypeManager::newFunction(Handle<Type> returnType, Handle<FixedArray> args,
86 Handle<FixedArray> defaults)
89 return Type::NewFunction(zone_, returnType, args, defaults);
93 TypeManager::newNative(Handle<Type> returnType, Handle<FixedArray> args,
94 Handle<FixedArray> defaults, bool variadic)
97 return Type::NewNative(zone_, returnType, args, defaults, variadic);
101 TypeManager::newEnum(Handle<String> name)
103 return Type::NewEnum(zone_, name);
107 TypeManager::newStruct(Handle<String> name, Handle<FixedArray> fields, Handle<Map> newMap)
109 return Type::NewStruct(zone_, name, fields, newMap);
113 TypeManager::accept(VirtualObjectVisitor *visitor)
115 visitor->visit(voidType_.address());
116 visitor->visit(uncheckedType_.address());
117 for (unsigned i = 0; i < PrimitiveTypes_Total; i++) {
118 visitor->visit(primitiveTypes_[i].address());
119 visitor->visit(referenceTypes_[i].address());