make isolate_incbins not take a global asm

Why on earth was this using globals?
This commit is contained in:
Bryan Bishop
2013-08-04 15:59:16 -05:00
parent dbf6c1eedc
commit a1bfc404cb
2 changed files with 11 additions and 10 deletions

View File

@@ -6663,9 +6663,11 @@ def get_dependencies_for(some_object, recompute=False, global_dependencies=set()
print "asm is: \n\n" + to_asm(some_object)
raise e
def isolate_incbins():
def isolate_incbins(asm=None):
"find each incbin line"
global incbin_lines, asm
global incbin_lines
if asm == None:
asm = globals()["asm"]
incbin_lines = []
for line in asm:
if line == "": continue
@@ -6687,7 +6689,7 @@ def process_incbins():
load_asm()
# get a list of incbins if that hasn't happened yet
if incbin_lines == [] or incbin_lines == None:
isolate_incbins()
isolate_incbins(asm=asm)
# reset the global that this function creates
processed_incbins = {}
# for each incbin..
@@ -6728,7 +6730,7 @@ def reset_incbins():
incbin_lines = []
processed_incbins = {}
load_asm()
isolate_incbins()
isolate_incbins(asm=asm)
process_incbins()
def find_incbin_to_replace_for(address, debug=False, rom_file="../baserom.gbc"):
@@ -7340,7 +7342,7 @@ def analyze_intervals():
if asm == None:
load_asm()
if processed_incbins == {}:
isolate_incbins()
isolate_incbins(asm=asm)
process_incbins()
results = []
ordered_keys = sorted(processed_incbins, key=lambda entry: processed_incbins[entry]["interval"])

View File

@@ -445,12 +445,11 @@ class TestAsmList(unittest.TestCase):
os.system("rm " + filename)
def test_isolate_incbins(self):
global asm
asm = ["123", "456", "789", "abc", "def", "ghi",
'INCBIN "baserom.gbc",$12DA,$12F8 - $12DA',
"jkl",
'INCBIN "baserom.gbc",$137A,$13D0 - $137A']
lines = isolate_incbins()
lines = isolate_incbins(asm=asm)
self.assertIn(asm[6], lines)
self.assertIn(asm[8], lines)
for line in lines:
@@ -489,7 +488,7 @@ class TestAsmList(unittest.TestCase):
asm = ['first line', 'second line', 'third line',
'INCBIN "baserom.gbc",$90,$200 - $90',
'fifth line', 'last line']
isolate_incbins()
isolate_incbins(asm=asm)
process_incbins()
line_num = find_incbin_to_replace_for(0x100)
# must be the 4th line (the INBIN line)
@@ -504,7 +503,7 @@ class TestAsmList(unittest.TestCase):
asm = ['first line', 'second line', 'third line',
'INCBIN "baserom.gbc",$90,$200 - $90',
'fifth line', 'last line']
isolate_incbins()
isolate_incbins(asm=asm)
process_incbins()
content = split_incbin_line_into_three(3, 0x100, 10)
# must end up with three INCBINs in output
@@ -517,7 +516,7 @@ class TestAsmList(unittest.TestCase):
'INCBIN "baserom.gbc",$90,$200 - $90',
'fifth line', 'last line',
'INCBIN "baserom.gbc",$33F,$4000 - $33F']
isolate_incbins()
isolate_incbins(asm=asm)
process_incbins()
largest = analyze_intervals()
self.assertEqual(largest[0]["line_number"], 6)