//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// PLEASE DO NOT EDIT WITHOUT THE EXPLICIT CONSENT OF THE AUTHOR! \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\

package hlt.language.design.instructions;

/**
 * @version     Last modified on Wed Jun 20 14:29:51 2012 by hak
 * @author      <a href="mailto:hak@acm.org">Hassan A&iuml;t-Kaci</a>
 * @copyright   &copy; <a href="http://www.hassan-ait-kaci.net/">by the author</a>
 */

import hlt.language.design.backend.Runtime;

public class PushValueObject extends Instruction implements PushValue, PushObject
{
  private Object _value;

  public PushValueObject ()
    {
      setName("PUSH_O");
    }

  public PushValueObject (Object value)
    {
      setName("PUSH_O");
      _value = value;
    }

  final Object value ()
    {
      return _value;
    }

  final void setValue (Object value)
    {
      _value = value;
    }

  public final void execute (Runtime r)
    {
      r.pushObject(_value);
      r.incIP();
    }
 
  public final boolean equals (Object object)
    {
      if (this == object)
        return true;

      if (!(object instanceof PushValueObject))
        return false;

      return _value == null ? ((PushValueObject)object).value() == null
                            : _value == ((PushValueObject)object).value();
    }

  public final int hashCode ()
    {
      return name().hashCode() + (_value == null ? "null".hashCode() :  _value.hashCode());
    }

 public final String toString ()
    {
      return name() + "(" + _value + ")";
    }
}
