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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 // | 72 // |
73 // Typically, the latter should be used to check whether a specific case needs | 73 // Typically, the latter should be used to check whether a specific case needs |
74 // handling (e.g., via T->Maybe(Number)). | 74 // handling (e.g., via T->Maybe(Number)). |
75 // | 75 // |
76 // There is no functionality to discover whether a type is a leaf in the | 76 // There is no functionality to discover whether a type is a leaf in the |
77 // lattice. That is intentional. It should always be possible to refine the | 77 // lattice. That is intentional. It should always be possible to refine the |
78 // lattice (e.g., splitting up number types further) without invalidating any | 78 // lattice (e.g., splitting up number types further) without invalidating any |
79 // existing assumptions or tests. | 79 // existing assumptions or tests. |
80 // | 80 // |
81 // Internally, all 'primitive' types, and their unions, are represented as | 81 // Internally, all 'primitive' types, and their unions, are represented as |
82 // bitsets via smis. Class and Constant are heap pointers to the respective | 82 // bitsets via smis. Class is a heap pointer to the respective map. Only |
83 // argument. Only unions containing Class'es or Constant's require allocation. | 83 // Constant's, or unions containing Class'es or Constant's, require allocation. |
84 // | 84 // |
85 // The type representation is heap-allocated, so cannot (currently) be used in | 85 // The type representation is heap-allocated, so cannot (currently) be used in |
86 // a parallel compilation context. | 86 // a parallel compilation context. |
87 | 87 |
88 class Type : public Object { | 88 class Type : public Object { |
89 public: | 89 public: |
90 typedef v8::internal::Object Value; | |
danno
2013/06/06 15:36:03
As discussed, I think the typedef is overkill here
rossberg
2013/06/06 15:38:35
Removed.
| |
91 | |
90 static Type* None() { return from_bitset(kNone); } | 92 static Type* None() { return from_bitset(kNone); } |
91 static Type* Any() { return from_bitset(kAny); } | 93 static Type* Any() { return from_bitset(kAny); } |
92 | 94 |
93 static Type* Oddball() { return from_bitset(kOddball); } | 95 static Type* Oddball() { return from_bitset(kOddball); } |
94 static Type* Boolean() { return from_bitset(kBoolean); } | 96 static Type* Boolean() { return from_bitset(kBoolean); } |
95 static Type* Null() { return from_bitset(kNull); } | 97 static Type* Null() { return from_bitset(kNull); } |
96 static Type* Undefined() { return from_bitset(kUndefined); } | 98 static Type* Undefined() { return from_bitset(kUndefined); } |
97 | 99 |
98 static Type* Number() { return from_bitset(kNumber); } | 100 static Type* Number() { return from_bitset(kNumber); } |
99 static Type* Smi() { return from_bitset(kSmi); } | 101 static Type* Smi() { return from_bitset(kSmi); } |
100 static Type* Double() { return from_bitset(kDouble); } | 102 static Type* Double() { return from_bitset(kDouble); } |
101 | 103 |
102 static Type* Name() { return from_bitset(kName); } | 104 static Type* Name() { return from_bitset(kName); } |
103 static Type* UniqueName() { return from_bitset(kUniqueName); } | 105 static Type* UniqueName() { return from_bitset(kUniqueName); } |
104 static Type* String() { return from_bitset(kString); } | 106 static Type* String() { return from_bitset(kString); } |
105 static Type* InternalizedString() { return from_bitset(kInternalizedString); } | 107 static Type* InternalizedString() { return from_bitset(kInternalizedString); } |
106 static Type* Symbol() { return from_bitset(kSymbol); } | 108 static Type* Symbol() { return from_bitset(kSymbol); } |
107 | 109 |
108 static Type* Receiver() { return from_bitset(kReceiver); } | 110 static Type* Receiver() { return from_bitset(kReceiver); } |
109 static Type* Object() { return from_bitset(kObject); } | 111 static Type* Object() { return from_bitset(kObject); } |
110 static Type* Array() { return from_bitset(kArray); } | 112 static Type* Array() { return from_bitset(kArray); } |
111 static Type* Function() { return from_bitset(kFunction); } | 113 static Type* Function() { return from_bitset(kFunction); } |
112 static Type* Proxy() { return from_bitset(kProxy); } | 114 static Type* Proxy() { return from_bitset(kProxy); } |
113 | 115 |
114 static Type* Class(Handle<Map> map) { return from_handle(map); } | 116 static Type* Class(Handle<Map> map) { return from_handle(map); } |
115 static Type* Constant(Handle<HeapObject> value) { | 117 static Type* Constant(Handle<HeapObject> value) { |
116 ASSERT(!value->IsMap() && !value->IsFixedArray()); | 118 return Constant(value, value->GetIsolate()); |
117 return from_handle(value); | 119 } |
120 static Type* Constant(Handle<Value> value, Isolate* isolate) { | |
121 return from_handle(isolate->factory()->NewBox(value)); | |
118 } | 122 } |
119 | 123 |
120 static Type* Union(Handle<Type> type1, Handle<Type> type2); | 124 static Type* Union(Handle<Type> type1, Handle<Type> type2); |
121 static Type* Optional(Handle<Type> type); // type \/ Undefined | 125 static Type* Optional(Handle<Type> type); // type \/ Undefined |
122 | 126 |
123 bool Is(Handle<Type> that); | 127 bool Is(Handle<Type> that); |
124 bool Maybe(Handle<Type> that); | 128 bool Maybe(Handle<Type> that); |
125 | 129 |
126 // TODO(rossberg): method to iterate unions? | 130 // TODO(rossberg): method to iterate unions? |
127 | 131 |
(...skipping 24 matching lines...) Expand all Loading... | |
152 kUniqueName = kSymbol | kInternalizedString, | 156 kUniqueName = kSymbol | kInternalizedString, |
153 kName = kSymbol | kString, | 157 kName = kSymbol | kString, |
154 kObject = kArray | kFunction | kOtherObject, | 158 kObject = kArray | kFunction | kOtherObject, |
155 kReceiver = kObject | kProxy, | 159 kReceiver = kObject | kProxy, |
156 kAny = kOddball | kNumber | kName | kReceiver, | 160 kAny = kOddball | kNumber | kName | kReceiver, |
157 kNone = 0 | 161 kNone = 0 |
158 }; | 162 }; |
159 | 163 |
160 bool is_bitset() { return this->IsSmi(); } | 164 bool is_bitset() { return this->IsSmi(); } |
161 bool is_class() { return this->IsMap(); } | 165 bool is_class() { return this->IsMap(); } |
162 bool is_constant() { return !(is_bitset() || is_class() || is_union()); } | 166 bool is_constant() { return this->IsBox(); } |
163 bool is_union() { return this->IsFixedArray(); } | 167 bool is_union() { return this->IsFixedArray(); } |
164 | 168 |
165 int as_bitset() { return Smi::cast(this)->value(); } | 169 int as_bitset() { return Smi::cast(this)->value(); } |
166 Handle<Map> as_class() { return Handle<Map>::cast(handle()); } | 170 Handle<Map> as_class() { return Handle<Map>::cast(handle()); } |
167 Handle<HeapObject> as_constant() { | 171 Handle<Box> as_constant() { return Handle<Box>::cast(handle()); } |
168 ASSERT(is_constant()); | |
169 return Handle<HeapObject>::cast(handle()); | |
170 } | |
171 Handle<Unioned> as_union() { return Handle<Unioned>::cast(handle()); } | 172 Handle<Unioned> as_union() { return Handle<Unioned>::cast(handle()); } |
172 | 173 |
173 Handle<Type> handle() { return handle_via_isolate_of(this); } | 174 Handle<Type> handle() { return handle_via_isolate_of(this); } |
174 Handle<Type> handle_via_isolate_of(Type* type) { | 175 Handle<Type> handle_via_isolate_of(Type* type) { |
175 ASSERT(type->IsHeapObject()); | 176 ASSERT(type->IsHeapObject()); |
176 return v8::internal::handle(this, HeapObject::cast(type)->GetIsolate()); | 177 return v8::internal::handle(this, HeapObject::cast(type)->GetIsolate()); |
177 } | 178 } |
178 | 179 |
179 static Type* from_bitset(int bitset) { | 180 static Type* from_bitset(int bitset) { |
180 return static_cast<Type*>(Object::cast(Smi::FromInt(bitset))); | 181 return static_cast<Type*>(Object::cast(Smi::FromInt(bitset))); |
(...skipping 10 matching lines...) Expand all Loading... | |
191 | 192 |
192 int LubBitset(); // least upper bound that's a bitset | 193 int LubBitset(); // least upper bound that's a bitset |
193 int GlbBitset(); // greatest lower bound that's a bitset | 194 int GlbBitset(); // greatest lower bound that's a bitset |
194 bool InUnion(Handle<Unioned> unioned, int current_size); | 195 bool InUnion(Handle<Unioned> unioned, int current_size); |
195 int ExtendUnion(Handle<Unioned> unioned, int current_size); | 196 int ExtendUnion(Handle<Unioned> unioned, int current_size); |
196 }; | 197 }; |
197 | 198 |
198 } } // namespace v8::internal | 199 } } // namespace v8::internal |
199 | 200 |
200 #endif // V8_TYPES_H_ | 201 #endif // V8_TYPES_H_ |
OLD | NEW |