OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/dart_entry.h" | 5 #include "vm/dart_entry.h" |
6 | 6 |
7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
8 #include "vm/code_generator.h" | 8 #include "vm/code_generator.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 | 22 |
23 RawObject* DartEntry::InvokeFunction(const Function& function, | 23 RawObject* DartEntry::InvokeFunction(const Function& function, |
24 const Array& arguments) { | 24 const Array& arguments) { |
25 const Array& arguments_descriptor = | 25 const Array& arguments_descriptor = |
26 Array::Handle(ArgumentsDescriptor::New(arguments.Length())); | 26 Array::Handle(ArgumentsDescriptor::New(arguments.Length())); |
27 return InvokeFunction(function, arguments, arguments_descriptor); | 27 return InvokeFunction(function, arguments, arguments_descriptor); |
28 } | 28 } |
29 | 29 |
30 | 30 |
31 RawObject* DartEntry::InvokeFunction(const Function& function, | |
32 const Array& arguments, | |
33 const Array& arguments_descriptor) { | |
34 const Context& context = | |
35 Context::Handle(Isolate::Current()->object_store()->empty_context()); | |
36 return InvokeFunction(function, arguments, arguments_descriptor, context); | |
37 } | |
38 | |
39 | |
40 class ScopedIsolateStackLimits : public ValueObject { | 31 class ScopedIsolateStackLimits : public ValueObject { |
41 public: | 32 public: |
42 explicit ScopedIsolateStackLimits(Isolate* isolate) | 33 explicit ScopedIsolateStackLimits(Isolate* isolate) |
43 : isolate_(isolate) { | 34 : isolate_(isolate) { |
44 ASSERT(isolate_ != NULL); | 35 ASSERT(isolate_ != NULL); |
45 ASSERT(isolate_ == Isolate::Current()); | 36 ASSERT(isolate_ == Isolate::Current()); |
46 uword stack_base = reinterpret_cast<uword>(this); | 37 uword stack_base = reinterpret_cast<uword>(this); |
47 if (stack_base >= isolate_->stack_base()) { | 38 if (stack_base >= isolate_->stack_base()) { |
48 isolate_->SetStackLimitFromStackBase(stack_base); | 39 isolate_->SetStackLimitFromStackBase(stack_base); |
49 } | 40 } |
50 } | 41 } |
51 | 42 |
52 ~ScopedIsolateStackLimits() { | 43 ~ScopedIsolateStackLimits() { |
53 ASSERT(isolate_ == Isolate::Current()); | 44 ASSERT(isolate_ == Isolate::Current()); |
54 uword stack_base = reinterpret_cast<uword>(this); | 45 uword stack_base = reinterpret_cast<uword>(this); |
55 if (isolate_->stack_base() == stack_base) { | 46 if (isolate_->stack_base() == stack_base) { |
56 // Bottomed out. | 47 // Bottomed out. |
57 isolate_->ClearStackLimit(); | 48 isolate_->ClearStackLimit(); |
58 } | 49 } |
59 } | 50 } |
60 | 51 |
61 private: | 52 private: |
62 Isolate* isolate_; | 53 Isolate* isolate_; |
63 }; | 54 }; |
64 | 55 |
65 | 56 |
66 RawObject* DartEntry::InvokeFunction(const Function& function, | 57 RawObject* DartEntry::InvokeFunction(const Function& function, |
67 const Array& arguments, | 58 const Array& arguments, |
68 const Array& arguments_descriptor, | 59 const Array& arguments_descriptor) { |
69 const Context& context) { | |
70 // Get the entrypoint corresponding to the function specified, this | 60 // Get the entrypoint corresponding to the function specified, this |
71 // will result in a compilation of the function if it is not already | 61 // will result in a compilation of the function if it is not already |
72 // compiled. | 62 // compiled. |
73 Isolate* isolate = Isolate::Current(); | 63 Isolate* isolate = Isolate::Current(); |
74 if (!function.HasCode()) { | 64 if (!function.HasCode()) { |
75 const Error& error = Error::Handle( | 65 const Error& error = Error::Handle( |
76 isolate, Compiler::CompileFunction(isolate, function)); | 66 isolate, Compiler::CompileFunction(isolate, function)); |
77 if (!error.IsNull()) { | 67 if (!error.IsNull()) { |
78 return error.raw(); | 68 return error.raw(); |
79 } | 69 } |
80 } | 70 } |
81 // Now Call the invoke stub which will invoke the dart function. | 71 // Now Call the invoke stub which will invoke the dart function. |
82 invokestub entrypoint = reinterpret_cast<invokestub>( | 72 invokestub entrypoint = reinterpret_cast<invokestub>( |
83 isolate->stub_code()->InvokeDartCodeEntryPoint()); | 73 isolate->stub_code()->InvokeDartCodeEntryPoint()); |
84 const Code& code = Code::Handle(isolate, function.CurrentCode()); | 74 const Code& code = Code::Handle(isolate, function.CurrentCode()); |
85 ASSERT(!code.IsNull()); | 75 ASSERT(!code.IsNull()); |
86 ASSERT(Isolate::Current()->no_callback_scope_depth() == 0); | 76 ASSERT(Isolate::Current()->no_callback_scope_depth() == 0); |
87 ScopedIsolateStackLimits stack_limit(isolate); | 77 ScopedIsolateStackLimits stack_limit(isolate); |
88 #if defined(USING_SIMULATOR) | 78 #if defined(USING_SIMULATOR) |
89 #if defined(ARCH_IS_64_BIT) | 79 #if defined(ARCH_IS_64_BIT) |
90 // TODO(zra): Change to intptr_t so we have only one case. | 80 // TODO(zra): Change to intptr_t so we have only one case. |
91 return bit_copy<RawObject*, int64_t>(Simulator::Current()->Call( | 81 return bit_copy<RawObject*, int64_t>(Simulator::Current()->Call( |
92 reinterpret_cast<int64_t>(entrypoint), | 82 reinterpret_cast<int64_t>(entrypoint), |
93 static_cast<int64_t>(code.EntryPoint()), | 83 static_cast<int64_t>(code.EntryPoint()), |
94 reinterpret_cast<int64_t>(&arguments_descriptor), | 84 reinterpret_cast<int64_t>(&arguments_descriptor), |
95 reinterpret_cast<int64_t>(&arguments), | 85 reinterpret_cast<int64_t>(&arguments), |
96 reinterpret_cast<int64_t>(&context))); | 86 0)); |
97 #else | 87 #else |
98 return bit_copy<RawObject*, int64_t>(Simulator::Current()->Call( | 88 return bit_copy<RawObject*, int64_t>(Simulator::Current()->Call( |
99 reinterpret_cast<int32_t>(entrypoint), | 89 reinterpret_cast<int32_t>(entrypoint), |
100 static_cast<int32_t>(code.EntryPoint()), | 90 static_cast<int32_t>(code.EntryPoint()), |
101 reinterpret_cast<int32_t>(&arguments_descriptor), | 91 reinterpret_cast<int32_t>(&arguments_descriptor), |
102 reinterpret_cast<int32_t>(&arguments), | 92 reinterpret_cast<int32_t>(&arguments), |
103 reinterpret_cast<int32_t>(&context))); | 93 0)); |
104 #endif | 94 #endif |
105 #else | 95 #else |
106 return entrypoint(code.EntryPoint(), | 96 return entrypoint(code.EntryPoint(), |
107 arguments_descriptor, | 97 arguments_descriptor, |
108 arguments, | 98 arguments); |
109 context); | |
110 #endif | 99 #endif |
111 } | 100 } |
112 | 101 |
113 | 102 |
114 RawObject* DartEntry::InvokeClosure(const Array& arguments) { | 103 RawObject* DartEntry::InvokeClosure(const Array& arguments) { |
115 const Array& arguments_descriptor = | 104 const Array& arguments_descriptor = |
116 Array::Handle(ArgumentsDescriptor::New(arguments.Length())); | 105 Array::Handle(ArgumentsDescriptor::New(arguments.Length())); |
117 return InvokeClosure(arguments, arguments_descriptor); | 106 return InvokeClosure(arguments, arguments_descriptor); |
118 } | 107 } |
119 | 108 |
120 | 109 |
121 RawObject* DartEntry::InvokeClosure(const Array& arguments, | 110 RawObject* DartEntry::InvokeClosure(const Array& arguments, |
122 const Array& arguments_descriptor) { | 111 const Array& arguments_descriptor) { |
123 Instance& instance = Instance::Handle(); | 112 Instance& instance = Instance::Handle(); |
124 instance ^= arguments.At(0); | 113 instance ^= arguments.At(0); |
125 // Get the entrypoint corresponding to the closure function or to the call | 114 // Get the entrypoint corresponding to the closure function or to the call |
126 // method of the instance. This will result in a compilation of the function | 115 // method of the instance. This will result in a compilation of the function |
127 // if it is not already compiled. | 116 // if it is not already compiled. |
128 Function& function = Function::Handle(); | 117 Function& function = Function::Handle(); |
129 Context& context = Context::Handle(); | 118 if (instance.IsCallable(&function)) { |
130 if (instance.IsCallable(&function, &context)) { | |
131 // Only invoke the function if its arguments are compatible. | 119 // Only invoke the function if its arguments are compatible. |
132 const ArgumentsDescriptor args_desc(arguments_descriptor); | 120 const ArgumentsDescriptor args_desc(arguments_descriptor); |
133 if (function.AreValidArgumentCounts(args_desc.Count(), | 121 if (function.AreValidArgumentCounts(args_desc.Count(), |
134 args_desc.NamedCount(), | 122 args_desc.NamedCount(), |
135 NULL)) { | 123 NULL)) { |
136 // The closure or non-closure object (receiver) is passed as implicit | 124 // The closure or non-closure object (receiver) is passed as implicit |
137 // first argument. It is already included in the arguments array. | 125 // first argument. It is already included in the arguments array. |
138 return InvokeFunction(function, arguments, arguments_descriptor, context); | 126 return InvokeFunction(function, arguments, arguments_descriptor); |
139 } | 127 } |
140 } | 128 } |
141 // There is no compatible 'call' method, so invoke noSuchMethod. | 129 // There is no compatible 'call' method, so invoke noSuchMethod. |
142 return InvokeNoSuchMethod(instance, | 130 return InvokeNoSuchMethod(instance, |
143 Symbols::Call(), | 131 Symbols::Call(), |
144 arguments, | 132 arguments, |
145 arguments_descriptor); | 133 arguments_descriptor); |
146 } | 134 } |
147 | 135 |
148 | 136 |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 const Array& args = Array::Handle(Array::New(kNumArguments)); | 495 const Array& args = Array::Handle(Array::New(kNumArguments)); |
508 args.SetAt(0, map); | 496 args.SetAt(0, map); |
509 args.SetAt(1, key); | 497 args.SetAt(1, key); |
510 args.SetAt(2, value); | 498 args.SetAt(2, value); |
511 const Object& result = Object::Handle(DartEntry::InvokeFunction(function, | 499 const Object& result = Object::Handle(DartEntry::InvokeFunction(function, |
512 args)); | 500 args)); |
513 return result.raw(); | 501 return result.raw(); |
514 } | 502 } |
515 | 503 |
516 } // namespace dart | 504 } // namespace dart |
OLD | NEW |