OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "src/hydrogen-types.h" | 7 #include "src/hydrogen-types.h" |
8 #include "src/isolate-inl.h" | 8 #include "src/isolate-inl.h" |
9 #include "src/types.h" | 9 #include "src/types.h" |
10 #include "test/cctest/cctest.h" | 10 #include "test/cctest/cctest.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 typedef std::vector<TypeHandle> TypeVector; | 182 typedef std::vector<TypeHandle> TypeVector; |
183 typedef std::vector<Handle<i::Map> > MapVector; | 183 typedef std::vector<Handle<i::Map> > MapVector; |
184 typedef std::vector<Handle<i::Object> > ValueVector; | 184 typedef std::vector<Handle<i::Object> > ValueVector; |
185 typedef std::vector<double> DoubleVector; | 185 typedef std::vector<double> DoubleVector; |
186 | 186 |
187 TypeVector types; | 187 TypeVector types; |
188 MapVector maps; | 188 MapVector maps; |
189 ValueVector values; | 189 ValueVector values; |
190 DoubleVector doubles; // Some floating-point values, excluding NaN. | 190 DoubleVector doubles; // Some floating-point values, excluding NaN. |
191 | 191 |
192 // Range type helper functions, partially copied from types.cc. | |
193 // Note: le(min(x,y), max(x,y)) holds iff neither x nor y is NaN. | |
194 static bool le(double x, double y) { | |
rossberg
2014/08/06 13:27:31
Hint: If you just don't make them static, then you
| |
195 return x <= y && copysign(1, x) <= copysign(1, y); | |
196 } | |
197 static bool eq(double x, double y) { | |
198 return le(x, y) && le(y, x); | |
199 } | |
200 static double min(double x, double y) { | |
201 return le(x, y) ? x : y; | |
202 } | |
203 static double max(double x, double y) { | |
204 return le(x, y) ? y : x; | |
205 } | |
206 | |
207 | |
208 | |
192 TypeHandle Of(Handle<i::Object> value) { | 209 TypeHandle Of(Handle<i::Object> value) { |
193 return Type::Of(value, region_); | 210 return Type::Of(value, region_); |
194 } | 211 } |
195 | 212 |
196 TypeHandle NowOf(Handle<i::Object> value) { | 213 TypeHandle NowOf(Handle<i::Object> value) { |
197 return Type::NowOf(value, region_); | 214 return Type::NowOf(value, region_); |
198 } | 215 } |
199 | 216 |
200 TypeHandle Constant(Handle<i::Object> value) { | 217 TypeHandle Constant(Handle<i::Object> value) { |
201 return Type::Constant(value, region_); | 218 return Type::Constant(value, region_); |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 CHECK(T.Constant(fac->NewNumber(-1.0*0.0))->Is(T.MinusZero)); | 559 CHECK(T.Constant(fac->NewNumber(-1.0*0.0))->Is(T.MinusZero)); |
543 CHECK(T.Constant(fac->NewNumber(v8::base::OS::nan_value()))->Is(T.NaN)); | 560 CHECK(T.Constant(fac->NewNumber(v8::base::OS::nan_value()))->Is(T.NaN)); |
544 CHECK(T.Constant(fac->NewNumber(V8_INFINITY))->Is(T.OtherNumber)); | 561 CHECK(T.Constant(fac->NewNumber(V8_INFINITY))->Is(T.OtherNumber)); |
545 CHECK(T.Constant(fac->NewNumber(-V8_INFINITY))->Is(T.OtherNumber)); | 562 CHECK(T.Constant(fac->NewNumber(-V8_INFINITY))->Is(T.OtherNumber)); |
546 } | 563 } |
547 | 564 |
548 void Range() { | 565 void Range() { |
549 // Constructor | 566 // Constructor |
550 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { | 567 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { |
551 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { | 568 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { |
552 double min = std::min(*i, *j); | 569 double min = TypesInstance::min(*i, *j); |
553 double max = std::max(*i, *j); | 570 double max = TypesInstance::max(*i, *j); |
554 TypeHandle type = T.Range(min, max); | 571 TypeHandle type = T.Range(min, max); |
555 CHECK(type->IsRange()); | 572 CHECK(type->IsRange()); |
556 } | 573 } |
557 } | 574 } |
558 | 575 |
559 // Range attributes | 576 // Range attributes |
560 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { | 577 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { |
561 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { | 578 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { |
562 double min = std::min(*i, *j); | 579 double min = TypesInstance::min(*i, *j); |
563 double max = std::max(*i, *j); | 580 double max = TypesInstance::max(*i, *j); |
564 printf("RangeType: min, max = %f, %f\n", min, max); | 581 printf("RangeType: min, max = %f, %f\n", min, max); |
565 TypeHandle type = T.Range(min, max); | 582 TypeHandle type = T.Range(min, max); |
566 printf("RangeType: Min, Max = %f, %f\n", | 583 printf("RangeType: Min, Max = %f, %f\n", |
567 type->AsRange()->Min(), type->AsRange()->Max()); | 584 type->AsRange()->Min(), type->AsRange()->Max()); |
568 CHECK(min == type->AsRange()->Min()); | 585 CHECK(min == type->AsRange()->Min()); |
569 CHECK(max == type->AsRange()->Max()); | 586 CHECK(max == type->AsRange()->Max()); |
570 } | 587 } |
571 } | 588 } |
572 | 589 |
573 // TODO(neis): enable once subtyping is updated. | 590 // TODO(neis): enable once subtyping is updated. |
574 // // Functionality & Injectivity: Range(min1, max1) = Range(min2, max2) <=> | 591 // // Functionality & Injectivity: Range(min1, max1) = Range(min2, max2) <=> |
575 // // min1 = min2 /\ max1 = max2 | 592 // // min1 = min2 /\ max1 = max2 |
576 // for (DoubleIterator i1 = T.doubles.begin(); i1 != T.doubles.end(); ++i1) { | 593 // for (DoubleIterator i1 = T.doubles.begin(); i1 != T.doubles.end(); ++i1) { |
577 // for (DoubleIterator j1 = T.doubles.begin(); j1 != T.doubles.end(); ++j1) { | 594 // for (DoubleIterator j1 = T.doubles.begin(); j1 != T.doubles.end(); ++j1) { |
578 // for (DoubleIterator i2 = T.doubles.begin(); | 595 // for (DoubleIterator i2 = T.doubles.begin(); |
579 // i2 != T.doubles.end(); ++i2) { | 596 // i2 != T.doubles.end(); ++i2) { |
580 // for (DoubleIterator j2 = T.doubles.begin(); | 597 // for (DoubleIterator j2 = T.doubles.begin(); |
581 // j2 != T.doubles.end(); ++j2) { | 598 // j2 != T.doubles.end(); ++j2) { |
582 // double min1 = std::min(*i1, *j1); | 599 // double min1 = TypesInstance::min(*i1, *j1); |
583 // double max1 = std::max(*i1, *j1); | 600 // double max1 = TypesInstance::max(*i1, *j1); |
584 // double min2 = std::min(*i2, *j2); | 601 // double min2 = TypesInstance::min(*i2, *j2); |
585 // double max2 = std::max(*i2, *j2); | 602 // double max2 = TypesInstance::max(*i2, *j2); |
586 // TypeHandle type1 = T.Range(min1, max1); | 603 // TypeHandle type1 = T.Range(min1, max1); |
587 // TypeHandle type2 = T.Range(min2, max2); | 604 // TypeHandle type2 = T.Range(min2, max2); |
588 // CHECK(Equal(type1, type2) == (min1 == min2 && max1 == max2)); | 605 // CHECK(Equal(type1, type2) == (eq(min1, min2) && eq(max1, max2))); |
589 // } | 606 // } |
590 // } | 607 // } |
591 // } | 608 // } |
592 // } | 609 // } |
593 } | 610 } |
594 | 611 |
595 void Array() { | 612 void Array() { |
596 // Constructor | 613 // Constructor |
597 for (int i = 0; i < 20; ++i) { | 614 for (int i = 0; i < 20; ++i) { |
598 TypeHandle type = T.Random(); | 615 TypeHandle type = T.Random(); |
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1944 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); | 1961 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); |
1945 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); | 1962 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); |
1946 } | 1963 } |
1947 | 1964 |
1948 | 1965 |
1949 TEST(HTypeFromType) { | 1966 TEST(HTypeFromType) { |
1950 CcTest::InitializeVM(); | 1967 CcTest::InitializeVM(); |
1951 ZoneTests().HTypeFromType(); | 1968 ZoneTests().HTypeFromType(); |
1952 HeapTests().HTypeFromType(); | 1969 HeapTests().HTypeFromType(); |
1953 } | 1970 } |
OLD | NEW |