aboutsummaryrefslogtreecommitdiff
path: root/src/parser.js
diff options
context:
space:
mode:
authoralon@honor <none@none>2010-09-06 11:14:12 -0700
committeralon@honor <none@none>2010-09-06 11:14:12 -0700
commit4cc594f20933435dee74046d2d10d61b1a19c5fa (patch)
tree397995ad40d7228ee55dc37fe7354c6a2d1ff3a5 /src/parser.js
parentfb18f94135ce2354ee3a225ffc2d73341139b6a8 (diff)
fix relooper bug with loops with just an inc block
Diffstat (limited to 'src/parser.js')
-rw-r--r--src/parser.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/parser.js b/src/parser.js
index 19e073bc..568dd3a4 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -1397,6 +1397,11 @@ print('// zz Merged away! ' + label2.ident + ' into ' + label1.ident);
};
if (!RELOOP) return def;
+ if (!entry) {
+ assertTrue(labels.length == 0);
+ return null; // Empty block - not even an entry
+ }
+
function getLastLine(block) {
//dprint('get last line at: ' + block.labels[0].ident);
if (block.next) return getLastLine(block.next);
@@ -1517,13 +1522,16 @@ print('// zz Merged away! ' + label2.ident + ' into ' + label1.ident);
}
});
// Fix inc branch into rest
- var nextEntry;
+ var nextEntry = null;
first.outLabels.forEach(function(outLabel) {
if (outLabel != pivot.ident) {
replaceLabels(lastLine, outLabel, 'BNOPP');
nextEntry = outLabel;
}
});
+ if (nextEntry == entry) { // We loop back to ourselves, the entire loop is just us
+ nextEntry = null;
+ }
var ret = {
type: 'loop',
labels: loopLabels,
@@ -1531,8 +1539,8 @@ print('// zz Merged away! ' + label2.ident + ' into ' + label1.ident);
inc: makeBlock([isolate(first)], entry, labelsDict),
rest: makeBlock(replaceInLabels(otherLoopLabels, entry), nextEntry, labelsDict),
};
- dprint(' getting last line for block starting with ' + entry);
- var lastLoopLine = getLastLine(ret.rest);
+ dprint(' getting last line for block starting with ' + entry + ' and nextEntry: ' + nextEntry);
+ var lastLoopLine = getLastLine(nextEntry ? ret.rest : ret.inc);
if (lastLoopLine) {
replaceLabels(lastLoopLine, 'BCONT' + entry, 'BNOPP'); // Last line will feed back into the loop anyhow
}