package nl.tudelft.simulation.dsol.interpreter.operations; import java.io.DataInput; import java.io.IOException; import nl.tudelft.simulation.dsol.interpreter.LocalVariable; import nl.tudelft.simulation.dsol.interpreter.OperandStack; import nl.tudelft.simulation.dsol.interpreter.classfile.Constant; /** * The ISTORE operation as defined in * http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc6.html . *
* (c) copyright 2002-2014 Delft University of Technology.
* BSD-style license. See DSOL License.
* @author Peter Jacobs
* @author Alexander Verbraeck
*/
public class ISTORE extends VoidOperation
{
/** OP refers to the operand code. */
public static final int OP = 54;
/** the index to load. */
private final int index;
/** see the wide statement. */
private final boolean widened;
/**
* constructs a new ISTORE.
* @param dataInput the dataInput
* @throws IOException on IOfailure
*/
public ISTORE(final DataInput dataInput) throws IOException
{
this(dataInput, false);
}
/**
* constructs a new ISTORE.
* @param dataInput the dataInput
* @param widened whether or not to widen
* @throws IOException on IOfailure
*/
public ISTORE(final DataInput dataInput, final boolean widened) throws IOException
{
super();
this.widened = widened;
if (widened)
{
this.index = dataInput.readUnsignedShort();
}
else
{
this.index = dataInput.readUnsignedByte();
}
}
/** {@inheritDoc} */
@Override
public final void execute(final OperandStack stack, final Constant[] constantPool,
final LocalVariable[] localVariables)
{
localVariables[this.index].setValue(stack.pop());
}
/** {@inheritDoc} */
@Override
public final int getByteLength()
{
int result = OPCODE_BYTE_LENGTH + 1;
if (this.widened)
{
result++;
}
return result;
}
/** {@inheritDoc} */
@Override
public final int getOpcode()
{
return ISTORE.OP;
}
}