Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 947 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { | 947 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { |
| 948 DARTSCOPE(Isolate::Current()); | 948 DARTSCOPE(Isolate::Current()); |
| 949 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 949 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 950 return obj.IsInteger(); | 950 return obj.IsInteger(); |
| 951 } | 951 } |
| 952 | 952 |
| 953 | 953 |
| 954 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, | 954 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, |
| 955 bool* fits) { | 955 bool* fits) { |
| 956 DARTSCOPE(Isolate::Current()); | 956 DARTSCOPE(Isolate::Current()); |
| 957 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); | 957 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); |
|
cshapiro
2011/12/08 22:50:50
Done here as well.
| |
| 958 if (obj.IsSmi() || obj.IsMint()) { | 958 if (obj.IsSmi() || obj.IsMint()) { |
| 959 *fits = true; | 959 *fits = true; |
| 960 return Api::Success(); | 960 return Api::Success(); |
| 961 } else if (obj.IsBigint()) { | 961 } else if (obj.IsBigint()) { |
| 962 #if defined(DEBUG) | 962 #if defined(DEBUG) |
| 963 Bigint& bigint = Bigint::Handle(); | 963 Bigint& bigint = Bigint::Handle(); |
| 964 bigint ^= obj.raw(); | 964 bigint ^= obj.raw(); |
| 965 ASSERT(!BigintOperations::FitsIntoInt64(bigint)); | 965 ASSERT(!BigintOperations::FitsIntoInt64(bigint)); |
| 966 #endif | 966 #endif |
| 967 *fits = false; | 967 *fits = false; |
| 968 return Api::Success(); | 968 return Api::Success(); |
| 969 } | 969 } |
| 970 return Api::Error("Object is not a Integer"); | 970 return Api::Error("Object is not a Integer"); |
| 971 } | 971 } |
| 972 | 972 |
| 973 | 973 |
| 974 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, | |
| 975 bool* fits) { | |
| 976 DARTSCOPE(Isolate::Current()); | |
| 977 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); | |
|
turnidge
2011/12/08 18:26:25
I've been doing things a new way. Sorry I didn't
cshapiro
2011/12/08 22:50:50
Done.
I will put together a separate change for D
| |
| 978 if (obj.IsSmi() || obj.IsMint()) { | |
| 979 Integer& integer = Integer::Handle(); | |
| 980 integer ^= obj.raw(); | |
| 981 if (integer.IsNegative()) { | |
| 982 *fits = false; | |
| 983 } else { | |
| 984 *fits = true; | |
| 985 } | |
| 986 return Api::Success(); | |
| 987 } else if (obj.IsBigint()) { | |
| 988 Bigint& bigint = Bigint::Handle(); | |
| 989 bigint ^= obj.raw(); | |
| 990 *fits = BigintOperations::FitsIntoUint64(bigint); | |
| 991 return Api::Success(); | |
| 992 } | |
| 993 return Api::Error("Object is not a Integer"); | |
| 994 } | |
| 995 | |
| 996 | |
| 974 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { | 997 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { |
| 975 DARTSCOPE(Isolate::Current()); | 998 DARTSCOPE(Isolate::Current()); |
| 976 const Integer& obj = Integer::Handle(Integer::New(value)); | 999 const Integer& obj = Integer::Handle(Integer::New(value)); |
| 977 return Api::NewLocalHandle(obj); | 1000 return Api::NewLocalHandle(obj); |
| 978 } | 1001 } |
| 979 | 1002 |
| 980 | 1003 |
| 981 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { | 1004 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { |
| 982 DARTSCOPE(Isolate::Current()); | 1005 DARTSCOPE(Isolate::Current()); |
| 983 const String& str_obj = String::Handle(String::New(str)); | 1006 const String& str_obj = String::Handle(String::New(str)); |
| 984 const Integer& obj = Integer::Handle(Integer::New(str_obj)); | 1007 const Integer& obj = Integer::Handle(Integer::New(str_obj)); |
| 985 return Api::NewLocalHandle(obj); | 1008 return Api::NewLocalHandle(obj); |
| 986 } | 1009 } |
| 987 | 1010 |
| 988 | 1011 |
| 989 DART_EXPORT Dart_Handle Dart_IntegerValue(Dart_Handle integer, int64_t* value) { | 1012 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, |
| 1013 int64_t* value) { | |
| 990 DARTSCOPE(Isolate::Current()); | 1014 DARTSCOPE(Isolate::Current()); |
| 991 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); | 1015 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); |
|
turnidge
2011/12/08 18:26:25
Do you mind changing this to use UnwrapIntegerHand
cshapiro
2011/12/08 22:50:50
Done.
| |
| 992 if (obj.IsSmi() || obj.IsMint()) { | 1016 if (obj.IsSmi() || obj.IsMint()) { |
| 993 Integer& integer = Integer::Handle(); | 1017 Integer& integer = Integer::Handle(); |
| 994 integer ^= obj.raw(); | 1018 integer ^= obj.raw(); |
| 995 *value = integer.AsInt64Value(); | 1019 *value = integer.AsInt64Value(); |
| 996 return Api::Success(); | 1020 return Api::Success(); |
| 997 } | 1021 } |
| 998 if (obj.IsBigint()) { | 1022 if (obj.IsBigint()) { |
| 999 Bigint& bigint = Bigint::Handle(); | 1023 Bigint& bigint = Bigint::Handle(); |
| 1000 bigint ^= obj.raw(); | 1024 bigint ^= obj.raw(); |
| 1001 if (BigintOperations::FitsIntoInt64(bigint)) { | 1025 if (BigintOperations::FitsIntoInt64(bigint)) { |
| 1002 *value = BigintOperations::ToInt64(bigint); | 1026 *value = BigintOperations::ToInt64(bigint); |
| 1003 return Api::Success(); | 1027 return Api::Success(); |
| 1004 } else { | 1028 } else { |
| 1005 return Api::Error("Integer too big to fit in int64_t"); | 1029 return Api::Error("Integer too big to fit in int64_t"); |
|
turnidge
2011/12/08 18:26:25
Now that I have printf args to Api::Error, I am tr
cshapiro
2011/12/08 22:50:50
Done.
| |
| 1006 } | 1030 } |
| 1007 } | 1031 } |
| 1008 return Api::Error("Object is not a Integer"); | 1032 return Api::Error("Object is not a Integer"); |
| 1009 } | 1033 } |
| 1010 | 1034 |
| 1011 | 1035 |
| 1012 DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer, | 1036 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer, |
| 1013 const char** value) { | 1037 uint64_t* value) { |
| 1038 DARTSCOPE(Isolate::Current()); | |
| 1039 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); | |
|
turnidge
2011/12/08 18:26:25
UnwrapIntegerHandle here too?
cshapiro
2011/12/08 22:50:50
Done.
| |
| 1040 if (obj.IsSmi() || obj.IsMint()) { | |
| 1041 Integer& integer = Integer::Handle(); | |
| 1042 integer ^= obj.raw(); | |
| 1043 if (integer.IsNegative()) { | |
| 1044 return Api::Error("Integer too small to fit in uint64_t"); | |
|
turnidge
2011/12/08 18:26:25
Fixup error message as suggested for IntegerToInt6
cshapiro
2011/12/08 22:50:50
Done. I have created a single call to error with
| |
| 1045 } | |
| 1046 integer ^= obj.raw(); | |
| 1047 *value = integer.AsInt64Value(); | |
| 1048 return Api::Success(); | |
| 1049 } | |
| 1050 if (obj.IsBigint()) { | |
| 1051 Bigint& bigint = Bigint::Handle(); | |
| 1052 bigint ^= obj.raw(); | |
| 1053 if (BigintOperations::FitsIntoUint64(bigint)) { | |
| 1054 *value = BigintOperations::ToUint64(bigint); | |
| 1055 return Api::Success(); | |
| 1056 } else { | |
| 1057 return Api::Error("Integer too big to fit in uint64_t"); | |
|
turnidge
2011/12/08 18:26:25
Fixup error message as above.
cshapiro
2011/12/08 22:50:50
Done.
| |
| 1058 } | |
| 1059 } | |
| 1060 return Api::Error("Object is not a Integer"); | |
| 1061 } | |
| 1062 | |
| 1063 | |
| 1064 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, | |
| 1065 const char** value) { | |
| 1014 DARTSCOPE(Isolate::Current()); | 1066 DARTSCOPE(Isolate::Current()); |
| 1015 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); | 1067 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); |
|
turnidge
2011/12/08 18:26:25
UnwrapIntegerHandle here too?
cshapiro
2011/12/08 22:50:50
Done.
| |
| 1016 Bigint& bigint = Bigint::Handle(); | 1068 Bigint& bigint = Bigint::Handle(); |
| 1017 if (obj.IsSmi() || obj.IsMint()) { | 1069 if (obj.IsSmi() || obj.IsMint()) { |
| 1018 Integer& integer = Integer::Handle(); | 1070 Integer& integer = Integer::Handle(); |
| 1019 integer ^= obj.raw(); | 1071 integer ^= obj.raw(); |
| 1020 bigint ^= BigintOperations::NewFromInt64(integer.AsInt64Value()); | 1072 bigint ^= BigintOperations::NewFromInt64(integer.AsInt64Value()); |
| 1021 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate); | 1073 *value = BigintOperations::ToHexCString(bigint, &Api::Allocate); |
| 1022 return Api::Success(); | 1074 return Api::Success(); |
| 1023 } | 1075 } |
| 1024 if (obj.IsBigint()) { | 1076 if (obj.IsBigint()) { |
| 1025 bigint ^= obj.raw(); | 1077 bigint ^= obj.raw(); |
| (...skipping 1448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2474 } | 2526 } |
| 2475 delete debug_region; | 2527 delete debug_region; |
| 2476 } else { | 2528 } else { |
| 2477 *buffer = NULL; | 2529 *buffer = NULL; |
| 2478 *buffer_size = 0; | 2530 *buffer_size = 0; |
| 2479 } | 2531 } |
| 2480 } | 2532 } |
| 2481 | 2533 |
| 2482 | 2534 |
| 2483 } // namespace dart | 2535 } // namespace dart |
| OLD | NEW |