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