}
-void FullCodeGenerator::EmitDeclaration(Variable* variable,
+void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy,
Variable::Mode mode,
FunctionLiteral* function) {
Comment cmnt(masm_, "[ Declaration");
+ Variable* variable = proxy->var();
ASSERT(variable != NULL); // Must have been resolved.
Slot* slot = variable->AsSlot();
ASSERT(slot != NULL);
// We know that we have written a function, which is not a smi.
__ mov(r1, Operand(cp));
__ RecordWrite(r1, Operand(offset), r2, result_register());
+ PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
} else if (mode == Variable::CONST || mode == Variable::LET) {
__ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
__ str(ip, ContextOperand(cp, slot->index()));
// No write barrier since the_hole_value is in old space.
+ PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
}
break;
void FullCodeGenerator::VisitDeclaration(Declaration* decl) {
- EmitDeclaration(decl->proxy()->var(), decl->mode(), decl->fun());
+ EmitDeclaration(decl->proxy(), decl->mode(), decl->fun());
}
// Platform-specific code for a variable, constant, or function
// declaration. Functions have an initial value.
- void EmitDeclaration(Variable* variable,
+ void EmitDeclaration(VariableProxy* proxy,
Variable::Mode mode,
FunctionLiteral* function);
// Handle implicit declaration of the function name in named function
// expressions before other declarations.
if (scope->is_function_scope() && scope->function() != NULL) {
- if (!scope->function()->IsStackAllocated()) {
- Bailout("unsupported declaration");
- return NULL;
- }
- environment()->Bind(scope->function(), graph()->GetConstantHole());
+ HandleDeclaration(scope->function(), Variable::CONST, NULL);
}
VisitDeclarations(scope->declarations());
AddSimulate(AstNode::kDeclarationsId);
void HGraphBuilder::VisitDeclaration(Declaration* decl) {
- // We support only declarations that do not require code generation.
- Variable* var = decl->proxy()->var();
- if (!var->IsStackAllocated() ||
- decl->mode() == Variable::LET) {
- return Bailout("unsupported declaration");
- }
-
- if (decl->mode() == Variable::CONST) {
- ASSERT(var->IsStackAllocated());
- environment()->Bind(var, graph()->GetConstantHole());
- } else if (decl->fun() != NULL) {
- VisitForValue(decl->fun());
- HValue* function = Pop();
- environment()->Bind(var, function);
+ HandleDeclaration(decl->proxy(), decl->mode(), decl->fun());
+}
+
+
+void HGraphBuilder::HandleDeclaration(VariableProxy* proxy,
+ Variable::Mode mode,
+ FunctionLiteral* function) {
+ if (mode == Variable::LET) return Bailout("unsupported let declaration");
+ Variable* var = proxy->var();
+ Slot* slot = var->AsSlot();
+ ASSERT(slot != NULL);
+ switch (slot->type()) {
+ case Slot::PARAMETER:
+ case Slot::LOCAL:
+ if (mode == Variable::CONST) {
+ environment()->Bind(var, graph()->GetConstantHole());
+ } else if (function != NULL) {
+ VisitForValue(function);
+ HValue* function_value = Pop();
+ environment()->Bind(var, function_value);
+ }
+ break;
+ case Slot::CONTEXT: {
+ HValue* context = environment()->LookupContext();
+ if (mode == Variable::CONST) {
+ HStoreContextSlot* store =
+ new HStoreContextSlot(context,
+ slot->index(),
+ graph()->GetConstantHole());
+ AddInstruction(store);
+ if (store->HasSideEffects()) AddSimulate(proxy->id());
+ } else if (function != NULL) {
+ VisitForValue(function);
+ HValue* function_value = Pop();
+ HStoreContextSlot* store =
+ new HStoreContextSlot(context,
+ slot->index(),
+ function_value);
+ AddInstruction(store);
+ if (store->HasSideEffects()) AddSimulate(proxy->id());
+ }
+ break;
+ }
+ case Slot::LOOKUP:
+ return Bailout("unsupported lookup slot in declaration");
}
}
INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_DECLARATION)
#undef INLINE_FUNCTION_GENERATOR_DECLARATION
+ void HandleDeclaration(VariableProxy* proxy,
+ Variable::Mode mode,
+ FunctionLiteral* function);
+
void VisitDelete(UnaryOperation* expr);
void VisitVoid(UnaryOperation* expr);
void VisitTypeof(UnaryOperation* expr);
}
-void FullCodeGenerator::EmitDeclaration(Variable* variable,
+void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy,
Variable::Mode mode,
FunctionLiteral* function) {
Comment cmnt(masm_, "[ Declaration");
+ Variable* variable = proxy->var();
ASSERT(variable != NULL); // Must have been resolved.
Slot* slot = variable->AsSlot();
ASSERT(slot != NULL);
int offset = Context::SlotOffset(slot->index());
__ mov(ebx, esi);
__ RecordWrite(ebx, offset, result_register(), ecx);
+ PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
} else if (mode == Variable::CONST || mode == Variable::LET) {
__ mov(ContextOperand(esi, slot->index()),
Immediate(isolate()->factory()->the_hole_value()));
// No write barrier since the hole value is in old space.
+ PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
}
break;
void FullCodeGenerator::VisitDeclaration(Declaration* decl) {
- EmitDeclaration(decl->proxy()->var(), decl->mode(), decl->fun());
+ EmitDeclaration(decl->proxy(), decl->mode(), decl->fun());
}
// For now, this must happen at the very end because of the
// ordering of the scope info slots and the respective slot indices.
if (scope->is_function_scope()) {
- Variable* var = scope->function();
- if (var != NULL &&
- var->is_used() &&
- var->AsSlot()->type() == Slot::CONTEXT) {
- function_name_ = var->name();
+ VariableProxy* proxy = scope->function();
+ if (proxy != NULL &&
+ proxy->var()->is_used() &&
+ proxy->var()->IsContextSlot()) {
+ function_name_ = proxy->name();
// Note that we must not find the function name in the context slot
// list - instead it must be handled separately in the
// Contexts::Lookup() function. Thus record an empty symbol here so we
// get the correct number of context slots.
- ASSERT(var->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS ==
+ ASSERT(proxy->var()->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS ==
context_slots_.length());
- ASSERT(var->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS ==
+ ASSERT(proxy->var()->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS ==
context_modes_.length());
context_slots_.Add(FACTORY->empty_symbol());
context_modes_.Add(Variable::INTERNAL);
Variable* Scope::DeclareFunctionVar(Handle<String> name) {
ASSERT(is_function_scope() && function_ == NULL);
- function_ = new Variable(this, name, Variable::CONST, true, Variable::NORMAL);
- return function_;
+ Variable* function_var =
+ new Variable(this, name, Variable::CONST, true, Variable::NORMAL);
+ function_ = new(isolate_->zone()) VariableProxy(isolate_, function_var);
+ return function_->var();
}
PrettyPrinter printer;
Indent(n1, "// function var\n");
if (function_ != NULL) {
- PrintVar(&printer, n1, function_);
+ PrintVar(&printer, n1, function_->var());
}
Indent(n1, "// temporary vars\n");
// the name of named function literal is kept in an intermediate scope
// in between this scope and the next outer scope.)
if (function_ != NULL && function_->name().is_identical_to(name)) {
- var = function_;
+ var = function_->var();
} else if (outer_scope_ != NULL) {
var = outer_scope_->LookupRecursive(
// because of the current ScopeInfo implementation (see
// ScopeInfo::ScopeInfo(FunctionScope* scope) constructor).
if (function_ != NULL) {
- AllocateNonParameterLocal(function_);
+ AllocateNonParameterLocal(function_->var());
}
}
// The variable holding the function literal for named function
// literals, or NULL.
// Only valid for function scopes.
- Variable* function() const {
+ VariableProxy* function() const {
ASSERT(is_function_scope());
return function_;
}
// Convenience variable.
Variable* receiver_;
// Function variable, if any; function scopes only.
- Variable* function_;
+ VariableProxy* function_;
// Convenience variable; function scopes only.
Variable* arguments_;
}
-void FullCodeGenerator::EmitDeclaration(Variable* variable,
+void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy,
Variable::Mode mode,
FunctionLiteral* function) {
Comment cmnt(masm_, "[ Declaration");
+ Variable* variable = proxy->var();
ASSERT(variable != NULL); // Must have been resolved.
Slot* slot = variable->AsSlot();
ASSERT(slot != NULL);
int offset = Context::SlotOffset(slot->index());
__ movq(rbx, rsi);
__ RecordWrite(rbx, offset, result_register(), rcx);
+ PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
} else if (mode == Variable::CONST || mode == Variable::LET) {
__ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex);
__ movq(ContextOperand(rsi, slot->index()), kScratchRegister);
// No write barrier since the hole value is in old space.
+ PrepareForBailoutForId(proxy->id(), NO_REGISTERS);
}
break;
void FullCodeGenerator::VisitDeclaration(Declaration* decl) {
- EmitDeclaration(decl->proxy()->var(), decl->mode(), decl->fun());
+ EmitDeclaration(decl->proxy(), decl->mode(), decl->fun());
}