git @ Cat's Eye Technologies SixtyPical / cc98e02
Simply always produce ForwardReferences in locexpr(forward=True). Chris Pressey 4 years ago
1 changed file(s) with 12 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
111111
112112 program = Program(self.scanner.line_number, defns=defns, routines=routines)
113113
114 def resolve_fwd_reference(obj, field):
115 field_value = getattr(obj, field, None)
116 if isinstance(field_value, ForwardReference):
117 setattr(obj, field, self.lookup(field_value.name))
118 elif isinstance(field_value, IndexedRef):
119 if isinstance(field_value.ref, ForwardReference):
120 field_value.ref = self.lookup(field_value.ref.name)
121
114122 for node in program.all_children():
115123 if isinstance(node, SingleOp):
116 instr = node
117 if isinstance(instr.location, ForwardReference):
118 instr.location = self.lookup(instr.location.name)
119 if isinstance(instr.src, ForwardReference):
120 instr.src = self.lookup(instr.src.name)
121 if isinstance(instr.dest, ForwardReference):
122 instr.dest = self.lookup(instr.dest.name)
124 resolve_fwd_reference(node, 'location')
125 resolve_fwd_reference(node, 'src')
126 resolve_fwd_reference(node, 'dest')
123127
124128 return program
125129
338342 elif forward:
339343 name = self.scanner.token
340344 self.scanner.scan()
341 loc = self.context.fetch(name)
342 if loc is not None:
343 return loc
344 else:
345 return ForwardReference(name)
345 return ForwardReference(name)
346346 else:
347347 loc = self.lookup(self.scanner.token)
348348 self.scanner.scan()