aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/jsifier.js14
-rw-r--r--tests/test_core.py6
-rw-r--r--tools/js-optimizer.js21
3 files changed, 17 insertions, 24 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index d7f00a1b..64da4228 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -821,9 +821,17 @@ function JSify(data, functionsOnly, givenFunctions) {
// Finalize function
if (LABEL_DEBUG && functionNameFilterTest(func.ident)) func.JS += " INDENT = INDENT.substr(0, INDENT.length-2);\n";
// Ensure a return in a function with a type that returns, even if it lacks a return (e.g., if it aborts())
- if (RELOOP && func.lines.length > 0 && func.returnType != 'void') {
- var returns = func.labels.filter(function(label) { return label.lines[label.lines.length-1].intertype == 'return' }).length;
- if (returns == 0) func.JS += INDENTATION + 'return ' + asmCoercion('0', func.returnType);
+ if (RELOOP && ASM_JS && func.lines.length > 0 && func.returnType != 'void') {
+ var lastCurly = func.JS.lastIndexOf('}');
+ var lastReturn = func.JS.lastIndexOf('return ');
+ if ((lastCurly < 0 && lastReturn < 0) || // no control flow, no return
+ (lastCurly >= 0 && lastReturn < lastCurly)) { // control flow, no return past last join
+ if (func.returnType in Runtime.FLOAT_TYPES) {
+ func.JS += ' return +0;\n';
+ } else {
+ func.JS += ' return 0;\n';
+ }
+ }
}
func.JS += '}\n';
diff --git a/tests/test_core.py b/tests/test_core.py
index 98ff678b..92edbaf4 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -8609,6 +8609,12 @@ void*:16
assert ' & 255]()' not in original, 'big function table does not exist'
assert ' & 255]()' in final, 'big function table exists'
+ assert 'asm1' in test_modes
+ if self.run_name == 'asm1':
+ assert not Settings.RELOOP
+ Settings.RELOOP = 1 # check for mixing of relooping with asm1
+ self.do_run(path_from_root('tests', 'cubescript'), '*\nTemp is 33\n9\n5\nhello, everyone\n*', main_file='command.cpp')
+
def test_gcc_unmangler(self):
Settings.NAMED_GLOBALS = 1 # test coverage for this
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 7df92c60..f03c04b8 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -768,32 +768,11 @@ function simplifyExpressions(ast) {
});
}
- function asmOpts(fun) {
- // Add final returns when necessary
- var returnType = null;
- traverse(fun, function(node, type) {
- if (type === 'return' && node[1]) {
- returnType = detectAsmCoercion(node[1]);
- }
- });
- // Add a final return if one is missing.
- if (returnType !== null) {
- var stats = getStatements(fun);
- var last = stats[stats.length-1];
- if (last[0] != 'return') {
- var returnValue = ['num', 0];
- if (returnType === ASM_DOUBLE) returnValue = ['unary-prefix', '+', returnValue];
- stats.push(['return', returnValue]);
- }
- }
- }
-
traverseGeneratedFunctions(ast, function(func) {
simplifyIntegerConversions(func);
simplifyBitops(func);
joinAdditions(func);
// simplifyZeroComp(func); TODO: investigate performance
- if (asm) asmOpts(func);
simplifyNotComps(func);
});
}