73 | 73 |
def clear_statics(self):
|
74 | 74 |
self.context.statics = {}
|
75 | 75 |
|
|
76 |
# ---- symbol resolution
|
|
77 |
|
76 | 78 |
def resolve_symbols(self, program):
|
77 | |
|
78 | |
def backpatch_constraint_labels(type_, resolver):
|
|
79 |
# This could stand to be better unified.
|
|
80 |
|
|
81 |
def backpatch_constraint_labels(type_):
|
79 | 82 |
def resolve(w):
|
80 | |
if not isinstance(w, str):
|
|
83 |
if not isinstance(w, ForwardReference):
|
81 | 84 |
return w
|
82 | |
return resolver(w)
|
|
85 |
return self.lookup(w.name)
|
83 | 86 |
if isinstance(type_, TableType):
|
84 | |
backpatch_constraint_labels(type_.of_type, resolver)
|
|
87 |
backpatch_constraint_labels(type_.of_type)
|
85 | 88 |
elif isinstance(type_, VectorType):
|
86 | |
backpatch_constraint_labels(type_.of_type, resolver)
|
|
89 |
backpatch_constraint_labels(type_.of_type)
|
87 | 90 |
elif isinstance(type_, RoutineType):
|
88 | 91 |
type_.inputs = set([resolve(w) for w in type_.inputs])
|
89 | 92 |
type_.outputs = set([resolve(w) for w in type_.outputs])
|
90 | 93 |
type_.trashes = set([resolve(w) for w in type_.trashes])
|
91 | 94 |
|
92 | 95 |
for defn in program.defns:
|
93 | |
backpatch_constraint_labels(defn.location.type, lambda w: self.lookup(w))
|
|
96 |
backpatch_constraint_labels(defn.location.type)
|
94 | 97 |
for routine in program.routines:
|
95 | |
backpatch_constraint_labels(routine.location.type, lambda w: self.lookup(w))
|
|
98 |
backpatch_constraint_labels(routine.location.type)
|
96 | 99 |
|
97 | 100 |
def resolve_fwd_reference(obj, field):
|
98 | 101 |
field_value = getattr(obj, field, None)
|
|
278 | 281 |
outputs = set(self.labels())
|
279 | 282 |
if self.scanner.consume('trashes'):
|
280 | 283 |
trashes = set(self.labels())
|
281 | |
return (inputs, outputs, trashes)
|
|
284 |
return (
|
|
285 |
set([ForwardReference(n) for n in inputs]),
|
|
286 |
set([ForwardReference(n) for n in outputs]),
|
|
287 |
set([ForwardReference(n) for n in trashes])
|
|
288 |
)
|
282 | 289 |
|
283 | 290 |
def legacy_routine(self):
|
284 | 291 |
self.scanner.expect('routine')
|