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