From 3010435addd87cfe2d84413f3effb25028f7df66 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Mon, 19 Oct 2015 18:44:20 +0100 Subject: [PATCH] Inputs/outputs/trashes are now part of the type information only. --- src/sixtypical/analyzer.py | 14 ++++++++------ src/sixtypical/parser.py | 26 ++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/sixtypical/analyzer.py b/src/sixtypical/analyzer.py index 518a831..8babfbd 100644 --- a/src/sixtypical/analyzer.py +++ b/src/sixtypical/analyzer.py @@ -134,12 +134,13 @@ def analyze_routine(routine, routines): if routine.block is None: # it's an extern, that's fine return - context = Context(routine.inputs, routine.outputs, routine.trashes) + type = routine.location.type + context = Context(type.inputs, type.outputs, type.trashes) analyze_block(routine.block, context, routines) - for ref in routine.outputs: + for ref in type.outputs: context.assert_meaningful(ref, exception_class=UninitializedOutputError) for ref in context.each_touched(): - if ref not in routine.outputs and ref not in routine.trashes: + if ref not in type.outputs and ref not in type.trashes: raise IllegalWriteError(ref.name) @@ -192,11 +193,12 @@ def analyze_instr(instr, context, routines): context.set_written(dest, FLAG_Z, FLAG_N, FLAG_C) elif opcode == 'call': routine = routines[instr.name] - for ref in routine.inputs: + type = routine.location.type + for ref in type.inputs: context.assert_meaningful(ref) - for ref in routine.outputs: + for ref in type.outputs: context.set_written(ref) - for ref in routine.trashes: + for ref in type.trashes: context.assert_writeable(ref) context.set_touched(ref) context.set_unmeaningful(ref) diff --git a/src/sixtypical/parser.py b/src/sixtypical/parser.py index 42095b6..ee30dc9 100644 --- a/src/sixtypical/parser.py +++ b/src/sixtypical/parser.py @@ -109,20 +109,14 @@ class Parser(object): name = defn.name if name in self.symbols: raise SyntaxError('Symbol "%s" already declared' % name) - self.symbols[name] = SymEntry(defn, LocationRef(defn.type, name)) + self.symbols[name] = SymEntry(defn, defn.location) defns.append(defn) while self.scanner.on('routine'): routine = self.routine() name = routine.name if name in self.symbols: - raise SyntaxError(name) - ref = LocationRef( - RoutineType(inputs=routine.inputs, - outputs=routine.outputs, - trashes=routine.trashes - ), name - ) - self.symbols[name] = SymEntry(routine, ref) + raise SyntaxError('Symbol "%s" already declared' % name) + self.symbols[name] = SymEntry(routine, routine.location) routines.append(routine) self.scanner.check_type('EOF') return Program(defns=defns, routines=routines) @@ -150,9 +144,9 @@ class Parser(object): if self.scanner.consume('@'): self.scanner.check_type('integer literal') addr = int(self.scanner.token) - self.scanner.scan() - return Defn(name=name, type=type, addr=addr, - inputs=inputs, outputs=outputs, trashes=trashes) + self.scanner.scan() + location = LocationRef(type, name) + return Defn(name=name, addr=addr, location=location) def constraints(self): inputs = [] @@ -179,9 +173,13 @@ class Parser(object): else: block = self.block() addr = None + location = LocationRef( + RoutineType(inputs=inputs, outputs=outputs, trashes=trashes), + name + ) return Routine( - name=name, inputs=inputs, outputs=outputs, trashes=trashes, - block=block, addr=addr + name=name, block=block, addr=addr, + location=location ) def locexprs(self):