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 1261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 func.ClearCode(); | 1272 func.ClearCode(); |
1273 } | 1273 } |
1274 } | 1274 } |
1275 } | 1275 } |
1276 return error.raw(); | 1276 return error.raw(); |
1277 } | 1277 } |
1278 | 1278 |
1279 | 1279 |
1280 void Compiler::CompileStaticInitializer(const Field& field) { | 1280 void Compiler::CompileStaticInitializer(const Field& field) { |
1281 ASSERT(field.is_static()); | 1281 ASSERT(field.is_static()); |
1282 if (field.initializer() != Function::null()) { | 1282 if (field.PrecompiledInitializer() != Function::null()) { |
1283 // TODO(rmacnak): Investigate why this happens for _enum_names. | 1283 // TODO(rmacnak): Investigate why this happens for _enum_names. |
1284 OS::Print("Warning: Ignoring repeated request for initializer for %s\n", | 1284 OS::Print("Warning: Ignoring repeated request for initializer for %s\n", |
1285 field.ToCString()); | 1285 field.ToCString()); |
1286 return; | 1286 return; |
1287 } | 1287 } |
1288 ASSERT(field.initializer() == Function::null()); | 1288 ASSERT(field.PrecompiledInitializer() == Function::null()); |
1289 Thread* thread = Thread::Current(); | 1289 Thread* thread = Thread::Current(); |
1290 StackZone zone(thread); | 1290 StackZone zone(thread); |
1291 | 1291 |
1292 ParsedFunction* parsed_function = Parser::ParseStaticFieldInitializer(field); | 1292 ParsedFunction* parsed_function = Parser::ParseStaticFieldInitializer(field); |
1293 | 1293 |
1294 parsed_function->AllocateVariables(); | 1294 parsed_function->AllocateVariables(); |
1295 // Non-optimized code generator. | 1295 // Non-optimized code generator. |
1296 DartCompilationPipeline pipeline; | 1296 DartCompilationPipeline pipeline; |
1297 CompileParsedFunctionHelper(&pipeline, | 1297 CompileParsedFunctionHelper(&pipeline, |
1298 parsed_function, | 1298 parsed_function, |
1299 false, // optimized | 1299 false, // optimized |
1300 Isolate::kNoDeoptId); | 1300 Isolate::kNoDeoptId); |
1301 | 1301 |
1302 const Function& initializer = parsed_function->function(); | 1302 const Function& initializer = parsed_function->function(); |
1303 field.set_initializer(initializer); | 1303 field.SetPrecompiledInitializer(initializer); |
1304 } | 1304 } |
1305 | 1305 |
1306 | 1306 |
1307 RawObject* Compiler::EvaluateStaticInitializer(const Field& field) { | 1307 RawObject* Compiler::EvaluateStaticInitializer(const Field& field) { |
1308 ASSERT(field.is_static()); | 1308 ASSERT(field.is_static()); |
1309 // The VM sets the field's value to transiton_sentinel prior to | 1309 // The VM sets the field's value to transiton_sentinel prior to |
1310 // evaluating the initializer value. | 1310 // evaluating the initializer value. |
1311 ASSERT(field.value() == Object::transition_sentinel().raw()); | 1311 ASSERT(field.StaticValue() == Object::transition_sentinel().raw()); |
1312 LongJumpScope jump; | 1312 LongJumpScope jump; |
1313 if (setjmp(*jump.Set()) == 0) { | 1313 if (setjmp(*jump.Set()) == 0) { |
1314 Function& initializer = Function::Handle(field.initializer()); | |
1315 | |
1316 // Under precompilation, the initializer may have already been compiled, in | 1314 // Under precompilation, the initializer may have already been compiled, in |
1317 // which case use it. Under lazy compilation or early in precompilation, the | 1315 // which case use it. Under lazy compilation or early in precompilation, the |
1318 // initializer has not yet been created, so create it now, but don't bother | 1316 // initializer has not yet been created, so create it now, but don't bother |
1319 // remembering it because it won't be used again. | 1317 // remembering it because it won't be used again. |
1320 if (initializer.IsNull()) { | 1318 Function& initializer = Function::Handle(); |
| 1319 if (!field.HasPrecompiledInitializer()) { |
1321 Thread* const thread = Thread::Current(); | 1320 Thread* const thread = Thread::Current(); |
1322 StackZone zone(thread); | 1321 StackZone zone(thread); |
1323 ParsedFunction* parsed_function = | 1322 ParsedFunction* parsed_function = |
1324 Parser::ParseStaticFieldInitializer(field); | 1323 Parser::ParseStaticFieldInitializer(field); |
1325 | 1324 |
1326 parsed_function->AllocateVariables(); | 1325 parsed_function->AllocateVariables(); |
1327 // Non-optimized code generator. | 1326 // Non-optimized code generator. |
1328 DartCompilationPipeline pipeline; | 1327 DartCompilationPipeline pipeline; |
1329 CompileParsedFunctionHelper(&pipeline, | 1328 CompileParsedFunctionHelper(&pipeline, |
1330 parsed_function, | 1329 parsed_function, |
1331 false, // optimized | 1330 false, // optimized |
1332 Isolate::kNoDeoptId); | 1331 Isolate::kNoDeoptId); |
1333 initializer = parsed_function->function().raw(); | 1332 initializer = parsed_function->function().raw(); |
| 1333 } else { |
| 1334 initializer ^= field.PrecompiledInitializer(); |
1334 } | 1335 } |
1335 // Invoke the function to evaluate the expression. | 1336 // Invoke the function to evaluate the expression. |
1336 return DartEntry::InvokeFunction(initializer, Object::empty_array()); | 1337 return DartEntry::InvokeFunction(initializer, Object::empty_array()); |
1337 } else { | 1338 } else { |
1338 Thread* const thread = Thread::Current(); | 1339 Thread* const thread = Thread::Current(); |
1339 Isolate* const isolate = thread->isolate(); | 1340 Isolate* const isolate = thread->isolate(); |
1340 StackZone zone(thread); | 1341 StackZone zone(thread); |
1341 const Error& error = | 1342 const Error& error = |
1342 Error::Handle(thread->zone(), isolate->object_store()->sticky_error()); | 1343 Error::Handle(thread->zone(), isolate->object_store()->sticky_error()); |
1343 isolate->object_store()->clear_sticky_error(); | 1344 isolate->object_store()->clear_sticky_error(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 const Object& result = | 1407 const Object& result = |
1407 PassiveObject::Handle(isolate->object_store()->sticky_error()); | 1408 PassiveObject::Handle(isolate->object_store()->sticky_error()); |
1408 isolate->object_store()->clear_sticky_error(); | 1409 isolate->object_store()->clear_sticky_error(); |
1409 return result.raw(); | 1410 return result.raw(); |
1410 } | 1411 } |
1411 UNREACHABLE(); | 1412 UNREACHABLE(); |
1412 return Object::null(); | 1413 return Object::null(); |
1413 } | 1414 } |
1414 | 1415 |
1415 } // namespace dart | 1416 } // namespace dart |
OLD | NEW |