Added error reporting API and fixed all known error paths.
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/.
26 Type::NewPrimitive(Zone *zone, Handle<String> tag)
28 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
32 type->kind_ = PRIMITIVE;
34 type->contained_ = NULL;
35 type->returnType_ = NULL;
36 type->parameters_ = NULL;
38 if (tag && strcmp(tag->chars(), "Float") == 0)
39 type->primitive_ = PrimitiveType_Float;
40 else if (tag && strcmp(tag->chars(), "String") == 0)
41 type->primitive_ = PrimitiveType_Char;
43 type->primitive_ = PrimitiveType_Int32;
48 Type::NewPrimitive(Zone *zone, PrimitiveType prim)
50 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
54 type->kind_ = PRIMITIVE;
56 type->contained_ = NULL;
57 type->returnType_ = NULL;
58 type->parameters_ = NULL;
59 type->primitive_ = prim;
64 Type::NewArray(Zone *zone, Handle<Type> contained, int elements, bool isConst)
66 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
72 type->contained_ = contained;
73 type->returnType_ = NULL;
74 type->parameters_ = NULL;
75 type->elements_ = elements;
76 if (contained->isPrimitive())
79 type->levels_ = contained->levels() + 1;
80 type->const_ = isConst;
85 Type::NewReference(Zone *zone, Handle<Type> contained, bool isConst)
87 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
91 type->kind_ = REFERENCE;
93 type->contained_ = contained;
94 type->returnType_ = NULL;
95 type->parameters_ = NULL;
96 type->const_ = isConst;
101 Type::NewFunction(Zone *zone, Handle<Type> returnType, Handle<FixedArray> parameters)
103 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
107 type->kind_ = FUNCTION;
108 type->contained_ = NULL;
109 type->returnType_ = returnType;
110 type->parameters_ = parameters;
115 Type::NewNative(Zone *zone, Handle<Type> returnType, Handle<FixedArray> parameters, bool variadic)
117 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
121 type->kind_ = NATIVE;
122 type->contained_ = NULL;
123 type->returnType_ = returnType;
124 type->parameters_ = parameters;
125 type->variadicNative_ = variadic;
130 Type::Compare(Type *left, Type *right)
132 if (left->kind() != right->kind())
135 switch (left->kind()) {
136 case Type::PRIMITIVE:
137 return (left->primitive() == right->primitive() &&
138 left->tag() == right->tag());
142 if (left->levels() != right->levels())
144 if (left->elements() != right->elements())
146 return Compare(left->contained(), right->contained());
151 if (!Compare(left->returnType(), right->returnType()))
153 if (left->parameters()->length() != right->parameters()->length())
155 if (left->isNative() != right->isNative())
157 if (left->isNative() && (left->isNativeVariadic() != right->isNativeVariadic()))
159 for (unsigned i = 0; i < left->parameters()->length(); i++) {
160 Type *leftparam = left->parameterAt(i);
161 Type *rightparam = right->parameterAt(i);
162 if (!Compare(leftparam, rightparam))
169 assert(left->kind() == Type::REFERENCE);
170 return Compare(left->contained(), right->contained());