aboutsummaryrefslogtreecommitdiff
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
parentfb18f94135ce2354ee3a225ffc2d73341139b6a8 (diff)
fix relooper bug with loops with just an inc block
-rw-r--r--src/parser.js14
-rw-r--r--tests/runner.py18
2 files changed, 28 insertions, 4 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
}
diff --git a/tests/runner.py b/tests/runner.py
index 42e8e7f1..eae225b4 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -341,11 +341,27 @@ class T(unittest.TestCase):
total += c->value;
c = c->next;
}
+
+ // Chunk of em
+ worker_args chunk[10];
+ for (int i = 0; i < 9; i++) {
+ chunk[i].value = i*10;
+ chunk[i].next = &chunk[i+1];
+ }
+ chunk[9].value = 90;
+ chunk[9].next = &chunk[0];
+
+ c = chunk;
+ do {
+ total += c->value;
+ c = c->next;
+ } while (c != chunk);
+
printf("*%d*\\n", total);
return 0;
}
'''
- self.do_test(src, '*960*')
+ self.do_test(src, '*1410*')
def test_class(self):
src = '''