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 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 "Error: Unable to read snapshot file %s\n", filename); | 1109 "Error: Unable to read snapshot file %s\n", filename); |
1110 } | 1110 } |
1111 DartUtils::CloseFile(file); | 1111 DartUtils::CloseFile(file); |
1112 } | 1112 } |
1113 | 1113 |
1114 | 1114 |
1115 static void* LoadLibrarySymbol(const char* libname, const char* symname) { | 1115 static void* LoadLibrarySymbol(const char* libname, const char* symname) { |
1116 void* library = Extensions::LoadExtensionLibrary(libname); | 1116 void* library = Extensions::LoadExtensionLibrary(libname); |
1117 if (library == NULL) { | 1117 if (library == NULL) { |
1118 Log::PrintErr("Error: Failed to load library '%s'\n", libname); | 1118 Log::PrintErr("Error: Failed to load library '%s'\n", libname); |
1119 exit(kErrorExitCode); | 1119 Platform::Exit(kErrorExitCode); |
1120 } | 1120 } |
1121 void* symbol = Extensions::ResolveSymbol(library, symname); | 1121 void* symbol = Extensions::ResolveSymbol(library, symname); |
1122 if (symbol == NULL) { | 1122 if (symbol == NULL) { |
1123 Log::PrintErr("Error: Failed to load symbol '%s'\n", symname); | 1123 Log::PrintErr("Error: Failed to load symbol '%s'\n", symname); |
1124 exit(kErrorExitCode); | 1124 Platform::Exit(kErrorExitCode); |
1125 } | 1125 } |
1126 return symbol; | 1126 return symbol; |
1127 } | 1127 } |
1128 | 1128 |
1129 | 1129 |
1130 static void GenerateScriptSnapshot() { | 1130 static void GenerateScriptSnapshot() { |
1131 // First create a snapshot. | 1131 // First create a snapshot. |
1132 uint8_t* buffer = NULL; | 1132 uint8_t* buffer = NULL; |
1133 intptr_t size = 0; | 1133 intptr_t size = 0; |
1134 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); | 1134 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 Process::TerminateExitCodeHandler(); | 1195 Process::TerminateExitCodeHandler(); |
1196 error = Dart_Cleanup(); | 1196 error = Dart_Cleanup(); |
1197 if (error != NULL) { | 1197 if (error != NULL) { |
1198 Log::PrintErr("VM cleanup failed: %s\n", error); | 1198 Log::PrintErr("VM cleanup failed: %s\n", error); |
1199 free(error); | 1199 free(error); |
1200 } | 1200 } |
1201 if (do_vm_shutdown) { | 1201 if (do_vm_shutdown) { |
1202 DebuggerConnectionHandler::StopHandler(); | 1202 DebuggerConnectionHandler::StopHandler(); |
1203 EventHandler::Stop(); | 1203 EventHandler::Stop(); |
1204 } | 1204 } |
1205 exit((exit_code != 0) ? exit_code : kErrorExitCode); | 1205 Platform::Exit((exit_code != 0) ? exit_code : kErrorExitCode); |
1206 } | 1206 } |
1207 delete [] isolate_name; | 1207 delete [] isolate_name; |
1208 | 1208 |
1209 Dart_EnterIsolate(isolate); | 1209 Dart_EnterIsolate(isolate); |
1210 ASSERT(isolate == Dart_CurrentIsolate()); | 1210 ASSERT(isolate == Dart_CurrentIsolate()); |
1211 ASSERT(isolate != NULL); | 1211 ASSERT(isolate != NULL); |
1212 Dart_Handle result; | 1212 Dart_Handle result; |
1213 | 1213 |
1214 Dart_EnterScope(); | 1214 Dart_EnterScope(); |
1215 | 1215 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 // Parse command line arguments. | 1377 // Parse command line arguments. |
1378 if (ParseArguments(argc, | 1378 if (ParseArguments(argc, |
1379 argv, | 1379 argv, |
1380 &vm_options, | 1380 &vm_options, |
1381 &script_name, | 1381 &script_name, |
1382 &dart_options, | 1382 &dart_options, |
1383 &print_flags_seen, | 1383 &print_flags_seen, |
1384 &verbose_debug_seen) < 0) { | 1384 &verbose_debug_seen) < 0) { |
1385 if (has_help_option) { | 1385 if (has_help_option) { |
1386 PrintUsage(); | 1386 PrintUsage(); |
1387 exit(0); | 1387 Platform::Exit(0); |
1388 } else if (has_version_option) { | 1388 } else if (has_version_option) { |
1389 PrintVersion(); | 1389 PrintVersion(); |
1390 exit(0); | 1390 Platform::Exit(0); |
1391 } else if (print_flags_seen) { | 1391 } else if (print_flags_seen) { |
1392 // Will set the VM flags, print them out and then we exit as no | 1392 // Will set the VM flags, print them out and then we exit as no |
1393 // script was specified on the command line. | 1393 // script was specified on the command line. |
1394 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1394 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
1395 exit(0); | 1395 Platform::Exit(0); |
1396 } else { | 1396 } else { |
1397 PrintUsage(); | 1397 PrintUsage(); |
1398 exit(kErrorExitCode); | 1398 Platform::Exit(kErrorExitCode); |
1399 } | 1399 } |
1400 } | 1400 } |
1401 | 1401 |
1402 Thread::InitOnce(); | 1402 Thread::InitOnce(); |
1403 | 1403 |
1404 if (!DartUtils::SetOriginalWorkingDirectory()) { | 1404 if (!DartUtils::SetOriginalWorkingDirectory()) { |
1405 OSError err; | 1405 OSError err; |
1406 fprintf(stderr, "Error determining current directory: %s\n", err.message()); | 1406 fprintf(stderr, "Error determining current directory: %s\n", err.message()); |
1407 fflush(stderr); | 1407 fflush(stderr); |
1408 exit(kErrorExitCode); | 1408 Platform::Exit(kErrorExitCode); |
1409 } | 1409 } |
1410 | 1410 |
1411 if (generate_script_snapshot) { | 1411 if (generate_script_snapshot) { |
1412 vm_options.AddArgument("--load_deferred_eagerly"); | 1412 vm_options.AddArgument("--load_deferred_eagerly"); |
1413 } | 1413 } |
1414 | 1414 |
1415 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1415 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
1416 | 1416 |
1417 // Start event handler. | 1417 // Start event handler. |
1418 EventHandler::Start(); | 1418 EventHandler::Start(); |
(...skipping 29 matching lines...) Expand all Loading... |
1448 DartUtils::EntropySource, | 1448 DartUtils::EntropySource, |
1449 GetVMServiceAssetsArchiveCallback); | 1449 GetVMServiceAssetsArchiveCallback); |
1450 if (error != NULL) { | 1450 if (error != NULL) { |
1451 if (do_vm_shutdown) { | 1451 if (do_vm_shutdown) { |
1452 DebuggerConnectionHandler::StopHandler(); | 1452 DebuggerConnectionHandler::StopHandler(); |
1453 EventHandler::Stop(); | 1453 EventHandler::Stop(); |
1454 } | 1454 } |
1455 fprintf(stderr, "VM initialization failed: %s\n", error); | 1455 fprintf(stderr, "VM initialization failed: %s\n", error); |
1456 fflush(stderr); | 1456 fflush(stderr); |
1457 free(error); | 1457 free(error); |
1458 exit(kErrorExitCode); | 1458 Platform::Exit(kErrorExitCode); |
1459 } | 1459 } |
1460 | 1460 |
1461 Dart_RegisterIsolateServiceRequestCallback( | 1461 Dart_RegisterIsolateServiceRequestCallback( |
1462 "getIO", &ServiceGetIOHandler, NULL); | 1462 "getIO", &ServiceGetIOHandler, NULL); |
1463 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, | 1463 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, |
1464 &ServiceStreamCancelCallback); | 1464 &ServiceStreamCancelCallback); |
1465 | 1465 |
1466 // Run the main isolate until we aren't told to restart. | 1466 // Run the main isolate until we aren't told to restart. |
1467 while (RunMainIsolate(script_name, &dart_options)) { | 1467 while (RunMainIsolate(script_name, &dart_options)) { |
1468 Log::PrintErr("Restarting VM\n"); | 1468 Log::PrintErr("Restarting VM\n"); |
(...skipping 21 matching lines...) Expand all Loading... |
1490 if (environment != NULL) { | 1490 if (environment != NULL) { |
1491 for (HashMap::Entry* p = environment->Start(); | 1491 for (HashMap::Entry* p = environment->Start(); |
1492 p != NULL; | 1492 p != NULL; |
1493 p = environment->Next(p)) { | 1493 p = environment->Next(p)) { |
1494 free(p->key); | 1494 free(p->key); |
1495 free(p->value); | 1495 free(p->value); |
1496 } | 1496 } |
1497 delete environment; | 1497 delete environment; |
1498 } | 1498 } |
1499 | 1499 |
1500 exit(Process::GlobalExitCode()); | 1500 Platform::Exit(Process::GlobalExitCode()); |
1501 } | 1501 } |
1502 | 1502 |
1503 } // namespace bin | 1503 } // namespace bin |
1504 } // namespace dart | 1504 } // namespace dart |
1505 | 1505 |
1506 int main(int argc, char** argv) { | 1506 int main(int argc, char** argv) { |
1507 dart::bin::main(argc, argv); | 1507 dart::bin::main(argc, argv); |
1508 UNREACHABLE(); | 1508 UNREACHABLE(); |
1509 } | 1509 } |
OLD | NEW |