From e46c6f6c6ee21ac914cf15ce3cdcaada6abc63be Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Tue, 12 Dec 2017 09:59:43 +0000 Subject: [PATCH] Improve error messaging yet more. Game kind of has game states now. --- eg/proto-game.60p | 22 ++++++++++------------ src/sixtypical/analyzer.py | 21 ++++++++++++++------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/eg/proto-game.60p b/eg/proto-game.60p index 944562e..c6f0436 100644 --- a/eg/proto-game.60p +++ b/eg/proto-game.60p @@ -32,7 +32,7 @@ word delta vector dispatch_game_state inputs joy2, pos - outputs delta, pos, screen, screen1 + outputs delta, pos, screen, screen1, dispatch_game_state trashes a, x, y, c, z, n, v, ptr // @@ -49,13 +49,13 @@ vector dispatch_game_state vector cinv inputs joy2, pos - outputs delta, pos, screen, screen1 + outputs delta, pos, dispatch_game_state, screen, screen1 trashes a, x, y, c, z, n, v, ptr @ 788 vector save_cinv inputs joy2, pos - outputs delta, pos, screen, screen1 + outputs delta, pos, dispatch_game_state, screen, screen1 trashes a, x, y, c, z, n, v, ptr @@ -125,7 +125,7 @@ routine clear_screen routine game_state_play inputs joy2, pos - outputs delta, pos, screen, screen1 + outputs delta, pos, dispatch_game_state, screen, screen1 trashes a, x, y, c, z, n, v, ptr { call read_stick @@ -145,7 +145,7 @@ routine game_state_play routine game_state_title_screen inputs joy2, pos - outputs delta, pos, screen, screen1 + outputs delta, pos, screen, screen1, dispatch_game_state trashes a, x, y, c, z, n, v, ptr { ld y, 0 @@ -162,10 +162,9 @@ routine game_state_title_screen if c { // call clear_screen // jsr init_game - // FIXME various reasons we can't do this, mainly that self-reference - // is disallowed: we would need to put "outputs dispatch_game_state" in - // the signature of dispatch_game_state! - // copy game_state_play, dispatch_game_state + copy game_state_play, dispatch_game_state + } else { + copy game_state_play, dispatch_game_state } goto save_cinv @@ -177,7 +176,7 @@ routine game_state_title_screen routine our_cinv inputs joy2, pos - outputs delta, pos, screen, screen1 + outputs delta, pos, dispatch_game_state, screen, screen1 trashes a, x, y, c, z, n, v, ptr { goto dispatch_game_state @@ -197,8 +196,7 @@ routine main call clear_screen - copy game_state_play, dispatch_game_state - // copy game_state_title_screen, dispatch_game_state + copy game_state_title_screen, dispatch_game_state copy word 0, pos with interrupts off { diff --git a/src/sixtypical/analyzer.py b/src/sixtypical/analyzer.py index c5e4506..34fce75 100644 --- a/src/sixtypical/analyzer.py +++ b/src/sixtypical/analyzer.py @@ -185,16 +185,23 @@ class Analyzer(object): ) def assert_affected_within(self, name, affected, limited_to): + # We reduce the set of LocationRefs to a set of strings (their labels). + # This is necessary because currently, two LocationRefs that refer to the + # same location are not considered euqal. (But two LocationRefs with the + # same label should always be the same type.) - def format(loc): - assert isinstance(loc, LocationRef) - return loc.name + affected = set([loc.name for loc in affected]) + limited_to = set([loc.name for loc in limited_to]) + + def loc_list(label_set): + return ', '.join(sorted(label_set)) - if affected <= limited_to: - return overage = affected - limited_to - overage_s = ', '.join(sorted([format(loc) for loc in overage])) - message = 'affected beyond %s: {%s} in %s' % (name, overage_s, self.current_routine.name) + if not overage: + return + message = 'in %s: %s are {%s} but affects {%s} which exceeds by: {%s} ' % ( + self.current_routine.name, name, loc_list(limited_to), loc_list(affected), loc_list(overage) + ) raise IncompatibleConstraintsError(message) def analyze_program(self, program):