Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: runtime/vm/object.cc

Issue 10832401: Gentle start with removing explicit interfaces (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 cls = Class::New<ExternalFloat64Array>(); 746 cls = Class::New<ExternalFloat64Array>();
747 object_store->set_external_float64_array_class(cls); 747 object_store->set_external_float64_array_class(cls);
748 name = Symbols::_ExternalFloat64Array(); 748 name = Symbols::_ExternalFloat64Array();
749 RegisterPrivateClass(cls, name, core_lib); 749 RegisterPrivateClass(cls, name, core_lib);
750 750
751 // Set the super type of class Stacktrace to Object type so that the 751 // Set the super type of class Stacktrace to Object type so that the
752 // 'toString' method is implemented. 752 // 'toString' method is implemented.
753 cls = object_store->stacktrace_class(); 753 cls = object_store->stacktrace_class();
754 cls.set_super_type(type); 754 cls.set_super_type(type);
755 755
756 cls = CreateAndRegisterInterface("Function", script, core_lib); 756 // Note: The abstract class Function is represented by VM class
757 // DartFunction, not VM class Function.
758 name = Symbols::Function();
759 cls = Class::New<DartFunction>();
760 RegisterClass(cls, name, core_lib);
757 pending_classes.Add(cls, Heap::kOld); 761 pending_classes.Add(cls, Heap::kOld);
758 type = Type::NewNonParameterizedType(cls); 762 type = Type::NewNonParameterizedType(cls);
759 object_store->set_function_interface(type); 763 object_store->set_function_type(type);
760 764
761 cls = CreateAndRegisterInterface("num", script, core_lib); 765 cls = Class::New<Number>();
762 pending_classes.Add(cls, Heap::kOld); 766 name = Symbols::Number();
767 RegisterClass(cls, name, core_lib);
763 type = Type::NewNonParameterizedType(cls); 768 type = Type::NewNonParameterizedType(cls);
764 object_store->set_number_interface(type); 769 object_store->set_number_type(type);
765 770
766 cls = CreateAndRegisterInterface("int", script, core_lib); 771 cls = CreateAndRegisterInterface("int", script, core_lib);
767 pending_classes.Add(cls, Heap::kOld); 772 pending_classes.Add(cls, Heap::kOld);
768 type = Type::NewNonParameterizedType(cls); 773 type = Type::NewNonParameterizedType(cls);
769 object_store->set_int_interface(type); 774 object_store->set_int_interface(type);
770 775
771 cls = CreateAndRegisterInterface("double", script, core_lib); 776 cls = CreateAndRegisterInterface("double", script, core_lib);
772 pending_classes.Add(cls, Heap::kOld); 777 pending_classes.Add(cls, Heap::kOld);
773 type = Type::NewNonParameterizedType(cls); 778 type = Type::NewNonParameterizedType(cls);
774 object_store->set_double_interface(type); 779 object_store->set_double_interface(type);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 1031
1027 cls = Class::New<Bool>(); 1032 cls = Class::New<Bool>();
1028 object_store->set_bool_class(cls); 1033 object_store->set_bool_class(cls);
1029 1034
1030 cls = Class::New<Stacktrace>(); 1035 cls = Class::New<Stacktrace>();
1031 object_store->set_stacktrace_class(cls); 1036 object_store->set_stacktrace_class(cls);
1032 1037
1033 cls = Class::New<JSRegExp>(); 1038 cls = Class::New<JSRegExp>();
1034 object_store->set_jsregexp_class(cls); 1039 object_store->set_jsregexp_class(cls);
1035 1040
1041 // Some classes are not stored in the object store. Yet we still need to
1042 // create their Class object so that they get put into the class_table
1043 // (as a side effect of Class::New()).
1044 cls = Class::New<DartFunction>();
1045 cls = Class::New<Number>();
1046
1036 cls = Class::New<WeakProperty>(); 1047 cls = Class::New<WeakProperty>();
1037 object_store->set_weak_property_class(cls); 1048 object_store->set_weak_property_class(cls);
1038 1049
1039 // Allocate pre-initialized values. 1050 // Allocate pre-initialized values.
1040 Bool& bool_value = Bool::Handle(); 1051 Bool& bool_value = Bool::Handle();
1041 bool_value = Bool::New(true); 1052 bool_value = Bool::New(true);
1042 object_store->set_true_value(bool_value); 1053 object_store->set_true_value(bool_value);
1043 bool_value = Bool::New(false); 1054 bool_value = Bool::New(false);
1044 object_store->set_false_value(bool_value); 1055 object_store->set_false_value(bool_value);
1045 } 1056 }
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 const Array& empty_array = Array::Handle(Object::empty_array()); 1749 const Array& empty_array = Array::Handle(Object::empty_array());
1739 ASSERT(!super_type.IsNull()); 1750 ASSERT(!super_type.IsNull());
1740 result.set_super_type(super_type); 1751 result.set_super_type(super_type);
1741 result.set_signature_function(signature_function); 1752 result.set_signature_function(signature_function);
1742 result.set_type_parameters(type_parameters); 1753 result.set_type_parameters(type_parameters);
1743 result.SetFields(empty_array); 1754 result.SetFields(empty_array);
1744 result.SetFunctions(empty_array); 1755 result.SetFunctions(empty_array);
1745 result.set_type_arguments_instance_field_offset( 1756 result.set_type_arguments_instance_field_offset(
1746 Closure::type_arguments_offset()); 1757 Closure::type_arguments_offset());
1747 // Implements interface "Function". 1758 // Implements interface "Function".
1748 const Type& function_interface = Type::Handle(Type::FunctionInterface()); 1759 const Type& function_type = Type::Handle(Type::Function());
1749 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); 1760 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld));
1750 interfaces.SetAt(0, function_interface); 1761 interfaces.SetAt(0, function_type);
1751 result.set_interfaces(interfaces); 1762 result.set_interfaces(interfaces);
1752 // Unless the signature function already has a signature class, create a 1763 // Unless the signature function already has a signature class, create a
1753 // canonical signature class by having the signature function point back to 1764 // canonical signature class by having the signature function point back to
1754 // the signature class. 1765 // the signature class.
1755 if (signature_function.signature_class() == Object::null()) { 1766 if (signature_function.signature_class() == Object::null()) {
1756 signature_function.set_signature_class(result); 1767 signature_function.set_signature_class(result);
1757 result.set_is_finalized(); 1768 result.set_is_finalized();
1758 } else { 1769 } else {
1759 // This new signature class is an alias. 1770 // This new signature class is an alias.
1760 ASSERT(!result.IsCanonicalSignatureClass()); 1771 ASSERT(!result.IsCanonicalSignatureClass());
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
2553 (type_class() == Type::Handle(Type::IntInterface()).type_class()); 2564 (type_class() == Type::Handle(Type::IntInterface()).type_class());
2554 } 2565 }
2555 2566
2556 2567
2557 bool AbstractType::IsDoubleInterface() const { 2568 bool AbstractType::IsDoubleInterface() const {
2558 return HasResolvedTypeClass() && 2569 return HasResolvedTypeClass() &&
2559 (type_class() == Type::Handle(Type::DoubleInterface()).type_class()); 2570 (type_class() == Type::Handle(Type::DoubleInterface()).type_class());
2560 } 2571 }
2561 2572
2562 2573
2563 bool AbstractType::IsNumberInterface() const { 2574 bool AbstractType::IsNumberType() const {
2564 return HasResolvedTypeClass() && 2575 return HasResolvedTypeClass() &&
2565 (type_class() == Type::Handle(Type::NumberInterface()).type_class()); 2576 (type_class() == Type::Handle(Type::Number()).type_class());
2566 } 2577 }
2567 2578
2568 2579
2569 bool AbstractType::IsStringInterface() const { 2580 bool AbstractType::IsStringInterface() const {
2570 return HasResolvedTypeClass() && 2581 return HasResolvedTypeClass() &&
2571 (type_class() == Type::Handle(Type::StringInterface()).type_class()); 2582 (type_class() == Type::Handle(Type::StringInterface()).type_class());
2572 } 2583 }
2573 2584
2574 2585
2575 bool AbstractType::IsFunctionInterface() const { 2586 bool AbstractType::IsFunctionType() const {
2576 return HasResolvedTypeClass() && 2587 return HasResolvedTypeClass() &&
2577 (type_class() == Type::Handle(Type::FunctionInterface()).type_class()); 2588 (type_class() == Type::Handle(Type::Function()).type_class());
2578 } 2589 }
2579 2590
2580 2591
2581 bool AbstractType::IsListInterface() const { 2592 bool AbstractType::IsListInterface() const {
2582 return HasResolvedTypeClass() && 2593 return HasResolvedTypeClass() &&
2583 (type_class() == Type::Handle(Type::ListInterface()).type_class()); 2594 (type_class() == Type::Handle(Type::ListInterface()).type_class());
2584 } 2595 }
2585 2596
2586 2597
2587 bool AbstractType::TypeTest(TypeTestKind test_kind, 2598 bool AbstractType::TypeTest(TypeTestKind test_kind,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2683 RawType* Type::IntInterface() { 2694 RawType* Type::IntInterface() {
2684 return Isolate::Current()->object_store()->int_interface(); 2695 return Isolate::Current()->object_store()->int_interface();
2685 } 2696 }
2686 2697
2687 2698
2688 RawType* Type::DoubleInterface() { 2699 RawType* Type::DoubleInterface() {
2689 return Isolate::Current()->object_store()->double_interface(); 2700 return Isolate::Current()->object_store()->double_interface();
2690 } 2701 }
2691 2702
2692 2703
2693 RawType* Type::NumberInterface() { 2704 RawType* Type::Number() {
2694 return Isolate::Current()->object_store()->number_interface(); 2705 return Isolate::Current()->object_store()->number_type();
2695 } 2706 }
2696 2707
2697 2708
2698 RawType* Type::StringInterface() { 2709 RawType* Type::StringInterface() {
2699 return Isolate::Current()->object_store()->string_interface(); 2710 return Isolate::Current()->object_store()->string_interface();
2700 } 2711 }
2701 2712
2702 2713
2703 RawType* Type::FunctionInterface() { 2714 RawType* Type::Function() {
2704 return Isolate::Current()->object_store()->function_interface(); 2715 return Isolate::Current()->object_store()->function_type();
2705 } 2716 }
2706 2717
2707 2718
2708 RawType* Type::ListInterface() { 2719 RawType* Type::ListInterface() {
2709 return Isolate::Current()->object_store()->list_interface(); 2720 return Isolate::Current()->object_store()->list_interface();
2710 } 2721 }
2711 2722
2712 2723
2713 RawType* Type::NewNonParameterizedType( 2724 RawType* Type::NewNonParameterizedType(
2714 const Class& type_class) { 2725 const Class& type_class) {
(...skipping 8135 matching lines...) Expand 10 before | Expand all | Expand 10 after
10850 void Closure::set_context(const Context& value) const { 10861 void Closure::set_context(const Context& value) const {
10851 StorePointer(&raw_ptr()->context_, value.raw()); 10862 StorePointer(&raw_ptr()->context_, value.raw());
10852 } 10863 }
10853 10864
10854 10865
10855 void Closure::set_function(const Function& value) const { 10866 void Closure::set_function(const Function& value) const {
10856 StorePointer(&raw_ptr()->function_, value.raw()); 10867 StorePointer(&raw_ptr()->function_, value.raw());
10857 } 10868 }
10858 10869
10859 10870
10871 const char* DartFunction::ToCString() const {
10872 return "Function";
regis 2012/08/23 03:53:10 This is only used for debugging, so I would be mor
hausner 2012/08/23 18:34:10 Done.
10873 }
10874
10875
10860 const char* Closure::ToCString() const { 10876 const char* Closure::ToCString() const {
10861 const Function& fun = Function::Handle(function()); 10877 const Function& fun = Function::Handle(function());
10862 const bool is_implicit_closure = fun.IsImplicitClosureFunction(); 10878 const bool is_implicit_closure = fun.IsImplicitClosureFunction();
10863 const char* fun_sig = String::Handle(fun.Signature()).ToCString(); 10879 const char* fun_sig = String::Handle(fun.Signature()).ToCString();
10864 const char* from = is_implicit_closure ? " from " : ""; 10880 const char* from = is_implicit_closure ? " from " : "";
10865 const char* fun_desc = is_implicit_closure ? fun.ToCString() : ""; 10881 const char* fun_desc = is_implicit_closure ? fun.ToCString() : "";
10866 const char* format = "Closure: %s%s%s"; 10882 const char* format = "Closure: %s%s%s";
10867 intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1; 10883 intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1;
10868 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 10884 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
10869 OS::SNPrint(chars, len, format, fun_sig, from, fun_desc); 10885 OS::SNPrint(chars, len, format, fun_sig, from, fun_desc);
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
11133 } 11149 }
11134 return result.raw(); 11150 return result.raw();
11135 } 11151 }
11136 11152
11137 11153
11138 const char* WeakProperty::ToCString() const { 11154 const char* WeakProperty::ToCString() const {
11139 return "WeakProperty"; 11155 return "WeakProperty";
11140 } 11156 }
11141 11157
11142 } // namespace dart 11158 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698