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 <stack> | 7 #include <stack> |
8 | 8 |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/interpreter/control-flow-builders.h" | 10 #include "src/interpreter/control-flow-builders.h" |
11 #include "src/objects.h" | 11 #include "src/objects.h" |
| 12 #include "src/parser.h" |
12 #include "src/scopes.h" | 13 #include "src/scopes.h" |
13 #include "src/token.h" | 14 #include "src/token.h" |
14 | 15 |
15 namespace v8 { | 16 namespace v8 { |
16 namespace internal { | 17 namespace internal { |
17 namespace interpreter { | 18 namespace interpreter { |
18 | 19 |
19 | 20 |
20 // Scoped class tracking context objects created by the visitor. Represents | 21 // Scoped class tracking context objects created by the visitor. Represents |
21 // mutations of the context chain within the function body and allows to | 22 // mutations of the context chain within the function body and allows to |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 CHECK(!shared_info.is_null()); // TODO(rmcilroy): Set stack overflow? | 452 CHECK(!shared_info.is_null()); // TODO(rmcilroy): Set stack overflow? |
452 | 453 |
453 // Call the runtime to create a new closure. | 454 // Call the runtime to create a new closure. |
454 // TODO(rmcilroy): Possibly call FastNewClosureStub when possible instead of | 455 // TODO(rmcilroy): Possibly call FastNewClosureStub when possible instead of |
455 // calling into the runtime. | 456 // calling into the runtime. |
456 Runtime::FunctionId function_id = | 457 Runtime::FunctionId function_id = |
457 expr->pretenure() ? Runtime::kNewClosure_Tenured : Runtime::kNewClosure; | 458 expr->pretenure() ? Runtime::kNewClosure_Tenured : Runtime::kNewClosure; |
458 | 459 |
459 TemporaryRegisterScope temporary_register_scope(builder()); | 460 TemporaryRegisterScope temporary_register_scope(builder()); |
460 Register shared = temporary_register_scope.NewRegister(); | 461 Register shared = temporary_register_scope.NewRegister(); |
461 builder()->LoadLiteral(shared_info) | 462 builder() |
| 463 ->LoadLiteral(shared_info) |
462 .StoreAccumulatorInRegister(shared) | 464 .StoreAccumulatorInRegister(shared) |
463 .CallRuntime(function_id, shared, 1); | 465 .CallRuntime(function_id, shared, 1); |
464 } | 466 } |
465 | 467 |
466 | 468 |
467 void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) { | 469 void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) { |
468 UNIMPLEMENTED(); | 470 UNIMPLEMENTED(); |
469 } | 471 } |
470 | 472 |
471 | 473 |
(...skipping 30 matching lines...) Expand all Loading... |
502 UNIMPLEMENTED(); | 504 UNIMPLEMENTED(); |
503 } | 505 } |
504 | 506 |
505 | 507 |
506 void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { | 508 void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
507 UNIMPLEMENTED(); | 509 UNIMPLEMENTED(); |
508 } | 510 } |
509 | 511 |
510 | 512 |
511 void BytecodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | 513 void BytecodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
512 UNIMPLEMENTED(); | 514 // Deep-copy the literal boilerplate. |
| 515 expr->BuildConstantElements(isolate()); |
| 516 builder() |
| 517 ->LoadLiteral(expr->constant_elements()) |
| 518 .CreateArrayLiteral(expr->literal_index(), expr->ComputeFlags(true)); |
| 519 |
| 520 TemporaryRegisterScope temporary_register_scope(builder()); |
| 521 Register index, literal_array; |
| 522 |
| 523 // Create nodes to evaluate all the non-constant subexpressions and to store |
| 524 // them into the newly cloned array. |
| 525 bool literal_array_in_accumulator = true; |
| 526 for (int array_index = 0; array_index < expr->values()->length(); |
| 527 array_index++) { |
| 528 Expression* subexpr = expr->values()->at(array_index); |
| 529 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; |
| 530 if (subexpr->IsSpread()) { |
| 531 // TODO(rmcilroy): Deal with spread expressions. |
| 532 UNIMPLEMENTED(); |
| 533 } |
| 534 |
| 535 if (literal_array_in_accumulator) { |
| 536 index = temporary_register_scope.NewRegister(); |
| 537 literal_array = temporary_register_scope.NewRegister(); |
| 538 builder()->StoreAccumulatorInRegister(literal_array); |
| 539 literal_array_in_accumulator = false; |
| 540 } |
| 541 |
| 542 builder() |
| 543 ->LoadLiteral(Smi::FromInt(array_index)) |
| 544 .StoreAccumulatorInRegister(index); |
| 545 Visit(subexpr); |
| 546 builder()->GenericStoreKeyedProperty(literal_array, index); |
| 547 } |
| 548 |
| 549 if (!literal_array_in_accumulator) { |
| 550 // Restore literal array into accumulator. |
| 551 builder()->LoadAccumulatorWithRegister(literal_array); |
| 552 } |
513 } | 553 } |
514 | 554 |
515 | 555 |
516 void BytecodeGenerator::VisitVariableProxy(VariableProxy* proxy) { | 556 void BytecodeGenerator::VisitVariableProxy(VariableProxy* proxy) { |
517 VisitVariableLoad(proxy->var(), proxy->VariableFeedbackSlot()); | 557 VisitVariableLoad(proxy->var(), proxy->VariableFeedbackSlot()); |
518 } | 558 } |
519 | 559 |
520 | 560 |
521 void BytecodeGenerator::VisitVariableLoad(Variable* variable, | 561 void BytecodeGenerator::VisitVariableLoad(Variable* variable, |
522 FeedbackVectorSlot slot) { | 562 FeedbackVectorSlot slot) { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 builder()->LoadUndefined().StoreAccumulatorInRegister(receiver); | 781 builder()->LoadUndefined().StoreAccumulatorInRegister(receiver); |
742 // Load callee as a global variable. | 782 // Load callee as a global variable. |
743 VariableProxy* proxy = callee_expr->AsVariableProxy(); | 783 VariableProxy* proxy = callee_expr->AsVariableProxy(); |
744 VisitVariableLoad(proxy->var(), proxy->VariableFeedbackSlot()); | 784 VisitVariableLoad(proxy->var(), proxy->VariableFeedbackSlot()); |
745 builder()->StoreAccumulatorInRegister(callee); | 785 builder()->StoreAccumulatorInRegister(callee); |
746 break; | 786 break; |
747 } | 787 } |
748 case Call::OTHER_CALL: { | 788 case Call::OTHER_CALL: { |
749 Visit(callee_expr); | 789 Visit(callee_expr); |
750 builder()->StoreAccumulatorInRegister(callee); | 790 builder()->StoreAccumulatorInRegister(callee); |
751 builder()->LoadUndefined() | 791 builder()->LoadUndefined().StoreAccumulatorInRegister(receiver); |
752 .StoreAccumulatorInRegister(receiver); | |
753 break; | 792 break; |
754 } | 793 } |
755 case Call::LOOKUP_SLOT_CALL: | 794 case Call::LOOKUP_SLOT_CALL: |
756 case Call::SUPER_CALL: | 795 case Call::SUPER_CALL: |
757 case Call::POSSIBLY_EVAL_CALL: | 796 case Call::POSSIBLY_EVAL_CALL: |
758 UNIMPLEMENTED(); | 797 UNIMPLEMENTED(); |
759 } | 798 } |
760 | 799 |
761 // Evaluate all arguments to the function call and store in sequential | 800 // Evaluate all arguments to the function call and store in sequential |
762 // registers. | 801 // registers. |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 } | 998 } |
960 | 999 |
961 | 1000 |
962 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 1001 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
963 return info()->feedback_vector()->GetIndex(slot); | 1002 return info()->feedback_vector()->GetIndex(slot); |
964 } | 1003 } |
965 | 1004 |
966 } // namespace interpreter | 1005 } // namespace interpreter |
967 } // namespace internal | 1006 } // namespace internal |
968 } // namespace v8 | 1007 } // namespace v8 |
OLD | NEW |