Merge remote-tracking branch 'origin/master'

master
Jonas Franz 5 years ago
commit 55e9a23f87
Signed by: JonasFranzDEV
GPG Key ID: 7293A220B7C38080
  1. 33
      hal/instructions.go

@ -50,6 +50,9 @@ var instructions = []*Instruction{
InstructionJump,
InstructionAdd,
InstructionAddNum,
InstructionSubNum,
InstructionMulNum,
InstructionDivNum,
}
var InstructionStart = &Instruction{
@ -171,10 +174,28 @@ var InstructionAdd = &Instruction{
},
}
var InstructionAddNum = &Instruction{
Name: "ADDNUM",
ExecuteWithOperand: func(module *Module, operand float64) error {
module.accumulator = module.accumulator + operand
return nil
},
func newMathNumInstruction(name string, operation func(accumulator, value float64) float64) *Instruction {
return &Instruction{
Name: name,
ExecuteWithOperand: func(module *Module, operand float64) error {
module.accumulator = operation(module.accumulator, operand)
return nil
},
}
}
var InstructionAddNum = newMathNumInstruction("ADDNUM", func(accumulator, value float64) float64 {
return accumulator + value
})
var InstructionSubNum = newMathNumInstruction("SUBNUM", func(accumulator, value float64) float64 {
return accumulator - value
})
var InstructionMulNum = newMathNumInstruction("MULNUM", func(accumulator, value float64) float64 {
return accumulator * value
})
var InstructionDivNum = newMathNumInstruction("DIVNUM", func(accumulator, value float64) float64 {
return accumulator / value
})

Loading…
Cancel
Save