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 function IntTest() { | 5 function IntTest() { |
6 "use asm"; | 6 "use asm"; |
7 function sum(a, b) { | 7 function sum(a, b) { |
8 a = a|0; | 8 a = a|0; |
9 b = b|0; | 9 b = b|0; |
10 var c = (b + 1)|0 | 10 var c = (b + 1)|0 |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 function add() { | 544 function add() { |
545 return +(a + b); | 545 return +(a + b); |
546 } | 546 } |
547 | 547 |
548 return {add:add}; | 548 return {add:add}; |
549 } | 549 } |
550 | 550 |
551 var module = WASM.instantiateModuleFromAsm(TestGlobalsWithInit.toString()); | 551 var module = WASM.instantiateModuleFromAsm(TestGlobalsWithInit.toString()); |
552 module.__init__(); | 552 module.__init__(); |
553 assertEquals(77.5, module.add()); | 553 assertEquals(77.5, module.add()); |
| 554 |
| 555 function TestForLoop() { |
| 556 "use asm" |
| 557 |
| 558 function caller() { |
| 559 var ret = 0; |
| 560 var i = 0; |
| 561 for (i = 2; i <= 10; i = (i+1)|0) { |
| 562 ret = (ret + i) | 0; |
| 563 } |
| 564 return ret|0; |
| 565 } |
| 566 |
| 567 return {caller:caller}; |
| 568 } |
| 569 |
| 570 assertEquals(54, WASM.asmCompileRun(TestForLoop.toString())); |
| 571 |
| 572 function TestForLoopWithoutInit() { |
| 573 "use asm" |
| 574 |
| 575 function caller() { |
| 576 var ret = 0; |
| 577 var i = 0; |
| 578 for (; i < 10; i = (i+1)|0) { |
| 579 ret = (ret + 10) | 0; |
| 580 } |
| 581 return ret|0; |
| 582 } |
| 583 |
| 584 return {caller:caller}; |
| 585 } |
| 586 |
| 587 assertEquals(100, WASM.asmCompileRun(TestForLoopWithoutInit.toString())); |
| 588 |
| 589 function TestForLoopWithoutCondition() { |
| 590 "use asm" |
| 591 |
| 592 function caller() { |
| 593 var ret = 0; |
| 594 var i = 0; |
| 595 for (i=1;; i = (i+1)|0) { |
| 596 ret = (ret + i) | 0; |
| 597 if (i == 11) { |
| 598 break; |
| 599 } |
| 600 } |
| 601 return ret|0; |
| 602 } |
| 603 |
| 604 return {caller:caller}; |
| 605 } |
| 606 |
| 607 assertEquals(66, WASM.asmCompileRun(TestForLoopWithoutCondition.toString())); |
| 608 |
| 609 function TestForLoopWithoutNext() { |
| 610 "use asm" |
| 611 |
| 612 function caller() { |
| 613 var i = 0; |
| 614 for (i=1; i < 41;) { |
| 615 i = (i + 1) | 0; |
| 616 } |
| 617 return i|0; |
| 618 } |
| 619 |
| 620 return {caller:caller}; |
| 621 } |
| 622 |
| 623 assertEquals(41, WASM.asmCompileRun(TestForLoopWithoutNext.toString())); |
| 624 |
| 625 function TestForLoopWithoutBody() { |
| 626 "use asm" |
| 627 |
| 628 function caller() { |
| 629 var i = 0; |
| 630 for (i=1; i < 45 ; i = (i+1)|0) { |
| 631 } |
| 632 return i|0; |
| 633 } |
| 634 |
| 635 return {caller:caller}; |
| 636 } |
| 637 |
| 638 assertEquals(45, WASM.asmCompileRun(TestForLoopWithoutBody.toString())); |
OLD | NEW |