| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Generate a snapshot file after loading all the scripts specified on the | 5 // Generate a snapshot file after loading all the scripts specified on the |
| 6 // command line. | 6 // command line. |
| 7 | 7 |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 Dart_Handle result; | 95 Dart_Handle result; |
| 96 Dart_EnterScope(); | 96 Dart_EnterScope(); |
| 97 | 97 |
| 98 ASSERT(snapshot_filename != NULL); | 98 ASSERT(snapshot_filename != NULL); |
| 99 | 99 |
| 100 // If a file is specified on the command line, load it up before a snapshot | 100 // If a file is specified on the command line, load it up before a snapshot |
| 101 // is created. | 101 // is created. |
| 102 if (script_name != NULL) { | 102 if (script_name != NULL) { |
| 103 // Load the specified script. | 103 // Load the specified script. |
| 104 Dart_Handle library = LoadSnapshotCreationScript(script_name); | 104 Dart_Handle library = LoadSnapshotCreationScript(script_name); |
| 105 if (!Dart_IsValid(library)) { | 105 if (Dart_IsError(library)) { |
| 106 const char* err_msg = Dart_GetError(library); | 106 const char* err_msg = Dart_GetError(library); |
| 107 fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg); | 107 fprintf(stderr, "Errors encountered while loading script: %s\n", err_msg); |
| 108 Dart_ExitScope(); | 108 Dart_ExitScope(); |
| 109 exit(255); | 109 exit(255); |
| 110 } | 110 } |
| 111 | 111 |
| 112 if (!Dart_IsLibrary(library)) { | 112 if (!Dart_IsLibrary(library)) { |
| 113 fprintf(stderr, | 113 fprintf(stderr, |
| 114 "Expected a library when loading script: %s", | 114 "Expected a library when loading script: %s", |
| 115 script_name); | 115 script_name); |
| 116 Dart_ExitScope(); | 116 Dart_ExitScope(); |
| 117 exit(255); | 117 exit(255); |
| 118 } | 118 } |
| 119 } else { | 119 } else { |
| 120 // Implicitly load builtin library. | 120 // Implicitly load builtin library. |
| 121 Builtin_LoadLibrary(); | 121 Builtin_LoadLibrary(); |
| 122 // Setup the native resolver for built in library functions. | 122 // Setup the native resolver for built in library functions. |
| 123 Builtin_SetNativeResolver(); | 123 Builtin_SetNativeResolver(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 uint8_t* buffer = NULL; | 126 uint8_t* buffer = NULL; |
| 127 intptr_t size = 0; | 127 intptr_t size = 0; |
| 128 // First create the snapshot. | 128 // First create the snapshot. |
| 129 result = Dart_CreateSnapshot(&buffer, &size); | 129 result = Dart_CreateSnapshot(&buffer, &size); |
| 130 if (!Dart_IsValid(result)) { | 130 if (Dart_IsError(result)) { |
| 131 const char* err_msg = Dart_GetError(result); | 131 const char* err_msg = Dart_GetError(result); |
| 132 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg); | 132 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg); |
| 133 Dart_ExitScope(); | 133 Dart_ExitScope(); |
| 134 exit(255); | 134 exit(255); |
| 135 } | 135 } |
| 136 // Now write the snapshot out to specified file and exit. | 136 // Now write the snapshot out to specified file and exit. |
| 137 WriteSnapshotFile(buffer, size); | 137 WriteSnapshotFile(buffer, size); |
| 138 Dart_ExitScope(); | 138 Dart_ExitScope(); |
| 139 return data; | 139 return data; |
| 140 } | 140 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // and writes out a snapshot. | 175 // and writes out a snapshot. |
| 176 Dart_Isolate isolate = Dart_CreateIsolate(NULL, script_name); | 176 Dart_Isolate isolate = Dart_CreateIsolate(NULL, script_name); |
| 177 if (isolate == NULL) { | 177 if (isolate == NULL) { |
| 178 return 255; | 178 return 255; |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Shutdown the isolate. | 181 // Shutdown the isolate. |
| 182 Dart_ShutdownIsolate(); | 182 Dart_ShutdownIsolate(); |
| 183 return 0; | 183 return 0; |
| 184 } | 184 } |
| OLD | NEW |