OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 3859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3870 // patch the stack to use the global proxy as 'this' in the | 3870 // patch the stack to use the global proxy as 'this' in the |
3871 // invoked function. | 3871 // invoked function. |
3872 LoadGlobal(); | 3872 LoadGlobal(); |
3873 | 3873 |
3874 // Load the arguments. | 3874 // Load the arguments. |
3875 int arg_count = args->length(); | 3875 int arg_count = args->length(); |
3876 for (int i = 0; i < arg_count; i++) { | 3876 for (int i = 0; i < arg_count; i++) { |
3877 Load(args->at(i)); | 3877 Load(args->at(i)); |
3878 } | 3878 } |
3879 | 3879 |
3880 // Setup the receiver register and call the IC initialization code. | 3880 // Call the IC initialization code. |
3881 Handle<Code> stub = (loop_nesting() > 0) | |
3882 ? ComputeCallInitializeInLoop(arg_count) | |
3883 : ComputeCallInitialize(arg_count); | |
3884 CodeForSourcePosition(node->position()); | 3881 CodeForSourcePosition(node->position()); |
3885 Result result = frame_->CallCodeObject(stub, | 3882 Result result = frame_->CallCallIC(RelocInfo::CODE_TARGET_CONTEXT, |
3886 RelocInfo::CODE_TARGET_CONTEXT, | 3883 arg_count, |
3887 arg_count + 1); | 3884 loop_nesting()); |
3888 frame_->RestoreContextRegister(); | 3885 frame_->RestoreContextRegister(); |
3889 | |
3890 // Replace the function on the stack with the result. | 3886 // Replace the function on the stack with the result. |
3891 frame_->SetElementAt(0, &result); | 3887 frame_->SetElementAt(0, &result); |
3892 | 3888 |
3893 } else if (var != NULL && var->slot() != NULL && | 3889 } else if (var != NULL && var->slot() != NULL && |
3894 var->slot()->type() == Slot::LOOKUP) { | 3890 var->slot()->type() == Slot::LOOKUP) { |
3895 // ---------------------------------- | 3891 // ---------------------------------- |
3896 // JavaScript example: 'with (obj) foo(1, 2, 3)' // foo is in obj | 3892 // JavaScript example: 'with (obj) foo(1, 2, 3)' // foo is in obj |
3897 // ---------------------------------- | 3893 // ---------------------------------- |
3898 | 3894 |
3899 // Load the function | 3895 // Load the function |
(...skipping 22 matching lines...) Expand all Loading... |
3922 frame_->Push(literal->handle()); | 3918 frame_->Push(literal->handle()); |
3923 Load(property->obj()); | 3919 Load(property->obj()); |
3924 | 3920 |
3925 // Load the arguments. | 3921 // Load the arguments. |
3926 int arg_count = args->length(); | 3922 int arg_count = args->length(); |
3927 for (int i = 0; i < arg_count; i++) { | 3923 for (int i = 0; i < arg_count; i++) { |
3928 Load(args->at(i)); | 3924 Load(args->at(i)); |
3929 } | 3925 } |
3930 | 3926 |
3931 // Call the IC initialization code. | 3927 // Call the IC initialization code. |
3932 Handle<Code> stub = (loop_nesting() > 0) | |
3933 ? ComputeCallInitializeInLoop(arg_count) | |
3934 : ComputeCallInitialize(arg_count); | |
3935 CodeForSourcePosition(node->position()); | 3928 CodeForSourcePosition(node->position()); |
3936 Result result = frame_->CallCodeObject(stub, | 3929 Result result = |
3937 RelocInfo::CODE_TARGET, | 3930 frame_->CallCallIC(RelocInfo::CODE_TARGET, arg_count, loop_nesting()); |
3938 arg_count + 1); | |
3939 frame_->RestoreContextRegister(); | 3931 frame_->RestoreContextRegister(); |
3940 | |
3941 // Replace the function on the stack with the result. | 3932 // Replace the function on the stack with the result. |
3942 frame_->SetElementAt(0, &result); | 3933 frame_->SetElementAt(0, &result); |
3943 | 3934 |
3944 } else { | 3935 } else { |
3945 // ------------------------------------------- | 3936 // ------------------------------------------- |
3946 // JavaScript example: 'array[index](1, 2, 3)' | 3937 // JavaScript example: 'array[index](1, 2, 3)' |
3947 // ------------------------------------------- | 3938 // ------------------------------------------- |
3948 | 3939 |
3949 // Load the function to call from the property through a reference. | 3940 // Load the function to call from the property through a reference. |
3950 Reference ref(this, property); | 3941 Reference ref(this, property); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3996 Load(node->expression()); | 3987 Load(node->expression()); |
3997 LoadGlobal(); | 3988 LoadGlobal(); |
3998 | 3989 |
3999 // Push the arguments ("left-to-right") on the stack. | 3990 // Push the arguments ("left-to-right") on the stack. |
4000 ZoneList<Expression*>* args = node->arguments(); | 3991 ZoneList<Expression*>* args = node->arguments(); |
4001 int arg_count = args->length(); | 3992 int arg_count = args->length(); |
4002 for (int i = 0; i < arg_count; i++) { | 3993 for (int i = 0; i < arg_count; i++) { |
4003 Load(args->at(i)); | 3994 Load(args->at(i)); |
4004 } | 3995 } |
4005 | 3996 |
4006 // Constructors are called with the number of arguments in register | |
4007 // eax for now. Another option would be to have separate construct | |
4008 // call trampolines per different arguments counts encountered. | |
4009 Result num_args = allocator()->Allocate(eax); | |
4010 ASSERT(num_args.is_valid()); | |
4011 __ Set(num_args.reg(), Immediate(arg_count)); | |
4012 | |
4013 // Load the function into temporary function slot as per calling | |
4014 // convention. | |
4015 frame_->PushElementAt(arg_count + 1); | |
4016 Result function = frame_->Pop(); | |
4017 function.ToRegister(edi); | |
4018 ASSERT(function.is_valid()); | |
4019 | |
4020 // Call the construct call builtin that handles allocation and | 3997 // Call the construct call builtin that handles allocation and |
4021 // constructor invocation. | 3998 // constructor invocation. |
4022 CodeForSourcePosition(node->position()); | 3999 CodeForSourcePosition(node->position()); |
4023 Handle<Code> ic(Builtins::builtin(Builtins::JSConstructCall)); | 4000 Result result = frame_->CallConstructor(arg_count); |
4024 Result result = frame_->CallCodeObject(ic, | |
4025 RelocInfo::CONSTRUCT_CALL, | |
4026 &num_args, | |
4027 &function, | |
4028 arg_count + 1); | |
4029 | |
4030 // Replace the function on the stack with the result. | 4001 // Replace the function on the stack with the result. |
4031 frame_->SetElementAt(0, &result); | 4002 frame_->SetElementAt(0, &result); |
4032 } | 4003 } |
4033 | 4004 |
4034 | 4005 |
4035 void CodeGenerator::VisitCallEval(CallEval* node) { | 4006 void CodeGenerator::VisitCallEval(CallEval* node) { |
4036 Comment cmnt(masm_, "[ CallEval"); | 4007 Comment cmnt(masm_, "[ CallEval"); |
4037 | 4008 |
4038 // In a call to eval, we first call %ResolvePossiblyDirectEval to resolve | 4009 // In a call to eval, we first call %ResolvePossiblyDirectEval to resolve |
4039 // the function we need to call and the receiver of the call. | 4010 // the function we need to call and the receiver of the call. |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4432 frame_->Push(&temp); | 4403 frame_->Push(&temp); |
4433 } | 4404 } |
4434 | 4405 |
4435 // Push the arguments ("left-to-right"). | 4406 // Push the arguments ("left-to-right"). |
4436 int arg_count = args->length(); | 4407 int arg_count = args->length(); |
4437 for (int i = 0; i < arg_count; i++) { | 4408 for (int i = 0; i < arg_count; i++) { |
4438 Load(args->at(i)); | 4409 Load(args->at(i)); |
4439 } | 4410 } |
4440 | 4411 |
4441 if (function == NULL) { | 4412 if (function == NULL) { |
4442 // Call the JS runtime function. | 4413 // Call the JS runtime function. Pass 0 as the loop nesting depth |
4443 Handle<Code> stub = ComputeCallInitialize(arg_count); | 4414 // because we do not handle runtime calls specially in loops. |
4444 Result answer = | 4415 Result answer = frame_->CallCallIC(RelocInfo::CODE_TARGET, arg_count, 0); |
4445 frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1); | |
4446 frame_->RestoreContextRegister(); | 4416 frame_->RestoreContextRegister(); |
4447 frame_->SetElementAt(0, &answer); | 4417 frame_->SetElementAt(0, &answer); |
4448 } else { | 4418 } else { |
4449 // Call the C runtime function. | 4419 // Call the C runtime function. |
4450 Result answer = frame_->CallRuntime(function, arg_count); | 4420 Result answer = frame_->CallRuntime(function, arg_count); |
4451 frame_->Push(&answer); | 4421 frame_->Push(&answer); |
4452 } | 4422 } |
4453 } | 4423 } |
4454 | 4424 |
4455 | 4425 |
(...skipping 2487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6943 | 6913 |
6944 // Slow-case: Go through the JavaScript implementation. | 6914 // Slow-case: Go through the JavaScript implementation. |
6945 __ bind(&slow); | 6915 __ bind(&slow); |
6946 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); | 6916 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
6947 } | 6917 } |
6948 | 6918 |
6949 | 6919 |
6950 #undef __ | 6920 #undef __ |
6951 | 6921 |
6952 } } // namespace v8::internal | 6922 } } // namespace v8::internal |
OLD | NEW |