git @ Cat's Eye Technologies SixtyPical / ceaae96
Make tests pass. Add two more tests towards completeness of spec. Chris Pressey 3 years ago
2 changed file(s) with 42 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
263263 self.set_meaningful(*refs)
264264
265265 def set_unwriteable(self, *refs):
266 """Intended to be used for implementing analyzing `for`."""
266267 for ref in refs:
267268 self._writeable.remove(ref)
269
270 def set_writeable(self, *refs):
271 """Intended to be used for implementing analyzing `for`."""
272 for ref in refs:
273 self._writeable.add(ref)
268274
269275 def set_encountered_goto(self):
270276 self._has_encountered_goto = True
669675 ))
670676 bottom = final
671677
672 subcontext = context.clone()
673 subcontext.set_range(instr.dest, bottom, top)
674 subcontext.set_unwriteable(instr.dest)
675 self.analyze_block(instr.block, subcontext)
676
678 # inside the block, the loop variable cannot be modified, and we know its range.
679 context.set_range(instr.dest, bottom, top)
680 context.set_unwriteable(instr.dest)
681
682 # it will always be executed at least once, so analyze it having
683 # been executed the first time.
684 self.analyze_block(instr.block, context)
685
686 # now analyze it having been executed a second time, with the context
687 # of it having already been executed.
688 self.analyze_block(instr.block, context)
689
690 # after it is executed, we know the range of the loop variable.
677691 context.set_range(instr.dest, instr.final, instr.final)
692 context.set_writeable(instr.dest)
16841684 | }
16851685 ? RangeExceededError
16861686
1687 You need to initialize the loop variable before the loop.
1688
1689 | byte table[16] tab
1690 |
1691 | define foo routine inputs tab trashes a, x, c, z, v, n {
1692 | for x up to 15 {
1693 | ld a, 0
1694 | }
1695 | }
1696 ? UnmeaningfulReadError
1697
16871698 You cannot modify the loop variable in a "for" loop.
16881699
16891700 | byte table[16] tab
17291740 | }
17301741 | }
17311742 ? RangeExceededError
1743
1744 You need to initialize the loop variable before a "for" loop (downward variant).
1745
1746 | byte table[16] tab
1747 |
1748 | define foo routine inputs tab trashes a, x, c, z, v, n {
1749 | for x down to 15 {
1750 | ld a, 0
1751 | }
1752 | }
1753 ? UnmeaningfulReadError
17321754
17331755 You cannot modify the loop variable in a "for" loop (downward variant).
17341756