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

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: Address review comments. 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 return Api::Success();
turnidge 2011/12/08 22:58:22 Remove this?
957 } else if (obj.IsBigint()) { 960 } else {
961 ASSERT(int_obj.IsBigint());
958 #if defined(DEBUG) 962 #if defined(DEBUG)
959 Bigint& bigint = Bigint::Handle(); 963 Bigint& bigint = Bigint::Handle();
960 bigint ^= obj.raw(); 964 bigint ^= int_obj.raw();
961 ASSERT(!BigintOperations::FitsIntoInt64(bigint)); 965 ASSERT(!BigintOperations::FitsIntoInt64(bigint));
962 #endif 966 #endif
963 *fits = false; 967 *fits = false;
964 return Api::Success();
965 } 968 }
966 return Api::Error("Object is not a Integer"); 969 return Api::Success();
967 } 970 }
968 971
969 972
973 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer,
974 bool* fits) {
975 DARTSCOPE(Isolate::Current());
976 const Integer& int_obj = Api::UnwrapIntegerHandle(integer);
977 if (int_obj.IsNull()) {
978 RETURN_TYPE_ERROR(integer, Integer);
979 }
980 if (int_obj.IsSmi() || int_obj.IsMint()) {
981 *fits = !int_obj.IsNegative();
982 } else {
983 ASSERT(int_obj.IsBigint());
984 Bigint& bigint = Bigint::Handle();
985 bigint ^= int_obj.raw();
986 *fits = BigintOperations::FitsIntoUint64(bigint);
987 }
988 return Api::Success();
989 }
990
991
970 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { 992 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) {
971 DARTSCOPE(Isolate::Current()); 993 DARTSCOPE(Isolate::Current());
972 const Integer& obj = Integer::Handle(Integer::New(value)); 994 const Integer& obj = Integer::Handle(Integer::New(value));
973 return Api::NewLocalHandle(obj); 995 return Api::NewLocalHandle(obj);
974 } 996 }
975 997
976 998
977 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { 999 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) {
978 DARTSCOPE(Isolate::Current()); 1000 DARTSCOPE(Isolate::Current());
979 const String& str_obj = String::Handle(String::New(str)); 1001 const String& str_obj = String::Handle(String::New(str));
980 const Integer& obj = Integer::Handle(Integer::New(str_obj)); 1002 const Integer& obj = Integer::Handle(Integer::New(str_obj));
981 return Api::NewLocalHandle(obj); 1003 return Api::NewLocalHandle(obj);
982 } 1004 }
983 1005
984 1006
985 DART_EXPORT Dart_Handle Dart_IntegerValue(Dart_Handle integer, int64_t* value) { 1007 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer,
1008 int64_t* value) {
986 DARTSCOPE(Isolate::Current()); 1009 DARTSCOPE(Isolate::Current());
987 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); 1010 const Integer& int_obj = Api::UnwrapIntegerHandle(integer);
988 if (obj.IsSmi() || obj.IsMint()) { 1011 if (int_obj.IsNull()) {
989 Integer& integer = Integer::Handle(); 1012 RETURN_TYPE_ERROR(integer, Integer);
990 integer ^= obj.raw();
991 *value = integer.AsInt64Value();
992 return Api::Success();
993 } 1013 }
994 if (obj.IsBigint()) { 1014 if (int_obj.IsSmi() || int_obj.IsMint()) {
1015 *value = int_obj.AsInt64Value();
1016 } else {
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();
1000 } else { 1022 } else {
1001 return Api::Error("Integer too big to fit in int64_t"); 1023 return Api::Error("%s: Integer %s cannot be represented as an int64_t.",
1024 CURRENT_FUNC, int_obj.ToCString());
1002 } 1025 }
1003 } 1026 }
1004 return Api::Error("Object is not a Integer"); 1027 return Api::Success();
1005 } 1028 }
1006 1029
1007 1030
1008 DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer, 1031 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer,
1009 const char** value) { 1032 uint64_t* value) {
1010 DARTSCOPE(Isolate::Current()); 1033 DARTSCOPE(Isolate::Current());
1011 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); 1034 const Integer& int_obj = Api::UnwrapIntegerHandle(integer);
1012 Bigint& bigint = Bigint::Handle(); 1035 if (int_obj.IsNull()) {
1013 if (obj.IsSmi() || obj.IsMint()) { 1036 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 } 1037 }
1020 if (obj.IsBigint()) { 1038 if (int_obj.IsSmi() || int_obj.IsMint()) {
1021 bigint ^= obj.raw(); 1039 if (!int_obj.IsNegative()) {
1022 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate); 1040 *value = int_obj.AsInt64Value();
1023 return Api::Success(); 1041 return Api::Success();
1042 }
1043 } else {
1044 ASSERT(int_obj.IsBigint());
1045 Bigint& bigint = Bigint::Handle();
1046 bigint ^= int_obj.raw();
1047 if (BigintOperations::FitsIntoUint64(bigint)) {
1048 *value = BigintOperations::ToUint64(bigint);
1049 return Api::Success();
1050 }
1024 } 1051 }
1025 return Api::Error("Object is not a Integer"); 1052 return Api::Error("%s: Integer %s cannot be represented as a uint64_t.",
1053 CURRENT_FUNC, int_obj.ToCString());
turnidge 2011/12/08 22:58:22 Make consistent with IntegerToInt64? (That is, fa
1026 } 1054 }
1027 1055
1028 1056
1057 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer,
1058 const char** value) {
1059 DARTSCOPE(Isolate::Current());
1060 const Integer& int_obj = Api::UnwrapIntegerHandle(integer);
1061 if (int_obj.IsNull()) {
1062 RETURN_TYPE_ERROR(integer, Integer);
1063 }
1064 Bigint& bigint = Bigint::Handle();
1065 if (int_obj.IsSmi() || int_obj.IsMint()) {
1066 bigint ^= BigintOperations::NewFromInt64(int_obj.AsInt64Value());
1067 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate);
1068 } else {
1069 ASSERT(int_obj.IsBigint());
1070 bigint ^= int_obj.raw();
1071 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate);
1072 }
1073 return Api::Success();
1074 }
1075
1076
1029 // --- Booleans ---- 1077 // --- Booleans ----
1030 1078
1031 1079
1032 DART_EXPORT Dart_Handle Dart_True() { 1080 DART_EXPORT Dart_Handle Dart_True() {
1033 CHECK_ISOLATE_SCOPE(Isolate::Current()); 1081 CHECK_ISOLATE_SCOPE(Isolate::Current());
1034 return Api::True(); 1082 return Api::True();
1035 } 1083 }
1036 1084
1037 1085
1038 DART_EXPORT Dart_Handle Dart_False() { 1086 DART_EXPORT Dart_Handle Dart_False() {
(...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after
2470 } 2518 }
2471 delete debug_region; 2519 delete debug_region;
2472 } else { 2520 } else {
2473 *buffer = NULL; 2521 *buffer = NULL;
2474 *buffer_size = 0; 2522 *buffer_size = 0;
2475 } 2523 }
2476 } 2524 }
2477 2525
2478 2526
2479 } // namespace dart 2527 } // 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