1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-15 14:29:32 +00:00

Constraint sets may only contain labels, which are resolved late.

This commit is contained in:
Chris Pressey 2017-12-11 17:49:02 +00:00
parent 2a71c7e247
commit ec2e051518
2 changed files with 51 additions and 3 deletions

View File

@ -29,6 +29,8 @@ class Parser(object):
raise SyntaxError('Undefined symbol "%s"' % name)
return self.symbols[name].model
# --- grammar productions
def program(self):
defns = []
routines = []
@ -47,6 +49,19 @@ class Parser(object):
self.symbols[name] = SymEntry(routine, routine.location)
routines.append(routine)
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])
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])
return Program(defns=defns, routines=routines)
def defn(self):
@ -108,11 +123,11 @@ class Parser(object):
outputs = set()
trashes = set()
if self.scanner.consume('inputs'):
inputs = set(self.locexprs())
inputs = set(self.labels())
if self.scanner.consume('outputs'):
outputs = set(self.locexprs())
outputs = set(self.labels())
if self.scanner.consume('trashes'):
trashes = set(self.locexprs())
trashes = set(self.labels())
return (inputs, outputs, trashes)
def routine(self):
@ -137,6 +152,20 @@ class Parser(object):
location=location
)
def labels(self):
accum = []
accum.append(self.label())
while self.scanner.consume(','):
accum.append(self.label())
return accum
def label(self):
"""Like a locexpr, but does not allow literal values, and the labels do not
need to be defined yet. They will be resolved at the end of parsing."""
loc = self.scanner.token
self.scanner.scan()
return loc
def locexprs(self):
accum = []
accum.append(self.locexpr())

View File

@ -305,6 +305,25 @@ Only vectors can be decorated with constraints like that.
| }
? SyntaxError
Constraints set may only contain labels.
| vector cinv
| inputs a
| outputs 200
| trashes a, x, z, n
| @ 788
|
| routine foo {
| ld a, 0
| }
| routine main {
| with interrupts off {
| copy foo, cinv
| }
| call cinv
| }
? SyntaxError
A vector can name itself in its inputs, outputs, and trashes.
| vector cinv