protected void AssignStacksFromFrame() { _floatStack = (floatStack) _floatFrameStack.top(); _intStack = (intStack) _intFrameStack.top(); _boolStack = (booleanStack) _boolFrameStack.top(); _codeStack = (ObjectStack) _codeFrameStack.top(); _nameStack = (ObjectStack) _nameFrameStack.top(); }
public void PopStacks() { _floatFrameStack.pop(); _intFrameStack.pop(); _boolFrameStack.pop(); _codeFrameStack.pop(); _nameFrameStack.pop(); AssignStacksFromFrame(); }
public void PushStacks() { _floatFrameStack.push(new floatStack()); _intFrameStack.push(new intStack()); _boolFrameStack.push(new booleanStack()); _codeFrameStack.push(new ObjectStack()); _nameFrameStack.push(new ObjectStack()); AssignStacksFromFrame(); }
/** * Steps a Push interpreter forward with a given instruction limit. * * <p>This method assumes that the intepreter is already setup with an active program (typically * using \ref Execute). * * @param inMaxSteps The maximum number of instructions allowed to be executed. * @return The number of instructions executed. */ public int Step(int inMaxSteps) { int executed = 0; while (inMaxSteps != 0 && _execStack.size() > 0) { ExecuteInstruction(_execStack.pop()); inMaxSteps--; executed++; } _totalStepsTaken += executed; return executed; }
/** Resets the Push interpreter state by clearing all of the stacks. */ public void ClearStacks() { _intStack.clear(); _floatStack.clear(); _execStack.clear(); _nameStack.clear(); _boolStack.clear(); _codeStack.clear(); _inputStack.clear(); // Clear all custom stacks for (Stack s : _customStacks) { s.clear(); } }
public int ExecuteInstruction(Object inObject) { if (inObject instanceof Program) { Program p = (Program) inObject; if (_useFrames) { _execStack.push("frame.pop"); } p.PushAllReverse(_execStack); if (_useFrames) { _execStack.push("frame.push"); } return 0; } if (inObject instanceof Integer) { _intStack.push((Integer) inObject); return 0; } if (inObject instanceof Number) { _floatStack.push(((Number) inObject).floatValue()); return 0; } if (inObject instanceof Instruction) { ((Instruction) inObject).Execute(this); return 0; } if (inObject instanceof String) { Instruction i = _instructions.get(inObject); if (i != null) { i.Execute(this); } else { _nameStack.push(inObject); } return 0; } return -1; }
public void PopFrame() { if (_useFrames) { boolean boolTop = _boolStack.top(); int intTop = _intStack.top(); float floatTop = _floatStack.top(); Object nameTop = _nameStack.top(); Object codeTop = _codeStack.top(); PopStacks(); _floatStack.push(floatTop); _intStack.push(intTop); _boolStack.push(boolTop); if (nameTop != null) _nameStack.push(nameTop); if (codeTop != null) _codeStack.push(codeTop); } }
/** * Loads a Push program into the interpreter's exec and code stacks. * * @param inProgram The program to load. */ public void LoadProgram(Program inProgram) { _codeStack.push(inProgram); _execStack.push(inProgram); }