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

Side by Side Diff: runtime/lib/function.cc

Issue 2859673002: Pass type argument vector to generic functions (if --reify-generic-functions is (Closed)
Patch Set: address review comments and sync Created 3 years, 7 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
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/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "vm/compiler.h" 7 #include "vm/compiler.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/exceptions.h" 9 #include "vm/exceptions.h"
10 #include "vm/native_entry.h" 10 #include "vm/native_entry.h"
11 #include "vm/object.h" 11 #include "vm/object.h"
12 #include "vm/symbols.h" 12 #include "vm/symbols.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 DEFINE_NATIVE_ENTRY(Function_apply, 2) { 16 DEFINE_NATIVE_ENTRY(Function_apply, 2) {
17 const Array& fun_arguments = Array::CheckedHandle(arguments->NativeArgAt(0)); 17 const int kTypeArgsLen = 0; // TODO(regis): Add support for generic function.
18 const Array& fun_arg_names = Array::CheckedHandle(arguments->NativeArgAt(1)); 18 const Array& fun_arguments =
19 Array::CheckedHandle(zone, arguments->NativeArgAt(0));
20 const Array& fun_arg_names =
21 Array::CheckedHandle(zone, arguments->NativeArgAt(1));
19 const Array& fun_args_desc = Array::Handle( 22 const Array& fun_args_desc = Array::Handle(
20 ArgumentsDescriptor::New(fun_arguments.Length(), fun_arg_names)); 23 zone, ArgumentsDescriptor::New(kTypeArgsLen, fun_arguments.Length(),
21 const Object& result = 24 fun_arg_names));
22 Object::Handle(DartEntry::InvokeClosure(fun_arguments, fun_args_desc)); 25 const Object& result = Object::Handle(
26 zone, DartEntry::InvokeClosure(fun_arguments, fun_args_desc));
23 if (result.IsError()) { 27 if (result.IsError()) {
24 Exceptions::PropagateError(Error::Cast(result)); 28 Exceptions::PropagateError(Error::Cast(result));
25 } 29 }
26 return result.raw(); 30 return result.raw();
27 } 31 }
28 32
29 33
30 DEFINE_NATIVE_ENTRY(Closure_equals, 2) { 34 DEFINE_NATIVE_ENTRY(Closure_equals, 2) {
31 const Closure& receiver = 35 const Closure& receiver =
32 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); 36 Closure::CheckedHandle(zone, arguments->NativeArgAt(0));
33 GET_NATIVE_ARGUMENT(Instance, other, arguments->NativeArgAt(1)); 37 GET_NATIVE_ARGUMENT(Instance, other, arguments->NativeArgAt(1));
34 ASSERT(!other.IsNull()); 38 ASSERT(!other.IsNull());
35 if (receiver.raw() == other.raw()) return Bool::True().raw(); 39 if (receiver.raw() == other.raw()) return Bool::True().raw();
36 if (other.IsClosure()) { 40 if (other.IsClosure()) {
37 const Function& func_a = Function::Handle(receiver.function()); 41 const Function& func_a = Function::Handle(zone, receiver.function());
38 const Function& func_b = Function::Handle(Closure::Cast(other).function()); 42 const Function& func_b =
43 Function::Handle(zone, Closure::Cast(other).function());
39 if (func_a.raw() == func_b.raw()) { 44 if (func_a.raw() == func_b.raw()) {
40 ASSERT(!func_a.IsImplicitStaticClosureFunction()); 45 ASSERT(!func_a.IsImplicitStaticClosureFunction());
41 if (func_a.IsImplicitInstanceClosureFunction()) { 46 if (func_a.IsImplicitInstanceClosureFunction()) {
42 const Context& context_a = Context::Handle(receiver.context()); 47 const Context& context_a = Context::Handle(zone, receiver.context());
43 const Context& context_b = 48 const Context& context_b =
44 Context::Handle(Closure::Cast(other).context()); 49 Context::Handle(zone, Closure::Cast(other).context());
45 const Object& receiver_a = Object::Handle(context_a.At(0)); 50 const Object& receiver_a = Object::Handle(zone, context_a.At(0));
46 const Object& receiver_b = Object::Handle(context_b.At(0)); 51 const Object& receiver_b = Object::Handle(zone, context_b.At(0));
47 if (receiver_a.raw() == receiver_b.raw()) return Bool::True().raw(); 52 if (receiver_a.raw() == receiver_b.raw()) return Bool::True().raw();
48 } 53 }
49 } else if (func_a.IsImplicitInstanceClosureFunction() && 54 } else if (func_a.IsImplicitInstanceClosureFunction() &&
50 func_b.IsImplicitInstanceClosureFunction()) { 55 func_b.IsImplicitInstanceClosureFunction()) {
51 // TODO(rmacnak): Patch existing tears off during reload instead. 56 // TODO(rmacnak): Patch existing tears off during reload instead.
52 const Context& context_a = Context::Handle(receiver.context()); 57 const Context& context_a = Context::Handle(zone, receiver.context());
53 const Context& context_b = 58 const Context& context_b =
54 Context::Handle(Closure::Cast(other).context()); 59 Context::Handle(zone, Closure::Cast(other).context());
55 const Object& receiver_a = Object::Handle(context_a.At(0)); 60 const Object& receiver_a = Object::Handle(zone, context_a.At(0));
56 const Object& receiver_b = Object::Handle(context_b.At(0)); 61 const Object& receiver_b = Object::Handle(zone, context_b.At(0));
57 if ((receiver_a.raw() == receiver_b.raw()) && 62 if ((receiver_a.raw() == receiver_b.raw()) &&
58 (func_a.name() == func_b.name()) && 63 (func_a.name() == func_b.name()) &&
59 (func_a.Owner() == func_b.Owner())) { 64 (func_a.Owner() == func_b.Owner())) {
60 return Bool::True().raw(); 65 return Bool::True().raw();
61 } 66 }
62 } 67 }
63 } 68 }
64 return Bool::False().raw(); 69 return Bool::False().raw();
65 } 70 }
66 71
67 72
68 DEFINE_NATIVE_ENTRY(Closure_hashCode, 1) { 73 DEFINE_NATIVE_ENTRY(Closure_hashCode, 1) {
69 const Closure& receiver = 74 const Closure& receiver =
70 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); 75 Closure::CheckedHandle(zone, arguments->NativeArgAt(0));
71 const Function& func = Function::Handle(receiver.function()); 76 const Function& func = Function::Handle(zone, receiver.function());
72 return func.GetClosureHashCode(); 77 return func.GetClosureHashCode();
73 } 78 }
74 79
75 80
76 DEFINE_NATIVE_ENTRY(Closure_clone, 1) { 81 DEFINE_NATIVE_ENTRY(Closure_clone, 1) {
77 const Closure& receiver = 82 const Closure& receiver =
78 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); 83 Closure::CheckedHandle(zone, arguments->NativeArgAt(0));
79 const TypeArguments& instantiator_type_arguments = 84 const TypeArguments& instantiator_type_arguments =
80 TypeArguments::Handle(zone, receiver.instantiator_type_arguments()); 85 TypeArguments::Handle(zone, receiver.instantiator_type_arguments());
81 const TypeArguments& function_type_arguments = 86 const TypeArguments& function_type_arguments =
82 TypeArguments::Handle(zone, receiver.function_type_arguments()); 87 TypeArguments::Handle(zone, receiver.function_type_arguments());
83 const Function& function = Function::Handle(zone, receiver.function()); 88 const Function& function = Function::Handle(zone, receiver.function());
84 const Context& context = Context::Handle(zone, receiver.context()); 89 const Context& context = Context::Handle(zone, receiver.context());
85 Context& cloned_context = 90 Context& cloned_context =
86 Context::Handle(zone, Context::New(context.num_variables())); 91 Context::Handle(zone, Context::New(context.num_variables()));
87 cloned_context.set_parent(Context::Handle(zone, context.parent())); 92 cloned_context.set_parent(Context::Handle(zone, context.parent()));
88 Object& instance = Object::Handle(zone); 93 Object& instance = Object::Handle(zone);
89 for (int i = 0; i < context.num_variables(); i++) { 94 for (int i = 0; i < context.num_variables(); i++) {
90 instance = context.At(i); 95 instance = context.At(i);
91 cloned_context.SetAt(i, instance); 96 cloned_context.SetAt(i, instance);
92 } 97 }
93 return Closure::New(instantiator_type_arguments, function_type_arguments, 98 return Closure::New(instantiator_type_arguments, function_type_arguments,
94 function, cloned_context); 99 function, cloned_context);
95 } 100 }
96 101
97 102
98 } // namespace dart 103 } // namespace dart
OLDNEW
« no previous file with comments | « pkg/kernel/lib/transformations/mixin_full_resolution.dart ('k') | runtime/lib/invocation_mirror_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698