Chromium Code Reviews| 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_debugger_api.h" | 10 #include "include/dart_debugger_api.h" |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 586 | 586 |
| 587 const char* kFormat = "%s/%s"; | 587 const char* kFormat = "%s/%s"; |
| 588 intptr_t len = strlen(script_name) + strlen(func_name) + 2; | 588 intptr_t len = strlen(script_name) + strlen(func_name) + 2; |
| 589 char* buffer = new char[len]; | 589 char* buffer = new char[len]; |
| 590 ASSERT(buffer != NULL); | 590 ASSERT(buffer != NULL); |
| 591 snprintf(buffer, len, kFormat, script_name, func_name); | 591 snprintf(buffer, len, kFormat, script_name, func_name); |
| 592 return buffer; | 592 return buffer; |
| 593 } | 593 } |
| 594 | 594 |
| 595 | 595 |
| 596 static const int kCompilationErrorExitCode = 254; // Indicates a compile error. | |
| 596 static const int kErrorExitCode = 255; // Indicates we encountered an error. | 597 static const int kErrorExitCode = 255; // Indicates we encountered an error. |
|
siva
2013/07/15 22:42:20
Should we change the comment of this to state
// I
regis
2013/07/15 23:32:47
Done.
| |
| 597 | 598 |
| 598 | 599 |
| 599 static int ErrorExit(const char* format, ...) { | 600 static int ErrorExit(int exit_code, const char* format, ...) { |
| 600 va_list arguments; | 601 va_list arguments; |
| 601 va_start(arguments, format); | 602 va_start(arguments, format); |
| 602 Log::VPrintErr(format, arguments); | 603 Log::VPrintErr(format, arguments); |
| 603 va_end(arguments); | 604 va_end(arguments); |
| 604 fflush(stderr); | 605 fflush(stderr); |
| 605 | 606 |
| 606 Dart_ExitScope(); | 607 Dart_ExitScope(); |
| 607 Dart_ShutdownIsolate(); | 608 Dart_ShutdownIsolate(); |
| 608 | 609 |
| 609 return kErrorExitCode; | 610 return exit_code; |
| 611 } | |
| 612 | |
| 613 | |
| 614 static int DartErrorExit(Dart_Handle error) { | |
| 615 const int exit_code = Dart_IsCompilationError(error) ? | |
| 616 kCompilationErrorExitCode: kErrorExitCode; | |
|
siva
2013/07/15 22:42:20
kCompilationErrorExitCode : kErrorExitCode
regis
2013/07/15 23:32:47
Done.
| |
| 617 return ErrorExit(exit_code, "%s\n", Dart_GetError(error)); | |
| 610 } | 618 } |
| 611 | 619 |
| 612 | 620 |
| 613 static void ShutdownIsolate(void* callback_data) { | 621 static void ShutdownIsolate(void* callback_data) { |
| 614 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); | 622 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); |
| 615 EventHandler* handler = isolate_data->event_handler; | 623 EventHandler* handler = isolate_data->event_handler; |
| 616 if (handler != NULL) handler->Shutdown(); | 624 if (handler != NULL) handler->Shutdown(); |
| 617 delete isolate_data; | 625 delete isolate_data; |
| 618 } | 626 } |
| 619 | 627 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 DartUtils::WriteMagicNumber(snapshot_file); | 768 DartUtils::WriteMagicNumber(snapshot_file); |
| 761 | 769 |
| 762 // Now write the snapshot out to specified file. | 770 // Now write the snapshot out to specified file. |
| 763 bool bytes_written = snapshot_file->WriteFully(buffer, size); | 771 bool bytes_written = snapshot_file->WriteFully(buffer, size); |
| 764 ASSERT(bytes_written); | 772 ASSERT(bytes_written); |
| 765 delete snapshot_file; | 773 delete snapshot_file; |
| 766 } else { | 774 } else { |
| 767 if (has_compile_all) { | 775 if (has_compile_all) { |
| 768 result = Dart_CompileAll(); | 776 result = Dart_CompileAll(); |
| 769 if (Dart_IsError(result)) { | 777 if (Dart_IsError(result)) { |
| 770 return ErrorExit("%s\n", Dart_GetError(result)); | 778 return DartErrorExit(result); |
| 771 } | 779 } |
| 772 } | 780 } |
| 773 | 781 |
| 774 if (has_check_function_fingerprints) { | 782 if (has_check_function_fingerprints) { |
| 775 result = Dart_CheckFunctionFingerprints(); | 783 result = Dart_CheckFunctionFingerprints(); |
| 776 if (Dart_IsError(result)) { | 784 if (Dart_IsError(result)) { |
| 777 return ErrorExit("%s\n", Dart_GetError(result)); | 785 return DartErrorExit(result); |
| 778 } | 786 } |
| 779 } | 787 } |
| 780 | 788 |
| 781 // Create a dart options object that can be accessed from dart code. | 789 // Create a dart options object that can be accessed from dart code. |
| 782 Dart_Handle options_result = | 790 Dart_Handle options_result = |
| 783 SetupRuntimeOptions(&dart_options, executable_name, script_name); | 791 SetupRuntimeOptions(&dart_options, executable_name, script_name); |
| 784 if (Dart_IsError(options_result)) { | 792 if (Dart_IsError(options_result)) { |
| 785 return ErrorExit("%s\n", Dart_GetError(options_result)); | 793 return DartErrorExit(options_result); |
| 786 } | 794 } |
| 787 // Lookup the library of the root script. | 795 // Lookup the library of the root script. |
| 788 Dart_Handle library = Dart_RootLibrary(); | 796 Dart_Handle library = Dart_RootLibrary(); |
| 789 if (Dart_IsNull(library)) { | 797 if (Dart_IsNull(library)) { |
| 790 return ErrorExit("Unable to find root library for '%s'\n", | 798 return ErrorExit(kErrorExitCode, |
| 799 "Unable to find root library for '%s'\n", | |
| 791 script_name); | 800 script_name); |
| 792 } | 801 } |
| 793 // Set debug breakpoint if specified on the command line. | 802 // Set debug breakpoint if specified on the command line. |
| 794 if (breakpoint_at != NULL) { | 803 if (breakpoint_at != NULL) { |
| 795 result = SetBreakpoint(breakpoint_at, library); | 804 result = SetBreakpoint(breakpoint_at, library); |
| 796 if (Dart_IsError(result)) { | 805 if (Dart_IsError(result)) { |
| 797 return ErrorExit("Error setting breakpoint at '%s': %s\n", | 806 return ErrorExit(kErrorExitCode, |
| 807 "Error setting breakpoint at '%s': %s\n", | |
| 798 breakpoint_at, | 808 breakpoint_at, |
| 799 Dart_GetError(result)); | 809 Dart_GetError(result)); |
| 800 } | 810 } |
| 801 } | 811 } |
| 802 if (has_print_script) { | 812 if (has_print_script) { |
| 803 result = GenerateScriptSource(); | 813 result = GenerateScriptSource(); |
| 804 if (Dart_IsError(result)) { | 814 if (Dart_IsError(result)) { |
| 805 return ErrorExit("%s\n", Dart_GetError(result)); | 815 return DartErrorExit(result); |
| 806 } | 816 } |
| 807 } else { | 817 } else { |
| 808 // Lookup and invoke the top level main function. | 818 // Lookup and invoke the top level main function. |
| 809 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); | 819 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); |
| 810 if (Dart_IsError(result)) { | 820 if (Dart_IsError(result)) { |
| 811 return ErrorExit("%s\n", Dart_GetError(result)); | 821 return DartErrorExit(result); |
| 812 } | 822 } |
| 813 | 823 |
| 814 // Keep handling messages until the last active receive port is closed. | 824 // Keep handling messages until the last active receive port is closed. |
| 815 result = Dart_RunLoop(); | 825 result = Dart_RunLoop(); |
| 816 if (Dart_IsError(result)) { | 826 if (Dart_IsError(result)) { |
| 817 return ErrorExit("%s\n", Dart_GetError(result)); | 827 return DartErrorExit(result); |
| 818 } | 828 } |
| 819 } | 829 } |
| 820 } | 830 } |
| 821 | 831 |
| 822 Dart_ExitScope(); | 832 Dart_ExitScope(); |
| 823 // Shutdown the isolate. | 833 // Shutdown the isolate. |
| 824 Dart_ShutdownIsolate(); | 834 Dart_ShutdownIsolate(); |
| 825 // Terminate process exit-code handler. | 835 // Terminate process exit-code handler. |
| 826 Process::TerminateExitCodeHandler(); | 836 Process::TerminateExitCodeHandler(); |
| 827 // Free copied argument strings if converted. | 837 // Free copied argument strings if converted. |
| 828 if (argv_converted) { | 838 if (argv_converted) { |
| 829 for (int i = 0; i < argc; i++) free(argv[i]); | 839 for (int i = 0; i < argc; i++) free(argv[i]); |
| 830 } | 840 } |
| 831 | 841 |
| 832 return Process::GlobalExitCode(); | 842 return Process::GlobalExitCode(); |
| 833 } | 843 } |
| 834 | 844 |
| 835 } // namespace bin | 845 } // namespace bin |
| 836 } // namespace dart | 846 } // namespace dart |
| 837 | 847 |
| 838 int main(int argc, char** argv) { | 848 int main(int argc, char** argv) { |
| 839 return dart::bin::main(argc, argv); | 849 return dart::bin::main(argc, argv); |
| 840 } | 850 } |
| OLD | NEW |