Class AbstractCopyInstruction
java.lang.Object
dev.zemco.codegame.execution.instructions.AbstractCopyInstruction
- All Implemented Interfaces:
IInstruction
- Direct Known Subclasses:
CopyFromInstruction,CopyToInstruction
Abstract base for instruction copying values from one
memory cell to some other.- Author:
- Erik Zemčík
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute(IExecutionContext executionContext) Copies the value from the sourcememory cellto the destinationmemory cell.protected abstract IMemoryCellgetDestinationMemoryCell(IMemory memory) Retrieves the destinationmemory cellfor copying.protected IMemoryCellgetMemoryCellAtAddress(IMemory memory, int address) Retrieves amemory cellat a given address.protected abstract IMemoryCellgetSourceMemoryCell(IMemory memory) Retrieves the sourcememory cellfor copying.
-
Constructor Details
-
AbstractCopyInstruction
public AbstractCopyInstruction()
-
-
Method Details
-
getSourceMemoryCell
protected abstract IMemoryCell getSourceMemoryCell(IMemory memory) throws InstructionExecutionException Retrieves the sourcememory cellfor copying.- Parameters:
memory- source ofmemory cells- Returns:
- source
memory cell - Throws:
InstructionExecutionException- if the sourcememory cellcould not be retrieved
-
getDestinationMemoryCell
protected abstract IMemoryCell getDestinationMemoryCell(IMemory memory) throws InstructionExecutionException Retrieves the destinationmemory cellfor copying.- Parameters:
memory- source ofmemory cells- Returns:
- destination
memory cell - Throws:
InstructionExecutionException- if the destinationmemory cellcould not be retrieved
-
execute
Copies the value from the sourcememory cellto the destinationmemory cell.Internally these
memory cellsare resolved through thegetSourceMemoryCell(IMemory)method and thegetDestinationMemoryCell(IMemory)respectively.- Specified by:
executein interfaceIInstruction- Parameters:
executionContext- context on which the instruction is executed- Throws:
IllegalArgumentException- ifexecutionContextisnullInstructionExecutionException- if the sourcememory cellhas no value
-
getMemoryCellAtAddress
protected IMemoryCell getMemoryCellAtAddress(IMemory memory, int address) throws InstructionExecutionException Retrieves amemory cellat a given address. This method is intended to be used by subclasses as it provides formatted exceptions when the address is invalid for the givenmemory- Parameters:
memory- source ofmemory cellsaddress- address of the targetmemory cell- Returns:
memory cellat the given address- Throws:
InstructionExecutionException- if the address is out of bounds of thememory
-