| Index: src/full-codegen.cc | 
| =================================================================== | 
| --- src/full-codegen.cc	(revision 11348) | 
| +++ src/full-codegen.cc	(working copy) | 
| @@ -568,88 +568,91 @@ | 
|  | 
| void FullCodeGenerator::VisitDeclarations( | 
| ZoneList<Declaration*>* declarations) { | 
| -  int save_global_count = global_count_; | 
| -  global_count_ = 0; | 
| +  ZoneList<Handle<Object> >* saved_globals = globals_; | 
| +  ZoneList<Handle<Object> > inner_globals(10); | 
| +  globals_ = &inner_globals; | 
|  | 
| AstVisitor::VisitDeclarations(declarations); | 
| - | 
| -  // Batch declare global functions and variables. | 
| -  if (global_count_ > 0) { | 
| -    Handle<FixedArray> array = | 
| -       isolate()->factory()->NewFixedArray(2 * global_count_, TENURED); | 
| -    int length = declarations->length(); | 
| -    for (int j = 0, i = 0; i < length; i++) { | 
| -      Declaration* decl = declarations->at(i); | 
| -      Variable* var = decl->proxy()->var(); | 
| - | 
| -      if (var->IsUnallocated()) { | 
| -        array->set(j++, *(var->name())); | 
| -        FunctionDeclaration* fun_decl = decl->AsFunctionDeclaration(); | 
| -        if (fun_decl == NULL) { | 
| -          if (var->binding_needs_init()) { | 
| -            // In case this binding needs initialization use the hole. | 
| -            array->set_the_hole(j++); | 
| -          } else { | 
| -            array->set_undefined(j++); | 
| -          } | 
| -        } else { | 
| -          Handle<SharedFunctionInfo> function = | 
| -              Compiler::BuildFunctionInfo(fun_decl->fun(), script()); | 
| -          // Check for stack-overflow exception. | 
| -          if (function.is_null()) { | 
| -            SetStackOverflow(); | 
| -            return; | 
| -          } | 
| -          array->set(j++, *function); | 
| -        } | 
| -      } | 
| -    } | 
| +  if (!globals_->is_empty()) { | 
| // Invoke the platform-dependent code generator to do the actual | 
| // declaration the global functions and variables. | 
| +    Handle<FixedArray> array = | 
| +       isolate()->factory()->NewFixedArray(globals_->length(), TENURED); | 
| +    for (int i = 0; i < globals_->length(); ++i) | 
| +      array->set(i, *globals_->at(i)); | 
| DeclareGlobals(array); | 
| } | 
|  | 
| -  global_count_ = save_global_count; | 
| +  globals_ = saved_globals; | 
| } | 
|  | 
|  | 
| -void FullCodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) { | 
| -  EmitDeclaration(decl->proxy(), decl->mode(), NULL); | 
| -} | 
| +void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) { | 
| +  Handle<JSModule> instance = module->interface()->Instance(); | 
| +  ASSERT(!instance.is_null()); | 
|  | 
| +  // Allocate a module context statically. | 
| +  Block* block = module->body(); | 
| +  Scope* saved_scope = scope(); | 
| +  scope_ = block->scope(); | 
| +  Handle<ScopeInfo> scope_info = scope_->GetScopeInfo(); | 
|  | 
| -void FullCodeGenerator::VisitFunctionDeclaration(FunctionDeclaration* decl) { | 
| -  EmitDeclaration(decl->proxy(), decl->mode(), decl->fun()); | 
| -} | 
| +  // Generate code for module creation and linking. | 
| +  Comment cmnt(masm_, "[ ModuleLiteral"); | 
| +  SetStatementPosition(block); | 
|  | 
| +  if (scope_info->HasContext()) { | 
| +    // Set up module context. | 
| +    __ Push(scope_info); | 
| +    __ Push(instance); | 
| +    __ CallRuntime(Runtime::kPushModuleContext, 2); | 
| +    StoreToFrameField( | 
| +        StandardFrameConstants::kContextOffset, context_register()); | 
| +  } | 
|  | 
| -void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* decl) { | 
| -  EmitDeclaration(decl->proxy(), decl->mode(), NULL); | 
| -} | 
| +  { | 
| +    Comment cmnt(masm_, "[ Declarations"); | 
| +    VisitDeclarations(scope_->declarations()); | 
| +  } | 
|  | 
| +  scope_ = saved_scope; | 
| +  if (scope_info->HasContext()) { | 
| +    // Pop module context. | 
| +    LoadContextField(context_register(), Context::PREVIOUS_INDEX); | 
| +    // Update local stack frame context field. | 
| +    StoreToFrameField( | 
| +        StandardFrameConstants::kContextOffset, context_register()); | 
| +  } | 
|  | 
| -void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* decl) { | 
| -  EmitDeclaration(decl->proxy(), decl->mode(), NULL); | 
| +  // Populate module instance object. | 
| +  const PropertyAttributes attr = | 
| +      static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE | DONT_ENUM); | 
| +  for (Interface::Iterator it = module->interface()->iterator(); | 
| +       !it.done(); it.Advance()) { | 
| +    if (it.interface()->IsModule()) { | 
| +      Handle<Object> value = it.interface()->Instance(); | 
| +      ASSERT(!value.is_null()); | 
| +      JSReceiver::SetProperty(instance, it.name(), value, attr, kStrictMode); | 
| +    } else { | 
| +      // TODO(rossberg): set proper getters instead of undefined... | 
| +      // instance->DefineAccessor(*it.name(), ACCESSOR_GETTER, *getter, attr); | 
| +      Handle<Object> value(isolate()->heap()->undefined_value()); | 
| +      JSReceiver::SetProperty(instance, it.name(), value, attr, kStrictMode); | 
| +    } | 
| +  } | 
| +  USE(instance->PreventExtensions()); | 
| } | 
|  | 
|  | 
| -void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* decl) { | 
| -  // TODO(rossberg) | 
| -} | 
| - | 
| - | 
| -void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) { | 
| -  // TODO(rossberg) | 
| -} | 
| - | 
| - | 
| void FullCodeGenerator::VisitModuleVariable(ModuleVariable* module) { | 
| -  // TODO(rossberg) | 
| +  // Noting to do. | 
| +  // The instance object is resolved statically through the module's interface. | 
| } | 
|  | 
|  | 
| void FullCodeGenerator::VisitModulePath(ModulePath* module) { | 
| -  // TODO(rossberg) | 
| +  // Noting to do. | 
| +  // The instance object is resolved statically through the module's interface. | 
| } | 
|  | 
|  | 
| @@ -911,9 +914,9 @@ | 
|  | 
| Scope* saved_scope = scope(); | 
| // Push a block context when entering a block with block scoped variables. | 
| -  if (stmt->block_scope() != NULL) { | 
| +  if (stmt->scope() != NULL) { | 
| { Comment cmnt(masm_, "[ Extend block context"); | 
| -      scope_ = stmt->block_scope(); | 
| +      scope_ = stmt->scope(); | 
| Handle<ScopeInfo> scope_info = scope_->GetScopeInfo(); | 
| int heap_slots = scope_info->ContextLength() - Context::MIN_CONTEXT_SLOTS; | 
| __ Push(scope_info); | 
| @@ -940,7 +943,7 @@ | 
| PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); | 
|  | 
| // Pop block context if necessary. | 
| -  if (stmt->block_scope() != NULL) { | 
| +  if (stmt->scope() != NULL) { | 
| LoadContextField(context_register(), Context::PREVIOUS_INDEX); | 
| // Update local stack frame context field. | 
| StoreToFrameField(StandardFrameConstants::kContextOffset, | 
|  |