From 07f7b1b892ac39597cb7e17fa95e3f52e617f5a2 Mon Sep 17 00:00:00 2001 From: yenatch Date: Mon, 2 Dec 2013 14:56:06 -0500 Subject: preprocessor: get rid of PointerLabel cruft now pretty much everything uses from_asm --- pokemontools/preprocessor.py | 46 +++----------------------------------------- 1 file changed, 3 insertions(+), 43 deletions(-) (limited to 'pokemontools/preprocessor.py') diff --git a/pokemontools/preprocessor.py b/pokemontools/preprocessor.py index f4e92b6..d6b7a43 100644 --- a/pokemontools/preprocessor.py +++ b/pokemontools/preprocessor.py @@ -604,64 +604,24 @@ class Preprocessor(object): if do_macro_sanity_check: self.check_macro_sanity(params, macro, original_line) - # used for storetext - correction = 0 output = "" index = 0 while index < len(params): - param_type = macro.param_types[index - correction] + param_type = macro.param_types[index] description = param_type["name"].strip() param_klass = param_type["class"] byte_type = param_klass.byte_type # db or dw - size = param_klass.size param = params[index].strip() - # param_klass.to_asm() won't work here because it doesn't - # include db/dw. - - # some parameters are really multiple types of bytes - if (byte_type == "dw" and size != 2) or \ - (byte_type == "db" and size != 1): - - output += ("; " + description + "\n") - - if size == 3 and is_based_on(param_klass, "PointerLabelBeforeBank"): - # write the bank first - output += ("db " + param + "\n") - # write the pointer second - output += ("dw " + params[index+1].strip() + "\n") - index += 2 - correction += 1 - elif size == 3 and is_based_on(param_klass, "PointerLabelAfterBank"): - # write the pointer first - output += ("dw " + param + "\n") - # write the bank second - output += ("db " + params[index+1].strip() + "\n") - index += 2 - correction += 1 - elif size == 3 and "from_asm" in dir(param_klass): - output += ("\t" + byte_type + " " + param_klass.from_asm(param) + "\n") - index += 1 - else: - raise exceptions.MacroException( - "dunno what to do with this macro param ({klass}) in line: {line}" - .format( - klass=param_klass, - line=original_line, - ) - ) - - elif "from_asm" in dir(param_klass): + if "from_asm" in dir(param_klass): output += ("\t" + byte_type + " " + param_klass.from_asm(param) + " ; " + description + "\n") - index += 1 - # or just print out the byte else: output += ("\t" + byte_type + " " + param + " ; " + description + "\n") - index += 1 + index += 1 sys.stdout.write(output) -- cgit v1.2.3 From a648e0a8cdc6c7d981a5641f4dc4d5b02e23e81e Mon Sep 17 00:00:00 2001 From: yenatch Date: Mon, 2 Dec 2013 15:08:19 -0500 Subject: preprocessor: remove some redundant code in macro_translator --- pokemontools/preprocessor.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'pokemontools/preprocessor.py') diff --git a/pokemontools/preprocessor.py b/pokemontools/preprocessor.py index d6b7a43..1fac44d 100644 --- a/pokemontools/preprocessor.py +++ b/pokemontools/preprocessor.py @@ -581,12 +581,6 @@ class Preprocessor(object): if show_original_lines: sys.stdout.write("; original_line: " + original_line) - # rgbasm can handle "db" so no preprocessing is required, plus this wont be - # reached because of earlier checks in macro_test. - if macro.macro_name in ["db", "dw"]: - sys.stdout.write(original_line) - return - # rgbasm can handle other macros too if "is_rgbasm_macro" in dir(macro): if macro.is_rgbasm_macro: -- cgit v1.2.3 From 3a586ef165b8022b0f5159dfdd586789f3166e70 Mon Sep 17 00:00:00 2001 From: yenatch Date: Mon, 2 Dec 2013 15:15:19 -0500 Subject: preprocessor: simplify macro_translator --- pokemontools/preprocessor.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'pokemontools/preprocessor.py') diff --git a/pokemontools/preprocessor.py b/pokemontools/preprocessor.py index 1fac44d..e032125 100644 --- a/pokemontools/preprocessor.py +++ b/pokemontools/preprocessor.py @@ -598,24 +598,18 @@ class Preprocessor(object): if do_macro_sanity_check: self.check_macro_sanity(params, macro, original_line) - output = "" - - index = 0 - while index < len(params): + for index in xrange(len(params)): param_type = macro.param_types[index] description = param_type["name"].strip() param_klass = param_type["class"] - byte_type = param_klass.byte_type # db or dw + byte_type = param_klass.byte_type param = params[index].strip() if "from_asm" in dir(param_klass): - output += ("\t" + byte_type + " " + param_klass.from_asm(param) + " ; " + description + "\n") - - else: - output += ("\t" + byte_type + " " + param + " ; " + description + "\n") + param = param_klass.from_asm(param) - index += 1 + output += ("\t" + byte_type + " " + param + " ; " + description + "\n") sys.stdout.write(output) -- cgit v1.2.3 From fef1cdd4f2d5760ce6742e40cb256296f597b836 Mon Sep 17 00:00:00 2001 From: yenatch Date: Mon, 2 Dec 2013 23:48:24 -0500 Subject: preprocessor: str.split() already removes preceding/trailing whitespace --- pokemontools/preprocessor.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'pokemontools/preprocessor.py') diff --git a/pokemontools/preprocessor.py b/pokemontools/preprocessor.py index e032125..5ac7724 100644 --- a/pokemontools/preprocessor.py +++ b/pokemontools/preprocessor.py @@ -553,29 +553,17 @@ class Preprocessor(object): original_line = line - # remove trailing newline - if line[-1] == "\n": - line = line[:-1] + has_tab = line[0] == "\t" - # remove first tab - has_tab = False - if line[0] == "\t": - has_tab = True - line = line[1:] - - # remove duplicate whitespace (also trailing) + # remove whitespace line = " ".join(line.split()) - params = [] - # check if the line has params if " " in line: # split the line into separate parameters params = line.replace(token, "").split(",") - - # check if there are no params (redundant) - if len(params) == 1 and params[0] == "": - raise exceptions.MacroException("macro has no params?") + else: + params = [] # write out a comment showing the original line if show_original_lines: -- cgit v1.2.3