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/code_generator.h" | 7 #include "vm/code_generator.h" |
8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
10 #include "vm/resolver.h" | 10 #include "vm/resolver.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 ASSERT(instance.raw() == arguments.At(0)); | 93 ASSERT(instance.raw() == arguments.At(0)); |
94 // Get the entrypoint corresponding to the closure function or to the call | 94 // Get the entrypoint corresponding to the closure function or to the call |
95 // method of the instance. This will result in a compilation of the function | 95 // method of the instance. This will result in a compilation of the function |
96 // if it is not already compiled. | 96 // if it is not already compiled. |
97 Function& function = Function::Handle(); | 97 Function& function = Function::Handle(); |
98 Context& context = Context::Handle(); | 98 Context& context = Context::Handle(); |
99 if (!instance.IsCallable(&function, &context)) { | 99 if (!instance.IsCallable(&function, &context)) { |
100 // Set up arguments to include the receiver as the first argument. | 100 // Set up arguments to include the receiver as the first argument. |
101 const String& call_symbol = String::Handle(Symbols::Call()); | 101 const String& call_symbol = String::Handle(Symbols::Call()); |
102 const Object& null_object = Object::Handle(); | 102 const Object& null_object = Object::Handle(); |
103 GrowableArray<const Object*> dart_arguments(5); | 103 const Array& dart_arguments = Array::Handle(Array::New(4)); |
104 dart_arguments.Add(&instance); | 104 dart_arguments.SetAt(0, instance); |
105 dart_arguments.Add(&call_symbol); | 105 dart_arguments.SetAt(1, call_symbol); |
106 dart_arguments.Add(&arguments); // Includes instance. | 106 dart_arguments.SetAt(2, arguments); // Includes instance. |
107 dart_arguments.Add(&null_object); // TODO(regis): Provide names. | 107 dart_arguments.SetAt(3, null_object); // TODO(regis): Provide names. |
108 // If a function "call" with different arguments exists, it will have been | 108 // If a function "call" with different arguments exists, it will have been |
109 // invoked above, so no need to handle this case here. | 109 // invoked above, so no need to handle this case here. |
110 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); | 110 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); |
111 UNREACHABLE(); | 111 UNREACHABLE(); |
112 return Object::null(); | 112 return Object::null(); |
113 } | 113 } |
114 ASSERT(!function.IsNull()); | 114 ASSERT(!function.IsNull()); |
115 if (!function.HasCode()) { | 115 if (!function.HasCode()) { |
116 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 116 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
117 if (!error.IsNull()) { | 117 if (!error.IsNull()) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 // Set terminating null. | 236 // Set terminating null. |
237 descriptor.SetAt((descriptor_len - 1), Object::Handle()); | 237 descriptor.SetAt((descriptor_len - 1), Object::Handle()); |
238 | 238 |
239 // Share the immutable descriptor when possible by canonicalizing it. | 239 // Share the immutable descriptor when possible by canonicalizing it. |
240 descriptor.MakeImmutable(); | 240 descriptor.MakeImmutable(); |
241 descriptor ^= descriptor.Canonicalize(); | 241 descriptor ^= descriptor.Canonicalize(); |
242 return descriptor.raw(); | 242 return descriptor.raw(); |
243 } | 243 } |
244 | 244 |
245 | 245 |
246 RawObject* DartLibraryCalls::ExceptionCreate( | 246 RawObject* DartLibraryCalls::ExceptionCreate(const Library& lib, |
247 const Library& lib, | 247 const String& class_name, |
248 const String& class_name, | 248 const Array& arguments) { |
249 const GrowableArray<const Object*>& arguments) { | |
250 const Class& cls = Class::Handle(lib.LookupClassAllowPrivate(class_name)); | 249 const Class& cls = Class::Handle(lib.LookupClassAllowPrivate(class_name)); |
251 ASSERT(!cls.IsNull()); | 250 ASSERT(!cls.IsNull()); |
252 // For now, we only support a non-parameterized or raw type. | 251 // For now, we only support a non-parameterized or raw type. |
253 const int kNumExtraArgs = 2; // implicit rcvr and construction phase args. | 252 const int kNumExtraArgs = 2; // implicit rcvr and construction phase args. |
254 const Instance& exception_object = Instance::Handle(Instance::New(cls)); | 253 const Instance& exception_object = Instance::Handle(Instance::New(cls)); |
255 const Array& constructor_arguments = | 254 const Array& constructor_arguments = |
256 Array::Handle(Array::New(arguments.length() + kNumExtraArgs)); | 255 Array::Handle(Array::New(arguments.Length() + kNumExtraArgs)); |
257 constructor_arguments.SetAt(0, exception_object); | 256 constructor_arguments.SetAt(0, exception_object); |
258 constructor_arguments.SetAt( | 257 constructor_arguments.SetAt( |
259 1, Smi::Handle(Smi::New(Function::kCtorPhaseAll))); | 258 1, Smi::Handle(Smi::New(Function::kCtorPhaseAll))); |
260 for (intptr_t i = 0; i < arguments.length(); i++) { | 259 Object& obj = Object::Handle(); |
261 constructor_arguments.SetAt((i + kNumExtraArgs), *(arguments[i])); | 260 for (intptr_t i = 0; i < arguments.Length(); i++) { |
| 261 obj = arguments.At(i); |
| 262 constructor_arguments.SetAt((i + kNumExtraArgs), obj); |
262 } | 263 } |
263 | 264 |
264 String& constructor_name = String::Handle( | 265 String& constructor_name = String::Handle( |
265 String::Concat(class_name, Symbols::DotHandle())); | 266 String::Concat(class_name, Symbols::DotHandle())); |
266 Function& constructor = | 267 Function& constructor = |
267 Function::Handle(cls.LookupConstructor(constructor_name)); | 268 Function::Handle(cls.LookupConstructor(constructor_name)); |
268 ASSERT(!constructor.IsNull()); | 269 ASSERT(!constructor.IsNull()); |
269 const Object& retval = | 270 const Object& retval = |
270 Object::Handle(DartEntry::InvokeStatic(constructor, constructor_arguments)); | 271 Object::Handle(DartEntry::InvokeStatic(constructor, constructor_arguments)); |
271 ASSERT(retval.IsNull() || retval.IsError()); | 272 ASSERT(retval.IsNull() || retval.IsError()); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 const String& func_name = String::Handle(Field::GetterName(field_name)); | 396 const String& func_name = String::Handle(Field::GetterName(field_name)); |
396 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); | 397 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); |
397 ASSERT(!func.IsNull()); | 398 ASSERT(!func.IsNull()); |
398 const Array& args = Array::Handle(Array::New(1)); | 399 const Array& args = Array::Handle(Array::New(1)); |
399 args.SetAt(0, port); | 400 args.SetAt(0, port); |
400 return DartEntry::InvokeDynamic(func, args); | 401 return DartEntry::InvokeDynamic(func, args); |
401 } | 402 } |
402 | 403 |
403 | 404 |
404 } // namespace dart | 405 } // namespace dart |
OLD | NEW |