|
16 | 16 | #include "../compiler/Parser.h"
|
17 | 17 | #include "../interpreter/bytecodes.h"
|
18 | 18 | #include "../misc/StringUtil.h"
|
19 |
| -#include "../misc/debug.h" |
20 | 19 | #include "../vm/Symbols.h"
|
21 | 20 | #include "../vmobjects/VMMethod.h"
|
22 | 21 |
|
@@ -654,6 +653,53 @@ void BytecodeGenerationTest::testIfTrueIfFalseNlrArg2() {
|
654 | 653 | BC_PUSH_ARG_2, BC_RETURN_LOCAL, BC_POP, BC_PUSH_CONSTANT_2, BC_POP,
|
655 | 654 | BC_PUSH_SELF, BC_RETURN_LOCAL});
|
656 | 655 | }
|
| 656 | +void BytecodeGenerationTest::testInliningOfOr() { |
| 657 | + inliningOfOr("or:"); |
| 658 | + inliningOfOr("||"); |
| 659 | +} |
| 660 | + |
| 661 | +void BytecodeGenerationTest::inliningOfOr(std::string selector) { |
| 662 | + std::string source = "test = ( true OR_SEL [ #val ] )"; |
| 663 | + bool wasReplaced = ReplacePattern(source, "OR_SEL", selector); |
| 664 | + assert(wasReplaced); |
| 665 | + |
| 666 | + auto bytecodes = methodToBytecode(source.data()); |
| 667 | + check(bytecodes, |
| 668 | + {BC_PUSH_CONSTANT_0, BC(BC_JUMP_ON_TRUE_POP, 7, 0), |
| 669 | + // true branch |
| 670 | + BC_PUSH_CONSTANT_1, // push the `#val` |
| 671 | + BC(BC_JUMP, 4, 0), |
| 672 | + // false branch, jump_on_true target, push true |
| 673 | + BC_PUSH_CONSTANT_0, BC_POP, |
| 674 | + // target of the jump in the true branch |
| 675 | + BC_PUSH_SELF, BC_RETURN_LOCAL}); |
| 676 | + |
| 677 | + tearDown(); |
| 678 | +} |
| 679 | + |
| 680 | +void BytecodeGenerationTest::testInliningOfAnd() { |
| 681 | + inliningOfAnd("and:"); |
| 682 | + inliningOfAnd("&&"); |
| 683 | +} |
| 684 | + |
| 685 | +void BytecodeGenerationTest::inliningOfAnd(std::string selector) { |
| 686 | + std::string source = "test = ( true AND_SEL [ #val ] )"; |
| 687 | + bool wasReplaced = ReplacePattern(source, "AND_SEL", selector); |
| 688 | + assert(wasReplaced); |
| 689 | + |
| 690 | + auto bytecodes = methodToBytecode(source.data()); |
| 691 | + check(bytecodes, |
| 692 | + {BC_PUSH_CONSTANT_0, BC(BC_JUMP_ON_FALSE_POP, 7, 0), |
| 693 | + // true branch |
| 694 | + BC_PUSH_CONSTANT_1, // push the `#val` |
| 695 | + BC(BC_JUMP, 4, 0), |
| 696 | + // false branch, jump_on_false target, push false |
| 697 | + BC_PUSH_CONSTANT_2, BC_POP, |
| 698 | + // target of the jump in the true branch |
| 699 | + BC_PUSH_SELF, BC_RETURN_LOCAL}); |
| 700 | + |
| 701 | + tearDown(); |
| 702 | +} |
657 | 703 |
|
658 | 704 | /*
|
659 | 705 | @pytest.mark.parametrize(
|
@@ -1265,50 +1311,7 @@ void BytecodeGenerationTest::testIfTrueIfFalseNlrArg2() {
|
1265 | 1311 | )
|
1266 | 1312 |
|
1267 | 1313 |
|
1268 |
| - @pytest.mark.parametrize("and_sel", ["and:", "&&"]) |
1269 |
| - def test_inlining_of_and(mgenc, and_sel): |
1270 |
| - bytecodes = method_to_bytecodes( |
1271 |
| - mgenc, "test = ( true AND_SEL [ #val ] )".replace("AND_SEL", and_sel) |
1272 |
| - ) |
1273 |
| -
|
1274 |
| - assert len(bytecodes) == 11 |
1275 |
| - check( |
1276 |
| - bytecodes, |
1277 |
| - [ |
1278 |
| - Bytecodes.push_constant_0, |
1279 |
| - BC(Bytecodes.jump_on_false_pop, 7), |
1280 |
| - # true branch |
1281 |
| - BC_PUSH_CONSTANT_2, # push the `#val` |
1282 |
| - BC(Bytecodes.jump, 5), |
1283 |
| - # false branch, jump_on_false target, push false |
1284 |
| - Bytecodes.push_constant, |
1285 |
| - # target of the jump in the true branch |
1286 |
| - Bytecodes.return_self, |
1287 |
| - ], |
1288 |
| - ) |
1289 |
| -
|
1290 |
| -
|
1291 |
| - @pytest.mark.parametrize("or_sel", ["or:", "||"]) |
1292 |
| - def test_inlining_of_or(mgenc, or_sel): |
1293 |
| - bytecodes = method_to_bytecodes( |
1294 |
| - mgenc, "test = ( true OR_SEL [ #val ] )".replace("OR_SEL", or_sel) |
1295 |
| - ) |
1296 | 1314 |
|
1297 |
| - assert len(bytecodes) == 10 |
1298 |
| - check( |
1299 |
| - bytecodes, |
1300 |
| - [ |
1301 |
| - Bytecodes.push_constant_0, |
1302 |
| - BC(Bytecodes.jump_on_true_pop, 7), |
1303 |
| - # true branch |
1304 |
| - BC_PUSH_CONSTANT_2, # push the `#val` |
1305 |
| - BC(Bytecodes.jump, 4), |
1306 |
| - # false branch, jump_on_true target, push true |
1307 |
| - Bytecodes.push_constant_0, |
1308 |
| - # target of the jump in the true branch |
1309 |
| - Bytecodes.return_self, |
1310 |
| - ], |
1311 |
| - ) |
1312 | 1315 |
|
1313 | 1316 |
|
1314 | 1317 | def test_field_read_inlining(cgenc, mgenc):
|
|
0 commit comments