Class ProgramExecutionEngine
java.lang.Object
dev.zemco.codegame.execution.engine.ProgramExecutionEngine
- All Implemented Interfaces:
IExecutionEngine
Implementation of the
execution engine that executes a program.
The program is executed sequentially from the first instruction.
This implementation manages its own execution context that is retrievable
using the getExecutionContext() method.
- Author:
- Erik Zemčík
-
Constructor Summary
ConstructorsConstructorDescriptionProgramExecutionEngine(Program program, IMemory memory, IInputSource inputSource, IOutputSink outputSink) Creates an instance ofProgramExecutionEnginethat executes a givenprogram. -
Method Summary
Modifier and TypeMethodDescriptionReturns theexecution contextmanaged by this engine.Returns a descriptor of the instruction that will be executed next by the engine.voidjumpToLabel(String label) Performs a jump to an instruction that is followed by the specifiedlabel.voidstep()Executes a single instruction on the engine'sexecution contextand moves to the next.
-
Constructor Details
-
ProgramExecutionEngine
public ProgramExecutionEngine(Program program, IMemory memory, IInputSource inputSource, IOutputSink outputSink) Creates an instance ofProgramExecutionEnginethat executes a givenprogram. This new instance uses the provided components (memory,inputSourceandoutputSink) as aexecution context.- Parameters:
program- program to executememory- memory to use during executioninputSource- input source to use during executionoutputSink- output sink to use during execution- Throws:
IllegalArgumentException- if any parameter isnull
-
-
Method Details
-
jumpToLabel
Performs a jump to an instruction that is followed by the specifiedlabel. This label must be known by theprogram, which is executed by the engine, and must be included in themapaccessible usingProgram.getJumpLabelToLinePositionMap().- Specified by:
jumpToLabelin interfaceIExecutionEngine- Parameters:
label- label to jump to- Throws:
IllegalArgumentException- iflabelisnullor emptyUnknownJumpLabelException- iflabelis not known by theprogram
-
getNextInstructionDescriptor
Returns a descriptor of the instruction that will be executed next by the engine. This method returns an emptyOptionalif the engine has reached the end of the execution.- Specified by:
getNextInstructionDescriptorin interfaceIExecutionEngine- Returns:
- instruction descriptor of the next instruction or an empty
Optional
-
step
public void step()Description copied from interface:IExecutionEngineExecutes a single instruction on the engine'sexecution contextand moves to the next.- Specified by:
stepin interfaceIExecutionEngine
-
getExecutionContext
Returns theexecution contextmanaged by this engine.- Returns:
- execution context managed by this engine
-