Esempio n. 1
0
        /// <summary>
        /// Parses a Block inside an open ReplSession
        /// </summary>
        /// <param name="expression">the Expression-Block that must be executed</param>
        /// <param name="replSession">the current repl-session</param>
        /// <returns>the result of the Execution-block</returns>
        public static object ParseBlock(string expression, IDisposable replSession)
        {
            if (replSession is InterpreterBuffer.RunnerItem rii)
            {
                ITVScriptingBaseVisitor <ScriptValue> visitor  = InterpreterBuffer.GetInterpreter(rii);
                ITVScriptingParser.ProgramContext     executor = GetProgramTree(expression);
                ScriptValue retVal = visitor.VisitProgram(executor);
                return(ScriptValueHelper.GetScriptValueResult <object>(retVal, false));
            }

            return(ParseBlock(expression, replSession, null));
        }
Esempio n. 2
0
        /// <summary>
        /// Runs a script inside a specific Scripting context
        /// </summary>
        /// <param name="scriptingContext">the scripting context in which a script is running</param>
        /// <returns>the result of the script</returns>
        public TOutput Execute(IDisposable scriptingContext)
        {
            CheckDate();
            bool ok = false;

            while (!ok)
            {
                lock (runCounterLock)
                {
                    ok = executionWait.WaitOne(100);
                    if (ok)
                    {
                        currentRuns++;
                    }
                }

                if (!ok)
                {
                    executionWait.WaitOne();
                }
            }

            try
            {
                if (!runnable)
                {
                    throw new ScriptException(string.Format("Script is not runnable! Suspect Line: {0}{2}Complete Error-List:{2} {1}", suspectLine, errors, Environment.NewLine));
                }

                var         visitor = InterpreterBuffer.GetInterpreter(scriptingContext);
                ScriptValue retVal  = visitor.VisitProgram(program);
                return(ScriptValueHelper.GetScriptValueResult <TOutput>(retVal, false));
            }
            finally
            {
                lock (runCounterLock)
                {
                    currentRuns--;
                    Monitor.Pulse(runCounterLock);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Invokes the body of this function using the provided arguments
        /// </summary>
        /// <param name="arguments">the arguments whith which to initialize the visitor for this method</param>
        /// <returns>the result of this method</returns>
        public object Invoke(object[] arguments)
        {
            var dct = scope.PrepareCall();

            try
            {
                Dictionary <string, object> parameters = new Dictionary <string, object>();
                for (int i = 0; i < this.arguments.Length; i++)
                {
                    object val = i < (arguments?.Length ?? 0) ? arguments[i] : null;
                    parameters[this.arguments[i]] = val;
                }

                parameters["parameters"] = arguments;
                scope.Clear(parameters);
                return(ScriptValueHelper.GetScriptValueResult <object>(visitor.Visit(body), false));
            }
            finally
            {
                scope.FinalizeScope(dct);
            }
        }