From b477c5e786e77e0bb34890843dc2c4f3458d4f58 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Wed, 13 Dec 2017 16:18:36 +0000 Subject: [PATCH] Don't trash `a` in `copy` if `a` is the dest of the `copy`, for now. --- eg/proto-game.60p | 21 ++++++++++----------- src/sixtypical/analyzer.py | 8 +++++++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/eg/proto-game.60p b/eg/proto-game.60p index 7ffd61c..83a53e5 100644 --- a/eg/proto-game.60p +++ b/eg/proto-game.60p @@ -237,17 +237,16 @@ routine player_logic // check collision. copy [ptr] + y, a - - // cmp a, 32 - // if z { - // copy new_pos, pos - // copy 81, [ptr] + y - // } else { - // // copy game_state_game_over, dispatch_game_state - // } - - copy 81, [ptr] + y - copy new_pos, pos + cmp a, 32 + if z { + copy new_pos, pos + copy 81, [ptr] + y + } else { + // copy game_state_game_over, dispatch_game_state + trash n + trash a + trash z + } // FIXME these trashes, strictly speaking, probably shouldn't be needed, // but currently the compiler cares too much about values that are diff --git a/src/sixtypical/analyzer.py b/src/sixtypical/analyzer.py index e193c46..1272055 100644 --- a/src/sixtypical/analyzer.py +++ b/src/sixtypical/analyzer.py @@ -392,6 +392,7 @@ class Analyzer(object): context.assert_meaningful(src.ref, REG_Y) # TODO this will need to be more sophisticated. the thing ref points to is touched, as well. context.set_touched(src.ref) # TODO and REG_Y? if not, why not? + context.set_touched(dest) context.set_written(dest) elif isinstance(src, LocationRef) and isinstance(dest, IndexedRef): context.assert_meaningful(src, dest.ref, dest.index) @@ -409,7 +410,12 @@ class Analyzer(object): context.set_written(dest) context.set_touched(REG_A, FLAG_Z, FLAG_N) - context.set_unmeaningful(REG_A, FLAG_Z, FLAG_N) + context.set_unmeaningful(FLAG_Z, FLAG_N) + + # FIXME: this is just to support "copy [foo] + y, a". consider disallowing `a` as something + # that can be used in `copy`. should be using `st` or `ld` instead, probably. + if dest != REG_A: + context.set_unmeaningful(REG_A) elif opcode == 'with-sei': self.analyze_block(instr.block, context)