| Index: runtime/vm/bootstrap_nocore.cc
|
| diff --git a/runtime/vm/bootstrap_nocore.cc b/runtime/vm/bootstrap_nocore.cc
|
| index d2aa1e3c2fb704f3f1da4521d511dbfb35ac96d2..aa60e06031a4f55009c3884b62919895fcc2dc2a 100644
|
| --- a/runtime/vm/bootstrap_nocore.cc
|
| +++ b/runtime/vm/bootstrap_nocore.cc
|
| @@ -6,14 +6,122 @@
|
|
|
| #include "include/dart_api.h"
|
|
|
| +#include "vm/class_finalizer.h"
|
| +#include "vm/compiler.h"
|
| +#include "vm/kernel_reader.h"
|
| #include "vm/object.h"
|
| +#include "vm/object_store.h"
|
|
|
| namespace dart {
|
|
|
| +#define MAKE_PROPERTIES(CamelName, hacker_name) \
|
| + { ObjectStore::k##CamelName, "dart:" #hacker_name },
|
|
|
| -RawError* Bootstrap::LoadandCompileScripts() {
|
| - UNREACHABLE();
|
| +
|
| +struct bootstrap_lib_props {
|
| + ObjectStore::BootstrapLibraryId index_;
|
| + const char* uri_;
|
| +};
|
| +
|
| +
|
| +static bootstrap_lib_props bootstrap_libraries[] = {
|
| + FOR_EACH_BOOTSTRAP_LIBRARY(MAKE_PROPERTIES)
|
| +};
|
| +
|
| +
|
| +static const intptr_t bootstrap_library_count = ARRAY_SIZE(bootstrap_libraries);
|
| +
|
| +
|
| +void Finish(Thread* thread, bool from_kernel) {
|
| + Bootstrap::SetupNativeResolver();
|
| + ClassFinalizer::ProcessPendingClasses(from_kernel);
|
| +
|
| + // Eagerly compile the _Closure class as it is the class of all closure
|
| + // instances. This allows us to just finalize function types without going
|
| + // through the hoops of trying to compile their scope class.
|
| + ObjectStore* object_store = thread->isolate()->object_store();
|
| + Class& cls = Class::Handle(thread->zone(), object_store->closure_class());
|
| + Compiler::CompileClass(cls);
|
| + // Eagerly compile Bool class, bool constants are used from within compiler.
|
| + cls = object_store->bool_class();
|
| + Compiler::CompileClass(cls);
|
| +}
|
| +
|
| +
|
| +RawError* BootstrapFromKernel(Thread* thread,
|
| + const uint8_t* buffer,
|
| + intptr_t buffer_length) {
|
| + Zone* zone = thread->zone();
|
| + kernel::Program* program =
|
| + ReadPrecompiledKernelFromBuffer(buffer, buffer_length);
|
| + if (program == NULL) {
|
| + const String& message =
|
| + String::Handle(zone, String::New("Failed to read Kernel file"));
|
| + return ApiError::New(message);
|
| + }
|
| +
|
| + Isolate* isolate = thread->isolate();
|
| + // Mark the already-pending classes. This mark bit will be used to avoid
|
| + // adding classes to the list more than once.
|
| + GrowableObjectArray& pending_classes = GrowableObjectArray::Handle(
|
| + zone, isolate->object_store()->pending_classes());
|
| + dart::Class& pending = dart::Class::Handle(zone);
|
| + for (intptr_t i = 0; i < pending_classes.Length(); ++i) {
|
| + pending ^= pending_classes.At(i);
|
| + pending.set_is_marked_for_parsing();
|
| + }
|
| +
|
| + Library& library = Library::Handle(zone);
|
| + String& dart_name = String::Handle(zone);
|
| + String& kernel_name = String::Handle(zone);
|
| + kernel::KernelReader reader(NULL, -1, true);
|
| + for (intptr_t i = 0; i < bootstrap_library_count; ++i) {
|
| + ObjectStore::BootstrapLibraryId id = bootstrap_libraries[i].index_;
|
| + library = isolate->object_store()->bootstrap_library(id);
|
| + dart_name = library.url();
|
| + for (intptr_t j = 0; j < program->libraries().length(); ++j) {
|
| + kernel::Library* kernel_library = program->libraries()[j];
|
| + kernel::String* uri = kernel_library->import_uri();
|
| + kernel_name = Symbols::FromUTF8(thread, uri->buffer(), uri->size());
|
| + if (kernel_name.Equals(dart_name)) {
|
| + reader.ReadLibrary(kernel_library);
|
| + library.SetLoaded();
|
| + break;
|
| + }
|
| + }
|
| + }
|
| +
|
| + Finish(thread, true);
|
| return Error::null();
|
| }
|
|
|
| +
|
| +RawError* Bootstrap::DoBootstrapping(const uint8_t* kernel_buffer,
|
| + intptr_t kernel_buffer_length) {
|
| + Thread* thread = Thread::Current();
|
| + Isolate* isolate = thread->isolate();
|
| + Zone* zone = thread->zone();
|
| + String& uri = String::Handle(zone);
|
| + Library& lib = Library::Handle(zone);
|
| +
|
| + HANDLESCOPE(thread);
|
| +
|
| + // Ensure there are library objects for all the bootstrap libraries.
|
| + for (intptr_t i = 0; i < bootstrap_library_count; ++i) {
|
| + ObjectStore::BootstrapLibraryId id = bootstrap_libraries[i].index_;
|
| + uri = Symbols::New(thread, bootstrap_libraries[i].uri_);
|
| + lib = isolate->object_store()->bootstrap_library(id);
|
| + ASSERT(lib.raw() == Library::LookupLibrary(thread, uri));
|
| + if (lib.IsNull()) {
|
| + lib = Library::NewLibraryHelper(uri, false);
|
| + lib.SetLoadRequested();
|
| + lib.Register(thread);
|
| + isolate->object_store()->set_bootstrap_library(id, lib);
|
| + }
|
| + }
|
| +
|
| + ASSERT(kernel_buffer != NULL);
|
| + return BootstrapFromKernel(thread, kernel_buffer, kernel_buffer_length);
|
| +}
|
| +
|
| } // namespace dart
|
|
|