aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralon@honor <none@none>2010-10-03 15:40:52 -0700
committeralon@honor <none@none>2010-10-03 15:40:52 -0700
commitddb4ec9cd01a955d5e0a3a15f328f1c09166a5a0 (patch)
tree6b93ee110d51ce6a35e9773ea707f5313804cc57 /src
parent7acd07a63ff39da63869856734c51bc665528270 (diff)
minor relooper fixes
Diffstat (limited to 'src')
-rw-r--r--src/analyzer.js7
-rw-r--r--src/jsifier.js11
2 files changed, 10 insertions, 8 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index 09403278..b3c5b0c8 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -303,9 +303,10 @@ function analyzer(data) {
function process(item) {
['label', 'labelTrue', 'labelFalse', 'toLabel', 'unwindLabel', 'defaultLabel'].forEach(function(id) {
if (item[id] && item[id] in labelIds) {
- dprint('relooping', 'zz replace ' + item[id] + ' with ' + toLabelId);
ret.push(item[id]);
+ assert(!item['old_' + id]);
item['old_' + id] = item[id]; // Save it; we need this later for labels before breaks, when we have multiple entries later
+ dprint('relooping', 'zz ' + id + ' replace ' + item[id] + ' with ' + toLabelId + '; old: ' + item['old_' + id]);
item[id] = toLabelId;
}
});
@@ -492,7 +493,7 @@ function analyzer(data) {
return {
type: 'emulated',
labels: [entryLabel],
- entry: entry,
+ entries: entries,
next: next ? makeBlock(others, [next], labelsDict, exitLabels, exitLabelsHit) : null,
};
}
@@ -527,7 +528,7 @@ function analyzer(data) {
// We will be in a loop, |continue| gets us back to the entry
entries.forEach(function(entry) {
- replaceLabelLabels(internals, searchable(entry), 'BCONT' + entries[0]); // entries[0] is the name of the loop, see walkBlock
+ replaceLabelLabels(internals, searchable(entries), 'BCONT' + entries[0]); // entries[0] is the name of the loop, see walkBlock
});
// To get to any of our (not our parents') exit labels, we will break.
diff --git a/src/jsifier.js b/src/jsifier.js
index 1f41f5d7..0892f1db 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -257,8 +257,8 @@ function JSify(data) {
// Walk function blocks and generate JS
function walkBlock(block, indent) {
if (!block) return '';
- if (!block.entry && block.entries.length == 1) block.entry = block.entries[0];
- dprint('relooping', 'walking block: ' + block.type + ',' + block.entry + ',' + block.entries + ' : ' + block.labels.length);
+ block.entry = block.entries[0];
+ dprint('relooping', 'walking block: ' + block.type + ',' + block.entries + ' : ' + block.labels.length);
function getLabelLines(label, indent) {
if (!label) return '';
var ret = '';
@@ -277,7 +277,7 @@ function JSify(data) {
var ret = '';
if (block.type == 'emulated') {
if (block.labels.length > 1) {
- if (block.entry) {
+ if (block.entries.length == 1) {
ret += indent + '__label__ = ' + getLabelId(block.entry) + '; /* ' + block.entry + ' */\n';
} // otherwise, should have been set before!
ret += indent + 'while(1) switch(__label__) {\n';
@@ -431,7 +431,8 @@ function JSify(data) {
return '__label__ = ' + getLabelId(oldLabel) + '; /* ' + cleanLabel(oldLabel) + ' */ ' + // TODO: optimize away
'break ' + label.substr(5) + ';';
} else if (label[1] == 'C') {
- return 'continue ' + label.substr(5) + ';';
+ return '__label__ = ' + getLabelId(oldLabel) + '; /* ' + cleanLabel(oldLabel) + ' */ ' + // TODO: optimize away
+ 'continue ' + label.substr(5) + ';';
} else { // NOPP
return ';'; // Returning no text might confuse this parser
}
@@ -443,7 +444,7 @@ function JSify(data) {
makeFuncLineZyme('branch', function(item) {
//print('branch: ' + dump(item));
if (!item.ident) {
- return makeBranch(item.label);
+ return makeBranch(item.label, item.old_label);
} else {
var labelTrue = makeBranch(item.labelTrue, item.old_labelTrue);
var labelFalse = makeBranch(item.labelFalse, item.old_labelFalse);