Exo change to support external usage
This commit is contained in:
parent
c2219d0343
commit
638ef10c84
54
C/exo.c
54
C/exo.c
@ -562,12 +562,9 @@ Yap_NextExo(choiceptr cptr, struct index_t *it)
|
||||
return next;
|
||||
}
|
||||
|
||||
static Int
|
||||
p_exodb_get_space( USES_REGS1 )
|
||||
{ /* '$number_of_clauses'(Predicate,M,N) */
|
||||
Term t = Deref(ARG1);
|
||||
Term mod = Deref(ARG2);
|
||||
Term tn = Deref(ARG3);
|
||||
MegaClause *
|
||||
exodb_get_space( Term t, Term mod, Term tn )
|
||||
{
|
||||
UInt arity;
|
||||
Prop pe;
|
||||
PredEntry *ap;
|
||||
@ -578,7 +575,7 @@ p_exodb_get_space( USES_REGS1 )
|
||||
|
||||
|
||||
if (IsVarTerm(mod) || !IsAtomTerm(mod)) {
|
||||
return(FALSE);
|
||||
return NULL;
|
||||
}
|
||||
if (IsAtomTerm(t)) {
|
||||
Atom a = AtomOfTerm(t);
|
||||
@ -589,10 +586,10 @@ p_exodb_get_space( USES_REGS1 )
|
||||
arity = ArityOfFunctor(f);
|
||||
pe = PredPropByFunc(f, mod);
|
||||
} else {
|
||||
return FALSE;
|
||||
return NULL;
|
||||
}
|
||||
if (EndOfPAEntr(pe))
|
||||
return FALSE;
|
||||
return NULL;
|
||||
ap = RepPredProp(pe);
|
||||
if (ap->PredFlags & (DynamicPredFlag|LogUpdatePredFlag
|
||||
#ifdef TABLING
|
||||
@ -600,21 +597,21 @@ p_exodb_get_space( USES_REGS1 )
|
||||
#endif /* TABLING */
|
||||
)) {
|
||||
Yap_Error(PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE,t,"dbload_get_space/4");
|
||||
return FALSE;
|
||||
return NULL;
|
||||
}
|
||||
if (IsVarTerm(tn) || !IsIntegerTerm(tn)) {
|
||||
return FALSE;
|
||||
return NULL;
|
||||
}
|
||||
ncls = IntegerOfTerm(tn);
|
||||
if (ncls <= 1) {
|
||||
return FALSE;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
required = ncls*arity*sizeof(CELL)+sizeof(MegaClause)+2*sizeof(struct index_t *);
|
||||
while (!(mcl = (MegaClause *)Yap_AllocCodeSpace(required))) {
|
||||
if (!Yap_growheap(FALSE, required, NULL)) {
|
||||
/* just fail, the system will keep on going */
|
||||
return FALSE;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
Yap_ClauseSpace += required;
|
||||
@ -637,13 +634,25 @@ p_exodb_get_space( USES_REGS1 )
|
||||
ap->OpcodeOfPred = Yap_opcode(_enter_exo);
|
||||
}
|
||||
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
||||
return mcl;
|
||||
}
|
||||
|
||||
|
||||
static Int
|
||||
p_exodb_get_space( USES_REGS1 )
|
||||
{ /* '$number_of_clauses'(Predicate,M,N) */
|
||||
void *mcl;
|
||||
|
||||
if ((mcl = exodb_get_space(Deref(ARG1), Deref(ARG2), Deref(ARG3))) == NULL)
|
||||
return FALSE;
|
||||
|
||||
return Yap_unify(ARG4, MkIntegerTerm((Int)mcl));
|
||||
}
|
||||
|
||||
#define DerefAndCheck(t, V) \
|
||||
t = Deref(V); if(IsVarTerm(t) || !(IsAtomOrIntTerm(t))) Yap_Error(TYPE_ERROR_ATOM, t0, "load_db");
|
||||
|
||||
static int
|
||||
static Int
|
||||
store_exo(yamop *pc, UInt arity, Term t0)
|
||||
{
|
||||
Term t;
|
||||
@ -659,12 +668,23 @@ store_exo(yamop *pc, UInt arity, Term t0)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
exoassert( void *handle, Int n, Term term )
|
||||
{ /* '$number_of_clauses'(Predicate,M,N) */
|
||||
PredEntry *pe;
|
||||
MegaClause *mcl;
|
||||
|
||||
|
||||
mcl = (MegaClause *) handle;
|
||||
pe = mcl->ClPred;
|
||||
store_exo((yamop *)((ADDR)mcl->ClCode+2*sizeof(struct index_t *)+n*(mcl->ClItemSize)),pe->ArityOfPE, term);
|
||||
}
|
||||
|
||||
static Int
|
||||
p_exoassert( USES_REGS1 )
|
||||
{ /* '$number_of_clauses'(Predicate,M,N) */
|
||||
Term thandle = Deref(ARG2);
|
||||
Term tn = Deref(ARG3);
|
||||
PredEntry *pe;
|
||||
MegaClause *mcl;
|
||||
Int n;
|
||||
|
||||
@ -677,8 +697,8 @@ p_exoassert( USES_REGS1 )
|
||||
return FALSE;
|
||||
}
|
||||
n = IntegerOfTerm(tn);
|
||||
pe = mcl->ClPred;
|
||||
return store_exo((yamop *)((ADDR)mcl->ClCode+2*sizeof(struct index_t *)+n*(mcl->ClItemSize)),pe->ArityOfPE, Deref(ARG1));
|
||||
exoassert(mcl,n,Deref(ARG1));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -115,6 +115,7 @@ INTERFACE_HEADERS = \
|
||||
$(srcdir)/include/yap_structs.h \
|
||||
$(srcdir)/include/YapInterface.h \
|
||||
$(srcdir)/include/SWI-Prolog.h \
|
||||
$(srcdir)/include/YapError.h \
|
||||
$(srcdir)/H/TermExt.h \
|
||||
$(srcdir)/H/YapTags.h \
|
||||
$(srcdir)/H/Tags_32bits.h \
|
||||
@ -149,7 +150,6 @@ HEADERS = \
|
||||
$(srcdir)/H/sshift.h \
|
||||
$(srcdir)/H/Yap.h \
|
||||
$(srcdir)/H/Yatom.h \
|
||||
$(srcdir)/include/YapError.h \
|
||||
$(srcdir)/H/YapHeap.h \
|
||||
$(srcdir)/H/Regs.h \
|
||||
$(srcdir)/H/Yapproto.h \
|
||||
|
Reference in New Issue
Block a user