Merge /home/vsc/github/yapdroid/join_yap/yap

This commit is contained in:
Vítor Santos Costa 2019-01-21 18:53:43 +00:00
commit 4aaad2b221
97 changed files with 3438 additions and 4084 deletions

View File

@ -378,16 +378,6 @@ ADDR Yap_ExpandPreAllocCodeSpace(UInt sz0, void *cip, int safe) {
struct various_codes *Yap_heap_regs; struct various_codes *Yap_heap_regs;
static void InitHeap(void) {
Yap_heap_regs =
(struct various_codes *)calloc(1, sizeof(struct various_codes));
}
void Yap_InitHeap(void *heap_addr) {
InitHeap();
Yap_HoleSize = 0;
HeapMax = 0;
}
// get an approximation to total memory data-base size. // get an approximation to total memory data-base size.
size_t Yap_HeapUsed(void) size_t Yap_HeapUsed(void)
@ -400,9 +390,9 @@ void Yap_InitHeap(void *heap_addr) {
#endif #endif
} }
static void InitExStacks(int wid, int Trail, int Stack) { static void InitExStacks(int wid, size_t Trail, size_t Stack) {
CACHE_REGS CACHE_REGS
UInt pm, sa; size_t pm, sa;
/* sanity checking for data areas */ /* sanity checking for data areas */
if (Trail < MinTrailSpace) if (Trail < MinTrailSpace)
@ -428,7 +418,7 @@ static void InitExStacks(int wid, int Trail, int Stack) {
#if DEBUG #if DEBUG
if (Yap_output_msg) { if (Yap_output_msg) {
UInt ta; size_t ta;
fprintf(stderr, fprintf(stderr,
"HeapBase = %p GlobalBase = %p\n LocalBase = %p TrailTop = %p\n", "HeapBase = %p GlobalBase = %p\n LocalBase = %p TrailTop = %p\n",
@ -443,7 +433,7 @@ static void InitExStacks(int wid, int Trail, int Stack) {
#endif /* DEBUG */ #endif /* DEBUG */
} }
void Yap_InitExStacks(int wid, int Trail, int Stack) { void Yap_InitExStacks(int wid, size_t Trail, size_t Stack) {
InitExStacks(wid, Trail, Stack); InitExStacks(wid, Trail, Stack);
} }
@ -464,7 +454,12 @@ void Yap_KillStacks(int wid) {
} }
#endif #endif
void Yap_InitMemory(UInt Trail, UInt Heap, UInt Stack) { InitHeap(); } void Yap_InitMemory(size_t Trail, size_t Heap, size_t Stack) {
Yap_HoleSize = 0;
HeapMax = 0;
Yap_heap_regs =
(struct various_codes *)calloc(1, sizeof(struct various_codes));
}
int Yap_ExtendWorkSpace(Int s) { int Yap_ExtendWorkSpace(Int s) {
CACHE_REGS CACHE_REGS

View File

@ -101,7 +101,7 @@ X_API int YAP_Reset(yap_reset_t mode, bool reset_global);
#define X_API __declspec(dllexport) #define X_API __declspec(dllexport)
#endif #endif
#define BootFilePath NULL #define SOURCEBOOTPath NULL
#if __ANDROID__ #if __ANDROID__
#define BOOT_FROM_SAVED_STATE true #define BOOT_FROM_SAVED_STATE true
#endif #endif
@ -1799,7 +1799,7 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
/* make sure we didn't leave live slots when we backtrack */ /* make sure we didn't leave live slots when we backtrack */
ASP = (CELL *)B; ASP = (CELL *)B;
LOCAL_CurSlot = dgi->EndSlot; LOCAL_CurSlot = dgi->EndSlot;
out = run_emulator(PASS_REGS1); out = Yap_exec_absmi(true, true );
if (out) { if (out) {
dgi->EndSlot = LOCAL_CurSlot; dgi->EndSlot = LOCAL_CurSlot;
dgi->b = LCL0 - (CELL *)B; dgi->b = LCL0 - (CELL *)B;
@ -2114,7 +2114,7 @@ X_API int YAP_InitConsult(int mode, const char *fname, char **full,
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_SOURCEBOOT;
} }
if (!fname || !(fl = Yap_AbsoluteFile(fname, true)) || !fl[0]) { if (!fname || !(fl = Yap_AbsoluteFile(fname, true)) || !fl[0]) {
__android_log_print( __android_log_print(
@ -2249,7 +2249,7 @@ X_API char *YAP_WriteBuffer(Term t, char *buf, size_t sze, int flags) {
inp.val.t = t; inp.val.t = t;
inp.type = YAP_STRING_TERM | YAP_STRING_DATUM; inp.type = YAP_STRING_TERM | YAP_STRING_DATUM;
out.type = YAP_STRING_CHARS; out.type = YAP_STRING_CHARS;
out.val.c = buf; out.val.c = NULL;
out.max = sze - 1; out.max = sze - 1;
out.enc = LOCAL_encoding; out.enc = LOCAL_encoding;
if (!Yap_CVT_Text(&inp, &out PASS_REGS)) { if (!Yap_CVT_Text(&inp, &out PASS_REGS)) {
@ -2261,7 +2261,11 @@ X_API char *YAP_WriteBuffer(Term t, char *buf, size_t sze, int flags) {
if (buf == out.val.c) { if (buf == out.val.c) {
return buf; return buf;
} else { } else {
return pop_output_text_stack(l, out.val.c); if ( strlen(out.val.c ) < sze) {
strcpy( buf, out.val.c);
pop_text_stack(l);
return buf;
}
} }
} }
} }

View File

@ -2536,7 +2536,7 @@ static Int
// pe = Yap_get_pred(t1, Deref(ARG2), "system_predicate"); // pe = Yap_get_pred(t1, Deref(ARG2), "system_predicate");
// if (!pe) // if (!pe)
pe = Yap_get_pred(t1, Deref(ARG2), "system_predicate"); pe = Yap_get_pred(t1, Deref(ARG2), "system_predicate");
// if (!pe) pe = Yap_get_pred(t1, USER_MODULE, "system_predicate"); // if (!pe) pe = Yap_get_pred(t1, Deref(ARG2), "system_predicate");
if (EndOfPAEntr(pe)) if (EndOfPAEntr(pe))
return FALSE; return FALSE;
return (pe->ModuleOfPred == 0); return (pe->ModuleOfPred == 0);

View File

@ -2174,7 +2174,7 @@ void Yap_InitYaamRegs(int myworker_id, bool full_reset) {
#endif #endif
STATIC_PREDICATES_MARKED = FALSE; STATIC_PREDICATES_MARKED = FALSE;
if (full_reset) { if (full_reset) {
HR = H0 + 1; HB = HR = H0 + 1;
h0var = MkVarTerm(); h0var = MkVarTerm();
REMOTE_GcGeneration(myworker_id) = Yap_NewTimedVar(h0var); REMOTE_GcGeneration(myworker_id) = Yap_NewTimedVar(h0var);
REMOTE_GcCurrentPhase(myworker_id) = 0L; REMOTE_GcCurrentPhase(myworker_id) = 0L;
@ -2185,7 +2185,8 @@ void Yap_InitYaamRegs(int myworker_id, bool full_reset) {
h0var = MkVarTerm(); h0var = MkVarTerm();
REMOTE_AttsMutableList(myworker_id) = Yap_NewTimedVar(h0var); REMOTE_AttsMutableList(myworker_id) = Yap_NewTimedVar(h0var);
#endif #endif
Yap_AllocateDefaultArena(128 * 1024, 2, myworker_id); size_t defsz = 128*1024;
Yap_AllocateDefaultArena(defsz, myworker_id);
} else { } else {
HR = Yap_ArenaLimit(REMOTE_GlobalArena(myworker_id)); HR = Yap_ArenaLimit(REMOTE_GlobalArena(myworker_id));
} }

View File

@ -145,13 +145,13 @@ threads that are created <em>after</em> the registration.
#define Global_MkIntegerTerm(I) MkIntegerTerm(I) #define Global_MkIntegerTerm(I) MkIntegerTerm(I)
static UInt big2arena_sz(CELL *arena_base) { static size_t big2arena_sz(CELL *arena_base) {
return (((MP_INT *)(arena_base + 2))->_mp_alloc * sizeof(mp_limb_t) + return (((MP_INT *)(arena_base + 2))->_mp_alloc * sizeof(mp_limb_t) +
sizeof(MP_INT) + sizeof(Functor) + 2 * sizeof(CELL)) / sizeof(MP_INT) + sizeof(Functor) + 2 * sizeof(CELL)) /
sizeof(CELL); sizeof(CELL);
} }
static UInt arena2big_sz(UInt sz) { static size_t arena2big_sz(size_t sz) {
return sz - return sz -
(sizeof(MP_INT) + sizeof(Functor) + 2 * sizeof(CELL)) / sizeof(CELL); (sizeof(MP_INT) + sizeof(Functor) + 2 * sizeof(CELL)) / sizeof(CELL);
} }
@ -159,7 +159,7 @@ static UInt arena2big_sz(UInt sz) {
/* pointer to top of an arena */ /* pointer to top of an arena */
static inline CELL *ArenaLimit(Term arena) { static inline CELL *ArenaLimit(Term arena) {
CELL *arena_base = RepAppl(arena); CELL *arena_base = RepAppl(arena);
UInt sz = big2arena_sz(arena_base); size_t sz = big2arena_sz(arena_base);
return arena_base + sz; return arena_base + sz;
} }
@ -171,9 +171,9 @@ CELL *Yap_ArenaLimit(Term arena) {
/* pointer to top of an arena */ /* pointer to top of an arena */
static inline CELL *ArenaPt(Term arena) { return (CELL *)RepAppl(arena); } static inline CELL *ArenaPt(Term arena) { return (CELL *)RepAppl(arena); }
static inline UInt ArenaSz(Term arena) { return big2arena_sz(RepAppl(arena)); } static inline size_t ArenaSz(Term arena) { return big2arena_sz(RepAppl(arena)); }
static Term CreateNewArena(CELL *ptr, UInt size) { static Term CreateNewArena(CELL *ptr, size_t size) {
Term t = AbsAppl(ptr); Term t = AbsAppl(ptr);
MP_INT *dst; MP_INT *dst;
@ -186,9 +186,9 @@ static Term CreateNewArena(CELL *ptr, UInt size) {
return t; return t;
} }
static Term NewArena(UInt size, int wid, UInt arity, CELL *where) { static Term NewArena(size_t size, int wid, UInt arity, CELL *where) {
Term t; Term t;
UInt new_size; size_t new_size;
WORKER_REGS(wid) WORKER_REGS(wid)
if (where == NULL || where == HR) { if (where == NULL || where == HR) {
@ -228,11 +228,11 @@ static Int p_default_arena_size(USES_REGS1) {
return Yap_unify(ARG1, MkIntegerTerm(ArenaSz(LOCAL_GlobalArena))); return Yap_unify(ARG1, MkIntegerTerm(ArenaSz(LOCAL_GlobalArena)));
} }
void Yap_AllocateDefaultArena(Int gsize, Int attsize, int wid) { void Yap_AllocateDefaultArena(size_t gsize, int wid) {
REMOTE_GlobalArena(wid) = NewArena(gsize, wid, 2, NULL); REMOTE_GlobalArena(wid) = NewArena(gsize, wid, 2, NULL);
} }
static void adjust_cps(UInt size USES_REGS) { static void adjust_cps(size_t size USES_REGS) {
/* adjust possible back pointers in choice-point stack */ /* adjust possible back pointers in choice-point stack */
choiceptr b_ptr = B; choiceptr b_ptr = B;
while (b_ptr->cp_h == HR) { while (b_ptr->cp_h == HR) {
@ -290,14 +290,14 @@ static int GrowArena(Term arena, CELL *pt, size_t old_size, size_t size,
return TRUE; return TRUE;
} }
CELL *Yap_GetFromArena(Term *arenap, UInt cells, UInt arity) { CELL *Yap_GetFromArena(Term *arenap, size_t cells, UInt arity) {
CACHE_REGS CACHE_REGS
restart : { restart : {
Term arena = *arenap; Term arena = *arenap;
CELL *max = ArenaLimit(arena); CELL *max = ArenaLimit(arena);
CELL *base = ArenaPt(arena); CELL *base = ArenaPt(arena);
CELL *newH; CELL *newH;
UInt old_sz = ArenaSz(arena), new_size; size_t old_sz = ArenaSz(arena), new_size;
if (IN_BETWEEN(base, HR, max)) { if (IN_BETWEEN(base, HR, max)) {
base = HR; base = HR;
@ -319,8 +319,8 @@ restart : {
} }
static void CloseArena(CELL *oldH, CELL *oldHB, CELL *oldASP, Term *oldArenaP, static void CloseArena(CELL *oldH, CELL *oldHB, CELL *oldASP, Term *oldArenaP,
UInt old_size USES_REGS) { size_t old_size USES_REGS) {
UInt new_size; size_t new_size;
if (HR == oldH) if (HR == oldH)
return; return;
@ -357,7 +357,7 @@ static inline void clean_dirty_tr(tr_fr_ptr TR0 USES_REGS) {
SP = S0+used; SF = S0+sz; } SP = S0+used; SF = S0+sz; }
static int copy_complex_term(register CELL *pt0, register CELL *pt0_end, static int copy_complex_term(register CELL *pt0, register CELL *pt0_end,
int share, int copy_att_vars, CELL *ptf, bool share, bool copy_att_vars, CELL *ptf,
CELL *HLow USES_REGS) { CELL *HLow USES_REGS) {
int lvl = push_text_stack(); int lvl = push_text_stack();
@ -480,7 +480,7 @@ loop:
break; break;
default: { default: {
/* big int */ /* big int */
UInt sz = (sizeof(MP_INT) + 3 * CellSize + size_t sz = (sizeof(MP_INT) + 3 * CellSize +
((MP_INT *)(ap2 + 2))->_mp_alloc * sizeof(mp_limb_t)) / ((MP_INT *)(ap2 + 2))->_mp_alloc * sizeof(mp_limb_t)) /
CellSize, CellSize,
i; i;

View File

@ -1321,8 +1321,8 @@ const char *Yap_version(void) {
} }
void Yap_InitWorkspace(struct yap_boot_params *yapi, void Yap_InitWorkspace(struct yap_boot_params *yapi,
UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt Heap, size_t Stack, size_t Trail, size_t Atts,
UInt max_table_size, int n_workers, int sch_loop, size_t max_table_size, int n_workers, int sch_loop,
int delay_load) int delay_load)
{ {
CACHE_REGS CACHE_REGS
@ -1364,11 +1364,7 @@ void Yap_InitWorkspace(struct yap_boot_params *yapi,
Stack = MinStackSpace; Stack = MinStackSpace;
Stack = AdjustPageSize(Stack * K); Stack = AdjustPageSize(Stack * K);
Stack /= (K); Stack /= (K);
if (!Atts) Atts = 0;
Atts = 2048 * sizeof(CELL);
else
Atts = AdjustPageSize(Atts * K);
Atts /= (K);
#if defined(THREADS) || defined(YAPOR) #if defined(THREADS) || defined(YAPOR)
worker_id = 0; worker_id = 0;
#endif /* YAPOR || THREADS */ #endif /* YAPOR || THREADS */

View File

@ -45,9 +45,6 @@ Int p_load_foreign(USES_REGS1) {
StringList new; StringList new;
bool returncode = FALSE; bool returncode = FALSE;
yhandle_t CurSlot = Yap_StartSlots(); yhandle_t CurSlot = Yap_StartSlots();
#if __ANDROID__
return true;
#endif
// Yap_DebugPlWrite(ARG1); printf("%s\n", " \n"); // Yap_DebugPlWrite(ARG1); printf("%s\n", " \n");
// Yap_DebugPlWrite(ARG2); printf("%s\n", " \n"); // Yap_DebugPlWrite(ARG2); printf("%s\n", " \n");
@ -246,7 +243,28 @@ static Int p_open_shared_objects(USES_REGS1) {
#endif #endif
} }
static Int check_embedded(USES_REGS1)
{
const char *s = Yap_TextTermToText(Deref(ARG1));
if (!s)
return false;
#if EMBEDDED_MYDDAS
if (!strcmp("init_myddas",s)) {
init_myddas();
return true;
}
#endif
#if EMBEDDED_SQLITE3
if (!strcmp("init_sqlite3",s)) {
init_sqlite3();
return true;
}
#endif
return false;
}
void Yap_InitLoadForeign(void) { void Yap_InitLoadForeign(void) {
Yap_InitCPred("$check_embedded", 1, check_embedded, SafePredFlag);
Yap_InitCPred("$load_foreign_files", 3, p_load_foreign, Yap_InitCPred("$load_foreign_files", 3, p_load_foreign,
SafePredFlag | SyncPredFlag); SafePredFlag | SyncPredFlag);
Yap_InitCPred("$open_shared_objects", 0, p_open_shared_objects, SafePredFlag); Yap_InitCPred("$open_shared_objects", 0, p_open_shared_objects, SafePredFlag);

View File

@ -197,6 +197,7 @@ Term Yap_Module(Term tmod) {
ModEntry *Yap_GetModuleEntry(Term mod) { ModEntry *Yap_GetModuleEntry(Term mod) {
ModEntry *me; ModEntry *me;
if (!(me = LookupModule(mod))) if (!(me = LookupModule(mod)))
return NULL; return NULL;
return me; return me;

View File

@ -1110,7 +1110,7 @@ YAP_file_type_t Yap_Restore(const char *s) {
return -1; return -1;
GLOBAL_RestoreFile = s; GLOBAL_RestoreFile = s;
if (do_header(stream) == NIL) if (do_header(stream) == NIL)
return YAP_BOOT_PL; return YAP_PL;
read_module(stream); read_module(stream);
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, true); setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, true);
fclose(stream); fclose(stream);

526
C/stack.c
View File

@ -1,3 +1,5 @@
/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog * * YAP Prolog *
@ -277,9 +279,14 @@ bool Yap_search_for_static_predicate_in_use(PredEntry *p,
yamop *cp = (yamop *)env_ptr[E_CP]; yamop *cp = (yamop *)env_ptr[E_CP];
PredEntry *pe; PredEntry *pe;
if (!cp)
return true;
pe = EnvPreg(cp); pe = EnvPreg(cp);
if (p == pe) if (p == pe)
return true; return true;
if( env_ptr == (CELL *)(env_ptr[E_E]))
return false;
if (env_ptr != NULL) if (env_ptr != NULL)
env_ptr = (CELL *)(env_ptr[E_E]); env_ptr = (CELL *)(env_ptr[E_E]);
} }
@ -1507,15 +1514,15 @@ static Int p_cpc_info(USES_REGS1) {
Yap_unify(ARG5, MkIntegerTerm(ClauseId(ipc, pe))); Yap_unify(ARG5, MkIntegerTerm(ClauseId(ipc, pe)));
} }
static Int p_choicepoint_info(USES_REGS1) { static PredEntry *choicepoint_owner(choiceptr cptr, Term *tp, yamop **nclp)
choiceptr cptr = (choiceptr)(LCL0 - IntegerOfTerm(Deref(ARG1))); {
PredEntry *pe = NULL; PredEntry *pe =
NULL;
int go_on = TRUE; int go_on = TRUE;
yamop *ipc = cptr->cp_ap; yamop *ipc = cptr->cp_ap;
yamop *ncl = NULL; yamop *ncl = NULL;
Term t = TermNil, taddr; Term t = TermNil;
taddr = MkIntegerTerm((Int)cptr);
while (go_on) { while (go_on) {
op_numbers opnum = Yap_op_from_opcode(ipc->opc); op_numbers opnum = Yap_op_from_opcode(ipc->opc);
go_on = FALSE; go_on = FALSE;
@ -1680,9 +1687,24 @@ static Int p_choicepoint_info(USES_REGS1) {
} break; } break;
case _Ystop: case _Ystop:
default: default:
return FALSE; pe = NULL;
} }
} }
if (tp)
*tp = t;
if (nclp)
*nclp = ncl;
return pe;
}
static Int p_choicepoint_info(USES_REGS1) {
PredEntry *pe;
Term t, taddr;
yamop *ncl;
choiceptr cptr = (choiceptr)(LCL0 - IntegerOfTerm(Deref(ARG1)));
taddr = MkIntegerTerm((Int)cptr);
pe = choicepoint_owner(cptr, &t, &ncl);
return UnifyPredInfo(pe, 3 PASS_REGS) && Yap_unify(ARG2, taddr) && return UnifyPredInfo(pe, 3 PASS_REGS) && Yap_unify(ARG2, taddr) &&
Yap_unify(ARG6, t) && Yap_unify(ARG6, t) &&
Yap_unify(ARG7, MkIntegerTerm(ClauseId(ncl, pe))); Yap_unify(ARG7, MkIntegerTerm(ClauseId(ncl, pe)));
@ -1770,6 +1792,19 @@ static bool handled_exception(USES_REGS1) {
#endif #endif
typedef struct buf_struct_t {
char *buf_;
char *lbuf_;
size_t bufsize_;
size_t lbufsz_;
} buf_t;
#define buf bufp->buf_
#define lbuf bufp->lbuf_
#define bufsize bufp->bufsize_
#define lbufsz bufp->lbufsz_
#define ADDBUF( CMD ) { \ #define ADDBUF( CMD ) { \
while (true) { \ while (true) { \
size_t sz = CMD; \ size_t sz = CMD; \
@ -1785,149 +1820,42 @@ while (true) { \
} \ } \
} }
const char *Yap_dump_stack(void) {
CACHE_REGS static char *ADDSTR( const char *STR, struct buf_struct_t *bufp ) { \
choiceptr b_ptr = B; while (true) { \
CELL *env_ptr = ENV; size_t sz = strlen(STR); \
char *tp; if (sz < lbufsz-256){ \
strcpy(lbuf, STR);
lbuf += sz; \
lbufsz -= sz; \
break; \
} \
char *nbuf = Realloc(buf, bufsize += 1024); \
lbuf = nbuf + (lbuf-buf); \
buf = nbuf; \
lbufsz += 1024; \
} \
return lbuf;
}
#if UNDEFINED
static void shortstack( choiceptr b_ptr, CELL * env_ptr , buf_struct_t *bufp) {
yamop *ipc = CP; yamop *ipc = CP;
int max_count = 200; int max_count = 200;
int lvl = push_text_stack(); int lvl = push_text_stack();
char *buf = Malloc(4096), *lbuf = buf;
size_t bufsize = 4096, lbufsz = bufsize-256;
/* check if handled */
// if (handled_exception(PASS_REGS1))
// return;
#if DEBUG
ADDBUF(snprintf(lbuf, lbufsz ,
"%% YAP regs: P=%p, CP=%p, ASP=%p, H=%p, TR=%p, HeapTop=%p~n", P,
CP, ASP, HR, TR, HeapTop));
ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% =====================================~n%%~n"));
ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% YAP Status:~n"));
ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% -------------------------------------~n%%~n"));
yap_error_number errnbr = LOCAL_Error_TYPE;
yap_error_class_number classno = Yap_errorClass(errnbr);
ADDBUF(snprintf(lbuf, lbufsz , "%% Error STATUS: %s/%s~n~n", Yap_errorName(errnbr),
Yap_errorClassName(classno)));
ADDBUF(snprintf(lbuf, lbufsz , "%% Execution mode~n"));
if (LOCAL_PrologMode & BootMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Bootstrap~n"));
if (LOCAL_PrologMode & UserMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% User Prolo~n"));
if (LOCAL_PrologMode & CritMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Exclusive Access Mode~n"));
if (LOCAL_PrologMode & AbortMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Abort~n"));
if (LOCAL_PrologMode & InterruptMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Interrupt~n"));
if (LOCAL_PrologMode & InErrorMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Error~n"));
if (LOCAL_PrologMode & ConsoleGetcMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Prompt Console~n"));
if (LOCAL_PrologMode & ExtendStackMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Stack expansion ~n"));
if (LOCAL_PrologMode & GrowHeapMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Data Base Expansion~n"));
if (LOCAL_PrologMode & GrowStackMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% User Prolog~n"));
if (LOCAL_PrologMode & GCMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Garbage Collection~n"));
if (LOCAL_PrologMode & ErrorHandlingMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Error handler~n"));
if (LOCAL_PrologMode & CCallMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% System Foreign Code~n"));
if (LOCAL_PrologMode & UnifyMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Off-line Foreign Code~n"));
if (LOCAL_PrologMode & UserCCallMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% User Foreig C~n"));
if (LOCAL_PrologMode & MallocMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Heap Allocaror~n"));
if (LOCAL_PrologMode & SystemMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Prolog Internals~n"));
if (LOCAL_PrologMode & AsyncIntMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Async Interruot mode~n"));
if (LOCAL_PrologMode & InReadlineMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Readline Console~n"));
if (LOCAL_PrologMode & TopGoalMode)
ADDBUF(snprintf(lbuf, lbufsz , "%% Creating new query~n"));
#endif
ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% -------------------------------------~n%%~n"));
ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% YAP Program:~n"));
ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% -------------------------------------~n%%~n"));
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);
ADDBUF(snprintf(lbuf, lbufsz , "%% Continuation: %s~n", (char *)HR));
Yap_output_bug_location(B->cp_ap, FIND_PRED_FROM_ANYWHERE, 256);
ADDBUF(snprintf(lbuf, lbufsz , "%% Alternative: %s~n", (char *)HR));
ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% -------------------------------------~n%%~n"));
ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% YAP Stack Usage:~n"));
ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% -------------------------------------~n%%~n"));
if (HR > ASP || HR > LCL0) {
ADDBUF(snprintf(lbuf, lbufsz , "%% YAP ERROR: Global Collided against Local (%p--%p)~n",
HR, ASP));
} else if (HeapTop > (ADDR)LOCAL_GlobalBase) {
ADDBUF(snprintf(lbuf, lbufsz ,
"%% YAP ERROR: Code Space Collided against Global (%p--%p)~n",
HeapTop, LOCAL_GlobalBase));
} else {
#if !USE_SYSTEM_MALLOC
ADDBUF(snprintf(lbuf, lbufsz , "%%ldKB of Code Space (%p--%p)~n",
(long int)((CELL)HeapTop - (CELL)Yap_HeapBase) / 1024, Yap_HeapBase,
HeapTop));
#if USE_DL_MALLOC
if (Yap_NOfMemoryHoles) {
UInt i;
for (i = 0; i < Yap_NOfMemoryHoles; i++)
ADDBUF(snprintf(lbuf, lbufsz , " Current hole: %p--%p~n", Yap_MemoryHoles[i].start,
Yap_MemoryHoles[i].end));
}
#endif
#endif
ADDBUF(snprintf(lbuf, lbufsz , "%% %luKB of Global Stack (%p--%p)~n",
(unsigned long int)(sizeof(CELL) * (HR - H0)) / 1024, H0, HR));
ADDBUF(snprintf(lbuf, lbufsz , "%% %luKB of Local Stack (%p--%p)~n",
(unsigned long int)(sizeof(CELL) * (LCL0 - ASP)) / 1024, ASP, LCL0));
ADDBUF(snprintf(lbuf, lbufsz , "%% %luKB of Trail (%p--%p)~n",
(unsigned long int)((ADDR)TR - LOCAL_TrailBase) / 1024,
LOCAL_TrailBase, TR));
ADDBUF(snprintf(lbuf, lbufsz , "%% Performed %ld garbage collections~n",
(unsigned long int)LOCAL_GcCalls));
#if LOW_LEVEL_TRACER
{
extern long long vsc_count;
if (vsc_count) {
#if _WIN32
ADDBUF(snprintf(lbuf, lbufsz , "Trace Counter at %I64d~n", vsc_count));
#else
ADDBUF(snprintf(lbuf, lbufsz , "Trace Counter at %lld~n", vsc_count));
#endif
}
}
#endif
ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% -------------------------------------~n%%~n"));
ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% YAP Stack:~n"));
ADDBUF(snprintf(lbuf, lbufsz , "%% ~n%% -------------------------------------~n%%~n"));
ADDBUF(snprintf(lbuf, lbufsz , "%% All Active Calls and~n"));
ADDBUF(snprintf(lbuf, lbufsz , "%% Goals With Alternatives Open (Global In "
"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) {
tp = 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;
ADDBUF(snprintf(lbuf, lbufsz , "%% %s~n", tp)); ADDBUF(snprintf(lbuf, lbufsz , "%% %s\n", tp));
} else { } else {
ADDBUF(snprintf(lbuf, lbufsz , "%% %s~n", tp)); ADDBUF(snprintf(lbuf, lbufsz , "%% %s\n", tp));
} }
if (!max_count--) { if (!max_count--) {
ADDBUF(snprintf(lbuf, lbufsz , "%% .....~n")); ADDBUF(snprintf(lbuf, lbufsz , "%% .....\n"));
return pop_output_text_stack(lvl, buf); return pop_output_text_stack(lvl, buf);
} }
ipc = (yamop *)(env_ptr[E_CP]); ipc = (yamop *)(env_ptr[E_CP]);
@ -1935,7 +1863,7 @@ const char *Yap_dump_stack(void) {
} }
if (b_ptr) { if (b_ptr) {
if (!max_count--) { if (!max_count--) {
ADDBUF(snprintf(lbuf, lbufsz , "// .....~n")); ADDBUF(snprintf(lbuf, lbufsz , "// .....\n"));
return pop_output_text_stack(lvl, buf); return pop_output_text_stack(lvl, buf);
} }
if (b_ptr->cp_ap && /* tabling */ if (b_ptr->cp_ap && /* tabling */
@ -1943,78 +1871,193 @@ const char *Yap_dump_stack(void) {
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 */
tp = Yap_output_bug_location(b_ptr->cp_ap, FIND_PRED_FROM_CP, 256); Term tp = Yap_output_bug_location(b_ptr->cp_ap, FIND_PRED_FROM_CP, 256);
ADDBUF(snprintf(lbuf, lbufsz , "%% %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;
} }
} }
#endif
const char *Yap_dump_stack(void) {
CACHE_REGS
int lvl = push_text_stack();
struct buf_struct_t b, *bufp = &b;
buf = Malloc(4096);
lbuf = buf;
bufsize = 4096;
lbufsz = bufsize-256;
/* check if handled */
// if (handled_exception(PASS_REGS1))
// return;
#if DEBUG
ADDBUF(snprintf(lbuf, lbufsz ,
"%% YAP regs: P=%p, CP=%p, ASP=%p, H=%p, TR=%p, HeapTop=%p\n", P,
CP, ASP, HR, TR, HeapTop));
ADDSTR( "%% \n%% =====================================\n%%\n", bufp);
ADDSTR( "%% \n%% YAP Status:\n", bufp);
ADDSTR( "%% \n%% -------------------------------------\n%%\n", bufp);
yap_error_number errnbr = LOCAL_Error_TYPE;
yap_error_class_number classno = Yap_errorClass(errnbr);
ADDBUF(snprintf(lbuf, lbufsz , "%% Error STATUS: %s/%s\n\n", Yap_errorName(errnbr),
Yap_errorClassName(classno)));
ADDSTR( "%% Execution mode\n", bufp );
if (LOCAL_PrologMode & BootMode)
ADDSTR( "%% Bootstrap\n", bufp );
if (LOCAL_PrologMode & UserMode)
ADDSTR( "%% User Prologg\n", bufp );
if (LOCAL_PrologMode & CritMode)
ADDSTR( "%% Exclusive Access Mode\n", bufp );
if (LOCAL_PrologMode & AbortMode)
ADDSTR( "%% Abort\n", bufp );
if (LOCAL_PrologMode & InterruptMode)
ADDSTR( "%% Interrupt\n", bufp );
if (LOCAL_PrologMode & InErrorMode)
ADDSTR( "%% Error\n", bufp );
if (LOCAL_PrologMode & ConsoleGetcMode)
ADDSTR( "%% Prompt Console\n", bufp );
if (LOCAL_PrologMode & ExtendStackMode)
ADDSTR( "%% Stack expansion \n", bufp );
if (LOCAL_PrologMode & GrowHeapMode)
ADDSTR( "%% Data Base Expansion\n", bufp );
if (LOCAL_PrologMode & GrowStackMode)
ADDSTR( "%% User Prolog\n", bufp );
if (LOCAL_PrologMode & GCMode)
ADDSTR( "%% Garbage Collection\n", bufp );
if (LOCAL_PrologMode & ErrorHandlingMode)
ADDSTR( "%% Error handler\n", bufp );
if (LOCAL_PrologMode & CCallMode)
ADDSTR( "%% System Foreign Code\n", bufp );
if (LOCAL_PrologMode & UnifyMode)
ADDSTR( "%% Off-line Foreign Code\n", bufp );
if (LOCAL_PrologMode & UserCCallMode)
ADDSTR( "%% User Foreig C\n", bufp );
if (LOCAL_PrologMode & MallocMode)
ADDSTR( "%% Heap Allocaror\n", bufp );
if (LOCAL_PrologMode & SystemMode)
ADDSTR( "%% Prolog Internals\n", bufp );
if (LOCAL_PrologMode & AsyncIntMode)
ADDSTR( "%% Async Interruot mode\n", bufp );
if (LOCAL_PrologMode & InReadlineMode)
ADDSTR( "%% Readline Console\n", bufp );
if (LOCAL_PrologMode & TopGoalMode)
ADDSTR( "%% Creating new query\n", bufp );
#endif
ADDSTR( "%% \n%% -------------------------------------\n%%\n", bufp );
ADDSTR( "%% \n%% YAP Program:\n", bufp );
ADDSTR( "%% \n%% -------------------------------------\n%%\n", bufp );
ADDBUF(snprintf(lbuf, lbufsz , "%% Program Position: %s\n\n", Yap_errorName(errno)));
char *o = Yap_output_bug_location(P, FIND_PRED_FROM_ANYWHERE, 256);
ADDBUF(snprintf(lbuf, lbufsz , "%% PC: %s\n", o) );
o = Yap_output_bug_location(CP, FIND_PRED_FROM_ANYWHERE, 256);
ADDBUF(snprintf(lbuf, lbufsz , "%% Continuation: %s\n", o) );
o = Yap_output_bug_location(B->cp_ap, FIND_PRED_FROM_ANYWHERE, 256);
ADDBUF(snprintf(lbuf, lbufsz , "%% Alternative: %s\n", o) );
ADDSTR( "%% \n%% -------------------------------------\n%%\n", bufp );
ADDSTR( "%% \n%% YAP Stack Usage:\n", bufp );
ADDSTR( "%% \n%% -------------------------------------\n%%\n", bufp );
if (HR > ASP || HR > LCL0) {
ADDBUF(snprintf(lbuf, lbufsz , "%% YAP ERROR: Global Collided against Local (%p--%p)\n",
HR, ASP));
} else if (HeapTop > (ADDR)LOCAL_GlobalBase) {
ADDBUF(snprintf(lbuf, lbufsz ,
"%% YAP ERROR: Code Space Collided against Global (%p--%p)\n",
HeapTop, LOCAL_GlobalBase));
} else {
#if !USE_SYSTEM_MALLOC
ADDBUF(snprintf(lbuf, lbufsz , "%%ldKB of Code Space (%p--%p)\n",
(long int)((CELL)HeapTop - (CELL)Yap_HeapBase) / 1024, Yap_HeapBase,
HeapTop));
#if USE_DL_MALLOC
if (Yap_NOfMemoryHoles) {
UInt i;
for (i = 0; i < Yap_NOfMemoryHoles; i++)
ADDBUF(snprintf(lbuf, lbufsz , " Current hole: %p--%p\n", Yap_MemoryHoles[i].start,
Yap_MemoryHoles[i].end));
}
#endif
#endif
ADDBUF(snprintf(lbuf, lbufsz , "%% %luKB of Global Stack (%p--%p)\n",
(unsigned long int)(sizeof(CELL) * (HR - H0)) / 1024, H0, HR));
ADDBUF(snprintf(lbuf, lbufsz , "%% %luKB of Local Stack (%p--%p)\n",
(unsigned long int)(sizeof(CELL) * (LCL0 - ASP)) / 1024, ASP, LCL0));
ADDBUF(snprintf(lbuf, lbufsz , "%% %luKB of Trail (%p--%p)\n",
(unsigned long int)((ADDR)TR - LOCAL_TrailBase) / 1024,
LOCAL_TrailBase, TR));
ADDBUF(snprintf(lbuf, lbufsz , "%% Performed %ld garbage collections\n",
(unsigned long int)LOCAL_GcCalls));
#if LOW_LEVEL_TRACER
{
extern long long vsc_count;
if (vsc_count) {
#if _WIN32
ADDBUF(snprintf(lbuf, lbufsz , "Trace Counter at %I64d\n", vsc_count));
#else
ADDBUF(snprintf(lbuf, lbufsz , "Trace Counter at %lld\n", vsc_count));
#endif
}
}
#endif
ADDSTR( "%% \n%% -------------------------------------\n%%\n", bufp );
ADDSTR( "%% \n%% YAP Stack:\n", bufp );
ADDSTR( "%% \n%% -------------------------------------\n%%\n", bufp );
ADDSTR( "%% All Active Calls and\n", bufp );
ADDSTR( "%% Goals With Alternatives Open (Global In "
"Use--Local In Use)\n%%\n", bufp);
} }
return pop_output_text_stack(lvl, buf); return pop_output_text_stack(lvl, buf);
} }
void DumpActiveGoals(USES_REGS1) {
/* try to dump active goals */
CELL *ep = YENV; /* and current environment */
choiceptr b_ptr = B;
CELL cp;
PredEntry *pe;
int first = 1;
if (legal_env(YENV PASS_REGS) && YENV < ENV) static bool outputep( CELL *ep, struct buf_struct_t *bufp) {
ep = YENV; PredEntry *pe = EnvPreg((yamop *)ep);
else if (legal_env(ENV PASS_REGS))
ep = ENV;
while (TRUE) {
if (!ONLOCAL(ep) || (Unsigned(ep) & (sizeof(CELL) - 1))) if (!ONLOCAL(ep) || (Unsigned(ep) & (sizeof(CELL) - 1)))
break; return false;
cp = ep[E_CP];
if (!ONHEAP(cp) || (Unsigned(cp) & (sizeof(CELL) - 1)))
break;
pe = EnvPreg((yamop *)cp);
if (!ONHEAP(pe) || Unsigned(pe) & (sizeof(CELL) - 1))
break;
PELOCK(71, pe);
if (pe->KindOfPE & 0xff00) {
UNLOCK(pe->PELock);
break;
}
if (pe->PredFlags & (CompiledPredFlag | DynamicPredFlag)) {
Functor f; Functor f;
UNLOCK(pe->PELock); UNLOCK(pe->PELock);
f = pe->FunctorOfPred; f = pe->FunctorOfPred;
if (pe->KindOfPE && hidden(NameOfFunctor(f))) if (pe->KindOfPE && hidden(NameOfFunctor(f))) {
goto next; return true;
if (first++ == 1) }
fprintf(stderr, "Active ancestors:\n");
Term mod = pe->ModuleOfPred; Term mod = pe->ModuleOfPred;
if (mod == PROLOG_MODULE) if (mod == PROLOG_MODULE)
mod = TermProlog; mod = TermProlog;
Term t = Yap_MkNewApplTerm(f, pe->ArityOfPE); arity_t arity = ArityOfFunctor(f);
Yap_plwrite(Yap_PredicateIndicator(t, mod), GLOBAL_Stream + 2, 0, 0,
GLOBAL_MaxPriority); int i;
fputc('\n', stderr); ADDSTR( RepAtom(AtomOfTerm(mod))->StrOfAE, bufp );
} else { if (arity == 0) {
UNLOCK(pe->PELock); ADDSTR( RepAtom(((Atom)f))->StrOfAE, bufp );
return true;
} }
next: Atom At = NameOfFunctor(f);
ep = (CELL *)ep[E_E]; ADDBUF(snprintf(lbuf, lbufsz, "%s(", RepAtom(At)->StrOfAE));
for (i = 0; i < arity; i++) {
if (i > 0) ADDSTR("...,", bufp);
} }
first = 1; ADDSTR( "...)", bufp);
fprintf(stderr, "Active Choice-Points:\n"); return true;
while (TRUE) { }
PredEntry *pe;
op_numbers opnum; static bool outputcp( choiceptr cp, struct buf_struct_t *bufp) {
if (!ONLOCAL(b_ptr) || b_ptr->cp_b == NULL) choiceptr b_ptr = cp;
break; PredEntry *pe = Yap_PredForChoicePt(b_ptr,NULL);
fprintf(stderr, "%% %p ", b_ptr); ADDBUF(snprintf(lbuf, lbufsz, "%% %p ", cp));
pe = Yap_PredForChoicePt(b_ptr, &opnum); op_numbers opnum = Yap_op_from_opcode(b_ptr->cp_ap->opc);
if (opnum == _Nstop) { if (opnum == _Nstop) {
fprintf(stderr, " ********** C-Code Interface Boundary ***********\n"); bool rc = outputep( (CELL *)cp, bufp);
} else { ADDSTR( " ********** C-Code Interface Boundary ***********\n", bufp);
return rc;
}
Functor f; Functor f;
Term mod = PROLOG_MODULE; Term mod = PROLOG_MODULE;
@ -2024,43 +2067,40 @@ void DumpActiveGoals(USES_REGS1) {
else else
mod = TermProlog; mod = TermProlog;
if (mod != TermProlog && mod != MkAtomTerm(AtomUser)) { if (mod != TermProlog && mod != MkAtomTerm(AtomUser)) {
Yap_plwrite(mod, GLOBAL_Stream + 2, 0, 0, GLOBAL_MaxPriority); ADDBUF(snprintf(lbuf, lbufsz, "%s:", RepAtom(AtomOfTerm(mod))->StrOfAE));
fputc(':', stderr);
} }
if (mod == IDB_MODULE) { if (mod == IDB_MODULE) {
if (pe->PredFlags & NumberDBPredFlag) { if (pe->PredFlags & NumberDBPredFlag) {
Int id = pe->src.IndxId; Term t = MkIntegerTerm(pe->src.IndxId);
Yap_plwrite(MkIntegerTerm(id), GLOBAL_Stream + 2, 0, 0, char *b = Yap_TermToBuffer(t, 0);
GLOBAL_MaxPriority); if (!b)
return false;
ADDSTR( b, bufp);
} else if (pe->PredFlags & AtomDBPredFlag) { } else if (pe->PredFlags & AtomDBPredFlag) {
Atom At = (Atom)pe->FunctorOfPred; Atom At = (Atom)pe->FunctorOfPred;
Yap_plwrite(MkAtomTerm(At), GLOBAL_Stream + 2, 0, 0, ADDSTR( RepAtom(At)->StrOfAE, bufp);
GLOBAL_MaxPriority);
} else { } else {
Functor f = pe->FunctorOfPred; Functor f = pe->FunctorOfPred;
Atom At = NameOfFunctor(f);
arity_t arity = ArityOfFunctor(f); arity_t arity = ArityOfFunctor(f);
int i; int i;
Yap_plwrite(MkAtomTerm(At), GLOBAL_Stream + 2, 0, 0, ADDBUF(snprintf(lbuf, lbufsz, "%s(", RepAtom((Atom)f)->StrOfAE));
GLOBAL_MaxPriority);
fputc('(', stderr);
for (i = 0; i < arity; i++) { for (i = 0; i < arity; i++) {
if (i > 0) if (i > 0) ADDSTR( "_,", bufp);
fputc(',', stderr);
fputc('_', stderr);
} }
fputc(')', stderr); ADDSTR( "), ", bufp);
} }
fputc('(', stderr); char *b = Yap_TermToBuffer(b_ptr->cp_a2, 0);
Yap_plwrite(b_ptr->cp_a2, GLOBAL_Stream + 2, 0, 0, GLOBAL_MaxPriority); if (!b)
fputc(')', stderr); return false;
} else if (pe->ArityOfPE == 0) { ADDSTR( b, bufp);
Yap_plwrite(MkAtomTerm((Atom)f), GLOBAL_Stream + 2, 0, 0, ADDSTR( ",_)", bufp);
GLOBAL_MaxPriority);
} else { } else {
ADDSTR(RepAtom((Atom)f)->StrOfAE, bufp);
if (pe->ArityOfPE == 0) {
Int i = 0, arity = pe->ArityOfPE; Int i = 0, arity = pe->ArityOfPE;
if (opnum == _or_last || opnum == _or_else) { if (opnum == _or_last || opnum == _or_else) {
/* skip, it should be in the list as an environment }
Yap_plwrite(MkAtomTerm(NameOfFunctor(f)), GLOBAL_Stream + 2, 0, 0, Yap_plwrite(MkAtomTerm(NameOfFunctor(f)), GLOBAL_Stream + 2, 0, 0,
GLOBAL_MaxPriority); GLOBAL_MaxPriority);
fputc('(', stderr); fputc('(', stderr);
@ -2070,25 +2110,69 @@ void DumpActiveGoals(USES_REGS1) {
fputc('_', stderr); fputc('_', stderr);
} }
fputs(") :- ... ( _ ; _ ", stderr); fputs(") :- ... ( _ ; _ ", stderr);
*/
} else { } else {
Term *args = &(b_ptr->cp_a1); Term *args = &(b_ptr->cp_a1);
Yap_plwrite(MkAtomTerm(NameOfFunctor(f)), GLOBAL_Stream + 2, 0, 0, ADDBUF(snprintf(lbuf, lbufsz, "%s(", RepAtom(NameOfFunctor(pe->FunctorOfPred))->StrOfAE));
GLOBAL_MaxPriority);
fputc('(', stderr);
for (i = 0; i < arity; i++) { for (i = 0; i < arity; i++) {
if (i > 0) if (i > 0)
fputc(',', stderr); ADDSTR( ", ", bufp);
Yap_plwrite(args[i], GLOBAL_Stream + 2, 0, 0, GLOBAL_MaxPriority);
char *b = Yap_TermToBuffer(args[i], 0);
if (!b)
return false;
ADDSTR( b, bufp);
}
ADDSTR( ") ", bufp);
} }
} }
fputc(')', stderr); ADDSTR( "\n", bufp);
}
fputc('\n', stderr);
}
b_ptr = b_ptr->cp_b;
} }
return true;
} }
void DumpActiveGoals(USES_REGS1) {
/* try to dump active goals */
void *ep = YENV; /* and current environment */
void *cp;
PredEntry *pe;
struct buf_struct_t buf0, *bufp = &buf0;
buf = Malloc(4096);
lbuf = buf;
bufsize = 4096;
lbufsz = bufsize-256;
if (legal_env(YENV PASS_REGS) && YENV < ENV)
ep = YENV;
else if (legal_env(ENV PASS_REGS))
ep = ENV;
while (true) {
if (!ONHEAP(cp) || (Unsigned(cp) & (sizeof(CELL) - 1)))
break;
PELOCK(71, pe);
if (pe->KindOfPE & 0xff00) {
UNLOCK(pe->PELock);
break;
}
if (cp <= ep) {
choiceptr p = cp;
pe = choicepoint_owner(p, NULL, NULL);
outputcp( p, bufp );
cp = p->cp_b;
if (cp == ep) {
CELL *e = ep;
ep = (void*)e[E_E];
}
cp = p;
} else {
CELL *e = ep;
pe = EnvPreg((yamop *)e);
if (!outputep( e, bufp ))
break;
ep = (void*)e[E_E];
}
}
}
/** /**
* Used for debugging. * Used for debugging.
* *

View File

@ -1618,9 +1618,6 @@ void Yap_InitCPreds(void) {
while (*p) while (*p)
(*(*p++))(); (*(*p++))();
} }
#if USE_MYDDAS
init_myddas();
#endif
#if CAMACHO #if CAMACHO
{ {
extern void InitForeignPreds(void); extern void InitForeignPreds(void);

File diff suppressed because it is too large Load Diff

View File

@ -146,7 +146,7 @@ static void init_globals(YAP_init_args *yap_init) {
const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR, const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR,
*Yap_PLDIR, *Yap_BOOTSTRAP, *Yap_COMMONSDIR, *Yap_INPUT_STARTUP, *Yap_PLDIR, *Yap_BOOTSTRAP, *Yap_COMMONSDIR, *Yap_INPUT_STARTUP,
*Yap_OUTPUT_STARTUP, *Yap_BOOTFILE, *Yap_INCLUDEDIR; *Yap_OUTPUT_STARTUP, *Yap_SOURCEBOOT, *Yap_INCLUDEDIR, *Yap_PLBOOTDIR;
/** /**
* consult loop in C: used to boot the system, butt supports goal execution and * consult loop in C: used to boot the system, butt supports goal execution and
@ -193,10 +193,20 @@ static bool load_file(const char *b_file USES_REGS) {
if (t == TermEof) if (t == TermEof)
break; break;
if (t == 0) { if (t == 0) {
fprintf(stderr, "[ SYNTAX ERROR: while parsing stream %s at line %ld ]\n", fprintf(stderr, "[ %s:%d: error: SYNTAX ERROR\n",
b_file, GLOBAL_Stream[c_stream].linecount); b_file, GLOBAL_Stream[c_stream].linecount);
} else if (IsVarTerm(t) || t == TermNil) { break;
fprintf(stderr, "[ line: " Int_FORMAT ": term cannot be compiled ]", }
//
// {
// char buu[1024];
//
// YAP_WriteBuffer(t, buu, 1023, 0);
// fprintf(stderr, "[ %s ]\n" , buu);
// }
if (IsVarTerm(t) || t == TermNil) {
fprintf(stderr, "[ unbound or []: while parsing %s at line %d ]\n",
GLOBAL_Stream[c_stream].linecount); GLOBAL_Stream[c_stream].linecount);
} else if (IsApplTerm(t) && (FunctorOfTerm(t) == functor_query || } else if (IsApplTerm(t) && (FunctorOfTerm(t) == functor_query ||
FunctorOfTerm(t) == functor_command1)) { FunctorOfTerm(t) == functor_command1)) {
@ -227,9 +237,11 @@ static bool load_file(const char *b_file USES_REGS) {
} }
static const char * EOLIST ="EOLINE"; static const char * EOLIST ="EOLINE";
static bool is_install;
static bool is_dir( const char *path, const void *info) { static bool is_dir( const char *path, const void *info) {
if (is_install)
return true;
if (Yap_isDirectory( path )) if (Yap_isDirectory( path ))
return true; return true;
@ -245,13 +257,16 @@ static const char * EOLIST ="EOLINE";
i = 1; i = 1;
} }
s[i] = '\0'; s[i] = '\0';
if (info == NULL)
return true;
return return
strcmp(info,s) == 0 || strcmp(info,s) == 0 ||
Yap_isDirectory( s ); Yap_isDirectory( s );
} }
static bool is_file( const char *path, const void *info) { static bool is_file( const char *path, const void *info) {
if (is_install)
return true;
return Yap_Exists( path ); return Yap_Exists( path );
} }
@ -270,33 +285,22 @@ static const char * EOLIST ="EOLINE";
const char *fmt = s1; const char *fmt = s1;
va_list ap; va_list ap;
char *buf = malloc(FILENAME_MAX + 1); char *buf = malloc(FILENAME_MAX + 1);
__android_log_print(
ANDROID_LOG_INFO, "YAPDroid", "try %s", s1);
va_start(ap, s1); va_start(ap, s1);
while (fmt != EOLIST) { while (fmt != EOLIST) {
__android_log_print( ANDROID_LOG_INFO, "YAPDroid", "loop %s", fmt);
if (fmt == NULL || fmt[0]=='\0') { if (fmt == NULL || fmt[0]=='\0') {
fmt = va_arg(ap, const char *); fmt = va_arg(ap, const char *);
continue; continue;
} }
strncpy(buf, fmt, FILENAME_MAX); // Yap_AbsoluteFile(fmt,true), FILENAME_MAX); strncpy(buf, fmt, FILENAME_MAX); // Yap_AbsoluteFile(fmt,true), FILENAME_MAX);
__android_log_print( ANDROID_LOG_INFO, "YAPDroid", "triyimh %s", buf);
if (test(buf,info)) { if (test(buf,info)) {
__android_log_print(
ANDROID_LOG_INFO, "YAPDroid", "got %s", buf);
buf = realloc(buf, strlen(buf) + 1); buf = realloc(buf, strlen(buf) + 1);
va_end(ap); va_end(ap);
return buf; return buf;
} }
__android_log_print(
ANDROID_LOG_INFO, "YAPDroid", "tried %s, failed", buf);
fmt = va_arg(ap, const char *); fmt = va_arg(ap, const char *);
} }
__android_log_print(
ANDROID_LOG_INFO, "YAPDroid", "failed search ");
va_end(ap); va_end(ap);
free(buf); free(buf);
return NULL; return NULL;
@ -311,14 +315,23 @@ static const char *join(const char *s0, const char *s1) {
if (!s1 || s1[0] == '\0') if (!s1 || s1[0] == '\0')
return s0; return s0;
// int lvl = push_text_stack(); // int lvl = push_text_stack();
char *buf = malloc(FILENAME_MAX + 1); char *buf = malloc(strlen(s0)+strlen(s1) + 2);
strcpy(buf, s0); strcpy(buf, s0);
if (Yap_dir_separator(s0[strlen(s0)-1])) {
if (Yap_dir_separator(s1[0])) {
s1 += 1;
}
} else {
if (!Yap_dir_separator(s1[0]-1)) {
strcat(buf, "/");
}
}
strcat(buf, s1); strcat(buf, s1);
return buf; return buf;
} }
static void Yap_set_locations(YAP_init_args *iap) { static void Yap_set_locations(YAP_init_args *iap) {
is_install= iap->install;
/// ROOT_DIR is the home of the YAP system. It can be: /// ROOT_DIR is the home of the YAP system. It can be:
/// -- provided by the user; /// -- provided by the user;
/// -- obtained from DESTDIR + DE=efalkRoot /// -- obtained from DESTDIR + DE=efalkRoot
@ -330,6 +343,8 @@ static void Yap_set_locations(YAP_init_args *iap) {
Yap_ROOTDIR = sel( is_dir, NULL, Yap_ROOTDIR = sel( is_dir, NULL,
iap->ROOTDIR, iap->ROOTDIR,
getenv("YAPROOTDIR"), getenv("YAPROOTDIR"),
join(getenv("DESTDIR"), YAP_ROOTDIR),
#if __ANDROID__ #if __ANDROID__
"/", "/",
#else #else
@ -341,6 +356,8 @@ static void Yap_set_locations(YAP_init_args *iap) {
#endif #endif
EOLIST EOLIST
); );
__android_log_print(
ANDROID_LOG_INFO,"YAPDroid", "Yap_ROOTDIR %s", Yap_ROOTDIR);
/// BINDIR: where the OS stores header files, namely libYap... /// BINDIR: where the OS stores header files, namely libYap...
Yap_BINDIR = sel( is_dir, Yap_ROOTDIR, iap->BINDIR, Yap_BINDIR = sel( is_dir, Yap_ROOTDIR, iap->BINDIR,
@ -348,7 +365,7 @@ static void Yap_set_locations(YAP_init_args *iap) {
#if !defined(__ANDROID__) #if !defined(__ANDROID__)
join(getenv("DESTDIR"), YAP_BINDIR), join(getenv("DESTDIR"), YAP_BINDIR),
#endif #endif
join(Yap_ROOTDIR, "/bin"), join(Yap_ROOTDIR, "bin"),
EOLIST); EOLIST);
/// LIBDIR: where the OS stores dynamic libraries, namely libYap... /// LIBDIR: where the OS stores dynamic libraries, namely libYap...
@ -356,16 +373,14 @@ static void Yap_set_locations(YAP_init_args *iap) {
#if !defined(__ANDROID__) #if !defined(__ANDROID__)
join(getenv("DESTDIR"), YAP_LIBDIR), join(getenv("DESTDIR"), YAP_LIBDIR),
#endif #endif
join(Yap_ROOTDIR, "/lib"), join(Yap_ROOTDIR, "lib"),
EOLIST); EOLIST);
/// DLLDIR: where libraries can find expicitely loaded DLLs /// DLLDIR: where libraries can find expicitely loaded DLLs
Yap_DLLDIR = sel(is_dir, Yap_LIBDIR, iap->DLLDIR, Yap_DLLDIR = sel(is_dir, Yap_LIBDIR, iap->DLLDIR,
getenv("YAPLIBDIR"), getenv("YAPLIBDIR"),
#if !defined(__ANDROID__)
join(getenv("DESTDIR"), YAP_DLLDIR), join(getenv("DESTDIR"), YAP_DLLDIR),
join(Yap_LIBDIR, "/yap"), join(Yap_LIBDIR, "/Yap"),
#endif
EOLIST); EOLIST);
/// INCLUDEDIR: where the OS stores header files, namely libYap... /// INCLUDEDIR: where the OS stores header files, namely libYap...
@ -373,79 +388,74 @@ static void Yap_set_locations(YAP_init_args *iap) {
#if !defined(__ANDROID__) #if !defined(__ANDROID__)
join(getenv("DESTDIR"), YAP_INCLUDEDIR), join(getenv("DESTDIR"), YAP_INCLUDEDIR),
#endif #endif
join(Yap_ROOTDIR, "/include"), join(Yap_ROOTDIR, "include"),
EOLIST); EOLIST);
/// SHAREDIR: where OS & ARCH independent files live /// SHAREDIR: where OS & ARCH independent files live
Yap_SHAREDIR = sel( is_dir, Yap_ROOTDIR, iap->SHAREDIR, Yap_SHAREDIR = sel( is_dir, Yap_ROOTDIR, iap->SHAREDIR,
getenv("YAPSHAREDIR"), getenv("YAPSHAREDIR"),
#if !defined(__ANDROID__) #if __ANDROID__
join(getenv("DESTDIR"), YAP_SHAREDIR), "/data/data/pt.up.yap/files",
join(Yap_ROOTDIR, "/share"),
"/assets", "/assets",
#endif #endif
join(Yap_ROOTDIR, "/files"), join(getenv("DESTDIR"), YAP_SHAREDIR),
join(Yap_ROOTDIR, "share"),
join(Yap_ROOTDIR, "files"),
EOLIST); EOLIST);
__android_log_print(
ANDROID_LOG_INFO,"YAPDroid", "Yap_SHAREDIR %s", Yap_SHAREDIR);
/// PLDIR: where we can find Prolog files /// PLDIR: where we can find Prolog files
Yap_PLDIR = sel( is_dir, Yap_SHAREDIR, iap->PLDIR, Yap_PLDIR = sel( is_dir, Yap_SHAREDIR, iap->PLDIR,
#if __ANDROID__ join(getenv("DESTDIR"), join(Yap_SHAREDIR, "Yap")),
YAP_PLDIR,
"/assets/Yap",
#else
join(getenv("DESTDIR"), YAP_PLDIR), join(getenv("DESTDIR"), YAP_PLDIR),
join(Yap_SHAREDIR, "/Yap"),
#endif
EOLIST); EOLIST);
__android_log_print(
ANDROID_LOG_INFO, "YAPDroid","Yap_PLDIR %s", Yap_PLDIR);
/// ``COMMONSDIR: Prolog Commons /// ``COMMONSDIR: Prolog Commons
Yap_COMMONSDIR = sel(is_dir, Yap_SHAREDIR, iap->COMMONSDIR, Yap_COMMONSDIR = sel(is_dir, Yap_SHAREDIR, iap->COMMONSDIR,
#if __ANDROID__ join(getenv("DESTDIR"), join(Yap_SHAREDIR, "PrologCommons")),
"/assets/PrologCommons",
#else
join(getenv("DESTDIR"), YAP_SHAREDIR "/PrologCommons"),
join(Yap_SHAREDIR, "PrologCommons"),
#endif
EOLIST); EOLIST);
/// BOOTPLDIR: where we can find Prolog bootstrap files /// SOURCEBOOT: booting from the Prolog boot file at compilation-time so we should not assume pl is installed.
Yap_BOOTSTRAP = sel( is_file, NULL, iap->BOOTSTRAP, Yap_SOURCEBOOT = sel( is_file, Yap_AbsoluteFile("pl",false), iap->SOURCEBOOT,
YAP_BOOTSTRAP, YAP_SOURCEBOOT,
"boot.yap",
EOLIST); EOLIST);
/// BOOTFILE: where we can find the core Prolog boot file __android_log_print(
ANDROID_LOG_INFO, "YAPDroid","Yap_SOURCEBOOT %s", Yap_SOURCEBOOT);
const char * Yap_PLBOOTDIR = sel( is_dir, Yap_PLDIR, Yap_PLBOOTDIR = sel( is_dir, Yap_PLDIR, iap->BOOTDIR,
#if __ANDROID__ join(getenv("DESTDIR"),join(Yap_PLDIR, "pl")),
"/assets/Yap/pl",
#else
join(Yap_PLDIR, "/pl"),
#endif
EOLIST); EOLIST);
__android_log_print(
Yap_BOOTFILE = sel( is_wfile, Yap_PLBOOTDIR, iap->BOOTFILE, ANDROID_LOG_INFO, "YAPDroid","Yap_BOOTSTRAP %s", Yap_BOOTSTRAP);
#if __ANDROID__ /// BOOTSTRAP: booting from the Prolog boot file after YAP is installed
"/assets/Yap/pl/boot.yap", Yap_BOOTSTRAP = sel( is_file, Yap_PLBOOTDIR, iap->BOOTSTRAP,
#else join(getenv("DESTDIR"),YAP_BOOTSTRAP),
join(Yap_PLBOOTDIR, "/boot.yap"), join(getenv("DESTDIR"),join(Yap_PLBOOTDIR, "boot.yap")),
#endif
EOLIST); EOLIST);
__android_log_print(
ANDROID_LOG_INFO,"YAPDroid", "Yap_BOOTSTRAP %s", Yap_PLBOOTDIR);
/// STARTUP: where we can find the core Prolog bootstrap file /// STARTUP: where we can find the core Prolog bootstrap file
Yap_OUTPUT_STARTUP = Yap_OUTPUT_STARTUP =
sel( is_wfile, Yap_AbsoluteFile(".",false), iap->OUTPUT_STARTUP, sel( is_wfile, ".", iap->OUTPUT_STARTUP,
#if defined(__ANDROID__)
EOLIST,
#else
YAP_OUTPUT_STARTUP, YAP_OUTPUT_STARTUP,
#endif join(getenv("DESTDIR"), join(Yap_DLLDIR, "startup.yss")),
join(getenv("DESTDIR"), join(Yap_DLLDIR,iap->OUTPUT_STARTUP)),
"startup.yss", "startup.yss",
EOLIST); EOLIST);
Yap_INPUT_STARTUP = Yap_INPUT_STARTUP =
sel( is_file, Yap_DLLDIR, iap->INPUT_STARTUP, sel( is_file, Yap_DLLDIR, iap->INPUT_STARTUP,
"startup.yss", "startup.yss",
#if __ANDROID__ join(getenv("DESTDIR"), join(Yap_DLLDIR, "startup.yss")),
EOLIST, #if !defined(__ANDROID__)
#else
join(getenv("DESTDIR"), YAP_INPUT_STARTUP), join(getenv("DESTDIR"), YAP_INPUT_STARTUP),
#endif #endif
join(Yap_DLLDIR, "/startup.yss"),
"/usr/local/lib/Yap/startup.yss", "/usr/local/lib/Yap/startup.yss",
"/usr/lib/Yap/startup.yss", "/usr/lib/Yap/startup.yss",
EOLIST); EOLIST);
@ -464,6 +474,7 @@ EOLIST,
static void print_usage(void) { static void print_usage(void) {
fprintf(stderr, "\n[ Valid switches for command line arguments: ]\n"); fprintf(stderr, "\n[ Valid switches for command line arguments: ]\n");
fprintf(stderr, " -? Shows this screen\n"); fprintf(stderr, " -? Shows this screen\n");
fprintf(stderr, " -B Used during compilation: boot from ../pl/boot.yap and generate a saved state. \n");
fprintf(stderr, " -b Boot file \n"); fprintf(stderr, " -b Boot file \n");
fprintf(stderr, " -dump-runtime-variables\n"); fprintf(stderr, " -dump-runtime-variables\n");
fprintf(stderr, " -f initialization file or \"none\"\n"); fprintf(stderr, " -f initialization file or \"none\"\n");
@ -562,10 +573,10 @@ X_API YAP_file_type_t Yap_InitDefaults(void *x, char *saved_state, int argc,
iap->Argc = argc; iap->Argc = argc;
iap->Argv = argv; iap->Argv = argv;
#if __ANDROID__ #if __ANDROID__
iap->boot_file_type = YAP_BOOT_PL; iap->boot_file_type = YAP_PL;
iap->INPUT_STARTUP = NULL; iap->INPUT_STARTUP = NULL;
iap->assetManager = NULL; iap->assetManager = NULL;
return YAP_BOOT_PL; return YAP_PL;
#else #else
iap->boot_file_type = YAP_QLY; iap->boot_file_type = YAP_QLY;
iap->INPUT_STARTUP = saved_state; iap->INPUT_STARTUP = saved_state;
@ -574,14 +585,13 @@ X_API YAP_file_type_t Yap_InitDefaults(void *x, char *saved_state, int argc,
} }
/** /**
* @short Paese command line * @short Parse command line
* @param argc number of arguments * @param argc number of arguments
* @param argv arguments * @param argv arguments
* @param iap options, see YAP_init_args * @param iap options, see YAP_init_args
* @return boot from saved state or restore; error * @return boot from saved state or restore; error
*/ */
X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[], X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap) {
YAP_init_args *iap) {
char *p; char *p;
size_t *ssize; size_t *ssize;
@ -593,18 +603,18 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
case 'b': case 'b':
iap->boot_file_type = YAP_PL; iap->boot_file_type = YAP_PL;
if (p[1]) if (p[1])
iap->BOOTFILE = p + 1; iap->BOOTSTRAP = p + 1;
else if (argv[1] && *argv[1] != '-') { else if (argv[1] && *argv[1] != '-') {
iap->BOOTFILE = *++argv; iap->BOOTSTRAP = *++argv;
argc--; argc--;
} }
break; break;
case 'B': case 'B':
iap->boot_file_type = YAP_BOOT_PL; iap->boot_file_type = YAP_SOURCE_PL;
if (p[1]) if (p[1])
iap->BOOTSTRAP = p + 1; iap->SOURCEBOOT = p + 1;
else if (argv[1] && *argv[1] != '-') { else if (argv[1] && *argv[1] != '-') {
iap->BOOTSTRAP = *++argv; iap->SOURCEBOOT = *++argv;
argc--; argc--;
} }
iap->install = true; iap->install = true;
@ -1086,6 +1096,7 @@ static void end_init(YAP_init_args *iap) {
Yap_exit(0); Yap_exit(0);
LOCAL_PrologMode &= ~BootMode; LOCAL_PrologMode &= ~BootMode;
CurrentModule = USER_MODULE; CurrentModule = USER_MODULE;
LOCAL_SourceModule = USER_MODULE;
} }
static void start_modules(void) { static void start_modules(void) {
@ -1103,7 +1114,8 @@ static void start_modules(void) {
X_API void YAP_Init(YAP_init_args *yap_init) { X_API void YAP_Init(YAP_init_args *yap_init) {
bool try_restore = yap_init->boot_file_type == YAP_QLY; bool try_restore = yap_init->boot_file_type == YAP_QLY;
bool do_bootstrap = yap_init->boot_file_type == YAP_BOOT_PL; bool do_bootstrap = yap_init->boot_file_type == YAP_PL ||
yap_init->boot_file_type == YAP_SOURCE_PL;
struct ssz_t minfo; struct ssz_t minfo;
__android_log_print( __android_log_print(
ANDROID_LOG_INFO, "YAPDroid", "start init "); ANDROID_LOG_INFO, "YAPDroid", "start init ");
@ -1123,6 +1135,7 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
// //
CACHE_REGS CACHE_REGS
CurrentModule = PROLOG_MODULE;
if (yap_init->QuietMode) { if (yap_init->QuietMode) {
setVerbosity(TermSilent); setVerbosity(TermSilent);
@ -1147,14 +1160,22 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
init_globals(yap_init); init_globals(yap_init);
start_modules(); start_modules();
CurrentModule = PROLOG_MODULE;
TermEof = MkAtomTerm(Yap_LookupAtom("end_of_file")); TermEof = MkAtomTerm(Yap_LookupAtom("end_of_file"));
LOCAL_consult_level = -1; LOCAL_consult_level = -1;
__android_log_print( __android_log_print(
ANDROID_LOG_INFO, "YAPDroid", "init %s ", Yap_BOOTSTRAP); ANDROID_LOG_INFO, "YAPDroid", "init %s ", Yap_BOOTSTRAP);
if (yap_init->install) {
load_file(Yap_SOURCEBOOT PASS_REGS);
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
MkAtomTerm(Yap_LookupAtom(Yap_SOURCEBOOT)));
}
else {
load_file(Yap_BOOTSTRAP PASS_REGS); load_file(Yap_BOOTSTRAP PASS_REGS);
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG, setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
MkAtomTerm(Yap_LookupAtom(Yap_BOOTFILE))); MkAtomTerm(Yap_LookupAtom(Yap_BOOTSTRAP)));
}
CurrentModule = LOCAL_SourceModule = TermUser;
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false); setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false);
} else { } else {
if (yap_init->QuietMode) { if (yap_init->QuietMode) {
@ -1163,6 +1184,7 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
__android_log_print( __android_log_print(
ANDROID_LOG_INFO, "YAPDroid", "restore %s ",Yap_INPUT_STARTUP ); ANDROID_LOG_INFO, "YAPDroid", "restore %s ",Yap_INPUT_STARTUP );
Yap_Restore(Yap_INPUT_STARTUP); Yap_Restore(Yap_INPUT_STARTUP);
CurrentModule = LOCAL_SourceModule = TermUser;
init_globals(yap_init); init_globals(yap_init);
start_modules(); start_modules();

View File

@ -83,8 +83,9 @@ endif ()
## options: libraries ## options: libraries
option(WITH_THREADED_CODE "threaded code" ON) option(WITH_THREADED_CODE "threaded code" ON)
if (NOT ANDROID)
option(WITH_MPI "Interface to OpenMPI/MPICH" ON) option(WITH_MPI "Interface to OpenMPI/MPICH" ON)
option(WITH_READLINE "use readline or libedit" ON) endif()
option(WITH_JIT "just in Time Clause Compilation" OFF) option(WITH_JIT "just in Time Clause Compilation" OFF)
if (APPLE) if (APPLE)
@ -121,7 +122,7 @@ if (APPLE)
GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PREFIX} DIRECTORY) GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PREFIX} DIRECTORY)
# "/opt/local/bin" doesn't have libs, so we get the parent directory # "/opt/local/bin" doesn't have libs, so we get the parent directory
GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PREFIX} DIRECTORY) GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PssREFIX} DIRECTORY)
# "/opt/local" is where MacPorts lives, add `/lib` suffix and link # "/opt/local" is where MacPorts lives, add `/lib` suffix and link
LINK_DIRECTORIES(${LINK DIRECTORIES} ${MACPORTS_PREFIX}/lib) LINK_DIRECTORIES(${LINK DIRECTORIES} ${MACPORTS_PREFIX}/lib)
@ -131,15 +132,31 @@ if (APPLE)
endif() endif()
endif() endif()
option (WITH_PACKAGES "packages and liaries that add value to YAP" ON) OPTION(WITH_MYDDAS " Enable MYDDAS DBMS interface" ON)
OPTION(WITH_MYDDAS " Enable MYDDAS driver" ${WITH_PACKAGES}) if (ANDROID)
OPTION(WITH_SQLITE3 " Enable MYDDAS SQLITE3 driver" ${WITH_MYDDAS}) option (WITH_PACKAGES "packages and libraries that add value to YAP" OFF)
OPTION(WITH_MYSQL " Enable MYDDAS MYSQL driver" ${WITH_MYDDAS}) OPTION(WITH_SWIG " Enable SWIG interfaces to foreign languages" ON)
OPTION(WITH_SQLITE3 " Enable MYDDAS SQLITE3 driver" ON)
else()
option (WITH_PACKAGES "packages and libraries that add value to YAP" ON)
OPTION(WITH_SWIG " Enable SWIG interfaces to foreign languages" ${WITH_PACKAGES})
OPTION(WITH_SQLITE3 " Enable MYDDAS SQLITE3 driver" ${WITH_PACKAGES})
endif()
OPTION(WITH_MYSQL " Enable MYDDAS MYSQL driver" ${WITH_MYDDAS}})
OPTION(WITH_ODBC " Enable MYDDAS ODBC driver" ${WITH_MYDDAS}) OPTION(WITH_ODBC " Enable MYDDAS ODBC driver" ${WITH_MYDDAS})
OPTION(WITH_POSTGRES " Enable MYDDAS POSTGRES 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})
IF (WITH_SWIG)
find_host_package(SWIG)
# macro_log_feature (SWIG_FOUND "Swig"
# "Use SWIG Interface Generator "
# "http://www.swig.org" ON)
ENDIF (WITH_SWIG)
OPTION(WITH_RAPTOR " Enable the RAPTOR RDF library" ${WITH_PACKAGES}) OPTION(WITH_RAPTOR " Enable the RAPTOR RDF library" ${WITH_PACKAGES})
OPTION(WITH_XML2 " Enable the RAPTOR XML2 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_XML " Enable the Prolog XML library" ${WITH_PACKAGES})
@ -165,21 +182,16 @@ if (POLICY CMP0042)
cmake_policy(SET CMP0042 NEW) cmake_policy(SET CMP0042 NEW)
endif () endif ()
function(add_to_group list output) if (ANDROID)
set(tmp ${${output}}) function(add_to_dir list output)
foreach (path ${${list}}) endfunction(add_to_dir list output)
get_source_file_property(path ${path} LOCATION)
list(APPEND tmp ${path})
endforeach ()
set(${output} ${tmp} CACHE INTERNAL "prolog library files")
endfunction(add_to_group list output)
function(add_to_libgroup el list) function(add_to_libgroup el list)
# add_custom_command( TARGET ${el} POST_BUILD # add_custom_command( TARGET ${el} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${el}> ${CMAKE_BINARY_DIR}/packages/python/swig/yap4py # COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${el}> ${CMAKE_BINARY_DIR}/packages/python/swig/yap4py
# DEPENDS ${el} ) # DEPENDS ${el} )
list(APPEND ${list} ${${el}}) #list(APPEND ${list} ${${el}})
set(${list} ${${list}} CACHE INTERNAL "prolog dll files") #set(${list} ${${list}} CACHE INTERNAL "prolog dll files")
endfunction(add_to_libgroup el list) endfunction(add_to_libgroup el list)
@ -191,6 +203,11 @@ function(add_to_corelibgroup el list)
set(${list} ${${list}} CACHE INTERNAL "prolog dll files") set(${list} ${${list}} CACHE INTERNAL "prolog dll files")
endfunction(add_to_corelibgroup el list) endfunction(add_to_corelibgroup el list)
else()
function(add_to_dir list output)
endfunction(add_to_dir list output)
endif()
if (ANDROID_OLD) if (ANDROID_OLD)
macro(MY_add_custom_target) macro(MY_add_custom_target)
@ -210,10 +227,6 @@ else ()
add_library(${arg1} OBJECT ${ARGN}) add_library(${arg1} OBJECT ${ARGN})
endmacro() endmacro()
endif () endif ()
macro(add_lib arg1)
add_library(${arg1} SHARED ${ARGN})
add_to_libgroup(${arg1} YAP_DLLS)
endmacro()
macro(add_corelib arg1) macro(add_corelib arg1)
add_library(${arg1} SHARED ${ARGN}) add_library(${arg1} SHARED ${ARGN})
add_to_corelibgroup(${arg1} YAP_DLLS) add_to_corelibgroup(${arg1} YAP_DLLS)
@ -311,7 +324,6 @@ ADD_CUSTOM_TARGET(run_install COMMAND ${CMAKE_MAKE_PROGRAM} install)
set(prefix ${CMAKE_INSTALL_PREFIX}) #BINDIR}) set(prefix ${CMAKE_INSTALL_PREFIX}) #BINDIR})
set(docdir ${CMAKE_INSTALL_PREFIX}/share/docs) #MANDIR}) set(docdir ${CMAKE_INSTALL_PREFIX}/share/docs) #MANDIR})
@ -327,8 +339,11 @@ set(YAP_PLDIR ${CMAKE_INSTALL_FULL_DATADIR}/Yap)
set(YAP_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/Yap) set(YAP_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/Yap)
set(YAP_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR}/Yap) set(YAP_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR}/Yap)
if (ANDROID)
set(YAP_INSTALL_DATADIR ${CMAKE_SOURCE_DIR}/../yaplib/src/generated/assets/Yap)
else()
set(YAP_INSTALL_DATADIR ${CMAKE_INSTALL_DATADIR}/Yap) set(YAP_INSTALL_DATADIR ${CMAKE_INSTALL_DATADIR}/Yap)
endif()
# #
# #
# include( Sources ) # include( Sources )
@ -350,7 +365,12 @@ find_package(GMP)
list(APPEND YAP_SYSTEM_OPTIONS big_numbers) list(APPEND YAP_SYSTEM_OPTIONS big_numbers)
include_directories(H
H/generated
include os OPTYap utf8proc JIT/HPP)
include_directories(BEFORE ${CMAKE_BINARY_DIR} ${CMAKE_TOP_BINARY_DIR})
add_subdirectory( H )
if (GMP_INCLUDE_DIRS) if (GMP_INCLUDE_DIRS)
#config.h needs this (TODO: change in code latter) #config.h needs this (TODO: change in code latter)
@ -520,6 +540,7 @@ endif (HAVE_GCC)
# #
#option (YAP_SWI_IO ON) #option (YAP_SWI_IO ON)
#TODO:
#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})
@ -528,41 +549,9 @@ endif (WITH_CALL_TRACER)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS UTF8PROC=1) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS UTF8PROC=1)
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)
IF (WITH_SWIG)
find_host_package(SWIG)
# macro_log_feature (SWIG_FOUND "Swig"
# "Use SWIG Interface Generator "
# "http://www.swig.org" ON)
ENDIF (WITH_SWIG)
IF (WITH_MYDDAS)
if (ANDROID)
include_directories (packages/swig/android)
else()
add_definitions(-DUSE_MYDDAS=1 -DMYDDAS_SQLITE3=1)
if (MYSQL_FOUND)
add_definitions(= -DMYDDAS_MYSQL=1)
endif ()
if (ODBC_FOUND)
add_definitions(= -DMYDDAS_ODBC=1)
endif ()
if (MYSQL_POSTGRES)
add_definitions(= -DMYDDAS_POSTGRES=1)
endif ()
endif(ANDROID)
endif(WITH_MYDDAS)
IF (WITH_PYTHON) IF (WITH_PYTHON)
include(python ) include(python )
ENDIF (WITH_PYTHON) ENDIF (WITH_PYTHON)
@ -574,6 +563,46 @@ IF (WITH_R)
ENDIF (WITH_R) ENDIF (WITH_R)
include(Sources)
ADD_SUBDIRECTORY(OPTYap)
ADD_SUBDIRECTORY(os)
ADD_SUBDIRECTORY(library/dialect/swi/fli)
ADD_SUBDIRECTORY(CXX)
add_subDIRECTORY(utf8proc )
if(ANDROID)
set(CXX_SWIG_OUTDIR ${CMAKE_BINARY_DIR}/packages/swig/android)
add_subdirectory(packages/swig/android)
add_definitions(-DMYDDAS=1 -DEMBEDDED_MYDDAS=1 -DMYDDAS_SQLITE3=1 -DEMBEDDED_SQLITE3=1)
link_directories(${CMAKE_SOURCE_DIR}/../sqlite-android/jni/${CMAKE_ANDROID_ARCH_ABI})
else()
add_definitions(-DMYDDAS=1 -DEMBEDDED_MYDDAS=1 -DMYDDAS_SQLITE3=1 )
endif()
if (MYSQL_FOUND)
add_definitions( -DMYDDAS_MYSQL=1)
endif ()
if (ODBC_FOUND)
add_definitions( -DMYDDAS_ODBC=1)
endif ()
if (POSTGRES_FOUND)
add_definitions( -DMYDDAS_POSTGRES=1)
endif()
#utf-8 is not aPconn option
# we use the nice UTF-8 package
#available at the Julia project
add_subDIRECTORY( packages/myddas )
List(APPEND YLIBS $<TARGET_OBJECTS:libOPTYap>) List(APPEND YLIBS $<TARGET_OBJECTS:libOPTYap>)
List(APPEND YLIBS $<TARGET_OBJECTS:libYAPOs>) List(APPEND YLIBS $<TARGET_OBJECTS:libYAPOs>)
List(APPEND YLIBS $<TARGET_OBJECTS:utf8proc>) List(APPEND YLIBS $<TARGET_OBJECTS:utf8proc>)
@ -586,22 +615,20 @@ if (WIN32 OR ANDROID)
endif () endif ()
if (ANDROID) if (ANDROID)
List(APPEND YLIBS $<TARGET_OBJECTS:YAPsqlite3>) List(APPEND YLIBS $<TARGET_OBJECTS:YAPsqlite3>)
List(APPEND YLIBS $<TARGET_OBJECTS:YAPJava>) List(APPEND YLIBS $<TARGET_OBJECTS:DROID>)
endif () endif ()
endif () endif ()
include(Sources)
add_library( # Sets the name of the library.
add_corelib( # Sets the name of the library.
libYap libYap
# Sets the library as a shared library. # Sets the library as a shared library.
SHARED SHARED
${ENGINE_SOURCES} ${ENGINE_SOURCES}
${C_INTERFACE_SOURCES} ${C_INTERFACE_SOURCES}
//${STATIC_SOURCES} ${STATIC_SOURCES}
# cmake object libraries # cmake object libraries
${YLIBS} ${YLIBS}
) )
@ -616,18 +643,30 @@ if (READLINE_FOUND)
endif () endif ()
if (ANDROID)
target_link_libraries(libYap sqliteX android log)
endif()
if (WIN32) if (WIN32)
target_link_libraries(libYap ${WINDLLS}) target_link_libraries(libYap ${WINDLLS})
if (WITH_PYTHON AND 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 ()
if (WITH_PYTHON AND PYTHON_INCLUDE_DIRS AND PYTHON_LIBRARIES)
target_link_libraries(libYap ${PYTHON_LIBRARIES})
endif ()
endif (WIN32) endif (WIN32)
target_link_libraries(libYap m) target_link_libraries(libYap m)
set_target_properties(libYap
PROPERTIES OUTPUT_NAME Yap
)
set(YAP_STARTUP startup.yss) set(YAP_STARTUP startup.yss)
set(YAP_BOOTFILE boot.yap ) set(YAP_SOURCEBOOT boot.yap )
## define system ## define system
# Optional libraries that affect compilation # Optional libraries that affect compilation
@ -646,13 +685,8 @@ string(SUBSTRING ${CMAKE_SHARED_LIBRARY_SUFFIX} 1 -1 SO_EXT)
set_property(DIRECTORY PROPERTY CXX_STANDARD 11) set_property(DIRECTORY PROPERTY CXX_STANDARD 11)
include_directories(H
H/generated
include os OPTYap utf8proc JIT/HPP)
include_directories(BEFORE ${CMAKE_BINARY_DIR} ${CMAKE_TOP_BINARY_DIR})
if (ANDROID) if (ANDROID)
include_directories(CXX ${CMAKE_SOURCE_DIR}/../generated/src/jni) include_directories(CXX ${CMAKE_SOURCE_DIR}/yaplib/../generated/src/jni)
endif () endif ()
include(Threads) include(Threads)
# #
@ -672,30 +706,6 @@ MY_set_target_properties(libYap
) )
#utf-8 is not aPconn option
# we use the nice UTF-8 package
#available at the Julia project
ADD_SUBDIRECTORY(OPTYap)
ADD_SUBDIRECTORY(os)
ADD_SUBDIRECTORY(packages/myddas)
ADD_SUBDIRECTORY(utf8proc)
ADD_SUBDIRECTORY(library/dialect/swi/fli)
ADD_SUBDIRECTORY(CXX)
add_subDIRECTORY(H)
#bootstrap and saved state
add_subDIRECTORY(pl)
ADD_SUBDIRECTORY(library)
ADD_SUBDIRECTORY(swi/library "swiLibrary")
set_target_properties(libYap
PROPERTIES OUTPUT_NAME Yap
)
# file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/packages/python/swig/yap4py) # file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/packages/python/swig/yap4py)
@ -717,20 +727,6 @@ if (WITH_PYTHON AND PYTHONLIBS_FOUND AND SWIG_FOUND)
endif () endif ()
IF ( ANDROID)
set(CMAKE_SWIG_OUTDIR ${YAP_APP_DIR}/src/generated/java/pt/up/yap/lib )
set(CMAKE_SWIG_OUTPUT ${YAP_APP_DIR}/src/generated/jni )
set( SWIG_MODULE_NAME pt.up.yap.lib )
add_subDIRECTORY(packages/swig )
target_link_libraries(libYap ${CMAKE_SOURCE_DIR}/../sqlite-android/jni/${ANDROID_ABI}/libsqliteX.so android log )
ENDIF ()
message(STATUS "Building YAP packages version ${YAP_VERSION}") message(STATUS "Building YAP packages version ${YAP_VERSION}")
@ -897,7 +893,7 @@ endif()
#todo: use cmake target builds #todo: use cmake target builds
# option (USE_MAXPERFORMANCE # option (USE_MAXPERFORMANCE
# "try using the best flags for specific architecture" OFF) # "try using the best flags for specific architecture" ON)
# option (USE_MAXMEMORY # option (USE_MAXMEMORY
# "try using the best flags for using the memory to the most" ON) # "try using the best flags for using the memory to the most" ON)
@ -905,11 +901,11 @@ endif()
#TODO: use cmake target builds #TODO: use cmake target builds
# option (USE_DEBUGYAP # option (USE_DEBUGYAP
# "enable C-debugging for YAP" OFF) # "enable C-debugging for YAP" ON)
#TODO: use cmake arch/compiler #TODO: use cmake arch/compiler
# option (USE_CYGWIN # option (USE_CYGWIN
# "use cygwin library in WIN32" OFF) # "use cygwin library in WIN32" ON)
#TODO: #TODO:
@ -987,8 +983,6 @@ endif(WITH_MPI)
install(FILES ${INCLUDE_HEADERS} ${CONFIGURATION_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Yap ) install(FILES ${INCLUDE_HEADERS} ${CONFIGURATION_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Yap )
macro_display_feature_log() macro_display_feature_log()
if (POLICY CMP0058) if (POLICY CMP0058)
cmake_policy(SET CMP0058 NEW) cmake_policy(SET CMP0058 NEW)

View File

@ -14,7 +14,7 @@ if ( WIN32 OR ANDROID)
set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_YAP_NOT_INSTALLED_=1;HAVE_CONFIG_H=1;_GNU_SOURCE;YAP_KERNEL=1" ) set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_YAP_NOT_INSTALLED_=1;HAVE_CONFIG_H=1;_GNU_SOURCE;YAP_KERNEL=1" )
else() else()
add_lib(YAP++ ${CXX_SOURCES} ) add_library(YAP++ ${CXX_SOURCES} )
if (WITH_PYTHON) if (WITH_PYTHON)
target_link_libraries(YAP++ Py4YAP ) target_link_libraries(YAP++ Py4YAP )
endif() endif()

View File

@ -599,11 +599,12 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
q.CurSlot = Yap_StartSlots(); q.CurSlot = Yap_StartSlots();
q.p = P; q.p = P;
q.cp = CP; q.cp = CP;
Term omod = CurrentModule;
PredEntry *ap = nullptr; PredEntry *ap = nullptr;
if (IsStringTerm(tmod)) if (IsStringTerm(tmod))
tmod = MkAtomTerm(Yap_LookupAtom(StringOfTerm(tmod))); tmod = MkAtomTerm(Yap_LookupAtom(StringOfTerm(tmod)));
YAPPredicate *p = new YAPPredicate(t, tmod, ts, "C++"); ap = Yap_get_pred(t, tmod, "C++");
if (p == nullptr || (ap = p->ap) == nullptr || if (ap == nullptr ||
ap->OpcodeOfPred == UNDEF_OPCODE) { ap->OpcodeOfPred == UNDEF_OPCODE) {
ap = rewriteUndefEngineQuery(ap, t, tmod); ap = rewriteUndefEngineQuery(ap, t, tmod);
} }
@ -627,6 +628,7 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
// std::cerr << "mgoal " << YAPTerm(tmod).text() << ":" << YAPTerm(t).text() << "\n"; // std::cerr << "mgoal " << YAPTerm(tmod).text() << ":" << YAPTerm(t).text() << "\n";
YAP_LeaveGoal(result && !release, &q); YAP_LeaveGoal(result && !release, &q);
CurrentModule = LOCAL_SourceModule = omod;
// PyEval_RestoreThread(_save); // PyEval_RestoreThread(_save);
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return result; return result;
@ -801,6 +803,7 @@ PredEntry *YAPQuery::rewriteUndefQuery() {
PredEntry *YAPEngine::rewriteUndefEngineQuery(PredEntry *a, Term &tgoal, PredEntry *YAPEngine::rewriteUndefEngineQuery(PredEntry *a, Term &tgoal,
Term mod) { Term mod) {
tgoal = Yap_MkApplTerm(FunctorCall, 1, &tgoal); tgoal = Yap_MkApplTerm(FunctorCall, 1, &tgoal);
LOCAL_ActiveError->errorNo = YAP_NO_ERROR;
return PredCall; return PredCall;
// return YAPApplTerm(FunctorUndefinedQuery, ts); // return YAPApplTerm(FunctorUndefinedQuery, ts);
@ -919,6 +922,7 @@ void YAPEngine::doInit(YAP_file_type_t BootMode, YAPEngineArgs *engineArgs) {
// initq.cut(); // initq.cut();
// } // }
CurrentModule = TermUser; CurrentModule = TermUser;
LOCAL_SourceModule = TermUser;
} }
YAPEngine::YAPEngine(int argc, char *argv[], YAPEngine::YAPEngine(int argc, char *argv[],

View File

@ -94,7 +94,7 @@ public:
/// should be a callable /// should be a callable
/// goal. /// goal.
inline YAPQuery(const char *s) : YAPPredicate(s, goal, names, (nts = &ARG1)) { inline YAPQuery(const char *s) : YAPPredicate(s, goal, names, (nts = &ARG1)) {
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %ld", __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %d",
LOCAL_CurSlot); LOCAL_CurSlot);
openQuery(); openQuery();
@ -175,11 +175,11 @@ struct X_API YAPEngineArgs : YAP_init_args {
public: public:
YAPEngineArgs() { YAPEngineArgs() {
memset(this,0,sizeof(YAPEngineArgs));
// const std::string *s = new std::string("startup.yss"); // const std::string *s = new std::string("startup.yss");
Embedded = true; Embedded = true;
install = false; install = false;
Yap_InitDefaults(&this->start, nullptr, 0, nullptr);
Yap_InitDefaults(this, nullptr, 0, nullptr);
#if YAP_PYTHON #if YAP_PYTHON
Embedded = true; Embedded = true;
python_in_python = Py_IsInitialized(); python_in_python = Py_IsInitialized();
@ -231,12 +231,12 @@ public:
inline const char *getOUTPUT_STARTUP() { return OUTPUT_STARTUP; }; inline const char *getOUTPUT_STARTUP() { return OUTPUT_STARTUP; };
inline void setBOOTFILE(const char *fl) { inline void setSOURCEBOOT(const char *fl) {
BOOTFILE = (const char *)malloc(strlen(fl) + 1); SOURCEBOOT = (const char *)malloc(strlen(fl) + 1);
strcpy((char *)BOOTFILE, fl); strcpy((char *)SOURCEBOOT, fl);
}; };
inline const char *getBOOTFILE() { return BOOTFILE; }; inline const char *getSOURCEBOOT() { return SOURCEBOOT; };
inline void setPrologBOOTSTRAP(const char *fl) { inline void setPrologBOOTSTRAP(const char *fl) {
BOOTSTRAP = (const char *)malloc(strlen(fl) + 1); BOOTSTRAP = (const char *)malloc(strlen(fl) + 1);
@ -298,7 +298,7 @@ public:
__android_log_print( __android_log_print(
ANDROID_LOG_INFO, "YAPDroid", "start engine "); ANDROID_LOG_INFO, "YAPDroid", "start engine ");
#ifdef __ANDROID__ #ifdef __ANDROID__
doInit(YAP_BOOT_PL, cargs); doInit(YAP_PL, cargs);
#else #else
doInit(YAP_QLY, cargs); doInit(YAP_QLY, cargs);
@ -352,6 +352,7 @@ public:
bool mgoal(Term t, Term tmod, bool release = false); bool mgoal(Term t, Term tmod, bool release = false);
/// current directory for the engine /// current directory for the engine
bool goal(YAPTerm t, bool release = false) { return goal(t.term(), release); }
bool goal(Term t, bool release = false) { bool goal(Term t, bool release = false) {
return mgoal(t, Yap_CurrentModule(), release); return mgoal(t, Yap_CurrentModule(), release);
} }

View File

@ -12,10 +12,10 @@ string(REGEX REPLACE "^LOCAL[^(]*[(][ \t]*([^,]+)[ \t]*,[ \t]*([^),]+).*" "#de
list( APPEND tmp2 ${i2} "\n") list( APPEND tmp2 ${i2} "\n")
endforeach() endforeach()
endif() endif()
file( WRITE ${CMAKE_TOP_BINARY_DIR}/dlocals.h ${tmp2}) file( WRITE ${CMAKE_BINARY_DIR}/dlocals.h ${tmp2})
add_custom_command( OUTPUT ${CMAKE_TOP_BINARY_DIR}/dlocals.h add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/dlocals.h
COMMAND ${CMAKE_COMMAND} -E COPY ${CMAKE_TOP_BINARY_DIR}/deflocals.h ${CMAKE_TOP_BINARY_DIR}/dlocals.h COMMAND ${CMAKE_COMMAND} -E COPY ${CMAKE_BINARY_DIR}/deflocals.h ${CMAKE_BINARY_DIR}/dlocals.h
DEPENDS locals.h ) DEPENDS locals.h )

View File

@ -175,7 +175,7 @@ typedef void *(*fptr_t)(void);
extern const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR, extern const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR,
*Yap_PLDIR, *Yap_COMMONSDIR, *Yap_STARTUP,*Yap_INPUT_STARTUP,*Yap_OUTPUT_STARTUP, *Yap_PLDIR, *Yap_COMMONSDIR, *Yap_STARTUP,*Yap_INPUT_STARTUP,*Yap_OUTPUT_STARTUP,
*Yap_BOOTFILE, *Yap_INCLUDEDIR; *Yap_SOURCEBOOT, *Yap_INCLUDEDIR;
/* Basic exports */ /* Basic exports */

View File

@ -631,34 +631,6 @@ and if it is bound to `off` disable them. The default for YAP is
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),
/**<
If `normal` allow printing of informational and banner messages,
such as the ones that are printed when consulting. If `silent`
disable printing these messages. It is `normal` by default except if
YAP is booted with the `-q` or `-L` flag.
*/
YAP_FLAG(VERBOSE_FLAG, "verbose", true, isatom, "normal", NULL),
/**<
If `true` allow printing of informational messages when
searching for file names. If `false` disable printing these messages. It
is `false` by default except if YAP is booted with the `-L`
flag.
*/
YAP_FLAG(VERBOSE_FILE_SEARCH_FLAG, "verbose_file_search", true, booleanFlag,
"false", NULL),
/**<
If `true` allow printing of informational messages when
consulting files. If `false` disable printing these messages. It
is `true` by default except if YAP is booted with the `-L`
flag.
*/
YAP_FLAG(VERBOSE_LOAD_FLAG, "verbose_load", true, booleanFlag, "true", NULL),
/**< /**<
Read-only flag that returns a compound term with the Read-only flag that returns a compound term with the

View File

@ -101,6 +101,37 @@ Just fail
*/ */
YAP_FLAG(TYPEIN_MODULE_FLAG, "typein_module", true, isatom, "user", YAP_FLAG(TYPEIN_MODULE_FLAG, "typein_module", true, isatom, "user",
typein), typein),
/**<
If `normal` allow printing of informational and banner messages,
such as the ones that are printed when consulting. If `silent`
disable printing these messages. It is `normal` by default except if
YAP is booted with the `-q` or `-L` flag.
*/
YAP_FLAG(VERBOSE_FLAG, "verbose", true, isatom, "normal", NULL),
/**<
If `true` allow printing of informational messages when
searching for file names. If `false` disable printing these messages. It
is `false` by default except if YAP is booted with the `-L`
flag.
*/
YAP_FLAG(VERBOSE_FILE_SEARCH_FLAG, "verbose_file_search", true, booleanFlag,
"false", NULL),
/**<
If `true` allow printing of informational messages when
consulting files. If `false` disable printing these messages. It
is `true` by default except if YAP is booted with the `-L`
flag.
*/
YAP_FLAG(VERBOSE_LOAD_FLAG, "verbose_load", true, booleanFlag, "true", NULL),
/**< /**<
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

View File

@ -75,12 +75,12 @@ extern void Yap_FreeCodeSpace(void *);
extern void *Yap_AllocAtomSpace(size_t); extern void *Yap_AllocAtomSpace(size_t);
extern void *Yap_AllocCodeSpace(size_t); extern void *Yap_AllocCodeSpace(size_t);
extern void *Yap_ReallocCodeSpace(void *, size_t); extern void *Yap_ReallocCodeSpace(void *, size_t);
extern ADDR Yap_AllocFromForeignArea(Int); extern ADDR Yap_AllocFromForeignArea(size_t);
extern int Yap_ExtendWorkSpace(Int); extern int Yap_ExtendWorkSpace(Int);
extern void Yap_FreeAtomSpace(void *); extern void Yap_FreeAtomSpace(void *);
extern int Yap_FreeWorkSpace(void); extern int Yap_FreeWorkSpace(void);
extern void Yap_InitMemory(UInt, UInt, UInt); extern void Yap_InitMemory(size_t, size_t, size_t);
extern void Yap_InitExStacks(int, int, int); extern void Yap_InitExStacks(int, size_t, size_t);
/* amasm.c */ /* amasm.c */
extern OPCODE Yap_opcode(op_numbers); extern OPCODE Yap_opcode(op_numbers);
@ -239,20 +239,20 @@ extern void Yap_inform_profiler_of_clause__(void *, void *, struct pred_entry *,
extern void Yap_tell_gprof(yamop *); extern void Yap_tell_gprof(yamop *);
/* globals.c */ /* globals.c */
extern Term Yap_NewArena(UInt, CELL *); extern Term Yap_NewArena(size_t, CELL *);
extern CELL *Yap_GetFromArena(Term *, UInt, UInt); extern CELL *Yap_GetFromArena(Term *, size_t, UInt);
extern void Yap_InitGlobals(void); extern void Yap_InitGlobals(void);
extern Term Yap_SaveTerm(Term); extern Term Yap_SaveTerm(Term);
extern Term Yap_SetGlobalVal(Atom, Term); extern Term Yap_SetGlobalVal(Atom, Term);
extern Term Yap_GetGlobal(Atom); extern Term Yap_GetGlobal(Atom);
extern Int Yap_DeleteGlobal(Atom); extern Int Yap_DeleteGlobal(Atom);
extern void Yap_AllocateDefaultArena(Int, Int, int); extern void Yap_AllocateDefaultArena(size_t gsize, int wid);
extern CELL *Yap_ArenaLimit(Term arena); extern CELL *Yap_ArenaLimit(Term arena);
/* grow.c */ /* grow.c */
extern Int Yap_total_stack_shift_time(void); extern Int Yap_total_stack_shift_time(void);
extern void Yap_InitGrowPreds(void); extern void Yap_InitGrowPreds(void);
extern UInt Yap_InsertInGlobal(CELL *, UInt); extern size_t Yap_InsertInGlobal(CELL *, size_t);
extern int Yap_growheap(bool, size_t, void *); extern int Yap_growheap(bool, size_t, void *);
extern int Yap_growstack(size_t); extern int Yap_growstack(size_t);
extern int Yap_growtrail(size_t, bool); extern int Yap_growtrail(size_t, bool);

View File

@ -20,6 +20,15 @@ if (ANDROID)
else() else()
message("Bad call: ${GMP_ROOT} does not exist") message("Bad call: ${GMP_ROOT} does not exist")
endif() endif()
set( GMP_ROOT ${CMAKE_SOURCE_DIR}/../../gmp/${ANDROID_ABI} )
if (EXISTS ${GMP_ROOT} )
message("Looking good for ${GMP_ROOT}")
set(GMP_INCLUDE_DIRS ${GMP_ROOT} CACHE PATH "include search path")
set(GMP_LIBRARIES ${GMP_ROOT}/libgmp.so CACHE FILEPATH "include search path")
set(GMP_LIBRARIES_DIR ${GMP_ROOT} CACHE PATH "include search path")
else()
message("Bad call: ${GMP_ROOT} does not exist")
endif()
find_path(GMP_INCLUDE_DIRS find_path(GMP_INCLUDE_DIRS
NAMES gmp.h NAMES gmp.h
HINTS ${GMP_ROOT} HINTS ${GMP_ROOT}

View File

@ -5,17 +5,6 @@
set (ABSMI_SOURCES set (ABSMI_SOURCES
C/absmi.c C/absmi.c
C/absmi_insts.h
C/fli_absmi_insts.h
C/or_absmi_insts.h
C/control_absmi_insts.h
C/index_absmi_insts.h
C/prim_absmi_insts.h
C/cp_absmi_insts.h
C/lu_absmi_insts.h
C/unify_absmi_insts.h
C/fail_absmi_insts.h
C/meta_absmi_insts.h
) )
set (ENGINE_SOURCES set (ENGINE_SOURCES

View File

@ -2035,13 +2035,13 @@ significant byte first (like Motorola and SPARC, unlike Intel). */
/* run-time boot */ /* run-time boot */
#ifndef YAP_BOOTFILE #ifndef YAP_SOURCEBOOT
#define YAP_BOOTFILE "${YAP_PLDIR}/pl/boot.yap" #define YAP_SOURCEBOOT "${CMAKE_SOURCE_DIR}/pl/boot.yap"
#endif #endif
/* init-time boot */ /* init-time boot */
#ifndef YAP_BOOTSTRAP #ifndef YAP_BOOTSTRAP
#define YAP_BOOTSTRAP "${CMAKE_SOURCE_DIR}/pl/boot.yap" #define YAP_BOOTSTRAP "${YAP_PLDIR}/pl/boot.yap"
#endif #endif

View File

@ -96,7 +96,7 @@ typedef enum {
YAP_SAVED_STATE = 0x0004, YAP_SAVED_STATE = 0x0004,
YAP_OBJ = 0x0008, YAP_OBJ = 0x0008,
YAP_PL = 0x0010, YAP_PL = 0x0010,
YAP_BOOT_PL = 0x0030, YAP_SOURCE_PL = 0x0030,
YAP_QLY = 0x0040, YAP_QLY = 0x0040,
YAP_EXE = 0x0080, YAP_EXE = 0x0080,
YAP_FOUND_BOOT_ERROR = 0x0100, YAP_FOUND_BOOT_ERROR = 0x0100,

View File

@ -20,6 +20,8 @@ X_API YAP_file_type_t Yap_InitDefaults(void *init_args, char saved_state[],
int Argc, char *Argv[]); int Argc, char *Argv[]);
typedef struct yap_boot_params { typedef struct yap_boot_params {
//> struct marker
void *start;
//> boot type as suggested by the user //> boot type as suggested by the user
YAP_file_type_t boot_file_type; YAP_file_type_t boot_file_type;
//> how files are organised: NULL is GNU/Linux way //> how files are organised: NULL is GNU/Linux way
@ -41,7 +43,9 @@ typedef struct yap_boot_params {
//> if NON-NULL, Prolog library, sets Yap_COMMONSDIR //> if NON-NULL, Prolog library, sets Yap_COMMONSDIR
const char *COMMONSDIR; const char *COMMONSDIR;
//> if NON-NULL, name for a Prolog file to use when booting at run-time //> if NON-NULL, name for a Prolog file to use when booting at run-time
const char *BOOTFILE; const char *BOOTDIR;
//> if NON-NULL, name for a Prolog directory that we shall use to start booting
const char *SOURCEBOOT;
//> if NON-NULL, name for a Prolog file to use when booting at compile-time //> if NON-NULL, name for a Prolog file to use when booting at compile-time
const char *BOOTSTRAP; const char *BOOTSTRAP;
//> if NON-NULL, path where we can find the saved state //> if NON-NULL, path where we can find the saved state

View File

@ -63,23 +63,19 @@ set (LIBRARY_PL
) )
MY_add_subdirectory(dialect) add_subdirectory(dialect)
MY_add_subdirectory(clp) # add_subdirectory(clp)
MY_add_subdirectory(matlab) MY_add_subdirectory(matlab)
MY_add_subdirectory(matrix) add_subdirectory(matrix)
MY_add_subdirectory(random) add_subdirectory(random)
MY_add_subdirectory(regex) add_subdirectory(regex)
MY_add_subdirectory(rltree) add_subdirectory(rltree)
MY_add_subdirectory(system) add_subdirectory(system)
MY_add_subdirectory(tries) add_subdirectory(tries)
MY_add_subdirectory(ytest) MY_add_subdirectory(ytest)
add_to_group( LIBRARY_PL pl_library) add_to_dir(LIBRARY_PL ${YAP_INSTALL_DATADIR})
install(FILES ${LIBRARY_PL} DESTINATION ${YAP_INSTALL_DATADIR}) install(FILES ${LIBRARY_PL} DESTINATION ${YAP_INSTALL_DATADIR})
if (ANDROID)
file( INSTALL ${LIBRARY_PL} DESTINATION ${YAP_INSTALL_DATADIR} )
endif()
include_directories("dialect/swi") include_directories("dialect/swi")

View File

@ -1,19 +0,0 @@
%:- start_low_level_trace.
:- module(user).
:- yap_flag(verbose,normal).
query( String ) :-
yap_flag(typein_module, Mod),
atomic_to_term( String, Goal, VarNames ),
query_to_answer( Mod:Goal, VarNames, Status, Bindings),
output( Bindings, Status) .
output( Bindings, Status) :-
(Status == answer -> true ;
Status == exit ->true
),
write_query_answer( Bindings ),
nl(user_error).
%:- [sqlitest].

View File

@ -7,7 +7,6 @@
* *
*/ */
:- module(apply_stub,[]). :- module(apply_stub,[]).

View File

@ -2216,7 +2216,7 @@ X_API int PL_initialise(int myargc, char **myargv) {
init_args.INPUT_STARTUP = NULL; init_args.INPUT_STARTUP = NULL;
#endif #endif
init_args.LIBDIR = NULL; init_args.LIBDIR = NULL;
init_args.BOOTFILE = NULL; init_args.SOURCEBOOT = NULL;
init_args.HaltAfterBoot = true; init_args.HaltAfterBoot = true;
init_args.FastBoot = FALSE; init_args.FastBoot = FALSE;
init_args.MaxTableSpaceSize = 0; init_args.MaxTableSpaceSize = 0;

View File

@ -67,7 +67,7 @@ set (MPI_YAP_SOURCES
# program, EXECUTABLE is the MPI program, and ARGS are the arguments to # program, EXECUTABLE is the MPI program, and ARGS are the arguments to
# pass to the MPI program. # pass to the MPI program.
# #
add_lib(yap_mpi ${MPI_YAP_SOURCES}) add_library(yap_mpi ${MPI_YAP_SOURCES})
target_link_libraries(yap_mpi libYap ${MPI_C_LIBRARIES}) target_link_libraries(yap_mpi libYap ${MPI_C_LIBRARIES})

View File

@ -1,3 +1,4 @@
/** /**
* @file maputils.yap * @file maputils.yap
* @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan> * @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan>
@ -27,6 +28,14 @@
*/ */
:- use_module(library(lists), [append/3]). :- use_module(library(lists), [append/3]).
%% goal_expansion_allowed is semidet.
%
% `True` if we can use
% goal-expansion.
goal_expansion_allowed :-
once( prolog_load_context(_, _) ), % make sure we are compiling.
\+ current_prolog_flag(xref, true).
:- dynamic number_of_expansions/1. :- dynamic number_of_expansions/1.
number_of_expansions(0). number_of_expansions(0).
@ -95,14 +104,6 @@ transformation_id(Id) :-
assert(number_of_expansions(Id1)). assert(number_of_expansions(Id1)).
transformation_id(0). transformation_id(0).
%% goal_expansion_allowed is semidet.
%
% `True` if we can use
% goal-expansion.
goal_expansion_allowed :-
once( prolog_load_context(_, _) ), % make sure we are compiling.
\+ current_prolog_flag(xref, true).
/** /**
@} @}
*/ */

View File

@ -1,5 +1,5 @@
add_lib(matrix matrix.c) add_library(matrix matrix.c)
target_link_libraries(matrix libYap) target_link_libraries(matrix libYap)

View File

@ -1,13 +1,10 @@
set( LIBRANDOM_SOURCES yap_random.c) set( LIBRANDOM_SOURCES yap_random.c)
add_lib(yap_random ${LIBRANDOM_SOURCES}) add_library(yap_random ${LIBRANDOM_SOURCES})
if (ANDROID)
else()
target_link_libraries(yap_random libYap) target_link_libraries(yap_random libYap)
set_target_properties (yap_random PROPERTIES PREFIX "") set_target_properties (yap_random PROPERTIES PREFIX "")
endif()
MY_install(TARGETS yap_random MY_install(TARGETS yap_random
LIBRARY DESTINATION ${YAP_INSTALL_LIBDIR} LIBRARY DESTINATION ${YAP_INSTALL_LIBDIR}

View File

@ -17,7 +17,7 @@ set ( REGEX_SOURCES
add_lib(regexp regexp.c ${REGEX_SOURCES}) add_library(regexp regexp.c ${REGEX_SOURCES})
target_link_libraries(regexp libYap) target_link_libraries(regexp libYap)

View File

@ -4,7 +4,7 @@ set ( RLTREE_SOURCES
range_list.h range_list.h
) )
add_lib(yap_rl yap_rl.c ${RLTREE_SOURCES}) add_library(yap_rl yap_rl.c ${RLTREE_SOURCES})
target_link_libraries(yap_rl libYap) target_link_libraries(yap_rl libYap)

View File

@ -2,7 +2,7 @@ set( LIBSYSTEM_SOURCES sys.c crypto/md5.c )
set( LIBSYSTEM_HEADERS crypto/md5.h) set( LIBSYSTEM_HEADERS crypto/md5.h)
add_lib(sys ${LIBSYSTEM_SOURCES}) add_library(sys ${LIBSYSTEM_SOURCES})
if (ANDROID) if (ANDROID)
set (TARGET libYap) set (TARGET libYap)
else() else()

View File

@ -237,8 +237,10 @@ static YAP_Bool list_directory(void) {
#else #else
#if __ANDROID__ #if __ANDROID__
{ {
extern AAssetManager *Yap_assetManager(void);
const char *dirName = buf + strlen("/assets/"); const char *dirName = buf + strlen("/assets/");
AAssetManager *mgr = GLOBAL_VFS->priv[0].mgr; AAssetManager *mgr = Yap_assetManager();
AAssetDir *de; AAssetDir *de;
const char *dp; const char *dp;

View File

@ -6,7 +6,7 @@ set ( TRIES_SOURCES
tries.c tries.c
) )
add_lib(tries ${TRIES_SOURCES}) add_library(tries ${TRIES_SOURCES})
target_link_libraries(tries libYap) target_link_libraries(tries libYap)
@ -27,7 +27,7 @@ set ( ITRIES_SOURCES
if (ANDROID OR WIN32) if (ANDROID OR WIN32)
add_component ( otries ${TRIES_SOURCES} ) add_component ( otries ${TRIES_SOURCES} )
endif() endif()
add_lib(itries ${ITRIES_SOURCES}) add_library(itries ${ITRIES_SOURCES})
target_link_libraries(itries libYap) target_link_libraries(itries libYap)

View File

@ -1,5 +1,6 @@
set (YAPOS_HEADERS set (YAPOS_HEADERS
getw.h getw.h
iopreds.h iopreds.h
yapio.h yapio.h
YapEncoding.h YapEncoding.h
@ -62,12 +63,7 @@ set (POSITION_INDEPENDENT_CODE TRUE)
yio.yap yio.yap
) )
add_to_group( YAPOS_PL_SOURCES pl_os_library) add_to_dir(YAPOS PL_SOURCES ${YAP_INSTALL_DATADIR}/os)
if (ANDROID)
file(INSTALL ${YAPOS_PL_SOURCES} DESTINATION ${YAP_INSTALL_DATADIR}/os)
else()
install (FILES ${YAPOS_PL_SOURCES} install (FILES ${YAPOS_PL_SOURCES}
DESTINATION ${YAP_INSTALL_DATADIR}/os ) DESTINATION ${YAP_INSTALL_DATADIR}/os )
endif()

View File

@ -77,7 +77,7 @@ open_asset(VFS_t *me, const char *fname, const char *io_mode, int sno) {
// AAssetDir *dp = AAssetManager_openDir( Yap_assetManager(), dirname(dir) ); // AAssetDir *dp = AAssetManager_openDir( Yap_assetManager(), dirname(dir) );
// strcpy(dir, fname); // strcpy(dir, fname);
// char *d = basename(dir); // char *d = basename(dir);
am = AAssetManager_open(Yap_assetManager(), fname, io_mode); am = AAssetManager_open(Yap_assetManager(), fname, AASSET_MODE_UNKNOWN);
//if (am==NULL) //if (am==NULL)
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "failed open %s <%s>", fname, strerror(errno) ); // __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "failed open %s <%s>", fname, strerror(errno) );
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "open %s <%s>", fname, io_mode); __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "open %s <%s>", fname, io_mode);

View File

@ -799,6 +799,7 @@ static const param_t expand_filename_defs[] = {EXPAND_FILENAME_DEFS()};
static Term do_expand_file_name(Term t1, Term opts USES_REGS) { static Term do_expand_file_name(Term t1, Term opts USES_REGS) {
xarg *args; xarg *args;
expand_filename_enum_choices_t i; expand_filename_enum_choices_t i;
bool use_system_expansion = true; bool use_system_expansion = true;
const char *tmpe = NULL; const char *tmpe = NULL;
const char *spec; const char *spec;
@ -1046,10 +1047,10 @@ static bool initSysPath(Term tlib, Term tcommons, bool dir_done,
bool commons_done) { bool commons_done) {
CACHE_REGS CACHE_REGS
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(Yap_PLDIR)))) if (!Yap_PLDIR || !Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(Yap_PLDIR))))
return false; return false;
return Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(Yap_COMMONSDIR))); return Yap_COMMONSDIR && Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(Yap_COMMONSDIR)));
} }
static Int libraries_directories(USES_REGS1) { static Int libraries_directories(USES_REGS1) {
@ -1057,21 +1058,7 @@ static Int libraries_directories(USES_REGS1) {
} }
static Int system_library(USES_REGS1) { static Int system_library(USES_REGS1) {
#if __ANDROID__
static Term dir = 0;
Term t;
if (IsVarTerm(t = Deref(ARG1))) {
if (dir == 0)
return false;
return Yap_unify(dir, ARG1);
}
if (!IsAtomTerm(t))
return false;
dir = t;
return true;
#else
return initSysPath(ARG1, MkVarTerm(), false, true); return initSysPath(ARG1, MkVarTerm(), false, true);
#endif
} }
static Int commons_library(USES_REGS1) { static Int commons_library(USES_REGS1) {

View File

@ -45,14 +45,14 @@ if (CMAKE_MAJOR_VERSION GREATER 2)
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
) )
ADD_LIB(horus ${HORUS_SOURCES} HorusYap.cpp ) add_library(horus ${HORUS_SOURCES} HorusYap.cpp )
if(DEFINED YAP_MAJOR_VERSION) if(DEFINED YAP_MAJOR_VERSION)
TARGET_LINK_LIBRARIES(horus TARGET_LINK_LIBRARIES(horus
libYap libYap
) )
else() else()
ADD_LIB(horus ${HORUS_SOURCES} ) add_library(horus ${HORUS_SOURCES} )
endif() endif()
#set_property(TARGET horus PROPERTY CXX_STANDARD 11) #set_property(TARGET horus PROPERTY CXX_STANDARD 11)

View File

@ -33,7 +33,7 @@ if (GECODE_FOUND)
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
) )
add_lib(gecode_yap ${GECODE_SOURCES}) add_library(gecode_yap ${GECODE_SOURCES})
target_link_libraries(gecode_yap libYap ${GECODE_LIBRARIES}) target_link_libraries(gecode_yap libYap ${GECODE_LIBRARIES})

View File

@ -132,7 +132,7 @@ IF (CUDD_FOUND)
${CMAKE_CURRENT_BINARY_DIR}/../bdd ${CMAKE_CURRENT_BINARY_DIR}/../bdd
) )
add_lib(bddem add_library(bddem
${BDDEM_SOURCES} ${BDDEM_SOURCES}
) )
@ -154,7 +154,7 @@ IF (CUDD_FOUND)
) )
add_lib(cplint add_library(cplint
${CPLINT_SOURCES} ${CPLINT_SOURCES}
) )

View File

@ -77,7 +77,7 @@ cuda.c
cuda.yap cuda.yap
) )
cuda_add_lib(libcuda ${CUDA_SOURCES}) cuda_add_library(libcuda ${CUDA_SOURCES})
target_link_libraries(libcuda libYap target_link_libraries(libcuda libYap
${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY} # ${CUDA_nppc_LIBRARY} ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY} # ${CUDA_nppc_LIBRARY}

View File

@ -32,7 +32,7 @@ if (GECODE_FOUND)
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
) )
add_lib(gecode_yap ${GECODE_SOURCES}) add_library(gecode_yap ${GECODE_SOURCES})
target_link_libraries(gecode_yap libYap ${GECODE_LIBRARIES}) target_link_libraries(gecode_yap libYap ${GECODE_LIBRARIES})

View File

@ -13,7 +13,9 @@ set(MYDDAS_SOURCES
myddas_top_level.c myddas_top_level.c
) )
include_directories(. sqlite3) set_property(DIRECTORY
APPEND PROPERTY
INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/sqlite3)
set(MYDDAS_HEADERS set(MYDDAS_HEADERS
@ -21,27 +23,19 @@ set(MYDDAS_HEADERS
myddas_statistics.h myddas_statistics.h
myddas_statistics_structs.h myddas_statistics_structs.h
myddas_structs.h myddas_structs.h
myddas_top_level.c
myddas_types.h) myddas_types.h)
set(MYDDAS_UTIL_SOURCES set(MYDDAS_UTIL_SOURCES
myddas_util.c myddas_util.c
myddas_initialization.c) myddas_initialization.c)
set (MYDDAS_FLAGS -DUSE_MYDDAS=1)
set_property(GLOBAL
APPEND PROPERTY
COMPILE_DEFINITIONS
-DUSE_MYDDAS=1)
include_directories(. sqlite3)
add_subdirectory(sqlite3) add_subdirectory(sqlite3)
if (NOT ANDROID)
add_subdirectory(mysql) add_subdirectory(mysql)
add_subdirectory(odbc) add_subdirectory(odbc)
add_subdirectory(postgres) add_subdirectory(postgres)
endif()
set(CXX_SWIG_OUTDIR ${CMAKE_BINARY_DIR}/packages/swig/android)
add_component(myddas add_component(myddas
${MYDDAS_SOURCES} ${MYDDAS_SOURCES}

View File

@ -1,3 +1,5 @@
#ifndef __MYDDAS_H__ #ifndef __MYDDAS_H__
#define __MYDDAS_H__ #define __MYDDAS_H__

View File

@ -1,7 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sqlite3.h>
#include "Yap.h" #include "Yap.h"
#include "myddas.h" #include "myddas.h"
#ifdef MYDDAS_STATS #ifdef MYDDAS_STATS

View File

@ -20,7 +20,7 @@
#include <stdlib.h> #include <stdlib.h>
#ifdef USE_MYDDAS #ifdef MYDDAS
#include "myddas.h" #include "myddas.h"
@ -689,9 +689,9 @@ void init_myddas(void) {
{ {
return; return;
} }
#if USE_MYDDAS #if MYDDAS
Term cm=CurrentModule; Yap_InitMYDDAS_SharedPreds();
CurrentModule = USER_MODULE; Yap_InitBackMYDDAS_SharedPreds();
#define stringify(X) _stringify(X) #define stringify(X) _stringify(X)
#define _stringify(X) #X #define _stringify(X) #X
Yap_REGS.MYDDAS_GLOBAL_POINTER = NULL; Yap_REGS.MYDDAS_GLOBAL_POINTER = NULL;
@ -699,26 +699,15 @@ void init_myddas(void) {
MkAtomTerm(Yap_LookupAtom(stringify(MYDDAS_VERSION)))); MkAtomTerm(Yap_LookupAtom(stringify(MYDDAS_VERSION))));
Yap_HaltRegisterHook((HaltHookFunc)Yap_MYDDAS_delete_all_myddas_structs, Yap_HaltRegisterHook((HaltHookFunc)Yap_MYDDAS_delete_all_myddas_structs,
NULL); NULL);
Yap_InitMYDDAS_SharedPreds();
Yap_InitBackMYDDAS_SharedPreds();
#undef stringify #undef stringify
#undef _stringify #undef _stringify
Yap_MYDDAS_delete_all_myddas_structs(); Yap_MYDDAS_delete_all_myddas_structs();
#if defined MYDDAS_ODBC
Yap_InitBackMYDDAS_ODBCPreds();
Yap_InitMYDDAS_ODBCPreds();
#endif
#if defined MYDDAS_TOP_LEVEL && \ #if defined MYDDAS_TOP_LEVEL && \
defined MYDDAS_MYSQL // && defined HAVE_LIBREADLINE defined MYDDAS_MYSQL // && defined HAVE_LIBREADLINE
Yap_InitMYDDAS_TopLevelPreds(); Yap_InitMYDDAS_TopLevelPreds();
#endif
c_db_initialize_myddas(PASS_REGS1);
#ifdef __ANDROID__
init_sqlite3();
#endif #endif
#endif #endif
myddas_initialised = true; myddas_initialised = true;
CurrentModule = cm;
} }
#ifdef _WIN32 #ifdef _WIN32

View File

@ -24,7 +24,7 @@ if (WITH_MYSQL)
if (WIN32) if (WIN32)
add_library(YAPmysql OBJECT ${MYSQL_SOURCES}) add_library(YAPmysql OBJECT ${MYSQL_SOURCES})
else() else()
add_lib(YAPmysql ${MYSQL_SOURCES}) add_library(YAPmysql ${MYSQL_SOURCES})
target_link_libraries(YAPmysql ${MYSQL_LIBRARIES} libYap) target_link_libraries(YAPmysql ${MYSQL_LIBRARIES} libYap)
install(TARGETS YAPmysql install(TARGETS YAPmysql
RUNTIME DESTINATION ${YAP_INSTALL_LIBDIR} RUNTIME DESTINATION ${YAP_INSTALL_LIBDIR}
@ -32,7 +32,7 @@ if (WITH_MYSQL)
LIBRARY DESTINATION ${YAP_INSTALL_LIBDIR} LIBRARY DESTINATION ${YAP_INSTALL_LIBDIR}
) )
endif() endif()
include_directories(${MYSQL_INCLUDE_DIR} ..) include_directories(${MYSQL_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..)
set_target_properties(YAPmysql PROPERTIES set_target_properties(YAPmysql PROPERTIES
POSITION_INDEPENDENT_CODE ON POSITION_INDEPENDENT_CODE ON
PREFIX "" PREFIX ""

View File

@ -14,21 +14,17 @@ if (WITH_ODBC)
# ODBC_INCLUDE_DIRECTORIES, where to find sql.h # ODBC_INCLUDE_DIRECTORIES, where to find sql.h
# ODBC_LIBRARIES, the libraries to link against to use ODBC # ODBC_LIBRARIES, the libraries to link against to use ODBC
# ODBC_FOUND. If false, you cannot build anything that requires Odbc. # ODBC_FOUND. If false, you cannot build anything that requires Odbc.
add_lib(YAPodbc ${YAPODBC_SOURCES}) add_library(YAPodbc ${YAPODBC_SOURCES})
target_link_libraries(YAPodbc libYap ${ODBC_LIBRARIES}) target_link_libraries(YAPodbc libYap ${ODBC_LIBRARIES})
include_directories (${ODBC_INCLUDE_DIRECTORIES} ..) set_property(DIRECTORY
APPEND PROPERTY
INCLUDE_DIRECTORIES ${ODBC_INCLUDE_DIRECTORIES} ${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR} )
set_target_properties (YAPodbc PROPERTIES set_target_properties (YAPodbc PROPERTIES
POSITION_INDEPENDENT_CODE ON POSITION_INDEPENDENT_CODE ON
PREFIX "" PREFIX ""
) )
list (APPEND MYDDAS_FLAGS -DMYDDAS_ODBC=1)
set (MYDDAS_FLAGS ${MYDDAS_FLAGS} ON PARENT_SCOPE)
set_property(GLOBAL APPEND PROPERTY COMPILE_DEFINITIONS
-DMYDDAS_ODBC=1)
install(TARGETS YAPodbc install(TARGETS YAPodbc
LIBRARY DESTINATION ${YAP_INSTALL_LIBDIR} LIBRARY DESTINATION ${YAP_INSTALL_LIBDIR}
RUNTIME DESTINATION ${YAP_INSTALL_LIBDIR} RUNTIME DESTINATION ${YAP_INSTALL_LIBDIR}

View File

@ -15,7 +15,7 @@
* * * *
*************************************************************************/ *************************************************************************/
#if defined MYDDAS_ODBC #if MYDDAS_ODBC
#if !defined(ODBCVER) #if !defined(ODBCVER)
typedef void *SQLHDBC; typedef void *SQLHDBC;

View File

@ -23,6 +23,7 @@ foreach (filename ${MYDDAS_YPP})
get_filename_component(base ${filename} NAME_WE) get_filename_component(base ${filename} NAME_WE)
set(base_abs ${MYDDAS_PL_OUTDIR}/${base}) set(base_abs ${MYDDAS_PL_OUTDIR}/${base})
set(outfile ${base_abs}.yap) set(outfile ${base_abs}.yap)
list(APPEND MYDDAS_YAP_FILES ${outfile})
execute_process( execute_process(
COMMAND ${CMAKE_C_COMPILER} ${MYDDAS_FLAGS} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/${filename} -o ${outfile} COMMAND ${CMAKE_C_COMPILER} ${MYDDAS_FLAGS} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/${filename} -o ${outfile}
) )
@ -30,6 +31,7 @@ foreach (filename ${MYDDAS_YPP})
endforeach () endforeach ()
foreach (dbms ${MYDDAS_DBMS} ) foreach (dbms ${MYDDAS_DBMS} )
set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap) set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap)
list(APPEND MYDDAS_YAP_FILES ${outfile})
execute_process( execute_process(
COMMAND ${CMAKE_C_COMPILER} -D${dbms} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/myddas_driver.ypp -o ${outfile} COMMAND ${CMAKE_C_COMPILER} -D${dbms} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/myddas_driver.ypp -o ${outfile}
) )
@ -37,8 +39,6 @@ foreach (dbms ${MYDDAS_DBMS} )
set_source_files_properties(outfile PROPERTIES GENERATED TRUE) set_source_files_properties(outfile PROPERTIES GENERATED TRUE)
endforeach() endforeach()
list(APPEND MYDDAS_YAP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/sqlitest.yap ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/chinook.db)
set( MYDDAS_YAP ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/sqlitest.yap ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/chinook.db) install(FILES ${MYDDAS_YAP_FILES} DESTINATION ${YAP_INSTALL_DATADIR})
add_to_group(MYDDAS_YAP pl_library )
file(INSTALL ${MYDDAS_YAP}
DESTINATION ${MYDDAS_PL_OUTDIR} )

View File

@ -15,11 +15,6 @@
* * * *
*************************************************************************/ *************************************************************************/
%%:- load_foreign_files([myddas], [], init_myddas).
/* Initialize MYDDAS GLOBAL STRUCTURES */
:- c_db_initialize_myddas.
#ifdef DEBUG #ifdef DEBUG
:- yap_flag(single_var_warnings,on). :- yap_flag(single_var_warnings,on).
:- yap_flag(write_strings,on). :- yap_flag(write_strings,on).
@ -114,6 +109,12 @@
% myddas_mysql.ypp % myddas_mysql.ypp
]). ]).
:- load_foreign_files([myddas], [], init_myddas).
/* Initialize MYDDAS GLOBAL STRUCTURES */
:- c_db_initialize_myddas.
#ifdef MYDDAS_TOP_LEVEL #ifdef MYDDAS_TOP_LEVEL
:- use_module(myddas_top_level,[ :- use_module(myddas_top_level,[
db_top_level/4, db_top_level/4,

View File

@ -76,9 +76,7 @@
'$make_a_list'/2, '$make_a_list'/2,
'$write_or_not'/1 '$write_or_not'/1
]). ]).
#ifndef __ANDROID__
:- load_foreign_files( [NAME()], [], INIT()). :- load_foreign_files( [NAME()], [], INIT()).
#endif
%-------------------------------------------------------- %--------------------------------------------------------
% Public Predicates % Public Predicates

View File

@ -16,9 +16,12 @@ if (WITH_POSTGRES)
# PostgreSQL_INCLUDE_DIRS - Include directories for PostgreSQL # PostgreSQL_INCLUDE_DIRS - Include directories for PostgreSQL
# PostgreSQL_LIBRARY_DIRS - Link directories for PostgreSQL libraries # PostgreSQL_LIBRARY_DIRS - Link directories for PostgreSQL libraries
# PostgreSQL_LIBRARIES - The PostgreSQL libraries. # PostgreSQL_LIBRARIES - The PostgreSQL libraries.
add_lib(YAPpostgres ${YAPPOSTGRES_SOURCES}) add_library(YAPpostgres ${YAPPOSTGRES_SOURCES})
target_link_libraries(YAPpostgres libYap ${PostgreSQL_LIBRARIES}) target_link_libraries(YAPpostgres libYap ${PostgreSQL_LIBRARIES})
include_directories (${PostgreSQL_INCLUDE_DIRS} ..) set_property(DIRECTORY
APPEND PROPERTY
INCLUDE_DIRECTORIES ${PostgreSQL_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/.. )
set_target_properties (YAPpostgres PROPERTIES set_target_properties (YAPpostgres PROPERTIES
POSITION_INDEPENDENT_CODE ON POSITION_INDEPENDENT_CODE ON
PREFIX "" PREFIX ""

View File

@ -1,7 +1,6 @@
if (WITH_SQLITE3) if (WITH_SQLITE3)
message( " * Sqlite3 Data-Base (http://www.sqlite3.org), distributed with MYDDAS" )
set (SQLITE_TEST set (SQLITE_TEST
sqlitest.yap) sqlitest.yap)
@ -9,21 +8,23 @@ if (WITH_SQLITE3)
set( YAPSQLITE3_SOURCES set( YAPSQLITE3_SOURCES
myddas_sqlite3.c myddas_sqlite3.c
src/sqlite3.h
src/sqlite3ext.h
) )
message( " * Sqlite3 Data-Base (http://www.sqlite3.org), distributed with MYDDAS" )
add_to_dir(SQLITE_DB ${YAP_INSTALL_DATADIR})
add_to_dir( SQLITE_TEST ${YAP_INSTALL_DATADIR})
#sqlite3 is now in the system #sqlite3 is now in the system
set (SQLITE3_FOUND ON CACHE PRIVATE "") set (SQLITE3_FOUND ON CACHE PRIVATE "")
include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..) set_property(DIRECTORY
APPEND PROPERTY
INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/src )
if (ANDROID)
add_definitions(-DSQLITE_FCNTL_MMAP_SIZE=0 )
endif()
add_definitions(-DSQLITE_ENABLE_COLUMN_METADATA=1 ) add_definitions(-DSQLITE_ENABLE_COLUMN_METADATA=1 )
@ -36,15 +37,17 @@ if (WITH_SQLITE3)
SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 ) SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 )
message("ql ${EMBEDDED_SQLITE3}")
message( " * Sqlite3 Data-Base (http://www.sqlite3.org), distributed with MYDDAS" )
if ( ANDROID ) if ( ANDROID )
add_definitions(-DSQLITE_FCNTL_MMAP_SIZE=0 )
add_library( YAPsqlite3 OBJECT add_library( YAPsqlite3 OBJECT
${YAPSQLITE3_SOURCES} ) ${YAPSQLITE3_SOURCES} )
else() else()
list(APPEND YAPSQLITE3_SOURCES src/sqlite3.c)
list(APPEND YAPSQLITE3_SOURCES src/sqlite3.c)
add_library( YAPsqlite3 SHARED add_library( YAPsqlite3 SHARED
${YAPSQLITE3_SOURCES}) ${YAPSQLITE3_SOURCES})
@ -67,11 +70,11 @@ if (WITH_SQLITE3)
endif() endif()
install(FILES ${SQLITE_DB} install(FILES ${SQLITE_DB}
DESTINATION ${YAP_PLDIR}/data DESTINATION ${YAP_INSTALL_DATADIR}/data
) )
install(FILES ${SQLITE_TEST} install(FILES ${SQLITE_TEST}
DESTINATION ${YAP_PLDIR}/test DESTINATION ${YAP_INSTALL_DATADIR}/test
) )
endif() endif()

View File

@ -673,7 +673,6 @@ static void Yap_InitBackMYDDAS_SQLITE3Preds(void) {
X_API void init_sqlite3(void) { X_API void init_sqlite3(void) {
Term cm = CurrentModule; Term cm = CurrentModule;
CurrentModule = MkAtomTerm(Yap_LookupAtom("user"));
Yap_InitMYDDAS_SQLITE3Preds(); Yap_InitMYDDAS_SQLITE3Preds();

View File

@ -9,7 +9,7 @@ include_directories( BEFORE ${PYTHON_INCLUDE_DIRS} ${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/os ${CMAKE_SOURCE_DIR}/H ${CMAKE_SOURCE_DIR}/OPTYap ) ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/os ${CMAKE_SOURCE_DIR}/H ${CMAKE_SOURCE_DIR}/OPTYap )
#talk to python.pl #talk to python.pl
add_lib(YAPPython pyload.c ${PYTHON_HEADERS} ) add_library(YAPPython pyload.c ${PYTHON_HEADERS} )
if (WIN32) if (WIN32)
@ -48,8 +48,6 @@ set (PYTHON_PL python.pl)
install(FILES python.pl DESTINATION ${YAP_INSTALL_DATADIR} ) install(FILES python.pl DESTINATION ${YAP_INSTALL_DATADIR} )
add_to_group( PYTHON_PL pl_library )
set_target_properties (YAPPython PROPERTIES PREFIX "") set_target_properties (YAPPython PROPERTIES PREFIX "")
install(TARGETS YAPPython install(TARGETS YAPPython

View File

@ -80,8 +80,6 @@ endif()
install(FILES ${YAP4PY_PL} DESTINATION ${YAP_INSTALL_DATADIR} ) install(FILES ${YAP4PY_PL} DESTINATION ${YAP_INSTALL_DATADIR} )
add_to_group( YAP4PY_PL pl_library )
if (WITH_DOCS AND DOXYGEN_FOUND) if (WITH_DOCS AND DOXYGEN_FOUND)
set(CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND}) set(CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})

View File

@ -98,7 +98,7 @@ def live():
args = yap.YAPEngineArgs() args = yap.YAPEngineArgs()
args.setYapShareDir(os.path.join(yap_lib_path,"prolog")) args.setYapShareDir(os.path.join(yap_lib_path,"prolog"))
args.setYapLibDir(yap_lib_path) args.setYapLibDir(yap_lib_path)
#args.setYapPrologBootFile(os.path.join(yap_lib_path."startup.yss")) #args.setYapPrologSOURCEBOOT(os.path.join(yap_lib_path."startup.yss"))
engine = yap.YAPEngine(args) engine = yap.YAPEngine(args)
engine.goal( use_module(library('yapi') ) ) engine.goal( use_module(library('yapi') ) )
loop = True loop = True

View File

@ -39,7 +39,7 @@ if (WIN32)
set( CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LIBXML2_LIBRARIES} ) set( CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LIBXML2_LIBRARIES} )
else (WIN32) else (WIN32)
ADD_LIB(libxml2 ${LIBXML2_SOURCES} ) add_library(libxml2 ${LIBXML2_SOURCES} )
if(DEFINED YAP_MAJOR_VERSION) if(DEFINED YAP_MAJOR_VERSION)
TARGET_LINK_LIBRARIES(libxml2 TARGET_LINK_LIBRARIES(libxml2
@ -88,7 +88,7 @@ IF (RAPTOR_FOUND)
raptor_yap.c raptor_yap.c
) )
ADD_LIB(raptor ${RAPTOR_SOURCES} ) add_library(raptor ${RAPTOR_SOURCES} )
if(DEFINED YAP_MAJOR_VERSION) if(DEFINED YAP_MAJOR_VERSION)
TARGET_LINK_LIBRARIES(raptor TARGET_LINK_LIBRARIES(raptor

View File

@ -16,7 +16,7 @@ set_package_properties(R PROPERTIES
DESCRIPTION "The R Project for Statistical Computing." DESCRIPTION "The R Project for Statistical Computing."
URL "https://www.r-project.org/") URL "https://www.r-project.org/")
add_lib(real ${REAL_SOURCES}) add_library(real ${REAL_SOURCES})
target_link_libraries (real ${LIBR_LIBRARIES} libYap) target_link_libraries (real ${LIBR_LIBRARIES} libYap)
include_directories ( include_directories (
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}

View File

@ -24,7 +24,7 @@ pl-minisat.C
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
) )
ADD_LIB(minisat2 ${MINISAT2_SOURCES} ${MINISAT2_HEADERS} ) add_library(minisat2 ${MINISAT2_SOURCES} ${MINISAT2_HEADERS} )
set_target_properties (minisat2 PROPERTIES OUTPUT_NAME pl-minisat) set_target_properties (minisat2 PROPERTIES OUTPUT_NAME pl-minisat)
set_target_properties (minisat2 PROPERTIES PREFIX "") set_target_properties (minisat2 PROPERTIES PREFIX "")

View File

@ -10,8 +10,6 @@
set (SOURCES yap.i) set (SOURCES yap.i)
INCLUDE(${SWIG_USE_FILE})
if (ANDROID) if (ANDROID)
add_subdirectory(android) add_subdirectory(android)
else(ANDROID) else(ANDROID)

View File

@ -1,68 +1,42 @@
# This is a CMake file for SWIG and Android # This is a CMake file for SWIG and Android
set(JAVA_SWIG_OUTDIR ${CMAKE_SOURCE_DIR}/../yaplib/src/generated/java/pt/up/yap/lib) set(GENERATED_SOURCE_DIR ${CMAKE_SOURCE_DIR}/../yaplib/src/generated)
set(SWIG_CXX_DIR ${CMAKE_BINARY_DIR}/src/generated/jni)
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/generated/java/pt/up/yap/lib) set(JAVA_SWIG_OUTDIR ${GENERATED_SOURCE_DIR}/java/pt/up/yap/lib)
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/generated/assets/Yap/pl)
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/generated/assets/so)
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/generated/jni)
set(YAP_ASSETS ${CMAKE_SOURCE_DIR}/../yaplib/src/generated/assets/Yap)
set(SWIG_SOURCES ${CMAKE_SOURCE_DIR}/packages/swig/yap.i) set(SWIG_SOURCES ${CMAKE_SOURCE_DIR}/packages/swig/yap.i)
SET_SOURCE_FILES_PROPERTIES(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON) SET_SOURCE_FILES_PROPERTIES(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON)
FILE( MAKE_DIRECTORY ${GENERATED_SOURCE_DIR}/assets/Yap/pl)
FILE( MAKE_DIRECTORY ${GENERATED_SOURCE_DIR}/assets/os)
include_directories( include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/CXX ${CMAKE_SOURCE_DIR}/CXX
) ${CMAKE_SOURCE_DIR}/include
set(GMP_ROOT ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI}) ${CMAKE_BINARY_DIR}
set(GMP_INCLUDE_DIRS ${GMP_ROOT}) ${CMAKE_SOURCE_DIR}/H
set(GMP_LIBRARIES ${GMP_ROOT}/libgmp.so) ${CMAKE_SOURCE_DIR}/os
${CMAKE_SOURCE_DIR}/OPTYap
file(INSTALL ${pl_library} DESTINATION ${YAP_ASSETS})
file(INSTALL ${CMAKE_CURRENT_SOURCE_DIR}/android.yap DESTINATION ${YAP_ASSETS})
file(INSTALL ${pl_boot_library} DESTINATION ${YAP_ASSETS}/pl)
file(INSTALL ${pl_os_library} DESTINATION ${YAP_ASSETS}/os)
execute_process(COMMAND swig -c++ -java -package pt.up.yap.lib -O -outdir ${JAVA_SWIG_OUTDIR} -addextern -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/include -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/os -I${CMAKE_SOURCE_DIR}/OPTYap -I${CMAKE_BINARY_DIR} -I${GMP_INCLUDE_DIRS} -DX_API -o ${SWIG_CXX_DIR}/yapi_swig.cxx ${SWIG_SOURCES}
) )
execute_process(COMMAND ${SWIG_EXECUTABLE} -c++ -java -package pt.up.yap.lib -O -outdir ${JAVA_SWIG_OUTDIR} -addextern -I${CMAKE_CURRENT_SOURCE_DIR} -o ${SWIG_CXX_DIR}/streamer_swig.cxx streamer.i add_custom_command( OUTPUT yapi_swig.cxx yapi_swig.hh
COMMAND swig -c++ -java -package pt.up.yap.lib -O -outdir ${JAVA_SWIG_OUTDIR}
-addextern -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/include
-I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/os -I${CMAKE_SOURCE_DIR}/OPTYap
-I${CMAKE_BINARY_DIR}
-I${GMP_INCLUDE_DIRS} -DX_API -o yapi_swig.cxx ${SWIG_SOURCES}
DEPENDS ${CMAKE_SOURCE_DIR}/CXX/yapi.hh ${SWIG_SOURCES}
) )
add_custom_command( OUTPUT streamer_swig.cxx streamer_swig.hh
add_library(YAPJava OBJECT COMMAND swig -c++ -java -package pt.up.yap.lib -O -outdir ${JAVA_SWIG_OUTDIR} -addextern -I${CMAKE_CURRENT_SOURCE_DIR} -o streamer_swig.cxx streamer.i
${CMAKE_BINARY_DIR}/src/generated/jni/streamer_swig.cxx DEPENDS ${CMAKE_SOURCE_DIR}/CXX/yapi.hh ${CMAKE_CURRENT_SOURCE_DIR}/streamer.i
${CMAKE_BINARY_DIR}/src/generated/jni/yapi_swig.cxx
streamer.cpp
) )
set_target_properties(YAPJava PROPERTIES LINKER_LANGUAGE CXX) add_library(DROID OBJECT
yapi_swig.cxx streamer_swig.cxx streamer.cpp
# GMP_FOUND - true if GMP/MPIR was found
# GMP_INCLUDE_DIRS - include search path
# GMP_LIBRARIES - libraries to link with
#config.h needs this (TODO: change in code latter)
include_directories(.;${GMP_INCLUDE_DIRS};${CMAKE_SOURCE_DIR}/include;${CMAKE_SOURCE_DIR}/H;${CMAKE_SOURCE_DIR}/H/generated;${CMAKE_SOURCE_DIR}/os;${CMAKE_SOURCE_DIR}/OPTYap;${CMAKE_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR})
if (FALSE)
set(SWIG_ADD_MODULE YAPJava SHARED CPLUSPLUS ${SWIG_SOURCES})
# Define swig module with given name and specified language
set(SWIG_LINK_LIBRARIES YAPJava YAP++ libYAP)
#- Link libraries to swig module
add_library(YAPJavaTop SHARED
main.cpp main.h
) )
target_link_libraries(YAPJavaTop ${SWIG_MODULE_${YAPJava}_REAL_NAME} YAP++ libYap android)
endif ()

View File

@ -59,14 +59,38 @@ and_close(int sno) {
static int static int
and_put(int sno, int ch) { and_put(int sno, int ch) {
buff0 += ch; buff0 += ch;
if (ch == '\n') {
streamerInstance->display(buff0); streamerInstance->display(buff0);
buff0.clear(); buff0.clear();
}
return ch;
}
static int
and_wput(int sno, int ch) {
unsigned char b0[8];
size_t extra = put_utf8(b0, ch);
if (extra < 0)
PlIOError(DOMAIN_ERROR_ENCODING, MkIntegerTerm(ch), "ch %C found at putw", ch);
else if(extra==0)
return false;
for (int i=0; i < extra; i++) {
buff0 += b0[i];
}
if (ch == '\n') {
streamerInstance->display(buff0);
buff0.clear();
}
return ch; return ch;
} }
static int static int
and_get(int sno) { and_get(int sno) {
PlIOError(PERMISSION_ERROR_OUTPUT_STREAM, MkIntTerm(sno), "streamer is just for writing");
return EOF; return EOF;
} }
@ -86,14 +110,16 @@ extern "C" {
void Java_pt_up_yap_streamerJNI_swig_1module_1init(void) { void Java_pt_up_yap_streamerJNI_swig_1module_1init(void) {
andstream = new VFS_t(); andstream = new VFS_t();
andstream->name = "/android/user_error"; andstream->name = "/android/user";
andstream->vflags = VFS_CAN_WRITE | VFS_HAS_PREFIX; andstream->vflags = VFS_CAN_WRITE | VFS_HAS_PREFIX;
andstream->prefix = "/android"; andstream->prefix = "/android";
andstream->suffix = NULL; andstream->suffix = NULL;
andstream->open = and_open; andstream->open = and_open;
andstream->close = and_close; andstream->close = and_close;
andstream->get_char = and_get; andstream->get_char = and_get;
andstream->get_wchar = and_get;
andstream->put_char = and_put; andstream->put_char = and_put;
andstream->put_wchar = and_wput;
andstream->flush = and_flush; andstream->flush = and_flush;
andstream->seek = and_seek; andstream->seek = and_seek;
andstream->next = GLOBAL_VFS; andstream->next = GLOBAL_VFS;

View File

@ -139,15 +139,6 @@ class YAPEngine;
#else #else
%typemap(in) arity_t { (jlong)($input); }
%typemap(in) jlong %{
$1 = (jlong)$input;
%}
%typemap(out) arity_t { *(jlong *)&$result = $1; }
// Language independent exception handler // Language independent exception handler
// simplified version // simplified version

View File

@ -11,7 +11,7 @@ SET ( SOURCES
b+tree_udi.c b+tree_udi.c
) )
ADD_LIB(udi_b+tree ${SOURCES}) add_library(udi_b+tree ${SOURCES})
INSTALL(TARGETS udi_b+tree DESTINATION ${YAP_PL_LIBRARY_DIR}) INSTALL(TARGETS udi_b+tree DESTINATION ${YAP_PL_LIBRARY_DIR})
INSTALL(FILES b+tree.yap DESTINATION ${YAP_PL_LIBRARY_DIR}) INSTALL(FILES b+tree.yap DESTINATION ${YAP_PL_LIBRARY_DIR})

View File

@ -11,7 +11,7 @@ SET ( SOURCES
rtree_udi.c rtree_udi.c
) )
ADD_LIB(udi_rtree ${SOURCES}) add_library(udi_rtree ${SOURCES})
INSTALL(TARGETS udi_rtree DESTINATION ${YAP_PL_LIBRARY_DIR}) INSTALL(TARGETS udi_rtree DESTINATION ${YAP_PL_LIBRARY_DIR})
INSTALL(FILES rtree.yap DESTINATION ${YAP_PL_LIBRARY_DIR}) INSTALL(FILES rtree.yap DESTINATION ${YAP_PL_LIBRARY_DIR})

View File

@ -10,7 +10,7 @@ SET ( SOURCES
uthash_udi.c uthash_udi.c
) )
ADD_LIB(udi_uthash ${SOURCES}) add_library(udi_uthash ${SOURCES})
INSTALL(TARGETS udi_uthash DESTINATION ${YAP_PL_LIBRARY_DIR}) INSTALL(TARGETS udi_uthash DESTINATION ${YAP_PL_LIBRARY_DIR})
INSTALL(FILES uthash.yap DESTINATION ${YAP_PL_LIBRARY_DIR}) INSTALL(FILES uthash.yap DESTINATION ${YAP_PL_LIBRARY_DIR})

View File

@ -1,11 +1,13 @@
set(PL_BOOT_SOURCES set(PL_BOOT_SOURCES
absf.yap absf.yap
android.yap
arith.yap arith.yap
arithpreds.yap arithpreds.yap
arrays.yap arrays.yap
atoms.yap atoms.yap
attributes.yap attributes.yap
boot.yap boot.yap
boot2.yap
bootlists.yap bootlists.yap
bootutils.yap bootutils.yap
builtins.yap builtins.yap
@ -62,13 +64,12 @@ set(PL_BOOT_SOURCES
ypp.yap ypp.yap
) )
add_to_group(PL_BOOT_SOURCES pl_boot_library) add_to_dir(PL_BOOT_SOURCES ${YAP_INSTALL_DATADIR}/pl)
if (ANDROID) if (ANDROID)
add_custom_target(STARTUP add_custom_target(STARTUP
DEPENDS ${PL_BOOT_SOURCES} DEPENDS ${PL_BOOT_SOURCES}
) )
file (INSTALL ${PL_BOOT_SOURCES} DESTINATION ${YAP_INSTALL_DATADIR}/pl)
elseif(CMAKE_CROSSCOMPILING) elseif(CMAKE_CROSSCOMPILING)
add_custom_target(STARTUP ALL SOURCES add_custom_target(STARTUP ALL SOURCES
DEPENDS ${PL_BOOT_SOURCES} DEPENDS ${PL_BOOT_SOURCES}
@ -78,7 +79,7 @@ else ()
DEPENDS ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP} DEPENDS ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP}
) )
add_custom_command(OUTPUT ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP} add_custom_command(OUTPUT ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP}
COMMAND yap-bin -B COMMAND yap-bin -b
VERBATIM VERBATIM
DEPENDS ${PL_BOOT_SOURCES} yap-bin DEPENDS ${PL_BOOT_SOURCES} yap-bin
) )
@ -89,8 +90,8 @@ else ()
install(FILES ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP} install(FILES ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP}
DESTINATION ${YAP_INSTALL_LIBDIR} DESTINATION ${YAP_INSTALL_DATADIR}/pl)
)
endif() endif()

View File

@ -1,4 +1,4 @@
/************************************************************************* qqqqq/*************************************************************************
* * * *
* YAP Prolog * * YAP Prolog *
* * * *

22
pl/android.yap Normal file
View File

@ -0,0 +1,22 @@
%:- start_low_level_trace.
%:- module(android,
% [text_to_query/2]).
:- initialization(yap_flag(verbose,_,normal)).
:- meta_predicate( text_to_query( :, - ) ).
text_to_query( MString, Status ) :-
strip_module( MString, Mod, String ),
atomic_to_term( String, Goal, VarNames ),
(
is_list(Goal) -> G = ensure_loaded( Goal ) ; G = Goal ),
catch(query_to_answer( Mod:G, VarNames, Status, Bindings),
H,error_handler(H,error)
),
write_query_answer( Bindings ),
nl(user_error).
%:- [sqlitest].

View File

@ -1,3 +1,4 @@
/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog * * YAP Prolog *
@ -118,19 +119,21 @@ do_not_compile_expressions :- set_value('$c_arith',[]).
'$c_built_in'(IN, M, H, OUT) :- '$c_built_in'(IN, M, H, OUT) :-
get_value('$c_arith',true), !, get_value('$c_arith',true), !,
do_c_built_in(IN, M, H, OUT). '$yap_strip_module'(M:IN, M1, G1),
do_c_built_in(G1, M1, H, OUT).
'$c_built_in'(IN, _, _H, IN). '$c_built_in'(IN, _, _H, IN).
do_c_built_in(G, M, H, OUT) :- var(G), !, do_c_built_in(G1, M1, H, OUT) :-
do_c_built_metacall(G, M, H, OUT).
do_c_built_in(Mod:G, _, H, OUT) :-
'$yap_strip_module'(Mod:G, M1, G1),
var(G1), !, var(G1), !,
do_c_built_metacall(G1, M1, H, OUT). do_c_built_metacall(G1, M1, H, OUT).
do_c_built_in(G1, M1, H, OUT) :-
var(M1), !,
do_c_built_metacall(G1, M1, H, OUT).
do_c_built_in('$do_error'( Error, Goal), M, Head, do_c_built_in('$do_error'( Error, Goal), M, Head,
throw(error(Error,M:(Head :- Goal))) throw(error(Error,M:(Head :- Goal)))
) :- !. ) :-
!.
do_c_built_in(system_error( Error, Goal), M, Head, ErrorG) :- do_c_built_in(system_error( Error, Goal), M, Head, ErrorG) :-
!, !,
do_c_built_in('$do_error'( Error, Goal), M, Head, ErrorG). do_c_built_in('$do_error'( Error, Goal), M, Head, ErrorG).
@ -155,7 +158,6 @@ do_c_built_in(phrase(NT,Xs), Mod, H, NTXsNil) :-
do_c_built_in(phrase(NT,Xs0,Xs), Mod, _, NewGoal) :- do_c_built_in(phrase(NT,Xs0,Xs), Mod, _, NewGoal) :-
!, !,
'$c_built_in_phrase'(NT, Xs0, Xs, Mod, NewGoal ). '$c_built_in_phrase'(NT, Xs0, Xs, Mod, NewGoal ).
do_c_built_in(Comp0, _, _, R) :- % now, do it for comparisons do_c_built_in(Comp0, _, _, R) :- % now, do it for comparisons
'$compop'(Comp0, Op, E, F), '$compop'(Comp0, Op, E, F),
!, !,
@ -240,7 +242,9 @@ expand_expr(T, E, V) :-
% and giving as result P (the last argument) % and giving as result P (the last argument)
expand_expr(Op, X, O, Q, Q) :- expand_expr(Op, X, O, Q, Q) :-
number(X), number(X),
catch(is( O, Op, X),_,fail), !. % do not do error handling at compile time !,
catch(is( O, Op, X),Error,bad_expr(Error,[Op, X])), !.
% do not do error handling at compile time
expand_expr(Op, X, O, Q, P) :- expand_expr(Op, X, O, Q, P) :-
'$unary_op_as_integer'(Op,IOp), '$unary_op_as_integer'(Op,IOp),
'$do_and'(Q, is( O, IOp, X), P). '$do_and'(Q, is( O, IOp, X), P).
@ -254,7 +258,7 @@ expand_expr(Op, X, O, Q, P) :-
% the elementar arithmetic operations [+,-,*,//] % the elementar arithmetic operations [+,-,*,//]
expand_expr(Op, X, Y, O, Q, Q) :- expand_expr(Op, X, Y, O, Q, Q) :-
number(X), number(Y), number(X), number(Y),
catch(is( O, Op, X, Y),_,fail), !. catch(is( O, Op, X, Y),Error,bad_expr(Error,[Op, X, Y ])), !.
expand_expr(+, X, Y, O, Q, P) :- !, expand_expr(+, X, Y, O, Q, P) :- !,
'$preprocess_args_for_commutative'(X, Y, X1, Y1, E), '$preprocess_args_for_commutative'(X, Y, X1, Y1, E),
'$do_and'(E, '$plus'(X1,Y1,O), F), '$do_and'(E, '$plus'(X1,Y1,O), F),

View File

@ -111,18 +111,25 @@ private(_).
% be careful here not to generate an undefined exception.. % be careful here not to generate an undefined exception..
print_message(L,E) :- print_message(L,E) :-
%stop_low_level_trace,
'$number_of_clauses'(print_message(L,E), prolog_complete, 1), '$number_of_clauses'(print_message(L,E), prolog_complete, 1),
!, !,
(L = informational (L = informational
-> ->
true true
; ;
format( user_error, '~w in bootstrap: got ~w~n',[L,E]) error(_,Info),
'$error_descriptor'(Info, Desc),
query_exception(prologPredFile, Desc, File),
query_exception(prologPredLine, Desc, FilePos),
format(user_error,'~a:~d: error:', [File,FilePos]),
'$print_exception'(Info),
format( user_error, '~w from bootstrap: got ~w~n',[L,E])
). ).
'$undefp0'([M|G], _Action) :- '$undefp0'([M|G], _Action) :-
stream_property( loop_stream, [file_name(F), line_number(L)]), stream_property( loop_stream, [file_name(F), line_number(L)]),
format(user_error,'~a:~d error undefined:',[F,L]), format(user_error,'~a:~d: error: undefined ~w~n:',[F,L,M:G]),
fail fail
; ;
format(user_error,' call to ~w~n',[M:G]), format(user_error,' call to ~w~n',[M:G]),
@ -145,8 +152,12 @@ print_message(L,E) :-
'$compile'(G, assertz, G, prolog, _R), '$compile'(G, assertz, G, prolog, _R),
'$system_meta_predicates'(L). '$system_meta_predicates'(L).
:- '$mk_dynamic'( prolog_file_type(_Ext, _NType), user).
:- '$new_multifile'( prolog_file_type(_Ext, _NType), user).
:- '$mk_dynamic'( '$meta_predicate'(_N,_M,_A,_P), prolog). :- '$mk_dynamic'( '$meta_predicate'(_N,_M,_A,_P), prolog).
:- '$new_multifile'( '$meta_predicate'(_N,_M,_A,_P), prolog). :- '$new_multifile'( '$meta_predicate'(_N,_M,_A,_P), prolog).
:- '$new_multifile'('$full_clause_optimisation'(_H, _M, _B0, _BF), prolog). :- '$new_multifile'('$full_clause_optimisation'(_H, _M, _B0, _BF), prolog).
:- '$new_multifile'('$exec_directive'(_,_,_,_,_), prolog). :- '$new_multifile'('$exec_directive'(_,_,_,_,_), prolog).
@ -305,181 +316,8 @@ initialize_prolog :-
'yapor.yap', 'yapor.yap',
'qly.yap', 'qly.yap',
'spy.yap', 'spy.yap',
'udi.yap']. 'udi.yap',
'boot2.yap'].
%:- start_low_level_trace.
:- meta_predicate(log_event(+,:)).
:- dynamic prolog:'$user_defined_flag'/4.
:- multifile prolog:debug_action_hook/1.
:- multifile prolog:'$system_predicate'/2.
:- '$opdec'(1150,fx,(mode),prolog).
:- dynamic 'extensions_to_present_answer'/1.
:- ['arrays.yap'].
:- multifile user:portray_message/2.
:- dynamic user:portray_message/2.
/** @pred prolog:goal_expansion( :G,+ M,- NG)
@pred user:goalexpansion(+ G,+ M,- NG)
The goal_expansion/3 hook is an user-defined
procedure that is called after term expansion when compiling or
asserting goals for each sub-goal in a clause. The first argument is
bound to the goal and the second to the module under which the goal
_G_ will execute. If goal_expansion/3 succeeds the new
sub-goal _NG_ will replace _G_ and will be processed in the same
way. If goal_expansion/3 fails the system will use the default
expandion mechanism.
This hook is called:
- at compilation time;
- when running a query in the top-level
Older versions of YAP would call this procedure at every meta-call.
*/
:- multifile user:goal_expansion/3.
:- dynamic user:goal_expansion/3.
:- multifile user:goal_expansion/2.
:- dynamic user:goal_expansion/2.
:- multifile system:goal_expansion/2.
:- dynamic system:goal_expansion/2.
:- multifile goal_expansion/2.
:- dynamic goal_expansion/2.
:- use_module('messages.yap').
:- ['undefined.yap'].
:- use_module('hacks.yap').
:- use_module('attributes.yap').
:- use_module('corout.yap').
:- use_module('dialect.yap').
:- use_module('dbload.yap').
:- use_module('ypp.yap').
:- use_module('../os/chartypes.yap').
:- ensure_loaded('../os/edio.yap').
yap_hacks:cut_by(CP) :- '$$cut_by'(CP).
:- '$change_type_of_char'(36,7). % Make $ a symbol character
:- set_prolog_flag(generate_debug_info,true).
%
% cleanup ensure loaded and recover some data-base space.
%
%:- ( recorded('$lf_loaded',_,R), erase(R), fail ; true ).
%:- ( recorded('$module',_,R), erase(R), fail ; true ).
:- set_value('$user_module',user), '$protect'.
:- style_check([+discontiguous,+multiple,+single_var]).
%
% moved this to init_gc in sgc.c to separate the alpha
%
% :- yap_flag(gc,on).
%
% :- yap_flag(gc_trace,verbose`
:- multifile
prolog:comment_hook/3.
:- source.
:- module(user).
/** @pred term_expansion( _T_,- _X_)
user:term_expansion( _T_,- _X_)
This user-defined predicate is called by `expand_term/3` to
preprocess all terms read when consulting a file. If it succeeds:
+
If _X_ is of the form `:- G` or `?- G`, it is processed as
a directive.
+
If _X_ is of the form `$source_location`( _File_, _Line_): _Clause_` it is processed as if from `File` and line `Line`.
+
If _X_ is a list, all terms of the list are asserted or processed
as directives.
+ The term _X_ is asserted instead of _T_.
*/
:- multifile term_expansion/2.
:- dynamic term_expansion/2.
:- multifile system:term_expansion/2.
:- dynamic system:term_expansion/2.
:- multifile system:swi_predicate_table/4.
/** @pred user:message_hook(+ _Term_, + _Kind_, + _Lines_)
Hook predicate that may be define in the module `user` to intercept
messages from print_message/2. _Term_ and _Kind_ are the
same as passed to print_message/2. _Lines_ is a list of
format statements as described with print_message_lines/3.
This predicate should be defined dynamic and multifile to allow other
modules defining clauses for it too.
*/
:- multifile user:message_hook/3.
:- dynamic user:message_hook/3.
/** @pred exception(+ _Exception_, + _Context_, - _Action_)
Dynamic predicate, normally not defined. Called by the Prolog system on run-time exceptions that can be repaired `just-in-time`. The values for _Exception_ are described below. See also catch/3 and throw/1.
If this hook preodicate succeeds it must instantiate the _Action_ argument to the atom `fail` to make the operation fail silently, `retry` to tell Prolog to retry the operation or `error` to make the system generate an exception. The action `retry` only makes sense if this hook modified the environment such that the operation can now succeed without error.
+ `undefined_predicate`
_Context_ is instantiated to a predicate-indicator ( _Module:Name/Arity_). If the predicate fails Prolog will generate an existence_error exception. The hook is intended to implement alternatives to the SWI built-in autoloader, such as autoloading code from a database. Do not use this hook to suppress existence errors on predicates. See also `unknown`.
+ `undefined_global_variable`
_Context_ is instantiated to the name of the missing global variable. The hook must call nb_setval/2 or b_setval/2 before returning with the action retry.
*/
:- multifile user:exception/3.
:- dynamic user:exception/3.
:- ensure_loaded('../pl/pathconf.yap').
:- current_prolog_flag(android,true), ensure_loaded('../android.yap').
:- set_prolog_flag(unknown,error).
%% @} %% @}

View File

@ -389,23 +389,13 @@ version(T) :-
fail. fail.
'$set_toplevel_hook'(_). '$set_toplevel_hook'(_).
query_to_answer(G, V, Status, Vs, Bindings ) :- query_to_answer(G, V, Status, LGs) :-
gated_call( true, (G,'$delayed_goals'(G, V, Vs, LGs, _DCP)), Status, '$answer'( Status, LGs, Vs, Bindings ) ). gated_call(true,
G,
'$answer'( exit, LGs, Vs, Bindings ) :- Status,
!, true),
'$sort'(Vs, NVs), '$delayed_goals'(G, V, NV, LVGs, _DCP),
'$prep_answer_var_by_var'(NVs, Bindings , LGs). lists:append(NV, LVGs, LGs).
'$answer'( answer, LGs, Vs, Bindings) :-
!,
'$sort'(Vs, NVs),
'$prep_answer_var_by_var'(NVs, Bindings , LGs).
'$answer'(!, _, _,_).
'$answer'(fail,_,_,_).
'$answer'(exception(E),_,_,_) :-
'$LoopError'(E,error).
'$answer'(external_exception(_),_,_,_).
%% @} %% @}

View File

@ -17,88 +17,91 @@
*/ */
:- '$mk_dynamic'('$parent_module'(_,_),prolog). :- '$mk_dynamic'('$parent_module'(_,_),prolog).
mimp :-
recorded('$import',I,_), %'$import'(ExportingMod,ImportingMod,G0,G,_,_),_),
writeln(I),
%(ImportingMod:G :- ExportingMod:G0)),
fail.
'$get_undefined_predicates'(G, ImportingMod, G0, ExportingMod) :-
recorded('$import','$import'(ExportingModI,ImportingMod,G0I,G,_,_),_), %:- start_low_level_trace.
'$continue_imported'(ExportingMod, ExportingModI, G0, G0I).
% SWI builtin
'$get_undefined_predicates'(G, _ImportingMod, G, user) :-
nonvar(G),
'$pred_exists'(G, user).
% autoload
'$get_undefined_predicates'(G, ImportingMod, G0, ExportingMod) :-
prolog_flag(autoload, true),
prolog_flag(unknown, OldUnk, fail),
(
'$autoload'(G, ImportingMod, ExportingModI, swi)
->
prolog_flag(unknown, _, OldUnk)
;
prolog_flag(unknown, _, OldUnk),
fail
),
'$continue_imported'(ExportingMod, ExportingModI, G0, G).
% parent module mechanism % parent module mechanism
'$get_undefined_predicates'(G, ImportingMod, G0, ExportingMod) :- '$get_undefined_predicates'(ImportingMod:G,ExportingMod:G0) :-
'$parent_module'(ImportingMod,ExportingModI), recorded('$import','$import'(ExportingMod,ImportingMod,G,G0,_,_),_)
'$continue_imported'(ExportingMod, ExportingModI, G0, G).
'$get_undefined_predicates'(G, _ImportingMod, G0, ExportingMod) :-
yap_flag(default_parent_module,ExportingModI),
'$continue_imported'(ExportingMod, ExportingModI, G0, G).
'$get_undefined_pred'(G, ImportingMod, G0, ExportingMod) :-
'$get_undefined_predicates'(G, ImportingMod, G0, ExportingMod),
!.
% be careful here not to generate an undefined exception.
'$imported_predicate'(G, _ImportingMod, G, prolog) :-
nonvar(G), '$is_system_predicate'(G, prolog), !.
'$imported_predicate'(G, ImportingMod, G0, ExportingMod) :-
( var(G) -> true ;
var(ImportingMod) -> true ;
'$undefined'(G, ImportingMod)
),
'$get_undefined_predicates'(G, ImportingMod, G0, ExportingMod),
ExportingMod \= ImportingMod.
% be careful here not to generate an undefined exception.
'$generate_imported_predicate'(G, ImportingMod, G0, ExportingMod) :-
(
recorded('$import','$import'(ExportingModI,ImportingMod,G0I,G,_,_),_)
;
'$parent_module'(ImportingMod,ExportingModI),
\+ recorded('$import','$import'(ExportingModI,ImportingMod,G0I,G,_,_),_)
),
ImportingMod \= ExportingModI,
(
'$undefined'(G, ExportingModI)
-> ->
'$generate_imported_predicate'(G, ExportingModI, G0, ExportingMod) true
; ;
G=G0, %% this should have been caught before
ExportingModI=ExportingMod '$is_system_predicate'(G, prolog)
). ->
true
;
% autoload
current_prolog_flag(autoload, true)
->
'$autoload'(G, ImportingMod, ExportingMod, swi)
;
'$parent_module'(ImportingMod, NewImportingMod)
->
'$get_undefined_predicates'(NewImportingMod:G, ExportingMod:G0).
/** /**
* *
* @pred '$continue_imported'(+ModIn, +ModOut, +PredIn ,+PredOut) * @pred '$continue_imported'(+Modn, +ModOut, +Predn ,+PredOut)
* *
* @return * @return
*/ */
'$continue_imported'(Mod,Mod,Pred,Pred) :- '$continue_imported'(Mod:Pred,Mod,Pred) :-
'$pred_exists'(Pred, Mod), '$pred_exists'(Pred, Mod),
!. !.
'$continue_imported'(FM,Mod,FPred,Pred) :- '$continue_imported'(FM:FPred,Mod:Pred) :-
recorded('$import','$import'(IM,Mod,IPred,Pred,_,_),_), '$get_undefined_predicates'(FM:FPred, ModI:PredI),
'$continue_imported'(FM, IM, FPred, IPred), !. '$continue_imported'(ModI:PredI,Mod:Pred).
'$continue_imported'(FM,Mod,FPred,Pred) :-
prolog:'$parent_module'(Mod,IM), %
'$continue_imported'(FM, IM, FPred, Pred). '$get_undefined_pred'(ImportingMod:G, ExportingMod:G0) :-
must_be_callablle( ImportingMod:G ),
'$get_undefined_predicates'(ImportingMod:G, ExportingMod:G0).
% be careful here not to generate an undefined exception.
'$imported_predicate'(ImportingMod:G, ExportingMod:G0) :-
var(G) ->
'$current_predicate'(_,G,ImportingMod,_),
'$imported_predicate'(ImportingMod:G, ExportingMod:G0)
;
var(ImportingMod) ->
current_module(ImportingMod),
'$imported_predicate'(ImportingMod:G, ExportingMod:G0)
;
'$undefined'(G, ImportingMod),
'$get_undefined_predicates'(ImportingMod:G, ExportingMod:G0),
ExportingMod \= ImportingMod.
'$autoload'(G, _ImportingMod, ExportingMod, Dialect) :- % check if current module redefines an imported predicate.
% and remove import.
%
'$not_imported'(H, Mod) :-
recorded('$import','$import'(NM,Mod,NH,H,_,_),R),
NM \= Mod,
functor(NH,N,Ar),
print_message(warning,redefine_imported(Mod,NM,N/Ar)),
erase(R),
fail.
'$not_imported'(_, _).
'$verify_import'(_M:G, prolog:G) :-
'$is_system_predicate'(G, prolog).
'$verify_import'(M:G, NM:NG) :-
'$get_undefined_pred'(G, M, NG, NM),
!.
'$verify_import'(MG, MG).
'$autoload'(G, _mportingMod, ExportingMod, Dialect) :-
functor(G, Name, Arity), functor(G, Name, Arity),
'$pred_exists'(index(Name,Arity,ExportingMod,_),Dialect), '$pred_exists'(index(Name,Arity,ExportingMod,_),Dialect),
call(Dialect:index(Name,Arity,ExportingMod,_)), call(Dialect:index(Name,Arity,ExportingMod,_)),
@ -108,25 +111,26 @@
functor(G0, N, K), functor(G0, N, K),
'$autoloader_find_predicate'(G0,ExportingMod), '$autoloader_find_predicate'(G0,ExportingMod),
ExportingMod \= ImportingMod, ExportingMod \= ImportingMod,
% assert_static(ExportingMod:G0 :- ImportingMod:G0),
(recordzifnot('$import','$import'(ExportingMod,ImportingMod,G0,G0, N ,K),_) -> true ; true ). (recordzifnot('$import','$import'(ExportingMod,ImportingMod,G0,G0, N ,K),_) -> true ; true ).
'$autoloader_find_predicate'(G,ExportingModI) :- '$autoloader_find_predicate'(G,ExportingMod) :-
'__NB_getval__'('$autoloader_set', true, false), !, '__NB_getval__'('$autoloader_set', true, false), !,
autoloader:find_predicate(G,ExportingModI). autoloader:find_predicate(G,ExportingMod).
'$autoloader_find_predicate'(G,ExportingModI) :- '$autoloader_find_predicate'(G,ExportingMod) :-
yap_flag(autoload, true, false), yap_flag(autoload, true, false),
yap_flag( unknown, Unknown, fail), yap_flag( unknown, Unknown, fail),
yap_flag(debug, Debug, false), !, yap_flag(debug, Debug, false), !,
load_files([library(autoloader), load_files([library(autoloader),
autoloader:library('INDEX'), autoloader:library('NDEX'),
swi:library('dialect/swi/INDEX')], swi:library('dialect/swi/NDEX')],
[autoload(true),if(not_loaded)]), [autoload(true),if(not_loaded)]),
nb_setval('$autoloader_set', true), nb_setval('$autoloader_set', true),
yap_flag(autoload, _, true), yap_flag(autoload, _, true),
yap_flag( unknown, _, Unknown), yap_flag( unknown, _, Unknown),
yap_flag( debug, _, Debug), yap_flag( debug, _, Debug),
autoloader:find_predicate(G,ExportingModI). autoloader:find_predicate(G,ExportingMod).

View File

@ -1,3 +1,4 @@
/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog * * YAP Prolog *
@ -97,12 +98,22 @@ listing(MV) :-
listing(Stream, MV). listing(Stream, MV).
listing(Stream, MV) :- listing(Stream, MV) :-
strip_module( MV, M, I), '$yap_strip_module'( MV, M, I),
'$mlisting'(Stream, I, M). listing_(Stream, I, M),
listing(_Stream, []) :- !. !.
listing(Stream, [MV|MVs]) :- !,
listing(Stream, MV), listing_(Stream, V, M) :-
listing(Stream, MVs). var(V),
!,
'$mlisting'(Stream, V, M).
listing_(_Stream, [], _) :-
!.
listing_(Stream, [MV|MVs], M) :-
!,
'$mlisting'(Stream, MV, M),
listing_(Stream, MVs, M).
listing_(Stream, MV, M) :-
'$mlisting'(Stream, MV, M).
'$mlisting'(Stream, MV, M) :- '$mlisting'(Stream, MV, M) :-
( var(MV) -> ( var(MV) ->
@ -113,10 +124,13 @@ listing(Stream, [MV|MVs]) :- !,
MV/_ = NA, MV/_ = NA,
'$do_listing'(Stream, M, NA) '$do_listing'(Stream, M, NA)
; ;
MV = N//Ar -> ( integer(Ar) -> Ar2 is Ar+2, NA is N/Ar2 ; '$do_listing'(Stream, NA/Ar2, M), Ar2 >= 2, Ar is Ar2-2 ) MV = N//Ar ->
( integer(Ar) -> Ar2 is Ar+2, NA is N/Ar2 ;
'$do_listing'(Stream, NA/Ar2, M), Ar2 >= 2, Ar is Ar2-2 )
; ;
MV = N/Ar, ( atom(N) -> true ; var(N) ), ( integer(Ar) -> true ; var(Ar) ) -> MV = N/Ar,
'$do_listing'(Stream, M, MV) ( atom(N) -> true ; var(N) ),
( integer(Ar) -> true ; var(Ar) ) -> '$do_listing'(Stream, M, MV)
; ;
MV = M1:PP -> '$mlisting'(Stream, PP, M1) MV = M1:PP -> '$mlisting'(Stream, PP, M1)
; ;
@ -213,7 +227,7 @@ listing(Stream, [MV|MVs]) :- !,
'$predicate_flags'(Pred,M,Flags,Flags), '$predicate_flags'(Pred,M,Flags,Flags),
% has to be dynamic, source, or log update. % has to be dynamic, source, or log update.
Flags /\ 0x08402000 =\= 0, Flags /\ 0x08402000 =\= 0,
'$clause'(Pred, M, Body, _), clause(M:Pred, Body, _),
'$current_module'(Mod), '$current_module'(Mod),
( M \= Mod -> H = M:Pred ; H = Pred ), ( M \= Mod -> H = M:Pred ; H = Pred ),
portray_clause(Stream,(H:-Body)), portray_clause(Stream,(H:-Body)),
@ -248,7 +262,8 @@ portray_clause(Clause) :-
'$portray_clause'(Stream, Pred) :- '$portray_clause'(Stream, Pred) :-
format(Stream, '~q.~n', [Pred]). format(Stream, '~q.~n', [Pred]).
'$write_body'(X,I,T,Stream) :- var(X), !, '$write_body'(X,I,T,Stream) :-
var(X), !,
'$beforelit'(T,I,Stream), '$beforelit'(T,I,Stream),
writeq(Stream, '_'). writeq(Stream, '_').
'$write_body'((P,Q), I, T, Stream) :- '$write_body'((P,Q), I, T, Stream) :-

View File

@ -62,6 +62,9 @@ YAP supports the SWI-Prolog interface to loading foreign code, the shlib package
*/ */
load_foreign_files(_Objs,_Libs,Entry) :-
'$check_embedded'(Entry),
!.
load_foreign_files(Objs,Libs,Entry) :- load_foreign_files(Objs,Libs,Entry) :-
source_module(M), source_module(M),
%G = load_foreign_files(Objs,Libs,Entry), %G = load_foreign_files(Objs,Libs,Entry),

View File

@ -1014,9 +1014,7 @@ stub to ensure everything os ok
prolog:print_message(Severity, Msg) :- prolog:print_message(Severity, Msg) :-
\+ in, \+ in,
assert(in), assert(in),
start_low_level_trace,
( prolog:print_message(Severity, Msg), fail; ( prolog:print_message(Severity, Msg), fail;
stop_low_level_trace,
retract(in) retract(in)
). ).
*/ */

View File

@ -74,6 +74,7 @@ meta_predicate(P) :-
'$install_meta_predicate'(P,M,_F,_N) :- '$install_meta_predicate'(P,M,_F,_N) :-
'$new_meta_pred'(P, M), '$new_meta_pred'(P, M),
fail. fail.
'$install_meta_predicate'(_P,M,F,N) :- '$install_meta_predicate'(_P,M,F,N) :-
( M = prolog -> M2 = _ ; M2 = M), ( M = prolog -> M2 = _ ; M2 = M),
retractall(prolog:'$meta_predicate'(F,M2,N,_)), retractall(prolog:'$meta_predicate'(F,M2,N,_)),
@ -199,6 +200,72 @@ meta_predicate(P) :-
'$expand_arg'(G, CM, _HVars, NCM:NG) :- '$expand_arg'(G, CM, _HVars, NCM:NG) :-
'$yap_strip_module'(CM:G, NCM, NG). '$yap_strip_module'(CM:G, NCM, NG).
'$match_mod'(G, _HMod, _SMod, M, O) :-
'$is_system_predicate'(G,M),
!,
O = G.
'$match_mod'(G, M, M, M, G) :- !.
'$match_mod'(G, _HM, _M, M, M:G).
'$import_expansion'(none, MG, MG).
'$import_expansion'(_, M:G, M1:G1) :-
'$imported_predicate'(M:G, M1:G1),
!.
'$import_expansion'(_, MG, MG).
'$end_goal_expansion'(G, G1, GOF, HM, SM, BM, H) :-
'$match_mod'(G, HM, SM, BM, G1),
'$c_built_in'(G1, BM, H, GO),
'$yap_strip_module'(BM:GO, MO, IGO),
'$match_mod'(IGO, HM, SM, MO, GOF).
'$user_expansion'(none, MG, MG) :-
!.
'$user_expansion'(Ctx, M0N:G0N, M1:G1) :-
'_user_expand_goal'(M0N:G0N, M:G),
!,
( M:G == M0N:G0N
->
M1:G1 = M:G
;
'$user_expansion'(Ctx, M:G, M1:G1)
).
'$user_expansion'(_,MG, MG).
'$meta_expansion'(GMG, BM, HVars, GM:GF) :-
'$yap_strip_module'(BM:GMG, GM, G ),
functor(G, F, Arity ),
'$meta_predicate'(F, GM, Arity, PredDef),
!,
'$meta_expand'(G, PredDef, GM, HVars, GF).
'$meta_expansion'(GF, BM, _HVars, BM:GF).
'$expand_goal'(G0, GF, GS, HM, SM, BM, HVars-H) :-
'$yap_strip_module'( BM:G0, M0N, G0N),
'$user_expansion'(HVars,M0N:G0N, M1:G1),
'$import_expansion'(HVars, M1:G1, M2:G2),
'$meta_expansion'(G2, M2, HVars, MG3),
'$yap_strip_module'(MG3, M4, B4),
'$end_goal_expansion'(B4, GF, GS, HM, SM, M4, H).
/*
'$match_mod'(G, HMod, SMod, M, O) :-
(
% \+ '$is_multifile'(G1,M),
%->
'$is_system_predicate'(G,M)
->
O = G
;
M == HMod, M == SMod
->
O = G
;
O = M:G
).
*/
% expand module names in a body % expand module names in a body
% args are: % args are:
% goals to expand % goals to expand
@ -357,77 +424,6 @@ meta_predicate(P) :-
'$expand_goal'(GM, G1, GO, HM, SM, NBM, HVars). '$expand_goal'(GM, G1, GO, HM, SM, NBM, HVars).
'$import_expansion'(M:G, M1:G1) :-
'$imported_predicate'(G, M, G1, M1),
!.
'$import_expansion'(MG, MG).
'$meta_expansion'(GMG, BM, HVars, GM:GF) :-
'$yap_strip_module'(GMG, GM, G ),
functor(G, F, Arity ),
'$meta_predicate'(F, GM, Arity, PredDef),
!,
'$meta_expand'(G, PredDef, BM, HVars, GF).
'$meta_expansion'(GMG, _BM, _HVars, GM:G) :-
'$yap_strip_module'(GMG, GM, G ).
%% none -- metacalls
'$expand_goal'(G0, GF, GF, _HM, _SM, BM, none-_) :-
!,
'$yap_strip_module'( BM:G0, M0N, G0N),
'$user_expansion'(M0N:G0N, M1:G1),
'$import_expansion'(M1:G1, M2:G2),
'$meta_expansion'(M2:G2, M1, [], GF).
'$expand_goal'(G0, G1F, GOF, HM, SM, BM, HVars-H) :-
'$yap_strip_module'( BM:G0, M0N, G0N),
'$user_expansion'(M0N:G0N, M1:G1),
'$import_expansion'(M1:G1, M2:G2),
'$meta_expansion'(M2:G2, M1, HVars, M2B1F),
'$yap_strip_module'(M2B1F, M3, B1F),
'$end_goal_expansion'(B1F, G1F, GOF, HM, SM, M3, H).
'$end_goal_expansion'(G, G1, GOF, HM, SM, BM, H) :-
'$match_mod'(G, HM, SM, BM, G1),
'$c_built_in'(G1, BM, H, GO),
'$yap_strip_module'(BM:GO, MO, IGO),
'$match_mod'(IGO, HM, SM, MO, GOF).
'$user_expansion'(M0N:G0N, M1:G1) :-
'_user_expand_goal'(M0N:G0N, M:G),
!,
( M:G == M0N:G0N
->
M1:G1 = M:G
;
'$user_expansion'(M:G, M1:G1)
).
'$user_expansion'(MG, MG).
'$match_mod'(G, _HMod, _SMod, M, O) :-
'$is_system_predicate'(G,M),
!,
O = G.
'$match_mod'(G, M, M, M, G) :- !.
'$match_mod'(G, _HM, _M, M, M:G).
/*
'$match_mod'(G, HMod, SMod, M, O) :-
(
% \+ '$is_multifile'(G1,M),
%->
'$is_system_predicate'(G,M)
->
O = G
;
M == HMod, M == SMod
->
O = G
;
O = M:G
).
*/
'$build_up'(HM, NH, SM, true, NH, true, NH) :- HM == SM, !. '$build_up'(HM, NH, SM, true, NH, true, NH) :- HM == SM, !.
'$build_up'(HM, NH, _SM, true, HM:NH, true, HM:NH) :- !. '$build_up'(HM, NH, _SM, true, HM:NH, true, HM:NH) :- !.
@ -451,28 +447,6 @@ meta_predicate(P) :-
BO = BO1 BO = BO1
). ).
%
% check if current module redefines an imported predicate.
% and remove import.
%
'$not_imported'(H, Mod) :-
recorded('$import','$import'(NM,Mod,NH,H,_,_),R),
NM \= Mod,
functor(NH,N,Ar),
print_message(warning,redefine_imported(Mod,NM,N/Ar)),
erase(R),
fail.
'$not_imported'(_, _).
'$verify_import'(_M:G, prolog:G) :-
'$is_system_predicate'(G, prolog).
'$verify_import'(M:G, NM:NG) :-
'$get_undefined_pred'(G, M, NG, NM),
!.
'$verify_import'(MG, MG).
% expand arguments of a meta-predicate % expand arguments of a meta-predicate
% $meta_expansion(ModuleWhereDefined,CurrentModule,Goal,ExpandedGoal,MetaVariables) % $meta_expansion(ModuleWhereDefined,CurrentModule,Goal,ExpandedGoal,MetaVariables)

View File

@ -42,7 +42,7 @@
'$do_import'/3, '$do_import'/3,
'$extend_exports'/3, '$extend_exports'/3,
'$get_undefined_pred'/4, '$get_undefined_pred'/4,
'$imported_predicate'/4, '$imported_predicate'/2,
'$meta_expand'/6, '$meta_expand'/6,
'$meta_predicate'/2, '$meta_predicate'/2,
'$meta_predicate'/4, '$meta_predicate'/4,
@ -297,6 +297,29 @@ use_module(F,Is) :-
functor(G1, N1, K1), functor(G1, N1, K1),
'$module_produced by'(M,MI,N1,K1). '$module_produced by'(M,MI,N1,K1).
%
% check if current module redefines an imported predicate.
% and remove import.
%
'$not_imported'(H, Mod) :-
recorded('$import','$import'(NM,Mod,NH,H,_,_),R),
NM \= Mod,
functor(NH,N,Ar),
print_message(warning,redefine_imported(Mod,NM,N/Ar)),
erase(R),
fail.
'$not_imported'(_, _).
'$verify_import'(_M:G, prolog:G) :-
'$is_system_predicate'(G, prolog).
'$verify_import'(M:G, NM:NG) :-
'$get_undefined_pred'(G, M, NG, NM),
!.
'$verify_import'(MG, MG).
/** @pred current_module( ? Mod:atom) is nondet /** @pred current_module( ? Mod:atom) is nondet

View File

@ -31,7 +31,7 @@ module(N) :-
module(N) :- module(N) :-
atom(N), !, atom(N), !,
% set it as current module. % set it as current module.
'$current_module'(_,N). '$change_module'(N).
module(N) :- module(N) :-
'$do_error'(type_error(atom,N),module(N)). '$do_error'(type_error(atom,N),module(N)).

View File

@ -14,7 +14,7 @@
:- module(user). :- module(user).
/** /**
@pred library_directory(?Directory:atom) is nondet, dynamic @pred user:library_directory(?Directory:atom) is nondet, dynamic
Dynamic, multi-file predicate that succeeds when _Directory_ is a Dynamic, multi-file predicate that succeeds when _Directory_ is a
current library directory name. Asserted in the user module. current library directory name. Asserted in the user module.
@ -26,24 +26,24 @@ reconsult/1, use_module/1, ensure_loaded/1, and load_files/2.
This directory is initialized by a rule that calls the system predicate This directory is initialized by a rule that calls the system predicate
system_library/1. system_library/1.
*/ */
:- multifile library_directory/1. :- multifile user:library_directory/1.
:- discontiguous library_directory/1. :- discontiguous user:library_directory/1.
:- dynamic library_directory/1. :- dynamic user:library_directory/1.
%% Specifies the set of directories where %% Specifies the set of directories where
% one can find Prolog libraries. % one can find Prolog libraries.
% %
library_directory(Home) :- user:library_directory(Home) :-
current_prolog_flag(prolog_library_directory, Home), current_prolog_flag(library_directory, Home),
Home \= ''. Home \= ''.
% 1. honor YAPSHAREDIR % 1. honor YAPSHAREDIR
library_directory( Dir ) :- user:library_directory( Dir ) :-
getenv( 'YAPSHAREDIR', Dir). getenv( 'YAPSHAREDIR', Dir).
%% 2. honor user-library %% 2. honor user-library
library_directory( '~/share/Yap' ). user:library_directory( '~/share/Yap' ).
%% 3. honor current directory %% 3. honor current directory
library_directory( '.' ). user:library_directory( '.' ).
%% 4. honor default location. %% 4. honor default location.
library_directory( Dir ) :- user:library_directory( Dir ) :-
system_library( Dir ). system_library( Dir ).
/** /**
@ -54,12 +54,12 @@ library_directory( Dir ) :-
This directory is initialized as a rule that calls the system predicate This directory is initialized as a rule that calls the system predicate
library_directories/2. library_directories/2.
*/ */
:- dynamic commons_directory/1. :- dynamic user:commons_directory/1.
:- discontiguous commons_directory/1. :- discontiguous user:commons_directory/1.
:- multifile commons_directory/1. :- multifile user:commons_directory/1.
commons_directory( Path ):- user:commons_directory( Path ):-
system_commons( Path ). system_commons( Path ).
/** /**
@ -81,7 +81,7 @@ foreign_directory(Home) :-
Home \= ''. Home \= ''.
foreign_directory(C) :- foreign_directory(C) :-
current_prolog_flag(windows, true), current_prolog_flag(windows, true),
file_search_path(path, C). user:file_search_path(path, C).
foreign_directory( '.'). foreign_directory( '.').
foreign_directory(yap('lib/Yap')). foreign_directory(yap('lib/Yap')).
%foreign_directory( Path ):- %foreign_directory( Path ):-
@ -96,64 +96,64 @@ foreign_directory(yap('lib/Yap')).
uses one of dll, so, or dylib for shared objects. Initial definition is: uses one of dll, so, or dylib for shared objects. Initial definition is:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~prolog ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~prolog
prolog_file_type(yap, prolog). user:prolog_file_type(yap, prolog).
prolog_file_type(pl, prolog). user:prolog_file_type(pl, prolog).
prolog_file_type(prolog, prolog). user:prolog_file_type(prolog, prolog).
prolog_file_type(qly, prolog). user:prolog_file_type(qly, prolog).
prolog_file_type(qly, qly). user:prolog_file_type(qly, qly).
prolog_file_type(A, prolog) :- user:prolog_file_type(A, prolog) :-
current_prolog_flag(associate, A), current_prolog_flag(associate, A),
A \== prolog, A \== prolog,
A \==pl, A \==pl,
A \== yap. A \== yap.
prolog_file_type(A, executable) :- user:prolog_file_type(A, executable) :-
current_prolog_flag(shared_object_extension, A). current_prolog_flag(shared_object_extension, A).
prolog_file_type(pyd, executable). user:prolog_file_type(pyd, executable).
~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
*/ */
:- multifile prolog_file_type/2. :- multifile user:prolog_file_type/2.
:- discontiguous prolog_file_type/2. :- discontiguous user:prolog_file_type/2.
:- dynamic prolog_file_type/2. :- dynamic user:prolog_file_type/2.
prolog_file_type(yap, prolog). user:prolog_file_type(yap, prolog).
prolog_file_type(pl, prolog). user:prolog_file_type(pl, prolog).
prolog_file_type(prolog, prolog). user:prolog_file_type(prolog, prolog).
prolog_file_type(A, prolog) :- user:prolog_file_type(A, prolog) :-
current_prolog_flag(associate, A), current_prolog_flag(associate, A),
A \== prolog, A \== prolog,
A \== pl, A \== pl,
A \== yap. A \== yap.
prolog_file_type(qly, qly). user:prolog_file_type(qly, qly).
prolog_file_type(A, executable) :- user:prolog_file_type(A, executable) :-
current_prolog_flag(shared_object_extension, A). current_prolog_flag(shared_object_extension, A).
prolog_file_type(pyd, executable). user:prolog_file_type(pyd, executable).
/** /**
@pred file_search_path(+Name:atom, -Directory:atom) is nondet @pred user:file_search_path(+Name:atom, -Directory:atom) is nondet
Allows writing file names as compound terms. The _Name_ and Allows writing file names as compound terms. The _Name_ and
_DIRECTORY_ must be atoms. The predicate may generate multiple _DIRECTORY_ must be atoms. The predicate may generate multiple
solutions. The predicate is originally defined as follows: solutions. The predicate is originally defined as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~pl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~pl
file_search_path(library, Dir) :- user:file_search_path(library, Dir) :-
library_directory(Dir). user:library_directory(Dir).
file_search_path(commons, Dir) :- user:file_search_path(commons, Dir) :-
commons_directory(Dir). commons_directory(Dir).
file_search_path(swi, Home) :- user:file_search_path(swi, Home) :-
current_prolog_flag(home, Home). current_prolog_flag(home, Home).
file_search_path(yap, Home) :- user:file_search_path(yap, Home) :-
current_prolog_flag(home, Home). current_prolog_flag(home, Home).
file_search_path(system, Dir) :- user:file_search_path(system, Dir) :-
prolog_flag(host_type, Dir). prolog_flag(host_type, Dir).
file_search_path(foreign, Dir) :- user:file_search_path(foreign, Dir) :-
foreign_directory(Dir). foreign_directory(Dir).
file_search_path(executable, Dir) :- user:file_search_path(executable, Dir) :-
foreign_directory(Dir). foreign_directory(Dir).
file_search_path(executable, Dir) :- user:file_search_path(executable, Dir) :-
foreign_directory(Dir). foreign_directory(Dir).
file_search_path(path, C) :- user:file_search_path(path, C) :-
( getenv('PATH', A), ( getenv('PATH', A),
( current_prolog_flag(windows, true) ( current_prolog_flag(windows, true)
-> atomic_list_concat(B, ;, A) -> atomic_list_concat(B, ;, A)
@ -165,30 +165,30 @@ file_search_path(path, C) :-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thus, `compile(library(A))` will search for a file using Thus, `compile(library(A))` will search for a file using
library_directory/1 to obtain the prefix, user:library_directory/1 to obtain the prefix,
whereas 'compile(system(A))` would look at the `host_type` flag. whereas 'compile(system(A))` would look at the `host_type` flag.
*/ */
:- multifile file_search_path/2. :- multifile user:file_search_path/2.
:- dynamic file_search_path/2. :- dynamic user:file_search_path/2.
:- discontiguous file_search_path/2. :- discontiguous user:file_search_path/2.
file_search_path(library, Dir) :- user:file_search_path(library, Dir) :-
library_directory(Dir). user:library_directory(Dir).
file_search_path(commons, Dir) :- user:file_search_path(commons, Dir) :-
commons_directory(Dir). user:commons_directory(Dir).
file_search_path(swi, Home) :- user:file_search_path(swi, Home) :-
current_prolog_flag(home, Home). current_prolog_flag(home, Home).
file_search_path(yap, Home) :- user:file_search_path(yap, Home) :-
current_prolog_flag(home, Home). current_prolog_flag(home, Home).
file_search_path(system, Dir) :- user:file_search_path(system, Dir) :-
prolog_flag(host_type, Dir). prolog_flag(host_type, Dir).
file_search_path(foreign, Dir) :- user:file_search_path(foreign, Dir) :-
foreign_directory(Dir). foreign_directory(Dir).
file_search_path(executable, Dir) :- user:file_search_path(executable, Dir) :-
foreign_directory(Dir). foreign_directory(Dir).
file_search_path(path, C) :- user:file_search_path(path, C) :-
( getenv('PATH', A), ( getenv('PATH', A),
( current_prolog_flag(windows, true) ( current_prolog_flag(windows, true)
-> atomic_list_concat(B, ;, A) -> atomic_list_concat(B, ;, A)
@ -197,5 +197,4 @@ file_search_path(path, C) :-
lists:member(C, B) lists:member(C, B)
). ).
%% @} %% @}

View File

@ -209,9 +209,6 @@ retract( C ) :-
Erases from the program the clause _C_ whose Erases from the program the clause _C_ whose
database reference is _R_. The predicate must be dynamic. database reference is _R_. The predicate must be dynamic.
*/ */
retract(M:C,R) :- !, retract(M:C,R) :- !,
'$yap_strip_module'( C, M, H0), '$yap_strip_module'( C, M, H0),

View File

@ -187,14 +187,14 @@ clause(V0,Q,R) :-
must_be_of_type( callable, V ), must_be_of_type( callable, V ),
'$clause'(V,M,Q,R). '$clause'(V,M,Q,R).
'$clause'(P,M,Q,R) :-
'$is_log_updatable'(P, M), !,
'$log_update_clause'(P,M,Q,R).
'$clause'(P,M,Q,R) :- '$clause'(P,M,Q,R) :-
'$is_exo'(P, M), !, '$is_exo'(P, M), !,
Q = true, Q = true,
R = '$exo_clause'(M,P), R = '$exo_clause'(M,P),
'$execute0'(P, M). '$execute0'(P, M).
'$clause'(P,M,Q,R) :-
'$is_log_updatable'(P, M), !,
'$log_update_clause'(P,M,Q,R).
'$clause'(P,M,Q,R) :- '$clause'(P,M,Q,R) :-
'$is_source'(P, M), !, '$is_source'(P, M), !,
'$static_clause'(P,M,Q,R). '$static_clause'(P,M,Q,R).
@ -607,9 +607,9 @@ current_predicate(A,T0) :-
; ;
(nonvar(T) (nonvar(T)
-> ->
'$imported_predicate'(T, M, T1, M1) '$imported_predicate'(M:T, M1:T1)
; ;
'$generate_imported_predicate'(T, M, T1, M1) '$imported_predicate'(M:T, M1:T1)
), ),
functor(T1, A, _), functor(T1, A, _),
\+ '$is_system_predicate'(T1,M1) \+ '$is_system_predicate'(T1,M1)

View File

@ -37,3 +37,4 @@
udi(Pred) :- udi(Pred) :-
'$udi_init'(Pred). '$udi_init'(Pred).

View File

@ -104,34 +104,25 @@ undefined_query(G0, M0, Cut) :-
'$yap_strip_module'(M0:G0, EM0, GM0), '$yap_strip_module'(M0:G0, EM0, GM0),
user:unknown_predicate_handler(GM0,EM0,MG), user:unknown_predicate_handler(GM0,EM0,MG),
!. !.
'$undefp_search'(M0:G0, M:G) :- '$undefp_search'(M0:G0, MG) :-
'$get_undefined_predicates'(G, M0, G0, M), !. '$get_undefined_predicates'(M0:G0, MG), !.
:- abolish('$undefp'/2).
% undef handler % undef handler
'$undefp'([M0|G0],_) :- '$undefp'([M0|G0],MG) :-
% make sure we do not loop on undefined predicates % make sure we do not loop on undefined predicates
setup_call_catcher_cleanup(
'$undef_set'(Action,Debug,Current), '$undef_set'(Action,Debug,Current),
'$search_def'(M0,G0,MG), '$search_def'(M0:G0,MG,Action,Debug,Current).
Port,
'$undef_reset'(Port,M0:G0,MG,Action,Debug,Current)
).
'$undef_set'(Action,Debug,Current) :- '$undef_set'(Action,Debug,Current) :-
yap_flag( unknown, Action, fail), yap_flag( unknown, Action, fail),
yap_flag( debug, Debug, false), yap_flag( debug, Debug, false),
'$stop_creeping'(Current). '$stop_creeping'(Current).
'$search_def'(M0,G0,NG:NM) :-
'$undefp_search'(M0:G0, NM:NG),
!,
'$pred_exists'(NG,NM).
'$undef_reset'(exit,_G0,NG:NM,Action,Debug,Current) :- '$search_def'(M0:G0,NM:NG,Action,Debug,Current) :-
'$undefp_search'(M0:G0, NM:NG),
'$pred_exists'(NG,NM),
!,
yap_flag( unknown, _, Action), yap_flag( unknown, _, Action),
yap_flag( debug, _, Debug), yap_flag( debug, _, Debug),
nonvar(NG), nonvar(NG),
@ -144,7 +135,7 @@ undefined_query(G0, M0, Cut) :-
; ;
'$execute0'(NG, NM) '$execute0'(NG, NM)
). ).
'$undef_reset'(_,M0:G0,_NG,Action,Debug,_Current) :- '$search_def'(M0:G0,_,Action,Debug,_Current) :-
yap_flag( unknown, _, Action), yap_flag( unknown, _, Action),
yap_flag( debug, _, Debug), yap_flag( debug, _, Debug),
'$start_creep'([prolog|true], creep), '$start_creep'([prolog|true], creep),

View File

@ -37,12 +37,8 @@ set (LIBRARY_PL
) )
if (ANDROID)
file(INSTALL ${LIBRARY_PL} DESTINATION ${YAP_INSTALL_DATADIR})
endif()
install(FILES ${LIBRARY_PL} install(FILES ${LIBRARY_PL}
DESTINATION ${YAP_INSTALL_DATADIR} DESTINATION ${YAP_INSTALL_DATADIR}
) )
add_to_group( LIBRARY_PL pl_library ) add_to_dir (LIBRARY_PL YAP_INSTALL_DATADIR )

View File

@ -1,5 +1,7 @@
/* Part of SWI-Prolog /* Part of SWI-Prolog
@file plunit.pl
Author: Jan Wielemaker Author: Jan Wielemaker
E-mail: J.Wielemaker@cs.vu.nl E-mail: J.Wielemaker@cs.vu.nl
WWW: http://www.swi-prolog.org WWW: http://www.swi-prolog.org
@ -43,7 +45,8 @@
test_report/1 % +What test_report/1 % +What
]). ]).
/** <module> Unit Testing /** @defgroup PlUnit Unit Testing
@ingroup library
Unit testing environment for SWI-Prolog and SICStus Prolog. For usage, Unit testing environment for SWI-Prolog and SICStus Prolog. For usage,
please visit http://www.swi-prolog.org/pldoc/package/plunit.html. please visit http://www.swi-prolog.org/pldoc/package/plunit.html.