1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2025-04-06 17:39:38 +00:00

Refactor: common method to backpatch labels.

This commit is contained in:
Chris Pressey 2017-12-12 12:51:19 +00:00
parent 8dc44673fa
commit 60df162625
2 changed files with 9 additions and 10 deletions

View File

@ -107,6 +107,13 @@ class LocationRef(Ref):
def is_constant(self):
return isinstance(self.type, RoutineType)
def backpatch_labels(self, resolver):
if isinstance(self.type, ExecutableType):
t = self.type
t.inputs = set([resolver(w) for w in t.inputs])
t.outputs = set([resolver(w) for w in t.outputs])
t.trashes = set([resolver(w) for w in t.trashes])
@classmethod
def format_set(cls, location_refs):
return '{%s}' % ', '.join([str(loc) for loc in sorted(location_refs)])

View File

@ -51,17 +51,9 @@ class Parser(object):
self.scanner.check_type('EOF')
# now backpatch the executable types.
for defn in defns:
if isinstance(defn.location.type, VectorType):
t = defn.location.type
t.inputs = set([self.lookup(w) for w in t.inputs])
t.outputs = set([self.lookup(w) for w in t.outputs])
t.trashes = set([self.lookup(w) for w in t.trashes])
defn.location.backpatch_labels(lambda w: self.lookup(w))
for routine in routines:
if isinstance(routine.location.type, ExecutableType):
t = routine.location.type
t.inputs = set([self.lookup(w) for w in t.inputs])
t.outputs = set([self.lookup(w) for w in t.outputs])
t.trashes = set([self.lookup(w) for w in t.trashes])
routine.location.backpatch_labels(lambda w: self.lookup(w))
return Program(defns=defns, routines=routines)
def defn(self):