diff options
-rw-r--r-- | src/jsifier.js | 6 | ||||
-rw-r--r-- | src/library.js | 7 | ||||
-rw-r--r-- | src/parseTools.js | 11 | ||||
-rw-r--r-- | src/preamble.js | 13 | ||||
-rw-r--r-- | tests/runner.py | 15 |
5 files changed, 43 insertions, 9 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index d4f3be66..9621bb8e 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -264,7 +264,11 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { } else { ident = '_' + ident; } - return (deps ? '\n' + deps.map(addFromLibrary).join('\n') : '') + 'var ' + ident + '=' + snippet + ';'; + var text = (deps ? '\n' + deps.map(addFromLibrary).join('\n') : '') + 'var ' + ident + '=' + snippet + ';'; + if (ident in EXPORTED_FUNCTIONS) { + text += '\nModule["' + ident + '"] = ' + ident + ';'; + } + return text; } item.JS = addFromLibrary(shortident); } else { diff --git a/src/library.js b/src/library.js index d2e13273..083bf29c 100644 --- a/src/library.js +++ b/src/library.js @@ -599,7 +599,7 @@ var Library = { return ret; }, - abs: 'Math.abs', + abs: 'Math.abs', // XXX should be integer? atoi: function(s) { return Math.floor(Number(Pointer_stringify(s))); @@ -1375,11 +1375,6 @@ var Library = { return 0; // NULL }, - unlink: function(filename) { - // TODO: Actually implement. - return 0; - }, - // time.h time: function(ptr) { diff --git a/src/parseTools.js b/src/parseTools.js index e307a710..39537ab2 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -692,7 +692,7 @@ function makeGetValue(ptr, pos, type, noNeedFirst, unsigned) { } } -function indexizeFunctions(value) { // TODO: Also check for externals +function indexizeFunctions(value) { if (value in Functions.currFunctions) { if (BUILD_AS_SHARED_LIB) { return '(FUNCTION_TABLE_OFFSET + ' + Functions.getIndex(value) + ')'; @@ -702,8 +702,15 @@ function indexizeFunctions(value) { // TODO: Also check for externals } if (value && value[0] && value[0] == '_') { var rootIdent = LibraryManager.getRootIdent(value.slice(1)); - if (rootIdent && typeof Library[rootIdent] === 'function') { + if (!rootIdent) return value; + if (typeof Library[rootIdent] === 'function') { return Functions.getIndex('_' + rootIdent); + } else if (rootIdent.substr(0, 5) === 'Math.') { + // Library[..] can be a string, in which case we apply that string. There is one + // case where this can be a function: Math.*, since we try to optimize those as much + // as possible. In other words, we don't want to have a wrapper function(x) return Math.sqrt(x). + // If other functions are deemed important as well, we will need to add them here. + return Functions.getIndex(rootIdent); } } return value; diff --git a/src/preamble.js b/src/preamble.js index c6fcafa7..8ee543a7 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -455,6 +455,19 @@ for (var i = 0; i < base.length; i++) { } Module['HEAP'] = HEAP; +#if USE_TYPED_ARRAYS == 1 +Module['IHEAP'] = IHEAP; +Module['FHEAP'] = FHEAP; +#endif +#if USE_TYPED_ARRAYS == 2 +Module['HEAP8'] = HEAP8; +Module['HEAP16'] = HEAP16; +Module['HEAP32'] = HEAP32; +Module['HEAPU8'] = HEAPU8; +Module['HEAPU16'] = HEAPU16; +Module['HEAPU32'] = HEAPU32; +Module['HEAPF32'] = HEAPF32; +#endif STACK_ROOT = STACKTOP = alignMemoryPage(10); var TOTAL_STACK = 1024*1024; // XXX: Changing this value can lead to bad perf on v8! diff --git a/tests/runner.py b/tests/runner.py index 59062302..4215bfea 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -1097,6 +1097,21 @@ if 'benchmark' not in sys.argv: ''' self.do_test(src, '*26,26,90,90,26,90*\n*1,0,0,1*\n*goodbye!*') + def test_mathfuncptr(self): + src = ''' + #include <math.h> + #include <stdio.h> + + int + main(void) { + float (*fn)(float) = &sqrtf; + float (*fn2)(float) = &fabsf; + printf("fn2(-5) = %d, fn(10) = %f\\n", (int)fn2(-5), fn(10)); + return 0; + } + ''' + self.do_test(src, 'fn2(-5) = 5, fn(10) = 3.16') + def test_emptyclass(self): src = ''' #include <stdio.h> |