private static Platform GetPlatform(SilkPlatform platform) { return(platform switch { SilkPlatform.Console => new ConsolePlatform(), SilkPlatform.Graphics => new GraphicsPlatform(), _ => throw new InvalidOperationException("Unknown platform specified."), });
private void CompileAndRunToolStripMenuItem_Click(object sender, EventArgs e) { string script = txtScript.Text; if (string.IsNullOrWhiteSpace(script)) { MessageBox.Show("There is no code to run."); return; } if (documentManager1.Save()) { try { lvwErrors.Items.Clear(); SilkPlatform platform = (cboPlatform.SelectedItem is SilkPlatformListItem listItem) ? listItem.Platform : SilkPlatform.Console; RunProgram runProgram = new(platform); if (!runProgram.Run(txtScript.Text)) { // Build failed: Display errors foreach (Error error in runProgram.Errors) { ListViewItem item = lvwErrors.Items.Add(error.Level.ToString()); item.SubItems.Add(string.Format("1{0,03:D3}", (int)error.Code)); item.SubItems.Add(error.Line.ToString()); item.SubItems.Add(error.Description); item.Tag = error; item.ForeColor = Color.Red; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public SilkPlatformListItem(string text, SilkPlatform platform) { Text = text; Platform = platform; }
/// <summary> /// Returns the description for the specified <see cref="SilkPlatform"/>. /// </summary> /// <param name="platform"></param> /// <returns></returns> public static string GetPlatformDescription(SilkPlatform platform) => GetEnumDescription(platform);
/// <summary> /// /// </summary> /// <param name="platform"></param> public RunProgram(SilkPlatform platform) { Platform = GetPlatform(platform); FunctionLookup = Platform.Functions.ToDictionary(f => f.Name, f => f.Handler, StringComparer.OrdinalIgnoreCase); Errors = new(); }