From 3f1f3bf16e134c7a0e9e40232ea806d635b77343 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Thu, 8 Feb 2018 13:43:06 +0000 Subject: [PATCH] Set a location as touched when trashed with a `trash` instruction. --- HISTORY.md | 1 + src/sixtypical/analyzer.py | 9 +++++---- tests/SixtyPical Analysis.md | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 5ed6df3..0f2e050 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,6 +6,7 @@ History of SixtyPical * `copy` is now understood to trash `a`, thus `copy ..., a` is not valid. Indirect addressing is supported in `ld`, as in `ld a, [ptr] + y`, to compensate. +* Fixed bug where `trash` was not marking the location as being virtually altered. 0.11 ---- diff --git a/src/sixtypical/analyzer.py b/src/sixtypical/analyzer.py index 29b4da6..64083bc 100644 --- a/src/sixtypical/analyzer.py +++ b/src/sixtypical/analyzer.py @@ -207,8 +207,8 @@ class Analyzer(object): if routine.block is None: # it's an extern, that's fine return - type = routine.location.type - context = Context(self.routines, routine, type.inputs, type.outputs, type.trashes) + type_ = routine.location.type + context = Context(self.routines, routine, type_.inputs, type_.outputs, type_.trashes) if self.debug: print "at start of routine `{}`:".format(routine.name) print context @@ -217,10 +217,10 @@ class Analyzer(object): print "at end of routine `{}`:".format(routine.name) print context if not self.has_encountered_goto: - for ref in type.outputs: + for ref in type_.outputs: context.assert_meaningful(ref, exception_class=UnmeaningfulOutputError) for ref in context.each_touched(): - if ref not in type.outputs and ref not in type.trashes: + if ref not in type_.outputs and ref not in type_.trashes: message = '%s in %s' % (ref.name, routine.name) raise ForbiddenWriteError(message) self.current_routine = None @@ -466,6 +466,7 @@ class Analyzer(object): self.has_encountered_goto = True elif opcode == 'trash': + context.set_touched(instr.dest) context.set_unmeaningful(instr.dest) else: raise NotImplementedError(opcode) diff --git a/tests/SixtyPical Analysis.md b/tests/SixtyPical Analysis.md index ff0967c..1105302 100644 --- a/tests/SixtyPical Analysis.md +++ b/tests/SixtyPical Analysis.md @@ -127,7 +127,7 @@ If a routine trashes a location, this must be declared. | { | trash x | } - ? UnmeaningfulOutputError: x in foo + ? ForbiddenWriteError: x in foo | routine foo | outputs x @@ -162,7 +162,7 @@ If a routine causes a location to be trashed, this must be declared in the calle | { | call trash_x | } - ? UnmeaningfulOutputError: x in foo + ? ForbiddenWriteError: x in foo | routine trash_x | trashes x, z, n