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); } }
public void Getter() { var lc = new LensCompiler(); lc.RegisterProperty("half", HalfValue); var fx = lc.Compile("half * 2"); Assert.AreEqual(42, fx()); }
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); }
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 ); } }
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 ); } }
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 ); } }