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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 8585049: Add an interface for retrieving the value of unsigned 64-bit integers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor consistency changes. Created 9 years 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 | « runtime/vm/bigint_operations_test.cc ('k') | runtime/vm/dart_api_impl_test.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { 943 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) {
944 DARTSCOPE(Isolate::Current()); 944 DARTSCOPE(Isolate::Current());
945 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 945 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
946 return obj.IsInteger(); 946 return obj.IsInteger();
947 } 947 }
948 948
949 949
950 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, 950 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer,
951 bool* fits) { 951 bool* fits) {
952 DARTSCOPE(Isolate::Current()); 952 DARTSCOPE(Isolate::Current());
953 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); 953 const Integer& int_obj = Api::UnwrapIntegerHandle(integer);
954 if (obj.IsSmi() || obj.IsMint()) { 954 if (int_obj.IsNull()) {
955 RETURN_TYPE_ERROR(integer, Integer);
956 }
957 if (int_obj.IsSmi() || int_obj.IsMint()) {
955 *fits = true; 958 *fits = true;
956 return Api::Success(); 959 } else {
957 } else if (obj.IsBigint()) { 960 ASSERT(int_obj.IsBigint());
958 #if defined(DEBUG) 961 #if defined(DEBUG)
959 Bigint& bigint = Bigint::Handle(); 962 Bigint& bigint = Bigint::Handle();
960 bigint ^= obj.raw(); 963 bigint ^= int_obj.raw();
961 ASSERT(!BigintOperations::FitsIntoInt64(bigint)); 964 ASSERT(!BigintOperations::FitsIntoInt64(bigint));
962 #endif 965 #endif
963 *fits = false; 966 *fits = false;
964 return Api::Success();
965 } 967 }
966 return Api::Error("Object is not a Integer"); 968 return Api::Success();
967 } 969 }
968 970
969 971
972 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer,
973 bool* fits) {
974 DARTSCOPE(Isolate::Current());
975 const Integer& int_obj = Api::UnwrapIntegerHandle(integer);
976 if (int_obj.IsNull()) {
977 RETURN_TYPE_ERROR(integer, Integer);
978 }
979 if (int_obj.IsSmi() || int_obj.IsMint()) {
980 *fits = !int_obj.IsNegative();
981 } else {
982 ASSERT(int_obj.IsBigint());
983 Bigint& bigint = Bigint::Handle();
984 bigint ^= int_obj.raw();
985 *fits = BigintOperations::FitsIntoUint64(bigint);
986 }
987 return Api::Success();
988 }
989
990
970 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { 991 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) {
971 DARTSCOPE(Isolate::Current()); 992 DARTSCOPE(Isolate::Current());
972 const Integer& obj = Integer::Handle(Integer::New(value)); 993 const Integer& obj = Integer::Handle(Integer::New(value));
973 return Api::NewLocalHandle(obj); 994 return Api::NewLocalHandle(obj);
974 } 995 }
975 996
976 997
977 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { 998 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) {
978 DARTSCOPE(Isolate::Current()); 999 DARTSCOPE(Isolate::Current());
979 const String& str_obj = String::Handle(String::New(str)); 1000 const String& str_obj = String::Handle(String::New(str));
980 const Integer& obj = Integer::Handle(Integer::New(str_obj)); 1001 const Integer& obj = Integer::Handle(Integer::New(str_obj));
981 return Api::NewLocalHandle(obj); 1002 return Api::NewLocalHandle(obj);
982 } 1003 }
983 1004
984 1005
985 DART_EXPORT Dart_Handle Dart_IntegerValue(Dart_Handle integer, int64_t* value) { 1006 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer,
1007 int64_t* value) {
986 DARTSCOPE(Isolate::Current()); 1008 DARTSCOPE(Isolate::Current());
987 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); 1009 const Integer& int_obj = Api::UnwrapIntegerHandle(integer);
988 if (obj.IsSmi() || obj.IsMint()) { 1010 if (int_obj.IsNull()) {
989 Integer& integer = Integer::Handle(); 1011 RETURN_TYPE_ERROR(integer, Integer);
990 integer ^= obj.raw(); 1012 }
991 *value = integer.AsInt64Value(); 1013 if (int_obj.IsSmi() || int_obj.IsMint()) {
1014 *value = int_obj.AsInt64Value();
992 return Api::Success(); 1015 return Api::Success();
993 } 1016 } else {
994 if (obj.IsBigint()) { 1017 ASSERT(int_obj.IsBigint());
995 Bigint& bigint = Bigint::Handle(); 1018 Bigint& bigint = Bigint::Handle();
996 bigint ^= obj.raw(); 1019 bigint ^= int_obj.raw();
997 if (BigintOperations::FitsIntoInt64(bigint)) { 1020 if (BigintOperations::FitsIntoInt64(bigint)) {
998 *value = BigintOperations::ToInt64(bigint); 1021 *value = BigintOperations::ToInt64(bigint);
999 return Api::Success(); 1022 return Api::Success();
1000 } else {
1001 return Api::Error("Integer too big to fit in int64_t");
1002 } 1023 }
1003 } 1024 }
1004 return Api::Error("Object is not a Integer"); 1025 return Api::Error("%s: Integer %s cannot be represented as an int64_t.",
1026 CURRENT_FUNC, int_obj.ToCString());
1005 } 1027 }
1006 1028
1007 1029
1008 DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer, 1030 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer,
1009 const char** value) { 1031 uint64_t* value) {
1010 DARTSCOPE(Isolate::Current()); 1032 DARTSCOPE(Isolate::Current());
1011 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); 1033 const Integer& int_obj = Api::UnwrapIntegerHandle(integer);
1012 Bigint& bigint = Bigint::Handle(); 1034 if (int_obj.IsNull()) {
1013 if (obj.IsSmi() || obj.IsMint()) { 1035 RETURN_TYPE_ERROR(integer, Integer);
1014 Integer& integer = Integer::Handle();
1015 integer ^= obj.raw();
1016 bigint ^= BigintOperations::NewFromInt64(integer.AsInt64Value());
1017 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate);
1018 return Api::Success();
1019 } 1036 }
1020 if (obj.IsBigint()) { 1037 if (int_obj.IsSmi() || int_obj.IsMint()) {
1021 bigint ^= obj.raw(); 1038 if (!int_obj.IsNegative()) {
1022 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate); 1039 *value = int_obj.AsInt64Value();
1023 return Api::Success(); 1040 return Api::Success();
1041 }
1042 } else {
1043 ASSERT(int_obj.IsBigint());
1044 Bigint& bigint = Bigint::Handle();
1045 bigint ^= int_obj.raw();
1046 if (BigintOperations::FitsIntoUint64(bigint)) {
1047 *value = BigintOperations::ToUint64(bigint);
1048 return Api::Success();
1049 }
1024 } 1050 }
1025 return Api::Error("Object is not a Integer"); 1051 return Api::Error("%s: Integer %s cannot be represented as a uint64_t.",
1052 CURRENT_FUNC, int_obj.ToCString());
1026 } 1053 }
1027 1054
1028 1055
1056 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer,
1057 const char** value) {
1058 DARTSCOPE(Isolate::Current());
1059 const Integer& int_obj = Api::UnwrapIntegerHandle(integer);
1060 if (int_obj.IsNull()) {
1061 RETURN_TYPE_ERROR(integer, Integer);
1062 }
1063 Bigint& bigint = Bigint::Handle();
1064 if (int_obj.IsSmi() || int_obj.IsMint()) {
1065 bigint ^= BigintOperations::NewFromInt64(int_obj.AsInt64Value());
1066 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate);
1067 } else {
1068 ASSERT(int_obj.IsBigint());
1069 bigint ^= int_obj.raw();
1070 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate);
1071 }
1072 return Api::Success();
1073 }
1074
1075
1029 // --- Booleans ---- 1076 // --- Booleans ----
1030 1077
1031 1078
1032 DART_EXPORT Dart_Handle Dart_True() { 1079 DART_EXPORT Dart_Handle Dart_True() {
1033 CHECK_ISOLATE_SCOPE(Isolate::Current()); 1080 CHECK_ISOLATE_SCOPE(Isolate::Current());
1034 return Api::True(); 1081 return Api::True();
1035 } 1082 }
1036 1083
1037 1084
1038 DART_EXPORT Dart_Handle Dart_False() { 1085 DART_EXPORT Dart_Handle Dart_False() {
(...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after
2470 } 2517 }
2471 delete debug_region; 2518 delete debug_region;
2472 } else { 2519 } else {
2473 *buffer = NULL; 2520 *buffer = NULL;
2474 *buffer_size = 0; 2521 *buffer_size = 0;
2475 } 2522 }
2476 } 2523 }
2477 2524
2478 2525
2479 } // namespace dart 2526 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/bigint_operations_test.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698