Exemple #1
0
        public void Execute(Interpreter inI)
        {
            ObjectStack cstack = inI.CodeStack();
            ObjectStack estack = inI.ExecStack();

            if (estack.Size() > 0)
            {
                cstack.Push(estack.Pop());
            }
        }
Exemple #2
0
        /// <summary>Steps a Push interpreter forward with a given instruction limit.</summary>
        /// <remarks>
        /// Steps a Push interpreter forward with a given instruction limit.
        /// This method assumes that the intepreter is already setup with an active
        /// program (typically using \ref Execute).
        /// </remarks>
        /// <param name="inMaxSteps">The maximum number of instructions allowed to be executed.</param>
        /// <returns>The number of instructions executed.</returns>
        public int Step(int inMaxSteps)
        {
            stop = false;
            int executed = 0;

            while (inMaxSteps != 0 && _execStack.Size() > 0 && !stop)
            {
                var inst = _execStack.Pop();
                switch (ExecuteInstruction(inst))
                {
                case 0:
                    break;

                case -1:
                    throw new Exception("Unable to execute instruction " + inst);
                }
                inMaxSteps--;
                executed++;
            }
            _totalStepsTaken += executed;
            return(executed);
        }