示例#1
0
// assign error to variable or match with next expression
int err_throw_catch(const char *err) {
  var_t *arg;
  var_t v_catch;
  int caught = 1;
  switch (code_peek()) {
  case kwTYPE_VAR:
    arg = code_getvarptr();
    v_setstr(arg, err);
    break;
  case kwTYPE_STR:
    v_init(&v_catch);
    eval(&v_catch);
    // catch is conditional on matching error
    caught = (v_catch.type == V_STR && strstr(err, v_catch.v.p.ptr) != NULL);
    v_free(&v_catch);
    break;
  case kwTYPE_EOC:
  case kwTYPE_LINE:
    break;
  default:
    rt_raise(ERR_INVALID_CATCH);
    break;
  }
  return caught;
}
示例#2
0
/**
 * build parameter table
 */
int slib_build_ptable(slib_par_t *ptable) {
#if defined(LNX_EXTLIB) || defined(WIN_EXTLIB)
  int pcount = 0;
  var_t *arg = NULL;
  byte ready, code;
  bcip_t ofs;

  if (code_peek() == kwTYPE_LEVEL_BEGIN) {
    code_skipnext();
    ready = 0;
    do {
      code = code_peek();
      switch (code) {
      case kwTYPE_EOC:
        code_skipnext();
        break;
      case kwTYPE_SEP:
        code_skipsep();
        break;
      case kwTYPE_LEVEL_END:
        ready = 1;
        break;
      case kwTYPE_VAR:
        // variable
        ofs = prog_ip;

        if (code_isvar()) {
          // push parameter
          ptable[pcount].var_p = code_getvarptr();
          ptable[pcount].byref = 1;
          pcount++;
          break;
        }

        // restore IP
        prog_ip = ofs;
        // no 'break' here
      default:
        // default --- expression (BYVAL ONLY)
        arg = v_new();
        eval(arg);
        if (!prog_error) {
          // push parameter
          ptable[pcount].var_p = arg;
          ptable[pcount].byref = 0;
          pcount++;
        }
        else {
          v_free(arg);
          v_detach(arg);
          return pcount;
        }
      }
    } while (!ready);
    // kwTYPE_LEVEL_END
    code_skipnext();
  }

  return pcount;
#else
  return 0;
#endif
}