diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-06-09 12:51:05 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-06-09 14:07:38 -0700 |
commit | 3781d44edc506c16c811bf921d61dcc8563e920d (patch) | |
tree | 875c60cb0e2d663972aa06e251964c2b851ef9b6 /src/modules.js | |
parent | 3cd726cc454bb50f3077d89a2f4cddf6a14632f2 (diff) |
apply library synonyms using wrapper functions, to avoid needing hacks in the compiler ; 1.19.21.19.2
Diffstat (limited to 'src/modules.js')
-rw-r--r-- | src/modules.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/modules.js b/src/modules.js index fd5c23cd..56f4c827 100644 --- a/src/modules.js +++ b/src/modules.js @@ -443,6 +443,31 @@ var LibraryManager = { } } + // apply synonyms. these are typically not speed-sensitive, and doing it this way makes it possible to not include hacks in the compiler + // (and makes it simpler to switch between SDL verisons, fastcomp and non-fastcomp, etc.). + var lib = LibraryManager.library; + libloop: for (var x in lib) { + if (x.lastIndexOf('__') > 0) continue; // ignore __deps, __* + if (lib[x + '__asm']) continue; // ignore asm library functions, those need to be fully optimized + if (typeof lib[x] === 'string') { + var target = x; + while (typeof lib[target] === 'string') { + if (lib[target].indexOf('(') >= 0) continue libloop; + target = lib[target]; + } + if (typeof lib[target] === 'undefined' || typeof lib[target] === 'function') { + if (target.indexOf('Math_') < 0) { + lib[x] = new Function('return _' + target + '.apply(null, arguments)'); + if (!lib[x + '__deps']) lib[x + '__deps'] = []; + lib[x + '__deps'].push(target); + } else { + lib[x] = new Function('return ' + target + '.apply(null, arguments)'); + } + continue; + } + } + } + /* // export code for CallHandlers.h printErr('============================'); |