mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-02-19 20:30:45 +00:00
Make tests pass. Add two more tests towards completeness of spec.
This commit is contained in:
parent
d88757c32b
commit
ceaae962d5
@ -264,9 +264,15 @@ class Context(object):
|
|||||||
self.set_meaningful(*refs)
|
self.set_meaningful(*refs)
|
||||||
|
|
||||||
def set_unwriteable(self, *refs):
|
def set_unwriteable(self, *refs):
|
||||||
|
"""Intended to be used for implementing analyzing `for`."""
|
||||||
for ref in refs:
|
for ref in refs:
|
||||||
self._writeable.remove(ref)
|
self._writeable.remove(ref)
|
||||||
|
|
||||||
|
def set_writeable(self, *refs):
|
||||||
|
"""Intended to be used for implementing analyzing `for`."""
|
||||||
|
for ref in refs:
|
||||||
|
self._writeable.add(ref)
|
||||||
|
|
||||||
def set_encountered_goto(self):
|
def set_encountered_goto(self):
|
||||||
self._has_encountered_goto = True
|
self._has_encountered_goto = True
|
||||||
|
|
||||||
@ -670,9 +676,18 @@ class Analyzer(object):
|
|||||||
))
|
))
|
||||||
bottom = final
|
bottom = final
|
||||||
|
|
||||||
subcontext = context.clone()
|
# inside the block, the loop variable cannot be modified, and we know its range.
|
||||||
subcontext.set_range(instr.dest, bottom, top)
|
context.set_range(instr.dest, bottom, top)
|
||||||
subcontext.set_unwriteable(instr.dest)
|
context.set_unwriteable(instr.dest)
|
||||||
self.analyze_block(instr.block, subcontext)
|
|
||||||
|
|
||||||
|
# it will always be executed at least once, so analyze it having
|
||||||
|
# been executed the first time.
|
||||||
|
self.analyze_block(instr.block, context)
|
||||||
|
|
||||||
|
# now analyze it having been executed a second time, with the context
|
||||||
|
# of it having already been executed.
|
||||||
|
self.analyze_block(instr.block, context)
|
||||||
|
|
||||||
|
# after it is executed, we know the range of the loop variable.
|
||||||
context.set_range(instr.dest, instr.final, instr.final)
|
context.set_range(instr.dest, instr.final, instr.final)
|
||||||
|
context.set_writeable(instr.dest)
|
||||||
|
@ -1685,6 +1685,17 @@ In a "for" loop, we know the exact range the loop variable takes on.
|
|||||||
| }
|
| }
|
||||||
? RangeExceededError
|
? RangeExceededError
|
||||||
|
|
||||||
|
You need to initialize the loop variable before the loop.
|
||||||
|
|
||||||
|
| byte table[16] tab
|
||||||
|
|
|
||||||
|
| define foo routine inputs tab trashes a, x, c, z, v, n {
|
||||||
|
| for x up to 15 {
|
||||||
|
| ld a, 0
|
||||||
|
| }
|
||||||
|
| }
|
||||||
|
? UnmeaningfulReadError
|
||||||
|
|
||||||
You cannot modify the loop variable in a "for" loop.
|
You cannot modify the loop variable in a "for" loop.
|
||||||
|
|
||||||
| byte table[16] tab
|
| byte table[16] tab
|
||||||
@ -1731,6 +1742,17 @@ In a "for" loop (downward-counting variant), we know the exact range the loop va
|
|||||||
| }
|
| }
|
||||||
? RangeExceededError
|
? RangeExceededError
|
||||||
|
|
||||||
|
You need to initialize the loop variable before a "for" loop (downward variant).
|
||||||
|
|
||||||
|
| byte table[16] tab
|
||||||
|
|
|
||||||
|
| define foo routine inputs tab trashes a, x, c, z, v, n {
|
||||||
|
| for x down to 15 {
|
||||||
|
| ld a, 0
|
||||||
|
| }
|
||||||
|
| }
|
||||||
|
? UnmeaningfulReadError
|
||||||
|
|
||||||
You cannot modify the loop variable in a "for" loop (downward variant).
|
You cannot modify the loop variable in a "for" loop (downward variant).
|
||||||
|
|
||||||
| byte table[16] tab
|
| byte table[16] tab
|
||||||
|
Loading…
x
Reference in New Issue
Block a user