OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
6 | 6 |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/interpreter/bytecode-register-allocator.h" | 10 #include "src/interpreter/bytecode-register-allocator.h" |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 builder()->LoadTheHole().StoreAccumulatorInRegister(destination); | 750 builder()->LoadTheHole().StoreAccumulatorInRegister(destination); |
751 } | 751 } |
752 break; | 752 break; |
753 case VariableLocation::CONTEXT: | 753 case VariableLocation::CONTEXT: |
754 if (hole_init) { | 754 if (hole_init) { |
755 builder()->LoadTheHole().StoreContextSlot(execution_context()->reg(), | 755 builder()->LoadTheHole().StoreContextSlot(execution_context()->reg(), |
756 variable->index()); | 756 variable->index()); |
757 } | 757 } |
758 break; | 758 break; |
759 case VariableLocation::LOOKUP: { | 759 case VariableLocation::LOOKUP: { |
760 DCHECK(IsDeclaredVariableMode(mode)); | 760 DCHECK_EQ(VAR, mode); |
761 DCHECK(!hole_init); | 761 DCHECK(!hole_init); |
762 | 762 |
763 register_allocator()->PrepareForConsecutiveAllocations(3); | 763 Register name = register_allocator()->NewRegister(); |
764 Register name = register_allocator()->NextConsecutiveRegister(); | |
765 Register init_value = register_allocator()->NextConsecutiveRegister(); | |
766 Register attributes = register_allocator()->NextConsecutiveRegister(); | |
767 | 764 |
768 builder()->LoadLiteral(variable->name()).StoreAccumulatorInRegister(name); | |
769 builder() | 765 builder() |
770 ->LoadLiteral(Smi::FromInt(0)) | 766 ->LoadLiteral(variable->name()) |
771 .StoreAccumulatorInRegister(init_value); | 767 .StoreAccumulatorInRegister(name) |
772 builder() | 768 .CallRuntime(Runtime::kDeclareEvalVar, name, 1); |
773 ->LoadLiteral(Smi::FromInt(variable->DeclarationPropertyAttributes())) | |
774 .StoreAccumulatorInRegister(attributes) | |
775 .CallRuntime(Runtime::kDeclareLookupSlot, name, 3); | |
776 break; | 769 break; |
777 } | 770 } |
778 } | 771 } |
779 } | 772 } |
780 | 773 |
781 void BytecodeGenerator::VisitFunctionDeclaration(FunctionDeclaration* decl) { | 774 void BytecodeGenerator::VisitFunctionDeclaration(FunctionDeclaration* decl) { |
782 Variable* variable = decl->proxy()->var(); | 775 Variable* variable = decl->proxy()->var(); |
783 switch (variable->location()) { | 776 switch (variable->location()) { |
784 case VariableLocation::GLOBAL: | 777 case VariableLocation::GLOBAL: |
785 case VariableLocation::UNALLOCATED: { | 778 case VariableLocation::UNALLOCATED: { |
(...skipping 15 matching lines...) Expand all Loading... |
801 break; | 794 break; |
802 } | 795 } |
803 case VariableLocation::CONTEXT: { | 796 case VariableLocation::CONTEXT: { |
804 DCHECK_EQ(0, execution_context()->ContextChainDepth(variable->scope())); | 797 DCHECK_EQ(0, execution_context()->ContextChainDepth(variable->scope())); |
805 VisitForAccumulatorValue(decl->fun()); | 798 VisitForAccumulatorValue(decl->fun()); |
806 builder()->StoreContextSlot(execution_context()->reg(), | 799 builder()->StoreContextSlot(execution_context()->reg(), |
807 variable->index()); | 800 variable->index()); |
808 break; | 801 break; |
809 } | 802 } |
810 case VariableLocation::LOOKUP: { | 803 case VariableLocation::LOOKUP: { |
811 register_allocator()->PrepareForConsecutiveAllocations(3); | 804 register_allocator()->PrepareForConsecutiveAllocations(2); |
812 Register name = register_allocator()->NextConsecutiveRegister(); | 805 Register name = register_allocator()->NextConsecutiveRegister(); |
813 Register literal = register_allocator()->NextConsecutiveRegister(); | 806 Register literal = register_allocator()->NextConsecutiveRegister(); |
814 Register attributes = register_allocator()->NextConsecutiveRegister(); | |
815 builder()->LoadLiteral(variable->name()).StoreAccumulatorInRegister(name); | 807 builder()->LoadLiteral(variable->name()).StoreAccumulatorInRegister(name); |
816 | 808 |
817 VisitForAccumulatorValue(decl->fun()); | 809 VisitForAccumulatorValue(decl->fun()); |
818 builder() | 810 builder()->StoreAccumulatorInRegister(literal).CallRuntime( |
819 ->StoreAccumulatorInRegister(literal) | 811 Runtime::kDeclareEvalFunction, name, 2); |
820 .LoadLiteral(Smi::FromInt(variable->DeclarationPropertyAttributes())) | |
821 .StoreAccumulatorInRegister(attributes) | |
822 .CallRuntime(Runtime::kDeclareLookupSlot, name, 3); | |
823 } | 812 } |
824 } | 813 } |
825 } | 814 } |
826 | 815 |
827 void BytecodeGenerator::VisitImportDeclaration(ImportDeclaration* decl) { | 816 void BytecodeGenerator::VisitImportDeclaration(ImportDeclaration* decl) { |
828 UNIMPLEMENTED(); | 817 UNIMPLEMENTED(); |
829 } | 818 } |
830 | 819 |
831 void BytecodeGenerator::VisitExportDeclaration(ExportDeclaration* decl) { | 820 void BytecodeGenerator::VisitExportDeclaration(ExportDeclaration* decl) { |
832 UNIMPLEMENTED(); | 821 UNIMPLEMENTED(); |
(...skipping 2357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3190 return execution_context()->scope()->language_mode(); | 3179 return execution_context()->scope()->language_mode(); |
3191 } | 3180 } |
3192 | 3181 |
3193 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 3182 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
3194 return TypeFeedbackVector::GetIndex(slot); | 3183 return TypeFeedbackVector::GetIndex(slot); |
3195 } | 3184 } |
3196 | 3185 |
3197 } // namespace interpreter | 3186 } // namespace interpreter |
3198 } // namespace internal | 3187 } // namespace internal |
3199 } // namespace v8 | 3188 } // namespace v8 |
OLD | NEW |