| 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 #ifndef INCLUDE_DART_API_H_ | 5 #ifndef INCLUDE_DART_API_H_ |
| 6 #define INCLUDE_DART_API_H_ | 6 #define INCLUDE_DART_API_H_ |
| 7 | 7 |
| 8 #ifdef __cplusplus | 8 #ifdef __cplusplus |
| 9 #define DART_EXTERN_C extern "C" | 9 #define DART_EXTERN_C extern "C" |
| 10 #else | 10 #else |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 typedef void* Dart_Handle; | 46 typedef void* Dart_Handle; |
| 47 typedef void* Dart_NativeArguments; | 47 typedef void* Dart_NativeArguments; |
| 48 typedef enum { | 48 typedef enum { |
| 49 kRetCIntptr = 0, | 49 kRetCIntptr = 0, |
| 50 kRetCBool, | 50 kRetCBool, |
| 51 kRetCString, | 51 kRetCString, |
| 52 kRetObject, | 52 kRetObject, |
| 53 kRetCInt64, | 53 kRetCInt64, |
| 54 kRetCDouble, | 54 kRetCDouble, |
| 55 kRetLibSpec, | 55 kRetLibSpec, |
| 56 kRetError, | |
| 57 } Dart_ReturnType; | 56 } Dart_ReturnType; |
| 58 | 57 |
| 59 typedef struct { | 58 typedef struct { |
| 60 Dart_ReturnType type_; | 59 Dart_ReturnType type_; |
| 61 union { | 60 union { |
| 62 intptr_t int_value; | 61 intptr_t int_value; |
| 63 bool bool_value; | 62 bool bool_value; |
| 64 const char* str_value; | 63 const char* str_value; |
| 65 Dart_Handle obj_value; | 64 Dart_Handle obj_value; |
| 66 int64_t int64_value; | 65 int64_t int64_value; |
| 67 double double_value; | 66 double double_value; |
| 68 const char* errmsg; | |
| 69 } retval_; | 67 } retval_; |
| 70 } Dart_Result; | 68 } Dart_Result; |
| 71 | 69 |
| 72 typedef enum { | 70 typedef enum { |
| 73 kLibraryTag = 0, | 71 kLibraryTag = 0, |
| 74 kImportTag, | 72 kImportTag, |
| 75 kSourceTag, | 73 kSourceTag, |
| 76 kCanonicalizeUrl, | 74 kCanonicalizeUrl, |
| 77 } Dart_LibraryTag; | 75 } Dart_LibraryTag; |
| 78 | 76 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 92 typedef void (*Dart_NativeFunction)(Dart_NativeArguments arguments); | 90 typedef void (*Dart_NativeFunction)(Dart_NativeArguments arguments); |
| 93 typedef Dart_NativeFunction (*Dart_NativeEntryResolver)(Dart_Handle name, | 91 typedef Dart_NativeFunction (*Dart_NativeEntryResolver)(Dart_Handle name, |
| 94 int num_of_arguments); | 92 int num_of_arguments); |
| 95 typedef Dart_Result (*Dart_LibraryTagHandler)(Dart_LibraryTag tag, | 93 typedef Dart_Result (*Dart_LibraryTagHandler)(Dart_LibraryTag tag, |
| 96 Dart_Handle library, | 94 Dart_Handle library, |
| 97 Dart_Handle url); | 95 Dart_Handle url); |
| 98 | 96 |
| 99 // TODO(iposva): This is a placeholder for the eventual external Dart API. | 97 // TODO(iposva): This is a placeholder for the eventual external Dart API. |
| 100 | 98 |
| 101 // Return value handling after a Dart API call. | 99 // Return value handling after a Dart API call. |
| 102 inline bool Dart_IsValidResult(const Dart_Result& result) { | 100 DART_EXPORT bool Dart_IsValidResult(const Dart_Result& result); |
| 103 return (result.type_ != kRetError); | 101 |
| 104 } | |
| 105 inline intptr_t Dart_GetResultAsCIntptr(const Dart_Result& result) { | 102 inline intptr_t Dart_GetResultAsCIntptr(const Dart_Result& result) { |
| 106 assert(result.type_ == kRetCIntptr); // Valid to access result as C int. | 103 assert(result.type_ == kRetCIntptr); // Valid to access result as C int. |
| 107 return result.retval_.int_value; | 104 return result.retval_.int_value; |
| 108 } | 105 } |
| 109 inline Dart_Result Dart_ResultAsCIntptr(intptr_t value) { | 106 inline Dart_Result Dart_ResultAsCIntptr(intptr_t value) { |
| 110 Dart_Result result; | 107 Dart_Result result; |
| 111 result.type_ = kRetCIntptr; | 108 result.type_ = kRetCIntptr; |
| 112 result.retval_.int_value = value; | 109 result.retval_.int_value = value; |
| 113 return result; | 110 return result; |
| 114 } | 111 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 inline double Dart_GetResultAsCDouble(const Dart_Result& result) { | 153 inline double Dart_GetResultAsCDouble(const Dart_Result& result) { |
| 157 assert(result.type_ == kRetCDouble); // Valid to access result as C double. | 154 assert(result.type_ == kRetCDouble); // Valid to access result as C double. |
| 158 return result.retval_.double_value; | 155 return result.retval_.double_value; |
| 159 } | 156 } |
| 160 inline Dart_Result Dart_ResultAsCDouble(double value) { | 157 inline Dart_Result Dart_ResultAsCDouble(double value) { |
| 161 Dart_Result result; | 158 Dart_Result result; |
| 162 result.type_ = kRetCDouble; | 159 result.type_ = kRetCDouble; |
| 163 result.retval_.double_value = value; | 160 result.retval_.double_value = value; |
| 164 return result; | 161 return result; |
| 165 } | 162 } |
| 166 inline const char* Dart_GetErrorCString(const Dart_Result& result) { | 163 DART_EXPORT const char* Dart_GetErrorCString(const Dart_Result& result); |
| 167 assert(result.type_ == kRetError); // Valid to access only on failure. | 164 DART_EXPORT Dart_Result Dart_ErrorResult(const char* value); |
| 168 return result.retval_.errmsg; | |
| 169 } | |
| 170 inline Dart_Result Dart_ErrorResult(const char* value) { | |
| 171 // Assumes passed in string value will be available on return. | |
| 172 Dart_Result result; | |
| 173 result.type_ = kRetError; | |
| 174 result.retval_.errmsg = value; | |
| 175 return result; | |
| 176 } | |
| 177 | 165 |
| 178 | 166 |
| 179 // Initialize the VM with commmand line flags. | 167 // Initialize the VM with commmand line flags. |
| 180 DART_EXPORT bool Dart_Initialize(int argc, char** argv, | 168 DART_EXPORT bool Dart_Initialize(int argc, char** argv, |
| 181 Dart_IsolateInitCallback callback); | 169 Dart_IsolateInitCallback callback); |
| 182 | 170 |
| 183 | 171 |
| 184 // Isolate handling. | 172 // Isolate handling. |
| 185 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const Dart_Snapshot* snapshot, | 173 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const Dart_Snapshot* snapshot, |
| 186 void* data); | 174 void* data); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 // External pprof support for gathering and dumping symbolic information | 374 // External pprof support for gathering and dumping symbolic information |
| 387 // that can be used for better profile reports for dynamically generated | 375 // that can be used for better profile reports for dynamically generated |
| 388 // code. | 376 // code. |
| 389 DART_EXPORT void Dart_InitPprofSupport(); | 377 DART_EXPORT void Dart_InitPprofSupport(); |
| 390 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size); | 378 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size); |
| 391 | 379 |
| 392 // Check set vm flags. | 380 // Check set vm flags. |
| 393 DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name); | 381 DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name); |
| 394 | 382 |
| 395 #endif // INCLUDE_DART_API_H_ | 383 #endif // INCLUDE_DART_API_H_ |
| OLD | NEW |