Esempio n. 1
0
 protected void AssignStacksFromFrame() {
   _floatStack = (floatStack) _floatFrameStack.top();
   _intStack = (intStack) _intFrameStack.top();
   _boolStack = (booleanStack) _boolFrameStack.top();
   _codeStack = (ObjectStack) _codeFrameStack.top();
   _nameStack = (ObjectStack) _nameFrameStack.top();
 }
Esempio n. 2
0
  public void PopStacks() {
    _floatFrameStack.pop();
    _intFrameStack.pop();
    _boolFrameStack.pop();
    _codeFrameStack.pop();
    _nameFrameStack.pop();

    AssignStacksFromFrame();
  }
Esempio n. 3
0
  public void PushStacks() {
    _floatFrameStack.push(new floatStack());
    _intFrameStack.push(new intStack());
    _boolFrameStack.push(new booleanStack());
    _codeFrameStack.push(new ObjectStack());
    _nameFrameStack.push(new ObjectStack());

    AssignStacksFromFrame();
  }
Esempio n. 4
0
  /**
   * 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;
  }
Esempio n. 5
0
  /** 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();
    }
  }
Esempio n. 6
0
  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;
  }
Esempio n. 7
0
  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);
    }
  }
Esempio n. 8
0
 /**
  * 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);
 }