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

Side by Side Diff: runtime/vm/object.h

Issue 2005723004: Fraction class prototype and test (not to be committed). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: work in progress Created 4 years, 5 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
« no previous file with comments | « runtime/vm/method_recognizer.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 // Returns an instance of Double or Double::null(). 1203 // Returns an instance of Double or Double::null().
1204 // 'index' points to either: 1204 // 'index' points to either:
1205 // - constants_list_ position of found element, or 1205 // - constants_list_ position of found element, or
1206 // - constants_list_ position where new canonical can be inserted. 1206 // - constants_list_ position where new canonical can be inserted.
1207 RawDouble* LookupCanonicalDouble(Zone* zone, 1207 RawDouble* LookupCanonicalDouble(Zone* zone,
1208 double value, intptr_t* index) const; 1208 double value, intptr_t* index) const;
1209 RawMint* LookupCanonicalMint(Zone* zone, 1209 RawMint* LookupCanonicalMint(Zone* zone,
1210 int64_t value, intptr_t* index) const; 1210 int64_t value, intptr_t* index) const;
1211 RawBigint* LookupCanonicalBigint(Zone* zone, 1211 RawBigint* LookupCanonicalBigint(Zone* zone,
1212 const Bigint& value, intptr_t* index) const; 1212 const Bigint& value, intptr_t* index) const;
1213 RawFraction* LookupCanonicalFraction(Zone* zone,
1214 const Fraction& value,
1215 intptr_t* index) const;
1213 // The methods above are more efficient than this generic one. 1216 // The methods above are more efficient than this generic one.
1214 RawInstance* LookupCanonicalInstance(Zone* zone, 1217 RawInstance* LookupCanonicalInstance(Zone* zone,
1215 const Instance& value) const; 1218 const Instance& value) const;
1216 1219
1217 RawInstance* InsertCanonicalConstant(Zone* zone, 1220 RawInstance* InsertCanonicalConstant(Zone* zone,
1218 const Instance& constant) const; 1221 const Instance& constant) const;
1219 void InsertCanonicalNumber(Zone* zone, 1222 void InsertCanonicalNumber(Zone* zone,
1220 intptr_t index, 1223 intptr_t index,
1221 const Number& constant) const; 1224 const Number& constant) const;
1222 1225
(...skipping 5114 matching lines...) Expand 10 before | Expand all | Expand 10 after
6337 static RawTypedData* NewDigitsFromDecCString(const char* str, intptr_t* used, 6340 static RawTypedData* NewDigitsFromDecCString(const char* str, intptr_t* used,
6338 Heap::Space space = Heap::kNew); 6341 Heap::Space space = Heap::kNew);
6339 6342
6340 static RawBigint* Allocate(intptr_t length, Heap::Space space = Heap::kNew); 6343 static RawBigint* Allocate(intptr_t length, Heap::Space space = Heap::kNew);
6341 6344
6342 FINAL_HEAP_OBJECT_IMPLEMENTATION(Bigint, Integer); 6345 FINAL_HEAP_OBJECT_IMPLEMENTATION(Bigint, Integer);
6343 friend class Class; 6346 friend class Class;
6344 }; 6347 };
6345 6348
6346 6349
6347 // Class Double represents class Double in corelib_impl, which implements 6350 class Fraction : public Number {
6351 public:
6352 RawInteger* numerator() const {
6353 return raw_ptr()->numerator_;
6354 }
6355 RawInteger* denominator() const {
6356 return raw_ptr()->denominator_;
6357 }
6358 virtual bool CanonicalizeEquals(const Instance& other) const;
6359
6360 static RawFraction* New(Heap::Space space = Heap::kNew); // For snapshots.
6361
6362 static RawFraction* New(uint64_t numerator,
6363 uint64_t denominator,
6364 Heap::Space space = Heap::kNew);
6365
6366 // Returns a canonical Fraction object allocated in the old gen space.
6367 static RawFraction* NewCanonical(const Fraction& value);
6368
6369 // Returns a canonical Fraction object (allocated in the old gen space) or
6370 // Fraction::null() if str points to a string that does not convert to a
6371 // Fraction value.
6372 static RawFraction* NewCanonical(const String& str);
6373
6374 static intptr_t InstanceSize() {
6375 return RoundedAllocationSize(sizeof(RawFraction));
6376 }
6377
6378 static intptr_t numerator_offset() {
6379 return OFFSET_OF(RawFraction, numerator_);
6380 }
6381 static intptr_t denominator_offset() {
6382 return OFFSET_OF(RawFraction, denominator_);
6383 }
6384
6385 private:
6386 void set_numerator(const Integer& value) const;
6387 void set_denominator(const Integer& value) const;
6388
6389 FINAL_HEAP_OBJECT_IMPLEMENTATION(Fraction, Number);
6390 friend class Class;
6391 friend class Number;
6392 };
6393
6394
6395 // Class Double represents Dart class _Double in runtime/lib, which implements
6348 // abstract class double in corelib. 6396 // abstract class double in corelib.
6349 class Double : public Number { 6397 class Double : public Number {
6350 public: 6398 public:
6351 double value() const { 6399 double value() const {
6352 return raw_ptr()->value_; 6400 return raw_ptr()->value_;
6353 } 6401 }
6354 6402
6355 bool BitwiseEqualsToDouble(double value) const; 6403 bool BitwiseEqualsToDouble(double value) const;
6356 virtual bool OperatorEquals(const Instance& other) const; 6404 virtual bool OperatorEquals(const Instance& other) const;
6357 virtual bool CanonicalizeEquals(const Instance& other) const; 6405 virtual bool CanonicalizeEquals(const Instance& other) const;
(...skipping 2297 matching lines...) Expand 10 before | Expand all | Expand 10 after
8655 8703
8656 inline void TypeArguments::SetHash(intptr_t value) const { 8704 inline void TypeArguments::SetHash(intptr_t value) const {
8657 // This is only safe because we create a new Smi, which does not cause 8705 // This is only safe because we create a new Smi, which does not cause
8658 // heap allocation. 8706 // heap allocation.
8659 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); 8707 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
8660 } 8708 }
8661 8709
8662 } // namespace dart 8710 } // namespace dart
8663 8711
8664 #endif // VM_OBJECT_H_ 8712 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/method_recognizer.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698