Class ConcreteStack
- java.lang.Object
-
- com.tonic.analysis.execution.state.ConcreteStack
-
public final class ConcreteStack extends Object
Fixed-capacity operand stack of concrete values with the JVM dup and swap shuffle operations.
-
-
Constructor Summary
Constructors Constructor Description ConcreteStack(int maxStack)Creates an empty stack.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all values.intdepth()voiddup()Duplicates the top value.voiddup2()Duplicates the top two slots: one wide value or two narrow values.voiddup2X1()Duplicates the top two values beneath the third value.voiddup2X2()Duplicates the top two values beneath the fourth value.voiddupX1()Duplicates the top value beneath the second value.voiddupX2()Duplicates the top value beneath the third value.ConcreteValueget(int index)Reads a value by absolute index from the bottom.booleanisEmpty()intmaxDepth()ConcreteValuepeek()Reads the top value without popping.ConcreteValuepeek(int depth)Reads a value below the top without popping.ConcreteValuepop()Pops the top value.voidpop(int count)Discards values from the top.doublepopDouble()Pops the top value as a double.floatpopFloat()Pops the top value as a float.intpopInt()Pops the top value as an int.longpopLong()Pops the top value as a long.ObjectInstancepopReference()Pops the top value as a reference.voidpush(ConcreteValue value)Pushes a value.voidpushDouble(double value)Pushes a double.voidpushFloat(float value)Pushes a float.voidpushInt(int value)Pushes an int.voidpushLong(long value)Pushes a long.voidpushNull()Pushes a null reference.voidpushReference(ObjectInstance instance)Pushes a reference, mapping null to the null value.voidset(int index, ConcreteValue value)Replaces a value by absolute index from the bottom.List<ConcreteValue>snapshot()Captures the stack bottom-to-top as an unmodifiable list.voidswap()Swaps the top two values.StringtoString()
-
-
-
Method Detail
-
push
public void push(ConcreteValue value)
Pushes a value.- Parameters:
value- value to push- Throws:
StackOverflowError- if the stack is full
-
pushInt
public void pushInt(int value)
Pushes an int.- Parameters:
value- value to push
-
pushLong
public void pushLong(long value)
Pushes a long.- Parameters:
value- value to push
-
pushFloat
public void pushFloat(float value)
Pushes a float.- Parameters:
value- value to push
-
pushDouble
public void pushDouble(double value)
Pushes a double.- Parameters:
value- value to push
-
pushReference
public void pushReference(ObjectInstance instance)
Pushes a reference, mapping null to the null value.- Parameters:
instance- instance to push, may be null
-
pushNull
public void pushNull()
Pushes a null reference.
-
pop
public ConcreteValue pop()
Pops the top value.- Returns:
- the popped value
- Throws:
IllegalStateException- if the stack is empty
-
popInt
public int popInt()
Pops the top value as an int.- Returns:
- the int value
-
popLong
public long popLong()
Pops the top value as a long.- Returns:
- the long value
-
popFloat
public float popFloat()
Pops the top value as a float.- Returns:
- the float value
-
popDouble
public double popDouble()
Pops the top value as a double.- Returns:
- the double value
-
popReference
public ObjectInstance popReference()
Pops the top value as a reference.- Returns:
- the instance, or null for a null reference
-
pop
public void pop(int count)
Discards values from the top.- Parameters:
count- number of values to discard- Throws:
IllegalArgumentException- if the count is negativeIllegalStateException- if the count exceeds the current depth
-
peek
public ConcreteValue peek()
Reads the top value without popping.- Returns:
- the top value
- Throws:
IllegalStateException- if the stack is empty
-
peek
public ConcreteValue peek(int depth)
Reads a value below the top without popping.- Parameters:
depth- distance from the top, zero for the top- Returns:
- the value at that depth
- Throws:
IllegalStateException- if the depth is out of range
-
set
public void set(int index, ConcreteValue value)Replaces a value by absolute index from the bottom.- Parameters:
index- absolute indexvalue- replacement value- Throws:
IndexOutOfBoundsException- if the index is out of rangeIllegalArgumentException- if the value is null
-
get
public ConcreteValue get(int index)
Reads a value by absolute index from the bottom.- Parameters:
index- absolute index- Returns:
- the value at that index
- Throws:
IndexOutOfBoundsException- if the index is out of range
-
dup
public void dup()
Duplicates the top value.
-
dupX1
public void dupX1()
Duplicates the top value beneath the second value.
-
dupX2
public void dupX2()
Duplicates the top value beneath the third value.
-
dup2
public void dup2()
Duplicates the top two slots: one wide value or two narrow values.
-
dup2X1
public void dup2X1()
Duplicates the top two values beneath the third value.
-
dup2X2
public void dup2X2()
Duplicates the top two values beneath the fourth value.
-
swap
public void swap()
Swaps the top two values.
-
depth
public int depth()
- Returns:
- the current number of values
-
maxDepth
public int maxDepth()
- Returns:
- the capacity
-
isEmpty
public boolean isEmpty()
- Returns:
- true if no values are on the stack
-
clear
public void clear()
Removes all values.
-
snapshot
public List<ConcreteValue> snapshot()
Captures the stack bottom-to-top as an unmodifiable list.- Returns:
- the current values
-
-