Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 // Consequently, do not use pointer equality for type tests, always use Is! | 87 // Consequently, do not use pointer equality for type tests, always use Is! |
| 88 // | 88 // |
| 89 // Internally, all 'primitive' types, and their unions, are represented as | 89 // Internally, all 'primitive' types, and their unions, are represented as |
| 90 // bitsets via smis. Class is a heap pointer to the respective map. Only | 90 // bitsets via smis. Class is a heap pointer to the respective map. Only |
| 91 // Constant's, or unions containing Class'es or Constant's, require allocation. | 91 // Constant's, or unions containing Class'es or Constant's, require allocation. |
| 92 // Note that the bitset representation is closed under both Union and Intersect. | 92 // Note that the bitset representation is closed under both Union and Intersect. |
| 93 // | 93 // |
| 94 // The type representation is heap-allocated, so cannot (currently) be used in | 94 // The type representation is heap-allocated, so cannot (currently) be used in |
| 95 // a parallel compilation context. | 95 // a parallel compilation context. |
| 96 | 96 |
| 97 | |
| 98 #define PRIMITIVE_TYPE_LIST(V) \ | |
| 99 V(None, 0) \ | |
| 100 V(Null, 1 << 0) \ | |
| 101 V(Undefined, 1 << 1) \ | |
| 102 V(Boolean, 1 << 2) \ | |
| 103 V(Smi, 1 << 3) \ | |
| 104 V(OtherSigned32, 1 << 4) \ | |
| 105 V(Unsigned32, 1 << 5) \ | |
| 106 V(Double, 1 << 6) \ | |
| 107 V(Symbol, 1 << 7) \ | |
| 108 V(InternalizedString, 1 << 8) \ | |
| 109 V(OtherString, 1 << 9) \ | |
| 110 V(Undetectable, 1 << 10) \ | |
| 111 V(Array, 1 << 11) \ | |
| 112 V(Function, 1 << 12) \ | |
| 113 V(RegExp, 1 << 13) \ | |
| 114 V(OtherObject, 1 << 14) \ | |
| 115 V(Proxy, 1 << 15) \ | |
| 116 V(Internal, 1 << 16) \ | |
| 117 V(Oddball, kBoolean | kNull | kUndefined) \ | |
|
rossberg
2013/07/03 14:52:54
Nit: Maybe insert an empty line before this one.
| |
| 118 V(Signed32, kSmi | kOtherSigned32) \ | |
| 119 V(Number, kSigned32 | kUnsigned32 | kDouble) \ | |
| 120 V(String, kInternalizedString | kOtherString) \ | |
| 121 V(UniqueName, kSymbol | kInternalizedString) \ | |
| 122 V(Name, kSymbol | kString) \ | |
| 123 V(NumberOrString, kNumber | kString) \ | |
| 124 V(Object, kUndetectable | kArray | kFunction | kRegExp | kOtherObject) \ | |
|
rossberg
2013/07/03 14:52:54
Aha, cheating with indentation!
| |
| 125 V(Receiver, kObject | kProxy) \ | |
| 126 V(Allocated, kDouble | kName | kReceiver) \ | |
| 127 V(Any, kOddball | kNumber | kAllocated | kInternal) \ | |
| 128 V(Detectable, kAllocated - kUndetectable) | |
| 129 | |
| 130 | |
| 97 class Type : public Object { | 131 class Type : public Object { |
| 98 public: | 132 public: |
| 99 static Type* None() { return from_bitset(kNone); } | 133 static Type* None() { return from_bitset(kNone); } |
|
rossberg
2013/07/03 14:52:54
Can't you generate all these functions from the ma
| |
| 100 static Type* Any() { return from_bitset(kAny); } | 134 static Type* Any() { return from_bitset(kAny); } |
| 101 static Type* Allocated() { return from_bitset(kAllocated); } | 135 static Type* Allocated() { return from_bitset(kAllocated); } |
| 102 static Type* Detectable() { return from_bitset(kDetectable); } | 136 static Type* Detectable() { return from_bitset(kDetectable); } |
| 103 | 137 |
| 104 static Type* Oddball() { return from_bitset(kOddball); } | 138 static Type* Oddball() { return from_bitset(kOddball); } |
| 105 static Type* Boolean() { return from_bitset(kBoolean); } | 139 static Type* Boolean() { return from_bitset(kBoolean); } |
| 106 static Type* Null() { return from_bitset(kNull); } | 140 static Type* Null() { return from_bitset(kNull); } |
| 107 static Type* Undefined() { return from_bitset(kUndefined); } | 141 static Type* Undefined() { return from_bitset(kUndefined); } |
| 108 | 142 |
| 109 static Type* Number() { return from_bitset(kNumber); } | 143 static Type* Number() { return from_bitset(kNumber); } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 } | 219 } |
| 186 | 220 |
| 187 private: | 221 private: |
| 188 // A union is a fixed array containing types. Invariants: | 222 // A union is a fixed array containing types. Invariants: |
| 189 // - its length is at least 2 | 223 // - its length is at least 2 |
| 190 // - at most one field is a bitset, and it must go into index 0 | 224 // - at most one field is a bitset, and it must go into index 0 |
| 191 // - no field is a union | 225 // - no field is a union |
| 192 typedef FixedArray Unioned; | 226 typedef FixedArray Unioned; |
| 193 | 227 |
| 194 enum { | 228 enum { |
| 195 kNull = 1 << 0, | 229 // Declare const for all primitive types. |
| 196 kUndefined = 1 << 1, | 230 #define DECLARE_PRIMITIVE_TYPE(type, value) k##type = (value), |
| 197 kBoolean = 1 << 2, | 231 PRIMITIVE_TYPE_LIST(DECLARE_PRIMITIVE_TYPE) |
|
rossberg
2013/07/03 14:52:54
Nit: maybe indent this by 2
oliv
2013/07/05 12:29:06
i'd rather not, since it looks very strange if the
| |
| 198 kSmi = 1 << 3, | 232 #undef DECLARE_OPCODE |
| 199 kOtherSigned32 = 1 << 4, | 233 kUnusedEOL = 0 |
|
rossberg
2013/07/03 14:52:54
What's that for?
oliv
2013/07/05 12:29:06
you cannot end the enum definition with a comma...
| |
| 200 kUnsigned32 = 1 << 5, | 234 }; |
| 201 kDouble = 1 << 6, | |
| 202 kSymbol = 1 << 7, | |
| 203 kInternalizedString = 1 << 8, | |
| 204 kOtherString = 1 << 9, | |
| 205 kUndetectable = 1 << 10, | |
| 206 kArray = 1 << 11, | |
| 207 kFunction = 1 << 12, | |
| 208 kRegExp = 1 << 13, | |
| 209 kOtherObject = 1 << 14, | |
| 210 kProxy = 1 << 15, | |
| 211 kInternal = 1 << 16, | |
| 212 | 235 |
| 213 kOddball = kBoolean | kNull | kUndefined, | 236 const char* GetPrimitiveName() { |
| 214 kSigned32 = kSmi | kOtherSigned32, | 237 switch (as_bitset()) { |
|
rossberg
2013/07/03 14:52:54
Yeah, that does not fly. Any combination of primit
| |
| 215 kNumber = kSigned32 | kUnsigned32 | kDouble, | 238 #define PRINT_PRIMITIVE_TYPE(type, value) \ |
| 216 kString = kInternalizedString | kOtherString, | 239 case k##type: \ |
| 217 kUniqueName = kSymbol | kInternalizedString, | 240 return # type; |
| 218 kName = kSymbol | kString, | 241 PRIMITIVE_TYPE_LIST(PRINT_PRIMITIVE_TYPE) |
| 219 kNumberOrString = kNumber | kString, | 242 #undef PRINT_PRIMITIVE_TYPE |
| 220 kObject = kUndetectable | kArray | kFunction | kRegExp | kOtherObject, | 243 default: |
| 221 kReceiver = kObject | kProxy, | 244 UNREACHABLE(); |
| 222 kAllocated = kDouble | kName | kReceiver, | 245 return "InvalidType"; |
| 223 kAny = kOddball | kNumber | kAllocated | kInternal, | 246 } |
| 224 kDetectable = kAllocated - kUndetectable, | 247 } |
| 225 kNone = 0 | |
| 226 }; | |
| 227 | 248 |
| 228 bool is_bitset() { return this->IsSmi(); } | 249 bool is_bitset() { return this->IsSmi(); } |
| 229 bool is_class() { return this->IsMap(); } | 250 bool is_class() { return this->IsMap(); } |
| 230 bool is_constant() { return this->IsBox(); } | 251 bool is_constant() { return this->IsBox(); } |
| 231 bool is_union() { return this->IsFixedArray(); } | 252 bool is_union() { return this->IsFixedArray(); } |
| 232 | 253 |
| 233 bool IsSlowCase(Type* that); | 254 bool IsSlowCase(Type* that); |
| 234 | 255 |
| 235 int as_bitset() { return Smi::cast(this)->value(); } | 256 int as_bitset() { return Smi::cast(this)->value(); } |
| 236 Handle<Map> as_class() { return Handle<Map>::cast(handle()); } | 257 Handle<Map> as_class() { return Handle<Map>::cast(handle()); } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 258 ASSERT(!type->is_union()); | 279 ASSERT(!type->is_union()); |
| 259 return type->handle_via_isolate_of(from_handle(unioned)); | 280 return type->handle_via_isolate_of(from_handle(unioned)); |
| 260 } | 281 } |
| 261 | 282 |
| 262 int LubBitset(); // least upper bound that's a bitset | 283 int LubBitset(); // least upper bound that's a bitset |
| 263 int GlbBitset(); // greatest lower bound that's a bitset | 284 int GlbBitset(); // greatest lower bound that's a bitset |
| 264 bool InUnion(Handle<Unioned> unioned, int current_size); | 285 bool InUnion(Handle<Unioned> unioned, int current_size); |
| 265 int ExtendUnion(Handle<Unioned> unioned, int current_size); | 286 int ExtendUnion(Handle<Unioned> unioned, int current_size); |
| 266 int ExtendIntersection( | 287 int ExtendIntersection( |
| 267 Handle<Unioned> unioned, Handle<Type> type, int current_size); | 288 Handle<Unioned> unioned, Handle<Type> type, int current_size); |
| 289 | |
| 290 static void PrintName(StringStream* stream, Type* type); | |
| 291 static SmartArrayPointer<const char> GetName(Type* type); | |
| 268 }; | 292 }; |
| 269 | 293 |
| 270 } } // namespace v8::internal | 294 } } // namespace v8::internal |
| 271 | 295 |
| 272 #endif // V8_TYPES_H_ | 296 #endif // V8_TYPES_H_ |
| OLD | NEW |