From 97d00637d277fe7c6900699fe7c7014da2493439 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Thu, 7 Dec 2017 11:31:46 +0000 Subject: [PATCH] Initial work on adding 16-bit constants to a 16-bit location. --- src/sixtypical/analyzer.py | 14 +++++++++++-- tests/SixtyPical Analysis.md | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/sixtypical/analyzer.py b/src/sixtypical/analyzer.py index 4a2b522..f74c318 100644 --- a/src/sixtypical/analyzer.py +++ b/src/sixtypical/analyzer.py @@ -2,7 +2,7 @@ from sixtypical.ast import Program, Routine, Block, Instr from sixtypical.model import ( - TYPE_BYTE, TYPE_BYTE_TABLE, BufferType, PointerType, VectorType, ExecutableType, + TYPE_BYTE, TYPE_WORD, TYPE_BYTE_TABLE, BufferType, PointerType, VectorType, ExecutableType, ConstantRef, LocationRef, IndirectRef, AddressRef, REG_A, REG_Y, FLAG_Z, FLAG_N, FLAG_V, FLAG_C ) @@ -233,7 +233,17 @@ class Analyzer(object): ) context.assert_meaningful(src) context.set_written(dest) - elif opcode in ('add', 'sub'): + elif opcode == 'add': + if src.type == TYPE_BYTE: + self.assert_type(TYPE_BYTE, src, dest) + context.assert_meaningful(src, dest, FLAG_C) + context.set_written(dest, FLAG_Z, FLAG_N, FLAG_C, FLAG_V) + else: + self.assert_type(TYPE_WORD, src, dest) + context.assert_meaningful(src, dest, FLAG_C) + context.set_written(dest, FLAG_Z, FLAG_N, FLAG_C, FLAG_V) + context.set_unmeaningful(REG_A) + elif opcode == 'sub': self.assert_type(TYPE_BYTE, src, dest) context.assert_meaningful(src, dest, FLAG_C) context.set_written(dest, FLAG_Z, FLAG_N, FLAG_C, FLAG_V) diff --git a/tests/SixtyPical Analysis.md b/tests/SixtyPical Analysis.md index c07db8a..9e7c753 100644 --- a/tests/SixtyPical Analysis.md +++ b/tests/SixtyPical Analysis.md @@ -373,6 +373,45 @@ Can't `add` to a memory location that isn't writeable. | } ? ForbiddenWriteError: a in main +You can `add` a word constant to a word memory location. + + | word score + | routine main + | inputs a, score + | outputs score + | trashes a, c, z, v, n + | { + | st off, c + | add score, 1999 + | } + = ok + +`add`ing a word constant to a word memory location trashes `a`. + + | word score + | routine main + | inputs a, score + | outputs score, a + | trashes c, z, v, n + | { + | st off, c + | add score, 1999 + | } + ? UnmeaningfulOutputError: a in main + +Not sure why this doesn't also raise an error? `a` is trashed... + + | word score + | routine main + | inputs score + | outputs score + | trashes c, z, v, n + | { + | st off, c + | add score, 1999 + | } + ? UnmeaningfulOutputError: a in main + ### sub ### Can't `sub` from or to a memory location that isn't initialized.