git @ Cat's Eye Technologies SixtyPical / b91c3ed
Add three more tests. Ensure they pass. Chris Pressey 3 years ago
2 changed file(s) with 47 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
657657
658658 def analyze_for(self, instr, context):
659659 context.assert_meaningful(instr.dest)
660 context.assert_writeable(instr.dest)
660661
661662 bottom, top = context.get_range(instr.dest)
662663 final = instr.final.value
17071707 | }
17081708 ? ForbiddenWriteError
17091709
1710 This includes nesting a loop on the same variable.
1711
1712 | byte table[16] tab
1713 |
1714 | define foo routine inputs tab trashes a, x, c, z, v, n {
1715 | ld x, 0
1716 | for x up to 8 {
1717 | for x up to 15 {
1718 | ld a, 0
1719 | }
1720 | }
1721 | }
1722 ? ForbiddenWriteError
1723
1724 But nesting with two different variables is okay.
1725
1726 | byte table[16] tab
1727 |
1728 | define foo routine inputs tab trashes a, x, y, c, z, v, n {
1729 | ld x, 0
1730 | for x up to 8 {
1731 | ld a, x
1732 | ld y, a
1733 | for y up to 15 {
1734 | ld a, 0
1735 | }
1736 | }
1737 | }
1738 = ok
1739
1740 Inside the inner loop, the outer variable is still not writeable.
1741
1742 | byte table[16] tab
1743 |
1744 | define foo routine inputs tab trashes a, x, y, c, z, v, n {
1745 | ld x, 0
1746 | for x up to 8 {
1747 | ld a, x
1748 | ld y, a
1749 | for y up to 15 {
1750 | ld x, 0
1751 | }
1752 | }
1753 | }
1754 ? ForbiddenWriteError
1755
17101756 If the range isn't known to be smaller than the final value, you can't go up to it.
17111757
17121758 | byte table[32] tab