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/compiler.h" | 5 #include "vm/compiler.h" |
6 | 6 |
7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 | 8 |
9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
10 #include "vm/block_scheduler.h" | 10 #include "vm/block_scheduler.h" |
(...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 static void CreateLocalVarDescriptors(const ParsedFunction& parsed_function) { | 1286 static void CreateLocalVarDescriptors(const ParsedFunction& parsed_function) { |
1287 const Function& func = parsed_function.function(); | 1287 const Function& func = parsed_function.function(); |
1288 LocalVarDescriptors& var_descs = LocalVarDescriptors::Handle(); | 1288 LocalVarDescriptors& var_descs = LocalVarDescriptors::Handle(); |
1289 var_descs = parsed_function.node_sequence()->scope()->GetVarDescriptors(func); | 1289 var_descs = parsed_function.node_sequence()->scope()->GetVarDescriptors(func); |
1290 Code::Handle(func.unoptimized_code()).set_var_descriptors(var_descs); | 1290 Code::Handle(func.unoptimized_code()).set_var_descriptors(var_descs); |
1291 } | 1291 } |
1292 | 1292 |
1293 | 1293 |
1294 void Compiler::CompileStaticInitializer(const Field& field) { | 1294 void Compiler::CompileStaticInitializer(const Field& field) { |
1295 ASSERT(field.is_static()); | 1295 ASSERT(field.is_static()); |
1296 if (field.initializer() != Function::null()) { | 1296 if (field.PrecompiledInitializer() != Function::null()) { |
1297 // TODO(rmacnak): Investigate why this happens for _enum_names. | 1297 // TODO(rmacnak): Investigate why this happens for _enum_names. |
1298 OS::Print("Warning: Ignoring repeated request for initializer for %s\n", | 1298 OS::Print("Warning: Ignoring repeated request for initializer for %s\n", |
1299 field.ToCString()); | 1299 field.ToCString()); |
1300 return; | 1300 return; |
1301 } | 1301 } |
1302 ASSERT(field.initializer() == Function::null()); | 1302 ASSERT(field.PrecompiledInitializer() == Function::null()); |
1303 Thread* thread = Thread::Current(); | 1303 Isolate* isolate = Isolate::Current(); |
1304 StackZone zone(thread); | 1304 StackZone zone(isolate); |
1305 | 1305 |
1306 ParsedFunction* parsed_function = Parser::ParseStaticFieldInitializer(field); | 1306 ParsedFunction* parsed_function = Parser::ParseStaticFieldInitializer(field); |
1307 | 1307 |
1308 parsed_function->AllocateVariables(); | 1308 parsed_function->AllocateVariables(); |
1309 // Non-optimized code generator. | 1309 // Non-optimized code generator. |
1310 DartCompilationPipeline pipeline; | 1310 DartCompilationPipeline pipeline; |
1311 CompileParsedFunctionHelper(&pipeline, | 1311 CompileParsedFunctionHelper(&pipeline, |
1312 parsed_function, | 1312 parsed_function, |
1313 false, // optimized | 1313 false, // optimized |
1314 Isolate::kNoDeoptId); | 1314 Isolate::kNoDeoptId); |
1315 | 1315 |
1316 const Function& initializer = parsed_function->function(); | 1316 const Function& initializer = parsed_function->function(); |
1317 field.set_initializer(initializer); | 1317 field.SetPrecompiledInitializer(initializer); |
1318 } | 1318 } |
1319 | 1319 |
1320 | 1320 |
1321 RawObject* Compiler::EvaluateStaticInitializer(const Field& field) { | 1321 RawObject* Compiler::EvaluateStaticInitializer(const Field& field) { |
1322 ASSERT(field.is_static()); | 1322 ASSERT(field.is_static()); |
1323 // The VM sets the field's value to transiton_sentinel prior to | 1323 // The VM sets the field's value to transiton_sentinel prior to |
1324 // evaluating the initializer value. | 1324 // evaluating the initializer value. |
1325 ASSERT(field.value() == Object::transition_sentinel().raw()); | 1325 ASSERT(field.StaticFieldValue() == Object::transition_sentinel().raw()); |
1326 LongJumpScope jump; | 1326 LongJumpScope jump; |
1327 if (setjmp(*jump.Set()) == 0) { | 1327 if (setjmp(*jump.Set()) == 0) { |
1328 Function& initializer = Function::Handle(field.initializer()); | |
1329 | |
1330 // Under precompilation, the initializer may have already been compiled, in | 1328 // Under precompilation, the initializer may have already been compiled, in |
1331 // which case use it. Under lazy compilation or early in precompilation, the | 1329 // which case use it. Under lazy compilation or early in precompilation, the |
1332 // initializer has not yet been created, so create it now, but don't bother | 1330 // initializer has not yet been created, so create it now, but don't bother |
1333 // remembering it because it won't be used again. | 1331 // remembering it because it won't be used again. |
1334 if (initializer.IsNull()) { | 1332 Function& initializer = Function::Handle(); |
| 1333 if (!field.HasPrecompiledInitializer()) { |
1335 Thread* const thread = Thread::Current(); | 1334 Thread* const thread = Thread::Current(); |
1336 StackZone zone(thread); | 1335 StackZone zone(thread); |
1337 ParsedFunction* parsed_function = | 1336 ParsedFunction* parsed_function = |
1338 Parser::ParseStaticFieldInitializer(field); | 1337 Parser::ParseStaticFieldInitializer(field); |
1339 | 1338 |
1340 parsed_function->AllocateVariables(); | 1339 parsed_function->AllocateVariables(); |
1341 // Non-optimized code generator. | 1340 // Non-optimized code generator. |
1342 DartCompilationPipeline pipeline; | 1341 DartCompilationPipeline pipeline; |
1343 CompileParsedFunctionHelper(&pipeline, | 1342 CompileParsedFunctionHelper(&pipeline, |
1344 parsed_function, | 1343 parsed_function, |
1345 false, // optimized | 1344 false, // optimized |
1346 Isolate::kNoDeoptId); | 1345 Isolate::kNoDeoptId); |
1347 // Eagerly create local var descriptors. | 1346 // Eagerly create local var descriptors. |
1348 CreateLocalVarDescriptors(*parsed_function); | 1347 CreateLocalVarDescriptors(*parsed_function); |
1349 | 1348 |
1350 initializer = parsed_function->function().raw(); | 1349 initializer = parsed_function->function().raw(); |
| 1350 } else { |
| 1351 initializer ^= field.PrecompiledInitializer(); |
1351 } | 1352 } |
1352 // Invoke the function to evaluate the expression. | 1353 // Invoke the function to evaluate the expression. |
1353 const Object& result = PassiveObject::Handle( | 1354 const Object& result = PassiveObject::Handle( |
1354 DartEntry::InvokeFunction(initializer, Object::empty_array())); | 1355 DartEntry::InvokeFunction(initializer, Object::empty_array())); |
1355 return result.raw(); | 1356 return result.raw(); |
1356 } else { | 1357 } else { |
1357 Thread* const thread = Thread::Current(); | 1358 Thread* const thread = Thread::Current(); |
1358 Isolate* const isolate = thread->isolate(); | 1359 Isolate* const isolate = thread->isolate(); |
1359 StackZone zone(thread); | 1360 StackZone zone(thread); |
1360 const Error& error = | 1361 const Error& error = |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 const Object& result = | 1428 const Object& result = |
1428 PassiveObject::Handle(isolate->object_store()->sticky_error()); | 1429 PassiveObject::Handle(isolate->object_store()->sticky_error()); |
1429 isolate->object_store()->clear_sticky_error(); | 1430 isolate->object_store()->clear_sticky_error(); |
1430 return result.raw(); | 1431 return result.raw(); |
1431 } | 1432 } |
1432 UNREACHABLE(); | 1433 UNREACHABLE(); |
1433 return Object::null(); | 1434 return Object::null(); |
1434 } | 1435 } |
1435 | 1436 |
1436 } // namespace dart | 1437 } // namespace dart |
OLD | NEW |