# HG changeset patch # User David Anderson # Date 1356346562 28800 # Node ID 43287eef2fffcaa1201a65763720361d34eaae56 # Parent 26e3035cdffc916966fc1cb838e276c586d98f29 Move PrimitiveType_String to a dedicated string type. diff -r 26e3035cdffc -r 43287eef2fff src/TypeManager.cpp --- a/src/TypeManager.cpp Mon Dec 24 02:49:20 2012 -0800 +++ b/src/TypeManager.cpp Mon Dec 24 02:56:02 2012 -0800 @@ -43,6 +43,10 @@ if (!uncheckedType_) return false; + stringType_ = Type::NewString(zone_); + if (!stringType_) + return false; + if ((primitiveTypes_[PrimitiveType_Int32] = Type::NewPrimitive(zone_, PrimitiveType_Int32)) == NULL) return false; if ((primitiveTypes_[PrimitiveType_Float] = Type::NewPrimitive(zone_, PrimitiveType_Float)) == NULL) @@ -53,8 +57,6 @@ return false; if ((primitiveTypes_[PrimitiveType_Bool] = Type::NewPrimitive(zone_, PrimitiveType_Bool)) == NULL) return false; - if ((primitiveTypes_[PrimitiveType_String] = Type::NewPrimitive(zone_, PrimitiveType_String)) == NULL) - return false; Local type(zone_); for (unsigned i = 0; i < PrimitiveTypes_Total; i++) { @@ -100,6 +102,7 @@ { visitor->visit(voidType_.address()); visitor->visit(uncheckedType_.address()); + visitor->visit(stringType_.address()); for (unsigned i = 0; i < PrimitiveTypes_Total; i++) { visitor->visit(primitiveTypes_[i].address()); visitor->visit(referenceTypes_[i].address()); diff -r 26e3035cdffc -r 43287eef2fff src/TypeManager.h --- a/src/TypeManager.h Mon Dec 24 02:49:20 2012 -0800 +++ b/src/TypeManager.h Mon Dec 24 02:56:02 2012 -0800 @@ -33,6 +33,7 @@ // Primitive type cache. Unbarriered voidType_; + Unbarriered stringType_; Unbarriered uncheckedType_; Unbarriered primitiveTypes_[PrimitiveTypes_Total]; Unbarriered referenceTypes_[PrimitiveTypes_Total]; @@ -46,6 +47,9 @@ return primitiveTypes_[type]; } + Type *getString() { + return stringType_; + } Type *getVoid() { return voidType_; } diff -r 26e3035cdffc -r 43287eef2fff src/Types.cpp --- a/src/Types.cpp Mon Dec 24 02:49:20 2012 -0800 +++ b/src/Types.cpp Mon Dec 24 02:56:02 2012 -0800 @@ -37,6 +37,17 @@ } Type * +Type::NewString(Zone *zone) +{ + Local type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old))); + if (!type) + return NULL; + + type->kind_ = STRING; + return type; +} + +Type * Type::NewUnchecked(Zone *zone) { Local type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old))); diff -r 26e3035cdffc -r 43287eef2fff src/Types.h --- a/src/Types.h Mon Dec 24 02:49:20 2012 -0800 +++ b/src/Types.h Mon Dec 24 02:56:02 2012 -0800 @@ -57,9 +57,6 @@ // on 64-bit systems), and does not exist in language semantics. PrimitiveType_Native, - // Internal string object. - PrimitiveType_String, - PrimitiveTypes_Total }; @@ -70,6 +67,25 @@ // A primitive is a plain-old-data type. PRIMITIVE, + // Void is an internal type used to specify that a function returns no + // value. + VOID, + + // Enums are plain-old-data with int32 storage. They allow for extra + // type checking that would not be possible with integers. + ENUM, + + // Unchecked is a magic type that has implicit, bitwise coercion to + // int32, float, bool, or an enum. + UNCHECKED, + + // ------ Add traceable types below ------- + + // An immutable type that is a primitive in terms of language + // semantics, but gets a special type here to make internal + // logic easier. + STRING, + // An array is a fixed-length vector of any other type. ARRAY, EXTERNAL_ARRAY, @@ -81,21 +97,9 @@ // A function type encapsulates a function signature. FUNCTION, - // Void is an internal type used to specify that a function returns no - // value. - VOID, - - // Enums are plain-old-data with int32 storage. They allow for extra - // type checking that would not be possible with integers. - ENUM, - // Structs are composite records that may contain primitives, arrays, // functions, enums, and other structs. - STRUCT, - - // Unchecked is a magic type that has implicit, bitwise coercion to - // int32, float, bool, or an enum. - UNCHECKED + STRUCT }; private: @@ -107,6 +111,7 @@ static Type *NewVoid(Zone *zone); static Type *NewUnchecked(Zone *zone); static Type *NewPrimitive(Zone *zone, PrimitiveType type); + static Type *NewString(Zone *zone); static bool Compare(Type *left, Type *right); @@ -173,17 +178,13 @@ return isPrimitive() && primitive() == PrimitiveType_Bool; } bool isString() { - return isPrimitive() && primitive() == PrimitiveType_String; + return kind() == STRING; } bool isExternalArray() { return kind() == EXTERNAL_ARRAY; } bool isTraceable() { - return (isPrimitive() && primitive() == PrimitiveType_String) || - isReference() || - isArray() || - isStruct() || - isFunction(); + return kind_ >= STRING; } bool isConst() { assert(isPrimitive() || diff -r 26e3035cdffc -r 43287eef2fff src/compiler/SemanticAnalysis.cpp --- a/src/compiler/SemanticAnalysis.cpp Mon Dec 24 02:49:20 2012 -0800 +++ b/src/compiler/SemanticAnalysis.cpp Mon Dec 24 02:56:02 2012 -0800 @@ -619,7 +619,7 @@ void SemanticAnalysis::visitStringLiteral(StringLiteral *node) { - Type *type = zone_->types()->getPrimitive(PrimitiveType_String); + Type *type = zone_->types()->getString(); hir_ = new (pool_) HString(node, type, node->string()); }