예제 #1
0
파일: REPL.cs 프로젝트: tiesont/CSharpEval
 private REPL(TypeParser parser)
 {
     DisplayData = new REPLData()
     {
         Packets =
         {
             new REPLData.Packet()
             {
                 User ={ ""            }
             }
         }
     };
     Parser = parser;
     Maker  = new MakeClass(Parser);
 }
예제 #2
0
        static public void MakeClass1()
        {
            SetUpTypeParser();
            MakeClass                  mc = new MakeClass(parser, LexList.Get(@"
       partial class Examples.TestClass   
       {
         public int GetTwoTimesTheInt () 
         {
           return TheInt * 2 ;
         }

         public void SetTheString ( string s )
         {
           TheString = s ; 
         }
       }"));
            Func <TestClass, int>      GetTwoTimesTheInt;
            Action <TestClass, string> SetTheString;

            mc.GetFunc <TestClass, int>(
                "GetTwoTimesTheInt", out GetTwoTimesTheInt);
            mc.GetAction <TestClass, string>(
                "SetTheString", out SetTheString);

            TestClass tc = new TestClass();

            tc.TheInt = 34;
            int i = GetTwoTimesTheInt(tc);

            if (i != 68)
            {
                MessageBox.Show("MakeClass1 error 1");
            }
            SetTheString(tc, "New string value");
            if (tc.TheString != "New string value")
            {
                MessageBox.Show("MakeClass1 error 2");
            }
        }
예제 #3
0
        static public void MakeClass4()
        {
            SetUpTypeParser();
            Func <TestClass, int> GetIntValue;
            Action <TestClass>    Init;
            MakeClass             mc = new MakeClass(parser, LexList.Get(@"
       partial class Examples.TestClass   
       {
         public int LastIntValue  ; 
         public int GetIntValue ()  
         {
           LastIntValue = TheInt ; 
           return TheInt ; 
         }
       }")).
                                       GetFunc <TestClass, int>("GetIntValue", out GetIntValue).
                                       GetAction <TestClass>("FieldsInitialiser", out Init);

            TestClass tc1 = new TestClass();

            tc1.TheInt = 22;
            Init(tc1);
            int i = GetIntValue(tc1);

            // i is 22 and so is LastIntValue
            if (i != 22 || tc1.Fields == null || tc1.Fields.Count < 1 || tc1.Fields[0] == null || !(tc1.Fields[0] is int) || ((int)(tc1.Fields[0])) != 22)
            {
                MessageBox.Show("Error 1 in makeClass4 ");
            }
            tc1.TheInt = 33;
            int j = GetIntValue(tc1);

            // j is 33 and so is LastIntValue
            if (j != 33 || tc1.Fields == null || tc1.Fields.Count < 1 || tc1.Fields[0] == null || !(tc1.Fields[0] is int) || ((int)(tc1.Fields[0])) != 33)
            {
                MessageBox.Show("Error 2 in makeClass4 ");
            }
            TestClass tc2 = new TestClass();

            Init(tc2);
            tc2.TheInt = 100;
            int k = GetIntValue(tc2);

            // k is 100 and so is LastIntValue
            if (k != 100 || tc2.Fields == null || tc2.Fields.Count < 1 || tc2.Fields[0] == null || !(tc2.Fields[0] is int) || ((int)(tc2.Fields[0])) != 100)
            {
                MessageBox.Show("Error 3 in makeClass4 ");
            }

            Action <TestClass, string> AddString;

            mc.AddMethodsAndFields(LexList.Get(@"
        partial class Examples.TestClass 
        {
          public List<string> ListOfStrings ; 
          public void AddString ( string s ) 
          { 
            if (ListOfStrings == null) 
              ListOfStrings = new List<string> () ; 
            ListOfStrings.Add ( s ) ; 
          }
        }"), true).
            GetAction <TestClass, string>("AddString", out AddString);

            Init(tc1);
            AddString(tc1, "String One");
            AddString(tc1, "String Two");
            if (tc1.Fields == null || tc1.Fields.Count < 2 || tc1.Fields[1] == null || !(tc1.Fields[1] is List <string>) ||
                ((List <string>)(tc1.Fields[1])).Count != 2 ||
                ((List <string>)(tc1.Fields[1]))[0] != "String One" ||
                ((List <string>)(tc1.Fields[1]))[1] != "String Two"
                )
            {
                MessageBox.Show("Error 4 in makeClass4 ");
            }
        }
예제 #4
0
        static public void MakeClass3()
        {
            SetUpTypeParser();
            Func <TestClass, int>      GetTwoTimesTheInt;
            Action <TestClass, string> SetTheString;
            MakeClass mc = new MakeClass(parser, LexList.Get(@"
       partial class Examples.TestClass   
       {
         public int GetTwoTimesTheInt () 
         {
           return TheInt * 2 ;
         }

         public void SetTheString ( string s )
         {
           TheString = s ; 
         }
       }")).
                           GetFunc <TestClass, int>(
                "GetTwoTimesTheInt", out GetTwoTimesTheInt).
                           GetAction <TestClass, string>(
                "SetTheString", out SetTheString);

            TestClass tc = new TestClass();

            tc.TheInt = 34;
            int i = GetTwoTimesTheInt(tc);

            if (i != 68)
            {
                MessageBox.Show("MakeClass1 error 1");
            }
            SetTheString(tc, "New string value");
            if (tc.TheString != "New string value")
            {
                MessageBox.Show("MakeClass3 error 2");
            }


            Action <TestClass, string, int> SetStringAndInt;

            mc.AddMethodsAndFields(LexList.Get(@"
        partial class Examples.TestClass   
        {
          public void SetStringAndInt ( string s , int i ) 
          {
            TheInt = i ;
            SetTheString ( s ) ; 
          }
        }"), true).
            GetAction <TestClass, string, int>(
                "SetStringAndInt", out SetStringAndInt);

            SetStringAndInt(tc, "Hello", 777);
            if (tc.TheString != "Hello" || tc.TheInt != 777)
            {
                MessageBox.Show("MakeClass3 error 3");
            }


            mc.AddMethodsAndFields(LexList.Get(@"
         partial class Examples.TestClass   
         {
           public void SetStringAndInt ( string s , int i ) 
           {
             TheInt = i * 100 ;
             SetTheString ( s ) ; 
           }
         }"), true);

            SetStringAndInt(tc, "Goodbye", 11);
            if (tc.TheString != "Goodbye" || tc.TheInt != 1100)
            {
                MessageBox.Show("MakeClass3 error 4");
            }
        }
예제 #5
0
        public static void Main()
        {
            LexToken.ShowError = (msg, theList) =>
            {
                new LexErrorDialog()
                {
                    Message      = msg,
                    CompilerList = theList,
                }.Show();
            };

            TypeParser parser = new TypeParser(Assembly.GetExecutingAssembly(), new List <string>()
            {
                "System",
                "System.Collections.Generic",
                "System.Linq",
                "System.Text",
                "System.Windows",
                "System.Windows.Shapes",
                "System.Windows.Controls",
                "System.Windows.Media",
                "System.IO",
                "System.Reflection",
                "Kamimu"
            }
                                               );

            TypeParser.DefaultParser = parser;



            Directory.CreateDirectory(@"C:\KamimuCodeTemp");
            Persist.ReadFromFile(@"C:\KamimuCodeTemp\CsharpEvalConfiguration.xml");

            try {
                {
                    Func <TestClass, int>     getLength;
                    Action <TestClass, int[]> setArray;
                    Action <TestClass>        actInit;
                    MakeClass mc = new MakeClass(parser, LexList.Get(@"
          partial class TestClass 
          {
            public int[] LocalInt ;
            public void SetArray ( int[] input ) 
            {
              LocalInt = input ; 
            }   
            public int GetLength () { return LocalInt.Length ; }
          }")).
                                   GetFunc <TestClass, int>("GetLength", out getLength).
                                   GetAction <TestClass, int[]>("SetArray", out setArray).
                                   GetAction <TestClass>("FieldsInitialiser", out actInit);
                    TestClass tc = new TestClass();
                    actInit(tc);
                    int[] thearray = new int[300];
                    setArray(tc, thearray);
                    if (getLength(tc) != thearray.Length)
                    {
                        MessageBox.Show("There was an error", "Test class with dialog");
                    }
                    else
                    {
                        MessageBox.Show("Ran OK", "Test class with dialog");
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show("There was a compilation or execution error.", "Test class with dialog");
            }

            Persist.WriteToFile();
        }
        public static void Main()
        {
            LexToken.ShowError = (msg, theList) =>
            {
                MessageBox.Show(msg + "\n" + theList.CodeFormat, "Error found");
            };

            TypeParser parser = new TypeParser(Assembly.GetExecutingAssembly(), new List <string>()
            {
                "System",
                "System.Collections.Generic",
                "System.Linq",
                "System.Text",
                "System.Windows",
                "System.Windows.Shapes",
                "System.Windows.Controls",
                "System.Windows.Media",
                "System.IO",
                "System.Reflection",
                "Kamimu"
            }
                                               );

            TypeParser.DefaultParser = parser;


            try {
                {
                    Func <TestClass, int>     getLength;
                    Action <TestClass, int[]> setArray;
                    Action <TestClass>        actInit;
                    MakeClass mc = new MakeClass(parser, LexList.Get(@"
          partial class TestClass 
          {
            public int[] LocalInt ;
            public void SetArray ( int[] input ) 
            {
              LocalInt = input ; 
            }   
            public int GetLength () { return LocalInt.Length ; }
          }")).
                                   GetFunc <TestClass, int>("GetLength", out getLength).
                                   GetAction <TestClass, int[]>("SetArray", out setArray).
                                   GetAction <TestClass>("FieldsInitialiser", out actInit);
                    TestClass tc = new TestClass();
                    actInit(tc);
                    int[] thearray = new int[300];
                    setArray(tc, thearray);
                    if (getLength(tc) != thearray.Length)
                    {
                        MessageBox.Show("There was an error", "Test class with dialog");
                    }
                    else
                    {
                        MessageBox.Show("Ran OK", "Test class with dialog");
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show("There was a compilation or execution error.", "Test class with dialog");
            }
        }