コード例 #1
0
        /// <summary>
        /// Execute the Algorithm/Function. <see cref="Instruction"/> by <see cref="Instruction"/>,
        /// until the list of instructions is exhausted and we can return the <see cref="_return_value"/>,
        /// using <see cref="Expression.parse"/> on it (it is an <see cref="Expression"/>)
        /// </summary>
        /// <returns> The evaluated <see cref="_return_value"/> after all the <see cref="_instructions"/> have been executed</returns>
        /// <exception cref="AquilaExceptions.RuntimeError"> ReturnValueException is null</exception>
        public Variable run()
        {
            try
            {
                // Algorithm start
                setStartContext();

                foreach (Instruction instr in _instructions)
                {
                    try
                    {
                        instr.execute();
                    }
                    catch (System.Reflection.TargetInvocationException out_exception)
                    {
                        // normal TargetInvocationException
                        if (!(out_exception.InnerException is AquilaControlFlowExceptions.ReturnValueException))
                        {
                            throw;
                        }
                        // casted ReturnValueException
                        AquilaControlFlowExceptions.ReturnValueException exception =
                            (AquilaControlFlowExceptions.ReturnValueException)out_exception.InnerException;

                        if (exception == null)
                        {
                            throw new AquilaExceptions.RuntimeError(
                                      "The inner ReturnValueException in the TargetInvocationException is null"); // something went wrong
                        }
                        _return_value = new Expression(exception.getExprStr());
                        Context.reset();
                        return(_return_value.evaluate());
                    }
                }

                // no resetting here. algorithm finished
                setEndContext();

                return(new NullVar()); // NoReturnCallWarning
            }
            catch (StopInterpreterException)
            {
                Global.stdoutWriteLine("Stopped Interpreter");
                Global.resetEnv();

                return(new NullVar());
            }
            catch (Exception e)
            {
                Global.stdoutWriteLine(e.ToString());

                return(new NullVar());
            }
        }
コード例 #2
0
        /// <summary>
        /// Run the Algorithm as a test run. <see cref="Instruction"/> by <see cref="Instruction"/>,
        /// until the list of instructions is exhausted and we can return the <see cref="_return_value"/>,
        /// using <see cref="Expression.parse"/> on it (it is an <see cref="Expression"/>)
        /// </summary>
        /// <returns> The evaluated <see cref="_return_value"/> after all the <see cref="_instructions"/> have been executed</returns>
        /// <exception cref="AquilaExceptions.RuntimeError"> ReturnValueException is null</exception>
        public Variable testRun()
        {
            initTestMode();
            try
            {
                // Run start
                Debugging.print("Starting Algorithm test run");
                setStartContext();

                foreach (Instruction instr in _instructions)
                {
                    try
                    {
                        instr.execute();
                    }
                    catch (System.Reflection.TargetInvocationException out_exception)
                    {
                        // normal TargetInvocationException
                        if (!(out_exception.InnerException is AquilaControlFlowExceptions.ReturnValueException))
                        {
                            throw;
                        }
                        // casted ReturnValueException
                        AquilaControlFlowExceptions.ReturnValueException exception =
                            (AquilaControlFlowExceptions.ReturnValueException)out_exception.InnerException;

                        if (exception == null)
                        {
                            throw new AquilaExceptions.RuntimeError("The inner ReturnValueException in the TargetInvocationException is null");                    // something went wrong
                        }
                        _return_value = new Expression(exception.getExprStr());
                        Context.reset();
                        Debugging.print("Ended Algorithm test run with return value");
                        Global.setSetting("test mode", false);
                        return(_return_value.evaluate());
                    }
                }

                // no resetting here. algorithm finished
                setEndContext();

                Debugging.print("Ended Algorithm test run with no return");
                Global.setSetting("test mode", false);
                return(new NullVar()); // NoReturnCallWarning
            }
            catch (Exception e)
            {
                Global.stdoutWriteLine(e.ToString());

                Debugging.print("Ended Algorithm test run with exception");
                Global.setSetting("test mode", false);
                return(new NullVar());
            }
        }