Fix begin/end stages not combining correctly [#31]

This commit is contained in:
David Evans 2018-01-15 19:36:16 +00:00
parent f8a757c508
commit 0c988e8658
4 changed files with 36 additions and 17 deletions

View File

@ -2202,15 +2202,14 @@ define('sequence/Generator',['core/ArrayUtilities'], (array) => {
const viable = findViableSequentialMergers(subStages); const viable = findViableSequentialMergers(subStages);
performSequentialMergers(lastViable, viable, lastStages, subStages); performSequentialMergers(lastViable, viable, lastStages, subStages);
lastViable = viable;
lastStages = subStages;
if(subStages.length === 0) { if(subStages.length === 0) {
stages.splice(i, 1); stages.splice(i, 1);
} else if(stage.type === 'parallel' && subStages.length === 1) {
stages.splice(i, 1, subStages[0]);
++ i;
} else { } else {
if(stage.type === 'parallel' && subStages.length === 1) {
stages.splice(i, 1, subStages[0]);
}
lastViable = viable;
lastStages = subStages;
++ i; ++ i;
} }
} }
@ -2510,7 +2509,6 @@ define('sequence/Generator',['core/ArrayUtilities'], (array) => {
this.currentNest.blockType + ')' this.currentNest.blockType + ')'
); );
} }
optimiseStages(this.currentSection.stages);
this.currentSection = { this.currentSection = {
header: { header: {
type: 'block split', type: 'block split',
@ -2530,7 +2528,6 @@ define('sequence/Generator',['core/ArrayUtilities'], (array) => {
if(this.nesting.length <= 1) { if(this.nesting.length <= 1) {
throw new Error('Invalid block nesting (too many "end"s)'); throw new Error('Invalid block nesting (too many "end"s)');
} }
optimiseStages(this.currentSection.stages);
const nested = this.nesting.pop(); const nested = this.nesting.pop();
this.currentNest = array.last(this.nesting); this.currentNest = array.last(this.nesting);
this.currentSection = array.last(this.currentNest.sections); this.currentSection = array.last(this.currentNest.sections);

File diff suppressed because one or more lines are too long

View File

@ -160,15 +160,14 @@ define(['core/ArrayUtilities'], (array) => {
const viable = findViableSequentialMergers(subStages); const viable = findViableSequentialMergers(subStages);
performSequentialMergers(lastViable, viable, lastStages, subStages); performSequentialMergers(lastViable, viable, lastStages, subStages);
lastViable = viable;
lastStages = subStages;
if(subStages.length === 0) { if(subStages.length === 0) {
stages.splice(i, 1); stages.splice(i, 1);
} else if(stage.type === 'parallel' && subStages.length === 1) {
stages.splice(i, 1, subStages[0]);
++ i;
} else { } else {
if(stage.type === 'parallel' && subStages.length === 1) {
stages.splice(i, 1, subStages[0]);
}
lastViable = viable;
lastStages = subStages;
++ i; ++ i;
} }
} }
@ -468,7 +467,6 @@ define(['core/ArrayUtilities'], (array) => {
this.currentNest.blockType + ')' this.currentNest.blockType + ')'
); );
} }
optimiseStages(this.currentSection.stages);
this.currentSection = { this.currentSection = {
header: { header: {
type: 'block split', type: 'block split',
@ -488,7 +486,6 @@ define(['core/ArrayUtilities'], (array) => {
if(this.nesting.length <= 1) { if(this.nesting.length <= 1) {
throw new Error('Invalid block nesting (too many "end"s)'); throw new Error('Invalid block nesting (too many "end"s)');
} }
optimiseStages(this.currentSection.stages);
const nested = this.nesting.pop(); const nested = this.nesting.pop();
this.currentNest = array.last(this.nesting); this.currentNest = array.last(this.nesting);
this.currentSection = array.last(this.currentNest.sections); this.currentSection = array.last(this.currentNest.sections);

View File

@ -563,6 +563,31 @@ defineDescribe('Sequence Generator', ['./Generator'], (Generator) => {
]); ]);
}); });
it('collapses chains of adjacent begin statements', () => {
const sequence = invoke([
PARSED.beginAgents(['A']),
PARSED.beginAgents(['B']),
PARSED.beginAgents(['C']),
]);
expect(sequence.stages).toEqual([
GENERATED.beginAgents(['A', 'B', 'C']),
any(),
]);
});
it('collapses chains of adjacent end statements', () => {
const sequence = invoke([
PARSED.beginAgents(['A', 'B', 'C']),
PARSED.endAgents(['A']),
PARSED.endAgents(['B']),
PARSED.endAgents(['C']),
]);
expect(sequence.stages).toEqual([
any(),
GENERATED.endAgents(['A', 'B', 'C']),
]);
});
it('removes superfluous begin statements', () => { it('removes superfluous begin statements', () => {
const sequence = invoke([ const sequence = invoke([
PARSED.connect(['A', 'B']), PARSED.connect(['A', 'B']),