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

Side by Side Diff: bin/main.cc

Issue 8437075: - Add the implementation of the Options interface to the runtime. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
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 | « no previous file | lib/lib_impl_sources.gypi » ('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 #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 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // Parse out options to be passed to dart main. 83 // Parse out options to be passed to dart main.
84 while (i < argc) { 84 while (i < argc) {
85 dart_options->AddArgument(argv[i]); 85 dart_options->AddArgument(argv[i]);
86 i += 1; 86 i += 1;
87 } 87 }
88 88
89 return 0; 89 return 0;
90 } 90 }
91 91
92 92
93 static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options) {
94 int options_count = options->count();
95 Dart_Handle dart_arguments = Dart_NewArray(options_count);
96 if (!Dart_IsValid(dart_arguments)) {
97 return dart_arguments;
98 }
99 for (int i = 0; i < options_count; i++) {
100 Dart_Handle argument_value = Dart_NewString(options->GetArgument(i));
101 if (!Dart_IsValid(argument_value)) {
102 return argument_value;
103 }
104 Dart_Handle result = Dart_ArraySetAt(dart_arguments, i, argument_value);
105 if (!Dart_IsValid(result)) {
106 return result;
107 }
108 }
109 Dart_Handle core_lib_url = Dart_NewString("dart:coreimpl");
110 if (!Dart_IsValid(core_lib_url)) {
111 return core_lib_url;
112 }
113 Dart_Handle core_lib = Dart_LookupLibrary(core_lib_url);
114 if (!Dart_IsValid(core_lib)) {
115 return core_lib;
116 }
117 Dart_Handle runtime_options_class_name = Dart_NewString("RuntimeOptions");
118 if (!Dart_IsValid(runtime_options_class_name)) {
119 return runtime_options_class_name;
120 }
121 Dart_Handle runtime_options_class = Dart_GetClass(
122 core_lib, runtime_options_class_name);
123 if (!Dart_IsValid(runtime_options_class)) {
124 return runtime_options_class;
125 }
126 Dart_Handle native_name = Dart_NewString("_nativeArguments");
127 if (!Dart_IsValid(native_name)) {
128 return native_name;
129 }
130
131 return Dart_SetStaticField(runtime_options_class,
132 native_name,
133 dart_arguments);
134 }
135
136
93 static void DumpPprofSymbolInfo() { 137 static void DumpPprofSymbolInfo() {
94 if (generate_pprof_symbols_filename != NULL) { 138 if (generate_pprof_symbols_filename != NULL) {
95 Dart_EnterScope(); 139 Dart_EnterScope();
96 File* pprof_file = File::Open(generate_pprof_symbols_filename, true); 140 File* pprof_file = File::Open(generate_pprof_symbols_filename, true);
97 ASSERT(pprof_file != NULL); 141 ASSERT(pprof_file != NULL);
98 void* buffer; 142 void* buffer;
99 int buffer_size; 143 int buffer_size;
100 Dart_GetPprofSymbolInfo(&buffer, &buffer_size); 144 Dart_GetPprofSymbolInfo(&buffer, &buffer_size);
101 if (buffer_size > 0) { 145 if (buffer_size > 0) {
102 ASSERT(buffer != NULL); 146 ASSERT(buffer != NULL);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 return 255; // Indicates we encountered an error. 236 return 255; // Indicates we encountered an error.
193 } 237 }
194 Dart_Isolate isolate = Dart_CreateIsolate(snapshot_buffer, 238 Dart_Isolate isolate = Dart_CreateIsolate(snapshot_buffer,
195 canonical_script_name); 239 canonical_script_name);
196 if (isolate == NULL) { 240 if (isolate == NULL) {
197 free(canonical_script_name); 241 free(canonical_script_name);
198 return 255; 242 return 255;
199 } 243 }
200 244
201 Dart_EnterScope(); 245 Dart_EnterScope();
202 // TODO(asiva): Create a dart options object that can be accessed from
203 // dart code.
204 if (HasCompileAll(vm_options)) { 246 if (HasCompileAll(vm_options)) {
205 Dart_Handle result = Dart_CompileAll(); 247 Dart_Handle result = Dart_CompileAll();
206 if (!Dart_IsValid(result)) { 248 if (!Dart_IsValid(result)) {
207 fprintf(stderr, "%s\n", Dart_GetError(result)); 249 fprintf(stderr, "%s\n", Dart_GetError(result));
208 Dart_ExitScope(); 250 Dart_ExitScope();
209 Dart_ShutdownIsolate(); 251 Dart_ShutdownIsolate();
210 free(canonical_script_name); 252 free(canonical_script_name);
211 return 255; // Indicates we encountered an error. 253 return 255; // Indicates we encountered an error.
212 } 254 }
213 } 255 }
214 256
257 // Create a dart options object that can be accessed from dart code.
258 Dart_Handle options_result = SetupRuntimeOptions(&dart_options);
259 if (!Dart_IsValid(options_result)) {
260 fprintf(stderr, "%s\n", Dart_GetError(options_result));
261 Dart_ExitScope();
262 Dart_ShutdownIsolate();
263 free(canonical_script_name);
264 return 255; // Indicates we encountered an error.
265 }
266
215 // Lookup and invoke the top level main function. 267 // Lookup and invoke the top level main function.
216 Dart_Handle script_url = Dart_NewString(canonical_script_name); 268 Dart_Handle script_url = Dart_NewString(canonical_script_name);
217 Dart_Handle library = Dart_LookupLibrary(script_url); 269 Dart_Handle library = Dart_LookupLibrary(script_url);
218 if (!Dart_IsValid(library)) { 270 if (!Dart_IsValid(library)) {
219 fprintf(stderr, "%s\n", Dart_GetError(library)); 271 fprintf(stderr, "%s\n", Dart_GetError(library));
220 Dart_ExitScope(); 272 Dart_ExitScope();
221 Dart_ShutdownIsolate(); 273 Dart_ShutdownIsolate();
222 free(canonical_script_name); 274 free(canonical_script_name);
223 return 255; // Indicates we encountered an error. 275 return 255; // Indicates we encountered an error.
224 } 276 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 return 255; // Indicates we encountered an error. 313 return 255; // Indicates we encountered an error.
262 } 314 }
263 free(canonical_script_name); 315 free(canonical_script_name);
264 Dart_ExitScope(); 316 Dart_ExitScope();
265 // Dump symbol information for the profiler. 317 // Dump symbol information for the profiler.
266 DumpPprofSymbolInfo(); 318 DumpPprofSymbolInfo();
267 // Shutdown the isolate. 319 // Shutdown the isolate.
268 Dart_ShutdownIsolate(); 320 Dart_ShutdownIsolate();
269 return 0; 321 return 0;
270 } 322 }
OLDNEW
« no previous file with comments | « no previous file | lib/lib_impl_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698