Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: src/full-codegen.cc

Issue 9844002: Implement rudimentary module linking. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/full-codegen.h ('k') | src/heap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 void FullCodeGenerator::DoTest(const TestContext* context) { 561 void FullCodeGenerator::DoTest(const TestContext* context) {
562 DoTest(context->condition(), 562 DoTest(context->condition(),
563 context->true_label(), 563 context->true_label(),
564 context->false_label(), 564 context->false_label(),
565 context->fall_through()); 565 context->fall_through());
566 } 566 }
567 567
568 568
569 void FullCodeGenerator::VisitDeclarations( 569 void FullCodeGenerator::VisitDeclarations(
570 ZoneList<Declaration*>* declarations) { 570 ZoneList<Declaration*>* declarations) {
571 ASSERT(globals_.is_empty()); 571 ZoneList<Handle<Object> >* saved_globals = globals_;
572 ZoneList<Handle<Object> > inner_globals(10);
573 globals_ = &inner_globals;
574
572 AstVisitor::VisitDeclarations(declarations); 575 AstVisitor::VisitDeclarations(declarations);
573 if (!globals_.is_empty()) { 576 if (!globals_->is_empty()) {
574 // Invoke the platform-dependent code generator to do the actual 577 // Invoke the platform-dependent code generator to do the actual
575 // declaration the global functions and variables. 578 // declaration the global functions and variables.
576 Handle<FixedArray> array = 579 Handle<FixedArray> array =
577 isolate()->factory()->NewFixedArray(globals_.length(), TENURED); 580 isolate()->factory()->NewFixedArray(globals_->length(), TENURED);
578 for (int i = 0; i < globals_.length(); ++i) array->set(i, *globals_.at(i)); 581 for (int i = 0; i < globals_->length(); ++i)
582 array->set(i, *globals_->at(i));
579 DeclareGlobals(array); 583 DeclareGlobals(array);
580 globals_.Clear();
581 } 584 }
585
586 globals_ = saved_globals;
582 } 587 }
583 588
584 589
585 void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) { 590 void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) {
586 // TODO(rossberg) 591 Handle<JSModule> instance = module->interface()->Instance();
592 ASSERT(!instance.is_null());
593
594 // Allocate a module context statically.
595 Block* block = module->body();
596 Scope* saved_scope = scope();
597 scope_ = block->scope();
598 Handle<ScopeInfo> scope_info = scope_->GetScopeInfo();
599
600 // Generate code for module creation and linking.
601 Comment cmnt(masm_, "[ ModuleLiteral");
602 SetStatementPosition(block);
603
604 if (scope_info->HasContext()) {
605 // Set up module context.
606 __ Push(scope_info);
607 __ Push(instance);
608 __ CallRuntime(Runtime::kPushModuleContext, 2);
609 StoreToFrameField(
610 StandardFrameConstants::kContextOffset, context_register());
611 }
612
613 {
614 Comment cmnt(masm_, "[ Declarations");
615 VisitDeclarations(scope_->declarations());
616 }
617
618 scope_ = saved_scope;
619 if (scope_info->HasContext()) {
620 // Pop module context.
621 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
622 // Update local stack frame context field.
623 StoreToFrameField(
624 StandardFrameConstants::kContextOffset, context_register());
625 }
626
627 // Populate module instance object.
628 const PropertyAttributes attr =
629 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE | DONT_ENUM);
630 for (Interface::Iterator it = module->interface()->iterator();
631 !it.done(); it.Advance()) {
632 if (it.interface()->IsModule()) {
633 Handle<Object> value = it.interface()->Instance();
634 ASSERT(!value.is_null());
635 JSReceiver::SetProperty(instance, it.name(), value, attr, kStrictMode);
636 } else {
637 // TODO(rossberg): set proper getters instead of undefined...
638 // instance->DefineAccessor(*it.name(), ACCESSOR_GETTER, *getter, attr);
639 Handle<Object> value(isolate()->heap()->undefined_value());
640 JSReceiver::SetProperty(instance, it.name(), value, attr, kStrictMode);
641 }
642 }
643 USE(instance->PreventExtensions());
587 } 644 }
588 645
589 646
590 void FullCodeGenerator::VisitModuleVariable(ModuleVariable* module) { 647 void FullCodeGenerator::VisitModuleVariable(ModuleVariable* module) {
591 // TODO(rossberg) 648 // Noting to do.
649 // The instance object is resolved statically through the module's interface.
592 } 650 }
593 651
594 652
595 void FullCodeGenerator::VisitModulePath(ModulePath* module) { 653 void FullCodeGenerator::VisitModulePath(ModulePath* module) {
596 // TODO(rossberg) 654 // Noting to do.
655 // The instance object is resolved statically through the module's interface.
597 } 656 }
598 657
599 658
600 void FullCodeGenerator::VisitModuleUrl(ModuleUrl* decl) { 659 void FullCodeGenerator::VisitModuleUrl(ModuleUrl* decl) {
601 // TODO(rossberg) 660 // TODO(rossberg)
602 } 661 }
603 662
604 663
605 int FullCodeGenerator::DeclareGlobalsFlags() { 664 int FullCodeGenerator::DeclareGlobalsFlags() {
606 ASSERT(DeclareGlobalsLanguageMode::is_valid(language_mode())); 665 ASSERT(DeclareGlobalsLanguageMode::is_valid(language_mode()));
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 } 907 }
849 908
850 909
851 void FullCodeGenerator::VisitBlock(Block* stmt) { 910 void FullCodeGenerator::VisitBlock(Block* stmt) {
852 Comment cmnt(masm_, "[ Block"); 911 Comment cmnt(masm_, "[ Block");
853 NestedBlock nested_block(this, stmt); 912 NestedBlock nested_block(this, stmt);
854 SetStatementPosition(stmt); 913 SetStatementPosition(stmt);
855 914
856 Scope* saved_scope = scope(); 915 Scope* saved_scope = scope();
857 // Push a block context when entering a block with block scoped variables. 916 // Push a block context when entering a block with block scoped variables.
858 if (stmt->block_scope() != NULL) { 917 if (stmt->scope() != NULL) {
859 { Comment cmnt(masm_, "[ Extend block context"); 918 { Comment cmnt(masm_, "[ Extend block context");
860 scope_ = stmt->block_scope(); 919 scope_ = stmt->scope();
861 Handle<ScopeInfo> scope_info = scope_->GetScopeInfo(); 920 Handle<ScopeInfo> scope_info = scope_->GetScopeInfo();
862 int heap_slots = scope_info->ContextLength() - Context::MIN_CONTEXT_SLOTS; 921 int heap_slots = scope_info->ContextLength() - Context::MIN_CONTEXT_SLOTS;
863 __ Push(scope_info); 922 __ Push(scope_info);
864 PushFunctionArgumentForContextAllocation(); 923 PushFunctionArgumentForContextAllocation();
865 if (heap_slots <= FastNewBlockContextStub::kMaximumSlots) { 924 if (heap_slots <= FastNewBlockContextStub::kMaximumSlots) {
866 FastNewBlockContextStub stub(heap_slots); 925 FastNewBlockContextStub stub(heap_slots);
867 __ CallStub(&stub); 926 __ CallStub(&stub);
868 } else { 927 } else {
869 __ CallRuntime(Runtime::kPushBlockContext, 2); 928 __ CallRuntime(Runtime::kPushBlockContext, 2);
870 } 929 }
871 930
872 // Replace the context stored in the frame. 931 // Replace the context stored in the frame.
873 StoreToFrameField(StandardFrameConstants::kContextOffset, 932 StoreToFrameField(StandardFrameConstants::kContextOffset,
874 context_register()); 933 context_register());
875 } 934 }
876 { Comment cmnt(masm_, "[ Declarations"); 935 { Comment cmnt(masm_, "[ Declarations");
877 VisitDeclarations(scope_->declarations()); 936 VisitDeclarations(scope_->declarations());
878 } 937 }
879 } 938 }
880 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); 939 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
881 VisitStatements(stmt->statements()); 940 VisitStatements(stmt->statements());
882 scope_ = saved_scope; 941 scope_ = saved_scope;
883 __ bind(nested_block.break_label()); 942 __ bind(nested_block.break_label());
884 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); 943 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
885 944
886 // Pop block context if necessary. 945 // Pop block context if necessary.
887 if (stmt->block_scope() != NULL) { 946 if (stmt->scope() != NULL) {
888 LoadContextField(context_register(), Context::PREVIOUS_INDEX); 947 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
889 // Update local stack frame context field. 948 // Update local stack frame context field.
890 StoreToFrameField(StandardFrameConstants::kContextOffset, 949 StoreToFrameField(StandardFrameConstants::kContextOffset,
891 context_register()); 950 context_register());
892 } 951 }
893 } 952 }
894 953
895 954
896 void FullCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { 955 void FullCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) {
897 Comment cmnt(masm_, "[ ExpressionStatement"); 956 Comment cmnt(masm_, "[ ExpressionStatement");
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1363 } 1422 }
1364 1423
1365 return false; 1424 return false;
1366 } 1425 }
1367 1426
1368 1427
1369 #undef __ 1428 #undef __
1370 1429
1371 1430
1372 } } // namespace v8::internal 1431 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/full-codegen.h ('k') | src/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698