| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1556 VisitStatementsAndSpill(node->statements()); | 1556 VisitStatementsAndSpill(node->statements()); |
| 1557 if (node->break_target()->is_linked()) { | 1557 if (node->break_target()->is_linked()) { |
| 1558 node->break_target()->Bind(); | 1558 node->break_target()->Bind(); |
| 1559 } | 1559 } |
| 1560 node->break_target()->Unuse(); | 1560 node->break_target()->Unuse(); |
| 1561 ASSERT(!has_valid_frame() || frame_->height() == original_height); | 1561 ASSERT(!has_valid_frame() || frame_->height() == original_height); |
| 1562 } | 1562 } |
| 1563 | 1563 |
| 1564 | 1564 |
| 1565 void CodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { | 1565 void CodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
| 1566 frame_->EmitPush(cp); |
| 1567 frame_->EmitPush(Operand(pairs)); |
| 1568 frame_->EmitPush(Operand(Smi::FromInt(is_eval() ? 1 : 0))); |
| 1569 |
| 1566 VirtualFrame::SpilledScope spilled_scope(frame_); | 1570 VirtualFrame::SpilledScope spilled_scope(frame_); |
| 1567 frame_->EmitPush(cp); | |
| 1568 __ mov(r0, Operand(pairs)); | |
| 1569 frame_->EmitPush(r0); | |
| 1570 __ mov(r0, Operand(Smi::FromInt(is_eval() ? 1 : 0))); | |
| 1571 frame_->EmitPush(r0); | |
| 1572 frame_->CallRuntime(Runtime::kDeclareGlobals, 3); | 1571 frame_->CallRuntime(Runtime::kDeclareGlobals, 3); |
| 1573 // The result is discarded. | 1572 // The result is discarded. |
| 1574 } | 1573 } |
| 1575 | 1574 |
| 1576 | 1575 |
| 1577 void CodeGenerator::VisitDeclaration(Declaration* node) { | 1576 void CodeGenerator::VisitDeclaration(Declaration* node) { |
| 1578 #ifdef DEBUG | 1577 #ifdef DEBUG |
| 1579 int original_height = frame_->height(); | 1578 int original_height = frame_->height(); |
| 1580 #endif | 1579 #endif |
| 1581 VirtualFrame::SpilledScope spilled_scope(frame_); | |
| 1582 Comment cmnt(masm_, "[ Declaration"); | 1580 Comment cmnt(masm_, "[ Declaration"); |
| 1583 Variable* var = node->proxy()->var(); | 1581 Variable* var = node->proxy()->var(); |
| 1584 ASSERT(var != NULL); // must have been resolved | 1582 ASSERT(var != NULL); // must have been resolved |
| 1585 Slot* slot = var->slot(); | 1583 Slot* slot = var->slot(); |
| 1586 | 1584 |
| 1587 // If it was not possible to allocate the variable at compile time, | 1585 // If it was not possible to allocate the variable at compile time, |
| 1588 // we need to "declare" it at runtime to make sure it actually | 1586 // we need to "declare" it at runtime to make sure it actually |
| 1589 // exists in the local context. | 1587 // exists in the local context. |
| 1590 if (slot != NULL && slot->type() == Slot::LOOKUP) { | 1588 if (slot != NULL && slot->type() == Slot::LOOKUP) { |
| 1591 // Variables with a "LOOKUP" slot were introduced as non-locals | 1589 // Variables with a "LOOKUP" slot were introduced as non-locals |
| 1592 // during variable resolution and must have mode DYNAMIC. | 1590 // during variable resolution and must have mode DYNAMIC. |
| 1593 ASSERT(var->is_dynamic()); | 1591 ASSERT(var->is_dynamic()); |
| 1594 // For now, just do a runtime call. | 1592 // For now, just do a runtime call. |
| 1595 frame_->EmitPush(cp); | 1593 frame_->EmitPush(cp); |
| 1596 __ mov(r0, Operand(var->name())); | 1594 frame_->EmitPush(Operand(var->name())); |
| 1597 frame_->EmitPush(r0); | |
| 1598 // Declaration nodes are always declared in only two modes. | 1595 // Declaration nodes are always declared in only two modes. |
| 1599 ASSERT(node->mode() == Variable::VAR || node->mode() == Variable::CONST); | 1596 ASSERT(node->mode() == Variable::VAR || node->mode() == Variable::CONST); |
| 1600 PropertyAttributes attr = node->mode() == Variable::VAR ? NONE : READ_ONLY; | 1597 PropertyAttributes attr = node->mode() == Variable::VAR ? NONE : READ_ONLY; |
| 1601 __ mov(r0, Operand(Smi::FromInt(attr))); | 1598 frame_->EmitPush(Operand(Smi::FromInt(attr))); |
| 1602 frame_->EmitPush(r0); | |
| 1603 // Push initial value, if any. | 1599 // Push initial value, if any. |
| 1604 // Note: For variables we must not push an initial value (such as | 1600 // Note: For variables we must not push an initial value (such as |
| 1605 // 'undefined') because we may have a (legal) redeclaration and we | 1601 // 'undefined') because we may have a (legal) redeclaration and we |
| 1606 // must not destroy the current value. | 1602 // must not destroy the current value. |
| 1607 if (node->mode() == Variable::CONST) { | 1603 if (node->mode() == Variable::CONST) { |
| 1608 __ LoadRoot(r0, Heap::kTheHoleValueRootIndex); | 1604 frame_->EmitPushRoot(Heap::kTheHoleValueRootIndex); |
| 1609 frame_->EmitPush(r0); | |
| 1610 } else if (node->fun() != NULL) { | 1605 } else if (node->fun() != NULL) { |
| 1611 LoadAndSpill(node->fun()); | 1606 Load(node->fun()); |
| 1612 } else { | 1607 } else { |
| 1613 __ mov(r0, Operand(0)); // no initial value! | 1608 frame_->EmitPush(Operand(0)); |
| 1614 frame_->EmitPush(r0); | |
| 1615 } | 1609 } |
| 1610 |
| 1611 VirtualFrame::SpilledScope spilled_scope(frame_); |
| 1616 frame_->CallRuntime(Runtime::kDeclareContextSlot, 4); | 1612 frame_->CallRuntime(Runtime::kDeclareContextSlot, 4); |
| 1617 // Ignore the return value (declarations are statements). | 1613 // Ignore the return value (declarations are statements). |
| 1614 |
| 1618 ASSERT(frame_->height() == original_height); | 1615 ASSERT(frame_->height() == original_height); |
| 1619 return; | 1616 return; |
| 1620 } | 1617 } |
| 1621 | 1618 |
| 1622 ASSERT(!var->is_global()); | 1619 ASSERT(!var->is_global()); |
| 1623 | 1620 |
| 1624 // If we have a function or a constant, we need to initialize the variable. | 1621 // If we have a function or a constant, we need to initialize the variable. |
| 1625 Expression* val = NULL; | 1622 Expression* val = NULL; |
| 1626 if (node->mode() == Variable::CONST) { | 1623 if (node->mode() == Variable::CONST) { |
| 1627 val = new Literal(Factory::the_hole_value()); | 1624 val = new Literal(Factory::the_hole_value()); |
| 1628 } else { | 1625 } else { |
| 1629 val = node->fun(); // NULL if we don't have a function | 1626 val = node->fun(); // NULL if we don't have a function |
| 1630 } | 1627 } |
| 1631 | 1628 |
| 1632 if (val != NULL) { | 1629 if (val != NULL) { |
| 1633 { | 1630 // Set initial value. |
| 1634 // Set initial value. | 1631 Reference target(this, node->proxy()); |
| 1635 Reference target(this, node->proxy()); | 1632 Load(val); |
| 1636 LoadAndSpill(val); | 1633 target.SetValue(NOT_CONST_INIT); |
| 1637 target.SetValue(NOT_CONST_INIT); | 1634 |
| 1638 } | |
| 1639 // Get rid of the assigned value (declarations are statements). | 1635 // Get rid of the assigned value (declarations are statements). |
| 1640 frame_->Drop(); | 1636 frame_->Drop(); |
| 1641 } | 1637 } |
| 1642 ASSERT(frame_->height() == original_height); | 1638 ASSERT(frame_->height() == original_height); |
| 1643 } | 1639 } |
| 1644 | 1640 |
| 1645 | 1641 |
| 1646 void CodeGenerator::VisitExpressionStatement(ExpressionStatement* node) { | 1642 void CodeGenerator::VisitExpressionStatement(ExpressionStatement* node) { |
| 1647 #ifdef DEBUG | 1643 #ifdef DEBUG |
| 1648 int original_height = frame_->height(); | 1644 int original_height = frame_->height(); |
| (...skipping 7804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9453 | 9449 |
| 9454 // Just jump to runtime to add the two strings. | 9450 // Just jump to runtime to add the two strings. |
| 9455 __ bind(&string_add_runtime); | 9451 __ bind(&string_add_runtime); |
| 9456 __ TailCallRuntime(Runtime::kStringAdd, 2, 1); | 9452 __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
| 9457 } | 9453 } |
| 9458 | 9454 |
| 9459 | 9455 |
| 9460 #undef __ | 9456 #undef __ |
| 9461 | 9457 |
| 9462 } } // namespace v8::internal | 9458 } } // namespace v8::internal |
| OLD | NEW |