/// <summary> /// Sends input to the interpreter thread and unlocks it /// </summary> private void SendInput() { if (DebuggerFlags.NoInputInConsoleFlag == false) { Console.ConsoleText += ">" + Console.InputText + Environment.NewLine; } _embeddedInterpreter.Input = Console.InputText + (DebuggerFlags.NoNewLineFlag ? "" : Environment.NewLine); IsTaskWaitingForInput = false; InputType = null; _embeddedInterpreter.WaitHandle.Set(); Console.InputText = ""; }
/// <summary> /// Sends a request to stop the interpreter thread /// </summary> private void EndCurrentInterpreterTask() { _cancellationTokenSource?.Cancel(); _embeddedInterpreter?.WaitHandle.Set(); if (IsDebuggingMode) { IsDebuggingMode = false; CurrentView = _editorView; } if (_isTaskRunning) { _isTaskRunning = false; } IsTaskWaitingForInput = false; InputType = null; }
/// <summary> /// Adds handlers to communicate with the interpreter thread /// </summary> /// <param name="debugMode"></param> private void AddHandlersToInterpreterThread(DebugMode debugMode) { _embeddedInterpreter.NewOutputEvent += new EventHandler <OutputEventArgs>(delegate(Object o, OutputEventArgs a) { if (a.Type == OutputType.Character) { Console.ConsoleText += a.CharacterOutput; } else { Console.ConsoleText += a.LineOutput + (a.RuntimeError ? "" : Environment.NewLine); } if (a.RuntimeError) { Console.ConsoleText += _mapRealLineNumbersWithRaw[a.LineNumberErrorHandling] + 1 + Environment.NewLine; } }); _embeddedInterpreter.WaitingForInputEvent += new EventHandler <WaitingForInputEventArgs>((_, a) => { IsTaskWaitingForInput = true; InputType = a; }); if (debugMode == DebugMode.StepByStep) { _embeddedInterpreter.PancakeStackChangedEvent += new EventHandler <Stack <int> >((o, a) => Debugger.Stack = a.ToList()); _embeddedInterpreter.LabelDictionaryChangedEvent += new EventHandler <Dictionary <string, int> >((_, a) => Debugger.Label = a.Select(x => new KeyValuePair <string, Tuple <int, int> >(x.Key, new Tuple <int, int>(x.Value + 2, _mapRealLineNumbersWithRaw[x.Value + 1] + 1))).ToList()); } _embeddedInterpreter.EndOfExecutionEvent += new EventHandler((o, a) => EndCurrentInterpreterTask()); }