diff --git a/grow/definition.go b/grow/definition.go index 996e8b0..88a0998 100644 --- a/grow/definition.go +++ b/grow/definition.go @@ -52,11 +52,8 @@ func (def *Definition) Grow(statusChan chan<- Status) (*vm.Program, error) { score, err := def.score(prog) if err != nil { - if statusChan != nil { - close(statusChan) - } - - return nil, err + // Can never get best score + continue } if score > status.BestScore { @@ -89,7 +86,10 @@ func (def *Definition) score(prog *vm.Program) (uint64, error) { sample.SetInputs(state) - state.Execute() // ignore error + err = state.Execute() + if err != nil { + return 0, err + } score += sample.matchingOuts(state) } diff --git a/vm/ophandler.go b/vm/ophandler.go index 6e1a494..0ec61fe 100644 --- a/vm/ophandler.go +++ b/vm/ophandler.go @@ -1,5 +1,6 @@ package vm +import "fmt" import "math" type opHandler func(*State, *Instruction) @@ -79,8 +80,7 @@ func (state *State) handleDivideUnsigned(instr *Instruction) { in2 := state.readUnsigned(instr.Operands[1]) if in2 == 0 { - // Divide by zero just returns zero - state.writeUnsigned(instr.Operands[0], 0) + state.setError(fmt.Errorf("Divide by zero")) } else { state.writeUnsigned(instr.Operands[0], in1/in2) } @@ -91,8 +91,7 @@ func (state *State) handleDivideSigned(instr *Instruction) { in2 := state.readSigned(instr.Operands[1]) if in2 == 0 { - // Divide by zero just returns zero - state.writeSigned(instr.Operands[0], 0) + state.setError(fmt.Errorf("Divide by zero")) } else { state.writeSigned(instr.Operands[0], in1/in2) } diff --git a/vm/state.go b/vm/state.go index cfbbd91..cd590fd 100644 --- a/vm/state.go +++ b/vm/state.go @@ -75,8 +75,7 @@ func (state *State) processInstruction() { state.instructionCount += 1 if state.program.InstructionLimit > 0 && state.instructionCount > state.program.InstructionLimit { - state.err = fmt.Errorf("Instruction limit (%d) exceeded", state.program.InstructionLimit) - state.running = false + state.setError(fmt.Errorf("Instruction limit (%d) exceeded", state.program.InstructionLimit)) } for state.functionIndex < 0 ||