Merge remote-tracking branch 'origin/master'

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

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