static void LookupPredEntry(PredEntry *pe) { CACHE_REGS CELL hash = (((CELL)(pe))/(2*sizeof(CELL))) % LOCAL_ExportPredEntryHashTableSize; export_pred_entry_hash_entry_t *p; UInt arity = pe->ArityOfPE; p = LOCAL_ExportPredEntryHashChain+hash; while (p->val) { if (p->val == pe) { return; } p++; if (p == LOCAL_ExportPredEntryHashChain+LOCAL_ExportPredEntryHashTableSize) p = LOCAL_ExportPredEntryHashChain; } p->arity = arity; p->val = pe; if (pe->ModuleOfPred != IDB_MODULE) { if (arity) { p->u_af.f = pe->FunctorOfPred; LookupFunctor(pe->FunctorOfPred); } else { p->u_af.a = (Atom)(pe->FunctorOfPred); LookupAtom((Atom)(pe->FunctorOfPred)); } } else { if (pe->PredFlags & AtomDBPredFlag) { p->u_af.a = (Atom)(pe->FunctorOfPred); p->arity = (CELL)(-2); LookupAtom((Atom)(pe->FunctorOfPred)); } else if (!(pe->PredFlags & NumberDBPredFlag)) { p->u_af.f = pe->FunctorOfPred; p->arity = (CELL)(-1); LookupFunctor(pe->FunctorOfPred); } else { p->u_af.f = pe->FunctorOfPred; } } if (pe->ModuleOfPred) { p->module = AtomOfTerm(pe->ModuleOfPred); } else { p->module = AtomProlog; } LookupAtom(p->module); LOCAL_ExportPredEntryHashTableNum++; if (LOCAL_ExportPredEntryHashTableNum > LOCAL_ExportPredEntryHashTableSize/2 ) { GrowPredTable(); if (!LOCAL_ExportPredEntryHashChain) { return; } } }
static void LookupFunctor(Functor fun) { CACHE_REGS CELL hash = ((CELL)(fun))/(2*sizeof(CELL)) % LOCAL_ExportFunctorHashTableSize; export_functor_hash_entry_t *f; Atom name = NameOfFunctor(fun); UInt arity = ArityOfFunctor(fun); f = LOCAL_ExportFunctorHashChain+hash; while (f->val) { if (f->val == fun) { return; } f++; if (f == LOCAL_ExportFunctorHashChain+LOCAL_ExportFunctorHashTableSize) f = LOCAL_ExportFunctorHashChain; } LookupAtom(name); f->val = fun; f->name = name; f->arity = arity; LOCAL_ExportFunctorHashTableNum++; if (LOCAL_ExportFunctorHashTableNum > LOCAL_ExportFunctorHashTableSize/2 ) { GrowFunctorTable(); if (!LOCAL_ExportFunctorHashChain) { return; } } }
Atom Yap_FullLookupAtom(const char *atom) { /* lookup atom in atom table */ Atom t; if ((t = SearchInInvisible((const unsigned char *)atom)) != NIL) { return (t); } return (LookupAtom((const unsigned char *)atom)); }
Atom Yap_FullLookupAtom(char *atom) { /* lookup atom in atom table */ Atom t; if ((t = SearchInInvisible(atom)) != NIL) { return (t); } return(LookupAtom(atom)); }
Atom Yap_LookupAtomWithLength(const char *atom, size_t len0) { /* lookup atom in atom table */ Atom at; unsigned char *ptr; /* not really a wide atom */ ptr = Yap_AllocCodeSpace(len0 + 1); if (!ptr) return NIL; memcpy(ptr, atom, len0); ptr[len0] = '\0'; at = LookupAtom(ptr); Yap_FreeCodeSpace(ptr); return at; }
Atom Yap_LookupMaybeWideAtomWithLength( const wchar_t *atom, size_t len0) { /* lookup atom in atom table */ Atom at; int wide = FALSE; size_t i = 0; while (i < len0) { // primary support for atoms with null chars wchar_t c = atom[i]; if (c > 255) { wide = TRUE; break; } if (c == '\0') { len0 = i; break; } i++; } if (wide) { wchar_t *ptr0; ptr0 = (wchar_t *)Yap_AllocCodeSpace(sizeof(wchar_t) * (len0 + 1)); if (!ptr0) return NIL; memcpy(ptr0, atom, len0 * sizeof(wchar_t)); ptr0[len0] = '\0'; at = LookupWideAtom(ptr0); Yap_FreeCodeSpace((char *)ptr0); return at; } else { unsigned char *ptr0; ptr0 = Yap_AllocCodeSpace((len0 + 1)); if (!ptr0) return NIL; for (i = 0; i < len0; i++) ptr0[i] = atom[i]; ptr0[len0] = '\0'; at = LookupAtom(ptr0); Yap_FreeCodeSpace(ptr0); return at; } }
Atom Yap_LookupMaybeWideAtomWithLength(wchar_t *atom, size_t len) { /* lookup atom in atom table */ wchar_t *p = atom, c; size_t len0 = 0; Atom at; int wide = FALSE; while ((c = *p++)) { if (c > 255) wide = TRUE; len0++; if (len0 == len) break; } if (p[0] == '\0' && wide) return LookupWideAtom(atom); else if (wide) { wchar_t *ptr, *ptr0; p = atom; ptr0 = ptr = (wchar_t *)Yap_AllocCodeSpace(sizeof(wchar_t)*(len+1)); if (!ptr) return NIL; while (len--) {*ptr++ = *p++;} ptr[0] = '\0'; at = LookupWideAtom(ptr0); Yap_FreeCodeSpace((char *)ptr0); return at; } else { char *ptr, *ptr0; /* not really a wide atom */ p = atom; ptr0 = ptr = Yap_AllocCodeSpace(len+1); if (!ptr) return NIL; while (len--) {*ptr++ = *p++;} ptr[0] = '\0'; at = LookupAtom(ptr0); Yap_FreeCodeSpace(ptr0); return at; } }
Atom Yap_LookupMaybeWideAtom(wchar_t *atom) { /* lookup atom in atom table */ wchar_t *p = atom, c; size_t len = 0; char *ptr, *ptr0; Atom at; while ((c = *p++)) { if (c > 255) return LookupWideAtom(atom); len++; } /* not really a wide atom */ p = atom; ptr0 = ptr = Yap_AllocCodeSpace(len+1); if (!ptr) return NIL; while ((*ptr++ = *p++)); at = LookupAtom(ptr0); Yap_FreeCodeSpace(ptr0); return at; }
Atom Yap_ULookupAtom( const unsigned char *atom) { /* lookup atom in atom table */ return LookupAtom(atom); }
static inline Term AtomTermAdjust(Term t) { LookupAtom(AtomOfTerm(t)); return t; }
static inline Atom AtomAdjust(Atom a) { LookupAtom(a); return a; }
static inline Term AtomTermAdjust(Term t) { return MkAtomTerm(LookupAtom(AtomOfTerm(t))); }
static inline Atom AtomAdjust(Atom a) { return LookupAtom(a); }
Atom Yap_LookupAtom(char *atom) { /* lookup atom in atom table */ return LookupAtom(atom); }