mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-02-21 04:29:14 +00:00
backpatch_constraint_labels can resolve ForwardReferences.
This commit is contained in:
parent
29a5bba85c
commit
07ef1e243a
@ -27,11 +27,11 @@ TYPE_WORD = Type('word', max_range=(0, 65535))
|
|||||||
|
|
||||||
class RoutineType(Type):
|
class RoutineType(Type):
|
||||||
"""This memory location contains the code for a routine."""
|
"""This memory location contains the code for a routine."""
|
||||||
def __init__(self, inputs=None, outputs=None, trashes=None):
|
def __init__(self, inputs, outputs, trashes):
|
||||||
self.name = 'routine'
|
self.name = 'routine'
|
||||||
self.inputs = inputs or set()
|
self.inputs = inputs
|
||||||
self.outputs = outputs or set()
|
self.outputs = outputs
|
||||||
self.trashes = trashes or set()
|
self.trashes = trashes
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '%s(%r, inputs=%r, outputs=%r, trashes=%r)' % (
|
return '%s(%r, inputs=%r, outputs=%r, trashes=%r)' % (
|
||||||
|
@ -74,26 +74,29 @@ class Parser(object):
|
|||||||
def clear_statics(self):
|
def clear_statics(self):
|
||||||
self.context.statics = {}
|
self.context.statics = {}
|
||||||
|
|
||||||
def resolve_symbols(self, program):
|
# ---- symbol resolution
|
||||||
|
|
||||||
def backpatch_constraint_labels(type_, resolver):
|
def resolve_symbols(self, program):
|
||||||
|
# This could stand to be better unified.
|
||||||
|
|
||||||
|
def backpatch_constraint_labels(type_):
|
||||||
def resolve(w):
|
def resolve(w):
|
||||||
if not isinstance(w, str):
|
if not isinstance(w, ForwardReference):
|
||||||
return w
|
return w
|
||||||
return resolver(w)
|
return self.lookup(w.name)
|
||||||
if isinstance(type_, TableType):
|
if isinstance(type_, TableType):
|
||||||
backpatch_constraint_labels(type_.of_type, resolver)
|
backpatch_constraint_labels(type_.of_type)
|
||||||
elif isinstance(type_, VectorType):
|
elif isinstance(type_, VectorType):
|
||||||
backpatch_constraint_labels(type_.of_type, resolver)
|
backpatch_constraint_labels(type_.of_type)
|
||||||
elif isinstance(type_, RoutineType):
|
elif isinstance(type_, RoutineType):
|
||||||
type_.inputs = set([resolve(w) for w in type_.inputs])
|
type_.inputs = set([resolve(w) for w in type_.inputs])
|
||||||
type_.outputs = set([resolve(w) for w in type_.outputs])
|
type_.outputs = set([resolve(w) for w in type_.outputs])
|
||||||
type_.trashes = set([resolve(w) for w in type_.trashes])
|
type_.trashes = set([resolve(w) for w in type_.trashes])
|
||||||
|
|
||||||
for defn in program.defns:
|
for defn in program.defns:
|
||||||
backpatch_constraint_labels(defn.location.type, lambda w: self.lookup(w))
|
backpatch_constraint_labels(defn.location.type)
|
||||||
for routine in program.routines:
|
for routine in program.routines:
|
||||||
backpatch_constraint_labels(routine.location.type, lambda w: self.lookup(w))
|
backpatch_constraint_labels(routine.location.type)
|
||||||
|
|
||||||
def resolve_fwd_reference(obj, field):
|
def resolve_fwd_reference(obj, field):
|
||||||
field_value = getattr(obj, field, None)
|
field_value = getattr(obj, field, None)
|
||||||
@ -279,7 +282,11 @@ class Parser(object):
|
|||||||
outputs = set(self.labels())
|
outputs = set(self.labels())
|
||||||
if self.scanner.consume('trashes'):
|
if self.scanner.consume('trashes'):
|
||||||
trashes = set(self.labels())
|
trashes = set(self.labels())
|
||||||
return (inputs, outputs, trashes)
|
return (
|
||||||
|
set([ForwardReference(n) for n in inputs]),
|
||||||
|
set([ForwardReference(n) for n in outputs]),
|
||||||
|
set([ForwardReference(n) for n in trashes])
|
||||||
|
)
|
||||||
|
|
||||||
def legacy_routine(self):
|
def legacy_routine(self):
|
||||||
self.scanner.expect('routine')
|
self.scanner.expect('routine')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user