def __init__(self):
self.is_microop = False
self.is_directive = False
+ self.params = ""
class Microop(Statement):
def __init__(self):
self.mnemonic = ""
self.labels = []
self.is_microop = True
- self.params = ""
class Directive(Statement):
def __init__(self):
raise
elif statement.is_directive:
try:
- eval('container.%s()' % statement.name)
+ eval('container.directives[statement.name](%s)' % statement.params)
except:
print_error("Error executing directive.")
print container.directives
label.text = t[2]
t[0] = label
-def p_directive(t):
+def p_directive_0(t):
'directive : DOT ID'
directive = Directive()
directive.name = t[2]
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
# *token*, not a grammar symbol (hence the need to use t.value)
def p_error(t):
microops["bah"] = Bah_Tweaked
def untweak(self):
microops["bah"] = Bah
+ def print_debug(self, message):
+ print message
def __init__(self, name):
super(TestMacroop, self).__init__(name)
self.directives = {
"tweak": self.tweak,
- "untweak": self.untweak
+ "untweak": self.untweak,
+ "print": self.print_debug
}
assembler = MicroAssembler(TestMacroop, microops, Rom('main ROM'))
.tweak
bah
.untweak
+ .print "In the midst"
bah
dah # single line comment after something
.tweak