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: runtime/bin/dartutils.h

Issue 509153003: New bigint implementation in the vm. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 3 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 | « no previous file | runtime/bin/dartutils.cc » ('j') | runtime/lib/bigint.dart » ('J')
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 BIN_DARTUTILS_H_ 5 #ifndef BIN_DARTUTILS_H_
6 #define BIN_DARTUTILS_H_ 6 #define BIN_DARTUTILS_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "include/dart_native_api.h" 9 #include "include/dart_native_api.h"
10 10
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 return Dart_ScopeAllocate(size); 261 return Dart_ScopeAllocate(size);
262 } 262 }
263 263
264 static CObject* Null(); 264 static CObject* Null();
265 static CObject* True(); 265 static CObject* True();
266 static CObject* False(); 266 static CObject* False();
267 static CObject* Bool(bool value); 267 static CObject* Bool(bool value);
268 static Dart_CObject* NewInt32(int32_t value); 268 static Dart_CObject* NewInt32(int32_t value);
269 static Dart_CObject* NewInt64(int64_t value); 269 static Dart_CObject* NewInt64(int64_t value);
270 static Dart_CObject* NewIntptr(intptr_t value); 270 static Dart_CObject* NewIntptr(intptr_t value);
271 // TODO(sgjesse): Add support for kBigint. 271 static Dart_CObject* NewBigint(const char* hex_value);
272 static char* BigintToHexValue(Dart_CObject* bigint);
272 static Dart_CObject* NewDouble(double value); 273 static Dart_CObject* NewDouble(double value);
273 static Dart_CObject* NewString(intptr_t length); 274 static Dart_CObject* NewString(intptr_t length);
274 static Dart_CObject* NewString(const char* str); 275 static Dart_CObject* NewString(const char* str);
275 static Dart_CObject* NewArray(intptr_t length); 276 static Dart_CObject* NewArray(intptr_t length);
276 static Dart_CObject* NewUint8Array(intptr_t length); 277 static Dart_CObject* NewUint8Array(intptr_t length);
278 static Dart_CObject* NewUint32Array(intptr_t length);
277 static Dart_CObject* NewExternalUint8Array( 279 static Dart_CObject* NewExternalUint8Array(
278 intptr_t length, uint8_t* data, void* peer, 280 intptr_t length, uint8_t* data, void* peer,
279 Dart_WeakPersistentHandleFinalizer callback); 281 Dart_WeakPersistentHandleFinalizer callback);
280 282
281 static Dart_CObject* NewIOBuffer(int64_t length); 283 static Dart_CObject* NewIOBuffer(int64_t length);
282 static void FreeIOBufferData(Dart_CObject* object); 284 static void FreeIOBufferData(Dart_CObject* object);
283 285
284 Dart_CObject* AsApiCObject() { return cobject_; } 286 Dart_CObject* AsApiCObject() { return cobject_; }
285 287
286 // Create a new CObject array with an illegal arguments error. 288 // Create a new CObject array with an illegal arguments error.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 return result; 411 return result;
410 } 412 }
411 413
412 private: 414 private:
413 DISALLOW_COPY_AND_ASSIGN(CObjectIntptr); 415 DISALLOW_COPY_AND_ASSIGN(CObjectIntptr);
414 }; 416 };
415 417
416 418
417 class CObjectBigint : public CObject { 419 class CObjectBigint : public CObject {
418 public: 420 public:
419 DECLARE_COBJECT_CONSTRUCTORS(Bigint) 421 // DECLARE_COBJECT_CONSTRUCTORS(Bigint) would miss hex_value_ initialization.
422 explicit CObjectBigint(Dart_CObject *cobject) : CObject(cobject) {
423 ASSERT(type() == Dart_CObject_kBigint);
424 cobject_ = cobject;
425 hex_value_ = NULL;
426 }
427 explicit CObjectBigint(CObject* cobject) : CObject() {
428 ASSERT(cobject != NULL);
429 ASSERT(cobject->type() == Dart_CObject_kBigint);
430 cobject_ = cobject->AsApiCObject();
431 hex_value_ = NULL;
432 }
420 433
421 char* Value() const { return cobject_->value.as_bigint; } 434 char* Value() {
435 if (hex_value_ == NULL) {
436 hex_value_ = BigintToHexValue(cobject_);
437 }
438 ASSERT(hex_value_ != NULL);
439 return hex_value_;
440 }
441
442 ~CObjectBigint() {
443 free(hex_value_);
444 }
422 445
423 private: 446 private:
447 char* hex_value_;
424 DISALLOW_COPY_AND_ASSIGN(CObjectBigint); 448 DISALLOW_COPY_AND_ASSIGN(CObjectBigint);
425 }; 449 };
426 450
427 451
428 class CObjectDouble : public CObject { 452 class CObjectDouble : public CObject {
429 public: 453 public:
430 DECLARE_COBJECT_CONSTRUCTORS(Double) 454 DECLARE_COBJECT_CONSTRUCTORS(Double)
431 455
432 double Value() const { return cobject_->value.as_double; } 456 double Value() const { return cobject_->value.as_double; }
433 457
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 564
541 ~ScopedBlockingCall() { 565 ~ScopedBlockingCall() {
542 Dart_IsolateUnblocked(); 566 Dart_IsolateUnblocked();
543 } 567 }
544 }; 568 };
545 569
546 } // namespace bin 570 } // namespace bin
547 } // namespace dart 571 } // namespace dart
548 572
549 #endif // BIN_DARTUTILS_H_ 573 #endif // BIN_DARTUTILS_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/dartutils.cc » ('j') | runtime/lib/bigint.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698