|
|
@ -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 |
|
|
|
|
|
|
|
}) |
|
|
|