public ReplWindow() { this.Width = 450; this.Height = 350; this.Title = "YACQ Console"; this.Content = this.textBox; this.textBox.AcceptsReturn = true; this.textBox.BorderThickness = new Thickness(0); this.textBox.FontFamily = new FontFamily("Consolas"); this.textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; this.textBox.VerticalScrollBarVisibility = ScrollBarVisibility.Visible; this.textBox.TextWrapping = TextWrapping.Wrap; this.textBox.Text = string.Format("YACQ {0} on Krile {1}\r\n", YacqServices.Version, typeof(App).Assembly.GetName().Version); this.textBox.Select(this.textBox.Text.Length, 0); this.textBox.PreviewKeyDown += this.textBox_PreviewKeyDown; this.symbolTable = new SymbolTable(YacqFilter.FilterSymbols, typeof(Symbols)) { { "*textbox*", YacqExpression.Constant(textBox) }, }; var rcPath = Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "yacq_lib\\rc.yacq" ); if (File.Exists(rcPath)) { YacqServices.ParseAll(this.symbolTable, File.ReadAllText(rcPath)) .ForEach(e => YacqExpression.Lambda(e).Compile().DynamicInvoke()); this.textBox.AppendText("rc.yacq was loaded.\r\n"); } this.textBox.AppendText(">>> "); }
public static void Main(string[] args) { var scriptFile = "EntryPoint.yacq"; if (args.Any()) { scriptFile = args[0]; } foreach (var exp in YacqServices.ParseAll(new SymbolTable(), File.ReadAllText(scriptFile))) { Expression.Lambda(exp).Compile().DynamicInvoke(); } }
private static Expression Parse(SymbolTable symbols, String code) { try { return(YacqServices.ParseAll(symbols, code) .Let(es => es.Length == 1 ? es.Single() : Expression.Block(es) )); } catch (Exception ex) { Fail(ex, Phase.Parse); return(null); } }
private void RunCode(string file) { try { YacqServices.ParseAll(new SymbolTable(), File.ReadAllText(file)) .Select(exp => Expression.Lambda(exp).Compile()) .ToArray() //全部コンパイルしてから .ForEach(dlg => dlg.DynamicInvoke()); } catch (Exception ex) { ExceptionStorage.Register( ex, ExceptionCategory.PluginError, string.Format("{0} の実行に失敗しました: {1}", Path.GetFileName(file), ex.Message), () => this.RunCode(file) ); } }
public void Start() { this._stopwatch.Start(); var expressions = Arrays.Empty <Expression>(); try { expressions = YacqServices.ParseAll(this._symbols, this._code); expressions .Select(e => Tuple.Create(Node.Serialize(e), TypeRef.Serialize(e.Type))) .ForEach(_ => this.NotifyParsed(_.Item1, _.Item2)); this._parsedExpressions.OnCompleted(); this.Log(LogEntry.Info, "Parsing completed."); } catch (Exception ex) { // BUG: causes cross-AppDomain problem // this._parsedExpressions.OnError(ex); this.Log(LogEntry.Error, "Failed to parse: " + ex); } try { expressions .Select(e => e.Evaluate(this._symbols) .If( o => o is IEnumerable && !o.GetType().Let(t => t.IsMarshalByRef || t.IsSerializable), o => ((IEnumerable)o).Cast <Object>().Remotable() ) ) .ForEach(this.NotifyReturned); this._returnValues.OnCompleted(); this.Log(LogEntry.Info, "Evaluation completed."); } catch (Exception ex) { this._returnValues.OnError(ex); this.Log(LogEntry.Error, "Failed to evaluate: " + ex); } }