Exemplo n.º 1
0
        public static object EvalCommand(object expr, int pos)
        {
            var    expr1 = WrapInFrame(expr, pos);
            var    expr2 = Runtime.Compile(expr1);
            object val   = Runtime.Execute(expr2);

            return(val);
        }
Exemplo n.º 2
0
        public static void RunCommand(Action <object> func, Cons lispCode, bool showTime = false, bool smartParens = false)
        {
            var output = GetConsoleOut();

            if (lispCode != null)
            {
                var head  = Runtime.First(lispCode) as Symbol;
                var scope = Runtime.ReplGetCurrentAnalysisScope();

                if (smartParens && head != null)
                {
                    if (Runtime.LooksLikeFunction(head))
                    {
                        lispCode = Runtime.MakeCons(lispCode, (Cons)null);
                    }
                }

                timer.Reset();

                foreach (var expr in lispCode)
                {
                    var expr2 = Runtime.Compile(expr, scope);
                    timer.Start();
                    object val = Runtime.Execute(expr2);
                    if (Runtime.ToBool(Runtime.GetDynamic(Symbols.ReplForceIt)))
                    {
                        val = Runtime.Force(val);
                    }
                    timer.Stop();
                    if (func == null)
                    {
                        Runtime.SetSymbolValue(Symbols.It, val);
                        if (val != VOID.Value)
                        {
                            Runtime.PrintStream(output, "", "it: ");
                            Runtime.PrettyPrintLine(output, 4, null, val);
                        }
                    }
                    else
                    {
                        func(val);
                    }
                }

                var time = timer.ElapsedMilliseconds;
                if (showTime)
                {
                    Runtime.PrintStream(GetConsoleLog(), "info", Runtime.MakeString("Elapsed time: ", time, " ms\n"));
                }
            }
            else
            {
                func(Runtime.SymbolValue(Symbols.It));
            }
        }