ref: b602cc9bd649e9b8283643acaf3946a186dfad69
parent: d46d1901c2214505ceab544c8f62555b3608deed
author: Bryan Bishop <[email protected]>
date: Wed Aug 28 12:48:29 EDT 2013
don't directly reference two macro classes Ideally the macro classes will be removed from the preprocessor core soon, there's no reason they should be infecting these functions.
--- a/preprocessor.py
+++ b/preprocessor.py
@@ -425,6 +425,18 @@
else:
return (None, None)
+def is_based_on(something, base):
+ """
+ Checks whether or not 'something' is a class that is a subclass of a class
+ by name. This is a terrible hack but it removes a direct dependency on
+ existing macros.
+
+ Used by macro_translator.
+ """
+ options = [str(klass.__name__) for klass in something.__bases__]
+ options += [something.__name__]
+ return (base in options)
+
def macro_translator(macro, token, line):
"""
Converts a line with a macro into a rgbasm-compatible line.
@@ -540,7 +552,7 @@
output += ("; " + description + "\n")
- if size == 3 and issubclass(param_klass, PointerLabelBeforeBank):
+ if size == 3 and is_based_on(param_klass, "PointerLabelBeforeBank"):
# write the bank first
output += ("db " + param + "\n")
# write the pointer second
@@ -547,7 +559,7 @@
output += ("dw " + params[index+1].strip() + "\n")
index += 2
correction += 1
- elif size == 3 and issubclass(param_klass, PointerLabelAfterBank):
+ elif size == 3 and is_based_on(param_klass, "PointerLabelAfterBank"):
# write the pointer first
output += ("dw " + param + "\n")
# write the bank second