summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2012-04-21 02:43:19 -0500
committerBryan Bishop <kanzure@gmail.com>2012-04-21 02:43:19 -0500
commit126510e975f2e97c9551e12b7c2f983163ecc042 (patch)
treef7d45ca5dd007756dec32364563593e65eb9730f
parentc8dd923e7ebf53efc95779284b0a163b68a08fec (diff)
flatten a list of dependencies into one giant list
original-commit-id: 7d6af535e9395a48e9e97b0c2a0741239c41f165
-rw-r--r--crystal.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/crystal.py b/crystal.py
index caa5158..4ab9095 100644
--- a/crystal.py
+++ b/crystal.py
@@ -4204,6 +4204,21 @@ def to_asm(some_object):
asm += "\n; " + hex(last_address)
return asm
+def flattener(x):
+ "flattens a list of sublists into just one list (generator)"
+ try:
+ it = iter(x)
+ except TypeError:
+ yield x
+ else:
+ for i in it:
+ for j in flattener(i):
+ yield j
+
+def flatten(x):
+ "flattens a list of sublists into just one list"
+ return list(flattener(x))
+
def get_dependencies_for(some_object):
"""
calculates which labels need to be satisfied for an object
@@ -4215,7 +4230,8 @@ def get_dependencies_for(some_object):
"""
if isinstance(some_object, int):
some_object = script_parse_table[some_object]
- return some_object.get_dependencies()
+ deps = some_object.get_dependencies()
+ return list(flatten(deps))
def isolate_incbins():
"find each incbin line"