Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: runtime/bin/gen_snapshot.cc

Issue 8380020: Refactor the dart api a bit: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/file.cc ('k') | runtime/bin/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 ASSERT(file != NULL); 85 ASSERT(file != NULL);
86 for (intptr_t i = 0; i < size; i++) { 86 for (intptr_t i = 0; i < size; i++) {
87 file->WriteByte(buffer[i]); 87 file->WriteByte(buffer[i]);
88 } 88 }
89 delete file; 89 delete file;
90 } 90 }
91 91
92 92
93 static void* SnapshotCreateCallback(void* data) { 93 static void* SnapshotCreateCallback(void* data) {
94 const char* script_name = reinterpret_cast<const char*>(data); 94 const char* script_name = reinterpret_cast<const char*>(data);
95 Dart_Result 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 result = LoadScript(script_name); 104 Dart_Handle library = LoadScript(script_name);
105 if (!Dart_IsValidResult(result)) { 105 if (!Dart_IsValid(library)) {
106 const char* err_msg = Dart_GetErrorCString(result); 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 Dart_Handle library = Dart_GetResult(result);
113 if (!Dart_IsLibrary(library)) { 112 if (!Dart_IsLibrary(library)) {
114 fprintf(stderr, 113 fprintf(stderr,
115 "Expected a library when loading script: %s", 114 "Expected a library when loading script: %s",
116 script_name); 115 script_name);
117 Dart_ExitScope(); 116 Dart_ExitScope();
118 exit(255); 117 exit(255);
119 } 118 }
120 Builtin_ImportLibrary(library); 119 Builtin_ImportLibrary(library);
121 } else { 120 } else {
122 Builtin_LoadLibrary(); 121 Builtin_LoadLibrary();
123 } 122 }
124 // Setup the native resolver for built in library functions. 123 // Setup the native resolver for built in library functions.
125 Builtin_SetNativeResolver(); 124 Builtin_SetNativeResolver();
126 125
127 uint8_t* buffer = NULL; 126 uint8_t* buffer = NULL;
128 intptr_t size = 0; 127 intptr_t size = 0;
129 // First create the snapshot. 128 // First create the snapshot.
130 result = Dart_CreateSnapshot(&buffer, &size); 129 result = Dart_CreateSnapshot(&buffer, &size);
131 if (!Dart_IsValidResult(result)) { 130 if (!Dart_IsValid(result)) {
132 const char* err_msg = Dart_GetErrorCString(result); 131 const char* err_msg = Dart_GetError(result);
133 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg); 132 fprintf(stderr, "Error while creating snapshot: %s\n", err_msg);
134 Dart_ExitScope(); 133 Dart_ExitScope();
135 exit(255); 134 exit(255);
136 } 135 }
137 // Now write the snapshot out to specified file and exit. 136 // Now write the snapshot out to specified file and exit.
138 WriteSnapshotFile(buffer, size); 137 WriteSnapshotFile(buffer, size);
139 Dart_ExitScope(); 138 Dart_ExitScope();
140 return data; 139 return data;
141 } 140 }
142 141
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // and writes out a snapshot. 175 // and writes out a snapshot.
177 Dart_Isolate isolate = Dart_CreateIsolate(NULL, script_name); 176 Dart_Isolate isolate = Dart_CreateIsolate(NULL, script_name);
178 if (isolate == NULL) { 177 if (isolate == NULL) {
179 return 255; 178 return 255;
180 } 179 }
181 180
182 // Shutdown the isolate. 181 // Shutdown the isolate.
183 Dart_ShutdownIsolate(); 182 Dart_ShutdownIsolate();
184 return 0; 183 return 0;
185 } 184 }
OLDNEW
« no previous file with comments | « runtime/bin/file.cc ('k') | runtime/bin/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698