package rebelsky.pal;

/**
 * Things that can store values (e.g., registers, memory locations)
 * for PAL, the pseudo-assembly language.  For simplicity, we assume
 * that all the kinds of values stored (currently floats and integers)
 * take the same amount of space.  The default values are integers.
 * Subclasses should not override fget and fset, which are intended
 * to convert to and from integers.
 *
 * @author Samuel A. Rebelsky
 * @version 1.1 of December 2002
 */
public abstract class Variable
{
  // +---------+-----------------------------------------------------------
  // | Methods |
  // +---------+

  /**
   * Get the float stored in this location.
   *
   * @exception Exception
   *   If the location is invalid.
   */
  public float fget(Computer hal)
    throws Exception
  {
    return Float.intBitsToFloat(this.iget(hal));
  } // fget(Computer)

  /**
   * Store a float in this location.
   *
   * @exception Exception
   *   If the location is invalid.
   */
  public void fset(Computer hal, float newval)
    throws Exception
  {
    this.iset(hal, Float.floatToIntBits(newval));
  } // fset(Computer, float)

  /** 
   * Get the integer stored in this location. 
   *
   * @exception Exception
   *   If the location is invalid.
   */
  public abstract int iget(Computer hal)
    throws Exception;

  /**
   * Store an integer at this location.
   *
   * @exception Exception
   *   If the location is invalid.
   *   If the container does not permit values to change.
   */
  public abstract void iset(Computer hal, int newval)
    throws Exception;

  /**
   * Convert the container to a string (for printing or something similar).
   */
  public abstract String toString();

} // interface Variable

