Class ScriptInstanceStack

java.lang.Object
com.blackrook.rookscript.ScriptInstanceStack

public class ScriptInstanceStack extends Object
The combined stack for a script instance.
Author:
Matthew Tropiano
  • Constructor Details

    • ScriptInstanceStack

      public ScriptInstanceStack(int activationDepth, int valueStackDepth)
      Creates a new instance stack.
      Parameters:
      activationDepth - the activation depth to use (function calls).
      valueStackDepth - the stack depth to use (script values).
  • Method Details

    • reset

      public void reset()
      Resets the stack.
    • getCurrentActivationStackDepth

      public int getCurrentActivationStackDepth()
      Gets the current activation stack depth. If 0, then this is 0 functions deep. If -1, this instance has not been started.
      Returns:
      the depth of the activation stack.
    • getActivationStackDepth

      public int getActivationStackDepth()
      Returns:
      the maximum depth of the activation stack.
    • getCurrentValueStackDepth

      public int getCurrentValueStackDepth()
      Returns:
      the current value stack depth.
    • getValueStackDepth

      public int getValueStackDepth()
      Returns:
      the maximum depth of the value stack.
    • getValue

      public boolean getValue(String name, ScriptValue out)
      Gets a corresponding script value by name. Only looks at the topmost scope. Changing the returned value reference does not change the mapped value, unless the referenced object type like a map or list.
      Parameters:
      name - the variable name.
      out - the destination variable for the value.
      Returns:
      true if a corresponding value was fetched into out, false if not. If false, out is set to the null value.
    • setValue

      public void setValue(String name, ScriptValue value)
      Sets a corresponding script value by name. If the value does not exist, it is set on the topmost scope in the stack.
      Parameters:
      name - the name of the variable.
      value - the value to set.
    • getCommandIndex

      public int getCommandIndex()
      Returns:
      the current command index.
    • setCommandIndex

      public void setCommandIndex(int index)
      Sets the current command index (jump).
      Parameters:
      index - the new index.
    • incrementCommandIndex

      public int incrementCommandIndex()
      Increments the current command index and returns it.
      Returns:
      the new current index.
    • pushFrame

      public void pushFrame(int nextCommandIndex)
      Pushes a new activation frame (local scope and command index).
      Parameters:
      nextCommandIndex - the next command index.
      Throws:
      ScriptStackException - if this call would breach the stack capacity.
    • popFrame

      public void popFrame()
      Pops an activation frame (local scope and command index).
      Throws:
      ScriptStackException - if there's nothing on the stack when this is called.
    • pushStackValue

      public <T> void pushStackValue(T value)
      Pushes a value onto the stack.
      Type Parameters:
      T - the value type.
      Parameters:
      value - the value to push.
      Throws:
      ScriptStackException - if this call would breach the stack capacity.
    • popStackValue

      public void popStackValue(ScriptValue out)
      Pops a value off the stack.
      Parameters:
      out - the output value.
      Throws:
      ScriptStackException - if there's nothing on the stack when this is called.
    • popStackValue

      public void popStackValue()
      Pops a value off the stack, ignoring output.
      Throws:
      ScriptStackException - if there's nothing on the stack when this is called.
    • getStackValue

      public void getStackValue(int depthFromTop, ScriptValue out)
      Gets a value on the stack (reference).
      Parameters:
      depthFromTop - the depth from the top (0 is top, 1 ... N is N places down).
      out - the output value.
      Throws:
      ScriptStackException - if the top minus the depth escapes the active stack bounds.
    • clearStackValuesFromDepth

      public void clearStackValuesFromDepth(int index)
      Nullifies values from an arbitrary index in the stack down to the current top of the stack (but not the current top).
      Parameters:
      index - the starting index. If past the capacity, it is the capacity - 1. If less than
    • clearStackValues

      public void clearStackValues()
      Clears the value stack.