Thread safety for status updates, periodically minify
This commit is contained in:
@@ -48,7 +48,7 @@ func (def *Definition) Grow(statusChan chan<- Status) (*vm.Program, error) {
|
||||
for {
|
||||
status.Attempts++
|
||||
|
||||
Mutate(prog)
|
||||
Mutate(def, prog)
|
||||
|
||||
score, err := def.score(prog)
|
||||
if err != nil {
|
||||
@@ -58,7 +58,7 @@ func (def *Definition) Grow(statusChan chan<- Status) (*vm.Program, error) {
|
||||
|
||||
if score > status.BestScore {
|
||||
status.BestScore = score
|
||||
status.BestProgram = prog
|
||||
status.BestProgram = prog.Copy()
|
||||
|
||||
if statusChan != nil {
|
||||
statusChan <- status
|
||||
@@ -73,6 +73,7 @@ func (def *Definition) Grow(statusChan chan<- Status) (*vm.Program, error) {
|
||||
|
||||
return nil, err
|
||||
}
|
||||
status.BestProgram = prog.Copy()
|
||||
|
||||
if statusChan != nil {
|
||||
statusChan <- status
|
||||
@@ -142,6 +143,7 @@ func (def *Definition) minifyFunction(prog *vm.Program, f int) error {
|
||||
|
||||
for i := 0; i < len(prog.Functions[f].Instructions); i++ {
|
||||
origInstructions := prog.Functions[f].Instructions
|
||||
|
||||
tmp := make([]*vm.Instruction, len(prog.Functions[f].Instructions))
|
||||
copy(tmp, prog.Functions[f].Instructions)
|
||||
prog.Functions[f].Instructions = append(tmp[:i], tmp[i+1:]...)
|
||||
|
||||
Reference in New Issue
Block a user