public void Execute(Interpreter inI) { ObjectStack cstack = inI.CodeStack(); ObjectStack estack = inI.ExecStack(); if (estack.Size() > 0) { cstack.Push(estack.Pop()); } }
public void PushInput(Interpreter inI, int n) { ObjectStack _stack = inI.InputStack(); if (_stack.Size() > n) { object inObject = _stack.DeepPeek(n); if (inObject is int) { IntStack istack = inI.IntStack(); istack.Push((int)inObject); } else { // if (inObject is Number) // { // FloatStack fstack = inI.FloatStack(); // fstack.Push(((Number)inObject).FloatValue()); // } //else if (inObject is float) { FloatStack fstack = inI.FloatStack(); fstack.Push((float)inObject); } else { if (inObject is bool) { BooleanStack bstack = inI.BoolStack(); bstack.Push((bool)inObject); } else { Console.Error.WriteLine("Error during input.index - object " + inObject.GetType() + " is not a legal object according to " + this.GetType() + "."); } } } } }
/// <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); }