OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 <set> | 5 #include <set> |
6 | 6 |
7 #include "vm/kernel_to_il.h" | 7 #include "vm/kernel_to_il.h" |
8 | 8 |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/intermediate_language.h" | 10 #include "vm/intermediate_language.h" |
(...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1734 } | 1734 } |
1735 | 1735 |
1736 | 1736 |
1737 RawObject* ConstantEvaluator::EvaluateConstConstructorCall( | 1737 RawObject* ConstantEvaluator::EvaluateConstConstructorCall( |
1738 const dart::Class& type_class, | 1738 const dart::Class& type_class, |
1739 const TypeArguments& type_arguments, | 1739 const TypeArguments& type_arguments, |
1740 const Function& constructor, | 1740 const Function& constructor, |
1741 const Object& argument) { | 1741 const Object& argument) { |
1742 // Factories have one extra argument: the type arguments. | 1742 // Factories have one extra argument: the type arguments. |
1743 // Constructors have 1 extra arguments: receiver. | 1743 // Constructors have 1 extra arguments: receiver. |
| 1744 const int kTypeArgsLen = 0; |
1744 const int kNumArgs = 1; | 1745 const int kNumArgs = 1; |
1745 const int kNumExtraArgs = 1; | 1746 const int kNumExtraArgs = 1; |
1746 const int num_arguments = kNumArgs + kNumExtraArgs; | 1747 const int num_arguments = kNumArgs + kNumExtraArgs; |
1747 const Array& arg_values = | 1748 const Array& arg_values = |
1748 Array::Handle(Z, Array::New(num_arguments, Heap::kOld)); | 1749 Array::Handle(Z, Array::New(num_arguments, Heap::kOld)); |
1749 Instance& instance = Instance::Handle(Z); | 1750 Instance& instance = Instance::Handle(Z); |
1750 if (!constructor.IsFactory()) { | 1751 if (!constructor.IsFactory()) { |
1751 instance = Instance::New(type_class, Heap::kOld); | 1752 instance = Instance::New(type_class, Heap::kOld); |
1752 if (!type_arguments.IsNull()) { | 1753 if (!type_arguments.IsNull()) { |
1753 ASSERT(type_arguments.IsInstantiated()); | 1754 ASSERT(type_arguments.IsInstantiated()); |
1754 instance.SetTypeArguments( | 1755 instance.SetTypeArguments( |
1755 TypeArguments::Handle(Z, type_arguments.Canonicalize())); | 1756 TypeArguments::Handle(Z, type_arguments.Canonicalize())); |
1756 } | 1757 } |
1757 arg_values.SetAt(0, instance); | 1758 arg_values.SetAt(0, instance); |
1758 } else { | 1759 } else { |
1759 // Prepend type_arguments to list of arguments to factory. | 1760 // Prepend type_arguments to list of arguments to factory. |
1760 ASSERT(type_arguments.IsZoneHandle()); | 1761 ASSERT(type_arguments.IsZoneHandle()); |
1761 arg_values.SetAt(0, type_arguments); | 1762 arg_values.SetAt(0, type_arguments); |
1762 } | 1763 } |
1763 arg_values.SetAt((0 + kNumExtraArgs), argument); | 1764 arg_values.SetAt((0 + kNumExtraArgs), argument); |
1764 const Array& args_descriptor = Array::Handle( | 1765 const Array& args_descriptor = |
1765 Z, ArgumentsDescriptor::New(num_arguments, Object::empty_array())); | 1766 Array::Handle(Z, ArgumentsDescriptor::New(kTypeArgsLen, num_arguments, |
| 1767 Object::empty_array())); |
1766 const Object& result = Object::Handle( | 1768 const Object& result = Object::Handle( |
1767 Z, DartEntry::InvokeFunction(constructor, arg_values, args_descriptor)); | 1769 Z, DartEntry::InvokeFunction(constructor, arg_values, args_descriptor)); |
1768 ASSERT(!result.IsError()); | 1770 ASSERT(!result.IsError()); |
1769 if (constructor.IsFactory()) { | 1771 if (constructor.IsFactory()) { |
1770 // The factory method returns the allocated object. | 1772 // The factory method returns the allocated object. |
1771 instance ^= result.raw(); | 1773 instance ^= result.raw(); |
1772 } | 1774 } |
1773 return H.Canonicalize(instance); | 1775 return H.Canonicalize(instance); |
1774 } | 1776 } |
1775 | 1777 |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2168 arguments.SetAt(pos++, result_); | 2170 arguments.SetAt(pos++, result_); |
2169 names.SetAt(i, H.DartSymbol(named_expression->name())); | 2171 names.SetAt(i, H.DartSymbol(named_expression->name())); |
2170 } | 2172 } |
2171 return RunFunction(function, arguments, names); | 2173 return RunFunction(function, arguments, names); |
2172 } | 2174 } |
2173 | 2175 |
2174 | 2176 |
2175 const Object& ConstantEvaluator::RunFunction(const Function& function, | 2177 const Object& ConstantEvaluator::RunFunction(const Function& function, |
2176 const Array& arguments, | 2178 const Array& arguments, |
2177 const Array& names) { | 2179 const Array& names) { |
2178 const Array& args_descriptor = | 2180 const int kTypeArgsLen = 0; // Generic functions not yet supported. |
2179 Array::Handle(Z, ArgumentsDescriptor::New(arguments.Length(), names)); | 2181 const Array& args_descriptor = Array::Handle( |
| 2182 Z, ArgumentsDescriptor::New(kTypeArgsLen, arguments.Length(), names)); |
2180 const Object& result = Object::Handle( | 2183 const Object& result = Object::Handle( |
2181 Z, DartEntry::InvokeFunction(function, arguments, args_descriptor)); | 2184 Z, DartEntry::InvokeFunction(function, arguments, args_descriptor)); |
2182 if (result.IsError()) { | 2185 if (result.IsError()) { |
2183 H.ReportError(Error::Cast(result), "error evaluating constant constructor"); | 2186 H.ReportError(Error::Cast(result), "error evaluating constant constructor"); |
2184 } | 2187 } |
2185 return result; | 2188 return result; |
2186 } | 2189 } |
2187 | 2190 |
2188 | 2191 |
2189 FlowGraphBuilder::FlowGraphBuilder( | 2192 FlowGraphBuilder::FlowGraphBuilder( |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2688 } | 2691 } |
2689 | 2692 |
2690 | 2693 |
2691 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, | 2694 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, |
2692 const dart::String& name, | 2695 const dart::String& name, |
2693 Token::Kind kind, | 2696 Token::Kind kind, |
2694 intptr_t argument_count, | 2697 intptr_t argument_count, |
2695 const Array& argument_names, | 2698 const Array& argument_names, |
2696 intptr_t num_args_checked) { | 2699 intptr_t num_args_checked) { |
2697 ArgumentArray arguments = GetArguments(argument_count); | 2700 ArgumentArray arguments = GetArguments(argument_count); |
2698 InstanceCallInstr* call = | 2701 const intptr_t kTypeArgsLen = 0; // Generic instance calls not yet supported. |
2699 new (Z) InstanceCallInstr(position, name, kind, arguments, argument_names, | 2702 InstanceCallInstr* call = new (Z) |
2700 num_args_checked, ic_data_array_); | 2703 InstanceCallInstr(position, name, kind, arguments, kTypeArgsLen, |
| 2704 argument_names, num_args_checked, ic_data_array_); |
2701 Push(call); | 2705 Push(call); |
2702 return Fragment(call); | 2706 return Fragment(call); |
2703 } | 2707 } |
2704 | 2708 |
2705 | 2709 |
2706 Fragment FlowGraphBuilder::ClosureCall(int argument_count, | 2710 Fragment FlowGraphBuilder::ClosureCall(int argument_count, |
2707 const Array& argument_names) { | 2711 const Array& argument_names) { |
2708 Value* function = Pop(); | 2712 Value* function = Pop(); |
2709 ArgumentArray arguments = GetArguments(argument_count); | 2713 ArgumentArray arguments = GetArguments(argument_count); |
2710 ClosureCallInstr* call = new (Z) ClosureCallInstr( | 2714 const intptr_t kTypeArgsLen = 0; // Generic closures not yet supported. |
2711 function, arguments, argument_names, TokenPosition::kNoSource); | 2715 ClosureCallInstr* call = |
| 2716 new (Z) ClosureCallInstr(function, arguments, kTypeArgsLen, |
| 2717 argument_names, TokenPosition::kNoSource); |
2712 Push(call); | 2718 Push(call); |
2713 return Fragment(call); | 2719 return Fragment(call); |
2714 } | 2720 } |
2715 | 2721 |
2716 | 2722 |
2717 Fragment FlowGraphBuilder::ThrowException(TokenPosition position) { | 2723 Fragment FlowGraphBuilder::ThrowException(TokenPosition position) { |
2718 Fragment instructions; | 2724 Fragment instructions; |
2719 instructions += Drop(); | 2725 instructions += Drop(); |
2720 instructions += Fragment(new (Z) ThrowInstr(position)).closed(); | 2726 instructions += Fragment(new (Z) ThrowInstr(position)).closed(); |
2721 // Use it's side effect of leaving a constant on the stack (does not change | 2727 // Use it's side effect of leaving a constant on the stack (does not change |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2914 } | 2920 } |
2915 return FactoryRecognizer::ResultCid(function); | 2921 return FactoryRecognizer::ResultCid(function); |
2916 } | 2922 } |
2917 | 2923 |
2918 | 2924 |
2919 Fragment FlowGraphBuilder::StaticCall(TokenPosition position, | 2925 Fragment FlowGraphBuilder::StaticCall(TokenPosition position, |
2920 const Function& target, | 2926 const Function& target, |
2921 intptr_t argument_count, | 2927 intptr_t argument_count, |
2922 const Array& argument_names) { | 2928 const Array& argument_names) { |
2923 ArgumentArray arguments = GetArguments(argument_count); | 2929 ArgumentArray arguments = GetArguments(argument_count); |
2924 StaticCallInstr* call = new (Z) StaticCallInstr( | 2930 const intptr_t kTypeArgsLen = 0; // Generic static calls not yet supported. |
2925 position, target, argument_names, arguments, ic_data_array_); | 2931 StaticCallInstr* call = |
| 2932 new (Z) StaticCallInstr(position, target, kTypeArgsLen, argument_names, |
| 2933 arguments, ic_data_array_); |
2926 const intptr_t list_cid = | 2934 const intptr_t list_cid = |
2927 GetResultCidOfListFactory(Z, target, argument_count); | 2935 GetResultCidOfListFactory(Z, target, argument_count); |
2928 if (list_cid != kDynamicCid) { | 2936 if (list_cid != kDynamicCid) { |
2929 call->set_result_cid(list_cid); | 2937 call->set_result_cid(list_cid); |
2930 call->set_is_known_list_constructor(true); | 2938 call->set_is_known_list_constructor(true); |
2931 } else if (target.recognized_kind() != MethodRecognizer::kUnknown) { | 2939 } else if (target.recognized_kind() != MethodRecognizer::kUnknown) { |
2932 call->set_result_cid(MethodRecognizer::ResultCid(target)); | 2940 call->set_result_cid(MethodRecognizer::ResultCid(target)); |
2933 } | 2941 } |
2934 Push(call); | 2942 Push(call); |
2935 return Fragment(call); | 2943 return Fragment(call); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3036 Fragment FlowGraphBuilder::StringInterpolate(TokenPosition position) { | 3044 Fragment FlowGraphBuilder::StringInterpolate(TokenPosition position) { |
3037 Value* array = Pop(); | 3045 Value* array = Pop(); |
3038 StringInterpolateInstr* interpolate = | 3046 StringInterpolateInstr* interpolate = |
3039 new (Z) StringInterpolateInstr(array, position); | 3047 new (Z) StringInterpolateInstr(array, position); |
3040 Push(interpolate); | 3048 Push(interpolate); |
3041 return Fragment(interpolate); | 3049 return Fragment(interpolate); |
3042 } | 3050 } |
3043 | 3051 |
3044 | 3052 |
3045 Fragment FlowGraphBuilder::StringInterpolateSingle(TokenPosition position) { | 3053 Fragment FlowGraphBuilder::StringInterpolateSingle(TokenPosition position) { |
| 3054 const int kTypeArgsLen = 0; |
3046 const int kNumberOfArguments = 1; | 3055 const int kNumberOfArguments = 1; |
3047 const Array& kNoArgumentNames = Object::null_array(); | 3056 const Array& kNoArgumentNames = Object::null_array(); |
3048 const dart::Class& cls = dart::Class::Handle( | 3057 const dart::Class& cls = dart::Class::Handle( |
3049 dart::Library::LookupCoreClass(Symbols::StringBase())); | 3058 dart::Library::LookupCoreClass(Symbols::StringBase())); |
3050 ASSERT(!cls.IsNull()); | 3059 ASSERT(!cls.IsNull()); |
3051 const Function& function = Function::ZoneHandle( | 3060 const Function& function = Function::ZoneHandle( |
3052 Z, Resolver::ResolveStatic(cls, dart::Library::PrivateCoreLibName( | 3061 Z, |
3053 Symbols::InterpolateSingle()), | 3062 Resolver::ResolveStatic( |
3054 kNumberOfArguments, kNoArgumentNames)); | 3063 cls, dart::Library::PrivateCoreLibName(Symbols::InterpolateSingle()), |
| 3064 kTypeArgsLen, kNumberOfArguments, kNoArgumentNames)); |
3055 Fragment instructions; | 3065 Fragment instructions; |
3056 instructions += PushArgument(); | 3066 instructions += PushArgument(); |
3057 instructions += StaticCall(position, function, 1); | 3067 instructions += StaticCall(position, function, 1); |
3058 return instructions; | 3068 return instructions; |
3059 } | 3069 } |
3060 | 3070 |
3061 | 3071 |
3062 Fragment FlowGraphBuilder::ThrowTypeError() { | 3072 Fragment FlowGraphBuilder::ThrowTypeError() { |
3063 const dart::Class& klass = dart::Class::ZoneHandle( | 3073 const dart::Class& klass = dart::Class::ZoneHandle( |
3064 Z, dart::Library::LookupCoreClass(Symbols::TypeError())); | 3074 Z, dart::Library::LookupCoreClass(Symbols::TypeError())); |
(...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4191 ZoneGrowableArray<const Instance*>* default_values = | 4201 ZoneGrowableArray<const Instance*>* default_values = |
4192 new ZoneGrowableArray<const Instance*>(Z, descriptor.NamedCount()); | 4202 new ZoneGrowableArray<const Instance*>(Z, descriptor.NamedCount()); |
4193 for (intptr_t i = 0; i < descriptor.NamedCount(); ++i) { | 4203 for (intptr_t i = 0; i < descriptor.NamedCount(); ++i) { |
4194 default_values->Add(&Object::null_instance()); | 4204 default_values->Add(&Object::null_instance()); |
4195 } | 4205 } |
4196 parsed_function_->set_default_parameter_values(default_values); | 4206 parsed_function_->set_default_parameter_values(default_values); |
4197 | 4207 |
4198 Fragment body(normal_entry); | 4208 Fragment body(normal_entry); |
4199 body += CheckStackOverflowInPrologue(); | 4209 body += CheckStackOverflowInPrologue(); |
4200 | 4210 |
| 4211 // TODO(regis): Check if a type argument vector is passed. |
| 4212 |
4201 // The receiver is the first argument to noSuchMethod, and it is the first | 4213 // The receiver is the first argument to noSuchMethod, and it is the first |
4202 // argument passed to the dispatcher function. | 4214 // argument passed to the dispatcher function. |
4203 LocalScope* scope = parsed_function_->node_sequence()->scope(); | 4215 LocalScope* scope = parsed_function_->node_sequence()->scope(); |
4204 body += LoadLocal(scope->VariableAt(0)); | 4216 body += LoadLocal(scope->VariableAt(0)); |
4205 body += PushArgument(); | 4217 body += PushArgument(); |
4206 | 4218 |
4207 // The second argument to noSuchMethod is an invocation mirror. Push the | 4219 // The second argument to noSuchMethod is an invocation mirror. Push the |
4208 // arguments for allocating the invocation mirror. First, the name. | 4220 // arguments for allocating the invocation mirror. First, the name. |
4209 body += Constant(dart::String::ZoneHandle(Z, function.name())); | 4221 body += Constant(dart::String::ZoneHandle(Z, function.name())); |
4210 body += PushArgument(); | 4222 body += PushArgument(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4246 const dart::Class& mirror_class = dart::Class::Handle( | 4258 const dart::Class& mirror_class = dart::Class::Handle( |
4247 Z, dart::Library::LookupCoreClass(Symbols::InvocationMirror())); | 4259 Z, dart::Library::LookupCoreClass(Symbols::InvocationMirror())); |
4248 ASSERT(!mirror_class.IsNull()); | 4260 ASSERT(!mirror_class.IsNull()); |
4249 const Function& allocation_function = Function::ZoneHandle( | 4261 const Function& allocation_function = Function::ZoneHandle( |
4250 Z, mirror_class.LookupStaticFunction(dart::Library::PrivateCoreLibName( | 4262 Z, mirror_class.LookupStaticFunction(dart::Library::PrivateCoreLibName( |
4251 Symbols::AllocateInvocationMirror()))); | 4263 Symbols::AllocateInvocationMirror()))); |
4252 ASSERT(!allocation_function.IsNull()); | 4264 ASSERT(!allocation_function.IsNull()); |
4253 body += StaticCall(TokenPosition::kMinSource, allocation_function, 4); | 4265 body += StaticCall(TokenPosition::kMinSource, allocation_function, 4); |
4254 body += PushArgument(); // For the call to noSuchMethod. | 4266 body += PushArgument(); // For the call to noSuchMethod. |
4255 | 4267 |
| 4268 const int kTypeArgsLen = 0; |
4256 ArgumentsDescriptor two_arguments( | 4269 ArgumentsDescriptor two_arguments( |
4257 Array::Handle(Z, ArgumentsDescriptor::New(2))); | 4270 Array::Handle(Z, ArgumentsDescriptor::New(kTypeArgsLen, 2))); |
4258 Function& no_such_method = | 4271 Function& no_such_method = |
4259 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass( | 4272 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass( |
4260 dart::Class::Handle(Z, function.Owner()), | 4273 dart::Class::Handle(Z, function.Owner()), |
4261 Symbols::NoSuchMethod(), two_arguments)); | 4274 Symbols::NoSuchMethod(), two_arguments)); |
4262 if (no_such_method.IsNull()) { | 4275 if (no_such_method.IsNull()) { |
4263 // If noSuchMethod is not found on the receiver class, call | 4276 // If noSuchMethod is not found on the receiver class, call |
4264 // Object.noSuchMethod. | 4277 // Object.noSuchMethod. |
4265 no_such_method = Resolver::ResolveDynamicForReceiverClass( | 4278 no_such_method = Resolver::ResolveDynamicForReceiverClass( |
4266 dart::Class::Handle(Z, I->object_store()->object_class()), | 4279 dart::Class::Handle(Z, I->object_store()->object_class()), |
4267 Symbols::NoSuchMethod(), two_arguments); | 4280 Symbols::NoSuchMethod(), two_arguments); |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5111 if (target.IsGenerativeConstructor() || target.IsFactory()) { | 5124 if (target.IsGenerativeConstructor() || target.IsFactory()) { |
5112 // The VM requires a TypeArguments object as first parameter for | 5125 // The VM requires a TypeArguments object as first parameter for |
5113 // every factory constructor. | 5126 // every factory constructor. |
5114 ++argument_count; | 5127 ++argument_count; |
5115 } | 5128 } |
5116 | 5129 |
5117 List<NamedExpression>& named = node->arguments()->named(); | 5130 List<NamedExpression>& named = node->arguments()->named(); |
5118 const Array& argument_names = H.ArgumentNames(&named); | 5131 const Array& argument_names = H.ArgumentNames(&named); |
5119 | 5132 |
5120 // The frontend ensures we the [StaticInvocation] has matching arguments. | 5133 // The frontend ensures we the [StaticInvocation] has matching arguments. |
5121 ASSERT(target.AreValidArguments(argument_count, argument_names, NULL)); | 5134 const intptr_t kTypeArgsLen = 0; // Generic functions not yet supported. |
| 5135 ASSERT(target.AreValidArguments(kTypeArgsLen, argument_count, argument_names, |
| 5136 NULL)); |
5122 | 5137 |
5123 Fragment instructions; | 5138 Fragment instructions; |
5124 LocalVariable* instance_variable = NULL; | 5139 LocalVariable* instance_variable = NULL; |
5125 | 5140 |
5126 // If we cross the Kernel -> VM core library boundary, a [StaticInvocation] | 5141 // If we cross the Kernel -> VM core library boundary, a [StaticInvocation] |
5127 // can appear, but the thing we're calling is not a static method, but a | 5142 // can appear, but the thing we're calling is not a static method, but a |
5128 // factory constructor. | 5143 // factory constructor. |
5129 // The `H.LookupStaticmethodByKernelProcedure` will potentially resolve to the | 5144 // The `H.LookupStaticmethodByKernelProcedure` will potentially resolve to the |
5130 // forwarded constructor. | 5145 // forwarded constructor. |
5131 // In that case we'll make an instance and pass it as first argument. | 5146 // In that case we'll make an instance and pass it as first argument. |
(...skipping 1742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6874 thread->clear_sticky_error(); | 6889 thread->clear_sticky_error(); |
6875 return error.raw(); | 6890 return error.raw(); |
6876 } | 6891 } |
6877 } | 6892 } |
6878 | 6893 |
6879 | 6894 |
6880 } // namespace kernel | 6895 } // namespace kernel |
6881 } // namespace dart | 6896 } // namespace dart |
6882 | 6897 |
6883 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 6898 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |