public static void Main(String[] myArgs)
        {
            _Compiler = new Runner();

            //var a = _Compiler.Execute("Math.Abs(-42);");
            //Assert.AreEqual(42, a);

            //var b = _Compiler.Execute("class Fact { public int Run(int n) { return n <= 0 ? 1 : n*Run(n-1); } }");
            //var c = _Compiler.Execute("new Fact().Run(5);");
            //Assert.AreEqual(120, c);

            //var d = _Compiler.Execute("\"abcdefgh\".Substring(1, 2);");
            //Assert.AreEqual("bc", d);

            //var e = _Compiler.Execute("var test = 123;");
            //Assert.AreEqual("bc", e);

            #region Feel free to step through...

            _Compiler = new Runner();
            var a = _Compiler.Execute("Math.Abs(-42);");
            var b = _Compiler.Execute("Math.Sin(Math.PI / 6);");
            var c = _Compiler.Execute("class Fact { public int Run(int n) { return n <= 0 ? 1 : n*Run(n-1); } }");
            var d = _Compiler.Execute("new Fact().Run(5);");
            var e = _Compiler.Execute("\"abcdefgh\".Substring(1, 2);");
            var f = _Compiler.Execute("class Echo { public Object Print(Object o) { return o; } }");
            var g = _Compiler.Execute("var test = 123;");
            var h = _Compiler.Execute("new Echo().Print(test);");

            #endregion

            #region Start the interactive (read-eval-print loop) shell...

            var _Report = new Report(new ConsoleReportPrinter());
            var _CLP    = new CommandLineParser(_Report);
                _CLP.UnknownOptionHandler += Mono.Driver.HandleExtraArguments;

            var _Settings = _CLP.ParseArguments(myArgs);
            if (_Settings == null || _Report.Errors > 0)
                Environment.Exit(1);

            var _Evaluator = new Evaluator(_Settings, _Report)
            {
                InteractiveBaseClass    = typeof(InteractiveBaseShell),
                DescribeTypeExpressions = true
            };

            //// Adding a assembly twice will lead to delayed errors...
            //_Evaluator.ReferenceAssembly(typeof(YourAssembly).Assembly);

            var _CSharpShell = new CSharpShell(_Evaluator).Run();

            #endregion
        }
Example #2
0
        public MainPage()
        {
            _runner = new Runner();

            History = new ObservableCollection<RunBlock>();

            History.Add(new RunBlock("Math.Abs(-42);"));
            History.Add(new RunBlock("Math.Sin(Math.PI / 6);"));
            History.Add(new RunBlock("class Fact { public int Run(int n) { return n <= 0 ? 1 : n*Run(n-1); } }"));
            History.Add(new RunBlock("new Fact().Run(5);"));
            History.Add(new RunBlock("var vals = new double[] { 1, 3, 5, 7, 11 };"));
            History.Add(new RunBlock("from v in vals where v > 3 orderby v descending select 2*v;"));

            InitializeComponent();
            LayoutRoot.DataContext = this;
        }
Example #3
0
        /// <summary>
        /// Executes the block using the given <see cref="Runner"/>
        /// </summary>
        /// <param name="runner">The <see cref="Runner"/> that will be used to run the code</param>
        /// <returns>Whether the <see cref="InputText"/> is complete</returns>
        public bool Run(Runner runner)
        {
            //
            // Run the code and track errors
            //
            Errors.Clear();
            var complete = runner.Run(InputText, msg => {
                Errors.Add(msg);
            });
            OnPropertyChanged("HasErrors");

            //
            // Set the output
            //
            if (runner.HasResult) {
                OutputValue = runner.Result;
            }
            else {
                OutputValue = null;
                _hasOutput = false;
                OnPropertyChanged("HasOutput");
            }

            return complete;
        }
 public Printer(Runner r)
 {
     _r = r;
 }