OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_TYPES_H_ | 5 #ifndef V8_TYPES_H_ |
6 #define V8_TYPES_H_ | 6 #define V8_TYPES_H_ |
7 | 7 |
8 #include "handles.h" | 8 #include "handles.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 27 matching lines...) Expand all Loading... |
38 // Array < Object | 38 // Array < Object |
39 // Function < Object | 39 // Function < Object |
40 // RegExp < Object | 40 // RegExp < Object |
41 // Undetectable < Object | 41 // Undetectable < Object |
42 // Detectable = Receiver \/ Number \/ Name - Undetectable | 42 // Detectable = Receiver \/ Number \/ Name - Undetectable |
43 // | 43 // |
44 // Class(map) < T iff instance_type(map) < T | 44 // Class(map) < T iff instance_type(map) < T |
45 // Constant(x) < T iff instance_type(map(x)) < T | 45 // Constant(x) < T iff instance_type(map(x)) < T |
46 // Array(T) < Array | 46 // Array(T) < Array |
47 // Function(R, S, T0, T1, ...) < Function | 47 // Function(R, S, T0, T1, ...) < Function |
| 48 // Context(T) < Internal |
48 // | 49 // |
49 // Both structural Array and Function types are invariant in all parameters. | 50 // Both structural Array and Function types are invariant in all parameters; |
50 // Relaxing this would make Union and Intersect operations more involved. | 51 // relaxing this would make Union and Intersect operations more involved. |
51 // Note that Constant(x) < Class(map(x)) does _not_ hold, since x's map can | 52 // There is no subtyping relation between Array, Function, or Context types |
| 53 // and respective Constant types, since these types cannot be reconstructed |
| 54 // for arbitrary heap values. |
| 55 // Note also that Constant(x) < Class(map(x)) does _not_ hold, since x's map can |
52 // change! (Its instance type cannot, however.) | 56 // change! (Its instance type cannot, however.) |
53 // TODO(rossberg): the latter is not currently true for proxies, because of fix, | 57 // TODO(rossberg): the latter is not currently true for proxies, because of fix, |
54 // but will hold once we implement direct proxies. | 58 // but will hold once we implement direct proxies. |
55 // However, we also define a 'temporal' variant of the subtyping relation that | 59 // However, we also define a 'temporal' variant of the subtyping relation that |
56 // considers the _current_ state only, i.e., Constant(x) <_now Class(map(x)). | 60 // considers the _current_ state only, i.e., Constant(x) <_now Class(map(x)). |
57 // | 61 // |
58 // REPRESENTATIONAL DIMENSION | 62 // REPRESENTATIONAL DIMENSION |
59 // | 63 // |
60 // For the representation axis, the following holds: | 64 // For the representation axis, the following holds: |
61 // | 65 // |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // There are two type representations, using different allocation: | 126 // There are two type representations, using different allocation: |
123 // | 127 // |
124 // - class Type (zone-allocated, for compiler and concurrent compilation) | 128 // - class Type (zone-allocated, for compiler and concurrent compilation) |
125 // - class HeapType (heap-allocated, for persistent types) | 129 // - class HeapType (heap-allocated, for persistent types) |
126 // | 130 // |
127 // Both provide the same API, and the Convert method can be used to interconvert | 131 // Both provide the same API, and the Convert method can be used to interconvert |
128 // them. For zone types, no query method touches the heap, only constructors do. | 132 // them. For zone types, no query method touches the heap, only constructors do. |
129 | 133 |
130 | 134 |
131 #define MASK_BITSET_TYPE_LIST(V) \ | 135 #define MASK_BITSET_TYPE_LIST(V) \ |
132 V(Representation, static_cast<int>(0xff800000)) \ | 136 V(Representation, static_cast<int>(0xffc00000)) \ |
133 V(Semantic, static_cast<int>(0x007fffff)) | 137 V(Semantic, static_cast<int>(0x003fffff)) |
134 | 138 |
135 #define REPRESENTATION(k) ((k) & kRepresentation) | 139 #define REPRESENTATION(k) ((k) & BitsetType::kRepresentation) |
136 #define SEMANTIC(k) ((k) & kSemantic) | 140 #define SEMANTIC(k) ((k) & BitsetType::kSemantic) |
137 | 141 |
138 #define REPRESENTATION_BITSET_TYPE_LIST(V) \ | 142 #define REPRESENTATION_BITSET_TYPE_LIST(V) \ |
139 V(None, 0) \ | 143 V(None, 0) \ |
| 144 V(UntaggedInt1, 1 << 22 | kSemantic) \ |
140 V(UntaggedInt8, 1 << 23 | kSemantic) \ | 145 V(UntaggedInt8, 1 << 23 | kSemantic) \ |
141 V(UntaggedInt16, 1 << 24 | kSemantic) \ | 146 V(UntaggedInt16, 1 << 24 | kSemantic) \ |
142 V(UntaggedInt32, 1 << 25 | kSemantic) \ | 147 V(UntaggedInt32, 1 << 25 | kSemantic) \ |
143 V(UntaggedFloat32, 1 << 26 | kSemantic) \ | 148 V(UntaggedFloat32, 1 << 26 | kSemantic) \ |
144 V(UntaggedFloat64, 1 << 27 | kSemantic) \ | 149 V(UntaggedFloat64, 1 << 27 | kSemantic) \ |
145 V(UntaggedPtr, 1 << 28 | kSemantic) \ | 150 V(UntaggedPtr, 1 << 28 | kSemantic) \ |
146 V(TaggedInt, 1 << 29 | kSemantic) \ | 151 V(TaggedInt, 1 << 29 | kSemantic) \ |
147 V(TaggedPtr, -1 << 30 | kSemantic) /* MSB has to be sign-extended */ \ | 152 V(TaggedPtr, -1 << 30 | kSemantic) /* MSB has to be sign-extended */ \ |
148 \ | 153 \ |
149 V(UntaggedInt, kUntaggedInt8 | kUntaggedInt16 | kUntaggedInt32) \ | 154 V(UntaggedInt, kUntaggedInt1 | kUntaggedInt8 | \ |
150 V(UntaggedFloat, kUntaggedFloat32 | kUntaggedFloat64) \ | 155 kUntaggedInt16 | kUntaggedInt32) \ |
151 V(UntaggedNumber, kUntaggedInt | kUntaggedFloat) \ | 156 V(UntaggedFloat, kUntaggedFloat32 | kUntaggedFloat64) \ |
152 V(Untagged, kUntaggedNumber | kUntaggedPtr) \ | 157 V(UntaggedNumber, kUntaggedInt | kUntaggedFloat) \ |
| 158 V(Untagged, kUntaggedNumber | kUntaggedPtr) \ |
153 V(Tagged, kTaggedInt | kTaggedPtr) | 159 V(Tagged, kTaggedInt | kTaggedPtr) |
154 | 160 |
155 #define SEMANTIC_BITSET_TYPE_LIST(V) \ | 161 #define SEMANTIC_BITSET_TYPE_LIST(V) \ |
156 V(Null, 1 << 0 | REPRESENTATION(kTaggedPtr)) \ | 162 V(Null, 1 << 0 | REPRESENTATION(kTaggedPtr)) \ |
157 V(Undefined, 1 << 1 | REPRESENTATION(kTaggedPtr)) \ | 163 V(Undefined, 1 << 1 | REPRESENTATION(kTaggedPtr)) \ |
158 V(Boolean, 1 << 2 | REPRESENTATION(kTaggedPtr)) \ | 164 V(Boolean, 1 << 2 | REPRESENTATION(kTaggedPtr)) \ |
159 V(SignedSmall, 1 << 3 | REPRESENTATION(kTagged | kUntaggedNumber)) \ | 165 V(UnsignedSmall, 1 << 3 | REPRESENTATION(kTagged | kUntaggedNumber)) \ |
160 V(OtherSigned32, 1 << 4 | REPRESENTATION(kTagged | kUntaggedNumber)) \ | 166 V(OtherSignedSmall, 1 << 4 | REPRESENTATION(kTagged | kUntaggedNumber)) \ |
161 V(Unsigned32, 1 << 5 | REPRESENTATION(kTagged | kUntaggedNumber)) \ | 167 V(OtherUnsigned31, 1 << 5 | REPRESENTATION(kTagged | kUntaggedNumber)) \ |
162 V(Float, 1 << 6 | REPRESENTATION(kTagged | kUntaggedNumber)) \ | 168 V(OtherUnsigned32, 1 << 6 | REPRESENTATION(kTagged | kUntaggedNumber)) \ |
163 V(Symbol, 1 << 7 | REPRESENTATION(kTaggedPtr)) \ | 169 V(OtherSigned32, 1 << 7 | REPRESENTATION(kTagged | kUntaggedNumber)) \ |
164 V(InternalizedString, 1 << 8 | REPRESENTATION(kTaggedPtr)) \ | 170 V(MinusZero, 1 << 8 | REPRESENTATION(kTagged | kUntaggedNumber)) \ |
165 V(OtherString, 1 << 9 | REPRESENTATION(kTaggedPtr)) \ | 171 V(NaN, 1 << 9 | REPRESENTATION(kTagged | kUntaggedNumber)) \ |
166 V(Undetectable, 1 << 10 | REPRESENTATION(kTaggedPtr)) \ | 172 V(OtherNumber, 1 << 10 | REPRESENTATION(kTagged | kUntaggedNumber)) \ |
167 V(Array, 1 << 11 | REPRESENTATION(kTaggedPtr)) \ | 173 V(Symbol, 1 << 11 | REPRESENTATION(kTaggedPtr)) \ |
168 V(Function, 1 << 12 | REPRESENTATION(kTaggedPtr)) \ | 174 V(InternalizedString, 1 << 12 | REPRESENTATION(kTaggedPtr)) \ |
169 V(RegExp, 1 << 13 | REPRESENTATION(kTaggedPtr)) \ | 175 V(OtherString, 1 << 13 | REPRESENTATION(kTaggedPtr)) \ |
170 V(OtherObject, 1 << 14 | REPRESENTATION(kTaggedPtr)) \ | 176 V(Undetectable, 1 << 14 | REPRESENTATION(kTaggedPtr)) \ |
171 V(Proxy, 1 << 15 | REPRESENTATION(kTaggedPtr)) \ | 177 V(Array, 1 << 15 | REPRESENTATION(kTaggedPtr)) \ |
172 V(Internal, 1 << 16 | REPRESENTATION(kTagged | kUntagged)) \ | 178 V(Buffer, 1 << 16 | REPRESENTATION(kTaggedPtr)) \ |
| 179 V(Function, 1 << 17 | REPRESENTATION(kTaggedPtr)) \ |
| 180 V(RegExp, 1 << 18 | REPRESENTATION(kTaggedPtr)) \ |
| 181 V(OtherObject, 1 << 19 | REPRESENTATION(kTaggedPtr)) \ |
| 182 V(Proxy, 1 << 20 | REPRESENTATION(kTaggedPtr)) \ |
| 183 V(Internal, 1 << 21 | REPRESENTATION(kTagged | kUntagged)) \ |
173 \ | 184 \ |
174 V(Signed32, kSignedSmall | kOtherSigned32) \ | 185 V(SignedSmall, kUnsignedSmall | kOtherSignedSmall) \ |
175 V(Number, kSigned32 | kUnsigned32 | kFloat) \ | 186 V(Signed32, kSignedSmall | kOtherUnsigned31 | kOtherSigned32) \ |
176 V(String, kInternalizedString | kOtherString) \ | 187 V(Unsigned32, kUnsignedSmall | kOtherUnsigned31 | kOtherUnsigned32) \ |
177 V(UniqueName, kSymbol | kInternalizedString) \ | 188 V(Integral32, kSigned32 | kUnsigned32) \ |
178 V(Name, kSymbol | kString) \ | 189 V(Number, kIntegral32 | kMinusZero | kNaN | kOtherNumber) \ |
179 V(NumberOrString, kNumber | kString) \ | 190 V(String, kInternalizedString | kOtherString) \ |
180 V(DetectableObject, kArray | kFunction | kRegExp | kOtherObject) \ | 191 V(UniqueName, kSymbol | kInternalizedString) \ |
181 V(DetectableReceiver, kDetectableObject | kProxy) \ | 192 V(Name, kSymbol | kString) \ |
182 V(Detectable, kDetectableReceiver | kNumber | kName) \ | 193 V(NumberOrString, kNumber | kString) \ |
183 V(Object, kDetectableObject | kUndetectable) \ | 194 V(Primitive, kNumber | kName | kBoolean | kNull | kUndefined) \ |
184 V(Receiver, kObject | kProxy) \ | 195 V(DetectableObject, kArray | kFunction | kRegExp | kOtherObject) \ |
185 V(NonNumber, kBoolean | kName | kNull | kReceiver | \ | 196 V(DetectableReceiver, kDetectableObject | kProxy) \ |
186 kUndefined | kInternal) \ | 197 V(Detectable, kDetectableReceiver | kNumber | kName) \ |
| 198 V(Object, kDetectableObject | kUndetectable) \ |
| 199 V(Receiver, kObject | kProxy) \ |
| 200 V(NonNumber, kBoolean | kName | kNull | kReceiver | \ |
| 201 kUndefined | kInternal) \ |
187 V(Any, -1) | 202 V(Any, -1) |
188 | 203 |
189 #define BITSET_TYPE_LIST(V) \ | 204 #define BITSET_TYPE_LIST(V) \ |
190 MASK_BITSET_TYPE_LIST(V) \ | 205 MASK_BITSET_TYPE_LIST(V) \ |
191 REPRESENTATION_BITSET_TYPE_LIST(V) \ | 206 REPRESENTATION_BITSET_TYPE_LIST(V) \ |
192 SEMANTIC_BITSET_TYPE_LIST(V) | 207 SEMANTIC_BITSET_TYPE_LIST(V) |
193 | 208 |
194 | 209 |
195 // struct Config { | 210 // struct Config { |
196 // typedef TypeImpl<Config> Type; | 211 // typedef TypeImpl<Config> Type; |
(...skipping 26 matching lines...) Expand all Loading... |
223 // } | 238 // } |
224 template<class Config> | 239 template<class Config> |
225 class TypeImpl : public Config::Base { | 240 class TypeImpl : public Config::Base { |
226 public: | 241 public: |
227 class BitsetType; // Internal | 242 class BitsetType; // Internal |
228 class StructuralType; // Internal | 243 class StructuralType; // Internal |
229 class UnionType; // Internal | 244 class UnionType; // Internal |
230 | 245 |
231 class ClassType; | 246 class ClassType; |
232 class ConstantType; | 247 class ConstantType; |
| 248 class ContextType; |
233 class ArrayType; | 249 class ArrayType; |
234 class FunctionType; | 250 class FunctionType; |
235 | 251 |
236 typedef typename Config::template Handle<TypeImpl>::type TypeHandle; | 252 typedef typename Config::template Handle<TypeImpl>::type TypeHandle; |
237 typedef typename Config::template Handle<ClassType>::type ClassHandle; | 253 typedef typename Config::template Handle<ClassType>::type ClassHandle; |
238 typedef typename Config::template Handle<ConstantType>::type ConstantHandle; | 254 typedef typename Config::template Handle<ConstantType>::type ConstantHandle; |
| 255 typedef typename Config::template Handle<ContextType>::type ContextHandle; |
239 typedef typename Config::template Handle<ArrayType>::type ArrayHandle; | 256 typedef typename Config::template Handle<ArrayType>::type ArrayHandle; |
240 typedef typename Config::template Handle<FunctionType>::type FunctionHandle; | 257 typedef typename Config::template Handle<FunctionType>::type FunctionHandle; |
241 typedef typename Config::template Handle<UnionType>::type UnionHandle; | 258 typedef typename Config::template Handle<UnionType>::type UnionHandle; |
242 typedef typename Config::Region Region; | 259 typedef typename Config::Region Region; |
243 | 260 |
244 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ | 261 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ |
245 static TypeImpl* type() { return BitsetType::New(BitsetType::k##type); } \ | 262 static TypeImpl* type() { return BitsetType::New(BitsetType::k##type); } \ |
246 static TypeHandle type(Region* region) { \ | 263 static TypeHandle type(Region* region) { \ |
247 return BitsetType::New(BitsetType::k##type, region); \ | 264 return BitsetType::New(BitsetType::k##type, region); \ |
248 } | 265 } |
249 BITSET_TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR) | 266 BITSET_TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR) |
250 #undef DEFINE_TYPE_CONSTRUCTOR | 267 #undef DEFINE_TYPE_CONSTRUCTOR |
251 | 268 |
252 static TypeHandle Class(i::Handle<i::Map> map, Region* region) { | 269 static TypeHandle Class(i::Handle<i::Map> map, Region* region) { |
253 return ClassType::New(map, region); | 270 return ClassType::New(map, region); |
254 } | 271 } |
255 static TypeHandle Constant(i::Handle<i::Object> value, Region* region) { | 272 static TypeHandle Constant(i::Handle<i::Object> value, Region* region) { |
256 return ConstantType::New(value, region); | 273 return ConstantType::New(value, region); |
257 } | 274 } |
| 275 static TypeHandle Context(TypeHandle outer, Region* region) { |
| 276 return ContextType::New(outer, region); |
| 277 } |
258 static TypeHandle Array(TypeHandle element, Region* region) { | 278 static TypeHandle Array(TypeHandle element, Region* region) { |
259 return ArrayType::New(element, region); | 279 return ArrayType::New(element, region); |
260 } | 280 } |
261 static FunctionHandle Function( | 281 static FunctionHandle Function( |
262 TypeHandle result, TypeHandle receiver, int arity, Region* region) { | 282 TypeHandle result, TypeHandle receiver, int arity, Region* region) { |
263 return FunctionType::New(result, receiver, arity, region); | 283 return FunctionType::New(result, receiver, arity, region); |
264 } | 284 } |
265 static TypeHandle Function(TypeHandle result, Region* region) { | 285 static TypeHandle Function(TypeHandle result, Region* region) { |
266 return Function(result, Any(region), 0, region); | 286 return Function(result, Any(region), 0, region); |
267 } | 287 } |
268 static TypeHandle Function( | 288 static TypeHandle Function( |
269 TypeHandle result, TypeHandle param0, Region* region) { | 289 TypeHandle result, TypeHandle param0, Region* region) { |
270 FunctionHandle function = Function(result, Any(region), 1, region); | 290 FunctionHandle function = Function(result, Any(region), 1, region); |
271 function->InitParameter(0, param0); | 291 function->InitParameter(0, param0); |
272 return function; | 292 return function; |
273 } | 293 } |
274 static TypeHandle Function( | 294 static TypeHandle Function( |
275 TypeHandle result, TypeHandle param0, TypeHandle param1, Region* region) { | 295 TypeHandle result, TypeHandle param0, TypeHandle param1, Region* region) { |
276 FunctionHandle function = Function(result, Any(region), 2, region); | 296 FunctionHandle function = Function(result, Any(region), 2, region); |
277 function->InitParameter(0, param0); | 297 function->InitParameter(0, param0); |
278 function->InitParameter(1, param1); | 298 function->InitParameter(1, param1); |
279 return function; | 299 return function; |
280 } | 300 } |
| 301 static TypeHandle Function( |
| 302 TypeHandle result, TypeHandle param0, TypeHandle param1, |
| 303 TypeHandle param2, Region* region) { |
| 304 FunctionHandle function = Function(result, Any(region), 3, region); |
| 305 function->InitParameter(0, param0); |
| 306 function->InitParameter(1, param1); |
| 307 function->InitParameter(2, param2); |
| 308 return function; |
| 309 } |
281 | 310 |
282 static TypeHandle Union(TypeHandle type1, TypeHandle type2, Region* reg); | 311 static TypeHandle Union(TypeHandle type1, TypeHandle type2, Region* reg); |
283 static TypeHandle Intersect(TypeHandle type1, TypeHandle type2, Region* reg); | 312 static TypeHandle Intersect(TypeHandle type1, TypeHandle type2, Region* reg); |
284 | 313 |
| 314 static TypeHandle Of(double value, Region* region) { |
| 315 return Config::from_bitset(BitsetType::Lub(value), region); |
| 316 } |
285 static TypeHandle Of(i::Object* value, Region* region) { | 317 static TypeHandle Of(i::Object* value, Region* region) { |
286 return Config::from_bitset(BitsetType::Lub(value), region); | 318 return Config::from_bitset(BitsetType::Lub(value), region); |
287 } | 319 } |
288 static TypeHandle Of(i::Handle<i::Object> value, Region* region) { | 320 static TypeHandle Of(i::Handle<i::Object> value, Region* region) { |
289 return Of(*value, region); | 321 return Of(*value, region); |
290 } | 322 } |
291 | 323 |
292 bool IsInhabited() { | 324 bool IsInhabited() { |
293 return !this->IsBitset() || BitsetType::IsInhabited(this->AsBitset()); | 325 return !this->IsBitset() || BitsetType::IsInhabited(this->AsBitset()); |
294 } | 326 } |
(...skipping 23 matching lines...) Expand all Loading... |
318 bool NowIs(TypeImpl* that); | 350 bool NowIs(TypeImpl* that); |
319 template<class TypeHandle> | 351 template<class TypeHandle> |
320 bool NowIs(TypeHandle that) { return this->NowIs(*that); } | 352 bool NowIs(TypeHandle that) { return this->NowIs(*that); } |
321 inline bool NowContains(i::Object* val); | 353 inline bool NowContains(i::Object* val); |
322 bool NowContains(i::Handle<i::Object> val) { return this->NowContains(*val); } | 354 bool NowContains(i::Handle<i::Object> val) { return this->NowContains(*val); } |
323 | 355 |
324 bool NowStable(); | 356 bool NowStable(); |
325 | 357 |
326 bool IsClass() { return Config::is_class(this); } | 358 bool IsClass() { return Config::is_class(this); } |
327 bool IsConstant() { return Config::is_constant(this); } | 359 bool IsConstant() { return Config::is_constant(this); } |
| 360 bool IsContext() { |
| 361 return Config::is_struct(this, StructuralType::kContextTag); |
| 362 } |
328 bool IsArray() { return Config::is_struct(this, StructuralType::kArrayTag); } | 363 bool IsArray() { return Config::is_struct(this, StructuralType::kArrayTag); } |
329 bool IsFunction() { | 364 bool IsFunction() { |
330 return Config::is_struct(this, StructuralType::kFunctionTag); | 365 return Config::is_struct(this, StructuralType::kFunctionTag); |
331 } | 366 } |
332 | 367 |
333 ClassType* AsClass() { return ClassType::cast(this); } | 368 ClassType* AsClass() { return ClassType::cast(this); } |
334 ConstantType* AsConstant() { return ConstantType::cast(this); } | 369 ConstantType* AsConstant() { return ConstantType::cast(this); } |
| 370 ContextType* AsContext() { return ContextType::cast(this); } |
335 ArrayType* AsArray() { return ArrayType::cast(this); } | 371 ArrayType* AsArray() { return ArrayType::cast(this); } |
336 FunctionType* AsFunction() { return FunctionType::cast(this); } | 372 FunctionType* AsFunction() { return FunctionType::cast(this); } |
337 | 373 |
338 int NumClasses(); | 374 int NumClasses(); |
339 int NumConstants(); | 375 int NumConstants(); |
340 | 376 |
341 template<class T> class Iterator; | 377 template<class T> class Iterator; |
342 Iterator<i::Map> Classes() { | 378 Iterator<i::Map> Classes() { |
343 if (this->IsBitset()) return Iterator<i::Map>(); | 379 if (this->IsBitset()) return Iterator<i::Map>(); |
344 return Iterator<i::Map>(Config::handle(this)); | 380 return Iterator<i::Map>(Config::handle(this)); |
345 } | 381 } |
346 Iterator<i::Object> Constants() { | 382 Iterator<i::Object> Constants() { |
347 if (this->IsBitset()) return Iterator<i::Object>(); | 383 if (this->IsBitset()) return Iterator<i::Object>(); |
348 return Iterator<i::Object>(Config::handle(this)); | 384 return Iterator<i::Object>(Config::handle(this)); |
349 } | 385 } |
350 | 386 |
351 static inline TypeImpl* cast(typename Config::Base* object); | 387 static inline TypeImpl* cast(typename Config::Base* object); |
352 | 388 |
353 template<class OtherTypeImpl> | 389 template<class OtherTypeImpl> |
354 static TypeHandle Convert( | 390 static TypeHandle Convert( |
355 typename OtherTypeImpl::TypeHandle type, Region* region); | 391 typename OtherTypeImpl::TypeHandle type, Region* region); |
356 | 392 |
357 enum PrintDimension { BOTH_DIMS, SEMANTIC_DIM, REPRESENTATION_DIM }; | 393 enum PrintDimension { BOTH_DIMS, SEMANTIC_DIM, REPRESENTATION_DIM }; |
| 394 void PrintTo(StringStream* stream, PrintDimension = BOTH_DIMS); |
358 void TypePrint(PrintDimension = BOTH_DIMS); | 395 void TypePrint(PrintDimension = BOTH_DIMS); |
359 void TypePrint(FILE* out, PrintDimension = BOTH_DIMS); | 396 void TypePrint(FILE* out, PrintDimension = BOTH_DIMS); |
360 | 397 |
361 protected: | 398 protected: |
362 template<class> friend class Iterator; | 399 template<class> friend class Iterator; |
363 template<class> friend class TypeImpl; | 400 template<class> friend class TypeImpl; |
364 | 401 |
365 template<class T> | 402 template<class T> |
366 static typename Config::template Handle<T>::type handle(T* type) { | 403 static typename Config::template Handle<T>::type handle(T* type) { |
367 return Config::handle(type); | 404 return Config::handle(type); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 return Config::from_bitset(bitset, region); | 449 return Config::from_bitset(bitset, region); |
413 } | 450 } |
414 | 451 |
415 static bool IsInhabited(int bitset) { | 452 static bool IsInhabited(int bitset) { |
416 return (bitset & kRepresentation) && (bitset & kSemantic); | 453 return (bitset & kRepresentation) && (bitset & kSemantic); |
417 } | 454 } |
418 | 455 |
419 static int Glb(TypeImpl* type); // greatest lower bound that's a bitset | 456 static int Glb(TypeImpl* type); // greatest lower bound that's a bitset |
420 static int Lub(TypeImpl* type); // least upper bound that's a bitset | 457 static int Lub(TypeImpl* type); // least upper bound that's a bitset |
421 static int Lub(i::Object* value); | 458 static int Lub(i::Object* value); |
| 459 static int Lub(double value); |
| 460 static int Lub(int32_t value); |
| 461 static int Lub(uint32_t value); |
422 static int Lub(i::Map* map); | 462 static int Lub(i::Map* map); |
423 | 463 |
424 static const char* Name(int bitset); | 464 static const char* Name(int bitset); |
425 static void BitsetTypePrint(FILE* out, int bitset); | 465 static void PrintTo(StringStream* stream, int bitset); |
| 466 using TypeImpl::PrintTo; |
426 }; | 467 }; |
427 | 468 |
428 | 469 |
429 // Internal | 470 // Internal |
430 // A structured type contains a tag and a variable number of type fields. | 471 // A structured type contains a tag and a variable number of type fields. |
431 template<class Config> | 472 template<class Config> |
432 class TypeImpl<Config>::StructuralType : public TypeImpl<Config> { | 473 class TypeImpl<Config>::StructuralType : public TypeImpl<Config> { |
433 protected: | 474 protected: |
434 template<class> friend class TypeImpl; | 475 template<class> friend class TypeImpl; |
435 friend struct ZoneTypeConfig; // For tags. | 476 friend struct ZoneTypeConfig; // For tags. |
436 friend struct HeapTypeConfig; | 477 friend struct HeapTypeConfig; |
437 | 478 |
438 enum Tag { | 479 enum Tag { |
439 kClassTag, | 480 kClassTag, |
440 kConstantTag, | 481 kConstantTag, |
| 482 kContextTag, |
441 kArrayTag, | 483 kArrayTag, |
442 kFunctionTag, | 484 kFunctionTag, |
443 kUnionTag | 485 kUnionTag |
444 }; | 486 }; |
445 | 487 |
446 int Length() { | 488 int Length() { |
447 return Config::struct_length(Config::as_struct(this)); | 489 return Config::struct_length(Config::as_struct(this)); |
448 } | 490 } |
449 TypeHandle Get(int i) { | 491 TypeHandle Get(int i) { |
450 return Config::struct_get(Config::as_struct(this), i); | 492 return Config::struct_get(Config::as_struct(this), i); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 Config::from_constant(value, BitsetType::Lub(*value), region)); | 531 Config::from_constant(value, BitsetType::Lub(*value), region)); |
490 } | 532 } |
491 | 533 |
492 static ConstantType* cast(TypeImpl* type) { | 534 static ConstantType* cast(TypeImpl* type) { |
493 ASSERT(type->IsConstant()); | 535 ASSERT(type->IsConstant()); |
494 return static_cast<ConstantType*>(type); | 536 return static_cast<ConstantType*>(type); |
495 } | 537 } |
496 }; | 538 }; |
497 | 539 |
498 | 540 |
| 541 template<class Config> |
| 542 class TypeImpl<Config>::ContextType : public StructuralType { |
| 543 public: |
| 544 TypeHandle Outer() { return this->Get(0); } |
| 545 |
| 546 static ContextHandle New(TypeHandle outer, Region* region) { |
| 547 ContextHandle type = Config::template cast<ContextType>( |
| 548 StructuralType::New(StructuralType::kContextTag, 1, region)); |
| 549 type->Set(0, outer); |
| 550 return type; |
| 551 } |
| 552 |
| 553 static ContextType* cast(TypeImpl* type) { |
| 554 ASSERT(type->IsContext()); |
| 555 return static_cast<ContextType*>(type); |
| 556 } |
| 557 }; |
| 558 |
| 559 |
499 // Internal | 560 // Internal |
500 // A union is a structured type with the following invariants: | 561 // A union is a structured type with the following invariants: |
501 // - its length is at least 2 | 562 // - its length is at least 2 |
502 // - at most one field is a bitset, and it must go into index 0 | 563 // - at most one field is a bitset, and it must go into index 0 |
503 // - no field is a union | 564 // - no field is a union |
504 template<class Config> | 565 template<class Config> |
505 class TypeImpl<Config>::UnionType : public StructuralType { | 566 class TypeImpl<Config>::UnionType : public StructuralType { |
506 public: | 567 public: |
507 static UnionHandle New(int length, Region* region) { | 568 static UnionHandle New(int length, Region* region) { |
508 return Config::template cast<UnionType>( | 569 return Config::template cast<UnionType>( |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 bool Narrows(BoundsImpl that) { | 784 bool Narrows(BoundsImpl that) { |
724 return that.lower->Is(this->lower) && this->upper->Is(that.upper); | 785 return that.lower->Is(this->lower) && this->upper->Is(that.upper); |
725 } | 786 } |
726 }; | 787 }; |
727 | 788 |
728 typedef BoundsImpl<ZoneTypeConfig> Bounds; | 789 typedef BoundsImpl<ZoneTypeConfig> Bounds; |
729 | 790 |
730 } } // namespace v8::internal | 791 } } // namespace v8::internal |
731 | 792 |
732 #endif // V8_TYPES_H_ | 793 #endif // V8_TYPES_H_ |
OLD | NEW |