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/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
6 | 6 |
7 #include "vm/compiler.h" | 7 #include "vm/compiler.h" |
8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
10 #include "vm/native_entry.h" | 10 #include "vm/native_entry.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 Class& invocation_mirror_class = | 26 Class& invocation_mirror_class = |
27 Class::Handle(core_lib.LookupClassAllowPrivate(invocation_mirror_name)); | 27 Class::Handle(core_lib.LookupClassAllowPrivate(invocation_mirror_name)); |
28 ASSERT(!invocation_mirror_class.IsNull()); | 28 ASSERT(!invocation_mirror_class.IsNull()); |
29 const String& allocation_function_name = | 29 const String& allocation_function_name = |
30 String::Handle(Symbols::AllocateInvocationMirror()); | 30 String::Handle(Symbols::AllocateInvocationMirror()); |
31 const Function& allocation_function = Function::Handle( | 31 const Function& allocation_function = Function::Handle( |
32 Resolver::ResolveStaticByName(invocation_mirror_class, | 32 Resolver::ResolveStaticByName(invocation_mirror_class, |
33 allocation_function_name, | 33 allocation_function_name, |
34 Resolver::kIsQualified)); | 34 Resolver::kIsQualified)); |
35 ASSERT(!allocation_function.IsNull()); | 35 ASSERT(!allocation_function.IsNull()); |
36 GrowableArray<const Object*> allocation_arguments(3); | 36 const int kNumAllocationArgs = 3; |
37 allocation_arguments.Add(&target_name); | 37 const Array& allocation_args = Array::Handle(Array::New(kNumAllocationArgs)); |
38 allocation_arguments.Add(&arguments_descriptor); | 38 allocation_args.SetAt(0, target_name); |
39 allocation_arguments.Add(&arguments); | 39 allocation_args.SetAt(1, arguments_descriptor); |
40 const Array& kNoArgumentNames = Array::Handle(); | 40 allocation_args.SetAt(2, arguments); |
41 const Object& invocation_mirror = | 41 const Object& invocation_mirror = |
42 Object::Handle(DartEntry::InvokeStatic(allocation_function, | 42 Object::Handle(DartEntry::InvokeStatic(allocation_function, |
43 allocation_arguments, | 43 allocation_args)); |
44 kNoArgumentNames)); | |
45 | 44 |
46 const String& function_name = String::Handle(Symbols::NoSuchMethod()); | 45 const String& function_name = String::Handle(Symbols::NoSuchMethod()); |
47 const int kNumArguments = 2; | 46 const int kNumInvokeArgs = 2; |
48 const int kNumNamedArguments = 0; | 47 const int kNumNamedInvokeArgs = 0; |
49 const Function& function = Function::Handle( | 48 const Function& function = Function::Handle( |
50 Resolver::ResolveDynamic(receiver, | 49 Resolver::ResolveDynamic(receiver, |
51 function_name, | 50 function_name, |
52 kNumArguments, | 51 kNumInvokeArgs, |
53 kNumNamedArguments)); | 52 kNumNamedInvokeArgs)); |
54 ASSERT(!function.IsNull()); | 53 ASSERT(!function.IsNull()); |
55 GrowableArray<const Object*> invoke_arguments(1); | 54 const Array& invoke_arguments = Array::Handle(Array::New(kNumInvokeArgs)); |
56 invoke_arguments.Add(&invocation_mirror); | 55 invoke_arguments.SetAt(0, receiver); |
| 56 invoke_arguments.SetAt(1, invocation_mirror); |
57 const Object& result = | 57 const Object& result = |
58 Object::Handle(DartEntry::InvokeDynamic(receiver, | 58 Object::Handle(DartEntry::InvokeDynamic(function, invoke_arguments)); |
59 function, | |
60 invoke_arguments, | |
61 kNoArgumentNames)); | |
62 if (result.IsError()) { | 59 if (result.IsError()) { |
63 Exceptions::PropagateError(Error::Cast(result)); | 60 Exceptions::PropagateError(Error::Cast(result)); |
64 } | 61 } |
65 return result.raw(); | 62 return result.raw(); |
66 } | 63 } |
67 | 64 |
68 | 65 |
69 DEFINE_NATIVE_ENTRY(InvocationMirror_invoke, 4) { | 66 DEFINE_NATIVE_ENTRY(InvocationMirror_invoke, 4) { |
70 const Instance& receiver = Instance::CheckedHandle(arguments->NativeArgAt(0)); | 67 const Instance& receiver = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
71 const String& fun_name = String::CheckedHandle(arguments->NativeArgAt(1)); | 68 const String& fun_name = String::CheckedHandle(arguments->NativeArgAt(1)); |
(...skipping 16 matching lines...) Expand all Loading... |
88 Resolver::ResolveDynamic(receiver, | 85 Resolver::ResolveDynamic(receiver, |
89 fun_name, | 86 fun_name, |
90 args_desc.Count(), | 87 args_desc.Count(), |
91 args_desc.NamedCount())); | 88 args_desc.NamedCount())); |
92 if (function.IsNull()) { | 89 if (function.IsNull()) { |
93 return InvokeNoSuchMethod(receiver, | 90 return InvokeNoSuchMethod(receiver, |
94 fun_name, | 91 fun_name, |
95 fun_args_desc, | 92 fun_args_desc, |
96 invoke_arguments); | 93 invoke_arguments); |
97 } | 94 } |
98 // TODO(regis): Simply call DartEntry::InvokeDynamic once it is modified to | |
99 // take an arguments descriptor array and an arguments array. | |
100 // Get the entrypoint corresponding to the instance function. This will | |
101 // result in a compilation of the function if it is not already compiled. | |
102 ASSERT(!function.IsNull()); | 95 ASSERT(!function.IsNull()); |
103 if (!function.HasCode()) { | 96 const Object& result = |
104 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 97 Object::Handle(DartEntry::InvokeDynamic(function, |
105 if (!error.IsNull()) { | 98 invoke_arguments, |
106 Exceptions::PropagateError(error); | 99 fun_args_desc)); |
107 } | |
108 } | |
109 // Set up arguments as GrowableArray. | |
110 GrowableArray<const Object*> args(num_arguments); | |
111 for (int i = 0; i < num_arguments; i++) { | |
112 args.Add(&Object::ZoneHandle(invoke_arguments.At(i))); | |
113 } | |
114 // Now call the invoke stub which will invoke the function. | |
115 DartEntry::invokestub entrypoint = reinterpret_cast<DartEntry::invokestub>( | |
116 StubCode::InvokeDartCodeEntryPoint()); | |
117 const Code& code = Code::Handle(function.CurrentCode()); | |
118 ASSERT(!code.IsNull()); | |
119 const Context& context = Context::ZoneHandle( | |
120 Isolate::Current()->object_store()->empty_context()); | |
121 const Object& result = Object::Handle( | |
122 entrypoint(code.EntryPoint(), fun_args_desc, args.data(), context)); | |
123 if (result.IsError()) { | 100 if (result.IsError()) { |
124 Exceptions::PropagateError(Error::Cast(result)); | 101 Exceptions::PropagateError(Error::Cast(result)); |
125 } | 102 } |
126 return result.raw(); | 103 return result.raw(); |
127 } | 104 } |
128 | 105 |
129 } // namespace dart | 106 } // namespace dart |
OLD | NEW |