From 20c824743e78ee529cb74bc9e0d255ce588e8690 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Mon, 5 Feb 2018 12:35:19 +0000 Subject: [PATCH] Fix table access bug where index wasn't required to be initialized. --- HISTORY.md | 1 + src/sixtypical/analyzer.py | 2 ++ tests/SixtyPical Analysis.md | 43 ++++++++++++++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index df6ec64..776ab73 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -8,6 +8,7 @@ History of SixtyPical * Initialized `byte table` values need not have all 256 bytes initialized. * Constraints for `vector` type come immediately after the type, not the variable. * `vector table` storage, and ability to copy vectors in and out of same. +* Fixed bug where index register wasn't required to be initialized before table access. 0.10 ---- diff --git a/src/sixtypical/analyzer.py b/src/sixtypical/analyzer.py index 2abc5b3..2320dbd 100644 --- a/src/sixtypical/analyzer.py +++ b/src/sixtypical/analyzer.py @@ -238,6 +238,7 @@ class Analyzer(object): raise TypeMismatchError('%s and %s in %s' % (src.name, dest.name, self.current_routine.name) ) + context.assert_meaningful(instr.index) elif src.type != dest.type: raise TypeMismatchError('%s and %s in %s' % (src.name, dest.name, self.current_routine.name) @@ -250,6 +251,7 @@ class Analyzer(object): pass else: raise TypeMismatchError((src, dest)) + context.assert_meaningful(instr.index) elif src.type != dest.type: raise TypeMismatchError('%s and %s in %s' % (src.name, dest.name, self.current_routine.name) diff --git a/tests/SixtyPical Analysis.md b/tests/SixtyPical Analysis.md index 4f27f5e..51032b7 100644 --- a/tests/SixtyPical Analysis.md +++ b/tests/SixtyPical Analysis.md @@ -240,7 +240,7 @@ Can't `st` a `word` type. ### tables ### -Storing to a table, you must use an index, and vice-versa. +Storing to a table, you must use an index. | byte one | byte table[256] many @@ -294,7 +294,21 @@ Storing to a table, you must use an index, and vice-versa. | } = ok -Reading from a table, you must use an index, and vice-versa. +The index must be initialized. + + | byte one + | byte table[256] many + | + | routine main + | outputs many + | trashes a, x, n, z + | { + | ld a, 0 + | st a, many + x + | } + ? UnmeaningfulReadError: x + +Reading from a table, you must use an index. | byte one | @@ -346,6 +360,31 @@ Reading from a table, you must use an index, and vice-versa. | } = ok + | byte table[256] many + | + | routine main + | inputs many + | outputs many + | trashes a, x, n, z + | { + | ld x, 0 + | ld a, many + x + | } + = ok + +The index must be initialized. + + | byte table[256] many + | + | routine main + | inputs many + | outputs many + | trashes a, x, n, z + | { + | ld a, many + x + | } + ? UnmeaningfulReadError: x + Copying to and from a word table. | word one