package nxm.sys.intr;

import nxm.sys.lib.Intrinsic;
import nxm.sys.lib.Midas;

/**
  Handles returning from a macro.

  @author Jeff Schoen

  @see Startmacro
*/
public class Endmacro extends Intrinsic {

  /** default constructor */
  public Endmacro () {}

  public int process() {
    if (M.macro == null) {
      M.warning("No macro executing ...");
    }
    else if (M.macro.level>0) {
      M.warning("Not at macro root level - structual error ...");
      M.macro.nextIndex = -1;
    }
    else if (M.pipeMode == Midas.PINIT) {
      M.macro.setPipeMode(Midas.PWAIT);
      M.pipeMode = Midas.PWAIT;
      M.macro.nextIndex--; // rerun this when pipe exits
    }
    else {
      M.macro.nextIndex = -1;
    }
    return FINISH;
  }
}
