Index: src/types.h |
diff --git a/src/types.h b/src/types.h |
index 0f59c0c8394402d185e8e1207424a99b28ad5e18..55c7e6c4692d8e19c89177a97128bd8ee222cd8b 100644 |
--- a/src/types.h |
+++ b/src/types.h |
@@ -270,21 +270,29 @@ namespace internal { |
// typedef TypeImpl<Config> Type; |
// typedef Base; |
// typedef Struct; |
+// typedef Range; |
// typedef Region; |
// template<class> struct Handle { typedef type; } // No template typedefs... |
// template<class T> static Handle<T>::type null_handle(); |
// template<class T> static Handle<T>::type handle(T* t); // !is_bitset(t) |
// template<class T> static Handle<T>::type cast(Handle<Type>::type); |
+// |
// static bool is_bitset(Type*); |
// static bool is_class(Type*); |
// static bool is_struct(Type*, int tag); |
+// static bool is_range(Type*); |
+// |
// static bitset as_bitset(Type*); |
// static i::Handle<i::Map> as_class(Type*); |
// static Handle<Struct>::type as_struct(Type*); |
+// static Handle<Range>::type as_range(Type*); |
+// |
// static Type* from_bitset(bitset); |
// static Handle<Type>::type from_bitset(bitset, Region*); |
// static Handle<Type>::type from_class(i::Handle<Map>, Region*); |
// static Handle<Type>::type from_struct(Handle<Struct>::type, int tag); |
+// static Handle<Type>::type from_range(Handle<Range>::type); |
+// |
// static Handle<Struct>::type struct_create(int tag, int length, Region*); |
// static void struct_shrink(Handle<Struct>::type, int length); |
// static int struct_tag(Handle<Struct>::type); |
@@ -295,6 +303,12 @@ namespace internal { |
// static i::Handle<V> struct_get_value(Handle<Struct>::type, int); |
// template<class V> |
// static void struct_set_value(Handle<Struct>::type, int, i::Handle<V>); |
+// |
+// static Handle<Range>::type range_create(Region*); |
+// static int range_get_bitset(Handle<Range>::type); |
+// static void range_set_bitset(Handle<Range>::type, int); |
+// static double range_get_double(Handle<Range>::type, int); |
+// static void range_set_double(Handle<Range>::type, int, double, Region*); |
// } |
template<class Config> |
class TypeImpl : public Config::Base { |
@@ -354,8 +368,7 @@ class TypeImpl : public Config::Base { |
static TypeHandle Constant(i::Handle<i::Object> value, Region* region) { |
return ConstantType::New(value, region); |
} |
- static TypeHandle Range( |
- i::Handle<i::Object> min, i::Handle<i::Object> max, Region* region) { |
+ static TypeHandle Range(double min, double max, Region* region) { |
return RangeType::New( |
min, max, BitsetType::New(REPRESENTATION(BitsetType::kTagged | |
BitsetType::kUntaggedNumber), |
@@ -453,6 +466,7 @@ class TypeImpl : public Config::Base { |
// Inspection. |
+ bool IsRange() { return Config::is_range(this); } |
bool IsClass() { |
return Config::is_class(this) |
|| Config::is_struct(this, StructuralType::kClassTag); |
@@ -460,9 +474,6 @@ class TypeImpl : public Config::Base { |
bool IsConstant() { |
return Config::is_struct(this, StructuralType::kConstantTag); |
} |
- bool IsRange() { |
- return Config::is_struct(this, StructuralType::kRangeTag); |
- } |
bool IsContext() { |
return Config::is_struct(this, StructuralType::kContextTag); |
} |
@@ -523,6 +534,8 @@ class TypeImpl : public Config::Base { |
void Print(); |
#endif |
+ bool IsUnionForTesting() { return IsUnion(); } |
+ |
protected: |
// Friends. |
@@ -565,22 +578,17 @@ class TypeImpl : public Config::Base { |
} |
struct Limits { |
- i::Handle<i::Object> min; |
- i::Handle<i::Object> max; |
+ double min; |
+ double max; |
bitset representation; |
- Limits(i::Handle<i::Object> min, i::Handle<i::Object> max, |
- bitset representation) |
+ Limits(double min, double max, bitset representation) |
: min(min), max(max), representation(representation) {} |
explicit Limits(RangeType* range) |
: min(range->Min()), |
max(range->Max()), |
- representation(REPRESENTATION(range->Bound()->AsBitset())) {} |
+ representation(REPRESENTATION(range->Bound())) {} |
static Limits Empty(Region* region) { |
- // TODO(jarin) Get rid of the heap numbers. |
- i::Factory* f = i::Isolate::Current()->factory(); |
- i::Handle<i::Object> min = f->NewNumber(1); |
- i::Handle<i::Object> max = f->NewNumber(0); |
- return Limits(min, max, BitsetType::kNone); |
+ return Limits(1, 0, BitsetType::kNone); |
} |
}; |
@@ -698,7 +706,6 @@ class TypeImpl<Config>::StructuralType : public TypeImpl<Config> { |
enum Tag { |
kClassTag, |
kConstantTag, |
- kRangeTag, |
kContextTag, |
kArrayTag, |
kFunctionTag, |
@@ -824,29 +831,28 @@ class TypeImpl<Config>::ConstantType : public StructuralType { |
// ----------------------------------------------------------------------------- |
// Range types. |
-template<class Config> |
-class TypeImpl<Config>::RangeType : public StructuralType { |
+template <class Config> |
+class TypeImpl<Config>::RangeType : public TypeImpl<Config> { |
public: |
- TypeHandle Bound() { return this->Get(0); } |
- i::Handle<i::Object> Min() { return this->template GetValue<i::Object>(1); } |
- i::Handle<i::Object> Max() { return this->template GetValue<i::Object>(2); } |
- |
- static RangeHandle New(i::Handle<i::Object> min, i::Handle<i::Object> max, |
- TypeHandle representation, Region* region) { |
- DCHECK(IsInteger(min->Number()) && IsInteger(max->Number())); |
- DCHECK(min->Number() <= max->Number()); |
+ bitset Bound() { return Config::range_get_bitset(Config::as_range(this)); } |
+ double Min() { return Config::range_get_double(Config::as_range(this), 0); } |
+ double Max() { return Config::range_get_double(Config::as_range(this), 1); } |
+ |
+ static RangeHandle New(double min, double max, TypeHandle representation, |
+ Region* region) { |
+ DCHECK(IsInteger(min) && IsInteger(max)); |
+ DCHECK(min <= max); |
bitset representation_bits = representation->AsBitset(); |
DCHECK(REPRESENTATION(representation_bits) == representation_bits); |
- RangeHandle type = Config::template cast<RangeType>( |
- StructuralType::New(StructuralType::kRangeTag, 3, region)); |
+ typename Config::template Handle<typename Config::Range>::type range = |
+ Config::range_create(region); |
- bitset bits = SEMANTIC(BitsetType::Lub(min->Number(), max->Number())) | |
- representation_bits; |
- type->Set(0, BitsetType::New(bits, region)); |
- type->SetValue(1, min); |
- type->SetValue(2, max); |
- return type; |
+ bitset bits = SEMANTIC(BitsetType::Lub(min, max)) | representation_bits; |
+ Config::range_set_bitset(range, bits); |
+ Config::range_set_double(range, 0, min, region); |
+ Config::range_set_double(range, 1, max, region); |
+ return Config::template cast<RangeType>(Config::from_range(range)); |
} |
static RangeHandle New(Limits lim, Region* region) { |
@@ -970,9 +976,19 @@ struct ZoneTypeConfig { |
typedef TypeImpl<ZoneTypeConfig> Type; |
class Base {}; |
typedef void* Struct; |
+ // Hack: the Struct and Range types can be aliased in memory, the first |
+ // pointer word of each both must be the tag (kRangeStructTag for Range, |
+ // anything else for Struct) so that we can differentiate them. |
+ struct Range { |
+ void* tag; |
+ int bitset; |
+ double limits[2]; |
+ }; |
typedef i::Zone Region; |
template<class T> struct Handle { typedef T* type; }; |
+ static const int kRangeStructTag = 0x1000; |
+ |
template<class T> static inline T* null_handle(); |
template<class T> static inline T* handle(T* type); |
template<class T> static inline T* cast(Type* type); |
@@ -980,15 +996,18 @@ struct ZoneTypeConfig { |
static inline bool is_bitset(Type* type); |
static inline bool is_class(Type* type); |
static inline bool is_struct(Type* type, int tag); |
+ static inline bool is_range(Type* type); |
static inline Type::bitset as_bitset(Type* type); |
static inline i::Handle<i::Map> as_class(Type* type); |
static inline Struct* as_struct(Type* type); |
+ static inline Range* as_range(Type* type); |
static inline Type* from_bitset(Type::bitset); |
static inline Type* from_bitset(Type::bitset, Zone* zone); |
static inline Type* from_class(i::Handle<i::Map> map, Zone* zone); |
static inline Type* from_struct(Struct* structured); |
+ static inline Type* from_range(Range* range); |
static inline Struct* struct_create(int tag, int length, Zone* zone); |
static inline void struct_shrink(Struct* structure, int length); |
@@ -1000,6 +1019,12 @@ struct ZoneTypeConfig { |
static inline i::Handle<V> struct_get_value(Struct* structure, int i); |
template<class V> static inline void struct_set_value( |
Struct* structure, int i, i::Handle<V> x); |
+ |
+ static inline Range* range_create(Zone* zone); |
+ static inline int range_get_bitset(Range* range); |
+ static inline void range_set_bitset(Range* range, int); |
+ static inline double range_get_double(Range*, int index); |
+ static inline void range_set_double(Range*, int index, double value, Zone*); |
}; |
typedef TypeImpl<ZoneTypeConfig> Type; |
@@ -1013,9 +1038,12 @@ struct HeapTypeConfig { |
typedef TypeImpl<HeapTypeConfig> Type; |
typedef i::Object Base; |
typedef i::FixedArray Struct; |
+ typedef i::FixedArray Range; |
typedef i::Isolate Region; |
template<class T> struct Handle { typedef i::Handle<T> type; }; |
+ static const int kRangeStructTag = 0xffff; |
+ |
template<class T> static inline i::Handle<T> null_handle(); |
template<class T> static inline i::Handle<T> handle(T* type); |
template<class T> static inline i::Handle<T> cast(i::Handle<Type> type); |
@@ -1023,16 +1051,19 @@ struct HeapTypeConfig { |
static inline bool is_bitset(Type* type); |
static inline bool is_class(Type* type); |
static inline bool is_struct(Type* type, int tag); |
+ static inline bool is_range(Type* type); |
static inline Type::bitset as_bitset(Type* type); |
static inline i::Handle<i::Map> as_class(Type* type); |
static inline i::Handle<Struct> as_struct(Type* type); |
+ static inline i::Handle<Range> as_range(Type* type); |
static inline Type* from_bitset(Type::bitset); |
static inline i::Handle<Type> from_bitset(Type::bitset, Isolate* isolate); |
static inline i::Handle<Type> from_class( |
i::Handle<i::Map> map, Isolate* isolate); |
static inline i::Handle<Type> from_struct(i::Handle<Struct> structure); |
+ static inline i::Handle<Type> from_range(i::Handle<Range> range); |
static inline i::Handle<Struct> struct_create( |
int tag, int length, Isolate* isolate); |
@@ -1048,6 +1079,13 @@ struct HeapTypeConfig { |
template<class V> |
static inline void struct_set_value( |
i::Handle<Struct> structure, int i, i::Handle<V> x); |
+ |
+ static inline i::Handle<Range> range_create(Isolate* isolate); |
+ static inline int range_get_bitset(i::Handle<Range> range); |
+ static inline void range_set_bitset(i::Handle<Range> range, int value); |
+ static inline double range_get_double(i::Handle<Range> range, int index); |
+ static inline void range_set_double(i::Handle<Range> range, int index, |
+ double value, Isolate* isolate); |
}; |
typedef TypeImpl<HeapTypeConfig> HeapType; |