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 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 return error.raw(); | 922 return error.raw(); |
923 } | 923 } |
924 func.ClearCode(); | 924 func.ClearCode(); |
925 } | 925 } |
926 } | 926 } |
927 } | 927 } |
928 return error.raw(); | 928 return error.raw(); |
929 } | 929 } |
930 | 930 |
931 | 931 |
| 932 RawObject* Compiler::EvaluateStaticInitializer(const Field& field) { |
| 933 ASSERT(field.is_static()); |
| 934 // The VM sets the field's value to transiton_sentinel prior to |
| 935 // evaluating the initializer value. |
| 936 ASSERT(field.value() == Object::transition_sentinel().raw()); |
| 937 Isolate* isolate = Isolate::Current(); |
| 938 StackZone zone(isolate); |
| 939 LongJumpScope jump; |
| 940 if (setjmp(*jump.Set()) == 0) { |
| 941 ParsedFunction* parsed_function = |
| 942 Parser::ParseStaticFieldInitializer(field); |
| 943 |
| 944 parsed_function->AllocateVariables(); |
| 945 // Non-optimized code generator. |
| 946 CompileParsedFunctionHelper(parsed_function, false, Isolate::kNoDeoptId); |
| 947 |
| 948 // Invoke the function to evaluate the expression. |
| 949 const Function& initializer = parsed_function->function(); |
| 950 const Object& result = Object::Handle( |
| 951 DartEntry::InvokeFunction(initializer, Object::empty_array())); |
| 952 return result.raw(); |
| 953 } else { |
| 954 const Error& error = |
| 955 Error::Handle(isolate, isolate->object_store()->sticky_error()); |
| 956 isolate->object_store()->clear_sticky_error(); |
| 957 return error.raw(); |
| 958 } |
| 959 UNREACHABLE(); |
| 960 return Object::null(); |
| 961 } |
| 962 |
| 963 |
| 964 |
932 RawObject* Compiler::ExecuteOnce(SequenceNode* fragment) { | 965 RawObject* Compiler::ExecuteOnce(SequenceNode* fragment) { |
933 Isolate* isolate = Isolate::Current(); | 966 Isolate* isolate = Isolate::Current(); |
934 LongJumpScope jump; | 967 LongJumpScope jump; |
935 if (setjmp(*jump.Set()) == 0) { | 968 if (setjmp(*jump.Set()) == 0) { |
936 if (FLAG_trace_compiler) { | 969 if (FLAG_trace_compiler) { |
937 OS::Print("compiling expression: "); | 970 OS::Print("compiling expression: "); |
938 AstPrinter::PrintNode(fragment); | 971 AstPrinter::PrintNode(fragment); |
939 } | 972 } |
940 | 973 |
941 // Create a dummy function object for the code generator. | 974 // Create a dummy function object for the code generator. |
(...skipping 10 matching lines...) Expand all Loading... |
952 false, // not native | 985 false, // not native |
953 Class::Handle(Type::Handle(Type::Function()).type_class()), | 986 Class::Handle(Type::Handle(Type::Function()).type_class()), |
954 fragment->token_pos())); | 987 fragment->token_pos())); |
955 | 988 |
956 func.set_result_type(Type::Handle(Type::DynamicType())); | 989 func.set_result_type(Type::Handle(Type::DynamicType())); |
957 func.set_num_fixed_parameters(0); | 990 func.set_num_fixed_parameters(0); |
958 func.SetNumOptionalParameters(0, true); | 991 func.SetNumOptionalParameters(0, true); |
959 // Manually generated AST, do not recompile. | 992 // Manually generated AST, do not recompile. |
960 func.SetIsOptimizable(false); | 993 func.SetIsOptimizable(false); |
961 | 994 |
962 // We compile the function here, even though InvokeStatic() below | 995 // We compile the function here, even though InvokeFunction() below |
963 // would compile func automatically. We are checking fewer invariants | 996 // would compile func automatically. We are checking fewer invariants |
964 // here. | 997 // here. |
965 ParsedFunction* parsed_function = new ParsedFunction(isolate, func); | 998 ParsedFunction* parsed_function = new ParsedFunction(isolate, func); |
966 parsed_function->SetNodeSequence(fragment); | 999 parsed_function->SetNodeSequence(fragment); |
967 parsed_function->set_default_parameter_values(Object::null_array()); | 1000 parsed_function->set_default_parameter_values(Object::null_array()); |
968 parsed_function->EnsureExpressionTemp(); | 1001 parsed_function->EnsureExpressionTemp(); |
969 fragment->scope()->AddVariable(parsed_function->expression_temp_var()); | 1002 fragment->scope()->AddVariable(parsed_function->expression_temp_var()); |
970 parsed_function->AllocateVariables(); | 1003 parsed_function->AllocateVariables(); |
971 | 1004 |
972 // Non-optimized code generator. | 1005 // Non-optimized code generator. |
973 CompileParsedFunctionHelper(parsed_function, false, Isolate::kNoDeoptId); | 1006 CompileParsedFunctionHelper(parsed_function, false, Isolate::kNoDeoptId); |
974 | 1007 |
975 const Object& result = Object::Handle( | 1008 const Object& result = Object::Handle( |
976 DartEntry::InvokeFunction(func, Object::empty_array())); | 1009 DartEntry::InvokeFunction(func, Object::empty_array())); |
977 return result.raw(); | 1010 return result.raw(); |
978 } else { | 1011 } else { |
979 const Object& result = | 1012 const Object& result = |
980 Object::Handle(isolate->object_store()->sticky_error()); | 1013 Object::Handle(isolate->object_store()->sticky_error()); |
981 isolate->object_store()->clear_sticky_error(); | 1014 isolate->object_store()->clear_sticky_error(); |
982 return result.raw(); | 1015 return result.raw(); |
983 } | 1016 } |
984 UNREACHABLE(); | 1017 UNREACHABLE(); |
985 return Object::null(); | 1018 return Object::null(); |
986 } | 1019 } |
987 | 1020 |
988 } // namespace dart | 1021 } // namespace dart |
OLD | NEW |