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

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

Issue 22425006: Fix equality of implicit closures in the Dart VM. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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
« no previous file with comments | « runtime/vm/bootstrap_natives.h ('k') | runtime/vm/parser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/cpu.h" 10 #include "vm/cpu.h"
(...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 false, // Not const. 1840 false, // Not const.
1841 false, // Not abstract. 1841 false, // Not abstract.
1842 false, // Not external. 1842 false, // Not external.
1843 *this, 1843 *this,
1844 0)); // No token position. 1844 0)); // No token position.
1845 ArgumentsDescriptor desc(args_desc); 1845 ArgumentsDescriptor desc(args_desc);
1846 invocation.set_num_fixed_parameters(desc.PositionalCount()); 1846 invocation.set_num_fixed_parameters(desc.PositionalCount());
1847 invocation.SetNumOptionalParameters(desc.NamedCount(), 1847 invocation.SetNumOptionalParameters(desc.NamedCount(),
1848 false); // Not positional. 1848 false); // Not positional.
1849 invocation.set_parameter_types(Array::Handle(Array::New(desc.Count(), 1849 invocation.set_parameter_types(Array::Handle(Array::New(desc.Count(),
1850 Heap::kOld))); 1850 Heap::kOld)));
1851 invocation.set_parameter_names(Array::Handle(Array::New(desc.Count(), 1851 invocation.set_parameter_names(Array::Handle(Array::New(desc.Count(),
1852 Heap::kOld))); 1852 Heap::kOld)));
1853 // Receiver. 1853 // Receiver.
1854 invocation.SetParameterTypeAt(0, Type::Handle(Type::DynamicType())); 1854 invocation.SetParameterTypeAt(0, Type::Handle(Type::DynamicType()));
1855 invocation.SetParameterNameAt(0, Symbols::This()); 1855 invocation.SetParameterNameAt(0, Symbols::This());
1856 // Remaining positional parameters. 1856 // Remaining positional parameters.
1857 intptr_t i = 1; 1857 intptr_t i = 1;
1858 for (; i < desc.PositionalCount(); i++) { 1858 for (; i < desc.PositionalCount(); i++) {
1859 invocation.SetParameterTypeAt(i, Type::Handle(Type::DynamicType())); 1859 invocation.SetParameterTypeAt(i, Type::Handle(Type::DynamicType()));
1860 char name[64]; 1860 char name[64];
1861 OS::SNPrint(name, 64, ":p%"Pd, i); 1861 OS::SNPrint(name, 64, ":p%"Pd, i);
1862 invocation.SetParameterNameAt(i, String::Handle(Symbols::New(name))); 1862 invocation.SetParameterNameAt(i, String::Handle(Symbols::New(name)));
(...skipping 2752 matching lines...) Expand 10 before | Expand all | Expand 10 after
4615 /* is_const = */ false, 4615 /* is_const = */ false,
4616 /* is_abstract = */ false, 4616 /* is_abstract = */ false,
4617 /* is_external = */ false, 4617 /* is_external = */ false,
4618 parent_owner, 4618 parent_owner,
4619 token_pos)); 4619 token_pos));
4620 result.set_parent_function(parent); 4620 result.set_parent_function(parent);
4621 return result.raw(); 4621 return result.raw();
4622 } 4622 }
4623 4623
4624 4624
4625 static RawFunction* CreateClosureEqualsFunction(const Class& owner) {
4626 Function& result = Function::Handle(
4627 Function::New(Symbols::EqualOperator(),
4628 RawFunction::kRegularFunction,
4629 false, // Not static.
4630 false, // Not const.
4631 false, // Not abstract.
4632 false, // Not external.
4633 owner,
4634 0)); // No token position.
4635 const intptr_t num_args = 2;
4636 result.set_num_fixed_parameters(num_args);
4637 result.SetNumOptionalParameters(0,
4638 false); // Not positional.
4639 result.set_parameter_types(Array::Handle(Array::New(num_args,
4640 Heap::kOld)));
4641 result.set_parameter_names(Array::Handle(Array::New(num_args,
4642 Heap::kOld)));
4643 // Receiver.
4644 result.SetParameterTypeAt(0, Type::Handle(Type::DynamicType()));
4645 result.SetParameterNameAt(0, Symbols::This());
4646 // Other.
4647 result.SetParameterTypeAt(1, Type::Handle(Type::DynamicType()));
4648 result.SetParameterNameAt(1, String::Handle(Symbols::New("other")));
4649
4650 result.set_result_type(Type::Handle(Type::BoolType()));
4651 return result.raw();
4652 }
4653
4654
4655 static RawFunction* CreateClosureHashCodeFunction(const Class& owner) {
4656 Function& result = Function::Handle(
4657 Function::New(Symbols::HashCode(),
4658 RawFunction::kGetterFunction,
4659 false, // Not static.
4660 false, // Not const.
4661 false, // Not abstract.
4662 false, // Not external.
4663 owner,
4664 0)); // No token position.
4665 const intptr_t num_args = 1;
4666 result.set_num_fixed_parameters(num_args);
4667 result.SetNumOptionalParameters(0,
4668 false); // Not positional.
4669 result.set_parameter_types(Array::Handle(Array::New(num_args,
4670 Heap::kOld)));
4671 result.set_parameter_names(Array::Handle(Array::New(num_args,
4672 Heap::kOld)));
4673 // Receiver.
4674 result.SetParameterTypeAt(0, Type::Handle(Type::DynamicType()));
4675 result.SetParameterNameAt(0, Symbols::This());
4676
4677 result.set_result_type(Type::Handle(Type::IntType()));
4678 return result.raw();
4679 }
4680
4681
4625 RawFunction* Function::ImplicitClosureFunction() const { 4682 RawFunction* Function::ImplicitClosureFunction() const {
4626 // Return the existing implicit closure function if any. 4683 // Return the existing implicit closure function if any.
4627 if (implicit_closure_function() != Function::null()) { 4684 if (implicit_closure_function() != Function::null()) {
4628 return implicit_closure_function(); 4685 return implicit_closure_function();
4629 } 4686 }
4630 ASSERT(!IsSignatureFunction() && !IsClosureFunction()); 4687 ASSERT(!IsSignatureFunction() && !IsClosureFunction());
4631 // Create closure function. 4688 // Create closure function.
4632 const String& closure_name = String::Handle(name()); 4689 const String& closure_name = String::Handle(name());
4633 const Function& closure_function = Function::Handle( 4690 const Function& closure_function = Function::Handle(
4634 NewClosureFunction(closure_name, *this, token_pos())); 4691 NewClosureFunction(closure_name, *this, token_pos()));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
4684 ASSERT(!library.IsNull()); 4741 ASSERT(!library.IsNull());
4685 const String& signature = String::Handle(closure_function.Signature()); 4742 const String& signature = String::Handle(closure_function.Signature());
4686 Class& signature_class = Class::ZoneHandle( 4743 Class& signature_class = Class::ZoneHandle(
4687 library.LookupLocalClass(signature)); 4744 library.LookupLocalClass(signature));
4688 if (signature_class.IsNull()) { 4745 if (signature_class.IsNull()) {
4689 const Script& script = Script::Handle(this->script()); 4746 const Script& script = Script::Handle(this->script());
4690 signature_class = Class::NewSignatureClass(signature, 4747 signature_class = Class::NewSignatureClass(signature,
4691 closure_function, 4748 closure_function,
4692 script, 4749 script,
4693 closure_function.token_pos()); 4750 closure_function.token_pos());
4751 // Add == function to implicit instance closures.
Ivan Posva 2013/08/09 21:24:30 This will not work because f, g and h in the examp
Florian Schneider 2013/08/12 09:32:12 Done. You're right. I'll make sure that == and has
4752 if (!closure_function.is_static()) {
4753 const Function& equals_function =
4754 Function::Handle(CreateClosureEqualsFunction(signature_class));
4755 signature_class.AddFunction(equals_function);
4756 const Function& hash_code_function =
4757 Function::Handle(CreateClosureHashCodeFunction(signature_class));
4758 signature_class.AddFunction(hash_code_function);
4759 }
4694 library.AddClass(signature_class); 4760 library.AddClass(signature_class);
4695 } else { 4761 } else {
4696 closure_function.set_signature_class(signature_class); 4762 closure_function.set_signature_class(signature_class);
4697 } 4763 }
4698 const Type& signature_type = Type::Handle(signature_class.SignatureType()); 4764 const Type& signature_type = Type::Handle(signature_class.SignatureType());
4699 if (!signature_type.IsFinalized()) { 4765 if (!signature_type.IsFinalized()) {
4700 ClassFinalizer::FinalizeType( 4766 ClassFinalizer::FinalizeType(
4701 signature_class, signature_type, ClassFinalizer::kCanonicalize); 4767 signature_class, signature_type, ClassFinalizer::kCanonicalize);
4702 } 4768 }
4703 ASSERT(closure_function.signature_class() == signature_class.raw()); 4769 ASSERT(closure_function.signature_class() == signature_class.raw());
(...skipping 9868 matching lines...) Expand 10 before | Expand all | Expand 10 after
14572 } 14638 }
14573 14639
14574 14640
14575 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14641 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14576 stream->OpenObject(); 14642 stream->OpenObject();
14577 stream->CloseObject(); 14643 stream->CloseObject();
14578 } 14644 }
14579 14645
14580 14646
14581 } // namespace dart 14647 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/bootstrap_natives.h ('k') | runtime/vm/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698