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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 // Exit code indicating an unhandled error that is not a compilation error. | 126 // Exit code indicating an unhandled error that is not a compilation error. |
127 static const int kErrorExitCode = 255; | 127 static const int kErrorExitCode = 255; |
128 // Exit code indicating a vm restart request. Never returned to the user. | 128 // Exit code indicating a vm restart request. Never returned to the user. |
129 static const int kRestartRequestExitCode = 1000; | 129 static const int kRestartRequestExitCode = 1000; |
130 | 130 |
131 static void ErrorExit(int exit_code, const char* format, ...) { | 131 static void ErrorExit(int exit_code, const char* format, ...) { |
132 va_list arguments; | 132 va_list arguments; |
133 va_start(arguments, format); | 133 va_start(arguments, format); |
134 Log::VPrintErr(format, arguments); | 134 Log::VPrintErr(format, arguments); |
135 va_end(arguments); | 135 va_end(arguments); |
136 fflush(stderr); | |
137 | 136 |
138 Dart_ExitScope(); | 137 Dart_ExitScope(); |
139 Dart_ShutdownIsolate(); | 138 Dart_ShutdownIsolate(); |
140 | 139 |
141 // Terminate process exit-code handler. | 140 // Terminate process exit-code handler. |
142 Process::TerminateExitCodeHandler(); | 141 Process::TerminateExitCodeHandler(); |
143 | 142 |
144 char* error = Dart_Cleanup(); | 143 char* error = Dart_Cleanup(); |
145 if (error != NULL) { | 144 if (error != NULL) { |
146 Log::PrintErr("VM cleanup failed: %s\n", error); | 145 Log::PrintErr("VM cleanup failed: %s\n", error); |
(...skipping 1444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1591 // lookup the main entry point exported from the root library. | 1590 // lookup the main entry point exported from the root library. |
1592 IsolateData* isolate_data = | 1591 IsolateData* isolate_data = |
1593 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); | 1592 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); |
1594 result = Dart_LibraryImportLibrary(isolate_data->builtin_lib(), root_lib, | 1593 result = Dart_LibraryImportLibrary(isolate_data->builtin_lib(), root_lib, |
1595 Dart_Null()); | 1594 Dart_Null()); |
1596 if (is_noopt || (gen_snapshot_kind == kAppAOT) || | 1595 if (is_noopt || (gen_snapshot_kind == kAppAOT) || |
1597 (gen_snapshot_kind == kAppJIT)) { | 1596 (gen_snapshot_kind == kAppJIT)) { |
1598 // Load the embedder's portion of the VM service's Dart code so it will | 1597 // Load the embedder's portion of the VM service's Dart code so it will |
1599 // be included in the app snapshot. | 1598 // be included in the app snapshot. |
1600 if (!VmService::LoadForGenPrecompiled()) { | 1599 if (!VmService::LoadForGenPrecompiled()) { |
1601 fprintf(stderr, "VM service loading failed: %s\n", | 1600 Log::PrintErr("VM service loading failed: %s\n", |
1602 VmService::GetErrorMessage()); | 1601 VmService::GetErrorMessage()); |
1603 fflush(stderr); | |
1604 exit(kErrorExitCode); | 1602 exit(kErrorExitCode); |
1605 } | 1603 } |
1606 } | 1604 } |
1607 | 1605 |
1608 if (compile_all) { | 1606 if (compile_all) { |
1609 result = Dart_CompileAll(); | 1607 result = Dart_CompileAll(); |
1610 CHECK_RESULT(result); | 1608 CHECK_RESULT(result); |
1611 } | 1609 } |
1612 | 1610 |
1613 if (parse_all) { | 1611 if (parse_all) { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1841 Platform::Exit(kErrorExitCode); | 1839 Platform::Exit(kErrorExitCode); |
1842 } | 1840 } |
1843 } | 1841 } |
1844 | 1842 |
1845 Thread::InitOnce(); | 1843 Thread::InitOnce(); |
1846 | 1844 |
1847 Loader::InitOnce(); | 1845 Loader::InitOnce(); |
1848 | 1846 |
1849 if (!DartUtils::SetOriginalWorkingDirectory()) { | 1847 if (!DartUtils::SetOriginalWorkingDirectory()) { |
1850 OSError err; | 1848 OSError err; |
1851 fprintf(stderr, "Error determining current directory: %s\n", err.message()); | 1849 Log::PrintErr("Error determining current directory: %s\n", err.message()); |
1852 fflush(stderr); | |
1853 Platform::Exit(kErrorExitCode); | 1850 Platform::Exit(kErrorExitCode); |
1854 } | 1851 } |
1855 | 1852 |
1856 const uint8_t* instructions_snapshot = NULL; | 1853 const uint8_t* instructions_snapshot = NULL; |
1857 const uint8_t* data_snapshot = NULL; | 1854 const uint8_t* data_snapshot = NULL; |
1858 | 1855 |
1859 if (ReadAppSnapshot(script_name, &vm_isolate_snapshot_buffer, | 1856 if (ReadAppSnapshot(script_name, &vm_isolate_snapshot_buffer, |
1860 &isolate_snapshot_buffer, &instructions_snapshot, | 1857 &isolate_snapshot_buffer, &instructions_snapshot, |
1861 &data_snapshot)) { | 1858 &data_snapshot)) { |
1862 run_app_snapshot = true; | 1859 run_app_snapshot = true; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1903 init_params.file_open = DartUtils::OpenFile; | 1900 init_params.file_open = DartUtils::OpenFile; |
1904 init_params.file_read = DartUtils::ReadFile; | 1901 init_params.file_read = DartUtils::ReadFile; |
1905 init_params.file_write = DartUtils::WriteFile; | 1902 init_params.file_write = DartUtils::WriteFile; |
1906 init_params.file_close = DartUtils::CloseFile; | 1903 init_params.file_close = DartUtils::CloseFile; |
1907 init_params.entropy_source = DartUtils::EntropySource; | 1904 init_params.entropy_source = DartUtils::EntropySource; |
1908 init_params.get_service_assets = GetVMServiceAssetsArchiveCallback; | 1905 init_params.get_service_assets = GetVMServiceAssetsArchiveCallback; |
1909 | 1906 |
1910 char* error = Dart_Initialize(&init_params); | 1907 char* error = Dart_Initialize(&init_params); |
1911 if (error != NULL) { | 1908 if (error != NULL) { |
1912 EventHandler::Stop(); | 1909 EventHandler::Stop(); |
1913 fprintf(stderr, "VM initialization failed: %s\n", error); | 1910 Log::PrintErr("VM initialization failed: %s\n", error); |
1914 fflush(stderr); | |
1915 free(error); | 1911 free(error); |
1916 Platform::Exit(kErrorExitCode); | 1912 Platform::Exit(kErrorExitCode); |
1917 } | 1913 } |
1918 | 1914 |
1919 Dart_RegisterIsolateServiceRequestCallback("getIO", &ServiceGetIOHandler, | 1915 Dart_RegisterIsolateServiceRequestCallback("getIO", &ServiceGetIOHandler, |
1920 NULL); | 1916 NULL); |
1921 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, | 1917 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, |
1922 &ServiceStreamCancelCallback); | 1918 &ServiceStreamCancelCallback); |
1923 Dart_SetFileModifiedCallback(&FileModifiedCallback); | 1919 Dart_SetFileModifiedCallback(&FileModifiedCallback); |
1924 | 1920 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1957 Platform::Exit(Process::GlobalExitCode()); | 1953 Platform::Exit(Process::GlobalExitCode()); |
1958 } | 1954 } |
1959 | 1955 |
1960 } // namespace bin | 1956 } // namespace bin |
1961 } // namespace dart | 1957 } // namespace dart |
1962 | 1958 |
1963 int main(int argc, char** argv) { | 1959 int main(int argc, char** argv) { |
1964 dart::bin::main(argc, argv); | 1960 dart::bin::main(argc, argv); |
1965 UNREACHABLE(); | 1961 UNREACHABLE(); |
1966 } | 1962 } |
OLD | NEW |