1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2025-02-20 13:29:09 +00:00

locexpr() always returns a ForwardReference if it can't lookup it.

This commit is contained in:
Chris Pressey 2018-09-07 15:03:41 +01:00
parent 07ef1e243a
commit 684b26dd5c

View File

@ -357,19 +357,19 @@ class Parser(object):
accum.append(self.locexpr()) accum.append(self.locexpr())
return accum return accum
def locexpr(self, forward=False): def locexpr(self):
if self.scanner.token in ('on', 'off', 'word') or self.scanner.token in self.context.consts or self.scanner.on_type('integer literal'): if self.scanner.token in ('on', 'off', 'word') or self.scanner.token in self.context.consts or self.scanner.on_type('integer literal'):
return self.const() return self.const()
elif forward: else:
name = self.scanner.token name = self.scanner.token
self.scanner.scan() self.scanner.scan()
return ForwardReference(name) loc = self.context.fetch(name)
else: if loc:
loc = self.lookup(self.scanner.token) return loc
self.scanner.scan() else:
return loc return ForwardReference(name)
def indlocexpr(self, forward=False): def indlocexpr(self):
if self.scanner.consume('['): if self.scanner.consume('['):
loc = self.locexpr() loc = self.locexpr()
self.scanner.expect(']') self.scanner.expect(']')
@ -380,10 +380,10 @@ class Parser(object):
loc = self.locexpr() loc = self.locexpr()
return AddressRef(loc) return AddressRef(loc)
else: else:
return self.indexed_locexpr(forward=forward) return self.indexed_locexpr()
def indexed_locexpr(self, forward=False): def indexed_locexpr(self):
loc = self.locexpr(forward=forward) loc = self.locexpr()
if not isinstance(loc, str): if not isinstance(loc, str):
index = None index = None
if self.scanner.consume('+'): if self.scanner.consume('+'):
@ -483,7 +483,7 @@ class Parser(object):
elif self.scanner.token in ("copy",): elif self.scanner.token in ("copy",):
opcode = self.scanner.token opcode = self.scanner.token
self.scanner.scan() self.scanner.scan()
src = self.indlocexpr(forward=True) src = self.indlocexpr()
self.scanner.expect(',') self.scanner.expect(',')
dest = self.indlocexpr() dest = self.indlocexpr()
instr = SingleOp(self.scanner.line_number, opcode=opcode, dest=dest, src=src) instr = SingleOp(self.scanner.line_number, opcode=opcode, dest=dest, src=src)