OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1482 // of the key to detect a named property. | 1482 // of the key to detect a named property. |
1483 if (prop != NULL) { | 1483 if (prop != NULL) { |
1484 assign_type = | 1484 assign_type = |
1485 (prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY; | 1485 (prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY; |
1486 } | 1486 } |
1487 | 1487 |
1488 // Evaluate expression and get value. | 1488 // Evaluate expression and get value. |
1489 if (assign_type == VARIABLE) { | 1489 if (assign_type == VARIABLE) { |
1490 ASSERT(expr->expression()->AsVariableProxy()->var() != NULL); | 1490 ASSERT(expr->expression()->AsVariableProxy()->var() != NULL); |
1491 Location saved_location = location_; | 1491 Location saved_location = location_; |
1492 location_ = kStack; | 1492 location_ = kAccumulator; |
1493 EmitVariableLoad(expr->expression()->AsVariableProxy()->var(), | 1493 EmitVariableLoad(expr->expression()->AsVariableProxy()->var(), |
1494 Expression::kValue); | 1494 Expression::kValue); |
1495 location_ = saved_location; | 1495 location_ = saved_location; |
1496 } else { | 1496 } else { |
1497 // Reserve space for result of postfix operation. | 1497 // Reserve space for result of postfix operation. |
1498 if (expr->is_postfix() && context_ != Expression::kEffect) { | 1498 if (expr->is_postfix() && context_ != Expression::kEffect) { |
1499 __ Push(Smi::FromInt(0)); | 1499 __ Push(Smi::FromInt(0)); |
1500 } | 1500 } |
1501 VisitForValue(prop->obj(), kStack); | 1501 VisitForValue(prop->obj(), kStack); |
1502 if (assign_type == NAMED_PROPERTY) { | 1502 if (assign_type == NAMED_PROPERTY) { |
1503 EmitNamedPropertyLoad(prop); | 1503 EmitNamedPropertyLoad(prop); |
1504 } else { | 1504 } else { |
1505 VisitForValue(prop->key(), kStack); | 1505 VisitForValue(prop->key(), kStack); |
1506 EmitKeyedPropertyLoad(prop); | 1506 EmitKeyedPropertyLoad(prop); |
1507 } | 1507 } |
1508 __ push(rax); | |
1509 } | 1508 } |
1510 | 1509 |
1511 // Convert to number. | 1510 // Call ToNumber only if operand is not a smi. |
| 1511 Label no_conversion; |
| 1512 Condition is_smi; |
| 1513 is_smi = masm_->CheckSmi(rax); |
| 1514 __ j(is_smi, &no_conversion); |
| 1515 __ push(rax); |
1512 __ InvokeBuiltin(Builtins::TO_NUMBER, CALL_FUNCTION); | 1516 __ InvokeBuiltin(Builtins::TO_NUMBER, CALL_FUNCTION); |
| 1517 __ bind(&no_conversion); |
1513 | 1518 |
1514 // Save result for postfix expressions. | 1519 // Save result for postfix expressions. |
1515 if (expr->is_postfix()) { | 1520 if (expr->is_postfix()) { |
1516 switch (context_) { | 1521 switch (context_) { |
1517 case Expression::kUninitialized: | 1522 case Expression::kUninitialized: |
1518 UNREACHABLE(); | 1523 UNREACHABLE(); |
1519 case Expression::kEffect: | 1524 case Expression::kEffect: |
1520 // Do not save result. | 1525 // Do not save result. |
1521 break; | 1526 break; |
1522 case Expression::kValue: | 1527 case Expression::kValue: |
(...skipping 11 matching lines...) Expand all Loading... |
1534 __ movq(Operand(rsp, kPointerSize), rax); | 1539 __ movq(Operand(rsp, kPointerSize), rax); |
1535 break; | 1540 break; |
1536 case KEYED_PROPERTY: | 1541 case KEYED_PROPERTY: |
1537 __ movq(Operand(rsp, 2 * kPointerSize), rax); | 1542 __ movq(Operand(rsp, 2 * kPointerSize), rax); |
1538 break; | 1543 break; |
1539 } | 1544 } |
1540 break; | 1545 break; |
1541 } | 1546 } |
1542 } | 1547 } |
1543 | 1548 |
| 1549 // Inline smi case if we are in a loop. |
| 1550 Label stub_call, done; |
| 1551 if (loop_depth() > 0) { |
| 1552 if (expr->op() == Token::INC) { |
| 1553 __ SmiAddConstant(rax, rax, Smi::FromInt(1)); |
| 1554 } else { |
| 1555 __ SmiSubConstant(rax, rax, Smi::FromInt(1)); |
| 1556 } |
| 1557 __ j(overflow, &stub_call); |
| 1558 // We could eliminate this smi check if we split the code at |
| 1559 // the first smi check before calling ToNumber. |
| 1560 is_smi = masm_->CheckSmi(rax); |
| 1561 __ j(is_smi, &done); |
| 1562 __ bind(&stub_call); |
| 1563 // Call stub. Undo operation first. |
| 1564 if (expr->op() == Token::INC) { |
| 1565 __ SmiSubConstant(rax, rax, Smi::FromInt(1)); |
| 1566 } else { |
| 1567 __ SmiAddConstant(rax, rax, Smi::FromInt(1)); |
| 1568 } |
| 1569 } |
1544 // Call stub for +1/-1. | 1570 // Call stub for +1/-1. |
1545 __ push(rax); | 1571 __ push(rax); |
1546 __ Push(Smi::FromInt(1)); | 1572 __ Push(Smi::FromInt(1)); |
1547 GenericBinaryOpStub stub(expr->binary_op(), | 1573 GenericBinaryOpStub stub(expr->binary_op(), |
1548 NO_OVERWRITE, | 1574 NO_OVERWRITE, |
1549 NO_GENERIC_BINARY_FLAGS); | 1575 NO_GENERIC_BINARY_FLAGS); |
1550 __ CallStub(&stub); | 1576 __ CallStub(&stub); |
| 1577 __ bind(&done); |
1551 | 1578 |
1552 // Store the value returned in rax. | 1579 // Store the value returned in rax. |
1553 switch (assign_type) { | 1580 switch (assign_type) { |
1554 case VARIABLE: | 1581 case VARIABLE: |
1555 if (expr->is_postfix()) { | 1582 if (expr->is_postfix()) { |
1556 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), | 1583 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
1557 Expression::kEffect); | 1584 Expression::kEffect); |
1558 // For all contexts except kEffect: We have the result on | 1585 // For all contexts except kEffect: We have the result on |
1559 // top of the stack. | 1586 // top of the stack. |
1560 if (context_ != Expression::kEffect) { | 1587 if (context_ != Expression::kEffect) { |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1802 __ movq(Operand(rsp, 0), rdx); | 1829 __ movq(Operand(rsp, 0), rdx); |
1803 // And return. | 1830 // And return. |
1804 __ ret(0); | 1831 __ ret(0); |
1805 } | 1832 } |
1806 | 1833 |
1807 | 1834 |
1808 #undef __ | 1835 #undef __ |
1809 | 1836 |
1810 | 1837 |
1811 } } // namespace v8::internal | 1838 } } // namespace v8::internal |
OLD | NEW |