package nxm.sys.intr;

import nxm.sys.lib.Intrinsic;

/**
  Handles returning from a procedure or subroutine.

  @author Jeff Schoen

  @see Subroutine
  @see Procedure

*/
public class Return extends Intrinsic {

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

  /** {@inheritDoc} */
  public int process() {
    if (M.macro == null) {
      M.warning("No macro executing ...");
    }
    else if (M.macro.level<=0) {
      M.warning("No level to return from ...");
      M.macro.nextIndex = -1;
    }
    else {
      M.macro.nextIndex = M.macro.returns[M.macro.level];
      M.results = M.macro.results[M.macro.level];
      M.macro.level--;
    }

    return (FINISH);
  }
}

