1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-12-01 16:50:09 +00:00

Add some failing tests for analyzing "for".

This commit is contained in:
Chris Pressey 2018-03-08 17:17:49 +00:00
parent d815e05e0c
commit f73a2313bd
2 changed files with 62 additions and 1 deletions

View File

@ -1,6 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from sixtypical.ast import Program, Routine, Block, Instr, SingleOp, If, Repeat, WithInterruptsOff from sixtypical.ast import Program, Routine, Block, Instr, SingleOp, If, Repeat, For, WithInterruptsOff
from sixtypical.model import ( from sixtypical.model import (
TYPE_BYTE, TYPE_WORD, TYPE_BYTE, TYPE_WORD,
TableType, BufferType, PointerType, VectorType, RoutineType, TableType, BufferType, PointerType, VectorType, RoutineType,
@ -329,6 +329,8 @@ class Analyzer(object):
self.analyze_if(instr, context) self.analyze_if(instr, context)
elif isinstance(instr, Repeat): elif isinstance(instr, Repeat):
self.analyze_repeat(instr, context) self.analyze_repeat(instr, context)
elif isinstance(instr, For):
self.analyze_for(instr, context)
elif isinstance(instr, WithInterruptsOff): elif isinstance(instr, WithInterruptsOff):
self.analyze_block(instr.block, context) self.analyze_block(instr.block, context)
else: else:
@ -611,3 +613,12 @@ class Analyzer(object):
self.analyze_block(instr.block, context) self.analyze_block(instr.block, context)
if instr.src is not None: if instr.src is not None:
context.assert_meaningful(instr.src) context.assert_meaningful(instr.src)
def analyze_for(self, instr, context):
# TODO: find the range of the loop variable in context, make sure it fits
# TODO: set the loop variable as 'not writeable' in the context
self.analyze_block(instr.block, context)
# TODO: at the end of the loop, we know the new range of the loop variable

View File

@ -1659,6 +1659,56 @@ The body of `repeat forever` can be empty.
| } | }
= ok = ok
### for ###
Basic "open-faced for" loop. We'll start with the "upto" variant.
In a "for" loop, we know the exact range the loop variable takes on.
| byte table[16] tab
|
| define foo routine inputs tab trashes a, x, c, z, v, n {
| ld x, 0
| for x upto 15 {
| ld a, tab + x
| }
| }
= ok
| byte table[15] tab
|
| define foo routine inputs tab trashes a, x, c, z, v, n {
| ld x, 0
| for x upto 15 {
| ld a, tab + x
| }
| }
? RangeExceededError
You cannot modify the loop variable in a "for" loop.
| byte table[16] tab
|
| define foo routine inputs tab trashes a, x, c, z, v, n {
| ld x, 0
| for x upto 15 {
| ld x, 0
| }
| }
? ForbiddenWriteError
If the range isn't known to be smaller than the final value, you can't go up to it.
| byte table[32] tab
|
| define foo routine inputs tab trashes a, x, c, z, v, n {
| ld x, 16
| for x upto 15 {
| ld a, tab + x
| }
| }
? RangeExceededError
### copy ### ### copy ###
Can't `copy` from a memory location that isn't initialized. Can't `copy` from a memory location that isn't initialized.