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 } |
| 371 |
| 372 const char* kFormat = "%s/%s"; |
| 373 intptr_t len = strlen(script_name) + strlen(func_name) + 2; |
| 374 char* buffer = new char[len]; |
| 375 ASSERT(buffer != NULL); |
| 376 snprintf(buffer, len, kFormat, script_name, func_name); |
| 377 return buffer; |
| 378 } |
| 379 |
| 380 |
362 int main(int argc, char** argv) { | 381 int main(int argc, char** argv) { |
363 char* script_name; | 382 char* script_name; |
364 CommandLineOptions vm_options(argc); | 383 CommandLineOptions vm_options(argc); |
365 CommandLineOptions dart_options(argc); | 384 CommandLineOptions dart_options(argc); |
366 | 385 |
367 // Perform platform specific initialization. | 386 // Perform platform specific initialization. |
368 if (!Platform::Initialize()) { | 387 if (!Platform::Initialize()) { |
369 fprintf(stderr, "Initialization failed\n"); | 388 fprintf(stderr, "Initialization failed\n"); |
370 } | 389 } |
371 | 390 |
(...skipping 26 matching lines...) Expand all Loading... |
398 // created. | 417 // created. |
399 if (use_script_snapshot) { | 418 if (use_script_snapshot) { |
400 if (!CaptureScriptSnapshot()) { | 419 if (!CaptureScriptSnapshot()) { |
401 return 255; // Error capturing script snapshot, error already reported. | 420 return 255; // Error capturing script snapshot, error already reported. |
402 } | 421 } |
403 } | 422 } |
404 | 423 |
405 // Call CreateIsolateAndSetup which creates an isolate and loads up | 424 // Call CreateIsolateAndSetup which creates an isolate and loads up |
406 // the specified application script. | 425 // the specified application script. |
407 char* error = NULL; | 426 char* error = NULL; |
408 if (!CreateIsolateAndSetup(NULL, &error)) { | 427 char* isolate_name = BuildIsolateName(canonical_script_name, "main"); |
| 428 if (!CreateIsolateAndSetup(isolate_name, NULL, &error)) { |
409 fprintf(stderr, "%s\n", error); | 429 fprintf(stderr, "%s\n", error); |
410 free(canonical_script_name); | 430 free(canonical_script_name); |
411 free(error); | 431 free(error); |
412 free(script_snapshot_buffer); | 432 free(script_snapshot_buffer); |
| 433 delete [] isolate_name; |
413 return 255; // Indicates we encountered an error. | 434 return 255; // Indicates we encountered an error. |
414 } | 435 } |
| 436 free(script_snapshot_buffer); // Don't need it anymore. |
| 437 delete [] isolate_name; |
415 | 438 |
416 free(script_snapshot_buffer); // Don't need it anymore. | |
417 Dart_Isolate isolate = Dart_CurrentIsolate(); | 439 Dart_Isolate isolate = Dart_CurrentIsolate(); |
418 ASSERT(isolate != NULL); | 440 ASSERT(isolate != NULL); |
419 Dart_Handle result; | 441 Dart_Handle result; |
420 | 442 |
421 Dart_EnterScope(); | 443 Dart_EnterScope(); |
422 | 444 |
423 if (has_compile_all) { | 445 if (has_compile_all) { |
424 result = Dart_CompileAll(); | 446 result = Dart_CompileAll(); |
425 if (Dart_IsError(result)) { | 447 if (Dart_IsError(result)) { |
426 fprintf(stderr, "%s\n", Dart_GetError(result)); | 448 fprintf(stderr, "%s\n", Dart_GetError(result)); |
427 Dart_ExitScope(); | 449 Dart_ExitScope(); |
428 Dart_ShutdownIsolate(); | 450 Dart_ShutdownIsolate(); |
429 free(canonical_script_name); | 451 free(canonical_script_name); |
430 return 255; // Indicates we encountered an error. | 452 return 255; // Indicates we encountered an error. |
431 } | 453 } |
432 } | 454 } |
433 | 455 |
434 // Create a dart options object that can be accessed from dart code. | 456 // Create a dart options object that can be accessed from dart code. |
435 Dart_Handle options_result = SetupRuntimeOptions(&dart_options); | 457 Dart_Handle options_result = SetupRuntimeOptions(&dart_options); |
436 if (Dart_IsError(options_result)) { | 458 if (Dart_IsError(options_result)) { |
437 fprintf(stderr, "%s\n", Dart_GetError(options_result)); | 459 fprintf(stderr, "%s\n", Dart_GetError(options_result)); |
438 Dart_ExitScope(); | 460 Dart_ExitScope(); |
439 Dart_ShutdownIsolate(); | 461 Dart_ShutdownIsolate(); |
440 free(canonical_script_name); | 462 free(canonical_script_name); |
441 return 255; // Indicates we encountered an error. | 463 return 255; // Indicates we encountered an error. |
442 } | 464 } |
443 | |
444 // Lookup the library of the main script. | 465 // Lookup the library of the main script. |
445 Dart_Handle script_url = Dart_NewString(canonical_script_name); | 466 Dart_Handle script_url = Dart_NewString(canonical_script_name); |
446 Dart_Handle library = Dart_LookupLibrary(script_url); | 467 Dart_Handle library = Dart_LookupLibrary(script_url); |
447 if (Dart_IsError(library)) { | 468 if (Dart_IsError(library)) { |
448 fprintf(stderr, "%s\n", Dart_GetError(library)); | 469 fprintf(stderr, "%s\n", Dart_GetError(library)); |
449 Dart_ExitScope(); | 470 Dart_ExitScope(); |
450 Dart_ShutdownIsolate(); | 471 Dart_ShutdownIsolate(); |
451 free(canonical_script_name); | 472 free(canonical_script_name); |
452 return 255; // Indicates we encountered an error. | 473 return 255; // Indicates we encountered an error. |
453 } | 474 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 Dart_ExitScope(); | 526 Dart_ExitScope(); |
506 // Dump symbol information for the profiler. | 527 // Dump symbol information for the profiler. |
507 DumpPprofSymbolInfo(); | 528 DumpPprofSymbolInfo(); |
508 // Shutdown the isolate. | 529 // Shutdown the isolate. |
509 Dart_ShutdownIsolate(); | 530 Dart_ShutdownIsolate(); |
510 // Terminate event handler. | 531 // Terminate event handler. |
511 EventHandler::Terminate(); | 532 EventHandler::Terminate(); |
512 | 533 |
513 return 0; | 534 return 0; |
514 } | 535 } |
OLD | NEW |