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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 // Add the preallocated classes to the list of classes to be finalized. | 559 // Add the preallocated classes to the list of classes to be finalized. |
560 ClassFinalizer::AddPendingClasses(pending_classes); | 560 ClassFinalizer::AddPendingClasses(pending_classes); |
561 | 561 |
562 // Allocate pre-initialized values. | 562 // Allocate pre-initialized values. |
563 Bool& bool_value = Bool::Handle(); | 563 Bool& bool_value = Bool::Handle(); |
564 bool_value = Bool::New(true); | 564 bool_value = Bool::New(true); |
565 object_store->set_true_value(bool_value); | 565 object_store->set_true_value(bool_value); |
566 bool_value = Bool::New(false); | 566 bool_value = Bool::New(false); |
567 object_store->set_false_value(bool_value); | 567 object_store->set_false_value(bool_value); |
568 | 568 |
| 569 // Setup some default native field classes which can be extended for |
| 570 // specifying native fields in dart classes. |
| 571 Library::InitNativeWrappersLibrary(isolate); |
| 572 ASSERT(isolate->object_store()->native_wrappers_library() != Library::null()); |
| 573 |
569 // Finish the initialization by compiling the bootstrap scripts containing the | 574 // Finish the initialization by compiling the bootstrap scripts containing the |
570 // base interfaces and the implementation of the internal classes. | 575 // base interfaces and the implementation of the internal classes. |
571 Bootstrap::Compile(core_lib, script); | 576 Bootstrap::Compile(core_lib, script); |
572 Bootstrap::Compile(core_impl_lib, impl_script); | 577 Bootstrap::Compile(core_impl_lib, impl_script); |
573 | 578 |
574 Bootstrap::SetupNativeResolver(); | 579 Bootstrap::SetupNativeResolver(); |
575 | 580 |
576 // Remove the Object superclass cycle by setting the super type to null (not | 581 // Remove the Object superclass cycle by setting the super type to null (not |
577 // to the type of null). | 582 // to the type of null). |
578 cls = object_store->object_class(); | 583 cls = object_store->object_class(); |
(...skipping 3544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4123 const Library& core_impl_lib = | 4128 const Library& core_impl_lib = |
4124 Library::Handle(Library::NewLibraryHelper(core_impl_lib_url, false)); | 4129 Library::Handle(Library::NewLibraryHelper(core_impl_lib_url, false)); |
4125 isolate->object_store()->set_core_impl_library(core_impl_lib); | 4130 isolate->object_store()->set_core_impl_library(core_impl_lib); |
4126 core_impl_lib.Register(); | 4131 core_impl_lib.Register(); |
4127 core_lib.AddImport(core_impl_lib); | 4132 core_lib.AddImport(core_impl_lib); |
4128 core_impl_lib.AddImport(core_lib); | 4133 core_impl_lib.AddImport(core_lib); |
4129 isolate->object_store()->set_root_library(Library::Handle()); | 4134 isolate->object_store()->set_root_library(Library::Handle()); |
4130 } | 4135 } |
4131 | 4136 |
4132 | 4137 |
| 4138 void Library::InitNativeWrappersLibrary(Isolate* isolate) { |
| 4139 static const int kNumNativeWrappersClasses = 4; |
| 4140 ASSERT(kNumNativeWrappersClasses > 0 && kNumNativeWrappersClasses < 10); |
| 4141 const String& native_flds_lib_url = String::Handle( |
| 4142 String::NewSymbol("dart:nativewrappers")); |
| 4143 Library& native_flds_lib = Library::Handle( |
| 4144 Library::NewLibraryHelper(native_flds_lib_url, false)); |
| 4145 native_flds_lib.Register(); |
| 4146 isolate->object_store()->set_native_wrappers_library(native_flds_lib); |
| 4147 static const char* const kNativeWrappersClass = "NativeFieldWrapperClass"; |
| 4148 static const int kNameLength = 25; |
| 4149 ASSERT(kNameLength == (strlen(kNativeWrappersClass) + 1 + 1)); |
| 4150 char name_buffer[kNameLength]; |
| 4151 String& cls_name = String::Handle(); |
| 4152 for (int fld_cnt = 1; fld_cnt <= kNumNativeWrappersClasses; fld_cnt++) { |
| 4153 OS::SNPrint(name_buffer, |
| 4154 kNameLength, |
| 4155 "%s%d", |
| 4156 kNativeWrappersClass, |
| 4157 fld_cnt); |
| 4158 cls_name = String::NewSymbol(name_buffer); |
| 4159 Class::NewNativeWrapper(&native_flds_lib, cls_name, fld_cnt); |
| 4160 } |
| 4161 } |
| 4162 |
| 4163 |
4133 RawLibrary* Library::LookupLibrary(const String &url) { | 4164 RawLibrary* Library::LookupLibrary(const String &url) { |
4134 Library& lib = Library::Handle(); | 4165 Library& lib = Library::Handle(); |
4135 String& lib_url = String::Handle(); | 4166 String& lib_url = String::Handle(); |
4136 lib = Isolate::Current()->object_store()->registered_libraries(); | 4167 lib = Isolate::Current()->object_store()->registered_libraries(); |
4137 while (!lib.IsNull()) { | 4168 while (!lib.IsNull()) { |
4138 lib_url = lib.url(); | 4169 lib_url = lib.url(); |
4139 if (lib_url.Equals(url)) { | 4170 if (lib_url.Equals(url)) { |
4140 return lib.raw(); | 4171 return lib.raw(); |
4141 } | 4172 } |
4142 lib = lib.next_registered(); | 4173 lib = lib.next_registered(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4193 RawLibrary* Library::CoreLibrary() { | 4224 RawLibrary* Library::CoreLibrary() { |
4194 return Isolate::Current()->object_store()->core_library(); | 4225 return Isolate::Current()->object_store()->core_library(); |
4195 } | 4226 } |
4196 | 4227 |
4197 | 4228 |
4198 RawLibrary* Library::CoreImplLibrary() { | 4229 RawLibrary* Library::CoreImplLibrary() { |
4199 return Isolate::Current()->object_store()->core_impl_library(); | 4230 return Isolate::Current()->object_store()->core_impl_library(); |
4200 } | 4231 } |
4201 | 4232 |
4202 | 4233 |
| 4234 RawLibrary* Library::NativeWrappersLibrary() { |
| 4235 return Isolate::Current()->object_store()->native_wrappers_library(); |
| 4236 } |
| 4237 |
| 4238 |
4203 const char* Library::ToCString() const { | 4239 const char* Library::ToCString() const { |
4204 const char* kFormat = "Library:'%s'"; | 4240 const char* kFormat = "Library:'%s'"; |
4205 const String& name = String::Handle(url()); | 4241 const String& name = String::Handle(url()); |
4206 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; | 4242 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; |
4207 char* chars = reinterpret_cast<char*>( | 4243 char* chars = reinterpret_cast<char*>( |
4208 Isolate::Current()->current_zone()->Allocate(len)); | 4244 Isolate::Current()->current_zone()->Allocate(len)); |
4209 OS::SNPrint(chars, len, kFormat, name.ToCString()); | 4245 OS::SNPrint(chars, len, kFormat, name.ToCString()); |
4210 return chars; | 4246 return chars; |
4211 } | 4247 } |
4212 | 4248 |
(...skipping 2815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7028 const String& str = String::Handle(pattern()); | 7064 const String& str = String::Handle(pattern()); |
7029 const char* format = "JSRegExp: pattern=%s flags=%s"; | 7065 const char* format = "JSRegExp: pattern=%s flags=%s"; |
7030 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 7066 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
7031 char* chars = reinterpret_cast<char*>( | 7067 char* chars = reinterpret_cast<char*>( |
7032 Isolate::Current()->current_zone()->Allocate(len + 1)); | 7068 Isolate::Current()->current_zone()->Allocate(len + 1)); |
7033 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 7069 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
7034 return chars; | 7070 return chars; |
7035 } | 7071 } |
7036 | 7072 |
7037 } // namespace dart | 7073 } // namespace dart |
OLD | NEW |