Chromium Code Reviews| 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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 | 594 |
| 595 DART_EXPORT Dart_Handle Dart_HandleMessage(Dart_Port dest_port, | 595 DART_EXPORT Dart_Handle Dart_HandleMessage(Dart_Port dest_port, |
| 596 Dart_Port reply_port, | 596 Dart_Port reply_port, |
| 597 Dart_Message dart_message) { | 597 Dart_Message dart_message) { |
| 598 DARTSCOPE(Isolate::Current()); | 598 DARTSCOPE(Isolate::Current()); |
| 599 | 599 |
| 600 const Instance& msg = Instance::Handle(DeserializeMessage(dart_message)); | 600 const Instance& msg = Instance::Handle(DeserializeMessage(dart_message)); |
| 601 const String& class_name = | 601 const String& class_name = |
| 602 String::Handle(String::NewSymbol("ReceivePortImpl")); | 602 String::Handle(String::NewSymbol("ReceivePortImpl")); |
| 603 const String& function_name = | 603 const String& function_name = |
| 604 String::Handle(String::NewSymbol("handleMessage_")); | 604 String::Handle(String::NewSymbol("_handleMessage")); |
| 605 const int kNumArguments = 3; | 605 const int kNumArguments = 3; |
| 606 const Array& kNoArgumentNames = Array::Handle(); | 606 const Array& kNoArgumentNames = Array::Handle(); |
| 607 const Function& function = Function::Handle( | 607 const Function& function = Function::Handle( |
| 608 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), | 608 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), |
| 609 class_name, | 609 class_name, |
| 610 function_name, | 610 function_name, |
| 611 kNumArguments, | 611 kNumArguments, |
| 612 kNoArgumentNames, | 612 kNoArgumentNames, |
| 613 Resolver::kIsQualified)); | 613 Resolver::kIsQualified)); |
| 614 GrowableArray<const Object*> arguments(kNumArguments); | 614 GrowableArray<const Object*> arguments(kNumArguments); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 637 isolate->StandardRunLoop(); | 637 isolate->StandardRunLoop(); |
| 638 result = Api::Success(); | 638 result = Api::Success(); |
| 639 } else { | 639 } else { |
| 640 SetupErrorResult(&result); | 640 SetupErrorResult(&result); |
| 641 } | 641 } |
| 642 isolate->set_long_jump_base(base); | 642 isolate->set_long_jump_base(base); |
| 643 return result; | 643 return result; |
| 644 } | 644 } |
| 645 | 645 |
| 646 | 646 |
| 647 DART_EXPORT bool Dart_IsolateHasActivePorts() { | |
| 648 // TODO(turnidge): before submitting turn this into a straight field access | |
| 649 // instead of a static method call? | |
| 650 Dart_EnterScope(); | |
| 651 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString("dart:coreimpl")); | |
| 652 if (Dart_IsError(lib)) { | |
| 653 return lib; | |
| 654 } | |
| 655 Dart_Handle count = Dart_InvokeStatic(lib, | |
| 656 Dart_NewString("ReceivePortImpl"), | |
| 657 Dart_NewString("_getNumLivePorts"), | |
| 658 0, | |
| 659 NULL); | |
| 660 DART_CHECK_VALID(count); | |
| 661 int64_t count_value = 0; | |
| 662 Dart_Handle result = Dart_IntegerValue(count, &count_value); | |
| 663 DART_CHECK_VALID(result); | |
| 664 Dart_ExitScope(); | |
| 665 | |
| 666 return count_value > 0; | |
| 667 } | |
| 668 | |
| 669 | |
| 647 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 670 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| 648 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 671 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 649 return reinterpret_cast<uint8_t*>(new_ptr); | 672 return reinterpret_cast<uint8_t*>(new_ptr); |
| 650 } | 673 } |
| 651 | 674 |
| 652 | 675 |
| 653 DART_EXPORT bool Dart_PostIntArray(Dart_Port port, | 676 DART_EXPORT bool Dart_PostIntArray(Dart_Port port, |
| 654 intptr_t len, | 677 intptr_t len, |
| 655 intptr_t* data) { | 678 intptr_t* data) { |
| 656 uint8_t* buffer = NULL; | 679 uint8_t* buffer = NULL; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 667 DARTSCOPE(Isolate::Current()); | 690 DARTSCOPE(Isolate::Current()); |
| 668 const Object& object = Object::Handle(Api::UnwrapHandle(handle)); | 691 const Object& object = Object::Handle(Api::UnwrapHandle(handle)); |
| 669 uint8_t* data = NULL; | 692 uint8_t* data = NULL; |
| 670 SnapshotWriter writer(false, &data, &allocator); | 693 SnapshotWriter writer(false, &data, &allocator); |
| 671 writer.WriteObject(object.raw()); | 694 writer.WriteObject(object.raw()); |
| 672 writer.FinalizeBuffer(); | 695 writer.FinalizeBuffer(); |
| 673 return PortMap::PostMessage(port, kNoReplyPort, data); | 696 return PortMap::PostMessage(port, kNoReplyPort, data); |
| 674 } | 697 } |
| 675 | 698 |
| 676 | 699 |
| 700 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port) { | |
| 701 // TODO(turnidge): before submitting consider grabbing the impl of this from | |
| 702 // lib/isolate.cc instead and sharing the code. | |
| 703 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString("dart:coreimpl")); | |
| 704 if (Dart_IsError(lib)) { | |
| 705 return lib; | |
| 706 } | |
| 707 Dart_Handle arg = Dart_NewInteger(port); | |
| 708 if (Dart_IsError(arg)) { | |
| 709 return arg; | |
| 710 } | |
| 711 Dart_Handle sp_args[1]; | |
| 712 sp_args[0] = arg; | |
| 713 Dart_Handle send_port = Dart_InvokeStatic(lib, | |
| 714 Dart_NewString("SendPortImpl"), | |
| 715 Dart_NewString("_create"), | |
| 716 1, | |
| 717 sp_args); | |
| 718 return send_port; | |
| 719 } | |
| 720 | |
| 721 | |
| 722 DART_EXPORT Dart_Handle Dart_NewReceivePort(Dart_Port port) { | |
| 723 // TODO(turnidge): before submitting consider grabbing the impl of this from | |
| 724 // lib/isolate.cc instead and sharing the code. | |
| 725 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString("dart:coreimpl")); | |
| 726 if (Dart_IsError(lib)) { | |
| 727 return lib; | |
| 728 } | |
| 729 Dart_Handle arg = Dart_NewInteger(port); | |
| 730 if (Dart_IsError(arg)) { | |
| 731 return arg; | |
| 732 } | |
| 733 Dart_Handle rp_args[1]; | |
| 734 rp_args[0] = arg; | |
| 735 Dart_Handle recv_port = Dart_InvokeStatic(lib, | |
| 736 Dart_NewString("ReceivePortImpl"), | |
| 737 Dart_NewString("_create"), | |
| 738 1, | |
| 739 rp_args); | |
| 740 return recv_port; | |
| 741 } | |
| 742 | |
| 743 | |
| 744 DART_EXPORT Dart_Port Dart_GetMainPort() { | |
| 745 Isolate* isolate = Isolate::Current(); | |
| 746 ASSERT(isolate); | |
| 747 return isolate->main_port(); | |
| 748 } | |
| 749 | |
| 677 // --- Scopes ---- | 750 // --- Scopes ---- |
| 678 | 751 |
| 679 | 752 |
| 680 DART_EXPORT void Dart_EnterScope() { | 753 DART_EXPORT void Dart_EnterScope() { |
| 681 Isolate* isolate = Isolate::Current(); | 754 Isolate* isolate = Isolate::Current(); |
| 682 ASSERT(isolate != NULL); | 755 ASSERT(isolate != NULL); |
| 683 ApiState* state = isolate->api_state(); | 756 ApiState* state = isolate->api_state(); |
| 684 ASSERT(state != NULL); | 757 ASSERT(state != NULL); |
| 685 ApiLocalScope* new_scope = new ApiLocalScope(state->top_scope(), | 758 ApiLocalScope* new_scope = new ApiLocalScope(state->top_scope(), |
| 686 reinterpret_cast<uword>(&state)); | 759 reinterpret_cast<uword>(&state)); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 830 if (obj.IsBigint()) { | 903 if (obj.IsBigint()) { |
| 831 Bigint& bigint = Bigint::Handle(); | 904 Bigint& bigint = Bigint::Handle(); |
| 832 bigint ^= obj.raw(); | 905 bigint ^= obj.raw(); |
| 833 if (BigintOperations::FitsIntoInt64(bigint)) { | 906 if (BigintOperations::FitsIntoInt64(bigint)) { |
| 834 *value = BigintOperations::ToInt64(bigint); | 907 *value = BigintOperations::ToInt64(bigint); |
| 835 return Api::Success(); | 908 return Api::Success(); |
| 836 } else { | 909 } else { |
| 837 return Api::Error("Integer too big to fit in int64_t"); | 910 return Api::Error("Integer too big to fit in int64_t"); |
| 838 } | 911 } |
| 839 } | 912 } |
| 913 OS::Print("%s\n", obj.ToCString()); | |
|
Anton Muhin
2011/11/23 19:28:14
nit: debugging stuff
turnidge
2011/11/23 21:45:37
Oops, thanks.
| |
| 840 return Api::Error("Object is not a Integer"); | 914 return Api::Error("Object is not a Integer"); |
| 841 } | 915 } |
| 842 | 916 |
| 843 | 917 |
| 844 DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer, | 918 DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer, |
| 845 const char** value) { | 919 const char** value) { |
| 846 DARTSCOPE(Isolate::Current()); | 920 DARTSCOPE(Isolate::Current()); |
| 847 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); | 921 const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); |
| 848 Bigint& bigint = Bigint::Handle(); | 922 Bigint& bigint = Bigint::Handle(); |
| 849 if (obj.IsSmi() || obj.IsMint()) { | 923 if (obj.IsSmi() || obj.IsMint()) { |
| (...skipping 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2295 } | 2369 } |
| 2296 delete debug_region; | 2370 delete debug_region; |
| 2297 } else { | 2371 } else { |
| 2298 *buffer = NULL; | 2372 *buffer = NULL; |
| 2299 *buffer_size = 0; | 2373 *buffer_size = 0; |
| 2300 } | 2374 } |
| 2301 } | 2375 } |
| 2302 | 2376 |
| 2303 | 2377 |
| 2304 } // namespace dart | 2378 } // namespace dart |
| OLD | NEW |