//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// 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;
import hlt.language.design.backend.ObjectMap;
import hlt.language.design.backend.Indexable;
import hlt.language.design.backend.SizeMatchException;
import hlt.language.design.backend.NullValueException;

public class ObjectArrayToMap extends Instruction
{
  public ObjectArrayToMap ()
    {
      setName("ARRAY_TO_MAP_O");
    }

  public final void execute (Runtime r) throws SizeMatchException, NullValueException
    {
      Object[] array = (Object[])r.popObject("can't convert a null array to a map");
      Indexable indexable = (Indexable)r.popObject("can't make a map with a null indexable");

      if (indexable.size() != array.length)
        throw new SizeMatchException("indexable size ("+indexable.size()+
                                     ") does not match array size ("+array.length+")");
      r.pushObject(new ObjectMap(array,indexable));
      r.incIP();
    }
}
