Index: src/interpreter/bytecode-generator.cc |
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc |
index 959e15514976132c32a0292e367ba17ea3b23d5e..08fd0e2d13b90cbc1a2e77314dc20ae96849e200 100644 |
--- a/src/interpreter/bytecode-generator.cc |
+++ b/src/interpreter/bytecode-generator.cc |
@@ -445,6 +445,8 @@ void BytecodeGenerator::VisitBlock(Block* stmt) { |
void BytecodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) { |
+ RegisterAllocationScope register_scope(this); |
rmcilroy
2016/01/15 14:17:20
Instead of adding these, could you instead modify
mythria
2016/01/15 17:10:36
Done.
|
+ |
Variable* variable = decl->proxy()->var(); |
VariableMode mode = decl->mode(); |
// Const and let variables are initialized with the hole so that we can |
@@ -480,14 +482,38 @@ void BytecodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) { |
variable->index()); |
} |
break; |
- case VariableLocation::LOOKUP: |
- UNIMPLEMENTED(); |
+ case VariableLocation::LOOKUP: { |
+ DCHECK(IsDeclaredVariableMode(mode)); |
+ |
+ register_allocator()->PrepareForConsecutiveAllocations(3); |
+ Register name = register_allocator()->NextConsecutiveRegister(); |
+ Register init_value = register_allocator()->NextConsecutiveRegister(); |
+ Register attributes = register_allocator()->NextConsecutiveRegister(); |
+ |
+ builder()->LoadLiteral(variable->name()).StoreAccumulatorInRegister(name); |
+ if (hole_init) { |
+ builder()->LoadTheHole().StoreAccumulatorInRegister(init_value); |
+ } else { |
+ // For variables, we must not use an initial value (such as 'undefined') |
+ // because we may have a (legal) redeclaration and we must not destroy |
+ // the current value. |
+ builder() |
+ ->LoadLiteral(Smi::FromInt(0)) |
+ .StoreAccumulatorInRegister(init_value); |
+ } |
+ builder() |
+ ->LoadLiteral(Smi::FromInt(variable->DeclarationPropertyAttributes())) |
+ .StoreAccumulatorInRegister(attributes) |
+ .CallRuntime(Runtime::kDeclareLookupSlot, name, 3); |
break; |
+ } |
} |
} |
void BytecodeGenerator::VisitFunctionDeclaration(FunctionDeclaration* decl) { |
+ RegisterAllocationScope register_scope(this); |
rmcilroy
2016/01/15 14:17:20
Also remove this once the above comment is done.
mythria
2016/01/15 17:10:36
Done.
|
+ |
Variable* variable = decl->proxy()->var(); |
switch (variable->location()) { |
case VariableLocation::GLOBAL: |
@@ -513,8 +539,20 @@ void BytecodeGenerator::VisitFunctionDeclaration(FunctionDeclaration* decl) { |
variable->index()); |
break; |
} |
- case VariableLocation::LOOKUP: |
- UNIMPLEMENTED(); |
+ case VariableLocation::LOOKUP: { |
+ register_allocator()->PrepareForConsecutiveAllocations(3); |
+ Register name = register_allocator()->NextConsecutiveRegister(); |
+ Register literal = register_allocator()->NextConsecutiveRegister(); |
+ Register attributes = register_allocator()->NextConsecutiveRegister(); |
+ builder()->LoadLiteral(variable->name()).StoreAccumulatorInRegister(name); |
+ |
+ VisitForAccumulatorValue(decl->fun()); |
+ builder() |
+ ->StoreAccumulatorInRegister(literal) |
+ .LoadLiteral(Smi::FromInt(variable->DeclarationPropertyAttributes())) |
+ .StoreAccumulatorInRegister(attributes) |
+ .CallRuntime(Runtime::kDeclareLookupSlot, name, 3); |
+ } |
} |
} |
@@ -1319,6 +1357,8 @@ void BytecodeGenerator::VisitVariableAssignment(Variable* variable, |
break; |
} |
case VariableLocation::LOOKUP: { |
+ // TODO(mythria): Use Runtime::kInitializeLegacyConstLookupSlot for |
+ // initializations of const declarations. |
builder()->StoreLookupSlot(variable->name(), language_mode()); |
break; |
} |
@@ -1559,7 +1599,7 @@ void BytecodeGenerator::VisitCall(Call* expr) { |
DCHECK(Register::AreContiguous(callee, receiver)); |
Variable* variable = callee_expr->AsVariableProxy()->var(); |
builder() |
- ->MoveRegister(Register::function_context(), context) |
+ ->MoveRegister(execution_context()->reg(), context) |
.LoadLiteral(variable->name()) |
.StoreAccumulatorInRegister(name) |
.CallRuntimeForPair(Runtime::kLoadLookupSlot, context, 2, callee); |