Merge /home/vsc/yap

This commit is contained in:
Vítor Santos Costa 2018-11-23 16:12:42 +00:00
commit 81e37d5ce0
287 changed files with 23366 additions and 11399 deletions

View File

@ -12,11 +12,15 @@ WITH_VARS="swig|yes|WITH_SWIG \
mpi|yes|WITH_MPI \ mpi|yes|WITH_MPI \
gecode|yes|WITH_GECODE \ gecode|yes|WITH_GECODE \
docs|yes|WITH_DOCS \ docs|yes|WITH_DOCS \
r|yes|WITH_REAL \ r|yes|WITH_R \
myddas|yes|WITH_MYDDAS \
cudd|yes|WITH_CUDD \ cudd|yes|WITH_CUDD \
xml2|yes|WITH_XML2 \ xml2|yes|WITH_XML2 \
raptor|yes|WITH_RAPTOR \ raptor|yes|WITH_RAPTOR \
python|yes|WITH_PYTHON \ python|yes|WITH_PYTHON \
openssl|yes|WITH_OPENSSL\ openssl|yes|WITH_OPENSSL\
java|yes|WITH_JAVA
lbfgs|yes|WITH_LBFGS
extensions|yes|WITH_EXTENSIONS
readline|yes|WITH_READLINE \ readline|yes|WITH_READLINE \
gmp|yes|WITH_GMP" gmp|yes|WITH_GMP"

View File

@ -224,7 +224,7 @@ static int stack_overflow(PredEntry *pe, CELL *env, yamop *cp,
Yap_get_signal(YAP_STOVF_SIGNAL)) { Yap_get_signal(YAP_STOVF_SIGNAL)) {
S = (CELL *)pe; S = (CELL *)pe;
if (!Yap_locked_gc(nargs, env, cp)) { if (!Yap_locked_gc(nargs, env, cp)) {
Yap_NilError(RESOURCE_ERROR_STACK, LOCAL_ErrorMessage); Yap_NilError(RESOURCE_ERROR_STACK, "stack overflow: gc failed");
return 0; return 0;
} }
return 1; return 1;
@ -239,7 +239,7 @@ static int code_overflow(CELL *yenv USES_REGS) {
/* do a garbage collection first to check if we can recover memory */ /* do a garbage collection first to check if we can recover memory */
if (!Yap_locked_growheap(false, 0, NULL)) { if (!Yap_locked_growheap(false, 0, NULL)) {
Yap_NilError(RESOURCE_ERROR_HEAP, "YAP failed to grow heap: %s", Yap_NilError(RESOURCE_ERROR_HEAP, "YAP failed to grow heap: %s",
LOCAL_ErrorMessage); "malloc/mmap failed");
return 0; return 0;
} }
CACHE_A1(); CACHE_A1();
@ -689,7 +689,7 @@ static int interrupt_deallocate(USES_REGS1) {
return rc; return rc;
} }
if (!Yap_locked_gc(0, ENV, YESCODE)) { if (!Yap_locked_gc(0, ENV, YESCODE)) {
Yap_NilError(RESOURCE_ERROR_STACK, LOCAL_ErrorMessage); Yap_NilError(RESOURCE_ERROR_STACK, "stack overflow: gc failed");
} }
S = ASP; S = ASP;
S[E_CB] = (CELL)(LCL0 - cut_b); S[E_CB] = (CELL)(LCL0 - cut_b);
@ -751,7 +751,7 @@ static int interrupt_cut_e(USES_REGS1) {
if ((v = check_alarm_fail_int(2 PASS_REGS)) >= 0) { if ((v = check_alarm_fail_int(2 PASS_REGS)) >= 0) {
return v; return v;
} }
if (!Yap_only_has_signals(YAP_CDOVF_SIGNAL, YAP_CREEP_SIGNAL)) { if (Yap_only_has_signals(YAP_CDOVF_SIGNAL, YAP_CREEP_SIGNAL)) {
return 2; return 2;
} }
/* find something to fool S */ /* find something to fool S */
@ -957,35 +957,32 @@ static void undef_goal(USES_REGS1) {
} else { } else {
d0 = AbsAppl(HR); d0 = AbsAppl(HR);
*HR++ = (CELL)pe->FunctorOfPred; *HR++ = (CELL)pe->FunctorOfPred;
CELL *ip=HR, *imax = HR+pe->ArityOfPE; CELL *ip=HR;
HR = imax; UInt imax = pe->ArityOfPE;
BEGP(pt1); HR += imax;
pt1 = XREGS + 1; UInt i = 1;
for (; ip < imax; ip++) { for (; i <= imax; ip++, i++) {
BEGD(d1); BEGD(d1);
BEGP(pt0); BEGP(pt0);
pt0 = pt1++; d1 = XREGS[i];
d1 = *pt0;
deref_head(d1, undef_unk); deref_head(d1, undef_unk);
undef_nonvar: undef_nonvar:
/* just copy it to the heap */ /* just copy it to the heap */
*ip = d1; *ip = d1;
continue; continue;
derefa_body(d1, pt0, undef_unk, undef_nonvar); deref_body(d1, pt0, undef_unk, undef_nonvar);
if (pt0 <= HR) { if (pt0 < HR) {
/* variable is safe */ /* variable is safe */
*ip = (CELL)pt0; *ip = (CELL)pt0;
} else { } else {
/* bind it, in case it is a local variable */ /* bind it, in case it is a local variable */
d1 = Unsigned(ip);
RESET_VARIABLE(ip); RESET_VARIABLE(ip);
Bind_Local(pt0, d1); Bind_Local(pt0, Unsigned(ip));
} }
ENDP(pt0); ENDP(pt0);
ENDD(d1); ENDD(d1);
} }
ENDP(pt1);
} }
ARG1 = AbsPair(HR); ARG1 = AbsPair(HR);
HR[1] = d0; HR[1] = d0;

View File

@ -1102,7 +1102,7 @@
PP = NULL; PP = NULL;
#endif #endif
if (!Yap_gc(3, ENV, CP)) { if (!Yap_gc(3, ENV, CP)) {
Yap_NilError(RESOURCE_ERROR_STACK, LOCAL_ErrorMessage); Yap_NilError(RESOURCE_ERROR_STACK, "stack overflow: gc failed");
FAIL(); FAIL();
} }
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
@ -1226,7 +1226,7 @@
PREG = NEXTOP(PREG,Osbpa); PREG = NEXTOP(PREG,Osbpa);
saveregs(); saveregs();
if (!Yap_gcl(sz, arity, YENV, PREG)) { if (!Yap_gcl(sz, arity, YENV, PREG)) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage); Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
setregs(); setregs();
FAIL(); FAIL();
} else { } else {
@ -10927,7 +10927,7 @@
/* make sure we have something to show for our trouble */ /* make sure we have something to show for our trouble */
saveregs(); saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,xxx),Osbpp))) { if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,xxx),Osbpp))) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage); Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
setregs(); setregs();
JMPNext(); JMPNext();
} else { } else {
@ -11044,7 +11044,7 @@
/* make sure we have something to show for our trouble */ /* make sure we have something to show for our trouble */
saveregs(); saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,xxc),Osbpp))) { if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,xxc),Osbpp))) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage); Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
setregs(); setregs();
JMPNext(); JMPNext();
} else { } else {
@ -11154,7 +11154,7 @@
/* make sure we have something to show for our trouble */ /* make sure we have something to show for our trouble */
saveregs(); saveregs();
if (!Yap_gc(0, YREG, NEXTOP(NEXTOP(PREG,xxn),Osbpp))) { if (!Yap_gc(0, YREG, NEXTOP(NEXTOP(PREG,xxn),Osbpp))) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage); Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
setregs(); setregs();
JMPNext(); JMPNext();
} else { } else {
@ -11261,7 +11261,7 @@
/* make sure we have something to show for our trouble */ /* make sure we have something to show for our trouble */
saveregs(); saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxx),Osbpp))) { if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxx),Osbpp))) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage); Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
setregs(); setregs();
JMPNext(); JMPNext();
} else { } else {
@ -11388,7 +11388,7 @@
/* make sure we have something to show for our trouble */ /* make sure we have something to show for our trouble */
saveregs(); saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxc),Osbpp))) { if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxc),Osbpp))) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage); Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
setregs(); setregs();
JMPNext(); JMPNext();
} else { } else {
@ -11516,7 +11516,7 @@
/* make sure we have something to show for our trouble */ /* make sure we have something to show for our trouble */
saveregs(); saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxn),Osbpp))) { if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxn),Osbpp))) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage); Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
setregs(); setregs();
JMPNext(); JMPNext();
} else { } else {
@ -11892,7 +11892,7 @@
/* make sure we have something to show for our trouble */ /* make sure we have something to show for our trouble */
saveregs(); saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 3, YREG, NEXTOP(NEXTOP(PREG,e),Osbmp))) { if (!Yap_gcl((1+d1)*sizeof(CELL), 3, YREG, NEXTOP(NEXTOP(PREG,e),Osbmp))) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage); Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed" );
setregs(); setregs();
JMPNext(); JMPNext();
} else { } else {

View File

@ -186,18 +186,6 @@ eval0(Int fi) {
RINT((Int)ASP); RINT((Int)ASP);
#else #else
RINT(LCL0 - ASP); RINT(LCL0 - ASP);
#endif
case op_b:
/// - $b
/// current choicepoint
///
#if YAPOR_SBA
RINT((Int)B);
#else
if (B)
RINT(LCL0 - (CELL *)B);
else
RINT(0);
#endif #endif
case op_env: case op_env:
/// - $env /// - $env
@ -257,7 +245,6 @@ static InitConstEntry InitConstTab[] = {
{"heapused", op_heapused}, {"heapused", op_heapused},
{"local_sp", op_localsp}, {"local_sp", op_localsp},
{"global_sp", op_globalsp}, {"global_sp", op_globalsp},
{"$last_choice_pt", op_b},
{"$env", op_env}, {"$env", op_env},
{"$tr", op_tr}, {"$tr", op_tr},
{"stackfree", op_stackfree}, {"stackfree", op_stackfree},

View File

@ -218,6 +218,11 @@ X_API YAP_Term YAP_A(int i) {
return (Deref(XREGS[i])); return (Deref(XREGS[i]));
} }
X_API YAP_Term YAP_SetA(int i, YAP_Term t) {
CACHE_REGS
return (Deref(XREGS[i]));
}
X_API YAP_Bool YAP_IsIntTerm(YAP_Term t) { return IsIntegerTerm(t); } X_API YAP_Bool YAP_IsIntTerm(YAP_Term t) { return IsIntegerTerm(t); }
X_API YAP_Bool YAP_IsNumberTerm(YAP_Term t) { X_API YAP_Bool YAP_IsNumberTerm(YAP_Term t) {
@ -1352,8 +1357,8 @@ X_API void YAP_FreeSpaceFromYap(void *ptr) { Yap_FreeCodeSpace(ptr); }
* @param bufsize bu * @param bufsize bu
* *
* @return * @return
*/ X_API char * */
YAP_StringToBuffer(Term t, char *buf, unsigned int bufsize) { X_API char *YAP_StringToBuffer(Term t, char *buf, unsigned int bufsize) {
CACHE_REGS CACHE_REGS
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
seq_tv_t inp, out; seq_tv_t inp, out;
@ -1464,7 +1469,8 @@ X_API Term YAP_ReadBuffer(const char *s, Term *tp) {
else else
tv = (Term)0; tv = (Term)0;
LOCAL_ErrorMessage = NULL; LOCAL_ErrorMessage = NULL;
while (!(t = Yap_BufferToTermWithPrioBindings(s, TermNil, tv, strlen(s) + 1, GLOBAL_MaxPriority))) { while (!(t = Yap_BufferToTermWithPrioBindings(s, TermNil, tv, strlen(s) + 1,
GLOBAL_MaxPriority))) {
if (LOCAL_ErrorMessage) { if (LOCAL_ErrorMessage) {
if (!strcmp(LOCAL_ErrorMessage, "Stack Overflow")) { if (!strcmp(LOCAL_ErrorMessage, "Stack Overflow")) {
if (!Yap_dogc(0, NULL PASS_REGS)) { if (!Yap_dogc(0, NULL PASS_REGS)) {
@ -1731,7 +1737,9 @@ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) {
CACHE_REGS CACHE_REGS
PredEntry *pe = ape; PredEntry *pe = ape;
bool out; bool out;
// fprintf(stderr,"EnterGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n",HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot); // fprintf(stderr,"EnterGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
// Slots=%d\n",HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP,
// LOCAL_CurSlot);
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
LOCAL_ActiveError->errorNo = YAP_NO_ERROR; LOCAL_ActiveError->errorNo = YAP_NO_ERROR;
@ -1753,7 +1761,9 @@ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) {
// fprintf(stderr,"PrepGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n", // fprintf(stderr,"PrepGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n",
// HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot); // HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
out = Yap_exec_absmi(true, false); out = Yap_exec_absmi(true, false);
// fprintf(stderr,"EnterGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n", out,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot); // fprintf(stderr,"EnterGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
// Slots=%d\n", out,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP,
// LOCAL_CurSlot);
dgi->b = LCL0 - (CELL *)B; dgi->b = LCL0 - (CELL *)B;
if (out) { if (out) {
dgi->EndSlot = LOCAL_CurSlot; dgi->EndSlot = LOCAL_CurSlot;
@ -1801,46 +1811,24 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
return out; return out;
} }
static void completeInnerCall( bool on_cut, yamop *old_CP, yamop *old_P)
{
if (on_cut) {
P = old_P;
ENV = (CELL *)ENV[E_E];
CP = old_CP;
LOCAL_AllowRestart = TRUE;
// we are back to user code again, need slots */
} else {
P = old_P;
ENV = B->cp_env;
ENV = (CELL *)ENV[E_E];
CP = old_CP;
HR = B->cp_h;
TR = B->cp_tr;
B = B->cp_b;
LOCAL_AllowRestart = FALSE;
SET_ASP(ENV, E_CB * sizeof(CELL));
// make sure the slots are ok.
}
}
X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) { X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
CACHE_REGS CACHE_REGS
choiceptr myB, handler; choiceptr myB, handler;
// fprintf(stderr,"LeaveGoal success=%d: H=%d ENV=%p B=%ld myB=%ld TR=%d P=%p CP=%p Slots=%d\n", successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,dgi->b0,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot); // fprintf(stderr,"LeaveGoal success=%d: H=%d ENV=%p B=%ld myB=%ld TR=%d
// P=%p CP=%p Slots=%d\n",
// successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,dgi->b0,(CELL*)TR-LCL0, P, CP,
// LOCAL_CurSlot);
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
myB = (choiceptr)(LCL0 - dgi->b); myB = (choiceptr)(LCL0 - dgi->b);
if (LOCAL_PrologMode & AsyncIntMode) { if (LOCAL_PrologMode & AsyncIntMode) {
Yap_signal(YAP_FAIL_SIGNAL); Yap_signal(YAP_FAIL_SIGNAL);
} }
handler = B; handler = B;
while (handler while (handler &&
&& LCL0-LOCAL_CBorder > (CELL *)handler LCL0 - LOCAL_CBorder > (CELL *)handler
//&& handler->cp_ap != NOCODE //&& handler->cp_ap != NOCODE
&& handler->cp_b != NULL && handler->cp_b != NULL && handler != myB) {
&& handler != myB
) {
if (handler < myB) { if (handler < myB) {
handler->cp_ap = TRUSTFAILCODE; handler->cp_ap = TRUSTFAILCODE;
} }
@ -1859,7 +1847,9 @@ X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
P = dgi->p; P = dgi->p;
CP = dgi->cp; CP = dgi->cp;
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
// fprintf(stderr,"LeftGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n", successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot); // fprintf(stderr,"LeftGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
// Slots=%d\n", successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P,
// CP, LOCAL_CurSlot);
return TRUE; return TRUE;
} }
@ -2114,14 +2104,16 @@ X_API void YAP_ClearExceptions(void) {
Yap_ResetException(worker_id); Yap_ResetException(worker_id);
} }
X_API int YAP_InitConsult(int mode, const char *fname, char **full, int *osnop) { X_API int YAP_InitConsult(int mode, const char *fname, char **full,
int *osnop) {
CACHE_REGS CACHE_REGS
int sno; int sno;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
const char *fl = NULL; const char *fl = NULL;
int lvl = push_text_stack(); int lvl = push_text_stack();
if (mode == YAP_BOOT_MODE) { if (mode == YAP_BOOT_MODE) {
mode = YAP_CONSULT_MODE; } mode = YAP_CONSULT_MODE;
}
if (fname == NULL || fname[0] == '\0') { if (fname == NULL || fname[0] == '\0') {
fl = Yap_BOOTFILE; fl = Yap_BOOTFILE;
} }
@ -2143,13 +2135,14 @@ X_API int YAP_InitConsult(int mode, const char *fname, char **full, int *osnop)
strcpy(d, fl); strcpy(d, fl);
bool consulted = (mode == YAP_CONSULT_MODE); bool consulted = (mode == YAP_CONSULT_MODE);
Term tat = MkAtomTerm(Yap_LookupAtom(d)); Term tat = MkAtomTerm(Yap_LookupAtom(d));
sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)), LOCAL_encoding); sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)),
if (sno < 0 || LOCAL_encoding);
!Yap_ChDir(dirname((char *)d))) { if (sno < 0 || !Yap_ChDir(dirname((char *)d))) {
pop_text_stack(lvl); pop_text_stack(lvl);
*full = NULL; *full = NULL;
return -1; return -1;
} LOCAL_PrologMode = UserMode; }
LOCAL_PrologMode = UserMode;
Yap_init_consult(consulted, pop_output_text_stack__(lvl, fl)); Yap_init_consult(consulted, pop_output_text_stack__(lvl, fl));
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
@ -2186,7 +2179,10 @@ X_API void YAP_EndConsult(int sno, int *osnop, const char *full) {
Yap_AddAlias(AtomLoopStream, *osnop); Yap_AddAlias(AtomLoopStream, *osnop);
Yap_end_consult(); Yap_end_consult();
__android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " closing %s:%s(%d), %d", __android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " closing %s:%s(%d), %d",
CurrentModule == 0? "prolog": RepAtom(AtomOfTerm(CurrentModule))->StrOfAE, full, *osnop, sno); CurrentModule == 0
? "prolog"
: RepAtom(AtomOfTerm(CurrentModule))->StrOfAE,
full, *osnop, sno);
// LOCAL_CurSlot); // LOCAL_CurSlot);
pop_text_stack(lvl); pop_text_stack(lvl);
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
@ -2215,7 +2211,13 @@ X_API Term YAP_ReadFromStream(int sno) {
X_API Term YAP_ReadClauseFromStream(int sno, Term vs, Term pos) { X_API Term YAP_ReadClauseFromStream(int sno, Term vs, Term pos) {
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
Term t = Yap_read_term(sno,MkPairTerm(Yap_MkApplTerm(Yap_MkFunctor(AtomVariableNames,1),1,&vs), MkPairTerm(Yap_MkApplTerm(Yap_MkFunctor(AtomTermPosition,1),1,&pos), TermNil)), true); Term t = Yap_read_term(
sno,
MkPairTerm(Yap_MkApplTerm(Yap_MkFunctor(AtomVariableNames, 1), 1, &vs),
MkPairTerm(Yap_MkApplTerm(Yap_MkFunctor(AtomTermPosition, 1),
1, &pos),
TermNil)),
true);
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return t; return t;
} }

View File

@ -94,20 +94,32 @@ void Yap_ResetConsultStack(void) {
LOCAL_ConsultCapacity = InitialConsultCapacity; LOCAL_ConsultCapacity = InitialConsultCapacity;
} }
/**
* Are we compiling a file?
*
*/
bool Yap_Consulting(USES_REGS1) {
return LOCAL_ConsultBase != NULL
&& LOCAL_ConsultSp != LOCAL_ConsultLow+LOCAL_ConsultCapacity;
}
/****************************************************************** /******************************************************************
ADDING AND REMOVE INFO TO A PROCEDURE ADDING AND REMOVE INFO TO A PROCEDURE
******************************************************************/ ******************************************************************/
/* /**
* we have three kinds of predicates: dynamic DynamicPredFlag * we have three kinds of predicates:
* static CompiledPredFlag fast FastPredFlag all the * + dynamic DynamicPredFlag
* + static CompiledPredFlag fast
* + fast FastPredFlag.
*
* all the
* database predicates are supported for dynamic predicates only abolish and * database predicates are supported for dynamic predicates only abolish and
* assertz are supported for static predicates no database predicates are * assertz are supported for static predicates no database predicates are
* supportted for fast predicates * supportted for fast predicates
*/ */
PredEntry *Yap_get_pred(Term t, Term tmod, const char *pname) { PredEntry *Yap_get_pred(Term t, Term tmod, const char *pname) {
Term t0 = t; Term t0 = t;
@ -1207,8 +1219,8 @@ static void add_first_dynamic(PredEntry *p, yamop *cp, int spy_flag) {
ncp = NEXTOP(ncp, e); ncp = NEXTOP(ncp, e);
ncp->opc = Yap_opcode(_Ystop); ncp->opc = Yap_opcode(_Ystop);
ncp->y_u.l.l = cl->ClCode; ncp->y_u.l.l = cl->ClCode;
// if (!(p->PredFlags & MultiFileFlag) && p->src.OwnerFile == AtomNil) if (!(p->PredFlags & MultiFileFlag) && p->src.OwnerFile == AtomNil)
// p->src.OwnerFile = Yap_ConsultingFile(PASS_REGS1); p->src.OwnerFile = Yap_ConsultingFile(PASS_REGS1);
} }
/* p is already locked */ /* p is already locked */
@ -2417,7 +2429,7 @@ static Int
} }
/* @pred '$new_multifile'(+G,+Mod) /* @pred '$new_multifile'(+G,+Mod)
* sets the multi-file flag * declares rgi/////// the multi-file flag
* */ * */
static Int new_multifile(USES_REGS1) { static Int new_multifile(USES_REGS1) {
PredEntry *pe; PredEntry *pe;
@ -3169,15 +3181,14 @@ stash_predicate(USES_REGS1) {
char ns[1024]; char ns[1024];
const char *s = (pe->ModuleOfPred == PROLOG_MODULE ? const char *s = (pe->ModuleOfPred == PROLOG_MODULE ?
"__prolog__stash__" : "__prolog__stash__" :
snprintf(sn,1023,"__%s__".RepAtom(AtomOfTerm( pe->ModuleOfPred )))); snprintf(sn,1023,"__%s__".RepAtom(AtomOfTerm(
pe->ModuleOfPred = MkAtomTerm(Yap_LookupAtom(s)); pe->ModuleOfPred )))); pe->ModuleOfPred = MkAtomTerm(Yap_LookupAtom(s));
*/ */
return true; return true;
} else } else
return false; return false;
} }
static Int /* $hidden_predicate(P) */ static Int /* $hidden_predicate(P) */
hidden_predicate(USES_REGS1) { hidden_predicate(USES_REGS1) {
PredEntry *pe = PredEntry *pe =

View File

@ -427,6 +427,8 @@ ructions *
Op(deallocate, p); Op(deallocate, p);
CACHE_Y_AS_ENV(YREG); CACHE_Y_AS_ENV(YREG);
// do this before checking
SREG = YREG;
check_trail(TR); check_trail(TR);
#ifndef NO_CHECKING #ifndef NO_CHECKING
/* check stacks */ /* check stacks */
@ -435,7 +437,6 @@ ructions *
PREG = NEXTOP(PREG, p); PREG = NEXTOP(PREG, p);
/* other instructions do depend on S being set by deallocate /* other instructions do depend on S being set by deallocate
:-( */ :-( */
SREG = YREG;
CPREG = (yamop *) ENV_YREG[E_CP]; CPREG = (yamop *) ENV_YREG[E_CP];
ENV = ENV_YREG = (CELL *) ENV_YREG[E_E]; ENV = ENV_YREG = (CELL *) ENV_YREG[E_E];
#ifdef DEPTH_LIMIT #ifdef DEPTH_LIMIT

156
C/dbase.c
View File

@ -25,90 +25,86 @@ static char SccsId[] = "%W% %G%";
* *
* @brief record and other forms of storing terms. * @brief record and other forms of storing terms.
* *
* @namespace prolog
*
*
*
*/ */
/** @defgroup Internal_Database Internal Data Base /** @defgroup Internal_Database Internal Data Base
*
@ingroup builtins * @ingroup builtins
@{ * @{
*
Some programs need global information for, e.g. counting or collecting * Some programs need global information for, e.g. counting or collecting
data obtained by backtracking. As a rule, to keep this information, the * data obtained by backtracking. As a rule, to keep this information, the
internal data base should be used instead of asserting and retracting * internal data base should be used instead of asserting and retracting
clauses (as most novice programmers do), . * clauses (as most novice programmers do), .
In YAP (as in some other Prolog systems) the internal data base (i.d.b. * In YAP (as in some other Prolog systems) the internal data base (i.d.b.
for short) is faster, needs less space and provides a better insulation of * for short) is faster, needs less space and provides a better insulation of
program and data than using asserted/retracted clauses. * program and data than using asserted/retracted clauses.
The i.d.b. is implemented as a set of terms, accessed by keys that * The i.d.b. is implemented as a set of terms, accessed by keys that
unlikely what happens in (non-Prolog) data bases are not part of the * unlikely what happens in (non-Prolog) data bases are not part of the
term. Under each key a list of terms is kept. References are provided so that * term. Under each key a list of terms is kept. References are provided so that
terms can be identified: each term in the i.d.b. has a unique reference * terms can be identified: each term in the i.d.b. has a unique reference
(references are also available for clauses of dynamic predicates). * (references are also available for clauses of dynamic predicates).
*
There is a strong analogy between the i.d.b. and the way dynamic * There is a strong analogy between the i.d.b. and the way dynamic
predicates are stored. In fact, the main i.d.b. predicates might be * predicates are stored. In fact, the main i.d.b. predicates might be
implemented using dynamic predicates: * implemented using dynamic predicates:
*
~~~~~ * ~~~~~
recorda(X,T,R) :- asserta(idb(X,T),R). * recorda(X,T,R) :- asserta(idb(X,T),R).
recordz(X,T,R) :- assertz(idb(X,T),R). * recordz(X,T,R) :- assertz(idb(X,T),R).
recorded(X,T,R) :- clause(idb(X,T),R). * recorded(X,T,R) :- clause(idb(X,T),R).
~~~~~ * ~~~~~
We can take advantage of this, the other way around, as it is quite * We can take advantage of this, the other way around, as it is quite
easy to write a simple Prolog interpreter, using the i.d.b.: * easy to write a simple Prolog interpreter, using the i.d.b.:
*
~~~~~ * ~~~~~
asserta(G) :- recorda(interpreter,G,_). * asserta(G) :- recorda(interpreter,G,_).
assertz(G) :- recordz(interpreter,G,_). * assertz(G) :- recordz(interpreter,G,_).
retract(G) :- recorded(interpreter,G,R), !, erase(R). * retract(G) :- recorded(interpreter,G,R), !, erase(R).
call(V) :- var(V), !, fail. * call(V) :- var(V), !, fail.
call((H :- B)) :- !, recorded(interpreter,(H :- B),_), call(B). * call((H :- B)) :- !, recorded(interpreter,(H :- B),_), call(B).
call(G) :- recorded(interpreter,G,_). * call(G) :- recorded(interpreter,G,_).
~~~~~ * ~~~~~
In YAP, much attention has been given to the implementation of the * In YAP, much attention has been given to the implementation of the
i.d.b., especially to the problem of accelerating the access to terms kept in * i.d.b., especially to the problem of accelerating the access to terms kept in
a large list under the same key. Besides using the key, YAP uses an internal * a large list under the same key. Besides using the key, YAP uses an internal
lookup function, transparent to the user, to find only the terms that might * lookup function, transparent to the user, to find only the terms that might
unify. For instance, in a data base containing the terms * unify. For instance, in a data base containing the terms
*
~~~~~ * ~~~~~
b * b
b(a) * b(a)
c(d) * c(d)
e(g) * e(g)
b(X) * b(X)
e(h) * e(h)
~~~~~ * ~~~~~
*
stored under the key k/1, when executing the query * stored under the key k/1, when executing the query
*
~~~~~ * ~~~~~
:- recorded(k(_),c(_),R). * :- recorded(k(_),c(_),R).
~~~~~ * ~~~~~
*
`recorded` would proceed directly to the third term, spending almost the * `recorded` would proceed directly to the third term, spending almost the
time as if `a(X)` or `b(X)` was being searched. * time as if `a(X)` or `b(X)` was being searched.
The lookup function uses the functor of the term, and its first three * The lookup function uses the functor of the term, and its first three
arguments (when they exist). So, `recorded(k(_),e(h),_)` would go * arguments (when they exist). So, `recorded(k(_),e(h),_)` would go
directly to the last term, while `recorded(k(_),e(_),_)` would find * directly to the last term, while `recorded(k(_),e(_),_)` would find
first the fourth term, and then, after backtracking, the last one. * first the fourth term, and then, after backtracking, the last one.
*
This mechanism may be useful to implement a sort of hierarchy, where * This mechanism may be useful to implement a sort of hierarchy, where
the functors of the terms (and eventually the first arguments) work as * the functors of the terms (and eventually the first arguments) work as
secondary keys. * secondary keys.
*
In the YAP's i.d.b. an optimized representation is used for * In the YAP's i.d.b. an optimized representation is used for
terms without free variables. This results in a faster retrieval of terms * terms without free variables. This results in a faster retrieval of terms
and better space usage. Whenever possible, avoid variables in terms in terms * and better space usage. Whenever possible, avoid variables in terms in terms
stored in the i.d.b. * stored in the i.d.b.
*
*
*
*/ */
#include "Yap.h" #include "Yap.h"

View File

@ -35,7 +35,7 @@
#define set_key_b(k, ks, q, i, t) \ #define set_key_b(k, ks, q, i, t) \
if (strcmp(ks, q) == 0) { \ if (strcmp(ks, q) == 0) { \
i->k = t == TermTrue ? true : false; \ i->k = ( t == TermTrue ? true : false); \
return i->k || t == TermFalse; \ return i->k || t == TermFalse; \
} }
@ -67,20 +67,21 @@ static bool setErr(const char *q, yap_error_descriptor_t *i, Term t) {
set_key_s(errorFunction, "errorFunction", q, i, t); set_key_s(errorFunction, "errorFunction", q, i, t);
set_key_s(errorFile, "errorFile", q, i, t); set_key_s(errorFile, "errorFile", q, i, t);
set_key_i(prologPredLine, "prologPredLine", q, i, t); set_key_i(prologPredLine, "prologPredLine", q, i, t);
set_key_i(prologPredFirstLine, "prologPredFirstLine", q, i, t);
set_key_i(prologPredLastLine, "prologPredLastLine", q, i, t);
set_key_s(prologPredName, "prologPredName", q, i, t); set_key_s(prologPredName, "prologPredName", q, i, t);
set_key_i(prologPredArity, "prologPredArity", q, i, t); set_key_i(prologPredArity, "prologPredArity", q, i, t);
set_key_s(prologPredModule, "prologPredModule", q, i, t); set_key_s(prologPredModule, "prologPredModule", q, i, t);
set_key_s(prologPredFile, "prologPredFile", q, i, t); set_key_s(prologPredFile, "prologPredFile", q, i, t);
set_key_i(prologParserPos, "prologParserPos", q, i, t); set_key_i(parserPos, "parserPos", q, i, t);
set_key_i(prologParserLine, "prologParserLine", q, i, t); set_key_i(parserLine, "parserLine", q, i, t);
set_key_i(prologParserFirstLine, "prologParserFirstLine", q, i, t); set_key_i(parserFirstLine, "parserFirstLine", q, i, t);
set_key_i(prologParserLastLine, "prologParserLastLine", q, i, t); set_key_i(parserLastLine, "parserLastLine", q, i, t);
set_key_s(prologParserText, "prologParserText", q, i, t); set_key_s(parserTextA, "parserTextA", q, i, t);
set_key_s(prologParserFile, "prologParserFile", q, i, t); set_key_s(parserTextB, "parserTextB", q, i, t);
set_key_s(parserFile, "parserFile", q, i, t);
set_key_b(parserReadingCode, "parserReadingcode", q, i, t);
set_key_b(prologConsulting, "prologConsulting", q, i, t); set_key_b(prologConsulting, "prologConsulting", q, i, t);
set_key_s(culprit, "culprit", q, i, t); set_key_s(culprit, "culprit", q, i, t);
set_key_s(prologStack, "prologStack", q, i, t);
set_key_s(errorMsg, "errorMsg", q, i, t); set_key_s(errorMsg, "errorMsg", q, i, t);
set_key_i(errorMsgLen, "errorMsgLen", q, i, t); set_key_i(errorMsgLen, "errorMsgLen", q, i, t);
return false; return false;
@ -116,20 +117,21 @@ static Term queryErr(const char *q, yap_error_descriptor_t *i) {
query_key_s(errorFunction, "errorFunction", q, i); query_key_s(errorFunction, "errorFunction", q, i);
query_key_s(errorFile, "errorFile", q, i); query_key_s(errorFile, "errorFile", q, i);
query_key_i(prologPredLine, "prologPredLine", q, i); query_key_i(prologPredLine, "prologPredLine", q, i);
query_key_i(prologPredFirstLine, "prologPredFirstLine", q, i);
query_key_i(prologPredLastLine, "prologPredLastLine", q, i);
query_key_s(prologPredName, "prologPredName", q, i); query_key_s(prologPredName, "prologPredName", q, i);
query_key_i(prologPredArity, "prologPredArity", q, i); query_key_i(prologPredArity, "prologPredArity", q, i);
query_key_s(prologPredModule, "prologPredModule", q, i); query_key_s(prologPredModule, "prologPredModule", q, i);
query_key_s(prologPredFile, "prologPredFile", q, i); query_key_s(prologPredFile, "prologPredFile", q, i);
query_key_i(prologParserPos, "prologParserPos", q, i); query_key_i(parserPos, "parserPos", q, i);
query_key_i(prologParserLine, "prologParserLine", q, i); query_key_i(parserLine, "parserLine", q, i);
query_key_i(prologParserFirstLine, "prologParserFirstLine", q, i); query_key_i(parserFirstLine, "parserFirstLine", q, i);
query_key_i(prologParserLastLine, "prologParserLastLine", q, i); query_key_i(parserLastLine, "parserLastLine", q, i);
query_key_s(prologParserText, "prologParserText", q, i); query_key_s(parserTextA, "parserTextA", q, i);
query_key_s(prologParserFile, "prologParserFile", q, i); query_key_s(parserTextB, "parserTextB", q, i);
query_key_s(parserFile, "parserFile", q, i);
query_key_b(parserReadingCode, "parserReadingCode", q, i);
query_key_b(prologConsulting, "prologConsulting", q, i); query_key_b(prologConsulting, "prologConsulting", q, i);
query_key_t(culprit, "culprit", q, i); query_key_s(prologStack, "prologStack", q, i);
query_key_s(culprit, "culprit", q, i);
query_key_s(errorMsg, "errorMsg", q, i); query_key_s(errorMsg, "errorMsg", q, i);
query_key_i(errorMsgLen, "errorMsgLen", q, i); query_key_i(errorMsgLen, "errorMsgLen", q, i);
return TermNil; return TermNil;
@ -162,20 +164,21 @@ static void printErr(yap_error_descriptor_t *i) {
print_key_s("errorFunction", i->errorFunction); print_key_s("errorFunction", i->errorFunction);
print_key_s("errorFile", i->errorFile); print_key_s("errorFile", i->errorFile);
print_key_i("prologPredLine", i->prologPredLine); print_key_i("prologPredLine", i->prologPredLine);
print_key_i("prologPredFirstLine", i->prologPredFirstLine);
print_key_i("prologPredLastLine", i->prologPredLastLine);
print_key_s("prologPredName", i->prologPredName); print_key_s("prologPredName", i->prologPredName);
print_key_i("prologPredArity", i->prologPredArity); print_key_i("prologPredArity", i->prologPredArity);
print_key_s("prologPredModule", i->prologPredModule); print_key_s("prologPredModule", i->prologPredModule);
print_key_s("prologPredFile", i->prologPredFile); print_key_s("prologPredFile", i->prologPredFile);
print_key_i("prologParserPos", i->prologParserPos); print_key_i("parserPos", i->parserPos);
print_key_i("prologParserLine", i->prologParserLine); print_key_i("parserLine", i->parserLine);
print_key_i("prologParserFirstLine", i->prologParserFirstLine); print_key_i("parserFirstLine", i->parserFirstLine);
print_key_i("prologParserLastLine", i->prologParserLastLine); print_key_i("parserLastLine", i->parserLastLine);
print_key_s("prologParserText", i->prologParserText); print_key_s("parserTextA", i->parserTextA);
print_key_s("prologParserFile", i->prologParserFile); print_key_s("parserTextB", i->parserTextB);
print_key_s("parserFile", i->parserFile);
print_key_b("parserReadingCode", i->parserReadingCode);
print_key_b("prologConsulting", i->prologConsulting); print_key_b("prologConsulting", i->prologConsulting);
print_key_s("culprit", i->culprit); print_key_s("culprit", i->culprit);
print_key_s("prologStack", i->prologStack);
if (i->errorMsgLen) { if (i->errorMsgLen) {
print_key_s("errorMsg", i->errorMsg); print_key_s("errorMsg", i->errorMsg);
print_key_i("errorMsgLen", i->errorMsgLen); print_key_i("errorMsgLen", i->errorMsgLen);
@ -220,20 +223,21 @@ static Term err2list(yap_error_descriptor_t *i) {
o = add_key_s("errorFunction", i->errorFunction, o); o = add_key_s("errorFunction", i->errorFunction, o);
o = add_key_s("errorFile", i->errorFile, o); o = add_key_s("errorFile", i->errorFile, o);
o = add_key_i("prologPredLine", i->prologPredLine, o); o = add_key_i("prologPredLine", i->prologPredLine, o);
o = add_key_i("prologPredFirstLine", i->prologPredFirstLine, o);
o = add_key_i("prologPredLastLine", i->prologPredLastLine, o);
o = add_key_s("prologPredName", i->prologPredName, o); o = add_key_s("prologPredName", i->prologPredName, o);
o = add_key_i("prologPredArity", i->prologPredArity, o); o = add_key_i("prologPredArity", i->prologPredArity, o);
o = add_key_s("prologPredModule", i->prologPredModule, o); o = add_key_s("prologPredModule", i->prologPredModule, o);
o = add_key_s("prologPredFile", i->prologPredFile, o); o = add_key_s("prologPredFile", i->prologPredFile, o);
o = add_key_i("prologParserPos", i->prologParserPos, o); o = add_key_i("parserPos", i->parserPos, o);
o = add_key_i("prologParserLine", i->prologParserLine, o); o = add_key_i("parserLine", i->parserLine, o);
o = add_key_i("prologParserFirstLine", i->prologParserFirstLine, o); o = add_key_i("parserFirstLine", i->parserFirstLine, o);
o = add_key_i("prologParserLastLine", i->prologParserLastLine, o); o = add_key_i("parserLastLine", i->parserLastLine, o);
o = add_key_s("prologParserText", i->prologParserText, o); o = add_key_s("parserTextA", i->parserTextA, o);
o = add_key_s("prologParserFile", i->prologParserFile, o); o = add_key_s("parserTextB", i->parserTextB, o);
o = add_key_s("parserFile", i->parserFile, o);
o = add_key_b("parserReadingCode", i->parserReadingCode, o);
o = add_key_b("prologConsulting", i->prologConsulting, o); o = add_key_b("prologConsulting", i->prologConsulting, o);
o = add_key_s("culprit", i->culprit, o); o = add_key_s("culprit", i->culprit, o);
o = add_key_s("prologStack", i->prologStack, o);
if (i->errorMsgLen) { if (i->errorMsgLen) {
o = add_key_s("errorMsg", i->errorMsg, o); o = add_key_s("errorMsg", i->errorMsg, o);
o = add_key_i("errorMsgLen", i->errorMsgLen, o); o = add_key_i("errorMsgLen", i->errorMsgLen, o);
@ -317,7 +321,7 @@ void Yap_InitError__(const char *file, const char *function, int lineno,
if (fmt) { if (fmt) {
LOCAL_Error_Size = strlen(tmpbuf); LOCAL_Error_Size = strlen(tmpbuf);
LOCAL_ActiveError->errorMsg = malloc(LOCAL_Error_Size + 1); LOCAL_ActiveError->errorMsg = malloc(LOCAL_Error_Size + 1);
strcpy(LOCAL_ActiveError->errorMsg, tmpbuf); strcpy((char *)LOCAL_ActiveError->errorMsg, tmpbuf);
} else { } else {
LOCAL_Error_Size = 0; LOCAL_Error_Size = 0;
} }
@ -328,12 +332,13 @@ bool Yap_PrintWarning(Term twarning) {
PredEntry *pred = RepPredProp(PredPropByFunc( PredEntry *pred = RepPredProp(PredPropByFunc(
FunctorPrintMessage, PROLOG_MODULE)); // PROCEDURE_print_message2; FunctorPrintMessage, PROLOG_MODULE)); // PROCEDURE_print_message2;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " warning(%s)", __android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " warning(%s)",
Yap_TermToBuffer(twarning, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f)); Yap_TermToBuffer(twarning, Quote_illegal_f | Ignore_ops_f | Ignore_cyclics_f));
Term cmod = (CurrentModule == PROLOG_MODULE ? TermProlog : CurrentModule); Term cmod = (CurrentModule == PROLOG_MODULE ? TermProlog : CurrentModule);
bool rc; bool rc;
Term ts[2], err; Term ts[2], err;
if (LOCAL_PrologMode & InErrorMode && LOCAL_ActiveError && if (LOCAL_PrologMode & InErrorMode && LOCAL_ActiveError &&
LOCAL_ActiveError->errorClass != WARNING &&
(err = LOCAL_ActiveError->errorNo)) { (err = LOCAL_ActiveError->errorNo)) {
fprintf(stderr, "%% Warning %s while processing error: %s %s\n", fprintf(stderr, "%% Warning %s while processing error: %s %s\n",
Yap_TermToBuffer(twarning, Yap_TermToBuffer(twarning,
@ -343,9 +348,10 @@ bool Yap_PrintWarning(Term twarning) {
} }
LOCAL_PrologMode |= InErrorMode; LOCAL_PrologMode |= InErrorMode;
if (pred->OpcodeOfPred == UNDEF_OPCODE || pred->OpcodeOfPred == FAIL_OPCODE) { if (pred->OpcodeOfPred == UNDEF_OPCODE || pred->OpcodeOfPred == FAIL_OPCODE) {
fprintf(stderr, "warning message:\n"); fprintf(stderr, "%s:%ld/* d:%d warning */:\n",
Yap_DebugPlWrite(twarning); LOCAL_ActiveError->errorFile,
fprintf(stderr, "\n"); LOCAL_ActiveError->errorLine, 0 );
Yap_DebugPlWriteln(twarning);
LOCAL_DoingUndefp = false; LOCAL_DoingUndefp = false;
LOCAL_PrologMode &= ~InErrorMode; LOCAL_PrologMode &= ~InErrorMode;
CurrentModule = cmod; CurrentModule = cmod;
@ -423,9 +429,7 @@ int Yap_SWIHandleError(const char *s, ...) {
yap_error_number err = LOCAL_Error_TYPE; yap_error_number err = LOCAL_Error_TYPE;
char *serr; char *serr;
if (LOCAL_ErrorMessage) { if (s) {
serr = LOCAL_ErrorMessage;
} else {
serr = (char *)s; serr = (char *)s;
} }
switch (err) { switch (err) {
@ -524,6 +528,7 @@ static char tmpbuf[YAP_BUF_SIZE];
#define BEGIN_ERRORS() \ #define BEGIN_ERRORS() \
static Term mkerrort(yap_error_number e, Term culprit, Term info) { \ static Term mkerrort(yap_error_number e, Term culprit, Term info) { \
if (!e || !info) return TermNil; \
switch (e) { switch (e) {
#define E0(A, B) \ #define E0(A, B) \
@ -574,8 +579,11 @@ static char tmpbuf[YAP_BUF_SIZE];
#include "YapErrors.h" #include "YapErrors.h"
bool Yap_pushErrorContext(bool pass, yap_error_descriptor_t *new_error) { /// add a new error descriptor, either to the top of the stack,
/// or replacing the top;
bool Yap_pushErrorContext(bool link , yap_error_descriptor_t *new_error) {
memset(new_error, 0, sizeof(yap_error_descriptor_t)); memset(new_error, 0, sizeof(yap_error_descriptor_t));
if (link)
new_error->top_error = LOCAL_ActiveError; new_error->top_error = LOCAL_ActiveError;
LOCAL_ActiveError = new_error; LOCAL_ActiveError = new_error;
return true; return true;
@ -625,7 +633,7 @@ void Yap_ThrowError__(const char *file, const char *function, int lineno,
// fprintf(stderr, "warning: "); // fprintf(stderr, "warning: ");
Yap_Error__(true, file, function, lineno, type, where, tmpbuf); Yap_Error__(true, file, function, lineno, type, where, tmpbuf);
} else { } else {
Yap_Error__(true, file, function, lineno, type, where); Yap_Error__(true, file, function, lineno, type, where, NULL);
} }
if (LOCAL_RestartEnv && !LOCAL_delay) { if (LOCAL_RestartEnv && !LOCAL_delay) {
Yap_RestartYap(5); Yap_RestartYap(5);
@ -644,6 +652,16 @@ void Yap_ThrowExistingError(void) {
Yap_exit(5); Yap_exit(5);
} }
Term Yap_MkFullError(void)
{
yap_error_descriptor_t *i = Yap_local.ActiveError;
i->errorAsText = Yap_errorName( i->errorNo );
i->errorClass = Yap_errorClass( i-> errorNo );
i->classAsText = Yap_errorClassName(i->errorClass);
return mkerrort(i->errorNo, TermNil , MkSysError(i) );
}
bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file, bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file,
const char *function, int lineno, yap_error_number type, const char *function, int lineno, yap_error_number type,
Term where, const char *s) { Term where, const char *s) {
@ -655,9 +673,9 @@ bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file,
r->culprit = Yap_TermToBuffer( r->culprit = Yap_TermToBuffer(
where, Quote_illegal_f | Ignore_ops_f); where, Quote_illegal_f | Ignore_ops_f);
} }
if (LOCAL_consult_level > 0) { if (type != SYNTAX_ERROR && LOCAL_consult_level > 0) {
r->prologParserFile = Yap_ConsultingFile(PASS_REGS1)->StrOfAE; r->parserFile = Yap_ConsultingFile(PASS_REGS1)->StrOfAE;
r->prologParserLine = Yap_source_line_no(); r->parserLine = Yap_source_line_no();
} }
r->errorNo = type; r->errorNo = type;
r->errorAsText = Yap_errorName(type); r->errorAsText = Yap_errorName(type);
@ -666,9 +684,11 @@ bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file,
r->errorLine = lineno; r->errorLine = lineno;
r->errorFunction = function; r->errorFunction = function;
r->errorFile = file; r->errorFile = file;
r->prologConsulting = Yap_Consulting();
LOCAL_PrologMode |= InErrorMode; LOCAL_PrologMode |= InErrorMode;
Yap_ClearExs(); Yap_ClearExs();
// first, obtain current location // first, obtain current location
// sprintf(LOCAL_FileNameBuf, "%s:%d in C-function %s ", file, lineno, // sprintf(LOCAL_FileNameBuf, "%s:%d in C-function %s ", file, lineno,
// function); // function);
// tf = MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)); // tf = MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf));
@ -693,13 +713,11 @@ bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file,
} }
// fprintf(stderr, "warning: "); // fprintf(stderr, "warning: ");
if (s && s[0]) { if (s && s[0]) {
char *ns;
r->errorMsgLen = strlen(s) + 1; r->errorMsgLen = strlen(s) + 1;
r->errorMsg = malloc(r->errorMsgLen); ns = malloc(r->errorMsgLen);
strcpy(r->errorMsg, s); strcpy(ns, s);
} else if (LOCAL_ErrorMessage && LOCAL_ErrorMessage[0]) { r->errorMsg = ns;
r->errorMsgLen = strlen(LOCAL_ErrorMessage) + 1;
r->errorMsg = malloc(r->errorMsgLen);
strcpy(r->errorMsg, LOCAL_ErrorMessage);
} else { } else {
r->errorMsgLen = 0; r->errorMsgLen = 0;
r->errorMsg = 0; r->errorMsg = 0;
@ -845,7 +863,8 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function,
#ifdef DEBUG #ifdef DEBUG
// DumpActiveGoals( USES_REGS1 ); // DumpActiveGoals( USES_REGS1 );
#endif /* DEBUG */ #endif /* DEBUG */
if (LOCAL_ActiveError->errorNo!= SYNTAX_ERROR)
LOCAL_ActiveError->prologStack=Yap_dump_stack();
CalculateStackGap(PASS_REGS1); CalculateStackGap(PASS_REGS1);
#if DEBUG #if DEBUG
// DumpActiveGoals( PASS_REGS1 ); // DumpActiveGoals( PASS_REGS1 );
@ -1022,7 +1041,27 @@ static Int print_exception(USES_REGS1) {
static Int query_exception(USES_REGS1) { static Int query_exception(USES_REGS1) {
const char *query; const char *query = NULL;
Term t;
if (IsAtomTerm((t = Deref(ARG1))))
query = RepAtom(AtomOfTerm(t))->StrOfAE;
if (IsStringTerm(t))
query = StringOfTerm(t);
if (!IsAddressTerm(Deref(ARG2)))
return false;
yap_error_descriptor_t *y = AddressOfTerm(Deref(ARG2));
// if (IsVarTerm(t3)) {
Term rc = queryErr(query, y);
// Yap_DebugPlWriteln(rc);
return Yap_unify(ARG3, rc);
// } else {
// return setErr(query, y, t3);
// }
}
static Int set_exception(USES_REGS1) {
const char *query = NULL;
Term t; Term t;
if (IsAtomTerm((t = Deref(ARG1)))) if (IsAtomTerm((t = Deref(ARG1))))
@ -1034,15 +1073,14 @@ static Int query_exception(USES_REGS1) {
yap_error_descriptor_t *y = AddressOfTerm(Deref(ARG2)); yap_error_descriptor_t *y = AddressOfTerm(Deref(ARG2));
Term t3 = Deref(ARG3); Term t3 = Deref(ARG3);
if (IsVarTerm(t3)) { if (IsVarTerm(t3)) {
Term rc = queryErr(query, y); return false;
// Yap_DebugPlWriteln(rc);
return Yap_unify(ARG3, rc);
} else { } else {
return setErr(query, y, t3); return setErr(query, y, t3);
} }
} }
static Int drop_exception(USES_REGS1) { static Int drop_exception(USES_REGS1) {
yap_error_descriptor_t *t = AddressOfTerm(Deref(ARG1)); yap_error_descriptor_t *t = AddressOfTerm(Deref(ARG1));
free(t); free(t);
@ -1066,7 +1104,9 @@ static Int get_exception(USES_REGS1) {
(i->errorClass == EVENT || i->errorNo == SYNTAX_ERROR)) { (i->errorClass == EVENT || i->errorNo == SYNTAX_ERROR)) {
t = i->errorRawTerm; t = i->errorRawTerm;
} else if (i->culprit != NULL) { } else if (i->culprit != NULL) {
t = mkerrort(i->errorNo, Yap_BufferToTerm(i->culprit, TermNil), Term culprit = Yap_BufferToTerm(i->culprit, TermNil);
if (culprit == 0) culprit = TermNil;
t = mkerrort(i->errorNo,culprit ,
MkSysError(i)); MkSysError(i));
} else { } else {
t = mkerrort(i->errorNo, TermNil, MkSysError(i)); t = mkerrort(i->errorNo, TermNil, MkSysError(i));
@ -1251,6 +1291,7 @@ void Yap_InitErrorPreds(void) {
Yap_InitCPred("$reset_exception", 1, reset_exception, 0); Yap_InitCPred("$reset_exception", 1, reset_exception, 0);
Yap_InitCPred("$new_exception", 1, new_exception, 0); Yap_InitCPred("$new_exception", 1, new_exception, 0);
Yap_InitCPred("$get_exception", 1, get_exception, 0); Yap_InitCPred("$get_exception", 1, get_exception, 0);
Yap_InitCPred("$set_exception", 3, set_exception, 0);
Yap_InitCPred("$read_exception", 2, read_exception, 0); Yap_InitCPred("$read_exception", 2, read_exception, 0);
Yap_InitCPred("$query_exception", 3, query_exception, 0); Yap_InitCPred("$query_exception", 3, query_exception, 0);
Yap_InitCPred("$drop_exception", 1, drop_exception, 0); Yap_InitCPred("$drop_exception", 1, drop_exception, 0);

View File

@ -327,7 +327,7 @@ inline static bool do_execute(Term t, Term mod USES_REGS) {
/* I cannot use the standard macro here because /* I cannot use the standard macro here because
otherwise I would dereference the argument and otherwise I would dereference the argument and
might skip a svar */ might skip a svar */
if (pen->PredFlags & (MetaPredFlag | UndefPredFlag)) { if (pen->PredFlags & (MetaPredFlag | UndefPredFlag | SpiedPredFlag)) {
return CallMetaCall(t0, mod0 PASS_REGS); return CallMetaCall(t0, mod0 PASS_REGS);
} }
pt = RepAppl(t) + 1; pt = RepAppl(t) + 1;

View File

@ -25,10 +25,12 @@
*/ */
/** /**
@{
@defgroup YAPFlags_Impl C-code to handle Prolog flags. @defgroup YAPFlags C-code to handle Prolog flags.
@ingroup YAPFlags @ingroup YAPFlags
@{
@brief Low-level code to support flags. @brief Low-level code to support flags.
Prolog Flags can be: Prolog Flags can be:
@ -1208,6 +1210,7 @@ Term Yap_UnknownFlag(Term mod) {
Term getYapFlag(Term tflag) { Term getYapFlag(Term tflag) {
FlagEntry *fv; FlagEntry *fv;
flag_term *tarr; flag_term *tarr;
tflag = Deref(tflag);
if (IsVarTerm(tflag)) { if (IsVarTerm(tflag)) {
Yap_Error(INSTANTIATION_ERROR, tflag, "yap_flag/2"); Yap_Error(INSTANTIATION_ERROR, tflag, "yap_flag/2");
return (FALSE); return (FALSE);
@ -1234,6 +1237,10 @@ Term getYapFlag(Term tflag) {
Yap_Error(TYPE_ERROR_ATOM, tflag, "yap_flag/2"); Yap_Error(TYPE_ERROR_ATOM, tflag, "yap_flag/2");
return (FALSE); return (FALSE);
} }
if (tflag == TermSilent)
{
Yap_DebugPlWriteln(TermSilent);
}
fv = GetFlagProp(AtomOfTerm(tflag)); fv = GetFlagProp(AtomOfTerm(tflag));
if (!fv) { if (!fv) {
Term fl = GLOBAL_Flags[USER_FLAGS_FLAG].at; Term fl = GLOBAL_Flags[USER_FLAGS_FLAG].at;
@ -1792,10 +1799,6 @@ void Yap_InitFlags(bool bootstrap) {
Yap_InitCPredBack("current_prolog_flag", 2, 1, current_prolog_flag, Yap_InitCPredBack("current_prolog_flag", 2, 1, current_prolog_flag,
cont_yap_flag, 0); cont_yap_flag, 0);
TR = tr0; TR = tr0;
/** @pred prolog_flag( ?Flag, - Value)
Obtain the value for a YAP Prolog flag, same as current_prolog_flag/2.
*/
Yap_InitCPredBack("prolog_flag", 3, 1, prolog_flag, cont_yap_flag, Yap_InitCPredBack("prolog_flag", 3, 1, prolog_flag, cont_yap_flag,
0); 0);
Yap_InitCPredBack("yap_flag", 3, 1, yap_flag, cont_yap_flag, 0); Yap_InitCPredBack("yap_flag", 3, 1, yap_flag, cont_yap_flag, 0);

View File

@ -623,6 +623,10 @@
BOp(undef_p, e); BOp(undef_p, e);
/* save S for module name */ /* save S for module name */
if (LOCAL_DoingUndefp) {
PREG=FAILCODE;
JMPNext();
}
LOCAL_DoingUndefp = true; LOCAL_DoingUndefp = true;
saveregs(); saveregs();
undef_goal(PASS_REGS1); undef_goal(PASS_REGS1);

View File

@ -35,7 +35,7 @@
* Revision 1.3 2006/01/17 14:10:40 vsc * Revision 1.3 2006/01/17 14:10:40 vsc
* YENV may be an HW register (breaks some tabling code) * YENV may be an HW register (breaks some tabling code)
* All YAAM instructions are now brackedted, so Op introduced an { and EndOp introduces an }. This is because Ricardo assumes that. * All YAAM instructions are now brackedted, so Op introduced an { and EndOp introduces an }. This is because Ricardo assumes that.
* Fix attvars when COROUTING is undefined. * Fix attvars
* *
* Revision 1.2 2005/12/23 00:20:13 vsc * Revision 1.2 2005/12/23 00:20:13 vsc
* updates to gprof * updates to gprof
@ -47,39 +47,39 @@
* * * *
*************************************************************************/ *************************************************************************/
/// @file gprof.c
/** @defgroup Tick_Profiler Tick Profiler /** @addtogroup Tick_Profiler
@ingroup Profiling * @ingroup Profiling@{
@{ *
* The tick profiler works by interrupting the Prolog code every so often
The tick profiler works by interrupting the Prolog code every so often * and checking at each point the code was. The pro/filer must be able to
and checking at each point the code was. The profiler must be able to * retrace the state of the abstract machine at every moment. The major
retrace the state of the abstract machine at every moment. The major * advantage of this approach is that it gives the actual amount of time
advantage of this approach is that it gives the actual amount of time * being spent per procedure, or whether garbage collection dominates
being spent per procedure, or whether garbage collection dominates * execution time. The major drawback is that tracking down the state of
execution time. The major drawback is that tracking down the state of * the abstract machine may take significant time, and in the worst case
the abstract machine may take significant time, and in the worst case * may slow down the whole execution.
may slow down the whole execution. *
* The following procedures are available:
The following procedures are available: *
* + profinit/0
+ profinit * Initialise the data-structures for the profiler. Unnecessary for
* dynamic profiler.
*
Initialise the data-structures for the profiler. Unnecessary for * + profon/0
dynamic profiler. * Start profiling.
*
+ profon * + profoff/0
* Stop profiling.
*
Start profiling. * + profoff/0
* Stop profiling.
+ profoff *
* + showprofres/0 and showprofres/1
* Stop tick counts per predicate.
Stop profiling. *
*
*/ */
#ifdef SCCS #ifdef SCCS
@ -728,20 +728,18 @@ return GLOBAL_DIRNAME;
char *profile_names(int); char *profile_names(int);
char *profile_names(int k) { char *profile_names(int k) {
static char *FNAME=NULL; char *FNAME=NULL;
int size=200; int size=200;
if (GLOBAL_DIRNAME==NULL) set_profile_dir(NULL); if (GLOBAL_DIRNAME==NULL) set_profile_dir(NULL);
size=strlen(GLOBAL_DIRNAME)+40; size=strlen(GLOBAL_DIRNAME)+40;
if (FNAME!=NULL) free(FNAME);
FNAME=malloc(size); FNAME=malloc(size);
if (FNAME==NULL) { printf("Profiler Out of Mem\n"); exit(1); } if (FNAME==NULL) { printf("Profiler Out of Mem\n"); exit(1); }
strcpy(FNAME,GLOBAL_DIRNAME);
if (k==PROFILING_FILE) { if (k==PROFILING_FILE) {
sprintf(FNAME,"%s/PROFILING_%d",FNAME,getpid()); sprintf(FNAME,"%s/PROFILING_%d",GLOBAL_DIRNAME,getpid());
} else { } else {
sprintf(FNAME,"%s/PROFPREDS_%d",FNAME,getpid()); sprintf(FNAME,"%s/PROFPREDS_%d",GLOBAL_DIRNAME,getpid());
} }
// printf("%s\n",FNAME); // printf("%s\n",FNAME);
@ -841,7 +839,7 @@ static void RemoveCode(CODEADDR clau)
} }
} }
static int static Int
showprofres( USES_REGS1 ) { showprofres( USES_REGS1 ) {
buf_ptr buf; buf_ptr buf;

View File

@ -60,12 +60,12 @@ static void syntax_msg(const char *msg, ...) {
va_list ap; va_list ap;
if (!LOCAL_ErrorMessage || if (!LOCAL_ErrorMessage ||
(LOCAL_Error_TYPE == SYNTAX_ERROR && (LOCAL_Error_TYPE == SYNTAX_ERROR &&
LOCAL_tokptr->TokPos < LOCAL_ActiveError->prologParserPos)) { LOCAL_tokptr->TokPos < LOCAL_ActiveError->parserPos)) {
if (!LOCAL_ErrorMessage) { if (!LOCAL_ErrorMessage) {
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE + 1); LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE + 1);
} }
LOCAL_ActiveError->prologParserLine = LOCAL_tokptr->TokLine; LOCAL_ActiveError->parserLine = LOCAL_tokptr->TokLine;
LOCAL_ActiveError->prologParserPos = LOCAL_tokptr->TokPos; LOCAL_ActiveError->parserPos = LOCAL_tokptr->TokPos;
va_start(ap, msg); va_start(ap, msg);
vsnprintf(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE, msg, ap); vsnprintf(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE, msg, ap);
va_end(ap); va_end(ap);
@ -911,12 +911,17 @@ Term Yap_Parse(UInt prio, encoding_t enc, Term cmod) {
CACHE_REGS CACHE_REGS
// ensure that if we throw an exception // ensure that if we throw an exception
// t will be 0. // t will be 0.
LOCAL_ActiveError->errorMsg=NULL;
LOCAL_ActiveError->errorMsgLen=0;
Volatile Term t = 0; Volatile Term t = 0;
JMPBUFF FailBuff; JMPBUFF FailBuff;
yhandle_t sls = Yap_StartSlots(); yhandle_t sls = Yap_StartSlots();
LOCAL_ErrorMessage = NULL;
LOCAL_toktide = LOCAL_tokptr; LOCAL_toktide = LOCAL_tokptr;
if (!sigsetjmp(FailBuff.JmpBuff, 0)) { if (!sigsetjmp(FailBuff.JmpBuff, 0)) {
LOCAL_ActiveError->errorMsg=NULL;
LOCAL_ActiveError->errorMsgLen=0;
t = ParseTerm(prio, &FailBuff, enc, cmod PASS_REGS); t = ParseTerm(prio, &FailBuff, enc, cmod PASS_REGS);
#if DEBUG #if DEBUG
@ -936,9 +941,13 @@ Term Yap_Parse(UInt prio, encoding_t enc, Term cmod) {
if (LOCAL_tokptr != NULL && LOCAL_tokptr->Tok != Ord(eot_tok)) { if (LOCAL_tokptr != NULL && LOCAL_tokptr->Tok != Ord(eot_tok)) {
LOCAL_Error_TYPE = SYNTAX_ERROR; LOCAL_Error_TYPE = SYNTAX_ERROR;
if (LOCAL_tokptr->TokNext) { if (LOCAL_tokptr->TokNext) {
LOCAL_ErrorMessage = "bracket or operator expected."; size_t sz = strlen("bracket or operator expected.");
LOCAL_ErrorMessage =malloc(sz+1);
strncpy(LOCAL_ErrorMessage, "bracket or operator expected.", sz );
} else { } else {
LOCAL_ErrorMessage = "term must end with . or EOF."; size_t sz = strlen("term must end with . or EOF.");
LOCAL_ErrorMessage =malloc(sz+1);
strncpy(LOCAL_ErrorMessage,"term must end with . or EOF.", sz );
} }
t = 0; t = 0;
} }

View File

@ -1469,6 +1469,7 @@ int Yap_SavedInfo(const char *FileName, CELL *ATrail,
mode = OpenRestore(FileName, &MyState, &MyTrail, &MyStack, &MyHeap, mode = OpenRestore(FileName, &MyState, &MyTrail, &MyStack, &MyHeap,
NULL); NULL);
if (mode == FAIL_RESTORE) { if (mode == FAIL_RESTORE) {
fprintf(stderr, "restore failed to open %s as a valid state\n", FileName);
return -1; return -1;
} }
close_file(); close_file();

View File

@ -1340,7 +1340,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
TokEntry *t, *l, *p; TokEntry *t, *l, *p;
enum TokenKinds kind; enum TokenKinds kind;
int solo_flag = TRUE; int solo_flag = TRUE;
int32_t ch, och; int32_t ch, och = ' ';
struct qq_struct_t *cur_qq = NULL; struct qq_struct_t *cur_qq = NULL;
int sign = 1; int sign = 1;
@ -1423,12 +1423,13 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
case UC: case UC:
case UL: case UL:
case LC: { case LC:
int32_t och = ch; och = ch;
ch = getchr(st); ch = getchr(st);
size_t sz = 512;
TokImage = Malloc(sz PASS_REGS);
scan_name: scan_name:
{
size_t sz = 1024;
TokImage = Malloc(sz PASS_REGS);
charp = (unsigned char *)TokImage; charp = (unsigned char *)TokImage;
isvar = (chtype(och) != LC); isvar = (chtype(och) != LC);
add_ch_to_buff(och); add_ch_to_buff(och);
@ -1514,7 +1515,6 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
case 'e': case 'e':
case 'E': case 'E':
och = cherr; och = cherr;
TokImage = Malloc(1024 PASS_REGS);
goto scan_name; goto scan_name;
break; break;
case '=': case '=':
@ -1981,6 +1981,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
return l; return l;
default: { default: {
kind = Error_tok;
char err[1024]; char err[1024];
snprintf(err, 1023, "\n++++ token: unrecognised char %c (%d), type %c\n", snprintf(err, 1023, "\n++++ token: unrecognised char %c (%d), type %c\n",
ch, ch, chtype(ch)); ch, ch, chtype(ch));

224
C/stack.c
View File

@ -105,6 +105,8 @@ restart:
return NULL; return NULL;
} }
extern char * Yap_output_bug_location(yamop *yap_pc, int where_from, int psize);
static PredEntry *PredForChoicePt(yamop *p_code, op_numbers *opn) { static PredEntry *PredForChoicePt(yamop *p_code, op_numbers *opn) {
while (TRUE) { while (TRUE) {
op_numbers opnum; op_numbers opnum;
@ -885,7 +887,7 @@ static PredEntry *ClauseInfoForCode(yamop *codeptr, void **startp,
if (codeptr >= COMMA_CODE && codeptr < FAILCODE) { if (codeptr >= COMMA_CODE && codeptr < FAILCODE) {
pp = RepPredProp(Yap_GetPredPropByFunc(FunctorComma, CurrentModule)); pp = RepPredProp(Yap_GetPredPropByFunc(FunctorComma, CurrentModule));
*startp = (CODEADDR)COMMA_CODE; *startp = (CODEADDR)COMMA_CODE;
*endp = (CODEADDR)(FAILCODE - 1); *endp = (CODEADDR)(FAILCODE);
return pp; return pp;
} }
pc = codeptr; pc = codeptr;
@ -1124,7 +1126,7 @@ static Term clause_info(yamop *codeptr, PredEntry *pp) {
yap_error_descriptor_t *set_clause_info(yap_error_descriptor_t *t, yap_error_descriptor_t *set_clause_info(yap_error_descriptor_t *t,
yamop *codeptr, PredEntry *pp) { yamop *codeptr, PredEntry *pp) {
CACHE_REGS CACHE_REGS
Term ts[2];
void *begin; void *begin;
if (pp->ArityOfPE == 0) { if (pp->ArityOfPE == 0) {
t->prologPredName = AtomName((Atom)pp->FunctorOfPred); t->prologPredName = AtomName((Atom)pp->FunctorOfPred);
@ -1138,36 +1140,18 @@ yap_error_descriptor_t *set_clause_info(yap_error_descriptor_t *t,
: "prolog"); : "prolog");
t->prologPredFile = RepAtom(pp->src.OwnerFile)->StrOfAE; t->prologPredFile = RepAtom(pp->src.OwnerFile)->StrOfAE;
if (codeptr->opc == UNDEF_OPCODE) { if (codeptr->opc == UNDEF_OPCODE) {
t->prologPredFirstLine = 0;
t->prologPredLine = 0; t->prologPredLine = 0;
t->prologPredLastLine = 0;
return t; return t;
} else if (pp->cs.p_code.NOfClauses) { } else if (pp->cs.p_code.NOfClauses) {
if ((t->prologPredCl = find_code_in_clause(pp, codeptr, &begin, NULL)) <= if ((t->prologPredLine = find_code_in_clause(pp, codeptr, &begin, NULL)) <=
0) { 0) {
t->prologPredLine = 0; t->prologPredLine = 0;
} else { } else {
t->prologPredLine = IntegerOfTerm(clause_loc(begin, pp)); t->prologPredLine = IntegerOfTerm(clause_loc(begin, pp));
} }
if (pp->PredFlags & LogUpdatePredFlag) {
t->prologPredFirstLine =
clause_loc(ClauseCodeToLogUpdClause(pp->cs.p_code.FirstClause), pp);
t->prologPredLastLine =
clause_loc(ClauseCodeToLogUpdClause(pp->cs.p_code.LastClause), pp);
} else {
t->prologPredFirstLine = IntegerOfTerm(
ts[0] = clause_loc(
ClauseCodeToStaticClause(pp->cs.p_code.FirstClause), pp));
t->prologPredLastLine = IntegerOfTerm(
ts[1] = clause_loc(ClauseCodeToStaticClause(pp->cs.p_code.LastClause),
pp));
}
return t; return t;
} else { } else {
t->prologPredFirstLine = 0;
t->prologPredLine = t->errorLine; t->prologPredLine = t->errorLine;
t->prologPredLastLine = 0;
t->prologPredFile = t->errorFile; t->prologPredFile = t->errorFile;
return t; return t;
} }
@ -1720,8 +1704,6 @@ parent_pred(USES_REGS1) {
Yap_unify(ARG2, MkAtomTerm(at)) && Yap_unify(ARG3, MkIntTerm(arity)); Yap_unify(ARG2, MkAtomTerm(at)) && Yap_unify(ARG3, MkIntTerm(arity));
} }
void Yap_dump_stack(void);
void DumpActiveGoals(CACHE_TYPE1); void DumpActiveGoals(CACHE_TYPE1);
static int hidden(Atom); static int hidden(Atom);
@ -1763,6 +1745,7 @@ static int legal_env(CELL *ep USES_REGS) {
return (TRUE); return (TRUE);
} }
#if 0
static bool handled_exception(USES_REGS1) { static bool handled_exception(USES_REGS1) {
yamop *pos = NEXTOP(PredDollarCatch->cs.p_code.TrueCodeOfPred, l); yamop *pos = NEXTOP(PredDollarCatch->cs.p_code.TrueCodeOfPred, l);
bool found_handler = false; bool found_handler = false;
@ -1785,173 +1768,193 @@ static bool handled_exception(USES_REGS1) {
return !found_handler; return !found_handler;
} }
void Yap_dump_stack(void) { #endif
#define ADDBUF( CMD ) { \
while (true) { \
size_t sz = CMD; \
if (sz < lbufsz-256) { \
lbuf += sz; \
lbufsz -= sz; \
break; \
} \
char *nbuf = Realloc(buf, bufsize += 1024); \
lbuf = nbuf + (lbuf-buf); \
buf = nbuf; \
lbufsz += 1024; \
} \
}
const char *Yap_dump_stack(void) {
CACHE_REGS CACHE_REGS
choiceptr b_ptr = B; choiceptr b_ptr = B;
CELL *env_ptr = ENV; CELL *env_ptr = ENV;
char tp[256]; char *tp;
yamop *ipc = CP; yamop *ipc = CP;
int max_count = 200; int max_count = 200;
int lvl = push_text_stack();
char *buf = Malloc(4096), *lbuf = buf;
size_t bufsize = 4096, lbufsz = bufsize-256;
/* check if handled */ /* check if handled */
if (handled_exception(PASS_REGS1)) // if (handled_exception(PASS_REGS1))
return; // return;
#if DEBU #if DEBUG
fprintf(stderr, "%% YAP regs: P=%p, CP=%p, ASP=%p, H=%p, TR=%p, HeapTop=%p\n", ADDBUF(snprintf(lbuf, lbufsz ,
P, CP, ASP, HR, TR, HeapTop); "%% YAP regs: P=%p, CP=%p, ASP=%p, H=%p, TR=%p, HeapTop=%p~n", P,
#endif CP, ASP, HR, TR, HeapTop));
fprintf(stderr, "%% \n%% =====================================\n%%\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% =====================================~n%%~n"));
fprintf(stderr, "%% \n%% YAP Status:\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% YAP Status:~n"));
fprintf(stderr, "%% \n%% -------------------------------------\n%%\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% -------------------------------------~n%%~n"));
yap_error_number errnbr = LOCAL_Error_TYPE; yap_error_number errnbr = LOCAL_Error_TYPE;
yap_error_class_number classno = Yap_errorClass(errnbr); yap_error_class_number classno = Yap_errorClass(errnbr);
fprintf(stderr, "%% Error STATUS: %s/%s\n\n", Yap_errorName(errnbr), ADDBUF(snprintf(lbuf, lbufsz , "%% Error STATUS: %s/%s~n~n", Yap_errorName(errnbr),
Yap_errorClassName(classno)); Yap_errorClassName(classno)));
fprintf(stderr, "%% Execution mode\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Execution mode~n"));
if (LOCAL_PrologMode & BootMode) if (LOCAL_PrologMode & BootMode)
fprintf(stderr, "%% Bootstrap\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Bootstrap~n"));
if (LOCAL_PrologMode & UserMode) if (LOCAL_PrologMode & UserMode)
fprintf(stderr, "%% User Prolo\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% User Prolo~n"));
if (LOCAL_PrologMode & CritMode) if (LOCAL_PrologMode & CritMode)
fprintf(stderr, "%% Exclusive Access Mode\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Exclusive Access Mode~n"));
if (LOCAL_PrologMode & AbortMode) if (LOCAL_PrologMode & AbortMode)
fprintf(stderr, "%% Abort\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Abort~n"));
if (LOCAL_PrologMode & InterruptMode) if (LOCAL_PrologMode & InterruptMode)
fprintf(stderr, "%% Interrupt\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Interrupt~n"));
if (LOCAL_PrologMode & InErrorMode) if (LOCAL_PrologMode & InErrorMode)
fprintf(stderr, "%% Error\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Error~n"));
if (LOCAL_PrologMode & ConsoleGetcMode) if (LOCAL_PrologMode & ConsoleGetcMode)
fprintf(stderr, "%% Prompt Console\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Prompt Console~n"));
if (LOCAL_PrologMode & ExtendStackMode) if (LOCAL_PrologMode & ExtendStackMode)
fprintf(stderr, "%% Stack expansion \n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Stack expansion ~n"));
if (LOCAL_PrologMode & GrowHeapMode) if (LOCAL_PrologMode & GrowHeapMode)
fprintf(stderr, "%% Data Base Expansion\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Data Base Expansion~n"));
if (LOCAL_PrologMode & GrowStackMode) if (LOCAL_PrologMode & GrowStackMode)
fprintf(stderr, "%% User Prolog\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% User Prolog~n"));
if (LOCAL_PrologMode & GCMode) if (LOCAL_PrologMode & GCMode)
fprintf(stderr, "%% Garbage Collection\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Garbage Collection~n"));
if (LOCAL_PrologMode & ErrorHandlingMode) if (LOCAL_PrologMode & ErrorHandlingMode)
fprintf(stderr, "%% Error handler\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Error handler~n"));
if (LOCAL_PrologMode & CCallMode) if (LOCAL_PrologMode & CCallMode)
fprintf(stderr, "%% System Foreign Code\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% System Foreign Code~n"));
if (LOCAL_PrologMode & UnifyMode) if (LOCAL_PrologMode & UnifyMode)
fprintf(stderr, "%% Off-line Foreign Code\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Off-line Foreign Code~n"));
if (LOCAL_PrologMode & UserCCallMode) if (LOCAL_PrologMode & UserCCallMode)
fprintf(stderr, "%% User Foreig C\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% User Foreig C~n"));
if (LOCAL_PrologMode & MallocMode) if (LOCAL_PrologMode & MallocMode)
fprintf(stderr, "%% Heap Allocaror\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Heap Allocaror~n"));
if (LOCAL_PrologMode & SystemMode) if (LOCAL_PrologMode & SystemMode)
fprintf(stderr, "%% Prolog Internals\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Prolog Internals~n"));
if (LOCAL_PrologMode & AsyncIntMode) if (LOCAL_PrologMode & AsyncIntMode)
fprintf(stderr, "%% Async Interruot mode\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Async Interruot mode~n"));
if (LOCAL_PrologMode & InReadlineMode) if (LOCAL_PrologMode & InReadlineMode)
fprintf(stderr, "%% Readline Console\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Readline Console~n"));
if (LOCAL_PrologMode & TopGoalMode) if (LOCAL_PrologMode & TopGoalMode)
fprintf(stderr, "%% Creating new query\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% Creating new query~n"));
fprintf(stderr, "%% \n%% -------------------------------------\n%%\n"); #endif
fprintf(stderr, "%% \n%% YAP Program:\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% -------------------------------------~n%%~n"));
fprintf(stderr, "%% \n%% -------------------------------------\n%%\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% YAP Program:~n"));
fprintf(stderr, "%% Program Position: %s\n\n", Yap_errorName(errno) ); ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% -------------------------------------~n%%~n"));
fprintf(stderr, "%% PC: %s\n", (char *)HR); ADDBUF(snprintf(lbuf, lbufsz , "%% Program Position: %s~n~n", Yap_errorName(errno)));
ADDBUF(snprintf(lbuf, lbufsz , "%% PC: %s~n", (char *)HR));
Yap_output_bug_location(CP, FIND_PRED_FROM_ANYWHERE, 256); Yap_output_bug_location(CP, FIND_PRED_FROM_ANYWHERE, 256);
fprintf(stderr, "%% Continuation: %s\n", (char *)HR); ADDBUF(snprintf(lbuf, lbufsz , "%% Continuation: %s~n", (char *)HR));
Yap_output_bug_location(B->cp_ap, FIND_PRED_FROM_ANYWHERE, 256); Yap_output_bug_location(B->cp_ap, FIND_PRED_FROM_ANYWHERE, 256);
fprintf(stderr, "%% Alternative: %s\n", (char *)HR); ADDBUF(snprintf(lbuf, lbufsz , "%% Alternative: %s~n", (char *)HR));
fprintf(stderr, "%% \n%% -------------------------------------\n%%\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% -------------------------------------~n%%~n"));
fprintf(stderr, "%% \n%% YAP Stack Usage:\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% YAP Stack Usage:~n"));
fprintf(stderr, "%% \n%% -------------------------------------\n%%\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% -------------------------------------~n%%~n"));
if (HR > ASP || HR > LCL0) { if (HR > ASP || HR > LCL0) {
fprintf(stderr, "%% YAP ERROR: Global Collided against Local (%p--%p)\n", ADDBUF(snprintf(lbuf, lbufsz , "%% YAP ERROR: Global Collided against Local (%p--%p)~n",
HR, ASP); HR, ASP));
} else if (HeapTop > (ADDR)LOCAL_GlobalBase) { } else if (HeapTop > (ADDR)LOCAL_GlobalBase) {
fprintf(stderr, ADDBUF(snprintf(lbuf, lbufsz ,
"%% YAP ERROR: Code Space Collided against Global (%p--%p)\n", "%% YAP ERROR: Code Space Collided against Global (%p--%p)~n",
HeapTop, LOCAL_GlobalBase); HeapTop, LOCAL_GlobalBase));
} else { } else {
#if !USE_SYSTEM_MALLOC #if !USE_SYSTEM_MALLOC
fprintf(stderr, "%%ldKB of Code Space (%p--%p)\n", ADDBUF(snprintf(lbuf, lbufsz , "%%ldKB of Code Space (%p--%p)~n",
(long int)((CELL)HeapTop - (CELL)Yap_HeapBase) / 1024, Yap_HeapBase, (long int)((CELL)HeapTop - (CELL)Yap_HeapBase) / 1024, Yap_HeapBase,
HeapTop); HeapTop));
#if USE_DL_MALLOC #if USE_DL_MALLOC
if (Yap_NOfMemoryHoles) { if (Yap_NOfMemoryHoles) {
UInt i; UInt i;
for (i = 0; i < Yap_NOfMemoryHoles; i++) for (i = 0; i < Yap_NOfMemoryHoles; i++)
fprintf(stderr, " Current hole: %p--%p\n", Yap_MemoryHoles[i].start, ADDBUF(snprintf(lbuf, lbufsz , " Current hole: %p--%p~n", Yap_MemoryHoles[i].start,
Yap_MemoryHoles[i].end); Yap_MemoryHoles[i].end));
} }
#endif #endif
#endif #endif
fprintf(stderr, "%% %luKB of Global Stack (%p--%p)\n", ADDBUF(snprintf(lbuf, lbufsz , "%% %luKB of Global Stack (%p--%p)~n",
(unsigned long int)(sizeof(CELL) * (HR - H0)) / 1024, H0, HR); (unsigned long int)(sizeof(CELL) * (HR - H0)) / 1024, H0, HR));
fprintf(stderr, "%% %luKB of Local Stack (%p--%p)\n", ADDBUF(snprintf(lbuf, lbufsz , "%% %luKB of Local Stack (%p--%p)~n",
(unsigned long int)(sizeof(CELL) * (LCL0 - ASP)) / 1024, ASP, LCL0); (unsigned long int)(sizeof(CELL) * (LCL0 - ASP)) / 1024, ASP, LCL0));
fprintf(stderr, "%% %luKB of Trail (%p--%p)\n", ADDBUF(snprintf(lbuf, lbufsz , "%% %luKB of Trail (%p--%p)~n",
(unsigned long int)((ADDR)TR - LOCAL_TrailBase) / 1024, (unsigned long int)((ADDR)TR - LOCAL_TrailBase) / 1024,
LOCAL_TrailBase, TR); LOCAL_TrailBase, TR));
fprintf(stderr, "%% Performed %ld garbage collections\n", ADDBUF(snprintf(lbuf, lbufsz , "%% Performed %ld garbage collections~n",
(unsigned long int)LOCAL_GcCalls); (unsigned long int)LOCAL_GcCalls));
#if LOW_LEVEL_TRACER #if LOW_LEVEL_TRACER
{ {
extern long long vsc_count; extern long long vsc_count;
if (vsc_count) { if (vsc_count) {
#if _WIN32 #if _WIN32
fprintf(stderr, "Trace Counter at %I64d\n", vsc_count); ADDBUF(snprintf(lbuf, lbufsz , "Trace Counter at %I64d~n", vsc_count));
#else #else
fprintf(stderr, "Trace Counter at %lld\n", vsc_count); ADDBUF(snprintf(lbuf, lbufsz , "Trace Counter at %lld~n", vsc_count));
#endif #endif
} }
} }
#endif #endif
fprintf(stderr, "%% \n%% -------------------------------------\n%%\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% -------------------------------------~n%%~n"));
fprintf(stderr, "%% \n%% YAP Stack:\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% YAP Stack:~n"));
fprintf(stderr, "%% \n%% -------------------------------------\n%%\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% -------------------------------------~n%%~n"));
fprintf(stderr, "%% All Active Calls and\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% All Active Calls and~n"));
fprintf(stderr, "%% Goals With Alternatives Open (Global In " ADDBUF(snprintf(lbuf, lbufsz , "%% Goals With Alternatives Open (Global In "
"Use--Local In Use)\n%%\n"); "Use--Local In Use)~n%%~n"));
while (b_ptr != NULL) { while (b_ptr != NULL) {
while (env_ptr && env_ptr <= (CELL *)b_ptr) { while (env_ptr && env_ptr <= (CELL *)b_ptr) {
Yap_output_bug_location(ipc, FIND_PRED_FROM_ENV, 256); tp = Yap_output_bug_location(ipc, FIND_PRED_FROM_ENV, 256);
if (env_ptr == (CELL *)b_ptr && (choiceptr)env_ptr[E_CB] > b_ptr) { if (env_ptr == (CELL *)b_ptr && (choiceptr)env_ptr[E_CB] > b_ptr) {
b_ptr = b_ptr->cp_b; b_ptr = b_ptr->cp_b;
fprintf(stderr, "%% %s\n", tp); ADDBUF(snprintf(lbuf, lbufsz , "%% %s~n", tp));
} else { } else {
fprintf(stderr, "%% %s\n", tp); ADDBUF(snprintf(lbuf, lbufsz , "%% %s~n", tp));
} }
if (!max_count--) { if (!max_count--) {
fprintf(stderr, "%% .....\n"); ADDBUF(snprintf(lbuf, lbufsz , "%% .....~n"));
return; return pop_output_text_stack(lvl, buf);
} }
ipc = (yamop *)(env_ptr[E_CP]); ipc = (yamop *)(env_ptr[E_CP]);
env_ptr = (CELL *)(env_ptr[E_E]); env_ptr = (CELL *)(env_ptr[E_E]);
} }
if (b_ptr) { if (b_ptr) {
if (!max_count--) { if (!max_count--) {
fprintf(stderr, "// .....\n"); ADDBUF(snprintf(lbuf, lbufsz , "// .....~n"));
return; return pop_output_text_stack(lvl, buf);
} }
if (b_ptr->cp_ap && /* tabling */ if (b_ptr->cp_ap && /* tabling */
b_ptr->cp_ap->opc != Yap_opcode(_or_else) && b_ptr->cp_ap->opc != Yap_opcode(_or_else) &&
b_ptr->cp_ap->opc != Yap_opcode(_or_last) && b_ptr->cp_ap->opc != Yap_opcode(_or_last) &&
b_ptr->cp_ap->opc != Yap_opcode(_Nstop)) { b_ptr->cp_ap->opc != Yap_opcode(_Nstop)) {
/* we can safely ignore ; because there is always an upper env */ /* we can safely ignore ; because there is always an upper env */
Yap_output_bug_location(b_ptr->cp_ap, FIND_PRED_FROM_CP, 256); tp = Yap_output_bug_location(b_ptr->cp_ap, FIND_PRED_FROM_CP, 256);
fprintf(stderr, "%% %s (%luKB--%luKB)\n", tp, ADDBUF(snprintf(lbuf, lbufsz , "%% %s (%luKB--%luKB)~n", tp,
(unsigned long int)((b_ptr->cp_h - H0) * sizeof(CELL) / 1024), (unsigned long int)((b_ptr->cp_h - H0) * sizeof(CELL) / 1024),
(unsigned long int)((ADDR)LCL0 - (ADDR)b_ptr) / 1024); (unsigned long int)((ADDR)LCL0 - (ADDR)b_ptr) / 1024));
} }
b_ptr = b_ptr->cp_b; b_ptr = b_ptr->cp_b;
} }
} }
} }
return pop_output_text_stack(lvl, buf);
} }
void DumpActiveGoals(USES_REGS1) { void DumpActiveGoals(USES_REGS1) {
/* try to dump active goals */ /* try to dump active goals */
CELL *ep = YENV; /* and current environment */ CELL *ep = YENV; /* and current environment */
@ -2086,33 +2089,34 @@ void DumpActiveGoals(USES_REGS1) {
} }
} }
/** /**
* Used for debugging. * Used for debugging.
* *
*/ */
void Yap_output_bug_location(yamop *yap_pc, int where_from, int psize) { char * Yap_output_bug_location(yamop *yap_pc, int where_from, int psize) {
Atom pred_name; Atom pred_name;
UInt pred_arity; UInt pred_arity;
Term pred_module; Term pred_module;
Int cl; Int cl;
char *o = Malloc(256);
if ((cl = Yap_PredForCode(yap_pc, where_from, &pred_name, &pred_arity, if ((cl = Yap_PredForCode(yap_pc, where_from, &pred_name, &pred_arity,
&pred_module)) == 0) { &pred_module)) == 0) {
/* system predicate */ /* system predicate */
fprintf(stderr, "%% %s", "meta-call"); snprintf(o, 255, "%% %s", "meta-call");
} else if (pred_module == 0) { } else if (pred_module == 0) {
fprintf(stderr, "in prolog:%s/%lu", RepAtom(pred_name)->StrOfAE, snprintf(o, 255, "in prolog:%s/%lu", RepAtom(pred_name)->StrOfAE,
(unsigned long int)pred_arity); (unsigned long int)pred_arity);
} else if (cl < 0) { } else if (cl < 0) {
fprintf(stderr, "%% %s:%s/%lu", RepAtom(AtomOfTerm(pred_module))->StrOfAE, snprintf(o, 255, "%% %s:%s/%lu", RepAtom(AtomOfTerm(pred_module))->StrOfAE,
RepAtom(pred_name)->StrOfAE, (unsigned long int)pred_arity); RepAtom(pred_name)->StrOfAE, (unsigned long int)pred_arity);
} else { } else {
fprintf(stderr, "%% %s:%s/%lu at clause %lu", snprintf(o, 255, "%% %s:%s/%lu at clause %lu",
RepAtom(AtomOfTerm(pred_module))->StrOfAE, RepAtom(AtomOfTerm(pred_module))->StrOfAE,
RepAtom(pred_name)->StrOfAE, (unsigned long int)pred_arity, RepAtom(pred_name)->StrOfAE, (unsigned long int)pred_arity,
(unsigned long int)cl); (unsigned long int)cl);
} }
return o;
} }
static yap_error_descriptor_t *add_bug_location(yap_error_descriptor_t *p, static yap_error_descriptor_t *add_bug_location(yap_error_descriptor_t *p,

121
C/text.c
View File

@ -59,54 +59,6 @@ typedef struct TextBuffer_manager {
} text_buffer_t; } text_buffer_t;
int AllocLevel(void) { return LOCAL_TextBuffer->lvl; } int AllocLevel(void) { return LOCAL_TextBuffer->lvl; }
int push_text_stack__(USES_REGS1) {
int i = LOCAL_TextBuffer->lvl;
i++;
LOCAL_TextBuffer->lvl = i;
return i;
}
int pop_text_stack__(int i) {
int lvl = LOCAL_TextBuffer->lvl;
while (lvl >= i) {
struct mblock *p = LOCAL_TextBuffer->first[lvl];
while (p) {
struct mblock *np = p->next;
free(p);
p = np;
}
LOCAL_TextBuffer->first[lvl] = NULL;
LOCAL_TextBuffer->last[lvl] = NULL;
lvl--;
}
LOCAL_TextBuffer->lvl = lvl;
return lvl;
}
void *pop_output_text_stack__(int i, const void *export) {
int lvl = LOCAL_TextBuffer->lvl;
while (lvl >= i) {
struct mblock *p = LOCAL_TextBuffer->first[lvl];
while (p) {
struct mblock *np = p->next;
if (p + 1 == export) {
size_t sz = p->sz - sizeof(struct mblock);
memmove(p, p + 1, sz);
export = p;
} else {
free(p);
}
p = np;
}
LOCAL_TextBuffer->first[lvl] = NULL;
LOCAL_TextBuffer->last[lvl] = NULL;
lvl--;
}
LOCAL_TextBuffer->lvl = lvl;
return (void *)export;
}
// void pop_text_stack(int i) { LOCAL_TextBuffer->lvl = i; } // void pop_text_stack(int i) { LOCAL_TextBuffer->lvl = i; }
void insert_block(struct mblock *o) { void insert_block(struct mblock *o) {
int lvl = o->lvl; int lvl = o->lvl;
@ -138,6 +90,68 @@ void release_block(struct mblock *o) {
o->next->prev = o->prev; o->next->prev = o->prev;
} }
int push_text_stack__(USES_REGS1) {
int i = LOCAL_TextBuffer->lvl;
i++;
LOCAL_TextBuffer->lvl = i;
return i;
}
int pop_text_stack__(int i) {
int lvl = LOCAL_TextBuffer->lvl;
while (lvl >= i) {
struct mblock *p = LOCAL_TextBuffer->first[lvl];
while (p) {
struct mblock *np = p->next;
free(p);
p = np;
}
LOCAL_TextBuffer->first[lvl] = NULL;
LOCAL_TextBuffer->last[lvl] = NULL;
lvl--;
}
LOCAL_TextBuffer->lvl = lvl;
return lvl;
}
void *pop_output_text_stack__(int i, const void *export) {
int lvl = LOCAL_TextBuffer->lvl;
bool found = false;
while (lvl >= i) {
struct mblock *p = LOCAL_TextBuffer->first[lvl];
while (p) {
struct mblock *np = p->next;
if (p + 1 == export) {
found = true;
} else {
free(p);
}
p = np;
}
LOCAL_TextBuffer->first[lvl] = NULL;
LOCAL_TextBuffer->last[lvl] = NULL;
lvl--;
}
LOCAL_TextBuffer->lvl = lvl;
if (found) {
if (lvl) {
struct mblock *o = (struct mblock *)export-1;
o->lvl = lvl;
o->prev = o->next = 0;
insert_block(o);
} else {
struct mblock *p = (struct mblock *)export-1;
size_t sz = p->sz - sizeof(struct mblock);
memmove(p, p + 1, sz);
export = p;
}
}
return (void *)export;
}
void *Malloc(size_t sz USES_REGS) { void *Malloc(size_t sz USES_REGS) {
int lvl = LOCAL_TextBuffer->lvl; int lvl = LOCAL_TextBuffer->lvl;
if (sz == 0) if (sz == 0)
@ -976,7 +990,7 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
else else
fprintf(stderr, "%s", out->val.c); fprintf(stderr, "%s", out->val.c);
fprintf(stderr, "\n]\n"); */ fprintf(stderr, "\n]\n"); */
pop_text_stack(l); out->val.uc = pop_output_text_stack(l,out->val.uc);
return rc; return rc;
} }
@ -1027,10 +1041,11 @@ bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) {
void **bufv; void **bufv;
unsigned char *buf; unsigned char *buf;
int i, j; int i, j;
// int lvl = push_text_stack();
int lvl = push_text_stack();
bufv = Malloc(tot * sizeof(unsigned char *)); bufv = Malloc(tot * sizeof(unsigned char *));
if (!bufv) { if (!bufv) {
// pop_text_stack(lvl); pop_text_stack(lvl);
return NULL; return NULL;
} }
for (i = 0, j = 0; i < tot; i++) { for (i = 0, j = 0; i < tot; i++) {
@ -1038,7 +1053,7 @@ bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) {
unsigned char *nbuf = Yap_readText(inp + i PASS_REGS); unsigned char *nbuf = Yap_readText(inp + i PASS_REGS);
if (!nbuf) { if (!nbuf) {
// pop_text_stack(lvl); pop_text_stack(lvl);
return NULL; return NULL;
} }
// if (!nbuf[0]) // if (!nbuf[0])
@ -1054,7 +1069,7 @@ bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) {
buf = concat(tot, bufv PASS_REGS); buf = concat(tot, bufv PASS_REGS);
} }
bool rc = write_Text(buf, out PASS_REGS); bool rc = write_Text(buf, out PASS_REGS);
// pop_text_stack( lvl ); pop_text_stack( lvl );
return rc; return rc;
} }

View File

@ -98,11 +98,9 @@ static char *send_tracer_message(char *start, char *name, arity_t arity,
if (max <= sz) { if (max <= sz) {
min = sz + 1024; min = sz + 1024;
expand = true; expand = true;
free((void*)sn);
continue; continue;
} }
strcpy(s, sn); strcpy(s, sn);
free((void*)sn);
sn = NULL; sn = NULL;
s += sz; s += sz;
max -= sz; max -= sz;

View File

@ -103,7 +103,6 @@ copy_complex_term(CELL *pt0, CELL *pt0_end, int share, int newattvs, CELL *ptf,
} }
*ptf = AbsPair(HR); *ptf = AbsPair(HR);
ptf++; ptf++;
#ifdef RATIONAL_TREES
if (to_visit+1 >= (struct cp_frame *)AuxSp) { if (to_visit+1 >= (struct cp_frame *)AuxSp) {
goto heap_overflow; goto heap_overflow;
} }
@ -115,18 +114,6 @@ copy_complex_term(CELL *pt0, CELL *pt0_end, int share, int newattvs, CELL *ptf,
/* fool the system into thinking we had a variable there */ /* fool the system into thinking we had a variable there */
*pt0 = AbsPair(HR); *pt0 = AbsPair(HR);
to_visit ++; to_visit ++;
#else
if (pt0 < pt0_end) {
if (to_visit+1 >= (struct cp_frame *)AuxSp) {
goto heap_overflow;
}
to_visit->start_cp = pt0;
to_visit->end_cp = pt0_end;
to_visit->to = ptf;
to_visit->ground = ground;
to_visit ++;
}
#endif
ground = TRUE; ground = TRUE;
pt0 = ap2 - 1; pt0 = ap2 - 1;
pt0_end = ap2 + 1; pt0_end = ap2 + 1;
@ -192,7 +179,6 @@ copy_complex_term(CELL *pt0, CELL *pt0_end, int share, int newattvs, CELL *ptf,
*ptf = AbsAppl(HR); *ptf = AbsAppl(HR);
ptf++; ptf++;
/* store the terms to visit */ /* store the terms to visit */
#ifdef RATIONAL_TREES
if (to_visit+1 >= (struct cp_frame *)AuxSp) { if (to_visit+1 >= (struct cp_frame *)AuxSp) {
goto heap_overflow; goto heap_overflow;
} }
@ -204,18 +190,6 @@ copy_complex_term(CELL *pt0, CELL *pt0_end, int share, int newattvs, CELL *ptf,
/* fool the system into thinking we had a variable there */ /* fool the system into thinking we had a variable there */
*pt0 = AbsAppl(HR); *pt0 = AbsAppl(HR);
to_visit ++; to_visit ++;
#else
if (pt0 < pt0_end) {
if (to_visit+1 >= (struct cp_frame *)AuxSp) {
goto heap_overflow;
}
to_visit->start_cp = pt0;
to_visit->end_cp = pt0_end;
to_visit->to = ptf;
to_visit->ground = ground;
to_visit ++;
}
#endif
ground = (f != FunctorMutable); ground = (f != FunctorMutable);
d0 = ArityOfFunctor(f); d0 = ArityOfFunctor(f);
pt0 = ap2; pt0 = ap2;
@ -267,9 +241,7 @@ copy_complex_term(CELL *pt0, CELL *pt0_end, int share, int newattvs, CELL *ptf,
} }
Bind_NonAtt(ptd0, (CELL)ptf); Bind_NonAtt(ptd0, (CELL)ptf);
ptf++; ptf++;
#ifdef COROUTINING
} }
#endif
} }
/* Do we still have compound terms to visit */ /* Do we still have compound terms to visit */
if (to_visit > to_visit0) { if (to_visit > to_visit0) {
@ -288,9 +260,7 @@ copy_complex_term(CELL *pt0, CELL *pt0_end, int share, int newattvs, CELL *ptf,
pt0 = to_visit->start_cp; pt0 = to_visit->start_cp;
pt0_end = to_visit->end_cp; pt0_end = to_visit->end_cp;
ptf = to_visit->to; ptf = to_visit->to;
#ifdef RATIONAL_TREES
*pt0 = to_visit->oldv; *pt0 = to_visit->oldv;
#endif
ground = (ground && to_visit->ground); ground = (ground && to_visit->ground);
goto loop; goto loop;
} }
@ -306,7 +276,6 @@ copy_complex_term(CELL *pt0, CELL *pt0_end, int share, int newattvs, CELL *ptf,
/* we've done it */ /* we've done it */
/* restore our nice, friendly, term to its original state */ /* restore our nice, friendly, term to its original state */
HB = HB0; HB = HB0;
#ifdef RATIONAL_TREES
while (to_visit > to_visit0) { while (to_visit > to_visit0) {
to_visit --; to_visit --;
pt0 = to_visit->start_cp; pt0 = to_visit->start_cp;
@ -314,7 +283,6 @@ copy_complex_term(CELL *pt0, CELL *pt0_end, int share, int newattvs, CELL *ptf,
ptf = to_visit->to; ptf = to_visit->to;
*pt0 = to_visit->oldv; *pt0 = to_visit->oldv;
} }
#endif
reset_trail(TR0); reset_trail(TR0);
/* follow chain of multi-assigned variables */ /* follow chain of multi-assigned variables */
return -1; return -1;
@ -325,7 +293,6 @@ trail_overflow:
/* we've done it */ /* we've done it */
/* restore our nice, friendly, term to its original state */ /* restore our nice, friendly, term to its original state */
HB = HB0; HB = HB0;
#ifdef RATIONAL_TREES
while (to_visit > to_visit0) { while (to_visit > to_visit0) {
to_visit --; to_visit --;
pt0 = to_visit->start_cp; pt0 = to_visit->start_cp;
@ -333,7 +300,6 @@ trail_overflow:
ptf = to_visit->to; ptf = to_visit->to;
*pt0 = to_visit->oldv; *pt0 = to_visit->oldv;
} }
#endif
{ {
tr_fr_ptr oTR = TR; tr_fr_ptr oTR = TR;
reset_trail(TR0); reset_trail(TR0);
@ -349,7 +315,6 @@ trail_overflow:
/* we've done it */ /* we've done it */
/* restore our nice, friendly, term to its original state */ /* restore our nice, friendly, term to its original state */
HB = HB0; HB = HB0;
#ifdef RATIONAL_TREES
while (to_visit > to_visit0) { while (to_visit > to_visit0) {
to_visit --; to_visit --;
pt0 = to_visit->start_cp; pt0 = to_visit->start_cp;
@ -357,7 +322,6 @@ trail_overflow:
ptf = to_visit->to; ptf = to_visit->to;
*pt0 = to_visit->oldv; *pt0 = to_visit->oldv;
} }
#endif
reset_trail(TR0); reset_trail(TR0);
LOCAL_Error_Size = (ADDR)AuxSp-(ADDR)to_visit0; LOCAL_Error_Size = (ADDR)AuxSp-(ADDR)to_visit0;
return -3; return -3;
@ -2679,7 +2643,7 @@ static Term free_vars_in_complex_term(register CELL *pt0, register CELL *pt0_end
clean_tr(TR0 PASS_REGS); clean_tr(TR0 PASS_REGS);
Yap_ReleasePreAllocCodeSpace((ADDR)to_visit0); Yap_ReleasePreAllocCodeSpace((ADDR)to_visit0);
if (HR != InitialH+1) { if (HR != InitialH) {
InitialH[0] = (CELL)Yap_MkFunctor(AtomDollar, (HR-InitialH)-1); InitialH[0] = (CELL)Yap_MkFunctor(AtomDollar, (HR-InitialH)-1);
return AbsAppl(InitialH); return AbsAppl(InitialH);
} else { } else {
@ -3002,9 +2966,9 @@ static Term non_singletons_in_complex_term(register CELL *pt0, register CELL *pt
CELL *pt2 = pt0; CELL *pt2 = pt0;
while(IsVarTerm(*pt2)) while(IsVarTerm(*pt2))
pt2 = (CELL *)(*pt2); pt2 = (CELL *)(*pt2);
HR[1] = AbsPair(HR+2); HR[0] = AbsPair(HR+2);
HR += 2; HR += 2;
HR[-2] = (CELL)pt2; HR[-1] = (CELL)pt2;
*pt2 = TermRefoundVar; *pt2 = TermRefoundVar;
} }
continue; continue;
@ -3019,24 +2983,28 @@ static Term non_singletons_in_complex_term(register CELL *pt0, register CELL *pt
} }
/* Do we still have compound terms to visit */ /* Do we still have compound terms to visit */
if (to_visit > to_visit0) { if (to_visit > to_visit0) {
#ifdef RATIONAL_TREES
to_visit -= 3; to_visit -= 3;
pt0 = to_visit[0]; pt0 = to_visit[0];
pt0_end = to_visit[1]; pt0_end = to_visit[1];
*pt0 = (CELL)to_visit[2]; *pt0 = (CELL)to_visit[2];
#else
to_visit -= 2;
pt0 = to_visit[0];
pt0_end = to_visit[1];
#endif
goto loop; goto loop;
} }
clean_tr(TR0 PASS_REGS); clean_tr(TR0 PASS_REGS);
if (HR != InitialH) {
CELL *pt0 = InitialH, *pt1 = pt0;
while (pt0 < InitialH) {
if(Deref(pt0[0]) == TermFoundVar) {
pt1[0] = pt0[0];
pt1[1] = AbsAppl(pt1+2);
pt1 += 2;
}
pt0 += 2;
}
}
if (HR != InitialH) { if (HR != InitialH) {
/* close the list */ /* close the list */
RESET_VARIABLE(HR-1); HR[-1] = Deref(ARG2);
Yap_unify((CELL)(HR-1),ARG2);
return output; return output;
} else { } else {
return ARG2; return ARG2;
@ -3067,7 +3035,7 @@ p_non_singletons_in_term( USES_REGS1 ) /* non_singletons in term t */
while (TRUE) { while (TRUE) {
t = Deref(ARG1); t = Deref(ARG1);
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
out = MkPairTerm(t,ARG2); out = ARG2;
} else if (IsPrimitiveTerm(t)) { } else if (IsPrimitiveTerm(t)) {
out = ARG2; out = ARG2;
} else if (IsPairTerm(t)) { } else if (IsPairTerm(t)) {
@ -4874,19 +4842,11 @@ loop:
if (to_visit + 32 >= to_visit_max) { if (to_visit + 32 >= to_visit_max) {
goto aux_overflow; goto aux_overflow;
} }
#ifdef RATIONAL_TREES
to_visit->beg = pt0; to_visit->beg = pt0;
to_visit->end = pt0_end; to_visit->end = pt0_end;
to_visit->oval = *pt0; to_visit->oval = *pt0;
to_visit ++; to_visit ++;
*pt0 = TermNil; *pt0 = TermNil;
#else
if (pt0 < pt0_end) {
to_visit[0] = pt0;
to_visit[1] = pt0_end;
to_visit += 2;
}
#endif
pt0 = RepPair(d0) - 1; pt0 = RepPair(d0) - 1;
pt0_end = RepPair(d0) + 1; pt0_end = RepPair(d0) + 1;
} else if (IsApplTerm(d0)) { } else if (IsApplTerm(d0)) {
@ -4906,14 +4866,11 @@ loop:
if (to_visit + 32 >= to_visit_max) { if (to_visit + 32 >= to_visit_max) {
goto aux_overflow; goto aux_overflow;
} }
#ifdef RATIONAL_TREES
#else
to_visit->beg = pt0; to_visit->beg = pt0;
to_visit->end = pt0_end; to_visit->end = pt0_end;
to_visit->oval = *pt0; to_visit->oval = *pt0;
to_visit ++; to_visit ++;
*pt0 = TermNil; *pt0 = TermNil;
#endif
d0 = ArityOfFunctor(f); d0 = ArityOfFunctor(f);
pt0 = ap2; pt0 = ap2;
pt0_end = ap2 + d0; pt0_end = ap2 + d0;

View File

@ -100,7 +100,8 @@ static bool callPortray(Term t, int sno USES_REGS) {
return false; return false;
} }
#define PROTECT(t,F) { \ #define PROTECT(t, F) \
{ \
yhandle_t yt = Yap_InitHandle(t); \ yhandle_t yt = Yap_InitHandle(t); \
F; \ F; \
t = Yap_PopHandle(yt); \ t = Yap_PopHandle(yt); \
@ -717,7 +718,6 @@ static void write_var(CELL *t, struct write_globs *wglb,
} }
} }
static void write_list(Term t, int direction, int depth, static void write_list(Term t, int direction, int depth,
struct write_globs *wglb, struct rewind_term *rwt) { struct write_globs *wglb, struct rewind_term *rwt) {
Term ti; Term ti;
@ -729,8 +729,7 @@ static void write_list(Term t, int direction, int depth,
int ndirection; int ndirection;
int do_jump; int do_jump;
PROTECT(t,writeTerm(HeadOfTerm(t), 999, depth + 1, FALSE, PROTECT(t, writeTerm(HeadOfTerm(t), 999, depth + 1, FALSE, wglb, &nrwt));
wglb, &nrwt));
ti = TailOfTerm(t); ti = TailOfTerm(t);
if (IsVarTerm(ti)) if (IsVarTerm(ti))
break; break;
@ -775,8 +774,7 @@ static void write_list(Term t, int direction, int depth,
} }
wrputc('|', wglb->stream); wrputc('|', wglb->stream);
lastw = separator; lastw = separator;
writeTerm(ti, 999, depth, FALSE, writeTerm(ti, 999, depth, FALSE, wglb, &nrwt);
wglb, &nrwt);
} }
} }
@ -807,11 +805,9 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg,
wrputs("'.'(", wglb->stream); wrputs("'.'(", wglb->stream);
lastw = separator; lastw = separator;
PROTECT( t, writeTerm(HeadOfTerm(t), 999, depth + 1, FALSE, PROTECT(t, writeTerm(HeadOfTerm(t), 999, depth + 1, FALSE, wglb, &nrwt));
wglb, &nrwt));
wrputs(",", wglb->stream); wrputs(",", wglb->stream);
writeTerm(TailOfTerm(t), 999, depth + 1, writeTerm(TailOfTerm(t), 999, depth + 1, FALSE, wglb, &nrwt);
FALSE, wglb, &nrwt);
wrclose_bracket(wglb, TRUE); wrclose_bracket(wglb, TRUE);
return; return;
} }
@ -877,8 +873,7 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg,
*p++; *p++;
lastw = separator; lastw = separator;
/* cannot use the term directly with the SBA */ /* cannot use the term directly with the SBA */
PROTECT( t, writeTerm(*p, 999, depth + 1, FALSE, wglb, PROTECT(t, writeTerm(*p, 999, depth + 1, FALSE, wglb, &nrwt));
&nrwt) );
if (*p) if (*p)
wrputc(',', wglb->stream); wrputc(',', wglb->stream);
argno++; argno++;
@ -906,8 +901,7 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg,
} else if (atom == AtomMinus) { } else if (atom == AtomMinus) {
last_minus = TRUE; last_minus = TRUE;
} }
writeTerm(tright, rp, depth + 1, TRUE, writeTerm(tright, rp, depth + 1, TRUE, wglb, &nrwt);
wglb, &nrwt);
if (bracket_right) { if (bracket_right) {
wrclose_bracket(wglb, TRUE); wrclose_bracket(wglb, TRUE);
} }
@ -940,8 +934,7 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg,
if (bracket_left) { if (bracket_left) {
wropen_bracket(wglb, TRUE); wropen_bracket(wglb, TRUE);
} }
writeTerm(ArgOfTerm(offset,t), lp, depth + 1, writeTerm(ArgOfTerm(offset, t), lp, depth + 1, rinfixarg, wglb, &nrwt);
rinfixarg, wglb, &nrwt);
if (bracket_left) { if (bracket_left) {
wrclose_bracket(wglb, TRUE); wrclose_bracket(wglb, TRUE);
} }
@ -986,8 +979,8 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg,
if (bracket_left) { if (bracket_left) {
wropen_bracket(wglb, TRUE); wropen_bracket(wglb, TRUE);
} }
PROTECT(t,writeTerm(ArgOfTerm(1,t), lp, depth + 1, PROTECT(
rinfixarg, wglb, &nrwt)); t, writeTerm(ArgOfTerm(1, t), lp, depth + 1, rinfixarg, wglb, &nrwt));
if (bracket_left) { if (bracket_left) {
wrclose_bracket(wglb, TRUE); wrclose_bracket(wglb, TRUE);
} }
@ -1006,8 +999,7 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg,
if (bracket_right) { if (bracket_right) {
wropen_bracket(wglb, TRUE); wropen_bracket(wglb, TRUE);
} }
writeTerm(ArgOfTerm(2,t), rp, depth + 1, TRUE, writeTerm(ArgOfTerm(2, t), rp, depth + 1, TRUE, wglb, &nrwt);
wglb, &nrwt);
if (bracket_right) { if (bracket_right) {
wrclose_bracket(wglb, TRUE); wrclose_bracket(wglb, TRUE);
} }
@ -1047,15 +1039,14 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg,
} else { } else {
wrputs("'$VAR'(", wglb->stream); wrputs("'$VAR'(", wglb->stream);
lastw = separator; lastw = separator;
writeTerm(ArgOfTerm(1, t), 999, depth + 1, writeTerm(ArgOfTerm(1, t), 999, depth + 1, FALSE, wglb, &nrwt);
FALSE, wglb, &nrwt);
wrclose_bracket(wglb, TRUE); wrclose_bracket(wglb, TRUE);
} }
} else if (!wglb->Ignore_ops && functor == FunctorBraces) { } else if (!wglb->Ignore_ops && functor == FunctorBraces) {
wrputc('{', wglb->stream); wrputc('{', wglb->stream);
lastw = separator; lastw = separator;
writeTerm(ArgOfTerm(1, t), GLOBAL_MaxPriority, writeTerm(ArgOfTerm(1, t), GLOBAL_MaxPriority, depth + 1, FALSE, wglb,
depth + 1, FALSE, wglb, &nrwt); &nrwt);
wrputc('}', wglb->stream); wrputc('}', wglb->stream);
lastw = separator; lastw = separator;
} else if (atom == AtomArray) { } else if (atom == AtomArray) {
@ -1066,17 +1057,15 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg,
wrputs("...", wglb->stream); wrputs("...", wglb->stream);
break; break;
} }
writeTerm(ArgOfTerm(op, t), 999, depth + 1, writeTerm(ArgOfTerm(op, t), 999, depth + 1, FALSE, wglb, &nrwt);
FALSE, wglb, &nrwt);
if (op != Arity) { if (op != Arity) {
PROTECT(t, writeTerm(ArgOfTerm(op, t), 999, depth + 1, PROTECT(t, writeTerm(ArgOfTerm(op, t), 999, depth + 1, FALSE, wglb,
FALSE, wglb, &nrwt)); &nrwt));
wrputc(',', wglb->stream); wrputc(',', wglb->stream);
lastw = separator; lastw = separator;
} }
} }
writeTerm(ArgOfTerm(op, t), 999, depth + 1, writeTerm(ArgOfTerm(op, t), 999, depth + 1, FALSE, wglb, &nrwt);
FALSE, wglb, &nrwt);
wrputc('}', wglb->stream); wrputc('}', wglb->stream);
lastw = separator; lastw = separator;
} else { } else {
@ -1090,13 +1079,12 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg,
wrputc('.', wglb->stream); wrputc('.', wglb->stream);
break; break;
} }
PROTECT(t,writeTerm(ArgOfTerm(op, t), 999, depth + 1, PROTECT(
FALSE, wglb, &nrwt)); t, writeTerm(ArgOfTerm(op, t), 999, depth + 1, FALSE, wglb, &nrwt));
wrputc(',', wglb->stream); wrputc(',', wglb->stream);
lastw = separator; lastw = separator;
} }
writeTerm(ArgOfTerm(op, t), 999, depth + 1, writeTerm(ArgOfTerm(op, t), 999, depth + 1, FALSE, wglb, &nrwt);
FALSE, wglb, &nrwt);
wrclose_bracket(wglb, TRUE); wrclose_bracket(wglb, TRUE);
} }
} }
@ -1164,4 +1152,3 @@ void Yap_plwrite(Term t, StreamDesc *mywrite, int max_depth, int flags,
Yap_CloseSlots(sls); Yap_CloseSlots(sls);
pop_text_stack(lvl); pop_text_stack(lvl);
} }

View File

@ -198,6 +198,7 @@ static bool consult(const char *b_file USES_REGS) {
t = ArgOfTerm(1, t); t = ArgOfTerm(1, t);
if (IsApplTerm(t) && FunctorOfTerm(t) == functor_compile2) { if (IsApplTerm(t) && FunctorOfTerm(t) == functor_compile2) {
consult(RepAtom(AtomOfTerm(ArgOfTerm(1, t)))->StrOfAE); consult(RepAtom(AtomOfTerm(ArgOfTerm(1, t)))->StrOfAE);
Yap_ResetException(LOCAL_ActiveError);
} else { } else {
YAP_RunGoalOnce(t); YAP_RunGoalOnce(t);
} }
@ -1052,6 +1053,9 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
MkAtomTerm(Yap_LookupAtom(Yap_BOOTFILE))); MkAtomTerm(Yap_LookupAtom(Yap_BOOTFILE)));
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false); setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false);
} else { } else {
if (yap_init->QuietMode) {
setVerbosity(TermSilent);
}
Yap_Restore(Yap_INPUT_STARTUP); Yap_Restore(Yap_INPUT_STARTUP);
init_globals(yap_init); init_globals(yap_init);

304
CMakeLists.txt Normal file → Executable file
View File

@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.4)
# Sets the version of CMake required to build the native # Sets the version of CMake required to build the native
# library. You should either keep the default value or pass a # library. You should either keep the default value or pass a
# value of 3.4.0 or lower. # value of 3.4.0 or lower.fg
include(CMakeToolsHelpers OPTIONAL) include(CMakeToolsHelpers OPTIONAL)
include(FeatureSummary) include(FeatureSummary)
@ -67,7 +67,92 @@ if (POLICY CMP0068)
cmake_policy(SET CMP0068 NEW) cmake_policy(SET CMP0068 NEW)
endif () endif ()
## options: compilation flags
option(BUILD_SHARED_LIBS "Build shared library" ON) option(BUILD_SHARED_LIBS "Build shared library" ON)
CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_MMAP "Use MMAP for shared memory allocation" ON "NOT WITH_YAPOR_THOR" OFF)
CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_SHM "Use SHM for shared memory allocation" ON "NOT WITH_YAPOR_THOR; NOT WITH_SYSTEM_MMAP" OFF)
OPTION(WITH_CALL_TRACER "support for procedure-call tracing" ${DEBUG})
option(WITH_YAP_DLL "compile YAP as a DLL" ON)
option(WITH_YAP_STATIC "compile YAP statically" OFF)
option(WITH_YAP_CONDOR "allow YAP to be used from condor" OFF)
option(WITH_YAP_DLL "compile YAP as a DLL" ON)
if (WITH_YAP_CONDOR)
set(WITH_YAP_STATIC ON)
set(WITH_YAP_DLL OFF)
endif ()
## options: libraries
option(WITH_THREADED_CODE "threaded code" ON)
option(WITH_MPI "Interface to OpenMPI/MPICH" ON)
option(WITH_READLINE "use readline or libedit" ON)
option(WITH_JIT "just in Time Clause Compilation" OFF)
if (APPLE)
set(MACOSX_RPATH ON)
option(WITH_BREW "brew" ON)
if (WITH_BREW)
EXECUTE_PROCESS(COMMAND brew --prefix RESULT_VARIABLE DETECT_BREW OUTPUT_VARIABLE BREW_PREFIX ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
IF (${DETECT_BREW} EQUAL 0)
# "/opt/local" is where MacPorts lives, add `/lib` suffix and link
LINK_DIRECTORIES( ${BREW_PREFIX}/lib)
list(INSERT CMAKE_PREFIX_PATH pos
${BREW_PREFIX}/opt/gmp
${BREW_PREFIX}/opt/libxml2
${BREW_PREFIX}/opt/openmpi
${BREW_PREFIX}/opt/openssl
${BREW_PREFIX}/opt/postgresql
${BREW_PREFIX}/opt/python3
${BREW_PREFIX}/opt/readline
${BREW_PREFIX}/opt/swig
)
else()
option(WITH_MACPORTS "mac-ports" ON)
if (WITH_MACPORTS)
# Add MacPorts
# Detect if the "port" command is valid on this system; if so, return full path
EXECUTE_PROCESS(COMMAND which port RESULT_VARIABLE DETECT_MACPORTS OUTPUT_VARIABLE MACPORTS_PREFIX ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
IF (${DETECT_MACPORTS} EQUAL 0)
# "/opt/local/bin/port" doesn't have libs, so we get the parent directory
GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PREFIX} DIRECTORY)
# "/opt/local/bin" doesn't have libs, so we get the parent directory
GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PREFIX} DIRECTORY)
# "/opt/local" is where MacPorts lives, add `/lib` suffix and link
LINK_DIRECTORIES(${LINK DIRECTORIES} ${MACPORTS_PREFIX}/lib)
endif()
endif()
endif()
endif()
endif()
option (WITH_PACKAGES "packages and liaries that add value to YAP" ON)
OPTION(WITH_MYDDAS " Enable MYDDAS driver" ${WITH_PACKAGES})
OPTION(WITH_SQLITE3 " Enable MYDDAS SQLITE3 driver" ${WITH_MYDDAS})
OPTION(WITH_MYSQL " Enable MYDDAS MYSQL driver" ${WITH_MYDDAS})
OPTION(WITH_ODBC " Enable MYDDAS ODBC driver" ${WITH_MYDDAS})
OPTION(WITH_POSTGRES " Enable MYDDAS POSTGRES driver" ${WITH_MYDDAS})
OPTION(WITH_SQLITE3 " Enable MYDDAS SQLITE3 driver" ${WITH_MYDDAS})
OPTION(WITH_SWIG " Enable SWIG interfaces to foreign languages" ${WITH_PACKAGES})
OPTION(WITH_RAPTOR " Enable the RAPTOR RDF library" ${WITH_PACKAGES})
OPTION(WITH_XML2 " Enable the RAPTOR XML2 library" ${WITH_PACKAGES})
OPTION(WITH_XML " Enable the Prolog XML library" ${WITH_PACKAGES})
OPTION(WITH_CLPBN" Enable the CLPBN and PFL probabilistic languages" ${WITH_PACKAGES})
OPTION(WITH_HORUS " Enable the HORUS inference libraray for CLPBN and PFL" ${WITH_CLPBN})
option(WITH_PROBLOG "include Problog-I." ${WITH_PACKAGES})
OPTION(WITH_CPLINT " Enable the cplint probabilistic language" ${WITH_PACKAGES})
option(WITH_GECODE "interface gecode constraint solver" ${WITH_PACKAGES})
option(WITH_LBFGS "interface with lbfgs" ${WITH_PACKAGES})
option(WITH_PRISM "use PRISM system in YAP" ${WITH_PACKAGES})
option(WITH_PYTHON "Allow Python->YAP and YAP->Python" ${WITH_PACKAGES})
option(WITH_R "Use R Interface" ${WITH_PACKAGES})
option(WITH_JAVA "Try to use Java (currently Java 6,7,8)" ${WITH_PACKAGES})
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
@ -225,79 +310,11 @@ endif()
ADD_CUSTOM_TARGET(run_install COMMAND ${CMAKE_MAKE_PROGRAM} install) ADD_CUSTOM_TARGET(run_install COMMAND ${CMAKE_MAKE_PROGRAM} install)
if (APPLE)
set(MACOSX_RPATH ON)
if (NOT $ENV{CONDA_BUILD}x STREQUAL "1x")
set(PATH $ENV{PATH})
option(WITH_BREW "brew" ON)
if (WITH_MACPORTS)
# Add MacPorts
# Detect if the "port" command is valid on this system; if so, return full path
EXECUTE_PROCESS(COMMAND which port RESULT_VARIABLE DETECT_MACPORTS OUTPUT_VARIABLE MACPORTS_PREFIX ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
IF (${DETECT_MACPORTS} EQUAL 0)
# "/opt/local/bin/port" doesn't have libs, so we get the parent directory
GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PREFIX} DIRECTORY)
# "/opt/local/bin" doesn't have libs, so we get the parent directory
GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PREFIX} DIRECTORY)
# "/opt/local" is where MacPorts lives, add `/lib` suffix and link
LINK_DIRECTORIES(${LINK DIRECTORIES} ${MACPORTS_PREFIX}/lib)
MESSAGE("WINNING!: ${MACPORTS_PREFIX}/lib")
ENDIF()
ENDIF()
option(WITH_BREW "brew" ON)
if (WITH_BREW)
EXECUTE_PROCESS(COMMAND brew --prefix RESULT_VARIABLE DETECT_BREW OUTPUT_VARIABLE BREW_PREFIX ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
IF (${DETECT_BREW} EQUAL 0)
# "/opt/local" is where MacPorts lives, add `/lib` suffix and link
LINK_DIRECTORIES( ${BREW_PREFIX}/lib)
MESSAGE("BREW!: ${BREW_PREFIX}/lib")
ENDIF()
list(INSERT CMAKE_PREFIX_PATH pos
${BREW_PREFIX}/opt/gmp
${BREW_PREFIX}/opt/libxml2
${BREW_PREFIX}/opt/openmpi
${BREW_PREFIX}/opt/openssl
${BREW_PREFIX}/opt/postgresql
${BREW_PREFIX}/opt/python3
${BREW_PREFIX}/opt/readline
${BREW_PREFIX}/opt/swig
)
endif ()
endif()
endif ()
set(prefix ${CMAKE_INSTALL_PREFIX}) #BINDIR}) set(prefix ${CMAKE_INSTALL_PREFIX}) #BINDIR})
set(bindir ${CMAKE_INSTALL_PREFIX}/bin) #BINDIR})
set(includedir ${CMAKE_INSTALL_PREFIX}/include) #INCLUDEDIR})
set(libdir ${CMAKE_INSTALL_PREFIX}/lib) #LIBDIR})
set(exec_prefix ${CMAKE_INSTALL_PREFIX}/libexec) #LIBEXECDIR})
set(datarootdir ${CMAKE_INSTALL_PREFIX}/share) #DATAROOTDIR})
if (ANDROID)
set(datarootdir ${YAP_APP_DIR}/src/generated/assets)
endif ()
set(datadir ${CMAKE_INSTALL_PREFIX}/share) #DATADIR})
set(mandir ${CMAKE_INSTALL_PREFIX}/share/man) #MANDIR})
set(docdir ${CMAKE_INSTALL_PREFIX}/share/docs) #MANDIR}) set(docdir ${CMAKE_INSTALL_PREFIX}/share/docs) #MANDIR})
set(libpl ${datadir}/Yap)
set(dlls ${libdir}/Yap)
set(YAP_ROOTDIR ${prefix}) set(YAP_ROOTDIR ${prefix})
# erootdir -> rootdir # erootdir -> rootdir
# libdir defined above # libdir defined above
@ -307,10 +324,9 @@ set(YAP_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR})
set(YAP_DLLDIR ${CMAKE_INSTALL_FULL_LIBDIR}/Yap) set(YAP_DLLDIR ${CMAKE_INSTALL_FULL_LIBDIR}/Yap)
set(YAP_PLDIR ${CMAKE_INSTALL_FULL_DATADIR}/Yap) set(YAP_PLDIR ${CMAKE_INSTALL_FULL_DATADIR}/Yap)
set(YAP_INSTALL_DLLDIR ${CMAKE_INSTALL_LIBDIR}/Yap) set(YAP_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/Yap)
set(YAP_INSTALL_PLDIR ${CMAKE_INSTALL_DATADIR}/Yap) set(YAP_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR}/Yap)
set(YAP_INSTALL_DATADIR ${CMAKE_INSTALL_DATADIR}/Yap)
set(libpl ${YAP_INSTALL_PLDIR})
# #
# #
@ -334,12 +350,12 @@ find_package(GMP)
list(APPEND YAP_SYSTEM_OPTIONS big_numbers) list(APPEND YAP_SYSTEM_OPTIONS big_numbers)
if (GMP_FOUND)
if (GMP_INCLUDE_DIRS)
#config.h needs this (TODO: change in code latter) #config.h needs this (TODO: change in code latter)
include_directories(${GMP_INCLUDE_DIRS}) include_directories(${GMP_INCLUDE_DIRS})
endif (GMP_FOUND) endif ()
option(WITH_READLINE "use readline or libedit" ON)
if (WITH_READLINE) if (WITH_READLINE)
include(FindReadline) include(FindReadline)
@ -416,7 +432,7 @@ set(DEF_TRAILSPACE 0)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS DEPTH_LIMIT=1;COROUTINING=1;RATIONAL_TREES=1) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS DEPTH_LIMIT=1;COROUTINING=1;RATIONAL_TREES=1)
# inform we are compiling YAP # inform we are compiling YAP
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_YAP_NOT_INSTALLED_=1;HAVE_CONFIG_H=1;_GNU_SOURCE") set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_YAP_NOT_INSTALLED_=1;HAVE_CONFIG_H=1;_GNU_SOURCE=1")
# Compilation model # Compilation model
# target_compile_definitions(libYap PUBLIC _XOPEN_SOURCE=700 ) # target_compile_definitions(libYap PUBLIC _XOPEN_SOURCE=700 )
@ -464,9 +480,9 @@ endif ()
# #
# #
## the RPATH to be used when installing, but only if it's not a system directory ## the RPATH to be used when installing, but only if it's not a system directory
#LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${libdir}" isSystemDir) #LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${YAP_INSTALL_LIBDIR}" isSystemDir)
# IF("${isSystemDir}" STREQUAL "-1") # IF("${isSystemDir}" STREQUAL "-1")
# SET(CMAKE_INSTALL_RPATH ${libdir}) # SET(CMAKE_INSTALL_RPATH ${YAP_INSTALL_LIBDIR})
#ENDIF("${isSystemDir}" STREQUAL "-1") #ENDIF("${isSystemDir}" STREQUAL "-1")
# #
IF(NOT WIN32 AND NOT APPLE) IF(NOT WIN32 AND NOT APPLE)
@ -485,7 +501,7 @@ ENDIF()
if (HAVE_GCC) if (HAVE_GCC)
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS -Wall) set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS -Wall)
if (${C_COMPILER} MATCHES "GNU") if (${C_COMPILER} MATCHES "GNU")
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS $<$<CONFIG:Release>:-O3;-fomit-frame-poinkter;-fstrict-aliasing;-freorder-blocks;-fsched-interblock>) set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS $<$<CONFIG:Release>:-O3;-fomit-frame-pointer;-fstrict-aliasing;-freorder-blocks;-fsched-interblock>)
else () else ()
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS $<$<CONFIG:Release>:-O3;-fstrict-aliasing;-freorder-blocks;-fsched-interblock>) set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS $<$<CONFIG:Release>:-O3;-fstrict-aliasing;-freorder-blocks;-fsched-interblock>)
endif () endif ()
@ -495,7 +511,6 @@ endif ()
# set_property( DIRECTORY APPEND_STRING PROPERTY -fsanitize=memory;-fsanitize-memory-track-origins=2) # set_property( DIRECTORY APPEND_STRING PROPERTY -fsanitize=memory;-fsanitize-memory-track-origins=2)
if (HAVE_GCC) if (HAVE_GCC)
# replace instructions codes by the address of their code # replace instructions codes by the address of their code
option(WITH_THREADED_CODE "threaded code" ON)
if (WITH_THREADED_CODE) if (WITH_THREADED_CODE)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS THREADED_CODE=1) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS THREADED_CODE=1)
endif (WITH_THREADED_CODE) endif (WITH_THREADED_CODE)
@ -504,8 +519,6 @@ endif (HAVE_GCC)
# #
#option (YAP_SWI_IO ON) #option (YAP_SWI_IO ON)
OPTION(WITH_CALL_TRACER
"support for procedure-call tracing" ON)
#TODO: #TODO:
if (WITH_CALL_TRACER) if (WITH_CALL_TRACER)
list(APPEND YAP_SYSTEM_OPTIONS "call_tracer " ${YAP_SYSTEM_OPTIONS}) list(APPEND YAP_SYSTEM_OPTIONS "call_tracer " ${YAP_SYSTEM_OPTIONS})
@ -518,11 +531,13 @@ include_directories(utf8proc packages/myddas packages/myddas/sqlite3/src )
set_property(SOURCE ${LIBYAP_SOURCES} APPEND PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1) set_property(SOURCE ${LIBYAP_SOURCES} APPEND PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1)
add_definitions(-DUSE_MYDDAS=1 -DMYDDAS_SQLITE3=1)
IF (WITH_MYDDAS)
if (ANDROID) if (ANDROID)
else() else()
add_definitions(-DUSE_MYDDAS=1 -DMYDDAS_SQLITE3=1)
if (MYSQL_FOUND) if (MYSQL_FOUND)
add_definitions(= -DMYDDAS_MYSQL=1) add_definitions(= -DMYDDAS_MYSQL=1)
endif () endif ()
@ -534,9 +549,9 @@ endif ()
if (MYSQL_POSTGRES) if (MYSQL_POSTGRES)
add_definitions(= -DMYDDAS_POSTGRES=1) add_definitions(= -DMYDDAS_POSTGRES=1)
endif () endif ()
endif() endif(ANDROID)
endif(WITH_MYDDAS)
OPTION(WITH_SWIG " Enable SWIG interfaces to foreign languages" ON)
IF (WITH_SWIG) IF (WITH_SWIG)
find_host_package(SWIG) find_host_package(SWIG)
@ -546,15 +561,11 @@ IF (WITH_SWIG)
ENDIF (WITH_SWIG) ENDIF (WITH_SWIG)
option(WITH_PYTHON
"Allow Python->YAP and YAP->Python" ON)
IF (WITH_PYTHON) IF (WITH_PYTHON)
include(python ) include(python )
ENDIF (WITH_PYTHON) ENDIF (WITH_PYTHON)
option(WITH_R
"Use R Interface" ON)
IF (WITH_R) IF (WITH_R)
find_host_package(LibR) find_host_package(LibR)
@ -568,12 +579,12 @@ List(APPEND YLIBS $<TARGET_OBJECTS:utf8proc>)
List(APPEND YLIBS $<TARGET_OBJECTS:myddas>) List(APPEND YLIBS $<TARGET_OBJECTS:myddas>)
List(APPEND YLIBS $<TARGET_OBJECTS:libswi>) List(APPEND YLIBS $<TARGET_OBJECTS:libswi>)
if (WIN32 OR ANDROID) if (WIN32 OR ANDROID)
List(APPEND YLIBS $<TARGET_OBJECTS:YAPsqlite3>)
List(APPEND YLIBS $<TARGET_OBJECTS:YAP++>) List(APPEND YLIBS $<TARGET_OBJECTS:YAP++>)
if (WIN32 AND WITH_PYTHON) if (WIN32 AND WITH_PYTHON)
List(APPEND YLIBS $<TARGET_OBJECTS:Py4YAP>) List(APPEND YLIBS $<TARGET_OBJECTS:Py4YAP>)
endif () endif ()
if (ANDROID) if (ANDROID)
List(APPEND YLIBS $<TARGET_OBJECTS:YAPsqlite3>)
List(APPEND YLIBS $<TARGET_OBJECTS:YAPJava>) List(APPEND YLIBS $<TARGET_OBJECTS:YAPJava>)
endif () endif ()
endif () endif ()
@ -606,7 +617,7 @@ endif ()
if (WIN32) if (WIN32)
target_link_libraries(libYap ${WINDLLS}) target_link_libraries(libYap ${WINDLLS})
if (PYTHON_INCLUDE_DIRS AND PYTHON_LIBRARIES) if (WITH_PYTHON AND PYTHON_INCLUDE_DIRS AND PYTHON_LIBRARIES)
target_link_libraries(libYap ${PYTHON_LIBRARIES}) target_link_libraries(libYap ${PYTHON_LIBRARIES})
endif () endif ()
endif (WIN32) endif (WIN32)
@ -687,7 +698,7 @@ set_target_properties(libYap
# file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/packages/python/swig/yap4py) # file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/packages/python/swig/yap4py)
if (PYTHONLIBS_FOUND AND SWIG_FOUND) if (WITH_PYTHON AND PYTHONLIBS_FOUND AND SWIG_FOUND)
set( ENV{PYTHONPATH} ${CMAKE_BINARY_DIR}/packages/python/swig:${CMAKE_BINARY_DIR}/packages/python/yap_kernel:. ) set( ENV{PYTHONPATH} ${CMAKE_BINARY_DIR}/packages/python/swig:${CMAKE_BINARY_DIR}/packages/python/yap_kernel:. )
add_subdirectory(packages/python/swig) add_subdirectory(packages/python/swig)
@ -728,26 +739,24 @@ if (NOT WIN32)
endif () endif ()
option(WITH_JIT
"just in Time Clause Compilation" OFF)
if (WITH_JIT) if (WITH_JIT)
add_subDIRECTORY(JIT) add_subDIRECTORY(JIT)
endif (WITH_JIT) endif (WITH_JIT)
if (WITH_XML2 OR WITH_RAPTOR)
add_subDIRECTORY(packages/raptor) add_subDIRECTORY(packages/raptor)
endif()
if (WITH_XML)
add_subDIRECTORY(packages/xml) add_subDIRECTORY(packages/xml)
endif ()
OPTION(WITH_CLPBN " Enable the CLPBN and PFL probabilistic languages" ON)
OPTION(WITH_CPLINT " Enable the cplint probabilistic language" ON)
OPTION(WITH_HORUS " Enable the CLPBN and PFL probabilistic languages" ON)
find_host_package(Doxygen)
option(WITH_DOCS "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND})
IF (WITH_CLPBN) IF (WITH_CLPBN)
add_subDIRECTORY(packages/CLPBN) add_subDIRECTORY(packages/CLPBN)
@ -757,37 +766,29 @@ IF (WITH_CPLINT)
add_subDIRECTORY(packages/cplint) add_subDIRECTORY(packages/cplint)
ENDIF (WITH_CPLINT) ENDIF (WITH_CPLINT)
# please install doxygen for prolog first
# git clone http://www.github.com/vscosta/doxygen-yap
# cd doxygen-yap
# mkdir -p build
# cd build
# make; sudo make install
option(WITH_DOCS
"generate YAP docs" OFF)
IF (WITH_DOCS) IF (WITH_DOCS)
get_target_property(YAP_SOURCES libYap SOURCES)
add_subDIRECTORY(docs) add_subDIRECTORY(docs)
find_host_package(Doxygen)
ENDIF (WITH_DOCS) ENDIF (WITH_DOCS)
# add_subDIRECTORY (packages/cuda) # add_subDIRECTORY (packages/cuda)
option(WITH_GECODE
"interface gecode constraint solver" ON)
if (WITH_GECODE) if (WITH_GECODE)
add_subDIRECTORY(packages/gecode) add_subDIRECTORY(packages/gecode)
endif () endif ()
option(WITH_LBFGS
"interface with lbfgs" ON)
if (WITH_LBFGS) if (WITH_LBFGS)
add_subDIRECTORY(packages/yap-lbfgs) add_subDIRECTORY(packages/yap-lbfgs)
endif () endif ()
option(WITH_JAVA "Try to use Java (currently Java 6,7,8)" ON)
if (WITH_JAVA) if (WITH_JAVA)
#detect java setup, as it is shared between different installations. #detect java setup, as it is shared between different installations.
@ -846,22 +847,52 @@ get_filename_component(JAVA_HOME ${JAVA_INCLUDE_PATH} DIRECTORY)
# JAVA_AWT_INCLUDE_PATH = the include path to jawt.h # JAVA_AWT_INCLUDE_PATH = the include path to jawt.h
get_filename_component ( JAVA_AWT_DIR ${JAVA_AWT_LIBRARY} DIRECTORY)
get_filename_component ( JAVA_JNI_DIR ${JAVA_JVM_LIBRARY} DIRECTORY)
list(APPEND CMAKE_INSTALL_RPATH ${JAVA_AWT_DIR};${JAVA_JNI_DIR})
if (APPLE)
set(CMAKE_MACOSX_RPATH 1)
find_library (JLI jli ${JAVA_AWT_DIR}/jli)
find_library (JAL JavaApplicationLauncher FRAMEWORK ONLY PATH /System/Library/PrivateFrameworks)
find_library (JL JavaLaunching FRAMEWORK ONLY PATH /System/Library/PrivateFrameworks)
list(APPEND CMAKE_INSTALL_RPATH ${JAVA_AWT_DIR}/jli)
list(APPEND JNI_LIBRARIES ${JLI};${JAL};${JL})
endif()
endif (JNI_FOUND) endif (JNI_FOUND)
endif (Java_Development_FOUND) endif (Java_Development_FOUND)
endif(WITH_JAVA)
add_subDIRECTORY(packages/jpl) add_subDIRECTORY(packages/jpl)
endif(WITH_JAVA)
if (WITH_CUDD)
add_subDIRECTORY(packages/bdd) add_subDIRECTORY(packages/bdd)
endif()
if (WITH_PROBLOG)
add_subDIRECTORY(packages/ProbLog) add_subDIRECTORY(packages/ProbLog)
endif()
if (WITH_MINISAT)
add_subDIRECTORY(packages/swi-minisat2) add_subDIRECTORY(packages/swi-minisat2)
endif()
if (WITH_CLPQR)
add_subDIRECTORY(packages/clpqr) add_subDIRECTORY(packages/clpqr)
endif()
#todo: use cmake target builds #todo: use cmake target builds
# option (USE_MAXPERFORMANCE # option (USE_MAXPERFORMANCE
@ -879,28 +910,9 @@ add_subDIRECTORY(packages/clpqr)
# option (USE_CYGWIN # option (USE_CYGWIN
# "use cygwin library in WIN32" OFF) # "use cygwin library in WIN32" OFF)
option(WITH_PRISM
"use PRISM system in YAP" ON)
#TODO: #TODO:
option(WITH_YAP_DLL
"compile YAP as a DLL" ON)
#TODO:
option(WITH_YAP_STATIC
"compile YAP statically" OFF)
#TODO:
option(WITH_YAP_CONDOR
"allow YAP to be used from condor" OFF)
if (WITH_YAP_CONDOR)
# use default allocator
set(YAP_STATIC ON)
set(YAP_DLL OFF)
endif ()
#TODO: detect arch before allow this option #TODO: detect arch before allow this option
# OPTION(WIN64 # OPTION(WIN64
# "compile YAP for win64" OFF) # "compile YAP for win64" OFF)
@ -927,7 +939,7 @@ if (WIN32)
set(MSVC_RUNTIME "dynamic") set(MSVC_RUNTIME "dynamic")
ENDIF (MSVC) ENDIF (MSVC)
target_link_libraries(libYap wsock32 ws2_32 Shlwapi) target_link_libraries(libYap wsock32 ws2_32 shlwapi)
endif (WIN32) endif (WIN32)
@ -945,20 +957,12 @@ install(TARGETS libYap yap-bin
) )
CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_MMAP "Use MMAP for shared memory allocation" ON if (WITH_MPI)
"NOT WITH_YAPOR_THOR" OFF)
CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_SHM "Use SHM for shared memory allocation" ON
"NOT WITH_YAPOR_THOR; NOT WITH_SYSTEM_MMAP" OFF)
if (NOT ANDROID)
add_subDIRECTORY(library/lammpi) add_subDIRECTORY(library/lammpi)
if (MPI_C_FOUND) if (MPI_C_FOUND)
CMAKE_DEPENDENT_OPTION(WITH_MPI ON "Interface to OpenMPI/MPICH"
"MPI_C_FOUND" OFF)
macro_optional_add_subDIRECTORY(library/mpi) macro_optional_add_subDIRECTORY(library/mpi)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MPI_C_COMPILE_FLAGS} ") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MPI_C_COMPILE_FLAGS} ")
include_directories(${MPI_C_INCLUDE_PATH}) include_directories(${MPI_C_INCLUDE_PATH})
@ -974,13 +978,13 @@ if (MPI_C_FOUND)
endif () endif ()
endif (MPI_C_FOUND) endif (MPI_C_FOUND)
endif(NOT ANDROID) endif(WITH_MPI)
## add_subDIRECTORY(utils) ## add_subDIRECTORY(utils)
# #
install(FILES ${INCLUDE_HEADERS} ${CONFIGURATION_HEADERS} DESTINATION ${includedir}/Yap ) install(FILES ${INCLUDE_HEADERS} ${CONFIGURATION_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Yap )

View File

@ -23,7 +23,7 @@ else()
MY_install(TARGETS YAP++ MY_install(TARGETS YAP++
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
) )
endif() endif()

View File

@ -1,7 +1,10 @@
extern "C" {
#include "inline-only.h" #include "inline-only.h"
#define _EXPORT_KERNEL 1 #define _EXPORT_KERNEL 1
}
#include "yapi.hh" #include "yapi.hh"
@ -19,6 +22,8 @@ extern "C" {
#include "YapInterface.h" #include "YapInterface.h"
#include "iopreds.h" #include "iopreds.h"
#include "YapInit.h"
X_API char *Yap_TermToBuffer(Term t, int flags); X_API char *Yap_TermToBuffer(Term t, int flags);
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, arity_t arity); X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, arity_t arity);
@ -975,7 +980,7 @@ PredEntry *YAPPredicate::getPred(Term &t, Term &m, CELL *&out) {
} else { } else {
ap = RepPredProp(PredPropByFunc(f, m)); ap = RepPredProp(PredPropByFunc(f, m));
if (out) if (out)
memmove(out, RepAppl(t) + 1, ap->ArityOfPE * sizeof(CELL)); memmove(out, (const CELL *)RepAppl(t) + 1, ap->ArityOfPE * sizeof(CELL));
else else
out = RepAppl(t) + 1; out = RepAppl(t) + 1;
} }

33
CXX/yapi.hh Normal file → Executable file
View File

@ -8,17 +8,27 @@
#define YAP_CPP_INTERFACE 1 #define YAP_CPP_INTERFACE 1
#include <gmpxx.h>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>
extern "C" {
#include "YapConfig.h"
}
#include <gmpxx.h>
/*! /*!
* *
* @ingroup fli_c_cxx * @ingroup fli_c_cxx
* @defgroup yap-cplus-interface An object oriented interface for YAP. * @defgroup yap-cplus-interface An object oriented interface for YAP.
* *
* @{ 1 * @{
* *
* *
* @brief C++ wrapper to terms, predicates and queries * @brief C++ wrapper to terms, predicates and queries
@ -32,17 +42,14 @@
extern "C" { extern "C" {
#include <stdlib.h> #include <stdlib.h>
// Bad export from Python // Bad export from Python
#include <config.h> #include <YapConfig.h>
#include <stddef.h> #include <stddef.h>
#if YAP_PYTHON #if YAP_PYTHON
#include <Python.h> #include <Python.h>
@ -93,22 +100,19 @@ X_API extern void YAP_UserCPredicate(const char *, YAP_UserCPred,
X_API extern void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, X_API extern void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred,
YAP_Arity, YAP_Term); YAP_Arity, YAP_Term);
X_API extern void YAP_UserBackCPredicate(const char *name, X_API extern void YAP_UserBackCPredicate(const char *name, YAP_UserCPred init,
YAP_UserCPred init, YAP_UserCPred cont, YAP_Arity arity,
YAP_UserCPred cont, YAP_Arity extra);
YAP_Arity arity, YAP_Arity extra);
X_API extern void YAP_UserBackCutCPredicate(const char *name, X_API extern void YAP_UserBackCutCPredicate(const char *name,
YAP_UserCPred init, YAP_UserCPred init,
YAP_UserCPred cont, YAP_UserCPred cont,
YAP_UserCPred cut, YAP_UserCPred cut, YAP_Arity arity,
YAP_Arity arity, YAP_Arity extra); YAP_Arity extra);
X_API extern YAP_Term YAP_ReadBuffer(const char *s, YAP_Term *tp); X_API extern YAP_Term YAP_ReadBuffer(const char *s, YAP_Term *tp);
extern YAP_Term YAP_MkcharPTerm(char *s); extern YAP_Term YAP_MkcharPTerm(char *s);
} }
class YAPEngine; class YAPEngine;
@ -121,7 +125,6 @@ class YAPModule;
class YAPError; class YAPError;
class YAPPredicate; class YAPPredicate;
#include "yapa.hh" #include "yapa.hh"
#include "yapie.hh" #include "yapie.hh"

View File

@ -29,7 +29,7 @@ class X_API YAPPPredicate;
/// take information on a Prolog error: /// take information on a Prolog error:
class X_API YAPError { class X_API YAPError {
int swigcode; //int swigcode;
yap_error_descriptor_t *info; yap_error_descriptor_t *info;
public: public:

View File

@ -525,8 +525,9 @@ public:
mk(t); mk(t);
} }
} }
/// type check for unbound
bool unbound() { return IsUnboundVar(VarOfTerm(gt())); } bool unbound() { return IsUnboundVar(VarOfTerm(gt())); }
inline bool isVar() { return true; } /// type check for unbound inline bool isVar() { return true; }
inline bool isAtom() { return false; } /// type check for atom inline bool isAtom() { return false; } /// type check for atom
inline bool isInteger() { return false; } /// type check for integer inline bool isInteger() { return false; } /// type check for integer
inline bool isFloat() { return false; } /// type check for floating-point inline bool isFloat() { return false; } /// type check for floating-point

View File

@ -106,6 +106,7 @@ A DBref F "$dbref"
A DInteger F "$integer" A DInteger F "$integer"
A DebugMeta F "$debug_meta" A DebugMeta F "$debug_meta"
A DebuggerInput N "debugger_input" A DebuggerInput N "debugger_input"
A DebuggerOutput N "debugger_output"
A Dec10 N "dec10" A Dec10 N "dec10"
A Default N "default" A Default N "default"
A DevNull N "/dev/null" A DevNull N "/dev/null"

View File

@ -19,3 +19,5 @@ add_custom_command( OUTPUT ${CMAKE_TOP_BINARY_DIR}/dlocals.h
DEPENDS locals.h ) DEPENDS locals.h )
install(FILES ${INCLUDE_HEADERS} ${CORE_HEADERS} ${OPTYap_HEADERS} ${YAPOS_HEADERS} ${CONFIGURATION_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Yap )

View File

@ -388,26 +388,6 @@ INLINE_ONLY bool IsStringTerm(Term t) {
#include <stdio.h> #include <stdio.h>
#if !defined(__cplusplus)
#include <gmp.h>
#endif
#else
typedef UInt mp_limb_t;
typedef struct {
Int _mp_size, _mp_alloc;
mp_limb_t *_mp_d;
} MP_INT;
typedef struct {
MP_INT _mp_num;
MP_INT _mp_den;
} MP_RAT;
#endif
INLINE_ONLY bool IsBigIntTerm(Term); INLINE_ONLY bool IsBigIntTerm(Term);
INLINE_ONLY bool IsBigIntTerm(Term t) { INLINE_ONLY bool IsBigIntTerm(Term t) {
@ -415,7 +395,13 @@ INLINE_ONLY bool IsBigIntTerm(Term t) {
FunctorOfTerm(t) == FunctorBigInt; FunctorOfTerm(t) == FunctorBigInt;
} }
#ifdef USE_GMP
#if !defined(__cplusplus)
#include <gmp.h>
#else
#include <gmpxx.h>
#endif
Term Yap_MkBigIntTerm(MP_INT *); Term Yap_MkBigIntTerm(MP_INT *);
MP_INT *Yap_BigIntOfTerm(Term); MP_INT *Yap_BigIntOfTerm(Term);

26
H/Yap.h
View File

@ -50,7 +50,7 @@
#endif /* THREADS && (YAPOR_COW || YAPOR_SBA || YAPOR_COPY) */ #endif /* THREADS && (YAPOR_COW || YAPOR_SBA || YAPOR_COPY) */
// Bad export from Python // Bad export from Python
#include "config.h" #include "YapConfig.h"
#ifndef COROUTINING #ifndef COROUTINING
#define COROUTINING 1 #define COROUTINING 1
@ -74,6 +74,28 @@
#include <stdint.h> #include <stdint.h>
#endif #endif
typedef YAP_Int Int;
typedef YAP_UInt UInt;
typedef YAP_Short Short;
typedef YAP_UShort UShort;
typedef uint16_t BITS16;
typedef int16_t SBITS16;
typedef uint32_t BITS32;
typedef YAP_CELL CELL;
typedef YAP_Term Term;
#define WordSize sizeof(BITS16)
#define CellSize sizeof(CELL)
#define SmallSize sizeof(SMALLUNSGN)
typedef YAP_Int Int;
typedef YAP_Float Float;
typedef YAP_handle_t yhandle_t;
#define TermZERO ((Term)0)
/* /*
#define RATIONAL_TREES 1 #define RATIONAL_TREES 1
@ -754,7 +776,7 @@ extern struct worker_local Yap_local;
#define REMOTE(wid) (&Yap_local) #define REMOTE(wid) (&Yap_local)
#endif #endif
#include "encoding.h" #include "YapEncoding.h"
#include <stdio.h> #include <stdio.h>
#define YP_FILE FILE #define YP_FILE FILE

5
H/YapEval.h Normal file → Executable file
View File

@ -205,7 +205,6 @@ typedef enum {
op_heapused, op_heapused,
op_localsp, op_localsp,
op_globalsp, op_globalsp,
op_b,
op_env, op_env,
op_tr, op_tr,
op_stackfree op_stackfree
@ -632,13 +631,13 @@ __Yap_Mk64IntegerTerm(YAP_LONG_LONG i USES_REGS) {
} }
inline static Term add_int(Int i, Int j USES_REGS) { inline static Term add_int(Int i, Int j USES_REGS) {
#if defined(__clang__) || defined(__GNUC__) #if defined(__clang__) || (defined(__GNUC__) && __GNUC__ > 4)
Int w; Int w;
if (!__builtin_add_overflow(i, j, &w)) if (!__builtin_add_overflow(i, j, &w))
RINT(w); RINT(w);
return Yap_gmp_add_ints(i, j); return Yap_gmp_add_ints(i, j);
; ;
#elif defined(__GNUC__) #elif defined(__GNUC__) && __GNUC__ > 4
Int w; Int w;
if (!__builtin_add_overflow_p(i, j, w)) if (!__builtin_add_overflow_p(i, j, w))
RINT(w); RINT(w);

View File

@ -354,8 +354,11 @@ static inline bool verboseMode(void) {
return GLOBAL_Flags[VERBOSE_FLAG].at != TermSilent; return GLOBAL_Flags[VERBOSE_FLAG].at != TermSilent;
} }
static inline void setVerbosity(Term val) { static inline void setVerbosity(Term val) {
GLOBAL_Flags[VERBOSE_FLAG].at = val; GLOBAL_Flags[VERBOSE_FLAG].at = val;
if (val == TermSilent)
GLOBAL_Flags[VERBOSE_LOAD_FLAG].at = TermFalse;
} }
static inline bool setSyntaxErrorsFlag(Term val) { static inline bool setSyntaxErrorsFlag(Term val) {

View File

@ -22,30 +22,38 @@
@brief global flags and their values. @brief global flags and their values.
*/ */
#ifdef __ANDROID__
#define IN_ANDROID "true"
#else
#define IN_ANDROID "false"
#endif
START_GLOBAL_FLAGS START_GLOBAL_FLAGS
YAP_FLAG(ADDRESS_BITS_FLAG, "address_bits", false, nat, BITNESS, NULL), /**< /**<
Number of address bits in the machine, either 64 or 32 bits. Number of address bits in the machine, either 64 or 32 bits.
*/ */
YAP_FLAG(ADDRESS_BITS_FLAG, "address_bits", false, nat, BITNESS, NULL),
YAP_FLAG(AGC_MARGIN_FLAG, "agc_margin", true, nat, "10000", /**<
agc_threshold), /**<
An integer: if this amount of atoms has been created since the last An integer: if this amount of atoms has been created since the last
atom-garbage collection, perform atom garbage collection at the first atom-garbage collection, perform atom garbage collection at the first
opportunity. Initial value is 10,000. May be changed. A value of 0 opportunity. Initial value is 10,000. May be changed. A value of 0
(zero) disables atom garbage collection. (zero) disables atom garbage collection.
*/ */
YAP_FLAG(AGC_MARGIN_FLAG, "agc_margin", true, nat, "10000",
agc_threshold),
YAP_FLAG(ALLOW_ASSERT_FOR_STATIC_PREDICATES, /**<
"allow_assert_for_static_predicates", true, booleanFlag, "true",
NULL), /**<
boolean: allow asserting and retracting clauses of static boolean: allow asserting and retracting clauses of static
predicates. */ predicates. */
YAP_FLAG(ALLOW_ASSERT_FOR_STATIC_PREDICATES,
"allow_assert_for_static_predicates", true, booleanFlag, "true",
NULL),
YAP_FLAG(ALLOW_VARIABLE_NAME_AS_FUNCTOR_FLAG, /**<
"allow_variable_name_as_functor", false, booleanFlag, "false",
NULL), /**<
boolean flag allows syntax such boolean flag allows syntax such
as as
@ -55,26 +63,31 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
Tree(R). Tree(R).
~~~ ~~~
*/ */
YAP_FLAG(ALLOW_VARIABLE_NAME_AS_FUNCTOR_FLAG,
"allow_variable_name_as_functor", false, booleanFlag, "false",
NULL),
YAP_FLAG(ANSWER_FORMAT_FLAG, "answer_format", true, isatom, "~p", NULL),
/**< how to present answers, default is `~p`. */ /**< how to present answers, default is `~p`. */
#if __ANDROID__ YAP_FLAG(ANSWER_FORMAT_FLAG, "answer_format", true, isatom, "~p", NULL),
YAP_FLAG(ANDROID_FLAG, "android", false, booleanFlag, "true", NULL), /**< /**<
read-only boolean, a machine running an Google's Android version of the read-only boolean, a machine running an Google's Android version of the
Linux Operating System */ Linux Operating System */
#endif YAP_FLAG(ANDROID_FLAG, "android", false, booleanFlag, IN_ANDROID, NULL),
#if __APPLE__ #if __APPLE__
YAP_FLAG(APPLE_FLAG, "apple", false, booleanFlag, "true", NULL), /**< /**<
read-only boolean, a machine running an Apple Operating System */ read-only boolean, a machine running an Apple Operating System */
YAP_FLAG(APPLE_FLAG, "apple", false, booleanFlag, "true", NULL),
#else
YAP_FLAG(APPLE_FLAG, "apple", false, booleanFlag, "false", NULL),
#endif #endif
YAP_FLAG(ARCH_FLAG, "arch", false, isatom, YAP_ARCH, NULL), /**< /**<
read-only atom, it describes the ISA used in this version of YAP. read-only atom, it describes the ISA used in this version of YAP.
Available from YAP_ARCH. Available from YAP_ARCH.
*/ */
YAP_FLAG(ARCH_FLAG, "arch", false, isatom, YAP_ARCH, NULL),
YAP_FLAG(ARGV_FLAG, "argv", false, argv, "@boot", NULL), YAP_FLAG(ARGV_FLAG, "argv", false, argv, "@boot", NULL),
YAP_FLAG(ARITHMETIC_EXCEPTIONS_FLAG, "arithmetic_exceptions", true,
booleanFlag, "true", NULL),
/**< /**<
Read-write flag telling whether arithmetic exceptions generate Read-write flag telling whether arithmetic exceptions generate
@ -95,71 +108,79 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
It is `true` by default, but it is disabled by packages like CLP(BN) and It is `true` by default, but it is disabled by packages like CLP(BN) and
ProbLog. ProbLog.
*/ */
YAP_FLAG(BACK_QUOTES_FLAG, "back_quotes", true, isatom, "true", bqs), YAP_FLAG(ARITHMETIC_EXCEPTIONS_FLAG, "arithmetic_exceptions", true,
booleanFlag, "true", NULL),
/**< /**<
If _Value_ is unbound, tell whether a back quoted list of characters If _Value_ is unbound, tell whether a back quoted list of characters
token is converted to a list of atoms, `chars`, to a list of integers, token is converted to a list of atoms, `chars`, to a list of integers,
`codes`, or to a single atom, `atom`. If _Value_ is bound, set to `codes`, or to a single atom, `atom`. If _Value_ is bound, set to
the corresponding behavior. The default value is `string` the corresponding behavior. The default value is `string`
*/ */
YAP_FLAG(BOUNDED_FLAG, "bounded", false, booleanFlag, "false", NULL), YAP_FLAG(BACK_QUOTES_FLAG, "back_quotes", true, isatom, "true", bqs),
/**< `bounded` is iso
/**<
Read-only flag telling whether integers are bounded. The value depends Read-only flag telling whether integers are bounded. The value depends
on whether YAP uses the GMP library or not. on whether YAP uses the GMP library or not.
*/ */
YAP_FLAG(BOUNDED_FLAG, "bounded", false, booleanFlag, "false", NULL),
YAP_FLAG(C_CC_FLAG, "c_cc", false, isatom, C_CC, NULL), YAP_FLAG(C_CC_FLAG, "c_cc", false, isatom, C_CC, NULL),
YAP_FLAG(C_CFLAGS_FLAG, "c_cflags", false, isatom, C_CFLAGS, NULL), YAP_FLAG(C_CFLAGS_FLAG, "c_cflags", false, isatom, C_CFLAGS, NULL),
YAP_FLAG(C_LDFLAGS_FLAG, "c_ldflags", false, isatom, C_LDFLAGS, NULL), YAP_FLAG(C_LDFLAGS_FLAG, "c_ldflags", false, isatom, C_LDFLAGS, NULL),
YAP_FLAG(C_LIBPLSO_FLAG, "c_libplso", false, isatom, C_LIBPLSO, NULL), YAP_FLAG(C_LIBPLSO_FLAG, "c_libplso", false, isatom, C_LIBPLSO, NULL),
YAP_FLAG(C_LIBS_FLAG, "c_libs", false, isatom, C_LIBS, NULL), YAP_FLAG(C_LIBS_FLAG, "c_libs", false, isatom, C_LIBS, NULL),
YAP_FLAG(CHAR_CONVERSION_FLAG, "char_conversion", true, booleanFlag,
"false", NULL),
/**< `char_conversion is iso` /**< `char_conversion is iso`
Writable flag telling whether a character conversion table is used when Writable flag telling whether a character conversion table is used when
reading terms. The default value for this flag is `off` except in reading terms. The default value for this flag is `off` except in
`sicstus` and `iso` language modes, where it is `on`. `sicstus` and `iso` language modes, where it is `on`.
*/ */
YAP_FLAG(CHARACTER_ESCAPES_FLAG, "character_escapes", true, booleanFlag, YAP_FLAG(CHAR_CONVERSION_FLAG, "char_conversion", true, booleanFlag,
"true", NULL), "false", NULL),
/**< ` /**< `
Writable flag telling whether a character escapes are enabled, Writable flag telling whether a character escapes are enabled,
`true`, or disabled, `false`. The default value for this flag is `true`, or disabled, `false`. The default value for this flag is
`true`. */ `true`. */
YAP_FLAG(COLON_SETS_CALLING_CONTEXT_FLAG, "colon_sets_calling_context", YAP_FLAG(CHARACTER_ESCAPES_FLAG, "character_escapes", true, booleanFlag,
true, booleanFlag, "true", NULL), "true", NULL),
/**< `compiled_at ` /**< `compiled_at `
Read-only flag that gives the time when the main YAP binary was compiled. Read-only flag that gives the time when the main YAP binary was compiled.
It is obtained staight from the __TIME__ macro, as defined in the C99. It is obtained staight from the __TIME__ macro, as defined in the C99.
*/ */
YAP_FLAG(COLON_SETS_CALLING_CONTEXT_FLAG, "colon_sets_calling_context",
true, booleanFlag, "true", NULL),
YAP_FLAG(COMPILED_AT_FLAG, "compiled_at", false, isatom, YAP_COMPILED_AT, YAP_FLAG(COMPILED_AT_FLAG, "compiled_at", false, isatom, YAP_COMPILED_AT,
NULL), NULL),
YAP_FLAG(DEBUG_FLAG, "debug", true, booleanFlag, "false", NULL),
/**< /**<
If _Value_ is unbound, tell whether debugging is `true` or If _Value_ is unbound, tell whether debugging is `true` or
`false`. If _Value_ is bound to `true` enable debugging, and if `false`. If _Value_ is bound to `true` enable debugging, and if
it is bound to `false` disable debugging. it is bound to `false` disable debugging.
*/ */
YAP_FLAG(DEBUG_FLAG, "debug", true, booleanFlag, "false", NULL),
YAP_FLAG(DEBUG_INFO_FLAG, "debug_info", true, booleanFlag, "true", NULL), YAP_FLAG(DEBUG_INFO_FLAG, "debug_info", true, booleanFlag, "true", NULL),
YAP_FLAG(DEBUG_ON_ERROR_FLAG, "debug_on_error", true, booleanFlag, "true",
NULL),
/**< /**<
If bound, set the argument to the `write_term/3` options the If bound, set the argument to the `write_term/3` options the
debugger uses to write terms. If unbound, show the current options. debugger uses to write terms. If unbound, show the current options.
*/ */
YAP_FLAG(DEBUG_ON_ERROR_FLAG, "debug_on_error", true, booleanFlag, "true",
NULL),
YAP_FLAG(DEBUGGER_PRINT_OPTIONS_FLAG, "debugger_print_options", true, YAP_FLAG(DEBUGGER_PRINT_OPTIONS_FLAG, "debugger_print_options", true,
list_option, list_option,
"[quoted(true),numbervars(true),portrayed(true),max_depth(10)]", "[quoted(true),numbervars(true),portrayed(true),max_depth(10)]",
NULL), NULL),
YAP_FLAG(DEBUGGER_SHOW_CONTEXT_FLAG, "debugger_show_context", true, YAP_FLAG(DEBUGGER_SHOW_CONTEXT_FLAG, "debugger_show_context", true,
booleanFlag, "false", NULL), booleanFlag, "false", NULL),
YAP_FLAG(DEFAULT_PARENT_MODULE_FLAG, "default_parent_module", true, isatom,
"user", NULL),
/**< /**<
* A module to be inherited by all other modules. Default is user that * A module to be inherited by all other modules. Default is user that
* reexports prolog. * reexports prolog.
@ -167,13 +188,15 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
* Set it to `prolog` for SICStus Prolog like resolution, to `user` for * Set it to `prolog` for SICStus Prolog like resolution, to `user` for
* SWI-like. * SWI-like.
*/ */
YAP_FLAG(DIALECT_FLAG, "dialect", false, ro, "yap", NULL), YAP_FLAG(DEFAULT_PARENT_MODULE_FLAG, "default_parent_module", true, isatom,
"user", NULL),
/**< /**<
Read-only flag that always returns `yap`. Read-only flag that always returns `yap`.
*/ */
YAP_FLAG(DISCONTIGUOUS_WARNINGS_FLAG, "discontiguous_warnings", true, YAP_FLAG(DIALECT_FLAG, "dialect", false, ro, "yap", NULL),
booleanFlag, "true", NULL),
/**< /**<
If `true` (default `true`) YAP checks for definitions of the same predicate If `true` (default `true`) YAP checks for definitions of the same predicate
@ -184,35 +207,41 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
predicates. predicates.
*/ */
YAP_FLAG(DOLLAR_AS_LOWER_CASE_FLAG, "dollar_as_lower_case", true, YAP_FLAG(DISCONTIGUOUS_WARNINGS_FLAG, "discontiguous_warnings", true,
booleanFlag, "false", NULL), booleanFlag, "true", NULL),
/**< /**<
If `off` (default) consider the character `$` a control character, if If `off` (default) consider the character `$` a control character, if
vxu `on` consider `$` a lower case character. vxu `on` consider `$` a lower case character.
*/ */
YAP_FLAG(DOUBLE_QUOTES_FLAG, "double_quotes", true, isatom, "codes", dqs), YAP_FLAG(DOLLAR_AS_LOWER_CASE_FLAG, "dollar_as_lower_case", true,
booleanFlag, "false", NULL),
/**< iso /**< iso
If _Value_ is unbound, tell whether a double quoted list of characters If _Value_ is unbound, tell whether a double quoted list of characters
token is converted to a list of atoms, `chars`, to a list of integers, token is converted to a list of atoms, `chars`, to a list of integers,
`codes`, or to a single atom, `atom`. If _Value_ is bound, set to `codes`, or to a single atom, `atom`. If _Value_ is bound, set to
the corresponding behavior. The default value is `codes`. */ the corresponding behavior. The default value is `codes`. */
YAP_FLAG(DOUBLE_QUOTES_FLAG, "double_quotes", true, isatom, "codes", dqs),
YAP_FLAG(EDITOR_FLAG, "editor", true, isatom, "$EDITOR", NULL), YAP_FLAG(EDITOR_FLAG, "editor", true, isatom, "$EDITOR", NULL),
YAP_FLAG(EXECUTABLE_FLAG, "executable", false, executable, "@boot", NULL),
/**< /**<
Read-only flag. It unifies with an atom that gives the Read-only flag. It unifies with an atom that gives the
original program path. original program path.
*/ */
YAP_FLAG(FAST_FLAG, "fast", true, booleanFlag, "false", NULL), YAP_FLAG(EXECUTABLE_FLAG, "executable", false, executable, "@boot", NULL),
/**< /**<
If `on` allow fast machine code, if `off` (default) disable it. Only If `on` allow fast machine code, if `off` (default) disable it. Only
available in experimental implementations. available in experimental implementations.
*/ */
YAP_FLAG(FAST_FLAG, "fast", true, booleanFlag, "false", NULL),
YAP_FLAG(FILE_NAME_VARIABLES_FLAG, "file_name_variables", true, booleanFlag, YAP_FLAG(FILE_NAME_VARIABLES_FLAG, "file_name_variables", true, booleanFlag,
"true", NULL), "true", NULL),
YAP_FLAG(FLOAT_FORMAT_FLAG, "float_format", true, isatom, "%.16f", NULL),
/**< /**<
C-library `printf()` format specification used by write/1 and C-library `printf()` format specification used by write/1 and
@ -222,19 +251,22 @@ vxu `on` consider `$` a lower case character.
printed, `%g` will print all floats using 6 digits instead of the printed, `%g` will print all floats using 6 digits instead of the
default 15. default 15.
*/ */
YAP_FLAG(GC_FLAG, "gc", true, booleanFlag, "on", NULL), YAP_FLAG(FLOAT_FORMAT_FLAG, "float_format", true, isatom, "%.16f", NULL),
/**< `gc` /**< `gc`
If `on` allow garbage collection (default), if `off` disable it. If `on` allow garbage collection (default), if `off` disable it.
*/ */
YAP_FLAG(GC_MARGIN_FLAG, "gc_margin", true, nat, "0", gc_margin), YAP_FLAG(GC_FLAG, "gc", true, booleanFlag, "on", NULL),
/**< `gc_margin ` /**< `gc_margin `
Set or show the minimum free stack before starting garbage Set or show the minimum free stack before starting garbage
collection. The default depends on total stack size. collection. The default depends on total stack size.
*/ */
YAP_FLAG(GC_TRACE_FLAG, "gc_trace", true, isatom, "off", NULL), YAP_FLAG(GC_MARGIN_FLAG, "gc_margin", true, nat, "0", gc_margin),
/**< /**<
* *
If `off` (default) do not show information on garbage collection If `off` (default) do not show information on garbage collection
@ -244,8 +276,8 @@ vxu `on` consider `$` a lower case character.
information on data-structures found during the garbage collection information on data-structures found during the garbage collection
process, namely, on choice-points. process, namely, on choice-points.
*/ */
YAP_FLAG(GENERATE_DEBUGGING_INFO_FLAG, "generate_debug_info", true, YAP_FLAG(GC_TRACE_FLAG, "gc_trace", true, isatom, "off", NULL),
booleanFlag, "true", NULL),
/**< ` /**< `
If `true` (default) generate debugging information for If `true` (default) generate debugging information for
@ -254,36 +286,41 @@ vxu `on` consider `$` a lower case character.
source mode is disabled. source mode is disabled.
*/ */
YAP_FLAG(GENERATE_DEBUGGING_INFO_FLAG, "generate_debug_info", true,
booleanFlag, "true", NULL),
YAP_FLAG(GMP_VERSION_FLAG, "gmp_version", false, isatom, "4.8.12", NULL), YAP_FLAG(GMP_VERSION_FLAG, "gmp_version", false, isatom, "4.8.12", NULL),
YAP_FLAG(HALT_AFTER_CONSULT_FLAG, "halt_after_consult", false, booleanFlag, YAP_FLAG(HALT_AFTER_CONSULT_FLAG, "halt_after_consult", false, booleanFlag,
"false", NULL), "false", NULL),
YAP_FLAG(HOME_FLAG, "home", false, isatom, YAP_ROOTDIR, NULL),
/**< home ` /**< home `
the root of the YAP installation, by default `/usr/local` in Unix or the root of the YAP installation, by default `/usr/local` in Unix or
`c:\Yap` in Windows system. Can only be set at configure time `c:\Yap` in Windows system. Can only be set at configure time
*/ */
YAP_FLAG(HOST_TYPE_FLAG, "host_type", false, isatom, HOST_ALIAS, NULL), YAP_FLAG(HOME_FLAG, "home", false, isatom, YAP_ROOTDIR, NULL),
/**< host_type ` /**< host_type `
Return `configure` system information, including the machine-id Return `configure` system information, including the machine-id
for which YAP was compiled and Operating System information. for which YAP was compiled and Operating System information.
*/ */
YAP_FLAG(INDEX_FLAG, "index", true, indexer, "multi", NULL), YAP_FLAG(HOST_TYPE_FLAG, "host_type", false, isatom, HOST_ALIAS, NULL),
/**< `index ` /**< `index `
If `on` allow indexing (default), if `off` disable it, if If `on` allow indexing (default), if `off` disable it, if
`single` allow on first argument only. `single` allow on first argument only.
*/ */
YAP_FLAG(INDEX_SUB_TERM_SEARCH_DEPTH_FLAG, "index_sub_term_search_depth", YAP_FLAG(INDEX_FLAG, "index", true, indexer, "multi", NULL),
true, nat, "0", NULL),
/**< `Index_sub_term_search_depth ` /**< `Index_sub_term_search_depth `
Maximum bound on searching sub-terms for indexing, if `0` (default) no Maximum bound on searching sub-terms for indexing, if `0` (default) no
bound. bound.
*/ */
YAP_FLAG(INFORMATIONAL_MESSAGES_FLAG, "informational_messages", true, YAP_FLAG(INDEX_SUB_TERM_SEARCH_DEPTH_FLAG, "index_sub_term_search_depth",
isatom, "normal", NULL), true, nat, "0", NULL),
/**< `informational_messages ` /**< `informational_messages `
If `on` allow printing of informational messages, such as the ones If `on` allow printing of informational messages, such as the ones
@ -291,17 +328,21 @@ vxu `on` consider `$` a lower case character.
these messages. It is `on` by default except if YAP is booted with these messages. It is `on` by default except if YAP is booted with
the `-L` flag. the `-L` flag.
*/ */
YAP_FLAG(INTEGER_ROUNDING_FUNCTION_FLAG, "integer_rounding_function", true, YAP_FLAG(INFORMATIONAL_MESSAGES_FLAG, "informational_messages", true,
isatom, "toward_zero", NULL), isatom, "normal", NULL),
/**< `integer_rounding_function is iso ` /**< `integer_rounding_function is iso `
Read-only flag telling the rounding function used for integers. Takes the Read-only flag telling the rounding function used for integers. Takes the
value `toward_zero` for the current version of YAP. value `toward_zero` for the current version of YAP.
*/ */
YAP_FLAG(INTEGER_ROUNDING_FUNCTION_FLAG, "integer_rounding_function", true,
isatom, "toward_zero", NULL),
YAP_FLAG(ISO_FLAG, "iso", true, booleanFlag, "false", NULL), YAP_FLAG(ISO_FLAG, "iso", true, booleanFlag, "false", NULL),
YAP_FLAG(JUPYTER_FLAG, "jupyter", false, booleanFlag, "true", NULL), /**< /**<
read-only boolean, a machine running Jupyter */ read-only boolean, a machine running Jupyter */
YAP_FLAG(LANGUAGE_FLAG, "language", true, isatom, "yap", NULL), YAP_FLAG(JUPYTER_FLAG, "jupyter", false, booleanFlag, "true", NULL),
/**< `language ` /**< `language `
Choose whether YAP follows native, closer to C-Prolog, `yap`, iso-prolog, Choose whether YAP follows native, closer to C-Prolog, `yap`, iso-prolog,
@ -311,21 +352,26 @@ vxu `on` consider `$` a lower case character.
are interpreted, when to use dynamic, character escapes, and how files are interpreted, when to use dynamic, character escapes, and how files
are consulted. Also check the `dialect` option. are consulted. Also check the `dialect` option.
*/ */
YAP_FLAG(PROLOG_LIBRARY_DIRECTORY_FLAG, "prolog_library_directory", true, YAP_FLAG(LANGUAGE_FLAG, "language", true, isatom, "yap", NULL),
isatom, "", NULL),
/**< if defined, first location where YAP expects to find the YAP Prolog /**< if defined, first location where YAP expects to find the YAP Prolog
library. Takes precedence over library_directory */ library. Takes precedence over library_directory */
YAP_FLAG(PROLOG_FOREIGN_DIRECTORY_FLAG, "prolog_foreign_directory", true, YAP_FLAG(PROLOG_LIBRARY_DIRECTORY_FLAG, "prolog_library_directory", true,
isatom, "", NULL), isatom, "", NULL),
/**< if defined, first location where YAP expects to find the YAP Prolog /**< if defined, first location where YAP expects to find the YAP Prolog
shared libraries (DLLS). Takes precedence over executable_directory/2. */ shared libraries (DLLS). Takes precedence over executable_directory/2. */
/**< `max_arity is iso ` /**< `max_arity is iso `
YAP_FLAG(MAX_ARITY_FLAG, "max_arity", false, isatom, "unbounded", NULL), YAP_FLAG(MAX_ARITY_FLAG, "max_arity", false, isatom, "unbounded", NULL),
Read-only flag telling the maximum arity of a functor. Takes the value Read-only flag telling the maximum arity of a functor. Takes the value
`unbounded` for the current version of YAP. `unbounded` for the current version of YAP.
*/ */
YAP_FLAG(PROLOG_FOREIGN_DIRECTORY_FLAG, "prolog_foreign_directory", true,
isatom, "", NULL),
YAP_FLAG(MAX_TAGGED_INTEGER_FLAG, "max_tagged_integer", false, at2n, YAP_FLAG(MAX_TAGGED_INTEGER_FLAG, "max_tagged_integer", false, at2n,
"INT_MAX", NULL), "INT_MAX", NULL),
YAP_FLAG(MAX_THREADS_FLAG, "max_threads", false, at2n, "MAX_THREADS", NULL), YAP_FLAG(MAX_THREADS_FLAG, "max_threads", false, at2n, "MAX_THREADS", NULL),
@ -336,16 +382,15 @@ vxu `on` consider `$` a lower case character.
"256", NULL), "256", NULL),
YAP_FLAG(OCCURS_CHECK_FLAG, "occurs_check", true, booleanFlag, "false", YAP_FLAG(OCCURS_CHECK_FLAG, "occurs_check", true, booleanFlag, "false",
NULL), NULL),
YAP_FLAG(OPEN_EXPANDS_FILENAME_FLAG, "open_expands_filename", true,
booleanFlag, "false", NULL),
/**< `open_expands_filename ` /**< `open_expands_filename `
If `true` the open/3 builtin performs filename-expansion If `true` the open/3 builtin performs filename-expansion
before opening a file (SICStus Prolog like). If `false` it does not before opening a file (SICStus Prolog like). If `false` it does not
(SWI-Prolog like). (SWI-Prolog like).
*/ */
YAP_FLAG(OPEN_SHARED_OBJECT_FLAG, "open_shared_object", true, booleanFlag, YAP_FLAG(OPEN_EXPANDS_FILENAME_FLAG, "open_expands_filename", true,
"true", NULL), booleanFlag, "false", NULL),
/**< `open_shared_object ` /**< `open_shared_object `
If true, `open_shared_object/2` and friends are implemented, If true, `open_shared_object/2` and friends are implemented,
@ -358,6 +403,10 @@ vxu `on` consider `$` a lower case character.
program. This is for compatibility with old software that program. This is for compatibility with old software that
might expect module-independent operators. might expect module-independent operators.
*/ */
YAP_FLAG(OPEN_SHARED_OBJECT_FLAG, "open_shared_object", true, booleanFlag,
"true", NULL),
YAP_FLAG(MODULE_INDEPENDENT_OPERATORS_FLAG, "module_independent_operators", YAP_FLAG(MODULE_INDEPENDENT_OPERATORS_FLAG, "module_independent_operators",
true, booleanFlag, "false", NULL), true, booleanFlag, "false", NULL),
@ -365,7 +414,6 @@ vxu `on` consider `$` a lower case character.
YAP_FLAG(OS_ARGV_FLAG, "os_argv", false, os_argv, "@boot", NULL), YAP_FLAG(OS_ARGV_FLAG, "os_argv", false, os_argv, "@boot", NULL),
YAP_FLAG(PID_FLAG, "pid", false, sys_pid, "@boot", NULL), YAP_FLAG(PID_FLAG, "pid", false, sys_pid, "@boot", NULL),
YAP_FLAG(PIPE_FLAG, "pipe", true, booleanFlag, "true", NULL), YAP_FLAG(PIPE_FLAG, "pipe", true, booleanFlag, "true", NULL),
YAP_FLAG(PROFILING_FLAG, "profiling", true, booleanFlag, "false", NULL),
/**< `profiling ` /**< `profiling `
If `off` (default) do not compile call counting information for If `off` (default) do not compile call counting information for
@ -373,8 +421,8 @@ vxu `on` consider `$` a lower case character.
retries to the predicate may be counted. Profiling data can be read through retries to the predicate may be counted. Profiling data can be read through
the call_count_data/3 built-in. the call_count_data/3 built-in.
*/ */
YAP_FLAG(PROMPT_ALTERNATIVES_ON_FLAG, "prompt_alternatives_on", true, YAP_FLAG(PROFILING_FLAG, "profiling", true, booleanFlag, "false", NULL),
isatom, "determinism", NULL),
/**< `prompt_alternatives_on(atom, /**< `prompt_alternatives_on(atom,
changeable) ` changeable) `
@ -383,17 +431,20 @@ vxu `on` consider `$` a lower case character.
and only if the query contains variables. The alternative, default in and only if the query contains variables. The alternative, default in
SWI-Prolog is <tt>determinism</tt> which implies the system prompts for SWI-Prolog is <tt>determinism</tt> which implies the system prompts for
alternatives if the goal succeeded while leaving choicepoints. */ alternatives if the goal succeeded while leaving choicepoints. */
YAP_FLAG(PROMPT_ALTERNATIVES_ON_FLAG, "prompt_alternatives_on", true,
isatom, "determinism", NULL),
YAP_FLAG(QUASI_QUOTATIONS_FLAG, "quasi_quotations", true, booleanFlag, YAP_FLAG(QUASI_QUOTATIONS_FLAG, "quasi_quotations", true, booleanFlag,
"true", NULL), "true", NULL),
YAP_FLAG(READLINE_FLAG, "readline", true, booleanFlag, "false",
Yap_InitReadline),
/**< `readline(boolean, changeable)` /**< `readline(boolean, changeable)`
} }
enable the use of the readline library for console interactions, true by enable the use of the readline library for console interactions, true by
default if readline was found. */ default if readline was found. */
YAP_FLAG(REDEFINE_WARNINGS_FLAG, "redefine_warnings", true, booleanFlag, YAP_FLAG(READLINE_FLAG, "readline", true, booleanFlag, "false",
"true", NULL), /**< Yap_InitReadline),
/**<
If _Value_ is unbound, tell whether warnings for procedures defined If _Value_ is unbound, tell whether warnings for procedures defined
in several different files are `on` or in several different files are `on` or
@ -401,43 +452,50 @@ in several different files are `on` or
and if it is bound to `off` disable them. The default for YAP is and if it is bound to `off` disable them. The default for YAP is
`off`, unless we are in `sicstus` or `iso` mode. `off`, unless we are in `sicstus` or `iso` mode.
*/ */
YAP_FLAG(REDEFINE_WARNINGS_FLAG, "redefine_warnings", true, booleanFlag,
"true", NULL),
YAP_FLAG(REPORT_ERROR_FLAG, "report_error", true, booleanFlag, "true", YAP_FLAG(REPORT_ERROR_FLAG, "report_error", true, booleanFlag, "true",
NULL), NULL),
YAP_FLAG(RESOURCE_DATABASE_FLAG, "resource_database", false, isatom,
YAP_BOOTSTRAP, NULL),
/**<`resource_database` /**<`resource_database`
Name of the resource file (saved-state or Prolog file) used to construct Name of the resource file (saved-state or Prolog file) used to construct
the YAP the YAP
run-time environment. run-time environment.
*/ */
YAP_FLAG(SAVED_PROGRAM_FLAG, "saved_program", false, booleanFlag, "false", YAP_FLAG(RESOURCE_DATABASE_FLAG, "resource_database", false, isatom,
NULL),
YAP_BOOTSTRAP, NULL),
/**<`saved_program` /**<`saved_program`
if `true` YAP booted from a `yss` file, usually `startup.yss'. If if `true` YAP booted from a `yss` file, usually `startup.yss'. If
`false`, YAP booted from a Prolog file, by default `boot.yap`. `false`, YAP booted from a Prolog file, by default `boot.yap`.
*/ */
YAP_FLAG(SHARED_OBJECT_EXTENSION_FLAG, "shared_object_extension", false, YAP_FLAG(SAVED_PROGRAM_FLAG, "saved_program", false, booleanFlag, "false",
isatom, SO_EXT, NULL), NULL),
/**< `shared_object_extension ` /**< `shared_object_extension `
Suffix associated with loadable code. Suffix associated with loadable code.
*/ */
YAP_FLAG(SHARED_OBJECT_SEARCH_PATH_FLAG, "shared_object_search_path", true, YAP_FLAG(SHARED_OBJECT_EXTENSION_FLAG, "shared_object_extension", false,
isatom, SO_PATH, NULL), isatom, SO_EXT, NULL),
/**< `shared_object_search_path `
/**<
Name of the environment variable used by the system to search for shared Name of the environment variable used by the system to search for shared
objects. objects.
*/ */
YAP_FLAG(SINGLE_QUOTES_FLAG, "single_quotes", true, isatom, "atom", sqf), YAP_FLAG(SHARED_OBJECT_SEARCH_PATH_FLAG, "shared_object_search_path", true,
/**< `single_quoted text is usuallly interpreted as atoms. This flagTerm isatom, SO_PATH, NULL),
allows other inerpretations such as strings_contains_strings */
YAP_FLAG(SINGLE_VAR_WARNINGS_FLAG, "single_var_warnings", true, booleanFlag, /**< single_quoted text is usuallly interpreted as atoms. This flag
"true", NULL), /**< allows other interpretations such as strings */
YAP_FLAG(SINGLE_QUOTES_FLAG, "single_quotes", true, isatom, "atom", sqf),
/**<
If `true` (default `true`) YAP checks for singleton If `true` (default `true`) YAP checks for singleton
variables when loading files. A singleton variable is a variables when loading files. A singleton variable is a
variable that appears ony once in a clause. The name variable that appears ony once in a clause. The name
@ -445,21 +503,24 @@ and if it is bound to `off` disable them. The default for YAP is
starts with underscore are never considered singleton. starts with underscore are never considered singleton.
*/ */
YAP_FLAG(SIGNALS_FLAG, "signals", true, booleanFlag, "true", NULL), YAP_FLAG(SINGLE_VAR_WARNINGS_FLAG, "single_var_warnings", true, booleanFlag,
/**< `signals` "true", NULL),
/**<
If `true` (default) YAP handles Signals such as `^C` If `true` (default) YAP handles Signals such as `^C`
(`SIGINT`). (`SIGINT`).
*/ */
YAP_FLAG(SOURCE_FLAG, "source", true, booleanFlag, "true", NULL), YAP_FLAG(SIGNALS_FLAG, "signals", true, booleanFlag, "true", NULL),
/**< `source`
/**<
If `true` maintain the source for all clauses. Notice that this is trivially If `true` maintain the source for all clauses. Notice that this is trivially
supported for facts, and always supported for dynamic code. supported for facts, and always supported for dynamic code.
*/ */
YAP_FLAG(STRICT_ISO_FLAG, "strict_iso", true, booleanFlag, "false", NULL), YAP_FLAG(SOURCE_FLAG, "source", true, booleanFlag, "true", NULL),
/**< `strict_iso ` /**< `strict_iso `
If _Value_ is unbound, tell whether strict ISO compatibility mode If _Value_ is unbound, tell whether strict ISO compatibility mode
@ -482,8 +543,8 @@ and if it is bound to `off` disable them. The default for YAP is
depends on a Prolog's platform specific features. depends on a Prolog's platform specific features.
*/ */
YAP_FLAG(SYSTEM_OPTIONS_FLAG, "system_options", false, options, YAP_FLAG(STRICT_ISO_FLAG, "strict_iso", true, booleanFlag, "false", NULL),
SYSTEM_OPTIONS, NULL),
/**< `system_options ` /**< `system_options `
This read only flag tells which options were used to compile This read only flag tells which options were used to compile
@ -492,19 +553,21 @@ and if it is bound to `off` disable them. The default for YAP is
`or-parallelism`, `rational_trees`, `readline`, `tabling`, `or-parallelism`, `rational_trees`, `readline`, `tabling`,
`threads`, or the `wam_profiler`. `threads`, or the `wam_profiler`.
*/ */
YAP_FLAG(SYSTEM_OPTIONS_FLAG, "system_options", false, options,
SYSTEM_OPTIONS, NULL),
YAP_FLAG(SYSTEM_THREAD_ID_FLAG, "system_thread_id", false, sys_thread_id, YAP_FLAG(SYSTEM_THREAD_ID_FLAG, "system_thread_id", false, sys_thread_id,
"@boot", NULL), "@boot", NULL),
YAP_FLAG(TABLING_MODE_FLAG, "tabling_mode", true, isatom, "[]", NULL),
/**< `tabling_mode` /**< `tabling_mode`
Sets or reads the tabling mode for all tabled predicates. Please Sets or reads the tabling mode for all tabled predicates. Please
(see Tabling) for the list of options. (see Tabling) for the list of options.
*/ */
YAP_FLAG(TABLING_MODE_FLAG, "tabling_mode", true, isatom, "[]", NULL),
YAP_FLAG(THREADS_FLAG, "threads", false, ro, "MAX_THREADS", NULL), YAP_FLAG(THREADS_FLAG, "threads", false, ro, "MAX_THREADS", NULL),
YAP_FLAG(TIMEZONE_FLAG, "timezone", false, ro, "18000", NULL), YAP_FLAG(TIMEZONE_FLAG, "timezone", false, ro, "18000", NULL),
YAP_FLAG(TOPLEVEL_HOOK_FLAG, "toplevel_hook", true, booleanFlag, "true",
NULL),
/**< `toplevel_hook ` /**< `toplevel_hook `
If bound, set the argument to a goal to be executed before entering the If bound, set the argument to a goal to be executed before entering the
@ -513,6 +576,9 @@ and if it is bound to `off` disable them. The default for YAP is
backtracked into. backtracked into.
*/ */
YAP_FLAG(TOPLEVEL_HOOK_FLAG, "toplevel_hook", true, booleanFlag, "true",
NULL),
YAP_FLAG(TOPLEVEL_PRINT_ANON_FLAG, "toplevel_print_anon", true, booleanFlag, YAP_FLAG(TOPLEVEL_PRINT_ANON_FLAG, "toplevel_print_anon", true, booleanFlag,
"true", NULL), "true", NULL),
YAP_FLAG(TOPLEVEL_PRINT_OPTIONS_FLAG, "toplevel_print_options", true, YAP_FLAG(TOPLEVEL_PRINT_OPTIONS_FLAG, "toplevel_print_options", true,
@ -521,7 +587,6 @@ and if it is bound to `off` disable them. The default for YAP is
YAP_FLAG(TOPLEVEL_PROMPT_FLAG, "toplevel_prompt", true, isatom, "?- ", YAP_FLAG(TOPLEVEL_PROMPT_FLAG, "toplevel_prompt", true, isatom, "?- ",
mkprompt), mkprompt),
YAP_FLAG(TTY_CONTROL_FLAG, "tty_control", true, booleanFlag, "true", NULL), YAP_FLAG(TTY_CONTROL_FLAG, "tty_control", true, booleanFlag, "true", NULL),
YAP_FLAG(UNIX_FLAG, "unix", false, ro, "true", NULL),
/**< `unix` /**< `unix`
Read-only BooleanFlag flag that unifies with `true` if YAP is Read-only BooleanFlag flag that unifies with `true` if YAP is
@ -537,9 +602,11 @@ and if it is bound to `off` disable them. The default for YAP is
procedures follow logical semantics but the internal data base still procedures follow logical semantics but the internal data base still
follows immediate semantics. follows immediate semantics.
*/ */
YAP_FLAG(UNIX_FLAG, "unix", false, ro, "true", NULL),
YAP_FLAG(UPDATE_SEMANTICS_FLAG, "update_semantics", true, isatom, "logical", YAP_FLAG(UPDATE_SEMANTICS_FLAG, "update_semantics", true, isatom, "logical",
NULL), NULL),
YAP_FLAG(USER_FLAGS_FLAG, "user_flags", true, isatom, "error", NULL),
/**< /**<
`user_flags ` `user_flags `
@ -551,18 +618,20 @@ and if it is bound to `off` disable them. The default for YAP is
developers are encouraged to use `create_prolog_flag/3` to create flags for developers are encouraged to use `create_prolog_flag/3` to create flags for
their library. their library.
*/ */
YAP_FLAG(UNKNOWN_FLAG, "unknown", true, isatom, "error", Yap_unknown), YAP_FLAG(USER_FLAGS_FLAG, "user_flags", true, isatom, "error", NULL),
/**< `unknown is iso` /**< `unknown is iso`
Corresponds to calling the unknown/2 built-in. Possible ISO values Corresponds to calling the unknown/2 built-in. Possible ISO values
are `error`, `fail`, and `warning`. Yap includes the following extensions: are `error`, `fail`, and `warning`. Yap includes the following extensions:
`fast_fail` does not invoke any handler. `fast_fail` does not invoke any handler.
*/ */
YAP_FLAG(UNKNOWN_FLAG, "unknown", true, isatom, "error", Yap_unknown),
YAP_FLAG(VARIABLE_NAMES_MAY_END_WITH_QUOTES_FLAG, YAP_FLAG(VARIABLE_NAMES_MAY_END_WITH_QUOTES_FLAG,
"variable_names_may_end_with_quotes", true, booleanFlag, "false", "variable_names_may_end_with_quotes", true, booleanFlag, "false",
NULL), NULL),
YAP_FLAG(VERBOSE_FLAG, "verbose", true, isatom, "normal", NULL), /**<
/**< `verbose `
If `normal` allow printing of informational and banner messages, If `normal` allow printing of informational and banner messages,
such as the ones that are printed when consulting. If `silent` such as the ones that are printed when consulting. If `silent`
@ -570,66 +639,75 @@ and if it is bound to `off` disable them. The default for YAP is
YAP is booted with the `-q` or `-L` flag. YAP is booted with the `-q` or `-L` flag.
*/ */
YAP_FLAG(VERBOSE_FILE_SEARCH_FLAG, "verbose_file_search", true, booleanFlag, YAP_FLAG(VERBOSE_FLAG, "verbose", true, isatom, "normal", NULL),
"false", NULL),
/**< `verbose_file_search ` /**<
If `true` allow printing of informational messages when If `true` allow printing of informational messages when
searching for file names. If `false` disable printing these messages. It searching for file names. If `false` disable printing these messages. It
is `false` by default except if YAP is booted with the `-L` is `false` by default except if YAP is booted with the `-L`
flag. flag.
*/ */
YAP_FLAG(VERBOSE_LOAD_FLAG, "verbose_load", true, isatom, "normal", NULL), YAP_FLAG(VERBOSE_FILE_SEARCH_FLAG, "verbose_file_search", true, booleanFlag,
/**< `verbose_load ` "false", NULL),
/**<
If `true` allow printing of informational messages when If `true` allow printing of informational messages when
consulting files. If `false` disable printing these messages. It consulting files. If `false` disable printing these messages. It
is `normal` by default except if YAP is booted with the `-L` is `true` by default except if YAP is booted with the `-L`
flag. flag.
*/ */
YAP_FLAG(VERSION_FLAG, "version", false, nat, YAP_NUMERIC_VERSION, NULL), YAP_FLAG(VERBOSE_LOAD_FLAG, "verbose_load", true, booleanFlag, "true", NULL),
/**< /**<
`version ` Read-only flag that returns a compound term with the Read-only flag that returns a compound term with the
current version of YAP. The term will have the name `yap` and arity 4, the current version of YAP. The term will have the name `yap` and arity 4, the
first argument will be the major version, the second the minor version, the first argument will be the major version, the second the minor version, the
third the patch number, and the last one is reserved. third the patch number, and the last one is reserved.
*/ */
YAP_FLAG(VERSION_DATA_FLAG, "version_data", false, ro, YAP_TVERSION, NULL), YAP_FLAG(VERSION_FLAG, "version", false, nat, YAP_NUMERIC_VERSION, NULL),
/**< `version_data `
/**<
Read-only flag that unifies with a number of the form Read-only flag that unifies with a number of the form
`_Major_ * 100000 + _Minor_ *100 + _Patch_`, where `_Major_ * 100000 + _Minor_ *100 + _Patch_`, where
_Major_ is the major version, _Minor_ is the minor version, _Major_ is the major version, _Minor_ is the minor version,
and _Patch_ is the patch number. and _Patch_ is the patch number.
*/ */
YAP_FLAG(VERSION_GIT_FLAG, "version_git", false, isatom, YAP_GIT_HEAD, YAP_FLAG(VERSION_DATA_FLAG, "version_data", false, ro, YAP_TVERSION, NULL),
NULL),
/**< `version_git ` /**<
` `
this is the unique identifier for the last commit of the current GIT HEAD, this is the unique identifier for the last commit of the current GIT HEAD,
it xan be used to identify versions that differ on small (or large) updates. it xan be used to identify versions that differ on small (or large) updates.
*/ */
YAP_FLAG(WRITE_ATTRIBUTES_FLAG, "write_attributes", true, isatom, "ignore", YAP_FLAG(VERSION_GIT_FLAG, "version_git", false, isatom, YAP_GIT_HEAD,
NULL), NULL),
#if __WINDOWS__
/**< `windows` /**<
Read-only booleanFlag flag that unifies with `true` if YAP is Read-only booleanFlag flag that unifies with `true` if YAP is
running on an Windows machine. running on an Windows machine.
*/ */
YAP_FLAG(WRITE_ATTRIBUTES_FLAG, "write_attributes", true, isatom, "ignore",
NULL),
#if __WINDOWS__
YAP_FLAG(WINDOWS_FLAG, "windows", false, ro, "true", NULL), YAP_FLAG(WINDOWS_FLAG, "windows", false, ro, "true", NULL),
#endif #endif
YAP_FLAG(WRITE_STRINGS_FLAG, "write_strings", true, booleanFlag, "false", /**<
NULL),
/**< `write_strings `
Writable flag telling whether the system should write lists of Writable flag telling whether the system should write lists of
integers that are writable character codes using the list notation. It integers that are writable character codes using the list notation. It
is `on` if enables or `off` if disabled. The default value for is `on` if enables or `off` if disabled. The default value for
this flag is `off`. this flag is `off`.
*/ */
YAP_FLAG(WRITE_STRINGS_FLAG, "write_strings", true, booleanFlag, "false",
NULL),
END_GLOBAL_FLAGS END_GLOBAL_FLAGS
//! @} //! @}

View File

@ -218,9 +218,9 @@ INLINE_ONLY yhandle_t Yap_InitHandle__(Term t USES_REGS) {
ensure_slots(1 PASS_REGS); ensure_slots(1 PASS_REGS);
if (t==0) { if (t==0) {
t = MkVarTerm(); t = MkVarTerm();
} else if (IsVarTerm(t) ) { } else if (IsVarTerm(t) && VarOfTerm(t) > HR ) {
Term tg = MkVarTerm(); Term tg = MkVarTerm();
Bind_Global( VarOfTerm(t), tg); Bind_Local(VarOfTerm(t), tg);
} }
LOCAL_HandleBase[old_slots] = t; LOCAL_HandleBase[old_slots] = t;
LOCAL_CurHandle++; LOCAL_CurHandle++;

View File

@ -1,5 +1,3 @@
/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog * * YAP Prolog *
@ -28,13 +26,13 @@
START_LOCAL_FLAGS START_LOCAL_FLAGS
/** + `autoload`: set the system to look for undefined procedures */ /**< set the system to look for undefined procedures */
YAP_FLAG(AUTOLOAD_FLAG, "autoload", true, booleanFlag, "false", NULL), YAP_FLAG(AUTOLOAD_FLAG, "autoload", true, booleanFlag, "false", NULL),
/** + `read-only flag, that tells if Prolog is in an inner top-level */
YAP_FLAG(BREAK_LEVEL_FLAG, "break_level", true, nat, "0", NULL),
YAP_FLAG(CALL_COUNTING_FLAG, "call_counting", true, booleanFlag, "true",
NULL), /** + `call_counting`
/**<`read-only flag, that tells if Prolog is in an inner top-level */
YAP_FLAG(BREAK_LEVEL_FLAG, "break_level", true, nat, "0", NULL),
/**<
Predicates compiled with this flag set maintain a counter Predicates compiled with this flag set maintain a counter
on the numbers of proceduree calls and of retries. These counters on the numbers of proceduree calls and of retries. These counters
are decreasing counters, and they can be used as timers. Three are decreasing counters, and they can be used as timers. Three
@ -51,28 +49,36 @@ YAP_FLAG(AUTOLOAD_FLAG, "autoload", true, booleanFlag, "false", NULL),
If `on` `fileerrors` is `on`, if `off` (default) If `on` `fileerrors` is `on`, if `off` (default)
`fileerrors` is disabled. `fileerrors` is disabled.
*/ */
YAP_FLAG(ENCODING_FLAG, "encoding", true, isatom, "utf-8", getenc), YAP_FLAG(CALL_COUNTING_FLAG, "call_counting", true, booleanFlag, "true",
YAP_FLAG(FILEERRORS_FLAG, "fileerrors", true, booleanFlag, "true", NULL),
NULL), /** + `fileerrors`
If `on` `fileerrors` is `on`, if `off` (default) /**< support for coding systens, YAP relies on UTF-8 internally.
`fileerrors` is disabled. */
YAP_FLAG(ENCODING_FLAG, "encoding", true, isatom, "utf-8", getenc),
/** + what to do if opening a file fails.
*/
YAP_FLAG(FILEERRORS_FLAG, "fileerrors", true, booleanFlag, "true",
NULL),
/**<
whether native mode or trying to emulate a different
Prolog.
*/ */
YAP_FLAG(LANGUAGE_MODE_FLAG, "language_mode", true, isatom, "yap", YAP_FLAG(LANGUAGE_MODE_FLAG, "language_mode", true, isatom, "yap",
NULL), /** + `language_mode` NULL),
wweter native mode or trying to emulate a different Prolog.
*/
YAP_FLAG(STACK_DUMP_ON_ERROR_FLAG, "stack_dump_on_error", true, booleanFlag, YAP_FLAG(STACK_DUMP_ON_ERROR_FLAG, "stack_dump_on_error", true, booleanFlag,
"true", NULL), /** + `stack_dump_on_error ` "true", NULL),
/**<`
If `true` show a stack dump when YAP finds an error. The default is If `true` show a stack dump when YAP finds an error. The default is
`off`. `off`.
*/ */
YAP_FLAG(STREAM_TYPE_CHECK_FLAG, "stream_type_check", true, isatom, "loose", YAP_FLAG(STREAM_TYPE_CHECK_FLAG, "stream_type_check", true, isatom, "loose",
NULL), NULL),
YAP_FLAG(SYNTAX_ERRORS_FLAG, "syntax_errors", true, synerr, "error", /** + `syntax_errors`
NULL), /** + `syntax_errors`
Control action to be taken after syntax errors while executing read/1, Control action to be taken after syntax errors while executing read/1,
`read/2`, or `read_term/3`: `read/2`, or `read_term/3`:
@ -85,16 +91,17 @@ Report the syntax error and generate an error (default).
+ `quiet` + `quiet`
Just fail Just fail
*/ */
YAP_FLAG(TYPEIN_MODULE_FLAG, "typein_module", true, isatom, "user", YAP_FLAG(SYNTAX_ERRORS_FLAG, "syntax_errors", true, synerr, "error",
typein), /** + `typein_module ` NULL),
/**<
If bound, set the current working or type-in module to the argument, If bound, set the current working or type-in module to the argument,
which must be an atom. If unbound, unify the argument with the current which must be an atom. If unbound, unify the argument with the current
working module. working module.
*/ */
YAP_FLAG(USER_ERROR_FLAG, "user_error", true, stream, "user_error", YAP_FLAG(TYPEIN_MODULE_FLAG, "typein_module", true, isatom, "user",
set_error_stream), /** + `user_error1` typein),
/**<
If the second argument is bound to a stream, set user_error to If the second argument is bound to a stream, set user_error to
this stream. If the second argument is unbound, unify the argument with this stream. If the second argument is unbound, unify the argument with
@ -125,6 +132,8 @@ prompts from the system were redirected to the stream
automatically redirects the user_error alias to the original automatically redirects the user_error alias to the original
`stderr`. `stderr`.
*/ */
YAP_FLAG(USER_ERROR_FLAG, "user_error", true, stream, "user_error",
set_error_stream),
YAP_FLAG(USER_INPUT_FLAG, "user_input", true, stream, "user_input", YAP_FLAG(USER_INPUT_FLAG, "user_input", true, stream, "user_input",
set_input_stream), set_input_stream),
YAP_FLAG(USER_OUTPUT_FLAG, "user_output", true, stream, "user_output", YAP_FLAG(USER_OUTPUT_FLAG, "user_output", true, stream, "user_output",

View File

@ -1,116 +0,0 @@
/*************************************************************************
* *
* YAP Prolog %W% %G% *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
* *
**************************************************************************
* *
* File: Yap.h *
* mods: *
* comments: abstract type definitions for YAP *
* version: $Id: Yap.h,v 1.38 2008-06-18 10:02:27 vsc Exp $ *
*************************************************************************/
#ifndef YAP_H
#include "YapTermConfig.h"
#include "config.h"
typedef void *Functor;
typedef void *Atom;
#endif
#if HAVE_STDINT_H
#include <stdint.h>
#endif
#if HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#define ALIGN_BY_TYPE(X, TYPE) \
(((CELL)(X) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1))
#ifndef EXTERN
#ifdef MSC_VER
#define EXTERN
#else
#define EXTERN extern
#endif
#endif
/* defines integer types Int and UInt (unsigned) with the same size as a ptr
** and integer types Short and UShort with half the size of a ptr */
#if defined(PRIdPTR)
typedef intptr_t Int;
typedef uintptr_t UInt;
#elif defined(_WIN64)
typedef int64_t Int;
typedef uint64_t UInt;
#elif defined(_WIN32)
typedef int32_t Int;
typedef uint32_t UInt;
#elif SIZEOF_LONG_INT == SIZEOF_INT_P
typedef long int Int;
typedef unsigned long int UInt;
#elif SIZEOF_INT == SIZEOF_INT_P
typedef int Int;
typedef unsigned int UInt;
#else
#error Yap require integer types of the same size as a pointer
#endif
/* */ typedef short int Short;
/* */ typedef unsigned short int UShort;
typedef UInt CELL;
typedef uint16_t BITS16;
typedef int16_t SBITS16;
typedef uint32_t BITS32;
#define WordSize sizeof(BITS16)
#define CellSize sizeof(CELL)
#define SmallSize sizeof(SMALLUNSGN)
#include "YapFormat.h"
/*************************************************************************************************
type casting macros
*************************************************************************************************/
typedef UInt Term;
typedef Int yhandle_t;
typedef double Float;
#if SIZEOF_INT < SIZEOF_INT_P
#define SHORT_INTS 1
#else
#define SHORT_INTS 0
#endif
#ifdef __GNUC__
typedef long long int YAP_LONG_LONG;
typedef unsigned long long int YAP_ULONG_LONG;
#else
typedef long int YAP_LONG_LONG;
typedef unsigned long int YAP_ULONG_LONG;
#endif
#define Unsigned(V) ((CELL)(V))
#define Signed(V) ((Int)(V))

View File

@ -175,7 +175,10 @@ INLINE_ONLY char_kind_t chtype(Int ch) {
#endif #endif
extern const char *Yap_tokText(void *tokptr); extern const char *Yap_tokText(void *tokptr);
extern Term Yap_tokRep(void *tokptr); /// represent token *_tokptr_ in string s, maxlength is sz-1
///
/// conversion is based on token type.
extern Term Yap_tokRep(void *tokptrXS);
// standard strings // standard strings

View File

@ -128,6 +128,7 @@ extern X_API Int YAP_RunGoalOnce(Term);
/* cdmgr.c */ /* cdmgr.c */
extern Term Yap_all_calls(void); extern Term Yap_all_calls(void);
extern Atom Yap_ConsultingFile(USES_REGS1); extern Atom Yap_ConsultingFile(USES_REGS1);
extern bool Yap_Consulting(USES_REGS1);
extern struct pred_entry *Yap_PredForChoicePt(choiceptr bptr, op_numbers *op); extern struct pred_entry *Yap_PredForChoicePt(choiceptr bptr, op_numbers *op);
extern void Yap_InitCdMgr(void); extern void Yap_InitCdMgr(void);
extern struct pred_entry *Yap_PredFromClause(Term t USES_REGS); extern struct pred_entry *Yap_PredFromClause(Term t USES_REGS);
@ -390,8 +391,7 @@ extern void Yap_InitSortPreds(void);
/* stack.c */ /* stack.c */
extern void Yap_InitStInfo(void); extern void Yap_InitStInfo(void);
extern void Yap_dump_stack(void); extern char *Yap_output_bug_location(yamop *yap_pc, int where_from, int psize);
extern void Yap_output_bug_location(yamop *yap_pc, int where_from, int psize);
#if !defined(YAPOR) && !defined(THREADS) #if !defined(YAPOR) && !defined(THREADS)
extern bool Yap_search_for_static_predicate_in_use(struct pred_entry *, bool); extern bool Yap_search_for_static_predicate_in_use(struct pred_entry *, bool);
@ -470,7 +470,7 @@ extern void Yap_InitAbsmi(void);
extern void Yap_InitUnify(void); extern void Yap_InitUnify(void);
extern void Yap_TrimTrail(void); extern void Yap_TrimTrail(void);
extern int Yap_Unifiable(Term d0, Term d1); extern int Yap_Unifiable(Term d0, Term d1);
extern int Yap_IUnify(register CELL d0, register CELL d1); extern int Yap_IUnify( CELL d0, CELL d1);
/* userpreds.c */ /* userpreds.c */
extern void Yap_InitUserCPreds(void); extern void Yap_InitUserCPreds(void);

View File

@ -1529,6 +1529,11 @@ extern bool Yap_HasException(void);
extern yap_error_descriptor_t *Yap_GetException(); extern yap_error_descriptor_t *Yap_GetException();
extern void Yap_PrintException(yap_error_descriptor_t *i); extern void Yap_PrintException(yap_error_descriptor_t *i);
INLINE_ONLY bool Yap_HasException(void) { INLINE_ONLY bool Yap_HasException(void) {
extern yap_error_number Yap_MathException__(USES_REGS1);
yap_error_number me;
if ((me = Yap_MathException__(PASS_REGS1)) && LOCAL_ActiveError->errorNo != YAP_NO_ERROR) {
LOCAL_ActiveError->errorNo = me;
}
return LOCAL_ActiveError->errorNo != YAP_NO_ERROR; return LOCAL_ActiveError->errorNo != YAP_NO_ERROR;
} }

View File

@ -24,13 +24,13 @@ inline static int sub_overflow(Int x, Int i, Int j) {
} }
inline static Term sub_int(Int i, Int j USES_REGS) { inline static Term sub_int(Int i, Int j USES_REGS) {
#if defined(__clang__ ) || defined(__GNUC__) #if defined(__clang__ ) || (defined(__GNUC__) && __GNUC__ > 4)
Int k; Int k;
if (__builtin_sub_overflow(i,j,&k)) { if (__builtin_sub_overflow(i,j,&k)) {
return Yap_gmp_sub_ints(i, j); return Yap_gmp_sub_ints(i, j);
} }
RINT(k); RINT(k);
#elif defined(__GNUC__) #elif defined(__GNUC__) && __GNUC__ >4
Int w; Int w;
if (!__builtin_sub_overflow_p(i,j,w)) if (!__builtin_sub_overflow_p(i,j,w))
RINT(w); RINT(w);
@ -64,7 +64,7 @@ inline static int mul_overflow(Int z, Int i1, Int i2) {
return (i2 && z / i2 != i1); return (i2 && z / i2 != i1);
} }
#if defined(__clang__) || defined(__GNUC__) #if defined(__clang__) || (defined(__GNUC__) && __GNUC__ > 4)
#define DO_MULTI() \ #define DO_MULTI() \
if (__builtin_mul_overflow(i1, i2, &z)) { \ if (__builtin_mul_overflow(i1, i2, &z)) { \
goto overflow; \ goto overflow; \

View File

@ -1,4 +1,4 @@
#include "config.h" #include "YapConfig.h"
#include "udi.h" #include "udi.h"
#include "utarray.h" #include "utarray.h"
#include "uthash.h" #include "uthash.h"
@ -19,8 +19,7 @@ UT_icd cl_icd = {sizeof(yamop *), NULL, NULL, NULL };
* All the info we need to enter user indexed code * All the info we need to enter user indexed code
* stored in a uthash * stored in a uthash
*/ */
struct udi_info struct udi_info {
{
PredEntry *p; // predicate (need to identify asserts) PredEntry *p; // predicate (need to identify asserts)
UT_array *clauselist; // clause list used on returns UT_array *clauselist; // clause list used on returns
UT_array *args; // indexed args UT_array *args; // indexed args
@ -44,18 +43,15 @@ static YAP_Int p_udi_args_init(Term spec, int arity, UdiInfo blk);
/* single indexing helpers (no intersection needed just create clauselist) */ /* single indexing helpers (no intersection needed just create clauselist) */
#include "clause_list.h" #include "clause_list.h"
struct si_callback_h struct si_callback_h {
{
clause_list_t cl; clause_list_t cl;
UT_array *clauselist; UT_array *clauselist;
void *pred; void *pred;
}; };
typedef struct si_callback_h *si_callback_h_t; typedef struct si_callback_h *si_callback_h_t;
static inline int si_callback(void *key, void *data, void *arg) static inline int si_callback(void *key, void *data, void *arg) {
{
si_callback_h_t c = (si_callback_h_t)arg; si_callback_h_t c = (si_callback_h_t)arg;
yamop **cl = (yamop **)utarray_eltptr(c->clauselist, ((YAP_Int)data) - 1); yamop **cl = (yamop **)utarray_eltptr(c->clauselist, ((YAP_Int)data) - 1);
return Yap_ClauseListExtend(c->cl, *cl, c->pred); return Yap_ClauseListExtend(c->cl, *cl, c->pred);
} }

View File

@ -65,12 +65,11 @@ add_lib (libyapjit
set_target_properties(libyapjit set_target_properties(libyapjit
PROPERTIES PROPERTIES
# RPATH ${libdir} VERSION ${LIBJIT_FULL_VERSION}
SOVERSION ${LIBJIT_MAJOR_VERSION}.${LIBJIT_MINOR_VERSION} SOVERSION ${LIBJIT_MAJOR_VERSION}.${LIBJIT_MINOR_VERSION}
POSITION_INDEPENDENT_CODE TRUE POSITION_INDEPENDENT_CODE TRUE
OUTPUT_NAME YapJIT OUTPUT_NAME YapJIT
) )
target_link_libraries(libyapjit libYap ${LLVM_LIBRARIES} z) target_link_libraries(libyapjit libYap ${LLVM_LIBRARIES})
set ( YAP_YAPJITLIB $<TARGET_FILE_NAME:libyapjit> ) set ( YAP_YAPJITLIB $<TARGET_FILE_NAME:libyapjit> )

View File

@ -71,7 +71,7 @@ add_component (libOPTYap
My_set_target_properties(libOPTYap My_set_target_properties(libOPTYap
PROPERTIES PROPERTIES
# RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION} # RPATH ${CMAKE_INSTALL_LIBDIR} VERSION ${LIBYAPTAI_FULL_VERSION}
# SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION} # SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION}
POSITION_INDEPENDENT_CODE TRUE POSITION_INDEPENDENT_CODE TRUE
OUTPUT_NAME OPTYap OUTPUT_NAME OPTYap

View File

@ -159,8 +159,8 @@ target_link_libraries(yap-bin libYap )
install(TARGETS libYap yap-bin install(TARGETS libYap yap-bin
RUNTIME DESTINATION ${bindir} RUNTIME DESTINATION ${bindir}
LIBRARY DESTINATION ${libdir} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${libdir} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
) )

View File

@ -1,7 +1,6 @@
`` <p align="center">
<center> <img src="./docs/icons/yap_128x128x32.png" alt="The YAP Logo"/>
![The YAP Logo](docs/icons/yap_128x128x32.png) </p>
</center>
NOTE: this version of YAP is still experimental, documentation may be out of date. NOTE: this version of YAP is still experimental, documentation may be out of date.

View File

@ -55,4 +55,6 @@
#endif #endif
#include "YapTerm.h"
#endif #endif

View File

@ -137,10 +137,8 @@ endif()
set ( libpl ${datarootdir}/Yap) set ( libpl ${datarootdir}/Yap)
set ( includedir "${prefix}/include") set ( includedir "${prefix}/include")
set ( exec_prefix "${prefix}") set ( exec_prefix "${prefix}")
set ( libdir "${exec_prefix}/lib")
set ( datadir "${datarootdir}") set ( datadir "${datarootdir}")
set ( mandir "${datarootdir}/man") set ( mandir "${datarootdir}/man")
set ( bindir "${exec_prefix}/bin")
set ( docdir "${datarootdir}/doc/Yap") set ( docdir "${datarootdir}/doc/Yap")
set ( dlls "${exec_prefix}/lib/Yap") set ( dlls "${exec_prefix}/lib/Yap")
@ -149,10 +147,10 @@ set(YAP_ROOTDIR ${prefix})
# erootdir -> rootdir # erootdir -> rootdir
# bindir defined above # bindir defined above
# libdir defined above # libdir defined above
set(YAP_LIBDIR "${dlls}") set(YAP_LIBDIR "${YAP_INSTALL_LIBDIR}")
set(YAP_SHAREDIR "${datarootdir}") set(YAP_SHAREDIR "${datarootdir}")
set(YAP_BINDIR "${bindir}") set(YAP_BINDIR "${CMAKE_INSTALL_BINDIR}")
set(YAP_INCLUDEDIR "${includedir}") set(YAP_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(YAP_ROOTDIR "${prefix}") set(YAP_ROOTDIR "${prefix}")
# #

View File

@ -253,8 +253,6 @@ set (OPTYap_HEADERS
) )
set (YAPOS_HEADERS set (YAPOS_HEADERS
${CMAKE_SOURCE_DIR}/os/encoding.h
${CMAKE_SOURCE_DIR}/os/fmemopen.h
${CMAKE_SOURCE_DIR}/os/format.h ${CMAKE_SOURCE_DIR}/os/format.h
${CMAKE_SOURCE_DIR}/os/getw.h ${CMAKE_SOURCE_DIR}/os/getw.h
${CMAKE_SOURCE_DIR}/os/iopreds.h ${CMAKE_SOURCE_DIR}/os/iopreds.h

View File

@ -1884,7 +1884,9 @@ signal. */
#endif #endif
/* use bignums/rationals in YAP code. */ /* use bignums/rationals in YAP code. */
#ifndef USE_GMP #if defined( __ANDROID__ ) && !defined(USE_GMP)
#define USE_GMP 1
#elif !defined(USE_GMP)
#define USE_GMP ${GMP_FOUND} #define USE_GMP ${GMP_FOUND}
#endif #endif
@ -2115,4 +2117,6 @@ calls it, or to nothing if 'inline' is not supported under any name. */
#endif #endif
#endif #endif
#include "YapTermConfig.h"
#endif #endif

12
configure vendored
View File

@ -165,7 +165,7 @@ print_help() {
--mandir=DIR man documentation [DATAROOTDIR/man] --mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/PROJECT_NAME] --docdir=DIR documentation root [DATAROOTDIR/doc/PROJECT_NAME]
--generator=Generator Specify the tool used to send callss --generator=GENERATOR Specify the tool used to send callss
EOF EOF
first=y first=y
@ -220,6 +220,8 @@ EOF
exit 0 exit 0
} }
while [ $# != 0 ]; do while [ $# != 0 ]; do
case "$1" in case "$1" in
"--cmake="*) "--cmake="*)
@ -291,10 +293,10 @@ while [ $# != 0 ]; do
"--docdir") "--docdir")
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DOCDIR=$(quote "$2")"; shift;; CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DOCDIR=$(quote "$2")"; shift;;
"-G="|"--generator="*) "--generator="*)
CMAKE_ARGS+="-G"${1#*=};; CMAKE_ARGS="$CMAKE_ARGS -G ${1#*=}";;
"-G"|"--generator") "-G")
CMAKE_ARGS+="-G$"$2; shift;; CMAKE_ARGS="$CMAKE_ARGS -G $2"; shift;;
"CC="*) "CC="*)
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_C_COMPILER=$(quote "${1#*=}")";; CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_C_COMPILER=$(quote "${1#*=}")";;

View File

@ -8,16 +8,14 @@
* * * *
************************************************************************** **************************************************************************
* * * *
* File: Yap.C * * File: Yap.C * Last Rev:
* Last Rev: * ** Mods: * Comments: Yap's Main File *
* Mods: *
* Comments: Yap's Main File *
* * * *
*************************************************************************/ *************************************************************************/
/* static char SccsId[] = "X 4.3.3"; */ /* static char SccsId[] = "X 4.3.3"; */
#include "YapConfig.h"
#include "YapInterface.h" #include "YapInterface.h"
#include "config.h"
#include "cut_c.h" #include "cut_c.h"
@ -113,7 +111,6 @@ static bool exec_top_level(int BootMode, YAP_init_args *iap) {
} }
return true; return true;
// YAP_Exit(EXIT_SUCCESS); // YAP_Exit(EXIT_SUCCESS);
} }
// FILE *debugf; // FILE *debugf;

View File

@ -264,6 +264,9 @@
#define REMOTE_OpenArray(wid) (REMOTE(wid)->OpenArray) #define REMOTE_OpenArray(wid) (REMOTE(wid)->OpenArray)
/* in a single gc */ /* in a single gc */
#define LOCAL_MallocDepth (Yap_local.MallocDepth)
#define REMOTE_MallocDepth(wid) (REMOTE(wid)->MallocDepth)
#define LOCAL_total_marked (Yap_local.total_marked) #define LOCAL_total_marked (Yap_local.total_marked)
#define REMOTE_total_marked(wid) (REMOTE(wid)->total_marked) #define REMOTE_total_marked(wid) (REMOTE(wid)->total_marked)

View File

@ -27,7 +27,6 @@ SET( EXT
${DOCS_SOURCE_DIR}/custom/yap.css ${DOCS_SOURCE_DIR}/custom/yap.css
) )
foreach(i ${CMAKE_HTML_EXTRA_}) foreach(i ${CMAKE_HTML_EXTRA_})
string(APPEND CMAKE_HTML_EXTRA ${i} " ") string(APPEND CMAKE_HTML_EXTRA ${i} " ")
endforeach(i ${CMAKE_HTML_EXTRA_}) endforeach(i ${CMAKE_HTML_EXTRA_})
@ -88,15 +87,11 @@ endforeach(i ${DOCS_EXCLUDE_})
set(doxyfile_in ${CMAKE_SOURCE_DIR}/docs/Doxyfile.in) set(doxyfile_in ${CMAKE_SOURCE_DIR}/docs/Doxyfile.in)
add_subdirectory(../packages/raptor/doc ${CMAKE_BINARY_DIR}/packages/raptor/doc) add_subdirectory(../packages/raptor/doc ${CMAKE_BINARY_DIR}/packages/raptor/doc)
SET(DOC_INPUT_FILES_ SET(DOC_INPUT_FILES_
${CMAKE_SOURCE_DIR}/pl
${CMAKE_SOURCE_DIR}/docs/md ${CMAKE_SOURCE_DIR}/docs/md
${CMAKE_SOURCE_DIR}/pl
${CMAKE_SOURCE_DIR}/CXX ${CMAKE_SOURCE_DIR}/CXX
${CMAKE_SOURCE_DIR}/OPTYap ${CMAKE_SOURCE_DIR}/OPTYap
${CMAKE_SOURCE_DIR}/C ${CMAKE_SOURCE_DIR}/C

View File

@ -146,20 +146,6 @@
<files visible="yes" title=""/> <files visible="yes" title=""/>
<namespaces visible="yes" title=""/> <namespaces visible="yes" title=""/>
<classes visible="no" title=""/> <classes visible="no" title=""/>
<defines title=""/>
<typedefs title=""/>
<enums title=""/>
<enumvalues title=""/>
<functions title=""/>
<variables title=""/>
<signals title=""/>
<publicslots title=""/>
<protectedslots title=""/>
<privateslots title=""/>
<events title=""/>
<properties title=""/>
<friends title=""/>
<membergroups visible="yes"/>
</memberdecl> </memberdecl>
<memberdef> <memberdef>
<pagedocs/> <pagedocs/>
@ -177,7 +163,23 @@
<events title=""/> <events title=""/>
<properties title=""/> <properties title=""/>
<friends title=""/> <friends title=""/>
<membergroups visible="yes"/>
</memberdef> </memberdef>
<memberdecl>
<defines title=""/>
<typedefs title=""/>
<enums title=""/>
<enumvalues title=""/>
<functions title=""/>
<variables title=""/>
<signals title=""/>
<publicslots title=""/>
<protectedslots title=""/>
<privateslots title=""/>
<events title=""/>
<properties title=""/>
<friends title=""/>
</memberdecl>
<authorsection visible="yes"/> <authorsection visible="yes"/>
</group> </group>

View File

@ -20,4 +20,6 @@ notation will be used:
+ an argument with no preceding symbol can be used in both ways. + an argument with no preceding symbol can be used in both ways.
@{ [TOC]
@}

View File

@ -13,11 +13,11 @@ predicates in a language other than Prolog. Under Unix systems,
most language implementations were linkable to `C`, and the first interface exported the YAP machinery to the C language. YAP also implements most of the SWI-Prolog foreign language interface. most language implementations were linkable to `C`, and the first interface exported the YAP machinery to the C language. YAP also implements most of the SWI-Prolog foreign language interface.
This gives portability with a number of SWI-Prolog packages and avoids garnage collection by using @ref slotInterface. Last, a new C++ based interface is This gives portability with a number of SWI-Prolog packages and avoids garnage collection by using @ref slotInterface. Last, a new C++ based interface is
being designed to work with the swig (www.swig.orgv) interface compiler. being designed to work with the swig (www.swig.orgv) interface compiler.
@}
@defgroup ChYInterface YAP original C-interface @defgroup ChYInterface YAP original C-interface
@{
@ingroup fli_c_cxx @ingroup fli_c_cxx
@{
Before describing in full detail how to interface to C code, we will examine Before describing in full detail how to interface to C code, we will examine
a brief example. a brief example.
@ -50,8 +50,8 @@ system.
@} @}
@defgroup CallYAP Using the compiler: @defgroup CallYAP Using the compiler:
@{
@ingroup ChYInterface @ingroup ChYInterface
@{
Under Linux you should use: Under Linux you should use:
@ -127,8 +127,8 @@ The rest of this appendix describes exhaustively how to interface C to YAP.
@} @}
@defgroup Manipulating_Terms Terms @defgroup Manipulating_Terms Terms
@{
@ingroup ChYInterface @ingroup ChYInterface
@{
This section provides information about the primitives available to the C This section provides information about the primitives available to the C
programmer for manipulating Prolog terms. programmer for manipulating Prolog terms.
@ -504,8 +504,8 @@ code. Slots can also be used if there is small state.
@} @}
@defgroup Unifying_Terms Unification @defgroup Unifying_Terms Unification
@{
@ingroup ChYInterface @ingroup ChYInterface
@{
YAP provides a single routine to attempt the unification of two Prolog YAP provides a single routine to attempt the unification of two Prolog
terms. The routine may succeed or fail: terms. The routine may succeed or fail:
@ -522,8 +522,8 @@ otherwise.
@} @}
@defgroup CallYAP Using the compiler: @defgroup CallYAP Using the compiler:
@{
@ingroup Manipulating_Strings Strings @ingroup Manipulating_Strings Strings
@{
The YAP C-interface now includes an utility routine to copy a string The YAP C-interface now includes an utility routine to copy a string
@ -608,8 +608,8 @@ and <tt>-1</tt> on error.
@} @}
@defgroup Memory_Allocation Memory Allocation @defgroup Memory_Allocation Memory Allocation
@{
@ingroup ChYInterface @ingroup ChYInterface
@{
The next routine can be used to ask space from the Prolog data-base: The next routine can be used to ask space from the Prolog data-base:
@ -638,8 +638,8 @@ area.
@} @}
@defgroup Controlling_Streams Controlling YAP Streams from `C` @defgroup Controlling_Streams Controlling YAP Streams from `C`
@{
@ingroup ChYInterface @ingroup ChYInterface
@{
The C-Interface also provides the C-application with a measure of The C-Interface also provides the C-application with a measure of
control over the YAP Input/Output system. The first routine allows one control over the YAP Input/Output system. The first routine allows one
@ -698,8 +698,8 @@ the name by which YAP should know the new stream.
@} @}
@defgroup Utility_Functions Utility Functions in `C @defgroup Utility_Functions Utility Functions in `C
@{
@ingroup ChYInterface @ingroup ChYInterface
@{
The C-Interface provides the C-application with a a number of utility The C-Interface provides the C-application with a a number of utility
functions that are useful. functions that are useful.
@ -794,9 +794,8 @@ ignore the variable.
@} @}
@defgroup Calling_YAP_From_C From `C` back to Prolog @defgroup Calling_YAP_From_C From `C` back to Prolog
@{
@ingroup ChYInterface @ingroup ChYInterface
### From `C` back to Prolog {#Calling_YAP_From_C} @{
There are several ways to call Prolog code from C-code. By default, the There are several ways to call Prolog code from C-code. By default, the
`YAP_RunGoal()` should be used for this task. It assumes the engine `YAP_RunGoal()` should be used for this task. It assumes the engine
@ -967,8 +966,8 @@ have moved the terms
@} @}
@defgroup CallYAP Using the compiler: @defgroup CallYAP Using the compiler:
@{
@ingroup Module_Manipulation_in_C Module Manipulation in C @ingroup Module_Manipulation_in_C Module Manipulation in C
@{
YAP allows one to create a new module from C-code. To create the new YAP allows one to create a new module from C-code. To create the new
code it is sufficient to call: code it is sufficient to call:
@ -998,8 +997,8 @@ Notice that this function returns a term, and not an atom. You can
@} @}
@defgroup Miscellaneous_ChYFunctions Miscellaneous C Functions @defgroup Miscellaneous_ChYFunctions Miscellaneous C Functions
@{
@ingroup ChYInterface @ingroup ChYInterface
@{
<ul> <ul>
<li>`void` YAP_Throw(`YAP_Term exception`) <li>`void` YAP_Throw(`YAP_Term exception`)
@ -1064,9 +1063,8 @@ of such arguments.
@} @}
@defgroup Writing_C Writing predicates in C @defgroup Writing_C Writing predicates in C
@{
@ingroup ChYInterface @ingroup ChYInterface
### Writing predicates in C {#Writing_C} @{
We will distinguish two kinds of predicates: We will distinguish two kinds of predicates:
@ -1321,8 +1319,8 @@ in this case no code is executed at cut time.
@} @}
@defgroup YAP4_Notes Changes to the C-Interface in YAP4 @defgroup YAP4_Notes Changes to the C-Interface in YAP4
@{
@ingroup ChYInterface @ingroup ChYInterface
@{
YAP4 includes several changes over the previous `load_foreign_files/3` YAP4 includes several changes over the previous `load_foreign_files/3`
interface. These changes were required to support the new binary code interface. These changes were required to support the new binary code
@ -1361,8 +1359,8 @@ arguments to the backtrackable procedure.
@} @}
@defgroup YAPAsLibrary Using YAP as a Library @defgroup YAPAsLibrary Using YAP as a Library
@{
@ingroup ChYInterface @ingroup ChYInterface
@{
YAP can be used as a library to be called from other YAP can be used as a library to be called from other
programs. To do so, you must first create the YAP library: programs. To do so, you must first create the YAP library:

View File

@ -1,9 +1,15 @@
@file LIBRARY.md
@defgroup library YAP Prolog Library @defgroup library YAP Prolog Library
@{ @{
YAP supports
the library_directory path (set by the the library_directory path (set by the
`LIBDIR` variable in the Makefile for YAP). Several files in the `LIBDIR` variable in the Makefile for YAP). Several files in the
library are originally from the public-domain Edinburgh Prolog library. library are originally from the public-domain Edinburgh Prolog library.
[TOC]
@} @}

View File

@ -1,23 +1,20 @@
Programming in YAP {#YAPProgramming} @defgroup YAPProgramming Programming in YAP
====================
+ @ref load_files @{
+ @ref YAPSyntax [TOC]
+ @ref YAPCompilerSettings
+ @ref Indexing
+ @ref Deb_Interaction
@}
@defgroup load_files Loading and Organizing YAP Programs @defgroup load_files Loading and Organizing YAP Programs
@{ @{
We present the main predicates and directives available to load We present the main predicates and directives available to load
files and to control the Prolog environment. files and to control the Prolog environment.
[TOC]
@} @}
@defgroup YAPModules The YAP Module system @defgroup YAPModules The YAP Module system
@ -141,7 +138,7 @@ We present the main predicates and directives available to load
their public predicates into the current type-in module. It is their public predicates into the current type-in module. It is
implemented as if by: implemented as if by:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.prolog} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.yap}
use_module(F) :- use_module(F) :-
load_files(F, [if(not_loaded),must_be_module(true)]). load_files(F, [if(not_loaded),must_be_module(true)]).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -1,3 +1,9 @@
2:- use_module( library(lineutils) ).
3
4main :-
5 unix(argv[Dir,Out]),
6 open(Out,write,O),
:- module( prolog, [] ). 7 go(Dir,O).
9go(Dir,O) :-

View File

@ -19,7 +19,7 @@ extern "C" {
//=== includes =============================================================== //=== includes ===============================================================
#ifdef YAP_KERNEL #ifdef YAP_KERNEL
#include "config.h" #include "YapConfig.h"
#ifdef __cplusplus #ifdef __cplusplus
} }
@ -40,8 +40,8 @@ extern "C" {
#include "YapInterface.h" #include "YapInterface.h"
#else #else
#if _YAP_NOT_INSTALLED_ #if _YAP_NOT_INSTALLED_
#include <YapConfig.h>
#include <YapInterface.h> #include <YapInterface.h>
#include <config.h>
#else #else
#include <Yap/YapInterface.h> #include <Yap/YapInterface.h>
#endif #endif

View File

@ -31,7 +31,7 @@
#endif #endif
#endif #endif
#include <encoding.h> #include <YapEncoding.h>
typedef struct { typedef struct {
dev_t st_dev; /* ID of device containing file */ dev_t st_dev; /* ID of device containing file */
@ -85,9 +85,11 @@ typedef struct vfs {
/// in this space, usual w,r,a,b flags plus B (store in a buffer) /// in this space, usual w,r,a,b flags plus B (store in a buffer)
bool (*close)(int sno); /// close the object bool (*close)(int sno); /// close the object
int (*get_char)(int sno); /// get an octet from the stream int (*get_char)(int sno); /// get an octet from the stream
int (*get_wchar)(int sno); /// get an octet from the stream
int (*peek_char)(int sno); /// unget an octet from the stream int (*peek_char)(int sno); /// unget an octet from the stream
int (*peek_wchar)(int sno); /// unget an octet from the stream int (*peek_wchar)(int sno); /// unget an octet from the stream
int (*put_char)(int sno, int ch); /// output an octet to the stream int (*put_char)(int sno, int ch); /// output an octet to the stream
int (*put_wchar)(int sno, int ch); /// output a character to the stream
void (*flush)(int sno); /// flush a stream void (*flush)(int sno); /// flush a stream
int64_t (*seek)(int sno, int64_t offset, int64_t (*seek)(int sno, int64_t offset,
int whence); /// jump around the stream int whence); /// jump around the stream

View File

@ -50,35 +50,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
/* The YAP main types */
#include "YapTerm.h"
#if HAVE_STDINT_H
#include <stdint.h>
#endif
#if HAVE_INTTYPES_H
#include <inttypes.h>
#endif
/**
FALSE and TRUE are the pre-standard versions,
still widely used.
*/
#ifndef TRUE
#define TRUE true
#endif
#ifndef FALSE
#define FALSE false
#endif
#ifndef YAP_Bool
typedef bool YAP_Bool;
#endif
/**
This term can never be constructed as a valid term, so it is
used as a "BAD" term
*/
#define TermZERO ((Term)0)
#include "YapConfig.h" #include "YapConfig.h"
@ -98,7 +69,7 @@ typedef int (*YAP_agc_hook)(void *_Atom);
#include "YapError.h" #include "YapError.h"
#include "../os/encoding.h" #include "YapEncoding.h"
typedef encoding_t YAP_encoding_t; typedef encoding_t YAP_encoding_t;
@ -152,10 +123,6 @@ typedef enum {
YAP_TAG_ARRAY = 0x4000 YAP_TAG_ARRAY = 0x4000
} YAP_tag_t; } YAP_tag_t;
#define YAP_BOOT_FROM_SAVED_CODE 1
#define YAP_BOOT_FROM_SAVED_STACKS 2
#define YAP_BOOT_ERROR -1
#define YAP_WRITE_QUOTED 1 #define YAP_WRITE_QUOTED 1
#define YAP_WRITE_IGNORE_OPS 2 #define YAP_WRITE_IGNORE_OPS 2
#define YAP_WRITE_HANDLE_VARS 4 #define YAP_WRITE_HANDLE_VARS 4
@ -167,130 +134,7 @@ typedef enum {
#define YAP_WRITE_ATTVAR_PORTRAY 0x400 #define YAP_WRITE_ATTVAR_PORTRAY 0x400
#define YAP_WRITE_BLOB_PORTRAY 0x800 #define YAP_WRITE_BLOB_PORTRAY 0x800
#define YAP_CONSULT_MODE 0 #include "YapInit.h"
#define YAP_RECONSULT_MODE 1
#define YAP_BOOT_MODE 2
X_API YAP_file_type_t Yap_InitDefaults(void *init_args, char saved_state[],
int Argc, char *Argv[]);
typedef struct yap_boot_params {
//> boot type as suggested by the user
YAP_file_type_t boot_file_type;
//> how files are organised: NULL is GNU/Linux way
// const char *directory_structure;
//> if NON-NULL, set value for Yap_ROOTDIR
const char *ROOTDIR;
//> if NON-NULL, location of yaap, sets Yap_BINDIR
const char *BINDIR;
//> if NON-NULL, location of libYap, sets Yap_LIBDIR
const char *LIBDIR;
//> if NON-NULL, architecture independent files, sets Yap_SHAREDIR
const char *SHAREDIR;
//> if NON-NULL, include files, sets Yap_INCLUDEDIR
const char *INCLUDEDIR;
//> if NON-NULL, Prolog DLL location, sets Yap_DLLDIR
const char *DLLDIR;
//> if NON-NULL, Prolog library, sets Yap_DLLDIR
const char *PLDIR;
//> if NON-NULL, Prolog library, sets Yap_COMMONSDIR
const char *COMMONSDIR;
//> if NON-NULL, name for a Prolog file to use when booting at run-time
const char *BOOTFILE;
//> if NON-NULL, name for a Prolog file to use when booting at compile-time
const char *BOOTSTRAP;
//> if NON-NULL, path where we can find the saved state
const char *INPUT_STARTUP;
//> bootstrapping mode: YAP is not properly installed
bool install;
//> jupyter mode: YAP is in space
bool jupyter;
//> generats a saved space at this path
const char *OUTPUT_STARTUP;
//> if NON-0, minimal size for Heap or Code Area
size_t HeapSize;
//> if NON-0, maximal size for Heap or Code Area
size_t MaxHeapSize;
//> if NON-0, minimal size for Local+Global Stack
size_t StackSize;
//> if NON-0, maximal size for Local+Global Stack
size_t MaxStackSize;
//*> deprecated
size_t MaxGlobalSize;
//> if NON-0, minimal size for Trail
size_t TrailSize;
//> if NON-0, maximal size for Trail
size_t MaxTrailSize;
//> if NON-0, minimal size for AttributeVarStack
size_t AttsSize;
//> if NON-0, maximal size for AttributeVarStack
size_t MaxAttsSize;
//> if NON-NULL, name for a Prolog file to use when initializing
const char *YapPrologInitGoal;
//> if NON-NULL, name for a Prolog file to consult before entering top-level
const char *PrologRCFile;
//> if NON-NULL, a goal to run before top-level
const char *PrologGoal;
//> if NON-NULL, a goal to run as top-level
const char *PrologTopLevelGoal;
//> if NON-NULL, a path to extend file-search-path
const char *PrologAddPath;
//> if previous NON-NULL and TRUE, halt after consulting that file
bool HaltAfterBoot;
//> ignore .yaprc, .prolog.ini, etc. files.
bool FastBoot;
//> the next field only interest YAPTAB
//> if NON-0, maximum size for Table Space
size_t MaxTableSpaceSize;
/* the next three fields only interest YAPOR, but we keep them so that
users don't need to recompile DLL in order to use YAPOR */
//> if NON-0, number of workers we want to have (default=1)
unsigned long int NumberWorkers;
//> if NON-0, manage the inner scheduler loop (default = 10)
unsigned long int SchedulerLoop;
//> if NON-0, say how long to keep nodes (default = 3)
unsigned long int DelayedReleaseLoad;
//> end of YAPOR fields
/* whether Prolog should handle interrupts. Note that
interrupts will always be disabled in embedded mode. */
bool PrologCannotHandleInterrupts;
//> flag for JIT mode
int ExecutionMode;
//> number of arguments that Prolog will see
int Argc;
//> array of arguments as seen by Prolog
char **Argv;
//> embedded in some other system: no signals, readline, etc
bool Embedded;
//> QuietMode
int QuietMode;
//> 0, maintain default, > 0 use fd-1, < 0 close
int inp, out, err;
#if __ANDROID__
//> android asset support
AAssetManager *assetManager;
#endif
/* support nf's ypp preprocessor code */
#define YAP_MAX_YPP_DEFS 100
char *def_var[YAP_MAX_YPP_DEFS];
char *def_value[YAP_MAX_YPP_DEFS];
int def_c;
/* End preprocessor code */
#ifdef MYDDAS_MYSQL
//> If any myddas option was given
short myddas;
//> MYDDAS Fields
char *myddas_user;
char *myddas_pass;
char *myddas_db;
char *myddas_host;
#endif
/* errornumber */
int ErrorNo;
//> errorstring
char *ErrorCause;
} YAP_init_args;
/* this should be opaque to the user */ /* this should be opaque to the user */
typedef struct { typedef struct {

View File

@ -200,31 +200,51 @@ INLINE_ONLY Term Yap_ensure_atom__(const char *fu, const char *fi, int line,
/// all we need to know about an error/throw /// all we need to know about an error/throw
typedef struct s_yap_error_descriptor { typedef struct s_yap_error_descriptor {
/// error identifier
yap_error_number errorNo; yap_error_number errorNo;
/// kind of error: derived from errorNo;
yap_error_class_number errorClass; yap_error_class_number errorClass;
/// if non-NULL: goal who caused error;
const char *errorGoal; const char *errorGoal;
/// errorNo as text
const char *errorAsText; const char *errorAsText;
/// errorClass as text
const char *classAsText; const char *classAsText;
/// c-code that generated the error
/// C-line
intptr_t errorLine; intptr_t errorLine;
/// C-function
const char *errorFunction; const char *errorFunction;
/// C-file
const char *errorFile; const char *errorFile;
// struct error_prolog_source *errorSource; // struct error_prolog_source *errorSource;
intptr_t prologPredCl; /// Prolog predicate that caused the error: name
uintptr_t prologPredLine;
uintptr_t prologPredFirstLine;
uintptr_t prologPredLastLine;
const char *prologPredName; const char *prologPredName;
/// Prolog predicate that caused the error:arity
uintptr_t prologPredArity; uintptr_t prologPredArity;
/// Prolog predicate that caused the error:module
const char *prologPredModule; const char *prologPredModule;
/// Prolog predicate that caused the error:line
const char *prologPredFile; const char *prologPredFile;
uintptr_t prologParserPos; /// line where error clause defined
uintptr_t prologParserLine; uintptr_t prologPredLine;
uintptr_t prologParserFirstLine; /// syntax and other parsing errors
uintptr_t prologParserLastLine; uintptr_t parserPos;
const char *prologParserText; uintptr_t parserFirstPos;
const char *prologParserFile; uintptr_t parserLastPos;
uintptr_t parserLine;
uintptr_t parserFirstLine;
uintptr_t parserLastLine;
const char *parserTextA;
const char *parserTextB;
const char *parserFile;
/// reading a clause, or called from read?
bool parserReadingCode;
/// whether we are consulting
bool prologConsulting; bool prologConsulting;
const char *culprit; const char *culprit;
/// Prolog stack at the time
const char *prologStack;
YAP_Term errorRawTerm, rawExtraErrorTerm; YAP_Term errorRawTerm, rawExtraErrorTerm;
char *errorMsg; char *errorMsg;
size_t errorMsgLen; size_t errorMsgLen;
@ -242,6 +262,7 @@ INLINE_ONLY Term Yap_ensure_atom__(const char *fu, const char *fi, int line,
extern void Yap_CatchError(void); extern void Yap_CatchError(void);
extern void Yap_ThrowExistingError(void); extern void Yap_ThrowExistingError(void);
extern YAP_Term Yap_MkFullError(void);
extern bool Yap_MkErrorRecord( extern bool Yap_MkErrorRecord(
yap_error_descriptor_t * r, const char *file, const char *function, yap_error_descriptor_t * r, const char *file, const char *function,
int lineno, yap_error_number type, YAP_Term where, const char *msg); int lineno, yap_error_number type, YAP_Term where, const char *msg);
@ -252,6 +273,8 @@ INLINE_ONLY Term Yap_ensure_atom__(const char *fu, const char *fi, int line,
yap_error_descriptor_t * t, void *cp0, void *b_ptr0, void *env0, yap_error_descriptor_t * t, void *cp0, void *b_ptr0, void *env0,
YAP_Int ignore_first); YAP_Int ignore_first);
extern const char *Yap_dump_stack(void);
extern yap_error_descriptor_t *Yap_prolog_add_culprit(yap_error_descriptor_t * extern yap_error_descriptor_t *Yap_prolog_add_culprit(yap_error_descriptor_t *
t); t);
extern yap_error_class_number Yap_errorClass(yap_error_number e); extern yap_error_class_number Yap_errorClass(yap_error_number e);

View File

@ -27,13 +27,15 @@ ECLASS(RESOURCE_ERROR, "resource_error", 2)
/// bad text /// bad text
ECLASS(SYNTAX_ERROR_CLASS, "syntax_error", 1) ECLASS(SYNTAX_ERROR_CLASS, "syntax_error", 1)
/// OS or internal /// OS or internal
ECLASS(SYSTEM_ERROR_CLASS, "system_error", 2) ECLASS(SYSTEM_ERROR_CLASS, "system_error", 1)
/// bad typing /// bad typing
ECLASS(TYPE_ERROR, "type_error", 2) ECLASS(TYPE_ERROR, "type_error", 2)
/// should be unbound /// should be unbound
ECLASS(UNINSTANTIATION_ERROR_CLASS, "uninstantiation_error", 1) ECLASS(UNINSTANTIATION_ERROR_CLASS, "uninstantiation_error", 1)
/// escape hatch /// not quite an error, but almost
ECLASS(EVENT, "event", 2) ECLASS(WARNING, "warning", 1)
/// user defined escape hatch
ECLASS(EVENT, "event", 1)
END_ERROR_CLASSES(); END_ERROR_CLASSES();
@ -88,6 +90,7 @@ E(DOMAIN_ERROR_WRITE_OPTION, DOMAIN_ERROR, "write_option")
E(EVALUATION_ERROR_FLOAT_OVERFLOW, EVALUATION_ERROR, "float_overflow") E(EVALUATION_ERROR_FLOAT_OVERFLOW, EVALUATION_ERROR, "float_overflow")
E(EVALUATION_ERROR_FLOAT_UNDERFLOW, EVALUATION_ERROR, "float_underflow") E(EVALUATION_ERROR_FLOAT_UNDERFLOW, EVALUATION_ERROR, "float_underflow")
E(EVALUATION_ERROR_INT_OVERFLOW, EVALUATION_ERROR, "int_overflow") E(EVALUATION_ERROR_INT_OVERFLOW, EVALUATION_ERROR, "int_overflow")
E(EVALUATION_ERROR_READ_STREAM, EVALUATION_ERROR, "read_from_stream")
E(EVALUATION_ERROR_UNDEFINED, EVALUATION_ERROR, "undefined") E(EVALUATION_ERROR_UNDEFINED, EVALUATION_ERROR, "undefined")
E(EVALUATION_ERROR_UNDERFLOW, EVALUATION_ERROR, "underflow") E(EVALUATION_ERROR_UNDERFLOW, EVALUATION_ERROR, "underflow")
E(EVALUATION_ERROR_ZERO_DIVISOR, EVALUATION_ERROR, "zero_divisor") E(EVALUATION_ERROR_ZERO_DIVISOR, EVALUATION_ERROR, "zero_divisor")
@ -196,7 +199,11 @@ E(TYPE_ERROR_REFERENCE, TYPE_ERROR, "reference")
E(TYPE_ERROR_STRING, TYPE_ERROR, "string") E(TYPE_ERROR_STRING, TYPE_ERROR, "string")
E(TYPE_ERROR_TEXT, TYPE_ERROR, "text") E(TYPE_ERROR_TEXT, TYPE_ERROR, "text")
E(TYPE_ERROR_UBYTE, TYPE_ERROR, "ubyte") E(TYPE_ERROR_UBYTE, TYPE_ERROR, "ubyte")
E(TYPE_ERROR_UCHAR, TYPE_ERROR, "uchar") E(TYPE_ERROR_UCHAR, TYPE_ERROR, "unsigned char")
E(WARNING_DISCONTIGUOUS, WARNING, "discontiguous")
E(WARNING_SINGLETONS, WARNING, "singletons")
E(WARNING_SYNTAX_ERROR, WARNING, "syntax_error")
E1(UNINSTANTIATION_ERROR, UNINSTANTIATION_ERROR_CLASS, "uninstantiation_error") E1(UNINSTANTIATION_ERROR, UNINSTANTIATION_ERROR_CLASS, "uninstantiation_error")

140
include/YapInit.h Normal file
View File

@ -0,0 +1,140 @@
/**
*
* @file YapInit.h
*
* * Utilities for Booting YAP
*/
#ifndef YAPINIT_H
#define YAPINIT_H
#define YAP_BOOT_FROM_SAVED_CODE 1
#define YAP_BOOT_FROM_SAVED_STACKS 2
#define YAP_BOOT_ERROR -1
#define YAP_CONSULT_MODE 0
#define YAP_RECONSULT_MODE 1
#define YAP_BOOT_MODE 2
X_API YAP_file_type_t Yap_InitDefaults(void *init_args, char saved_state[],
int Argc, char *Argv[]);
typedef struct yap_boot_params {
//> boot type as suggested by the user
YAP_file_type_t boot_file_type;
//> how files are organised: NULL is GNU/Linux way
// const char *directory_structure;
//> if NON-NULL, set value for Yap_ROOTDIR
const char *ROOTDIR;
//> if NON-NULL, location of yaap, sets Yap_BINDIR
const char *BINDIR;
//> if NON-NULL, location of libYap, sets Yap_LIBDIR
const char *LIBDIR;
//> if NON-NULL, architecture independent files, sets Yap_SHAREDIR
const char *SHAREDIR;
//> if NON-NULL, include files, sets Yap_INCLUDEDIR
const char *INCLUDEDIR;
//> if NON-NULL, Prolog DLL location, sets Yap_DLLDIR
const char *DLLDIR;
//> if NON-NULL, Prolog library, sets Yap_DLLDIR
const char *PLDIR;
//> if NON-NULL, Prolog library, sets Yap_COMMONSDIR
const char *COMMONSDIR;
//> if NON-NULL, name for a Prolog file to use when booting at run-time
const char *BOOTFILE;
//> if NON-NULL, name for a Prolog file to use when booting at compile-time
const char *BOOTSTRAP;
//> if NON-NULL, path where we can find the saved state
const char *INPUT_STARTUP;
//> bootstrapping mode: YAP is not properly installed
bool install;
//> jupyter mode: YAP is in space
bool jupyter;
//> generats a saved space at this path
const char *OUTPUT_STARTUP;
//> if NON-0, minimal size for Heap or Code Area
size_t HeapSize;
//> if NON-0, maximal size for Heap or Code Area
size_t MaxHeapSize;
//> if NON-0, minimal size for Local+Global Stack
size_t StackSize;
//> if NON-0, maximal size for Local+Global Stack
size_t MaxStackSize;
//*> deprecated
size_t MaxGlobalSize;
//> if NON-0, minimal size for Trail
size_t TrailSize;
//> if NON-0, maximal size for Trail
size_t MaxTrailSize;
//> if NON-0, minimal size for AttributeVarStack
size_t AttsSize;
//> if NON-0, maximal size for AttributeVarStack
size_t MaxAttsSize;
//> if NON-NULL, name for a Prolog file to use when initializing
const char *YapPrologInitGoal;
//> if NON-NULL, name for a Prolog file to consult before entering top-level
const char *PrologRCFile;
//> if NON-NULL, a goal to run before top-level
const char *PrologGoal;
//> if NON-NULL, a goal to run as top-level
const char *PrologTopLevelGoal;
//> if NON-NULL, a path to extend file-search-path
const char *PrologAddPath;
//> if previous NON-NULL and TRUE, halt after consulting that file
bool HaltAfterBoot;
//> ignore .yaprc, .prolog.ini, etc. files.
bool FastBoot;
//> the next field only interest YAPTAB
//> if NON-0, maximum size for Table Space
size_t MaxTableSpaceSize;
/* the next three fields only interest YAPOR, but we keep them so that
users don't need to recompile DLL in order to use YAPOR */
//> if NON-0, number of workers we want to have (default=1)
unsigned long int NumberWorkers;
//> if NON-0, manage the inner scheduler loop (default = 10)
unsigned long int SchedulerLoop;
//> if NON-0, say how long to keep nodes (default = 3)
unsigned long int DelayedReleaseLoad;
//> end of YAPOR fields
/* whether Prolog should handle interrupts. Note that
interrupts will always be disabled in embedded mode. */
bool PrologCannotHandleInterrupts;
//> flag for JIT mode
int ExecutionMode;
//> number of arguments that Prolog will see
int Argc;
//> array of arguments as seen by Prolog
char **Argv;
//> embedded in some other system: no signals, readline, etc
bool Embedded;
//> QuietMode
int QuietMode;
//> 0, maintain default, > 0 use fd-1, < 0 close
int inp, out, err;
#if __ANDROID__
//> android asset support
AAssetManager *assetManager;
#endif
/* support nf's ypp preprocessor code */
#define YAP_MAX_YPP_DEFS 100
char *def_var[YAP_MAX_YPP_DEFS];
char *def_value[YAP_MAX_YPP_DEFS];
int def_c;
/* End preprocessor code */
#ifdef MYDDAS_MYSQL
//> If any myddas option was given
short myddas;
//> MYDDAS Fields
char *myddas_user;
char *myddas_pass;
char *myddas_db;
char *myddas_host;
#endif
/* errornumber */
int ErrorNo;
//> errorstring
char *ErrorCause;
} YAP_init_args;
#endif

View File

@ -31,6 +31,8 @@ The following routines export the YAP internals and architecture.
#define _yap_c_interface_h 1 #define _yap_c_interface_h 1
#include "YapConfig.h"
#define __YAP_PROLOG__ 1 #define __YAP_PROLOG__ 1
#ifndef YAPVERSION #ifndef YAPVERSION
@ -102,6 +104,9 @@ extern YAP_Term YAP_A(int);
#define YAP_ARG15 YAP_A(15) #define YAP_ARG15 YAP_A(15)
#define YAP_ARG16 YAP_A(16) #define YAP_ARG16 YAP_A(16)
X_API
extern YAP_Term YAP_SetA(int, YAP_Term);
/* YAP_Bool IsVarTerm(YAP_Term) */ /* YAP_Bool IsVarTerm(YAP_Term) */
extern X_API YAP_Bool YAP_IsVarTerm(YAP_Term); extern X_API YAP_Bool YAP_IsVarTerm(YAP_Term);
@ -268,7 +273,6 @@ extern X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred,
extern X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred, extern X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred,
YAP_UserCPred, YAP_Arity, YAP_Arity); YAP_UserCPred, YAP_Arity, YAP_Arity);
/* void UserBackCPredicate(char *name, int *init(), int *cont(), int *cut(), /* void UserBackCPredicate(char *name, int *init(), int *cont(), int *cut(),
int int
arity, int extra) */ arity, int extra) */
@ -383,8 +387,7 @@ extern X_API int YAP_AssertTuples(YAP_PredEntryPtr pred, const YAP_Term *ts,
extern X_API void YAP_Init(YAP_init_args *); extern X_API void YAP_Init(YAP_init_args *);
/* int YAP_FastInit(const char *) */ /* int YAP_FastInit(const char *) */
extern X_API void YAP_FastInit(char saved_state[], int argc, extern X_API void YAP_FastInit(char saved_state[], int argc, char *argv[]);
char *argv[]);
#ifndef _PL_STREAM_H #ifndef _PL_STREAM_H
// if we don't know what a stream is, just don't assume nothing about the // if we don't know what a stream is, just don't assume nothing about the
@ -402,7 +405,8 @@ extern X_API YAP_Term YAP_ReadFromStream(int s);
/// read a Prolog clause from a Prolog opened stream $s$. Similar to /// read a Prolog clause from a Prolog opened stream $s$. Similar to
/// YAP_ReadFromStream() but takes /// default options from read_clause/3. /// YAP_ReadFromStream() but takes /// default options from read_clause/3.
extern X_API YAP_Term YAP_ReadClauseFromStream(int s, YAP_Term varNames, YAP_Term); extern X_API YAP_Term YAP_ReadClauseFromStream(int s, YAP_Term varNames,
YAP_Term);
extern X_API void YAP_Write(YAP_Term t, FILE *s, int); extern X_API void YAP_Write(YAP_Term t, FILE *s, int);
@ -411,7 +415,8 @@ extern X_API FILE *YAP_TermToStream(YAP_Term t);
extern X_API int YAP_InitConsult(int mode, const char *filename, char **buf, extern X_API int YAP_InitConsult(int mode, const char *filename, char **buf,
int *previous_sno); int *previous_sno);
extern X_API void YAP_EndConsult(int s, int *previous_sno, const char *previous_cwd); extern X_API void YAP_EndConsult(int s, int *previous_sno,
const char *previous_cwd);
extern X_API void YAP_Exit(int); extern X_API void YAP_Exit(int);
@ -477,7 +482,6 @@ extern X_API void YAP_SetOutputMessage(void);
extern X_API int YAP_StreamToFileNo(YAP_Term); extern X_API int YAP_StreamToFileNo(YAP_Term);
/** /**
* Utility routine to Obtain a pointer to the YAP representation of a stream. * Utility routine to Obtain a pointer to the YAP representation of a stream.
* *
@ -486,7 +490,6 @@ extern X_API int YAP_StreamToFileNo(YAP_Term);
*/ */
extern X_API void *YAP_RepStreamFromId(int sno); extern X_API void *YAP_RepStreamFromId(int sno);
extern X_API void YAP_CloseAllOpenStreams(void); extern X_API void YAP_CloseAllOpenStreams(void);
extern X_API void YAP_FlushAllStreams(void); extern X_API void YAP_FlushAllStreams(void);

View File

@ -13,17 +13,11 @@
* version: $Id: Yap.h,v 1.38 2008-06-18 10:02:27 vsc Exp $ * * version: $Id: Yap.h,v 1.38 2008-06-18 10:02:27 vsc Exp $ *
*************************************************************************/ *************************************************************************/
#ifndef YAP_H #include <stddef.h>
#include "YapTermConfig.h"
#include "config.h"
#endif
#if HAVE_STDINT_H #if HAVE_STDTYPES_H
#include <stdint.h> #include <stdtypes.h>
#endif
#if HAVE_INTTYPES_H
#include <inttypes.h>
#endif #endif
/* truth-values */ /* truth-values */
@ -41,6 +35,13 @@ typedef int _Bool;
#endif #endif
#endif /* HAVE_STDBOOL_H */ #endif /* HAVE_STDBOOL_H */
#if HAVE_STDINT_H
#include <stdint.h>
#endif
#if HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#define ALIGN_BY_TYPE(X, TYPE) \ #define ALIGN_BY_TYPE(X, TYPE) \
(((CELL)(X) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1)) (((CELL)(X) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1))
@ -99,10 +100,10 @@ typedef YAP_UInt YAP_Term;
#define TRUE true #define TRUE true
#endif #endif
#ifndef FALSE #ifndef FALSE
#define FALSE false
#endif #endif
typedef bool YAP_Bool; typedef bool YAP_Bool;
#define FALSE false
typedef YAP_Int YAP_handle_t; typedef YAP_Int YAP_handle_t;
@ -113,34 +114,9 @@ typedef void *YAP_Atom;
typedef void *YAP_Functor; typedef void *YAP_Functor;
#ifdef YAP_H
typedef YAP_Int Int;
typedef YAP_UInt UInt;
typedef YAP_Short Short;
typedef YAP_UShort UShort;
typedef uint16_t BITS16;
typedef int16_t SBITS16;
typedef uint32_t BITS32;
typedef YAP_CELL CELL;
typedef YAP_Term Term;
#define WordSize sizeof(BITS16)
#define CellSize sizeof(CELL)
#define SmallSize sizeof(SMALLUNSGN)
typedef YAP_Int Int;
typedef YAP_Float Float;
typedef YAP_handle_t yhandle_t;
#endif
#include "YapError.h" #include "YapError.h"
#include "../os/encoding.h" #include "YapEncoding.h"
typedef encoding_t YAP_encoding_t; typedef encoding_t YAP_encoding_t;

View File

@ -28,7 +28,7 @@ SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# (but later on when installing) # (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${libdir};${dlls}:") SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR};${YAP_INSTALL_LIBDIR}:")
# add the automatically determined parts of the RPATH # add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH # which point to directories outside the build tree to the install RPATH
@ -47,9 +47,9 @@ set_target_properties(libYap
endif() endif()
# the RPATH to be used when installing, but only if it's not a system directory # the RPATH to be used when installing, but only if it's not a system directory
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${libdir};${dlls}" isSystemDir) LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_LIBDIR};${YAP_INSTALL_LIBDIR}" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1") IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${libdir};${dlls}") SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR};${YAP_INSTALL_LIBDIR}")
ENDIF("${isSystemDir}" STREQUAL "-1") ENDIF("${isSystemDir}" STREQUAL "-1")

View File

@ -76,10 +76,10 @@ MY_add_subdirectory(ytest)
add_to_group( LIBRARY_PL pl_library) add_to_group( LIBRARY_PL pl_library)
install(FILES ${LIBRARY_PL} DESTINATION ${libpl}) install(FILES ${LIBRARY_PL} DESTINATION ${YAP_INSTALL_DATADIR})
if (ANDROID) if (ANDROID)
file( INSTALL ${LIBRARY_PL} DESTINATION ${libpl} ) file( INSTALL ${LIBRARY_PL} DESTINATION ${YAP_INSTALL_DATADIR} )
endif() endif()
include_directories("dialect/swi") include_directories("dialect/swi")

View File

@ -23,28 +23,30 @@
/** /**
* *
*
@defgroup args Term Argument Manipulation. * @defgroup args Term Argument Manipulation.
*
@ingroup @library * @ingroup library
*
@{ * @{
*
Extends arg/3 by including backtracking through arguments and access *This library extends arg/3 by supporting backtracking through
to sub-arguments, *arguments and access to sub-arguments,
*
- arg0/3 * - arg0/3
- args/3 * - args/3
- args0/3 * - args0/3
- genarg/3 * - genarg/3
- genarg0/3 * - genarg0/3
- path_arg/3 * - path_arg/3
*
*
It is based on the Quintus Prolog arg library. Except for project, all *It is based on the Quintus Prolog public domain library. Except for
predicates use the arg/3 argument pattern. *project, all predicates use the arg/3 argument pattern. This file has
This file has been included in the YAP library by Vitor Santos Costa, 2008. No error checking is actuallly performed within the package: this left to the C-code thaat implements arg``/3 and *been included in the YAP library by Vitor Santos Costa, 2008.
genarg/3. *
* No error checking is actuallly performed within the package: this
*left to the C-code that implements arg/3 and genarg/3.
*/ */
/** /**

View File

@ -5,7 +5,7 @@ set (LIBRARY_PL_VLP
) )
install(FILES ${LIBRARY_PL_CLP} install(FILES ${LIBRARY_PL_CLP}
DESTINATION ${libpl} DESTINATION ${YAP_INSTALL_DATADIR}
) )

View File

@ -7,7 +7,7 @@ set (LIBRARY_PL_CLP
add_to_group( LIBRARY_PL_CLP pl_library ) add_to_group( LIBRARY_PL_CLP pl_library )
install(FILES ${LIBRARY_PL_CLP} install(FILES ${LIBRARY_PL_CLP}
DESTINATION ${libpl} DESTINATION ${YAP_INSTALL_DATADIR}
) )

View File

@ -14,5 +14,5 @@ COMMAND ${CMAKE_COMMAND} -E touch visited
DEPENDS ${DIALECTS_PL} ) # WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) DEPENDS ${DIALECTS_PL} ) # WORKING_DIRECTORY ${CMAKE_BINARY_DIR} )
install(FILES ${DIALECTS_PL} install(FILES ${DIALECTS_PL}
DESTINATION ${libpl}/dialect DESTINATION ${YAP_INSTALL_DATADIR}/dialect
) )

View File

@ -7,5 +7,5 @@ set (SDIALECTS_PL
add_SubDirectory( fli ) add_SubDirectory( fli )
install(FILES ${SDIALECTS_PL} install(FILES ${SDIALECTS_PL}
DESTINATION ${libpl}/dialect/swi DESTINATION ${YAP_INSTALL_DATADIR}/dialect/swi
) )

View File

@ -8,7 +8,7 @@ add_component (libswi
MY_set_target_properties(libswi MY_set_target_properties(libswi
PROPERTIES PROPERTIES
# RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION} # RPATH ${CMAKE_INSTALL_LIBDIR} VERSION ${LIBYAPTAI_FULL_VERSION}
# SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION} # SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION}
POSITION_INDEPENDENT_CODE ON POSITION_INDEPENDENT_CODE ON
) )

View File

@ -58,7 +58,7 @@ add_component (libswi_os
set_target_properties(libswi_os set_target_properties(libswi_os
PROPERTIES PROPERTIES
# RPATH ${libdir} VERSION ${LIBSWI_OS_FULL_VERSION} # RPATH ${CMAKE_INSTALL_LIBDIR} VERSION ${LIBSWI_OS_FULL_VERSION}
# SOVERSION ${LIBSWI_OS_MAJOR_VERSION}.${LIBSWI_OS_MINOR_VERSION} # SOVERSION ${LIBSWI_OS_MAJOR_VERSION}.${LIBSWI_OS_MINOR_VERSION}
POSITION_INDEPENDENT_CODE TRUE POSITION_INDEPENDENT_CODE TRUE
OUTPUT_NAME swi_os OUTPUT_NAME swi_os

View File

@ -45,7 +45,7 @@ add_library (libyaptai OBJECT
set_target_properties(libyaptai set_target_properties(libyaptai
PROPERTIES PROPERTIES
# RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION} # RPATH ${CMAKE_INSTALL_LIBDIR} VERSION ${LIBYAPTAI_FULL_VERSION}
# SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION} # SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION}
POSITION_INDEPENDENT_CODE TRUE POSITION_INDEPENDENT_CODE TRUE
OUTPUT_NAME yaptai OUTPUT_NAME yaptai

View File

@ -28,21 +28,20 @@
:- dynamic gensym_key/2. :- dynamic gensym_key/2.
init_gensym(Key) :- init_gensym(Key) :-
assert(gensym_key(Atom,0) ). retractall(gensym_key(Key,_)),
assert(gensym_key(Key,0) ).
gensym(Atom, New) :- gensym(Key, New) :-
retract(gensym_key(Atom,Id)), !, retract(gensym_key(Key,Id)), !,
atomic_concat(Atom,Id,New), atomic_concat(Key,Id,New),
NId is Id+1, NId is Id+1,
assert(gensym_key(Atom,NId)). assert(gensym_key(Key,NId)).
gensym(Atom, New) :- gensym(Atom, New) :-
atomic_concat(Atom,1,New), atomic_concat(Atom,0,New),
assert(gensym_key(Atom,2)). assert(gensym_key(Atom,1)).
reset_gensym(Atom) :- reset_gensym(Atom) :-
retract(gensym_key(Atom,_)). retract(gensym_key(Atom,_)).
reset_gensym :- reset_gensym :-
retractall(gensym_key(_,_)). retractall(gensym_key(_,_)).

View File

@ -78,9 +78,9 @@ set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS HAVE_MPI_H=1)
PUBLIC ${MPI_C_COMPILE_FLAGS}) PUBLIC ${MPI_C_COMPILE_FLAGS})
install(TARGETS yap_mpi install(TARGETS yap_mpi
RUNTIME DESTINATION ${bindir} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR} LIBRARY DESTINATION ${YAP_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} ARCHIVE DESTINATION ${YAP_INSTALL_LIBDIR}
) )
endif (MPI_C_FOUND) endif (MPI_C_FOUND)

View File

@ -31,20 +31,3 @@
portray_clause/2, % +Stream, +Clause portray_clause/2, % +Stream, +Clause
portray_clause/3 % +Stream, +Clause, +Options portray_clause/3 % +Stream, +Clause, +Options
]). ]).
/*
* @defgroup swi_listing SWI Prolog listing emulation
* @ingroup library
emulates listing.pl, but just the interface for now.
*/
:- meta_predicate portray_clause( +, + , : ).
portray_clause(Stream, Term, M:Options) :-
portray_clause( Stream, Term ).

View File

@ -57,7 +57,7 @@
with the `use_module(library(lists))` command. with the `use_module(library(lists))` command.
*/ */
:- include(pl/bootlists). %:- include(pl/bootlists).
/** @pred list_concat(+ _Lists_,? _List_) /** @pred list_concat(+ _Lists_,? _List_)

View File

@ -65,7 +65,7 @@
sumnodes_body(3,+,+,-,+,+), sumnodes_body(3,+,+,-,+,+),
include(1,+,-), include(1,+,-),
exclude(1,+,-), exclude(1,+,-),
partition(2,+,-,-), partition(1,+,-,-),
partition(2,+,-,-,-), partition(2,+,-,-,-),
foldl(3, +, +, -), foldl(3, +, +, -),
foldl2(5, +, +, -, +, -), foldl2(5, +, +, -, +, -),

View File

@ -77,7 +77,7 @@ aux_args([Arg|Args], MVars, [Arg|PArgs], PVars, [Arg|ProtoArgs]) :-
aux_args([Arg|Args], [Arg|MVars], [PVar|PArgs], [PVar|PVars], ['_'|ProtoArgs]) :- aux_args([Arg|Args], [Arg|MVars], [PVar|PArgs], [PVar|PVars], ['_'|ProtoArgs]) :-
aux_args(Args, MVars, PArgs, PVars, ProtoArgs). aux_args(Args, MVars, PArgs, PVars, ProtoArgs).
pred_name(Macro, Arity, _ , Name) :- pred_name(Macro, Arity, P , Name) :-
prolog_load_context(file, FullFileName), prolog_load_context(file, FullFileName),
file_base_name( FullFileName, File ), file_base_name( FullFileName, File ),
prolog_load_context(term_position, Pos), prolog_load_context(term_position, Pos),

View File

@ -15,8 +15,8 @@ if (MATLAB_FOUND)
target_link_libraries(matlab libYap $(MATLAB_LIBRARIES) ) target_link_libraries(matlab libYap $(MATLAB_LIBRARIES) )
install(TARGETS matlab install(TARGETS matlab
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR} RUNTIME DESTINATION ${YAP_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} ) ARCHIVE DESTINATION ${YAP_INSTALL_LIBDIR} )
endif (MATLAB_FOUND) endif (MATLAB_FOUND)

View File

@ -775,6 +775,9 @@ rhs(log(RHS), Logs ) :- !,
rhs(exp(RHS), Logs ) :- !, rhs(exp(RHS), Logs ) :- !,
rhs(RHS, X1), rhs(RHS, X1),
matrix_to_exps( X1, Logs ). matrix_to_exps( X1, Logs ).
rhs(sum(RHS), Logs ) :- !,
rhs(RHS, X1),
matrix_sum( X1, Logs ).
rhs(S, NS) :- rhs(S, NS) :-
rhs_opaque( S ), !, rhs_opaque( S ), !,
S = NS. S = NS.

View File

@ -6,8 +6,8 @@ target_link_libraries(matrix libYap)
set_target_properties (matrix PROPERTIES PREFIX "") set_target_properties (matrix PROPERTIES PREFIX "")
install(TARGETS matrix install(TARGETS matrix
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR} RUNTIME DESTINATION ${YAP_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} ARCHIVE DESTINATION ${YAP_INSTALL_LIBDIR}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR} LIBRARY DESTINATION ${YAP_INSTALL_LIBDIR}
) )

File diff suppressed because it is too large Load Diff

View File

@ -10,5 +10,5 @@ set_target_properties (yap_random PROPERTIES PREFIX "")
endif() endif()
MY_install(TARGETS yap_random MY_install(TARGETS yap_random
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR} LIBRARY DESTINATION ${YAP_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} ) ARCHIVE DESTINATION ${YAP_INSTALL_LIBDIR} )

View File

@ -8,14 +8,11 @@
* * * *
************************************************************************** **************************************************************************
* * * *
* File: random.c * * File: random.c * Last rev:
* Last rev: * ** mods: * comments: regular expression interpreter *
* mods: *
* comments: regular expression interpreter *
* * * *
*************************************************************************/ *************************************************************************/
#include "config.h"
#include "YapInterface.h" #include "YapInterface.h"
#include <math.h> #include <math.h>
#if defined(__MINGW32__) || _MSC_VER #if defined(__MINGW32__) || _MSC_VER
@ -26,9 +23,7 @@ X_API void init_random( void );
static short a1 = 27314, b1 = 9213, c1 = 17773; static short a1 = 27314, b1 = 9213, c1 = 17773;
static YAP_Bool static YAP_Bool p_random(void) {
p_random(void)
{
double fli; double fli;
long int t1, t2, t3; long int t1, t2, t3;
@ -42,26 +37,20 @@ p_random(void)
return (YAP_Unify(YAP_ARG1, YAP_MkFloatTerm(fli - (int)(fli)))); return (YAP_Unify(YAP_ARG1, YAP_MkFloatTerm(fli - (int)(fli))));
} }
static YAP_Bool static YAP_Bool p_setrand(void) {
p_setrand(void)
{
a1 = YAP_IntOfTerm(YAP_ARG1); a1 = YAP_IntOfTerm(YAP_ARG1);
b1 = YAP_IntOfTerm(YAP_ARG2); b1 = YAP_IntOfTerm(YAP_ARG2);
c1 = YAP_IntOfTerm(YAP_ARG3); c1 = YAP_IntOfTerm(YAP_ARG3);
return (TRUE); return (TRUE);
} }
static YAP_Bool static YAP_Bool p_getrand(void) {
p_getrand(void)
{
return (YAP_Unify(YAP_ARG1, YAP_MkIntTerm(a1)) && return (YAP_Unify(YAP_ARG1, YAP_MkIntTerm(a1)) &&
YAP_Unify(YAP_ARG2, YAP_MkIntTerm(b1)) && YAP_Unify(YAP_ARG2, YAP_MkIntTerm(b1)) &&
YAP_Unify(YAP_ARG3, YAP_MkIntTerm(c1))); YAP_Unify(YAP_ARG3, YAP_MkIntTerm(c1)));
} }
X_API void X_API void init_random(void) {
init_random(void)
{
YAP_UserCPredicate("random", p_random, 1); YAP_UserCPredicate("random", p_random, 1);
YAP_UserCPredicate("setrand", p_setrand, 3); YAP_UserCPredicate("setrand", p_setrand, 3);
YAP_UserCPredicate("getrand", p_getrand, 3); YAP_UserCPredicate("getrand", p_getrand, 3);
@ -71,10 +60,8 @@ init_random(void)
int WINAPI win_random(HANDLE, DWORD, LPVOID); int WINAPI win_random(HANDLE, DWORD, LPVOID);
int WINAPI win_random(HANDLE hinst, DWORD reason, LPVOID reserved) int WINAPI win_random(HANDLE hinst, DWORD reason, LPVOID reserved) {
{ switch (reason) {
switch (reason)
{
case DLL_PROCESS_ATTACH: case DLL_PROCESS_ATTACH:
break; break;
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:

View File

@ -26,6 +26,6 @@ TARGET_INCLUDE_DIRECTORIES (regexp PUBLIC BEFORE
${CMAKE_TOP_SOURCE_DIR}/include;${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR} ) ${CMAKE_TOP_SOURCE_DIR}/include;${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR} )
install(TARGETS regexp install(TARGETS regexp
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR} LIBRARY DESTINATION ${YAP_INSTALL_LIBDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR} RUNTIME DESTINATION ${YAP_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} ) ARCHIVE DESTINATION ${YAP_INSTALL_LIBDIR} )

View File

@ -50,7 +50,7 @@ static char sccsid[] = "@(#)regcomp.c 8.5 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include "YapInterface.h" #include "YapInterface.h"
#include "config.h"
#if HAVE_SYS_TYPES_H #if HAVE_SYS_TYPES_H
#include <sys/types.h> #include <sys/types.h>
#endif #endif

View File

@ -48,11 +48,10 @@ static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94";
* macros that code uses. This lets the same code operate on two different * macros that code uses. This lets the same code operate on two different
* representations for state sets. * representations for state sets.
*/ */
#include "config.h" #include "YapInterface.h"
#ifndef HAVE_REGEXEC #ifndef HAVE_REGEXEC
#include "YapInterface.h"
#if HAVE_SYS_TYPES_H #if HAVE_SYS_TYPES_H
#include <sys/types.h> #include <sys/types.h>
#endif #endif
@ -68,8 +67,8 @@ static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94";
#include <limits.h> #include <limits.h>
#endif #endif
#include "utils.h"
#include "regex2.h" #include "regex2.h"
#include "utils.h"
#include "yapregex.h" #include "yapregex.h"
#if used #if used

View File

@ -22,7 +22,6 @@
* *
*/ */
#include "config.h"
#if HAVE_SYS_TYPES_H #if HAVE_SYS_TYPES_H
#include <sys/types.h> #include <sys/types.h>
#endif #endif

View File

@ -40,6 +40,8 @@
#ifndef _REGEX_H_ #ifndef _REGEX_H_
#define _REGEX_H_ #define _REGEX_H_
#include "YapInterface.h"
/* types */ /* types */
typedef int regoff_t; typedef int regoff_t;

View File

@ -11,6 +11,6 @@ target_link_libraries(yap_rl libYap)
set_target_properties (yap_rl PROPERTIES PREFIX "") set_target_properties (yap_rl PROPERTIES PREFIX "")
install(TARGETS yap_rl install(TARGETS yap_rl
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR} LIBRARY DESTINATION ${YAP_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} ) ARCHIVE DESTINATION ${YAP_INSTALL_LIBDIR} )

View File

@ -20,8 +20,6 @@
* @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan> * @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan>
* @date Wed Nov 18 01:23:45 2015 * @date Wed Nov 18 01:23:45 2015
* *
* @brief interaction with the OS, be it Unix, Linux, or Windows.
*
* *
*/ */
@ -33,6 +31,7 @@
delete_file/1, delete_file/1,
delete_file/2, delete_file/2,
directory_files/2, directory_files/2,
directory_map/2,
environ/2, environ/2,
exec/3, exec/3,
file_exists/2, file_exists/2,
@ -61,7 +60,11 @@
working_directory/2 working_directory/2
]). ]).
/** @defgroup operating_system_support, Operating System Functionality
/** @defgroup operating_system_support Operating System Functionality
* @brief Portable Interaction with the OS, be it Unix, Linux, OSX, or Windows.
*
@ingroup library @ingroup library
@{ @{
@ -74,13 +77,6 @@ are available through the `use_module(library(system))` command.
*/ */
/** @pred file_exists(+ _File_)
The atom _File_ corresponds to an existing file.
*/
/** @pred file_property(+ _File_,? _Property_) /** @pred file_property(+ _File_,? _Property_)
@ -212,13 +208,6 @@ completes. YAP uses `/bin/sh` in Unix systems and `COMSPEC` in
WIN32. WIN32.
*/
/** @pred system(+ _Command_,- _Res_)
Interface to `system`: execute command _Command_ and unify
_Res_ with the result.
*/ */
/** @pred tmp_file(+_Base_, - _File_) /** @pred tmp_file(+_Base_, - _File_)
@ -236,21 +225,6 @@ temporary files.
Interface with _tmpnam_: obtain a new, unique file name _File_. Interface with _tmpnam_: obtain a new, unique file name _File_.
*/
/** @pred working_directory(- _Old_,+ _New_)
/** @pred working_directory(- _CurDir_,? _NextDir_)
Fetch the current directory at _CurDir_. If _NextDir_ is bound
to an atom, make its value the current working directory.
Unifies _Old_ with an absolute path to the current working directory
and change working directory to _New_. Use the pattern
`working_directory(CWD, CWD)` to get the current directory. See
also `absolute_file_name/2` and chdir/1.
*/ */
:- use_module(library(lists), [append/3]). :- use_module(library(lists), [append/3]).
@ -451,15 +425,11 @@ if there is one. This predicate is backtrackable in Unix systems, but
not currently in Win32 configurations. not currently in Win32 configurations.
~~~~~ ~~~~~
?- environ('HOME',X). ?- environ('HOME',V).
X = 'C:\\cygwin\\home\\administrator' ? V = 'C:\\cygwin\\home\\administrator' ?
~~~~~ ~~~~~
*/ _EnvVar_ may be bound to an atom, or just be
/** @pred environ(+E, -S)
Given an environment variable _E_ this predicate unifies the second
argument _S_ with its value. _E_ may be bound to an atom, or just be
unbound. In the latter case environ/2 will enumerate over all unbound. In the latter case environ/2 will enumerate over all
environment variables. environment variables.
@ -666,6 +636,19 @@ get_shell(Shell, '/c') :-
getenv('COMSPEC', Shell). getenv('COMSPEC', Shell).
get_shell('/bin/sh','-c'). get_shell('/bin/sh','-c').
/**
* @pred system(+ _S_)
Passes command _S_ to the Bourne shell (on UNIX environments) or the
current command interpreter in WIN32 environments.
*/
/**
* @pred system
Passes command _S_ to the Bourne shell (on UNIX environments) or the
current command interpreter in WIN32 environments.
*/
system :- system :-
default_shell(Command), default_shell(Command),
do_system(Command, _Status, Error), do_system(Command, _Status, Error),
@ -676,6 +659,13 @@ default_shell(Shell) :- win, !,
default_shell('/bin/sh'). default_shell('/bin/sh').
/** @pred system(+ _Command_,- _Res_)
Interface to `system`: execute command _Command_ and unify
_Res_ with the result.
n*/
system(Command, Status) :- system(Command, Status) :-
G = system(Command, Status), G = system(Command, Status),
check_command(Command, G), check_command(Command, G),
@ -764,13 +754,6 @@ rename_file(F0, F) :-
rename_file(F0, F, Error), rename_file(F0, F, Error),
handle_system_internal(Error, off, rename_file(F0, F)). handle_system_internal(Error, off, rename_file(F0, F)).
/**
* @pred system(+ _S_)
Passes command _S_ to the Bourne shell (on UNIX environments) or the
current command interpreter in WIN32 environments.
*/
/** @pred directory_files(+ _Dir_,+ _List_) /** @pred directory_files(+ _Dir_,+ _List_)
@ -788,4 +771,46 @@ environments, and `findfirst` in WIN32 through the system_library buil
directory_files(X,Y) :- directory_files(X,Y) :-
list_directory(X,Y). list_directory(X,Y).
:- meta_predicate directory_map(+,1,-),
rb_apply(+,+,2,-).
/** @pred directory_map(+ _Dir_, 1:_P_)
Given a directory _Dir_, directory_map/2 visits all files in _Dir_,
and verifies whether `P(F)` holds, where _F_ is the file's absolute
path.
~~~~~
?- directory_map('.', process).
~~~~~
The predicates performs a left-recursive traversal. It does not protect against file system errors and it does not check for symbolic links.
*/
directory_map(D, P) :-
working_directory(_, D),
list_directory(D,L),
d_map(L,D, P).
d_map([],_,_).
d_map(['.'|Fs],D, P) :-
!,
d_map(Fs,D, P).
d_map(['..'|Fs],D, P) :-
!,
d_map(Fs, D, P).
d_map([F|Fs], D, P) :-
absolute_file_name( F, File, [prefix(D)] ),
f_map(File, P),
d_map(Fs, D, P).
f_map(File, P) :-
catch( file_property( File, type(directory) ), _, fail ),
directory_map( File, P).
f_map(File, P) :-
call(P,File).
/** @} */ /** @} */

View File

@ -39,8 +39,8 @@ set_target_properties (sys PROPERTIES PREFIX "")
endif() endif()
MY_install(TARGETS sys MY_install(TARGETS sys
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR} LIBRARY DESTINATION ${YAP_INSTALL_LIBDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR} RUNTIME DESTINATION ${YAP_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} ) ARCHIVE DESTINATION ${YAP_INSTALL_LIBDIR} )
configure_file ("sys_config.h.cmake" "sys_config.h" ) configure_file ("sys_config.h.cmake" "sys_config.h" )

Some files were not shown because too many files have changed in this diff Show More