Tests for the `downto` variant too.
Chris Pressey
4 years ago
1708 | 1708 | | } |
1709 | 1709 | ? RangeExceededError |
1710 | 1710 | |
1711 | In a "for" loop (downto variant), we know the exact range the loop variable takes on. | |
1712 | ||
1713 | | byte table[16] tab | |
1714 | | | |
1715 | | define foo routine inputs tab trashes a, x, c, z, v, n { | |
1716 | | ld x, 15 | |
1717 | | for x downto 0 { | |
1718 | | ld a, tab + x | |
1719 | | } | |
1720 | | } | |
1721 | = ok | |
1722 | ||
1723 | | byte table[15] tab | |
1724 | | | |
1725 | | define foo routine inputs tab trashes a, x, c, z, v, n { | |
1726 | | ld x, 15 | |
1727 | | for x downto 0 { | |
1728 | | ld a, tab + x | |
1729 | | } | |
1730 | | } | |
1731 | ? RangeExceededError | |
1732 | ||
1733 | You cannot modify the loop variable in a "for" loop (downto variant). | |
1734 | ||
1735 | | byte table[16] tab | |
1736 | | | |
1737 | | define foo routine inputs tab trashes a, x, c, z, v, n { | |
1738 | | ld x, 15 | |
1739 | | for x downto 0 { | |
1740 | | ld x, 0 | |
1741 | | } | |
1742 | | } | |
1743 | ? ForbiddenWriteError | |
1744 | ||
1745 | If the range isn't known to be larger than the final value, you can't go down to it. | |
1746 | ||
1747 | | byte table[32] tab | |
1748 | | | |
1749 | | define foo routine inputs tab trashes a, x, c, z, v, n { | |
1750 | | ld x, 0 | |
1751 | | for x downto 0 { | |
1752 | | ld a, tab + x | |
1753 | | } | |
1754 | | } | |
1755 | ? RangeExceededError | |
1756 | ||
1711 | 1757 | ### copy ### |
1712 | 1758 | |
1713 | 1759 | Can't `copy` from a memory location that isn't initialized. |