| 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/code_generator.h" | 10 #include "vm/code_generator.h" |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 // Skips parsing if we need to only install unoptimized code. | 428 // Skips parsing if we need to only install unoptimized code. |
| 429 if (!optimized && !Code::Handle(function.unoptimized_code()).IsNull()) { | 429 if (!optimized && !Code::Handle(function.unoptimized_code()).IsNull()) { |
| 430 InstallUnoptimizedCode(function); | 430 InstallUnoptimizedCode(function); |
| 431 isolate->set_long_jump_base(base); | 431 isolate->set_long_jump_base(base); |
| 432 return Error::null(); | 432 return Error::null(); |
| 433 } | 433 } |
| 434 if (setjmp(*jump.Set()) == 0) { | 434 if (setjmp(*jump.Set()) == 0) { |
| 435 TIMERSCOPE(time_compilation); | 435 TIMERSCOPE(time_compilation); |
| 436 Timer per_compile_timer(FLAG_trace_compiler, "Compilation time"); | 436 Timer per_compile_timer(FLAG_trace_compiler, "Compilation time"); |
| 437 per_compile_timer.Start(); | 437 per_compile_timer.Start(); |
| 438 ParsedFunction* parsed_function = new ParsedFunction(function); | 438 ParsedFunction* parsed_function = new ParsedFunction( |
| 439 Function::ZoneHandle(function.raw())); |
| 439 if (FLAG_trace_compiler) { | 440 if (FLAG_trace_compiler) { |
| 440 OS::Print("Compiling %sfunction: '%s' @ token %"Pd"\n", | 441 OS::Print("Compiling %sfunction: '%s' @ token %"Pd"\n", |
| 441 (optimized ? "optimized " : ""), | 442 (optimized ? "optimized " : ""), |
| 442 function.ToFullyQualifiedCString(), | 443 function.ToFullyQualifiedCString(), |
| 443 function.token_pos()); | 444 function.token_pos()); |
| 444 } | 445 } |
| 445 Parser::ParseFunction(parsed_function); | 446 Parser::ParseFunction(parsed_function); |
| 446 parsed_function->AllocateVariables(); | 447 parsed_function->AllocateVariables(); |
| 447 | 448 |
| 448 const bool success = | 449 const bool success = |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 if (setjmp(*jump.Set()) == 0) { | 555 if (setjmp(*jump.Set()) == 0) { |
| 555 if (FLAG_trace_compiler) { | 556 if (FLAG_trace_compiler) { |
| 556 OS::Print("compiling expression: "); | 557 OS::Print("compiling expression: "); |
| 557 AstPrinter::PrintNode(fragment); | 558 AstPrinter::PrintNode(fragment); |
| 558 } | 559 } |
| 559 | 560 |
| 560 // Create a dummy function object for the code generator. | 561 // Create a dummy function object for the code generator. |
| 561 // The function needs to be associated with a named Class: the interface | 562 // The function needs to be associated with a named Class: the interface |
| 562 // Function fits the bill. | 563 // Function fits the bill. |
| 563 const char* kEvalConst = "eval_const"; | 564 const char* kEvalConst = "eval_const"; |
| 564 const Function& func = Function::Handle(Function::New( | 565 const Function& func = Function::ZoneHandle(Function::New( |
| 565 String::Handle(Symbols::New(kEvalConst)), | 566 String::Handle(Symbols::New(kEvalConst)), |
| 566 RawFunction::kConstImplicitGetter, | 567 RawFunction::kConstImplicitGetter, |
| 567 true, // static function. | 568 true, // static function. |
| 568 false, // not const function. | 569 false, // not const function. |
| 569 false, // not abstract | 570 false, // not abstract |
| 570 false, // not external. | 571 false, // not external. |
| 571 Class::Handle(Type::Handle(Type::Function()).type_class()), | 572 Class::Handle(Type::Handle(Type::Function()).type_class()), |
| 572 fragment->token_pos())); | 573 fragment->token_pos())); |
| 573 | 574 |
| 574 func.set_result_type(Type::Handle(Type::DynamicType())); | 575 func.set_result_type(Type::Handle(Type::DynamicType())); |
| 575 func.set_num_fixed_parameters(0); | 576 func.set_num_fixed_parameters(0); |
| 576 func.SetNumOptionalParameters(0, true); | 577 func.SetNumOptionalParameters(0, true); |
| 577 // Manually generated AST, do not recompile. | 578 // Manually generated AST, do not recompile. |
| 578 func.set_is_optimizable(false); | 579 func.set_is_optimizable(false); |
| 579 | 580 |
| 580 // We compile the function here, even though InvokeStatic() below | 581 // We compile the function here, even though InvokeStatic() below |
| 581 // would compile func automatically. We are checking fewer invariants | 582 // would compile func automatically. We are checking fewer invariants |
| 582 // here. | 583 // here. |
| 583 ParsedFunction* parsed_function = new ParsedFunction(func); | 584 ParsedFunction* parsed_function = new ParsedFunction(func); |
| 584 parsed_function->SetNodeSequence(fragment); | 585 parsed_function->SetNodeSequence(fragment); |
| 585 parsed_function->set_default_parameter_values(Array::Handle()); | 586 parsed_function->set_default_parameter_values(Array::ZoneHandle()); |
| 586 parsed_function->set_expression_temp_var( | 587 parsed_function->set_expression_temp_var( |
| 587 ParsedFunction::CreateExpressionTempVar(0)); | 588 ParsedFunction::CreateExpressionTempVar(0)); |
| 588 fragment->scope()->AddVariable(parsed_function->expression_temp_var()); | 589 fragment->scope()->AddVariable(parsed_function->expression_temp_var()); |
| 589 parsed_function->AllocateVariables(); | 590 parsed_function->AllocateVariables(); |
| 590 | 591 |
| 591 // Non-optimized code generator. | 592 // Non-optimized code generator. |
| 592 CompileParsedFunctionHelper(*parsed_function, false); | 593 CompileParsedFunctionHelper(*parsed_function, false); |
| 593 | 594 |
| 594 GrowableArray<const Object*> arguments; // no arguments. | 595 GrowableArray<const Object*> arguments; // no arguments. |
| 595 const Array& kNoArgumentNames = Array::Handle(); | 596 const Array& kNoArgumentNames = Array::Handle(); |
| 596 Object& result = Object::Handle(); | 597 Object& result = Object::Handle(); |
| 597 result = DartEntry::InvokeStatic(func, | 598 result = DartEntry::InvokeStatic(func, |
| 598 arguments, | 599 arguments, |
| 599 kNoArgumentNames); | 600 kNoArgumentNames); |
| 600 isolate->set_long_jump_base(base); | 601 isolate->set_long_jump_base(base); |
| 601 return result.raw(); | 602 return result.raw(); |
| 602 } else { | 603 } else { |
| 603 Object& result = Object::Handle(); | 604 Object& result = Object::Handle(); |
| 604 result = isolate->object_store()->sticky_error(); | 605 result = isolate->object_store()->sticky_error(); |
| 605 isolate->object_store()->clear_sticky_error(); | 606 isolate->object_store()->clear_sticky_error(); |
| 606 isolate->set_long_jump_base(base); | 607 isolate->set_long_jump_base(base); |
| 607 return result.raw(); | 608 return result.raw(); |
| 608 } | 609 } |
| 609 UNREACHABLE(); | 610 UNREACHABLE(); |
| 610 return Object::null(); | 611 return Object::null(); |
| 611 } | 612 } |
| 612 | 613 |
| 613 } // namespace dart | 614 } // namespace dart |
| OLD | NEW |