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 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 VariableDeclaration* declaration) { | 775 VariableDeclaration* declaration) { |
776 // If it was not possible to allocate the variable at compile time, we | 776 // If it was not possible to allocate the variable at compile time, we |
777 // need to "declare" it at runtime to make sure it actually exists in the | 777 // need to "declare" it at runtime to make sure it actually exists in the |
778 // local context. | 778 // local context. |
779 VariableProxy* proxy = declaration->proxy(); | 779 VariableProxy* proxy = declaration->proxy(); |
780 VariableMode mode = declaration->mode(); | 780 VariableMode mode = declaration->mode(); |
781 Variable* variable = proxy->var(); | 781 Variable* variable = proxy->var(); |
782 bool hole_init = mode == CONST || mode == CONST_HARMONY || mode == LET; | 782 bool hole_init = mode == CONST || mode == CONST_HARMONY || mode == LET; |
783 switch (variable->location()) { | 783 switch (variable->location()) { |
784 case Variable::UNALLOCATED: | 784 case Variable::UNALLOCATED: |
785 globals_.Add(variable->name()); | 785 globals_->Add(variable->name()); |
786 globals_.Add(variable->binding_needs_init() | 786 globals_->Add(variable->binding_needs_init() |
787 ? isolate()->factory()->the_hole_value() | 787 ? isolate()->factory()->the_hole_value() |
788 : isolate()->factory()->undefined_value()); | 788 : isolate()->factory()->undefined_value()); |
789 break; | 789 break; |
790 | 790 |
791 case Variable::PARAMETER: | 791 case Variable::PARAMETER: |
792 case Variable::LOCAL: | 792 case Variable::LOCAL: |
793 if (hole_init) { | 793 if (hole_init) { |
794 Comment cmnt(masm_, "[ VariableDeclaration"); | 794 Comment cmnt(masm_, "[ VariableDeclaration"); |
795 __ mov(StackOperand(variable), | 795 __ mov(StackOperand(variable), |
796 Immediate(isolate()->factory()->the_hole_value())); | 796 Immediate(isolate()->factory()->the_hole_value())); |
797 } | 797 } |
798 break; | 798 break; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 } | 833 } |
834 } | 834 } |
835 | 835 |
836 | 836 |
837 void FullCodeGenerator::VisitFunctionDeclaration( | 837 void FullCodeGenerator::VisitFunctionDeclaration( |
838 FunctionDeclaration* declaration) { | 838 FunctionDeclaration* declaration) { |
839 VariableProxy* proxy = declaration->proxy(); | 839 VariableProxy* proxy = declaration->proxy(); |
840 Variable* variable = proxy->var(); | 840 Variable* variable = proxy->var(); |
841 switch (variable->location()) { | 841 switch (variable->location()) { |
842 case Variable::UNALLOCATED: { | 842 case Variable::UNALLOCATED: { |
843 globals_.Add(variable->name()); | 843 globals_->Add(variable->name()); |
844 Handle<SharedFunctionInfo> function = | 844 Handle<SharedFunctionInfo> function = |
845 Compiler::BuildFunctionInfo(declaration->fun(), script()); | 845 Compiler::BuildFunctionInfo(declaration->fun(), script()); |
846 // Check for stack-overflow exception. | 846 // Check for stack-overflow exception. |
847 if (function.is_null()) return SetStackOverflow(); | 847 if (function.is_null()) return SetStackOverflow(); |
848 globals_.Add(function); | 848 globals_->Add(function); |
849 break; | 849 break; |
850 } | 850 } |
851 | 851 |
852 case Variable::PARAMETER: | 852 case Variable::PARAMETER: |
853 case Variable::LOCAL: { | 853 case Variable::LOCAL: { |
854 Comment cmnt(masm_, "[ FunctionDeclaration"); | 854 Comment cmnt(masm_, "[ FunctionDeclaration"); |
855 VisitForAccumulatorValue(declaration->fun()); | 855 VisitForAccumulatorValue(declaration->fun()); |
856 __ mov(StackOperand(variable), result_register()); | 856 __ mov(StackOperand(variable), result_register()); |
857 break; | 857 break; |
858 } | 858 } |
(...skipping 24 matching lines...) Expand all Loading... |
883 __ CallRuntime(Runtime::kDeclareContextSlot, 4); | 883 __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
884 break; | 884 break; |
885 } | 885 } |
886 } | 886 } |
887 } | 887 } |
888 | 888 |
889 | 889 |
890 void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { | 890 void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { |
891 VariableProxy* proxy = declaration->proxy(); | 891 VariableProxy* proxy = declaration->proxy(); |
892 Variable* variable = proxy->var(); | 892 Variable* variable = proxy->var(); |
| 893 Handle<JSModule> instance = declaration->module()->interface()->Instance(); |
| 894 ASSERT(!instance.is_null()); |
| 895 |
893 switch (variable->location()) { | 896 switch (variable->location()) { |
894 case Variable::UNALLOCATED: | 897 case Variable::UNALLOCATED: { |
895 // TODO(rossberg): initialize module instance object | 898 Comment cmnt(masm_, "[ ModuleDeclaration"); |
| 899 globals_->Add(variable->name()); |
| 900 globals_->Add(instance); |
| 901 Visit(declaration->module()); |
896 break; | 902 break; |
| 903 } |
897 | 904 |
898 case Variable::CONTEXT: { | 905 case Variable::CONTEXT: { |
899 Comment cmnt(masm_, "[ ModuleDeclaration"); | 906 Comment cmnt(masm_, "[ ModuleDeclaration"); |
900 EmitDebugCheckDeclarationContext(variable); | 907 EmitDebugCheckDeclarationContext(variable); |
901 // TODO(rossberg): initialize module instance object | 908 __ mov(ContextOperand(esi, variable->index()), Immediate(instance)); |
| 909 Visit(declaration->module()); |
902 break; | 910 break; |
903 } | 911 } |
904 | 912 |
905 case Variable::PARAMETER: | 913 case Variable::PARAMETER: |
906 case Variable::LOCAL: | 914 case Variable::LOCAL: |
907 case Variable::LOOKUP: | 915 case Variable::LOOKUP: |
908 UNREACHABLE(); | 916 UNREACHABLE(); |
909 } | 917 } |
910 } | 918 } |
911 | 919 |
(...skipping 3602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4514 } | 4522 } |
4515 | 4523 |
4516 | 4524 |
4517 void FullCodeGenerator::LoadContextField(Register dst, int context_index) { | 4525 void FullCodeGenerator::LoadContextField(Register dst, int context_index) { |
4518 __ mov(dst, ContextOperand(esi, context_index)); | 4526 __ mov(dst, ContextOperand(esi, context_index)); |
4519 } | 4527 } |
4520 | 4528 |
4521 | 4529 |
4522 void FullCodeGenerator::PushFunctionArgumentForContextAllocation() { | 4530 void FullCodeGenerator::PushFunctionArgumentForContextAllocation() { |
4523 Scope* declaration_scope = scope()->DeclarationScope(); | 4531 Scope* declaration_scope = scope()->DeclarationScope(); |
4524 if (declaration_scope->is_global_scope()) { | 4532 if (declaration_scope->is_global_scope() || |
| 4533 declaration_scope->is_module_scope()) { |
4525 // Contexts nested in the global context have a canonical empty function | 4534 // Contexts nested in the global context have a canonical empty function |
4526 // as their closure, not the anonymous closure containing the global | 4535 // as their closure, not the anonymous closure containing the global |
4527 // code. Pass a smi sentinel and let the runtime look up the empty | 4536 // code. Pass a smi sentinel and let the runtime look up the empty |
4528 // function. | 4537 // function. |
4529 __ push(Immediate(Smi::FromInt(0))); | 4538 __ push(Immediate(Smi::FromInt(0))); |
4530 } else if (declaration_scope->is_eval_scope()) { | 4539 } else if (declaration_scope->is_eval_scope()) { |
4531 // Contexts nested inside eval code have the same closure as the context | 4540 // Contexts nested inside eval code have the same closure as the context |
4532 // calling eval, not the anonymous closure containing the eval code. | 4541 // calling eval, not the anonymous closure containing the eval code. |
4533 // Fetch it from the context. | 4542 // Fetch it from the context. |
4534 __ push(ContextOperand(esi, Context::CLOSURE_INDEX)); | 4543 __ push(ContextOperand(esi, Context::CLOSURE_INDEX)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4593 *context_length = 0; | 4602 *context_length = 0; |
4594 return previous_; | 4603 return previous_; |
4595 } | 4604 } |
4596 | 4605 |
4597 | 4606 |
4598 #undef __ | 4607 #undef __ |
4599 | 4608 |
4600 } } // namespace v8::internal | 4609 } } // namespace v8::internal |
4601 | 4610 |
4602 #endif // V8_TARGET_ARCH_IA32 | 4611 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |