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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/handles.h ('k') | src/types.cc » ('j') | src/types.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/types.h
diff --git a/src/types.h b/src/types.h
new file mode 100644
index 0000000000000000000000000000000000000000..6643aa731ecfc46d7b4a9b55beea6cfe8ee0fc97
--- /dev/null
+++ b/src/types.h
@@ -0,0 +1,147 @@
+// Copyright 2013 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef V8_TYPES_H_
+#define V8_TYPES_H_
+
+#include "v8.h"
+
+#include "objects.h"
+
+namespace v8 {
+namespace internal {
+
+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.
+ public:
+ static Type* None() { return from_bitset(kNone); }
+ static Type* Any() { return from_bitset(kAny); }
+
+ static Type* Oddball() { return from_bitset(kOddball); }
+ static Type* Boolean() { return from_bitset(kBoolean); }
+ static Type* Null() { return from_bitset(kNull); }
+ static Type* Undefined() { return from_bitset(kUndefined); }
+
+ static Type* Number() { return from_bitset(kNumber); }
+ static Type* Smi() { return from_bitset(kSmi); }
+ static Type* Double() { return from_bitset(kDouble); }
+
+ static Type* Name() { return from_bitset(kName); }
+ static Type* UniqueName() { return from_bitset(kUniqueName); }
+ static Type* String() { return from_bitset(kString); }
+ static Type* InternalizedString() { return from_bitset(kInternalizedString); }
+ static Type* Symbol() { return from_bitset(kSymbol); }
+
+ static Type* Receiver() { return from_bitset(kReceiver); }
+ static Type* Object() { return from_bitset(kObject); }
+ static Type* Array() { return from_bitset(kArray); }
+ static Type* Function() { return from_bitset(kFunction); }
+ static Type* Proxy() { return from_bitset(kProxy); }
+
+ static Type* Class(Handle<Map> map) { return from_handle(map); }
+ static Type* Constant(Handle<HeapObject> value) {
+ ASSERT(!value->IsMap() && !value->IsFixedArray());
+ return from_handle(value);
+ }
+
+ static Type* Union(Handle<Type> type1, Handle<Type> type2);
+ static Type* Optional(Handle<Type> type); // type \/ Undefined
+
+ bool Is(Handle<Type> that);
+ bool Maybe(Handle<Type> that);
+
+ // TODO(rossberg): method to iterate unions?
+
+ private:
+ // A union is a fixed array containing types. Invariants:
+ // - its length is at least 2
+ // - at most one field is a bitset, and it must go into index 0
+ // - no field is a union
+ typedef FixedArray Unioned;
+
+ enum {
+ kNull = 1<<0,
+ kUndefined = 1<<1,
+ kBoolean = 1<<2,
+ kSmi = 1<<3,
+ kDouble = 1<<4,
+ kSymbol = 1<<5,
+ kInternalizedString = 1<<6,
+ kOtherString = 1<<7,
+ kArray = 1<<8,
+ kFunction = 1<<9,
+ kOtherObject = 1<<10,
+ kProxy = 1<<11,
+
+ kOddball = kBoolean | kNull | kUndefined,
+ kNumber = kSmi | kDouble,
+ kString = kInternalizedString | kOtherString,
+ kUniqueName = kSymbol | kInternalizedString,
+ kName = kSymbol | kString,
+ kObject = kArray | kFunction | kOtherObject,
+ kReceiver = kObject | kProxy,
+ kAny = kOddball | kNumber | kName | kReceiver,
+ kNone = 0
+ };
+
+ bool is_bitset() { return this->IsSmi(); }
+ bool is_class() { return this->IsMap(); }
+ bool is_constant() { return !(is_bitset() || is_class() || is_union()); }
+ bool is_union() { return this->IsFixedArray(); }
+
+ int as_bitset() { return Smi::cast(this)->value(); }
+ Handle<Map> as_class() { return Handle<Map>::cast(handle()); }
+ 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. :)
+ Handle<Unioned> as_union() { return Handle<Unioned>::cast(handle()); }
+
+ Handle<Type> handle() { return handle_via(this); }
+ Handle<Type> handle_via(Type* type) {
+ 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.
+ return v8::internal::handle(this, HeapObject::cast(type)->GetIsolate());
+ }
+
+ static Type* from_bitset(int bitset) {
+ return static_cast<Type*>(Object::cast(Smi::FromInt(bitset)));
+ }
+ static Type* from_handle(Handle<HeapObject> handle) {
+ return static_cast<Type*>(Object::cast(*handle));
+ }
+
+ static Handle<Type> union_get(Handle<Unioned> unioned, int i) {
+ Type* type = static_cast<Type*>(unioned->get(i));
+ ASSERT(!type->is_union());
+ return type->handle_via(from_handle(unioned));
+ }
+
+ int LubBitset();
+ int GlbBitset();
+ bool InUnion(Handle<Unioned> unioned, int current_size);
+ int ExtendUnion(Handle<Unioned> unioned, int current_size);
+};
+
+} } // namespace v8::internal
+
+#endif // V8_TYPES_H_
« 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