| 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/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 | 421 |
| 422 ASSERT(class_class() != null_); | 422 ASSERT(class_class() != null_); |
| 423 | 423 |
| 424 // Pre-allocate the Array and OneByteString class in the vm isolate so that | 424 // Pre-allocate the Array and OneByteString class in the vm isolate so that |
| 425 // we can create a symbol table and populate it with some frequently used | 425 // we can create a symbol table and populate it with some frequently used |
| 426 // strings as symbols. | 426 // strings as symbols. |
| 427 cls = Class::New<Array>(); | 427 cls = Class::New<Array>(); |
| 428 isolate->object_store()->set_array_class(cls); | 428 isolate->object_store()->set_array_class(cls); |
| 429 cls = Class::New<OneByteString>(); | 429 cls = Class::New<OneByteString>(); |
| 430 isolate->object_store()->set_one_byte_string_class(cls); | 430 isolate->object_store()->set_one_byte_string_class(cls); |
| 431 |
| 432 // TODO(asiva): Assign the names of shared classes instead of relying on the |
| 433 // lookup switch in Object::GetSingletonClassName. |
| 431 } | 434 } |
| 432 | 435 |
| 433 | 436 |
| 434 RawClass* Object::CreateAndRegisterInterface(const char* cname, | 437 RawClass* Object::CreateAndRegisterInterface(const char* cname, |
| 435 const Script& script, | 438 const Script& script, |
| 436 const Library& lib) { | 439 const Library& lib) { |
| 437 const String& name = String::Handle(Symbols::New(cname)); | 440 const String& name = String::Handle(Symbols::New(cname)); |
| 438 const Class& cls = Class::Handle( | 441 const Class& cls = Class::Handle( |
| 439 Class::NewInterface(name, script, Scanner::kDummyTokenIndex)); | 442 Class::NewInterface(name, script, Scanner::kDummyTokenIndex)); |
| 440 lib.AddClass(cls); | 443 lib.AddClass(cls); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 | 761 |
| 759 cls = CreateAndRegisterInterface("ByteArray", script, core_lib); | 762 cls = CreateAndRegisterInterface("ByteArray", script, core_lib); |
| 760 pending_classes.Add(cls, Heap::kOld); | 763 pending_classes.Add(cls, Heap::kOld); |
| 761 type = Type::NewNonParameterizedType(cls); | 764 type = Type::NewNonParameterizedType(cls); |
| 762 object_store->set_byte_array_interface(type); | 765 object_store->set_byte_array_interface(type); |
| 763 | 766 |
| 764 // The classes 'Null' and 'void' are not registered in the class dictionary, | 767 // The classes 'Null' and 'void' are not registered in the class dictionary, |
| 765 // because their names are reserved keywords. Their names are not heap | 768 // because their names are reserved keywords. Their names are not heap |
| 766 // allocated, because the classes reside in the VM isolate. | 769 // allocated, because the classes reside in the VM isolate. |
| 767 // The corresponding types are stored in the object store. | 770 // The corresponding types are stored in the object store. |
| 768 cls = null_class_; | 771 cls = null_class(); |
| 769 type = Type::NewNonParameterizedType(cls); | 772 type = Type::NewNonParameterizedType(cls); |
| 770 object_store->set_null_type(type); | 773 object_store->set_null_type(type); |
| 771 | 774 |
| 772 cls = void_class_; | 775 cls = void_class(); |
| 773 type = Type::NewNonParameterizedType(cls); | 776 type = Type::NewNonParameterizedType(cls); |
| 774 object_store->set_void_type(type); | 777 object_store->set_void_type(type); |
| 775 | 778 |
| 776 // The class 'Dynamic' is registered in the class dictionary because its name | 779 // The class 'Dynamic' is registered in the class dictionary because its name |
| 777 // is a built-in identifier, rather than a reserved keyword. Its name is not | 780 // is a built-in identifier, rather than a reserved keyword. Its name is not |
| 778 // heap allocated, because the class resides in the VM isolate. | 781 // heap allocated, because the class resides in the VM isolate. |
| 779 // The corresponding type, the "unknown type", is stored in the object store. | 782 // The corresponding type, the "unknown type", is stored in the object store. |
| 780 cls = dynamic_class_; | 783 cls = dynamic_class(); |
| 781 type = Type::NewNonParameterizedType(cls); | 784 type = Type::NewNonParameterizedType(cls); |
| 782 object_store->set_dynamic_type(type); | 785 object_store->set_dynamic_type(type); |
| 783 core_lib.AddClass(cls); | |
| 784 | 786 |
| 785 // Allocate pre-initialized values. | 787 // Allocate pre-initialized values. |
| 786 Bool& bool_value = Bool::Handle(); | 788 Bool& bool_value = Bool::Handle(); |
| 787 bool_value = Bool::New(true); | 789 bool_value = Bool::New(true); |
| 788 object_store->set_true_value(bool_value); | 790 object_store->set_true_value(bool_value); |
| 789 bool_value = Bool::New(false); | 791 bool_value = Bool::New(false); |
| 790 object_store->set_false_value(bool_value); | 792 object_store->set_false_value(bool_value); |
| 791 | 793 |
| 792 // Setup some default native field classes which can be extended for | 794 // Setup some default native field classes which can be extended for |
| 793 // specifying native fields in dart classes. | 795 // specifying native fields in dart classes. |
| (...skipping 5250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6044 isolate->object_store()->set_core_library(core_lib); | 6046 isolate->object_store()->set_core_library(core_lib); |
| 6045 const String& core_impl_lib_url = | 6047 const String& core_impl_lib_url = |
| 6046 String::Handle(Symbols::New("dart:coreimpl")); | 6048 String::Handle(Symbols::New("dart:coreimpl")); |
| 6047 const Library& core_impl_lib = | 6049 const Library& core_impl_lib = |
| 6048 Library::Handle(Library::NewLibraryHelper(core_impl_lib_url, false)); | 6050 Library::Handle(Library::NewLibraryHelper(core_impl_lib_url, false)); |
| 6049 isolate->object_store()->set_core_impl_library(core_impl_lib); | 6051 isolate->object_store()->set_core_impl_library(core_impl_lib); |
| 6050 core_impl_lib.Register(); | 6052 core_impl_lib.Register(); |
| 6051 core_lib.AddImport(core_impl_lib); | 6053 core_lib.AddImport(core_impl_lib); |
| 6052 core_impl_lib.AddImport(core_lib); | 6054 core_impl_lib.AddImport(core_lib); |
| 6053 isolate->object_store()->set_root_library(Library::Handle()); | 6055 isolate->object_store()->set_root_library(Library::Handle()); |
| 6056 |
| 6057 // Hook up predefined classes without setting their library pointers. These |
| 6058 // classes are coming from the VM isolate, and are shared between multiple |
| 6059 // isolates so setting their library pointers would be wrong. |
| 6060 const Class& cls = Class::Handle(Object::dynamic_class()); |
| 6061 core_lib.AddObject(cls, String::Handle(cls.Name())); |
| 6054 } | 6062 } |
| 6055 | 6063 |
| 6056 | 6064 |
| 6057 void Library::InitMathLibrary(Isolate* isolate) { | 6065 void Library::InitMathLibrary(Isolate* isolate) { |
| 6058 const String& url = String::Handle(Symbols::New("dart:math")); | 6066 const String& url = String::Handle(Symbols::New("dart:math")); |
| 6059 const Library& lib = Library::Handle(Library::New(url)); | 6067 const Library& lib = Library::Handle(Library::New(url)); |
| 6060 lib.Register(); | 6068 lib.Register(); |
| 6061 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); | 6069 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); |
| 6062 lib.AddImport(core_impl_lib); | 6070 lib.AddImport(core_impl_lib); |
| 6063 isolate->object_store()->set_math_library(lib); | 6071 isolate->object_store()->set_math_library(lib); |
| (...skipping 4782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10846 const String& str = String::Handle(pattern()); | 10854 const String& str = String::Handle(pattern()); |
| 10847 const char* format = "JSRegExp: pattern=%s flags=%s"; | 10855 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 10848 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 10856 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 10849 char* chars = reinterpret_cast<char*>( | 10857 char* chars = reinterpret_cast<char*>( |
| 10850 Isolate::Current()->current_zone()->Allocate(len + 1)); | 10858 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 10851 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 10859 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 10852 return chars; | 10860 return chars; |
| 10853 } | 10861 } |
| 10854 | 10862 |
| 10855 } // namespace dart | 10863 } // namespace dart |
| OLD | NEW |