Move PrimitiveType_String to a dedicated string type.
Move PrimitiveType_String to a dedicated string type.
1.1 --- a/src/TypeManager.cpp Mon Dec 24 02:49:20 2012 -0800
1.2 +++ b/src/TypeManager.cpp Mon Dec 24 02:56:02 2012 -0800
1.3 @@ -43,6 +43,10 @@
1.4 if (!uncheckedType_)
1.5 return false;
1.6
1.7 + stringType_ = Type::NewString(zone_);
1.8 + if (!stringType_)
1.9 + return false;
1.10 +
1.11 if ((primitiveTypes_[PrimitiveType_Int32] = Type::NewPrimitive(zone_, PrimitiveType_Int32)) == NULL)
1.12 return false;
1.13 if ((primitiveTypes_[PrimitiveType_Float] = Type::NewPrimitive(zone_, PrimitiveType_Float)) == NULL)
1.14 @@ -53,8 +57,6 @@
1.15 return false;
1.16 if ((primitiveTypes_[PrimitiveType_Bool] = Type::NewPrimitive(zone_, PrimitiveType_Bool)) == NULL)
1.17 return false;
1.18 - if ((primitiveTypes_[PrimitiveType_String] = Type::NewPrimitive(zone_, PrimitiveType_String)) == NULL)
1.19 - return false;
1.20
1.21 Local<Type> type(zone_);
1.22 for (unsigned i = 0; i < PrimitiveTypes_Total; i++) {
1.23 @@ -100,6 +102,7 @@
1.24 {
1.25 visitor->visit(voidType_.address());
1.26 visitor->visit(uncheckedType_.address());
1.27 + visitor->visit(stringType_.address());
1.28 for (unsigned i = 0; i < PrimitiveTypes_Total; i++) {
1.29 visitor->visit(primitiveTypes_[i].address());
1.30 visitor->visit(referenceTypes_[i].address());
2.1 --- a/src/TypeManager.h Mon Dec 24 02:49:20 2012 -0800
2.2 +++ b/src/TypeManager.h Mon Dec 24 02:56:02 2012 -0800
2.3 @@ -33,6 +33,7 @@
2.4
2.5 // Primitive type cache.
2.6 Unbarriered<Type> voidType_;
2.7 + Unbarriered<Type> stringType_;
2.8 Unbarriered<Type> uncheckedType_;
2.9 Unbarriered<Type> primitiveTypes_[PrimitiveTypes_Total];
2.10 Unbarriered<ReferenceType> referenceTypes_[PrimitiveTypes_Total];
2.11 @@ -46,6 +47,9 @@
2.12 return primitiveTypes_[type];
2.13 }
2.14
2.15 + Type *getString() {
2.16 + return stringType_;
2.17 + }
2.18 Type *getVoid() {
2.19 return voidType_;
2.20 }
3.1 --- a/src/Types.cpp Mon Dec 24 02:49:20 2012 -0800
3.2 +++ b/src/Types.cpp Mon Dec 24 02:56:02 2012 -0800
3.3 @@ -37,6 +37,17 @@
3.4 }
3.5
3.6 Type *
3.7 +Type::NewString(Zone *zone)
3.8 +{
3.9 + Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
3.10 + if (!type)
3.11 + return NULL;
3.12 +
3.13 + type->kind_ = STRING;
3.14 + return type;
3.15 +}
3.16 +
3.17 +Type *
3.18 Type::NewUnchecked(Zone *zone)
3.19 {
3.20 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
4.1 --- a/src/Types.h Mon Dec 24 02:49:20 2012 -0800
4.2 +++ b/src/Types.h Mon Dec 24 02:56:02 2012 -0800
4.3 @@ -57,9 +57,6 @@
4.4 // on 64-bit systems), and does not exist in language semantics.
4.5 PrimitiveType_Native,
4.6
4.7 - // Internal string object.
4.8 - PrimitiveType_String,
4.9 -
4.10 PrimitiveTypes_Total
4.11 };
4.12
4.13 @@ -70,6 +67,25 @@
4.14 // A primitive is a plain-old-data type.
4.15 PRIMITIVE,
4.16
4.17 + // Void is an internal type used to specify that a function returns no
4.18 + // value.
4.19 + VOID,
4.20 +
4.21 + // Enums are plain-old-data with int32 storage. They allow for extra
4.22 + // type checking that would not be possible with integers.
4.23 + ENUM,
4.24 +
4.25 + // Unchecked is a magic type that has implicit, bitwise coercion to
4.26 + // int32, float, bool, or an enum.
4.27 + UNCHECKED,
4.28 +
4.29 + // ------ Add traceable types below -------
4.30 +
4.31 + // An immutable type that is a primitive in terms of language
4.32 + // semantics, but gets a special type here to make internal
4.33 + // logic easier.
4.34 + STRING,
4.35 +
4.36 // An array is a fixed-length vector of any other type.
4.37 ARRAY,
4.38 EXTERNAL_ARRAY,
4.39 @@ -81,21 +97,9 @@
4.40 // A function type encapsulates a function signature.
4.41 FUNCTION,
4.42
4.43 - // Void is an internal type used to specify that a function returns no
4.44 - // value.
4.45 - VOID,
4.46 -
4.47 - // Enums are plain-old-data with int32 storage. They allow for extra
4.48 - // type checking that would not be possible with integers.
4.49 - ENUM,
4.50 -
4.51 // Structs are composite records that may contain primitives, arrays,
4.52 // functions, enums, and other structs.
4.53 - STRUCT,
4.54 -
4.55 - // Unchecked is a magic type that has implicit, bitwise coercion to
4.56 - // int32, float, bool, or an enum.
4.57 - UNCHECKED
4.58 + STRUCT
4.59 };
4.60
4.61 private:
4.62 @@ -107,6 +111,7 @@
4.63 static Type *NewVoid(Zone *zone);
4.64 static Type *NewUnchecked(Zone *zone);
4.65 static Type *NewPrimitive(Zone *zone, PrimitiveType type);
4.66 + static Type *NewString(Zone *zone);
4.67
4.68 static bool Compare(Type *left, Type *right);
4.69
4.70 @@ -173,17 +178,13 @@
4.71 return isPrimitive() && primitive() == PrimitiveType_Bool;
4.72 }
4.73 bool isString() {
4.74 - return isPrimitive() && primitive() == PrimitiveType_String;
4.75 + return kind() == STRING;
4.76 }
4.77 bool isExternalArray() {
4.78 return kind() == EXTERNAL_ARRAY;
4.79 }
4.80 bool isTraceable() {
4.81 - return (isPrimitive() && primitive() == PrimitiveType_String) ||
4.82 - isReference() ||
4.83 - isArray() ||
4.84 - isStruct() ||
4.85 - isFunction();
4.86 + return kind_ >= STRING;
4.87 }
4.88 bool isConst() {
4.89 assert(isPrimitive() ||
5.1 --- a/src/compiler/SemanticAnalysis.cpp Mon Dec 24 02:49:20 2012 -0800
5.2 +++ b/src/compiler/SemanticAnalysis.cpp Mon Dec 24 02:56:02 2012 -0800
5.3 @@ -619,7 +619,7 @@
5.4 void
5.5 SemanticAnalysis::visitStringLiteral(StringLiteral *node)
5.6 {
5.7 - Type *type = zone_->types()->getPrimitive(PrimitiveType_String);
5.8 + Type *type = zone_->types()->getString();
5.9 hir_ = new (pool_) HString(node, type, node->string());
5.10 }
5.11