aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--emlink.py11
-rwxr-xr-xtests/runner.py4
-rw-r--r--tools/js_optimizer.py2
3 files changed, 10 insertions, 7 deletions
diff --git a/emlink.py b/emlink.py
index 7feb989a..92af957e 100644
--- a/emlink.py
+++ b/emlink.py
@@ -83,8 +83,11 @@ class AsmModule():
# imports
self.imports_js = self.js[self.start_asm:self.start_funcs]
- self.imports = [m.group(0) for m in js_optimizer.import_sig.finditer(self.imports_js)]
- #print 'imports', self.imports
+ self.imports = {}
+ for imp in js_optimizer.import_sig.finditer(self.imports_js):
+ key, value = imp.group(0).split('var ')[1][:-1].replace(' ', '').split('=')
+ self.imports[key] = value
+ #print >> sys.stderr, 'imports', self.imports
# funcs
self.funcs_js = self.js[self.start_funcs:self.end_funcs]
@@ -121,9 +124,7 @@ class AsmModule():
#print >> sys.stderr, 'replacements:', replacements
# imports
- main_imports = set(main.imports)
- new_imports = [imp for imp in self.imports if imp not in main_imports and
- imp.split('var ')[1].split('=')[0] not in main_funcs] # a previous import may now be implemented # TODO: reverse
+ 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'
# sendings: add invokes for new tables
diff --git a/tests/runner.py b/tests/runner.py
index b0d86c6a..5737a298 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -10624,7 +10624,9 @@ f.close()
out = run_js('together.js', engine=SPIDERMONKEY_ENGINE, stderr=PIPE, full_output=True)
self.assertContained(expected, out)
self.validate_asmjs(out)
- if first: test(name + ' (reverse)', header, side, main, expected, False) # test reverse order
+ if first:
+ shutil.copyfile('together.js', 'first.js')
+ test(name + ' (reverse)', header, side, main, expected, False) # test reverse order
# test a simple call from one module to another. only one has a string (and constant memory initialization for it)
test('basics', '', '''
diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py
index e7e48c41..f28ca02d 100644
--- a/tools/js_optimizer.py
+++ b/tools/js_optimizer.py
@@ -19,7 +19,7 @@ WINDOWS = sys.platform.startswith('win')
DEBUG = os.environ.get('EMCC_DEBUG')
-import_sig = re.compile('( *)var ([_\w$]+) *=.*;')
+import_sig = re.compile('var ([_\w$]+) *=[^,;]+;')
func_sig = re.compile('( *)function ([_\w$]+)\(')
class Minifier: