diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-07-01 13:03:51 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-07-03 15:31:05 -0700 |
commit | f4adccef1ae92a6da54d9c29a84fe64758f76201 (patch) | |
tree | 689beb50782d495e320c3c38b58eb19c6ebb6949 /emlink.py | |
parent | 4f9dfa2025f92130036dc7ca83ea91ebc8275e89 (diff) |
refactor sendings linking
Diffstat (limited to 'emlink.py')
-rw-r--r-- | emlink.py | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -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:] |