public bool PopStack(out object execution, out ExecutionCallback callback, ExecutionEnvironment e)
 {
     callback = Callback;
     if (current == 0)
     {
         execution = Time;
         return(true);
     }
     else if (current == 1)
     {
         execution = X;
         return(true);
     }
     else if (current == 2)
     {
         execution = Y;
         return(true);
     }
     else if (!finish)
     {
         execution = new Literal()
         {
             Raw = "1"
         };
         return(true);
     }
     execution = null;
     return(false);
 }
Exemple #2
0
        void HandleException(Exception e)
        {
            Console.WriteLine("Exception occur");
            Console.WriteLine(e.Message);
            Console.WriteLine(e.StackTrace);
            ExecutionCallback callback = null;

            while (Stacks.Count > 0)
            {
                ExecStackItem item   = Stacks.Peek();
                bool          handle = false;
                try
                {
                    handle = item.Execution.HandleException(e);
                    callback(null, e, item.Previous);
                }
                catch (Exception excption) { }
                if (handle)
                {
                    return;
                }
                else
                {
                    Stacks.Pop();
                    callback = item.Callback;
                }
            }
            Console.WriteLine("Exception occur and no try block, so exit");
            //TO DO terminate execution
        }
Exemple #3
0
        public bool PopStack(out object execution, out ExecutionCallback callback, ExecutionEnvironment e)
        {
            int  current    = (int)e.GetState("current");
            bool testResult = (bool)e.GetState("testResult");

            if (current == 0)
            {
                execution = Test;
                callback  = Callback;
                return(true);
            }
            else if (current == 1)
            {
                if (testResult)
                {
                    execution = Consequent;
                }
                else
                {
                    execution = Alternate;
                }
                callback = Callback;
                return(false);
            }
            execution = null;
            callback  = null;
            return(false);
        }
Exemple #4
0
        public void ExecuteInTransaction(ExecutionCallback callback, int transactionId, string name)
        {
            CheckThreadId();

            bool hadTransaction = HasTransaction();

            try
            {
                if (!hadTransaction)
                {
                    History.Instance.StartTransaction(transactionId, name);
                }

                callback();
            }
            catch (Exception ex)
            {
                if (!hadTransaction)
                {
                    History.Instance.RollBackTransaction();
                }

                throw ex;
            }

            if (!hadTransaction)
            {
                History.Instance.EndTransaction();
            }
        }
Exemple #5
0
 public bool PopStack(out object execution, out ExecutionCallback callback, ExecutionEnvironment _env)
 {
     callback = Callback;
     if (Args != null && current < Args.Count)
     {
         execution = Args[current];
         return true;
     }
     else
     {
         Function func = null;
         Instance This = _env.This;
         foreach (Function f in This.Class.Functions)
         {
             if (f.Name == Function)
                 func = f;
         }
         int i = 0;
         foreach (object v in pVals)
         {
             func.Params[i].Value = v;
             i++;
         }
         execution = func;
         return false;
     }
 }
Exemple #6
0
 public ExecStackItem(Execution2 exec, ExecutionCallback callback, ExecutionEnvironment env, ExecutionEnvironment preEnv)
 {
     Execution        = exec;
     Callback         = callback;
     Environment      = env;
     HasMoreExecution = true;
     Previous         = preEnv;
 }
Exemple #7
0
 public bool PopStack(out object execution, out ExecutionCallback callback, ExecutionEnvironment e)
 {
     if (current == 0)
     {
         execution = Right;
         callback  = Callback;
         return(false);
     }
     execution = null;
     callback  = null;
     return(false);
 }
 public bool PopStack(out object execution, out ExecutionCallback callback, ExecutionEnvironment e)
 {
     if (current == 0)
     {
         execution = X;
         callback  = Callback;
         return(true);
     }
     else
     {
         execution = Y;
         callback  = Callback;
         return(false);
     }
 }
        public bool PopStack(out object execution, out ExecutionCallback callback, ExecutionEnvironment e)
        {
            int current = (int)e.GetState("current");

            callback = Callback;
            if (current == 0)
            {
                execution = Min;
                return(true);
            }
            else
            {
                execution = Max;
                return(false);
            }
        }
Exemple #10
0
        Nullable <DateTime> ExecCallBack(ExecutionCallback callback, object value, object exception, ExecutionEnvironment env)
        {
            Exception ex = null;

            try
            {
                return(callback(value, exception, env));
            }
            catch (Exception e) {
                ex = e;
            }
            if (ex != null)
            {
                HandleException(ex);
            }
            return(null);
        }
Exemple #11
0
        public bool PopStack(out object execution, out ExecutionCallback callback, ExecutionEnvironment e)
        {
            int current       = (int)e.GetState("current");
            int currentNumber = (int)e.GetState("currentNumber");
            int loopNumber    = (int)e.GetState("loopNumber");

            if (current == 0)
            {
                execution = Loop;
                callback  = Callback;
                return(true);
            }
            else
            {
                execution = Body;
                callback  = Callback;
                return(currentNumber < loopNumber);
            }
        }
Exemple #12
0
        public bool PopStack(out object execution, out ExecutionCallback callback, ExecutionEnvironment e)
        {
            callback = Callback;
            int current = (int)e.GetState("current");

            if (current < Body.Count)
            {
                execution = Body[current];
                if (execution is ReturnStatement)
                {
                    return(false);
                }
            }
            else
            {
                execution = null;
                return(false);
            }
            return((current + 1) != Body.Count);
        }
Exemple #13
0
        public bool PopStack(out object execution, out ExecutionCallback callback, ExecutionEnvironment e)
        {
            int  current     = (int)e.GetState("current");
            bool canContinue = (bool)e.GetState("canContinue");

            if (current % 2 == 0)
            {
                execution = Test;
                callback  = Callback;
                return(true);
            }
            else if (canContinue)
            {
                execution = Body;
                callback  = Callback;
                return(true);
            }
            execution = null;
            callback  = null;
            return(false);
        }
 public bool PopStack(out object execution, out ExecutionCallback callback, ExecutionEnvironment e)
 {
     if (current == 0)
     {
         execution = Test;
         callback  = Callback;
         return(true);
     }
     else
     {
         if (testResult)
         {
             execution = Consequent;
         }
         else
         {
             execution = Alternate;
         }
     }
     callback = Callback;
     return(false);
 }
 public bool PopStack(out object execution, out ExecutionCallback callback, ExecutionEnvironment e)
 {
     if (current == 0)
     {
         execution = Try;;
         callback  = Callback;
         return(true);
     }
     else
     {
         if (hasException)
         {
             execution = Catch;
             callback  = Callback;
         }
         else
         {
             execution = null;
             callback  = null;
         }
         return(false);
     }
 }
Exemple #16
0
 public bool PopStack(out object execution, out ExecutionCallback callback, ExecutionEnvironment e)
 {
     execution = Degree;
     callback  = Callback;
     return(false);
 }
Exemple #17
0
        Nullable <DateTime> EndCall(ExecStackItem current)
        {
            Exception  ex     = null;
            Completion retVal = null;

            try
            {
                retVal = current.Execution.EndCall(current.Environment);
            }
            catch (Exception e)
            {
                ex = e;
            }
            if (ex != null)
            {
                HandleException(ex);
                return(null);
            }
            Stacks.Pop();
            if (current.Execution is ReturnStatement)
            {
                ExecStackItem func = Stacks.Peek();
                while (!(func.Execution is Function))
                {
                    Stacks.Pop();
                    func = Stacks.Peek();
                }
                ExecCallBack(func.Callback, retVal.ReturnValue, null, func.Previous);
                return(null);
            }
            else if (current.Execution is BreakStatement)
            {
                ExecStackItem func = Stacks.Peek();
                while (!(func.Execution is Loop))
                {
                    Stacks.Pop();
                    func = Stacks.Peek();
                    if (Stacks.Count == 1)
                    {
                        break;
                    }
                }
                func = Stacks.Pop();
                if (!(func.Execution is Loop))
                {
                    HandleException(new Exception("Break must be in a loop"));
                    return(null);
                }
                ExecCallBack(func.Callback, retVal.ReturnValue, null, func.Previous);
                return(null);
            }
            else if (current.Execution is ContinueStatement)
            {
                ExecStackItem     func     = Stacks.Peek();
                ExecStackItem     last     = null;
                ExecutionCallback callBack = null;
                while (!(func.Execution is Loop))
                {
                    callBack = func.Callback;
                    last     = func;
                    Stacks.Pop();
                    func = Stacks.Peek();
                    if (Stacks.Count == 1)
                    {
                        break;
                    }
                }
                if (!(func.Execution is Loop))
                {
                    HandleException(new Exception("continue must be in a loop"));
                    return(null);
                }
                return(ExecCallBack(last.Callback, retVal.ReturnValue, null, last.Environment));
            }
            return(ExecCallBack(current.Callback, retVal.ReturnValue, null, current.Previous));
        }