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 "src/conversions.h" | 8 #include "src/conversions.h" |
9 #include "src/handles.h" | 9 #include "src/handles.h" |
10 #include "src/objects.h" | 10 #include "src/objects.h" |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 class BitsetType; // Internal | 325 class BitsetType; // Internal |
326 class StructuralType; // Internal | 326 class StructuralType; // Internal |
327 class UnionType; // Internal | 327 class UnionType; // Internal |
328 | 328 |
329 class ClassType; | 329 class ClassType; |
330 class ConstantType; | 330 class ConstantType; |
331 class RangeType; | 331 class RangeType; |
332 class ContextType; | 332 class ContextType; |
333 class ArrayType; | 333 class ArrayType; |
334 class FunctionType; | 334 class FunctionType; |
| 335 class TupleType; |
335 | 336 |
336 typedef typename Config::template Handle<TypeImpl>::type TypeHandle; | 337 typedef typename Config::template Handle<TypeImpl>::type TypeHandle; |
337 typedef typename Config::template Handle<ClassType>::type ClassHandle; | 338 typedef typename Config::template Handle<ClassType>::type ClassHandle; |
338 typedef typename Config::template Handle<ConstantType>::type ConstantHandle; | 339 typedef typename Config::template Handle<ConstantType>::type ConstantHandle; |
339 typedef typename Config::template Handle<RangeType>::type RangeHandle; | 340 typedef typename Config::template Handle<RangeType>::type RangeHandle; |
340 typedef typename Config::template Handle<ContextType>::type ContextHandle; | 341 typedef typename Config::template Handle<ContextType>::type ContextHandle; |
341 typedef typename Config::template Handle<ArrayType>::type ArrayHandle; | 342 typedef typename Config::template Handle<ArrayType>::type ArrayHandle; |
342 typedef typename Config::template Handle<FunctionType>::type FunctionHandle; | 343 typedef typename Config::template Handle<FunctionType>::type FunctionHandle; |
343 typedef typename Config::template Handle<UnionType>::type UnionHandle; | 344 typedef typename Config::template Handle<UnionType>::type UnionHandle; |
| 345 typedef typename Config::template Handle<TupleType>::type TupleHandle; |
344 typedef typename Config::Region Region; | 346 typedef typename Config::Region Region; |
345 | 347 |
346 // Constructors. | 348 // Constructors. |
347 | 349 |
348 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ | 350 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ |
349 static TypeImpl* type() { \ | 351 static TypeImpl* type() { \ |
350 return BitsetType::New(BitsetType::k##type); \ | 352 return BitsetType::New(BitsetType::k##type); \ |
351 } \ | 353 } \ |
352 static TypeHandle type(Region* region) { \ | 354 static TypeHandle type(Region* region) { \ |
353 return BitsetType::New(BitsetType::k##type, region); \ | 355 return BitsetType::New(BitsetType::k##type, region); \ |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 return function; | 419 return function; |
418 } | 420 } |
419 static TypeHandle Function(TypeHandle result, int arity, TypeHandle* params, | 421 static TypeHandle Function(TypeHandle result, int arity, TypeHandle* params, |
420 Region* region) { | 422 Region* region) { |
421 FunctionHandle function = Function(result, Any(region), arity, region); | 423 FunctionHandle function = Function(result, Any(region), arity, region); |
422 for (int i = 0; i < arity; ++i) { | 424 for (int i = 0; i < arity; ++i) { |
423 function->InitParameter(i, params[i]); | 425 function->InitParameter(i, params[i]); |
424 } | 426 } |
425 return function; | 427 return function; |
426 } | 428 } |
| 429 static TypeHandle Tuple(TypeHandle first, TypeHandle second, TypeHandle third, |
| 430 Region* region) { |
| 431 TupleHandle tuple = TupleType::New(3, region); |
| 432 tuple->InitElement(0, first); |
| 433 tuple->InitElement(1, second); |
| 434 tuple->InitElement(2, third); |
| 435 return tuple; |
| 436 } |
427 | 437 |
428 #define CONSTRUCT_SIMD_TYPE(NAME, Name, name, lane_count, lane_type) \ | 438 #define CONSTRUCT_SIMD_TYPE(NAME, Name, name, lane_count, lane_type) \ |
429 static TypeHandle Name(Isolate* isolate, Region* region); | 439 static TypeHandle Name(Isolate* isolate, Region* region); |
430 SIMD128_TYPES(CONSTRUCT_SIMD_TYPE) | 440 SIMD128_TYPES(CONSTRUCT_SIMD_TYPE) |
431 #undef CONSTRUCT_SIMD_TYPE | 441 #undef CONSTRUCT_SIMD_TYPE |
432 | 442 |
433 static TypeHandle Union(TypeHandle type1, TypeHandle type2, Region* reg); | 443 static TypeHandle Union(TypeHandle type1, TypeHandle type2, Region* reg); |
434 static TypeHandle Intersect(TypeHandle type1, TypeHandle type2, Region* reg); | 444 static TypeHandle Intersect(TypeHandle type1, TypeHandle type2, Region* reg); |
435 | 445 |
436 static TypeHandle Of(double value, Region* region) { | 446 static TypeHandle Of(double value, Region* region) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 } | 504 } |
495 bool IsContext() { | 505 bool IsContext() { |
496 return Config::is_struct(this, StructuralType::kContextTag); | 506 return Config::is_struct(this, StructuralType::kContextTag); |
497 } | 507 } |
498 bool IsArray() { | 508 bool IsArray() { |
499 return Config::is_struct(this, StructuralType::kArrayTag); | 509 return Config::is_struct(this, StructuralType::kArrayTag); |
500 } | 510 } |
501 bool IsFunction() { | 511 bool IsFunction() { |
502 return Config::is_struct(this, StructuralType::kFunctionTag); | 512 return Config::is_struct(this, StructuralType::kFunctionTag); |
503 } | 513 } |
| 514 bool IsTuple() { return Config::is_struct(this, StructuralType::kTupleTag); } |
504 | 515 |
505 ClassType* AsClass() { return ClassType::cast(this); } | 516 ClassType* AsClass() { return ClassType::cast(this); } |
506 ConstantType* AsConstant() { return ConstantType::cast(this); } | 517 ConstantType* AsConstant() { return ConstantType::cast(this); } |
507 RangeType* AsRange() { return RangeType::cast(this); } | 518 RangeType* AsRange() { return RangeType::cast(this); } |
508 ContextType* AsContext() { return ContextType::cast(this); } | 519 ContextType* AsContext() { return ContextType::cast(this); } |
509 ArrayType* AsArray() { return ArrayType::cast(this); } | 520 ArrayType* AsArray() { return ArrayType::cast(this); } |
510 FunctionType* AsFunction() { return FunctionType::cast(this); } | 521 FunctionType* AsFunction() { return FunctionType::cast(this); } |
| 522 TupleType* AsTuple() { return TupleType::cast(this); } |
511 | 523 |
512 // Minimum and maximum of a numeric type. | 524 // Minimum and maximum of a numeric type. |
513 // These functions do not distinguish between -0 and +0. If the type equals | 525 // These functions do not distinguish between -0 and +0. If the type equals |
514 // kNaN, they return NaN; otherwise kNaN is ignored. Only call these | 526 // kNaN, they return NaN; otherwise kNaN is ignored. Only call these |
515 // functions on subtypes of Number. | 527 // functions on subtypes of Number. |
516 double Min(); | 528 double Min(); |
517 double Max(); | 529 double Max(); |
518 | 530 |
519 // Extracts a range from the type: if the type is a range or a union | 531 // Extracts a range from the type: if the type is a range or a union |
520 // containing a range, that range is returned; otherwise, NULL is returned. | 532 // containing a range, that range is returned; otherwise, NULL is returned. |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 template<class> friend class TypeImpl; | 729 template<class> friend class TypeImpl; |
718 friend struct ZoneTypeConfig; // For tags. | 730 friend struct ZoneTypeConfig; // For tags. |
719 friend struct HeapTypeConfig; | 731 friend struct HeapTypeConfig; |
720 | 732 |
721 enum Tag { | 733 enum Tag { |
722 kClassTag, | 734 kClassTag, |
723 kConstantTag, | 735 kConstantTag, |
724 kContextTag, | 736 kContextTag, |
725 kArrayTag, | 737 kArrayTag, |
726 kFunctionTag, | 738 kFunctionTag, |
| 739 kTupleTag, |
727 kUnionTag | 740 kUnionTag |
728 }; | 741 }; |
729 | 742 |
730 int Length() { | 743 int Length() { |
731 return Config::struct_length(Config::as_struct(this)); | 744 return Config::struct_length(Config::as_struct(this)); |
732 } | 745 } |
733 TypeHandle Get(int i) { | 746 TypeHandle Get(int i) { |
734 DCHECK(0 <= i && i < this->Length()); | 747 DCHECK(0 <= i && i < this->Length()); |
735 return Config::struct_get(Config::as_struct(this), i); | 748 return Config::struct_get(Config::as_struct(this), i); |
736 } | 749 } |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 } | 973 } |
961 | 974 |
962 static FunctionType* cast(TypeImpl* type) { | 975 static FunctionType* cast(TypeImpl* type) { |
963 DCHECK(type->IsFunction()); | 976 DCHECK(type->IsFunction()); |
964 return static_cast<FunctionType*>(type); | 977 return static_cast<FunctionType*>(type); |
965 } | 978 } |
966 }; | 979 }; |
967 | 980 |
968 | 981 |
969 // ----------------------------------------------------------------------------- | 982 // ----------------------------------------------------------------------------- |
| 983 // Tuple types. |
| 984 |
| 985 template <class Config> |
| 986 class TypeImpl<Config>::TupleType : public StructuralType { |
| 987 public: |
| 988 int Arity() { return this->Length(); } |
| 989 TypeHandle Element(int i) { return this->Get(i); } |
| 990 |
| 991 void InitElement(int i, TypeHandle type) { this->Set(i, type); } |
| 992 |
| 993 static TupleHandle New(int length, Region* region) { |
| 994 TupleHandle type = Config::template cast<TupleType>( |
| 995 StructuralType::New(StructuralType::kTupleTag, length, region)); |
| 996 return type; |
| 997 } |
| 998 |
| 999 static TupleType* cast(TypeImpl* type) { |
| 1000 DCHECK(type->IsTuple()); |
| 1001 return static_cast<TupleType*>(type); |
| 1002 } |
| 1003 }; |
| 1004 |
| 1005 |
| 1006 // ----------------------------------------------------------------------------- |
970 // Type iterators. | 1007 // Type iterators. |
971 | 1008 |
972 template<class Config> template<class T> | 1009 template<class Config> template<class T> |
973 class TypeImpl<Config>::Iterator { | 1010 class TypeImpl<Config>::Iterator { |
974 public: | 1011 public: |
975 bool Done() const { return index_ < 0; } | 1012 bool Done() const { return index_ < 0; } |
976 i::Handle<T> Current(); | 1013 i::Handle<T> Current(); |
977 void Advance(); | 1014 void Advance(); |
978 | 1015 |
979 private: | 1016 private: |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1176 return that.lower->Is(this->lower) && this->upper->Is(that.upper); | 1213 return that.lower->Is(this->lower) && this->upper->Is(that.upper); |
1177 } | 1214 } |
1178 }; | 1215 }; |
1179 | 1216 |
1180 typedef BoundsImpl<ZoneTypeConfig> Bounds; | 1217 typedef BoundsImpl<ZoneTypeConfig> Bounds; |
1181 | 1218 |
1182 } // namespace internal | 1219 } // namespace internal |
1183 } // namespace v8 | 1220 } // namespace v8 |
1184 | 1221 |
1185 #endif // V8_TYPES_H_ | 1222 #endif // V8_TYPES_H_ |
OLD | NEW |