aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-06-29 10:05:29 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-07-03 15:31:04 -0700
commit7596d284a0fd54be6ed9661d377dd7903a27f072 (patch)
tree813bca30f7f6358b0a7f2935c1f6c5499c8d93be /tools
parent7be8c34546c5c8db548f8b7a5864f7cbd7594ef4 (diff)
refactor invoke generation and add missing invokes when linking
Diffstat (limited to 'tools')
-rw-r--r--tools/shared.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tools/shared.py b/tools/shared.py
index 26bb55b3..3e7bac9d 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -1361,6 +1361,20 @@ class JS:
return ident.replace('%', '$').replace('@', '_')
@staticmethod
+ def make_invoke(sig, named=True):
+ args = ','.join(['a' + str(i) for i in range(1, len(sig))])
+ args = 'index' + (',' if args else '') + args
+ # C++ exceptions are numbers, and longjmp is a string 'longjmp'
+ return '''function%s(%s) {
+ try {
+ %sModule["dynCall_%s"](%s);
+ } catch(e) {
+ if (typeof e !== 'number' && e !== 'longjmp') throw e;
+ asm["setThrew"](1, 0);
+ }
+}''' % ((' invoke_' + sig) if named else '', args, 'return ' if sig[0] != 'v' else '', sig, args)
+
+ @staticmethod
def align(x, by):
while x % by != 0: x += 1
return x