Beispiel #1
0
static char *predicate_enumerate(const char *prefix, int state) {
  CACHE_REGS
  PredEntry *p;
  ModEntry m0, *mod;
  AtomEntry *ap;

  if (!state) {
    p = NULL;
    mod = &m0;
    m0.NextME = CurrentModules;
    if (mod->AtomOfME == AtomIDB)
      mod = mod->NextME;
  } else {
    Term cmod;
    p = LOCAL_SearchPreds;
    cmod = (p->ModuleOfPred != PROLOG_MODULE ? p->ModuleOfPred : TermProlog);
    mod = Yap_GetModuleEntry(cmod);
  }
  while (mod) {
    // move to next o;
    if (p)
      p = p->NextPredOfModule;
    while (p == NULL) {
      mod = mod->NextME;
      if (!mod) {
        // done
        LOCAL_SearchPreds = NULL;
        return NULL;
      }
      if (mod->AtomOfME == AtomIDB)
        mod = mod->NextME;
      p = mod->PredForME;
    }
    char *c = RepAtom(ap = NameOfPred(p))->StrOfAE;
    if (strlen(c) > strlen(prefix) && strstr(c, prefix) == c &&
        !(p->PredFlags & HiddenPredFlag)) {
      LOCAL_SearchPreds = p;
      arity_t ar = p->ArityOfPE;
      int l, r;
      if (Yap_IsPrefixOp(AbsAtom(ap), &l, &r) && ar == 1) {
        return c;
      }
      strncpy(LOCAL_FileNameBuf, c, YAP_FILENAME_MAX);
      strncat(LOCAL_FileNameBuf, "(", YAP_FILENAME_MAX);
      return LOCAL_FileNameBuf;
    }
  }
  LOCAL_SearchPreds = NULL;
  return NULL;
}
Beispiel #2
0
static int OpDec(int p, const char *type, Atom a, Term m) {
  int i;
  AtomEntry *ae = RepAtom(a);
  OpEntry *info;

#if defined(MODULE_INDEPENDENT_OPERATORS_FLAG)
  if (booleanFlag(MODULE_INDEPENDENT_OPERATORS_FLAG)) {
    m = PROLOG_MODULE;    
} else
#endif
    {
  if (m == TermProlog)
    m = PROLOG_MODULE;
  else if (m == USER_MODULE)
    m = PROLOG_MODULE;    
  }
  for (i = 1; i <= 7; ++i)
    if (strcmp(type, optypes[i]) == 0)
      break;
  if (i > 7) {
    Yap_Error(DOMAIN_ERROR_OPERATOR_SPECIFIER, MkAtomTerm(Yap_LookupAtom(type)),
              "op/3");
    return (FALSE);
  }
  if (p) {
    if (i == 1 || i == 2 || i == 4)
      p |= DcrlpFlag;
    if (i == 1 || i == 3 || i == 6)
      p |= DcrrpFlag;
  }
  WRITE_LOCK(ae->ARWLock);
  info = Yap_GetOpPropForAModuleHavingALock(ae, m);
  if (EndOfPAEntr(info)) {
    ModEntry *me;
    info = (OpEntry *)Yap_AllocAtomSpace(sizeof(OpEntry));
    if (!info)
      return false;
    info->KindOfPE = Ord(OpProperty);
    info->NextForME = (me = Yap_GetModuleEntry(m))->OpForME;
    me->OpForME = info;
    info->OpModule = m;    
    info->OpName = a;
    // LOCK(OpListLock);
    info->OpNext = OpList;
    OpList = info;
    // UNLOCK(OpListLock);
    AddPropToAtom(ae, (PropEntry *)info);
    INIT_RWLOCK(info->OpRWLock);
    WRITE_LOCK(info->OpRWLock);
    WRITE_UNLOCK(ae->ARWLock);
    info->Prefix = info->Infix = info->Posfix = 0;
  } else {
    WRITE_LOCK(info->OpRWLock);
    WRITE_UNLOCK(ae->ARWLock);
  }
  if (i <= 3) {
    if (trueGlobalPrologFlag(ISO_FLAG) &&
        info->Posfix != 0) /* there is a posfix operator */ {
      /* ISO dictates */
      WRITE_UNLOCK(info->OpRWLock);
      Yap_Error(PERMISSION_ERROR_CREATE_OPERATOR, MkAtomTerm(a), "op/3");
      return false;
    }
    info->Infix = p;
  } else if (i <= 5) {

    if (trueGlobalPrologFlag(ISO_FLAG) &&
        info->Infix != 0) /* there is an infix operator */ {
      /* ISO dictates */
      WRITE_UNLOCK(info->OpRWLock);
      Yap_Error(PERMISSION_ERROR_CREATE_OPERATOR, MkAtomTerm(a), "op/3");
      return false;
    }
    info->Posfix = p;
  } else {
    info->Prefix = p;
  }
  WRITE_UNLOCK(info->OpRWLock);
  return true;
}