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

Side by Side Diff: test/cctest/test-types.cc

Issue 228223002: Revert "Refactoring to allow adding new structured types" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
« no previous file with comments | « src/types-inl.h ('k') | no next file » | 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 UNREACHABLE(); 169 UNREACHABLE();
170 } 170 }
171 171
172 private: 172 private:
173 Region* region_; 173 Region* region_;
174 }; 174 };
175 175
176 176
177 // Testing auxiliaries (breaking the Type abstraction). 177 // Testing auxiliaries (breaking the Type abstraction).
178 struct ZoneRep { 178 struct ZoneRep {
179 struct Struct { int tag; int length; void* args[1]; }; 179 static bool IsTagged(Type* t, int tag) {
180 180 return !IsBitset(t)
181 static bool IsStruct(Type* t, int tag) { 181 && reinterpret_cast<intptr_t>(AsTagged(t)->at(0)) == tag;
182 return !IsBitset(t) && AsStruct(t)->tag == tag;
183 } 182 }
184 static bool IsBitset(Type* t) { return reinterpret_cast<intptr_t>(t) & 1; } 183 static bool IsBitset(Type* t) { return reinterpret_cast<intptr_t>(t) & 1; }
185 static bool IsClass(Type* t) { return IsStruct(t, 0); } 184 static bool IsClass(Type* t) { return IsTagged(t, 0); }
186 static bool IsConstant(Type* t) { return IsStruct(t, 1); } 185 static bool IsConstant(Type* t) { return IsTagged(t, 1); }
187 static bool IsUnion(Type* t) { return IsStruct(t, 2); } 186 static bool IsUnion(Type* t) { return IsTagged(t, 2); }
188 187
189 static Struct* AsStruct(Type* t) { 188 static ZoneList<void*>* AsTagged(Type* t) {
190 return reinterpret_cast<Struct*>(t); 189 return reinterpret_cast<ZoneList<void*>*>(t);
191 } 190 }
192 static int AsBitset(Type* t) { 191 static int AsBitset(Type* t) {
193 return static_cast<int>(reinterpret_cast<intptr_t>(t) >> 1); 192 return static_cast<int>(reinterpret_cast<intptr_t>(t) >> 1);
194 } 193 }
195 static Map* AsClass(Type* t) { 194 static Map* AsClass(Type* t) {
196 return *static_cast<Map**>(AsStruct(t)->args[1]); 195 return *reinterpret_cast<Map**>(AsTagged(t)->at(2));
197 } 196 }
198 static Object* AsConstant(Type* t) { 197 static Object* AsConstant(Type* t) {
199 return *static_cast<Object**>(AsStruct(t)->args[1]); 198 return *reinterpret_cast<Object**>(AsTagged(t)->at(2));
200 } 199 }
201 static Struct* AsUnion(Type* t) { 200 static ZoneList<Type*>* AsUnion(Type* t) {
202 return AsStruct(t); 201 return reinterpret_cast<ZoneList<Type*>*>(AsTagged(t));
203 } 202 }
204 static int Length(Struct* structured) { return structured->length; }
205 203
206 static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; } 204 static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
207 }; 205 };
208 206
209 207
210 struct HeapRep { 208 struct HeapRep {
211 typedef FixedArray Struct;
212
213 static bool IsStruct(Handle<HeapType> t, int tag) {
214 return t->IsFixedArray() && Smi::cast(AsStruct(t)->get(0))->value() == tag;
215 }
216 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); } 209 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); }
217 static bool IsClass(Handle<HeapType> t) { return t->IsMap(); } 210 static bool IsClass(Handle<HeapType> t) { return t->IsMap(); }
218 static bool IsConstant(Handle<HeapType> t) { return t->IsBox(); } 211 static bool IsConstant(Handle<HeapType> t) { return t->IsBox(); }
219 static bool IsUnion(Handle<HeapType> t) { return IsStruct(t, 2); } 212 static bool IsUnion(Handle<HeapType> t) { return t->IsFixedArray(); }
220 213
221 static Struct* AsStruct(Handle<HeapType> t) { return FixedArray::cast(*t); }
222 static int AsBitset(Handle<HeapType> t) { return Smi::cast(*t)->value(); } 214 static int AsBitset(Handle<HeapType> t) { return Smi::cast(*t)->value(); }
223 static Map* AsClass(Handle<HeapType> t) { return Map::cast(*t); } 215 static Map* AsClass(Handle<HeapType> t) { return Map::cast(*t); }
224 static Object* AsConstant(Handle<HeapType> t) { 216 static Object* AsConstant(Handle<HeapType> t) {
225 return Box::cast(*t)->value(); 217 return Box::cast(*t)->value();
226 } 218 }
227 static Struct* AsUnion(Handle<HeapType> t) { return AsStruct(t); } 219 static FixedArray* AsUnion(Handle<HeapType> t) {
228 static int Length(Struct* structured) { return structured->length() - 1; } 220 return FixedArray::cast(*t);
221 }
229 222
230 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; } 223 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
231 }; 224 };
232 225
233 226
234 template<class Type, class TypeHandle, class Region, class Rep> 227 template<class Type, class TypeHandle, class Region, class Rep>
235 struct Tests : Rep { 228 struct Tests : Rep {
236 Isolate* isolate; 229 Isolate* isolate;
237 HandleScope scope; 230 HandleScope scope;
238 Zone zone; 231 Zone zone;
(...skipping 13 matching lines...) Expand all
252 CHECK_EQ(Rep::IsUnion(type1), Rep::IsUnion(type2)); 245 CHECK_EQ(Rep::IsUnion(type1), Rep::IsUnion(type2));
253 CHECK_EQ(type1->NumClasses(), type2->NumClasses()); 246 CHECK_EQ(type1->NumClasses(), type2->NumClasses());
254 CHECK_EQ(type1->NumConstants(), type2->NumConstants()); 247 CHECK_EQ(type1->NumConstants(), type2->NumConstants());
255 if (Rep::IsBitset(type1)) { 248 if (Rep::IsBitset(type1)) {
256 CHECK_EQ(Rep::AsBitset(type1), Rep::AsBitset(type2)); 249 CHECK_EQ(Rep::AsBitset(type1), Rep::AsBitset(type2));
257 } else if (Rep::IsClass(type1)) { 250 } else if (Rep::IsClass(type1)) {
258 CHECK_EQ(Rep::AsClass(type1), Rep::AsClass(type2)); 251 CHECK_EQ(Rep::AsClass(type1), Rep::AsClass(type2));
259 } else if (Rep::IsConstant(type1)) { 252 } else if (Rep::IsConstant(type1)) {
260 CHECK_EQ(Rep::AsConstant(type1), Rep::AsConstant(type2)); 253 CHECK_EQ(Rep::AsConstant(type1), Rep::AsConstant(type2));
261 } else if (Rep::IsUnion(type1)) { 254 } else if (Rep::IsUnion(type1)) {
262 CHECK_EQ( 255 CHECK_EQ(Rep::AsUnion(type1)->length(), Rep::AsUnion(type2)->length());
263 Rep::Length(Rep::AsUnion(type1)), Rep::Length(Rep::AsUnion(type2)));
264 } 256 }
265 CHECK(type1->Is(type2)); 257 CHECK(type1->Is(type2));
266 CHECK(type2->Is(type1)); 258 CHECK(type2->Is(type1));
267 } 259 }
268 260
269 void CheckSub(TypeHandle type1, TypeHandle type2) { 261 void CheckSub(TypeHandle type1, TypeHandle type2) {
270 CHECK(type1->Is(type2)); 262 CHECK(type1->Is(type2));
271 CHECK(!type2->Is(type1)); 263 CHECK(!type2->Is(type1));
272 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) { 264 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) {
273 CHECK_NE(Rep::AsBitset(type1), Rep::AsBitset(type2)); 265 CHECK_NE(Rep::AsBitset(type1), Rep::AsBitset(type2));
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 ZoneTests().Intersect(); 877 ZoneTests().Intersect();
886 HeapTests().Intersect(); 878 HeapTests().Intersect();
887 } 879 }
888 880
889 881
890 TEST(Convert) { 882 TEST(Convert) {
891 CcTest::InitializeVM(); 883 CcTest::InitializeVM();
892 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); 884 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>();
893 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); 885 HeapTests().Convert<Type, Type*, Zone, ZoneRep>();
894 } 886 }
OLDNEW
« no previous file with comments | « src/types-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698