View Javadoc

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