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