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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 const Code& code = Code::Handle(function.CurrentCode()); | 124 const Code& code = Code::Handle(function.CurrentCode()); |
125 ASSERT(!code.IsNull()); | 125 ASSERT(!code.IsNull()); |
126 return entrypoint(code.EntryPoint(), | 126 return entrypoint(code.EntryPoint(), |
127 arguments_descriptor, | 127 arguments_descriptor, |
128 arguments, | 128 arguments, |
129 context); | 129 context); |
130 } | 130 } |
131 } | 131 } |
132 // There is no compatible 'call' method, so invoke noSuchMethod. | 132 // There is no compatible 'call' method, so invoke noSuchMethod. |
133 return InvokeNoSuchMethod(instance, | 133 return InvokeNoSuchMethod(instance, |
134 String::Handle(Symbols::Call()), | 134 Symbols::Call(), |
135 arguments, | 135 arguments, |
136 arguments_descriptor); | 136 arguments_descriptor); |
137 } | 137 } |
138 | 138 |
139 | 139 |
140 RawObject* DartEntry::InvokeNoSuchMethod(const Instance& receiver, | 140 RawObject* DartEntry::InvokeNoSuchMethod(const Instance& receiver, |
141 const String& target_name, | 141 const String& target_name, |
142 const Array& arguments, | 142 const Array& arguments, |
143 const Array& arguments_descriptor) { | 143 const Array& arguments_descriptor) { |
144 ASSERT(receiver.raw() == arguments.At(0)); | 144 ASSERT(receiver.raw() == arguments.At(0)); |
145 // Allocate an InvocationMirror object. | 145 // Allocate an InvocationMirror object. |
146 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 146 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
147 const String& invocation_mirror_name = | 147 Class& invocation_mirror_class = Class::Handle( |
148 String::Handle(Symbols::InvocationMirror()); | 148 core_lib.LookupClassAllowPrivate(Symbols::InvocationMirror())); |
149 Class& invocation_mirror_class = | |
150 Class::Handle(core_lib.LookupClassAllowPrivate(invocation_mirror_name)); | |
151 ASSERT(!invocation_mirror_class.IsNull()); | 149 ASSERT(!invocation_mirror_class.IsNull()); |
152 const String& allocation_function_name = | |
153 String::Handle(Symbols::AllocateInvocationMirror()); | |
154 const Function& allocation_function = Function::Handle( | 150 const Function& allocation_function = Function::Handle( |
155 Resolver::ResolveStaticByName(invocation_mirror_class, | 151 Resolver::ResolveStaticByName(invocation_mirror_class, |
156 allocation_function_name, | 152 Symbols::AllocateInvocationMirror(), |
157 Resolver::kIsQualified)); | 153 Resolver::kIsQualified)); |
158 ASSERT(!allocation_function.IsNull()); | 154 ASSERT(!allocation_function.IsNull()); |
159 const int kNumAllocationArgs = 3; | 155 const int kNumAllocationArgs = 3; |
160 const Array& allocation_args = Array::Handle(Array::New(kNumAllocationArgs)); | 156 const Array& allocation_args = Array::Handle(Array::New(kNumAllocationArgs)); |
161 allocation_args.SetAt(0, target_name); | 157 allocation_args.SetAt(0, target_name); |
162 allocation_args.SetAt(1, arguments_descriptor); | 158 allocation_args.SetAt(1, arguments_descriptor); |
163 allocation_args.SetAt(2, arguments); | 159 allocation_args.SetAt(2, arguments); |
164 const Object& invocation_mirror = Object::Handle( | 160 const Object& invocation_mirror = Object::Handle( |
165 InvokeStatic(allocation_function, allocation_args)); | 161 InvokeStatic(allocation_function, allocation_args)); |
166 | 162 |
167 // Now use the invocation mirror object and invoke NoSuchMethod. | 163 // Now use the invocation mirror object and invoke NoSuchMethod. |
168 const String& function_name = String::Handle(Symbols::NoSuchMethod()); | |
169 const int kNumArguments = 2; | 164 const int kNumArguments = 2; |
170 const int kNumNamedArguments = 0; | 165 const int kNumNamedArguments = 0; |
171 const Function& function = Function::Handle( | 166 const Function& function = Function::Handle( |
172 Resolver::ResolveDynamic(receiver, | 167 Resolver::ResolveDynamic(receiver, |
173 function_name, | 168 Symbols::NoSuchMethod(), |
174 kNumArguments, | 169 kNumArguments, |
175 kNumNamedArguments)); | 170 kNumNamedArguments)); |
176 ASSERT(!function.IsNull()); | 171 ASSERT(!function.IsNull()); |
177 const Array& args = Array::Handle(Array::New(kNumArguments)); | 172 const Array& args = Array::Handle(Array::New(kNumArguments)); |
178 args.SetAt(0, receiver); | 173 args.SetAt(0, receiver); |
179 args.SetAt(1, invocation_mirror); | 174 args.SetAt(1, invocation_mirror); |
180 return InvokeDynamic(function, args); | 175 return InvokeDynamic(function, args); |
181 } | 176 } |
182 | 177 |
183 | 178 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 constructor_arguments.SetAt(0, exception_object); | 304 constructor_arguments.SetAt(0, exception_object); |
310 constructor_arguments.SetAt( | 305 constructor_arguments.SetAt( |
311 1, Smi::Handle(Smi::New(Function::kCtorPhaseAll))); | 306 1, Smi::Handle(Smi::New(Function::kCtorPhaseAll))); |
312 Object& obj = Object::Handle(); | 307 Object& obj = Object::Handle(); |
313 for (intptr_t i = 0; i < arguments.Length(); i++) { | 308 for (intptr_t i = 0; i < arguments.Length(); i++) { |
314 obj = arguments.At(i); | 309 obj = arguments.At(i); |
315 constructor_arguments.SetAt((i + kNumExtraArgs), obj); | 310 constructor_arguments.SetAt((i + kNumExtraArgs), obj); |
316 } | 311 } |
317 | 312 |
318 String& constructor_name = String::Handle( | 313 String& constructor_name = String::Handle( |
319 String::Concat(class_name, Symbols::DotHandle())); | 314 String::Concat(class_name, Symbols::Dot())); |
320 Function& constructor = | 315 Function& constructor = |
321 Function::Handle(cls.LookupConstructor(constructor_name)); | 316 Function::Handle(cls.LookupConstructor(constructor_name)); |
322 ASSERT(!constructor.IsNull()); | 317 ASSERT(!constructor.IsNull()); |
323 const Object& retval = | 318 const Object& retval = |
324 Object::Handle(DartEntry::InvokeStatic(constructor, constructor_arguments)); | 319 Object::Handle(DartEntry::InvokeStatic(constructor, constructor_arguments)); |
325 ASSERT(retval.IsNull() || retval.IsError()); | 320 ASSERT(retval.IsNull() || retval.IsError()); |
326 if (retval.IsError()) { | 321 if (retval.IsError()) { |
327 return retval.raw(); | 322 return retval.raw(); |
328 } | 323 } |
329 return exception_object.raw(); | 324 return exception_object.raw(); |
330 } | 325 } |
331 | 326 |
332 | 327 |
333 RawObject* DartLibraryCalls::ToString(const Instance& receiver) { | 328 RawObject* DartLibraryCalls::ToString(const Instance& receiver) { |
334 const String& function_name = | |
335 String::Handle(Symbols::New("toString")); | |
336 const int kNumArguments = 1; // Receiver. | 329 const int kNumArguments = 1; // Receiver. |
337 const int kNumNamedArguments = 0; // None. | 330 const int kNumNamedArguments = 0; // None. |
338 const Function& function = Function::Handle( | 331 const Function& function = Function::Handle( |
339 Resolver::ResolveDynamic(receiver, | 332 Resolver::ResolveDynamic(receiver, |
340 function_name, | 333 Symbols::toString(), |
341 kNumArguments, | 334 kNumArguments, |
342 kNumNamedArguments)); | 335 kNumNamedArguments)); |
343 ASSERT(!function.IsNull()); | 336 ASSERT(!function.IsNull()); |
344 const Array& args = Array::Handle(Array::New(kNumArguments)); | 337 const Array& args = Array::Handle(Array::New(kNumArguments)); |
345 args.SetAt(0, receiver); | 338 args.SetAt(0, receiver); |
346 const Object& result = Object::Handle(DartEntry::InvokeDynamic(function, | 339 const Object& result = Object::Handle(DartEntry::InvokeDynamic(function, |
347 args)); | 340 args)); |
348 ASSERT(result.IsInstance() || result.IsError()); | 341 ASSERT(result.IsInstance() || result.IsError()); |
349 return result.raw(); | 342 return result.raw(); |
350 } | 343 } |
351 | 344 |
352 | 345 |
353 RawObject* DartLibraryCalls::Equals(const Instance& left, | 346 RawObject* DartLibraryCalls::Equals(const Instance& left, |
354 const Instance& right) { | 347 const Instance& right) { |
355 const int kNumArguments = 2; | 348 const int kNumArguments = 2; |
356 const int kNumNamedArguments = 0; | 349 const int kNumNamedArguments = 0; |
357 const Function& function = Function::Handle( | 350 const Function& function = Function::Handle( |
358 Resolver::ResolveDynamic(left, | 351 Resolver::ResolveDynamic(left, |
359 Symbols::EqualOperatorHandle(), | 352 Symbols::EqualOperator(), |
360 kNumArguments, | 353 kNumArguments, |
361 kNumNamedArguments)); | 354 kNumNamedArguments)); |
362 ASSERT(!function.IsNull()); | 355 ASSERT(!function.IsNull()); |
363 | 356 |
364 const Array& args = Array::Handle(Array::New(kNumArguments)); | 357 const Array& args = Array::Handle(Array::New(kNumArguments)); |
365 args.SetAt(0, left); | 358 args.SetAt(0, left); |
366 args.SetAt(1, right); | 359 args.SetAt(1, right); |
367 const Object& result = Object::Handle(DartEntry::InvokeDynamic(function, | 360 const Object& result = Object::Handle(DartEntry::InvokeDynamic(function, |
368 args)); | 361 args)); |
369 ASSERT(result.IsInstance() || result.IsError()); | 362 ASSERT(result.IsInstance() || result.IsError()); |
370 return result.raw(); | 363 return result.raw(); |
371 } | 364 } |
372 | 365 |
373 | 366 |
374 RawObject* DartLibraryCalls::LookupReceivePort(Dart_Port port_id) { | 367 RawObject* DartLibraryCalls::LookupReceivePort(Dart_Port port_id) { |
375 Isolate* isolate = Isolate::Current(); | 368 Isolate* isolate = Isolate::Current(); |
376 Function& function = | 369 Function& function = |
377 Function::Handle(isolate, | 370 Function::Handle(isolate, |
378 isolate->object_store()->lookup_receive_port_function()); | 371 isolate->object_store()->lookup_receive_port_function()); |
379 const int kNumArguments = 1; | 372 const int kNumArguments = 1; |
380 if (function.IsNull()) { | 373 if (function.IsNull()) { |
381 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); | 374 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); |
382 ASSERT(!isolate_lib.IsNull()); | 375 ASSERT(!isolate_lib.IsNull()); |
383 const String& public_class_name = | |
384 String::Handle(Symbols::New("_ReceivePortImpl")); | |
385 const String& class_name = | 376 const String& class_name = |
386 String::Handle(isolate_lib.PrivateName(public_class_name)); | 377 String::Handle(isolate_lib.PrivateName(Symbols::_ReceivePortImpl())); |
387 const String& function_name = | |
388 String::Handle(Symbols::New("_lookupReceivePort")); | |
389 const Array& kNoArgumentNames = Array::Handle(); | |
390 function = Resolver::ResolveStatic(isolate_lib, | 378 function = Resolver::ResolveStatic(isolate_lib, |
391 class_name, | 379 class_name, |
392 function_name, | 380 Symbols::_lookupReceivePort(), |
393 kNumArguments, | 381 kNumArguments, |
394 kNoArgumentNames, | 382 Object::empty_array(), |
395 Resolver::kIsQualified); | 383 Resolver::kIsQualified); |
396 isolate->object_store()->set_lookup_receive_port_function(function); | 384 isolate->object_store()->set_lookup_receive_port_function(function); |
397 } | 385 } |
398 const Array& args = Array::Handle(Array::New(kNumArguments)); | 386 const Array& args = Array::Handle(Array::New(kNumArguments)); |
399 args.SetAt(0, Integer::Handle(Integer::New(port_id))); | 387 args.SetAt(0, Integer::Handle(Integer::New(port_id))); |
400 const Object& result = | 388 const Object& result = |
401 Object::Handle(DartEntry::InvokeStatic(function, args)); | 389 Object::Handle(DartEntry::InvokeStatic(function, args)); |
402 return result.raw(); | 390 return result.raw(); |
403 } | 391 } |
404 | 392 |
405 | 393 |
406 RawObject* DartLibraryCalls::HandleMessage(const Object& receive_port, | 394 RawObject* DartLibraryCalls::HandleMessage(const Object& receive_port, |
407 Dart_Port reply_port_id, | 395 Dart_Port reply_port_id, |
408 const Instance& message) { | 396 const Instance& message) { |
409 Isolate* isolate = Isolate::Current(); | 397 Isolate* isolate = Isolate::Current(); |
410 Function& function = | 398 Function& function = |
411 Function::Handle(isolate, | 399 Function::Handle(isolate, |
412 isolate->object_store()->handle_message_function()); | 400 isolate->object_store()->handle_message_function()); |
413 const int kNumArguments = 3; | 401 const int kNumArguments = 3; |
414 if (function.IsNull()) { | 402 if (function.IsNull()) { |
415 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); | 403 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); |
416 ASSERT(!isolate_lib.IsNull()); | 404 ASSERT(!isolate_lib.IsNull()); |
417 const String& public_class_name = | |
418 String::Handle(Symbols::New("_ReceivePortImpl")); | |
419 const String& class_name = | 405 const String& class_name = |
420 String::Handle(isolate_lib.PrivateName(public_class_name)); | 406 String::Handle(isolate_lib.PrivateName(Symbols::_ReceivePortImpl())); |
421 const String& function_name = | |
422 String::Handle(Symbols::New("_handleMessage")); | |
423 const Array& kNoArgumentNames = Array::Handle(); | |
424 function = Resolver::ResolveStatic(isolate_lib, | 407 function = Resolver::ResolveStatic(isolate_lib, |
425 class_name, | 408 class_name, |
426 function_name, | 409 Symbols::_handleMessage(), |
427 kNumArguments, | 410 kNumArguments, |
428 kNoArgumentNames, | 411 Object::empty_array(), |
429 Resolver::kIsQualified); | 412 Resolver::kIsQualified); |
430 isolate->object_store()->set_handle_message_function(function); | 413 isolate->object_store()->set_handle_message_function(function); |
431 } | 414 } |
432 const Array& args = Array::Handle(isolate, Array::New(kNumArguments)); | 415 const Array& args = Array::Handle(isolate, Array::New(kNumArguments)); |
433 args.SetAt(0, receive_port); | 416 args.SetAt(0, receive_port); |
434 args.SetAt(1, Integer::Handle(isolate, Integer::New(reply_port_id))); | 417 args.SetAt(1, Integer::Handle(isolate, Integer::New(reply_port_id))); |
435 args.SetAt(2, message); | 418 args.SetAt(2, message); |
436 const Object& result = | 419 const Object& result = |
437 Object::Handle(isolate, DartEntry::InvokeStatic(function, args)); | 420 Object::Handle(isolate, DartEntry::InvokeStatic(function, args)); |
438 ASSERT(result.IsNull() || result.IsError()); | 421 ASSERT(result.IsNull() || result.IsError()); |
439 return result.raw(); | 422 return result.raw(); |
440 } | 423 } |
441 | 424 |
442 | 425 |
443 RawObject* DartLibraryCalls::NewSendPort(intptr_t port_id) { | 426 RawObject* DartLibraryCalls::NewSendPort(intptr_t port_id) { |
444 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); | 427 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); |
445 ASSERT(!isolate_lib.IsNull()); | 428 ASSERT(!isolate_lib.IsNull()); |
446 const String& public_class_name = | |
447 String::Handle(String::New("_SendPortImpl")); | |
448 const String& class_name = | 429 const String& class_name = |
449 String::Handle(isolate_lib.PrivateName(public_class_name)); | 430 String::Handle(isolate_lib.PrivateName(Symbols::_SendPortImpl())); |
450 const String& function_name = String::Handle(Symbols::New("_create")); | |
451 const int kNumArguments = 1; | 431 const int kNumArguments = 1; |
452 const Array& kNoArgumentNames = Array::Handle(); | |
453 const Function& function = Function::Handle( | 432 const Function& function = Function::Handle( |
454 Resolver::ResolveStatic(isolate_lib, | 433 Resolver::ResolveStatic(isolate_lib, |
455 class_name, | 434 class_name, |
456 function_name, | 435 Symbols::_create(), |
457 kNumArguments, | 436 kNumArguments, |
458 kNoArgumentNames, | 437 Object::empty_array(), |
459 Resolver::kIsQualified)); | 438 Resolver::kIsQualified)); |
460 const Array& args = Array::Handle(Array::New(kNumArguments)); | 439 const Array& args = Array::Handle(Array::New(kNumArguments)); |
461 args.SetAt(0, Integer::Handle(Integer::New(port_id))); | 440 args.SetAt(0, Integer::Handle(Integer::New(port_id))); |
462 return DartEntry::InvokeStatic(function, args); | 441 return DartEntry::InvokeStatic(function, args); |
463 } | 442 } |
464 | 443 |
465 | 444 |
466 RawObject* DartLibraryCalls::MapSetAt(const Instance& map, | 445 RawObject* DartLibraryCalls::MapSetAt(const Instance& map, |
467 const Instance& key, | 446 const Instance& key, |
468 const Instance& value) { | 447 const Instance& value) { |
469 String& name = String::Handle(Symbols::AssignIndexToken()); | |
470 const int kNumArguments = 3; | 448 const int kNumArguments = 3; |
471 const Function& function = Function::Handle( | 449 const Function& function = Function::Handle( |
472 Resolver::ResolveDynamic(map, name, kNumArguments, 0)); | 450 Resolver::ResolveDynamic(map, |
| 451 Symbols::AssignIndexToken(), |
| 452 kNumArguments, |
| 453 0)); |
473 ASSERT(!function.IsNull()); | 454 ASSERT(!function.IsNull()); |
474 const Array& args = Array::Handle(Array::New(kNumArguments)); | 455 const Array& args = Array::Handle(Array::New(kNumArguments)); |
475 args.SetAt(0, map); | 456 args.SetAt(0, map); |
476 args.SetAt(1, key); | 457 args.SetAt(1, key); |
477 args.SetAt(2, value); | 458 args.SetAt(2, value); |
478 const Object& result = Object::Handle(DartEntry::InvokeDynamic(function, | 459 const Object& result = Object::Handle(DartEntry::InvokeDynamic(function, |
479 args)); | 460 args)); |
480 return result.raw(); | 461 return result.raw(); |
481 } | 462 } |
482 | 463 |
483 | 464 |
484 RawObject* DartLibraryCalls::PortGetId(const Instance& port) { | 465 RawObject* DartLibraryCalls::PortGetId(const Instance& port) { |
485 const String& field_name = String::Handle(Symbols::New("_id")); | |
486 const Class& cls = Class::Handle(port.clazz()); | 466 const Class& cls = Class::Handle(port.clazz()); |
487 const String& func_name = String::Handle(Field::GetterName(field_name)); | 467 const String& func_name = String::Handle(Field::GetterName(Symbols::_id())); |
488 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); | 468 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); |
489 ASSERT(!func.IsNull()); | 469 ASSERT(!func.IsNull()); |
490 const Array& args = Array::Handle(Array::New(1)); | 470 const Array& args = Array::Handle(Array::New(1)); |
491 args.SetAt(0, port); | 471 args.SetAt(0, port); |
492 return DartEntry::InvokeDynamic(func, args); | 472 return DartEntry::InvokeDynamic(func, args); |
493 } | 473 } |
494 | 474 |
495 | 475 |
496 } // namespace dart | 476 } // namespace dart |
OLD | NEW |