git @ Cat's Eye Technologies SixtyPical / 5bad7ff
Another conversion away from self.context.fetch to self.declare. Chris Pressey 6 years ago
1 changed file(s) with 13 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
5555 self.syntax_error('Undefined symbol "{}"'.format(name))
5656 return model
5757
58 def declare(self, name, symentry):
58 def declare(self, name, symentry, static=False):
5959 if self.context.fetch(name):
6060 self.syntax_error('Symbol "%s" already declared' % name)
61 self.context.symbols[name] = symentry
61 if static:
62 self.context.statics[name] = symentry
63 else:
64 self.context.symbols[name] = symentry
65
66 def clear_statics(self):
67 self.context.statics = {}
6268
6369 # --- grammar productions
6470
285291 else:
286292 statics = self.statics()
287293
288 self.context.statics = self.compose_statics_dict(statics)
289 block = self.block()
290 self.context.statics = {}
294 self.clear_statics()
295 for defn in statics:
296 self.declare(defn.name, SymEntry(defn, defn.location), static=True)
297 block = self.block()
298 self.clear_statics()
291299
292300 addr = None
293301 location = LocationRef(type_, name)
296304 name=name, block=block, addr=addr,
297305 location=location, statics=statics
298306 )
299
300 def compose_statics_dict(self, statics):
301 c = {}
302 for defn in statics:
303 name = defn.name
304 if self.context.fetch(name):
305 self.syntax_error('Symbol "%s" already declared' % name)
306 c[name] = SymEntry(defn, defn.location)
307 return c
308307
309308 def labels(self):
310309 accum = []