Example #1
0
        public void SetNewBranchTest2()
        {
            List <Step> sequence = new List <Step>()
            {
                new NavigateStep(),
                new GroupStep()
                {
                    Steps = new List <Step>()
                    {
                        new GetValueStep(),
                        new GetValueStep()
                    }
                }
            };
            ExecutionStack executionStack = new ExecutionStack();

            executionStack.SetSequence(sequence);

            List <Step>   newBranch = ((GroupStep)sequence[1]).Steps;
            FixedIterator iterator  = new FixedIterator(new FixedIteration());

            executionStack.SetNewBranch(newBranch, iterator);

            PrivateObject m_PendingBranch = new PrivateObject(executionStack, "m_PendingBranch");

            Assert.IsTrue(m_PendingBranch
                          .GetProperty("Steps", null)
                          .Equals(newBranch));

            Assert.IsTrue(m_PendingBranch
                          .GetProperty("IterationContext", null)
                          .Equals(iterator));
        }
        public void AllSteps(int index, bool eachExecution)
        {
            bool isStopped = false;

            ProgramState ps = repo.GetProgramState(index);

            Console.WriteLine(ps.Tostring());

            ExecutionStack executionStack = ps.GetExecutionStack();


            while (!executionStack.IsEmpty())
            {
                try
                {
                    OneStep(ps, executionStack, eachExecution);
                    repo.SaveLog(ps);
                }
                catch (CustomException exc)
                {
                    Console.WriteLine(exc.Message);
                    isStopped = true;
                    break;
                }
            }
            if (!eachExecution && !isStopped)
            {
                Console.WriteLine(ps.Tostring());
            }
            ps.Reload();
        }
Example #3
0
 public DebugEngine()
   : base() {
   Log = new Log();
   ExecutionStack = new ExecutionStack();
   OperatorTrace = new OperatorTrace();
   InitializeTimer();
 }
Example #4
0
        public void Execution_Stack_Test_Add_Guid_Makes_Stack_Nonempty()
        {
            var SUT = new ExecutionStack();

            SUT.ProcessEntry(1, Guid.NewGuid());
            Assert.IsTrue(!SUT.IsStackEmpty(1));
            SUT.ClearStack();
        }
        public ProgramState Execute(ProgramState ps)
        {
            ExecutionStack executionStack = ps.GetExecutionStack();

            executionStack.Push(right);
            executionStack.Push(left);
            return(ps);
        }
Example #6
0
 public static EXECUTION_RESULT?EQ_VERIFY(ref ExecutionStack stack)
 {
     if (EQUALS(ref stack) != null)
     {
         stack.Push(false);
     }
     return(Verify.VERIFY(ref stack));
 }
Example #7
0
        public void Execution_Stack_Test_No_Access_To_Other_Thread()
        {
            var SUT = new ExecutionStack();

            SUT.ProcessEntry(1, Guid.NewGuid());
            Assert.IsTrue(SUT.IsStackEmpty(2));
            SUT.ClearStack();
        }
Example #8
0
        public void Execution_Stack_Test_Check_Equality_Of_Pushed_Method()
        {
            var SUT     = new ExecutionStack();
            var newGuid = Guid.NewGuid();

            SUT.ProcessEntry(1, newGuid);
            Assert.IsTrue(SUT.ExecutingGuid(1) == newGuid);
        }
Example #9
0
        public void Execution_Stack_Test_Clear_Stack()
        {
            var SUT = new ExecutionStack();

            SUT.ProcessEntry(1, Guid.NewGuid());
            SUT.ClearStack();
            Assert.IsTrue(SUT.IsStackEmpty(1));
        }
Example #10
0
 public static EXECUTION_RESULT?CHECKLOCKTIME_VERIFY(ref ExecutionStack stack)
 {
     if (CHECKLOCKTIME(ref stack) != null)
     {
         stack.Push(false);
     }
     return(VERIFY(ref stack));
 }
        public ProgramState execute(ProgramState programState)
        {
            ExecutionStack <Statement> executionStack = programState.getExecutionStack();

            executionStack.push(second);
            executionStack.push(first);
            return(programState);
        }
Example #12
0
        public static void EVAL_SCRIPT(ref ExecutionStack stack)
        {
            Script lockScript   = new Script(stack.Pop());
            Script unlockScript = new Script(stack.Pop());

            unlockScript.InsertScript(lockScript);

            stack.Script.AddRange(unlockScript.Reverse().ToArray());
        }
Example #13
0
        public void Execution_Stack_Test_Method_Exception_Removes_Guid()
        {
            var SUT = new ExecutionStack();

            SUT.ProcessEntry(1, Guid.NewGuid());
            SUT.ProcessException(1);
            Assert.IsTrue(SUT.IsStackEmpty(1));
            SUT.ClearStack();
        }
Example #14
0
        public static EXECUTION_RESULT?EQUALS(ref ExecutionStack stack)
        {
            if (stack.Count < 2)
            {
                return(EXECUTION_RESULT.INVALID_STACK);
            }

            stack.Push(System.Linq.Enumerable.SequenceEqual(stack.Pop(), stack.Pop()));
            return(null);
        }
Example #15
0
        public void BreakBranchTest()
        {
            ExecutionStack executionStack = new ExecutionStack();

            executionStack.BreakBranch();

            PrivateObject m_BreakBranch = new PrivateObject(executionStack, "m_BreakBranch");

            Assert.IsTrue((bool)m_BreakBranch.Target);
        }
Example #16
0
 public Interpreter(int maxStack, int maxStorage, int maxFunctions, int maxInstructionDefs, int maxTwilightPoints)
 {
     stack = new ExecutionStack(maxStack);
     storage = new int[maxStorage];
     functions = new InstructionStream[maxFunctions];
     instructionDefs = new InstructionStream[maxInstructionDefs > 0 ? 256 : 0];
     state = new GraphicsState();
     cvtState = new GraphicsState();
     twilight = new Zone(new PointF[maxTwilightPoints], isTwilight: true);
 }
Example #17
0
        public void SkipIterationTest()
        {
            ExecutionStack executionStack = new ExecutionStack();

            executionStack.SkipIteration();

            PrivateObject m_SkipIteration = new PrivateObject(executionStack, "m_SkipIteration");

            Assert.IsTrue((bool)m_SkipIteration.Target);
        }
Example #18
0
        public static EXECUTION_RESULT?DUP(ref ExecutionStack stack)
        {
            if (!stack.Any())
            {
                return(EXECUTION_RESULT.INVALID_STACK);
            }
            var item = stack.Pop();

            stack.Push(item, item);
            return(null);
        }
Example #19
0
        public void SetSequenceTest()
        {
            List <Step> sequence = new List <Step>()
            {
                new NavigateStep()
            };
            ExecutionStack executionStack = new ExecutionStack();

            executionStack.SetSequence(sequence);

            Assert.IsNotNull(executionStack.CurrentBranch);
        }
Example #20
0
        public void Execution_Stack_Test_Check_Equality_Of_Mult_Pushed_Methods()
        {
            var SUT = new ExecutionStack();
            var g1  = Guid.NewGuid();
            var g2  = Guid.NewGuid();

            SUT.ProcessEntry(1, g1);
            SUT.ProcessEntry(1, g2);
            Assert.IsTrue(SUT.ExecutingGuid(1) == g2);
            SUT.ProcessExit(1);
            Assert.IsTrue(SUT.ExecutingGuid(1) == g1);
        }
 public ProgramState(ExecutionStack <Statement> executionStack,
                     SymbolTable <string, int> symbolTable,
                     FileTable <int, FileData <string, StreamReader> > fileTable,
                     FileDescriptorGenerator generator,
                     Output <string> output)
 {
     this.executionStack = executionStack;
     this.symbolTable    = symbolTable;
     this.fileTable      = fileTable;
     this.generator      = generator;
     this.output         = output;
 }
        protected override void Run(CancellationToken cancellationToken)
        {
            IOperation          next;
            OperationCollection coll;
            IAtomicOperation    operation;

            while (ExecutionStack.Count > 0)
            {
                cancellationToken.ThrowIfCancellationRequested();

                next = ExecutionStack.Pop();
                if (next is OperationCollection)
                {
                    coll = (OperationCollection)next;
                    for (int i = coll.Count - 1; i >= 0; i--)
                    {
                        if (coll[i] != null)
                        {
                            ExecutionStack.Push(coll[i]);
                        }
                    }
                }
                else if (next is IAtomicOperation)
                {
                    operation = (IAtomicOperation)next;
                    try {
                        next = operation.Operator.Execute((IExecutionContext)operation, cancellationToken);
                    }
                    catch (Exception ex) {
                        ExecutionStack.Push(operation);
                        if (ex is OperationCanceledException)
                        {
                            throw ex;
                        }
                        else
                        {
                            throw new OperatorExecutionException(operation.Operator, ex);
                        }
                    }
                    if (next != null)
                    {
                        ExecutionStack.Push(next);
                    }

                    if (operation.Operator.Breakpoint)
                    {
                        Log.LogMessage(string.Format("Breakpoint: {0}", operation.Operator.Name != string.Empty ? operation.Operator.Name : operation.Operator.ItemName));
                        Pause();
                    }
                }
            }
        }
Example #23
0
 public static EXECUTION_RESULT?VERIFY(ref ExecutionStack stack)
 {
     if (!stack.Any())
     {
         return(EXECUTION_RESULT.INVALID_STACK);
     }
     else if (!stack.PopBool())
     {
         return(EXECUTION_RESULT.FAILURE);
     }
     else
     {
         return(null);
     }
 }
Example #24
0
        public static EXECUTION_RESULT?CHECKSIG(ref ExecutionStack stack)
        {
            if (stack.Transaction == null)
            {
                return(EXECUTION_RESULT.NO_TRANSACTION_GIVEN);
            }
            if (stack.Count < 2)
            {
                return(EXECUTION_RESULT.INVALID_STACK);
            }

            //Verify if signature is valid
            stack.Push(new CryptoRSA(stack.Pop()).Verify(stack.Transaction.Hash(), stack.Pop()));
            return(null);
        }
        public ProgramState Execute(ProgramState ps)
        {
            SymbolTable    symbolTable    = ps.GetSymbolTable();
            ExecutionStack executionStack = ps.GetExecutionStack();
            int            result         = expression.Evaluate(symbolTable);

            if (result == 0)
            {
                executionStack.Push(selse);
            }
            else
            {
                executionStack.Push(sthen);
            }
            return(ps);
        }
        public ProgramState execute(ProgramState programState)
        {
            ExecutionStack <Statement> executionStack = programState.getExecutionStack();
            SymbolTable <string, int>  symbolTable    = programState.getSymbolTable();

            if (expression.evaluate(symbolTable) != 0)
            {
                executionStack.push(ifBranch);
            }
            else if (elseBranch != null)
            {
                executionStack.push(elseBranch);
            }

            return(programState);
        }
 public void OneStep(ProgramState ps, ExecutionStack es, bool eachExecution)
 {
     try
     {
         IStatement statement = es.Pop();
         statement.Execute(ps);
         if (eachExecution)
         {
             Console.WriteLine(ps.Tostring());
         }
     }
     catch (CustomException exc)
     {
         throw exc;
     }
 }
Example #28
0
        public void Execution_Stack_Test_Exit_On_Empty_Stack_Throws_Exception()
        {
            var SUT             = new ExecutionStack();
            var exceptionThrown = false;

            try
            {
                SUT.ProcessExit(1);
            }
            catch (ExecutionStackEmptyException ex)
            {
                exceptionThrown = true;
            }
            Assert.IsTrue(exceptionThrown);
            SUT.ClearStack();
        }
Example #29
0
        protected override void Run(CancellationToken cancellationToken)
        {
            IOperation          next;
            OperationCollection coll;
            IAtomicOperation    operation;

            while (ExecutionStack.Count > 0)
            {
                cancellationToken.ThrowIfCancellationRequested();

                next = ExecutionStack.Pop();
                if (next is OperationCollection)
                {
                    coll = (OperationCollection)next;
                    for (int i = coll.Count - 1; i >= 0; i--)
                    {
                        if (coll[i] != null)
                        {
                            ExecutionStack.Push(coll[i]);
                        }
                    }
                }
                else if (next is IAtomicOperation)
                {
                    operation = (IAtomicOperation)next;
                    try {
                        next = operation.Operator.Execute((IExecutionContext)operation, cancellationToken);
                    }
                    catch (Exception ex) {
                        ExecutionStack.Push(operation);
                        if (ex is OperationCanceledException)
                        {
                            throw;
                        }
                        else
                        {
                            throw new OperatorExecutionException(operation.Operator, ex);
                        }
                    }
                    if (next != null)
                    {
                        ExecutionStack.Push(next);
                    }
                }
            }
        }
Example #30
0
        public ProgramState executeOneStep(ProgramState program)
        {
            if (program == null)
            {
                throw (new InterpreterException("error: no program to execute"));
            }

            ExecutionStack <Statement> executionStack = program.getExecutionStack();

            if (executionStack.isEmpty())
            {
                throw (new InterpreterException("\nerror: execution stack is empty"));
            }
            else
            {
                Statement statement = executionStack.pop();
                return(statement.execute(program));
            }
        }
Example #31
0
        public static EXECUTION_RESULT?CHECKLOCKTIME(ref ExecutionStack stack)
        {
            if (stack.Transaction == null)
            {
                return(EXECUTION_RESULT.NO_TRANSACTION_GIVEN);
            }
            if (stack.Count() < 1)
            {
                return(EXECUTION_RESULT.INVALID_STACK);
            }
            if (stack.Peek().Length != 4)
            {
                return(EXECUTION_RESULT.INVALID_BYTE_SIZE);
            }

            uint size = stack.PopUInt();

            stack.Push(stack.Transaction.lockTime >= size);
            return(null);
        }
Example #32
0
 private IEnumerable <string> CommandProcessor(XmlNode root)
 {
     if (root.HasChildNodes)
     {
         foreach (XmlNode topLevelCommand in root.ChildNodes)
         {
             if (topLevelCommand.LocalName.Equals("Run", StringComparison.InvariantCultureIgnoreCase))
             {
                 string name = "Unnamed Run";
                 SetupRun(topLevelCommand, ref name);
                 yield return(name);
             }
             else
             {
                 if (topLevelCommand.NodeType != XmlNodeType.Comment)
                 {
                     var commandName = topLevelCommand.LocalName;
                     if (!BatchCommands.TryGetValue(commandName.ToLowerInvariant(), out Action <XmlNode> command))
                     {
                         throw new XTMFRuntimeException(this, "We are unable to find a command named '" + commandName
                                                        + "' for batch processing.  Please check your batch file!\r\n" + topLevelCommand.OuterXml);
                     }
                     var initialCount = ExecutionStack.Count;
                     command.Invoke(topLevelCommand);
                     if (initialCount < ExecutionStack.Count)
                     {
                         var current = ExecutionStack.Pop();
                         foreach (var run in CommandProcessor(current))
                         {
                             yield return(run);
                         }
                     }
                 }
             }
         }
     }
 }