Make directives take parameters and use the directive function and not it's name

--HG--
extra : convert_revision : fbc93ba592b0cc009696e8d7edead841ec2ea01c
This commit is contained in:
Gabe Black 2007-05-31 20:45:06 +00:00
parent ace2890f9f
commit d24a9c7d21
2 changed files with 15 additions and 4 deletions

View file

@ -91,6 +91,7 @@ class Statement(object):
def __init__(self): def __init__(self):
self.is_microop = False self.is_microop = False
self.is_directive = False self.is_directive = False
self.params = ""
class Microop(Statement): class Microop(Statement):
def __init__(self): def __init__(self):
@ -98,7 +99,6 @@ class Microop(Statement):
self.mnemonic = "" self.mnemonic = ""
self.labels = [] self.labels = []
self.is_microop = True self.is_microop = True
self.params = ""
class Directive(Statement): class Directive(Statement):
def __init__(self): def __init__(self):
@ -136,7 +136,7 @@ def handle_statement(parser, container, statement):
raise raise
elif statement.is_directive: elif statement.is_directive:
try: try:
eval('container.%s()' % statement.name) eval('container.directives[statement.name](%s)' % statement.params)
except: except:
print_error("Error executing directive.") print_error("Error executing directive.")
print container.directives print container.directives
@ -415,12 +415,19 @@ def p_label_1(t):
label.text = t[2] label.text = t[2]
t[0] = label t[0] = label
def p_directive(t): def p_directive_0(t):
'directive : DOT ID' 'directive : DOT ID'
directive = Directive() directive = Directive()
directive.name = t[2] directive.name = t[2]
t[0] = directive t[0] = directive
def p_directive_1(t):
'directive : DOT ID PARAMS'
directive = Directive()
directive.name = t[2]
directive.params = t[3]
t[0] = directive
# Parse error handler. Note that the argument here is the offending # Parse error handler. Note that the argument here is the offending
# *token*, not a grammar symbol (hence the need to use t.value) # *token*, not a grammar symbol (hence the need to use t.value)
def p_error(t): def p_error(t):

View file

@ -57,12 +57,15 @@ class TestMacroop(Macroop):
microops["bah"] = Bah_Tweaked microops["bah"] = Bah_Tweaked
def untweak(self): def untweak(self):
microops["bah"] = Bah microops["bah"] = Bah
def print_debug(self, message):
print message
def __init__(self, name): def __init__(self, name):
super(TestMacroop, self).__init__(name) super(TestMacroop, self).__init__(name)
self.directives = { self.directives = {
"tweak": self.tweak, "tweak": self.tweak,
"untweak": self.untweak "untweak": self.untweak,
"print": self.print_debug
} }
assembler = MicroAssembler(TestMacroop, microops, Rom('main ROM')) assembler = MicroAssembler(TestMacroop, microops, Rom('main ROM'))
@ -82,6 +85,7 @@ def macroop squishy {
.tweak .tweak
bah bah
.untweak .untweak
.print "In the midst"
bah bah
dah # single line comment after something dah # single line comment after something
.tweak .tweak