/// <summary> /// Validates the code and runs it in the built-in interpreter in a new thread /// </summary> private void RunInterpreter() { EndCurrentInterpreterTask(); Console.ConsoleText = ""; var validateCode = new ValidateSourceCode(Document.Text); _mapRealLineNumbersWithRaw = validateCode.MapRealLineNumbersWithRaw(); if (!validateCode.CheckIfCodeEndsWithEatAllOfThePancakesInstruction()) { Console.ConsoleText = "The code must end with an \"Eat all of the pancakes!\" instruction"; return; } if (validateCode.ValidateInstructions().Item1) { _embeddedInterpreter = new EmbeddedInterpreter(validateCode.ValidSourceCode); AddHandlersToInterpreterThread(DebugMode.Continuous); _cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = _cancellationTokenSource.Token; _interpreterTask = Task.Factory.StartNew(() => _embeddedInterpreter.StartExecuting(cancellationToken), cancellationToken); _isTaskRunning = true; } else { Console.ConsoleText = string.Format("Instruction on line {0} cannot be found{1}", _mapRealLineNumbersWithRaw[validateCode.ValidateInstructions().Item2] + 1, Environment.NewLine); } }
public void MapRealLineNumbersWithRaw_ShouldMapRawCodeLinesWithPreparedAndBeDifferent_WhenInlineCommentAndBlankSpaces() { var result = testClassWithInlineCommentsAndBlankSpaces.MapRealLineNumbersWithRaw(); var values = result.Values.ToList(); var keys = result.Keys.ToList(); Assert.IsFalse(Enumerable.SequenceEqual(values, keys)); }
public void MapRealLineNumbersWithRaw_ShouldMapRawCodeLinesWithPreparedAndBeTheSame_WhenInlineComment() { var result = testClassWithInlineComments.MapRealLineNumbersWithRaw(); var values = result.Values.ToList(); var keys = result.Keys.ToList(); Assert.IsTrue(Enumerable.SequenceEqual(values, keys)); }
/// <summary> /// Validates the code and runs it in the built-in interpreter with only one instruction per call in a new thread /// </summary> private void NextInstruction() { if (!IsDebuggingMode) { var validateCode = new ValidateSourceCode(Document.Text); _mapRealLineNumbersWithRaw = validateCode.MapRealLineNumbersWithRaw(); if (!validateCode.CheckIfCodeEndsWithEatAllOfThePancakesInstruction()) { Console.ConsoleText = "The code must end with an \"Eat all of the pancakes!\" instruction"; return; } if (validateCode.ValidateInstructions().Item1) { _embeddedInterpreter = new EmbeddedInterpreter(validateCode.ValidSourceCode); DebugDocument.Lines = new System.Collections.ObjectModel.ObservableCollection <TextLine>(Document.Text.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.None).Select(x => new TextLine() { Text = x, BackgroundColor = Brushes.Transparent })); var startLine = 0; _mapRealLineNumbersWithRaw.TryGetValue(0, out startLine); DebugDocument.LinePointer = startLine; _previousInstruction = startLine; CurrentView = _editorDebugView; Console.ConsoleText = ""; AddHandlersToInterpreterThread(DebugMode.StepByStep); IsDebuggingMode = true; Debugger.Stack = null; Debugger.Label = null; } else { Console.ConsoleText = string.Format("Instruction on line {0} cannot be found{1}", _mapRealLineNumbersWithRaw[validateCode.ValidateInstructions().Item2] + 1, Environment.NewLine); } } else if (!IsTaskWaitingForInput) { DebugDocument.Lines[_previousInstruction].BackgroundColor = Brushes.Transparent; DebugDocument.Lines[_previousInstruction].ForegroundColor = Brushes.White; _cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = _cancellationTokenSource.Token; _interpreterTask = Task.Factory.StartNew(() => _embeddedInterpreter.ExecuteNext(cancellationToken), cancellationToken).ContinueWith((_) => { var line = 0; // if error _mapRealLineNumbersWithRaw.TryGetValue(_embeddedInterpreter.ProgramIterator, out line); DebugDocument.LinePointer = line; _previousInstruction = line; }); } }