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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 } | 150 } |
151 | 151 |
152 for (intptr_t i = 0; i < length; i++) { | 152 for (intptr_t i = 0; i < length; i++) { |
153 dart::Library& library = | 153 dart::Library& library = |
154 LookupLibrary(program_->libraries()[i]->canonical_name()); | 154 LookupLibrary(program_->libraries()[i]->canonical_name()); |
155 if (!library.Loaded()) library.SetLoaded(); | 155 if (!library.Loaded()) library.SetLoaded(); |
156 } | 156 } |
157 | 157 |
158 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { | 158 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { |
159 CanonicalName* main = program_->main_method(); | 159 CanonicalName* main = program_->main_method(); |
160 dart::Library& library = LookupLibrary(H.EnclosingName(main)); | 160 if (main == NULL) { |
| 161 return dart::Library::Handle(Z); |
| 162 } |
161 | 163 |
| 164 CanonicalName* main_library = H.EnclosingName(main); |
| 165 dart::Library& library = LookupLibrary(main_library); |
162 // Sanity check that we can find the main entrypoint. | 166 // Sanity check that we can find the main entrypoint. |
163 Object& main_obj = Object::Handle( | 167 Object& main_obj = Object::Handle( |
164 Z, library.LookupObjectAllowPrivate(H.DartSymbol("main"))); | 168 Z, library.LookupObjectAllowPrivate(H.DartSymbol("main"))); |
165 ASSERT(!main_obj.IsNull()); | 169 ASSERT(!main_obj.IsNull()); |
| 170 |
| 171 // There is a function _getMainClosure in dart:_builtin that returns the |
| 172 // main procedure. Since the platform libraries are compiled before the |
| 173 // program script, this function is patched here. |
| 174 // |
| 175 // TODO(kmillikin): we are leaking the function body. Find a way to |
| 176 // deallocate it. |
| 177 dart::Library& builtin_library = |
| 178 dart::Library::Handle(Z, I->object_store()->builtin_library()); |
| 179 Function& to_patch = Function::Handle( |
| 180 Z, builtin_library.LookupFunctionAllowPrivate( |
| 181 dart::String::Handle(dart::String::New("_getMainClosure")))); |
| 182 |
| 183 // We will handle the StaticGet specially and will not use the name. |
| 184 Procedure* procedure = |
| 185 reinterpret_cast<Procedure*>(to_patch.kernel_function()); |
| 186 procedure->function()->set_body(new ReturnStatement(new StaticGet(NULL))); |
| 187 |
166 return library; | 188 return library; |
167 } | 189 } |
168 } | 190 } |
169 | 191 |
170 // Either class finalization failed or we caught a compile error. | 192 // Either class finalization failed or we caught a compile error. |
171 // In both cases sticky error would be set. | 193 // In both cases sticky error would be set. |
172 Error& error = Error::Handle(Z); | 194 Error& error = Error::Handle(Z); |
173 error = thread_->sticky_error(); | 195 error = thread_->sticky_error(); |
174 thread_->clear_sticky_error(); | 196 thread_->clear_sticky_error(); |
175 return error; | 197 return error; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 248 |
227 // Load toplevel procedures. | 249 // Load toplevel procedures. |
228 for (intptr_t i = 0; i < kernel_library->procedures().length(); i++) { | 250 for (intptr_t i = 0; i < kernel_library->procedures().length(); i++) { |
229 Procedure* kernel_procedure = kernel_library->procedures()[i]; | 251 Procedure* kernel_procedure = kernel_library->procedures()[i]; |
230 ReadProcedure(library, toplevel_class, kernel_procedure); | 252 ReadProcedure(library, toplevel_class, kernel_procedure); |
231 } | 253 } |
232 | 254 |
233 toplevel_class.SetFunctions(Array::Handle(MakeFunctionsArray())); | 255 toplevel_class.SetFunctions(Array::Handle(MakeFunctionsArray())); |
234 | 256 |
235 const GrowableObjectArray& classes = | 257 const GrowableObjectArray& classes = |
236 GrowableObjectArray::Handle(I->object_store()->pending_classes()); | 258 GrowableObjectArray::Handle(Z, I->object_store()->pending_classes()); |
237 | 259 |
238 // Load all classes. | 260 // Load all classes. |
239 for (intptr_t i = 0; i < kernel_library->classes().length(); i++) { | 261 for (intptr_t i = 0; i < kernel_library->classes().length(); i++) { |
240 Class* kernel_klass = kernel_library->classes()[i]; | 262 Class* kernel_klass = kernel_library->classes()[i]; |
241 classes.Add(ReadClass(library, toplevel_class, kernel_klass), Heap::kOld); | 263 classes.Add(ReadClass(library, toplevel_class, kernel_klass), Heap::kOld); |
242 } | 264 } |
243 | 265 |
244 classes.Add(toplevel_class, Heap::kOld); | 266 classes.Add(toplevel_class, Heap::kOld); |
245 } | 267 } |
246 | 268 |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 initializer_fun.set_is_debuggable(false); | 904 initializer_fun.set_is_debuggable(false); |
883 initializer_fun.set_is_reflectable(false); | 905 initializer_fun.set_is_reflectable(false); |
884 initializer_fun.set_is_inlinable(false); | 906 initializer_fun.set_is_inlinable(false); |
885 return new (zone) ParsedFunction(thread, initializer_fun); | 907 return new (zone) ParsedFunction(thread, initializer_fun); |
886 } | 908 } |
887 | 909 |
888 | 910 |
889 } // namespace kernel | 911 } // namespace kernel |
890 } // namespace dart | 912 } // namespace dart |
891 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 913 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |