make the preprocessor a little faster

This reduced the preprocessing time from 8s to 2.7s.
This commit is contained in:
Bryan Bishop 2013-01-10 15:15:59 -06:00
parent 3f95529102
commit f2fd544e20

View File

@ -393,6 +393,10 @@ def extract_token(asm):
token = asm.split(" ")[0].replace("\t", "").replace("\n", "") token = asm.split(" ")[0].replace("\t", "").replace("\n", "")
return token return token
def make_macro_table():
return dict([(macro.macro_name, macro) for macro in macros])
macro_table = make_macro_table()
def macro_test(asm): def macro_test(asm):
""" Returns a matching macro, or None/False. """ Returns a matching macro, or None/False.
""" """
@ -401,11 +405,10 @@ def macro_test(asm):
token = extract_token(asm) token = extract_token(asm)
# check against all names # check against all names
for macro in macros: try:
if macro.macro_name == token: return (macro_table[token], token)
return macro, token except:
return (None, None)
return None, None
def macro_translator(macro, token, line): def macro_translator(macro, token, line):
""" Converts a line with a macro into a rgbasm-compatible line. """ Converts a line with a macro into a rgbasm-compatible line.