OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
6 | 6 |
7 #include "src/ast/compile-time-value.h" | 7 #include "src/ast/compile-time-value.h" |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/builtins/builtins-constructor.h" | 9 #include "src/builtins/builtins-constructor.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1404 | 1404 |
1405 void BytecodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { | 1405 void BytecodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { |
1406 uint8_t flags = CreateClosureFlags::Encode(expr->pretenure(), | 1406 uint8_t flags = CreateClosureFlags::Encode(expr->pretenure(), |
1407 scope()->is_function_scope()); | 1407 scope()->is_function_scope()); |
1408 size_t entry = builder()->AllocateConstantPoolEntry(); | 1408 size_t entry = builder()->AllocateConstantPoolEntry(); |
1409 builder()->CreateClosure(entry, flags); | 1409 builder()->CreateClosure(entry, flags); |
1410 function_literals_.push_back(std::make_pair(expr, entry)); | 1410 function_literals_.push_back(std::make_pair(expr, entry)); |
1411 } | 1411 } |
1412 | 1412 |
1413 void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) { | 1413 void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) { |
1414 VisitClassLiteralForRuntimeDefinition(expr); | 1414 Register constructor = register_allocator()->NewRegister(); |
1415 VisitForRegisterValue(expr->constructor(), constructor); | |
rmcilroy
2017/01/04 09:55:59
nit - you can just do:
Register constructor = Visi
adamk
2017/01/04 17:57:03
Ah, nice.
| |
1416 Register prototype = register_allocator()->NewRegister(); | |
rmcilroy
2017/01/04 09:55:59
nit - you could save a register if you allocate th
adamk
2017/01/04 17:57:03
Done.
| |
1417 { | |
1418 RegisterAllocationScope register_scope(this); | |
1419 RegisterList args = register_allocator()->NewRegisterList(4); | |
1420 VisitForAccumulatorValueOrTheHole(expr->extends()); | |
1421 builder() | |
1422 ->StoreAccumulatorInRegister(args[0]) | |
1423 .MoveRegister(constructor, args[1]) | |
1424 .LoadLiteral(Smi::FromInt(expr->start_position())) | |
1425 .StoreAccumulatorInRegister(args[2]) | |
1426 .LoadLiteral(Smi::FromInt(expr->end_position())) | |
1427 .StoreAccumulatorInRegister(args[3]) | |
1428 .CallRuntime(Runtime::kDefineClass, args) | |
1429 .StoreAccumulatorInRegister(prototype); | |
1430 } | |
1415 | 1431 |
1416 // Load the "prototype" from the constructor. | 1432 if (FunctionLiteral::NeedsHomeObject(expr->constructor())) { |
1417 Register literal = register_allocator()->NewRegister(); | 1433 // prototype is already in the accumulator |
rmcilroy
2017/01/04 09:55:59
nit - fullstop and capital letter for comments.
adamk
2017/01/04 17:57:03
Done.
| |
1418 Register prototype = register_allocator()->NewRegister(); | 1434 builder()->StoreNamedProperty(constructor, home_object_symbol(), |
1419 FeedbackVectorSlot slot = expr->PrototypeSlot(); | 1435 feedback_index(expr->HomeObjectSlot()), |
1420 builder() | 1436 language_mode()); |
1421 ->StoreAccumulatorInRegister(literal) | 1437 } |
1422 .LoadNamedProperty(literal, prototype_string(), feedback_index(slot)) | |
1423 .StoreAccumulatorInRegister(prototype); | |
1424 | 1438 |
1425 VisitClassLiteralProperties(expr, literal, prototype); | 1439 VisitClassLiteralProperties(expr, constructor, prototype); |
1426 BuildClassLiteralNameProperty(expr, literal); | 1440 BuildClassLiteralNameProperty(expr, constructor); |
1427 builder()->CallRuntime(Runtime::kToFastProperties, literal); | 1441 builder()->CallRuntime(Runtime::kToFastProperties, constructor); |
1428 // Assign to class variable. | 1442 // Assign to class variable. |
1429 if (expr->class_variable_proxy() != nullptr) { | 1443 if (expr->class_variable_proxy() != nullptr) { |
1430 VariableProxy* proxy = expr->class_variable_proxy(); | 1444 VariableProxy* proxy = expr->class_variable_proxy(); |
1431 FeedbackVectorSlot slot = expr->NeedsProxySlot() | 1445 FeedbackVectorSlot slot = expr->NeedsProxySlot() |
1432 ? expr->ProxySlot() | 1446 ? expr->ProxySlot() |
1433 : FeedbackVectorSlot::Invalid(); | 1447 : FeedbackVectorSlot::Invalid(); |
1434 BuildVariableAssignment(proxy->var(), Token::INIT, slot, | 1448 BuildVariableAssignment(proxy->var(), Token::INIT, slot, |
1435 HoleCheckMode::kElided); | 1449 HoleCheckMode::kElided); |
1436 } | 1450 } |
1437 } | 1451 } |
1438 | 1452 |
1439 void BytecodeGenerator::VisitClassLiteralForRuntimeDefinition( | |
1440 ClassLiteral* expr) { | |
1441 RegisterAllocationScope register_scope(this); | |
1442 RegisterList args = register_allocator()->NewRegisterList(4); | |
1443 VisitForAccumulatorValueOrTheHole(expr->extends()); | |
1444 builder()->StoreAccumulatorInRegister(args[0]); | |
1445 VisitForRegisterValue(expr->constructor(), args[1]); | |
1446 builder() | |
1447 ->LoadLiteral(Smi::FromInt(expr->start_position())) | |
1448 .StoreAccumulatorInRegister(args[2]) | |
1449 .LoadLiteral(Smi::FromInt(expr->end_position())) | |
1450 .StoreAccumulatorInRegister(args[3]) | |
1451 .CallRuntime(Runtime::kDefineClass, args); | |
1452 } | |
1453 | |
1454 void BytecodeGenerator::VisitClassLiteralProperties(ClassLiteral* expr, | 1453 void BytecodeGenerator::VisitClassLiteralProperties(ClassLiteral* expr, |
1455 Register literal, | 1454 Register constructor, |
1456 Register prototype) { | 1455 Register prototype) { |
1457 RegisterAllocationScope register_scope(this); | 1456 RegisterAllocationScope register_scope(this); |
1458 RegisterList args = register_allocator()->NewRegisterList(4); | 1457 RegisterList args = register_allocator()->NewRegisterList(4); |
1459 Register receiver = args[0], key = args[1], value = args[2], attr = args[3]; | 1458 Register receiver = args[0], key = args[1], value = args[2], attr = args[3]; |
1460 | 1459 |
1461 bool attr_assigned = false; | 1460 bool attr_assigned = false; |
1462 Register old_receiver = Register::invalid_value(); | 1461 Register old_receiver = Register::invalid_value(); |
1463 | 1462 |
1464 // Create nodes to store method values into the literal. | 1463 // Create nodes to store method values into the literal. |
1465 for (int i = 0; i < expr->properties()->length(); i++) { | 1464 for (int i = 0; i < expr->properties()->length(); i++) { |
1466 ClassLiteral::Property* property = expr->properties()->at(i); | 1465 ClassLiteral::Property* property = expr->properties()->at(i); |
1467 | 1466 |
1468 // Set-up receiver. | 1467 // Set-up receiver. |
1469 Register new_receiver = property->is_static() ? literal : prototype; | 1468 Register new_receiver = property->is_static() ? constructor : prototype; |
1470 if (new_receiver != old_receiver) { | 1469 if (new_receiver != old_receiver) { |
1471 builder()->MoveRegister(new_receiver, receiver); | 1470 builder()->MoveRegister(new_receiver, receiver); |
1472 old_receiver = new_receiver; | 1471 old_receiver = new_receiver; |
1473 } | 1472 } |
1474 | 1473 |
1475 VisitForAccumulatorValue(property->key()); | 1474 VisitForAccumulatorValue(property->key()); |
1476 builder()->ConvertAccumulatorToName(key); | 1475 builder()->ConvertAccumulatorToName(key); |
1477 | 1476 |
1478 if (property->is_static() && property->is_computed_name()) { | 1477 if (property->is_static() && property->is_computed_name()) { |
1479 // The static prototype property is read only. We handle the non computed | 1478 // The static prototype property is read only. We handle the non computed |
(...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3309 } | 3308 } |
3310 | 3309 |
3311 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { | 3310 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { |
3312 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict | 3311 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict |
3313 : Runtime::kStoreKeyedToSuper_Sloppy; | 3312 : Runtime::kStoreKeyedToSuper_Sloppy; |
3314 } | 3313 } |
3315 | 3314 |
3316 } // namespace interpreter | 3315 } // namespace interpreter |
3317 } // namespace internal | 3316 } // namespace internal |
3318 } // namespace v8 | 3317 } // namespace v8 |
OLD | NEW |