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/interpreter.h" | 5 #include "src/interpreter/interpreter.h" |
6 | 6 |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
9 #include "src/compiler/interpreter-assembler.h" | 9 #include "src/compiler/interpreter-assembler.h" |
10 #include "src/factory.h" | 10 #include "src/factory.h" |
(...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 __ SetAccumulator(result); | 1095 __ SetAccumulator(result); |
1096 __ Dispatch(); | 1096 __ Dispatch(); |
1097 } | 1097 } |
1098 | 1098 |
1099 | 1099 |
1100 // ToObject | 1100 // ToObject |
1101 // | 1101 // |
1102 // Cast the object referenced by the accumulator to a JSObject. | 1102 // Cast the object referenced by the accumulator to a JSObject. |
1103 void Interpreter::DoToObject(compiler::InterpreterAssembler* assembler) { | 1103 void Interpreter::DoToObject(compiler::InterpreterAssembler* assembler) { |
1104 Node* accumulator = __ GetAccumulator(); | 1104 Node* accumulator = __ GetAccumulator(); |
1105 Node* result = __ CallRuntime(Runtime::kToObject, accumulator); | 1105 Node* result = |
| 1106 __ CallRuntime(Runtime::kInterpreterToObjectOrNull, accumulator); |
1106 __ SetAccumulator(result); | 1107 __ SetAccumulator(result); |
1107 __ Dispatch(); | 1108 __ Dispatch(); |
1108 } | 1109 } |
1109 | 1110 |
1110 | 1111 |
1111 // Jump <imm8> | 1112 // Jump <imm8> |
1112 // | 1113 // |
1113 // Jump by number of bytes represented by the immediate operand |imm8|. | 1114 // Jump by number of bytes represented by the immediate operand |imm8|. |
1114 void Interpreter::DoJump(compiler::InterpreterAssembler* assembler) { | 1115 void Interpreter::DoJump(compiler::InterpreterAssembler* assembler) { |
1115 Node* relative_jump = __ BytecodeOperandImm(0); | 1116 Node* relative_jump = __ BytecodeOperandImm(0); |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1444 | 1445 |
1445 | 1446 |
1446 // Return | 1447 // Return |
1447 // | 1448 // |
1448 // Return the value in the accumulator. | 1449 // Return the value in the accumulator. |
1449 void Interpreter::DoReturn(compiler::InterpreterAssembler* assembler) { | 1450 void Interpreter::DoReturn(compiler::InterpreterAssembler* assembler) { |
1450 __ Return(); | 1451 __ Return(); |
1451 } | 1452 } |
1452 | 1453 |
1453 | 1454 |
1454 // ForInPrepare <receiver> | 1455 // ForInPrepare <receiver> <cache_type> <cache_array> <cache_length> |
1455 // | 1456 // |
1456 // Returns state for for..in loop execution based on the |receiver| and | 1457 // Returns state for for..in loop execution based on the object in the |
1457 // the property names in the accumulator. | 1458 // accumulator. |
| 1459 // The |receiver| is an input parameter. |
| 1460 // |cache_type|, |cache_array|, and |cache_length| are all output parameters. |
1458 void Interpreter::DoForInPrepare(compiler::InterpreterAssembler* assembler) { | 1461 void Interpreter::DoForInPrepare(compiler::InterpreterAssembler* assembler) { |
1459 Node* receiver_reg = __ BytecodeOperandReg(0); | 1462 // Call runtime to set-up ForInPrepareState |
1460 Node* receiver = __ LoadRegister(receiver_reg); | 1463 Node* object = __ GetAccumulator(); |
1461 Node* property_names = __ GetAccumulator(); | 1464 Node* result = __ CallRuntime(Runtime::kInterpreterForInPrepare, object); |
1462 Node* result = __ CallRuntime(Runtime::kInterpreterForInPrepare, receiver, | 1465 |
1463 property_names); | 1466 for (int i = 0; i < 3; i++) { |
| 1467 // 0 == receiver, 1 == cache_type, 2 == cache_array, 3 == cache_length |
| 1468 Node* cache_info = __ LoadFixedArrayElement(result, i); |
| 1469 Node* cache_info_reg = __ BytecodeOperandReg(i + 1); |
| 1470 __ StoreRegister(cache_info, cache_info_reg); |
| 1471 } |
1464 __ SetAccumulator(result); | 1472 __ SetAccumulator(result); |
1465 __ Dispatch(); | 1473 __ Dispatch(); |
1466 } | 1474 } |
1467 | 1475 |
1468 | 1476 |
1469 // ForInNext <for_in_state> <index> | 1477 // ForInNext <receiver> <cache_type> <cache_array> <index> |
1470 // | 1478 // |
1471 // Returns the next key in a for..in loop. The state associated with the | 1479 // Returns the next key in a for..in loop. |
1472 // iteration is contained in |for_in_state| and |index| is the current | |
1473 // zero-based iteration count. | |
1474 void Interpreter::DoForInNext(compiler::InterpreterAssembler* assembler) { | 1480 void Interpreter::DoForInNext(compiler::InterpreterAssembler* assembler) { |
1475 Node* for_in_state_reg = __ BytecodeOperandReg(0); | 1481 Node* receiver_reg = __ BytecodeOperandReg(0); |
1476 Node* for_in_state = __ LoadRegister(for_in_state_reg); | 1482 Node* receiver = __ LoadRegister(receiver_reg); |
1477 Node* receiver = __ LoadFixedArrayElement(for_in_state, 0); | 1483 Node* cache_type_reg = __ BytecodeOperandReg(1); |
1478 Node* cache_array = __ LoadFixedArrayElement(for_in_state, 1); | 1484 Node* cache_type = __ LoadRegister(cache_type_reg); |
1479 Node* cache_type = __ LoadFixedArrayElement(for_in_state, 2); | 1485 Node* cache_array_reg = __ BytecodeOperandReg(2); |
1480 Node* index_reg = __ BytecodeOperandReg(1); | 1486 Node* cache_array = __ LoadRegister(cache_array_reg); |
| 1487 Node* index_reg = __ BytecodeOperandReg(3); |
1481 Node* index = __ LoadRegister(index_reg); | 1488 Node* index = __ LoadRegister(index_reg); |
1482 Node* result = __ CallRuntime(Runtime::kForInNext, receiver, cache_array, | 1489 Node* result = __ CallRuntime(Runtime::kForInNext, receiver, cache_array, |
1483 cache_type, index); | 1490 cache_type, index); |
1484 __ SetAccumulator(result); | 1491 __ SetAccumulator(result); |
1485 __ Dispatch(); | 1492 __ Dispatch(); |
1486 } | 1493 } |
1487 | 1494 |
1488 | 1495 |
1489 // ForInDone <for_in_state> | 1496 // ForInDone <index> <cache_length> |
1490 // | 1497 // |
1491 // Returns the next key in a for..in loop. The accumulator contains the current | 1498 // Returns the next key in a for..in loop. |
1492 // zero-based iteration count and |for_in_state| is the state returned by an | |
1493 // earlier invocation of ForInPrepare. | |
1494 void Interpreter::DoForInDone(compiler::InterpreterAssembler* assembler) { | 1499 void Interpreter::DoForInDone(compiler::InterpreterAssembler* assembler) { |
1495 Node* index = __ GetAccumulator(); | 1500 // TODO(oth): Implement directly rather than runtime call. |
1496 Node* for_in_state_reg = __ BytecodeOperandReg(0); | 1501 Node* index_reg = __ BytecodeOperandReg(0); |
1497 Node* for_in_state = __ LoadRegister(for_in_state_reg); | 1502 Node* index = __ LoadRegister(index_reg); |
1498 Node* cache_length = __ LoadFixedArrayElement(for_in_state, 3); | 1503 Node* cache_length_reg = __ BytecodeOperandReg(1); |
| 1504 Node* cache_length = __ LoadRegister(cache_length_reg); |
1499 Node* result = __ CallRuntime(Runtime::kForInDone, index, cache_length); | 1505 Node* result = __ CallRuntime(Runtime::kForInDone, index, cache_length); |
1500 __ SetAccumulator(result); | 1506 __ SetAccumulator(result); |
1501 __ Dispatch(); | 1507 __ Dispatch(); |
1502 } | 1508 } |
1503 | 1509 |
1504 | 1510 |
| 1511 // ForInStep <index> |
| 1512 // |
| 1513 // Increments the loop counter |index|. |
| 1514 void Interpreter::DoForInStep(compiler::InterpreterAssembler* assembler) { |
| 1515 // TODO(oth): Implement directly rather than runtime call. |
| 1516 Node* index_reg = __ BytecodeOperandReg(0); |
| 1517 Node* index = __ LoadRegister(index_reg); |
| 1518 Node* result = __ CallRuntime(Runtime::kForInStep, index); |
| 1519 __ StoreRegister(result, index_reg); |
| 1520 __ Dispatch(); |
| 1521 } |
| 1522 |
| 1523 |
1505 } // namespace interpreter | 1524 } // namespace interpreter |
1506 } // namespace internal | 1525 } // namespace internal |
1507 } // namespace v8 | 1526 } // namespace v8 |
OLD | NEW |