OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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/kernel_reader.h" | 5 #include "vm/kernel_reader.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 } | 128 } |
129 | 129 |
130 for (intptr_t i = 0; i < length; i++) { | 130 for (intptr_t i = 0; i < length; i++) { |
131 dart::Library& library = | 131 dart::Library& library = |
132 LookupLibrary(program_->libraries()[i]->canonical_name()); | 132 LookupLibrary(program_->libraries()[i]->canonical_name()); |
133 if (!library.Loaded()) library.SetLoaded(); | 133 if (!library.Loaded()) library.SetLoaded(); |
134 } | 134 } |
135 | 135 |
136 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { | 136 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { |
137 CanonicalName* main = program_->main_method(); | 137 CanonicalName* main = program_->main_method(); |
138 dart::Library& library = LookupLibrary(main->EnclosingName()); | 138 if (main == NULL) { |
139 return dart::Library::Handle(Z); | |
140 } | |
139 | 141 |
142 CanonicalName* main_library = main->EnclosingName(); | |
143 dart::Library& library = LookupLibrary(main_library); | |
140 // Sanity check that we can find the main entrypoint. | 144 // Sanity check that we can find the main entrypoint. |
141 Object& main_obj = Object::Handle( | 145 Object& main_obj = Object::Handle( |
142 Z, library.LookupObjectAllowPrivate(H.DartSymbol("main"))); | 146 Z, library.LookupObjectAllowPrivate(H.DartSymbol("main"))); |
143 ASSERT(!main_obj.IsNull()); | 147 ASSERT(!main_obj.IsNull()); |
148 | |
149 // There is a function _getMainClosure in dart:_builtin that returns the | |
Kevin Millikin (Google)
2017/03/31 10:05:42
I'm aware that this is ugly. It would be better t
Vyacheslav Egorov (Google)
2017/04/05 12:21:23
We would also need to come up with solution for th
Kevin Millikin (Google)
2017/04/25 18:20:29
I know, and those changes started landing before t
| |
150 // main procedure. Since the platform libraries are compiled before the | |
151 // program script, this function is patched here. | |
152 dart::Library& builtin_library = | |
153 dart::Library::Handle(Z, I->object_store()->builtin_library()); | |
154 Function& to_patch = | |
155 Function::Handle(builtin_library.LookupFunctionAllowPrivate( | |
kustermann
2017/04/05 11:47:07
Handle(Z,
Kevin Millikin (Google)
2017/04/25 18:20:29
Done.
| |
156 dart::String::Handle(dart::String::New("_getMainClosure")))); | |
157 | |
158 // Build a canonical name tree instead of sharing main's canonical name. | |
159 CanonicalName* name = CanonicalName::NewRoot(); | |
kustermann
2017/04/05 11:47:07
This will leak [name], right?
Please add a commen
| |
160 name = name->AddChild(new String(main_library->name()->buffer(), | |
161 main_library->name()->size())); | |
kustermann
2017/04/05 11:47:07
This "new String()" will never be freed afaik! (al
Kevin Millikin (Google)
2017/04/25 18:20:29
Comment added that we are leaking the whole body.
| |
162 CanonicalName* kind = main->parent(); | |
163 name = name->AddChild( | |
164 new String(kind->name()->buffer(), kind->name()->size())); | |
165 name = name->AddChild(new String("main")); | |
166 | |
167 Procedure* procedure = | |
168 reinterpret_cast<Procedure*>(to_patch.kernel_function()); | |
169 procedure->function()->set_body(new ReturnStatement(new StaticGet(name))); | |
kustermann
2017/04/05 11:47:07
I assume the function has already a body (like nsm
Kevin Millikin (Google)
2017/04/25 18:20:29
It doesn't have a body, it's treated as if it were
| |
170 | |
144 return library; | 171 return library; |
145 } | 172 } |
146 } | 173 } |
147 | 174 |
148 // Either class finalization failed or we caught a compile error. | 175 // Either class finalization failed or we caught a compile error. |
149 // In both cases sticky error would be set. | 176 // In both cases sticky error would be set. |
150 Error& error = Error::Handle(Z); | 177 Error& error = Error::Handle(Z); |
151 error = thread_->sticky_error(); | 178 error = thread_->sticky_error(); |
152 thread_->clear_sticky_error(); | 179 thread_->clear_sticky_error(); |
153 return error; | 180 return error; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 | 231 |
205 // Load toplevel procedures. | 232 // Load toplevel procedures. |
206 for (intptr_t i = 0; i < kernel_library->procedures().length(); i++) { | 233 for (intptr_t i = 0; i < kernel_library->procedures().length(); i++) { |
207 Procedure* kernel_procedure = kernel_library->procedures()[i]; | 234 Procedure* kernel_procedure = kernel_library->procedures()[i]; |
208 ReadProcedure(library, toplevel_class, kernel_procedure); | 235 ReadProcedure(library, toplevel_class, kernel_procedure); |
209 } | 236 } |
210 | 237 |
211 toplevel_class.SetFunctions(Array::Handle(MakeFunctionsArray())); | 238 toplevel_class.SetFunctions(Array::Handle(MakeFunctionsArray())); |
212 | 239 |
213 const GrowableObjectArray& classes = | 240 const GrowableObjectArray& classes = |
214 GrowableObjectArray::Handle(I->object_store()->pending_classes()); | 241 GrowableObjectArray::Handle(Z, I->object_store()->pending_classes()); |
215 | 242 |
216 // Load all classes. | 243 // Load all classes. |
217 for (intptr_t i = 0; i < kernel_library->classes().length(); i++) { | 244 for (intptr_t i = 0; i < kernel_library->classes().length(); i++) { |
218 Class* kernel_klass = kernel_library->classes()[i]; | 245 Class* kernel_klass = kernel_library->classes()[i]; |
219 classes.Add(ReadClass(library, toplevel_class, kernel_klass), Heap::kOld); | 246 classes.Add(ReadClass(library, toplevel_class, kernel_klass), Heap::kOld); |
220 } | 247 } |
221 | 248 |
222 classes.Add(toplevel_class, Heap::kOld); | 249 classes.Add(toplevel_class, Heap::kOld); |
223 } | 250 } |
224 | 251 |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
864 initializer_fun.set_is_debuggable(false); | 891 initializer_fun.set_is_debuggable(false); |
865 initializer_fun.set_is_reflectable(false); | 892 initializer_fun.set_is_reflectable(false); |
866 initializer_fun.set_is_inlinable(false); | 893 initializer_fun.set_is_inlinable(false); |
867 return new (zone) ParsedFunction(thread, initializer_fun); | 894 return new (zone) ParsedFunction(thread, initializer_fun); |
868 } | 895 } |
869 | 896 |
870 | 897 |
871 } // namespace kernel | 898 } // namespace kernel |
872 } // namespace dart | 899 } // namespace dart |
873 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 900 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |