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

Side by Side Diff: src/types.h

Issue 16562003: Allow smis for singleton types (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comments Created 7 years, 6 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
« no previous file with comments | « src/objects-printer.cc ('k') | src/types.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 static Type* None() { return from_bitset(kNone); } 90 static Type* None() { return from_bitset(kNone); }
91 static Type* Any() { return from_bitset(kAny); } 91 static Type* Any() { return from_bitset(kAny); }
92 92
93 static Type* Oddball() { return from_bitset(kOddball); } 93 static Type* Oddball() { return from_bitset(kOddball); }
(...skipping 12 matching lines...) Expand all
106 static Type* Symbol() { return from_bitset(kSymbol); } 106 static Type* Symbol() { return from_bitset(kSymbol); }
107 107
108 static Type* Receiver() { return from_bitset(kReceiver); } 108 static Type* Receiver() { return from_bitset(kReceiver); }
109 static Type* Object() { return from_bitset(kObject); } 109 static Type* Object() { return from_bitset(kObject); }
110 static Type* Array() { return from_bitset(kArray); } 110 static Type* Array() { return from_bitset(kArray); }
111 static Type* Function() { return from_bitset(kFunction); } 111 static Type* Function() { return from_bitset(kFunction); }
112 static Type* Proxy() { return from_bitset(kProxy); } 112 static Type* Proxy() { return from_bitset(kProxy); }
113 113
114 static Type* Class(Handle<Map> map) { return from_handle(map); } 114 static Type* Class(Handle<Map> map) { return from_handle(map); }
115 static Type* Constant(Handle<HeapObject> value) { 115 static Type* Constant(Handle<HeapObject> value) {
116 ASSERT(!value->IsMap() && !value->IsFixedArray()); 116 return Constant(value, value->GetIsolate());
117 return from_handle(value); 117 }
118 static Type* Constant(Handle<v8::internal::Object> value, Isolate* isolate) {
119 return from_handle(isolate->factory()->NewBox(value));
118 } 120 }
119 121
120 static Type* Union(Handle<Type> type1, Handle<Type> type2); 122 static Type* Union(Handle<Type> type1, Handle<Type> type2);
121 static Type* Optional(Handle<Type> type); // type \/ Undefined 123 static Type* Optional(Handle<Type> type); // type \/ Undefined
122 124
123 bool Is(Handle<Type> that); 125 bool Is(Handle<Type> that);
124 bool Maybe(Handle<Type> that); 126 bool Maybe(Handle<Type> that);
125 127
126 // TODO(rossberg): method to iterate unions? 128 // TODO(rossberg): method to iterate unions?
127 129
(...skipping 24 matching lines...) Expand all
152 kUniqueName = kSymbol | kInternalizedString, 154 kUniqueName = kSymbol | kInternalizedString,
153 kName = kSymbol | kString, 155 kName = kSymbol | kString,
154 kObject = kArray | kFunction | kOtherObject, 156 kObject = kArray | kFunction | kOtherObject,
155 kReceiver = kObject | kProxy, 157 kReceiver = kObject | kProxy,
156 kAny = kOddball | kNumber | kName | kReceiver, 158 kAny = kOddball | kNumber | kName | kReceiver,
157 kNone = 0 159 kNone = 0
158 }; 160 };
159 161
160 bool is_bitset() { return this->IsSmi(); } 162 bool is_bitset() { return this->IsSmi(); }
161 bool is_class() { return this->IsMap(); } 163 bool is_class() { return this->IsMap(); }
162 bool is_constant() { return !(is_bitset() || is_class() || is_union()); } 164 bool is_constant() { return this->IsBox(); }
163 bool is_union() { return this->IsFixedArray(); } 165 bool is_union() { return this->IsFixedArray(); }
164 166
165 int as_bitset() { return Smi::cast(this)->value(); } 167 int as_bitset() { return Smi::cast(this)->value(); }
166 Handle<Map> as_class() { return Handle<Map>::cast(handle()); } 168 Handle<Map> as_class() { return Handle<Map>::cast(handle()); }
167 Handle<HeapObject> as_constant() { 169 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()); } 170 Handle<Unioned> as_union() { return Handle<Unioned>::cast(handle()); }
172 171
173 Handle<Type> handle() { return handle_via_isolate_of(this); } 172 Handle<Type> handle() { return handle_via_isolate_of(this); }
174 Handle<Type> handle_via_isolate_of(Type* type) { 173 Handle<Type> handle_via_isolate_of(Type* type) {
175 ASSERT(type->IsHeapObject()); 174 ASSERT(type->IsHeapObject());
176 return v8::internal::handle(this, HeapObject::cast(type)->GetIsolate()); 175 return v8::internal::handle(this, HeapObject::cast(type)->GetIsolate());
177 } 176 }
178 177
179 static Type* from_bitset(int bitset) { 178 static Type* from_bitset(int bitset) {
180 return static_cast<Type*>(Object::cast(Smi::FromInt(bitset))); 179 return static_cast<Type*>(Object::cast(Smi::FromInt(bitset)));
(...skipping 10 matching lines...) Expand all
191 190
192 int LubBitset(); // least upper bound that's a bitset 191 int LubBitset(); // least upper bound that's a bitset
193 int GlbBitset(); // greatest lower bound that's a bitset 192 int GlbBitset(); // greatest lower bound that's a bitset
194 bool InUnion(Handle<Unioned> unioned, int current_size); 193 bool InUnion(Handle<Unioned> unioned, int current_size);
195 int ExtendUnion(Handle<Unioned> unioned, int current_size); 194 int ExtendUnion(Handle<Unioned> unioned, int current_size);
196 }; 195 };
197 196
198 } } // namespace v8::internal 197 } } // namespace v8::internal
199 198
200 #endif // V8_TYPES_H_ 199 #endif // V8_TYPES_H_
OLDNEW
« no previous file with comments | « src/objects-printer.cc ('k') | src/types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698