| 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 <assert.h> | 5 #include <assert.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 | 9 |
| 10 #include "include/dart_api.h" | 10 #include "include/dart_api.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 pprof_file->WriteFully(buffer, buffer_size); | 104 pprof_file->WriteFully(buffer, buffer_size); |
| 105 } | 105 } |
| 106 delete pprof_file; // Closes the file. | 106 delete pprof_file; // Closes the file. |
| 107 Dart_ExitScope(); | 107 Dart_ExitScope(); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 | 111 |
| 112 static void* MainIsolateInitCallback(void* data) { | 112 static void* MainIsolateInitCallback(void* data) { |
| 113 const char* script_name = reinterpret_cast<const char*>(data); | 113 const char* script_name = reinterpret_cast<const char*>(data); |
| 114 Dart_Result result; | 114 Dart_Handle library; |
| 115 Dart_EnterScope(); | 115 Dart_EnterScope(); |
| 116 | 116 |
| 117 // Load the specified script. | 117 // Load the specified script. |
| 118 result = LoadScript(script_name); | 118 library = LoadScript(script_name); |
| 119 if (!Dart_IsValidResult(result)) { | 119 if (!Dart_IsValid(library)) { |
| 120 const char* err_msg = Dart_GetErrorCString(result); | 120 const char* err_msg = Dart_GetError(library); |
| 121 fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg); | 121 fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg); |
| 122 Dart_ExitScope(); | 122 Dart_ExitScope(); |
| 123 exit(255); | 123 exit(255); |
| 124 } | 124 } |
| 125 | 125 |
| 126 Dart_Handle library = Dart_GetResult(result); | |
| 127 if (!Dart_IsLibrary(library)) { | 126 if (!Dart_IsLibrary(library)) { |
| 128 fprintf(stderr, | 127 fprintf(stderr, |
| 129 "Expected a library when loading script: %s", | 128 "Expected a library when loading script: %s", |
| 130 script_name); | 129 script_name); |
| 131 Dart_ExitScope(); | 130 Dart_ExitScope(); |
| 132 exit(255); | 131 exit(255); |
| 133 } | 132 } |
| 134 Builtin_ImportLibrary(library); | 133 Builtin_ImportLibrary(library); |
| 135 // Setup the native resolver for built in library functions. | 134 // Setup the native resolver for built in library functions. |
| 136 Builtin_SetNativeResolver(); | 135 Builtin_SetNativeResolver(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 150 for (int i = 0; i < options.count(); i++) { | 149 for (int i = 0; i < options.count(); i++) { |
| 151 if (strcmp(options.GetArgument(i), "--compile_all") == 0) { | 150 if (strcmp(options.GetArgument(i), "--compile_all") == 0) { |
| 152 return true; | 151 return true; |
| 153 } | 152 } |
| 154 } | 153 } |
| 155 return false; | 154 return false; |
| 156 } | 155 } |
| 157 | 156 |
| 158 | 157 |
| 159 static void PrintObject(FILE* out, Dart_Handle object) { | 158 static void PrintObject(FILE* out, Dart_Handle object) { |
| 160 Dart_Result result = Dart_ObjectToString(object); | 159 Dart_Handle result = Dart_ObjectToString(object); |
| 161 if (Dart_IsValidResult(result)) { | 160 if (Dart_IsValid(result)) { |
| 162 Dart_Handle string = Dart_GetResult(result); | 161 PrintString(out, result); |
| 163 PrintString(out, string); | |
| 164 } else { | 162 } else { |
| 165 fprintf(out, "%s\n", Dart_GetErrorCString(result)); | 163 fprintf(out, "%s\n", Dart_GetError(result)); |
| 166 } | 164 } |
| 167 } | 165 } |
| 168 | 166 |
| 169 | 167 |
| 170 int main(int argc, char** argv) { | 168 int main(int argc, char** argv) { |
| 171 char* script_name; | 169 char* script_name; |
| 172 CommandLineOptions vm_options(argc); | 170 CommandLineOptions vm_options(argc); |
| 173 CommandLineOptions dart_options(argc); | 171 CommandLineOptions dart_options(argc); |
| 174 | 172 |
| 175 // Parse command line arguments. | 173 // Parse command line arguments. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 191 // gets called, which loads the scripts and libraries. | 189 // gets called, which loads the scripts and libraries. |
| 192 Dart_Isolate isolate = Dart_CreateIsolate(snapshot_buffer, script_name); | 190 Dart_Isolate isolate = Dart_CreateIsolate(snapshot_buffer, script_name); |
| 193 if (isolate == NULL) { | 191 if (isolate == NULL) { |
| 194 return 255; | 192 return 255; |
| 195 } | 193 } |
| 196 | 194 |
| 197 Dart_EnterScope(); | 195 Dart_EnterScope(); |
| 198 // TODO(asiva): Create a dart options object that can be accessed from | 196 // TODO(asiva): Create a dart options object that can be accessed from |
| 199 // dart code. | 197 // dart code. |
| 200 if (HasCompileAll(vm_options)) { | 198 if (HasCompileAll(vm_options)) { |
| 201 Dart_Result result = Dart_CompileAll(); | 199 Dart_Handle result = Dart_CompileAll(); |
| 202 if (!Dart_IsValidResult(result)) { | 200 if (!Dart_IsValid(result)) { |
| 203 fprintf(stderr, "%s\n", Dart_GetErrorCString(result)); | 201 fprintf(stderr, "%s\n", Dart_GetError(result)); |
| 204 Dart_ExitScope(); | 202 Dart_ExitScope(); |
| 205 Dart_ShutdownIsolate(); | 203 Dart_ShutdownIsolate(); |
| 206 return 255; // Indicates we encountered an error. | 204 return 255; // Indicates we encountered an error. |
| 207 } | 205 } |
| 208 } | 206 } |
| 209 | 207 |
| 210 // Lookup and invoke the top level main function. | 208 // Lookup and invoke the top level main function. |
| 211 Dart_Handle script_url = Dart_NewString(script_name); | 209 Dart_Handle script_url = Dart_NewString(script_name); |
| 212 Dart_Result result = Dart_LookupLibrary(script_url); | 210 Dart_Handle library = Dart_LookupLibrary(script_url); |
| 213 if (!Dart_IsValidResult(result)) { | 211 if (!Dart_IsValid(library)) { |
| 214 fprintf(stderr, "%s\n", Dart_GetErrorCString(result)); | 212 fprintf(stderr, "%s\n", Dart_GetError(library)); |
| 215 Dart_ExitScope(); | 213 Dart_ExitScope(); |
| 216 Dart_ShutdownIsolate(); | 214 Dart_ShutdownIsolate(); |
| 217 return 255; // Indicates we encountered an error. | 215 return 255; // Indicates we encountered an error. |
| 218 } | 216 } |
| 219 Dart_Handle library = Dart_GetResult(result); | 217 Dart_Handle result = Dart_InvokeStatic(library, |
| 220 result = Dart_InvokeStatic(library, | 218 Dart_NewString(""), |
| 221 Dart_NewString(""), | 219 Dart_NewString("main"), |
| 222 Dart_NewString("main"), | 220 0, |
| 223 0, | 221 NULL); |
| 224 NULL); | 222 if (Dart_IsValid(result)) { |
| 225 | 223 if (Dart_ExceptionOccurred(result)) { |
| 226 if (Dart_IsValidResult(result)) { | |
| 227 Dart_Handle result_obj = Dart_GetResult(result); | |
| 228 if (Dart_ExceptionOccurred(result_obj)) { | |
| 229 // Print the exception object. | 224 // Print the exception object. |
| 230 fprintf(stderr, "An unhandled exception has been thrown\n"); | 225 fprintf(stderr, "An unhandled exception has been thrown\n"); |
| 231 Dart_Result exception_result = Dart_GetException(result_obj); | 226 Dart_Handle exception_result = Dart_GetException(result); |
| 232 assert(Dart_IsValidResult(exception_result)); | 227 assert(Dart_IsValid(exception_result)); |
| 233 PrintObject(stderr, Dart_GetResult(exception_result)); | 228 PrintObject(stderr, exception_result); |
| 234 // Print the stack trace. | 229 // Print the stack trace. |
| 235 Dart_Result stacktrace = Dart_GetStacktrace(result_obj); | 230 Dart_Handle stacktrace = Dart_GetStacktrace(result); |
| 236 assert(Dart_IsValidResult(stacktrace)); | 231 assert(Dart_IsValid(stacktrace)); |
| 237 PrintObject(stderr, Dart_GetResult(stacktrace)); | 232 PrintObject(stderr, stacktrace); |
| 238 fprintf(stderr, "\n"); | 233 fprintf(stderr, "\n"); |
| 239 Dart_ExitScope(); | 234 Dart_ExitScope(); |
| 240 Dart_ShutdownIsolate(); | 235 Dart_ShutdownIsolate(); |
| 241 return 255; // We had an unhandled exception, hence indicate an error. | 236 return 255; // We had an unhandled exception, hence indicate an error. |
| 242 } | 237 } |
| 243 } else { | 238 } else { |
| 244 fprintf(stderr, "%s\n", Dart_GetErrorCString(result)); | 239 fprintf(stderr, "%s\n", Dart_GetError(result)); |
| 245 Dart_ExitScope(); | 240 Dart_ExitScope(); |
| 246 Dart_ShutdownIsolate(); | 241 Dart_ShutdownIsolate(); |
| 247 return 255; // Indicates we encountered an error. | 242 return 255; // Indicates we encountered an error. |
| 248 } | 243 } |
| 249 // Keep handling messages until the last active receive port is closed. | 244 // Keep handling messages until the last active receive port is closed. |
| 250 result = Dart_RunLoop(); | 245 result = Dart_RunLoop(); |
| 251 if (!Dart_IsValidResult(result)) { | 246 if (!Dart_IsValid(result)) { |
| 252 fprintf(stderr, "%s\n", Dart_GetErrorCString(result)); | 247 fprintf(stderr, "%s\n", Dart_GetError(result)); |
| 253 Dart_ExitScope(); | 248 Dart_ExitScope(); |
| 254 Dart_ShutdownIsolate(); | 249 Dart_ShutdownIsolate(); |
| 255 return 255; // Indicates we encountered an error. | 250 return 255; // Indicates we encountered an error. |
| 256 } | 251 } |
| 257 Dart_ExitScope(); | 252 Dart_ExitScope(); |
| 258 // Dump symbol information for the profiler. | 253 // Dump symbol information for the profiler. |
| 259 DumpPprofSymbolInfo(); | 254 DumpPprofSymbolInfo(); |
| 260 // Shutdown the isolate. | 255 // Shutdown the isolate. |
| 261 Dart_ShutdownIsolate(); | 256 Dart_ShutdownIsolate(); |
| 262 return 0; | 257 return 0; |
| 263 } | 258 } |
| OLD | NEW |