Implement re-tag unary expression.
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/.
27 Type::NewVoid(Zone *zone)
29 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
35 type->contained_ = NULL;
36 type->returnType_ = NULL;
37 type->parameters_ = NULL;
42 Type::NewPrimitive(Zone *zone, Handle<String> tag)
44 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
48 assert(!tag || strcmp(tag->chars(), "_"));
50 type->kind_ = PRIMITIVE;
52 type->contained_ = NULL;
53 type->returnType_ = NULL;
54 type->parameters_ = NULL;
56 if (tag && strcmp(tag->chars(), "Float") == 0)
57 type->primitive_ = PrimitiveType_Float;
58 else if (tag && strcmp(tag->chars(), "String") == 0)
59 type->primitive_ = PrimitiveType_Char;
61 type->primitive_ = PrimitiveType_Int32;
66 Type::NewPrimitive(Zone *zone, PrimitiveType prim)
68 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
72 type->kind_ = PRIMITIVE;
74 type->contained_ = NULL;
75 type->returnType_ = NULL;
76 type->parameters_ = NULL;
77 type->primitive_ = prim;
82 Type::NewArray(Zone *zone, Handle<Type> contained, int elements, bool isConst)
84 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
90 type->contained_ = contained;
91 type->returnType_ = NULL;
92 type->parameters_ = NULL;
93 type->elements_ = elements;
94 if (contained->isPrimitive())
97 type->levels_ = contained->levels() + 1;
98 type->const_ = isConst;
103 Type::NewReference(Zone *zone, Handle<Type> contained, bool isConst)
105 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
109 type->kind_ = REFERENCE;
111 type->contained_ = contained;
112 type->returnType_ = NULL;
113 type->parameters_ = NULL;
114 type->const_ = isConst;
119 Type::NewFunction(Zone *zone, Handle<Type> returnType, Handle<FixedArray> parameters)
121 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
125 type->kind_ = FUNCTION;
126 type->contained_ = NULL;
127 type->returnType_ = returnType;
128 type->parameters_ = parameters;
133 Type::NewNative(Zone *zone, Handle<Type> returnType, Handle<FixedArray> parameters, bool variadic)
135 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
139 type->kind_ = NATIVE;
140 type->contained_ = NULL;
141 type->returnType_ = returnType;
142 type->parameters_ = parameters;
143 type->variadicNative_ = variadic;
148 Type::Compare(Type *left, Type *right)
150 if (left->kind() != right->kind())
153 switch (left->kind()) {
154 case Type::PRIMITIVE:
155 return (left->primitive() == right->primitive() &&
156 left->tag() == right->tag());
160 if (left->levels() != right->levels())
162 if (left->elements() != right->elements())
164 return Compare(left->contained(), right->contained());
169 if (!Compare(left->returnType(), right->returnType()))
171 if (left->parameters()->length() != right->parameters()->length())
173 if (left->isNative() != right->isNative())
175 if (left->isNative() && (left->isNativeVariadic() != right->isNativeVariadic()))
177 for (unsigned i = 0; i < left->parameters()->length(); i++) {
178 Type *leftparam = left->parameterAt(i);
179 Type *rightparam = right->parameterAt(i);
180 if (!Compare(leftparam, rightparam))
190 assert(left->kind() == Type::REFERENCE);
191 return Compare(left->contained(), right->contained());