package rebelsky.pal; /** * A temprary in a PAL program. Temporaries should eventually be * eliminated from programs. * * @author Samuel A. Rebelsky * @version 1.1 of December 2002 */ public class Temporary extends Variable { // +---------------+----------------------------------------------------- // | Static Fields | // +---------------+ /** The counter of temporaries, used mostly for printing. */ static int temps = 0; // +--------+------------------------------------------------------------ // | Fields | // +--------+ /** The number of the temporary. */ int tempnum; /** The contents of the temporary. Right now, we only permit integers. */ int contents = 0; // +--------------+------------------------------------------------------ // | Constructors | // +--------------+ /** * Build a new temporary. */ public Temporary() { this.tempnum = temps++; } // Label() // +---------+----------------------------------------------------------- // | Methods | // +---------+ /** * Get the integer stored in this temporary. */ public int iget(Computer hal) { return this.contents; } // iget() /** * Store an integer in the temporary. */ public void iset(Computer hal, int newval) { this.contents = newval; } // iset(int) /** Convert the location to a string (usually for printing). */ public String toString() { return "%tmp-" + tempnum; } // toString() } // class Temporary