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 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 | 472 |
473 __ CallRuntime(function, arg_count); | 473 __ CallRuntime(function, arg_count); |
474 if (expr->location().is_temporary()) { | 474 if (expr->location().is_temporary()) { |
475 __ push(r0); | 475 __ push(r0); |
476 } else { | 476 } else { |
477 ASSERT(expr->location().is_nowhere()); | 477 ASSERT(expr->location().is_nowhere()); |
478 } | 478 } |
479 } | 479 } |
480 | 480 |
481 | 481 |
| 482 void FastCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) { |
| 483 // Compile a short-circuited boolean or operation in a non-test |
| 484 // context. |
| 485 ASSERT(expr->op() == Token::OR); |
| 486 // Compile (e0 || e1) as if it were |
| 487 // (let (temp = e0) temp ? temp : e1). |
| 488 |
| 489 Label done; |
| 490 Location destination = expr->location(); |
| 491 ASSERT(!destination.is_constant()); |
| 492 |
| 493 Expression* left = expr->left(); |
| 494 Location left_source = left->location(); |
| 495 ASSERT(!left_source.is_nowhere()); |
| 496 |
| 497 Expression* right = expr->right(); |
| 498 Location right_source = right->location(); |
| 499 ASSERT(!right_source.is_nowhere()); |
| 500 |
| 501 Visit(left); |
| 502 // Call the runtime to find the boolean value of the left-hand |
| 503 // subexpression. Duplicate the value if it may be needed as the final |
| 504 // result. |
| 505 if (left_source.is_temporary()) { |
| 506 if (destination.is_temporary()) { |
| 507 __ ldr(r0, MemOperand(sp)); |
| 508 __ push(r0); |
| 509 } |
| 510 } else { |
| 511 ASSERT(left->AsLiteral() != NULL); |
| 512 __ mov(r0, Operand(left->AsLiteral()->handle())); |
| 513 __ push(r0); |
| 514 if (destination.is_temporary()) __ push(r0); |
| 515 } |
| 516 // The left-hand value is in on top of the stack. It is duplicated on the |
| 517 // stack iff the destination location is temporary. |
| 518 __ CallRuntime(Runtime::kToBool, 1); |
| 519 __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 520 __ cmp(r0, ip); |
| 521 __ b(eq, &done); |
| 522 |
| 523 // Discard the left-hand value if present on the stack. |
| 524 if (destination.is_temporary()) __ pop(); |
| 525 Visit(right); |
| 526 |
| 527 // Save or discard the right-hand value as needed. |
| 528 if (destination.is_temporary() && right_source.is_constant()) { |
| 529 ASSERT(right->AsLiteral() != NULL); |
| 530 __ mov(ip, Operand(right->AsLiteral()->handle())); |
| 531 __ push(ip); |
| 532 } else if (destination.is_nowhere() && right_source.is_temporary()) { |
| 533 __ pop(); |
| 534 } |
| 535 |
| 536 __ bind(&done); |
| 537 } |
| 538 |
482 } } // namespace v8::internal | 539 } } // namespace v8::internal |
OLD | NEW |