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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 Dart_Handle source = DartUtils::ReadStringFromFile(script_name); | 253 Dart_Handle source = DartUtils::ReadStringFromFile(script_name); |
| 254 if (Dart_IsError(source)) { | 254 if (Dart_IsError(source)) { |
| 255 return source; | 255 return source; |
| 256 } | 256 } |
| 257 Dart_Handle url = Dart_NewString(script_name); | 257 Dart_Handle url = Dart_NewString(script_name); |
| 258 | 258 |
| 259 return Dart_LoadScript(url, source, LibraryTagHandler); | 259 return Dart_LoadScript(url, source, LibraryTagHandler); |
| 260 } | 260 } |
| 261 | 261 |
| 262 | 262 |
| 263 static bool CreateIsolateAndSetup(void* data, char** error) { | 263 static bool CreateIsolateAndSetup(const char* name_prefix, |
| 264 Dart_Isolate isolate = Dart_CreateIsolate(snapshot_buffer, data, error); | 264 void* data, char** error) { |
| 265 Dart_Isolate isolate = | |
| 266 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error); | |
| 265 if (isolate == NULL) { | 267 if (isolate == NULL) { |
| 266 return false; | 268 return false; |
| 267 } | 269 } |
| 268 | 270 |
| 269 Dart_Handle library; | 271 Dart_Handle library; |
| 270 Dart_EnterScope(); | 272 Dart_EnterScope(); |
| 271 | 273 |
| 272 // Load the specified application script into the newly created isolate. | 274 // Load the specified application script into the newly created isolate. |
| 273 if (script_snapshot_buffer != NULL) { | 275 if (script_snapshot_buffer != NULL) { |
| 274 library = Dart_LoadScriptFromSnapshot(script_snapshot_buffer); | 276 library = Dart_LoadScriptFromSnapshot(script_snapshot_buffer); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 301 Dart_ExitScope(); | 303 Dart_ExitScope(); |
| 302 return true; | 304 return true; |
| 303 } | 305 } |
| 304 | 306 |
| 305 | 307 |
| 306 static bool CaptureScriptSnapshot() { | 308 static bool CaptureScriptSnapshot() { |
| 307 char* error = NULL; | 309 char* error = NULL; |
| 308 Dart_Handle result; | 310 Dart_Handle result; |
| 309 | 311 |
| 310 // First create an isolate and load up the specified script in it. | 312 // First create an isolate and load up the specified script in it. |
| 311 if (!CreateIsolateAndSetup(NULL, &error)) { | 313 if (!CreateIsolateAndSetup(NULL, NULL, &error)) { |
| 312 fprintf(stderr, "%s\n", error); | 314 fprintf(stderr, "%s\n", error); |
| 313 free(canonical_script_name); | 315 free(canonical_script_name); |
| 314 free(error); | 316 free(error); |
| 315 return false; // Indicates we encountered an error. | 317 return false; // Indicates we encountered an error. |
| 316 } | 318 } |
| 317 | 319 |
| 318 Dart_EnterScope(); | 320 Dart_EnterScope(); |
| 319 | 321 |
| 320 #if 0 | 322 #if 0 |
| 321 // Lookup the library of the main script. | 323 // Lookup the library of the main script. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 352 return true; | 354 return true; |
| 353 } | 355 } |
| 354 | 356 |
| 355 | 357 |
| 356 static void PrintUsage() { | 358 static void PrintUsage() { |
| 357 fprintf(stderr, | 359 fprintf(stderr, |
| 358 "dart [<vm-flags>] <dart-script-file> [<dart-options>]\n"); | 360 "dart [<vm-flags>] <dart-script-file> [<dart-options>]\n"); |
| 359 } | 361 } |
| 360 | 362 |
| 361 | 363 |
| 364 char* BuildIsolateName(const char* script_name, | |
| 365 const char* func_name) { | |
| 366 // Skip past any slashes in the script name. | |
| 367 const char* last_slash = strrchr(script_name, '/'); | |
| 368 if (last_slash != NULL) { | |
| 369 script_name = last_slash + 1; | |
| 370 } | |
|
siva
2012/01/18 06:26:03
Would skipping past slashes cause the name to be n
turnidge
2012/01/18 21:29:21
Yes and no. If there are two dart scripts with th
| |
| 371 | |
| 372 const char* kFormat = "%s/%s"; | |
| 373 intptr_t len = strlen(script_name) + strlen(func_name) + 2; | |
| 374 char* buffer = new char[len]; | |
|
siva
2012/01/18 06:26:03
ASSERT(buffer != NULL);
turnidge
2012/01/18 21:29:21
Done.
| |
| 375 snprintf(buffer, len, kFormat, script_name, func_name); | |
| 376 return buffer; | |
| 377 } | |
| 378 | |
| 379 | |
| 362 int main(int argc, char** argv) { | 380 int main(int argc, char** argv) { |
| 363 char* script_name; | 381 char* script_name; |
| 364 CommandLineOptions vm_options(argc); | 382 CommandLineOptions vm_options(argc); |
| 365 CommandLineOptions dart_options(argc); | 383 CommandLineOptions dart_options(argc); |
| 366 | 384 |
| 367 // Perform platform specific initialization. | 385 // Perform platform specific initialization. |
| 368 if (!Platform::Initialize()) { | 386 if (!Platform::Initialize()) { |
| 369 fprintf(stderr, "Initialization failed\n"); | 387 fprintf(stderr, "Initialization failed\n"); |
| 370 } | 388 } |
| 371 | 389 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 398 // created. | 416 // created. |
| 399 if (use_script_snapshot) { | 417 if (use_script_snapshot) { |
| 400 if (!CaptureScriptSnapshot()) { | 418 if (!CaptureScriptSnapshot()) { |
| 401 return 255; // Error capturing script snapshot, error already reported. | 419 return 255; // Error capturing script snapshot, error already reported. |
| 402 } | 420 } |
| 403 } | 421 } |
| 404 | 422 |
| 405 // Call CreateIsolateAndSetup which creates an isolate and loads up | 423 // Call CreateIsolateAndSetup which creates an isolate and loads up |
| 406 // the specified application script. | 424 // the specified application script. |
| 407 char* error = NULL; | 425 char* error = NULL; |
| 408 if (!CreateIsolateAndSetup(NULL, &error)) { | 426 char* isolate_name = BuildIsolateName(canonical_script_name, "main"); |
| 427 if (!CreateIsolateAndSetup(isolate_name, NULL, &error)) { | |
| 409 fprintf(stderr, "%s\n", error); | 428 fprintf(stderr, "%s\n", error); |
| 410 free(canonical_script_name); | 429 free(canonical_script_name); |
| 411 free(error); | 430 free(error); |
| 412 free(script_snapshot_buffer); | 431 free(script_snapshot_buffer); |
| 432 delete [] isolate_name; | |
| 413 return 255; // Indicates we encountered an error. | 433 return 255; // Indicates we encountered an error. |
| 414 } | 434 } |
| 435 free(script_snapshot_buffer); // Don't need it anymore. | |
| 436 delete [] isolate_name; | |
| 415 | 437 |
| 416 free(script_snapshot_buffer); // Don't need it anymore. | |
| 417 Dart_Isolate isolate = Dart_CurrentIsolate(); | 438 Dart_Isolate isolate = Dart_CurrentIsolate(); |
| 418 ASSERT(isolate != NULL); | 439 ASSERT(isolate != NULL); |
| 419 Dart_Handle result; | 440 Dart_Handle result; |
| 420 | 441 |
| 421 Dart_EnterScope(); | 442 Dart_EnterScope(); |
| 422 | 443 |
| 423 if (has_compile_all) { | 444 if (has_compile_all) { |
| 424 result = Dart_CompileAll(); | 445 result = Dart_CompileAll(); |
| 425 if (Dart_IsError(result)) { | 446 if (Dart_IsError(result)) { |
| 426 fprintf(stderr, "%s\n", Dart_GetError(result)); | 447 fprintf(stderr, "%s\n", Dart_GetError(result)); |
| 427 Dart_ExitScope(); | 448 Dart_ExitScope(); |
| 428 Dart_ShutdownIsolate(); | 449 Dart_ShutdownIsolate(); |
| 429 free(canonical_script_name); | 450 free(canonical_script_name); |
| 430 return 255; // Indicates we encountered an error. | 451 return 255; // Indicates we encountered an error. |
| 431 } | 452 } |
| 432 } | 453 } |
| 433 | 454 |
| 434 // Create a dart options object that can be accessed from dart code. | 455 // Create a dart options object that can be accessed from dart code. |
| 435 Dart_Handle options_result = SetupRuntimeOptions(&dart_options); | 456 Dart_Handle options_result = SetupRuntimeOptions(&dart_options); |
| 436 if (Dart_IsError(options_result)) { | 457 if (Dart_IsError(options_result)) { |
| 437 fprintf(stderr, "%s\n", Dart_GetError(options_result)); | 458 fprintf(stderr, "%s\n", Dart_GetError(options_result)); |
| 438 Dart_ExitScope(); | 459 Dart_ExitScope(); |
| 439 Dart_ShutdownIsolate(); | 460 Dart_ShutdownIsolate(); |
| 440 free(canonical_script_name); | 461 free(canonical_script_name); |
| 441 return 255; // Indicates we encountered an error. | 462 return 255; // Indicates we encountered an error. |
| 442 } | 463 } |
| 443 | |
| 444 // Lookup the library of the main script. | 464 // Lookup the library of the main script. |
| 445 Dart_Handle script_url = Dart_NewString(canonical_script_name); | 465 Dart_Handle script_url = Dart_NewString(canonical_script_name); |
| 446 Dart_Handle library = Dart_LookupLibrary(script_url); | 466 Dart_Handle library = Dart_LookupLibrary(script_url); |
| 447 if (Dart_IsError(library)) { | 467 if (Dart_IsError(library)) { |
| 448 fprintf(stderr, "%s\n", Dart_GetError(library)); | 468 fprintf(stderr, "%s\n", Dart_GetError(library)); |
| 449 Dart_ExitScope(); | 469 Dart_ExitScope(); |
| 450 Dart_ShutdownIsolate(); | 470 Dart_ShutdownIsolate(); |
| 451 free(canonical_script_name); | 471 free(canonical_script_name); |
| 452 return 255; // Indicates we encountered an error. | 472 return 255; // Indicates we encountered an error. |
| 453 } | 473 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 Dart_ExitScope(); | 525 Dart_ExitScope(); |
| 506 // Dump symbol information for the profiler. | 526 // Dump symbol information for the profiler. |
| 507 DumpPprofSymbolInfo(); | 527 DumpPprofSymbolInfo(); |
| 508 // Shutdown the isolate. | 528 // Shutdown the isolate. |
| 509 Dart_ShutdownIsolate(); | 529 Dart_ShutdownIsolate(); |
| 510 // Terminate event handler. | 530 // Terminate event handler. |
| 511 EventHandler::Terminate(); | 531 EventHandler::Terminate(); |
| 512 | 532 |
| 513 return 0; | 533 return 0; |
| 514 } | 534 } |
| OLD | NEW |