Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Side by Side Diff: src/types-inl.h

Issue 228263005: Implement structural function and array types (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Eps Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_INL_H_ 5 #ifndef V8_TYPES_INL_H_
6 #define V8_TYPES_INL_H_ 6 #define V8_TYPES_INL_H_
7 7
8 #include "types.h" 8 #include "types.h"
9 9
10 #include "factory.h" 10 #include "factory.h"
11 #include "handles-inl.h" 11 #include "handles-inl.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 15
16 // -------------------------------------------------------------------------- //
17 // TypeImpl
18
19 template<class Config>
20 TypeImpl<Config>::Iterator<i::Map> TypeImpl<Config>::Classes() {
21 if (this->IsBitset()) return Iterator<i::Map>();
22 return Iterator<i::Map>(Config::handle(this));
23 }
24
25
26 template<class Config>
27 TypeImpl<Config>::Iterator<i::Object> TypeImpl<Config>::Constants() {
28 if (this->IsBitset()) return Iterator<i::Object>();
29 return Iterator<i::Object>(Config::handle(this));
30 }
31
32
33 template<class Config>
34 TypeImpl<Config>* TypeImpl<Config>::cast(typename Config::Base* object) {
35 TypeImpl* t = static_cast<TypeImpl*>(object);
36 ASSERT(t->IsBitset() || t->IsClass() || t->IsConstant() ||
37 t->IsUnion() || t->IsArray() || t->IsFunction());
38 return t;
39 }
40
41
42 // -------------------------------------------------------------------------- //
43 // ZoneTypeConfig
44
16 // static 45 // static
17 Type* ZoneTypeConfig::handle(Type* type) { 46 template<class T>
47 T* ZoneTypeConfig::handle(T* type) {
18 return type; 48 return type;
19 } 49 }
20 50
21 51
22 // static 52 // static
53 template<class T>
54 T* ZoneTypeConfig::cast(Type* type) {
55 return static_cast<T*>(type);
56 }
57
58
59 // static
23 bool ZoneTypeConfig::is_bitset(Type* type) { 60 bool ZoneTypeConfig::is_bitset(Type* type) {
24 return reinterpret_cast<intptr_t>(type) & 1; 61 return reinterpret_cast<intptr_t>(type) & 1;
25 } 62 }
26 63
27 64
28 // static 65 // static
29 bool ZoneTypeConfig::is_struct(Type* type) { 66 bool ZoneTypeConfig::is_struct(Type* type, int tag) {
30 return !is_bitset(type); 67 return !is_bitset(type) && struct_tag(as_struct(type)) == tag;
31 } 68 }
32 69
33 70
34 // static 71 // static
35 bool ZoneTypeConfig::is_class(Type* type) { 72 bool ZoneTypeConfig::is_class(Type* type) {
36 return is_struct(type) && struct_tag(as_struct(type)) == Type::kClassTag; 73 return is_struct(type, Type::StructuralType::kClassTag);
37 } 74 }
38 75
39 76
40 // static 77 // static
41 bool ZoneTypeConfig::is_constant(Type* type) { 78 bool ZoneTypeConfig::is_constant(Type* type) {
42 return is_struct(type) && struct_tag(as_struct(type)) == Type::kConstantTag; 79 return is_struct(type, Type::StructuralType::kConstantTag);
43 } 80 }
44 81
45 82
46 // static 83 // static
47 int ZoneTypeConfig::as_bitset(Type* type) { 84 int ZoneTypeConfig::as_bitset(Type* type) {
48 ASSERT(is_bitset(type)); 85 ASSERT(is_bitset(type));
49 return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1); 86 return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1);
50 } 87 }
51 88
52 89
53 // static 90 // static
54 ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) { 91 ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) {
55 ASSERT(is_struct(type)); 92 ASSERT(!is_bitset(type));
56 return reinterpret_cast<Struct*>(type); 93 return reinterpret_cast<Struct*>(type);
57 } 94 }
58 95
59 96
60 // static 97 // static
61 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) { 98 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) {
62 ASSERT(is_class(type)); 99 ASSERT(is_class(type));
63 return i::Handle<i::Map>(static_cast<i::Map**>(as_struct(type)[3])); 100 return i::Handle<i::Map>(static_cast<i::Map**>(as_struct(type)[3]));
64 } 101 }
65 102
(...skipping 20 matching lines...) Expand all
86 123
87 // static 124 // static
88 ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structured) { 125 ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structured) {
89 return reinterpret_cast<Type*>(structured); 126 return reinterpret_cast<Type*>(structured);
90 } 127 }
91 128
92 129
93 // static 130 // static
94 ZoneTypeConfig::Type* ZoneTypeConfig::from_class( 131 ZoneTypeConfig::Type* ZoneTypeConfig::from_class(
95 i::Handle<i::Map> map, int lub, Zone* zone) { 132 i::Handle<i::Map> map, int lub, Zone* zone) {
96 Struct* structured = struct_create(Type::kClassTag, 2, zone); 133 Struct* structured = struct_create(Type::StructuralType::kClassTag, 2, zone);
97 structured[2] = from_bitset(lub); 134 structured[2] = from_bitset(lub);
98 structured[3] = map.location(); 135 structured[3] = map.location();
99 return from_struct(structured); 136 return from_struct(structured);
100 } 137 }
101 138
102 139
103 // static 140 // static
104 ZoneTypeConfig::Type* ZoneTypeConfig::from_constant( 141 ZoneTypeConfig::Type* ZoneTypeConfig::from_constant(
105 i::Handle<i::Object> value, int lub, Zone* zone) { 142 i::Handle<i::Object> value, int lub, Zone* zone) {
106 Struct* structured = struct_create(Type::kConstantTag, 2, zone); 143 Struct* structured =
144 struct_create(Type::StructuralType::kConstantTag, 2, zone);
107 structured[2] = from_bitset(lub); 145 structured[2] = from_bitset(lub);
108 structured[3] = value.location(); 146 structured[3] = value.location();
109 return from_struct(structured); 147 return from_struct(structured);
110 } 148 }
111 149
112 150
113 // static 151 // static
114 ZoneTypeConfig::Struct* ZoneTypeConfig::struct_create( 152 ZoneTypeConfig::Struct* ZoneTypeConfig::struct_create(
115 int tag, int length, Zone* zone) { 153 int tag, int length, Zone* zone) {
116 Struct* structured = reinterpret_cast<Struct*>( 154 Struct* structured = reinterpret_cast<Struct*>(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 structured[2 + i] = type; 191 structured[2 + i] = type;
154 } 192 }
155 193
156 194
157 // static 195 // static
158 int ZoneTypeConfig::lub_bitset(Type* type) { 196 int ZoneTypeConfig::lub_bitset(Type* type) {
159 ASSERT(is_class(type) || is_constant(type)); 197 ASSERT(is_class(type) || is_constant(type));
160 return as_bitset(struct_get(as_struct(type), 0)); 198 return as_bitset(struct_get(as_struct(type), 0));
161 } 199 }
162 200
201
163 // -------------------------------------------------------------------------- // 202 // -------------------------------------------------------------------------- //
203 // HeapTypeConfig
164 204
165 // static 205 // static
166 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::handle(Type* type) { 206 template<class T>
207 i::Handle<T> HeapTypeConfig::handle(T* type) {
167 return i::handle(type, i::HeapObject::cast(type)->GetIsolate()); 208 return i::handle(type, i::HeapObject::cast(type)->GetIsolate());
168 } 209 }
169 210
170 211
171 // static 212 // static
213 template<class T>
214 i::Handle<T> HeapTypeConfig::cast(i::Handle<Type> type) {
215 return i::Handle<T>::cast(type);
216 }
217
218
219 // static
172 bool HeapTypeConfig::is_bitset(Type* type) { 220 bool HeapTypeConfig::is_bitset(Type* type) {
173 return type->IsSmi(); 221 return type->IsSmi();
174 } 222 }
175 223
176 224
177 // static 225 // static
178 bool HeapTypeConfig::is_class(Type* type) { 226 bool HeapTypeConfig::is_class(Type* type) {
179 return type->IsMap(); 227 return type->IsMap();
180 } 228 }
181 229
182 230
183 // static 231 // static
184 bool HeapTypeConfig::is_constant(Type* type) { 232 bool HeapTypeConfig::is_constant(Type* type) {
185 return type->IsBox(); 233 return type->IsBox();
186 } 234 }
187 235
188 236
189 // static 237 // static
190 bool HeapTypeConfig::is_struct(Type* type) { 238 bool HeapTypeConfig::is_struct(Type* type, int tag) {
191 return type->IsFixedArray(); 239 return type->IsFixedArray() && struct_tag(as_struct(type)) == tag;
192 } 240 }
193 241
194 242
195 // static 243 // static
196 int HeapTypeConfig::as_bitset(Type* type) { 244 int HeapTypeConfig::as_bitset(Type* type) {
197 return Smi::cast(type)->value(); 245 return i::Smi::cast(type)->value();
198 } 246 }
199 247
200 248
201 // static 249 // static
202 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) { 250 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) {
203 return i::handle(i::Map::cast(type)); 251 return i::handle(i::Map::cast(type));
204 } 252 }
205 253
206 254
207 // static 255 // static
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 343
296 344
297 // static 345 // static
298 int HeapTypeConfig::lub_bitset(Type* type) { 346 int HeapTypeConfig::lub_bitset(Type* type) {
299 return 0; // kNone, which causes recomputation. 347 return 0; // kNone, which causes recomputation.
300 } 348 }
301 349
302 } } // namespace v8::internal 350 } } // namespace v8::internal
303 351
304 #endif // V8_TYPES_INL_H_ 352 #endif // V8_TYPES_INL_H_
OLDNEW
« src/types.h ('K') | « src/types.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698