1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.interpreter.operations;
11
12 import java.io.DataInput;
13 import java.io.IOException;
14
15 import nl.tudelft.simulation.dsol.interpreter.LocalVariable;
16 import nl.tudelft.simulation.dsol.interpreter.OperandStack;
17 import nl.tudelft.simulation.dsol.interpreter.classfile.Constant;
18
19 /***
20 * The LSTORE operation as defined in <a
21 * href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc8.html">
22 * http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc8.html
23 * </a>.
24 * <p>
25 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
26 * University of Technology </a>, the Netherlands. <br>
27 * See for project information <a
28 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
29 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
30 * License (GPL) </a>, no warranty <br>
31 *
32 * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
33 * Jacobs </a><a
34 * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
35 * Verbraeck </a>
36 * @version 1.3 Apr 6, 2004
37 * @since 1.4
38 */
39 public class LSTORE extends VoidOperation
40 {
41 /*** OP refers to the operand code */
42 public static final int OP = 55;
43
44 /*** the index to load */
45 private int index = -1;
46
47 /*** see the wide statement */
48 private boolean widened = false;
49
50 /***
51 * constructs a new LSTORE
52 *
53 * @param dataInput the dataInput
54 * @throws IOException on IOfailure
55 */
56 public LSTORE(final DataInput dataInput) throws IOException
57 {
58 this(dataInput, false);
59 }
60
61 /***
62 * constructs a new LSTORE
63 *
64 * @param dataInput the dataInput
65 * @param widened whether or not to widen
66 * @throws IOException on IOfailure
67 */
68 public LSTORE(final DataInput dataInput, final boolean widened)
69 throws IOException
70 {
71 super();
72 this.widened = widened;
73 if (widened)
74 {
75 this.index = dataInput.readUnsignedShort();
76 } else
77 {
78 this.index = dataInput.readUnsignedByte();
79 }
80 }
81
82 /***
83 * @see nl.tudelft.simulation.dsol.interpreter.operations.VoidOperation#execute(
84 * nl.tudelft.simulation.dsol.interpreter.OperandStack,
85 * nl.tudelft.simulation.dsol.interpreter.classfile.Constant[],
86 * nl.tudelft.simulation.dsol.interpreter.LocalVariable[])
87 */
88 public void execute(final OperandStack stack,
89 final Constant[] constantPool, final LocalVariable[] localVariables)
90 {
91 localVariables[this.index].setValue(stack.pop());
92 }
93
94 /***
95 * @see nl.tudelft.simulation.dsol.interpreter.Operation#getByteLength()
96 */
97 public int getByteLength()
98 {
99 int result = OPCODE_BYTE_LENGTH + 1;
100 if (this.widened)
101 {
102 result++;
103 }
104 return result;
105
106 }
107
108 /***
109 * @see nl.tudelft.simulation.dsol.interpreter.Operation#getOpcode()
110 */
111 public int getOpcode()
112 {
113 return LSTORE.OP;
114 }
115 }