mirror of https://github.com/pret/pokecrystal.git
use generic skippable macros in preprocessor
This removes TextEndingCommand from the preprocessor. Instead, there is a generic concept of a skippable type of macro like "db". This adds SkippableMacro to the preprocessor.
This commit is contained in:
parent
b602cc9bd6
commit
16bfc01124
|
@ -13,7 +13,6 @@ from extras.pokemontools.crystal import (
|
||||||
PointerLabelBeforeBank,
|
PointerLabelBeforeBank,
|
||||||
PointerLabelAfterBank,
|
PointerLabelAfterBank,
|
||||||
ItemFragment,
|
ItemFragment,
|
||||||
TextEndingCommand,
|
|
||||||
text_command_classes,
|
text_command_classes,
|
||||||
movement_command_classes,
|
movement_command_classes,
|
||||||
music_classes,
|
music_classes,
|
||||||
|
@ -42,6 +41,13 @@ 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"
|
||||||
|
|
||||||
|
skippable_macros = [SkippableMacro]
|
||||||
|
|
||||||
|
macros += skippable_macros
|
||||||
|
|
||||||
chars = {
|
chars = {
|
||||||
"ガ": 0x05,
|
"ガ": 0x05,
|
||||||
"ギ": 0x06,
|
"ギ": 0x06,
|
||||||
|
@ -437,7 +443,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):
|
def macro_translator(macro, token, line, skippable_macros):
|
||||||
"""
|
"""
|
||||||
Converts a line with a macro into a rgbasm-compatible line.
|
Converts a line with a macro into a rgbasm-compatible line.
|
||||||
"""
|
"""
|
||||||
|
@ -476,10 +482,10 @@ def macro_translator(macro, token, line):
|
||||||
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 TextEndingCommand
|
# "db" is a macro because of SkippableMacro
|
||||||
# rgbasm can handle "db" so no preprocessing is required
|
# rgbasm can handle "db" so no preprocessing is required
|
||||||
# (don't check its param count)
|
# (don't check its param count)
|
||||||
if macro.macro_name == "db" and macro in [TextEndingCommand, ItemFragment]:
|
if macro.macro_name == "db" and macro in skippable_macros:
|
||||||
sys.stdout.write(original_line)
|
sys.stdout.write(original_line)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -582,7 +588,7 @@ def macro_translator(macro, token, line):
|
||||||
|
|
||||||
sys.stdout.write(output)
|
sys.stdout.write(output)
|
||||||
|
|
||||||
def read_line(l):
|
def read_line(l, skippable_macros):
|
||||||
"""Preprocesses a given line of asm."""
|
"""Preprocesses a given line of asm."""
|
||||||
|
|
||||||
# strip comments from asm
|
# strip comments from asm
|
||||||
|
@ -610,14 +616,18 @@ def read_line(l):
|
||||||
else:
|
else:
|
||||||
macro, token = macro_test(asm)
|
macro, token = macro_test(asm)
|
||||||
if macro:
|
if macro:
|
||||||
macro_translator(macro, token, asm)
|
macro_translator(macro, token, asm, skippable_macros)
|
||||||
else:
|
else:
|
||||||
sys.stdout.write(asm)
|
sys.stdout.write(asm)
|
||||||
|
|
||||||
if comment: sys.stdout.write(comment)
|
if comment: sys.stdout.write(comment)
|
||||||
|
|
||||||
def preprocess(lines=None):
|
def preprocess(skippable_macros=None, lines=None):
|
||||||
"""Main entry point for the preprocessor."""
|
"""Main entry point for the preprocessor."""
|
||||||
|
if skippable_macros == None:
|
||||||
|
# Note that this is bad because the macro table doesn't include the
|
||||||
|
# skippable macros.
|
||||||
|
skippable_macros = [SkippableMacro]
|
||||||
|
|
||||||
if not lines:
|
if not lines:
|
||||||
# read each line from stdin
|
# read each line from stdin
|
||||||
|
@ -627,8 +637,8 @@ def preprocess(lines=None):
|
||||||
lines = lines.split("\n")
|
lines = lines.split("\n")
|
||||||
|
|
||||||
for l in lines:
|
for l in lines:
|
||||||
read_line(l)
|
read_line(l, skippable_macros)
|
||||||
|
|
||||||
# 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__":
|
||||||
preprocess()
|
preprocess(skippable_macros=skippable_macros)
|
||||||
|
|
Loading…
Reference in New Issue