| 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 #include "vm/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 // Add the preallocated classes to the list of classes to be finalized. | 566 // Add the preallocated classes to the list of classes to be finalized. |
| 567 ClassFinalizer::AddPendingClasses(pending_classes); | 567 ClassFinalizer::AddPendingClasses(pending_classes); |
| 568 | 568 |
| 569 // Allocate pre-initialized values. | 569 // Allocate pre-initialized values. |
| 570 Bool& bool_value = Bool::Handle(); | 570 Bool& bool_value = Bool::Handle(); |
| 571 bool_value = Bool::New(true); | 571 bool_value = Bool::New(true); |
| 572 object_store->set_true_value(bool_value); | 572 object_store->set_true_value(bool_value); |
| 573 bool_value = Bool::New(false); | 573 bool_value = Bool::New(false); |
| 574 object_store->set_false_value(bool_value); | 574 object_store->set_false_value(bool_value); |
| 575 | 575 |
| 576 // Setup some default native field classes which can be extended for |
| 577 // specifying native fields in dart classes. |
| 578 Library::InitNativeWrappersLibrary(isolate); |
| 579 ASSERT(isolate->object_store()->native_wrappers_library() != Library::null()); |
| 580 |
| 576 // Finish the initialization by compiling the bootstrap scripts containing the | 581 // Finish the initialization by compiling the bootstrap scripts containing the |
| 577 // base interfaces and the implementation of the internal classes. | 582 // base interfaces and the implementation of the internal classes. |
| 578 Bootstrap::Compile(core_lib, script); | 583 Bootstrap::Compile(core_lib, script); |
| 579 Bootstrap::Compile(core_impl_lib, impl_script); | 584 Bootstrap::Compile(core_impl_lib, impl_script); |
| 580 | 585 |
| 581 Bootstrap::SetupNativeResolver(); | 586 Bootstrap::SetupNativeResolver(); |
| 582 | 587 |
| 583 // Remove the Object superclass cycle by setting the super type to null (not | 588 // Remove the Object superclass cycle by setting the super type to null (not |
| 584 // to the type of null). | 589 // to the type of null). |
| 585 cls = object_store->object_class(); | 590 cls = object_store->object_class(); |
| (...skipping 3550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4136 const Library& core_impl_lib = | 4141 const Library& core_impl_lib = |
| 4137 Library::Handle(Library::NewLibraryHelper(core_impl_lib_url, false)); | 4142 Library::Handle(Library::NewLibraryHelper(core_impl_lib_url, false)); |
| 4138 isolate->object_store()->set_core_impl_library(core_impl_lib); | 4143 isolate->object_store()->set_core_impl_library(core_impl_lib); |
| 4139 core_impl_lib.Register(); | 4144 core_impl_lib.Register(); |
| 4140 core_lib.AddImport(core_impl_lib); | 4145 core_lib.AddImport(core_impl_lib); |
| 4141 core_impl_lib.AddImport(core_lib); | 4146 core_impl_lib.AddImport(core_lib); |
| 4142 isolate->object_store()->set_root_library(Library::Handle()); | 4147 isolate->object_store()->set_root_library(Library::Handle()); |
| 4143 } | 4148 } |
| 4144 | 4149 |
| 4145 | 4150 |
| 4151 void Library::InitNativeWrappersLibrary(Isolate* isolate) { |
| 4152 static const int kNumNativeWrappersClasses = 4; |
| 4153 ASSERT(kNumNativeWrappersClasses > 0 && kNumNativeWrappersClasses < 10); |
| 4154 const String& native_flds_lib_url = String::Handle( |
| 4155 String::NewSymbol("dart:nativewrappers")); |
| 4156 Library& native_flds_lib = Library::Handle( |
| 4157 Library::NewLibraryHelper(native_flds_lib_url, false)); |
| 4158 native_flds_lib.Register(); |
| 4159 isolate->object_store()->set_native_wrappers_library(native_flds_lib); |
| 4160 static const char* const kNativeWrappersClass = "NativeFieldWrapperClass"; |
| 4161 static const int kNameLength = 25; |
| 4162 ASSERT(kNameLength == (strlen(kNativeWrappersClass) + 1 + 1)); |
| 4163 char name_buffer[kNameLength]; |
| 4164 String& cls_name = String::Handle(); |
| 4165 for (int fld_cnt = 1; fld_cnt <= kNumNativeWrappersClasses; fld_cnt++) { |
| 4166 OS::SNPrint(name_buffer, |
| 4167 kNameLength, |
| 4168 "%s%d", |
| 4169 kNativeWrappersClass, |
| 4170 fld_cnt); |
| 4171 cls_name = String::NewSymbol(name_buffer); |
| 4172 Class::NewNativeWrapper(&native_flds_lib, cls_name, fld_cnt); |
| 4173 } |
| 4174 } |
| 4175 |
| 4176 |
| 4146 RawLibrary* Library::LookupLibrary(const String &url) { | 4177 RawLibrary* Library::LookupLibrary(const String &url) { |
| 4147 Library& lib = Library::Handle(); | 4178 Library& lib = Library::Handle(); |
| 4148 String& lib_url = String::Handle(); | 4179 String& lib_url = String::Handle(); |
| 4149 lib = Isolate::Current()->object_store()->registered_libraries(); | 4180 lib = Isolate::Current()->object_store()->registered_libraries(); |
| 4150 while (!lib.IsNull()) { | 4181 while (!lib.IsNull()) { |
| 4151 lib_url = lib.url(); | 4182 lib_url = lib.url(); |
| 4152 if (lib_url.Equals(url)) { | 4183 if (lib_url.Equals(url)) { |
| 4153 return lib.raw(); | 4184 return lib.raw(); |
| 4154 } | 4185 } |
| 4155 lib = lib.next_registered(); | 4186 lib = lib.next_registered(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4206 RawLibrary* Library::CoreLibrary() { | 4237 RawLibrary* Library::CoreLibrary() { |
| 4207 return Isolate::Current()->object_store()->core_library(); | 4238 return Isolate::Current()->object_store()->core_library(); |
| 4208 } | 4239 } |
| 4209 | 4240 |
| 4210 | 4241 |
| 4211 RawLibrary* Library::CoreImplLibrary() { | 4242 RawLibrary* Library::CoreImplLibrary() { |
| 4212 return Isolate::Current()->object_store()->core_impl_library(); | 4243 return Isolate::Current()->object_store()->core_impl_library(); |
| 4213 } | 4244 } |
| 4214 | 4245 |
| 4215 | 4246 |
| 4247 RawLibrary* Library::NativeWrappersLibrary() { |
| 4248 return Isolate::Current()->object_store()->native_wrappers_library(); |
| 4249 } |
| 4250 |
| 4251 |
| 4216 const char* Library::ToCString() const { | 4252 const char* Library::ToCString() const { |
| 4217 const char* kFormat = "Library:'%s'"; | 4253 const char* kFormat = "Library:'%s'"; |
| 4218 const String& name = String::Handle(url()); | 4254 const String& name = String::Handle(url()); |
| 4219 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; | 4255 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; |
| 4220 char* chars = reinterpret_cast<char*>( | 4256 char* chars = reinterpret_cast<char*>( |
| 4221 Isolate::Current()->current_zone()->Allocate(len)); | 4257 Isolate::Current()->current_zone()->Allocate(len)); |
| 4222 OS::SNPrint(chars, len, kFormat, name.ToCString()); | 4258 OS::SNPrint(chars, len, kFormat, name.ToCString()); |
| 4223 return chars; | 4259 return chars; |
| 4224 } | 4260 } |
| 4225 | 4261 |
| (...skipping 2862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7088 const String& str = String::Handle(pattern()); | 7124 const String& str = String::Handle(pattern()); |
| 7089 const char* format = "JSRegExp: pattern=%s flags=%s"; | 7125 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 7090 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 7126 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 7091 char* chars = reinterpret_cast<char*>( | 7127 char* chars = reinterpret_cast<char*>( |
| 7092 Isolate::Current()->current_zone()->Allocate(len + 1)); | 7128 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 7093 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 7129 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 7094 return chars; | 7130 return chars; |
| 7095 } | 7131 } |
| 7096 | 7132 |
| 7097 } // namespace dart | 7133 } // namespace dart |
| OLD | NEW |