/// <returns>Instruction successful</returns> public bool StepForward() { if (index == -1) { return(false); } // Save current machine state prevStates.AddLast(new MachineState(index, Registers, Stack)); if (prevStates.Count >= MaxStates) { prevStates.RemoveFirst(); } // Execute next instruction Instruction inst = file.Instructions[index]; bool success = inst.Execute(Registers, Stack, ref index); // Skip comments while (0 <= index && index < file.Instructions.Count && file.Instructions[index] is Comment) { index++; } // Detect end of program if (index >= file.Instructions.Count) { index = -1; } OnInstructionReady?.Invoke(index, success); return(success); }
/// <returns>Successful (always true)</returns> public bool Start(int startIndex) { index = startIndex; prevStates = new LinkedList <MachineState>(); OnInstructionReady?.Invoke(index, true); return(true); }
/// <returns>Instruction successful (true if a previous state exists, false otherwise)</returns> public bool StepBackward() { if (prevStates.Count == 0) { return(false); } MachineState last = prevStates.Last(); last.Restore(Registers, Stack); prevStates.RemoveLast(); index = last.InstIndex; OnInstructionReady?.Invoke(index, true); return(true); }
/// <returns>Instruction successful (always false)</returns> public bool Ignore() { index++; OnInstructionReady?.Invoke(index, false); return(false); }