| 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/factory.h" | 9 #include "src/factory.h" |
| 10 #include "src/handles.h" | 10 #include "src/handles.h" |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 | 780 |
| 781 template<class Config> | 781 template<class Config> |
| 782 class TypeImpl<Config>::RangeType : public StructuralType { | 782 class TypeImpl<Config>::RangeType : public StructuralType { |
| 783 public: | 783 public: |
| 784 int BitsetLub() { return this->Get(0)->AsBitset(); } | 784 int BitsetLub() { return this->Get(0)->AsBitset(); } |
| 785 i::Handle<i::Object> Min() { return this->template GetValue<i::Object>(1); } | 785 i::Handle<i::Object> Min() { return this->template GetValue<i::Object>(1); } |
| 786 i::Handle<i::Object> Max() { return this->template GetValue<i::Object>(2); } | 786 i::Handle<i::Object> Max() { return this->template GetValue<i::Object>(2); } |
| 787 | 787 |
| 788 static RangeHandle New( | 788 static RangeHandle New( |
| 789 i::Handle<i::Object> min, i::Handle<i::Object> max, Region* region) { | 789 i::Handle<i::Object> min, i::Handle<i::Object> max, Region* region) { |
| 790 DCHECK(IsInteger(min->Number()) && IsInteger(max->Number())); |
| 790 DCHECK(min->Number() <= max->Number()); | 791 DCHECK(min->Number() <= max->Number()); |
| 791 RangeHandle type = Config::template cast<RangeType>( | 792 RangeHandle type = Config::template cast<RangeType>( |
| 792 StructuralType::New(StructuralType::kRangeTag, 3, region)); | 793 StructuralType::New(StructuralType::kRangeTag, 3, region)); |
| 793 type->Set(0, BitsetType::New( | 794 type->Set(0, BitsetType::New( |
| 794 BitsetType::Lub(min->Number(), max->Number()), region)); | 795 BitsetType::Lub(min->Number(), max->Number()), region)); |
| 795 type->SetValue(1, min); | 796 type->SetValue(1, min); |
| 796 type->SetValue(2, max); | 797 type->SetValue(2, max); |
| 797 return type; | 798 return type; |
| 798 } | 799 } |
| 799 | 800 |
| 800 static RangeHandle New(Limits lim, Region* region) { | 801 static RangeHandle New(Limits lim, Region* region) { |
| 801 return New(lim.min, lim.max, region); | 802 return New(lim.min, lim.max, region); |
| 802 } | 803 } |
| 803 | 804 |
| 805 // Returns the least integers-only supertype that's not a range. If there is |
| 806 // no such supertype, it returns Range(-inf, +inf) instead. |
| 807 TypeHandle Weaken(Region* region) { |
| 808 bitset lub = this->BitsetLub(); |
| 809 if (BitsetType::Is(SEMANTIC(BitsetType::kOtherNumber), lub)) { |
| 810 return New( |
| 811 Config::factory(region)->NewNumber(-V8_INFINITY), |
| 812 Config::factory(region)->NewNumber(+V8_INFINITY), region); |
| 813 } |
| 814 return BitsetType::New(lub, region); |
| 815 } |
| 816 |
| 804 static RangeType* cast(TypeImpl* type) { | 817 static RangeType* cast(TypeImpl* type) { |
| 805 DCHECK(type->IsRange()); | 818 DCHECK(type->IsRange()); |
| 806 return static_cast<RangeType*>(type); | 819 return static_cast<RangeType*>(type); |
| 807 } | 820 } |
| 808 }; | 821 }; |
| 809 // TODO(neis): Also cache min and max values. | 822 // TODO(neis): Also cache min and max values. |
| 810 // TODO(neis): Allow restricting the representation. | 823 // TODO(neis): Allow restricting the representation. |
| 811 | 824 |
| 812 | 825 |
| 813 // ----------------------------------------------------------------------------- | 826 // ----------------------------------------------------------------------------- |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 static inline Struct* struct_create(int tag, int length, Zone* zone); | 953 static inline Struct* struct_create(int tag, int length, Zone* zone); |
| 941 static inline void struct_shrink(Struct* structure, int length); | 954 static inline void struct_shrink(Struct* structure, int length); |
| 942 static inline int struct_tag(Struct* structure); | 955 static inline int struct_tag(Struct* structure); |
| 943 static inline int struct_length(Struct* structure); | 956 static inline int struct_length(Struct* structure); |
| 944 static inline Type* struct_get(Struct* structure, int i); | 957 static inline Type* struct_get(Struct* structure, int i); |
| 945 static inline void struct_set(Struct* structure, int i, Type* type); | 958 static inline void struct_set(Struct* structure, int i, Type* type); |
| 946 template<class V> | 959 template<class V> |
| 947 static inline i::Handle<V> struct_get_value(Struct* structure, int i); | 960 static inline i::Handle<V> struct_get_value(Struct* structure, int i); |
| 948 template<class V> static inline void struct_set_value( | 961 template<class V> static inline void struct_set_value( |
| 949 Struct* structure, int i, i::Handle<V> x); | 962 Struct* structure, int i, i::Handle<V> x); |
| 963 |
| 964 static inline Factory* factory(Zone* zone) { |
| 965 return zone->isolate()->factory(); |
| 966 } |
| 950 }; | 967 }; |
| 951 | 968 |
| 952 typedef TypeImpl<ZoneTypeConfig> Type; | 969 typedef TypeImpl<ZoneTypeConfig> Type; |
| 953 | 970 |
| 954 | 971 |
| 955 // ----------------------------------------------------------------------------- | 972 // ----------------------------------------------------------------------------- |
| 956 // Heap-allocated types; either smis for bitsets, maps for classes, boxes for | 973 // Heap-allocated types; either smis for bitsets, maps for classes, boxes for |
| 957 // constants, or fixed arrays for unions. | 974 // constants, or fixed arrays for unions. |
| 958 | 975 |
| 959 struct HeapTypeConfig { | 976 struct HeapTypeConfig { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 988 static inline int struct_length(i::Handle<Struct> structure); | 1005 static inline int struct_length(i::Handle<Struct> structure); |
| 989 static inline i::Handle<Type> struct_get(i::Handle<Struct> structure, int i); | 1006 static inline i::Handle<Type> struct_get(i::Handle<Struct> structure, int i); |
| 990 static inline void struct_set( | 1007 static inline void struct_set( |
| 991 i::Handle<Struct> structure, int i, i::Handle<Type> type); | 1008 i::Handle<Struct> structure, int i, i::Handle<Type> type); |
| 992 template<class V> | 1009 template<class V> |
| 993 static inline i::Handle<V> struct_get_value( | 1010 static inline i::Handle<V> struct_get_value( |
| 994 i::Handle<Struct> structure, int i); | 1011 i::Handle<Struct> structure, int i); |
| 995 template<class V> | 1012 template<class V> |
| 996 static inline void struct_set_value( | 1013 static inline void struct_set_value( |
| 997 i::Handle<Struct> structure, int i, i::Handle<V> x); | 1014 i::Handle<Struct> structure, int i, i::Handle<V> x); |
| 1015 |
| 1016 static inline Factory* factory(Isolate* isolate) { |
| 1017 return isolate->factory(); |
| 1018 } |
| 998 }; | 1019 }; |
| 999 | 1020 |
| 1000 typedef TypeImpl<HeapTypeConfig> HeapType; | 1021 typedef TypeImpl<HeapTypeConfig> HeapType; |
| 1001 | 1022 |
| 1002 | 1023 |
| 1003 // ----------------------------------------------------------------------------- | 1024 // ----------------------------------------------------------------------------- |
| 1004 // Type bounds. A simple struct to represent a pair of lower/upper types. | 1025 // Type bounds. A simple struct to represent a pair of lower/upper types. |
| 1005 | 1026 |
| 1006 template<class Config> | 1027 template<class Config> |
| 1007 struct BoundsImpl { | 1028 struct BoundsImpl { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 bool Narrows(BoundsImpl that) { | 1077 bool Narrows(BoundsImpl that) { |
| 1057 return that.lower->Is(this->lower) && this->upper->Is(that.upper); | 1078 return that.lower->Is(this->lower) && this->upper->Is(that.upper); |
| 1058 } | 1079 } |
| 1059 }; | 1080 }; |
| 1060 | 1081 |
| 1061 typedef BoundsImpl<ZoneTypeConfig> Bounds; | 1082 typedef BoundsImpl<ZoneTypeConfig> Bounds; |
| 1062 | 1083 |
| 1063 } } // namespace v8::internal | 1084 } } // namespace v8::internal |
| 1064 | 1085 |
| 1065 #endif // V8_TYPES_H_ | 1086 #endif // V8_TYPES_H_ |
| OLD | NEW |