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 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
847 !func.IsRedirectingFactory()) { | 847 !func.IsRedirectingFactory()) { |
848 error = CompileFunction(func); | 848 error = CompileFunction(func); |
849 if (!error.IsNull()) { | 849 if (!error.IsNull()) { |
850 return error.raw(); | 850 return error.raw(); |
851 } | 851 } |
852 } | 852 } |
853 } | 853 } |
854 return error.raw(); | 854 return error.raw(); |
855 } | 855 } |
856 | 856 |
857 static RawPatchClass* MakeTempPatchClass(const Class& cls, | |
858 const String& expr) { | |
859 String& src = String::Handle(String::New("() => ")); | |
860 src = String::Concat(src, expr); | |
861 src = String::Concat(src, Symbols::Semicolon()); | |
862 Script& script = Script::Handle(); | |
863 script = Script::New(Symbols::Empty(), src, RawScript::kSourceTag); | |
864 // In order to tokenize the source, we need to get the key to mangle | |
865 // private names from the library from which the object's class | |
866 // originates. | |
867 const Library& lib = Library::Handle(cls.library()); | |
868 ASSERT(!lib.IsNull()); | |
869 const String& lib_key = String::Handle(lib.private_key()); | |
870 script.Tokenize(lib_key); | |
871 | |
872 const String& src_class_name = String::Handle(Symbols::New(":internal")); | |
873 const Class& src_class = Class::Handle( | |
874 Class::New(src_class_name, script, Scanner::kDummyTokenIndex)); | |
875 src_class.set_is_finalized(); | |
876 src_class.set_library(lib); | |
877 return PatchClass::New(cls, src_class); | |
878 } | |
879 | |
880 | |
881 RawObject* Compiler::Evaluate(const Instance& obj, const String& expr) { | |
hausner
2013/08/14 23:54:09
Should this functionality be here in class Compile
Ivan Posva
2013/08/19 21:32:18
Could you add Evaluate on the Instance C++ class?
hausner
2013/08/19 22:47:38
Done.
| |
882 const Class& obj_cls = Class::Handle(obj.clazz()); | |
883 const PatchClass& temp_class = | |
884 PatchClass::Handle(MakeTempPatchClass(obj_cls, expr)); | |
885 const String& eval_func_name = String::Handle(Symbols::New(":eval")); | |
886 const Function& eval_func = | |
887 Function::Handle(Function::New(eval_func_name, | |
888 RawFunction::kRegularFunction, | |
889 false, // Not static. | |
890 false, // Not const. | |
891 false, // Not abstract. | |
892 false, // Not external. | |
893 temp_class, | |
894 0)); | |
895 eval_func.set_result_type(Type::Handle(Type::DynamicType())); | |
896 eval_func.set_num_fixed_parameters(1); | |
897 eval_func.SetNumOptionalParameters(0, true); | |
898 eval_func.set_is_optimizable(false); | |
899 | |
900 const Array& args = Array::Handle(Array::New(1)); | |
901 args.SetAt(0, obj); | |
902 const Object& result = | |
903 Object::Handle(DartEntry::InvokeFunction(eval_func, args)); | |
904 return result.raw(); | |
905 } | |
906 | |
857 | 907 |
858 RawObject* Compiler::ExecuteOnce(SequenceNode* fragment) { | 908 RawObject* Compiler::ExecuteOnce(SequenceNode* fragment) { |
859 Isolate* isolate = Isolate::Current(); | 909 Isolate* isolate = Isolate::Current(); |
860 LongJump* base = isolate->long_jump_base(); | 910 LongJump* base = isolate->long_jump_base(); |
861 LongJump jump; | 911 LongJump jump; |
862 isolate->set_long_jump_base(&jump); | 912 isolate->set_long_jump_base(&jump); |
863 if (setjmp(*jump.Set()) == 0) { | 913 if (setjmp(*jump.Set()) == 0) { |
864 if (FLAG_trace_compiler) { | 914 if (FLAG_trace_compiler) { |
865 OS::Print("compiling expression: "); | 915 OS::Print("compiling expression: "); |
866 AstPrinter::PrintNode(fragment); | 916 AstPrinter::PrintNode(fragment); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
908 Object::Handle(isolate->object_store()->sticky_error()); | 958 Object::Handle(isolate->object_store()->sticky_error()); |
909 isolate->object_store()->clear_sticky_error(); | 959 isolate->object_store()->clear_sticky_error(); |
910 isolate->set_long_jump_base(base); | 960 isolate->set_long_jump_base(base); |
911 return result.raw(); | 961 return result.raw(); |
912 } | 962 } |
913 UNREACHABLE(); | 963 UNREACHABLE(); |
914 return Object::null(); | 964 return Object::null(); |
915 } | 965 } |
916 | 966 |
917 } // namespace dart | 967 } // namespace dart |
OLD | NEW |