Beispiel #1
0
static p_file *
mpy_on_include(const char *filename, int fullparse)
{
  mpy_fopen_t *f = 0;
  long len = 0;

  if (!mpy_parallel)
    return p_fopen(filename, "r");

  /* refuse to reopen file for debug line numbers when parallel */
  if (!fullparse) return 0;

  if (mpy_rank == 0) {
    p_file *file = p_fopen(filename, "r");
    long sz = file? p_fsize(file) : 0;
    char *txt;
    long dims[2];
    if (file) len = strlen(filename);
    dims[0] = 1;
    dims[1] = len + 1 + sz;
    ypush_check(1);  /* may be called outside any interpreted function */
    txt = ypush_c(dims);
    if (len) {
      strcpy(txt, filename);
      txt += len + 1;
      if (p_fread(file, txt, sz) != sz) {
        yarg_drop(1);
        y_errorq("rank 0 cannot read include file %s", filename);
        return 0;
      }
    } else {
      txt[0] = '\0';
    }
  }

  mpy_bcast(1);  /* broadcast top of stack to all ranks */
  if (mpy_rank > 0) {
    /* set filename, file contents on all non-0 ranks */
    long sz = 0;
    filename = ygeta_c(0, &sz, (long *)0);
    len = strlen(filename);
  }
  mpy_bcast(0);  /* send acknowledgement back to rank 0 */
  if (!len) return 0;

  f = p_malloc(sizeof(mpy_fopen_t));
  f->ops = &mpy_fopen_ops;
  f->array = yget_use(0);
  f->addr = len + 1;
  yarg_drop(1);

  return (p_file *)f;
}
Beispiel #2
0
int
yarg_true(int iarg)
{
  Symbol *s = (iarg>=0)? sp - iarg : 0;
  int x = 0;
  if (s) {
    CheckStack(1);
    sp[1].ops = &intScalar;
    if (s->ops==&referenceSym) s = &globTab[s->index];
    if (s->ops != &dataBlockSym) sp[1].value = s->value;
    else sp[1].value.db = Ref(s->value.db);
    sp++;
    sp->ops = s->ops;
    sp->ops->True();
    x = (int)ygets_l(0);
    yarg_drop(1);
  }
  return x;
}
Beispiel #3
0
Datei: yusb.c Projekt: emmt/yusb
static void define_global_int(const char* name, int value)
{
  ypush_int(value);
  yput_global(yget_global(name, 0), 0);
  yarg_drop(1);
}
Beispiel #4
0
/* modified main calls mpy_on_launch instead of on_launch */
int
mpy_on_launch(int argc, char *argv[])
{
  /* codger creates yinit.c:on_launch, which calls std0.c:y_launch */
  char *txt;
  int ret;
  mpy_initialize(&argc, &argv);
  if (!mpy_size) return on_launch(argc, argv);

  /* on_launch is collective operation, because it queries filesystem
   * to find path for .i files
   */
  if (!mpy_rank) {
    long i;
    /* broadcast yLaunchDir, ySiteDir, yHomeDir, defaultPath */
    long dims[2];
    int batflag = (argc>1) && !strcmp(argv[1],"-batch");
    /* lie about arguments for startup, will put back command line later */
    ret = on_launch(batflag?2:(argc?1:0), argv);
    if (batflag) {
      if (argc > 2) {
        /* mpy_initialize already saved -batch script name */
        for (i=3 ; i<argc ; i++) argv[i-2] = argv[i];
        argc -= 2;
      } else {
        argc = 1;
      }
    }
    /* now that on_launch/y_launch done, put back true command line */
    ym_argc = argc;
    ym_argv = argv;
    dims[0] = 1;
    dims[1] = STRLEN_P_1(yLaunchDir) + STRLEN_P_1(ySiteDir)
      + STRLEN_P_1(yHomeDir) + STRLEN_P_1(y_user_dir) + STRLEN_P_1(y_gist_dir);
    ypush_check(1);  /* we are outside any interpreted function */
    txt = ypush_c(dims);
    STRCPY_TXT(yLaunchDir);
    STRCPY_TXT(ySiteDir);
    STRCPY_TXT(yHomeDir);
    STRCPY_TXT(y_user_dir);
    STRCPY_TXT(y_gist_dir);
    mpy_bcast(1);

  } else {
    extern void Y_set_site(int);
    /* need to call on_launch to initialize interpreter for mpy_bcast */
    ret = on_launch(2, mpy_fake_argv);
    mpy_bcast(1);
    txt = ygeta_c(0, (long *)0, (long *)0);
    if (!txt[0]) txt++, yLaunchDir = 0;
    else yLaunchDir = p_strcpy(txt), txt += strlen(txt)+1;
    if (!txt[0]) txt++, ySiteDir = 0;
    else ySiteDir = p_strcpy(txt), txt += strlen(txt)+1;
    if (!txt[0]) txt++, yHomeDir = 0;
    else yHomeDir = p_strcpy(txt), txt += strlen(txt)+1;
    if (!txt[0]) txt++, y_user_dir = 0;
    else y_user_dir = p_strcpy(txt);
    if (!txt[0]) txt++, y_gist_dir = 0;
    else y_gist_dir = p_strcpy(txt);
    Y_set_site(0);
  }
  yarg_drop(1);
  /* after on_launch, virtual machine initialized, startup .i files
   * (including mpy.i) are queued by name but not yet opened, and
   * batch mode has been set if -batch argv
   */

  /* replace on_include with parallel version, set parallel flag */
  ycall_on_include(mpy_on_include);
  mpy_parallel = 1;

  /* disable autoload */
  if (!mpy0_eval_auto) {
    mpy0_eval_auto = auto_ops.Eval;
    auto_ops.Eval = mpy_eval_auto;
  }

  return ret;
}