package nxm.sys.intr;

import nxm.sys.lib.Intrinsic;
import nxm.sys.lib.Table;

/**
  Declare global results parameters.

  This causes table lookups of the named keynames to traverse to the
  previous table.

  @author Jeff Schoen
*/
public class Global extends Intrinsic {

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

  public int process() {
    // find global table
    nxm.sys.lib.Table rt = MR.getRoot();
    if (MA.getState("/PARENT")) rt = MR.getPrevious();

    // add local reference to global table
    for (int i=1; i<=MA.nargs; i++) {
      String label = MA.getU(i);
      int ic = label.indexOf(':');
      if (ic>=0) {
        M.warning("Ignored typing of global variable "+label);
        label = label.substring(ic+1);
      }
      MR.put (label,rt);
    }

    if (MA.getState("/READALL")) MR.setFlags(Table.AUTOREADPREV);

    return FINISH;
  }

}
