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

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

Issue 8271008: Set type argument vector at run time in instantiated closure objects. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 2 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) 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/object.h" 5 #include "vm/object.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/assert.h" 8 #include "vm/assert.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 result.set_is_interface(); 969 result.set_is_interface();
970 return result.raw(); 970 return result.raw();
971 } 971 }
972 972
973 973
974 RawClass* Class::NewSignatureClass(const String& name, 974 RawClass* Class::NewSignatureClass(const String& name,
975 const Function& signature_function, 975 const Function& signature_function,
976 const Script& script, 976 const Script& script,
977 intptr_t token_index) { 977 intptr_t token_index) {
978 ASSERT(!signature_function.IsNull()); 978 ASSERT(!signature_function.IsNull());
979 Type& super_type = Type::Handle(Type::ObjectType());
979 Array& type_parameters = Array::Handle(); 980 Array& type_parameters = Array::Handle();
980 TypeArray& type_parameter_extends = TypeArray::Handle(); 981 TypeArray& type_parameter_extends = TypeArray::Handle();
981 if (!signature_function.is_static()) { 982 if (!signature_function.is_static()) {
982 const Class& function_class = 983 const Class& owner_class = Class::Handle(signature_function.owner());
983 Class::Handle(signature_function.owner()); 984 ASSERT(!owner_class.IsNull());
984 ASSERT(!function_class.IsNull()); 985 ASSERT(!owner_class.is_interface());
985 type_parameters = function_class.type_parameters(); 986 if (owner_class.IsParameterized()) {
986 type_parameter_extends = function_class.type_parameter_extends(); 987 // Share the function owner super class as the super class of the
988 // signature class, so that the type argument vector of the closure at
989 // run time matches the type argument vector of the closure instantiator.
990 type_parameters = owner_class.type_parameters();
991 type_parameter_extends = owner_class.type_parameter_extends();
992 super_type = owner_class.super_type();
993 }
987 } 994 }
988 Class& result = Class::Handle(New<Closure>(name, script)); 995 Class& result = Class::Handle(New<Closure>(name, script));
996 result.set_super_type(super_type);
989 result.set_signature_function(signature_function); 997 result.set_signature_function(signature_function);
990 result.set_type_parameters(type_parameters); 998 result.set_type_parameters(type_parameters);
991 result.set_type_parameter_extends(type_parameter_extends); 999 result.set_type_parameter_extends(type_parameter_extends);
992 result.SetFields(Array::Handle(Array::Empty())); 1000 result.SetFields(Array::Handle(Array::Empty()));
993 result.SetFunctions(Array::Handle(Array::Empty())); 1001 result.SetFunctions(Array::Handle(Array::Empty()));
994 // Set super class to Object.
995 result.set_super_type(Type::Handle(Type::ObjectType()));
996 // Implements interface Function. 1002 // Implements interface Function.
997 const Type& function_interface = Type::Handle(Type::FunctionInterface()); 1003 const Type& function_interface = Type::Handle(Type::FunctionInterface());
998 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); 1004 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld));
999 interfaces.SetAt(0, function_interface); 1005 interfaces.SetAt(0, function_interface);
1000 result.set_interfaces(interfaces); 1006 result.set_interfaces(interfaces);
1001 return result.raw(); 1007 return result.raw();
1002 } 1008 }
1003 1009
1004 1010
1005 RawClass* Class::GetClass(ObjectKind kind) { 1011 RawClass* Class::GetClass(ObjectKind kind) {
(...skipping 3363 matching lines...) Expand 10 before | Expand all | Expand 10 after
4369 return false; 4375 return false;
4370 } else { 4376 } else {
4371 ASSERT(test == Type::kIsAssignableTo); 4377 ASSERT(test == Type::kIsAssignableTo);
4372 return true; 4378 return true;
4373 } 4379 }
4374 } 4380 }
4375 const Class& cls = Class::Handle(clazz()); 4381 const Class& cls = Class::Handle(clazz());
4376 TypeArguments& type_arguments = TypeArguments::Handle(); 4382 TypeArguments& type_arguments = TypeArguments::Handle();
4377 if (cls.IsParameterized()) { 4383 if (cls.IsParameterized()) {
4378 type_arguments = GetTypeArguments(); 4384 type_arguments = GetTypeArguments();
4385 // Verify that the number of type arguments in the instance matches the
4386 // number of type arguments expected by the instance class.
4387 // A discrepancy is allowed for closures, which borrow the type argument
4388 // vector of their instantiator, which may be of a super class of the class
4389 // defining the closure. Truncating the vector to the correct length on
4390 // instantiation is unnecessary. The vector may therefore be longer.
4379 ASSERT(type_arguments.IsNull() || 4391 ASSERT(type_arguments.IsNull() ||
4380 (type_arguments.Length() == cls.NumTypeArguments())); 4392 (type_arguments.Length() == cls.NumTypeArguments()) ||
4393 (cls.IsSignatureClass() &&
4394 (type_arguments.Length() > cls.NumTypeArguments())));
4381 } 4395 }
4382 Class& other_class = Class::Handle(); 4396 Class& other_class = Class::Handle();
4383 TypeArguments& other_type_arguments = TypeArguments::Handle(); 4397 TypeArguments& other_type_arguments = TypeArguments::Handle();
4384 // In case 'other' is not instantiated, we could simply call 4398 // In case 'other' is not instantiated, we could simply call
4385 // other.InstantiateFrom(other_instantiator, 0), however, we can save the 4399 // other.InstantiateFrom(other_instantiator, 0), however, we can save the
4386 // allocation of a new Type by inlining the code. 4400 // allocation of a new Type by inlining the code.
4387 if (other.IsTypeParameter()) { 4401 if (other.IsTypeParameter()) {
4388 Type& instantiated_other = Type::Handle(); 4402 Type& instantiated_other = Type::Handle();
4389 if (!other_instantiator.IsNull()) { 4403 if (!other_instantiator.IsNull()) {
4390 instantiated_other = other_instantiator.TypeAt(other.Index()); 4404 instantiated_other = other_instantiator.TypeAt(other.Index());
(...skipping 1894 matching lines...) Expand 10 before | Expand all | Expand 10 after
6285 const String& str = String::Handle(pattern()); 6299 const String& str = String::Handle(pattern());
6286 const char* format = "JSRegExp: pattern=%s flags=%s"; 6300 const char* format = "JSRegExp: pattern=%s flags=%s";
6287 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 6301 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
6288 char* chars = reinterpret_cast<char*>( 6302 char* chars = reinterpret_cast<char*>(
6289 Isolate::Current()->current_zone()->Allocate(len + 1)); 6303 Isolate::Current()->current_zone()->Allocate(len + 1));
6290 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 6304 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
6291 return chars; 6305 return chars;
6292 } 6306 }
6293 6307
6294 } // namespace dart 6308 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698