| 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 1744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1755 TypeArguments::Handle(Z, type_arguments.Canonicalize())); | 1755 TypeArguments::Handle(Z, type_arguments.Canonicalize())); |
| 1756 } | 1756 } |
| 1757 arg_values.SetAt(0, instance); | 1757 arg_values.SetAt(0, instance); |
| 1758 } else { | 1758 } else { |
| 1759 // Prepend type_arguments to list of arguments to factory. | 1759 // Prepend type_arguments to list of arguments to factory. |
| 1760 ASSERT(type_arguments.IsZoneHandle()); | 1760 ASSERT(type_arguments.IsZoneHandle()); |
| 1761 arg_values.SetAt(0, type_arguments); | 1761 arg_values.SetAt(0, type_arguments); |
| 1762 } | 1762 } |
| 1763 arg_values.SetAt((0 + kNumExtraArgs), argument); | 1763 arg_values.SetAt((0 + kNumExtraArgs), argument); |
| 1764 const Array& args_descriptor = Array::Handle( | 1764 const Array& args_descriptor = Array::Handle( |
| 1765 Z, ArgumentsDescriptor::New(num_arguments, Object::empty_array())); | 1765 Z, ArgumentsDescriptor::New(0, num_arguments, Object::empty_array())); |
| 1766 const Object& result = Object::Handle( | 1766 const Object& result = Object::Handle( |
| 1767 Z, DartEntry::InvokeFunction(constructor, arg_values, args_descriptor)); | 1767 Z, DartEntry::InvokeFunction(constructor, arg_values, args_descriptor)); |
| 1768 ASSERT(!result.IsError()); | 1768 ASSERT(!result.IsError()); |
| 1769 if (constructor.IsFactory()) { | 1769 if (constructor.IsFactory()) { |
| 1770 // The factory method returns the allocated object. | 1770 // The factory method returns the allocated object. |
| 1771 instance ^= result.raw(); | 1771 instance ^= result.raw(); |
| 1772 } | 1772 } |
| 1773 return H.Canonicalize(instance); | 1773 return H.Canonicalize(instance); |
| 1774 } | 1774 } |
| 1775 | 1775 |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2169 names.SetAt(i, H.DartSymbol(named_expression->name())); | 2169 names.SetAt(i, H.DartSymbol(named_expression->name())); |
| 2170 } | 2170 } |
| 2171 return RunFunction(function, arguments, names); | 2171 return RunFunction(function, arguments, names); |
| 2172 } | 2172 } |
| 2173 | 2173 |
| 2174 | 2174 |
| 2175 const Object& ConstantEvaluator::RunFunction(const Function& function, | 2175 const Object& ConstantEvaluator::RunFunction(const Function& function, |
| 2176 const Array& arguments, | 2176 const Array& arguments, |
| 2177 const Array& names) { | 2177 const Array& names) { |
| 2178 const Array& args_descriptor = | 2178 const Array& args_descriptor = |
| 2179 Array::Handle(Z, ArgumentsDescriptor::New(arguments.Length(), names)); | 2179 Array::Handle(Z, ArgumentsDescriptor::New(0, arguments.Length(), names)); |
| 2180 const Object& result = Object::Handle( | 2180 const Object& result = Object::Handle( |
| 2181 Z, DartEntry::InvokeFunction(function, arguments, args_descriptor)); | 2181 Z, DartEntry::InvokeFunction(function, arguments, args_descriptor)); |
| 2182 if (result.IsError()) { | 2182 if (result.IsError()) { |
| 2183 H.ReportError(Error::Cast(result), "error evaluating constant constructor"); | 2183 H.ReportError(Error::Cast(result), "error evaluating constant constructor"); |
| 2184 } | 2184 } |
| 2185 return result; | 2185 return result; |
| 2186 } | 2186 } |
| 2187 | 2187 |
| 2188 | 2188 |
| 2189 FlowGraphBuilder::FlowGraphBuilder( | 2189 FlowGraphBuilder::FlowGraphBuilder( |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2688 } | 2688 } |
| 2689 | 2689 |
| 2690 | 2690 |
| 2691 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, | 2691 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, |
| 2692 const dart::String& name, | 2692 const dart::String& name, |
| 2693 Token::Kind kind, | 2693 Token::Kind kind, |
| 2694 intptr_t argument_count, | 2694 intptr_t argument_count, |
| 2695 const Array& argument_names, | 2695 const Array& argument_names, |
| 2696 intptr_t num_args_checked) { | 2696 intptr_t num_args_checked) { |
| 2697 ArgumentArray arguments = GetArguments(argument_count); | 2697 ArgumentArray arguments = GetArguments(argument_count); |
| 2698 InstanceCallInstr* call = | 2698 const intptr_t kTypeArgsLen = 0; // Generic instance calls not yet supported. |
| 2699 new (Z) InstanceCallInstr(position, name, kind, arguments, argument_names, | 2699 InstanceCallInstr* call = new (Z) |
| 2700 num_args_checked, ic_data_array_); | 2700 InstanceCallInstr(position, name, kind, arguments, kTypeArgsLen, |
| 2701 argument_names, num_args_checked, ic_data_array_); |
| 2701 Push(call); | 2702 Push(call); |
| 2702 return Fragment(call); | 2703 return Fragment(call); |
| 2703 } | 2704 } |
| 2704 | 2705 |
| 2705 | 2706 |
| 2706 Fragment FlowGraphBuilder::ClosureCall(int argument_count, | 2707 Fragment FlowGraphBuilder::ClosureCall(int argument_count, |
| 2707 const Array& argument_names) { | 2708 const Array& argument_names) { |
| 2708 Value* function = Pop(); | 2709 Value* function = Pop(); |
| 2709 ArgumentArray arguments = GetArguments(argument_count); | 2710 ArgumentArray arguments = GetArguments(argument_count); |
| 2710 ClosureCallInstr* call = new (Z) ClosureCallInstr( | 2711 const intptr_t kTypeArgsLen = 0; // Generic closures not yet supported. |
| 2711 function, arguments, argument_names, TokenPosition::kNoSource); | 2712 ClosureCallInstr* call = |
| 2713 new (Z) ClosureCallInstr(function, arguments, kTypeArgsLen, |
| 2714 argument_names, TokenPosition::kNoSource); |
| 2712 Push(call); | 2715 Push(call); |
| 2713 return Fragment(call); | 2716 return Fragment(call); |
| 2714 } | 2717 } |
| 2715 | 2718 |
| 2716 | 2719 |
| 2717 Fragment FlowGraphBuilder::ThrowException(TokenPosition position) { | 2720 Fragment FlowGraphBuilder::ThrowException(TokenPosition position) { |
| 2718 Fragment instructions; | 2721 Fragment instructions; |
| 2719 instructions += Drop(); | 2722 instructions += Drop(); |
| 2720 instructions += Fragment(new (Z) ThrowInstr(position)).closed(); | 2723 instructions += Fragment(new (Z) ThrowInstr(position)).closed(); |
| 2721 // Use it's side effect of leaving a constant on the stack (does not change | 2724 // 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 } | 2917 } |
| 2915 return FactoryRecognizer::ResultCid(function); | 2918 return FactoryRecognizer::ResultCid(function); |
| 2916 } | 2919 } |
| 2917 | 2920 |
| 2918 | 2921 |
| 2919 Fragment FlowGraphBuilder::StaticCall(TokenPosition position, | 2922 Fragment FlowGraphBuilder::StaticCall(TokenPosition position, |
| 2920 const Function& target, | 2923 const Function& target, |
| 2921 intptr_t argument_count, | 2924 intptr_t argument_count, |
| 2922 const Array& argument_names) { | 2925 const Array& argument_names) { |
| 2923 ArgumentArray arguments = GetArguments(argument_count); | 2926 ArgumentArray arguments = GetArguments(argument_count); |
| 2924 StaticCallInstr* call = new (Z) StaticCallInstr( | 2927 const intptr_t kTypeArgsLen = 0; // Generic static calls not yet supported. |
| 2925 position, target, argument_names, arguments, ic_data_array_); | 2928 StaticCallInstr* call = |
| 2929 new (Z) StaticCallInstr(position, target, kTypeArgsLen, argument_names, |
| 2930 arguments, ic_data_array_); |
| 2926 const intptr_t list_cid = | 2931 const intptr_t list_cid = |
| 2927 GetResultCidOfListFactory(Z, target, argument_count); | 2932 GetResultCidOfListFactory(Z, target, argument_count); |
| 2928 if (list_cid != kDynamicCid) { | 2933 if (list_cid != kDynamicCid) { |
| 2929 call->set_result_cid(list_cid); | 2934 call->set_result_cid(list_cid); |
| 2930 call->set_is_known_list_constructor(true); | 2935 call->set_is_known_list_constructor(true); |
| 2931 } else if (target.recognized_kind() != MethodRecognizer::kUnknown) { | 2936 } else if (target.recognized_kind() != MethodRecognizer::kUnknown) { |
| 2932 call->set_result_cid(MethodRecognizer::ResultCid(target)); | 2937 call->set_result_cid(MethodRecognizer::ResultCid(target)); |
| 2933 } | 2938 } |
| 2934 Push(call); | 2939 Push(call); |
| 2935 return Fragment(call); | 2940 return Fragment(call); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3036 Fragment FlowGraphBuilder::StringInterpolate(TokenPosition position) { | 3041 Fragment FlowGraphBuilder::StringInterpolate(TokenPosition position) { |
| 3037 Value* array = Pop(); | 3042 Value* array = Pop(); |
| 3038 StringInterpolateInstr* interpolate = | 3043 StringInterpolateInstr* interpolate = |
| 3039 new (Z) StringInterpolateInstr(array, position); | 3044 new (Z) StringInterpolateInstr(array, position); |
| 3040 Push(interpolate); | 3045 Push(interpolate); |
| 3041 return Fragment(interpolate); | 3046 return Fragment(interpolate); |
| 3042 } | 3047 } |
| 3043 | 3048 |
| 3044 | 3049 |
| 3045 Fragment FlowGraphBuilder::StringInterpolateSingle(TokenPosition position) { | 3050 Fragment FlowGraphBuilder::StringInterpolateSingle(TokenPosition position) { |
| 3051 const int kTypeArgsLen = 0; |
| 3046 const int kNumberOfArguments = 1; | 3052 const int kNumberOfArguments = 1; |
| 3047 const Array& kNoArgumentNames = Object::null_array(); | 3053 const Array& kNoArgumentNames = Object::null_array(); |
| 3048 const dart::Class& cls = dart::Class::Handle( | 3054 const dart::Class& cls = dart::Class::Handle( |
| 3049 dart::Library::LookupCoreClass(Symbols::StringBase())); | 3055 dart::Library::LookupCoreClass(Symbols::StringBase())); |
| 3050 ASSERT(!cls.IsNull()); | 3056 ASSERT(!cls.IsNull()); |
| 3051 const Function& function = Function::ZoneHandle( | 3057 const Function& function = Function::ZoneHandle( |
| 3052 Z, Resolver::ResolveStatic(cls, dart::Library::PrivateCoreLibName( | 3058 Z, |
| 3053 Symbols::InterpolateSingle()), | 3059 Resolver::ResolveStatic( |
| 3054 kNumberOfArguments, kNoArgumentNames)); | 3060 cls, dart::Library::PrivateCoreLibName(Symbols::InterpolateSingle()), |
| 3061 kTypeArgsLen, kNumberOfArguments, kNoArgumentNames)); |
| 3055 Fragment instructions; | 3062 Fragment instructions; |
| 3056 instructions += PushArgument(); | 3063 instructions += PushArgument(); |
| 3057 instructions += StaticCall(position, function, 1); | 3064 instructions += StaticCall(position, function, 1); |
| 3058 return instructions; | 3065 return instructions; |
| 3059 } | 3066 } |
| 3060 | 3067 |
| 3061 | 3068 |
| 3062 Fragment FlowGraphBuilder::ThrowTypeError() { | 3069 Fragment FlowGraphBuilder::ThrowTypeError() { |
| 3063 const dart::Class& klass = dart::Class::ZoneHandle( | 3070 const dart::Class& klass = dart::Class::ZoneHandle( |
| 3064 Z, dart::Library::LookupCoreClass(Symbols::TypeError())); | 3071 Z, dart::Library::LookupCoreClass(Symbols::TypeError())); |
| (...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4247 Z, dart::Library::LookupCoreClass(Symbols::InvocationMirror())); | 4254 Z, dart::Library::LookupCoreClass(Symbols::InvocationMirror())); |
| 4248 ASSERT(!mirror_class.IsNull()); | 4255 ASSERT(!mirror_class.IsNull()); |
| 4249 const Function& allocation_function = Function::ZoneHandle( | 4256 const Function& allocation_function = Function::ZoneHandle( |
| 4250 Z, mirror_class.LookupStaticFunction(dart::Library::PrivateCoreLibName( | 4257 Z, mirror_class.LookupStaticFunction(dart::Library::PrivateCoreLibName( |
| 4251 Symbols::AllocateInvocationMirror()))); | 4258 Symbols::AllocateInvocationMirror()))); |
| 4252 ASSERT(!allocation_function.IsNull()); | 4259 ASSERT(!allocation_function.IsNull()); |
| 4253 body += StaticCall(TokenPosition::kMinSource, allocation_function, 4); | 4260 body += StaticCall(TokenPosition::kMinSource, allocation_function, 4); |
| 4254 body += PushArgument(); // For the call to noSuchMethod. | 4261 body += PushArgument(); // For the call to noSuchMethod. |
| 4255 | 4262 |
| 4256 ArgumentsDescriptor two_arguments( | 4263 ArgumentsDescriptor two_arguments( |
| 4257 Array::Handle(Z, ArgumentsDescriptor::New(2))); | 4264 Array::Handle(Z, ArgumentsDescriptor::New(0, 2))); |
| 4258 Function& no_such_method = | 4265 Function& no_such_method = |
| 4259 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass( | 4266 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass( |
| 4260 dart::Class::Handle(Z, function.Owner()), | 4267 dart::Class::Handle(Z, function.Owner()), |
| 4261 Symbols::NoSuchMethod(), two_arguments)); | 4268 Symbols::NoSuchMethod(), two_arguments)); |
| 4262 if (no_such_method.IsNull()) { | 4269 if (no_such_method.IsNull()) { |
| 4263 // If noSuchMethod is not found on the receiver class, call | 4270 // If noSuchMethod is not found on the receiver class, call |
| 4264 // Object.noSuchMethod. | 4271 // Object.noSuchMethod. |
| 4265 no_such_method = Resolver::ResolveDynamicForReceiverClass( | 4272 no_such_method = Resolver::ResolveDynamicForReceiverClass( |
| 4266 dart::Class::Handle(Z, I->object_store()->object_class()), | 4273 dart::Class::Handle(Z, I->object_store()->object_class()), |
| 4267 Symbols::NoSuchMethod(), two_arguments); | 4274 Symbols::NoSuchMethod(), two_arguments); |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5111 if (target.IsGenerativeConstructor() || target.IsFactory()) { | 5118 if (target.IsGenerativeConstructor() || target.IsFactory()) { |
| 5112 // The VM requires a TypeArguments object as first parameter for | 5119 // The VM requires a TypeArguments object as first parameter for |
| 5113 // every factory constructor. | 5120 // every factory constructor. |
| 5114 ++argument_count; | 5121 ++argument_count; |
| 5115 } | 5122 } |
| 5116 | 5123 |
| 5117 List<NamedExpression>& named = node->arguments()->named(); | 5124 List<NamedExpression>& named = node->arguments()->named(); |
| 5118 const Array& argument_names = H.ArgumentNames(&named); | 5125 const Array& argument_names = H.ArgumentNames(&named); |
| 5119 | 5126 |
| 5120 // The frontend ensures we the [StaticInvocation] has matching arguments. | 5127 // The frontend ensures we the [StaticInvocation] has matching arguments. |
| 5121 ASSERT(target.AreValidArguments(argument_count, argument_names, NULL)); | 5128 const intptr_t kTypeArgsLen = 0; // Generic functions not yet supported. |
| 5129 ASSERT(target.AreValidArguments(kTypeArgsLen, argument_count, argument_names, |
| 5130 NULL)); |
| 5122 | 5131 |
| 5123 Fragment instructions; | 5132 Fragment instructions; |
| 5124 LocalVariable* instance_variable = NULL; | 5133 LocalVariable* instance_variable = NULL; |
| 5125 | 5134 |
| 5126 // If we cross the Kernel -> VM core library boundary, a [StaticInvocation] | 5135 // 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 | 5136 // can appear, but the thing we're calling is not a static method, but a |
| 5128 // factory constructor. | 5137 // factory constructor. |
| 5129 // The `H.LookupStaticmethodByKernelProcedure` will potentially resolve to the | 5138 // The `H.LookupStaticmethodByKernelProcedure` will potentially resolve to the |
| 5130 // forwarded constructor. | 5139 // forwarded constructor. |
| 5131 // In that case we'll make an instance and pass it as first argument. | 5140 // 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(); | 6883 thread->clear_sticky_error(); |
| 6875 return error.raw(); | 6884 return error.raw(); |
| 6876 } | 6885 } |
| 6877 } | 6886 } |
| 6878 | 6887 |
| 6879 | 6888 |
| 6880 } // namespace kernel | 6889 } // namespace kernel |
| 6881 } // namespace dart | 6890 } // namespace dart |
| 6882 | 6891 |
| 6883 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 6892 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |