OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 Comment cmnt(masm_, "[ Declarations"); | 262 Comment cmnt(masm_, "[ Declarations"); |
263 scope()->VisitIllegalRedeclaration(this); | 263 scope()->VisitIllegalRedeclaration(this); |
264 | 264 |
265 } else { | 265 } else { |
266 PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS); | 266 PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS); |
267 { Comment cmnt(masm_, "[ Declarations"); | 267 { Comment cmnt(masm_, "[ Declarations"); |
268 // For named function expressions, declare the function name as a | 268 // For named function expressions, declare the function name as a |
269 // constant. | 269 // constant. |
270 if (scope()->is_function_scope() && scope()->function() != NULL) { | 270 if (scope()->is_function_scope() && scope()->function() != NULL) { |
271 int ignored = 0; | 271 int ignored = 0; |
272 EmitDeclaration(scope()->function(), Variable::CONST, NULL, &ignored); | 272 EmitDeclaration(scope()->function(), CONST, NULL, &ignored); |
273 } | 273 } |
274 VisitDeclarations(scope()->declarations()); | 274 VisitDeclarations(scope()->declarations()); |
275 } | 275 } |
276 | 276 |
277 { Comment cmnt(masm_, "[ Stack check"); | 277 { Comment cmnt(masm_, "[ Stack check"); |
278 PrepareForBailoutForId(AstNode::kDeclarationsId, NO_REGISTERS); | 278 PrepareForBailoutForId(AstNode::kDeclarationsId, NO_REGISTERS); |
279 Label ok; | 279 Label ok; |
280 __ LoadRoot(ip, Heap::kStackLimitRootIndex); | 280 __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
281 __ cmp(sp, Operand(ip)); | 281 __ cmp(sp, Operand(ip)); |
282 __ b(hs, &ok); | 282 __ b(hs, &ok); |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 if (should_normalize) { | 704 if (should_normalize) { |
705 __ LoadRoot(ip, Heap::kTrueValueRootIndex); | 705 __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
706 __ cmp(r0, ip); | 706 __ cmp(r0, ip); |
707 Split(eq, if_true, if_false, NULL); | 707 Split(eq, if_true, if_false, NULL); |
708 __ bind(&skip); | 708 __ bind(&skip); |
709 } | 709 } |
710 } | 710 } |
711 | 711 |
712 | 712 |
713 void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, | 713 void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, |
714 Variable::Mode mode, | 714 VariableMode mode, |
715 FunctionLiteral* function, | 715 FunctionLiteral* function, |
716 int* global_count) { | 716 int* global_count) { |
717 // If it was not possible to allocate the variable at compile time, we | 717 // If it was not possible to allocate the variable at compile time, we |
718 // need to "declare" it at runtime to make sure it actually exists in the | 718 // need to "declare" it at runtime to make sure it actually exists in the |
719 // local context. | 719 // local context. |
720 Variable* variable = proxy->var(); | 720 Variable* variable = proxy->var(); |
721 switch (variable->location()) { | 721 switch (variable->location()) { |
722 case Variable::UNALLOCATED: | 722 case Variable::UNALLOCATED: |
723 ++(*global_count); | 723 ++(*global_count); |
724 break; | 724 break; |
725 | 725 |
726 case Variable::PARAMETER: | 726 case Variable::PARAMETER: |
727 case Variable::LOCAL: | 727 case Variable::LOCAL: |
728 if (function != NULL) { | 728 if (function != NULL) { |
729 Comment cmnt(masm_, "[ Declaration"); | 729 Comment cmnt(masm_, "[ Declaration"); |
730 VisitForAccumulatorValue(function); | 730 VisitForAccumulatorValue(function); |
731 __ str(result_register(), StackOperand(variable)); | 731 __ str(result_register(), StackOperand(variable)); |
732 } else if (mode == Variable::CONST || mode == Variable::LET) { | 732 } else if (mode == CONST || mode == LET) { |
733 Comment cmnt(masm_, "[ Declaration"); | 733 Comment cmnt(masm_, "[ Declaration"); |
734 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); | 734 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
735 __ str(ip, StackOperand(variable)); | 735 __ str(ip, StackOperand(variable)); |
736 } | 736 } |
737 break; | 737 break; |
738 | 738 |
739 case Variable::CONTEXT: | 739 case Variable::CONTEXT: |
740 // The variable in the decl always resides in the current function | 740 // The variable in the decl always resides in the current function |
741 // context. | 741 // context. |
742 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); | 742 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
(...skipping 13 matching lines...) Expand all Loading... |
756 // We know that we have written a function, which is not a smi. | 756 // We know that we have written a function, which is not a smi. |
757 __ RecordWriteContextSlot(cp, | 757 __ RecordWriteContextSlot(cp, |
758 offset, | 758 offset, |
759 result_register(), | 759 result_register(), |
760 r2, | 760 r2, |
761 kLRHasBeenSaved, | 761 kLRHasBeenSaved, |
762 kDontSaveFPRegs, | 762 kDontSaveFPRegs, |
763 EMIT_REMEMBERED_SET, | 763 EMIT_REMEMBERED_SET, |
764 OMIT_SMI_CHECK); | 764 OMIT_SMI_CHECK); |
765 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); | 765 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
766 } else if (mode == Variable::CONST || mode == Variable::LET) { | 766 } else if (mode == CONST || mode == LET) { |
767 Comment cmnt(masm_, "[ Declaration"); | 767 Comment cmnt(masm_, "[ Declaration"); |
768 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); | 768 __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
769 __ str(ip, ContextOperand(cp, variable->index())); | 769 __ str(ip, ContextOperand(cp, variable->index())); |
770 // No write barrier since the_hole_value is in old space. | 770 // No write barrier since the_hole_value is in old space. |
771 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); | 771 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
772 } | 772 } |
773 break; | 773 break; |
774 | 774 |
775 case Variable::LOOKUP: { | 775 case Variable::LOOKUP: { |
776 Comment cmnt(masm_, "[ Declaration"); | 776 Comment cmnt(masm_, "[ Declaration"); |
777 __ mov(r2, Operand(variable->name())); | 777 __ mov(r2, Operand(variable->name())); |
778 // Declaration nodes are always introduced in one of three modes. | 778 // Declaration nodes are always introduced in one of three modes. |
779 ASSERT(mode == Variable::VAR || | 779 ASSERT(mode == VAR || mode == CONST || mode == LET); |
780 mode == Variable::CONST || | 780 PropertyAttributes attr = (mode == CONST) ? READ_ONLY : NONE; |
781 mode == Variable::LET); | |
782 PropertyAttributes attr = (mode == Variable::CONST) ? READ_ONLY : NONE; | |
783 __ mov(r1, Operand(Smi::FromInt(attr))); | 781 __ mov(r1, Operand(Smi::FromInt(attr))); |
784 // Push initial value, if any. | 782 // Push initial value, if any. |
785 // Note: For variables we must not push an initial value (such as | 783 // Note: For variables we must not push an initial value (such as |
786 // 'undefined') because we may have a (legal) redeclaration and we | 784 // 'undefined') because we may have a (legal) redeclaration and we |
787 // must not destroy the current value. | 785 // must not destroy the current value. |
788 if (function != NULL) { | 786 if (function != NULL) { |
789 __ Push(cp, r2, r1); | 787 __ Push(cp, r2, r1); |
790 // Push initial value for function declaration. | 788 // Push initial value for function declaration. |
791 VisitForStackValue(function); | 789 VisitForStackValue(function); |
792 } else if (mode == Variable::CONST || mode == Variable::LET) { | 790 } else if (mode == CONST || mode == LET) { |
793 __ LoadRoot(r0, Heap::kTheHoleValueRootIndex); | 791 __ LoadRoot(r0, Heap::kTheHoleValueRootIndex); |
794 __ Push(cp, r2, r1, r0); | 792 __ Push(cp, r2, r1, r0); |
795 } else { | 793 } else { |
796 __ mov(r0, Operand(Smi::FromInt(0))); // Indicates no initial value. | 794 __ mov(r0, Operand(Smi::FromInt(0))); // Indicates no initial value. |
797 __ Push(cp, r2, r1, r0); | 795 __ Push(cp, r2, r1, r0); |
798 } | 796 } |
799 __ CallRuntime(Runtime::kDeclareContextSlot, 4); | 797 __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
800 break; | 798 break; |
801 } | 799 } |
802 } | 800 } |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 | 1210 |
1213 void FullCodeGenerator::EmitDynamicLookupFastCase(Variable* var, | 1211 void FullCodeGenerator::EmitDynamicLookupFastCase(Variable* var, |
1214 TypeofState typeof_state, | 1212 TypeofState typeof_state, |
1215 Label* slow, | 1213 Label* slow, |
1216 Label* done) { | 1214 Label* done) { |
1217 // Generate fast-case code for variables that might be shadowed by | 1215 // Generate fast-case code for variables that might be shadowed by |
1218 // eval-introduced variables. Eval is used a lot without | 1216 // eval-introduced variables. Eval is used a lot without |
1219 // introducing variables. In those cases, we do not want to | 1217 // introducing variables. In those cases, we do not want to |
1220 // perform a runtime call for all variables in the scope | 1218 // perform a runtime call for all variables in the scope |
1221 // containing the eval. | 1219 // containing the eval. |
1222 if (var->mode() == Variable::DYNAMIC_GLOBAL) { | 1220 if (var->mode() == DYNAMIC_GLOBAL) { |
1223 EmitLoadGlobalCheckExtensions(var, typeof_state, slow); | 1221 EmitLoadGlobalCheckExtensions(var, typeof_state, slow); |
1224 __ jmp(done); | 1222 __ jmp(done); |
1225 } else if (var->mode() == Variable::DYNAMIC_LOCAL) { | 1223 } else if (var->mode() == DYNAMIC_LOCAL) { |
1226 Variable* local = var->local_if_not_shadowed(); | 1224 Variable* local = var->local_if_not_shadowed(); |
1227 __ ldr(r0, ContextSlotOperandCheckExtensions(local, slow)); | 1225 __ ldr(r0, ContextSlotOperandCheckExtensions(local, slow)); |
1228 if (local->mode() == Variable::CONST || | 1226 if (local->mode() == CONST || |
1229 local->mode() == Variable::LET) { | 1227 local->mode() == LET) { |
1230 __ CompareRoot(r0, Heap::kTheHoleValueRootIndex); | 1228 __ CompareRoot(r0, Heap::kTheHoleValueRootIndex); |
1231 if (local->mode() == Variable::CONST) { | 1229 if (local->mode() == CONST) { |
1232 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); | 1230 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); |
1233 } else { // Variable::LET | 1231 } else { // LET |
1234 __ b(ne, done); | 1232 __ b(ne, done); |
1235 __ mov(r0, Operand(var->name())); | 1233 __ mov(r0, Operand(var->name())); |
1236 __ push(r0); | 1234 __ push(r0); |
1237 __ CallRuntime(Runtime::kThrowReferenceError, 1); | 1235 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
1238 } | 1236 } |
1239 } | 1237 } |
1240 __ jmp(done); | 1238 __ jmp(done); |
1241 } | 1239 } |
1242 } | 1240 } |
1243 | 1241 |
(...skipping 17 matching lines...) Expand all Loading... |
1261 context()->Plug(r0); | 1259 context()->Plug(r0); |
1262 break; | 1260 break; |
1263 } | 1261 } |
1264 | 1262 |
1265 case Variable::PARAMETER: | 1263 case Variable::PARAMETER: |
1266 case Variable::LOCAL: | 1264 case Variable::LOCAL: |
1267 case Variable::CONTEXT: { | 1265 case Variable::CONTEXT: { |
1268 Comment cmnt(masm_, var->IsContextSlot() | 1266 Comment cmnt(masm_, var->IsContextSlot() |
1269 ? "Context variable" | 1267 ? "Context variable" |
1270 : "Stack variable"); | 1268 : "Stack variable"); |
1271 if (var->mode() != Variable::LET && var->mode() != Variable::CONST) { | 1269 if (var->mode() != LET && var->mode() != CONST) { |
1272 context()->Plug(var); | 1270 context()->Plug(var); |
1273 } else { | 1271 } else { |
1274 // Let and const need a read barrier. | 1272 // Let and const need a read barrier. |
1275 GetVar(r0, var); | 1273 GetVar(r0, var); |
1276 __ CompareRoot(r0, Heap::kTheHoleValueRootIndex); | 1274 __ CompareRoot(r0, Heap::kTheHoleValueRootIndex); |
1277 if (var->mode() == Variable::LET) { | 1275 if (var->mode() == LET) { |
1278 Label done; | 1276 Label done; |
1279 __ b(ne, &done); | 1277 __ b(ne, &done); |
1280 __ mov(r0, Operand(var->name())); | 1278 __ mov(r0, Operand(var->name())); |
1281 __ push(r0); | 1279 __ push(r0); |
1282 __ CallRuntime(Runtime::kThrowReferenceError, 1); | 1280 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
1283 __ bind(&done); | 1281 __ bind(&done); |
1284 } else { | 1282 } else { |
1285 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); | 1283 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); |
1286 } | 1284 } |
1287 context()->Plug(r0); | 1285 context()->Plug(r0); |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1868 // scope. However, unlike var initializers, const initializers are | 1866 // scope. However, unlike var initializers, const initializers are |
1869 // able to drill a hole to that function context, even from inside a | 1867 // able to drill a hole to that function context, even from inside a |
1870 // 'with' context. We thus bypass the normal static scope lookup for | 1868 // 'with' context. We thus bypass the normal static scope lookup for |
1871 // var->IsContextSlot(). | 1869 // var->IsContextSlot(). |
1872 __ push(r0); | 1870 __ push(r0); |
1873 __ mov(r0, Operand(var->name())); | 1871 __ mov(r0, Operand(var->name())); |
1874 __ Push(cp, r0); // Context and name. | 1872 __ Push(cp, r0); // Context and name. |
1875 __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); | 1873 __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); |
1876 } | 1874 } |
1877 | 1875 |
1878 } else if (var->mode() == Variable::LET && op != Token::INIT_LET) { | 1876 } else if (var->mode() == LET && op != Token::INIT_LET) { |
1879 // Non-initializing assignment to let variable needs a write barrier. | 1877 // Non-initializing assignment to let variable needs a write barrier. |
1880 if (var->IsLookupSlot()) { | 1878 if (var->IsLookupSlot()) { |
1881 __ push(r0); // Value. | 1879 __ push(r0); // Value. |
1882 __ mov(r1, Operand(var->name())); | 1880 __ mov(r1, Operand(var->name())); |
1883 __ mov(r0, Operand(Smi::FromInt(strict_mode_flag()))); | 1881 __ mov(r0, Operand(Smi::FromInt(strict_mode_flag()))); |
1884 __ Push(cp, r1, r0); // Context, name, strict mode. | 1882 __ Push(cp, r1, r0); // Context, name, strict mode. |
1885 __ CallRuntime(Runtime::kStoreContextSlot, 4); | 1883 __ CallRuntime(Runtime::kStoreContextSlot, 4); |
1886 } else { | 1884 } else { |
1887 ASSERT(var->IsStackAllocated() || var->IsContextSlot()); | 1885 ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
1888 Label assign; | 1886 Label assign; |
1889 MemOperand location = VarOperand(var, r1); | 1887 MemOperand location = VarOperand(var, r1); |
1890 __ ldr(r3, location); | 1888 __ ldr(r3, location); |
1891 __ CompareRoot(r3, Heap::kTheHoleValueRootIndex); | 1889 __ CompareRoot(r3, Heap::kTheHoleValueRootIndex); |
1892 __ b(ne, &assign); | 1890 __ b(ne, &assign); |
1893 __ mov(r3, Operand(var->name())); | 1891 __ mov(r3, Operand(var->name())); |
1894 __ push(r3); | 1892 __ push(r3); |
1895 __ CallRuntime(Runtime::kThrowReferenceError, 1); | 1893 __ CallRuntime(Runtime::kThrowReferenceError, 1); |
1896 // Perform the assignment. | 1894 // Perform the assignment. |
1897 __ bind(&assign); | 1895 __ bind(&assign); |
1898 __ str(result_register(), location); | 1896 __ str(result_register(), location); |
1899 if (var->IsContextSlot()) { | 1897 if (var->IsContextSlot()) { |
1900 // RecordWrite may destroy all its register arguments. | 1898 // RecordWrite may destroy all its register arguments. |
1901 __ mov(r3, result_register()); | 1899 __ mov(r3, result_register()); |
1902 int offset = Context::SlotOffset(var->index()); | 1900 int offset = Context::SlotOffset(var->index()); |
1903 __ RecordWriteContextSlot( | 1901 __ RecordWriteContextSlot( |
1904 r1, offset, r3, r2, kLRHasBeenSaved, kDontSaveFPRegs); | 1902 r1, offset, r3, r2, kLRHasBeenSaved, kDontSaveFPRegs); |
1905 } | 1903 } |
1906 } | 1904 } |
1907 | 1905 |
1908 } else if (var->mode() != Variable::CONST) { | 1906 } else if (var->mode() != CONST) { |
1909 // Assignment to var or initializing assignment to let. | 1907 // Assignment to var or initializing assignment to let. |
1910 if (var->IsStackAllocated() || var->IsContextSlot()) { | 1908 if (var->IsStackAllocated() || var->IsContextSlot()) { |
1911 MemOperand location = VarOperand(var, r1); | 1909 MemOperand location = VarOperand(var, r1); |
1912 if (FLAG_debug_code && op == Token::INIT_LET) { | 1910 if (FLAG_debug_code && op == Token::INIT_LET) { |
1913 // Check for an uninitialized let binding. | 1911 // Check for an uninitialized let binding. |
1914 __ ldr(r2, location); | 1912 __ ldr(r2, location); |
1915 __ CompareRoot(r2, Heap::kTheHoleValueRootIndex); | 1913 __ CompareRoot(r2, Heap::kTheHoleValueRootIndex); |
1916 __ Check(eq, "Let binding re-initialization."); | 1914 __ Check(eq, "Let binding re-initialization."); |
1917 } | 1915 } |
1918 // Perform the assignment. | 1916 // Perform the assignment. |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2183 for (int i = 0; i < arg_count; i++) { | 2181 for (int i = 0; i < arg_count; i++) { |
2184 VisitForStackValue(args->at(i)); | 2182 VisitForStackValue(args->at(i)); |
2185 } | 2183 } |
2186 | 2184 |
2187 // If we know that eval can only be shadowed by eval-introduced | 2185 // If we know that eval can only be shadowed by eval-introduced |
2188 // variables we attempt to load the global eval function directly | 2186 // variables we attempt to load the global eval function directly |
2189 // in generated code. If we succeed, there is no need to perform a | 2187 // in generated code. If we succeed, there is no need to perform a |
2190 // context lookup in the runtime system. | 2188 // context lookup in the runtime system. |
2191 Label done; | 2189 Label done; |
2192 Variable* var = proxy->var(); | 2190 Variable* var = proxy->var(); |
2193 if (!var->IsUnallocated() && var->mode() == Variable::DYNAMIC_GLOBAL) { | 2191 if (!var->IsUnallocated() && var->mode() == DYNAMIC_GLOBAL) { |
2194 Label slow; | 2192 Label slow; |
2195 EmitLoadGlobalCheckExtensions(var, NOT_INSIDE_TYPEOF, &slow); | 2193 EmitLoadGlobalCheckExtensions(var, NOT_INSIDE_TYPEOF, &slow); |
2196 // Push the function and resolve eval. | 2194 // Push the function and resolve eval. |
2197 __ push(r0); | 2195 __ push(r0); |
2198 EmitResolvePossiblyDirectEval(SKIP_CONTEXT_LOOKUP, arg_count); | 2196 EmitResolvePossiblyDirectEval(SKIP_CONTEXT_LOOKUP, arg_count); |
2199 __ jmp(&done); | 2197 __ jmp(&done); |
2200 __ bind(&slow); | 2198 __ bind(&slow); |
2201 } | 2199 } |
2202 | 2200 |
2203 // Push a copy of the function (found below the arguments) and | 2201 // Push a copy of the function (found below the arguments) and |
(...skipping 2068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4272 *context_length = 0; | 4270 *context_length = 0; |
4273 return previous_; | 4271 return previous_; |
4274 } | 4272 } |
4275 | 4273 |
4276 | 4274 |
4277 #undef __ | 4275 #undef __ |
4278 | 4276 |
4279 } } // namespace v8::internal | 4277 } } // namespace v8::internal |
4280 | 4278 |
4281 #endif // V8_TARGET_ARCH_ARM | 4279 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |