void RunEnd(IOStream iostream, RuntimeMachine runtime, HASMSource source) { if (InvokeRequired) { Invoke(new RunEndDelegate(RunEnd), iostream, runtime, source); } else { if (runtime == null || source == null) { toolStripLabel1.Text = "Run aborted"; Output = null; } else { Output = iostream.ReadAll(); int size = 0; //source.ParseResult.Sum(p => p.FixedSize); toolStripLabel1.Text = $"Parsed in: {Formatter.ToPrettyFormat(source.ParseTime)}" + $" | Byte code size: {size} {(HASMBase.IsSTD ? "byte" : "fbn")}{(size == 1 ? "" : "s")}" + $" | Run in: {Formatter.ToPrettyFormat(runtime.TimeOfRunning)} or {runtime.Ticks} step{(runtime.Ticks == 1 ? "" : "s")}" + $" | Result is: {Output.Count} {(HASMBase.IsSTD ? "byte" : "fbn")}{(Output.Count == 1 ? "" : "s")}"; } OutputToTextBox(); loadingCircle1.Visible = false; stopToolStripMenuItem.Enabled = false; tabControl1.Enabled = true; (tabControl1.SelectedTab as TextEditor)?.TextBox.Focus(); } }
public void Run(HASMSource source) { this.source = source; StartTime = DateTime.Now; Status = ParseTaskStatus.Running; InnerRun(); }
private void Parser_AsyncTaskChanged(ParseTaskRunner runner, HASMSource Source) { if (InvokeRequired) { Invoke(new ParseTaskRunner.AsyncTaskChangedDelegate(Parser_AsyncTaskChanged), runner, Source); } else { Tasks = runner.Tasks; OutputToTextBox(); } }
public void Run(string FileName) { HASMSource source = new HASMSource(Machine, new FileInfo(FileName.NormalizePath()), null); loadingCircle1.Visible = true; tabControl1.Enabled = false; stopToolStripMenuItem.Enabled = true; var parser = new ParseTaskRunner(source); parser.AsyncParseEnd += ParsingEnd; parser.AsyncTaskСhanged += Parser_AsyncTaskChanged; parser.RunAsync(); }
public ParseError BuildCache() { foreach (var file in PathsToCache) { HASMSource source = new HASMSource(parrent, new FileInfo(file)); ParseTaskRunner runner = new ParseTaskRunner(source); runner.Run(); if (runner.Status != ParseTaskStatus.Ok) { return(runner.Tasks[runner.FailedTaskIndex].Error); } FileCache.Add(file, new FileCache() { AbsoluteFileName = file, CompiledClasses = source.Assembly == null ? new List <Class>() : source.Assembly.Classes, CompiledDefines = PreprocessorDirective.defines ?? new List <Define>() }); } return(null); }
public void RunAsync(HASMSource source) { workingThread = new Thread(p => Run(source)); workingThread.Start(); }
public TextEditor(string path, Control parent) { InitPlatformSpecificRegexes(); path = path.NormalizePath(); Parrent = parent as Editor; if (!File.Exists(path)) { MessageBox.Show($"Unable to find file \"{path}\""); return; } TextBox = new FastColoredTextBox { Dock = DockStyle.Fill, Text = File.ReadAllText(path), BracketsHighlightStrategy = BracketsHighlightStrategy.Strategy1, AutoCompleteBrackets = true, LeftBracket = '(', RightBracket = ')', }; popupMenu = new AutocompleteMenu(TextBox) { ImageList = AutocompleteImageList, MinFragmentLength = 1 }; popupMenu.Items.SetAutocompleteItems(AutoCompleteStaticValues); popupMenu.Items.MaximumSize = new Size(300, 200); popupMenu.Items.Width = 300; HASMSource source = new HASMSource(Parrent.Machine, TextBox.Text); TaskRunner = new ParseTaskRunner(source); Directory = new FileInfo(path).Directory.FullName; DisplayName = path.Remove(0, path.LastIndexOf(PlatformSpecific.NameSeparator) + 1) + " [x]"; Text = DisplayName; if (DisplayName.EndsWith(".cfg", true, CultureInfo.InvariantCulture)) { TextBox.VisibleRangeChanged += (obj, args) => { TextBox.VisibleRange.ClearStyle(StyleIndex.All); TextBox.SyntaxHighlighter.XMLSyntaxHighlight(TextBox.VisibleRange); TextBox.SyntaxHighlighter.XmlTagNameStyle = TextBox.SyntaxHighlighter.BlueStyle; }; } else { TextBox.SyntaxHighlighter.InitStyleSchema(Language.CSharp); TextBox.ToolTipDelay = 200; TextBox.ToolTip = new ToolTip(); TextBox.DelayedTextChangedInterval = 200; TextBox.ToolTipNeeded += TextBox_ToolTipNeeded; TextBox.TextChangedDelayed += TextBox_TextChangedDelayed; } TextBox.TextChanged += TextBox_TextChanged; TextBox.KeyDown += TextBox_KeyDown; TextBox.HighlightingRangeType = HighlightingRangeType.ChangedRange; Path = path; Controls.Add(TextBox); toolStripLabel = Parrent.toolStripLabel1; }
public RuntimeMachine(HASMMachine machine, HASMSource source) { _machine = machine; _source = source; }
void ParsingEnd(ParseTaskRunner runner, HASMSource source) { if (InvokeRequired) { var del = new ParseTaskRunner.AsyncParseEndDelegate(ParsingEnd); Invoke(del, runner, source); } else { if (runner.Status == ParseTaskStatus.Failed) { ParseError error = runner.Tasks[runner.FailedTaskIndex].Error; error.Line++; MessageBox.Show($"Task \"{runner.Tasks[runner.FailedTaskIndex].Name}\" failed\n{error.ToString()}", "Parsing error", MessageBoxButtons.OK, MessageBoxIcon.Error); loadingCircle1.Visible = false; stopToolStripMenuItem.Enabled = false; tabControl1.Enabled = true; if (error.FileName != null) { bool found = false; foreach (TextEditor page in tabControl1.TabPages) { if (page.Path == error.FileName) { tabControl1.SelectedTab = page; found = true; break; } } if (!found) { AddTab(error.FileName); } if (error.Line != -1) { TextEditor tab = (tabControl1.SelectedTab as TextEditor); FastColoredTextBox tb = tab.TextBox; var minLines = 0; var maxLines = tb.LinesCount; var max = tb.VerticalScroll.Maximum; var min = tb.VerticalScroll.Minimum; var currentLine = error.Line; var maxLinesInScreen = tb.Height / tb.Font.SizeInPoints; if (tab.HighlightedLine != -1) { tb[tab.HighlightedLine].BackgroundBrush = Brushes.Transparent; tab.HighlightedLine = -1; } tab.HighlightedLine = error.Line - 1; tb[error.Line - 1].BackgroundBrush = Brushes.Pink; if (maxLinesInScreen < maxLines) { currentLine = Math.Max(Math.Abs((int)(maxLinesInScreen / 2) - currentLine) + 1, 1); int position = (int)((currentLine - minLines) * (max - min) / (float)(maxLines - minLines) + min); tb.VerticalScroll.Value = position - 1; tb.VerticalScroll.Value = position; } } } } else { IOStream stdOut = new IOStream("stdout", StreamDirection.Out); IOStream stdIn = new IOStream("stdin", StreamDirection.In); var runtime = source.Machine.CreateRuntimeMachine(source, new List <IOStream>() { stdOut, stdIn }); runThread = new Thread(p => { var result = runtime.Run(); if (result != null) { MessageBox.Show(result.ToString(), "Runtime error", MessageBoxButtons.OK, MessageBoxIcon.Error); } RunEnd(stdOut, runtime, source); }); runThread.Start(); } } }
public ParseTaskRunner(HASMSource source) { Source = source; }