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

package ilog.language.design.base;

/**
 * @version     Last modified on Wed Apr 10 17:56:46 2002 by hak
 * @author      <a href="mailto:hak@ilog.fr">Hassan A&iuml;t-Kaci</a>
 * @copyright   &copy; 2002 <a href="http://www.ilog.fr/">ILOG, S.A.</a>
 */

import ilog.language.design.backend.Runtime;
import ilog.language.design.backend.ObjectMap;
import ilog.language.design.backend.Indexable;
import ilog.language.design.backend.SizeMatchException;
import ilog.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();
    }
}
