Пример #1
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());
 }
Пример #2
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());
        }
Пример #3
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);
 }
Пример #4
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);
        }
Пример #5
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);
            }
        }
Пример #6
0
 public void Getter()
 {
     var lc = new LensCompiler();
     lc.RegisterProperty("half", HalfValue);
     var fx = lc.Compile("half * 2");
     Assert.AreEqual(42, fx());
 }
Пример #7
0
        public void Getter()
        {
            var lc = new LensCompiler();

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

            Assert.AreEqual(42, fx());
        }
Пример #8
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
                    );
            }
        }
Пример #9
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
                );
            }
        }
Пример #10
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
                    );
            }
        }
Пример #11
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);
        }