Nicened the loop code so it isn't quite as nested

This commit is contained in:
Chris Sexton 2012-11-13 22:27:18 -05:00
parent 763b188a6a
commit 3f9743f3a9
1 changed files with 15 additions and 19 deletions

View File

@ -83,9 +83,8 @@ func (m *Machine) Run(input []byte) {
// execute the program
for ip := 0; ip < len(input); ip++ {
instr := input[ip]
if instr == '[' {
// if *ptr == 0, jump to ]
if m.value() == 0 {
if instr == '[' && m.value() == 0 {
for lc := 1; lc > 0; {
ip += 1
if input[ip] == ']' {
@ -94,10 +93,8 @@ func (m *Machine) Run(input []byte) {
lc += 1
}
}
}
} else if instr == ']' {
} else if instr == ']' && m.value() != 0 {
// if *ptr != 0, go back to [
if m.value() != 0 {
for lc := 1; lc > 0; {
ip -= 1
if input[ip] == ']' {
@ -106,7 +103,6 @@ func (m *Machine) Run(input []byte) {
lc -= 1
}
}
}
} else if instr == '>' {
m.PtrIncr()
} else if instr == '<' {