mirror of
https://github.com/catseye/SixtyPical.git
synced 2024-12-01 16:50:09 +00:00
Another conversion away from self.context.fetch to self.declare.
This commit is contained in:
parent
c73590f88c
commit
5bad7ff576
@ -56,10 +56,16 @@ class Parser(object):
|
|||||||
self.syntax_error('Undefined symbol "{}"'.format(name))
|
self.syntax_error('Undefined symbol "{}"'.format(name))
|
||||||
return model
|
return model
|
||||||
|
|
||||||
def declare(self, name, symentry):
|
def declare(self, name, symentry, static=False):
|
||||||
if self.context.fetch(name):
|
if self.context.fetch(name):
|
||||||
self.syntax_error('Symbol "%s" already declared' % 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
|
# --- grammar productions
|
||||||
|
|
||||||
@ -286,9 +292,11 @@ class Parser(object):
|
|||||||
else:
|
else:
|
||||||
statics = self.statics()
|
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()
|
block = self.block()
|
||||||
self.context.statics = {}
|
self.clear_statics()
|
||||||
|
|
||||||
addr = None
|
addr = None
|
||||||
location = LocationRef(type_, name)
|
location = LocationRef(type_, name)
|
||||||
@ -298,15 +306,6 @@ class Parser(object):
|
|||||||
location=location, statics=statics
|
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):
|
def labels(self):
|
||||||
accum = []
|
accum = []
|
||||||
accum.append(self.label())
|
accum.append(self.label())
|
||||||
|
Loading…
Reference in New Issue
Block a user