/*
* Copyright (c) 2006 Thomas Weise
*
* E-Mail : tweise@gmx.de
* Creation Date : 2006-06-26 08:21:11
* Original Filename: org.dgpf.gp.vm.instructions.ctrl.Pop.java
* Version : 1.0.0
* Last modification: 2006-07-15
* by: Thomas Weise
*
* License : GNU LESSER GENERAL PUBLIC LICENSE
* Version 2.1, February 1999
* You should have received a copy of this license along
* with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307, USA or download the license under
* http://www.gnu.org/copyleft/lesser.html.
*
* Warranty : This software is provided "as is" without any
* warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose.
* See the Gnu Lesser General Public License for more
* details.
*/
package org.dgpf.gp.vm.instructions.ctrl;
import org.dgpf.gp.vm.base.IInstructionHandler;
import org.dgpf.gp.vm.base.VM;
import org.dgpf.gp.vm.instructions.BasicCosts;
import org.dgpf.gp.vm.instructions.base.MemInstr1;
/**
* The pop operation.
*
* @author Thomas Weise
*/
public class Pop extends MemInstr1
{
/**
* The serial version uid.
*/
private static final long serialVersionUID = 1;
/**
* Create a new pop instruction.
* @param p_addr_1 The first address.
* @param p_relative_1 true
for relative memory access,
* false
for direct access for the first
* address.
*/
public Pop (final int p_addr_1,
final boolean p_relative_1)
{
super(p_addr_1, p_relative_1);
}
/**
* Execute this instruction on a virtual machine.
* @param p_machine The virtual machine to execute on.
* @return The cost of the execution of the last instruction.
*/
@Override
protected final double execute (final VM p_machine)
{
this.write_1(p_machine, p_machine.pop());
return BasicCosts.POP_COSTS;
}
/**
* Store this objects content into a string builder.
* @param p_sb The string builder to store stuff into.
*/
@Override
public final void to_string (final StringBuilder p_sb)
{
p_sb.append("pop ");
this.mem_1_str(p_sb);
}
/**
* Obtain the instruction handler to be used for this sort of instructions.
* @return The instruction handler to be used for this sort of instructions.
*/
@Override
public final IInstructionHandler get_handler()
{
return PopHandler.INSTANCE;
}
/**
* This method tells if this instruction can be useful at the beginning of
* a procedure. A pop, for example, will never be useful, since the stack
* of a procedure is initially empty.
* @return true
if and only if an instruction is useful at the
* beginning of a procedure.
*/
public boolean is_useful_at_begin()
{
return false;
}
/**
* Check whether the address parameter of the index p_index
* is read from or written to.
* @param p_index The index of the address parameter wanted.
* @return Or-ed combination of 1
if this addres is read from,
* 2
if it is written to.
*/
@Override
protected final int get_access (final int p_index)
{
return ((p_index == 1) ? 2 : 0);
}
/**
* Get a string that can be copy-pasted into a java file an that creates
* this instruction.
* @param p_b The string builder to add with.
*/
@Override
public final void to_creation_string (final StringBuilder p_b)
{
p_b.append("new Pop(");
super.to_creation_string(p_b);
p_b.append(')');
}
}