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 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1160 __ SetAccumulator(result); | 1160 __ SetAccumulator(result); |
1161 __ Dispatch(); | 1161 __ Dispatch(); |
1162 } | 1162 } |
1163 | 1163 |
1164 | 1164 |
1165 // ToObject | 1165 // ToObject |
1166 // | 1166 // |
1167 // Cast the object referenced by the accumulator to a JSObject. | 1167 // Cast the object referenced by the accumulator to a JSObject. |
1168 void Interpreter::DoToObject(compiler::InterpreterAssembler* assembler) { | 1168 void Interpreter::DoToObject(compiler::InterpreterAssembler* assembler) { |
1169 Node* accumulator = __ GetAccumulator(); | 1169 Node* accumulator = __ GetAccumulator(); |
1170 Node* result = __ CallRuntime(Runtime::kToObject, accumulator); | 1170 Node* result = |
1171 __ CallRuntime(Runtime::kInterpreterToObjectOrNull, accumulator); | |
1171 __ SetAccumulator(result); | 1172 __ SetAccumulator(result); |
1172 __ Dispatch(); | 1173 __ Dispatch(); |
1173 } | 1174 } |
1174 | 1175 |
1175 | 1176 |
1176 // Jump <imm8> | 1177 // Jump <imm8> |
1177 // | 1178 // |
1178 // Jump by number of bytes represented by the immediate operand |imm8|. | 1179 // Jump by number of bytes represented by the immediate operand |imm8|. |
1179 void Interpreter::DoJump(compiler::InterpreterAssembler* assembler) { | 1180 void Interpreter::DoJump(compiler::InterpreterAssembler* assembler) { |
1180 Node* relative_jump = __ BytecodeOperandImm(0); | 1181 Node* relative_jump = __ BytecodeOperandImm(0); |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1509 | 1510 |
1510 | 1511 |
1511 // Return | 1512 // Return |
1512 // | 1513 // |
1513 // Return the value in the accumulator. | 1514 // Return the value in the accumulator. |
1514 void Interpreter::DoReturn(compiler::InterpreterAssembler* assembler) { | 1515 void Interpreter::DoReturn(compiler::InterpreterAssembler* assembler) { |
1515 __ Return(); | 1516 __ Return(); |
1516 } | 1517 } |
1517 | 1518 |
1518 | 1519 |
1519 // ForInPrepare <receiver> | 1520 // ForInPrepare <receiver> <cache_type> <cache_array> <cache_length> |
1520 // | 1521 // |
1521 // Returns state for for..in loop execution based on the |receiver| and | 1522 // Returns state for for..in loop execution based on the object in the |
1522 // the property names in the accumulator. | 1523 // accumulator. |
1524 // The |receiver| is an input parameter. | |
1525 // |cache_type|, |cache_array|, and |cache_length| are all output parameters. | |
1523 void Interpreter::DoForInPrepare(compiler::InterpreterAssembler* assembler) { | 1526 void Interpreter::DoForInPrepare(compiler::InterpreterAssembler* assembler) { |
1524 Node* receiver_reg = __ BytecodeOperandReg(0); | 1527 // Call runtime to set-up ForInPrepareState |
1525 Node* receiver = __ LoadRegister(receiver_reg); | 1528 Node* object = __ GetAccumulator(); |
rmcilroy
2015/12/18 16:01:55
nit - could you change this to get the receiver fr
oth
2015/12/21 10:05:53
Removed the receiver argument. This cleans up the
| |
1526 Node* property_names = __ GetAccumulator(); | 1529 Node* result = __ CallRuntime(Runtime::kInterpreterForInPrepare, object); |
1527 Node* result = __ CallRuntime(Runtime::kInterpreterForInPrepare, receiver, | 1530 |
1528 property_names); | 1531 for (int i = 0; i < 3; i++) { |
1532 // 0 == receiver, 1 == cache_type, 2 == cache_array, 3 == cache_length | |
1533 Node* cache_info = __ LoadFixedArrayElement(result, i); | |
1534 Node* cache_info_reg = __ BytecodeOperandReg(i + 1); | |
1535 __ StoreRegister(cache_info, cache_info_reg); | |
1536 } | |
1529 __ SetAccumulator(result); | 1537 __ SetAccumulator(result); |
1530 __ Dispatch(); | 1538 __ Dispatch(); |
1531 } | 1539 } |
1532 | 1540 |
1533 | 1541 |
1534 // ForInNext <for_in_state> <index> | 1542 // ForInNext <receiver> <cache_type> <cache_array> <index> |
1535 // | 1543 // |
1536 // Returns the next key in a for..in loop. The state associated with the | 1544 // Returns the next key in a for..in loop. |
1537 // iteration is contained in |for_in_state| and |index| is the current | |
1538 // zero-based iteration count. | |
1539 void Interpreter::DoForInNext(compiler::InterpreterAssembler* assembler) { | 1545 void Interpreter::DoForInNext(compiler::InterpreterAssembler* assembler) { |
1540 Node* for_in_state_reg = __ BytecodeOperandReg(0); | 1546 Node* receiver_reg = __ BytecodeOperandReg(0); |
1541 Node* for_in_state = __ LoadRegister(for_in_state_reg); | 1547 Node* receiver = __ LoadRegister(receiver_reg); |
1542 Node* receiver = __ LoadFixedArrayElement(for_in_state, 0); | 1548 Node* cache_type_reg = __ BytecodeOperandReg(1); |
1543 Node* cache_array = __ LoadFixedArrayElement(for_in_state, 1); | 1549 Node* cache_type = __ LoadRegister(cache_type_reg); |
1544 Node* cache_type = __ LoadFixedArrayElement(for_in_state, 2); | 1550 Node* cache_array_reg = __ BytecodeOperandReg(2); |
1545 Node* index_reg = __ BytecodeOperandReg(1); | 1551 Node* cache_array = __ LoadRegister(cache_array_reg); |
1552 Node* index_reg = __ BytecodeOperandReg(3); | |
1546 Node* index = __ LoadRegister(index_reg); | 1553 Node* index = __ LoadRegister(index_reg); |
1547 Node* result = __ CallRuntime(Runtime::kForInNext, receiver, cache_array, | 1554 Node* result = __ CallRuntime(Runtime::kForInNext, receiver, cache_array, |
1548 cache_type, index); | 1555 cache_type, index); |
1549 __ SetAccumulator(result); | 1556 __ SetAccumulator(result); |
1550 __ Dispatch(); | 1557 __ Dispatch(); |
1551 } | 1558 } |
1552 | 1559 |
1553 | 1560 |
1554 // ForInDone <for_in_state> | 1561 // ForInDone <index> <cache_length> |
1555 // | 1562 // |
1556 // Returns the next key in a for..in loop. The accumulator contains the current | 1563 // Returns the next key in a for..in loop. |
1557 // zero-based iteration count and |for_in_state| is the state returned by an | |
1558 // earlier invocation of ForInPrepare. | |
1559 void Interpreter::DoForInDone(compiler::InterpreterAssembler* assembler) { | 1564 void Interpreter::DoForInDone(compiler::InterpreterAssembler* assembler) { |
1560 Node* index = __ GetAccumulator(); | 1565 // TODO(oth): Implement directly rather than runtime call. |
1561 Node* for_in_state_reg = __ BytecodeOperandReg(0); | 1566 Node* index_reg = __ BytecodeOperandReg(0); |
1562 Node* for_in_state = __ LoadRegister(for_in_state_reg); | 1567 Node* index = __ LoadRegister(index_reg); |
1563 Node* cache_length = __ LoadFixedArrayElement(for_in_state, 3); | 1568 Node* cache_length_reg = __ BytecodeOperandReg(1); |
1569 Node* cache_length = __ LoadRegister(cache_length_reg); | |
1564 Node* result = __ CallRuntime(Runtime::kForInDone, index, cache_length); | 1570 Node* result = __ CallRuntime(Runtime::kForInDone, index, cache_length); |
1565 __ SetAccumulator(result); | 1571 __ SetAccumulator(result); |
1566 __ Dispatch(); | 1572 __ Dispatch(); |
1567 } | 1573 } |
1568 | 1574 |
1569 | 1575 |
1576 // ForInStep <index> | |
1577 // | |
1578 // Increments the loop counter |index|. | |
1579 void Interpreter::DoForInStep(compiler::InterpreterAssembler* assembler) { | |
1580 // TODO(oth): Implement directly rather than runtime call. | |
1581 Node* index_reg = __ BytecodeOperandReg(0); | |
1582 Node* index = __ LoadRegister(index_reg); | |
1583 Node* result = __ CallRuntime(Runtime::kForInStep, index); | |
1584 __ StoreRegister(result, index_reg); | |
1585 __ Dispatch(); | |
1586 } | |
1587 | |
1588 | |
1570 } // namespace interpreter | 1589 } // namespace interpreter |
1571 } // namespace internal | 1590 } // namespace internal |
1572 } // namespace v8 | 1591 } // namespace v8 |
OLD | NEW |