OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 if (scope()->HasIllegalRedeclaration()) { | 268 if (scope()->HasIllegalRedeclaration()) { |
269 Comment cmnt(masm_, "[ Declarations"); | 269 Comment cmnt(masm_, "[ Declarations"); |
270 scope()->VisitIllegalRedeclaration(this); | 270 scope()->VisitIllegalRedeclaration(this); |
271 | 271 |
272 } else { | 272 } else { |
273 PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS); | 273 PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS); |
274 { Comment cmnt(masm_, "[ Declarations"); | 274 { Comment cmnt(masm_, "[ Declarations"); |
275 // For named function expressions, declare the function name as a | 275 // For named function expressions, declare the function name as a |
276 // constant. | 276 // constant. |
277 if (scope()->is_function_scope() && scope()->function() != NULL) { | 277 if (scope()->is_function_scope() && scope()->function() != NULL) { |
278 VariableProxy* proxy = scope()->function(); | 278 VariableDeclaration* function = scope()->function(); |
279 ASSERT(proxy->var()->mode() == CONST || | 279 ASSERT(function->proxy()->var()->mode() == CONST || |
280 proxy->var()->mode() == CONST_HARMONY); | 280 function->proxy()->var()->mode() == CONST_HARMONY); |
281 ASSERT(proxy->var()->location() != Variable::UNALLOCATED); | 281 ASSERT(function->proxy()->var()->location() != Variable::UNALLOCATED); |
282 EmitDeclaration(proxy, proxy->var()->mode(), NULL); | 282 VisitVariableDeclaration(function); |
283 } | 283 } |
284 VisitDeclarations(scope()->declarations()); | 284 VisitDeclarations(scope()->declarations()); |
285 } | 285 } |
286 | 286 |
287 { Comment cmnt(masm_, "[ Stack check"); | 287 { Comment cmnt(masm_, "[ Stack check"); |
288 PrepareForBailoutForId(AstNode::kDeclarationsId, NO_REGISTERS); | 288 PrepareForBailoutForId(AstNode::kDeclarationsId, NO_REGISTERS); |
289 Label ok; | 289 Label ok; |
290 __ LoadRoot(t0, Heap::kStackLimitRootIndex); | 290 __ LoadRoot(t0, Heap::kStackLimitRootIndex); |
291 __ Branch(&ok, hs, sp, Operand(t0)); | 291 __ Branch(&ok, hs, sp, Operand(t0)); |
292 StackCheckStub stub; | 292 StackCheckStub stub; |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 if (should_normalize) __ Branch(&skip); | 782 if (should_normalize) __ Branch(&skip); |
783 PrepareForBailout(expr, TOS_REG); | 783 PrepareForBailout(expr, TOS_REG); |
784 if (should_normalize) { | 784 if (should_normalize) { |
785 __ LoadRoot(t0, Heap::kTrueValueRootIndex); | 785 __ LoadRoot(t0, Heap::kTrueValueRootIndex); |
786 Split(eq, a0, Operand(t0), if_true, if_false, NULL); | 786 Split(eq, a0, Operand(t0), if_true, if_false, NULL); |
787 __ bind(&skip); | 787 __ bind(&skip); |
788 } | 788 } |
789 } | 789 } |
790 | 790 |
791 | 791 |
792 void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, | 792 void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { |
793 VariableMode mode, | 793 // The variable in the declaration always resides in the current function |
794 FunctionLiteral* function) { | 794 // context. |
| 795 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
| 796 if (FLAG_debug_code) { |
| 797 // Check that we're not inside a with or catch context. |
| 798 __ lw(a1, FieldMemOperand(cp, HeapObject::kMapOffset)); |
| 799 __ LoadRoot(t0, Heap::kWithContextMapRootIndex); |
| 800 __ Check(ne, "Declaration in with context.", |
| 801 a1, Operand(t0)); |
| 802 __ LoadRoot(t0, Heap::kCatchContextMapRootIndex); |
| 803 __ Check(ne, "Declaration in catch context.", |
| 804 a1, Operand(t0)); |
| 805 } |
| 806 } |
| 807 |
| 808 |
| 809 void FullCodeGenerator::VisitVariableDeclaration( |
| 810 VariableDeclaration* declaration) { |
795 // If it was not possible to allocate the variable at compile time, we | 811 // If it was not possible to allocate the variable at compile time, we |
796 // need to "declare" it at runtime to make sure it actually exists in the | 812 // need to "declare" it at runtime to make sure it actually exists in the |
797 // local context. | 813 // local context. |
| 814 VariableProxy* proxy = declaration->proxy(); |
| 815 VariableMode mode = declaration->mode(); |
798 Variable* variable = proxy->var(); | 816 Variable* variable = proxy->var(); |
799 bool binding_needs_init = (function == NULL) && | 817 bool hole_init = mode == CONST || mode == CONST_HARMONY || mode == LET; |
800 (mode == CONST || mode == CONST_HARMONY || mode == LET); | |
801 switch (variable->location()) { | 818 switch (variable->location()) { |
802 case Variable::UNALLOCATED: | 819 case Variable::UNALLOCATED: |
803 ++global_count_; | 820 ++global_count_; |
804 break; | 821 break; |
805 | 822 |
806 case Variable::PARAMETER: | 823 case Variable::PARAMETER: |
807 case Variable::LOCAL: | 824 case Variable::LOCAL: |
808 if (function != NULL) { | 825 if (hole_init) { |
809 Comment cmnt(masm_, "[ Declaration"); | 826 Comment cmnt(masm_, "[ VariableDeclaration"); |
810 VisitForAccumulatorValue(function); | 827 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); |
811 __ sw(result_register(), StackOperand(variable)); | 828 __ sw(t0, StackOperand(variable)); |
812 } else if (binding_needs_init) { | |
813 Comment cmnt(masm_, "[ Declaration"); | |
814 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); | |
815 __ sw(t0, StackOperand(variable)); | |
816 } | 829 } |
817 break; | 830 break; |
818 | 831 |
819 case Variable::CONTEXT: | 832 case Variable::CONTEXT: |
820 // The variable in the decl always resides in the current function | 833 if (hole_init) { |
821 // context. | 834 Comment cmnt(masm_, "[ VariableDeclaration"); |
822 ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); | 835 EmitDebugCheckDeclarationContext(variable); |
823 if (FLAG_debug_code) { | |
824 // Check that we're not inside a with or catch context. | |
825 __ lw(a1, FieldMemOperand(cp, HeapObject::kMapOffset)); | |
826 __ LoadRoot(t0, Heap::kWithContextMapRootIndex); | |
827 __ Check(ne, "Declaration in with context.", | |
828 a1, Operand(t0)); | |
829 __ LoadRoot(t0, Heap::kCatchContextMapRootIndex); | |
830 __ Check(ne, "Declaration in catch context.", | |
831 a1, Operand(t0)); | |
832 } | |
833 if (function != NULL) { | |
834 Comment cmnt(masm_, "[ Declaration"); | |
835 VisitForAccumulatorValue(function); | |
836 __ sw(result_register(), ContextOperand(cp, variable->index())); | |
837 int offset = Context::SlotOffset(variable->index()); | |
838 // We know that we have written a function, which is not a smi. | |
839 __ RecordWriteContextSlot(cp, | |
840 offset, | |
841 result_register(), | |
842 a2, | |
843 kRAHasBeenSaved, | |
844 kDontSaveFPRegs, | |
845 EMIT_REMEMBERED_SET, | |
846 OMIT_SMI_CHECK); | |
847 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); | |
848 } else if (binding_needs_init) { | |
849 Comment cmnt(masm_, "[ Declaration"); | |
850 __ LoadRoot(at, Heap::kTheHoleValueRootIndex); | 836 __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
851 __ sw(at, ContextOperand(cp, variable->index())); | 837 __ sw(at, ContextOperand(cp, variable->index())); |
852 // No write barrier since the_hole_value is in old space. | 838 // No write barrier since the_hole_value is in old space. |
853 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); | 839 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
854 } | 840 } |
855 break; | 841 break; |
856 | 842 |
857 case Variable::LOOKUP: { | 843 case Variable::LOOKUP: { |
858 Comment cmnt(masm_, "[ Declaration"); | 844 Comment cmnt(masm_, "[ VariableDeclaration"); |
859 __ li(a2, Operand(variable->name())); | 845 __ li(a2, Operand(variable->name())); |
860 // Declaration nodes are always introduced in one of four modes. | 846 // Declaration nodes are always introduced in one of four modes. |
861 ASSERT(mode == VAR || | 847 ASSERT(mode == VAR || mode == LET || |
862 mode == CONST || | 848 mode == CONST || mode == CONST_HARMONY); |
863 mode == CONST_HARMONY || | |
864 mode == LET); | |
865 PropertyAttributes attr = (mode == CONST || mode == CONST_HARMONY) | 849 PropertyAttributes attr = (mode == CONST || mode == CONST_HARMONY) |
866 ? READ_ONLY : NONE; | 850 ? READ_ONLY : NONE; |
867 __ li(a1, Operand(Smi::FromInt(attr))); | 851 __ li(a1, Operand(Smi::FromInt(attr))); |
868 // Push initial value, if any. | 852 // Push initial value, if any. |
869 // Note: For variables we must not push an initial value (such as | 853 // Note: For variables we must not push an initial value (such as |
870 // 'undefined') because we may have a (legal) redeclaration and we | 854 // 'undefined') because we may have a (legal) redeclaration and we |
871 // must not destroy the current value. | 855 // must not destroy the current value. |
872 if (function != NULL) { | 856 if (hole_init) { |
873 __ Push(cp, a2, a1); | 857 __ LoadRoot(a0, Heap::kTheHoleValueRootIndex); |
874 // Push initial value for function declaration. | 858 __ Push(cp, a2, a1, a0); |
875 VisitForStackValue(function); | |
876 } else if (binding_needs_init) { | |
877 __ LoadRoot(a0, Heap::kTheHoleValueRootIndex); | |
878 __ Push(cp, a2, a1, a0); | |
879 } else { | 859 } else { |
880 ASSERT(Smi::FromInt(0) == 0); | 860 ASSERT(Smi::FromInt(0) == 0); |
881 __ mov(a0, zero_reg); // Smi::FromInt(0) indicates no initial value. | 861 __ mov(a0, zero_reg); // Smi::FromInt(0) indicates no initial value. |
882 __ Push(cp, a2, a1, a0); | 862 __ Push(cp, a2, a1, a0); |
883 } | 863 } |
884 __ CallRuntime(Runtime::kDeclareContextSlot, 4); | 864 __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
885 break; | 865 break; |
886 } | 866 } |
887 } | 867 } |
888 } | 868 } |
889 | 869 |
890 | 870 |
| 871 void FullCodeGenerator::VisitFunctionDeclaration( |
| 872 FunctionDeclaration* declaration) { |
| 873 VariableProxy* proxy = declaration->proxy(); |
| 874 Variable* variable = proxy->var(); |
| 875 switch (variable->location()) { |
| 876 case Variable::UNALLOCATED: |
| 877 ++global_count_; |
| 878 break; |
| 879 |
| 880 case Variable::PARAMETER: |
| 881 case Variable::LOCAL: { |
| 882 Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 883 VisitForAccumulatorValue(declaration->fun()); |
| 884 __ sw(result_register(), StackOperand(variable)); |
| 885 break; |
| 886 } |
| 887 |
| 888 case Variable::CONTEXT: { |
| 889 Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 890 EmitDebugCheckDeclarationContext(variable); |
| 891 VisitForAccumulatorValue(declaration->fun()); |
| 892 __ sw(result_register(), ContextOperand(cp, variable->index())); |
| 893 int offset = Context::SlotOffset(variable->index()); |
| 894 // We know that we have written a function, which is not a smi. |
| 895 __ RecordWriteContextSlot(cp, |
| 896 offset, |
| 897 result_register(), |
| 898 a2, |
| 899 kRAHasBeenSaved, |
| 900 kDontSaveFPRegs, |
| 901 EMIT_REMEMBERED_SET, |
| 902 OMIT_SMI_CHECK); |
| 903 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
| 904 break; |
| 905 } |
| 906 |
| 907 case Variable::LOOKUP: { |
| 908 Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 909 __ li(a2, Operand(variable->name())); |
| 910 __ li(a1, Operand(Smi::FromInt(NONE))); |
| 911 __ Push(cp, a2, a1); |
| 912 // Push initial value for function declaration. |
| 913 VisitForStackValue(declaration->fun()); |
| 914 __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
| 915 break; |
| 916 } |
| 917 } |
| 918 } |
| 919 |
| 920 |
| 921 void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { |
| 922 VariableProxy* proxy = declaration->proxy(); |
| 923 Variable* variable = proxy->var(); |
| 924 switch (variable->location()) { |
| 925 case Variable::UNALLOCATED: |
| 926 ++global_count_; |
| 927 break; |
| 928 |
| 929 case Variable::CONTEXT: { |
| 930 Comment cmnt(masm_, "[ ModuleDeclaration"); |
| 931 EmitDebugCheckDeclarationContext(variable); |
| 932 // TODO(rossberg): initialize module instance object |
| 933 break; |
| 934 } |
| 935 |
| 936 case Variable::PARAMETER: |
| 937 case Variable::LOCAL: |
| 938 case Variable::LOOKUP: |
| 939 UNREACHABLE(); |
| 940 } |
| 941 } |
| 942 |
| 943 |
| 944 void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { |
| 945 VariableProxy* proxy = declaration->proxy(); |
| 946 Variable* variable = proxy->var(); |
| 947 switch (variable->location()) { |
| 948 case Variable::UNALLOCATED: |
| 949 ++global_count_; |
| 950 break; |
| 951 |
| 952 case Variable::CONTEXT: { |
| 953 Comment cmnt(masm_, "[ ImportDeclaration"); |
| 954 EmitDebugCheckDeclarationContext(variable); |
| 955 // TODO(rossberg) |
| 956 break; |
| 957 } |
| 958 |
| 959 case Variable::PARAMETER: |
| 960 case Variable::LOCAL: |
| 961 case Variable::LOOKUP: |
| 962 UNREACHABLE(); |
| 963 } |
| 964 } |
| 965 |
| 966 |
| 967 void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) { |
| 968 // TODO(rossberg) |
| 969 } |
| 970 |
| 971 |
891 void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { | 972 void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
892 // Call the runtime to declare the globals. | 973 // Call the runtime to declare the globals. |
893 // The context is the first argument. | 974 // The context is the first argument. |
894 __ li(a1, Operand(pairs)); | 975 __ li(a1, Operand(pairs)); |
895 __ li(a0, Operand(Smi::FromInt(DeclareGlobalsFlags()))); | 976 __ li(a0, Operand(Smi::FromInt(DeclareGlobalsFlags()))); |
896 __ Push(cp, a1, a0); | 977 __ Push(cp, a1, a0); |
897 __ CallRuntime(Runtime::kDeclareGlobals, 3); | 978 __ CallRuntime(Runtime::kDeclareGlobals, 3); |
898 // Return value is ignored. | 979 // Return value is ignored. |
899 } | 980 } |
900 | 981 |
(...skipping 3658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4559 *context_length = 0; | 4640 *context_length = 0; |
4560 return previous_; | 4641 return previous_; |
4561 } | 4642 } |
4562 | 4643 |
4563 | 4644 |
4564 #undef __ | 4645 #undef __ |
4565 | 4646 |
4566 } } // namespace v8::internal | 4647 } } // namespace v8::internal |
4567 | 4648 |
4568 #endif // V8_TARGET_ARCH_MIPS | 4649 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |