Simplify instructions

master
kolaente 5 years ago
parent 8166344340
commit de243c162b
Signed by: kolaente
GPG Key ID: F40E70337AB24C9B
  1. 48
      hal/instructions.go

@ -163,6 +163,22 @@ var InstructionJump = newJumpInstruction("JUMP", func(accumulator float64) bool
return true
})
var addInstr = func(accumulator, value float64) float64 {
return accumulator + value
}
var subInstr = func(accumulator, value float64) float64 {
return accumulator - value
}
var mulInstr = func(accumulator, value float64) float64 {
return accumulator * value
}
var divInstr = func(accumulator, value float64) float64 {
return accumulator / value
}
func newMathNumInstruction(name string, operation func(accumulator, value float64) float64) *Instruction {
return &Instruction{
Name: name,
@ -173,21 +189,13 @@ func newMathNumInstruction(name string, operation func(accumulator, value float6
}
}
var InstructionAddNum = newMathNumInstruction("ADDNUM", func(accumulator, value float64) float64 {
return accumulator + value
})
var InstructionAddNum = newMathNumInstruction("ADDNUM", addInstr)
var InstructionSubNum = newMathNumInstruction("SUBNUM", func(accumulator, value float64) float64 {
return accumulator - value
})
var InstructionSubNum = newMathNumInstruction("SUBNUM", subInstr)
var InstructionMulNum = newMathNumInstruction("MULNUM", func(accumulator, value float64) float64 {
return accumulator * value
})
var InstructionMulNum = newMathNumInstruction("MULNUM", mulInstr)
var InstructionDivNum = newMathNumInstruction("DIVNUM", func(accumulator, value float64) float64 {
return accumulator / value
})
var InstructionDivNum = newMathNumInstruction("DIVNUM", divInstr)
func newMathInstruction(name string, operation func(accumulator, register float64) float64) *Instruction {
return &Instruction{
@ -204,18 +212,10 @@ func newMathInstruction(name string, operation func(accumulator, register float6
}
}
var InstructionAdd = newMathInstruction("ADD", func(accumulator, value float64) float64 {
return accumulator + value
})
var InstructionAdd = newMathInstruction("ADD", addInstr)
var InstructionSub = newMathInstruction("SUB", func(accumulator, value float64) float64 {
return accumulator - value
})
var InstructionSub = newMathInstruction("SUB", subInstr)
var InstructionMul = newMathInstruction("MUL", func(accumulator, value float64) float64 {
return accumulator * value
})
var InstructionMul = newMathInstruction("MUL", mulInstr)
var InstructionDiv = newMathInstruction("DIV", func(accumulator, value float64) float64 {
return accumulator / value
})
var InstructionDiv = newMathInstruction("DIV", divInstr)

Loading…
Cancel
Save