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 import nl.tudelft.simulation.dsol.interpreter.classfile.ConstantFloat;
19 import nl.tudelft.simulation.dsol.interpreter.classfile.ConstantInteger;
20 import nl.tudelft.simulation.dsol.interpreter.classfile.ConstantString;
21
22 /***
23 * The LDC operation as defined in <a
24 * href="http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc8.html">
25 * http://java.sun.com/docs/books/vmspec/2nd-edition/html/Instructions2.doc8.html
26 * </a>.
27 * <p>
28 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
29 * University of Technology </a>, the Netherlands. <br>
30 * See for project information <a
31 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
32 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
33 * License (GPL) </a>, no warranty <br>
34 *
35 * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
36 * Jacobs </a><a
37 * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
38 * Verbraeck </a>
39 * @version 1.3 Apr 6, 2004
40 * @since 1.4
41 */
42 public class LDC extends VoidOperation
43 {
44 /*** OP refers to the operand code */
45 public static final int OP = 18;
46
47 /*** the index to load */
48 private int index = -1;
49
50 /***
51 * constructs a new LDC
52 *
53 * @param dataInput the dataInput
54 * @throws IOException on IOfailure
55 */
56 public LDC(final DataInput dataInput) throws IOException
57 {
58 super();
59 this.index = dataInput.readUnsignedByte();
60 }
61
62 /***
63 * @see nl.tudelft.simulation.dsol.interpreter.operations.VoidOperation#execute(
64 * nl.tudelft.simulation.dsol.interpreter.OperandStack,
65 * nl.tudelft.simulation.dsol.interpreter.classfile.Constant[],
66 * nl.tudelft.simulation.dsol.interpreter.LocalVariable[])
67 */
68 public void execute(final OperandStack stack,
69 final Constant[] constantPool, final LocalVariable[] localVariables)
70 {
71 Constant constant = constantPool[this.index];
72 if (constant instanceof ConstantInteger)
73 {
74 stack.push(new Integer(((ConstantInteger) constant).getValue()));
75 } else if (constant instanceof ConstantFloat)
76 {
77 stack.push(new Float(((ConstantFloat) constant).getValue()));
78 } else if (constant instanceof ConstantString)
79 {
80 stack.push(((ConstantString) constant).getValue());
81 }
82 }
83
84 /***
85 * @see nl.tudelft.simulation.dsol.interpreter.Operation#getByteLength()
86 */
87 public int getByteLength()
88 {
89 return OPCODE_BYTE_LENGTH + 1;
90 }
91
92 /***
93 * @see nl.tudelft.simulation.dsol.interpreter.Operation#getOpcode()
94 */
95 public int getOpcode()
96 {
97 return LDC.OP;
98 }
99 }