diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-03-21 19:48:26 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-03-21 19:48:26 -0700 |
commit | 24856d20699818b35f01963e4144c87d1a5c56ff (patch) | |
tree | ade6915ad86dedcc646eec29bcca845d5bf90212 /src/modules.js | |
parent | 98f6e8924d27246f40f50ec3f75084f1f04b6459 (diff) |
optimize FUNCTION_POINTER and exporting
Diffstat (limited to 'src/modules.js')
-rw-r--r-- | src/modules.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/modules.js b/src/modules.js index 4d225057..804de24a 100644 --- a/src/modules.js +++ b/src/modules.js @@ -114,3 +114,23 @@ var Types = { needAnalysis: {} // Types noticed during parsing, that need analysis }; +var Functions = { + indexedFunctions: [0, 0], // 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 + } + return key.toString(); + }, + + // Generate code for function indexing + generateIndexing: function() { + return 'var FUNCTION_TABLE = [' + this.indexedFunctions.toString().replace('"', '') + '];'; + } +}; + |