// public virtual async Task <VirtualMachineActionPosition> BreakAsync() { if (!_IsProgrammed) { throw new MachineNotProgrammedYetException(); } if (_Status != VirtualMachineRunningStatus.StandBy && _Status != VirtualMachineRunningStatus.Breaking) { _Status = VirtualMachineRunningStatus.Breaking; OnStatusChanged(_Status); await Task.Run(() => { Thread.CurrentThread.Name = $"{this.Title} Breaking Watcher Thread"; while (_Status != VirtualMachineRunningStatus.StandBy) { Thread.Sleep(_StatusWaitingCheckEveryTimeMS); } }); return((VirtualMachineActionPosition)_NextSymbol); } else { throw new ImpossibleActionAtTheMomentException(_NextSymbol, _ActionCell); } }
public async Task <VirtualMachineRunResult> StartAsync() { if (!_Programmed) { throw new MachineNotProgrammedYetException(); } VirtualMachineRunResult RES; if (_Status == VirtualMachineRunningStatus.StandBy) { _ActionCell = _CodeLength + 1; _Status = VirtualMachineRunningStatus.Runtime; StatusChanged?.Invoke(this, new VirtualMachineStatusChangedEventArgs(_Status, _NextSymbol)); RES = await Task <VirtualMachineRunResult> .Factory.StartNew(() => Run(0, 0, 0)); if (_Status != VirtualMachineRunningStatus.StandBy) { _Status = VirtualMachineRunningStatus.StandBy; StatusChanged?.Invoke(this, new VirtualMachineStatusChangedEventArgs(_Status, _NextSymbol)); } return(RES); } else { throw new ImpossibleActionAtTheMomentException(_NextSymbol, _ActionCell); } }
// public virtual async Task <VirtualMachineActionPosition> StepAsync() { if (!_IsProgrammed) { throw new MachineNotProgrammedYetException(); } switch (_Status) { case VirtualMachineRunningStatus.Paused: _Status = VirtualMachineRunningStatus.Stepping; OnStatusChanged(_Status); break; default: throw new MachineIsRunningAlreadyException(_NextSymbol, _ActionCell); } await Task.Run(() => { Thread.CurrentThread.Name = $"{this.Title} Stepping Watcher Thread"; while (_Status != VirtualMachineRunningStatus.Paused && _Status != VirtualMachineRunningStatus.StandBy) { Thread.Sleep(_StatusWaitingCheckEveryTimeMS); } OnStatusChanged(_Status); }); return((VirtualMachineActionPosition)_NextSymbol); }
public ClassicBFmachine(int caretBound = 30000, bool overBound = true, bool unLimit = true, byte interruptingPeriod = 20) { _CaretBound = caretBound; _RoundCaretRange = overBound; _RoundValueRange = unLimit; _CharSet = Encoding.Default; _ByteOrder = ByteOrders.LittleEndian; _InterruptingPeriod = interruptingPeriod; _Status = VirtualMachineRunningStatus.StandBy; ResetAsync(); }
public async Task <VirtualMachineActionPosition> BreakAsync() { if (!_Programmed) { return(VirtualMachineActionPosition.Invalid); } if (_Status == VirtualMachineRunningStatus.Runtime) { _Status = VirtualMachineRunningStatus.Breaking; } else { return(VirtualMachineActionPosition.Invalid); } StatusChanged?.Invoke(this, new VirtualMachineStatusChangedEventArgs(_Status, _NextSymbol)); return((VirtualMachineActionPosition)_NextSymbol); }
public async Task ResetAsync() { if (_Status == VirtualMachineRunningStatus.Runtime) { BreakAsync(); while (_Status != VirtualMachineRunningStatus.StandBy) { Application.DoEvents(); } } _RunningTask = null; MRAM = new byte[_CaretBound - 1]; _CodeLength = 0; _Programmed = false; if (_Status != VirtualMachineRunningStatus.StandBy) { _Status = VirtualMachineRunningStatus.StandBy; StatusChanged?.Invoke(this, new VirtualMachineStatusChangedEventArgs(_Status, _NextSymbol)); } _NextSymbol = 0; _ActionCell = 0; }
public VirtualMachineStatusChangedEventArgs(VirtualMachineRunningStatus newStatus, int nextSymbol) { NewStatus = newStatus; NextSymbol = nextSymbol; }
// protected virtual void OnStatusChanged(VirtualMachineRunningStatus newStatus) { StatusChanged?.Invoke(this, new VirtualMachineStatusChangedEventArgs(newStatus, NextSymbol)); }
public ClassicBFmachine() { _Status = VirtualMachineRunningStatus.StandBy; DefaultSettings(true); }