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 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 VariableDeclaration* declaration) { | 772 VariableDeclaration* declaration) { |
773 // If it was not possible to allocate the variable at compile time, we | 773 // If it was not possible to allocate the variable at compile time, we |
774 // need to "declare" it at runtime to make sure it actually exists in the | 774 // need to "declare" it at runtime to make sure it actually exists in the |
775 // local context. | 775 // local context. |
776 VariableProxy* proxy = declaration->proxy(); | 776 VariableProxy* proxy = declaration->proxy(); |
777 VariableMode mode = declaration->mode(); | 777 VariableMode mode = declaration->mode(); |
778 Variable* variable = proxy->var(); | 778 Variable* variable = proxy->var(); |
779 bool hole_init = mode == CONST || mode == CONST_HARMONY || mode == LET; | 779 bool hole_init = mode == CONST || mode == CONST_HARMONY || mode == LET; |
780 switch (variable->location()) { | 780 switch (variable->location()) { |
781 case Variable::UNALLOCATED: | 781 case Variable::UNALLOCATED: |
782 globals_.Add(variable->name()); | 782 globals_->Add(variable->name()); |
783 globals_.Add(variable->binding_needs_init() | 783 globals_->Add(variable->binding_needs_init() |
784 ? isolate()->factory()->the_hole_value() | 784 ? isolate()->factory()->the_hole_value() |
785 : isolate()->factory()->undefined_value()); | 785 : isolate()->factory()->undefined_value()); |
786 break; | 786 break; |
787 | 787 |
788 case Variable::PARAMETER: | 788 case Variable::PARAMETER: |
789 case Variable::LOCAL: | 789 case Variable::LOCAL: |
790 if (hole_init) { | 790 if (hole_init) { |
791 Comment cmnt(masm_, "[ VariableDeclaration"); | 791 Comment cmnt(masm_, "[ VariableDeclaration"); |
792 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); | 792 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); |
793 __ movq(StackOperand(variable), kScratchRegister); | 793 __ movq(StackOperand(variable), kScratchRegister); |
794 } | 794 } |
795 break; | 795 break; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 } | 830 } |
831 } | 831 } |
832 | 832 |
833 | 833 |
834 void FullCodeGenerator::VisitFunctionDeclaration( | 834 void FullCodeGenerator::VisitFunctionDeclaration( |
835 FunctionDeclaration* declaration) { | 835 FunctionDeclaration* declaration) { |
836 VariableProxy* proxy = declaration->proxy(); | 836 VariableProxy* proxy = declaration->proxy(); |
837 Variable* variable = proxy->var(); | 837 Variable* variable = proxy->var(); |
838 switch (variable->location()) { | 838 switch (variable->location()) { |
839 case Variable::UNALLOCATED: { | 839 case Variable::UNALLOCATED: { |
840 globals_.Add(variable->name()); | 840 globals_->Add(variable->name()); |
841 Handle<SharedFunctionInfo> function = | 841 Handle<SharedFunctionInfo> function = |
842 Compiler::BuildFunctionInfo(declaration->fun(), script()); | 842 Compiler::BuildFunctionInfo(declaration->fun(), script()); |
843 // Check for stack-overflow exception. | 843 // Check for stack-overflow exception. |
844 if (function.is_null()) return SetStackOverflow(); | 844 if (function.is_null()) return SetStackOverflow(); |
845 globals_.Add(function); | 845 globals_->Add(function); |
846 break; | 846 break; |
847 } | 847 } |
848 | 848 |
849 case Variable::PARAMETER: | 849 case Variable::PARAMETER: |
850 case Variable::LOCAL: { | 850 case Variable::LOCAL: { |
851 Comment cmnt(masm_, "[ FunctionDeclaration"); | 851 Comment cmnt(masm_, "[ FunctionDeclaration"); |
852 VisitForAccumulatorValue(declaration->fun()); | 852 VisitForAccumulatorValue(declaration->fun()); |
853 __ movq(StackOperand(variable), result_register()); | 853 __ movq(StackOperand(variable), result_register()); |
854 break; | 854 break; |
855 } | 855 } |
(...skipping 25 matching lines...) Expand all Loading... |
881 __ CallRuntime(Runtime::kDeclareContextSlot, 4); | 881 __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
882 break; | 882 break; |
883 } | 883 } |
884 } | 884 } |
885 } | 885 } |
886 | 886 |
887 | 887 |
888 void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { | 888 void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { |
889 VariableProxy* proxy = declaration->proxy(); | 889 VariableProxy* proxy = declaration->proxy(); |
890 Variable* variable = proxy->var(); | 890 Variable* variable = proxy->var(); |
| 891 Handle<JSModule> instance = declaration->module()->interface()->Instance(); |
| 892 ASSERT(!instance.is_null()); |
| 893 |
891 switch (variable->location()) { | 894 switch (variable->location()) { |
892 case Variable::UNALLOCATED: | 895 case Variable::UNALLOCATED: { |
893 // TODO(rossberg): initialize module instance object | 896 Comment cmnt(masm_, "[ ModuleDeclaration"); |
| 897 globals_->Add(variable->name()); |
| 898 globals_->Add(instance); |
| 899 Visit(declaration->module()); |
894 break; | 900 break; |
| 901 } |
895 | 902 |
896 case Variable::CONTEXT: { | 903 case Variable::CONTEXT: { |
897 Comment cmnt(masm_, "[ ModuleDeclaration"); | 904 Comment cmnt(masm_, "[ ModuleDeclaration"); |
898 EmitDebugCheckDeclarationContext(variable); | 905 EmitDebugCheckDeclarationContext(variable); |
899 // TODO(rossberg): initialize module instance object | 906 __ Move(ContextOperand(rsi, variable->index()), instance); |
| 907 Visit(declaration->module()); |
900 break; | 908 break; |
901 } | 909 } |
902 | 910 |
903 case Variable::PARAMETER: | 911 case Variable::PARAMETER: |
904 case Variable::LOCAL: | 912 case Variable::LOCAL: |
905 case Variable::LOOKUP: | 913 case Variable::LOOKUP: |
906 UNREACHABLE(); | 914 UNREACHABLE(); |
907 } | 915 } |
908 } | 916 } |
909 | 917 |
(...skipping 3586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4496 } | 4504 } |
4497 | 4505 |
4498 | 4506 |
4499 void FullCodeGenerator::LoadContextField(Register dst, int context_index) { | 4507 void FullCodeGenerator::LoadContextField(Register dst, int context_index) { |
4500 __ movq(dst, ContextOperand(rsi, context_index)); | 4508 __ movq(dst, ContextOperand(rsi, context_index)); |
4501 } | 4509 } |
4502 | 4510 |
4503 | 4511 |
4504 void FullCodeGenerator::PushFunctionArgumentForContextAllocation() { | 4512 void FullCodeGenerator::PushFunctionArgumentForContextAllocation() { |
4505 Scope* declaration_scope = scope()->DeclarationScope(); | 4513 Scope* declaration_scope = scope()->DeclarationScope(); |
4506 if (declaration_scope->is_global_scope()) { | 4514 if (declaration_scope->is_global_scope() || |
| 4515 declaration_scope->is_module_scope()) { |
4507 // Contexts nested in the global context have a canonical empty function | 4516 // Contexts nested in the global context have a canonical empty function |
4508 // as their closure, not the anonymous closure containing the global | 4517 // as their closure, not the anonymous closure containing the global |
4509 // code. Pass a smi sentinel and let the runtime look up the empty | 4518 // code. Pass a smi sentinel and let the runtime look up the empty |
4510 // function. | 4519 // function. |
4511 __ Push(Smi::FromInt(0)); | 4520 __ Push(Smi::FromInt(0)); |
4512 } else if (declaration_scope->is_eval_scope()) { | 4521 } else if (declaration_scope->is_eval_scope()) { |
4513 // Contexts created by a call to eval have the same closure as the | 4522 // Contexts created by a call to eval have the same closure as the |
4514 // context calling eval, not the anonymous closure containing the eval | 4523 // context calling eval, not the anonymous closure containing the eval |
4515 // code. Fetch it from the context. | 4524 // code. Fetch it from the context. |
4516 __ push(ContextOperand(rsi, Context::CLOSURE_INDEX)); | 4525 __ push(ContextOperand(rsi, Context::CLOSURE_INDEX)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4578 *context_length = 0; | 4587 *context_length = 0; |
4579 return previous_; | 4588 return previous_; |
4580 } | 4589 } |
4581 | 4590 |
4582 | 4591 |
4583 #undef __ | 4592 #undef __ |
4584 | 4593 |
4585 } } // namespace v8::internal | 4594 } } // namespace v8::internal |
4586 | 4595 |
4587 #endif // V8_TARGET_ARCH_X64 | 4596 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |