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

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

Issue 154393003: Implement eager instantiation and canonicalization of type arguments at run (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 #include "include/dart_mirrors_api.h" 6 #include "include/dart_mirrors_api.h"
7 #include "include/dart_native_api.h" 7 #include "include/dart_native_api.h"
8 8
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 } 1331 }
1332 // Finalize all classes. 1332 // Finalize all classes.
1333 Dart_Handle state = Api::CheckIsolateState(isolate); 1333 Dart_Handle state = Api::CheckIsolateState(isolate);
1334 if (::Dart_IsError(state)) { 1334 if (::Dart_IsError(state)) {
1335 *value = false; 1335 *value = false;
1336 return state; 1336 return state;
1337 } 1337 }
1338 CHECK_CALLBACK_STATE(isolate); 1338 CHECK_CALLBACK_STATE(isolate);
1339 Error& malformed_type_error = Error::Handle(isolate); 1339 Error& malformed_type_error = Error::Handle(isolate);
1340 *value = instance.IsInstanceOf(type_obj, 1340 *value = instance.IsInstanceOf(type_obj,
1341 Object::null_abstract_type_arguments(), 1341 Object::null_type_arguments(),
1342 &malformed_type_error); 1342 &malformed_type_error);
1343 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. 1343 ASSERT(malformed_type_error.IsNull()); // Type was created from a class.
1344 return Api::Success(); 1344 return Api::Success();
1345 } 1345 }
1346 1346
1347 1347
1348 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { 1348 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) {
1349 Isolate* isolate = Isolate::Current(); 1349 Isolate* isolate = Isolate::Current();
1350 DARTSCOPE(isolate); 1350 DARTSCOPE(isolate);
1351 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 1351 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
(...skipping 1586 matching lines...) Expand 10 before | Expand all | Expand 10 after
2938 } 2938 }
2939 2939
2940 // Get the class to instantiate. 2940 // Get the class to instantiate.
2941 Object& unchecked_type = Object::Handle(Api::UnwrapHandle(type)); 2941 Object& unchecked_type = Object::Handle(Api::UnwrapHandle(type));
2942 if (unchecked_type.IsNull() || !unchecked_type.IsType()) { 2942 if (unchecked_type.IsNull() || !unchecked_type.IsType()) {
2943 RETURN_TYPE_ERROR(isolate, type, Type); 2943 RETURN_TYPE_ERROR(isolate, type, Type);
2944 } 2944 }
2945 Type& type_obj = Type::Handle(); 2945 Type& type_obj = Type::Handle();
2946 type_obj ^= unchecked_type.raw(); 2946 type_obj ^= unchecked_type.raw();
2947 Class& cls = Class::Handle(isolate, type_obj.type_class()); 2947 Class& cls = Class::Handle(isolate, type_obj.type_class());
2948 AbstractTypeArguments& type_arguments = 2948 TypeArguments& type_arguments =
2949 AbstractTypeArguments::Handle(isolate, type_obj.arguments()); 2949 TypeArguments::Handle(isolate, type_obj.arguments());
2950 2950
2951 const String& base_constructor_name = String::Handle(isolate, cls.Name()); 2951 const String& base_constructor_name = String::Handle(isolate, cls.Name());
2952 2952
2953 // And get the name of the constructor to invoke. 2953 // And get the name of the constructor to invoke.
2954 String& dot_name = String::Handle(isolate); 2954 String& dot_name = String::Handle(isolate);
2955 result = Api::UnwrapHandle(constructor_name); 2955 result = Api::UnwrapHandle(constructor_name);
2956 if (result.IsNull()) { 2956 if (result.IsNull()) {
2957 dot_name = Symbols::Dot().raw(); 2957 dot_name = Symbols::Dot().raw();
2958 } else if (result.IsString()) { 2958 } else if (result.IsString()) {
2959 dot_name = String::Concat(Symbols::Dot(), String::Cast(result)); 2959 dot_name = String::Concat(Symbols::Dot(), String::Cast(result));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2992 2992
2993 if (!redirect_type.IsInstantiated()) { 2993 if (!redirect_type.IsInstantiated()) {
2994 // The type arguments of the redirection type are instantiated from the 2994 // The type arguments of the redirection type are instantiated from the
2995 // type arguments of the type argument. 2995 // type arguments of the type argument.
2996 Error& bound_error = Error::Handle(); 2996 Error& bound_error = Error::Handle();
2997 redirect_type ^= redirect_type.InstantiateFrom(type_arguments, 2997 redirect_type ^= redirect_type.InstantiateFrom(type_arguments,
2998 &bound_error); 2998 &bound_error);
2999 if (!bound_error.IsNull()) { 2999 if (!bound_error.IsNull()) {
3000 return Api::NewHandle(isolate, bound_error.raw()); 3000 return Api::NewHandle(isolate, bound_error.raw());
3001 } 3001 }
3002 redirect_type ^= redirect_type.Canonicalize();
3002 } 3003 }
3003 3004
3004 type_obj = redirect_type.raw(); 3005 type_obj = redirect_type.raw();
3005 type_arguments = redirect_type.arguments(); 3006 type_arguments = redirect_type.arguments();
3006 3007
3007 cls = type_obj.type_class(); 3008 cls = type_obj.type_class();
3008 } 3009 }
3009 if (constructor.IsConstructor()) { 3010 if (constructor.IsConstructor()) {
3010 // Create the new object. 3011 // Create the new object.
3011 new_object = Instance::New(cls); 3012 new_object = Instance::New(cls);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
3153 3154
3154 // Construct name of the constructor to invoke. 3155 // Construct name of the constructor to invoke.
3155 const Type& type_obj = Type::Handle(isolate, instance.GetType()); 3156 const Type& type_obj = Type::Handle(isolate, instance.GetType());
3156 const Class& cls = Class::Handle(isolate, type_obj.type_class()); 3157 const Class& cls = Class::Handle(isolate, type_obj.type_class());
3157 const String& class_name = String::Handle(isolate, cls.Name()); 3158 const String& class_name = String::Handle(isolate, cls.Name());
3158 const Array& strings = Array::Handle(Array::New(3)); 3159 const Array& strings = Array::Handle(Array::New(3));
3159 strings.SetAt(0, class_name); 3160 strings.SetAt(0, class_name);
3160 strings.SetAt(1, Symbols::Dot()); 3161 strings.SetAt(1, Symbols::Dot());
3161 strings.SetAt(2, constructor_name); 3162 strings.SetAt(2, constructor_name);
3162 const String& dot_name = String::Handle(isolate, String::ConcatAll(strings)); 3163 const String& dot_name = String::Handle(isolate, String::ConcatAll(strings));
3163 const AbstractTypeArguments& type_arguments = 3164 const TypeArguments& type_arguments =
3164 AbstractTypeArguments::Handle(isolate, type_obj.arguments()); 3165 TypeArguments::Handle(isolate, type_obj.arguments());
srdjan 2014/02/07 21:59:47 Indent 4 spaces
3165 const Function& constructor = 3166 const Function& constructor =
3166 Function::Handle(isolate, cls.LookupFunctionAllowPrivate(dot_name)); 3167 Function::Handle(isolate, cls.LookupFunctionAllowPrivate(dot_name));
3167 const int extra_args = 2; 3168 const int extra_args = 2;
3168 if (!constructor.IsNull() && 3169 if (!constructor.IsNull() &&
3169 constructor.IsConstructor() && 3170 constructor.IsConstructor() &&
3170 constructor.AreValidArgumentCounts(number_of_arguments + extra_args, 3171 constructor.AreValidArgumentCounts(number_of_arguments + extra_args,
3171 0, 3172 0,
3172 NULL)) { 3173 NULL)) {
3173 // Create the argument list. 3174 // Create the argument list.
3174 // Constructors get the uninitialized object and a constructor phase. 3175 // Constructors get the uninitialized object and a constructor phase.
(...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after
4548 } 4549 }
4549 4550
4550 4551
4551 // --- Service support --- 4552 // --- Service support ---
4552 4553
4553 DART_EXPORT Dart_Isolate Dart_GetServiceIsolate(void* callback_data) { 4554 DART_EXPORT Dart_Isolate Dart_GetServiceIsolate(void* callback_data) {
4554 return Api::CastIsolate(Service::GetServiceIsolate(callback_data)); 4555 return Api::CastIsolate(Service::GetServiceIsolate(callback_data));
4555 } 4556 }
4556 4557
4557 } // namespace dart 4558 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698