2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: adtdefs.c *
|
|
|
|
* Last rev: *
|
|
|
|
* mods: *
|
|
|
|
* comments: abstract machine definitions *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
#ifdef SCCS
|
|
|
|
static char SccsId[] = "%W% %G%";
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ADTDEFS_C
|
|
|
|
|
2002-02-22 06:12:18 +00:00
|
|
|
#ifdef __SUNPRO_CC
|
|
|
|
#define inline
|
|
|
|
#endif
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#include "Yap.h"
|
2004-01-23 02:23:51 +00:00
|
|
|
ADDR STD_PROTO(Yap_PreAllocCodeSpace, (void));
|
2004-02-12 12:37:12 +00:00
|
|
|
Prop STD_PROTO(PredPropByFunc,(Functor, Term));
|
|
|
|
Prop STD_PROTO(PredPropByAtom,(Atom, Term));
|
2001-04-09 20:54:03 +01:00
|
|
|
#include "Yatom.h"
|
|
|
|
#include "Heap.h"
|
|
|
|
#include "yapio.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#if HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* this routine must be run at least having a read lock on ae */
|
|
|
|
static Prop
|
|
|
|
GetFunctorProp(AtomEntry *ae, unsigned int arity)
|
|
|
|
{ /* look property list of atom a for kind */
|
|
|
|
FunctorEntry *pp;
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
pp = RepFunctorProp(ae->PropsOfAE);
|
2001-04-09 20:54:03 +01:00
|
|
|
while (!EndOfPAEntr(pp) &&
|
|
|
|
(!IsFunctorProperty(pp->KindOfPE) ||
|
|
|
|
pp->ArityOfFE != arity))
|
|
|
|
pp = RepFunctorProp(pp->NextOfPE);
|
|
|
|
return (AbsFunctorProp(pp));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vsc: We must guarantee that IsVarTerm(functor) returns true! */
|
|
|
|
static inline Functor
|
|
|
|
InlinedUnlockedMkFunctor(AtomEntry *ae, unsigned int arity)
|
|
|
|
{
|
|
|
|
FunctorEntry *p;
|
|
|
|
Prop p0;
|
|
|
|
|
|
|
|
p0 = GetFunctorProp(ae, arity);
|
|
|
|
if (p0 != NIL) {
|
|
|
|
return ((Functor) RepProp(p0));
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
p = (FunctorEntry *) Yap_AllocAtomSpace(sizeof(*p));
|
2001-04-09 20:54:03 +01:00
|
|
|
p->KindOfPE = FunctorProperty;
|
|
|
|
p->NameOfFE = AbsAtom(ae);
|
|
|
|
p->ArityOfFE = arity;
|
2001-10-03 14:39:16 +01:00
|
|
|
p->PropsOfFE = NIL;
|
2001-10-30 16:42:05 +00:00
|
|
|
p->NextOfPE = ae->PropsOfAE;
|
2001-10-03 14:39:16 +01:00
|
|
|
INIT_RWLOCK(p->FRWLock);
|
2001-10-30 16:42:05 +00:00
|
|
|
ae->PropsOfAE = AbsProp((PropEntry *) p);
|
2001-04-09 20:54:03 +01:00
|
|
|
return ((Functor) p);
|
|
|
|
}
|
|
|
|
|
|
|
|
Functor
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_UnlockedMkFunctor(AtomEntry *ae, unsigned int arity)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
return(InlinedUnlockedMkFunctor(ae, arity));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vsc: We must guarantee that IsVarTerm(functor) returns true! */
|
|
|
|
Functor
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_MkFunctor(Atom ap, unsigned int arity)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
AtomEntry *ae = RepAtom(ap);
|
|
|
|
Functor f;
|
|
|
|
|
|
|
|
WRITE_LOCK(ae->ARWLock);
|
|
|
|
f = InlinedUnlockedMkFunctor(ae, arity);
|
|
|
|
WRITE_UNLOCK(ae->ARWLock);
|
|
|
|
return (f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vsc: We must guarantee that IsVarTerm(functor) returns true! */
|
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_MkFunctorWithAddress(Atom ap, unsigned int arity, FunctorEntry *p)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
AtomEntry *ae = RepAtom(ap);
|
|
|
|
|
|
|
|
WRITE_LOCK(ae->ARWLock);
|
|
|
|
p->KindOfPE = FunctorProperty;
|
|
|
|
p->NameOfFE = ap;
|
|
|
|
p->ArityOfFE = arity;
|
2001-10-30 16:42:05 +00:00
|
|
|
p->NextOfPE = RepAtom(ap)->PropsOfAE;
|
|
|
|
ae->PropsOfAE = AbsProp((PropEntry *) p);
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_UNLOCK(ae->ARWLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static Atom
|
|
|
|
SearchInInvisible(char *atom)
|
|
|
|
{
|
|
|
|
AtomEntry *chain;
|
|
|
|
|
|
|
|
READ_LOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
chain = RepAtom(INVISIBLECHAIN.Entry);
|
|
|
|
while (!EndOfPAEntr(chain) && strcmp(chain->StrOfAE, atom) != 0) {
|
|
|
|
chain = RepAtom(chain->NextOfAE);
|
|
|
|
}
|
|
|
|
READ_UNLOCK(INVISIBLECHAIN.AERWLock);
|
|
|
|
if (EndOfPAEntr(chain))
|
|
|
|
return (NIL);
|
|
|
|
else
|
|
|
|
return(AbsAtom(chain));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline Atom
|
|
|
|
SearchAtom(unsigned char *p, Atom a) {
|
|
|
|
AtomEntry *ae;
|
|
|
|
|
|
|
|
/* search atom in chain */
|
|
|
|
while (a != NIL) {
|
|
|
|
ae = RepAtom(a);
|
|
|
|
if (strcmp(ae->StrOfAE, (const char *)p) == 0) {
|
|
|
|
return(a);
|
|
|
|
}
|
|
|
|
a = ae->NextOfAE;
|
|
|
|
}
|
|
|
|
return(NIL);
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static Atom
|
2001-04-09 20:54:03 +01:00
|
|
|
LookupAtom(char *atom)
|
|
|
|
{ /* lookup atom in atom table */
|
|
|
|
register CELL hash;
|
|
|
|
register unsigned char *p;
|
2003-12-01 17:27:42 +00:00
|
|
|
Atom a, na;
|
2001-04-09 20:54:03 +01:00
|
|
|
AtomEntry *ae;
|
|
|
|
|
|
|
|
/* compute hash */
|
|
|
|
p = (unsigned char *)atom;
|
2003-10-28 01:16:03 +00:00
|
|
|
hash = HashFunction(p) % AtomHashTableSize;
|
2003-12-01 17:27:42 +00:00
|
|
|
/* we'll start by holding a read lock in order to avoid contention */
|
|
|
|
READ_LOCK(HashChain[hash].AERWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
a = HashChain[hash].Entry;
|
|
|
|
/* search atom in chain */
|
2003-12-01 17:27:42 +00:00
|
|
|
na = SearchAtom((unsigned char *)atom, a);
|
|
|
|
if (na != NIL) {
|
|
|
|
READ_UNLOCK(HashChain[hash].AERWLock);
|
|
|
|
return(na);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2003-12-01 17:27:42 +00:00
|
|
|
READ_UNLOCK(HashChain[hash].AERWLock);
|
|
|
|
/* we need a write lock */
|
|
|
|
WRITE_LOCK(HashChain[hash].AERWLock);
|
|
|
|
/* concurrent version of Yap, need to take care */
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
if (a != HashChain[hash].Entry) {
|
|
|
|
a = HashChain[hash].Entry;
|
|
|
|
na = SearchAtom((unsigned char *)atom, a);
|
|
|
|
if (na != NIL) {
|
|
|
|
WRITE_UNLOCK(HashChain[hash].AERWLock);
|
|
|
|
return(na);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2003-10-28 01:16:03 +00:00
|
|
|
NOfAtoms++;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* add new atom to start of chain */
|
2003-10-14 02:32:55 +01:00
|
|
|
ae = (AtomEntry *) Yap_AllocAtomSpace((sizeof *ae) + strlen(atom) + 1);
|
2003-12-01 17:27:42 +00:00
|
|
|
na = AbsAtom(ae);
|
2001-10-30 16:42:05 +00:00
|
|
|
ae->PropsOfAE = NIL;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (ae->StrOfAE != atom)
|
|
|
|
strcpy(ae->StrOfAE, atom);
|
2003-12-01 17:27:42 +00:00
|
|
|
ae->NextOfAE = a;
|
|
|
|
HashChain[hash].Entry = na;
|
2001-04-09 20:54:03 +01:00
|
|
|
INIT_RWLOCK(ae->ARWLock);
|
|
|
|
WRITE_UNLOCK(HashChain[hash].AERWLock);
|
2003-10-28 01:16:03 +00:00
|
|
|
if (NOfAtoms > 2*AtomHashTableSize) {
|
2004-01-23 02:23:51 +00:00
|
|
|
Yap_signal(YAP_CDOVF_SIGNAL);
|
2003-10-28 01:16:03 +00:00
|
|
|
}
|
2003-12-01 17:27:42 +00:00
|
|
|
return na;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Atom
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_LookupAtom(char *atom)
|
2002-11-11 17:38:10 +00:00
|
|
|
{ /* lookup atom in atom table */
|
|
|
|
return(LookupAtom(atom));
|
|
|
|
}
|
|
|
|
|
|
|
|
Atom
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_FullLookupAtom(char *atom)
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* lookup atom in atom table */
|
|
|
|
Atom t;
|
|
|
|
|
|
|
|
if ((t = SearchInInvisible(atom)) != NIL) {
|
|
|
|
return (t);
|
|
|
|
}
|
|
|
|
return(LookupAtom(atom));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_LookupAtomWithAddress(char *atom, AtomEntry *ae)
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* lookup atom in atom table */
|
|
|
|
register CELL hash;
|
|
|
|
register unsigned char *p;
|
|
|
|
Atom a;
|
|
|
|
|
|
|
|
/* compute hash */
|
|
|
|
p = (unsigned char *)atom;
|
2003-10-28 01:16:03 +00:00
|
|
|
hash = HashFunction(p) % AtomHashTableSize;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* ask for a WRITE lock because it is highly unlikely we shall find anything */
|
|
|
|
WRITE_LOCK(HashChain[hash].AERWLock);
|
|
|
|
a = HashChain[hash].Entry;
|
|
|
|
/* search atom in chain */
|
|
|
|
if (SearchAtom(p, a) != NIL) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(FATAL_ERROR,TermNil,"repeated initialisation for atom %s", ae);
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_UNLOCK(HashChain[hash].AERWLock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* add new atom to start of chain */
|
|
|
|
ae->NextOfAE = a;
|
|
|
|
HashChain[hash].Entry = AbsAtom(ae);
|
2001-10-30 16:42:05 +00:00
|
|
|
ae->PropsOfAE = NIL;
|
2001-04-09 20:54:03 +01:00
|
|
|
strcpy(ae->StrOfAE, atom);
|
|
|
|
INIT_RWLOCK(ae->ARWLock);
|
|
|
|
WRITE_UNLOCK(HashChain[hash].AERWLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_ReleaseAtom(Atom atom)
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* Releases an atom from the hash chain */
|
|
|
|
register Int hash;
|
|
|
|
register unsigned char *p;
|
|
|
|
AtomEntry *inChain;
|
|
|
|
AtomEntry *ap = RepAtom(atom);
|
|
|
|
char *name = ap->StrOfAE;
|
|
|
|
|
|
|
|
/* compute hash */
|
|
|
|
p = (unsigned char *)name;
|
2003-10-28 01:16:03 +00:00
|
|
|
hash = HashFunction(p) % AtomHashTableSize;
|
2001-04-09 20:54:03 +01:00
|
|
|
WRITE_LOCK(HashChain[hash].AERWLock);
|
|
|
|
if (HashChain[hash].Entry == atom) {
|
2003-10-28 01:16:03 +00:00
|
|
|
NOfAtoms--;
|
2001-04-09 20:54:03 +01:00
|
|
|
HashChain[hash].Entry = ap->NextOfAE;
|
|
|
|
WRITE_UNLOCK(HashChain[hash].AERWLock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* else */
|
|
|
|
inChain = RepAtom(HashChain[hash].Entry);
|
|
|
|
while (inChain->NextOfAE != atom)
|
|
|
|
inChain = RepAtom(inChain->NextOfAE);
|
|
|
|
WRITE_LOCK(inChain->ARWLock);
|
|
|
|
inChain->NextOfAE = ap->NextOfAE;
|
|
|
|
WRITE_UNLOCK(inChain->ARWLock);
|
|
|
|
WRITE_UNLOCK(HashChain[hash].AERWLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Prop
|
2002-11-11 17:38:10 +00:00
|
|
|
GetAPropHavingLock(AtomEntry *ae, PropFlags kind)
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* look property list of atom a for kind */
|
|
|
|
PropEntry *pp;
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
pp = RepProp(ae->PropsOfAE);
|
2001-04-09 20:54:03 +01:00
|
|
|
while (!EndOfPAEntr(pp) && pp->KindOfPE != kind)
|
|
|
|
pp = RepProp(pp->NextOfPE);
|
|
|
|
return (AbsProp(pp));
|
|
|
|
}
|
|
|
|
|
|
|
|
Prop
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_GetAPropHavingLock(AtomEntry *ae, PropFlags kind)
|
2001-04-09 20:54:03 +01:00
|
|
|
{ /* look property list of atom a for kind */
|
2002-11-11 17:38:10 +00:00
|
|
|
return (GetAPropHavingLock(ae,kind));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static Prop
|
2001-04-09 20:54:03 +01:00
|
|
|
GetAProp(Atom a, PropFlags kind)
|
|
|
|
{ /* look property list of atom a for kind */
|
|
|
|
AtomEntry *ae = RepAtom(a);
|
|
|
|
Prop out;
|
|
|
|
|
|
|
|
READ_LOCK(ae->ARWLock);
|
2002-11-11 17:38:10 +00:00
|
|
|
out = GetAPropHavingLock(ae, kind);
|
2001-04-09 20:54:03 +01:00
|
|
|
READ_UNLOCK(ae->ARWLock);
|
|
|
|
return (out);
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
Prop
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_GetAProp(Atom a, PropFlags kind)
|
2002-11-11 17:38:10 +00:00
|
|
|
{ /* look property list of atom a for kind */
|
|
|
|
return GetAProp(a,kind);
|
|
|
|
}
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
inline static Prop
|
2004-02-12 12:37:12 +00:00
|
|
|
GetPredPropByAtomHavingLock(AtomEntry* ae, Term cur_mod)
|
2001-10-30 16:42:05 +00:00
|
|
|
/* get predicate entry for ap/arity; create it if neccessary. */
|
|
|
|
{
|
|
|
|
Prop p0;
|
|
|
|
|
|
|
|
p0 = ae->PropsOfAE;
|
|
|
|
while (p0) {
|
|
|
|
PredEntry *pe = RepPredProp(p0);
|
|
|
|
if ( pe->KindOfPE == PEProp &&
|
|
|
|
(pe->ModuleOfPred == cur_mod || !pe->ModuleOfPred)) {
|
|
|
|
return(p0);
|
2004-02-11 16:09:15 +00:00
|
|
|
#if THREADS
|
|
|
|
/* Thread Local Predicates */
|
|
|
|
if (pe->PredFlags & ThreadLocalPredFlag) {
|
|
|
|
return AbsPredProp(Yap_GetThreadPred(pe));
|
|
|
|
}
|
|
|
|
#endif
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
|
|
|
p0 = pe->NextOfPE;
|
|
|
|
}
|
|
|
|
return(NIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
Prop
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_GetPredPropByAtom(Atom at, Term cur_mod)
|
2001-10-30 16:42:05 +00:00
|
|
|
/* get predicate entry for ap/arity; create it if neccessary. */
|
|
|
|
{
|
|
|
|
Prop p0;
|
|
|
|
AtomEntry *ae = RepAtom(at);
|
|
|
|
|
|
|
|
READ_LOCK(ae->ARWLock);
|
|
|
|
p0 = GetPredPropByAtomHavingLock(ae, cur_mod);
|
|
|
|
READ_UNLOCK(ae->ARWLock);
|
|
|
|
return(p0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-25 19:42:35 +01:00
|
|
|
inline static Prop
|
2004-02-12 12:37:12 +00:00
|
|
|
GetPredPropByAtomHavingLockInThisModule(AtomEntry* ae, Term cur_mod)
|
2003-08-25 19:42:35 +01:00
|
|
|
/* get predicate entry for ap/arity; create it if neccessary. */
|
|
|
|
{
|
|
|
|
Prop p0;
|
|
|
|
|
|
|
|
p0 = ae->PropsOfAE;
|
|
|
|
while (p0) {
|
|
|
|
PredEntry *pe = RepPredProp(p0);
|
|
|
|
if ( pe->KindOfPE == PEProp && pe->ModuleOfPred == cur_mod ) {
|
2004-02-11 16:09:15 +00:00
|
|
|
#if THREADS
|
|
|
|
/* Thread Local Predicates */
|
|
|
|
if (pe->PredFlags & ThreadLocalPredFlag) {
|
|
|
|
return AbsPredProp(Yap_GetThreadPred(pe));
|
|
|
|
}
|
|
|
|
#endif
|
2003-08-25 19:42:35 +01:00
|
|
|
return(p0);
|
|
|
|
}
|
|
|
|
p0 = pe->NextOfPE;
|
|
|
|
}
|
|
|
|
return(NIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
Prop
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_GetPredPropByAtomInThisModule(Atom at, Term cur_mod)
|
2003-08-25 19:42:35 +01:00
|
|
|
/* get predicate entry for ap/arity; create it if neccessary. */
|
|
|
|
{
|
|
|
|
Prop p0;
|
|
|
|
AtomEntry *ae = RepAtom(at);
|
|
|
|
|
|
|
|
READ_LOCK(ae->ARWLock);
|
|
|
|
p0 = GetPredPropByAtomHavingLockInThisModule(ae, cur_mod);
|
|
|
|
READ_UNLOCK(ae->ARWLock);
|
|
|
|
return(p0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
static inline Prop
|
2004-02-12 12:37:12 +00:00
|
|
|
GetPredPropByFuncHavingLock(Functor f, Term cur_mod)
|
2001-11-15 00:01:43 +00:00
|
|
|
/* get predicate entry for ap/arity; create it if neccessary. */
|
2001-10-03 14:39:16 +01:00
|
|
|
{
|
|
|
|
Prop p0;
|
2001-11-15 00:01:43 +00:00
|
|
|
FunctorEntry *fe = (FunctorEntry *)f;
|
2001-10-03 14:39:16 +01:00
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
p0 = fe->PropsOfFE;
|
|
|
|
while (p0) {
|
|
|
|
PredEntry *p = RepPredProp(p0);
|
|
|
|
if (/* p->KindOfPE != 0 || only props */
|
|
|
|
(p->ModuleOfPred == cur_mod || !(p->ModuleOfPred))) {
|
2004-02-11 16:09:15 +00:00
|
|
|
#if THREADS
|
|
|
|
/* Thread Local Predicates */
|
|
|
|
if (p->PredFlags & ThreadLocalPredFlag) {
|
|
|
|
return AbsPredProp(Yap_GetThreadPred(p));
|
|
|
|
}
|
|
|
|
#endif
|
2001-11-15 00:01:43 +00:00
|
|
|
return (p0);
|
|
|
|
}
|
|
|
|
p0 = p->NextOfPE;
|
|
|
|
}
|
|
|
|
return(NIL);
|
2001-10-03 14:39:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Prop
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_GetPredPropByFunc(Functor f, Term cur_mod)
|
2001-10-03 14:39:16 +01:00
|
|
|
/* get predicate entry for ap/arity; */
|
|
|
|
{
|
|
|
|
Prop p0;
|
|
|
|
|
2001-10-30 22:13:18 +00:00
|
|
|
READ_LOCK(f->FRWLock);
|
2001-11-15 00:01:43 +00:00
|
|
|
p0 = GetPredPropByFuncHavingLock(f, cur_mod);
|
2001-10-03 14:39:16 +01:00
|
|
|
READ_UNLOCK(f->FRWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (p0);
|
|
|
|
}
|
|
|
|
|
2003-08-25 19:42:35 +01:00
|
|
|
static inline Prop
|
2004-02-12 12:37:12 +00:00
|
|
|
GetPredPropByFuncHavingLockInThisModule(Functor f, Term cur_mod)
|
2003-08-25 19:42:35 +01:00
|
|
|
/* get predicate entry for ap/arity; create it if neccessary. */
|
|
|
|
{
|
|
|
|
Prop p0;
|
|
|
|
FunctorEntry *fe = (FunctorEntry *)f;
|
|
|
|
|
|
|
|
p0 = fe->PropsOfFE;
|
|
|
|
while (p0) {
|
|
|
|
PredEntry *p = RepPredProp(p0);
|
|
|
|
if (p->ModuleOfPred == cur_mod) {
|
2004-02-11 16:09:15 +00:00
|
|
|
#if THREADS
|
|
|
|
/* Thread Local Predicates */
|
|
|
|
if (p->PredFlags & ThreadLocalPredFlag) {
|
|
|
|
return AbsPredProp(Yap_GetThreadPred(p));
|
|
|
|
}
|
|
|
|
#endif
|
2003-08-25 19:42:35 +01:00
|
|
|
return (p0);
|
|
|
|
}
|
|
|
|
p0 = p->NextOfPE;
|
|
|
|
}
|
|
|
|
return(NIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
Prop
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_GetPredPropByFuncInThisModule(Functor f, Term cur_mod)
|
2003-08-25 19:42:35 +01:00
|
|
|
/* get predicate entry for ap/arity; */
|
|
|
|
{
|
|
|
|
Prop p0;
|
|
|
|
|
|
|
|
READ_LOCK(f->FRWLock);
|
|
|
|
p0 = GetPredPropByFuncHavingLockInThisModule(f, cur_mod);
|
|
|
|
READ_UNLOCK(f->FRWLock);
|
|
|
|
return (p0);
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
Prop
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_GetPredPropHavingLock(Atom ap, unsigned int arity, Term mod)
|
2001-04-09 20:54:03 +01:00
|
|
|
/* get predicate entry for ap/arity; */
|
|
|
|
{
|
|
|
|
Prop p0;
|
|
|
|
AtomEntry *ae = RepAtom(ap);
|
2001-10-03 14:39:16 +01:00
|
|
|
Functor f;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
if (arity == 0) {
|
2001-11-15 00:01:43 +00:00
|
|
|
GetPredPropByAtomHavingLock(ae, mod);
|
2001-10-30 16:42:05 +00:00
|
|
|
}
|
2001-10-03 14:39:16 +01:00
|
|
|
f = InlinedUnlockedMkFunctor(ae, arity);
|
2001-10-30 22:13:18 +00:00
|
|
|
READ_LOCK(f->FRWLock);
|
2001-11-15 00:01:43 +00:00
|
|
|
p0 = GetPredPropByFuncHavingLock(f, mod);
|
2001-10-03 14:39:16 +01:00
|
|
|
READ_UNLOCK(f->FRWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (p0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get expression entry for at/arity; */
|
|
|
|
Prop
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_GetExpProp(Atom at, unsigned int arity)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Prop p0;
|
|
|
|
AtomEntry *ae = RepAtom(at);
|
|
|
|
ExpEntry *p;
|
|
|
|
|
|
|
|
READ_LOCK(ae->ARWLock);
|
2001-10-30 16:42:05 +00:00
|
|
|
p = RepExpProp(p0 = ae->PropsOfAE);
|
2001-04-09 20:54:03 +01:00
|
|
|
while (p0 && (p->KindOfPE != ExpProperty || p->ArityOfEE != arity))
|
|
|
|
p = RepExpProp(p0 = p->NextOfPE);
|
|
|
|
READ_UNLOCK(ae->ARWLock);
|
|
|
|
return (p0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get expression entry for at/arity, at is already locked; */
|
|
|
|
Prop
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_GetExpPropHavingLock(AtomEntry *ae, unsigned int arity)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Prop p0;
|
|
|
|
ExpEntry *p;
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
p = RepExpProp(p0 = ae->PropsOfAE);
|
2001-04-09 20:54:03 +01:00
|
|
|
while (p0 && (p->KindOfPE != ExpProperty || p->ArityOfEE != arity))
|
|
|
|
p = RepExpProp(p0 = p->NextOfPE);
|
|
|
|
return (p0);
|
|
|
|
}
|
|
|
|
|
2003-12-01 17:27:42 +00:00
|
|
|
/* fe is supposed to be locked */
|
2001-04-09 20:54:03 +01:00
|
|
|
Prop
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_NewPredPropByFunctor(FunctorEntry *fe, Term cur_mod)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Prop p0;
|
2002-11-18 18:18:05 +00:00
|
|
|
PredEntry *p = (PredEntry *) Yap_AllocAtomSpace(sizeof(*p));
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
INIT_RWLOCK(p->PRWLock);
|
2004-02-05 16:57:02 +00:00
|
|
|
INIT_LOCK(p->PELock);
|
2001-04-09 20:54:03 +01:00
|
|
|
p->KindOfPE = PEProp;
|
2001-10-03 14:39:16 +01:00
|
|
|
p->ArityOfPE = fe->ArityOfFE;
|
2002-12-27 16:53:09 +00:00
|
|
|
p->cs.p_code.FirstClause = p->cs.p_code.LastClause = NULL;
|
2003-04-30 18:46:05 +01:00
|
|
|
p->cs.p_code.NOfClauses = 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
p->PredFlags = 0L;
|
2003-08-25 19:42:35 +01:00
|
|
|
p->src.OwnerFile = AtomNil;
|
2001-04-09 20:54:03 +01:00
|
|
|
p->OpcodeOfPred = UNDEF_OPCODE;
|
2002-12-27 16:53:09 +00:00
|
|
|
p->CodeOfPred = p->cs.p_code.TrueCodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2003-08-25 19:42:35 +01:00
|
|
|
p->cs.p_code.ExpandCode = EXPAND_OP_CODE;
|
2004-02-12 12:37:12 +00:00
|
|
|
if (cur_mod == TermProlog)
|
2004-06-05 04:37:01 +01:00
|
|
|
p->ModuleOfPred = 0L;
|
2004-02-12 12:37:12 +00:00
|
|
|
else
|
|
|
|
p->ModuleOfPred = cur_mod;
|
|
|
|
Yap_NewModulePred(cur_mod, p);
|
2001-04-09 20:54:03 +01:00
|
|
|
INIT_LOCK(p->StatisticsForPred.lock);
|
|
|
|
p->StatisticsForPred.NOfEntries = 0;
|
|
|
|
p->StatisticsForPred.NOfHeadSuccesses = 0;
|
|
|
|
p->StatisticsForPred.NOfRetries = 0;
|
|
|
|
#ifdef TABLING
|
|
|
|
p->TableOfPred = NULL;
|
|
|
|
#endif /* TABLING */
|
|
|
|
/* careful that they don't cross MkFunctor */
|
2001-10-03 14:39:16 +01:00
|
|
|
p->NextOfPE = fe->PropsOfFE;
|
|
|
|
fe->PropsOfFE = p0 = AbsPredProp(p);
|
2001-10-30 16:42:05 +00:00
|
|
|
p->FunctorOfPred = (Functor)fe;
|
2001-10-03 14:39:16 +01:00
|
|
|
WRITE_UNLOCK(fe->FRWLock);
|
2001-04-09 20:54:03 +01:00
|
|
|
return (p0);
|
|
|
|
}
|
|
|
|
|
2004-02-05 16:57:02 +00:00
|
|
|
#if THREADS
|
|
|
|
Prop
|
|
|
|
Yap_NewThreadPred(PredEntry *ap)
|
|
|
|
{
|
|
|
|
PredEntry *p = (PredEntry *) Yap_AllocAtomSpace(sizeof(*p));
|
|
|
|
|
|
|
|
INIT_RWLOCK(p->PRWLock);
|
|
|
|
INIT_LOCK(p->PELock);
|
|
|
|
p->KindOfPE = PEProp;
|
|
|
|
p->ArityOfPE = ap->ArityOfPE;
|
|
|
|
p->cs.p_code.FirstClause = p->cs.p_code.LastClause = NULL;
|
|
|
|
p->cs.p_code.NOfClauses = 0;
|
2004-02-11 13:33:19 +00:00
|
|
|
p->PredFlags = ap->PredFlags & ~(IndexedPredFlag|SpiedPredFlag);
|
2004-02-05 16:57:02 +00:00
|
|
|
p->src.OwnerFile = ap->src.OwnerFile;
|
|
|
|
p->OpcodeOfPred = UNDEF_OPCODE;
|
|
|
|
p->CodeOfPred = p->cs.p_code.TrueCodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
|
|
|
p->cs.p_code.ExpandCode = EXPAND_OP_CODE;
|
|
|
|
p->ModuleOfPred = ap->ModuleOfPred;
|
|
|
|
p->NextPredOfModule = NULL;
|
|
|
|
INIT_LOCK(p->StatisticsForPred.lock);
|
|
|
|
p->StatisticsForPred.NOfEntries = 0;
|
|
|
|
p->StatisticsForPred.NOfHeadSuccesses = 0;
|
|
|
|
p->StatisticsForPred.NOfRetries = 0;
|
|
|
|
#ifdef TABLING
|
|
|
|
p->TableOfPred = NULL;
|
|
|
|
#endif /* TABLING */
|
|
|
|
/* careful that they don't cross MkFunctor */
|
|
|
|
p->NextOfPE = AbsPredProp(ThreadHandle[worker_id].local_preds);
|
|
|
|
ThreadHandle[worker_id].local_preds = p;
|
|
|
|
p->FunctorOfPred = ap->FunctorOfPred;
|
|
|
|
return AbsPredProp(p);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
Prop
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_NewPredPropByAtom(AtomEntry *ae, Term cur_mod)
|
2001-10-30 16:42:05 +00:00
|
|
|
{
|
|
|
|
Prop p0;
|
2002-11-18 18:18:05 +00:00
|
|
|
PredEntry *p = (PredEntry *) Yap_AllocAtomSpace(sizeof(*p));
|
2001-11-15 00:01:43 +00:00
|
|
|
|
2004-02-12 12:37:12 +00:00
|
|
|
/* Printf("entering %s:%s/0\n", RepAtom(AtomOfTerm(cur_mod))->StrOfAE, ae->StrOfAE); */
|
2001-10-30 16:42:05 +00:00
|
|
|
|
|
|
|
INIT_RWLOCK(p->PRWLock);
|
2004-02-05 16:57:02 +00:00
|
|
|
INIT_LOCK(p->PELock);
|
2001-10-30 16:42:05 +00:00
|
|
|
p->KindOfPE = PEProp;
|
|
|
|
p->ArityOfPE = 0;
|
2002-12-27 16:53:09 +00:00
|
|
|
p->cs.p_code.FirstClause = p->cs.p_code.LastClause = NULL;
|
2003-04-30 18:46:05 +01:00
|
|
|
p->cs.p_code.NOfClauses = 0;
|
2001-10-30 16:42:05 +00:00
|
|
|
p->PredFlags = 0L;
|
2003-08-25 19:42:35 +01:00
|
|
|
p->src.OwnerFile = AtomNil;
|
2001-10-30 16:42:05 +00:00
|
|
|
p->OpcodeOfPred = UNDEF_OPCODE;
|
2003-08-25 19:42:35 +01:00
|
|
|
p->cs.p_code.ExpandCode = EXPAND_OP_CODE;
|
2002-12-27 16:53:09 +00:00
|
|
|
p->CodeOfPred = p->cs.p_code.TrueCodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
2004-02-12 12:37:12 +00:00
|
|
|
if (cur_mod == TermProlog)
|
|
|
|
p->ModuleOfPred = 0;
|
|
|
|
else
|
|
|
|
p->ModuleOfPred = cur_mod;
|
|
|
|
Yap_NewModulePred(cur_mod, p);
|
2001-10-30 16:42:05 +00:00
|
|
|
INIT_LOCK(p->StatisticsForPred.lock);
|
|
|
|
p->StatisticsForPred.NOfEntries = 0;
|
|
|
|
p->StatisticsForPred.NOfHeadSuccesses = 0;
|
|
|
|
p->StatisticsForPred.NOfRetries = 0;
|
|
|
|
#ifdef TABLING
|
|
|
|
p->TableOfPred = NULL;
|
|
|
|
#endif /* TABLING */
|
|
|
|
/* careful that they don't cross MkFunctor */
|
|
|
|
p->NextOfPE = ae->PropsOfAE;
|
|
|
|
ae->PropsOfAE = p0 = AbsPredProp(p);
|
|
|
|
p->FunctorOfPred = (Functor)AbsAtom(ae);
|
|
|
|
WRITE_UNLOCK(ae->ARWLock);
|
|
|
|
return (p0);
|
|
|
|
}
|
|
|
|
|
2004-02-11 01:20:56 +00:00
|
|
|
Prop
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_PredPropByFunctorNonThreadLocal(Functor f, Term cur_mod)
|
2004-02-11 01:20:56 +00:00
|
|
|
/* get predicate entry for ap/arity; create it if neccessary. */
|
|
|
|
{
|
|
|
|
Prop p0;
|
|
|
|
FunctorEntry *fe = (FunctorEntry *)f;
|
|
|
|
|
|
|
|
WRITE_LOCK(fe->FRWLock);
|
|
|
|
p0 = fe->PropsOfFE;
|
|
|
|
while (p0) {
|
|
|
|
PredEntry *p = RepPredProp(p0);
|
|
|
|
if (/* p->KindOfPE != 0 || only props */
|
|
|
|
(p->ModuleOfPred == cur_mod || !(p->ModuleOfPred))) {
|
|
|
|
WRITE_UNLOCK(fe->FRWLock);
|
|
|
|
return (p0);
|
|
|
|
}
|
|
|
|
p0 = p->NextOfPE;
|
|
|
|
}
|
|
|
|
return Yap_NewPredPropByFunctor(fe,cur_mod);
|
|
|
|
}
|
|
|
|
|
|
|
|
Prop
|
2004-02-12 12:37:12 +00:00
|
|
|
Yap_PredPropByAtomNonThreadLocal(Atom at, Term cur_mod)
|
2004-02-11 01:20:56 +00:00
|
|
|
/* get predicate entry for ap/arity; create it if neccessary. */
|
|
|
|
{
|
|
|
|
Prop p0;
|
|
|
|
AtomEntry *ae = RepAtom(at);
|
|
|
|
|
|
|
|
WRITE_LOCK(ae->ARWLock);
|
|
|
|
p0 = ae->PropsOfAE;
|
|
|
|
while (p0) {
|
|
|
|
PredEntry *pe = RepPredProp(p0);
|
|
|
|
if ( pe->KindOfPE == PEProp &&
|
|
|
|
(pe->ModuleOfPred == cur_mod || !pe->ModuleOfPred)) {
|
|
|
|
WRITE_UNLOCK(ae->ARWLock);
|
|
|
|
return(p0);
|
|
|
|
}
|
|
|
|
p0 = pe->NextOfPE;
|
|
|
|
}
|
|
|
|
return Yap_NewPredPropByAtom(ae,cur_mod);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
Term
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_GetValue(Atom a)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
Prop p0 = GetAProp(a, ValProperty);
|
|
|
|
Term out;
|
|
|
|
|
|
|
|
if (p0 == NIL)
|
|
|
|
return (TermNil);
|
|
|
|
READ_LOCK(RepValProp(p0)->VRWLock);
|
|
|
|
out = RepValProp(p0)->ValueOfVE;
|
2002-02-27 01:20:18 +00:00
|
|
|
if (IsApplTerm(out)) {
|
|
|
|
Functor f = FunctorOfTerm(out);
|
|
|
|
if (f == FunctorDouble) {
|
|
|
|
out = MkFloatTerm(FloatOfTerm(out));
|
|
|
|
} else if (f == FunctorLongInt) {
|
|
|
|
out = MkLongIntTerm(LongIntOfTerm(out));
|
|
|
|
}
|
|
|
|
#ifdef USE_GMP
|
|
|
|
else {
|
2002-11-18 18:18:05 +00:00
|
|
|
out = Yap_MkBigIntTerm(Yap_BigIntOfTerm(out));
|
2002-02-27 01:20:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
READ_UNLOCK(RepValProp(p0)->VRWLock);
|
|
|
|
return (out);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PutValue(Atom a, Term v)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
AtomEntry *ae = RepAtom(a);
|
|
|
|
Prop p0;
|
|
|
|
ValEntry *p;
|
2002-02-27 01:11:51 +00:00
|
|
|
Term t0;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
WRITE_LOCK(ae->ARWLock);
|
2001-10-30 16:42:05 +00:00
|
|
|
p0 = GetAPropHavingLock(ae, ValProperty);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (p0 != NIL) {
|
|
|
|
p = RepValProp(p0);
|
|
|
|
WRITE_LOCK(p->VRWLock);
|
|
|
|
WRITE_UNLOCK(ae->ARWLock);
|
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
p = (ValEntry *) Yap_AllocAtomSpace(sizeof(ValEntry));
|
2001-10-30 16:42:05 +00:00
|
|
|
p->NextOfPE = RepAtom(a)->PropsOfAE;
|
|
|
|
RepAtom(a)->PropsOfAE = AbsValProp(p);
|
2001-04-09 20:54:03 +01:00
|
|
|
p->KindOfPE = ValProperty;
|
2002-02-27 01:11:51 +00:00
|
|
|
p->ValueOfVE = TermNil;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* take care that the lock for the property will be inited even
|
|
|
|
if someone else searches for the property */
|
|
|
|
INIT_RWLOCK(p->VRWLock);
|
|
|
|
WRITE_LOCK(p->VRWLock);
|
|
|
|
WRITE_UNLOCK(ae->ARWLock);
|
|
|
|
}
|
2002-02-27 01:11:51 +00:00
|
|
|
t0 = p->ValueOfVE;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (IsFloatTerm(v)) {
|
|
|
|
/* store a float in code space, so that we can access the property */
|
|
|
|
union {
|
|
|
|
Float f;
|
|
|
|
CELL ar[sizeof(Float) / sizeof(CELL)];
|
|
|
|
} un;
|
|
|
|
CELL *pt, *iptr;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
un.f = FloatOfTerm(v);
|
2002-02-27 01:11:51 +00:00
|
|
|
if (IsFloatTerm(t0)) {
|
|
|
|
pt = RepAppl(t0);
|
|
|
|
} else {
|
|
|
|
if (IsApplTerm(t0)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_FreeCodeSpace((char *) (RepAppl(t0)));
|
2002-02-27 01:11:51 +00:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
pt = (CELL *) Yap_AllocAtomSpace(sizeof(CELL)*(1 + 2*sizeof(Float)/sizeof(CELL)));
|
2002-02-27 01:11:51 +00:00
|
|
|
p->ValueOfVE = AbsAppl(pt);
|
|
|
|
pt[0] = (CELL)FunctorDouble;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
iptr = pt+1;
|
|
|
|
for (i = 0; i < sizeof(Float) / sizeof(CELL); i++) {
|
2002-02-27 01:11:51 +00:00
|
|
|
*iptr++ = (CELL)un.ar[i];
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
} else if (IsLongIntTerm(v)) {
|
|
|
|
CELL *pt;
|
|
|
|
Int val = LongIntOfTerm(v);
|
2002-02-27 01:11:51 +00:00
|
|
|
|
|
|
|
if (IsLongIntTerm(t0)) {
|
|
|
|
pt = RepAppl(t0);
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-02-27 01:11:51 +00:00
|
|
|
if (IsApplTerm(t0)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_FreeCodeSpace((char *) (RepAppl(t0)));
|
2002-02-27 01:11:51 +00:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
pt = (CELL *) Yap_AllocAtomSpace(2*sizeof(CELL));
|
2002-02-27 01:11:51 +00:00
|
|
|
p->ValueOfVE = AbsAppl(pt);
|
|
|
|
pt[0] = (CELL)FunctorLongInt;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2002-02-27 01:11:51 +00:00
|
|
|
pt[1] = (CELL)val;
|
|
|
|
#ifdef USE_GMP
|
|
|
|
} else if (IsBigIntTerm(v)) {
|
|
|
|
CELL *ap = RepAppl(v);
|
|
|
|
Int sz =
|
|
|
|
sizeof(MP_INT)+sizeof(CELL)+
|
|
|
|
(((MP_INT *)(ap+1))->_mp_alloc*sizeof(mp_limb_t));
|
2002-11-18 18:18:05 +00:00
|
|
|
CELL *pt = (CELL *) Yap_AllocAtomSpace(sz);
|
2002-02-27 01:11:51 +00:00
|
|
|
if (IsApplTerm(t0)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_FreeCodeSpace((char *) RepAppl(t0));
|
2002-02-27 01:11:51 +00:00
|
|
|
}
|
|
|
|
memcpy((void *)pt, (void *)ap, sz);
|
2001-04-09 20:54:03 +01:00
|
|
|
p->ValueOfVE = AbsAppl(pt);
|
2002-02-27 01:11:51 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-02-27 01:11:51 +00:00
|
|
|
if (IsApplTerm(t0)) {
|
2001-04-09 20:54:03 +01:00
|
|
|
/* recover space */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_FreeCodeSpace((char *) (RepAppl(p->ValueOfVE)));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
p->ValueOfVE = v;
|
|
|
|
}
|
|
|
|
WRITE_UNLOCK(p->VRWLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
Term
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_StringToList(char *s)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
register Term t;
|
|
|
|
register unsigned char *cp = (unsigned char *)s + strlen(s);
|
|
|
|
|
|
|
|
t = MkAtomTerm(AtomNil);
|
|
|
|
while (cp > (unsigned char *)s) {
|
|
|
|
t = MkPairTerm(MkIntTerm(*--cp), t);
|
|
|
|
}
|
|
|
|
return (t);
|
|
|
|
}
|
|
|
|
|
|
|
|
Term
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_StringToListOfAtoms(char *s)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
register Term t;
|
|
|
|
char so[2];
|
|
|
|
register unsigned char *cp = (unsigned char *)s + strlen(s);
|
|
|
|
|
|
|
|
so[1] = '\0';
|
|
|
|
t = MkAtomTerm(AtomNil);
|
|
|
|
while (cp > (unsigned char *)s) {
|
|
|
|
so[0] = *--cp;
|
|
|
|
t = MkPairTerm(MkAtomTerm(LookupAtom(so)), t);
|
|
|
|
}
|
|
|
|
return (t);
|
|
|
|
}
|
|
|
|
|
|
|
|
Term
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_ArrayToList(register Term *tp, int nof)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
register Term *pt = tp + nof;
|
|
|
|
register Term t;
|
|
|
|
|
|
|
|
t = MkAtomTerm(AtomNil);
|
|
|
|
while (pt > tp) {
|
|
|
|
Term tm = *--pt;
|
|
|
|
#if SBA
|
|
|
|
if (tm == 0)
|
|
|
|
t = MkPairTerm((CELL)pt, t);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
t = MkPairTerm(tm, t);
|
|
|
|
}
|
|
|
|
return (t);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_GetName(char *s, UInt max, Term t)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
register Term Head;
|
|
|
|
register Int i;
|
|
|
|
|
|
|
|
if (IsVarTerm(t) || !IsPairTerm(t))
|
|
|
|
return (FALSE);
|
|
|
|
while (IsPairTerm(t)) {
|
|
|
|
Head = HeadOfTerm(t);
|
|
|
|
if (!IsNumTerm(Head))
|
|
|
|
return (FALSE);
|
|
|
|
i = IntOfTerm(Head);
|
|
|
|
if (i < 0 || i > 255)
|
|
|
|
return (FALSE);
|
|
|
|
*s++ = i;
|
|
|
|
t = TailOfTerm(t);
|
2002-01-02 20:56:22 +00:00
|
|
|
if (--max == 0) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(FATAL_ERROR,t,"not enough space for GetName");
|
2002-01-02 20:56:22 +00:00
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
*s = '\0';
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SFUNC
|
|
|
|
|
|
|
|
Term
|
|
|
|
MkSFTerm(Functor f, int n, Term *a, empty_value)
|
|
|
|
{
|
|
|
|
Term t, p = AbsAppl(H);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
*H++ = f;
|
|
|
|
RESET_VARIABLE(H);
|
|
|
|
++H;
|
|
|
|
for (i = 1; i <= n; ++i) {
|
|
|
|
t = Derefa(a++);
|
|
|
|
if (t != empty_value) {
|
|
|
|
*H++ = i;
|
|
|
|
*H++ = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*H++ = 0;
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
CELL *
|
|
|
|
ArgsOfSFTerm(Term t)
|
|
|
|
{
|
|
|
|
CELL *p = RepAppl(t) + 1;
|
|
|
|
|
|
|
|
while (*p != (CELL) p)
|
|
|
|
p = CellPtr(*p) + 1;
|
|
|
|
return (p + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2002-10-17 01:05:29 +01:00
|
|
|
|
|
|
|
long
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_NewSlots(int n)
|
2002-10-17 01:05:29 +01:00
|
|
|
{
|
|
|
|
Int old_slots = IntOfTerm(ASP[0]), oldn = n;
|
|
|
|
while (n > 0) {
|
|
|
|
RESET_VARIABLE(ASP);
|
|
|
|
ASP--;
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
ASP[0] = MkIntTerm(old_slots+oldn);
|
|
|
|
return((ASP+1)-LCL0);
|
|
|
|
}
|
|
|
|
|
|
|
|
long
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitSlot(Term t)
|
2002-10-17 01:05:29 +01:00
|
|
|
{
|
|
|
|
Int old_slots = IntOfTerm(ASP[0]);
|
|
|
|
*ASP = t;
|
|
|
|
ASP--;
|
|
|
|
ASP[0] = MkIntTerm(old_slots+1);
|
|
|
|
return((ASP+1)-LCL0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_RecoverSlots(int n)
|
2002-10-17 01:05:29 +01:00
|
|
|
{
|
|
|
|
Int old_slots = IntOfTerm(ASP[0]);
|
|
|
|
ASP += n;
|
|
|
|
ASP[0] = MkIntTerm(old_slots-n);
|
|
|
|
}
|
|
|
|
|
|
|
|
Term
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_GetFromSlot(long slot)
|
2002-10-17 01:05:29 +01:00
|
|
|
{
|
|
|
|
return(Deref(LCL0[slot]));
|
|
|
|
}
|
|
|
|
|
|
|
|
Term *
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_AddressFromSlot(long slot)
|
2002-10-17 01:05:29 +01:00
|
|
|
{
|
|
|
|
return(LCL0+slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PutInSlot(long slot, Term t)
|
2002-10-17 01:05:29 +01:00
|
|
|
{
|
|
|
|
LCL0[slot] = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
|