示例#1
0
        static void Main(string[] args)
        {
            var test = new List <string>().Select(i => i);

            if (args.Length > 0)
            {
                try
                {
                    var code   = File.ReadAllText(args[0]).Replace("\"", "'");
                    var result = new Lisp.Compiler.Compiler().Compile(code).Invoke();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
                return;
            }

            Stopwatch sw = new Stopwatch();
            // new Lisp.Compiler.Compiler().Compile("(defn x [a] (+ a 5))").Invoke();
            // var fn = new Lisp.Compiler.Compiler().Compile("(x 10)");
            var compiler = new Lisp.Compiler.Compiler();

            compiler.Compile("(defn myfunc [a b] (+ a b))").Invoke();
            var fn = compiler.Compile("(+ 10 20)");

            while (true)
            {
                sw.Reset();
                fn.Invoke();
                sw.Start();
                var x = 0;
                Func <object[], object> f = args => Add(args[0], args[1]);
                for (var i = 0; i < 1000000; i++)
                {
                    fn.Invoke();
                    // x += (int)f(new object[] { 10,20 });
                }
                sw.Stop();
                Console.WriteLine(sw.ElapsedMilliseconds);
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            // Creates a line editor, and sets the name of the editing session to
            // "foo".  This is used to save the history of input entered
            LineEditor le = new LineEditor("foo")
            {
                HeuristicsMode = "csharp"
            };

            // Configures auto-completion, in this example, the result
            // is always to offer the numbers as completions
            le.AutoCompleteEvent += delegate(string text, int pos)
            {
                string prefix      = "";
                var    completions = new string[] {
                    "first", "reduce", "map"
                };
                return(new Mono.Terminal.LineEditor.Completion(prefix, completions));
            };

            string s;

            // Prompts the user for input
            while ((s = le.Edit("> ", "")) != null)
            {
                if (s == "exit")
                {
                    System.Environment.Exit(0);
                }
                var compiler = new Lisp.Compiler.Compiler();
                try {
                    if (s != string.Empty)
                    {
                        Console.WriteLine(compiler.Compile(s).Invoke().Stringify(true));
                    }
                }
                catch (Exception e) {
                    Console.WriteLine(e);
                }
            }
        }