|
|
|
@ -48,7 +48,8 @@ var instructions = []*Instruction{ |
|
|
|
|
InstructionJumpPos, |
|
|
|
|
InstructionJumpNull, |
|
|
|
|
InstructionJump, |
|
|
|
|
InstructionAddnum, |
|
|
|
|
InstructionAdd, |
|
|
|
|
InstructionAddNum, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var InstructionStart = &Instruction{ |
|
|
|
@ -156,9 +157,22 @@ var InstructionJump = newJumpInstruction("JUMP", func(accumulator float64) bool |
|
|
|
|
return true |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
var InstructionAddnum = &Instruction{ |
|
|
|
|
var InstructionAdd = &Instruction{ |
|
|
|
|
Name: "ADD", |
|
|
|
|
ExecuteWithOperand: func(module *Module, operand float64) error { |
|
|
|
|
index := int64(operand) |
|
|
|
|
if _, ok := module.programStorage[index]; !ok { |
|
|
|
|
return fmt.Errorf("index %d does not exist in program storage", index) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var InstructionAddNum = &Instruction{ |
|
|
|
|
Name: "ADDNUM", |
|
|
|
|
ExecuteWithOperand: func(module *Module, operand float64) { |
|
|
|
|
ExecuteWithOperand: func(module *Module, operand float64) error { |
|
|
|
|
module.accumulator = module.accumulator + operand |
|
|
|
|
return nil |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|