diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/analyzer.js | 31 | ||||
-rw-r--r-- | src/jsifier.js | 12 | ||||
-rw-r--r-- | src/utility.js | 4 |
3 files changed, 8 insertions, 39 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index 7245a583..9e827cd1 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -1172,37 +1172,7 @@ function analyzer(data) { replaceLabelLabels(block.labels, set('BJSET|*|' + block.willGetTo), 'BNOPP'); replaceLabelLabels(block.labels, set('BCONT|*|' + block.willGetTo), 'BNOPP'); replaceLabelLabels(block.labels, set('BREAK|*|' + block.willGetTo), 'BNOPP'); - } else if (block.type === 'multiple') { - // Check if the one-time loop (that allows breaking out) is actually needed - if (replaceLabelLabels(block.labels, set('BREAK|' + block.id + '|*')).length === 0) { - block.loopless = true; - } - } - } - - // Checks whether we actually need labels. We return whether we have a loop nested inside us. - function optimizeOutUnneededLabels(block) { - if (!block) return false; - - dprint('relooping', "// optimizing (2) block: " + block.type + ' : ' + block.entries); - - var containLoop = sum(recurseBlock(block, optimizeOutUnneededLabels)) > 0; - - if (block.type === 'emulated') { - return containLoop; - } else if (block.type === 'multiple') { - // TODO: Apply the same optimization below for 'reloop', to looped multiples - return containLoop || !block.loopless; - } else if (block.type === 'reloop') { - if (!containLoop) { - block.needBlockId = false; - - replaceLabelLabels(block.labels, set('BCONT|' + block.id + '|*'), 'BCONT||*'); - replaceLabelLabels(block.labels, set('BREAK|' + block.id + '|*'), 'BREAK||*'); - } - return true; } - return assert(false); } // TODO: Parallelize @@ -1210,7 +1180,6 @@ function analyzer(data) { dprint('relooping', "// loopOptimizing function: " + func.ident); exploreBlockEndings(func.block); optimizeBlockEndings(func.block); - optimizeOutUnneededLabels(func.block); }); return finish(); } diff --git a/src/jsifier.js b/src/jsifier.js index 49bac511..2869d059 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -495,16 +495,14 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { } ret += '\n'; } else if (block.type == 'reloop') { - ret += indent + (block.needBlockId ? block.id + ': ' : '') + 'while(1) { ' + (SHOW_LABELS ? ' /* ' + block.entries + + ' */' : '') + '\n'; + ret += indent + block.id + ': while(1) { ' + (SHOW_LABELS ? ' /* ' + block.entries + + ' */' : '') + '\n'; ret += walkBlock(block.inner, indent + ' '); ret += indent + '}\n'; } else if (block.type == 'multiple') { var first = true; var multipleIdent = ''; - if (!block.loopless) { - ret += indent + (block.needBlockId ? block.id + ': ' : '') + 'do { \n'; - multipleIdent = ' '; - } + ret += indent + block.id + ': do { \n'; + multipleIdent = ' '; // TODO: Find out cases where the final if/case is not needed - where we know we must be in a specific label at that point var SWITCH_IN_MULTIPLE = 0; // This appears to never be worth it, for no amount of labels if (SWITCH_IN_MULTIPLE && block.entryLabels.length >= 2) { @@ -523,9 +521,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { first = false; }); } - if (!block.loopless) { - ret += indent + '} while(0);\n'; - } + ret += indent + '} while(0);\n'; } else { throw "Walked into an invalid block type: " + block.type; } diff --git a/src/utility.js b/src/utility.js index ba97a399..f0439ea7 100644 --- a/src/utility.js +++ b/src/utility.js @@ -135,6 +135,10 @@ function sumStringy(x) { return x.reduce(function(a,b) { return a+b }, ''); } +function filterTruthy(x) { + return x.filter(function(y) { return !!y }); +} + function loopOn(array, func) { for (var i = 0; i < array.length; i++) { func(i, array[i]); |