Commit f040685
committed
py: Only store the exception instance on Py stack in bytecode try block.
When an exception is raised and is to be handled by the VM, it is stored
on the Python value stack so the bytecode can access it. CPython stores
3 objects on the stack for each exception: exc type, exc instance and
traceback. uPy followed this approach, but it turns out not to be
necessary. Instead, it is enough to store just the exception instance on
the Python value stack. The only place where the 3 values are needed
explicitly is for the __exit__ handler of a with-statement context, but
for these cases the 3 values can be extracted from the single exception
instance.
This patch removes the need to store 3 values on the stack, and instead
just stores the exception instance.
Code size is reduced by about 50-100 bytes, the compiler and VM are
slightly simpler, generate bytecode is smaller (by 2 bytes for each try
block), and the Python value stack is reduced in size for functions that
handle exceptions.1 parent 67d52d8 commit f040685
3 files changed
Lines changed: 30 additions & 44 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1495 | 1495 | | |
1496 | 1496 | | |
1497 | 1497 | | |
| 1498 | + | |
| 1499 | + | |
1498 | 1500 | | |
1499 | 1501 | | |
1500 | 1502 | | |
| |||
1528 | 1530 | | |
1529 | 1531 | | |
1530 | 1532 | | |
1531 | | - | |
1532 | | - | |
| 1533 | + | |
1533 | 1534 | | |
1534 | 1535 | | |
1535 | 1536 | | |
1536 | 1537 | | |
1537 | 1538 | | |
1538 | 1539 | | |
1539 | | - | |
1540 | | - | |
1541 | 1540 | | |
1542 | 1541 | | |
1543 | 1542 | | |
| |||
1561 | 1560 | | |
1562 | 1561 | | |
1563 | 1562 | | |
1564 | | - | |
| 1563 | + | |
1565 | 1564 | | |
1566 | 1565 | | |
1567 | 1566 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
751 | 751 | | |
752 | 752 | | |
753 | 753 | | |
754 | | - | |
755 | | - | |
756 | | - | |
757 | | - | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
758 | 757 | | |
759 | 758 | | |
760 | 759 | | |
761 | 760 | | |
762 | 761 | | |
763 | 762 | | |
764 | 763 | | |
765 | | - | |
| 764 | + | |
766 | 765 | | |
| 766 | + | |
767 | 767 | | |
768 | 768 | | |
769 | 769 | | |
| |||
955 | 955 | | |
956 | 956 | | |
957 | 957 | | |
958 | | - | |
| 958 | + | |
959 | 959 | | |
960 | 960 | | |
961 | 961 | | |
962 | | - | |
| 962 | + | |
963 | 963 | | |
964 | 964 | | |
965 | 965 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
587 | 587 | | |
588 | 588 | | |
589 | 589 | | |
| 590 | + | |
| 591 | + | |
590 | 592 | | |
591 | 593 | | |
592 | 594 | | |
| |||
620 | 622 | | |
621 | 623 | | |
622 | 624 | | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
632 | 633 | | |
633 | 634 | | |
634 | 635 | | |
635 | 636 | | |
636 | 637 | | |
637 | | - | |
638 | 638 | | |
639 | 639 | | |
640 | 640 | | |
641 | 641 | | |
642 | 642 | | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
| 643 | + | |
| 644 | + | |
648 | 645 | | |
649 | 646 | | |
650 | 647 | | |
| |||
698 | 695 | | |
699 | 696 | | |
700 | 697 | | |
701 | | - | |
702 | | - | |
703 | 698 | | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
| 699 | + | |
| 700 | + | |
709 | 701 | | |
710 | 702 | | |
711 | | - | |
712 | | - | |
| 703 | + | |
713 | 704 | | |
714 | 705 | | |
715 | 706 | | |
| |||
719 | 710 | | |
720 | 711 | | |
721 | 712 | | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
722 | 716 | | |
723 | 717 | | |
724 | 718 | | |
| |||
751 | 745 | | |
752 | 746 | | |
753 | 747 | | |
754 | | - | |
755 | | - | |
756 | 748 | | |
757 | 749 | | |
758 | | - | |
759 | | - | |
760 | 750 | | |
761 | | - | |
762 | 751 | | |
763 | 752 | | |
764 | 753 | | |
| |||
1359 | 1348 | | |
1360 | 1349 | | |
1361 | 1350 | | |
1362 | | - | |
1363 | | - | |
| 1351 | + | |
1364 | 1352 | | |
1365 | | - | |
1366 | 1353 | | |
1367 | 1354 | | |
1368 | 1355 | | |
| |||
0 commit comments