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::InitNativeFieldsLibrary(isolate); |
| 572 ASSERT(isolate->object_store()->native_fields_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 3516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4095 const Library& core_impl_lib = | 4100 const Library& core_impl_lib = |
4096 Library::Handle(Library::NewLibraryHelper(core_impl_lib_url, false)); | 4101 Library::Handle(Library::NewLibraryHelper(core_impl_lib_url, false)); |
4097 isolate->object_store()->set_core_impl_library(core_impl_lib); | 4102 isolate->object_store()->set_core_impl_library(core_impl_lib); |
4098 core_impl_lib.Register(); | 4103 core_impl_lib.Register(); |
4099 core_lib.AddImport(core_impl_lib); | 4104 core_lib.AddImport(core_impl_lib); |
4100 core_impl_lib.AddImport(core_lib); | 4105 core_impl_lib.AddImport(core_lib); |
4101 isolate->object_store()->set_root_library(Library::Handle()); | 4106 isolate->object_store()->set_root_library(Library::Handle()); |
4102 } | 4107 } |
4103 | 4108 |
4104 | 4109 |
| 4110 void Library::InitNativeFieldsLibrary(Isolate* isolate) { |
| 4111 static const int kNumNativeFieldClasses = 4; |
| 4112 ASSERT(kNumNativeFieldClasses > 0 && kNumNativeFieldClasses < 10); |
| 4113 const String& native_flds_lib_url = String::Handle( |
| 4114 String::NewSymbol("dart:core-native-fields")); |
| 4115 Library& native_flds_lib = Library::Handle( |
| 4116 Library::NewLibraryHelper(native_flds_lib_url, false)); |
| 4117 native_flds_lib.Register(); |
| 4118 isolate->object_store()->set_native_fields_library(native_flds_lib); |
| 4119 static const char* const kNativeFieldClass = "NativeFieldWrapperClass"; |
| 4120 static const int kNameLength = strlen(kNativeFieldClass) + 1 + 1; |
| 4121 char name_buffer[kNameLength]; |
| 4122 String& cls_name = String::Handle(); |
| 4123 for (int fld_cnt = 1; fld_cnt <= kNumNativeFieldClasses; fld_cnt++) { |
| 4124 OS::SNPrint(name_buffer, kNameLength, "%s%d", kNativeFieldClass, fld_cnt); |
| 4125 cls_name = String::NewSymbol(name_buffer); |
| 4126 Class::NewNativeWrapper(&native_flds_lib, cls_name, fld_cnt); |
| 4127 } |
| 4128 } |
| 4129 |
| 4130 |
4105 RawLibrary* Library::LookupLibrary(const String &url) { | 4131 RawLibrary* Library::LookupLibrary(const String &url) { |
4106 Library& lib = Library::Handle(); | 4132 Library& lib = Library::Handle(); |
4107 String& lib_url = String::Handle(); | 4133 String& lib_url = String::Handle(); |
4108 lib = Isolate::Current()->object_store()->registered_libraries(); | 4134 lib = Isolate::Current()->object_store()->registered_libraries(); |
4109 while (!lib.IsNull()) { | 4135 while (!lib.IsNull()) { |
4110 lib_url = lib.url(); | 4136 lib_url = lib.url(); |
4111 if (lib_url.Equals(url)) { | 4137 if (lib_url.Equals(url)) { |
4112 return lib.raw(); | 4138 return lib.raw(); |
4113 } | 4139 } |
4114 lib = lib.next_registered(); | 4140 lib = lib.next_registered(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4165 RawLibrary* Library::CoreLibrary() { | 4191 RawLibrary* Library::CoreLibrary() { |
4166 return Isolate::Current()->object_store()->core_library(); | 4192 return Isolate::Current()->object_store()->core_library(); |
4167 } | 4193 } |
4168 | 4194 |
4169 | 4195 |
4170 RawLibrary* Library::CoreImplLibrary() { | 4196 RawLibrary* Library::CoreImplLibrary() { |
4171 return Isolate::Current()->object_store()->core_impl_library(); | 4197 return Isolate::Current()->object_store()->core_impl_library(); |
4172 } | 4198 } |
4173 | 4199 |
4174 | 4200 |
| 4201 RawLibrary* Library::NativeFieldsLibrary() { |
| 4202 return Isolate::Current()->object_store()->native_fields_library(); |
| 4203 } |
| 4204 |
| 4205 |
4175 const char* Library::ToCString() const { | 4206 const char* Library::ToCString() const { |
4176 const char* kFormat = "Library:'%s'"; | 4207 const char* kFormat = "Library:'%s'"; |
4177 const String& name = String::Handle(url()); | 4208 const String& name = String::Handle(url()); |
4178 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; | 4209 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; |
4179 char* chars = reinterpret_cast<char*>( | 4210 char* chars = reinterpret_cast<char*>( |
4180 Isolate::Current()->current_zone()->Allocate(len)); | 4211 Isolate::Current()->current_zone()->Allocate(len)); |
4181 OS::SNPrint(chars, len, kFormat, name.ToCString()); | 4212 OS::SNPrint(chars, len, kFormat, name.ToCString()); |
4182 return chars; | 4213 return chars; |
4183 } | 4214 } |
4184 | 4215 |
(...skipping 2810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6995 const String& str = String::Handle(pattern()); | 7026 const String& str = String::Handle(pattern()); |
6996 const char* format = "JSRegExp: pattern=%s flags=%s"; | 7027 const char* format = "JSRegExp: pattern=%s flags=%s"; |
6997 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 7028 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
6998 char* chars = reinterpret_cast<char*>( | 7029 char* chars = reinterpret_cast<char*>( |
6999 Isolate::Current()->current_zone()->Allocate(len + 1)); | 7030 Isolate::Current()->current_zone()->Allocate(len + 1)); |
7000 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 7031 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
7001 return chars; | 7032 return chars; |
7002 } | 7033 } |
7003 | 7034 |
7004 } // namespace dart | 7035 } // namespace dart |
OLD | NEW |