YAP meets exo
This commit is contained in:
parent
9483572213
commit
8f0ce4bb94
90
C/exo.c
90
C/exo.c
@ -31,6 +31,15 @@
|
|||||||
#if HAVE_STRING_H
|
#if HAVE_STRING_H
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
#if HAVE_STRING_H
|
||||||
|
#include <string.h>
|
||||||
|
#endif
|
||||||
|
#if HAVE_STDBOOL_H
|
||||||
|
#include <stdbool.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool YAP_NewExo( PredEntry *ap, size_t data, struct udi_info *udi);
|
||||||
|
bool YAP_ExoAssert( PredEntry *pe, const Term *ts, size_t m);
|
||||||
|
|
||||||
//static int exo_write=FALSE;
|
//static int exo_write=FALSE;
|
||||||
|
|
||||||
@ -38,11 +47,21 @@
|
|||||||
|
|
||||||
#define MAX_ARITY 256
|
#define MAX_ARITY 256
|
||||||
|
|
||||||
#define FNV32_PRIME ((UInt)16777619)
|
#if SIZEOF_INT_P==4
|
||||||
#define FNV64_PRIME ((UInt)1099511628211)
|
#define FNV32_PRIME (16777619UL)
|
||||||
|
#define FNV32_OFFSET (0x811c9dc5UL)
|
||||||
#define FNV32_OFFSET ((UInt)0x811c9dc5)
|
#define FNV_PRIME FNV32_PRIME
|
||||||
#define FNV64_OFFSET ((UInt)14695981039346656037)
|
#define FNV_OFFSET FNV32_OFFSET
|
||||||
|
#elif SIZEOF_INT_P==8
|
||||||
|
#define FNV64_PRIME (1099511628211)
|
||||||
|
#if SIZEOF_LONG_INT==4
|
||||||
|
#define FNV64_OFFSET (14695981039346656037ULL)
|
||||||
|
#else
|
||||||
|
#define FNV64_OFFSET (14695981039346656037UL)
|
||||||
|
#endif
|
||||||
|
#define FNV_PRIME FNV64_PRIME
|
||||||
|
#define FNV_OFFSET FNV64_OFFSET
|
||||||
|
#endif
|
||||||
|
|
||||||
/*MurmurHash3 from: https://code.google.com/p/smhasher/wiki/MurmurHash3*/
|
/*MurmurHash3 from: https://code.google.com/p/smhasher/wiki/MurmurHash3*/
|
||||||
BITS32 rotl32 ( BITS32, int8_t);
|
BITS32 rotl32 ( BITS32, int8_t);
|
||||||
@ -79,7 +98,7 @@ HASH_MURMUR3_32 (UInt arity, CELL *cl, UInt bnds[], UInt sz)
|
|||||||
const BITS32 c1 = 0xcc9e2d51;
|
const BITS32 c1 = 0xcc9e2d51;
|
||||||
const BITS32 c2 = 0x1b873593;
|
const BITS32 c2 = 0x1b873593;
|
||||||
|
|
||||||
hash = FNV32_OFFSET; /*did not find what seed to use yet*/
|
hash = FNV_OFFSET; /*did not find what seed to use yet*/
|
||||||
|
|
||||||
while (j < arity) {
|
while (j < arity) {
|
||||||
if (bnds[j]) {
|
if (bnds[j]) {
|
||||||
@ -189,7 +208,7 @@ HASH_FVN_1A(UInt arity, CELL *cl, UInt bnds[], UInt sz)
|
|||||||
UInt hash;
|
UInt hash;
|
||||||
UInt j=0;
|
UInt j=0;
|
||||||
|
|
||||||
hash = FNV32_OFFSET;
|
hash = FNV_OFFSET;
|
||||||
while (j < arity) {
|
while (j < arity) {
|
||||||
if (bnds[j]) {
|
if (bnds[j]) {
|
||||||
unsigned char *i=(unsigned char*)(cl+j);
|
unsigned char *i=(unsigned char*)(cl+j);
|
||||||
@ -197,7 +216,7 @@ HASH_FVN_1A(UInt arity, CELL *cl, UInt bnds[], UInt sz)
|
|||||||
|
|
||||||
while (i < m) {
|
while (i < m) {
|
||||||
hash = hash ^ i[0];
|
hash = hash ^ i[0];
|
||||||
hash = hash * FNV32_PRIME;
|
hash = hash * FNV_PRIME;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -635,6 +654,46 @@ exodb_get_space( Term t, Term mod, Term tn )
|
|||||||
return mcl;
|
return mcl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
YAP_NewExo( PredEntry *ap, size_t data, struct udi_info *udi)
|
||||||
|
{
|
||||||
|
MegaClause *mcl;
|
||||||
|
size_t required;
|
||||||
|
struct index_t **li;
|
||||||
|
|
||||||
|
if (data <= ap->ArityOfPE*sizeof(CELL)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// data = ncls*arity*sizeof(CELL);
|
||||||
|
required = data+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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Yap_ClauseSpace += required;
|
||||||
|
/* cool, it's our turn to do the conversion */
|
||||||
|
mcl->ClFlags = MegaMask|ExoMask;
|
||||||
|
mcl->ClSize = required;
|
||||||
|
mcl->ClPred = ap;
|
||||||
|
mcl->ClItemSize = ap->ArityOfPE*sizeof(CELL);
|
||||||
|
mcl->ClNext = NULL;
|
||||||
|
li = (struct index_t **)(mcl->ClCode);
|
||||||
|
li[0] = li[1] = NULL;
|
||||||
|
ap->cs.p_code.FirstClause =
|
||||||
|
ap->cs.p_code.LastClause =
|
||||||
|
mcl->ClCode;
|
||||||
|
ap->PredFlags |= MegaClausePredFlag;
|
||||||
|
ap->cs.p_code.NOfClauses = 0;
|
||||||
|
if (ap->PredFlags & (SpiedPredFlag|CountPredFlag|ProfiledPredFlag)) {
|
||||||
|
ap->OpcodeOfPred = Yap_opcode(_spy_pred);
|
||||||
|
} else {
|
||||||
|
ap->OpcodeOfPred = Yap_opcode(_enter_exo);
|
||||||
|
}
|
||||||
|
ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static Int
|
static Int
|
||||||
p_exodb_get_space( USES_REGS1 )
|
p_exodb_get_space( USES_REGS1 )
|
||||||
@ -648,7 +707,7 @@ p_exodb_get_space( USES_REGS1 )
|
|||||||
}
|
}
|
||||||
|
|
||||||
#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_ATOMIC, t0, "load_db");
|
||||||
|
|
||||||
static Int
|
static Int
|
||||||
store_exo(yamop *pc, UInt arity, Term t0)
|
store_exo(yamop *pc, UInt arity, Term t0)
|
||||||
@ -666,6 +725,19 @@ store_exo(yamop *pc, UInt arity, Term t0)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
YAP_ExoAssert( PredEntry *pe, const Term *ts, size_t m)
|
||||||
|
{
|
||||||
|
MegaClause *mcl = ClauseCodeToMegaClause(pe->cs.p_code.FirstClause);
|
||||||
|
size_t i, n = pe->cs.p_code.NOfClauses;
|
||||||
|
ADDR base = (ADDR)mcl->ClCode+2*sizeof(struct index_t *);
|
||||||
|
for (i=0; i<n; i++) {
|
||||||
|
yamop *ptr = (yamop *)(base+n*(mcl->ClItemSize));
|
||||||
|
store_exo( ptr, pe->ArityOfPE, ts[i]);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
exoassert( void *handle, Int n, Term term )
|
exoassert( void *handle, Int n, Term term )
|
||||||
{ /* '$number_of_clauses'(Predicate,M,N) */
|
{ /* '$number_of_clauses'(Predicate,M,N) */
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* *
|
* *
|
||||||
* YAP Prolog @(#)c_interface.h 2.2 *
|
* YAP Prolog @(#)c_interface.h 2.2 *
|
||||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||||
* *
|
* *
|
||||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||||
@ -923,7 +923,7 @@ array of terms _Array_. _infop_ is the address of a goal
|
|||||||
handle that can be used to backtrack and to recover space. Succeeds if
|
handle that can be used to backtrack and to recover space. Succeeds if
|
||||||
a solution was found.
|
a solution was found.
|
||||||
|
|
||||||
Notice that you cannot create new slots if an YAP_EnterGoal goal is open.
|
Notice that you cannot create new slots if an YAP_ExnterGoal goal is open.
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
<li>`YAP_Bool` YAP_RetryGoal(`YAP_dogoalinfo \*` _infop_) @anchor YAP_RetryGoal
|
<li>`YAP_Bool` YAP_RetryGoal(`YAP_dogoalinfo \*` _infop_) @anchor YAP_RetryGoal
|
||||||
@ -1420,6 +1420,15 @@ The following C-functions are available from YAP:
|
|||||||
Compile the Prolog term _Clause_ and assert it as the last clause
|
Compile the Prolog term _Clause_ and assert it as the last clause
|
||||||
for the corresponding procedure.
|
for the corresponding procedure.
|
||||||
|
|
||||||
|
+ YAP_MkExo(`YAP_PredEntryPtr` _pred_, `size_t` _sz_, `void *` _uid_)
|
||||||
|
Predicate _pred_ is an exo-predicate that needs _sz_ bytes of
|
||||||
|
contiguous storage. If _uid_ is non-null associate user-defined
|
||||||
|
code with _pred_.
|
||||||
|
|
||||||
|
+ YAP_AssertTuples(`YAP_PredEntryPtr` pred, `const YAP_Term *` _Facts_, `size_t` nb)
|
||||||
|
Add the array of _nb_ Prolog term `Facts` to the table
|
||||||
|
`Predicate`.
|
||||||
|
|
||||||
+ `int` YAP_ContinueGoal(`void`)
|
+ `int` YAP_ContinueGoal(`void`)
|
||||||
Continue execution from the point where it stopped.
|
Continue execution from the point where it stopped.
|
||||||
|
|
||||||
@ -1846,6 +1855,10 @@ extern X_API YAP_Term YAP_CopyTerm(YAP_Term);
|
|||||||
/* char *YAP_CompileClause(YAP_Term) */
|
/* char *YAP_CompileClause(YAP_Term) */
|
||||||
extern X_API char *YAP_CompileClause(YAP_Term);
|
extern X_API char *YAP_CompileClause(YAP_Term);
|
||||||
|
|
||||||
|
extern X_API int YAP_NewExo( YAP_PredEntryPtr ap, size_t data, void *user_di);
|
||||||
|
|
||||||
|
extern X_API int YAP_AssertTuples( YAP_PredEntryPtr pred, const YAP_Term *ts, size_t sz);
|
||||||
|
|
||||||
/* int YAP_Init(YAP_init_args *) */
|
/* int YAP_Init(YAP_init_args *) */
|
||||||
extern X_API YAP_Int YAP_Init(YAP_init_args *);
|
extern X_API YAP_Int YAP_Init(YAP_init_args *);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user