diff options
author | alon@honor <none@none> | 2010-10-31 15:50:56 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-10-31 15:50:56 -0700 |
commit | db2dfd4026c5aaba0a4b1fc2778b1ca36bec8a62 (patch) | |
tree | eeffd846e36469148e66c7e1b58cfc8a19ca1248 /src/jsifier.js | |
parent | 9343f81a117efd605ff274fd290d38d674c55d25 (diff) |
remove getters from global vars
Diffstat (limited to 'src/jsifier.js')
-rw-r--r-- | src/jsifier.js | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index f140cecc..2f79b18c 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -173,10 +173,11 @@ function JSify(data) { } } - // globalVariablw + // globalVariable substrate.addZyme('GlobalVariable', { processItem: function(item) { - dprint('gconst', '// zz global Cons: ' + dump(item) + ' :: ' + dump(item.value)); + item.intertype = 'GlobalVariableStub'; + item.__result__ = true; if (item.ident == '_llvm_global_ctors') { item.JS = '\n__globalConstructor__ = function() {\n' + item.ctors.map(function(ctor) { return ' ' + toNiceIdent(ctor) + '();' }).join('\n') + @@ -184,10 +185,13 @@ function JSify(data) { } else if (item.type == 'external') { item.JS = 'var ' + item.ident + ' = ' + '0; /* external value? */'; } else { - // GETTER - lazy loading, fixes issues with ordering. - item.JS = 'this.__defineGetter__("' + item.ident + '", function() { delete ' + item.ident + '; ' + item.ident + ' = ' + parseConst(item.value, item.type) + '; return ' + item.ident + ' });'; + item.JS = 'var ' + item.ident + ';'; + return [item, { + intertype: 'GlobalVariable', + JS: 'globalFuncs.push(function() { ' + item.ident + ' = ' + parseConst(item.value, item.type) + ' });', + __result__: true, + }]; } - item.__result__ = true; return [item]; }, }); @@ -864,12 +868,25 @@ function JSify(data) { function finalCombiner(items) { var ret = items.filter(function(item) { return item.intertype == 'type' }); - ret = ret.concat(items.filter(function(item) { return item.intertype == 'globalVariable' })); + ret = ret.concat(items.filter(function(item) { return item.intertype == 'GlobalVariableStub' })); ret.push('\n'); ret = ret.concat(items.filter(function(item) { return item.intertype == 'functionStub' })); ret.push('\n'); ret = ret.concat(items.filter(function(item) { return item.intertype == 'function' })); - return ret.map(function(item) { return item.JS }).join('\n'); + ret = ret.map(function(item) { return item.JS }).join('\n'); + + var params = { 'QUANTUM_SIZE': QUANTUM_SIZE }; + var body = preprocess(read('preamble.js').replace('{{RUNTIME}}', getRuntime()) + ret + read('postamble.js'), params); + function reverse_(x) { + if (LLVM_STYLE === 'old') { + return x.reverse(); + } else { + return x; + } + } + var globalVars = reverse_(items.filter(function(item) { return item.intertype == 'GlobalVariable' }).map(function(item) { return item.JS })).join('\n'); + return read('shell.js').replace('{{BODY}}', indentify(body, 2)) + .replace('{{GLOBAL_VARS}}', indentify(globalVars, 4)); } // Data @@ -879,8 +896,6 @@ function JSify(data) { substrate.addItems(data.functions, 'FunctionSplitter'); substrate.addItems(data.functionStubs, 'FunctionStub'); - var params = { 'QUANTUM_SIZE': QUANTUM_SIZE }; - var body = preprocess(read('preamble.js').replace('{{RUNTIME}}', getRuntime()) + finalCombiner(substrate.solve()) + read('postamble.js'), params); - return read('shell.js').replace('{{BODY}}', indentify(body, 2)); + return finalCombiner(substrate.solve()); } |