| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
| 10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 char* error = Dart_Cleanup(); | 135 char* error = Dart_Cleanup(); |
| 136 if (error != NULL) { | 136 if (error != NULL) { |
| 137 Log::PrintErr("VM cleanup failed: %s\n", error); | 137 Log::PrintErr("VM cleanup failed: %s\n", error); |
| 138 free(error); | 138 free(error); |
| 139 } | 139 } |
| 140 | 140 |
| 141 if (do_vm_shutdown) { | 141 if (do_vm_shutdown) { |
| 142 DebuggerConnectionHandler::StopHandler(); | 142 DebuggerConnectionHandler::StopHandler(); |
| 143 EventHandler::Stop(); | 143 EventHandler::Stop(); |
| 144 } | 144 } |
| 145 exit(exit_code); | 145 Platform::Exit(exit_code); |
| 146 } | 146 } |
| 147 | 147 |
| 148 | 148 |
| 149 // The environment provided through the command line using -D options. | 149 // The environment provided through the command line using -D options. |
| 150 static dart::HashMap* environment = NULL; | 150 static dart::HashMap* environment = NULL; |
| 151 | 151 |
| 152 static bool IsValidFlag(const char* name, | 152 static bool IsValidFlag(const char* name, |
| 153 const char* prefix, | 153 const char* prefix, |
| 154 intptr_t prefix_length) { | 154 intptr_t prefix_length) { |
| 155 intptr_t name_length = strlen(name); | 155 intptr_t name_length = strlen(name); |
| (...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 "Error: Unable to read snapshot file %s\n", filename); | 1111 "Error: Unable to read snapshot file %s\n", filename); |
| 1112 } | 1112 } |
| 1113 DartUtils::CloseFile(file); | 1113 DartUtils::CloseFile(file); |
| 1114 } | 1114 } |
| 1115 | 1115 |
| 1116 | 1116 |
| 1117 static void* LoadLibrarySymbol(const char* libname, const char* symname) { | 1117 static void* LoadLibrarySymbol(const char* libname, const char* symname) { |
| 1118 void* library = Extensions::LoadExtensionLibrary(libname); | 1118 void* library = Extensions::LoadExtensionLibrary(libname); |
| 1119 if (library == NULL) { | 1119 if (library == NULL) { |
| 1120 Log::PrintErr("Error: Failed to load library '%s'\n", libname); | 1120 Log::PrintErr("Error: Failed to load library '%s'\n", libname); |
| 1121 exit(kErrorExitCode); | 1121 Platform::Exit(kErrorExitCode); |
| 1122 } | 1122 } |
| 1123 void* symbol = Extensions::ResolveSymbol(library, symname); | 1123 void* symbol = Extensions::ResolveSymbol(library, symname); |
| 1124 if (symbol == NULL) { | 1124 if (symbol == NULL) { |
| 1125 Log::PrintErr("Error: Failed to load symbol '%s'\n", symname); | 1125 Log::PrintErr("Error: Failed to load symbol '%s'\n", symname); |
| 1126 exit(kErrorExitCode); | 1126 Platform::Exit(kErrorExitCode); |
| 1127 } | 1127 } |
| 1128 return symbol; | 1128 return symbol; |
| 1129 } | 1129 } |
| 1130 | 1130 |
| 1131 | 1131 |
| 1132 static void GenerateScriptSnapshot() { | 1132 static void GenerateScriptSnapshot() { |
| 1133 // First create a snapshot. | 1133 // First create a snapshot. |
| 1134 uint8_t* buffer = NULL; | 1134 uint8_t* buffer = NULL; |
| 1135 intptr_t size = 0; | 1135 intptr_t size = 0; |
| 1136 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); | 1136 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1197 Process::TerminateExitCodeHandler(); | 1197 Process::TerminateExitCodeHandler(); |
| 1198 error = Dart_Cleanup(); | 1198 error = Dart_Cleanup(); |
| 1199 if (error != NULL) { | 1199 if (error != NULL) { |
| 1200 Log::PrintErr("VM cleanup failed: %s\n", error); | 1200 Log::PrintErr("VM cleanup failed: %s\n", error); |
| 1201 free(error); | 1201 free(error); |
| 1202 } | 1202 } |
| 1203 if (do_vm_shutdown) { | 1203 if (do_vm_shutdown) { |
| 1204 DebuggerConnectionHandler::StopHandler(); | 1204 DebuggerConnectionHandler::StopHandler(); |
| 1205 EventHandler::Stop(); | 1205 EventHandler::Stop(); |
| 1206 } | 1206 } |
| 1207 exit((exit_code != 0) ? exit_code : kErrorExitCode); | 1207 Platform::Exit((exit_code != 0) ? exit_code : kErrorExitCode); |
| 1208 } | 1208 } |
| 1209 delete [] isolate_name; | 1209 delete [] isolate_name; |
| 1210 | 1210 |
| 1211 Dart_EnterIsolate(isolate); | 1211 Dart_EnterIsolate(isolate); |
| 1212 ASSERT(isolate == Dart_CurrentIsolate()); | 1212 ASSERT(isolate == Dart_CurrentIsolate()); |
| 1213 ASSERT(isolate != NULL); | 1213 ASSERT(isolate != NULL); |
| 1214 Dart_Handle result; | 1214 Dart_Handle result; |
| 1215 | 1215 |
| 1216 Dart_EnterScope(); | 1216 Dart_EnterScope(); |
| 1217 | 1217 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 // Parse command line arguments. | 1393 // Parse command line arguments. |
| 1394 if (ParseArguments(argc, | 1394 if (ParseArguments(argc, |
| 1395 argv, | 1395 argv, |
| 1396 &vm_options, | 1396 &vm_options, |
| 1397 &script_name, | 1397 &script_name, |
| 1398 &dart_options, | 1398 &dart_options, |
| 1399 &print_flags_seen, | 1399 &print_flags_seen, |
| 1400 &verbose_debug_seen) < 0) { | 1400 &verbose_debug_seen) < 0) { |
| 1401 if (has_help_option) { | 1401 if (has_help_option) { |
| 1402 PrintUsage(); | 1402 PrintUsage(); |
| 1403 exit(0); | 1403 Platform::Exit(0); |
| 1404 } else if (has_version_option) { | 1404 } else if (has_version_option) { |
| 1405 PrintVersion(); | 1405 PrintVersion(); |
| 1406 exit(0); | 1406 Platform::Exit(0); |
| 1407 } else if (print_flags_seen) { | 1407 } else if (print_flags_seen) { |
| 1408 // Will set the VM flags, print them out and then we exit as no | 1408 // Will set the VM flags, print them out and then we exit as no |
| 1409 // script was specified on the command line. | 1409 // script was specified on the command line. |
| 1410 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1410 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
| 1411 exit(0); | 1411 Platform::Exit(0); |
| 1412 } else { | 1412 } else { |
| 1413 PrintUsage(); | 1413 PrintUsage(); |
| 1414 exit(kErrorExitCode); | 1414 Platform::Exit(kErrorExitCode); |
| 1415 } | 1415 } |
| 1416 } | 1416 } |
| 1417 | 1417 |
| 1418 Thread::InitOnce(); | 1418 Thread::InitOnce(); |
| 1419 | 1419 |
| 1420 if (!DartUtils::SetOriginalWorkingDirectory()) { | 1420 if (!DartUtils::SetOriginalWorkingDirectory()) { |
| 1421 OSError err; | 1421 OSError err; |
| 1422 fprintf(stderr, "Error determining current directory: %s\n", err.message()); | 1422 fprintf(stderr, "Error determining current directory: %s\n", err.message()); |
| 1423 fflush(stderr); | 1423 fflush(stderr); |
| 1424 exit(kErrorExitCode); | 1424 Platform::Exit(kErrorExitCode); |
| 1425 } | 1425 } |
| 1426 | 1426 |
| 1427 if (generate_script_snapshot) { | 1427 if (generate_script_snapshot) { |
| 1428 vm_options.AddArgument("--load_deferred_eagerly"); | 1428 vm_options.AddArgument("--load_deferred_eagerly"); |
| 1429 } | 1429 } |
| 1430 | 1430 |
| 1431 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1431 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
| 1432 | 1432 |
| 1433 // Start event handler. | 1433 // Start event handler. |
| 1434 EventHandler::Start(); | 1434 EventHandler::Start(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1464 DartUtils::EntropySource, | 1464 DartUtils::EntropySource, |
| 1465 GetVMServiceAssetsArchiveCallback); | 1465 GetVMServiceAssetsArchiveCallback); |
| 1466 if (error != NULL) { | 1466 if (error != NULL) { |
| 1467 if (do_vm_shutdown) { | 1467 if (do_vm_shutdown) { |
| 1468 DebuggerConnectionHandler::StopHandler(); | 1468 DebuggerConnectionHandler::StopHandler(); |
| 1469 EventHandler::Stop(); | 1469 EventHandler::Stop(); |
| 1470 } | 1470 } |
| 1471 fprintf(stderr, "VM initialization failed: %s\n", error); | 1471 fprintf(stderr, "VM initialization failed: %s\n", error); |
| 1472 fflush(stderr); | 1472 fflush(stderr); |
| 1473 free(error); | 1473 free(error); |
| 1474 exit(kErrorExitCode); | 1474 Platform::Exit(kErrorExitCode); |
| 1475 } | 1475 } |
| 1476 | 1476 |
| 1477 Dart_RegisterIsolateServiceRequestCallback( | 1477 Dart_RegisterIsolateServiceRequestCallback( |
| 1478 "getIO", &ServiceGetIOHandler, NULL); | 1478 "getIO", &ServiceGetIOHandler, NULL); |
| 1479 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, | 1479 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, |
| 1480 &ServiceStreamCancelCallback); | 1480 &ServiceStreamCancelCallback); |
| 1481 | 1481 |
| 1482 // Run the main isolate until we aren't told to restart. | 1482 // Run the main isolate until we aren't told to restart. |
| 1483 while (RunMainIsolate(script_name, &dart_options)) { | 1483 while (RunMainIsolate(script_name, &dart_options)) { |
| 1484 Log::PrintErr("Restarting VM\n"); | 1484 Log::PrintErr("Restarting VM\n"); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1506 if (environment != NULL) { | 1506 if (environment != NULL) { |
| 1507 for (HashMap::Entry* p = environment->Start(); | 1507 for (HashMap::Entry* p = environment->Start(); |
| 1508 p != NULL; | 1508 p != NULL; |
| 1509 p = environment->Next(p)) { | 1509 p = environment->Next(p)) { |
| 1510 free(p->key); | 1510 free(p->key); |
| 1511 free(p->value); | 1511 free(p->value); |
| 1512 } | 1512 } |
| 1513 delete environment; | 1513 delete environment; |
| 1514 } | 1514 } |
| 1515 | 1515 |
| 1516 exit(Process::GlobalExitCode()); | 1516 Platform::Exit(Process::GlobalExitCode()); |
| 1517 } | 1517 } |
| 1518 | 1518 |
| 1519 } // namespace bin | 1519 } // namespace bin |
| 1520 } // namespace dart | 1520 } // namespace dart |
| 1521 | 1521 |
| 1522 int main(int argc, char** argv) { | 1522 int main(int argc, char** argv) { |
| 1523 dart::bin::main(argc, argv); | 1523 dart::bin::main(argc, argv); |
| 1524 UNREACHABLE(); | 1524 UNREACHABLE(); |
| 1525 } | 1525 } |
| OLD | NEW |