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

Side by Side Diff: src/types.h

Issue 16154027: New unified type representation (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: More simplifications 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/handles.h ('k') | src/types.cc » ('j') | src/types.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #ifndef V8_TYPES_H_
29 #define V8_TYPES_H_
30
31 #include "v8.h"
32
33 #include "objects.h"
34
35 namespace v8 {
36 namespace internal {
37
38 class Type : public Object {
Sven Panne 2013/06/05 08:02:41 Although I hate comments in general, a comment des
rossberg 2013/06/05 09:44:24 Done.
39 public:
40 static Type* None() { return from_bitset(kNone); }
41 static Type* Any() { return from_bitset(kAny); }
42
43 static Type* Oddball() { return from_bitset(kOddball); }
44 static Type* Boolean() { return from_bitset(kBoolean); }
45 static Type* Null() { return from_bitset(kNull); }
46 static Type* Undefined() { return from_bitset(kUndefined); }
47
48 static Type* Number() { return from_bitset(kNumber); }
49 static Type* Smi() { return from_bitset(kSmi); }
50 static Type* Double() { return from_bitset(kDouble); }
51
52 static Type* Name() { return from_bitset(kName); }
53 static Type* UniqueName() { return from_bitset(kUniqueName); }
54 static Type* String() { return from_bitset(kString); }
55 static Type* InternalizedString() { return from_bitset(kInternalizedString); }
56 static Type* Symbol() { return from_bitset(kSymbol); }
57
58 static Type* Receiver() { return from_bitset(kReceiver); }
59 static Type* Object() { return from_bitset(kObject); }
60 static Type* Array() { return from_bitset(kArray); }
61 static Type* Function() { return from_bitset(kFunction); }
62 static Type* Proxy() { return from_bitset(kProxy); }
63
64 static Type* Class(Handle<Map> map) { return from_handle(map); }
65 static Type* Constant(Handle<HeapObject> value) {
66 ASSERT(!value->IsMap() && !value->IsFixedArray());
67 return from_handle(value);
68 }
69
70 static Type* Union(Handle<Type> type1, Handle<Type> type2);
71 static Type* Optional(Handle<Type> type); // type \/ Undefined
72
73 bool Is(Handle<Type> that);
74 bool Maybe(Handle<Type> that);
75
76 // TODO(rossberg): method to iterate unions?
77
78 private:
79 // A union is a fixed array containing types. Invariants:
80 // - its length is at least 2
81 // - at most one field is a bitset, and it must go into index 0
82 // - no field is a union
83 typedef FixedArray Unioned;
84
85 enum {
86 kNull = 1<<0,
87 kUndefined = 1<<1,
88 kBoolean = 1<<2,
89 kSmi = 1<<3,
90 kDouble = 1<<4,
91 kSymbol = 1<<5,
92 kInternalizedString = 1<<6,
93 kOtherString = 1<<7,
94 kArray = 1<<8,
95 kFunction = 1<<9,
96 kOtherObject = 1<<10,
97 kProxy = 1<<11,
98
99 kOddball = kBoolean | kNull | kUndefined,
100 kNumber = kSmi | kDouble,
101 kString = kInternalizedString | kOtherString,
102 kUniqueName = kSymbol | kInternalizedString,
103 kName = kSymbol | kString,
104 kObject = kArray | kFunction | kOtherObject,
105 kReceiver = kObject | kProxy,
106 kAny = kOddball | kNumber | kName | kReceiver,
107 kNone = 0
108 };
109
110 bool is_bitset() { return this->IsSmi(); }
111 bool is_class() { return this->IsMap(); }
112 bool is_constant() { return !(is_bitset() || is_class() || is_union()); }
113 bool is_union() { return this->IsFixedArray(); }
114
115 int as_bitset() { return Smi::cast(this)->value(); }
116 Handle<Map> as_class() { return Handle<Map>::cast(handle()); }
117 Handle<HeapObject> as_constant() { return Handle<HeapObject>::cast(handle());}
Sven Panne 2013/06/05 08:02:41 Cheater! ;-)
rossberg 2013/06/05 09:44:24 No more, wanted to add an assertion anyway. :)
118 Handle<Unioned> as_union() { return Handle<Unioned>::cast(handle()); }
119
120 Handle<Type> handle() { return handle_via(this); }
121 Handle<Type> handle_via(Type* type) {
122 ASSERT(type->IsHeapObject());
Sven Panne 2013/06/05 08:02:41 No need for this ASSERT, HeapObject::cast already
rossberg 2013/06/05 09:44:24 Yeah, but I wanted to make it very explicit.
123 return v8::internal::handle(this, HeapObject::cast(type)->GetIsolate());
124 }
125
126 static Type* from_bitset(int bitset) {
127 return static_cast<Type*>(Object::cast(Smi::FromInt(bitset)));
128 }
129 static Type* from_handle(Handle<HeapObject> handle) {
130 return static_cast<Type*>(Object::cast(*handle));
131 }
132
133 static Handle<Type> union_get(Handle<Unioned> unioned, int i) {
134 Type* type = static_cast<Type*>(unioned->get(i));
135 ASSERT(!type->is_union());
136 return type->handle_via(from_handle(unioned));
137 }
138
139 int LubBitset();
140 int GlbBitset();
141 bool InUnion(Handle<Unioned> unioned, int current_size);
142 int ExtendUnion(Handle<Unioned> unioned, int current_size);
143 };
144
145 } } // namespace v8::internal
146
147 #endif // V8_TYPES_H_
OLDNEW
« no previous file with comments | « src/handles.h ('k') | src/types.cc » ('j') | src/types.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698