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

package ilog.language.design.base;

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

import ilog.language.design.backend.Runtime;
import ilog.language.design.backend.Indexable;
import ilog.language.design.backend.RuntimeInt;
import ilog.language.design.backend.SizeMatchException;

public class CheckArraySize extends Instruction
{
  public CheckArraySize ()
    {
      setName("CHECK_ARRAY_SIZE");
    }

  public final void execute (Runtime r) throws SizeMatchException
    {
      int actualSize = r.popInt();
      int neededSize = 0;

      if (r.objectResult() instanceof RuntimeInt)
        neededSize = ((RuntimeInt)r.popObject()).value();
      else
        {
          neededSize = ((Indexable)r.objectResult()).size();      
          r.pushObject(null);   // dummy permutation array
        }

      if (actualSize != neededSize)
        throw new SizeMatchException("can't initialize an array of size "+neededSize+
                                     " with an array of size "+actualSize);

      r.incIP();
    }
}
