Beispiel #1
0
        private static void Main()
        {
            PrintPreamble();
            WarmUp();

            var timer = false;

            while (RequestInput(out var source, ref timer))
            {
                Console.WriteLine();
                try
                {
                    var lc = new LensCompiler(new LensCompilerOptions {
                        AllowSave = true, MeasureTime = timer
                    });
                    var res = lc.Run(source);
                    PrintObject(res);

                    if (timer)
                    {
                        PrintMeasurements(lc.Measurements);
                    }
                }
                catch (LensCompilerException ex)
                {
                    PrintError(source, ex);
                }
                catch (Exception ex)
                {
                    PrintException("An unexpected error has occured!", ex.Message + Environment.NewLine + ex.StackTrace);
                }
            }
        }
Beispiel #2
0
        public void Run()
        {
            var lc = new LensCompiler();

            lc.RegisterType(typeof(Figure));
            lc.RegisterType("Rect", typeof(Rect));
            lc.RegisterType("Circle", typeof(Circle));
            lc.RegisterProperty("Screen", () => m_Manager);

            try
            {
                var fx = lc.Compile(Code);
                fx();

                Status = Status.Success;

                m_Manager.Draw();
            }
            catch (LensCompilerException ex)
            {
                Status       = Status.Error;
                ErrorMessage = ex.FullMessage;
                MarkErrorLocation(ex);
            }
        }
Beispiel #3
0
 public void Getter()
 {
     var lc = new LensCompiler();
     lc.RegisterProperty("half", HalfValue);
     var fx = lc.Compile("half * 2");
     Assert.AreEqual(42, fx());
 }
Beispiel #4
0
 public void Statics()
 {
     SetX(1337);
     var lc = new LensCompiler();
     lc.RegisterProperty("x", GetX);
     lc.RegisterProperty("y", GetY, SetY);
     lc.Run("y = x - 337");
     Assert.AreEqual(1000, GetY());
 }
Beispiel #5
0
        public void Getter()
        {
            var lc = new LensCompiler();

            lc.RegisterProperty("half", HalfValue);
            var fx = lc.Compile("half * 2");

            Assert.AreEqual(42, fx());
        }
Beispiel #6
0
        private static LensCompiler createCompiler(LensCompilerOptions opts)
        {
            var compiler = new LensCompiler(opts ?? new LensCompilerOptions {
                AllowSave = true
            });

            compiler.RegisterAssembly(Assembly.Load("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"));
            return(compiler);
        }
Beispiel #7
0
 public void Lambdas()
 {
     var x = 10;
     var y = 0;
     var lc = new LensCompiler();
     lc.RegisterProperty("x", () => x, nx => x = nx);
     lc.RegisterProperty("y", () => y, ny => y = ny);
     lc.Run("y = x + 32");
     Assert.AreEqual(42, y);
 }
Beispiel #8
0
        public void Statics()
        {
            SetX(1337);
            var lc = new LensCompiler();

            lc.RegisterProperty("x", GetX);
            lc.RegisterProperty("y", GetY, SetY);
            lc.Run("y = x - 337");
            Assert.AreEqual(1000, GetY());
        }
Beispiel #9
0
        public void Lambdas()
        {
            var x  = 10;
            var y  = 0;
            var lc = new LensCompiler();

            lc.RegisterProperty("x", () => x, nx => x = nx);
            lc.RegisterProperty("y", () => y, ny => y = ny);
            lc.Run("y = x + 32");
            Assert.AreEqual(42, y);
        }
Beispiel #10
0
        public void RandTest3()
        {
            var src  = "rand (new [1; 2; 3; 4; 5])";
            var opts = new LensCompilerOptions();
            var fx   = new LensCompiler(opts).Compile(src);

            for (var idx = 0; idx < 100; idx++)
            {
                var res = (int)fx();
                Assert.IsTrue(res >= 1 && res <= 5);
            }
        }
Beispiel #11
0
        public void RandTest2()
        {
            var src  = "rand 1 1000";
            var opts = new LensCompilerOptions();
            var fx   = new LensCompiler(opts).Compile(src);

            for (var idx = 0; idx < 1000; idx++)
            {
                var res = (int)fx();
                Assert.IsTrue(res >= 1 && res <= 1000);
            }
        }
Beispiel #12
0
        public void RandTest1()
        {
            var src  = "rand ()";
            var opts = new LensCompilerOptions();
            var fx   = new LensCompiler(opts).Compile(src);

            for (var idx = 0; idx < 1000; idx++)
            {
                var res = (double)fx();
                Assert.IsTrue(res >= 0 && res <= 1);
            }
        }
Beispiel #13
0
        protected static LensCompiler CreateCompiler(LensCompilerOptions opts)
        {
            var compiler = new LensCompiler(opts ?? new LensCompilerOptions
            {
                #if NET_CLASSIC
                AllowSave = true
                #endif
            });

            compiler.RegisterAssembly(Assembly.Load("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"));
            return(compiler);
        }
Beispiel #14
0
        public void RandTest2()
        {
            var src = "rand 1 1000";
            var opts = new LensCompilerOptions { AllowSave = true };
            var fx = new LensCompiler(opts).Compile(src);

            for (var idx = 0; idx < 1000; idx++)
            {
                var res = (int)fx();
                Assert.IsTrue(res >= 1 && res <= 1000);
            }
        }
Beispiel #15
0
        public void RandTest1()
        {
            var src = "rand ()";
            var opts = new LensCompilerOptions { AllowSave = true };
            var fx = new LensCompiler(opts).Compile(src);

            for (var idx = 0; idx < 1000; idx ++)
            {
                var res = (double) fx();
                Assert.IsTrue(res >= 0 && res <= 1);
            }
        }
Beispiel #16
0
        public async Task RunAsync()
        {
            var compiler = new LensCompiler();

            foreach (var entry in Container.Names)
            {
                var name = entry.Value;
                var type = entry.Key;

                compiler.RegisterProperty(name, () => Container.Resolve(type));
            }
            var compiled = compiler.Compile(Code);
            await Task.Run(compiled);
        }
Beispiel #17
0
        private void run()
        {
            var lens = new LensCompiler();

            var currX = getDouble(StartPos, -10);
            var endX  = getDouble(EndPos, 10);
            var currY = 0.0;
            var step  = getDouble(Step, 0.1);

            var obs = new ObservableDataSource <Point>();

            obs.SetXYMapping(p => p);

            if (m_PreviousGraph != null)
            {
                m_PreviousGraph.Remove();
            }

            m_PreviousGraph = Chart.AddLineGraph(obs, Colors.Green, 2, "Graph");

            lens.RegisterProperty("x", () => currX);
            lens.RegisterProperty("y", () => currY, y => currY = y);

            try
            {
                var fx = lens.Compile(Func.Text);

                while (currX < endX)
                {
                    fx();
                    obs.AppendAsync(Chart.Dispatcher, new Point(currX, currY));
                    currX += step;
                }
            }
            catch (LensCompilerException ex)
            {
                MessageBox.Show(
                    ex.FullMessage,
                    "Compilation Error",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error
                    );
            }
        }
Beispiel #18
0
        private void run()
        {
            var lens = new LensCompiler();

            var currX = getDouble(StartPos, -10);
            var endX = getDouble(EndPos, 10);
            var currY = 0.0;
            var step = getDouble(Step, 0.1);

            var obs = new ObservableDataSource<Point>();
            obs.SetXYMapping(p => p);

            if (m_PreviousGraph != null)
                m_PreviousGraph.Remove();

            m_PreviousGraph = Chart.AddLineGraph(obs, Colors.Green, 2, "Graph");

            lens.RegisterProperty("x", () => currX);
            lens.RegisterProperty("y", () => currY, y => currY = y);

            try
            {
                var fx = lens.Compile(Func.Text);

                while (currX < endX)
                {
                    fx();
                    obs.AppendAsync(Chart.Dispatcher, new Point(currX, currY));
                    currX += step;
                }
            }
            catch (LensCompilerException ex)
            {
                MessageBox.Show(
                    ex.FullMessage,
                    "Compilation Error",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error
                );
            }
        }
Beispiel #19
0
        private void Run()
        {
            var lens = new LensCompiler();

            var currX = GetDouble(StartPos, -10);
            var endX  = GetDouble(EndPos, 10);
            var currY = 0.0;
            var step  = GetDouble(Step, 0.1);

            lens.RegisterProperty("x", () => currX);
            lens.RegisterProperty("y", () => currY, y => currY = y);

            IEnumerable <(double x, double y)> GenerateValues()
            {
                var fx = lens.Compile(Func.Text);

                while (currX < endX)
                {
                    fx();
                    yield return(currX, currY);

                    currX += step;
                }
            }

            try
            {
                var values = GenerateValues().ToList();
                Graph.Plot(values.Select(v => v.x), values.Select(v => v.y));
            }
            catch (LensCompilerException ex)
            {
                MessageBox.Show(
                    ex.FullMessage,
                    "Compilation Error",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error
                    );
            }
        }
Beispiel #20
0
        static void Main()
        {
            printPreamble();

            string source;
            var timer = false;
            while (RequestInput(out source, ref timer))
            {
                Console.WriteLine();
                try
                {
                    var lc = new LensCompiler(new LensCompilerOptions { AllowSave = true, MeasureTime = timer });
                    var res = lc.Run(source);
                    printObject(res);

                    if (timer)
                        printMeasurements(lc.Measurements);
                }
                catch (LensCompilerException ex)
                {
                    printError(source, ex);
                }
                catch (Exception ex)
                {
                    printException("An unexpected error has occured!", ex.Message + Environment.NewLine + ex.StackTrace);
                }
            }
        }
Beispiel #21
0
        private static void WarmUp()
        {
            var compiler = new LensCompiler(new LensCompilerOptions());

            compiler.Run("1 + 2");
        }
Beispiel #22
0
 private static LensCompiler createCompiler(LensCompilerOptions opts)
 {
     var compiler = new LensCompiler(opts ?? new LensCompilerOptions { AllowSave = true });
     compiler.RegisterAssembly(Assembly.Load("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"));
     return compiler;
 }