Merge remote-tracking branch 'kanzure/master'

This commit is contained in:
yenatch 2013-08-31 03:56:40 -04:00
commit c6c09cf3dd
1 changed files with 17 additions and 26 deletions

View File

@ -10,7 +10,6 @@ from extras.pokemontools.crystal import (
Signpost, Signpost,
PeopleEvent, PeopleEvent,
DataByteWordMacro, DataByteWordMacro,
ItemFragment,
text_command_classes, text_command_classes,
movement_command_classes, movement_command_classes,
music_classes, music_classes,
@ -23,7 +22,6 @@ even_more_macros = [
Signpost, Signpost,
PeopleEvent, PeopleEvent,
DataByteWordMacro, DataByteWordMacro,
ItemFragment,
] ]
macros = command_classes macros = command_classes
@ -39,9 +37,6 @@ show_original_lines = False
# helpful for debugging macros # helpful for debugging macros
do_macro_sanity_check = False do_macro_sanity_check = False
class SkippableMacro(object):
macro_name = "db"
chars = { chars = {
"": 0x05, "": 0x05,
"": 0x06, "": 0x06,
@ -418,10 +413,13 @@ def macro_test(asm, macro_table):
""" """
# macros are determined by the first symbol on the line # macros are determined by the first symbol on the line
token = extract_token(asm) token = extract_token(asm)
# skip db and dw since rgbasm handles those and they aren't macros
if token not in ["db", "dw"]:
# check against all names # check against all names
if token in macro_table: if token in macro_table:
return (macro_table[token], token) return (macro_table[token], token)
else:
return (None, None) return (None, None)
def is_based_on(something, base): def is_based_on(something, base):
@ -436,7 +434,7 @@ def is_based_on(something, base):
options += [something.__name__] options += [something.__name__]
return (base in options) return (base in options)
def macro_translator(macro, token, line, skippable_macros): 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.
""" """
@ -475,10 +473,9 @@ def macro_translator(macro, token, line, skippable_macros):
if show_original_lines: if show_original_lines:
sys.stdout.write("; original_line: " + original_line) sys.stdout.write("; original_line: " + original_line)
# "db" is a macro because of SkippableMacro # rgbasm can handle "db" so no preprocessing is required, plus this wont be
# rgbasm can handle "db" so no preprocessing is required # reached because of earlier checks in macro_test.
# (don't check its param count) if macro.macro_name in ["db", "dw"]:
if macro.__name__ in skippable_macros or (macro.macro_name == "db" and macro in skippable_macros):
sys.stdout.write(original_line) sys.stdout.write(original_line)
return return
@ -584,7 +581,7 @@ def macro_translator(macro, token, line, skippable_macros):
sys.stdout.write(output) sys.stdout.write(output)
def read_line(l, skippable_macros, macro_table): def read_line(l, macro_table):
"""Preprocesses a given line of asm.""" """Preprocesses a given line of asm."""
# strip comments from asm # strip comments from asm
@ -612,21 +609,15 @@ def read_line(l, skippable_macros, macro_table):
else: else:
macro, token = macro_test(asm, macro_table) macro, token = macro_test(asm, macro_table)
if macro: if macro:
macro_translator(macro, token, asm, skippable_macros) macro_translator(macro, token, asm)
else: else:
sys.stdout.write(asm) sys.stdout.write(asm)
if comment: sys.stdout.write(comment) if comment: sys.stdout.write(comment)
def preprocess(macros, skippable_macros=None, lines=None): def preprocess(macros, lines=None):
"""Main entry point for the preprocessor.""" """Main entry point for the preprocessor."""
if skippable_macros == None: macro_table = make_macro_table(macros)
skippable_macros = [SkippableMacro]
macro_table = make_macro_table(list(set(macros + skippable_macros)))
# HACK for pokecrystal. Must be after make_macro_table call.
skippable_macros += ["TextEndingCommand"]
if not lines: if not lines:
# read each line from stdin # read each line from stdin
@ -636,7 +627,7 @@ def preprocess(macros, skippable_macros=None, lines=None):
lines = lines.split("\n") lines = lines.split("\n")
for l in lines: for l in lines:
read_line(l, skippable_macros, macro_table) read_line(l, macro_table)
# only run against stdin when not included as a module # only run against stdin when not included as a module
if __name__ == "__main__": if __name__ == "__main__":