joinAdjacentOps should recurse
This commit is contained in:
parent
151c8c9113
commit
e046d187ae
22
gir.js
22
gir.js
|
@ -241,17 +241,23 @@ function joinAdjacentOps(parsed) {
|
||||||
// Start of a possible run of commands
|
// Start of a possible run of commands
|
||||||
prevOfType = true;
|
prevOfType = true;
|
||||||
value = command.value;
|
value = command.value;
|
||||||
} else if(prevOfType && command.type != type) {
|
} else {
|
||||||
// A run has ended, add it to optimized
|
// If a run has ended, add it to optimized
|
||||||
// However, skip it if value is 0
|
// However, skip it if value is 0
|
||||||
if(value != 0) {
|
if(prevOfType && value != 0) {
|
||||||
optimized.push({type: type, value: value});
|
optimized.push({type: type, value: value});
|
||||||
}
|
}
|
||||||
// Also add the command for this round
|
|
||||||
optimized.push(command);
|
// Add the command for this round
|
||||||
prevOfType = false;
|
if(command.type == loop) {
|
||||||
} else {
|
// Recurse
|
||||||
optimized.push(command);
|
optimized.push({type: loop,
|
||||||
|
contents: worker(
|
||||||
|
command.contents,
|
||||||
|
type)});
|
||||||
|
} else {
|
||||||
|
optimized.push(command);
|
||||||
|
}
|
||||||
prevOfType = false;
|
prevOfType = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ joinAdjacentOps
|
||||||
* *produces*: commands without offsets
|
* *produces*: commands without offsets
|
||||||
* *unknown commands*: passed through unmodified
|
* *unknown commands*: passed through unmodified
|
||||||
* *acts on*: `moveHead`, `add`
|
* *acts on*: `moveHead`, `add`
|
||||||
|
* *other known commands*: `loop` (recurses)
|
||||||
|
|
||||||
`joinAdjacentOps` joins adjacent `moveHead`s and `add`s together. Normally
|
`joinAdjacentOps` joins adjacent `moveHead`s and `add`s together. Normally
|
||||||
`parse` joins runs of `<>` or `+-` into one command, but if the runs are
|
`parse` joins runs of `<>` or `+-` into one command, but if the runs are
|
||||||
|
@ -19,6 +20,7 @@ transformClearLoops
|
||||||
* *produces*: commands without offsets
|
* *produces*: commands without offsets
|
||||||
* *unknown commands*: passed through unmodified
|
* *unknown commands*: passed through unmodified
|
||||||
* *acts on*: `loop` with one command, which is `add 1` or `add -1`
|
* *acts on*: `loop` with one command, which is `add 1` or `add -1`
|
||||||
|
* *other known commands*: `loop` (recurses)
|
||||||
|
|
||||||
`transformClearLoops` changes loops of the form `[-]` or `[+]` into a single
|
`transformClearLoops` changes loops of the form `[-]` or `[+]` into a single
|
||||||
`clear` command.
|
`clear` command.
|
||||||
|
|
Loading…
Reference in New Issue