OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/ast.h" | 7 #include "src/ast.h" |
8 #include "src/ast-numbering.h" | 8 #include "src/ast-numbering.h" |
9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 void FullCodeGenerator::AllocateModules(ZoneList<Declaration*>* declarations) { | 603 void FullCodeGenerator::AllocateModules(ZoneList<Declaration*>* declarations) { |
604 DCHECK(scope_->is_script_scope()); | 604 DCHECK(scope_->is_script_scope()); |
605 | 605 |
606 for (int i = 0; i < declarations->length(); i++) { | 606 for (int i = 0; i < declarations->length(); i++) { |
607 ModuleDeclaration* declaration = declarations->at(i)->AsModuleDeclaration(); | 607 ModuleDeclaration* declaration = declarations->at(i)->AsModuleDeclaration(); |
608 if (declaration != NULL) { | 608 if (declaration != NULL) { |
609 ModuleLiteral* module = declaration->module()->AsModuleLiteral(); | 609 ModuleLiteral* module = declaration->module()->AsModuleLiteral(); |
610 if (module != NULL) { | 610 if (module != NULL) { |
611 Comment cmnt(masm_, "[ Link nested modules"); | 611 Comment cmnt(masm_, "[ Link nested modules"); |
612 Scope* scope = module->body()->scope(); | 612 Scope* scope = module->body()->scope(); |
613 Interface* interface = scope->interface(); | 613 DCHECK(scope->module()->IsFrozen()); |
614 DCHECK(interface->IsFrozen()); | |
615 | 614 |
616 interface->Allocate(scope->module_var()->index()); | 615 scope->module()->Allocate(scope->module_var()->index()); |
617 | 616 |
618 // Set up module context. | 617 // Set up module context. |
619 DCHECK(scope->interface()->Index() >= 0); | 618 DCHECK(scope->module()->Index() >= 0); |
620 __ Push(Smi::FromInt(scope->interface()->Index())); | 619 __ Push(Smi::FromInt(scope->module()->Index())); |
621 __ Push(scope->GetScopeInfo(isolate())); | 620 __ Push(scope->GetScopeInfo(isolate())); |
622 __ CallRuntime(Runtime::kPushModuleContext, 2); | 621 __ CallRuntime(Runtime::kPushModuleContext, 2); |
623 StoreToFrameField(StandardFrameConstants::kContextOffset, | 622 StoreToFrameField(StandardFrameConstants::kContextOffset, |
624 context_register()); | 623 context_register()); |
625 | 624 |
626 AllocateModules(scope->declarations()); | 625 AllocateModules(scope->declarations()); |
627 | 626 |
628 // Pop module context. | 627 // Pop module context. |
629 LoadContextField(context_register(), Context::PREVIOUS_INDEX); | 628 LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
630 // Update local stack frame context field. | 629 // Update local stack frame context field. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 } | 743 } |
745 | 744 |
746 globals_ = saved_globals; | 745 globals_ = saved_globals; |
747 } | 746 } |
748 | 747 |
749 | 748 |
750 void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) { | 749 void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) { |
751 Block* block = module->body(); | 750 Block* block = module->body(); |
752 Scope* saved_scope = scope(); | 751 Scope* saved_scope = scope(); |
753 scope_ = block->scope(); | 752 scope_ = block->scope(); |
754 Interface* interface = scope_->interface(); | 753 ModuleDescriptor* descriptor = scope_->module(); |
755 | 754 |
756 Comment cmnt(masm_, "[ ModuleLiteral"); | 755 Comment cmnt(masm_, "[ ModuleLiteral"); |
757 SetStatementPosition(block); | 756 SetStatementPosition(block); |
758 | 757 |
759 DCHECK(!modules_.is_null()); | 758 DCHECK(!modules_.is_null()); |
760 DCHECK(module_index_ < modules_->length()); | 759 DCHECK(module_index_ < modules_->length()); |
761 int index = module_index_++; | 760 int index = module_index_++; |
762 | 761 |
763 // Set up module context. | 762 // Set up module context. |
764 DCHECK(interface->Index() >= 0); | 763 DCHECK(descriptor->Index() >= 0); |
765 __ Push(Smi::FromInt(interface->Index())); | 764 __ Push(Smi::FromInt(descriptor->Index())); |
766 __ Push(Smi::FromInt(0)); | 765 __ Push(Smi::FromInt(0)); |
767 __ CallRuntime(Runtime::kPushModuleContext, 2); | 766 __ CallRuntime(Runtime::kPushModuleContext, 2); |
768 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); | 767 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
769 | 768 |
770 { | 769 { |
771 Comment cmnt(masm_, "[ Declarations"); | 770 Comment cmnt(masm_, "[ Declarations"); |
772 VisitDeclarations(scope_->declarations()); | 771 VisitDeclarations(scope_->declarations()); |
773 } | 772 } |
774 | 773 |
775 // Populate the module description. | 774 // Populate the module description. |
776 Handle<ModuleInfo> description = | 775 Handle<ModuleInfo> description = |
777 ModuleInfo::Create(isolate(), interface, scope_); | 776 ModuleInfo::Create(isolate(), descriptor, scope_); |
778 modules_->set(index, *description); | 777 modules_->set(index, *description); |
779 | 778 |
780 scope_ = saved_scope; | 779 scope_ = saved_scope; |
781 // Pop module context. | 780 // Pop module context. |
782 LoadContextField(context_register(), Context::PREVIOUS_INDEX); | 781 LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
783 // Update local stack frame context field. | 782 // Update local stack frame context field. |
784 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); | 783 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
785 } | 784 } |
786 | 785 |
787 | 786 |
| 787 // TODO(adamk): Delete ModulePath. |
788 void FullCodeGenerator::VisitModulePath(ModulePath* module) { | 788 void FullCodeGenerator::VisitModulePath(ModulePath* module) { |
789 // Nothing to do. | |
790 // The instance object is resolved statically through the module's interface. | |
791 } | 789 } |
792 | 790 |
793 | 791 |
| 792 // TODO(adamk): Delete ModuleUrl. |
794 void FullCodeGenerator::VisitModuleUrl(ModuleUrl* module) { | 793 void FullCodeGenerator::VisitModuleUrl(ModuleUrl* module) { |
795 // TODO(rossberg): dummy allocation for now. | |
796 Scope* scope = module->body()->scope(); | |
797 Interface* interface = scope_->interface(); | |
798 | |
799 DCHECK(interface->IsFrozen()); | |
800 DCHECK(!modules_.is_null()); | |
801 DCHECK(module_index_ < modules_->length()); | |
802 interface->Allocate(scope->module_var()->index()); | |
803 int index = module_index_++; | |
804 | |
805 Handle<ModuleInfo> description = | |
806 ModuleInfo::Create(isolate(), interface, scope_); | |
807 modules_->set(index, *description); | |
808 } | 794 } |
809 | 795 |
810 | 796 |
811 int FullCodeGenerator::DeclareGlobalsFlags() { | 797 int FullCodeGenerator::DeclareGlobalsFlags() { |
812 DCHECK(DeclareGlobalsLanguageMode::is_valid(language_mode())); | 798 DCHECK(DeclareGlobalsLanguageMode::is_valid(language_mode())); |
813 return DeclareGlobalsEvalFlag::encode(is_eval()) | | 799 return DeclareGlobalsEvalFlag::encode(is_eval()) | |
814 DeclareGlobalsNativeFlag::encode(is_native()) | | 800 DeclareGlobalsNativeFlag::encode(is_native()) | |
815 DeclareGlobalsLanguageMode::encode(language_mode()); | 801 DeclareGlobalsLanguageMode::encode(language_mode()); |
816 } | 802 } |
817 | 803 |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 __ bind(nested_block.break_label()); | 1074 __ bind(nested_block.break_label()); |
1089 } | 1075 } |
1090 } | 1076 } |
1091 | 1077 |
1092 | 1078 |
1093 void FullCodeGenerator::VisitModuleStatement(ModuleStatement* stmt) { | 1079 void FullCodeGenerator::VisitModuleStatement(ModuleStatement* stmt) { |
1094 Comment cmnt(masm_, "[ Module context"); | 1080 Comment cmnt(masm_, "[ Module context"); |
1095 | 1081 |
1096 DCHECK(stmt->body()->scope()->is_module_scope()); | 1082 DCHECK(stmt->body()->scope()->is_module_scope()); |
1097 | 1083 |
1098 __ Push(Smi::FromInt(stmt->body()->scope()->interface()->Index())); | 1084 __ Push(Smi::FromInt(stmt->body()->scope()->module()->Index())); |
1099 __ Push(Smi::FromInt(0)); | 1085 __ Push(Smi::FromInt(0)); |
1100 __ CallRuntime(Runtime::kPushModuleContext, 2); | 1086 __ CallRuntime(Runtime::kPushModuleContext, 2); |
1101 StoreToFrameField( | 1087 StoreToFrameField( |
1102 StandardFrameConstants::kContextOffset, context_register()); | 1088 StandardFrameConstants::kContextOffset, context_register()); |
1103 | 1089 |
1104 Scope* saved_scope = scope_; | 1090 Scope* saved_scope = scope_; |
1105 scope_ = stmt->body()->scope(); | 1091 scope_ = stmt->body()->scope(); |
1106 VisitStatements(stmt->body()->statements()); | 1092 VisitStatements(stmt->body()->statements()); |
1107 scope_ = saved_scope; | 1093 scope_ = saved_scope; |
1108 LoadContextField(context_register(), Context::PREVIOUS_INDEX); | 1094 LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1837 } | 1823 } |
1838 codegen_->PrepareForBailoutForId(exit_id_, NO_REGISTERS); | 1824 codegen_->PrepareForBailoutForId(exit_id_, NO_REGISTERS); |
1839 codegen_->scope_ = saved_scope_; | 1825 codegen_->scope_ = saved_scope_; |
1840 } | 1826 } |
1841 | 1827 |
1842 | 1828 |
1843 #undef __ | 1829 #undef __ |
1844 | 1830 |
1845 | 1831 |
1846 } } // namespace v8::internal | 1832 } } // namespace v8::internal |
OLD | NEW |