|
|
|
@ -79,7 +79,7 @@ var InstructionOut = &Instruction{ |
|
|
|
|
Name: "OUT", |
|
|
|
|
ExecuteWithOperand: func(module *Module, operand float64) error { |
|
|
|
|
index := int(operand) |
|
|
|
|
if len(module.IO) >= index { |
|
|
|
|
if len(module.IO) <= index { |
|
|
|
|
return fmt.Errorf("index %d exceeds IO size of %d", index, len(module.IO)) |
|
|
|
|
} |
|
|
|
|
module.IO[int64(operand)] = module.accumulator |
|
|
|
@ -91,7 +91,7 @@ var InstructionIn = &Instruction{ |
|
|
|
|
Name: "IN", |
|
|
|
|
ExecuteWithOperand: func(module *Module, operand float64) error { |
|
|
|
|
index := int(operand) |
|
|
|
|
if len(module.IO) >= index { |
|
|
|
|
if len(module.IO) <= index { |
|
|
|
|
return fmt.Errorf("index %d exceeds IO size of %d", index, len(module.IO)) |
|
|
|
|
} |
|
|
|
|
module.accumulator = module.IO[index] |
|
|
|
@ -103,7 +103,7 @@ var InstructionLoad = &Instruction{ |
|
|
|
|
Name: "LOAD", |
|
|
|
|
ExecuteWithOperand: func(module *Module, operand float64) error { |
|
|
|
|
index := int(operand) |
|
|
|
|
if len(module.register) >= index { |
|
|
|
|
if len(module.register) <= index { |
|
|
|
|
return fmt.Errorf("index %d exceeds register size of %d", index, len(module.IO)) |
|
|
|
|
} |
|
|
|
|
module.accumulator = module.register[index] |
|
|
|
@ -123,7 +123,7 @@ var InstructionStore = &Instruction{ |
|
|
|
|
Name: "STORE", |
|
|
|
|
ExecuteWithOperand: func(module *Module, operand float64) error { |
|
|
|
|
index := int(operand) |
|
|
|
|
if len(module.register) >= index { |
|
|
|
|
if len(module.register) <= index { |
|
|
|
|
return fmt.Errorf("index %d exceeds register size of %d", index, len(module.IO)) |
|
|
|
|
} |
|
|
|
|
module.register[index] = module.accumulator |
|
|
|
@ -148,11 +148,11 @@ func newJumpInstruction(name string, doJump func(accumulator float64) bool) *Ins |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var InstructionJumpNeg = newJumpInstruction("JUMPNEG", func(accumulator float64) bool { |
|
|
|
|
return accumulator > 0 |
|
|
|
|
return accumulator < 0 |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
var InstructionJumpPos = newJumpInstruction("JUMPPOS", func(accumulator float64) bool { |
|
|
|
|
return accumulator < 0 |
|
|
|
|
return accumulator > 0 |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
var InstructionJumpNull = newJumpInstruction("JUMPNULL", func(accumulator float64) bool { |
|
|
|
|