diff options
-rw-r--r-- | src/jsifier.js | 2 | ||||
-rw-r--r-- | src/modules.js | 11 | ||||
-rw-r--r-- | src/parseTools.js | 12 |
3 files changed, 13 insertions, 12 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 7072c9c8..c0f42ceb 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1525,7 +1525,7 @@ function JSify(data, functionsOnly, givenFunctions) { // This is a call through an invoke_*, either a forced one, or a setjmp-required one // note: no need to update argsTypes at this point if (byPointerForced) Functions.unimplementedFunctions[callIdent] = sig; - args.unshift(byPointerForced ? Functions.getIndex(callIdent) : asmCoercion(callIdent, 'i32')); + args.unshift(byPointerForced ? Functions.getIndex(callIdent, undefined, sig) : asmCoercion(callIdent, 'i32')); callIdent = 'invoke_' + sig; } } else if (SAFE_DYNCALLS) { diff --git a/src/modules.js b/src/modules.js index e04304fa..cf5be093 100644 --- a/src/modules.js +++ b/src/modules.js @@ -264,20 +264,25 @@ var Functions = { if (!Functions.getIndex.tentative) Functions.getIndex.tentative = {}; // only used by GL emulation; TODO: generalize when needed Functions.getIndex.tentative[ident] = 0; } + var ret; if (phase != 'post' && singlePhase) { if (!doNotCreate) this.indexedFunctions[ident] = 0; // tell python we need this indexized - return "'{{ FI_" + toNiceIdent(ident) + " }}'"; // something python will replace later + ret = "'{{ FI_" + toNiceIdent(ident) + " }}'"; // something python will replace later } else { if (!singlePhase) return 'NO_INDEX'; // Should not index functions in post - var ret = this.indexedFunctions[ident]; + ret = this.indexedFunctions[ident]; if (!ret) { if (doNotCreate) return '0'; ret = this.nextIndex; this.nextIndex += 2; // Need to have indexes be even numbers, see |polymorph| test this.indexedFunctions[ident] = ret; } - return ret.toString(); + ret = ret.toString(); } + if (BUILD_AS_SHARED_LIB) { + ret = '(FUNCTION_TABLE_OFFSET + ' + ret + ')'; + } + return ret; }, getTable: function(sig) { diff --git a/src/parseTools.js b/src/parseTools.js index 2b143697..68f61fa0 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -1229,15 +1229,11 @@ function indexizeFunctions(value, type) { var out = {}; if (type && isFunctionType(type, out) && value[0] === '_') { // checking for _ differentiates from $ (local vars) // add signature to library functions that we now know need indexing - if (!(value in Functions.implementedFunctions) && !(value in Functions.unimplementedFunctions)) { - Functions.unimplementedFunctions[value] = Functions.getSignature(out.returnType, out.segments ? out.segments.map(function(segment) { return segment[0].text }) : []); - } - - if (BUILD_AS_SHARED_LIB) { - return '(FUNCTION_TABLE_OFFSET + ' + Functions.getIndex(value) + ')'; - } else { - return Functions.getIndex(value); + var sig = Functions.implementedFunctions[value] || Functions.unimplementedFunctions[value]; + if (!sig) { + sig = Functions.unimplementedFunctions[value] = Functions.getSignature(out.returnType, out.segments ? out.segments.map(function(segment) { return segment[0].text }) : []); } + return Functions.getIndex(value, undefined, sig); } return value; } |