diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-12-08 18:33:43 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-12-08 18:33:43 -0800 |
commit | 093ebe033d9bc906babb1a3511e2a4638b58d6a0 (patch) | |
tree | 3f69c8ecb0c07306e83cc4a89dfa741058153083 /src/modules.js | |
parent | 5a74e784b2feac3268dedd17d425a26b0437452d (diff) |
properly resolve multilevel function aliases, fixes bug with adding indexing for aliases. also optimize function indexing in compiler
Diffstat (limited to 'src/modules.js')
-rw-r--r-- | src/modules.js | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/modules.js b/src/modules.js index 3ce4a541..49f93e61 100644 --- a/src/modules.js +++ b/src/modules.js @@ -254,22 +254,37 @@ var Functions = { // All the function idents seen so far allIdents: [], - indexedFunctions: [0, 0], // Start at a non-0 (even, see below) value + indexedFunctions: {}, + nextIndex: 2, // Start at a non-0 (even, see below) value // Mark a function as needing indexing, and returns the index getIndex: function(ident) { - var key = this.indexedFunctions.indexOf(ident); - if (key < 0) { - key = this.indexedFunctions.length; - this.indexedFunctions[key] = ident; - this.indexedFunctions[key+1] = 0; // Need to have keys be even numbers, see |polymorph| test + var ret = this.indexedFunctions[ident]; + if (!ret) { + ret = this.nextIndex; + this.nextIndex += 2; // Need to have indexes be even numbers, see |polymorph| test + this.indexedFunctions[ident] = ret; } - return key.toString(); + return ret.toString(); }, // Generate code for function indexing generateIndexing: function() { - var indices = this.indexedFunctions.toString().replace('"', ''); + var vals = zeros(this.nextIndex); + for (var ident in this.indexedFunctions) { + vals[this.indexedFunctions[ident]] = ident; + } + + // Resolve multi-level aliases all the way down + for (var i = 0; i < vals.length; i++) { + while (1) { + var varData = Variables.globals[vals[i]]; + if (!(varData && varData.resolvedAlias)) break; + vals[i] = vals[varData.resolvedAlias]; + } + } + + var indices = vals.toString().replace('"', ''); if (BUILD_AS_SHARED_LIB) { // Shared libraries reuse the parent's function table. return 'FUNCTION_TABLE = FUNCTION_TABLE.concat([' + indices + ']);'; |