package rebelsky.pal;

/**
 * Convert a float to an integer.
 *
 * @author Samuel A. Rebelsky
 * @version 1.1 of December 2002.
 */
public class F2I
  implements Instruction
{
  // +--------+------------------------------------------------------------
  // | Fields |
  // +--------+

  /** The source of the conversion (the float). */
  Variable source;

  /** The destination of the conversion (the integer). */
  Variable destination;


  // +--------------+------------------------------------------------------
  // | Constructors |
  // +--------------+

  /** 
   * Create a new instruction to convert a value.
   */
  public F2I(Variable source, Variable destination)
  {
    this.source = source;
    this.destination = destination;
  } // F2I(Variable,Variable)


  // +---------+-----------------------------------------------------------
  // | Methods |
  // +---------+

  /** 
   * Execute the instruction on a machine. 
   * 
   * @exception Exception
   *   If one of the memory locations is invalid.
   *   If the destination is a constant or label.
   */
  public void execute(Computer hal)
    throws Exception
  {
    destination.iset(hal, (int) source.fget(hal));
  } // execute(Computer)

  /** Convert the instruction to a string (usually for printing). */
  public String toString()
  {
    return "  F2I " + source.toString() + " -> " + destination.toString();
  } // toString()

} // class F2I

