| 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 "vm/bootstrap.h" | 5 #include "vm/bootstrap.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "vm/bootstrap_natives.h" | 9 #include "vm/bootstrap_natives.h" |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 83 |
| 84 { ObjectStore::kNone, NULL, NULL, NULL, NULL } | 84 { ObjectStore::kNone, NULL, NULL, NULL, NULL } |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 | 87 |
| 88 static RawString* GetLibrarySource(const Library& lib, | 88 static RawString* GetLibrarySource(const Library& lib, |
| 89 const String& uri, | 89 const String& uri, |
| 90 bool patch) { | 90 bool patch) { |
| 91 // First check if this is a valid boot strap library and find it's index | 91 // First check if this is a valid boot strap library and find it's index |
| 92 // in the 'bootstrap_libraries' table above. | 92 // in the 'bootstrap_libraries' table above. |
| 93 intptr_t index = 0; | 93 intptr_t index; |
| 94 const String& lib_uri = String::Handle(lib.url()); | 94 const String& lib_uri = String::Handle(lib.url()); |
| 95 while (bootstrap_libraries[index].index_ != ObjectStore::kNone) { | 95 for (index = 0; |
| 96 bootstrap_libraries[index].index_ != ObjectStore::kNone; |
| 97 ++index) { |
| 96 if (lib_uri.Equals(bootstrap_libraries[index].uri_)) { | 98 if (lib_uri.Equals(bootstrap_libraries[index].uri_)) { |
| 97 break; | 99 break; |
| 98 } | 100 } |
| 99 index += 1; | |
| 100 } | 101 } |
| 101 if (bootstrap_libraries[index].index_ == ObjectStore::kNone) { | 102 if (bootstrap_libraries[index].index_ == ObjectStore::kNone) { |
| 102 return String::null(); // Library is not a boot strap library. | 103 return String::null(); // Library is not a boot strap library. |
| 103 } | 104 } |
| 104 | 105 |
| 105 // Try to read the source using the path specified for the uri. | 106 // Try to read the source using the path specified for the uri. |
| 106 const char** source_paths = patch ? | 107 const char** source_paths = patch ? |
| 107 bootstrap_libraries[index].patch_paths_ : | 108 bootstrap_libraries[index].patch_paths_ : |
| 108 bootstrap_libraries[index].source_paths_; | 109 bootstrap_libraries[index].source_paths_; |
| 109 if (source_paths == NULL) { | 110 if (source_paths == NULL) { |
| 110 return String::null(); // No path mapping information exists for library. | 111 return String::null(); // No path mapping information exists for library. |
| 111 } | 112 } |
| 112 intptr_t i = 0; | |
| 113 const char* source_path = NULL; | 113 const char* source_path = NULL; |
| 114 while (source_paths[i] != NULL) { | 114 for (intptr_t i = 0; source_paths[i] != NULL; i += 2) { |
| 115 if (uri.Equals(source_paths[i])) { | 115 if (uri.Equals(source_paths[i])) { |
| 116 source_path = source_paths[i + 1]; | 116 source_path = source_paths[i + 1]; |
| 117 break; | 117 break; |
| 118 } | 118 } |
| 119 i += 2; | |
| 120 } | 119 } |
| 121 if (source_path == NULL) { | 120 if (source_path == NULL) { |
| 122 return String::null(); // Uri does not exist in path mapping information. | 121 return String::null(); // Uri does not exist in path mapping information. |
| 123 } | 122 } |
| 124 | 123 |
| 125 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); | 124 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); |
| 126 Dart_FileReadCallback file_read = Isolate::file_read_callback(); | 125 Dart_FileReadCallback file_read = Isolate::file_read_callback(); |
| 127 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); | 126 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); |
| 128 if (file_open == NULL || file_read == NULL || file_close == NULL) { | 127 if (file_open == NULL || file_read == NULL || file_close == NULL) { |
| 129 return String::null(); // File operations are not supported. | 128 return String::null(); // File operations are not supported. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 const Library& lib, | 232 const Library& lib, |
| 234 const String& patch_uri, | 233 const String& patch_uri, |
| 235 const char** patch_files) { | 234 const char** patch_files) { |
| 236 String& patch_file_uri = String::Handle(isolate); | 235 String& patch_file_uri = String::Handle(isolate); |
| 237 String& source = String::Handle(isolate); | 236 String& source = String::Handle(isolate); |
| 238 Script& script = Script::Handle(isolate); | 237 Script& script = Script::Handle(isolate); |
| 239 Error& error = Error::Handle(isolate); | 238 Error& error = Error::Handle(isolate); |
| 240 const Array& strings = Array::Handle(isolate, Array::New(3)); | 239 const Array& strings = Array::Handle(isolate, Array::New(3)); |
| 241 strings.SetAt(0, patch_uri); | 240 strings.SetAt(0, patch_uri); |
| 242 strings.SetAt(1, Symbols::Slash()); | 241 strings.SetAt(1, Symbols::Slash()); |
| 243 intptr_t j = 0; | 242 for (intptr_t j = 0; patch_files[j] != NULL; j += 2) { |
| 244 while (patch_files[j] != NULL) { | |
| 245 patch_file_uri = String::New(patch_files[j]); | 243 patch_file_uri = String::New(patch_files[j]); |
| 246 source = GetLibrarySource(lib, patch_file_uri, true); | 244 source = GetLibrarySource(lib, patch_file_uri, true); |
| 247 if (source.IsNull()) { | 245 if (source.IsNull()) { |
| 248 return Api::UnwrapErrorHandle( | 246 return Api::UnwrapErrorHandle( |
| 249 isolate, | 247 isolate, |
| 250 Api::NewError("Unable to find dart patch source for %s", | 248 Api::NewError("Unable to find dart patch source for %s", |
| 251 patch_file_uri.ToCString())).raw(); | 249 patch_file_uri.ToCString())).raw(); |
| 252 } | 250 } |
| 253 // Prepend the patch library URI to form a unique script URI for the patch. | 251 // Prepend the patch library URI to form a unique script URI for the patch. |
| 254 strings.SetAt(2, patch_file_uri); | 252 strings.SetAt(2, patch_file_uri); |
| 255 patch_file_uri = String::ConcatAll(strings); | 253 patch_file_uri = String::ConcatAll(strings); |
| 256 script = Script::New(patch_file_uri, source, RawScript::kPatchTag); | 254 script = Script::New(patch_file_uri, source, RawScript::kPatchTag); |
| 257 error = lib.Patch(script); | 255 error = lib.Patch(script); |
| 258 if (!error.IsNull()) { | 256 if (!error.IsNull()) { |
| 259 return error.raw(); | 257 return error.raw(); |
| 260 } | 258 } |
| 261 j += 2; | |
| 262 } | 259 } |
| 263 return Error::null(); | 260 return Error::null(); |
| 264 } | 261 } |
| 265 | 262 |
| 266 | 263 |
| 267 RawError* Bootstrap::LoadandCompileScripts() { | 264 RawError* Bootstrap::LoadandCompileScripts() { |
| 268 Isolate* isolate = Isolate::Current(); | 265 Isolate* isolate = Isolate::Current(); |
| 269 String& uri = String::Handle(); | 266 String& uri = String::Handle(); |
| 270 String& patch_uri = String::Handle(); | 267 String& patch_uri = String::Handle(); |
| 271 String& source = String::Handle(); | 268 String& source = String::Handle(); |
| 272 Script& script = Script::Handle(); | 269 Script& script = Script::Handle(); |
| 273 Library& lib = Library::Handle(); | 270 Library& lib = Library::Handle(); |
| 274 Error& error = Error::Handle(); | 271 Error& error = Error::Handle(); |
| 275 Dart_LibraryTagHandler saved_tag_handler = isolate->library_tag_handler(); | 272 Dart_LibraryTagHandler saved_tag_handler = isolate->library_tag_handler(); |
| 276 | 273 |
| 277 // Set the library tag handler for the isolate to the bootstrap | 274 // Set the library tag handler for the isolate to the bootstrap |
| 278 // library tag handler so that we can load all the bootstrap libraries. | 275 // library tag handler so that we can load all the bootstrap libraries. |
| 279 isolate->set_library_tag_handler(BootstrapLibraryTagHandler); | 276 isolate->set_library_tag_handler(BootstrapLibraryTagHandler); |
| 280 | 277 |
| 281 // Enter the Dart Scope as we will be calling back into the library | 278 // Enter the Dart Scope as we will be calling back into the library |
| 282 // tag handler when compiling the bootstrap libraries. | 279 // tag handler when compiling the bootstrap libraries. |
| 283 Dart_EnterScope(); | 280 Dart_EnterScope(); |
| 284 | 281 |
| 285 // Create library objects for all the bootstrap libraries. | 282 // Create library objects for all the bootstrap libraries. |
| 286 intptr_t i = 0; | 283 for (intptr_t i = 0; |
| 287 while (bootstrap_libraries[i].index_ != ObjectStore::kNone) { | 284 bootstrap_libraries[i].index_ != ObjectStore::kNone; |
| 285 ++i) { |
| 288 uri = Symbols::New(bootstrap_libraries[i].uri_); | 286 uri = Symbols::New(bootstrap_libraries[i].uri_); |
| 289 lib = Library::LookupLibrary(uri); | 287 lib = Library::LookupLibrary(uri); |
| 290 if (lib.IsNull()) { | 288 if (lib.IsNull()) { |
| 291 lib = Library::NewLibraryHelper(uri, false); | 289 lib = Library::NewLibraryHelper(uri, false); |
| 292 lib.Register(); | 290 lib.Register(); |
| 293 } | 291 } |
| 294 isolate->object_store()->set_bootstrap_library( | 292 isolate->object_store()->set_bootstrap_library( |
| 295 bootstrap_libraries[i].index_, lib); | 293 bootstrap_libraries[i].index_, lib); |
| 296 i = i + 1; | |
| 297 } | 294 } |
| 298 | 295 |
| 299 // Load, compile and patch bootstrap libraries. | 296 // Load, compile and patch bootstrap libraries. |
| 300 i = 0; | 297 for (intptr_t i = 0; |
| 301 while (bootstrap_libraries[i].index_ != ObjectStore::kNone) { | 298 bootstrap_libraries[i].index_ != ObjectStore::kNone; |
| 299 ++i) { |
| 302 uri = Symbols::New(bootstrap_libraries[i].uri_); | 300 uri = Symbols::New(bootstrap_libraries[i].uri_); |
| 303 lib = Library::LookupLibrary(uri); | 301 lib = Library::LookupLibrary(uri); |
| 304 ASSERT(!lib.IsNull()); | 302 ASSERT(!lib.IsNull()); |
| 305 source = GetLibrarySource(lib, uri, false); | 303 source = GetLibrarySource(lib, uri, false); |
| 306 if (source.IsNull()) { | 304 if (source.IsNull()) { |
| 307 error ^= Api::UnwrapErrorHandle( | 305 error ^= Api::UnwrapErrorHandle( |
| 308 isolate, Api::NewError("Unable to find dart source for %s", | 306 isolate, Api::NewError("Unable to find dart source for %s", |
| 309 uri.ToCString())).raw(); | 307 uri.ToCString())).raw(); |
| 310 break; | 308 break; |
| 311 } | 309 } |
| 312 script = Script::New(uri, source, RawScript::kLibraryTag); | 310 script = Script::New(uri, source, RawScript::kLibraryTag); |
| 313 error = Compile(lib, script); | 311 error = Compile(lib, script); |
| 314 if (!error.IsNull()) { | 312 if (!error.IsNull()) { |
| 315 break; | 313 break; |
| 316 } | 314 } |
| 317 // If a patch exists, load and patch the script. | 315 // If a patch exists, load and patch the script. |
| 318 if (bootstrap_libraries[i].patch_paths_ != NULL) { | 316 if (bootstrap_libraries[i].patch_paths_ != NULL) { |
| 319 patch_uri = Symbols::New(bootstrap_libraries[i].patch_uri_); | 317 patch_uri = Symbols::New(bootstrap_libraries[i].patch_uri_); |
| 320 error = LoadPatchFiles(isolate, | 318 error = LoadPatchFiles(isolate, |
| 321 lib, | 319 lib, |
| 322 patch_uri, | 320 patch_uri, |
| 323 bootstrap_libraries[i].patch_paths_); | 321 bootstrap_libraries[i].patch_paths_); |
| 324 if (!error.IsNull()) { | 322 if (!error.IsNull()) { |
| 325 break; | 323 break; |
| 326 } | 324 } |
| 327 } | 325 } |
| 328 i = i + 1; | |
| 329 } | 326 } |
| 330 if (error.IsNull()) { | 327 if (error.IsNull()) { |
| 331 SetupNativeResolver(); | 328 SetupNativeResolver(); |
| 332 } | 329 } |
| 333 | 330 |
| 334 // Exit the Dart scope. | 331 // Exit the Dart scope. |
| 335 Dart_ExitScope(); | 332 Dart_ExitScope(); |
| 336 | 333 |
| 337 // Restore the library tag handler for the isolate. | 334 // Restore the library tag handler for the isolate. |
| 338 isolate->set_library_tag_handler(saved_tag_handler); | 335 isolate->set_library_tag_handler(saved_tag_handler); |
| 339 | 336 |
| 340 return error.raw(); | 337 return error.raw(); |
| 341 } | 338 } |
| 342 | 339 |
| 343 } // namespace dart | 340 } // namespace dart |
| OLD | NEW |