From 442501f338eca28cc022c3883f79b01f0de9f17c Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Sat, 13 Dec 2014 19:44:47 -0800 Subject: [PATCH] Move breakpoints out of AddressParser and into Monitor --- py65/monitor.py | 24 +++++++++++++----------- py65/tests/test_monitor.py | 6 +++--- py65/utils/addressing.py | 8 +------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/py65/monitor.py b/py65/monitor.py index b0167db..21f2b19 100644 --- a/py65/monitor.py +++ b/py65/monitor.py @@ -46,6 +46,7 @@ class Monitor(cmd.Cmd): if argv is None: argv = sys.argv self._reset(self.mpu_type) + self._breakpoints = [] self._width = 78 self.prompt = "." self._add_shortcuts() @@ -437,7 +438,7 @@ class Monitor(cmd.Cmd): def _run(self, stopcodes=[]): last_instruct = None - if not self._address_parser.breakpoints: + if not self._breakpoints: while last_instruct not in stopcodes: self._mpu.step() last_instruct = self._mpu.memory[self._mpu.pc] @@ -447,11 +448,11 @@ class Monitor(cmd.Cmd): while last_instruct not in stopcodes and not breakpoint: self._mpu.step() last_instruct = self._mpu.memory[self._mpu.pc] - if self._mpu.pc in self._address_parser.breakpoints: - self._output("Breakpoint %d reached." % self._address_parser.breakpoints.index(self._mpu.pc)) + if self._mpu.pc in self._breakpoints: + msg = "Breakpoint %d reached." + self._output(msg % self._breakpoints.index(self._mpu.pc)) breakpoint = True - def help_radix(self): self._output("radix [H|D|O|B]") self._output("Set default radix to hex, decimal, octal, or binary.") @@ -761,11 +762,12 @@ class Monitor(cmd.Cmd): address = self._address_parser.number(split[0]) - if address not in self._address_parser.breakpoints: - self._output("Breakpoint %d added at $%04X" % (len(self._address_parser.breakpoints), address)) - self._address_parser.breakpoints.append(address) - else: + if address in self._breakpoints: self._output("Breakpoint already present at $%04X" % address) + else: + self._breakpoints.append(address) + msg = "Breakpoint %d added at $%04X" + self._output(msg % (len(self._breakpoints), address)) def help_add_breakpoint(self): self._output("add_breakpoint ") @@ -787,8 +789,8 @@ class Monitor(cmd.Cmd): self._output("Illegal number: %s" % args) return - if self._address_parser.breakpoints[number] is not None: - self._address_parser.breakpoints[number] = None + if self._breakpoints[number] is not None: + self._breakpoints[number] = None self._output("Breakpoint %d removed" % number) else: self._output("Breakpoint %d already removed" % number) @@ -798,7 +800,7 @@ class Monitor(cmd.Cmd): self._output("Delete the breakpoint on execution marked by the given number") def do_list_breakpoints(self, args): - for (index, bp) in enumerate(self._address_parser.breakpoints): + for (index, bp) in enumerate(self._breakpoints): if bp is None: continue label = self._address_parser.label_for(bp, '') diff --git a/py65/tests/test_monitor.py b/py65/tests/test_monitor.py index b927e2a..a3cc08a 100644 --- a/py65/tests/test_monitor.py +++ b/py65/tests/test_monitor.py @@ -67,7 +67,7 @@ class MonitorTests(unittest.TestCase): mon.do_add_breakpoint('ffd2') out = stdout.getvalue() address_parser = mon._address_parser - self.assertTrue(0xffd2 in address_parser.breakpoints) + self.assertTrue(0xffd2 in mon._breakpoints) def test_do_add_breakpoint_adds_number(self): stdout = StringIO() @@ -76,7 +76,7 @@ class MonitorTests(unittest.TestCase): address_parser.labels['chrout'] = 0xffd2 mon.do_add_breakpoint('chrout') out = stdout.getvalue() - self.assertTrue(0xffd2 in address_parser.breakpoints) + self.assertTrue(0xffd2 in mon._breakpoints) # add_label @@ -461,7 +461,7 @@ class MonitorTests(unittest.TestCase): def test_goto_stops_execution_at_breakpoint(self): stdout = StringIO() mon = Monitor(stdout=stdout) - mon._address_parser.breakpoints = [ 0x02 ] + mon._breakpoints = [ 0x02 ] mon._mpu.memory = [ 0xEA, 0xEA, 0xEA, 0xEA ] mon.do_goto('0') out = stdout.getvalue() diff --git a/py65/utils/addressing.py b/py65/utils/addressing.py index 274f751..fab7424 100644 --- a/py65/utils/addressing.py +++ b/py65/utils/addressing.py @@ -5,7 +5,7 @@ class AddressParser(object): """Parse user input into addresses or ranges of addresses. """ - def __init__(self, maxwidth=16, radix=16, labels={}, breakpoints=[]): + def __init__(self, maxwidth=16, radix=16, labels={}): """Maxwidth is the maximum width of an address in bits. Radix is the default radix to use when one is not specified as a prefix of any input. Labels are a dictionary of label @@ -18,12 +18,6 @@ class AddressParser(object): for k, v in labels.items(): self.labels[k] = self._constrain(v) - self.breakpoints = [] - for v in breakpoints: - address = self._constrain(v) - if address not in self.breakpoints: - self.breakpoints.append(address) - def _get_maxwidth(self): return self._maxwidth