Ejemplo n.º 1
0
        private async Task DumpFormatAsync(ExpressionViewModel vm, string msg) =>
        //if ()
        //{
        //    return ;
        //}

        //var retVal = SerializingFormatter.Format(
        //    Interpreter,
        //    true,
        //    Interpreter.GetReturnValue(),
        //    ignoreNull: false,
        //    ignoreClrObj: false,
        //    scopes: AphidObject.GetScopeAncestors(Interpreter.CurrentScope));
        //return CodeViewer.Run(() => vm.Value = retVal);


        await CodeViewer.Run(
            x => vm.Value = x,
            await(msg != null ?
                  (Func <Task <string> >)(() => Task.FromResult(msg)) :
                  (() => Task.Run(
                       () => SerializingFormatter.Format(
                           Interpreter,
                           true,
                           Interpreter.GetReturnValue(),
                           ignoreNull: false,
                           ignoreClrObj: false,
                           scopes: AphidObject
                           .GetScopeAncestors(Interpreter.CurrentScope)))))());
Ejemplo n.º 2
0
 public static void Dump(AphidInterpreter interpreter, object obj) =>
 SerializingFormatter
 .Format(interpreter, obj)
 .Then(CodeViewer.HighlightAsync)
 .ContinueWith(x =>
               interpreter.CurrentScope
               .Resolve(interpreter, ViewModelName)
               .Get <AphidReplViewModel>()
               .CodeViewer
               .AppendColoredOutput(x.Result))
 .Do(DumpTasks.Add);
Ejemplo n.º 3
0
 public static void DumpValue(
     AphidInterpreter interpreter,
     object value,
     bool ignoreNull   = true,
     bool ignoreClrObj = true) =>
 WriteLineHighlighted(
     SerializingFormatter.Format(
         interpreter,
         value,
         ignoreNull,
         ignoreClrObj));
Ejemplo n.º 4
0
        public static AphidObject EvalExpression(AphidInterpreter interpreter, string code)
        {
            AphidObject result = null;

            void action()
            {
                if (code.Trim()?.Length == 0)
                {
                    return;
                }

                var lexer  = new AphidLexer(code);
                var tokens = lexer.GetTokens();
                var exp    = AphidParser.ParseExpression(tokens, code);
                var retExp = new UnaryOperatorExpression(AphidTokenType.retKeyword, exp);

                //new AphidCodeVisitor(code).VisitExpression(retExp);
                interpreter.Interpret(retExp);
                result = interpreter.GetReturnValue(true);

                if (result != null && (result.Value != null || result.Any()))
                {
                    WriteLineHighlighted(
                        SerializingFormatter.Format(
                            interpreter,
                            result,
                            ignoreNull: false,
                            ignoreClrObj: false));
                }
            }

            if (AphidErrorHandling.HandleErrors)
            {
                TryAction(interpreter, code, action);
            }
            else
            {
                action();
            }

            return(result);
        }
Ejemplo n.º 5
0
        private async void ExecuteExpression(string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                return;
            }

            AddHistoricalCode();

            var ast = ParseRetExpression(code);

            if (ast == null)
            {
                return;
            }

            try
            {
                try
                {
                    Interpreter.ResetState();
                    Interpreter.TakeOwnership();

#if APHID_FRAME_ADD_DATA || APHID_FRAME_CATCH_POP
                    try
                    {
#endif
                    Interpreter.Interpret(ast);
#if APHID_FRAME_ADD_DATA || APHID_FRAME_CATCH_POP
                }
#endif
#if APHID_FRAME_ADD_DATA || APHID_FRAME_CATCH_POP
#if APHID_FRAME_ADD_DATA
                    catch (Exception e)
#else
                    catch
#endif
                    {
                        if (e.Source != AphidName.DebugInterpreter)
                        {
                            e.Source = AphidName.DebugInterpreter;

#if APHID_FRAME_CATCH_POP
                            Interpreter.PopQueuedFrames();
#endif

#if APHID_FRAME_ADD_DATA
                            e.Data.Add(AphidName.Interpreter, Interpreter);
                            e.Data.Add(AphidName.FramesKey, Interpreter.GetRawStackTrace());
#endif
                        }

                        throw;
                    }
#endif
                }
                catch (AphidRuntimeException ex)
                {
                    CodeViewer.AppendException(code, "Runtime error", ex, Interpreter);

                    return;
                }
                catch (AphidParserException ex)
                {
                    CodeViewer.AppendParserException(code, ex);

                    return;
                }
                catch (Exception ex)
                {
                    CodeViewer.AppendException(code, ".NET Runtime error", ex, Interpreter);

                    return;
                }

                var serialized = SerializingFormatter
                                 .CreateSerializer(Interpreter)
                                 .Serialize(Interpreter.GetReturnValue());

                await WaitDumpTasksAsync();

                await CodeViewer.Async(() =>
                                       CodeViewer.AppendColoredOutput(
                                           Highlight(code),
                                           Highlight(serialized)));
            }
            finally
            {
                UpdateVariables();
                await ExecuteWatchExpressionsAsync();
            }
        }
Ejemplo n.º 6
0
        public static void DumpStackTrace(AphidInterpreter interpreter, AphidFrame[] trace)
        {
            var cfg      = AphidConfig.Current;
            var frameNum = 0;

            if (!Console.IsOutputRedirected)
            {
                WriteSubheader(StackTraceHead, "~|Blue~~White~");
            }
            else
            {
                WriteErrorMessage(StackTraceHead);
            }

            foreach (var frame in trace)
            {
                var frameStr = FrameFormatter.FormatFrame(frameNum++, in frame);
                WriteLineOut(frameStr);

                if (cfg.StackTraceParams)
                {
                    var args = frame.Arguments
                               .Select((x, y) => string.Format(
                                           "{0} $args[{1}] = {2}",
                                           GetAphidObjectTypeName(x),
                                           y,
                                           SerializingFormatter.Format(
                                               interpreter,
                                               x,
                                               ignoreNull: false,
                                               ignoreClrObj: false)));

                    if (cfg.StackTraceParamsMax >= 0)
                    {
                        var h = cfg.StackTraceParamsMax / 2f;
                        int first = (int)Math.Ceiling(h), last = (int)Math.Floor(h);
                        var count = frame.Arguments.Count();
                        var skip  = Math.Max(0, count - first - last);

                        if (skip != 0)
                        {
                            args = args
                                   .Where((_, i) => i < first || i >= skip + first)
                                   .Append(string.Format("/* Skipped {0:n0} args /*", skip))
                                   .Skip(skip);
                        }
                    }

                    var argStr = args.JoinLines();

                    if (argStr.Length > 0)
                    {
                        WriteLineOut(Format(argStr.Indent("  ")));
                    }

                    //var locals = frame.Scope
                    //    .Select(x => string.Format(
                    //        "{0} {1} = {2}",
                    //        x.Key,
                    //        GetAphidObjectTypeName(x.Value),
                    //        DumpValue(interpreter, serializer, x.Value)))
                    //    .JoinLines();

                    //if (locals.Length > 0)
                    //{
                    //    WriteLineOut(Highlight(StyleEscape(locals.Indent("  "))));
                    //}
                }
            }

            WriteLineOut("");

            if (cfg.ShowErrorExpression || cfg.ShowErrorStatement)
            {
                ShowErrorNodes(interpreter, cfg, trace);
            }

            if (cfg.ShowErrorFrameExcerpts)
            {
                var dumpCount = 0;

                foreach (var t in trace)
                {
                    if (DumpFirstExcerpt(
                            t.Expression,
                            string.Format(
                                "Frame {0:x4} Excerpt",
                                Array.IndexOf(trace, t))) &&
                        ++dumpCount == cfg.FrameExcerptsMax)
                    {
                        break;
                    }
                }
            }

            //if(dumpCount == 0)
            //{
            //    foreach(var pair in ctxPairs)
            //    {
            //        DumpFirstExcerpt(
            //            pair.Item2,
            //            string.Format("Current {0} Excerpt", pair.Item1));
            //    }

            //}

            var headerPrinted = false;
            var statement     = interpreter.CurrentStatement;
            var exp           = interpreter.CurrentExpression;
            var file          = interpreter.GetScriptFilename();
            var stmtFile      = statement?.Filename;
            var expFile       = exp?.Filename;

            if (cfg.ShowErrorFileList)
            {
                foreach (var s in new (string, string, Func <List <AphidExpression> >)[]