diff options
-rw-r--r-- | src/analyzer.js | 11 | ||||
-rw-r--r-- | src/jsifier.js | 21 | ||||
-rw-r--r-- | tests/runner.py | 5 |
3 files changed, 22 insertions, 15 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index 8f4ba95e..0cb89eda 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -217,6 +217,17 @@ function analyzer(data, givenTypes) { // Variable analyzer substrate.addActor('VariableAnalyzer', { processItem: function(item) { + // Globals + + var old = item.globalVariables; + item.globalVariables = {}; + old.forEach(function(variable) { + variable.impl = 'emulated'; // All global variables are emulated, for now. Consider optimizing later if useful + item.globalVariables[variable.ident] = variable; + }); + + // Function locals + item.functions.forEach(function(func) { dprint('vars', 'Analyzing variables in ' + func.ident); diff --git a/src/jsifier.js b/src/jsifier.js index 85108b7d..e3fbf3e4 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1,12 +1,13 @@ // Convert analyzed data to javascript -function JSify(data, functionsOnly, givenTypes, givenFunctions) { +function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVariables) { substrate = new Substrate('JSifyer'); var TYPES = functionsOnly ? givenTypes : data.types; - var FUNCTIONS = functionsOnly ? givenFunctions : {}; + var GLOBAL_VARIABLES = functionsOnly ? givenGlobalVariables : data.globalVariables; + var FUNCTIONS = functionsOnly ? givenFunctions : {}; // Now that analysis has completed, we can get around to handling unparsedFunctions (functionsOnly ? data.functions : data.unparsedFunctions.concat(data.functions)).forEach(function(func) { // Save just what we need, to save memory - whether there are varargs, and the # of parameters @@ -19,7 +20,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) { for (var i = 0; i < data.unparsedFunctions.length; i++) { var func = data.unparsedFunctions[i]; dprint('unparsedFunctions', 'processing |' + func.ident + '|, ' + i + '/' + data.unparsedFunctions.length); - func.JS = JSify(analyzer(intertyper(func.lines, true, func.lineNum-1), TYPES), true, TYPES, FUNCTIONS); + func.JS = JSify(analyzer(intertyper(func.lines, true, func.lineNum-1), TYPES), true, TYPES, FUNCTIONS, GLOBAL_VARIABLES); delete func.lines; // clean up memory as much as possible } @@ -441,17 +442,14 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) { } }); - function getVarData(funcData, ident) { // XXX - need to check globals as well! - return funcData.variables[ident]; + function getVarData(funcData, ident) { + return funcData.variables[ident] || GLOBAL_VARIABLES[ident]; } function getVarImpl(funcData, ident) { var data = getVarData(funcData, ident); - if (data) { - return data.impl; - } else { - return 'emulated'; // All global are emulated - } + assert(data, 'What variable is this? |' + ident + '|'); + return data.impl; } substrate.addActor('FuncLineTriager', { @@ -484,7 +482,6 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) { var type = item.value.type; var value = parseNumerical(item.value.JS); - //print("zz var: " + item.JS); var impl = getVarImpl(item.funcData, item.ident); switch (impl) { case VAR_NATIVE: { @@ -990,7 +987,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) { // Data substrate.addItems(values(data.types).filter(function(type) { return type.lineNum != '?' }), 'Type'); - substrate.addItems(data.globalVariables, 'GlobalVariable'); + substrate.addItems(values(data.globalVariables), 'GlobalVariable'); substrate.addItems(data.functions, 'FunctionSplitter'); substrate.addItems(data.functionStubs, 'FunctionStub'); diff --git a/tests/runner.py b/tests/runner.py index f661f3ab..5a9ccc7a 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -1264,7 +1264,8 @@ if 'benchmark' not in sys.argv: self.do_test(src, output, ['3', '16']) def test_dlmalloc(self): - assert COMPILER_ENGINE != SPIDERMONKEY_ENGINE # See cubescript test + # XXX Warning: Running this in SpiderMonkey can lead to an extreme amount of memory being + # used, see Mozilla bug 593659. src = open(path_from_root(['tests', 'dlmalloc.c']), 'r').read() self.do_test(src, '*1,0*') @@ -1294,8 +1295,6 @@ if 'benchmark' not in sys.argv: def test_cubescript(self): # XXX Warning: Running this in SpiderMonkey can lead to an extreme amount of memory being # used, see Mozilla bug 593659. - assert COMPILER_ENGINE != SPIDERMONKEY_ENGINE - global SAFE_HEAP; SAFE_HEAP = 0 # Has some actual loads of unwritten-to places, in the C++ code... global CHECK_OVERFLOWS; CHECK_OVERFLOWS = 0 # Overflows in hash loop... seems to work though, doesn't overflow too much |