1.1 --- a/src/Types.h Sat Nov 17 22:02:08 2012 -0800
1.2 +++ b/src/Types.h Sat Nov 17 23:11:38 2012 -0800
1.3 @@ -29,6 +29,7 @@
1.4 class String;
1.5 class Descriptor;
1.6 class StructMap;
1.7 +class ArrayMap;
1.8
1.9 #define MAX_ARRAY_DEPTH 5
1.10
1.11 @@ -105,8 +106,6 @@
1.12 static Type *NewVoid(Zone *zone);
1.13 static Type *NewUnchecked(Zone *zone);
1.14 static Type *NewPrimitive(Zone *zone, PrimitiveType type);
1.15 - static Type *NewArray(Zone *zone, Handle<Type> contained, int elements, bool isConst);
1.16 - static Type *NewExternalArray(Zone *zone, Handle<Type> contained);
1.17 static Type *NewReference(Zone *zone, Handle<Type> contained, bool isConst);
1.18 static Type *NewEnum(Zone *zone, Handle<String> name);
1.19
1.20 @@ -116,7 +115,8 @@
1.21 assert(!obj ||
1.22 obj->is(MapKind_Type) ||
1.23 obj->is(MapKind_FunctionType) ||
1.24 - obj->is(MapKind_StructType));
1.25 + obj->is(MapKind_StructType) ||
1.26 + obj->is(MapKind_ArrayType));
1.27 return (Type *)obj;
1.28 }
1.29
1.30 @@ -156,37 +156,6 @@
1.31 : primitive()
1.32 : PrimitiveType_Int32;
1.33 }
1.34 - Type *contained() {
1.35 - assert(isArray() || isReference());
1.36 - return Type::cast(contained_);
1.37 - }
1.38 - bool isFixedLength() {
1.39 - assert(isArray());
1.40 - return elements_ > 0;
1.41 - }
1.42 - unsigned fixedLength() {
1.43 - assert(isFixedLength());
1.44 - return elements_;
1.45 - }
1.46 - unsigned levels() {
1.47 - assert(isArray());
1.48 - return levels_;
1.49 - }
1.50 - bool hasInlineElements() {
1.51 - assert(isArray());
1.52 -
1.53 - // We don't allocate traceable elements inline, since there's no
1.54 - // point to the optimization; we're going to be allocating lots of
1.55 - // objects anyway (in theory).
1.56 - return isFixedLength() && !contained()->isTraceable();
1.57 - }
1.58 - Type *innermost() {
1.59 - assert(isArray());
1.60 - Type *temp = contained();
1.61 - while (temp->isArray())
1.62 - temp = temp->contained();
1.63 - return temp;
1.64 - }
1.65 bool isFloat() {
1.66 return isPrimitive() && primitive() == PrimitiveType_Float;
1.67 }
1.68 @@ -199,11 +168,6 @@
1.69 bool isBool() {
1.70 return isPrimitive() && primitive() == PrimitiveType_Bool;
1.71 }
1.72 - bool isCharArray() {
1.73 - return isArray() &&
1.74 - contained()->isPrimitive() &&
1.75 - contained()->primitive() == PrimitiveType_Char;
1.76 - }
1.77 bool isExternalArray() {
1.78 return kind() == EXTERNAL_ARRAY;
1.79 }
1.80 @@ -224,19 +188,12 @@
1.81 assert(isEnum() || isStruct());
1.82 return name_;
1.83 }
1.84 -
1.85 - Map *newMap() {
1.86 + Type *contained_ref() {
1.87 assert(false);
1.88 return NULL;
1.89 }
1.90 - void setNewMap(void *p) {
1.91 - assert(false);
1.92 - }
1.93
1.94 // GC Descriptor.
1.95 - static inline size_t offsetOfContained() {
1.96 - return OFFSETOF(Type, contained_);
1.97 - }
1.98 static inline size_t offsetOfName() {
1.99 return OFFSETOF(Type, name_);
1.100 }
1.101 @@ -249,15 +206,80 @@
1.102 // Primitives, arrays, and references.
1.103 bool const_;
1.104
1.105 - // Arrays only.
1.106 + // Enums and structs only.
1.107 + Barriered<String> name_;
1.108 +};
1.109 +
1.110 +class ArrayType : public Type
1.111 +{
1.112 + public:
1.113 + static ArrayType *New(Zone *zone, Handle<Type> contained, int elements);
1.114 + static ArrayType *NewExternal(Zone *zone, Handle<Type> contained);
1.115 +
1.116 + Type *innermost() {
1.117 + assert(isArray());
1.118 + Type *temp = contained();
1.119 + while (temp->isArray())
1.120 + temp = ArrayType::cast(temp)->contained();
1.121 + return temp;
1.122 + }
1.123 +
1.124 + Type *contained() {
1.125 + return contained_;
1.126 + }
1.127 + bool isFixedLength() {
1.128 + assert(isArray());
1.129 + return elements_ > 0;
1.130 + }
1.131 + bool isCharArray() {
1.132 + return contained()->isPrimitive() &&
1.133 + contained()->primitive() == PrimitiveType_Char;
1.134 + }
1.135 + unsigned fixedLength() {
1.136 + assert(isFixedLength());
1.137 + return elements_;
1.138 + }
1.139 + unsigned levels() {
1.140 + assert(isArray());
1.141 + return levels_;
1.142 + }
1.143 + bool hasInlineElements() {
1.144 + assert(isArray());
1.145 +
1.146 + // We don't allocate traceable elements inline, since there's no
1.147 + // point to the optimization; we're going to be allocating lots of
1.148 + // objects anyway (in theory).
1.149 + return isFixedLength() && !contained()->isTraceable();
1.150 + }
1.151 +
1.152 + // Arrays of this type can be created with this cached map.
1.153 + ArrayMap *newMap() {
1.154 + return newMap_;
1.155 + }
1.156 + void setNewMap(ArrayMap *map) {
1.157 + assert(!newMap());
1.158 + newMap_ = map;
1.159 + }
1.160 +
1.161 + // GC Descriptor.
1.162 + static inline size_t offsetOfContained() {
1.163 + return OFFSETOF(ArrayType, contained_);
1.164 + }
1.165 + static inline size_t offsetOfNewMap() {
1.166 + return OFFSETOF(ArrayType, newMap_);
1.167 + }
1.168 + // End GC Descriptor.
1.169 +
1.170 + static ArrayType *cast(Object *obj) {
1.171 + assert(!obj || obj->is(MapKind_ArrayType));
1.172 + return (ArrayType *)obj;
1.173 + }
1.174 +
1.175 + private:
1.176 int32 elements_;
1.177 unsigned levels_;
1.178 -
1.179 - // Arrays and references only.
1.180 Barriered<Type> contained_;
1.181 -
1.182 - // Enums and structs only.
1.183 - Barriered<String> name_;
1.184 + Barriered<ArrayMap> newMap_;
1.185 };
1.186
1.187 class StructType : public Type