예제 #1
0
 private static Platform GetPlatform(SilkPlatform platform)
 {
     return(platform switch
     {
         SilkPlatform.Console => new ConsolePlatform(),
         SilkPlatform.Graphics => new GraphicsPlatform(),
         _ => throw new InvalidOperationException("Unknown platform specified."),
     });
예제 #2
0
        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);
                }
            }
        }
예제 #3
0
 public SilkPlatformListItem(string text, SilkPlatform platform)
 {
     Text     = text;
     Platform = platform;
 }
예제 #4
0
 /// <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);
예제 #5
0
 /// <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();
 }