git @ Cat's Eye Technologies SixtyPical / ec2e051
Constraint sets may only contain labels, which are resolved late. Chris Pressey 3 years ago
2 changed file(s) with 51 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
2727 if name not in self.symbols:
2828 raise SyntaxError('Undefined symbol "%s"' % name)
2929 return self.symbols[name].model
30
31 # --- grammar productions
3032
3133 def program(self):
3234 defns = []
4648 self.symbols[name] = SymEntry(routine, routine.location)
4749 routines.append(routine)
4850 self.scanner.check_type('EOF')
51 # now backpatch the executable types.
52 for defn in defns:
53 if isinstance(defn.location.type, VectorType):
54 t = defn.location.type
55 t.inputs = set([self.lookup(w) for w in t.inputs])
56 t.outputs = set([self.lookup(w) for w in t.outputs])
57 t.trashes = set([self.lookup(w) for w in t.trashes])
58 for routine in routines:
59 if isinstance(routine.location.type, ExecutableType):
60 t = routine.location.type
61 t.inputs = set([self.lookup(w) for w in t.inputs])
62 t.outputs = set([self.lookup(w) for w in t.outputs])
63 t.trashes = set([self.lookup(w) for w in t.trashes])
4964 return Program(defns=defns, routines=routines)
5065
5166 def defn(self):
107122 outputs = set()
108123 trashes = set()
109124 if self.scanner.consume('inputs'):
110 inputs = set(self.locexprs())
125 inputs = set(self.labels())
111126 if self.scanner.consume('outputs'):
112 outputs = set(self.locexprs())
127 outputs = set(self.labels())
113128 if self.scanner.consume('trashes'):
114 trashes = set(self.locexprs())
129 trashes = set(self.labels())
115130 return (inputs, outputs, trashes)
116131
117132 def routine(self):
135150 name=name, block=block, addr=addr,
136151 location=location
137152 )
153
154 def labels(self):
155 accum = []
156 accum.append(self.label())
157 while self.scanner.consume(','):
158 accum.append(self.label())
159 return accum
160
161 def label(self):
162 """Like a locexpr, but does not allow literal values, and the labels do not
163 need to be defined yet. They will be resolved at the end of parsing."""
164 loc = self.scanner.token
165 self.scanner.scan()
166 return loc
138167
139168 def locexprs(self):
140169 accum = []
304304 | }
305305 ? SyntaxError
306306
307 Constraints set may only contain labels.
308
309 | vector cinv
310 | inputs a
311 | outputs 200
312 | trashes a, x, z, n
313 | @ 788
314 |
315 | routine foo {
316 | ld a, 0
317 | }
318 | routine main {
319 | with interrupts off {
320 | copy foo, cinv
321 | }
322 | call cinv
323 | }
324 ? SyntaxError
325
307326 A vector can name itself in its inputs, outputs, and trashes.
308327
309328 | vector cinv