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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 } | 156 } |
| 157 return false; | 157 return false; |
| 158 } | 158 } |
| 159 | 159 |
| 160 | 160 |
| 161 // Parse out the command line arguments. Returns -1 if the arguments | 161 // Parse out the command line arguments. Returns -1 if the arguments |
| 162 // are incorrect, 0 otherwise. | 162 // are incorrect, 0 otherwise. |
| 163 static int ParseArguments(int argc, | 163 static int ParseArguments(int argc, |
| 164 char** argv, | 164 char** argv, |
| 165 CommandLineOptions* vm_options, | 165 CommandLineOptions* vm_options, |
| 166 char** executable_name, | |
| 166 char** script_name, | 167 char** script_name, |
| 167 CommandLineOptions* dart_options) { | 168 CommandLineOptions* dart_options) { |
| 168 const char* kPrefix = "--"; | 169 const char* kPrefix = "--"; |
| 169 const intptr_t kPrefixLen = strlen(kPrefix); | 170 const intptr_t kPrefixLen = strlen(kPrefix); |
| 170 | 171 |
| 171 // Skip the binary name. | 172 // Get the executable name. |
| 173 *executable_name = argv[0]; | |
| 174 | |
| 175 // Start the rest after the executable name. | |
| 172 int i = 1; | 176 int i = 1; |
| 173 | 177 |
| 174 // Parse out the vm options. | 178 // Parse out the vm options. |
| 175 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { | 179 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { |
| 176 if (ProcessMainOptions(argv[i])) { | 180 if (ProcessMainOptions(argv[i])) { |
| 177 i += 1; | 181 ++i; |
|
Ivan Posva
2012/05/07 17:40:36
i++ is more conventional, no?
Mads Ager (google)
2012/05/08 06:39:04
Yes, it is. Done.
| |
| 178 } else { | 182 } else { |
| 179 vm_options->AddArgument(argv[i]); | 183 vm_options->AddArgument(argv[i]); |
| 180 i += 1; | 184 ++i; |
| 181 } | 185 } |
| 182 } | 186 } |
| 183 if (generate_pprof_symbols_filename != NULL) { | 187 if (generate_pprof_symbols_filename != NULL) { |
| 184 Dart_InitPprofSupport(); | 188 Dart_InitPprofSupport(); |
| 185 } | 189 } |
| 186 | 190 |
| 187 // Get the script name. | 191 // Get the script name. |
| 188 if (i < argc) { | 192 if (i < argc) { |
| 189 *script_name = argv[i]; | 193 *script_name = argv[i]; |
| 190 i += 1; | 194 ++i; |
| 191 } else { | 195 } else { |
| 192 return -1; | 196 return -1; |
| 193 } | 197 } |
| 194 | 198 |
| 195 // Parse out options to be passed to dart main. | 199 // Parse out options to be passed to dart main. |
| 196 while (i < argc) { | 200 while (i < argc) { |
| 197 dart_options->AddArgument(argv[i]); | 201 dart_options->AddArgument(argv[i]); |
| 198 i += 1; | 202 i += 1; |
| 199 } | 203 } |
| 200 | 204 |
| 201 return 0; | 205 return 0; |
| 202 } | 206 } |
| 203 | 207 |
| 204 | 208 |
| 205 static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options, | 209 static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options, |
| 210 const char* executable_name, | |
| 206 const char* script_name) { | 211 const char* script_name) { |
| 207 int options_count = options->count(); | 212 int options_count = options->count(); |
| 213 Dart_Handle dart_executable = Dart_NewString(executable_name); | |
| 214 if (Dart_IsError(dart_executable)) { | |
| 215 return dart_executable; | |
| 216 } | |
| 208 Dart_Handle dart_script = Dart_NewString(script_name); | 217 Dart_Handle dart_script = Dart_NewString(script_name); |
| 209 if (Dart_IsError(dart_script)) { | 218 if (Dart_IsError(dart_script)) { |
| 210 return dart_script; | 219 return dart_script; |
| 211 } | 220 } |
| 212 Dart_Handle dart_arguments = Dart_NewList(options_count); | 221 Dart_Handle dart_arguments = Dart_NewList(options_count); |
| 213 if (Dart_IsError(dart_arguments)) { | 222 if (Dart_IsError(dart_arguments)) { |
| 214 return dart_arguments; | 223 return dart_arguments; |
| 215 } | 224 } |
| 216 for (int i = 0; i < options_count; i++) { | 225 for (int i = 0; i < options_count; i++) { |
| 217 Dart_Handle argument_value = Dart_NewString(options->GetArgument(i)); | 226 Dart_Handle argument_value = Dart_NewString(options->GetArgument(i)); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 233 } | 242 } |
| 234 Dart_Handle runtime_options_class_name = Dart_NewString("RuntimeOptions"); | 243 Dart_Handle runtime_options_class_name = Dart_NewString("RuntimeOptions"); |
| 235 if (Dart_IsError(runtime_options_class_name)) { | 244 if (Dart_IsError(runtime_options_class_name)) { |
| 236 return runtime_options_class_name; | 245 return runtime_options_class_name; |
| 237 } | 246 } |
| 238 Dart_Handle runtime_options_class = Dart_GetClass( | 247 Dart_Handle runtime_options_class = Dart_GetClass( |
| 239 core_lib, runtime_options_class_name); | 248 core_lib, runtime_options_class_name); |
| 240 if (Dart_IsError(runtime_options_class)) { | 249 if (Dart_IsError(runtime_options_class)) { |
| 241 return runtime_options_class; | 250 return runtime_options_class; |
| 242 } | 251 } |
| 252 Dart_Handle executable_name_name = Dart_NewString("_nativeExecutable"); | |
| 253 if (Dart_IsError(executable_name_name)) { | |
| 254 return executable_name_name; | |
| 255 } | |
| 256 Dart_Handle set_executable_name = | |
| 257 Dart_SetField(runtime_options_class, | |
| 258 executable_name_name, | |
| 259 dart_executable); | |
| 260 if (Dart_IsError(set_executable_name)) { | |
| 261 return set_executable_name; | |
| 262 } | |
| 243 Dart_Handle script_name_name = Dart_NewString("_nativeScript"); | 263 Dart_Handle script_name_name = Dart_NewString("_nativeScript"); |
| 244 if (Dart_IsError(script_name_name)) { | 264 if (Dart_IsError(script_name_name)) { |
| 245 return script_name_name; | 265 return script_name_name; |
| 246 } | 266 } |
| 247 Dart_Handle set_script_name = | 267 Dart_Handle set_script_name = |
| 248 Dart_SetField(runtime_options_class, script_name_name, dart_script); | 268 Dart_SetField(runtime_options_class, script_name_name, dart_script); |
| 249 if (Dart_IsError(set_script_name)) { | 269 if (Dart_IsError(set_script_name)) { |
| 250 return set_script_name; | 270 return set_script_name; |
| 251 } | 271 } |
| 252 Dart_Handle native_name = Dart_NewString("_nativeArguments"); | 272 Dart_Handle native_name = Dart_NewString("_nativeArguments"); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 562 | 582 |
| 563 free(const_cast<char*>(original_script_name)); | 583 free(const_cast<char*>(original_script_name)); |
| 564 free(const_cast<char*>(original_working_directory)); | 584 free(const_cast<char*>(original_working_directory)); |
| 565 free(const_cast<char*>(original_script_url)); | 585 free(const_cast<char*>(original_script_url)); |
| 566 | 586 |
| 567 return kErrorExitCode; | 587 return kErrorExitCode; |
| 568 } | 588 } |
| 569 | 589 |
| 570 | 590 |
| 571 int main(int argc, char** argv) { | 591 int main(int argc, char** argv) { |
| 592 char* executable_name; | |
| 572 char* script_name; | 593 char* script_name; |
| 573 CommandLineOptions vm_options(argc); | 594 CommandLineOptions vm_options(argc); |
| 574 CommandLineOptions dart_options(argc); | 595 CommandLineOptions dart_options(argc); |
| 575 CommandLineOptions import_map(argc); | 596 CommandLineOptions import_map(argc); |
| 576 import_map_options = &import_map; | 597 import_map_options = &import_map; |
| 577 | 598 |
| 578 // Perform platform specific initialization. | 599 // Perform platform specific initialization. |
| 579 if (!Platform::Initialize()) { | 600 if (!Platform::Initialize()) { |
| 580 fprintf(stderr, "Initialization failed\n"); | 601 fprintf(stderr, "Initialization failed\n"); |
| 581 } | 602 } |
| 582 | 603 |
| 583 // Parse command line arguments. | 604 // Parse command line arguments. |
| 584 if (ParseArguments(argc, | 605 if (ParseArguments(argc, |
| 585 argv, | 606 argv, |
| 586 &vm_options, | 607 &vm_options, |
| 608 &executable_name, | |
| 587 &script_name, | 609 &script_name, |
| 588 &dart_options) < 0) { | 610 &dart_options) < 0) { |
| 589 PrintUsage(); | 611 PrintUsage(); |
| 590 return kErrorExitCode; | 612 return kErrorExitCode; |
| 591 } | 613 } |
| 592 | 614 |
| 593 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 615 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
| 594 | 616 |
| 595 // Initialize the Dart VM. | 617 // Initialize the Dart VM. |
| 596 Dart_Initialize(CreateIsolateAndSetup, NULL); | 618 Dart_Initialize(CreateIsolateAndSetup, NULL); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 620 | 642 |
| 621 if (has_compile_all) { | 643 if (has_compile_all) { |
| 622 result = Dart_CompileAll(); | 644 result = Dart_CompileAll(); |
| 623 if (Dart_IsError(result)) { | 645 if (Dart_IsError(result)) { |
| 624 return ErrorExit("%s\n", Dart_GetError(result)); | 646 return ErrorExit("%s\n", Dart_GetError(result)); |
| 625 } | 647 } |
| 626 } | 648 } |
| 627 | 649 |
| 628 // Create a dart options object that can be accessed from dart code. | 650 // Create a dart options object that can be accessed from dart code. |
| 629 Dart_Handle options_result = | 651 Dart_Handle options_result = |
| 630 SetupRuntimeOptions(&dart_options, original_script_name); | 652 SetupRuntimeOptions(&dart_options, executable_name, original_script_name); |
| 631 if (Dart_IsError(options_result)) { | 653 if (Dart_IsError(options_result)) { |
| 632 return ErrorExit("%s\n", Dart_GetError(options_result)); | 654 return ErrorExit("%s\n", Dart_GetError(options_result)); |
| 633 } | 655 } |
| 634 // Lookup the library of the main script. | 656 // Lookup the library of the main script. |
| 635 Dart_Handle script_url = Dart_NewString(original_script_url); | 657 Dart_Handle script_url = Dart_NewString(original_script_url); |
| 636 Dart_Handle library = Dart_LookupLibrary(script_url); | 658 Dart_Handle library = Dart_LookupLibrary(script_url); |
| 637 if (Dart_IsError(library)) { | 659 if (Dart_IsError(library)) { |
| 638 return ErrorExit("%s\n", Dart_GetError(library)); | 660 return ErrorExit("%s\n", Dart_GetError(library)); |
| 639 } | 661 } |
| 640 // Set debug breakpoint if specified on the command line. | 662 // Set debug breakpoint if specified on the command line. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 671 Dart_ShutdownIsolate(); | 693 Dart_ShutdownIsolate(); |
| 672 // Terminate process exit-code handler. | 694 // Terminate process exit-code handler. |
| 673 Process::TerminateExitCodeHandler(); | 695 Process::TerminateExitCodeHandler(); |
| 674 | 696 |
| 675 free(const_cast<char*>(original_script_name)); | 697 free(const_cast<char*>(original_script_name)); |
| 676 free(const_cast<char*>(original_working_directory)); | 698 free(const_cast<char*>(original_working_directory)); |
| 677 free(const_cast<char*>(original_script_url)); | 699 free(const_cast<char*>(original_script_url)); |
| 678 | 700 |
| 679 return 0; | 701 return 0; |
| 680 } | 702 } |
| OLD | NEW |