diff --git a/C/absmi.c b/C/absmi.c index fcd31e639..1ec017858 100755 --- a/C/absmi.c +++ b/C/absmi.c @@ -916,24 +916,26 @@ static int interrupt_dexecute(USES_REGS1) { static void undef_goal(USES_REGS1) { PredEntry *pe = PredFromDefCode(P); - BEGD(d0); -/* avoid trouble with undefined dynamic procedures */ -/* I assume they were not locked beforehand */ -#if defined(YAPOR) || defined(THREADS) + /* avoid trouble with undefined dynamic procedures */ + /* I assume they were not locked beforehand */ + #if defined(YAPOR) || defined(THREADS) if (!PP) { PELOCK(19, pe); PP = pe; } #endif - if (pe->PredFlags & (DynamicPredFlag | LogUpdatePredFlag | MultiFileFlag) ) { + BACKUP_MACHINE_REGS(); +if (pe->PredFlags & (DynamicPredFlag | LogUpdatePredFlag | MultiFileFlag) ) { #if defined(YAPOR) || defined(THREADS) UNLOCKPE(19, PP); PP = NULL; #endif CalculateStackGap(PASS_REGS1); P = FAILCODE; + RECOVER_MACHINE_REGS(); return; } +#if DEBUG if (UndefCode == NULL || UndefCode->OpcodeOfPred == UNDEF_OPCODE) { fprintf(stderr,"call to undefined Predicates %s ->", IndicatorOfPred(pe)); Yap_DebugPlWriteln(ARG1); @@ -946,16 +948,28 @@ static void undef_goal(USES_REGS1) { #endif CalculateStackGap(PASS_REGS1); P = FAILCODE; + RECOVER_MACHINE_REGS(); return; } +#endif #if defined(YAPOR) || defined(THREADS) UNLOCKPE(19, PP); PP = NULL; -#endif - if (pe->ArityOfPE == 0) { - d0 = MkAtomTerm((Atom)(pe->FunctorOfPred)); + #endif + CELL o = AbsPair(HR); + if (pe->ModuleOfPred == PROLOG_MODULE) { + if (CurrentModule == PROLOG_MODULE) + HR[0] = TermProlog; + else + HR[0] = CurrentModule; } else { - d0 = AbsAppl(HR); + HR[0] = Yap_Module_Name(pe); + } + HR += 2; + if (pe->ArityOfPE == 0) { + HR[-1] = MkAtomTerm((Atom)(pe->FunctorOfPred)); + } else { + HR[-1] = AbsAppl(HR); *HR++ = (CELL)pe->FunctorOfPred; CELL *ip=HR; UInt imax = pe->ArityOfPE; @@ -984,30 +998,20 @@ static void undef_goal(USES_REGS1) { ENDD(d1); } } - ARG1 = AbsPair(HR); - HR[1] = d0; -ENDD(d0); - if (pe->ModuleOfPred == PROLOG_MODULE) { - if (CurrentModule == PROLOG_MODULE) - HR[0] = TermProlog; - else - HR[0] = CurrentModule; - } else { - HR[0] = Yap_Module_Name(pe); - } - ARG2 = Yap_getUnknownModule(Yap_GetModuleEntry(HR[0])); - HR += 2; + ARG1 = o; + ARG2 = MkVarTerm(); #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) low_level_trace(enter_pred, UndefCode, XREGS + 1); #endif /* LOW_LEVEL_TRACE */ P = UndefCode->CodeOfPred; + RECOVER_MACHINE_REGS(); } static void spy_goal(USES_REGS1) { PredEntry *pe = PredFromDefCode(P); - + BACKUP_MACHINE_REGS(); #if defined(YAPOR) || defined(THREADS) if (!PP) { PELOCK(14, pe); @@ -1027,6 +1031,7 @@ static void spy_goal(USES_REGS1) { PP = NULL; } #endif + RECOVER_MACHINE_REGS(); return; } } @@ -1044,6 +1049,7 @@ static void spy_goal(USES_REGS1) { } #endif Yap_NilError(CALL_COUNTER_UNDERFLOW_EVENT, ""); + RECOVER_MACHINE_REGS(); return; } LOCAL_PredEntriesCounter--; @@ -1055,6 +1061,7 @@ static void spy_goal(USES_REGS1) { } #endif Yap_NilError(PRED_ENTRY_COUNTER_UNDERFLOW_EVENT, ""); + RECOVER_MACHINE_REGS(); return; } if ((pe->PredFlags & (CountPredFlag | ProfiledPredFlag | SpiedPredFlag)) == @@ -1066,6 +1073,7 @@ static void spy_goal(USES_REGS1) { } #endif P = pe->cs.p_code.TrueCodeOfPred; + RECOVER_MACHINE_REGS(); return; } } @@ -1084,6 +1092,7 @@ static void spy_goal(USES_REGS1) { PP = NULL; } #endif + RECOVER_MACHINE_REGS(); return; } } @@ -1153,6 +1162,7 @@ static void spy_goal(USES_REGS1) { low_level_trace(enter_pred, pt0, XREGS + 1); #endif /* LOW_LEVEL_TRACE */ } + RECOVER_MACHINE_REGS(); } Int Yap_absmi(int inp) { diff --git a/C/c_interface.c b/C/c_interface.c index b757f8b93..756abb7af 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -1725,6 +1725,7 @@ X_API YAP_PredEntryPtr YAP_AtomToPredInModule(YAP_Atom at, Term mod) { return RepPredProp(PredPropByAtom(at, mod)); } +/* static int run_emulator(USES_REGS1) { int out; @@ -1732,6 +1733,7 @@ static int run_emulator(USES_REGS1) { LOCAL_PrologMode |= UserCCallMode; return out; } +*/ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) { CACHE_REGS @@ -2210,8 +2212,10 @@ X_API Term YAP_ReadClauseFromStream(int sno, Term vs, Term pos) { BACKUP_MACHINE_REGS(); Term t = Yap_read_term( sno, - MkPairTerm(Yap_MkApplTerm(Yap_MkFunctor(AtomVariableNames, 1), 1, &vs), - MkPairTerm(Yap_MkApplTerm(Yap_MkFunctor(AtomTermPosition, 1), + MkPairTerm( + Yap_MkApplTerm(Yap_MkFunctor(AtomVariableNames, 1), 1, &vs), + MkPairTerm( + Yap_MkApplTerm(Yap_MkFunctor(AtomTermPosition, 1), 1, &pos), TermNil)), true); @@ -2268,6 +2272,7 @@ X_API char *YAP_WriteBuffer(Term t, char *buf, size_t sze, int flags) { } } } + return out.val.c = pop_output_text_stack(l,buf); } /// write a a term to n user-provided buffer: make sure not tp diff --git a/C/dbase.c b/C/dbase.c index db253b349..70c6deea2 100644 --- a/C/dbase.c +++ b/C/dbase.c @@ -4000,7 +4000,7 @@ static void EraseLogUpdCl(LogUpdClause *clau) { if (ap->cs.p_code.NOfClauses > 1) { if (ap->TimeStampOfPred >= TIMESTAMP_RESET) Yap_UpdateTimestamps(ap); - ++ap->TimeStampOfPred; + ++(ap->TimeStampOfPred); /* fprintf(stderr,"- * %x--%d--%ul\n",ap,ap->TimeStampOfPred,ap->ArityOfPE);*/ ap->LastCallOfPred = LUCALL_RETRACT; @@ -4017,7 +4017,7 @@ static void EraseLogUpdCl(LogUpdClause *clau) { ap->LastCallOfPred = LUCALL_ASSERT; } } - clau->ClTimeEnd = ap->TimeStampOfPred; + //clau->ClTimeEnd = ap->TimeStampOfPred; Yap_RemoveClauseFromIndex(ap, clau->ClCode); /* release the extra reference */ } diff --git a/C/errors.c b/C/errors.c index 53c53bd7f..2e02c1cbe 100755 --- a/C/errors.c +++ b/C/errors.c @@ -41,8 +41,8 @@ #define set_key_i(k, ks, q, i, t) \ if (strcmp(ks, q) == 0) { \ - i->k = IsIntegerTerm(t) ? IntegerOfTerm(t) : 0; \ - return IsIntegerTerm(t); \ + i->k = IsIntegerTerm(t) ? IntegerOfTerm(t) : 0; \ + return IsIntegerTerm(t); \ } #define set_key_s(k, ks, q, i, t) \ @@ -99,7 +99,7 @@ if (strcmp(ks, q) == 0) { \ #define query_key_s(k, ks, q, i) \ if (strcmp(ks, q) == 0 ) \ -{ if (i->k) return MkAtomTerm(Yap_LookupAtom(i->k)); else return TermNil; } +{ if (i->k) return MkAtomTerm(Yap_LookupAtom(i->k)); else return TermEmptyAtom; } #define query_key_t(k, ks, q, i) \ @@ -1258,15 +1258,25 @@ static Int is_callable(USES_REGS1) { return false; } -static Int is_predicate_indicator(USES_REGS1) { +/** + * @pred is_predicate_indicator( Term, Module, Name, Arity ) + * + * This predicates can be used to verify if Term is a predicate indicator, that is of the form: + * + Name/Arity + * + Name//Arity-2 + * + Module:Name/Arity + * + Module:Name//Arity-2 + * + * if it is, it will extract the predicate's module, name, and arity. + */ +static Int get_predicate_indicator(USES_REGS1) { Term G = Deref(ARG1); // Term Context = Deref(ARG2); Term mod = CurrentModule; G = Yap_YapStripModule(G, &mod); if (IsVarTerm(G)) { - Yap_Error(INSTANTIATION_ERROR, G, NULL); - return false; + Yap_ThrowError(INSTANTIATION_ERROR, G, NULL); } if (!IsVarTerm(mod) && !IsAtomTerm(mod)) { Yap_Error(TYPE_ERROR_ATOM, G, NULL); @@ -1275,13 +1285,34 @@ static Int is_predicate_indicator(USES_REGS1) { if (IsApplTerm(G)) { Functor f = FunctorOfTerm(G); if (IsExtensionFunctor(f)) { - Yap_Error(TYPE_ERROR_PREDICATE_INDICATOR, G, NULL); + Yap_ThrowError(TYPE_ERROR_PREDICATE_INDICATOR, G, NULL); } if (f == FunctorSlash || f == FunctorDoubleSlash) { - return true; + Term name = ArgOfTerm(1,G), arity = ArgOfTerm(2,G); + if (IsVarTerm(name)) { + Yap_ThrowError(INSTANTIATION_ERROR, name, NULL); + } else if (!IsAtomTerm(name)) { + Yap_ThrowError(TYPE_ERROR_ATOM, name, NULL); + } + if (IsVarTerm(arity)) { + Yap_ThrowError(INSTANTIATION_ERROR, arity, NULL); + } else if (!IsIntegerTerm(arity)) { + Yap_ThrowError(TYPE_ERROR_INTEGER, arity, NULL); + } else { + Int ar = IntegerOfTerm(arity); + if (ar < 0) { + Yap_ThrowError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, arity, NULL); + } + if ( f == FunctorDoubleSlash) { + arity = MkIntegerTerm(ar+2); + } + return Yap_unify(mod, ARG2) && + Yap_unify(name, ARG3) && + Yap_unify(arity, ARG4); + } + } } - } - Yap_Error(TYPE_ERROR_PREDICATE_INDICATOR, G, NULL); + Yap_ThrowError(TYPE_ERROR_PREDICATE_INDICATOR, G, NULL); return false; } @@ -1296,9 +1327,8 @@ void Yap_InitErrorPreds(void) { Yap_InitCPred("$query_exception", 3, query_exception, 0); Yap_InitCPred("$drop_exception", 1, drop_exception, 0); Yap_InitCPred("$close_error", 0, close_error, HiddenPredFlag); - Yap_InitCPred("is_boolean", 2, is_boolean, TestPredFlag); - Yap_InitCPred("is_callable", 2, is_callable, TestPredFlag); - Yap_InitCPred("is_atom", 2, is_atom, TestPredFlag); - Yap_InitCPred("is_predicate_indicator", 2, is_predicate_indicator, - TestPredFlag); + Yap_InitCPred("is_boolean", 1, is_boolean, TestPredFlag); + Yap_InitCPred("is_callable", 1, is_callable, TestPredFlag); + Yap_InitCPred("is_atom", 1, is_atom, TestPredFlag); + Yap_InitCPred("get_predicate_indicator", 4, get_predicate_indicator, 0); } diff --git a/C/modules.c b/C/modules.c index 3aac99e55..798e05cb5 100644 --- a/C/modules.c +++ b/C/modules.c @@ -6,7 +6,7 @@ * * * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * * * -*************************************************************** f*********** +************************************************************************** * * File: modules.c * * Last rev: * @@ -24,7 +24,7 @@ static char SccsId[] = "%W% %G%"; #include "YapHeap.h" #include "Yatom.h" -static Int current_module(USES_REGS1); +static Int currgent_module(USES_REGS1); static Int current_module1(USES_REGS1); static ModEntry *LookupModule(Term a); static ModEntry *LookupSystemModule(Term a); diff --git a/C/utilpreds.c b/C/utilpreds.c index 903c08ca2..2a60761b5 100644 --- a/C/utilpreds.c +++ b/C/utilpreds.c @@ -93,12 +93,12 @@ typedef struct non_single_struct_t { #define def_trail_overflow() \ trail_overflow:{ \ - pop_text_stack(lvl);\ while (to_visit > to_visit0) {\ to_visit --;\ CELL *ptd0 = to_visit->ptd0;\ *ptd0 = to_visit->d0;\ }\ + pop_text_stack(lvl);\ LOCAL_Error_TYPE = RESOURCE_ERROR_TRAIL;\ LOCAL_Error_Size = (TR-TR0)*sizeof(tr_fr_ptr *);\ clean_tr(TR0 PASS_REGS);\ @@ -640,7 +640,7 @@ break_rationals_complex_term(CELL *pt0, CELL *pt0_end, CELL *ptf, Term *vout, Te { if (IsPairTerm(d0)) { CELL *ap2 = RepPair(d0); - fprintf(stderr, "%d \n", RepPair(ap2[0])- ptf); + //fprintf(stderr, "%d \n", RepPair(ap2[0])- ptf); if (IsVarTerm(ap2[0]) && IN_BETWEEN(HB, (ap2[0]),HR)) { Term v = MkVarTerm(); *ptf = v; @@ -2656,13 +2656,13 @@ static Int ground_complex_term(register CELL *pt0, register CELL *pt0_end USES_R derefa_body(d0, ptd0, vars_in_term_unk, vars_in_term_nvar); - pop_text_stack(lvl); while (to_visit > to_visit0) { to_visit --; CELL *ptd0 = to_visit->ptd0; *ptd0 = to_visit->d0; } - return FALSE; + pop_text_stack(lvl); + return false; } /* Do we still have compound terms to visit */ if (to_visit > to_visit0) { @@ -2675,7 +2675,7 @@ static Int ground_complex_term(register CELL *pt0, register CELL *pt0_end USES_R goto restart; } pop_text_stack(lvl); - return TRUE; + return true; def_aux_overflow(); } @@ -4340,6 +4340,7 @@ int vsc; static Int numbervars_in_complex_term(register CELL *pt0, register CELL *pt0_end, Int numbv, int singles USES_REGS) { + int lvl = push_text_stack(); struct non_single_struct_t @@ -4480,6 +4481,7 @@ unnumber_complex_term(CELL *pt0, CELL *pt0_end, CELL *ptf, CELL *HLow, int share int ground = share; Int max = -1; + int lvl = push_text_stack(); HB = HLow; to_visit0 = to_visit; loop: @@ -4501,7 +4503,6 @@ unnumber_complex_term(CELL *pt0, CELL *pt0_end, CELL *ptf, CELL *HLow, int share } *ptf = AbsPair(HR); ptf++; -#ifdef RATIONAL_TREES if (to_visit+1 >= (struct cp_frame *)AuxSp) { goto heap_overflow; } @@ -4513,18 +4514,6 @@ unnumber_complex_term(CELL *pt0, CELL *pt0_end, CELL *ptf, CELL *HLow, int share /* fool the system into thinking we had a variable there */ *pt0 = AbsPair(HR); to_visit ++; -#else - if (pt0 < pt0_end) { - if (to_visit+1 >= (struct cp_frame *)AuxSp) { - goto heap_overflow; - } - to_visit->start_cp = pt0; - to_visit->end_cp = pt0_end; - to_visit->to = ptf; - to_visit->ground = ground; - to_visit ++; - } -#endif ground = share; pt0 = ap2 - 1; pt0_end = ap2 + 1; @@ -4553,6 +4542,7 @@ unnumber_complex_term(CELL *pt0, CELL *pt0_end, CELL *ptf, CELL *HLow, int share Int id = IntegerOfTerm(ap2[1]); ground = FALSE; if (id < -1) { + pop_text_stack(lvl); Yap_Error(RESOURCE_ERROR_STACK, TermNil, "unnumber vars cannot cope with VAR(-%d)", id); return 0L; } @@ -4587,7 +4577,6 @@ unnumber_complex_term(CELL *pt0, CELL *pt0_end, CELL *ptf, CELL *HLow, int share *ptf = AbsAppl(HR); ptf++; /* store the terms to visit */ -#ifdef RATIONAL_TREES if (to_visit+1 >= (struct cp_frame *)AuxSp) { goto heap_overflow; } @@ -4599,18 +4588,6 @@ unnumber_complex_term(CELL *pt0, CELL *pt0_end, CELL *ptf, CELL *HLow, int share /* fool the system into thinking we had a variable there */ *pt0 = AbsAppl(HR); to_visit ++; -#else - if (pt0 < pt0_end) { - if (to_visit+1 >= (struct cp_frame *)AuxSp) { - goto heap_overflow; - } - to_visit->start_cp = pt0; - to_visit->end_cp = pt0_end; - to_visit->to = ptf; - to_visit->ground = ground; - to_visit ++; - } -#endif ground = (f != FunctorMutable) && share; d0 = ArityOfFunctor(f); pt0 = ap2; @@ -4661,6 +4638,7 @@ unnumber_complex_term(CELL *pt0, CELL *pt0_end, CELL *ptf, CELL *HLow, int share /* restore our nice, friendly, term to its original state */ clean_dirty_tr(TR0 PASS_REGS); HB = HB0; + pop_text_stack(lvl); return ground; overflow: @@ -4669,7 +4647,6 @@ unnumber_complex_term(CELL *pt0, CELL *pt0_end, CELL *ptf, CELL *HLow, int share /* we've done it */ /* restore our nice, friendly, term to its original state */ HB = HB0; -#ifdef RATIONAL_TREES while (to_visit > to_visit0) { to_visit --; pt0 = to_visit->start_cp; @@ -4677,9 +4654,9 @@ unnumber_complex_term(CELL *pt0, CELL *pt0_end, CELL *ptf, CELL *HLow, int share ptf = to_visit->to; *pt0 = to_visit->oldv; } -#endif reset_trail(TR0); /* follow chain of multi-assigned variables */ + pop_text_stack(lvl); return -1; heap_overflow: @@ -4688,7 +4665,6 @@ unnumber_complex_term(CELL *pt0, CELL *pt0_end, CELL *ptf, CELL *HLow, int share /* we've done it */ /* restore our nice, friendly, term to its original state */ HB = HB0; -#ifdef RATIONAL_TREES while (to_visit > to_visit0) { to_visit --; pt0 = to_visit->start_cp; @@ -4696,9 +4672,9 @@ unnumber_complex_term(CELL *pt0, CELL *pt0_end, CELL *ptf, CELL *HLow, int share ptf = to_visit->to; *pt0 = to_visit->oldv; } -#endif reset_trail(TR0); LOCAL_Error_Size = (ADDR)AuxSp-(ADDR)to_visit0; + pop_text_stack(lvl); return -3; } diff --git a/C/yap-args.c b/C/yap-args.c index 45eb54fff..f03161571 100755 --- a/C/yap-args.c +++ b/C/yap-args.c @@ -76,11 +76,13 @@ static void init_globals(YAP_init_args *yap_init) { #endif /* YAPOR || TABLING */ #ifdef YAPOR Yap_init_yapor_workers(); + if ( #if YAPOR_THREADS - if (Yap_thread_self() != 0) { + Yap_thread_self() != 0 #else - if (worker_id != 0) { + worker_id != 0 #endif + ) { #if defined(YAPOR_COPY) || defined(YAPOR_SBA) /* In the SBA we cannot just happily inherit registers @@ -96,7 +98,7 @@ static void init_globals(YAP_init_args *yap_init) { P = GETWORK_FIRST_TIME; Yap_exec_absmi(FALSE, YAP_EXEC_ABSMI); Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, - "abstract machine unexpected exit (YAP_Init)"); + "abstract machine unexpected exit (YAP_Init)"); } #endif /* YAPOR */ RECOVER_MACHINE_REGS(); @@ -118,25 +120,25 @@ static void init_globals(YAP_init_args *yap_init) { } if (yap_init->PrologRCFile) { Yap_PutValue(AtomConsultOnBoot, - MkAtomTerm(Yap_LookupAtom(yap_init->PrologRCFile))); + MkAtomTerm(Yap_LookupAtom(yap_init->PrologRCFile))); /* This must be done again after restore, as yap_flags has been overwritten .... */ setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG, - yap_init->HaltAfterBoot); + yap_init->HaltAfterBoot); } if (yap_init->PrologTopLevelGoal) { Yap_PutValue(AtomTopLevelGoal, - MkAtomTerm(Yap_LookupAtom(yap_init->PrologTopLevelGoal))); + MkAtomTerm(Yap_LookupAtom(yap_init->PrologTopLevelGoal))); } if (yap_init->PrologGoal) { Yap_PutValue(AtomInitGoal, - MkAtomTerm(Yap_LookupAtom(yap_init->PrologGoal))); + MkAtomTerm(Yap_LookupAtom(yap_init->PrologGoal))); } if (yap_init->PrologAddPath) { Yap_PutValue(AtomExtendFileSearchPath, - MkAtomTerm(Yap_LookupAtom(yap_init->PrologAddPath))); + MkAtomTerm(Yap_LookupAtom(yap_init->PrologAddPath))); } if (yap_init->QuietMode) { @@ -144,9 +146,10 @@ static void init_globals(YAP_init_args *yap_init) { } } + const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR, - *Yap_PLDIR, *Yap_BOOTSTRAP, *Yap_COMMONSDIR, *Yap_INPUT_STARTUP, - *Yap_OUTPUT_STARTUP, *Yap_SOURCEBOOT, *Yap_INCLUDEDIR, *Yap_PLBOOTDIR; + *Yap_PLDIR, *Yap_BOOTSTRAP, *Yap_COMMONSDIR, *Yap_INPUT_STARTUP, + *Yap_OUTPUT_STARTUP, *Yap_SOURCEBOOT, *Yap_INCLUDEDIR, *Yap_PLBOOTDIR; /** * consult loop in C: used to boot the system, butt supports goal execution and @@ -157,21 +160,21 @@ static bool load_file(const char *b_file USES_REGS) { Term t; int c_stream, osno, oactive; - Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1); + Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1); Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1); Functor functor_compile2 = Yap_MkFunctor(Yap_LookupAtom("c_compile"), 1); /* consult in C */ int lvl = push_text_stack(); char *full; - /* the consult mode does not matter here, really */ + /* the consult mode does not matter here, really */ if ((osno = Yap_CheckAlias(AtomLoopStream)) < 0) { osno = 0; } c_stream = YAP_InitConsult(YAP_BOOT_MODE, b_file, &full, &oactive); - __android_log_print( - ANDROID_LOG_INFO, "YAPDroid", "done init_ consult %s ",b_file); - if (c_stream < 0) { + __android_log_print( + ANDROID_LOG_INFO, "YAPDroid", "done init_consult %s ",b_file); + if (c_stream < 0) { fprintf(stderr, "[ FATAL ERROR: could not open file %s ]\n", b_file); pop_text_stack(lvl); exit(1); @@ -181,51 +184,54 @@ static bool load_file(const char *b_file USES_REGS) { return false; } __android_log_print( - ANDROID_LOG_INFO, "YAPDroid", "do reset %s ",b_file); + ANDROID_LOG_INFO, "YAPDroid", "do reset %s ",b_file); - do { + while (t != TermEof) { CACHE_REGS - YAP_Reset(YAP_FULL_RESET, false); - Yap_StartSlots(); + YAP_Reset(YAP_FULL_RESET, false); + Yap_StartSlots(); Term vs = MkVarTerm(), pos = MkVarTerm(); t = YAP_ReadClauseFromStream(c_stream, vs, pos); // Yap_GetNèwSlot(t); - if (t == TermEof) - break; - if (t == 0) { - fprintf(stderr, "[ %s:%d: error: SYNTAX ERROR\n", - b_file, GLOBAL_Stream[c_stream].linecount); - break; - } -// -// { -// 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); - } else if (IsApplTerm(t) && (FunctorOfTerm(t) == functor_query || - FunctorOfTerm(t) == functor_command1)) { + if (t == TermEof || t == TermNil) { + continue; + } else if (t == 0) { + fprintf(stderr, "%s:" Int_FORMAT " :0: error: SYNTAX ERROR\n", + b_file, GLOBAL_Stream[c_stream].linecount); + // + // { + // char buu[1024]; + //1 + // YAP_WriteBuffer(t, buu, 1023, 0); + // fprintf(stderr, "[ %s ]\n" , buu); + // } + continue; + } else if (IsVarTerm(t)) { + fprintf(stderr, "%s:" Int_FORMAT ":0: error: unbound or NULL parser output\n\n", + b_file, + GLOBAL_Stream[c_stream].linecount); + continue; + } else if (IsApplTerm(t) && + (FunctorOfTerm(t) == functor_query || + FunctorOfTerm(t) == functor_command1)) { t = ArgOfTerm(1, t); if (IsApplTerm(t) && FunctorOfTerm(t) == functor_compile2) { - load_file(RepAtom(AtomOfTerm(ArgOfTerm(1, t)))->StrOfAE); + load_file(RepAtom(AtomOfTerm(ArgOfTerm(1, t)))->StrOfAE); Yap_ResetException(LOCAL_ActiveError); + continue; } else { - YAP_RunGoalOnce(t); + YAP_RunGoalOnce(t); } } else { YAP_CompileClause(t); } + yap_error_descriptor_t *errd; - if ((errd = Yap_GetException(LOCAL_ActiveError)) && (errd->errorNo != YAP_NO_ERROR)) { - fprintf(stderr, "%s:%ld:0: Error %s %s Found\n", errd->errorFile, - (long int)errd->errorLine, errd->classAsText, errd->errorAsText); + if ((errd = Yap_GetException(LOCAL_ActiveError)) && + (errd->errorNo != YAP_NO_ERROR)) { + fprintf(stderr, "%s:" Int_FORMAT ":0: error: %s/%s %s\n\n", b_file, errd->errorLine, errd->errorAsText, errd->classAsText, errd->errorMsg); } - } while (true); + } BACKUP_MACHINE_REGS(); YAP_EndConsult(c_stream, &osno, full); if (!Yap_AddAlias(AtomLoopStream, osno)) { @@ -233,24 +239,24 @@ static bool load_file(const char *b_file USES_REGS) { return false; } pop_text_stack(lvl); - return true; + return t == TermEof; } static const char * EOLIST ="EOLINE"; - static bool is_install; +static bool is_install; - static bool is_dir( const char *path, const void *info) { - if (is_install) - return true; +static bool is_dir( const char *path, const void *info) { + if (is_install) + return true; - if (Yap_isDirectory( path )) - return true; - char s[YAP_FILENAME_MAX + 1]; - Int i = strlen(path); - strncpy(s, path, YAP_FILENAME_MAX); + if (Yap_isDirectory( path )) + return true; + char s[YAP_FILENAME_MAX + 1]; + Int i = strlen(path); + strncpy(s, path, YAP_FILENAME_MAX); while (--i) { if (Yap_dir_separator((int)path[i])) - break; + break; } if (i == 0) { s[0] = '.'; @@ -258,80 +264,84 @@ static const char * EOLIST ="EOLINE"; } s[i] = '\0'; if (info == NULL) - return true; + return true; return strcmp(info,s) == 0 || Yap_isDirectory( s ); - } - - static bool is_file( const char *path, const void *info) { - if (is_install) - return true; - return Yap_Exists( path ); - } - - static bool is_wfile( const char *path, const void *info) { - - return true; - } +} + +static bool is_file( const char *path, const void *info) { + if (is_install) + return true; + return Yap_Exists( path ); +} + +static bool is_wfile( const char *path, const void *info) { + + return true; +} - typedef bool testf(const char *s, const void *info); +typedef bool testf(const char *s, const void *info); /// /// - static const char *sel( - testf test, const void *info, const char *s1, ...) { - const char *fmt = s1; -va_list ap; - char *buf = malloc(FILENAME_MAX + 1); +static const char *sel( + testf test, const void *info, const char *s1, ...) { + const char *fmt = s1; + va_list ap; + char *buf = malloc(FILENAME_MAX + 1); - va_start(ap, s1); - while (fmt != EOLIST) { - if (fmt == NULL || fmt[0]=='\0') { - fmt = va_arg(ap, const char *); - continue; - } - strncpy(buf, fmt, FILENAME_MAX); // Yap_AbsoluteFile(fmt,true), FILENAME_MAX); - if (test(buf,info)) { - buf = realloc(buf, strlen(buf) + 1); - va_end(ap); - return buf; - } - fmt = va_arg(ap, const char *); - } - - va_end(ap); - free(buf); -return NULL; + va_start(ap, s1); + while (fmt != EOLIST) { + if (fmt == NULL || fmt[0]=='\0') { + fmt = va_arg(ap, const char *); + continue; } + strncpy(buf, fmt, FILENAME_MAX); // Yap_AbsoluteFile(fmt,true), FILENAME_MAX); + if (test(buf,info)) { + buf = realloc(buf, strlen(buf) + 1); + va_end(ap); + return buf; + } + fmt = va_arg(ap, const char *); + } + + va_end(ap); + free(buf); + return NULL; +} static const char *join(const char *s0, const char *s1) { CACHE_REGS - if (!s0 || s0[0] == '\0') - return s1; + if (!s0 || s0[0] == '\0') { + if (s1 && s1[0]) + return s1; + else + return NULL; + } if (!s1 || s1[0] == '\0') return s0; // int lvl = push_text_stack(); char *buf = malloc(strlen(s0)+strlen(s1) + 2); strcpy(buf, s0); if (Yap_dir_separator(s0[strlen(s0)-1])) { - if (Yap_dir_separator(s1[0])) { - s1 += 1; - } + if (Yap_dir_separator(s1[0])) { + s1 += 1; + } } else { if (!Yap_dir_separator(s1[0]-1)) { - strcat(buf, "/"); - } + strcat(buf, "/"); + } } strcat(buf, s1); return buf; } static void Yap_set_locations(YAP_init_args *iap) { -is_install= iap->install; + is_install= iap->install; /// ROOT_DIR is the home of the YAP system. It can be: /// -- provided by the user; /// -- obtained from DESTDIR + DE=efalkRoot @@ -339,136 +349,137 @@ is_install= iap->install; /// It is: // --_not useful in Android, WIN32; /// -- DESTDIR/ in Anaconda - /// -- /usr/locall in most Unix style systems - Yap_ROOTDIR = sel( is_dir, NULL, - iap->ROOTDIR, - getenv("YAPROOTDIR"), - join(getenv("DESTDIR"), YAP_ROOTDIR), + /// -- /usr/loca77l in most Unix style systems + Yap_ROOTDIR = sel( is_dir, NULL, + iap->ROOTDIR, + getenv("YAPROOTDIR"), + join(getenv("DESTDIR"), YAP_ROOTDIR), #if __ANDROID__ - "/", + "/", #else - join(getenv("DESTDIR"), YAP_ROOTDIR), - join(getenv("DESTDIR"), join(getenv("ḦOME"),".local")), - join(getenv("DESTDIR"), "/usr/local"), - join(getenv("DESTDIR"), "/usr"), - join(getenv("DESTDIR"), "/opt"), + join(getenv("DESTDIR"), YAP_ROOTDIR), + join(getenv("DESTDIR"), join(getenv("ḦOME"),".local")), + join(getenv("DESTDIR"), "/usr/local"), + join(getenv("DESTDIR"), "/usr"), + join(getenv("DESTDIR"), "/opt"), #endif - EOLIST - ); - __android_log_print( - ANDROID_LOG_INFO,"YAPDroid", "Yap_ROOTDIR %s", Yap_ROOTDIR); + EOLIST + ); + __android_log_print( + ANDROID_LOG_INFO,"YAPDroid", "Yap_ROOTDIR %s", Yap_ROOTDIR); - /// BINDIR: where the OS stores header files, namely libYap... - Yap_BINDIR = sel( is_dir, Yap_ROOTDIR, iap->BINDIR, - getenv("YAPBINDIR"), + /// BINDIR: where the OS stores header files, namely libYap... + Yap_BINDIR = sel( is_dir, Yap_ROOTDIR, iap->BINDIR, + getenv("YAPBINDIR"), #if !defined(__ANDROID__) - join(getenv("DESTDIR"), YAP_BINDIR), + join(getenv("DESTDIR"), YAP_BINDIR), #endif - join(Yap_ROOTDIR, "bin"), - EOLIST); + join(Yap_ROOTDIR, "bin"), + EOLIST); /// LIBDIR: where the OS stores dynamic libraries, namely libYap... - Yap_LIBDIR = sel( is_dir, Yap_ROOTDIR, iap->LIBDIR, + Yap_LIBDIR = sel( is_dir, Yap_ROOTDIR, iap->LIBDIR, #if !defined(__ANDROID__) - join(getenv("DESTDIR"), YAP_LIBDIR), + join(getenv("DESTDIR"), YAP_LIBDIR), #endif - join(Yap_ROOTDIR, "lib"), - EOLIST); + join(Yap_ROOTDIR, "lib"), + EOLIST); /// DLLDIR: where libraries can find expicitely loaded DLLs - Yap_DLLDIR = sel(is_dir, Yap_LIBDIR, iap->DLLDIR, - getenv("YAPLIBDIR"), - join(getenv("DESTDIR"), YAP_DLLDIR), - join(Yap_LIBDIR, "/Yap"), - EOLIST); + Yap_DLLDIR = sel(is_dir, Yap_LIBDIR, iap->DLLDIR, + getenv("YAPLIBDIR"), + join(getenv("DESTDIR"), YAP_DLLDIR), + join(Yap_DLLDIR, "Yap"), + EOLIST); /// INCLUDEDIR: where the OS stores header files, namely libYap... - Yap_INCLUDEDIR = sel(is_dir, Yap_ROOTDIR, iap->INCLUDEDIR, + Yap_INCLUDEDIR = sel(is_dir, Yap_ROOTDIR, iap->INCLUDEDIR, #if !defined(__ANDROID__) - join(getenv("DESTDIR"), YAP_INCLUDEDIR), + join(getenv("DESTDIR"), YAP_INCLUDEDIR), #endif join(Yap_ROOTDIR, "include"), EOLIST); - /// SHAREDIR: where OS & ARCH independent files live - Yap_SHAREDIR = sel( is_dir, Yap_ROOTDIR, iap->SHAREDIR, - getenv("YAPSHAREDIR"), + /// SHAREDIR: where OS & ARCH independent files live + Yap_SHAREDIR = sel( is_dir, Yap_ROOTDIR, iap->SHAREDIR, + getenv("YAPSHAREDIR"), #if __ANDROID__ - "/data/data/pt.up.yap/files", - "/assets", + "/data/data/pt.up.yap/files", + "/assets", #endif - join(getenv("DESTDIR"), YAP_SHAREDIR), - join(Yap_ROOTDIR, "share"), - join(Yap_ROOTDIR, "files"), - EOLIST); - __android_log_print( - ANDROID_LOG_INFO,"YAPDroid", "Yap_SHAREDIR %s", Yap_SHAREDIR); + join(getenv("DESTDIR"), YAP_SHAREDIR), + join(Yap_ROOTDIR, "share"), + join(Yap_ROOTDIR, "files"), + 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, - join(getenv("DESTDIR"), join(Yap_SHAREDIR, "Yap")), - join(getenv("DESTDIR"), YAP_PLDIR), - EOLIST); + join(getenv("DESTDIR"), join(Yap_SHAREDIR, "Yap")), + EOLIST); - __android_log_print( - ANDROID_LOG_INFO, "YAPDroid","Yap_PLDIR %s", Yap_PLDIR); + __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, - join(getenv("DESTDIR"), join(Yap_SHAREDIR, "PrologCommons")), - EOLIST); + join(getenv("DESTDIR"), join(Yap_SHAREDIR, "PrologCommons")), + EOLIST); /// SOURCEBOOT: booting from the Prolog boot file at compilation-time so we should not assume pl is installed. - Yap_SOURCEBOOT = sel( is_file, Yap_AbsoluteFile("pl",false), iap->SOURCEBOOT, - YAP_SOURCEBOOT, - "boot.yap", - EOLIST); - __android_log_print( - ANDROID_LOG_INFO, "YAPDroid","Yap_SOURCEBOOT %s", Yap_SOURCEBOOT); - Yap_PLBOOTDIR = sel( is_dir, Yap_PLDIR, iap->BOOTDIR, - join(getenv("DESTDIR"),join(Yap_PLDIR, "pl")), - EOLIST); - __android_log_print( - ANDROID_LOG_INFO, "YAPDroid","Yap_BOOTSTRAP %s", Yap_BOOTSTRAP); -/// BOOTSTRAP: booting from the Prolog boot file after YAP is installed - Yap_BOOTSTRAP = sel( is_file, Yap_PLBOOTDIR, iap->BOOTSTRAP, - join(getenv("DESTDIR"),YAP_BOOTSTRAP), - join(getenv("DESTDIR"),join(Yap_PLBOOTDIR, "boot.yap")), - EOLIST); - __android_log_print( - ANDROID_LOG_INFO,"YAPDroid", "Yap_BOOTSTRAP %s", Yap_PLBOOTDIR); + Yap_SOURCEBOOT = sel( is_file, Yap_AbsoluteFile("pl",false), iap->SOURCEBOOT, + YAP_SOURCEBOOT, + "boot.yap", + "../pl/boot.yap", + EOLIST); + __android_log_print( + ANDROID_LOG_INFO, "YAPDroid","Yap_SOURCEBOOT %s", Yap_SOURCEBOOT); + + Yap_PLBOOTDIR = sel( is_dir, Yap_PLDIR, iap->BOOTDIR, + join(getenv("DESTDIR"),join(Yap_PLDIR, "pl")), + EOLIST); + __android_log_print( + ANDROID_LOG_INFO, "YAPDroid","Yap_BOOTSTRAP %s", Yap_BOOTSTRAP); + /// BOOTSTRAP: booting from the Prolog boot file after YAP is installed + Yap_BOOTSTRAP = sel( is_file, Yap_PLBOOTDIR, iap->BOOTSTRAP, + join(getenv("DESTDIR"),YAP_BOOTSTRAP), + join(getenv("DESTDIR"),join(Yap_PLBOOTDIR, "boot.yap")), + EOLIST); + __android_log_print( + ANDROID_LOG_INFO,"YAPDroid", "Yap_BOOTSTRAP %s", Yap_PLBOOTDIR); /// STARTUP: where we can find the core Prolog bootstrap file Yap_OUTPUT_STARTUP = - sel( is_wfile, ".", iap->OUTPUT_STARTUP, - YAP_OUTPUT_STARTUP, - join(getenv("DESTDIR"), join(Yap_DLLDIR, "startup.yss")), - join(getenv("DESTDIR"), join(Yap_DLLDIR,iap->OUTPUT_STARTUP)), - "startup.yss", - EOLIST); + sel( is_wfile, ".", iap->OUTPUT_STARTUP, + YAP_OUTPUT_STARTUP, + join(getenv("DESTDIR"), join(Yap_DLLDIR, "startup.yss")), + join(getenv("DESTDIR"), join(Yap_DLLDIR,iap->OUTPUT_STARTUP)), + "startup.yss", + EOLIST); Yap_INPUT_STARTUP = sel( is_file, Yap_DLLDIR, iap->INPUT_STARTUP, - "startup.yss", - join(getenv("DESTDIR"), join(Yap_DLLDIR, "startup.yss")), + "startup.yss", + join(getenv("DESTDIR"), join(Yap_DLLDIR, "startup.yss")), #if !defined(__ANDROID__) - join(getenv("DESTDIR"), YAP_INPUT_STARTUP), + join(getenv("DESTDIR"), YAP_INPUT_STARTUP), #endif - "/usr/local/lib/Yap/startup.yss", - "/usr/lib/Yap/startup.yss", - EOLIST); + "/usr/local/lib/Yap/startup.yss", + "/usr/lib/Yap/startup.yss", + EOLIST); - if (Yap_ROOTDIR) + if (Yap_ROOTDIR) setAtomicGlobalPrologFlag(HOME_FLAG, - MkAtomTerm(Yap_LookupAtom(Yap_ROOTDIR))); + MkAtomTerm(Yap_LookupAtom(Yap_ROOTDIR))); if (Yap_PLDIR) setAtomicGlobalPrologFlag(PROLOG_LIBRARY_DIRECTORY_FLAG, - MkAtomTerm(Yap_LookupAtom(Yap_PLDIR))); + MkAtomTerm(Yap_LookupAtom(Yap_PLDIR))); if (Yap_DLLDIR) setAtomicGlobalPrologFlag(PROLOG_FOREIGN_DIRECTORY_FLAG, - MkAtomTerm(Yap_LookupAtom(Yap_DLLDIR))); + MkAtomTerm(Yap_LookupAtom(Yap_DLLDIR))); } static void print_usage(void) { @@ -485,16 +496,16 @@ static void print_usage(void) { fprintf(stderr, " -L run Prolog file and exit\n"); fprintf(stderr, " -p extra path for file-search-path\n"); fprintf(stderr, " -hSize Heap area in Kbytes (default: %d, minimum: %d)\n", - DefHeapSpace, MinHeapSpace); + DefHeapSpace, MinHeapSpace); fprintf(stderr, - " -sSize Stack area in Kbytes (default: %d, minimum: %d)\n", - DefStackSpace, MinStackSpace); + " -sSize Stack area in Kbytes (default: %d, minimum: %d)\n", + DefStackSpace, MinStackSpace); fprintf(stderr, - " -tSize Trail area in Kbytes (default: %d, minimum: %d)\n", - DefTrailSpace, MinTrailSpace); + " -tSize Trail area in Kbytes (default: %d, minimum: %d)\n", + DefTrailSpace, MinTrailSpace); fprintf(stderr, " -GSize Max Area for Global Stack\n"); fprintf(stderr, - " -LSize Max Area for Local Stack (number must follow L)\n"); + " -LSize Max Area for Local Stack (number must follow L)\n"); fprintf(stderr, " -TSize Max Area for Trail (number must follow T)\n"); fprintf(stderr, " -nosignals disable signal handling from Prolog\n"); fprintf(stderr, "\n[Execution Modes]\n"); @@ -506,18 +517,18 @@ static void print_usage(void) { #ifdef TABLING fprintf(stderr, - " -ts Maximum table space area in Mbytes (default: unlimited)\n"); + " -ts Maximum table space area in Mbytes (default: unlimited)\n"); #endif /* TABLING */ -#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \ - defined(YAPOR_THREADS) +#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \ + defined(YAPOR_THREADS) fprintf(stderr, " -w Number of workers (default: %d)\n", - DEFAULT_NUMBERWORKERS); + DEFAULT_NUMBERWORKERS); fprintf(stderr, - " -sl Loop scheduler executions before look for hiden " - "shared work (default: %d)\n", - DEFAULT_SCHEDULERLOOP); + " -sl Loop scheduler executions before look for hiden " + "shared work (default: %d)\n", + DEFAULT_SCHEDULERLOOP); fprintf(stderr, " -d Value of delayed release of load (default: %d)\n", - DEFAULT_DELAYEDRELEASELOAD); + DEFAULT_DELAYEDRELEASELOAD); #endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA || YAPOR_THREADS */ /* nf: Preprocessor */ /* fprintf(stderr," -DVar=Name Persistent definition\n"); */ @@ -564,14 +575,14 @@ static int dump_runtime_variables(void) { } X_API YAP_file_type_t Yap_InitDefaults(void *x, char *saved_state, int argc, - char *argv[]) { + char *argv[]) { if (!LOCAL_TextBuffer) LOCAL_TextBuffer = Yap_InitTextAllocator(); YAP_init_args *iap = x; memset(iap, 0, sizeof(YAP_init_args)); - iap->Argc = argc; - iap->Argv = argv; + iap->Argc = argc; + iap->Argv = argv; #if __ANDROID__ iap->boot_file_type = YAP_PL; iap->INPUT_STARTUP = NULL; @@ -601,401 +612,401 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_a if (*p == '-') switch (*++p) { case 'b': - iap->boot_file_type = YAP_PL; - if (p[1]) - iap->BOOTSTRAP = p + 1; - else if (argv[1] && *argv[1] != '-') { - iap->BOOTSTRAP = *++argv; - argc--; - } - break; + iap->boot_file_type = YAP_PL; + if (p[1]) + iap->BOOTSTRAP = p + 1; + else if (argv[1] && *argv[1] != '-') { + iap->BOOTSTRAP = *++argv; + argc--; + } + break; case 'B': - iap->boot_file_type = YAP_SOURCE_PL; - if (p[1]) - iap->SOURCEBOOT = p + 1; - else if (argv[1] && *argv[1] != '-') { - iap->SOURCEBOOT = *++argv; - argc--; - } - iap->install = true; - break; + iap->boot_file_type = YAP_SOURCE_PL; + if (p[1]) + iap->SOURCEBOOT = p + 1; + else if (argv[1] && *argv[1] != '-') { + iap->SOURCEBOOT = *++argv; + argc--; + } + iap->install = true; + break; case '?': - print_usage(); - exit(EXIT_SUCCESS); + print_usage(); + exit(EXIT_SUCCESS); case 'q': - iap->QuietMode = TRUE; - break; -#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \ - defined(YAPOR_THREADS) + iap->QuietMode = TRUE; + break; +#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \ + defined(YAPOR_THREADS) case 'w': - ssize = &(iap->NumberWorkers); - goto GetSize; + ssize = &(iap->NumberWorkers); + goto GetSize; case 'd': - if (!strcmp("dump-runtime-variables", p)) - return dump_runtime_variables(); - ssize = &(iap->DelayedReleaseLoad); - goto GetSize; + if (!strcmp("dump-runtime-variables", p)) + return dump_runtime_variables(); + ssize = &(iap->DelayedReleaseLoad); + goto GetSize; #else case 'd': - if (!strcmp("dump-runtime-variables", p)) - return dump_runtime_variables(); + if (!strcmp("dump-runtime-variables", p)) + return dump_runtime_variables(); #endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA || YAPOR_THREADS */ case 'F': - /* just ignore for now */ - argc--; - argv++; - break; + /* just ignore for now */ + argc--; + argv++; + break; case 'f': - iap->FastBoot = TRUE; - if (argc > 1 && argv[1][0] != '-') { - argc--; - argv++; - if (strcmp(*argv, "none")) { - iap->PrologRCFile = *argv; - } - break; - } - break; - // execution mode + iap->FastBoot = TRUE; + if (argc > 1 && argv[1][0] != '-') { + argc--; + argv++; + if (strcmp(*argv, "none")) { + iap->PrologRCFile = *argv; + } + break; + } + break; + // execution mode case 'J': - switch (p[1]) { - case '0': - iap->ExecutionMode = YAPC_INTERPRETED; - break; - case '1': - iap->ExecutionMode = YAPC_MIXED_MODE_USER; - break; - case '2': - iap->ExecutionMode = YAPC_MIXED_MODE_ALL; - break; - case '3': - iap->ExecutionMode = YAPC_COMPILE_USER; - break; - case '4': - iap->ExecutionMode = YAPC_COMPILE_ALL; - break; - default: - fprintf(stderr, "[ YAP unrecoverable error: unknown switch -%c%c ]\n", - *p, p[1]); - exit(EXIT_FAILURE); - } - p++; - break; + switch (p[1]) { + case '0': + iap->ExecutionMode = YAPC_INTERPRETED; + break; + case '1': + iap->ExecutionMode = YAPC_MIXED_MODE_USER; + break; + case '2': + iap->ExecutionMode = YAPC_MIXED_MODE_ALL; + break; + case '3': + iap->ExecutionMode = YAPC_COMPILE_USER; + break; + case '4': + iap->ExecutionMode = YAPC_COMPILE_ALL; + break; + default: + fprintf(stderr, "[ YAP unrecoverable error: unknown switch -%c%c ]\n", + *p, p[1]); + exit(EXIT_FAILURE); + } + p++; + break; case 'G': - ssize = &(iap->MaxGlobalSize); - goto GetSize; - break; + ssize = &(iap->MaxGlobalSize); + goto GetSize; + break; case 's': case 'S': - ssize = &(iap->StackSize); -#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \ - defined(YAPOR_THREADS) - if (p[1] == 'l') { - p++; - ssize = &(iap->SchedulerLoop); - } + ssize = &(iap->StackSize); +#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \ + defined(YAPOR_THREADS) + if (p[1] == 'l') { + p++; + ssize = &(iap->SchedulerLoop); + } #endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA || YAPOR_THREADS */ - goto GetSize; + goto GetSize; case 'a': case 'A': - ssize = &(iap->AttsSize); - goto GetSize; + ssize = &(iap->AttsSize); + goto GetSize; case 'T': - ssize = &(iap->MaxTrailSize); - goto get_trail_size; + ssize = &(iap->MaxTrailSize); + goto get_trail_size; case 't': - ssize = &(iap->TrailSize); + ssize = &(iap->TrailSize); #ifdef TABLING - if (p[1] == 's') { - p++; - ssize = &(iap->MaxTableSpaceSize); - } + if (p[1] == 's') { + p++; + ssize = &(iap->MaxTableSpaceSize); + } #endif /* TABLING */ get_trail_size: - if (*++p == '\0') { - if (argc > 1) - --argc, p = *++argv; - else { - fprintf(stderr, - "[ YAP unrecoverable error: missing size in flag %s ]", - argv[0]); - print_usage(); - exit(EXIT_FAILURE); - } - } - { - unsigned long int i = 0, ch; - while ((ch = *p++) >= '0' && ch <= '9') - i = i * 10 + ch - '0'; - switch (ch) { - case 'M': - case 'm': - i *= 1024; - ch = *p++; - break; - case 'g': - i *= 1024 * 1024; - ch = *p++; - break; - case 'k': - case 'K': - ch = *p++; - break; - } - if (ch) { - iap->PrologTopLevelGoal = add_end_dot(*argv); - } else { - *ssize = i; - } - } - break; + if (*++p == '\0') { + if (argc > 1) + --argc, p = *++argv; + else { + fprintf(stderr, + "[ YAP unrecoverable error: missing size in flag %s ]", + argv[0]); + print_usage(); + exit(EXIT_FAILURE); + } + } + { + unsigned long int i = 0, ch; + while ((ch = *p++) >= '0' && ch <= '9') + i = i * 10 + ch - '0'; + switch (ch) { + case 'M': + case 'm': + i *= 1024; + ch = *p++; + break; + case 'g': + i *= 1024 * 1024; + ch = *p++; + break; + case 'k': + case 'K': + ch = *p++; + break; + } + if (ch) { + iap->PrologTopLevelGoal = add_end_dot(*argv); + } else { + *ssize = i; + } + } + break; case 'h': case 'H': - ssize = &(iap->HeapSize); + ssize = &(iap->HeapSize); GetSize: - if (*++p == '\0') { - if (argc > 1) - --argc, p = *++argv; - else { - fprintf(stderr, - "[ YAP unrecoverable error: missing size in flag %s ]", - argv[0]); - print_usage(); - exit(EXIT_FAILURE); - } - } - { - unsigned long int i = 0, ch; - while ((ch = *p++) >= '0' && ch <= '9') - i = i * 10 + ch - '0'; - switch (ch) { - case 'M': - case 'm': - i *= 1024; - ch = *p++; - break; - case 'g': - case 'G': - i *= 1024 * 1024; - ch = *p++; - break; - case 'k': - case 'K': - ch = *p++; - break; - } - if (ch) { - fprintf( - stderr, - "[ YAP unrecoverable error: illegal size specification %s ]", - argv[-1]); - Yap_exit(1); - } - *ssize = i; - } - break; + if (*++p == '\0') { + if (argc > 1) + --argc, p = *++argv; + else { + fprintf(stderr, + "[ YAP unrecoverable error: missing size in flag %s ]", + argv[0]); + print_usage(); + exit(EXIT_FAILURE); + } + } + { + unsigned long int i = 0, ch; + while ((ch = *p++) >= '0' && ch <= '9') + i = i * 10 + ch - '0'; + switch (ch) { + case 'M': + case 'm': + i *= 1024; + ch = *p++; + break; + case 'g': + case 'G': + i *= 1024 * 1024; + ch = *p++; + break; + case 'k': + case 'K': + ch = *p++; + break; + } + if (ch) { + fprintf( + stderr, + "[ YAP unrecoverable error: illegal size specification %s ]", + argv[-1]); + Yap_exit(1); + } + *ssize = i; + } + break; #ifdef DEBUG case 'P': - if (p[1] != '\0') { - while (p[1] != '\0') { - int ch = p[1]; - if (ch >= 'A' && ch <= 'Z') - ch += ('a' - 'A'); - if (ch >= 'a' && ch <= 'z') - GLOBAL_Option[ch - 96] = 1; - p++; - } - } else { - YAP_SetOutputMessage(); - } - break; + if (p[1] != '\0') { + while (p[1] != '\0') { + int ch = p[1]; + if (ch >= 'A' && ch <= 'Z') + ch += ('a' - 'A'); + if (ch >= 'a' && ch <= 'z') + GLOBAL_Option[ch - 96] = 1; + p++; + } + } else { + YAP_SetOutputMessage(); + } + break; #endif case 'L': - if (p[1] && p[1] >= '0' && - p[1] <= '9') /* hack to emulate SWI's L local option */ - { - ssize = &(iap->MaxStackSize); - goto GetSize; - } - iap->QuietMode = TRUE; - iap->HaltAfterBoot = true; + if (p[1] && p[1] >= '0' && + p[1] <= '9') /* hack to emulate SWI's L local option */ + { + ssize = &(iap->MaxStackSize); + goto GetSize; + } + iap->QuietMode = TRUE; + iap->HaltAfterBoot = true; case 'l': - p++; - if (!*++argv) { - fprintf(stderr, - "%% YAP unrecoverable error: missing load file name\n"); - exit(1); - } else if (!strcmp("--", *argv)) { - /* shell script, the next entry should be the file itself */ - iap->PrologRCFile = argv[1]; - argc = 1; - break; - } else { - iap->PrologRCFile = *argv; - argc--; - } - if (*p) { - /* we have something, usually, of the form: - -L -- - FileName - ExtraArgs - */ - /* being called from a script */ - while (*p && (*p == ' ' || *p == '\t')) - p++; - if (p[0] == '-' && p[1] == '-') { - /* ignore what is next */ - argc = 1; - } - } - break; - /* run goal before top-level */ + p++; + if (!*++argv) { + fprintf(stderr, + "%% YAP unrecoverable error: missing load file name\n"); + exit(1); + } else if (!strcmp("--", *argv)) { + /* shell script, the next entry should be the file itself */ + iap->PrologRCFile = argv[1]; + argc = 1; + break; + } else { + iap->PrologRCFile = *argv; + argc--; + } + if (*p) { + /* we have something, usually, of the form: + -L -- + FileName + ExtraArgs + */ + /* being called from a script */ + while (*p && (*p == ' ' || *p == '\t')) + p++; + if (p[0] == '-' && p[1] == '-') { + /* ignore what is next */ + argc = 1; + } + } + break; + /* run goal before top-level */ case 'g': - if ((*argv)[0] == '\0') - iap->PrologGoal = *argv; - else { - argc--; - if (argc == 0) { - fprintf(stderr, " [ YAP unrecoverable error: missing " - "initialization goal for option 'g' ]\n"); - exit(EXIT_FAILURE); - } - argv++; - iap->PrologGoal = *argv; - } - break; - /* run goal as top-level */ + if ((*argv)[0] == '\0') + iap->PrologGoal = *argv; + else { + argc--; + if (argc == 0) { + fprintf(stderr, " [ YAP unrecoverable error: missing " + "initialization goal for option 'g' ]\n"); + exit(EXIT_FAILURE); + } + argv++; + iap->PrologGoal = *argv; + } + break; + /* run goal as top-level */ case 'z': - if ((*argv)[0] == '\0') - iap->PrologTopLevelGoal = *argv; - else { - argc--; - if (argc == 0) { - fprintf(stderr, " [ YAP unrecoverable error: missing goal for " - "option 'z' ]\n"); - exit(EXIT_FAILURE); - } - argv++; - iap->PrologTopLevelGoal = add_end_dot(*argv); - } - iap->HaltAfterBoot = true; - break; + if ((*argv)[0] == '\0') + iap->PrologTopLevelGoal = *argv; + else { + argc--; + if (argc == 0) { + fprintf(stderr, " [ YAP unrecoverable error: missing goal for " + "option 'z' ]\n"); + exit(EXIT_FAILURE); + } + argv++; + iap->PrologTopLevelGoal = add_end_dot(*argv); + } + iap->HaltAfterBoot = true; + break; case 'n': - if (!strcmp("nosignals", p)) { - iap->PrologCannotHandleInterrupts = true; - break; - } - break; + if (!strcmp("nosignals", p)) { + iap->PrologCannotHandleInterrupts = true; + break; + } + break; case '-': - if (!strcmp("-nosignals", p)) { - iap->PrologCannotHandleInterrupts = true; - break; - } else if (!strncmp("-output-saved-state=", p, - strlen("-output-saved-state="))) { - iap->OUTPUT_STARTUP = p + strlen("-output-saved-state="); - } else if (!strncmp("-home=", p, strlen("-home="))) { - iap->ROOTDIR = p + strlen("-home="); - } else if (!strncmp("-system-library-directory=", p, - strlen("-system-library-directory="))) { - iap->LIBDIR = p + strlen("-system-library-directory="); - } else if (!strncmp("-system-shared-directory=", p, - strlen("-system-shared-directory="))) { - iap->SHAREDIR = p + strlen("-system-shared-directory="); - } else if (!strncmp("-prolog-library-directory=", p, - strlen("-prolog-library-directory="))) { - iap->PLDIR = p + strlen("-prolog-library-directory="); - } else if (!strncmp("-dll-library-directory=", p, - strlen("-dll-library-directory="))) { - iap->DLLDIR = p + strlen("-dll-library-directory="); - } else if (!strncmp("-home=", p, strlen("-home="))) { - iap->ROOTDIR = p + strlen("-home="); - } else if (!strncmp("-cwd=", p, strlen("-cwd="))) { - if (!Yap_ChDir(p + strlen("-cwd="))) { - fprintf(stderr, " [ YAP unrecoverable error in setting cwd: %s ]\n", - strerror(errno)); - } - } else if (!strncmp("-stack=", p, strlen("-stack="))) { - ssize = &(iap->StackSize); - p += strlen("-stack="); - goto GetSize; - } else if (!strncmp("-trail=", p, strlen("-trail="))) { - ssize = &(iap->TrailSize); - p += strlen("-trail="); - goto GetSize; - } else if (!strncmp("-heap=", p, strlen("-heap="))) { - ssize = &(iap->HeapSize); - p += strlen("-heap="); - goto GetSize; - } else if (!strncmp("-max-stack=", p, strlen("-max-stack="))) { - ssize = &(iap->MaxStackSize); - p += strlen("-max-stack="); - goto GetSize; - } else if (!strncmp("-max-trail=", p, strlen("-max-trail="))) { - ssize = &(iap->MaxTrailSize); - p += strlen("-max-trail="); - goto GetSize; - } else if (!strncmp("-max-heap=", p, strlen("-max-heap="))) { - ssize = &(iap->MaxHeapSize); - p += strlen("-max-heap="); - goto GetSize; - } else if (!strncmp("-goal=", p, strlen("-goal="))) { - iap->PrologGoal = p + strlen("-goal="); - } else if (!strncmp("-top-level=", p, strlen("-top-level="))) { - iap->PrologTopLevelGoal = p + strlen("-top-level="); - } else if (!strncmp("-table=", p, strlen("-table="))) { - ssize = &(iap->MaxTableSpaceSize); - p += strlen("-table="); - goto GetSize; - } else if (!strncmp("-", p, strlen("-="))) { - ssize = &(iap->MaxTableSpaceSize); - p += strlen("-table="); - /* skip remaining arguments */ - argc = 1; - } - break; + if (!strcmp("-nosignals", p)) { + iap->PrologCannotHandleInterrupts = true; + break; + } else if (!strncmp("-output-saved-state=", p, + strlen("-output-saved-state="))) { + iap->OUTPUT_STARTUP = p + strlen("-output-saved-state="); + } else if (!strncmp("-home=", p, strlen("-home="))) { + iap->ROOTDIR = p + strlen("-home="); + } else if (!strncmp("-system-library-directory=", p, + strlen("-system-library-directory="))) { + iap->LIBDIR = p + strlen("-system-library-directory="); + } else if (!strncmp("-system-shared-directory=", p, + strlen("-system-shared-directory="))) { + iap->SHAREDIR = p + strlen("-system-shared-directory="); + } else if (!strncmp("-prolog-library-directory=", p, + strlen("-prolog-library-directory="))) { + iap->PLDIR = p + strlen("-prolog-library-directory="); + } else if (!strncmp("-dll-library-directory=", p, + strlen("-dll-library-directory="))) { + iap->DLLDIR = p + strlen("-dll-library-directory="); + } else if (!strncmp("-home=", p, strlen("-home="))) { + iap->ROOTDIR = p + strlen("-home="); + } else if (!strncmp("-cwd=", p, strlen("-cwd="))) { + if (!Yap_ChDir(p + strlen("-cwd="))) { + fprintf(stderr, " [ YAP unrecoverable error in setting cwd: %s ]\n", + strerror(errno)); + } + } else if (!strncmp("-stack=", p, strlen("-stack="))) { + ssize = &(iap->StackSize); + p += strlen("-stack="); + goto GetSize; + } else if (!strncmp("-trail=", p, strlen("-trail="))) { + ssize = &(iap->TrailSize); + p += strlen("-trail="); + goto GetSize; + } else if (!strncmp("-heap=", p, strlen("-heap="))) { + ssize = &(iap->HeapSize); + p += strlen("-heap="); + goto GetSize; + } else if (!strncmp("-max-stack=", p, strlen("-max-stack="))) { + ssize = &(iap->MaxStackSize); + p += strlen("-max-stack="); + goto GetSize; + } else if (!strncmp("-max-trail=", p, strlen("-max-trail="))) { + ssize = &(iap->MaxTrailSize); + p += strlen("-max-trail="); + goto GetSize; + } else if (!strncmp("-max-heap=", p, strlen("-max-heap="))) { + ssize = &(iap->MaxHeapSize); + p += strlen("-max-heap="); + goto GetSize; + } else if (!strncmp("-goal=", p, strlen("-goal="))) { + iap->PrologGoal = p + strlen("-goal="); + } else if (!strncmp("-top-level=", p, strlen("-top-level="))) { + iap->PrologTopLevelGoal = p + strlen("-top-level="); + } else if (!strncmp("-table=", p, strlen("-table="))) { + ssize = &(iap->MaxTableSpaceSize); + p += strlen("-table="); + goto GetSize; + } else if (!strncmp("-", p, strlen("-="))) { + ssize = &(iap->MaxTableSpaceSize); + p += strlen("-table="); + /* skip remaining arguments */ + argc = 1; + } + break; case 'p': - if ((*argv)[0] == '\0') - iap->PrologAddPath = *argv; - else { - argc--; - if (argc == 0) { - fprintf(stderr, " [ YAP unrecoverable error: missing paths for " - "option 'p' ]\n"); - exit(EXIT_FAILURE); - } - argv++; - iap->PrologAddPath = *argv; - } - break; - /* nf: Begin preprocessor code */ + if ((*argv)[0] == '\0') + iap->PrologAddPath = *argv; + else { + argc--; + if (argc == 0) { + fprintf(stderr, " [ YAP unrecoverable error: missing paths for " + "option 'p' ]\n"); + exit(EXIT_FAILURE); + } + argv++; + iap->PrologAddPath = *argv; + } + break; + /* nf: Begin preprocessor code */ case 'D': { - char *var, *value; - ++p; - var = p; - if (var == NULL || *var == '\0') - break; - while (*p != '=' && *p != '\0') - ++p; - if (*p == '\0') - break; - *p = '\0'; - ++p; - value = p; - if (*value == '\0') - break; - if (iap->def_c == YAP_MAX_YPP_DEFS) - break; - iap->def_var[iap->def_c] = var; - iap->def_value[iap->def_c] = value; - ++(iap->def_c); - break; + char *var, *value; + ++p; + var = p; + if (var == NULL || *var == '\0') + break; + while (*p != '=' && *p != '\0') + ++p; + if (*p == '\0') + break; + *p = '\0'; + ++p; + value = p; + if (*value == '\0') + break; + if (iap->def_c == YAP_MAX_YPP_DEFS) + break; + iap->def_var[iap->def_c] = var; + iap->def_value[iap->def_c] = value; + ++(iap->def_c); + break; } - /* End preprocessor code */ + /* End preprocessor code */ default: { - fprintf(stderr, "[ YAP unrecoverable error: unknown switch -%c ]\n", - *p); - print_usage(); - exit(EXIT_FAILURE); + fprintf(stderr, "[ YAP unrecoverable error: unknown switch -%c ]\n", + *p); + print_usage(); + exit(EXIT_FAILURE); } } else { @@ -1044,20 +1055,20 @@ bool Yap_Embedded; static void init_hw(YAP_init_args *yap_init, struct ssz_t *spt) { Yap_page_size = Yap_InitPageSize(); /* init memory page size, required by - later functions */ + later functions */ #if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) Yap_init_yapor_global_local_memory(); #endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */ if (yap_init->Embedded) { yap_init->install = false; GLOBAL_PrologShouldHandleInterrupts = - yap_init->PrologCannotHandleInterrupts = true; + yap_init->PrologCannotHandleInterrupts = true; } else { GLOBAL_PrologShouldHandleInterrupts = - !yap_init->PrologCannotHandleInterrupts; + !yap_init->PrologCannotHandleInterrupts; } Yap_InitSysbits(0); /* init signal handling and time, required by later - functions */ + functions */ GLOBAL_argv = yap_init->Argv; GLOBAL_argc = yap_init->Argc; @@ -1115,10 +1126,10 @@ static void start_modules(void) { X_API void YAP_Init(YAP_init_args *yap_init) { bool try_restore = yap_init->boot_file_type == YAP_QLY; bool do_bootstrap = yap_init->boot_file_type == YAP_PL || - yap_init->boot_file_type == YAP_SOURCE_PL; + yap_init->boot_file_type == YAP_SOURCE_PL; struct ssz_t minfo; - __android_log_print( - ANDROID_LOG_INFO, "YAPDroid", "start init "); + __android_log_print( + ANDROID_LOG_INFO, "YAPDroid", "start init "); if (YAP_initialized) /* ignore repeated calls to YAP_Init */ return; @@ -1130,14 +1141,14 @@ X_API void YAP_Init(YAP_init_args *yap_init) { minfo.Trail = 0, minfo.Stack = 0, minfo.Trail = 0; init_hw(yap_init, &minfo); Yap_InitWorkspace(yap_init, minfo.Heap, minfo.Stack, minfo.Trail, 0, - yap_init->MaxTableSpaceSize, yap_init->NumberWorkers, - yap_init->SchedulerLoop, yap_init->DelayedReleaseLoad); + yap_init->MaxTableSpaceSize, yap_init->NumberWorkers, + yap_init->SchedulerLoop, yap_init->DelayedReleaseLoad); // CACHE_REGS CurrentModule = PROLOG_MODULE; - if (yap_init->QuietMode) { + if (yap_init->QuietMode) { setVerbosity(TermSilent); } if (yap_init->PrologRCFile != NULL) { @@ -1146,7 +1157,7 @@ X_API void YAP_Init(YAP_init_args *yap_init) { restore will print out messages .... */ setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG, - yap_init->HaltAfterBoot); + yap_init->HaltAfterBoot); } /* tell the system who should cope with interrupts */ Yap_ExecutionMode = yap_init->ExecutionMode; @@ -1156,41 +1167,41 @@ X_API void YAP_Init(YAP_init_args *yap_init) { try_restore = false; if (do_bootstrap || !try_restore || !Yap_SavedInfo(Yap_INPUT_STARTUP, &minfo.Trail, &minfo.Stack, - &minfo.Heap)) { + &minfo.Heap)) { init_globals(yap_init); start_modules(); - TermEof = MkAtomTerm(Yap_LookupAtom("end_of_file")); + TermEof = MkAtomTerm(Yap_LookupAtom("end_of_file")); LOCAL_consult_level = -1; __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))); + load_file(Yap_SOURCEBOOT PASS_REGS); + setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG, + MkAtomTerm(Yap_LookupAtom(Yap_SOURCEBOOT))); } else { - load_file(Yap_BOOTSTRAP PASS_REGS); - setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG, - MkAtomTerm(Yap_LookupAtom(Yap_BOOTSTRAP))); + load_file(Yap_BOOTSTRAP PASS_REGS); + setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG, + MkAtomTerm(Yap_LookupAtom(Yap_BOOTSTRAP))); } CurrentModule = LOCAL_SourceModule = TermUser; - setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false); + setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false); } else { if (yap_init->QuietMode) { - setVerbosity(TermSilent); - } + setVerbosity(TermSilent); + } __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); - CurrentModule = LOCAL_SourceModule = TermUser; + CurrentModule = LOCAL_SourceModule = TermUser; init_globals(yap_init); start_modules(); if (yap_init->install && Yap_OUTPUT_STARTUP) { setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG, - MkAtomTerm(Yap_LookupAtom(Yap_INPUT_STARTUP))); + MkAtomTerm(Yap_LookupAtom(Yap_INPUT_STARTUP))); setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, true); } LOCAL_consult_level = -1; @@ -1199,7 +1210,7 @@ X_API void YAP_Init(YAP_init_args *yap_init) { if (yap_init->install && Yap_OUTPUT_STARTUP) { Term t = MkAtomTerm(Yap_LookupAtom(Yap_OUTPUT_STARTUP)); Term g = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("qsave_program"), 1), - 1, &t); + 1, &t); YAP_RunGoalOnce(g); } diff --git a/CMakeLists.txt b/CMakeLists.txt index dd11fab71..bdcc46d1c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -375,22 +375,30 @@ if (GMP_INCLUDE_DIRS) endif () -if (WITH_READLINE) +# - Find the readline library +# This module defines +# READLINE_INCLUDE_DIR, path to readline/readline.h, etc. +# READLINE_LIBRARIES, the libraries required to use READLINE. +# READLINE_FOUND, If false, do not try to use READLINE. +# also defined, but not for general use are +# READLINE_readline_LIBRARY, where to find the READLINE library. +# READLINE_ncurses_LIBRARY, where to find the ncurses library [might not be defined] + include(FindReadline) - List(APPEND YAP_SYSTEM_OPTIONS readline) + option (WITH_READLINE "use Readline" ON) # include subdirectories configuration ## after we have all functionality in # # ADD_SUBDIRECTORY(console/terminal) if (READLINE_FOUND) + List(APPEND YAP_SYSTEM_OPTIONS readline) # required for configure - list(APPEND CMAKE_REQUIRED_INCLUDES ${READLINE_INCLUDE_DIR} + include_directories( ${READLINE_INCLUDE_DIR} ${READLINE_INCLUDE_DIR}/readline ) endif () -endif() include_directories(H H/generated @@ -450,7 +458,6 @@ set(DEF_STACKSPACE 0) set(DEF_HEAPSPACE 0) set(DEF_TRAILSPACE 0) -# option (RATIONAL_TREES "support infinite rational trees" ON) # dd_definitions (-D) ## don't touch these opts @@ -582,8 +589,12 @@ ADD_SUBDIRECTORY(pl) ADD_SUBDIRECTORY(library) +ADD_SUBDIRECTORY(swi/library) + add_subDIRECTORY(utf8proc ) + + if(ANDROID) set(CXX_SWIG_OUTDIR ${CMAKE_BINARY_DIR}/packages/swig/android) @@ -612,6 +623,7 @@ endif() add_subDIRECTORY( packages/myddas ) +add_subDIRECTORY( packages/clpqr ) List(APPEND YLIBS $) diff --git a/H/YapGFlagInfo.h b/H/YapGFlagInfo.h index e797ce9ed..f8466d7dd 100644 --- a/H/YapGFlagInfo.h +++ b/H/YapGFlagInfo.h @@ -354,23 +354,12 @@ vxu `on` consider `$` a lower case character. */ YAP_FLAG(LANGUAGE_FLAG, "language", true, isatom, "yap", NULL), - /**< if defined, first location where YAP expects to find the YAP Prolog - library. Takes precedence over library_directory */ - YAP_FLAG(PROLOG_LIBRARY_DIRECTORY_FLAG, "prolog_library_directory", true, - isatom, "", NULL), - - /**< if defined, first location where YAP expects to find the YAP Prolog - shared libraries (DLLS). Takes precedence over executable_directory/2. */ /**< `max_arity is iso ` - YAP_FLAG(MAX_ARITY_FLAG, "max_arity", false, isatom, "unbounded", NULL), Read-only flag telling the maximum arity of a functor. Takes the value `unbounded` for the current version of YAP. */ - YAP_FLAG(PROLOG_FOREIGN_DIRECTORY_FLAG, "prolog_foreign_directory", true, - isatom, "", NULL), - - + YAP_FLAG(MAX_ARITY_FLAG, "max_arity", false, isatom, "unbounded", NULL), YAP_FLAG(MAX_TAGGED_INTEGER_FLAG, "max_tagged_integer", false, at2n, "INT_MAX", NULL), @@ -378,7 +367,14 @@ vxu `on` consider `$` a lower case character. YAP_FLAG(MAX_WORKERS_FLAG, "max_workers", false, at2n, "MAX_WORKERS", NULL), YAP_FLAG(MIN_TAGGED_INTEGER_FLAG, "min_tagged_integer", false, at2n, "INT_MIN", NULL), - YAP_FLAG(N_OF_INTEGER_KEYS_IN_DB_FLAG, "n_of_integer_keys_in_db", false, ro, + + + YAP_FLAG(MODULE_INDEPENDENT_OPERATORS_FLAG, "module_independent_operators", + true, booleanFlag, "false", NULL), + + + + YAP_FLAG(N_OF_INTEGER_KEYS_IN_DB_FLAG, "n_of_integer_keys_in_db", false, ro, "256", NULL), YAP_FLAG(OCCURS_CHECK_FLAG, "occurs_check", true, booleanFlag, "false", NULL), @@ -407,8 +403,16 @@ vxu `on` consider `$` a lower case character. "true", NULL), - YAP_FLAG(MODULE_INDEPENDENT_OPERATORS_FLAG, "module_independent_operators", - true, booleanFlag, "false", NULL), + /**< if defined, first location where YAP expects to find the YAP Prolog + library. Takes precedence over library_directory */ + YAP_FLAG(PROLOG_LIBRARY_DIRECTORY_FLAG, "prolog_library_directory", true, + isatom, "", NULL), + + /**< if defined, first location where YAP expects to find the YAP Prolog + shared libraries (DLLS). Takes precedence over executable_directory/2. */ + YAP_FLAG(PROLOG_FOREIGN_DIRECTORY_FLAG, "prolog_foreign_directory", true, + isatom, "", NULL), + YAP_FLAG(OPTIMISE_FLAG, "optimise", true, booleanFlag, "false", NULL), YAP_FLAG(OS_ARGV_FLAG, "os_argv", false, os_argv, "@boot", NULL), @@ -566,7 +570,6 @@ and if it is bound to `off` disable them. The default for YAP is */ YAP_FLAG(TABLING_MODE_FLAG, "tabling_mode", true, isatom, "[]", NULL), - YAP_FLAG(THREADS_FLAG, "threads", false, ro, "MAX_THREADS", NULL), YAP_FLAG(TIMEZONE_FLAG, "timezone", false, ro, "18000", NULL), /**< `toplevel_hook ` diff --git a/include/YapError.h b/include/YapError.h index 83bfb4e0c..246e5c81f 100644 --- a/include/YapError.h +++ b/include/YapError.h @@ -53,7 +53,7 @@ extern void Yap_ThrowError__(const char *file, const char *function, int lineno, ; #define Yap_NilError(id, ...) \ - Yap_Error__(false, __FILE__, __FUNCTION__, __LINE__, id, TermNil, __VA_ARGS__) +Yap_Error__(false, __FILE__, __FUNCTION__, __LINE__, id, TermNil, __VA_ARGS__) #define Yap_InitError(id, ...) \ Yap_InitError__(__FILE__, __FUNCTION__, __LINE__, id, TermNil, __VA_ARGS__) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index d231de802..219c2b7f0 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -1,11 +1,9 @@ set (LIBRARY_PL - INDEX.pl apply.yap apply_macros.yap arg.yap assoc.yap atts.yap - autoloader.yap avl.yap bhash.yap charsio.yap diff --git a/library/autoloader.yap b/library/autoloader.yap index 2037a5825..621ade734 100644 --- a/library/autoloader.yap +++ b/library/autoloader.yap @@ -120,10 +120,7 @@ find_predicate(G,ExportingModI) :- var(G), index(Name,Arity,ExportingModI,File), functor(G, Name, Arity), - ensure_file_loaded(File). + ensure_loaded(File). + +:- ensure_loaded('INDEX'). -ensure_file_loaded(File) :- - loaded(File), !. -ensure_file_loaded(File) :- - load_files(autoloader:File,[silent(true),if(not_loaded)]), - assert(loaded(File)). diff --git a/library/maplist.yap b/library/maplist.yap index 76368f864..7d4cc40d2 100644 --- a/library/maplist.yap +++ b/library/maplist.yap @@ -705,7 +705,7 @@ scanl_([H1|T1], [H2|T2], [H3|T3], [H4|T4], Goal, V, [VH|VT]) :- goal_expansion(checklist(Meta, List), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -726,7 +726,7 @@ goal_expansion(checklist(Meta, List), Mod:Goal) :- goal_expansion(maplist(Meta, List), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -747,7 +747,7 @@ goal_expansion(maplist(Meta, List), Mod:Goal) :- goal_expansion(maplist(Meta, ListIn, ListOut), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -768,7 +768,7 @@ goal_expansion(maplist(Meta, ListIn, ListOut), Mod:Goal) :- goal_expansion(maplist(Meta, L1, L2, L3), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -789,7 +789,7 @@ goal_expansion(maplist(Meta, L1, L2, L3), Mod:Goal) :- goal_expansion(maplist(Meta, L1, L2, L3, L4), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -810,7 +810,7 @@ goal_expansion(maplist(Meta, L1, L2, L3, L4), Mod:Goal) :- goal_expansion(maplist(Meta, L1, L2, L3, L4, L5), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -831,7 +831,7 @@ goal_expansion(maplist(Meta, L1, L2, L3, L4, L5), Mod:Goal) :- goal_expansion(selectlist(Meta, ListIn, ListOut), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -854,7 +854,7 @@ goal_expansion(selectlist(Meta, ListIn, ListOut), Mod:Goal) :- goal_expansion(selectlist(Meta, ListIn, ListIn1, ListOut), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -877,7 +877,7 @@ goal_expansion(selectlist(Meta, ListIn, ListIn1, ListOut), Mod:Goal) :- goal_expansion(selectlists(Meta, ListIn, ListIn1, ListOut, ListOut1), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -901,7 +901,7 @@ goal_expansion(selectlists(Meta, ListIn, ListIn1, ListOut, ListOut1), Mod:Goal) % same as selectlist goal_expansion(include(Meta, ListIn, ListOut), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -924,7 +924,7 @@ goal_expansion(include(Meta, ListIn, ListOut), Mod:Goal) :- goal_expansion(exclude(Meta, ListIn, ListOut), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -947,7 +947,7 @@ goal_expansion(exclude(Meta, ListIn, ListOut), Mod:Goal) :- goal_expansion(partition(Meta, ListIn, List1, List2), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -970,7 +970,7 @@ goal_expansion(partition(Meta, ListIn, List1, List2), Mod:Goal) :- goal_expansion(partition(Meta, ListIn, List1, List2, List3), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -1010,7 +1010,7 @@ goal_expansion(partition(Meta, ListIn, List1, List2, List3), Mod:Goal) :- goal_expansion(convlist(Meta, ListIn, ListOut), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -1033,7 +1033,7 @@ goal_expansion(convlist(Meta, ListIn, ListOut), Mod:Goal) :- goal_expansion(convlist(Meta, ListIn, ListExtra, ListOut), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -1056,7 +1056,7 @@ goal_expansion(convlist(Meta, ListIn, ListExtra, ListOut), Mod:Goal) :- goal_expansion(sumlist(Meta, List, AccIn, AccOut), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -1077,7 +1077,7 @@ goal_expansion(sumlist(Meta, List, AccIn, AccOut), Mod:Goal) :- goal_expansion(foldl(Meta, List, AccIn, AccOut), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -1098,7 +1098,7 @@ goal_expansion(foldl(Meta, List, AccIn, AccOut), Mod:Goal) :- goal_expansion(foldl(Meta, List1, List2, AccIn, AccOut), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -1119,7 +1119,7 @@ goal_expansion(foldl(Meta, List1, List2, AccIn, AccOut), Mod:Goal) :- goal_expansion(foldl(Meta, List1, List2, List3, AccIn, AccOut), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -1140,7 +1140,7 @@ goal_expansion(foldl(Meta, List1, List2, List3, AccIn, AccOut), Mod:Goal) :- goal_expansion(foldl2(Meta, List, AccIn, AccOut, W0, W), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -1161,7 +1161,7 @@ goal_expansion(foldl2(Meta, List, AccIn, AccOut, W0, W), Mod:Goal) :- goal_expansion(foldl2(Meta, List1, List2, AccIn, AccOut, W0, W), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -1182,7 +1182,7 @@ goal_expansion(foldl2(Meta, List1, List2, AccIn, AccOut, W0, W), Mod:Goal) :- goal_expansion(foldl2(Meta, List1, List2, List3, AccIn, AccOut, W0, W), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -1203,7 +1203,7 @@ goal_expansion(foldl2(Meta, List1, List2, List3, AccIn, AccOut, W0, W), Mod:Goal goal_expansion(foldl3(Meta, List, AccIn, AccOut, W0, W, X0, X), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -1224,7 +1224,7 @@ goal_expansion(foldl3(Meta, List, AccIn, AccOut, W0, W, X0, X), Mod:Goal) :- goal_expansion(foldl4(Meta, List, AccIn, AccOut, W0, W, X0, X, Y0, Y), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -1245,7 +1245,7 @@ goal_expansion(foldl4(Meta, List, AccIn, AccOut, W0, W, X0, X, Y0, Y), Mod:Goal) goal_expansion(mapnodes(Meta, InTerm, OutTerm), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -1277,7 +1277,7 @@ goal_expansion(mapnodes(Meta, InTerm, OutTerm), Mod:Goal) :- goal_expansion(checknodes(Meta, Term), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, @@ -1307,7 +1307,7 @@ goal_expansion(checknodes(Meta, Term), Mod:Goal) :- goal_expansion(sumnodes(Meta, Term, AccIn, AccOut), Mod:Goal) :- goal_expansion_allowed, - callable(Meta), + is_callable(Meta), prolog_load_context(module, Mod), aux_preds(Meta, MetaVars, Pred, PredVars, Proto), !, diff --git a/library/system/sys_config.h b/library/system/sys_config.h index 17e29d49d..ace898575 100644 --- a/library/system/sys_config.h +++ b/library/system/sys_config.h @@ -5,7 +5,7 @@ /* Define to 1 if you have the header file. */ #ifndef HAVE_APR_1_APR_MD5_H -#define HAVE_APR_1_APR_MD5_H 1 +/* #undef HAVE_APR_1_APR_MD5_H */ #endif diff --git a/packages/clpqr/CMakeLists.txt b/packages/clpqr/CMakeLists.txt index b66383937..a00ed9b11 100644 --- a/packages/clpqr/CMakeLists.txt +++ b/packages/clpqr/CMakeLists.txt @@ -19,7 +19,10 @@ set (CLPQRPRIV clpqr/class.pl clpqr/dump.pl clpqr/project.pl clpqr/redund.pl) set (LIBPL clpr.pl clpq.pl ${CLPRPRIV} ${CLPQPRIV} ${CLPQRPRIV} ) -install ( FILES ${YAP_INSTALL_DATADIR} DESTINATION ${YAP_INSTALL_DATADIR} ) +install ( FILES ${CLPQPRIV} DESTINATION ${YAP_INSTALL_DATADIR}/clpq ) +install ( FILES ${CLPRPRIV} DESTINATION ${YAP_INSTALL_DATADIR}/clpr ) +install ( FILES ${CLPQRPRIV} DESTINATION ${YAP_INSTALL_DATADIR}/clpqr ) +install ( FILES clpr.pl clpq.pl DESTINATION ${YAP_INSTALL_DATADIR} ) # $(PL) -q -f $(srcdir)/clpr_test.pl -g test,halt -t 'halt(1)' diff --git a/packages/clpqr/clpr.pl b/packages/clpqr/clpr.pl index d84070ba4..2669b337e 100644 --- a/packages/clpqr/clpr.pl +++ b/packages/clpqr/clpr.pl @@ -128,7 +128,7 @@ minimise variable _V_ dump/3%, projecting_assert/1 ]). -:- expects_dialect(swi). +%:- expects_dialect(swi). % % Don't report export of private predicates from clpr diff --git a/packages/jpl/src/c/CMakeLists.txt b/packages/jpl/src/c/CMakeLists.txt index 5c309c77e..9e7415b5e 100644 --- a/packages/jpl/src/c/CMakeLists.txt +++ b/packages/jpl/src/c/CMakeLists.txt @@ -1,6 +1,6 @@ # set(CMAKE_MACOSX_RPATH 1) -add_lib(jplYap jpl.h jpl.c hacks.h) +add_library(jplYap jpl.c) include_directories (${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2} ${JAVA_AWT_PATH} ) diff --git a/packages/python/pybips.c b/packages/python/pybips.c index 986162d01..a160dc1e6 100644 --- a/packages/python/pybips.c +++ b/packages/python/pybips.c @@ -762,7 +762,7 @@ PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) { } else { PyStructSequence_Desc *desc = PyMem_Calloc(sizeof(PyStructSequence_Desc), 1); desc->name = PyMem_Malloc(strlen(s) + 1); - strcpy(desc->name, s); + strcpy((char *)desc->name, s); desc->doc = "YAPTerm"; desc->fields = pnull; desc->n_in_sequence = arity; diff --git a/packages/python/swig/README.md b/packages/python/swig/README.md index 90f64fe05..d609f6392 100644 --- a/packages/python/swig/README.md +++ b/packages/python/swig/README.md @@ -1,16 +1,14 @@ -The YAP Prolog System {#main} -=========== +
![The YAP Logo](docs/icons/yap_128x128x32.png)
NOTE: this version of YAP is still experimental, documentation may be out of date. -Introduction -++++++++++ +## Introduction This document provides User information on version 6.3.4 of -YAP (*Yet Another Prolog*). The YAP Prolog System is a +YAP (Yet Another Prolog). The YAP Prolog System is a high-performance Prolog compiler developed at Universidade do Porto. YAP supports stream Input/Output, sockets, modules, exceptions, Prolog debugger, C-interface, dynamic code, internal @@ -18,6 +16,7 @@ Porto. YAP supports stream Input/Output, sockets, modules, We explicitly allow both commercial and non-commercial use of YAP. + YAP is based on the David H. D. Warren's WAM (Warren Abstract Machine), with several optimizations for better performance. YAP follows the Edinburgh tradition, and was originally designed to be largely @@ -48,33 +47,47 @@ different licenses. If you have a question about this software, desire to add code, found a bug, want to request a feature, or wonder how to get further assistance, -please send e-mail to `yap-users AT lists.sourceforge.net. To -subscribe to the mailing list, visit the [YAP Mailing list page](https://lists.sourceforge.net/lists/listinfo/yap-users). +please send e-mail to . To +subscribe to the mailing list, visit the page +. On-line documentation is available for [YAP](http://www.dcc.fp.pt/~vsc/yap/) + + The packages are, in alphabetical order: -+ The CHR package developed by Tom Schrijvers, Christian Holzbaur, and Jan Wielemaker. ++ The CHR package developed by Tom Schrijvers, +Christian Holzbaur, and Jan Wielemaker. + The CLP(BN) package and Horus toolkit developed by Tiago Gomes, and Vítor Santos Costa. -+ The CLP(R) package developed by Leslie De Koninck, Bart Demoen, Tom Schrijvers, and Jan Wielemaker, based on the CLP(Q,R) implementation by Christian Holzbaur. ++ The CLP(R) package developed by Leslie De Koninck, Bart Demoen, Tom +Schrijvers, and Jan Wielemaker, based on the CLP(Q,R) implementation +by Christian Holzbaur. -+ The CPLint package developed by Fabrizio Riguzzi's research laboratory at the [University of Ferrara](http://www.ing.unife.it/Docenti/FabrizioRiguzzi/). ++ The CPLint package developed by Fabrizio Riguzzi's research +laboratory at the [University of Ferrara](http://www.ing.unife.it/Docenti/FabrizioRiguzzi/) -+ The CUDA interface package developed by Carlos Martínez, Jorge Buenabad, Inês Dutra and Vítor Santos Costa. ++ The CUDA interface package developed by Carlos Martínez, Jorge +Buenabad, Inês Dutra and Vítor Santos Costa. + The [GECODE](http://www.gecode.org) interface package developed by Denys Duchier and Vítor Santos Costa. + The [JPL](http://www.swi-prolog.org/packages/jpl/) (Java-Prolog Library) package developed by . -+ The minisat SAT solver interface developed by Michael Codish, Vitaly Lagoon, and Peter J. Stuckey. + The minisat SAT solver interface developed by Michael Codish, + Vitaly Lagoon, and Peter J. Stuckey. -+ The MYDDAS relational data-base interface developed at the Universidade do Porto by Tiago Soares, Michel Ferreira, and Ricardo Rocha. ++ The MYDDAS relational data-base interface developed at the + Universidade do Porto by Tiago Soares, Michel Ferreira, and Ricardo Rocha. -+ The [PRISM](http://rjida.meijo-u.ac.jp/prism/) logic-based programming system for statistical modeling developed at the Sato Research Laboratory, TITECH, Japan. ++ The [PRISM](http://rjida.meijo-u.ac.jp/prism/) logic-based +programming system for statistical modeling developed at the Sato +Research Laboratory, TITECH, Japan. -+ The ProbLog 1 system developed by the [ProbLog](https://dtai.cs.kuleuven.be/problog) team in the DTAI group of KULeuven. ++ The ProbLog 1 system developed by the [ProbLog](https://dtai.cs.kuleuven.be/problog) team in the +DTAI group of KULeuven. -+ The [R](http://stoics.org.uk/~nicos/sware/packs/real/) interface package developed by Nicos Angelopoulos, Vítor Santos Costa, João Azevedo, Jan Wielemaker, and Rui Camacho. ++ The [R](http://stoics.org.uk/~nicos/sware/packs/real/) interface package developed by Nicos Angelopoulos, +Vítor Santos Costa, João Azevedo, Jan Wielemaker, and Rui Camacho. diff --git a/packages/python/swig/setup.py b/packages/python/swig/setup.py index 23c49be72..3082198f7 100644 --- a/packages/python/swig/setup.py +++ b/packages/python/swig/setup.py @@ -65,11 +65,11 @@ if platform.system() == 'Windows': win_libs = ['wsock32','ws2_32'] my_extra_link_args = ['-Wl,-export-all-symbols'] elif platform.system() == 'Darwin': - my_extra_link_args = ['-L','..','-Wl,-rpath,'+abspath(join(sysconfig.get_path('platlib'),'yap4py')),'-Wl,-rpath,/usr/local/lib','-Wl,-rpath,../yap4py'] + my_extra_link_args = ['-L','..','-Wl,-rpath,'+abspath(join(sysconfig.get_path('platlib'),'yap4py')),'-Wl,-rpath,/lib','-Wl,-rpath,../yap4py'] win_libs = [] local_libs = ['Py4YAP'] elif platform.system() == 'Linux': - my_extra_link_args = ['-L','..','-Wl,-rpath,'+abspath(join(sysconfig.get_path('platlib'),'yap4py')),'-Wl,-rpath,/usr/local/lib','-Wl,-rpath,'+join('/usr/local/lib','..'),'-Wl,-rpath,../yap4py'] + my_extra_link_args = ['-L','..','-Wl,-rpath,'+abspath(join(sysconfig.get_path('platlib'),'yap4py')),'-Wl,-rpath,/lib','-Wl,-rpath,'+join('/lib','..'),'-Wl,-rpath,../yap4py'] win_libs = [] local_libs = ['Py4YAP'] @@ -91,10 +91,10 @@ extensions = [Extension('_yap', native_sources, ('PYTHONSWIG', '1'), ('_GNU_SOURCE', '1')], runtime_library_dirs=[ - abspath(join(sysconfig.get_path('platlib'),'yap4py')), abspath(sysconfig.get_path('platlib')),'/usr/local/lib'], + abspath(join(sysconfig.get_path('platlib'),'yap4py')), abspath(sysconfig.get_path('platlib')),'/lib'], swig_opts=['-modern', '-c++', '-py3', '-DX_API', '-Iyap4py/include' ], - library_dirs=[".",'../../..','/usr/local/lib'], + library_dirs=[".",'../../..','/lib'], extra_link_args=my_extra_link_args, libraries=['Yap','gmp']+win_libs+local_libs, include_dirs=['/home/vsc/github/yap-6.3/H', diff --git a/pl/CMakeLists.txt b/pl/CMakeLists.txt index 9697c2d7e..36b79a68a 100644 --- a/pl/CMakeLists.txt +++ b/pl/CMakeLists.txt @@ -1,4 +1,4 @@ -set(11PL_BOOT_SOURCES +set(PL_BOOT_SOURCES absf.yap android.yap arith.yap diff --git a/pl/boot.yap b/pl/boot.yap index 4c8f1381e..4837158ca 100644 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -53,7 +53,6 @@ private(_). true/0], ['$$compile'/4, '$call'/4, '$catch'/3, - '$check_callable'/2, '$check_head_and_body'/4, '$check_if_reconsulted'/2, '$clear_reconsulting'/0, @@ -118,7 +117,7 @@ print_message(L,E) :- -> true ; - error(_,Info), + system_error(_,Info), '$error_descriptor'(Info, Desc), query_exception(prologPredFile, Desc, File), query_exception(prologPredLine, Desc, FilePos), @@ -132,7 +131,7 @@ print_message(L,E) :- format(user_error,'~a:~d: error: undefined ~w~n:',[F,L,M:G]), fail ; - format(user_error,' call to ~w~n',[M:G]), + format(user_error,' call to undefined procedure ~w~n',[M:G]), fail. :- '$undefp_handler'('$undefp0'(_,_),prolog). diff --git a/pl/consult.yap b/pl/consult.yap index a7b1f71f6..5920f944e 100644 --- a/pl/consult.yap +++ b/pl/consult.yap @@ -265,7 +265,7 @@ load_files(Files0,Opts) :- '$lf_option'(sandboxed, 24, false). '$lf_option'(scope_settings, 25, false). '$lf_option'(modified, 26, _). -'$lf_option'('$context_module', 27, _). +'$lf_option'(source_module, 27, _). '$lf_option'('$parent_topts', 28, _). '$lf_option'(must_be_module, 29, false). '$lf_option'('$source_pos', 30, _). @@ -317,12 +317,12 @@ load_files(Files0,Opts) :- '__NB_getval__'('$lf_status', OldTOpts, fail), nonvar(OldTOpts), functor( OldTOpts, opt, LastOpt ), '$lf_opt'(autoload, OldTOpts, OldAutoload), - '$lf_opt'('$context_module', OldTOpts, OldContextModule) + '$lf_opt'(source_module, OldTOpts, OldContextModule) ; current_prolog_flag(autoload, OldAutoload), functor( OldTOpts, opt, LastOpt ), '$lf_opt'(autoload, OldTOpts, OldAutoload), - '$lf_opt'('$context_module', OldTOpts, OldContextModule) + '$lf_opt'(source_module, OldTOpts, OldContextModule) ), functor( TOpts, opt, LastOpt ), ( source_location(ParentF, Line) -> true ; ParentF = user_input, Line = -1 ), @@ -448,7 +448,7 @@ load_files(Files0,Opts) :- ( Val == false -> true ; Val == true -> true ; '$do_error'(domain_error(unimplemented_option,register(Val)),Call) ). -'$process_lf_opt'('$context_module', Mod, Call) :- +'$process_lf_opt'(source_module, Mod, Call) :- ( atom(Mod) -> true ; '$do_error'(type_error(atom,Mod),Call) ). @@ -724,7 +724,7 @@ db_files(Fs) :- set_stream( Stream, [alias(loop_stream), encoding(Encoding)] ), '__NB_getval__'('$loop_streams',Sts0, Sts0=[]), nb_setval('$loop_streams',[Stream|Sts0]), - '$lf_opt'('$context_module', TOpts, ContextModule), + '$lf_opt'(source_module, TOpts, ContextModule), '$lf_opt'(reexport, TOpts, Reexport), '$lf_opt'(qcompile, TOpts, QCompiling), '__NB_getval__'('$qcompile', ContextQCompiling, ContextQCompiling = never), @@ -1359,7 +1359,7 @@ account the following observations: '$reexport'( TOpts, File, Reexport, Imports, OldF ) :- ( Reexport == false -> true ; ( '$lf_opt'('$parent_topts', TOpts, OldTOpts), - '$lf_opt'('$context_module', OldTOpts, OldContextModule) + '$lf_opt'(source_module, OldTOpts, OldContextModule) -> true ; diff --git a/pl/debug.yap b/pl/debug.yap index 04223319d..ca648226f 100644 --- a/pl/debug.yap +++ b/pl/debug.yap @@ -477,7 +477,7 @@ be lost. '$trace_goal'(G, M, GoalNumber, H) :- '$undefined'(G, M), !, - '$get_undefined_pred'(G, M, Goal, NM), + '$get_undefined_pred'(M:G, NM:Goal), ( ( M == NM ; NM == prolog), G == Goal -> yap_flag( unknown, Action ), diff --git a/pl/error.yap b/pl/error.yap index 864484bd2..c71a0d1a9 100644 --- a/pl/error.yap +++ b/pl/error.yap @@ -10,8 +10,10 @@ [ must_be_of_type/2, % +Type, +Term must_be_of_type/3, % +Type, +Term, +Comment must_be/2, % +Type, +Term + must_be_callable/1, % +Type, +Term must_be/3, % +Type, +Term, +Comment type_error/2, % +Type, +Term + must_be_called/1, % must_be_in_domain/2, % +Domain, +Term % must_be_in_domain/3, % +Domain, +Term, +Comment domain_error/3, % +Domain, +Values, +Term @@ -21,7 +23,9 @@ must_bind_to_type/2, % +Type, ?Term instantiation_error/1, % +Term representation_error/1, % +Reason - is_of_type/2 % +Type, +Term + is_of_type/2, % +Type, +Term + is_callable/1, + is_callable/2 ]), []) . /** @@ -104,13 +108,13 @@ must_be(Type, X, Comment) :- must_be_of_type(callable, X) :- !, - is_callable(X, _). + is_callable(X). must_be_of_type(atom, X) :- !, - is_atom(X, _). + is_atom(X). must_be_of_type(module, X) :- !, - is_atom(X, _). + is_atom(X). must_be_of_type(predicate_indicator, X) :- !, is_predicate_indicator(X, _). @@ -120,19 +124,12 @@ must_be_of_type(Type, X) :- ; is_not(Type, X) ). -inline(must_be_of_type( atom, X ), is_atom(X, _) ). -inline(must_be_of_type( module, X ), is_module(X, _) ). -inline(must_be_of_type( callable, X ), is_callable(X, _) ). -inline(must_be_of_type( callable, X ), is_callable(X, _) ). -inline(must_be_atom( X ), is_callable(X, _) ). -inline(must_be_module( X ), is_atom(X, _) ). - must_be_of_type(predicate_indicator, X, Comment) :- !, is_predicate_indicator(X, Comment). -must_be_of_type(callable, X, Comment) :- +must_be_of_type(callable, X, _Comment) :- !, - is_callable(X, Comment). + is_callable(X). must_be_of_type(Type, X, _Comment) :- ( has_type(Type, X) -> true @@ -335,4 +332,16 @@ must_be_instantiated(X) :- must_be_instantiated(X, Comment) :- ( var(X) -> instantiation_error(X, Comment) ; true). +must_be_callable(X) :- + is_callable(X). + + +inline(must_be_of_type( atom, X ), is_atom(X) ). +inline(must_be_of_type( module, X ), is_atom(X) ). +inline(must_be_of_type( callable, X ), is_callable(X) ). +inline(must_be_atom( X ), is_atom(X) ). +inline(must_be_module( X ), is_atom(X) ). +inline(must_be_callable( X ), is_callable(X) ). +inline(is_callable( X,_ ), is_callable(X) ). + %% @} diff --git a/pl/imports.yap b/pl/imports.yap index 77bf042d9..10c759ed7 100644 --- a/pl/imports.yap +++ b/pl/imports.yap @@ -60,7 +60,7 @@ fail. % '$get_undefined_pred'(ImportingMod:G, ExportingMod:G0) :- - must_be_callablle( ImportingMod:G ), + must_be_callable( ImportingMod:G ), '$get_undefined_predicates'(ImportingMod:G, ExportingMod:G0). % be careful here not to generate an undefined exception. @@ -94,7 +94,7 @@ fail. '$verify_import'(_M:G, prolog:G) :- '$is_system_predicate'(G, prolog). '$verify_import'(M:G, NM:NG) :- - '$get_undefined_pred'(G, M, NG, NM), + '$get_undefined_predicates'(M:G, M, NM:NG), !. '$verify_import'(MG, MG). @@ -111,8 +111,13 @@ fail. functor(G0, N, K), '$autoloader_find_predicate'(G0,ExportingMod), 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),_), + \+ '$system_predicate'(G0,prolog) + -> + '$compile'((G:-ExportingMod:G0), reconsult ,(ImportingMod:G:-ExportingMod:G0), ImportingMod, _) + ; + true + ). '$autoloader_find_predicate'(G,ExportingMod) :- @@ -122,10 +127,7 @@ fail. yap_flag(autoload, true, false), yap_flag( unknown, Unknown, fail), yap_flag(debug, Debug, false), !, - load_files([library(autoloader), - autoloader:library('NDEX'), - swi:library('dialect/swi/NDEX')], - [autoload(true),if(not_loaded)]), + load_files([library(autoloader)],[silent(true)]), nb_setval('$autoloader_set', true), yap_flag(autoload, _, true), yap_flag( unknown, _, Unknown), diff --git a/pl/modules.yap b/pl/modules.yap index 95ce44332..87fb38cbd 100644 --- a/pl/modules.yap +++ b/pl/modules.yap @@ -302,7 +302,7 @@ use_module(F,Is) :- % and remove import. % '$not_imported'(H, Mod) :- - recorded('$import','$import'(NM,Mod,NH,H,_,_),R), + recorded('$import','$import'(NM,Mod,NH,H,_,_),R), NM \= Mod, functor(NH,N,Ar), print_message(warning,redefine_imported(Mod,NM,N/Ar)), @@ -470,10 +470,14 @@ export_list(Module, List) :- G1=..[N1|Args], ( '$check_import'(M0,ContextMod,N1,K) -> ( ContextMod == prolog -> - recordzifnot('$import','$import'(M0,user,G0,G1,N1,K),_), - fail + recordzifnot('$import','$import'(M0,user,G0,G1,N1,K),_), + \+ '$is_system_predicate'(G1, prolog), + '$compile'((G1:-M0:G0), reconsult,(user:G1:-M0:G0) , user, R), + fail ; recordaifnot('$import','$import'(M0,ContextMod,G0,G1,N1,K),_), + \+ '$is_system_predicate'(G1, prolog), + '$compile'((G1:-M0:G0), reconsult,(ContextMod:G1:-M0:G0) , ContextMod, R), fail ; true @@ -535,7 +539,7 @@ other source modules. This built-in was introduced by SWI-Prolog. In YAP, by default, modules only inherit from `prolog`. This extension allows predicates in the current module (see module/2 and module/1) to inherit from `user` or other modules. - + x2 */ set_base_module(ExportingModule) :- var(ExportingModule), diff --git a/pl/preddyns.yap b/pl/preddyns.yap index a9922e23f..ab4aee3f0 100644 --- a/pl/preddyns.yap +++ b/pl/preddyns.yap @@ -248,7 +248,7 @@ Retract all the clauses whose head matches the goal _G_. Goal */ retractall(V) :- '$yap_strip_module'(V,M,P), - is_callable(M,P), + is_callable(M:P), '$retractall'(P,M). '$retractall'(T,M) :- diff --git a/pl/preds.yap b/pl/preds.yap index 2bb938faf..9cb45460b 100644 --- a/pl/preds.yap +++ b/pl/preds.yap @@ -248,163 +248,55 @@ nth_clause(V,I,R) :- '$nth_clause'(P,M,I,R) :- '$fetch_nth_clause'(P,M,I,R). + +/** + @pred abolish(+ _PredSpec_) is iso + + +Deletes the predicate given by _PredSpec_ from the database. All +state on the predicate, including whether it is dynamic or static, +multifile, or meta-predicate, will be lost. The specification must +include the name and arity, and it may include module +information. Under iso language mode this built-in will only +abolish dynamic procedures. Under other modes it will abolish any +procedures. + +Older versions of YAP would accept unbound arguments; please use +current_predicate/2 to enumerate the predicates you want to discard. + +*/ +abolish(X) :- + get_predicate_indicator(X, M, Na, Ar), + functor(H, Na, Ar), + ( '$is_dynamic'(H, M) -> '$abolishd'(H, M) ; + '$undefined'(H, M) -> true ; + current_prolog_flag(language, iso) -> '$do_error'(permission_error(modify,static_procedure,Na/Ar),abolish(X)) ; + '$abolishs'(H,M) + ). + /** @pred abolish(+ _P_,+ _N_) Completely delete the predicate with name _P_ and arity _N_. It will remove both static and dynamic predicates. All state on the predicate, including whether it is dynamic or static, multifile, or meta-predicate, will be lost. -*/ -abolish(N0,A) :- - strip_module(N0, Mod, N), !, - '$abolish'(N,A,Mod). - -'$abolish'(N,A,M) :- var(N), !, - '$do_error'(instantiation_error,abolish(M:N,A)). -'$abolish'(N,A,M) :- var(A), !, - '$do_error'(instantiation_error,abolish(M:N,A)). -'$abolish'(N,A,M) :- - ( recorded('$predicate_defs','$predicate_defs'(N,A,M,_),R) -> erase(R) ), - fail. -'$abolish'(N,A,M) :- functor(T,N,A), - ( '$is_dynamic'(T, M) -> '$abolishd'(T,M) ; - /* else */ '$abolishs'(T,M) ). - -/** @pred abolish(+ _PredSpec_) is iso - - -Deletes the predicate given by _PredSpec_ from the database. If -§§ _PredSpec_ is an unbound variable, delete all predicates for the -current module. The -specification must include the name and arity, and it may include module -information. Under iso language mode this built-in will only abolish -dynamic procedures. Under other modes it will abolish any procedures. +abolish/2 is similar to abolish/1, but it always tries to erase static properties. It should not be confused with SICStus Prolog abolish/2, which is abolish/1 plus a list of options. */ -abolish(X0) :- - strip_module(X0,M,X), - '$abolish'(X,M). - -'$abolish'(X,M) :- - current_prolog_flag(language, sicstus), !, - '$new_abolish'(X,M). -'$abolish'(X, M) :- - '$old_abolish'(X,M). - -'$new_abolish'(V,M) :- var(V), !, - '$abolish_all_in_module'(M). -'$new_abolish'(A/V,M) :- atom(A), var(V), !, - '$abolish_all_atoms'(A,M). -'$new_abolish'(Na//Ar1, M) :- - integer(Ar1), - !, - Ar is Ar1+2, - '$new_abolish'(Na//Ar, M). -'$new_abolish'(Na/Ar, M) :- +abolish(N,A) :- + get_predicate_indicator(N/A, M, Na, Ar), functor(H, Na, Ar), - '$is_dynamic'(H, M), !, - '$abolishd'(H, M). -'$new_abolish'(Na/Ar, M) :- % succeed for undefined procedures. - functor(T, Na, Ar), - '$undefined'(T, M), !. -'$new_abolish'(Na/Ar, M) :- - '$do_error'(permission_error(modify,static_procedure,Na/Ar),abolish(M:Na/Ar)). -'$new_abolish'(T, M) :- - '$do_error'(type_error(predicate_indicator,T),abolish(M:T)). + ( '$is_dynamic'(H, M) -> '$abolishd'(H, M) ; + '$undefined'(H, M) -> true ; + '$abolishs'(H,M) + ). -'$abolish_all_in_module'(M) :- - '$current_predicate'(Na, M, S, _), - functor(S, Na, Ar), - '$new_abolish'(Na/Ar, M), - fail. -'$abolish_all_in_module'(_). -'$abolish_all_atoms'(Na, M) :- - '$current_predicate'(Na,M,S,_), - functor(S, Na, Ar), - '$new_abolish'(Na/Ar, M), - fail. -'$abolish_all_atoms'(_,_). - -'$check_error_in_predicate_indicator'(V, Msg) :- - var(V), !, - '$do_error'(instantiation_error, Msg). -'$check_error_in_predicate_indicator'(M:S, Msg) :- !, - '$check_error_in_module'(M, Msg), - '$check_error_in_predicate_indicator'(S, Msg). -'$check_error_in_predicate_indicator'(S, Msg) :- - S \= _/_, - S \= _//_, !, - '$do_error'(type_error(predicate_indicator,S), Msg). -'$check_error_in_predicate_indicator'(Na/_, Msg) :- - var(Na), !, - '$do_error'(instantiation_error, Msg). -'$check_error_in_predicate_indicator'(Na/_, Msg) :- - \+ atom(Na), !, - '$do_error'(type_error(atom,Na), Msg). -'$check_error_in_predicate_indicator'(_/Ar, Msg) :- - var(Ar), !, - '$do_error'(instantiation_error, Msg). -'$check_error_in_predicate_indicator'(_/Ar, Msg) :- - \+ integer(Ar), !, - '$do_error'(type_error(integer,Ar), Msg). -'$check_error_in_predicate_indicator'(_/Ar, Msg) :- - Ar < 0, !, - '$do_error'(domain_error(not_less_than_zero,Ar), Msg). -% not yet implemented! -%'$check_error_in_predicate_indicator'(Na/Ar, Msg) :- -% Ar < maxarity, !, -% '$do_error'(type_error(representation_error(max_arity),Ar), Msg). - -'$check_error_in_module'(M, Msg) :- - var(M), !, - '$do_error'(instantiation_error, Msg). -'$check_error_in_module'(M, Msg) :- - \+ atom(M), !, - '$do_error'(type_error(atom,M), Msg). - -'$old_abolish'(V,M) :- var(V), !, - ( true -> % current_prolog_flag(language, sicstus) -> - '$do_error'(instantiation_error,abolish(M:V)) - ; - '$abolish_all_old'(M) - ). -'$old_abolish'(N/A, M) :- !, - '$abolish'(N, A, M). -'$old_abolish'(A,M) :- atom(A), !, - ( current_prolog_flag(language, iso) -> - '$do_error'(type_error(predicate_indicator,A),abolish(M:A)) - ; - '$abolish_all_atoms_old'(A,M) - ). -'$old_abolish'([], _) :- !. -'$old_abolish'([H|T], M) :- !, '$old_abolish'(H, M), '$old_abolish'(T, M). -'$old_abolish'(T, M) :- - '$do_error'(type_error(predicate_indicator,T),abolish(M:T)). - -'$abolish_all_old'(M) :- - '$current_predicate'(Na, M, S, _), - functor( S, Na, Ar ), - '$abolish'(Na, Ar, M), - fail. -'$abolish_all_old'(_). - -'$abolish_all_atoms_old'(Na, M) :- - '$current_predicate'(Na, M, S, _), - functor(S, Na, Ar), - '$abolish'(Na, Ar, M), - fail. -'$abolish_all_atoms_old'(_,_). - -'$abolishs'(G, M) :- '$system_predicate'(G,M), !, - functor(G,Name,Arity), - '$do_error'(permission_error(modify,static_procedure,Name/Arity),abolish(M:G)). -'$abolishs'(G, Module) :- - current_prolog_flag(language, sicstus), % only do this in sicstus mode - '$undefined'(G, Module), +'$abolishs'(G, M) :- + '$system_predicate'(G,M), !, functor(G,Name,Arity), - print_message(warning,no_match(abolish(Module:Name/Arity))). + '$do_error'(permission_error(modify,static_procedure,Name/Arity),abolish(M:G)). '$abolishs'(G, M) :- '$is_multifile'(G,M), functor(G,Name,Arity), @@ -420,6 +312,7 @@ abolish(X0) :- '$purge_clauses'(G, M), fail. '$abolishs'(_, _). + /** @pred stash_predicate(+ _Pred_) Make predicate _Pred_ invisible to new code, and to `current_predicate/2`, `listing`, and friends. New predicates with the same name and @@ -509,7 +402,7 @@ predicate_property(Pred,Prop) :- M = Mod, NPred = TruePred ; - '$get_undefined_pred'(TruePred, Mod, NPred, M) + '$get_undefined_pred'(Mod:TruePred, M:NPred) ), '$predicate_property'(NPred,M,Mod,Prop). diff --git a/pl/threads.yap b/pl/threads.yap index 5fe496375..ca03a31a6 100644 --- a/pl/threads.yap +++ b/pl/threads.yap @@ -73,7 +73,7 @@ for MS-Windows. '$thread_gfetch'/1, '$thread_local'/2]). -:- use_system_module( '$_boot', ['$check_callable'/2, +:- use_system_module( '$_boot', [ '$run_at_thread_start'/0, '$system_catch'/4]). @@ -162,7 +162,7 @@ Create a new Prolog detached thread using default options. See thread_create/3. */ thread_create(Goal) :- G0 = thread_create(Goal), - '$check_callable'(Goal, G0), + is_callable(Goal), '$thread_options'([detached(true)], [], Stack, Trail, System, Detached, AtExit, G0), '$thread_new_tid'(Id), % '$erase_thread_info'(Id), % this should not be here @@ -184,7 +184,7 @@ Create a new Prolog thread using default options. See thread_create/3. */ thread_create(Goal, Id) :- G0 = thread_create(Goal, Id), - '$check_callable'(Goal, G0), + is_callable(Goal), ( nonvar(Id) -> '$do_error'(uninstantiation_error(Id),G0) ; true ), '$thread_options'([], [], Stack, Trail, System, Detached, AtExit, G0), '$thread_new_tid'(Id), @@ -243,7 +243,7 @@ data from their stacks. */ thread_create(Goal, Id, Options) :- G0 = thread_create(Goal, Id, Options), - '$check_callable'(Goal,G0), + is_callable(Goal), ( nonvar(Id) -> '$do_error'(uninstantiation_error(Id),G0) ; true ), '$thread_options'(Options, Alias, Stack, Trail, System, Detached, AtExit, G0), '$thread_new_tid'(Id), @@ -564,7 +564,7 @@ using instead the `at_exit/1` option of thread_create/3. */ thread_at_exit(Goal) :- - '$check_callable'(Goal,thread_at_exit(Goal)), + is_callable(Goal), '$thread_self'(Id0), recordz('$thread_exit_hook',[Id0|Goal],_). @@ -1284,7 +1284,7 @@ thread_sleep(Time) :- thread_signal(Id, Goal) :- '$check_thread_or_alias'(Id, thread_signal(Id, Goal)), - '$check_callable'(Goal, thread_signal(Id, Goal)), + is_callable(Goal), '$thread_id_alias'(Id0, Id), ( recorded('$thread_signal', [Id0| _], R), erase(R), fail ; true diff --git a/pl/top.yap b/pl/top.yap index 9845b32fb..242fbc30f 100644 --- a/pl/top.yap +++ b/pl/top.yap @@ -731,19 +731,6 @@ write_query_answer( Bindings ) :- % */ '$execute0'(G, CurMod). -'$check_callable'(V,G) :- var(V), !, - '$do_error'(instantiation_error,G). -'$check_callable'(M:_G1,G) :- var(M), !, - '$do_error'(instantiation_error,G). -'$check_callable'(_:G1,G) :- !, - '$check_callable'(G1,G). -'$check_callable'(A,G) :- number(A), !, - '$do_error'(type_error(callable,A),G). -'$check_callable'(R,G) :- db_reference(R), !, - '$do_error'(type_error(callable,R),G). -'$check_callable'(_,_). - - '$loop'(Stream,exo) :- prolog_flag(agc_margin,Old,0), prompt1(': '), prompt(_,' '), @@ -861,16 +848,16 @@ gated_call(Setup, Goal, Catcher, Cleanup) :- % % split head and body, generate an error if body is unbound. % -'$check_head_and_body'(C,M,H,B,P) :- +'$check_head_and_body'(C,M,H,B,_P) :- '$yap_strip_module'(C,M1,(MH:-B0)), !, '$yap_strip_module'(M1:MH,M,H), ( M == M1 -> B = B0 ; B = M1:B0), - is_callable(M:H,P). + is_callable(M:H). -'$check_head_and_body'(MH, M, H, true, P) :- +'$check_head_and_body'(MH, M, H, true, _XsP) :- '$yap_strip_module'(MH,M,H), - is_callable(M:H,P). + is_callable(M:H). % term expansion % % return two arguments: Expanded0 is the term after "USER" expansion. diff --git a/pl/undefined.yap b/pl/undefined.yap index 4b01e029d..016ca7cf3 100644 --- a/pl/undefined.yap +++ b/pl/undefined.yap @@ -72,9 +72,7 @@ undefined_query(G0, M0, Cut) :- '$handle_error'(error,Goal,Mod) :- functor(Goal,Name,Arity), - 'program_continuation'(PMod,PName,PAr), - '$do_error'(existence_error(procedure,Name/Arity), - context(Mod:Goal,PMod:PName/PAr)). + '$do_error'(existence_error(procedure,Name/Arity), Mod:Goal). '$handle_error'(warning,Goal,Mod) :- functor(Goal,Name,Arity), 'program_continuation'(PMod,PName,PAr), diff --git a/swi/library/CMakeLists.txt b/swi/library/CMakeLists.txt index 8b8889098..2c8c5c614 100644 --- a/swi/library/CMakeLists.txt +++ b/swi/library/CMakeLists.txt @@ -1,5 +1,7 @@ set (LIBRARY_PL +INDEX.pl aggregate.pl + autoloader.yap base64.pl broadcast.pl ctypes.pl diff --git a/library/INDEX.pl b/swi/library/INDEX.pl similarity index 100% rename from library/INDEX.pl rename to swi/library/INDEX.pl diff --git a/swi/library/autoloader.yap b/swi/library/autoloader.yap new file mode 100644 index 000000000..b37ac4102 --- /dev/null +++ b/swi/library/autoloader.yap @@ -0,0 +1,132 @@ +/** + * @file autoloader.yap + + */ +:- module(autoloader,[make_library_index/0]). + +:- use_module(library(lists),[append/3]). + +:- dynamic exported/3, loaded/1. + +make_library_index :- + scan_library_exports, + scan_swi_exports. + +scan_library_exports :- + % init table file. + open('INDEX.pl', write, W), + close(W), + scan_exports('../GPL/aggregate', library(aggregate)), + scan_exports(apply, library(apply)), + scan_exports(arg, library(arg)), + scan_exports(assoc, library(assoc)), + scan_exports(avl, library(avl)), + scan_exports(bhash, library(bhash)), + scan_exports(charsio, library(charsio)), + scan_exports('../packages/chr/chr_swi', library(chr)), + scan_exports(clp/clpfd, library(clpfd)), + scan_exports('../packages/clpqr/clpr', library(clpr)), + scan_exports(gensym, library(gensym)), + scan_exports(heaps, library(heaps)), + scan_exports('../packages/jpl/jpl', library(jpl)), + scan_exports(lists, library(lists)), + scan_exports(nb, library(nb)), + scan_exports(occurs, library(occurs)), + scan_exports('../LGPL/option', library(option)), + scan_exports(ordsets, library(ordsets)), + scan_exports(pairs, library(pairs)), + scan_exports('../LGPL/prolog_xref', library(prolog_xref)), + scan_exports('../packages/plunit/plunit', library(plunit)), + scan_exports(queues, library(queues)), + scan_exports(random, library(random)), + scan_exports(rbtrees, library(rbtrees)), + scan_exports('../LGPL/readutil', library(readutil)), + scan_exports(regexp, library(regexp)), + scan_exports('../LGPL/shlib', library(shlib)), + scan_exports(system, library(system)), + scan_exports(terms, library(terms)), + scan_exports(timeout, library(timeout)), + scan_exports(trees, library(trees)). + +scan_exports(Library, CallName) :- + absolute_file_name(Library, Path, + [ file_type(prolog), + access(read), + file_errors(fail) + ]), + open(Path, read, O), + !, + get_exports(O, Exports, Module), + close(O), + open('INDEX.pl', append, W), + publish_exports(Exports, W, CallName, Module), + close(W). +scan_exports(Library) :- + format(user_error,'[ warning: library ~w not defined ]~n',[Library]). + +% +% SWI is the only language that uses autoload. +% +scan_swi_exports :- + retractall(exported(_,_,_)), + absolute_file_name(dialect/swi, Path, + [ file_type(prolog), + access(read), + file_errors(fail) + ]), + open(Path, read, O), + get_exports(O, Exports, Module), + get_reexports(O, Reexports, Exports), + close(O), + open('dialect/swi/INDEX.pl', write, W), + publish_exports(Reexports, W, library(dialect/swi), Module), + close(W). + +get_exports(O, Exports, Module) :- + read(O, (:- module(Module,Exports))), !. +get_exports(O, Exports, Module) :- + get_exports(O, Exports, Module). + +get_reexports(O, Exports, ExportsL) :- + read(O, (:- reexport(_File,ExportsI))), !, + get_reexports(O, Exports0, ExportsL), + append(ExportsI, Exports0, Exports). +get_reexports(_, Exports, Exports). + +publish_exports([], _, _, _). +publish_exports([F/A|Exports], W, Path, Module) :- + publish_export(F, A, W, Path, Module), + publish_exports(Exports, W, Path, Module). +publish_exports([F//A0|Exports], W, Path, Module) :- + A is A0+2, + publish_export(F, A, W, Path, Module), + publish_exports(Exports, W, Path, Module). +publish_exports([op(_,_,_)|Exports], W, Path, Module) :- + publish_exports(Exports, W, Path, Module). + +publish_export(F, A, _, _, Module) :- + exported(F, A, M), M \= Module, !, + format(user_error,'[ warning: clash between ~a and ~a over ~a/~d ]~n',[Module,M,F,A]). +publish_export(F, A, W, Path, Module) :- + assert(exported(F, A, Module)), !, + portray_clause(W, index(F, A, Module, Path)). + +find_predicate(G,ExportingModI) :- + nonvar(G), !, + functor(G, Name, Arity), + index(Name,Arity,ExportingModI,File), + ensure_file_loaded(File). +find_predicate(G,ExportingModI) :- + var(G), + index(Name,Arity,ExportingModI,File), + functor(G, Name, Arity), + ensure_file_loaded(File). + +ensure_file_loaded(File) :- + loaded(File), !. +ensure_file_loaded(File) :- + load_files(autoloader:File,[silent(true),if(not_loaded)]), + assert(loaded(File)). + +:- include('INDEX'). +