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 2889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2900 } | 2900 } |
2901 | 2901 |
2902 | 2902 |
2903 void CodeGenerator::VisitCall(Call* node) { | 2903 void CodeGenerator::VisitCall(Call* node) { |
2904 #ifdef DEBUG | 2904 #ifdef DEBUG |
2905 int original_height = frame_->height(); | 2905 int original_height = frame_->height(); |
2906 #endif | 2906 #endif |
2907 VirtualFrame::SpilledScope spilled_scope; | 2907 VirtualFrame::SpilledScope spilled_scope; |
2908 Comment cmnt(masm_, "[ Call"); | 2908 Comment cmnt(masm_, "[ Call"); |
2909 | 2909 |
| 2910 Expression* function = node->expression(); |
2910 ZoneList<Expression*>* args = node->arguments(); | 2911 ZoneList<Expression*>* args = node->arguments(); |
2911 | 2912 |
2912 // Standard function call. | 2913 // Standard function call. |
2913 // Check if the function is a variable or a property. | 2914 // Check if the function is a variable or a property. |
2914 Expression* function = node->expression(); | |
2915 Variable* var = function->AsVariableProxy()->AsVariable(); | 2915 Variable* var = function->AsVariableProxy()->AsVariable(); |
2916 Property* property = function->AsProperty(); | 2916 Property* property = function->AsProperty(); |
2917 | 2917 |
2918 // ------------------------------------------------------------------------ | 2918 // ------------------------------------------------------------------------ |
2919 // Fast-case: Use inline caching. | 2919 // Fast-case: Use inline caching. |
2920 // --- | 2920 // --- |
2921 // According to ECMA-262, section 11.2.3, page 44, the function to call | 2921 // According to ECMA-262, section 11.2.3, page 44, the function to call |
2922 // must be resolved after the arguments have been evaluated. The IC code | 2922 // must be resolved after the arguments have been evaluated. The IC code |
2923 // automatically handles this by loading the arguments before the function | 2923 // automatically handles this by loading the arguments before the function |
2924 // is resolved in cache misses (this also holds for megamorphic calls). | 2924 // is resolved in cache misses (this also holds for megamorphic calls). |
2925 // ------------------------------------------------------------------------ | 2925 // ------------------------------------------------------------------------ |
2926 | 2926 |
2927 if (var != NULL && !var->is_this() && var->is_global()) { | 2927 if (var != NULL && var->is_possibly_eval()) { |
| 2928 // ---------------------------------- |
| 2929 // JavaScript example: 'eval(arg)' // eval is not known to be shadowed |
| 2930 // ---------------------------------- |
| 2931 |
| 2932 // In a call to eval, we first call %ResolvePossiblyDirectEval to |
| 2933 // resolve the function we need to call and the receiver of the |
| 2934 // call. Then we call the resolved function using the given |
| 2935 // arguments. |
| 2936 // Prepare stack for call to resolved function. |
| 2937 LoadAndSpill(function); |
| 2938 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
| 2939 frame_->EmitPush(r2); // Slot for receiver |
| 2940 int arg_count = args->length(); |
| 2941 for (int i = 0; i < arg_count; i++) { |
| 2942 LoadAndSpill(args->at(i)); |
| 2943 } |
| 2944 |
| 2945 // Prepare stack for call to ResolvePossiblyDirectEval. |
| 2946 __ ldr(r1, MemOperand(sp, arg_count * kPointerSize + kPointerSize)); |
| 2947 frame_->EmitPush(r1); |
| 2948 if (arg_count > 0) { |
| 2949 __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 2950 frame_->EmitPush(r1); |
| 2951 } else { |
| 2952 frame_->EmitPush(r2); |
| 2953 } |
| 2954 |
| 2955 // Resolve the call. |
| 2956 frame_->CallRuntime(Runtime::kResolvePossiblyDirectEval, 2); |
| 2957 |
| 2958 // Touch up stack with the right values for the function and the receiver. |
| 2959 __ ldr(r1, FieldMemOperand(r0, FixedArray::kHeaderSize)); |
| 2960 __ str(r1, MemOperand(sp, (arg_count + 1) * kPointerSize)); |
| 2961 __ ldr(r1, FieldMemOperand(r0, FixedArray::kHeaderSize + kPointerSize)); |
| 2962 __ str(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 2963 |
| 2964 // Call the function. |
| 2965 CodeForSourcePosition(node->position()); |
| 2966 |
| 2967 InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
| 2968 CallFunctionStub call_function(arg_count, in_loop); |
| 2969 frame_->CallStub(&call_function, arg_count + 1); |
| 2970 |
| 2971 __ ldr(cp, frame_->Context()); |
| 2972 // Remove the function from the stack. |
| 2973 frame_->Drop(); |
| 2974 frame_->EmitPush(r0); |
| 2975 |
| 2976 } else if (var != NULL && !var->is_this() && var->is_global()) { |
2928 // ---------------------------------- | 2977 // ---------------------------------- |
2929 // JavaScript example: 'foo(1, 2, 3)' // foo is global | 2978 // JavaScript example: 'foo(1, 2, 3)' // foo is global |
2930 // ---------------------------------- | 2979 // ---------------------------------- |
2931 | 2980 |
2932 // Push the name of the function and the receiver onto the stack. | 2981 // Push the name of the function and the receiver onto the stack. |
2933 __ mov(r0, Operand(var->name())); | 2982 __ mov(r0, Operand(var->name())); |
2934 frame_->EmitPush(r0); | 2983 frame_->EmitPush(r0); |
2935 | 2984 |
2936 // Pass the global object as the receiver and let the IC stub | 2985 // Pass the global object as the receiver and let the IC stub |
2937 // patch the stack to use the global proxy as 'this' in the | 2986 // patch the stack to use the global proxy as 'this' in the |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3042 LoadGlobalReceiver(r0); | 3091 LoadGlobalReceiver(r0); |
3043 | 3092 |
3044 // Call the function. | 3093 // Call the function. |
3045 CallWithArguments(args, node->position()); | 3094 CallWithArguments(args, node->position()); |
3046 frame_->EmitPush(r0); | 3095 frame_->EmitPush(r0); |
3047 } | 3096 } |
3048 ASSERT(frame_->height() == original_height + 1); | 3097 ASSERT(frame_->height() == original_height + 1); |
3049 } | 3098 } |
3050 | 3099 |
3051 | 3100 |
3052 void CodeGenerator::VisitCallEval(CallEval* node) { | |
3053 #ifdef DEBUG | |
3054 int original_height = frame_->height(); | |
3055 #endif | |
3056 VirtualFrame::SpilledScope spilled_scope; | |
3057 Comment cmnt(masm_, "[ CallEval"); | |
3058 | |
3059 // In a call to eval, we first call %ResolvePossiblyDirectEval to resolve | |
3060 // the function we need to call and the receiver of the call. | |
3061 // Then we call the resolved function using the given arguments. | |
3062 | |
3063 ZoneList<Expression*>* args = node->arguments(); | |
3064 Expression* function = node->expression(); | |
3065 | |
3066 // Prepare stack for call to resolved function. | |
3067 LoadAndSpill(function); | |
3068 __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); | |
3069 frame_->EmitPush(r2); // Slot for receiver | |
3070 int arg_count = args->length(); | |
3071 for (int i = 0; i < arg_count; i++) { | |
3072 LoadAndSpill(args->at(i)); | |
3073 } | |
3074 | |
3075 // Prepare stack for call to ResolvePossiblyDirectEval. | |
3076 __ ldr(r1, MemOperand(sp, arg_count * kPointerSize + kPointerSize)); | |
3077 frame_->EmitPush(r1); | |
3078 if (arg_count > 0) { | |
3079 __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); | |
3080 frame_->EmitPush(r1); | |
3081 } else { | |
3082 frame_->EmitPush(r2); | |
3083 } | |
3084 | |
3085 // Resolve the call. | |
3086 frame_->CallRuntime(Runtime::kResolvePossiblyDirectEval, 2); | |
3087 | |
3088 // Touch up stack with the right values for the function and the receiver. | |
3089 __ ldr(r1, FieldMemOperand(r0, FixedArray::kHeaderSize)); | |
3090 __ str(r1, MemOperand(sp, (arg_count + 1) * kPointerSize)); | |
3091 __ ldr(r1, FieldMemOperand(r0, FixedArray::kHeaderSize + kPointerSize)); | |
3092 __ str(r1, MemOperand(sp, arg_count * kPointerSize)); | |
3093 | |
3094 // Call the function. | |
3095 CodeForSourcePosition(node->position()); | |
3096 | |
3097 InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; | |
3098 CallFunctionStub call_function(arg_count, in_loop); | |
3099 frame_->CallStub(&call_function, arg_count + 1); | |
3100 | |
3101 __ ldr(cp, frame_->Context()); | |
3102 // Remove the function from the stack. | |
3103 frame_->Drop(); | |
3104 frame_->EmitPush(r0); | |
3105 ASSERT(frame_->height() == original_height + 1); | |
3106 } | |
3107 | |
3108 | |
3109 void CodeGenerator::VisitCallNew(CallNew* node) { | 3101 void CodeGenerator::VisitCallNew(CallNew* node) { |
3110 #ifdef DEBUG | 3102 #ifdef DEBUG |
3111 int original_height = frame_->height(); | 3103 int original_height = frame_->height(); |
3112 #endif | 3104 #endif |
3113 VirtualFrame::SpilledScope spilled_scope; | 3105 VirtualFrame::SpilledScope spilled_scope; |
3114 Comment cmnt(masm_, "[ CallNew"); | 3106 Comment cmnt(masm_, "[ CallNew"); |
3115 | 3107 |
3116 // According to ECMA-262, section 11.2.2, page 44, the function | 3108 // According to ECMA-262, section 11.2.2, page 44, the function |
3117 // expression in new calls must be evaluated before the | 3109 // expression in new calls must be evaluated before the |
3118 // arguments. This is different from ordinary calls, where the | 3110 // arguments. This is different from ordinary calls, where the |
(...skipping 3142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6261 int CompareStub::MinorKey() { | 6253 int CompareStub::MinorKey() { |
6262 // Encode the two parameters in a unique 16 bit value. | 6254 // Encode the two parameters in a unique 16 bit value. |
6263 ASSERT(static_cast<unsigned>(cc_) >> 28 < (1 << 15)); | 6255 ASSERT(static_cast<unsigned>(cc_) >> 28 < (1 << 15)); |
6264 return (static_cast<unsigned>(cc_) >> 27) | (strict_ ? 1 : 0); | 6256 return (static_cast<unsigned>(cc_) >> 27) | (strict_ ? 1 : 0); |
6265 } | 6257 } |
6266 | 6258 |
6267 | 6259 |
6268 #undef __ | 6260 #undef __ |
6269 | 6261 |
6270 } } // namespace v8::internal | 6262 } } // namespace v8::internal |
OLD | NEW |