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

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

Issue 225923002: 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 UNREACHABLE(); 171 UNREACHABLE();
172 } 172 }
173 173
174 private: 174 private:
175 Region* region_; 175 Region* region_;
176 }; 176 };
177 177
178 178
179 // Testing auxiliaries (breaking the Type abstraction). 179 // Testing auxiliaries (breaking the Type abstraction).
180 struct ZoneRep { 180 struct ZoneRep {
181 static bool IsTagged(Type* t, int tag) { 181 struct Struct { int tag; int length; void* args[1]; };
182 return !IsBitset(t) 182
183 && reinterpret_cast<intptr_t>(AsTagged(t)->at(0)) == tag; 183 static bool IsStruct(Type* t, int tag) {
184 return !IsBitset(t) && AsStruct(t)->tag == tag;
184 } 185 }
185 static bool IsBitset(Type* t) { return reinterpret_cast<intptr_t>(t) & 1; } 186 static bool IsBitset(Type* t) { return reinterpret_cast<intptr_t>(t) & 1; }
186 static bool IsClass(Type* t) { return IsTagged(t, 0); } 187 static bool IsClass(Type* t) { return IsStruct(t, 0); }
187 static bool IsConstant(Type* t) { return IsTagged(t, 1); } 188 static bool IsConstant(Type* t) { return IsStruct(t, 1); }
188 static bool IsUnion(Type* t) { return IsTagged(t, 2); } 189 static bool IsUnion(Type* t) { return IsStruct(t, 2); }
189 190
190 static ZoneList<void*>* AsTagged(Type* t) { 191 static Struct* AsStruct(Type* t) {
191 return reinterpret_cast<ZoneList<void*>*>(t); 192 return reinterpret_cast<Struct*>(t);
192 } 193 }
193 static int AsBitset(Type* t) { 194 static int AsBitset(Type* t) {
194 return static_cast<int>(reinterpret_cast<intptr_t>(t) >> 1); 195 return static_cast<int>(reinterpret_cast<intptr_t>(t) >> 1);
195 } 196 }
196 static Map* AsClass(Type* t) { 197 static Map* AsClass(Type* t) {
197 return *reinterpret_cast<Map**>(AsTagged(t)->at(2)); 198 return *static_cast<Map**>(AsStruct(t)->args[1]);
198 } 199 }
199 static Object* AsConstant(Type* t) { 200 static Object* AsConstant(Type* t) {
200 return *reinterpret_cast<Object**>(AsTagged(t)->at(2)); 201 return *static_cast<Object**>(AsStruct(t)->args[1]);
201 } 202 }
202 static ZoneList<Type*>* AsUnion(Type* t) { 203 static Struct* AsUnion(Type* t) {
203 return reinterpret_cast<ZoneList<Type*>*>(AsTagged(t)); 204 return AsStruct(t);
204 } 205 }
206 static int Length(Struct* structured) { return structured->length; }
205 207
206 static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; } 208 static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
207 }; 209 };
208 210
209 211
210 struct HeapRep { 212 struct HeapRep {
213 typedef FixedArray Struct;
214
215 static bool IsStruct(Handle<HeapType> t, int tag) {
216 return t->IsFixedArray() && Smi::cast(AsStruct(t)->get(0))->value() == tag;
217 }
211 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); } 218 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); }
212 static bool IsClass(Handle<HeapType> t) { return t->IsMap(); } 219 static bool IsClass(Handle<HeapType> t) { return t->IsMap(); }
213 static bool IsConstant(Handle<HeapType> t) { return t->IsBox(); } 220 static bool IsConstant(Handle<HeapType> t) { return t->IsBox(); }
214 static bool IsUnion(Handle<HeapType> t) { return t->IsFixedArray(); } 221 static bool IsUnion(Handle<HeapType> t) { return IsStruct(t, 2); }
215 222
223 static Struct* AsStruct(Handle<HeapType> t) { return FixedArray::cast(*t); }
216 static int AsBitset(Handle<HeapType> t) { return Smi::cast(*t)->value(); } 224 static int AsBitset(Handle<HeapType> t) { return Smi::cast(*t)->value(); }
217 static Map* AsClass(Handle<HeapType> t) { return Map::cast(*t); } 225 static Map* AsClass(Handle<HeapType> t) { return Map::cast(*t); }
218 static Object* AsConstant(Handle<HeapType> t) { 226 static Object* AsConstant(Handle<HeapType> t) {
219 return Box::cast(*t)->value(); 227 return Box::cast(*t)->value();
220 } 228 }
221 static FixedArray* AsUnion(Handle<HeapType> t) { 229 static Struct* AsUnion(Handle<HeapType> t) { return AsStruct(t); }
222 return FixedArray::cast(*t); 230 static int Length(Struct* structured) { return structured->length() - 1; }
223 }
224 231
225 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; } 232 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
226 }; 233 };
227 234
228 235
229 template<class Type, class TypeHandle, class Region, class Rep> 236 template<class Type, class TypeHandle, class Region, class Rep>
230 struct Tests : Rep { 237 struct Tests : Rep {
231 Isolate* isolate; 238 Isolate* isolate;
232 HandleScope scope; 239 HandleScope scope;
233 Zone zone; 240 Zone zone;
(...skipping 13 matching lines...) Expand all
247 CHECK_EQ(Rep::IsUnion(type1), Rep::IsUnion(type2)); 254 CHECK_EQ(Rep::IsUnion(type1), Rep::IsUnion(type2));
248 CHECK_EQ(type1->NumClasses(), type2->NumClasses()); 255 CHECK_EQ(type1->NumClasses(), type2->NumClasses());
249 CHECK_EQ(type1->NumConstants(), type2->NumConstants()); 256 CHECK_EQ(type1->NumConstants(), type2->NumConstants());
250 if (Rep::IsBitset(type1)) { 257 if (Rep::IsBitset(type1)) {
251 CHECK_EQ(Rep::AsBitset(type1), Rep::AsBitset(type2)); 258 CHECK_EQ(Rep::AsBitset(type1), Rep::AsBitset(type2));
252 } else if (Rep::IsClass(type1)) { 259 } else if (Rep::IsClass(type1)) {
253 CHECK_EQ(Rep::AsClass(type1), Rep::AsClass(type2)); 260 CHECK_EQ(Rep::AsClass(type1), Rep::AsClass(type2));
254 } else if (Rep::IsConstant(type1)) { 261 } else if (Rep::IsConstant(type1)) {
255 CHECK_EQ(Rep::AsConstant(type1), Rep::AsConstant(type2)); 262 CHECK_EQ(Rep::AsConstant(type1), Rep::AsConstant(type2));
256 } else if (Rep::IsUnion(type1)) { 263 } else if (Rep::IsUnion(type1)) {
257 CHECK_EQ(Rep::AsUnion(type1)->length(), Rep::AsUnion(type2)->length()); 264 CHECK_EQ(
265 Rep::Length(Rep::AsUnion(type1)), Rep::Length(Rep::AsUnion(type2)));
258 } 266 }
259 CHECK(type1->Is(type2)); 267 CHECK(type1->Is(type2));
260 CHECK(type2->Is(type1)); 268 CHECK(type2->Is(type1));
261 } 269 }
262 270
263 void CheckSub(TypeHandle type1, TypeHandle type2) { 271 void CheckSub(TypeHandle type1, TypeHandle type2) {
264 CHECK(type1->Is(type2)); 272 CHECK(type1->Is(type2));
265 CHECK(!type2->Is(type1)); 273 CHECK(!type2->Is(type1));
266 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) { 274 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) {
267 CHECK_NE(Rep::AsBitset(type1), Rep::AsBitset(type2)); 275 CHECK_NE(Rep::AsBitset(type1), Rep::AsBitset(type2));
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 ZoneTests().Intersect(); 895 ZoneTests().Intersect();
888 HeapTests().Intersect(); 896 HeapTests().Intersect();
889 } 897 }
890 898
891 899
892 TEST(Convert) { 900 TEST(Convert) {
893 CcTest::InitializeVM(); 901 CcTest::InitializeVM();
894 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); 902 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>();
895 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); 903 HeapTests().Convert<Type, Type*, Zone, ZoneRep>();
896 } 904 }
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