aboutsummaryrefslogtreecommitdiff
path: root/emlink.py
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-07-01 13:03:51 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-07-03 15:31:05 -0700
commitf4adccef1ae92a6da54d9c29a84fe64758f76201 (patch)
tree689beb50782d495e320c3c38b58eb19c6ebb6949 /emlink.py
parent4f9dfa2025f92130036dc7ca83ea91ebc8275e89 (diff)
refactor sendings linking
Diffstat (limited to 'emlink.py')
-rw-r--r--emlink.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/emlink.py b/emlink.py
index 92af957e..d5b5cdf7 100644
--- a/emlink.py
+++ b/emlink.py
@@ -104,7 +104,10 @@ class AsmModule():
# post
self.post_js = self.js[self.end_asm:]
- self.sendings = set([sending.strip() for sending in self.post_js[self.post_js.find('}, { ')+5:self.post_js.find(' }, buffer);')].split(',')])
+ self.sendings = {}
+ for sending in [sending.strip() for sending in self.post_js[self.post_js.find('}, { ')+5:self.post_js.find(' }, buffer);')].split(',')]:
+ colon = sending.find(':')
+ self.sendings[sending[:colon].replace('"', '')] = sending[colon+1:].strip()
self.module_defs = set(re.findall('var [\w\d_$]+ = Module\["[\w\d_$]+"\] = asm\["[\w\d_$]+"\];\n', self.post_js))
def relocate_into(self, main):
@@ -124,17 +127,19 @@ class AsmModule():
#print >> sys.stderr, 'replacements:', replacements
# imports
- new_imports = ['var %s = %s;' % (imp, self.imports[imp]) for imp in self.imports if imp not in main.imports and imp not in main_funcs]
- main.imports_js += '\n'.join(new_imports) + '\n'
+ new_imports = [imp for imp in self.imports if imp not in main.imports and imp not in main_funcs]
+ main.imports_js += '\n'.join(['var %s = %s;' % (imp, self.imports[imp]) for imp in new_imports]) + '\n'
# sendings: add invokes for new tables
- new_sendings = []
+ all_sendings = main.sendings
+ added_sending = False
for table in self.tables:
if table not in main.tables:
sig = table[table.rfind('_')+1:]
- new_sendings.append('"invoke_%s": %s' % (sig, shared.JS.make_invoke(sig, named=False)))
- if new_sendings:
- sendings_js = ', '.join(main.sendings.union(new_sendings))
+ all_sendings['invoke_%s' % sig] = shared.JS.make_invoke(sig, named=False)
+ added_sending = True
+ if added_sending:
+ sendings_js = ', '.join(['%s: %s' % (key, value) for key, value in all_sendings.iteritems()])
sendings_start = main.post_js.find('}, { ')+5
sendings_end = main.post_js.find(' }, buffer);')
main.post_js = main.post_js[:sendings_start] + sendings_js + main.post_js[sendings_end:]