Ejemplo n.º 1
0
        public void Stop()
        {
            IsExecuting = false;

            Task.Run(() =>
            {
                if (_interpreterThread != null)
                {
                    try
                    {
                        _interpreterThread.Abort();
                    }
                    catch { }

                    _interpreterThread = null;
                }

                CodeViewer.AppendOutput("Stopped");
                CodeViewer.BeginInvoke(() => Status = "Script stopped");
            });
        }
Ejemplo n.º 2
0
        private async void ExecuteStatements(string code)
        {
            ResetInterpreter();
            await CodeViewer.Document.BeginInvoke(CodeViewer.Document.Blocks.Clear);

            CodeViewer.AppendOutput("Running script...");

            if (string.IsNullOrEmpty(code))
            {
                return;
            }

            List <AphidExpression> ast = null;

            try
            {
                ast = AphidParser.Parse(code);
            }
            catch (AphidParserException ex)
            {
                CodeViewer.AppendParserException(code, ex);

                return;
            }
            catch (Exception ex)
            {
                CodeViewer.AppendException(code, "Internal parser exception (please report)", ex, Interpreter);

                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.AppendRuntimeException(code, ex, Interpreter);

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

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

                    return;
                }
            }
            finally
            {
                UpdateVariables();
            }

            await ExecuteWatchExpressionsAsync();
            await WaitDumpTasksAsync();

            CodeViewer.AppendOutput("Done");
        }
Ejemplo n.º 3
0
        private void ExecuteExpression()
        {
            if (string.IsNullOrEmpty(Code))
            {
                return;
            }

            AddHistoricalCode();

            var tokens = new AphidLexer(Code + " ").GetTokens();

            if (!tokens.Any(x => x.TokenType == AphidTokenType.EndOfStatement))
            {
                tokens.Add(new AphidToken(AphidTokenType.EndOfStatement, "", 0));
            }

            List <Components.Aphid.Parser.Expression> ast = null;

            try
            {
                ast = new AphidParser(tokens).Parse();
            }
            catch (AphidParserException ex)
            {
                InvokeDispatcher(() => _codeViewer.AppendParserException(Code, ex));

                return;
            }

            if (ast.Count != 1)
            {
                throw new InvalidOperationException();
            }

            var exp   = ast.First();
            var unary = exp as UnaryOperatorExpression;

            if (unary == null ||
                unary.Operator != AphidTokenType.retKeyword)
            {
                ast.Clear();
                ast.Add(new UnaryOperatorExpression(
                            AphidTokenType.retKeyword,
                            exp));
            }



            try
            {
                _interpreter.Interpret(ast);
            }
            catch (AphidRuntimeException ex)
            {
                InvokeDispatcher(() =>
                                 _codeViewer.AppendException(Code, "Runtime error", ex));

                return;
            }
            catch (AphidParserException ex)
            {
                InvokeDispatcher(() =>
                                 _codeViewer.AppendParserException(Code, ex));

                return;
            }

            var retVal = _interpreter.GetReturnValue();

            var serializer = new AphidSerializer()
            {
                IgnoreFunctions = false
            };

            InvokeDispatcher(() =>
                             _codeViewer.AppendOutput(Code, serializer.Serialize(retVal)));

            UpdateVariables();
            ExecuteWatchExpressions();
        }