1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-25 23:49:17 +00:00

Another conversion away from self.context.fetch to self.declare.

This commit is contained in:
Chris Pressey 2018-09-07 12:43:55 +01:00
parent c73590f88c
commit 5bad7ff576

View File

@ -56,10 +56,16 @@ class Parser(object):
self.syntax_error('Undefined symbol "{}"'.format(name))
return model
def declare(self, name, symentry):
def declare(self, name, symentry, static=False):
if self.context.fetch(name):
self.syntax_error('Symbol "%s" already declared' % name)
self.context.symbols[name] = symentry
if static:
self.context.statics[name] = symentry
else:
self.context.symbols[name] = symentry
def clear_statics(self):
self.context.statics = {}
# --- grammar productions
@ -286,9 +292,11 @@ class Parser(object):
else:
statics = self.statics()
self.context.statics = self.compose_statics_dict(statics)
self.clear_statics()
for defn in statics:
self.declare(defn.name, SymEntry(defn, defn.location), static=True)
block = self.block()
self.context.statics = {}
self.clear_statics()
addr = None
location = LocationRef(type_, name)
@ -298,15 +306,6 @@ class Parser(object):
location=location, statics=statics
)
def compose_statics_dict(self, statics):
c = {}
for defn in statics:
name = defn.name
if self.context.fetch(name):
self.syntax_error('Symbol "%s" already declared' % name)
c[name] = SymEntry(defn, defn.location)
return c
def labels(self):
accum = []
accum.append(self.label())