Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(619)

Side by Side Diff: runtime/vm/object.cc

Issue 14520010: First step towards loading the core library scripts directly from the sources (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/cpu.h" 10 #include "vm/cpu.h"
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 const Library& lib) { 670 const Library& lib) {
671 ASSERT(public_class_name.Length() > 0); 671 ASSERT(public_class_name.Length() > 0);
672 ASSERT(public_class_name.CharAt(0) == '_'); 672 ASSERT(public_class_name.CharAt(0) == '_');
673 String& str = String::Handle(); 673 String& str = String::Handle();
674 str = lib.PrivateName(public_class_name); 674 str = lib.PrivateName(public_class_name);
675 cls.set_name(str); 675 cls.set_name(str);
676 lib.AddClass(cls); 676 lib.AddClass(cls);
677 } 677 }
678 678
679 679
680 #define LOAD_LIBRARY(name, raw_name) \ 680 #define LOAD_LIBRARY(name, raw_name) \
Ivan Posva 2013/04/29 04:42:32 This is now an empty macro.
siva 2013/04/29 17:35:58 Yes, removed it. On 2013/04/29 04:42:32, Ivan Pos
681 url = Symbols::Dart##name().raw(); \
682 lib = Library::LookupLibrary(url); \
683 if (lib.IsNull()) { \
684 lib = Library::NewLibraryHelper(url, true); \
685 lib.Register(); \
686 } \
687 isolate->object_store()->set_##raw_name##_library(lib); \
688
689 #define INIT_LIBRARY(name, raw_name, has_patch) \
690 LOAD_LIBRARY(name, raw_name) \
691 script = Bootstrap::Load##name##Script(false); \
692 error = Bootstrap::Compile(lib, script); \
693 if (!error.IsNull()) { \
694 return error.raw(); \
695 } \
696 if (has_patch) { \
697 script = Bootstrap::Load##name##Script(true); \
698 error = lib.Patch(script); \
699 if (!error.IsNull()) { \
700 return error.raw(); \
701 } \
702 } \
703 681
704 682
705 RawError* Object::Init(Isolate* isolate) { 683 RawError* Object::Init(Isolate* isolate) {
706 TIMERSCOPE(time_bootstrap); 684 TIMERSCOPE(time_bootstrap);
707 ObjectStore* object_store = isolate->object_store(); 685 ObjectStore* object_store = isolate->object_store();
708 686
709 Class& cls = Class::Handle(); 687 Class& cls = Class::Handle();
710 Type& type = Type::Handle(); 688 Type& type = Type::Handle();
711 Array& array = Array::Handle(); 689 Array& array = Array::Handle();
712 String& url = String::Handle();
713 Library& lib = Library::Handle(); 690 Library& lib = Library::Handle();
714 Script& script = Script::Handle();
715 Error& error = Error::Handle();
716 691
717 // All RawArray fields will be initialized to an empty array, therefore 692 // All RawArray fields will be initialized to an empty array, therefore
718 // initialize array class first. 693 // initialize array class first.
719 cls = Class::New<Array>(); 694 cls = Class::New<Array>();
720 object_store->set_array_class(cls); 695 object_store->set_array_class(cls);
721 696
722 // Array and ImmutableArray are the only VM classes that are parameterized. 697 // Array and ImmutableArray are the only VM classes that are parameterized.
723 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we 698 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we
724 // need to set the offset of their type_arguments_ field, which is explicitly 699 // need to set the offset of their type_arguments_ field, which is explicitly
725 // declared in RawArray. 700 // declared in RawArray.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 RegisterClass(cls, Symbols::StackTrace(), core_lib); 811 RegisterClass(cls, Symbols::StackTrace(), core_lib);
837 pending_classes.Add(cls, Heap::kOld); 812 pending_classes.Add(cls, Heap::kOld);
838 // Super type set below, after Object is allocated. 813 // Super type set below, after Object is allocated.
839 814
840 cls = Class::New<JSRegExp>(); 815 cls = Class::New<JSRegExp>();
841 object_store->set_jsregexp_class(cls); 816 object_store->set_jsregexp_class(cls);
842 RegisterPrivateClass(cls, Symbols::JSSyntaxRegExp(), core_lib); 817 RegisterPrivateClass(cls, Symbols::JSSyntaxRegExp(), core_lib);
843 pending_classes.Add(cls, Heap::kOld); 818 pending_classes.Add(cls, Heap::kOld);
844 819
845 // Initialize the base interfaces used by the core VM classes. 820 // Initialize the base interfaces used by the core VM classes.
846 script = Bootstrap::LoadCoreScript(false); 821 const Script& core_script = Script::Handle(Bootstrap::LoadCoreScript());
847 822
848 // Allocate and initialize the pre-allocated classes in the core library. 823 // Allocate and initialize the pre-allocated classes in the core library.
849 cls = Class::New<Instance>(kInstanceCid); 824 cls = Class::New<Instance>(kInstanceCid);
850 object_store->set_object_class(cls); 825 object_store->set_object_class(cls);
851 cls.set_name(Symbols::Object()); 826 cls.set_name(Symbols::Object());
852 cls.set_script(script); 827 cls.set_script(core_script);
853 cls.set_is_prefinalized(); 828 cls.set_is_prefinalized();
854 core_lib.AddClass(cls); 829 core_lib.AddClass(cls);
855 pending_classes.Add(cls, Heap::kOld); 830 pending_classes.Add(cls, Heap::kOld);
856 type = Type::NewNonParameterizedType(cls); 831 type = Type::NewNonParameterizedType(cls);
857 object_store->set_object_type(type); 832 object_store->set_object_type(type);
858 833
859 cls = object_store->type_class(); 834 cls = object_store->type_class();
860 RegisterPrivateClass(cls, Symbols::Type(), core_lib); 835 RegisterPrivateClass(cls, Symbols::Type(), core_lib);
861 pending_classes.Add(cls, Heap::kOld); 836 pending_classes.Add(cls, Heap::kOld);
862 837
(...skipping 30 matching lines...) Expand all
893 object_store->set_weak_property_class(cls); 868 object_store->set_weak_property_class(cls);
894 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib); 869 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib);
895 870
896 // Setup some default native field classes which can be extended for 871 // Setup some default native field classes which can be extended for
897 // specifying native fields in dart classes. 872 // specifying native fields in dart classes.
898 Library::InitNativeWrappersLibrary(isolate); 873 Library::InitNativeWrappersLibrary(isolate);
899 ASSERT(isolate->object_store()->native_wrappers_library() != Library::null()); 874 ASSERT(isolate->object_store()->native_wrappers_library() != Library::null());
900 875
901 // Pre-register the typed_data library so the native class implementations 876 // Pre-register the typed_data library so the native class implementations
902 // can be hooked up before compiling it. 877 // can be hooked up before compiling it.
903 LOAD_LIBRARY(TypedData, typed_data); 878 lib = Library::LookupLibrary(Symbols::DartTypedData());
879 if (lib.IsNull()) {
880 lib = Library::NewLibraryHelper(Symbols::DartTypedData(), true);
881 lib.Register();
882 isolate->object_store()->set_bootstrap_library(ObjectStore::kTypedData,
883 lib);
884 }
904 ASSERT(!lib.IsNull()); 885 ASSERT(!lib.IsNull());
905 ASSERT(lib.raw() == Library::TypedDataLibrary()); 886 ASSERT(lib.raw() == Library::TypedDataLibrary());
906 const intptr_t typed_data_class_array_length = 887 const intptr_t typed_data_class_array_length =
907 RawObject::NumberOfTypedDataClasses(); 888 RawObject::NumberOfTypedDataClasses();
908 Array& typed_data_classes = 889 Array& typed_data_classes =
909 Array::Handle(Array::New(typed_data_class_array_length)); 890 Array::Handle(Array::New(typed_data_class_array_length));
910 int index = 0; 891 int index = 0;
911 #define REGISTER_TYPED_DATA_CLASS(clazz) \ 892 #define REGISTER_TYPED_DATA_CLASS(clazz) \
912 cls = Class::NewTypedDataClass(kTypedData##clazz##Cid); \ 893 cls = Class::NewTypedDataClass(kTypedData##clazz##Cid); \
913 index = kTypedData##clazz##Cid - kTypedDataInt8ArrayCid; \ 894 index = kTypedData##clazz##Cid - kTypedDataInt8ArrayCid; \
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 pending_classes.Add(cls, Heap::kOld); 953 pending_classes.Add(cls, Heap::kOld);
973 type = Type::NewNonParameterizedType(cls); 954 type = Type::NewNonParameterizedType(cls);
974 object_store->set_function_type(type); 955 object_store->set_function_type(type);
975 956
976 cls = Class::New<Number>(); 957 cls = Class::New<Number>();
977 RegisterClass(cls, Symbols::Number(), core_lib); 958 RegisterClass(cls, Symbols::Number(), core_lib);
978 pending_classes.Add(cls, Heap::kOld); 959 pending_classes.Add(cls, Heap::kOld);
979 type = Type::NewNonParameterizedType(cls); 960 type = Type::NewNonParameterizedType(cls);
980 object_store->set_number_type(type); 961 object_store->set_number_type(type);
981 962
982 cls = Class::New<Instance>(Symbols::Int(), script, Scanner::kDummyTokenIndex); 963 cls = Class::New<Instance>(Symbols::Int(),
964 core_script,
965 Scanner::kDummyTokenIndex);
983 RegisterClass(cls, Symbols::Int(), core_lib); 966 RegisterClass(cls, Symbols::Int(), core_lib);
984 pending_classes.Add(cls, Heap::kOld); 967 pending_classes.Add(cls, Heap::kOld);
985 type = Type::NewNonParameterizedType(cls); 968 type = Type::NewNonParameterizedType(cls);
986 object_store->set_int_type(type); 969 object_store->set_int_type(type);
987 970
988 cls = Class::New<Instance>(Symbols::Double(), 971 cls = Class::New<Instance>(Symbols::Double(),
989 script, 972 core_script,
990 Scanner::kDummyTokenIndex); 973 Scanner::kDummyTokenIndex);
991 RegisterClass(cls, Symbols::Double(), core_lib); 974 RegisterClass(cls, Symbols::Double(), core_lib);
992 pending_classes.Add(cls, Heap::kOld); 975 pending_classes.Add(cls, Heap::kOld);
993 type = Type::NewNonParameterizedType(cls); 976 type = Type::NewNonParameterizedType(cls);
994 object_store->set_double_type(type); 977 object_store->set_double_type(type);
995 978
996 name = Symbols::New("String"); 979 name = Symbols::New("String");
997 cls = Class::New<Instance>(name, script, Scanner::kDummyTokenIndex); 980 cls = Class::New<Instance>(name, core_script, Scanner::kDummyTokenIndex);
998 RegisterClass(cls, name, core_lib); 981 RegisterClass(cls, name, core_lib);
999 pending_classes.Add(cls, Heap::kOld); 982 pending_classes.Add(cls, Heap::kOld);
1000 type = Type::NewNonParameterizedType(cls); 983 type = Type::NewNonParameterizedType(cls);
1001 object_store->set_string_type(type); 984 object_store->set_string_type(type);
1002 985
1003 cls = Class::New<Instance>(Symbols::List(), 986 cls = Class::New<Instance>(Symbols::List(),
1004 script, 987 core_script,
1005 Scanner::kDummyTokenIndex); 988 Scanner::kDummyTokenIndex);
1006 RegisterClass(cls, Symbols::List(), core_lib); 989 RegisterClass(cls, Symbols::List(), core_lib);
1007 pending_classes.Add(cls, Heap::kOld); 990 pending_classes.Add(cls, Heap::kOld);
1008 object_store->set_list_class(cls); 991 object_store->set_list_class(cls);
1009 992
1010 cls = object_store->bool_class(); 993 cls = object_store->bool_class();
1011 type = Type::NewNonParameterizedType(cls); 994 type = Type::NewNonParameterizedType(cls);
1012 object_store->set_bool_type(type); 995 object_store->set_bool_type(type);
1013 996
1014 cls = object_store->smi_class(); 997 cls = object_store->smi_class();
(...skipping 19 matching lines...) Expand all
1034 // The class 'dynamic' is registered in the class dictionary because its name 1017 // The class 'dynamic' is registered in the class dictionary because its name
1035 // is a built-in identifier, rather than a reserved keyword. Its name is not 1018 // is a built-in identifier, rather than a reserved keyword. Its name is not
1036 // heap allocated, because the class resides in the VM isolate. 1019 // heap allocated, because the class resides in the VM isolate.
1037 // The corresponding type, the "unknown type", is stored in the object store. 1020 // The corresponding type, the "unknown type", is stored in the object store.
1038 cls = dynamic_class(); 1021 cls = dynamic_class();
1039 type = Type::NewNonParameterizedType(cls); 1022 type = Type::NewNonParameterizedType(cls);
1040 object_store->set_dynamic_type(type); 1023 object_store->set_dynamic_type(type);
1041 1024
1042 // Finish the initialization by compiling the bootstrap scripts containing the 1025 // Finish the initialization by compiling the bootstrap scripts containing the
1043 // base interfaces and the implementation of the internal classes. 1026 // base interfaces and the implementation of the internal classes.
1044 INIT_LIBRARY(Core, core, true); 1027 const Error& error =
1045 1028 Error::Handle(Bootstrap::LoadandCompileScripts(core_script));
1046 INIT_LIBRARY(Async, async, true); 1029 if (!error.IsNull()) {
1047 INIT_LIBRARY(Collection, collection, true); 1030 return error.raw();
1048 INIT_LIBRARY(CollectionDev, collection_dev, true); 1031 }
1049 INIT_LIBRARY(Crypto, crypto, false);
1050 INIT_LIBRARY(Isolate, isolate, true);
1051 INIT_LIBRARY(Json, json, true);
1052 INIT_LIBRARY(Math, math, true);
1053 INIT_LIBRARY(Mirrors, mirrors, true);
1054 INIT_LIBRARY(TypedData, typed_data, true);
1055 INIT_LIBRARY(Utf, utf, false);
1056 INIT_LIBRARY(Uri, uri, false);
1057
1058 Bootstrap::SetupNativeResolver();
1059 1032
1060 // Remove the Object superclass cycle by setting the super type to null (not 1033 // Remove the Object superclass cycle by setting the super type to null (not
1061 // to the type of null). 1034 // to the type of null).
1062 cls = object_store->object_class(); 1035 cls = object_store->object_class();
1063 cls.set_super_type(Type::Handle()); 1036 cls.set_super_type(Type::Handle());
1064 1037
1065 ClassFinalizer::VerifyBootstrapClasses(); 1038 ClassFinalizer::VerifyBootstrapClasses();
1066 MarkInvisibleFunctions(); 1039 MarkInvisibleFunctions();
1067 1040
1068 // Set up the intrinsic state of all functions (core, math and scalar list). 1041 // Set up the intrinsic state of all functions (core, math and scalar list).
(...skipping 5369 matching lines...) Expand 10 before | Expand all | Expand 10 after
6438 RawLibrary* Library::New(const String& url) { 6411 RawLibrary* Library::New(const String& url) {
6439 return NewLibraryHelper(url, false); 6412 return NewLibraryHelper(url, false);
6440 } 6413 }
6441 6414
6442 6415
6443 void Library::InitCoreLibrary(Isolate* isolate) { 6416 void Library::InitCoreLibrary(Isolate* isolate) {
6444 const String& core_lib_url = Symbols::DartCore(); 6417 const String& core_lib_url = Symbols::DartCore();
6445 const Library& core_lib = 6418 const Library& core_lib =
6446 Library::Handle(Library::NewLibraryHelper(core_lib_url, false)); 6419 Library::Handle(Library::NewLibraryHelper(core_lib_url, false));
6447 core_lib.Register(); 6420 core_lib.Register();
6448 isolate->object_store()->set_core_library(core_lib); 6421 isolate->object_store()->set_bootstrap_library(ObjectStore::kCore, core_lib);
6449 isolate->object_store()->set_root_library(Library::Handle()); 6422 isolate->object_store()->set_root_library(Library::Handle());
6450 6423
6451 // Hook up predefined classes without setting their library pointers. These 6424 // Hook up predefined classes without setting their library pointers. These
6452 // classes are coming from the VM isolate, and are shared between multiple 6425 // classes are coming from the VM isolate, and are shared between multiple
6453 // isolates so setting their library pointers would be wrong. 6426 // isolates so setting their library pointers would be wrong.
6454 const Class& cls = Class::Handle(Object::dynamic_class()); 6427 const Class& cls = Class::Handle(Object::dynamic_class());
6455 core_lib.AddObject(cls, String::Handle(cls.Name())); 6428 core_lib.AddObject(cls, String::Handle(cls.Name()));
6456 } 6429 }
6457 6430
6458 6431
(...skipping 6726 matching lines...) Expand 10 before | Expand all | Expand 10 after
13185 } 13158 }
13186 return result.raw(); 13159 return result.raw();
13187 } 13160 }
13188 13161
13189 13162
13190 const char* WeakProperty::ToCString() const { 13163 const char* WeakProperty::ToCString() const {
13191 return "_WeakProperty"; 13164 return "_WeakProperty";
13192 } 13165 }
13193 13166
13194 } // namespace dart 13167 } // namespace dart
OLDNEW
« runtime/vm/bootstrap.cc ('K') | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698