diff --git a/C/errors.c b/C/errors.c index 5c41fe2da..2b3753e7a 100755 --- a/C/errors.c +++ b/C/errors.c @@ -639,6 +639,69 @@ void Yap_ThrowExistingError(void) { Yap_exit(5); } +bool Yap_MkErrorRecord( yap_error_descriptor_t *r, + const char *file, const char *function, + int lineno, yap_error_number type, Term where, + const char *s) { + if (!Yap_pc_add_location(r, CP, B, ENV)) + Yap_env_add_location(r, CP, B, ENV, 0); + if (where == 0L || where == TermNil||type==INSTANTIATION_ERROR) { + r->culprit = NULL; + } else { + r->culprit = Yap_TermToBuffer( + where, ENC_ISO_UTF8, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f); + } + r->errorNo = type; + r->errorAsText = Yap_errorName(type); + r->errorClass = Yap_errorClass(type); + r->classAsText = + Yap_errorClassName(r->errorClass); + r->errorLine = lineno; + r->errorFunction = function; + r->errorFile = file; + Yap_prolog_add_culprit(r PASS_REGS1); + LOCAL_PrologMode |= InErrorMode; + Yap_ClearExs(); + // first, obtain current location + // sprintf(LOCAL_FileNameBuf, "%s:%d in C-function %s ", file, lineno, + // function); + // tf = MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)); +#if DEBUG_STRICT + if (Yap_heap_regs && !(LOCAL_PrologMode & BootMode)) + fprintf(stderr, "***** Processing Error %d (%lx,%x) %s***\n", type, + (unsigned long int)LOCAL_Signals, LOCAL_PrologMode, fmt); + else + fprintf(stderr, "***** Processing Error %d (%x) %s***\n", type, + LOCAL_PrologMode, fmt); +#endif + if (r->errorNo == SYNTAX_ERROR) { + r->errorClass = SYNTAX_ERROR_CLASS; + } else if (r->errorNo == SYNTAX_ERROR_NUMBER) { + r->errorClass = SYNTAX_ERROR_CLASS; + r->errorNo = SYNTAX_ERROR; + } + if (type == INTERRUPT_EVENT) { + fprintf(stderr, "%% YAP exiting: cannot handle signal %d\n", + (int)IntOfTerm(where)); + Yap_exit(1); + } + // fprintf(stderr, "warning: "); + if (s[0]) { + r->errorMsgLen = strlen(s) + 1; + r->errorMsg = malloc(r->errorMsgLen); + strcpy(r->errorMsg, s); + } else if (LOCAL_ErrorMessage && LOCAL_ErrorMessage[0]) { + r->errorMsgLen = strlen(LOCAL_ErrorMessage) + 1; + r->errorMsg = malloc(r->errorMsgLen); + strcpy(r->errorMsg, LOCAL_ErrorMessage); + } else { + r->errorMsgLen = 0; + r->errorMsg = 0; + } + return true; +} + + /** * @brief Yap_Error * This function handles errors in the C code. Check errors.yap for the @@ -666,7 +729,8 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function, va_list ap; char *fmt; char s[MAXPATHLEN]; - switch (type) { + + switch (type) { case SYSTEM_ERROR_INTERNAL: { fprintf(stderr, "%% Internal YAP Error: %s exiting....\n", tmpbuf); // serious = true; @@ -736,73 +800,8 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function, P = FAILCODE; LOCAL_PrologMode &= ~InErrorMode; return P; - default: - if (!Yap_pc_add_location(LOCAL_ActiveError, CP, B, ENV)) - Yap_env_add_location(LOCAL_ActiveError, CP, B, ENV, 0); - break; - } - - yap_error_number err = LOCAL_ActiveError->errorNo; - /* disallow recursive error handling */ - if (LOCAL_PrologMode & InErrorMode && err) { - fprintf(stderr, "%% ERROR %s %s WITHIN ERROR %s %s\n", - Yap_errorClassName(Yap_errorClass(type)), Yap_errorName(type), - Yap_errorClassName(Yap_errorClass(err)), Yap_errorName(err)); - return P; - } - if (LOCAL_PrologMode & BootMode || type == SYSTEM_ERROR_FATAL) { - /* crash in flames! */ - fprintf(stderr, - "%s:%d:0 YAP Fatal Error %d in function %s:\n %s exiting....\n", - file, lineno, type, function, s); - error_exit_yap(1); - } - if (LOCAL_DoingUndefp && type == EVALUATION_ERROR_UNDEFINED) { - P = FAILCODE; - CalculateStackGap(PASS_REGS1); - return P; - } - if (where == 0L || where == TermNil||type==INSTANTIATION_ERROR) { - LOCAL_ActiveError->culprit = NULL; - } else { - LOCAL_ActiveError->culprit = Yap_TermToBuffer( - where, ENC_ISO_UTF8, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f); - } - LOCAL_ActiveError->errorNo = type; - LOCAL_ActiveError->errorAsText = Yap_errorName(type); - LOCAL_ActiveError->errorClass = Yap_errorClass(type); - LOCAL_ActiveError->classAsText = - Yap_errorClassName(LOCAL_ActiveError->errorClass); - LOCAL_ActiveError->errorLine = lineno; - LOCAL_ActiveError->errorFunction = function; - LOCAL_ActiveError->errorFile = file; - Yap_prolog_add_culprit(LOCAL_ActiveError PASS_REGS1); - LOCAL_PrologMode |= InErrorMode; - Yap_ClearExs(); - // first, obtain current location - // sprintf(LOCAL_FileNameBuf, "%s:%d in C-function %s ", file, lineno, - // function); - // tf = MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)); -#if DEBUG_STRICT - if (Yap_heap_regs && !(LOCAL_PrologMode & BootMode)) - fprintf(stderr, "***** Processing Error %d (%lx,%x) %s***\n", type, - (unsigned long int)LOCAL_Signals, LOCAL_PrologMode, fmt); - else - fprintf(stderr, "***** Processing Error %d (%x) %s***\n", type, - LOCAL_PrologMode, fmt); -#endif - if (LOCAL_ActiveError->errorNo == SYNTAX_ERROR) { - LOCAL_ActiveError->errorClass = SYNTAX_ERROR_CLASS; - } else if (LOCAL_ActiveError->errorNo == SYNTAX_ERROR_NUMBER) { - LOCAL_ActiveError->errorClass = SYNTAX_ERROR_CLASS; - LOCAL_ActiveError->errorNo = SYNTAX_ERROR; - } - if (type == INTERRUPT_EVENT) { - fprintf(stderr, "%% YAP exiting: cannot handle signal %d\n", - (int)IntOfTerm(where)); - Yap_exit(1); - } - va_start(ap, where); + default: + va_start(ap, where); fmt = va_arg(ap, char *); if (fmt != NULL) { #if HAVE_VSNPRINTF @@ -810,22 +809,12 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function, #else (void)vsprintf(s, fmt, ap); #endif - // fprintf(stderr, "warning: "); - if (s[0]) { - LOCAL_ActiveError->errorMsgLen = strlen(s) + 1; - LOCAL_ActiveError->errorMsg = malloc(LOCAL_ActiveError->errorMsgLen); - strcpy(LOCAL_ActiveError->errorMsg, s); - } else if (LOCAL_ErrorMessage && LOCAL_ErrorMessage[0]) { - LOCAL_ActiveError->errorMsgLen = strlen(LOCAL_ErrorMessage) + 1; - LOCAL_ActiveError->errorMsg = malloc(LOCAL_ActiveError->errorMsgLen); - strcpy(LOCAL_ActiveError->errorMsg, LOCAL_ErrorMessage); - } else { - LOCAL_ActiveError->errorMsgLen = 0; - LOCAL_ActiveError->errorMsg = 0; - } + va_end(ap); + break; } - va_end(ap); - if (where == 0 || where == TermNil) { + } + Yap_MkErrorRecord(LOCAL_ActiveError, file, function, lineno, type, where, s); + if (where == 0 || where == TermNil) { LOCAL_ActiveError->culprit = 0; } if (P == (yamop *)(FAILCODE)) { diff --git a/C/exec.c b/C/exec.c index dba53f32c..b3fb5a456 100755 --- a/C/exec.c +++ b/C/exec.c @@ -54,7 +54,6 @@ static choiceptr cp_from_integer(Term cpt USES_REGS) { /** * Represents a choice-point as an offset to the top of local stack. This should * *be stable acroos gc or stack shifts. - * @procedure Yap_cp_as_integer * @param cp pointer to choice-point * @return Term with offset */ diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp index d6dcff868..c0db4b720 100644 --- a/CXX/yapi.cpp +++ b/CXX/yapi.cpp @@ -36,7 +36,7 @@ YAPPredicate::YAPPredicate(Term &t, Term &tmod, CELL *&ts, const char *pname) { ap = nullptr; restart: if (IsVarTerm(t)) { - Yap_Error(INSTANTIATION_ERROR, t0, pname); + throw YAPError( SOURCE(), INSTANTIATION_ERROR, t0, pname); } else if (IsAtomTerm(t)) { ap = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t), tmod)); ts = nullptr; @@ -49,15 +49,15 @@ restart: } else if (IsApplTerm(t)) { Functor fun = FunctorOfTerm(t); if (IsExtensionFunctor(fun)) { - Yap_Error(TYPE_ERROR_CALLABLE, Yap_PredicateIndicator(t, tmod), pname); + throw YAPError( SOURCE(), TYPE_ERROR_CALLABLE, Yap_PredicateIndicator(t, tmod), pname); } if (fun == FunctorModule) { tmod = ArgOfTerm(1, t); if (IsVarTerm(tmod)) { - Yap_Error(INSTANTIATION_ERROR, t0, pname); + throw YAPError( SOURCE(), INSTANTIATION_ERROR, t0, pname); } if (!IsAtomTerm(tmod)) { - Yap_Error(TYPE_ERROR_ATOM, t0, pname); + throw YAPError( SOURCE(), TYPE_ERROR_ATOM, t0, pname); } t = ArgOfTerm(2, t); goto restart; @@ -65,10 +65,33 @@ restart: ap = RepPredProp(Yap_GetPredPropByFunc(fun, tmod)); ts = RepAppl(t) + 1; } else { - Yap_Error(TYPE_ERROR_CALLABLE, t0, pname); + throw YAPError( SOURCE(), TYPE_ERROR_CALLABLE, t0, pname); } } + Term YAPTerm::getArg(arity_t i) { + BACKUP_MACHINE_REGS(); + Term tf = 0; + Term t0 = gt(); + + if (IsApplTerm(t0)) { + if (i > ArityOfFunctor(FunctorOfTerm(t0))) + throw YAPError( SOURCE(), DOMAIN_ERROR_OUT_OF_RANGE, t0, "t0.getArg()"); + tf = (ArgOfTerm(i, t0)); + } else if (IsPairTerm(t0)) { + if (i == 1) + tf = (HeadOfTerm(t0)); + else if (i == 2) + tf = (TailOfTerm(t0)); + else + throw YAPError( SOURCE(), DOMAIN_ERROR_OUT_OF_RANGE, t0, "t0.getArg()"); + } else { + throw YAPError( SOURCE(), TYPE_ERROR_COMPOUND, t0, "t0.getArg()"); + } + RECOVER_MACHINE_REGS(); + return tf; + } + YAPAtomTerm::YAPAtomTerm(char s[]) { // build string BACKUP_H(); @@ -242,7 +265,7 @@ Term &YAPTerm::operator[](arity_t i) { tf = RepPair(t0) + 1; RECOVER_MACHINE_REGS(); } else { - Yap_Error(TYPE_ERROR_COMPOUND, t0, ""); + throw YAPError( SOURCE(), TYPE_ERROR_COMPOUND, t0, ""); } RECOVER_MACHINE_REGS(); return *tf; @@ -279,6 +302,24 @@ YAPPairTerm::YAPPairTerm() { RECOVER_H(); } +std::vector YAPPairTerm::listToArray() { + Term *tailp; + Term t1 = gt(); + Int l = Yap_SkipList(&t1, &tailp); + if (l < 0) { + throw YAPError( SOURCE(), TYPE_ERROR_LIST, (t), nullptr); + } + std::vector o = std::vector(l); + int i = 0; + Term t = gt(); + while (t != TermNil) { + o[i++] = HeadOfTerm(t); + t = TailOfTerm(t); + } + return o; + } + + YAP_tag_t YAPTerm::tag() { Term tt = gt(); if (IsVarTerm(tt)) { @@ -333,6 +374,16 @@ Term YAPTerm::deepCopy() { return (tn); } +Term YAPListTerm::cdr() { + Term to = gt(); + if (IsPairTerm(to)) + return (TailOfTerm(to)); + else if (to == TermNil) + return TermNil; + /* error */ + throw YAPError( SOURCE(), TYPE_ERROR_LIST, to, ""); + } + Term YAPListTerm::dup() { yhandle_t tn; BACKUP_MACHINE_REGS(); @@ -380,7 +431,7 @@ Term YAPListTerm::car() { if (IsPairTerm(to)) return (HeadOfTerm(to)); else { - Yap_Error(TYPE_ERROR_LIST, to, ""); + throw YAPError( SOURCE(), TYPE_ERROR_LIST, to, ""); return TermUnique; } } @@ -436,9 +487,9 @@ bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) { if (LOCAL_CommittedError != nullptr) { std::cerr << "Exception received by " << __func__ << "( " - << YAPError(LOCAL_CommittedError).text() << ").\n Forwarded...\n\n"; - // Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm); - // throw YAPError(); + << YAPError( LOCAL_CommittedError).text() << ").\n Forwarded...\n\n"; + // Yap_PopTermFromDB(info->errorTerm); + // throw throw YAPError( SOURCE(), ); } Yap_CloseHandles(q.CurSlot); RECOVER_MACHINE_REGS(); @@ -454,43 +505,50 @@ bool YAPEngine::mgoal(Term t, Term tmod) { CACHE_REGS BACKUP_MACHINE_REGS(); Term *ts = nullptr; - if (IsStringTerm(tmod)) - tmod = MkAtomTerm(Yap_LookupAtom(StringOfTerm(tmod))); - PredEntry *ap = (new YAPPredicate(t, tmod, ts, "C++"))->ap; - if (ap == nullptr || ap->OpcodeOfPred == UNDEF_OPCODE) { - ap = rewriteUndefEngineQuery(ap, t, tmod); - } - if (IsApplTerm(t)) - ts = RepAppl(t) + 1; - else if (IsPairTerm(t)) - ts = RepPair(t); - /* legal ap */ - arity_t arity = ap->ArityOfPE; + try { + if (IsStringTerm(tmod)) + tmod = MkAtomTerm(Yap_LookupAtom(StringOfTerm(tmod))); + PredEntry *ap = (new YAPPredicate(t, tmod, ts, "C++"))->ap; + if (ap == nullptr || ap->OpcodeOfPred == UNDEF_OPCODE) { + ap = rewriteUndefEngineQuery(ap, t, tmod); + } + if (IsApplTerm(t)) + ts = RepAppl(t) + 1; + else if (IsPairTerm(t)) + ts = RepPair(t); + /* legal ap */ + arity_t arity = ap->ArityOfPE; - for (arity_t i = 0; i < arity; i++) { - XREGS[i + 1] = ts[i]; - } - ts = nullptr; - bool result; - q.CurSlot = Yap_StartSlots(); - q.p = P; - q.cp = CP; + for (arity_t i = 0; i < arity; i++) { + XREGS[i + 1] = ts[i]; + } + ts = nullptr; + bool result; + q.CurSlot = Yap_StartSlots(); + q.p = P; + q.cp = CP; // allow Prolog style exception handling // don't forget, on success these guys may create slots - __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec "); - - result = (bool)YAP_EnterGoal(ap, nullptr, &q); - if (LOCAL_CommittedError != nullptr) { - std::cerr << "Exception received by " << __func__ << "( " - << YAPError(LOCAL_CommittedError).text() << ").\n Forwarded...\n\n"; - } - + __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec "); + + result = (bool)YAP_EnterGoal(ap, nullptr, &q); + if (LOCAL_CommittedError != nullptr && + LOCAL_CommittedError->errorNo != YAP_NO_ERROR) { + throw YAPError( LOCAL_CommittedError); + } { YAP_LeaveGoal(result, &q); // PyEval_RestoreThread(_save); RECOVER_MACHINE_REGS(); return result; } + } catch ( ... ) { + if (LOCAL_CommittedError != nullptr && + LOCAL_CommittedError->errorNo != YAP_NO_ERROR) { + std::cerr << "Exception received by " << __func__ << "( " + << YAPError( LOCAL_CommittedError).text() << ").\n Forwarded...\n\n"; + } + } } void YAPEngine::release() { @@ -527,7 +585,7 @@ Term YAPEngine::fun(Term t) { name = AtomDot; f = FunctorDot; } else { - Yap_ThrowError(TYPE_ERROR_CALLABLE, t, 0); + throw YAPError( SOURCE(), TYPE_ERROR_CALLABLE, t, 0); return 0L; } XREGS[arity + 1] = MkVarTerm(); @@ -548,9 +606,9 @@ Term YAPEngine::fun(Term t) { bool result = (bool)YAP_EnterGoal(ap, nullptr, &q); if (LOCAL_CommittedError != nullptr) { std::cerr << "Exception received by " << __func__ << "( " - << YAPError(LOCAL_CommittedError).text() << ").\n Forwarded...\n\n"; - // Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm); - // throw YAPError(); + << YAPError( LOCAL_CommittedError).text() << ").\n Forwarded...\n\n"; + // Yap_PopTermFromDB(info->errorTerm); + // throw throw YAPError( SOURCE(), ); } { YAP_LeaveGoal(result, &q); @@ -668,15 +726,15 @@ bool YAPQuery::next() { Yap_CloseHandles(q_handles); q_open = false; if (LOCAL_CommittedError != nullptr) { - // Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm); - // throw YAPError(); + // Yap_PopTermFromDB(info->errorTerm); + // throw throw YAPError( ); Term es[2]; es[0] = TermError; es[1] = MkErrorTerm(LOCAL_CommittedError); Functor f = Yap_MkFunctor(Yap_LookupAtom("print_message"), 2); YAP_RunGoalOnce(Yap_MkApplTerm(f, 2, es)); - // Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm); - // throw YAPError(); + // Yap_PopTermFromDB(info->errorTerm); + // throw throw YAPError( SOURCE(), ); } } else { q_handles = Yap_StartSlots(); @@ -806,7 +864,7 @@ void YAPEngine::doInit(YAP_file_type_t BootMode, YAPEngineArgs *engineArgs) { YAP_Init(engineArgs); /* Begin preprocessor code */ /* live */ -// yerror = YAPError(); +// yerror = throw YAPError( SOURCE(), ); #if YAP_PYTHON do_init_python(); #endif @@ -853,13 +911,15 @@ PredEntry *YAPPredicate::getPred(YAPTerm &tt, CELL *&outp) { CACHE_REGS Term m = Yap_CurrentModule(), t = tt.term(); t = Yap_StripModule(t, &m); + + std::cerr << "Exception received by " << __func__ << "( " + << tt.text() << ").\n Forwarded...\n\n"; + if (IsVarTerm(t) || IsNumTerm(t)) { if (IsVarTerm(t)) - Yap_ThrowError(INSTANTIATION_ERROR, tt.term(), 0); + throw YAPError( SOURCE(), INSTANTIATION_ERROR, tt.term(), 0); else if (IsNumTerm(t)) - Yap_ThrowError(TYPE_ERROR_CALLABLE, tt.term(), 0); - std::cerr << "Exception received by " << __func__ << "( " - << YAPTerm(tt).text() << ").\n Forwarded...\n\n"; + throw YAPError( SOURCE(), TYPE_ERROR_CALLABLE, tt.term(), 0); } tt.put(t); if (IsAtomTerm(t)) { @@ -878,7 +938,7 @@ PredEntry *YAPPredicate::getPred(YAPTerm &tt, CELL *&outp) { } Functor f = FunctorOfTerm(t); if (IsExtensionFunctor(f)) { - Yap_ThrowError(TYPE_ERROR_CALLABLE, t, 0); + throw YAPError( SOURCE(), TYPE_ERROR_CALLABLE, t, 0); } else { ap = RepPredProp(PredPropByFunc(f, m)); outp = RepAppl(t) + 1; @@ -943,34 +1003,41 @@ void *YAPPrologPredicate::retractClause(YAPTerm skeleton, bool all) { std::string YAPError::text() { char buf[256]; std::string s = ""; - if (LOCAL_ActiveError->errorFunction) { - s += LOCAL_ActiveError->errorFile; + if (info->errorNo == YAP_NO_ERROR) + return 0; + if (info->errorFunction) { + s += info->errorFile; s += ":"; - sprintf(buf, "%ld", (long int)LOCAL_ActiveError->errorLine); + sprintf(buf, "%ld", (long int)info->errorLine); s += buf; s += ":0 in C-code"; } - if (LOCAL_ActiveError->prologPredLine) { + if (info->prologPredLine) { s += "\n"; - s += LOCAL_ActiveError->prologPredFile; + s += info->prologPredFile; s += ":"; - sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredLine); - s += buf; // std::to_string(LOCAL_ActiveError->prologPredLine) ; - // YAPIntegerTerm(LOCAL_ActiveError->prologPredLine).text(); + sprintf(buf, "%ld", (long int)info->prologPredLine); + s += buf; // std::to_string(info->prologPredLine) ; + // YAPIntegerTerm(info->prologPredLine).text(); s += ":0 "; - s += LOCAL_ActiveError->prologPredModule; + s += info->prologPredModule; s += ":"; - s += (LOCAL_ActiveError->prologPredName); + s += (info->prologPredName); s += "/"; - sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredArity); - s += // std::to_string(LOCAL_ActiveError->prologPredArity); + sprintf(buf, "%ld", (long int)info->prologPredArity); + s += // std::to_string(info->prologPredArity); buf; } s += " error "; - if (LOCAL_ActiveError->classAsText != nullptr) - s += LOCAL_ActiveError->classAsText; + if (info->classAsText == nullptr) + info->classAsText = Yap_errorClassName(info->errorClass); + if (info->classAsText != nullptr) + s += info->classAsText; s += "."; - s += LOCAL_ActiveError->errorAsText; + if (info->errorAsText == nullptr) + info->errorAsText = Yap_errorName(info->errorNo); + if (info->errorAsText != nullptr) + s += info->errorAsText; s += ".\n"; // printf("%s\n", s.c_str()); return s.c_str(); @@ -996,11 +1063,6 @@ void YAPEngine::reSet() { RECOVER_MACHINE_REGS(); } -YAPError::YAPError(yap_error_number id, YAPTerm culprit, std::string txt) { - ID = id; - goal = culprit.text(); - info = txt; -} Term YAPEngine::top_level(std::string s) { /// parse string s and make term with var names @@ -1010,7 +1072,7 @@ Term YAPEngine::top_level(std::string s) { ARG2 = tp; ARG3 = MkVarTerm(); if (ARG1 == 0) - Yap_Error(SYNTAX_ERROR, ARG1, "in input query"); + throw YAPError( SOURCE(), SYNTAX_ERROR, ARG1, "in input query"); YAPPredicate p = YAPPredicate(YAP_TopGoal()); YAPQuery *Q = new YAPQuery(p, 0); Term ts[2]; diff --git a/CXX/yapi.hh b/CXX/yapi.hh index c5a3d4acb..e7268dfeb 100644 --- a/CXX/yapi.hh +++ b/CXX/yapi.hh @@ -121,6 +121,7 @@ class YAPModule; class YAPError; class YAPPredicate; + #include "yapa.hh" #include "yapie.hh" diff --git a/CXX/yapie.hh b/CXX/yapie.hh index c4e80d36b..93554e3fa 100644 --- a/CXX/yapie.hh +++ b/CXX/yapie.hh @@ -1,12 +1,12 @@ /** * @file yapie.hh * - * @defgroup yap-cplus-error-hanadlinge Errir Handling in the YAP interface. + * @defgroup yap-cplus-error-hanadlinge Error Handling in the YAP interface. * - * @brief this is an attempt at supporting error + * @brief error handling in C++ and OO languages * * @ingroup yap-cplus-interface - * @tableofcontents + * * * @{ * @@ -15,7 +15,7 @@ * YAP itself. One can also define one's own error objects. * * Errors will be thrown from the `C++` code, and may be processed in - * very different ways. The error object should provide as much data asa + * very different ways. The error object should provide as much data as * possible. */ @@ -24,43 +24,65 @@ #define YAPIE_HH class X_API YAPPPredicate; -class X_API YAPTerm; + + /// take information on a Prolog error: class X_API YAPError { - yap_error_number ID; - std::string goal, info; int swigcode; - + yap_error_descriptor_t *info; + public: - YAPError(){ - if (LOCAL_ActiveError == nullptr) - return; - ID = LOCAL_ActiveError->errorNo; - if (ID != YAP_NO_ERROR) {}; - std::cerr << "Error detected" << ID << "\n"; + /// wraps the default error descriptor + YAPError() { + info = LOCAL_ActiveError; + if (!info) + LOCAL_ActiveError = info = (yap_error_descriptor_t *)calloc( sizeof( yap_error_descriptor_t ), 1); + // if (info->errorNo != YAP_NO_ERROR) {}; + //std::cerr << "Error detected" << info->errorNo << "\n"; } - YAPError(yap_error_descriptor_t *des){ - ID = des->errorNo; - if (ID != YAP_NO_ERROR) {}; - std::cerr << "Error detected" << ID << "\n"; + /// if des != nullptr, wrap a preexisting error descriptor; + /// otherwise, generate a new one + YAPError(yap_error_descriptor_t *des) { + if (des) + info= des; + else info = (yap_error_descriptor_t *)calloc( sizeof( yap_error_descriptor_t ), 1); + // if (info->errorNo != YAP_NO_ERROR) {}; + //std::cerr << "Error detected" << info->errorNo << "\n"; + } + + /// error handler object with initial data when receiving the error term - YAPError(yap_error_number id, YAPTerm culprit, std::string txt); + // YAPError( std::string file, std::string function, int lineno, + // yap_error_number id, YAPTerm culprit, std::string txt) { + // info = new yap_error_descriptor_t; + // Yap_MkErrorRecord(info, file.c_str(), function.c_str(), lineno, id, culprit.term(), txt.c_str()); + //} + + /// error handler object with initial data when receiving the error term + YAPError( const char * file, const char * function, int lineno, + yap_error_number id, YAP_Term culprit, const char * txt) { + info = (yap_error_descriptor_t *)calloc( sizeof( yap_error_descriptor_t ), 1); + Yap_MkErrorRecord(info, file, function, lineno, id, culprit, txt); + } + + /// short version +#define SOURCE() __FILE__, __FUNCTION__, __LINE__ /// we just know the error number /// exact error ID - yap_error_number getID() { return LOCAL_ActiveError->errorNo; }; + yap_error_number getID() { return info->errorNo; }; /// class of error yap_error_class_number getErrorClass() { - return Yap_errorClass(LOCAL_ActiveError->errorNo); + return Yap_errorClass(info->errorNo); }; /// where in the code things happened; - const char *getFile() { return LOCAL_ActiveError->errorFile; }; + const char *getFile() { return info->errorFile; }; /// predicate things happened; - Int getLine() { return LOCAL_ActiveError->errorLine; }; + Int getLine() { return info->errorLine; }; /// the term that caused the bug - // YAPTerm getCulprit(LOCAL_ActiveError->errorFile){}; + // YAPTerm getCulprit(info->errorFile){}; /// text describing the Error std::string text(); }; diff --git a/CXX/yapt.hh b/CXX/yapt.hh index edc4f154d..23c27de5d 100644 --- a/CXX/yapt.hh +++ b/CXX/yapt.hh @@ -195,29 +195,8 @@ public: virtual bool isList() { return Yap_IsListTerm(gt()); } /// term is a list /// extract the argument i of the term, where i in 1...arityvoid *Yap_RepStreamFromId(int sno) - virtual Term getArg(arity_t i) { - BACKUP_MACHINE_REGS(); - Term tf = 0; - Term t0 = gt(); - - if (IsApplTerm(t0)) { - if (i > ArityOfFunctor(FunctorOfTerm(t0))) - YAPError(DOMAIN_ERROR_OUT_OF_RANGE, t0, "t0.getArg()"); - tf = (ArgOfTerm(i, t0)); - } else if (IsPairTerm(t0)) { - if (i == 1) - tf = (HeadOfTerm(t0)); - else if (i == 2) - tf = (TailOfTerm(t0)); - else - YAPError(DOMAIN_ERROR_OUT_OF_RANGE, t0, "t0.getArg()"); - } else { - YAPError(TYPE_ERROR_COMPOUND, t0, "t0.getArg()"); - } - RECOVER_MACHINE_REGS(); - return tf; - } - + virtual Term getArg(arity_t i); + /// extract the arity of the term /// variables have arity 0 virtual inline arity_t arity() { @@ -375,22 +354,7 @@ public: YAPTerm car() { return YAPTerm(HeadOfTerm(gt())); } bool nil() { return gt() == TermNil; } YAPPairTerm cdr() { return YAPPairTerm(TailOfTerm(gt())); } - std::vector listToArray() { - Term *tailp; - Term t1 = gt(); - Int l = Yap_SkipList(&t1, &tailp); - if (l < 0) { - throw YAPError(TYPE_ERROR_LIST, YAPTerm(t), ""); - } - std::vector o = std::vector(l); - int i = 0; - Term t = gt(); - while (t != TermNil) { - o[i++] = HeadOfTerm(t); - t = TailOfTerm(t); - } - return o; - } + std::vector listToArray(); }; /** @@ -455,15 +419,7 @@ public: /// Extract the tail elements of a list. /// /// @param[in] the list - Term cdr() { - Term to = gt(); - if (IsPairTerm(to)) - return (TailOfTerm(to)); - else if (to == TermNil) - return TermNil; - /* error */ - throw YAPError(TYPE_ERROR_LIST, YAPTerm(to), ""); - } + Term cdr(); /// copy a list. /// /// @param[in] the list diff --git a/H/YapFlags.h b/H/YapFlags.h index 5aa3fcb7c..48dc637a6 100644 --- a/H/YapFlags.h +++ b/H/YapFlags.h @@ -239,9 +239,9 @@ Set or read system properties for _Param_: #define YAP_FLAG(ITEM, NAME, WRITABLE, DEF, INIT, HELPER) ITEM -#define START_LOCAL_FLAGS enum { +#define START_LOCAL_FLAGS enum THREAD_LOCAL_FLAGS { #define END_LOCAL_FLAGS }; -#define START_GLOBAL_FLAGS enum { +#define START_GLOBAL_FLAGS enum GLOBAL_FLAGS { #define END_GLOBAL_FLAGS }; /* */ @@ -249,7 +249,8 @@ Set or read system properties for _Param_: /* Local flags */ #include "YapLFlagInfo.h" - + +#ifndef DOXYGEN #undef YAP_FLAG #undef START_LOCAL_FLAGS @@ -257,6 +258,8 @@ Set or read system properties for _Param_: #undef START_GLOBAL_FLAGS #undef END_GLOBAL_FLAGS +#endif + bool setYapFlag(Term tflag, Term t2); Term getYapFlag(Term tflag); diff --git a/H/YapGFlagInfo.h b/H/YapGFlagInfo.h index dd47f7039..848f54e12 100644 --- a/H/YapGFlagInfo.h +++ b/H/YapGFlagInfo.h @@ -17,11 +17,10 @@ /** @file YapGFlagInfo.h - @addtogroup YAPGFlags YAPGlobalFlags - @ingroup builtins + @addtogroup YAPFlags @{ - @enum global_flags_setup Global Flags supported by YAP + @enum GLOBAL_FLAGS Global Flags supported by YAP @brief global flags and their values. */ diff --git a/H/YapLFlagInfo.h b/H/YapLFlagInfo.h index 28d7e15b8..24c16cc53 100644 --- a/H/YapLFlagInfo.h +++ b/H/YapLFlagInfo.h @@ -24,7 +24,8 @@ @{ -@enum local_flags_setup thread-local flag: + @enum THREAD_LOCAL_FLAGS Local Flags supported by YAP + @brief local flags and their values. */ START_LOCAL_FLAGS diff --git a/H/YapText.h b/H/YapText.h index fdc736f56..02c517f3a 100644 --- a/H/YapText.h +++ b/H/YapText.h @@ -354,10 +354,8 @@ typedef enum { YAP_STRING_INT = 0x40, /// target is an integer term YAP_STRING_FLOAT = 0x80, /// target is a floar term YAP_STRING_BIG = 0x100, /// target is an big num term - YAP_STRING_DATUM = - 0x200, /// associated with previous 3, use actual object if type, not tern - YAP_STRING_LENGTH = - 0x400, /// input: length is fixed; output: return integer with length + YAP_STRING_DATUM = 0x200, /// associated with previous 3, use actual object if type, not tern + YAP_STRING_LENGTH = 0x400, /// input: length is fixed; output: return integer with length YAP_STRING_NTH = 0x800, /// input: ignored; output: nth char YAP_STRING_TERM = 0x1000, // Generic term, if nothing else given YAP_STRING_DIFF = 0x2000, // difference list diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 467f41be3..28dec706f 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -59,13 +59,20 @@ ${CMAKE_SOURCE_DIR}/packages/prosqlite ${CMAKE_SOURCE_DIR}/packages/pyswip ${CMAKE_SOURCE_DIR}/packages/yap-lbfgs/liblbfgs-1.10 ${CMAKE_SOURCE_DIR}/library/dialect/swi/os -${CMAKE_SOURCE_DIR}/packages/gecode/gecode3_yap.cc - ${CMAKE_SOURCE_DIR}/packages/gecode/gecode4_yap.cc - ${CMAKE_SOURCE_DIR}/packages/gecode/gecode3.yap - ${CMAKE_SOURCE_DIR}/packages/gecode/gecode4.yap - ${CMAKE_SOURCE_DIR}/packages/gecode/gecode3_yap_hand_written.yap - ${CMAKE_SOURCE_DIR}/packages/gecode/gecode4_yap_hand_written.yap - */CMakeFiles/* *~ */#* +${CMAKE_SOURCE_DIR}/packages/python +${CMAKE_SOURCE_DIR}/*/bprolog/* + ${CMAKE_SOURCE_DIR}/*/prism/* + ${CMAKE_SOURCE_DIR}/*/gecodde/[345]* + ${CMAKE_SOURCE_DIR}/packages/gecode/gecode3_yap.cc + ${CMAKE_SOURCE_DIR}/packages/gecode/gecode4_yap.cc + ${CMAKE_SOURCE_DIR}/packages/gecode/gecode5_yap.cc + ${CMAKE_SOURCE_DIR}/packages/gecode/gecode3.yap + ${CMAKE_SOURCE_DIR}/packages/gecode/gecode4.yap + ${CMAKE_SOURCE_DIR}/packages/gecode/gecode5.yap + ${CMAKE_SOURCE_DIR}/packages/gecode/gecode3_yap_hand_written.yap + ${CMAKE_SOURCE_DIR}/packages/gecode/gecode4_yap_hand_written.yap + ${CMAKE_SOURCE_DIR}/packages/gecode/gecode5_yap_hand_written.yap + */CMakeFiles/* *~ */#* ) @@ -97,6 +104,7 @@ endforeach(i ${DOCS_EXCLUDE_}) ${CMAKE_SOURCE_DIR}/os ${CMAKE_SOURCE_DIR}/library ${CMAKE_SOURCE_DIR}/swi/library + ${CMAKE_SOURCE_DIR}/packages ) foreach(i ${DOC_INPUT_FILES_}) diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in index be133d21d..fc71aaaf1 100644 --- a/docs/Doxyfile.in +++ b/docs/Doxyfile.in @@ -98,7 +98,7 @@ OUTPUT_LANGUAGE = English # documentation (similar to Javadoc). Set to NO to disable this. # The default value is: YES. -BRIEF_MEMBER_DESC = NO +BRIEF_MEMBER_DESC = YES # If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief # description of a member or function before the detailed description @@ -107,7 +107,7 @@ BRIEF_MEMBER_DESC = NO # brief descriptions will be completely suppressed. # The default value is: YES. -REPEAT_BRIEF = NO +REPEAT_BRIEF = YES # This tag implements a quasi-intelligent brief description abbreviator that is # used to form the text in various listings. Each string in this list, if found @@ -899,15 +899,8 @@ EXCLUDE_SYMLINKS = NO # # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories for example use the pattern */test/* - -EXCLUDE_PATTERNS = @PROJECT_SOURCE_DIR@/*/bprolog/* \ - @PROJECT_SOURCE_DIR@/*/prism/* \ - @PROJECT_SOURCE_DIR@/packages/gecode/gecode4_yap.cc \ - @PROJECT_SOURCE_DIR@/packages/gecode/gecode3.yap \ - @PROJECT_SOURCE_DIR@/packages/gecode/gecode4.yap \ - @PROJECT_SOURCE_DIR@/packages/gecode/gecode3_yap_hand_written.yap \ - \ \ - @PROJECT_SOURCE_DIR@/packages/gecode/gecode4_yap_hand_written.yap + +EXCLUDE_PATTERNS = @DOCS_EXCLUDE@ # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the @@ -2071,7 +2064,7 @@ ENABLE_PREPROCESSING = YES # The default value is: NO. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -MACRO_EXPANSION = NO +MACRO_EXPANSION = YES # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then # the macro expansion is limited to the macros specified with the PREDEFINED and @@ -2079,14 +2072,14 @@ MACRO_EXPANSION = NO # The default value is: NO. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -EXPAND_ONLY_PREDEF = NO +EXPAND_ONLY_PREDEF = YES # If the SEARCH_INCLUDES tag is set to YES, the include files in the # INCLUDE_PATH will be searched if a #include is found. # The default value is: YES. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -SEARCH_INCLUDES = YES +SEARCH_INCLUDES = NO # The INCLUDE_PATH tag can be used to specify one or more directories that # contain include files that are not input files but should be processed by the @@ -2116,7 +2109,20 @@ INCLUDE_FILE_PATTERNS = # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -PREDEFINED = +PREDEFINED = + YAP_FLAG(ITEM,NAME,WRITABLE,DEF,INIT,HELPER)=ITEM \ + START_LOCAL_FLAGS="enum THREAD_LOCAL_FLAGS {" \ + END_LOCAL_FLAGS=" };"\ + START_GLOBAL_FLAGS="enum GLOBAL_FLAGS {" \ + END_GLOBAL_FLAGS="};" \ + LOCAL(A, B)="A B" \ + LOCAL_INIT(A, B, C)="A B;B = C" \ + LOCAL_ARRAY(A, B, C)="A B[C]" \ + LOCAL_ARRAY_ARRAY(A, B, C,D)="A B[C][D]"\ + LOCAL_INIT(A, B, C, D)="A B[C][D]"\ + LOCAL_INITF(A, B, C)=" A B; C"\ + LOCAL_INIT_RESTORE(A,B,C,D)="A B; C; D;"\ + PREG=Yap_REGS.P_ # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The @@ -2125,7 +2131,7 @@ PREDEFINED = # definition found in the source code. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -EXPAND_AS_DEFINED = +EXPAND_AS_DEFINED = # If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will # remove all references to function-like macros that are alone on a line, have diff --git a/docs/custom/doxy-boot.js b/docs/custom/doxy-boot.js index b192f5582..244bee61d 100644 --- a/docs/custom/doxy-boot.js +++ b/docs/custom/doxy-boot.js @@ -60,7 +60,7 @@ $( document ).ready(function() { $('div.fragment.well div.line:last').css('margin-bottom', '15px'); $('table.doxtable').removeClass('doxtable').addClass('table table-striped table-bordered table-small;').each(function(){ - $(this).prepend(''); + $(this).prepend('firstLasts'); $(this).find('tbody > tr:first').prependTo($(this).find('thead')); $(this).bootstrapTable('remove', {class: 'separator'}); $(this).find('td > span.success').parent().addClass('success'); diff --git a/docs/md/INSTALL.md b/docs/md/INSTALL.md index e02de2c66..d2042b8d8 100644 --- a/docs/md/INSTALL.md +++ b/docs/md/INSTALL.md @@ -1,12 +1,11 @@ -lDownloading and Installing YAP {#INSTALL} +Downloading and Installing YAP {#INSTALL} =========================== This text includes instructions to download and install YAP. [TOC] -Downloading YAP {#Download} ----------------- +## Downloading YAP {#Download} The latest development version of Yap-6 is available source-only through GIT repositories. The main reference repository is at @@ -32,7 +31,10 @@ The first argument is the repository, the last argument is the (optional) target It may be useful to know: + If you are have limited bandwith or disk spaceq, consider using - `git clone --depth XX` to only include the last `XX` commits. +~~~~~ +git clone --depth XX +~~~~~ +to only include the last `XX` commits. + Older versions of YAP were distributed with modules. YAP-6.3.5 is a single package, and it does not need `git submodule`. @@ -42,16 +44,16 @@ It may be useful to know: version of doxygen adapted to Prolog that was used to generate these documents. -Compiling YAP {#CompilingYAP} ----------------- +## CompilingYAP Compiling YAP + YAP-6.3.4 is a [cmake](www.cmake.org) based system. We use `cmake` because it supports mosts popular software, can generate Makefiles, Ninja, Apple's XCode, VisualStudio and ANdroid Studio, and because it includes packaging suppport, The steps required -to install core YAP under `cmake`: +to install core YAP under `cmake` are presented in detail next. -### The compiler +### Compilation The compiler *Status as of early 2017* @@ -104,7 +106,7 @@ available at GitHub. + make sure to install Python-3, and not Python-2, -### Compile and Install +### Compiling Compile and Install 1: Create a directory, say `Build` and `cd` to the directory (`cd Build`). *YAP should not be compiled at its rootxo directory, some packages do not allow for that. diff --git a/docs/md/packages.md b/docs/md/packages.md index cc2508806..feeca504c 100644 --- a/docs/md/packages.md +++ b/docs/md/packages.md @@ -1,7 +1,7 @@ YAP packages {#packages} ============ - + @subpage realxplxc + + @subpage realmd + @subpage BDDs diff --git a/include/YapError.h b/include/YapError.h index 2b037a23a..7342cd337 100644 --- a/include/YapError.h +++ b/include/YapError.h @@ -241,7 +241,10 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi, #define LOCAL_ErrorMessage LOCAL_ActiveError->errorMsg extern void Yap_ThrowExistingError(void); - + extern bool Yap_MkErrorRecord( yap_error_descriptor_t *r, + const char *file, const char *function, + int lineno, yap_error_number type, YAP_Term where, + const char *msg); extern yap_error_descriptor_t * Yap_pc_add_location(yap_error_descriptor_t *t, void *pc0, void *b_ptr0, void *env0); extern yap_error_descriptor_t *Yap_env_add_location(yap_error_descriptor_t *t,void *cp0, void * b_ptr0, void *env0, YAP_Int ignore_first); diff --git a/library/apply.yap b/library/apply.yap index 60ded7e4d..fdac0ce03 100644 --- a/library/apply.yap +++ b/library/apply.yap @@ -5,7 +5,6 @@ * * @brief Stub for maplist and friends * - * */ @@ -24,11 +23,10 @@ ]). /** -@defgroup apply_stub Apply Predicates -@ingroup library +@defgroup ApplyMaplist Appy Stub for maplist Predicates +@ingroup maplist - @{ This library provides a SWI-compatible set of utilities for applying a @@ -37,14 +35,14 @@ predicate to all elements of a list. The apply library is a _stub_, it just forwards definitions to the @ref maplist library. The predicates forwarded are: -* maplist:maplist/2, -* maplist:maplist/3, -* maplist:maplist/4, -* maplist:maplist/5, -* maplist:include/3, -* maplist:exclude/3, -* maplist:partition/4, -* maplist:partition/5 +* maplist/2, +* maplist/3, +* maplist/4, +* maplist/5, +* include/3, +* exclude/3, +* partition/4, +* partition/5 */ diff --git a/library/apply_macros.yap b/library/apply_macros.yap index 4299bcdda..e9bac5044 100644 --- a/library/apply_macros.yap +++ b/library/apply_macros.yap @@ -6,11 +6,12 @@ %% of a list or to all sub-terms of a term. :- module(apply_macros, []). +%% @namespace maplist /** @defgroup apply_macros Apply Interface to maplist -@ingroup library +@ingroup maplist @{ This library provides a SWI-compatible set of utilities for applying a @@ -19,14 +20,15 @@ predicate to all elements of a list. The apply library just forwards definitions to the @ref maplist library, these include: - - maplist/2, - - maplist/3, - - maplist/4, - - maplist/5, - - include/3, - - exclude/3, - - partition/4, - - partition/5 + ++ maplist/2, ++ maplist/3, ++ maplist/4, ++ maplist/5, ++ include/3, ++ exclude/3, ++ partition/4, ++ partition/5 */ diff --git a/library/maplist.yap b/library/maplist.yap index ae7e990ab..3c244ab4b 100644 --- a/library/maplist.yap +++ b/library/maplist.yap @@ -44,83 +44,6 @@ sumnodes/4 ]). -/** - * @defgroup maplist Map List and Term Operations - * @ingroup library - * @{ - * - * This library provides a set of utilities for applying a predicate to - * all elements of a list. They allow one to easily perform the most common do-loop constructs in Prolog. - * To avoid performance degradation, each call creates an - * equivalent Prolog program, without meta-calls, which is executed by - * the Prolog engine instead. The library was based on code - * by Joachim Schimpf and on code from SWI-Prolog, and it is also inspired by the GHC - * libraries. - * - * The routines are available once included with the - * `use_module(library(apply_macros))` command. - -*/ - - /* - -Examples: - -~~~~ - -given the progran: - -~~~~ -plus(X,Y,Z) :- Z is X + Y. - -plus_if_pos(X,Y,Z) :- Y > 0, Z is X + Y. - -vars(X, Y, [X|Y]) :- var(X), !. -vars(_, Y, Y). - -trans(TermIn, TermOut) :- - nonvar(TermIn), - TermIn =.. [p|Args], - TermOut =..[q|Args], !. -trans(X,X). -~~~~ -%success - - ?- maplist(plus(1), [1,2,3,4], [2,3,4,5]). - - ?- checklist(var, [X,Y,Z]). - - ?- selectlist(<(0), [-1,0,1], [1]). - - ?- convlist(plus_if_pos(1), [-1,0,1], [2]). - - ?- sumlist(plus, [1,2,3,4], 1, 11). - - ?- maplist(mapargs(number_atom),[c(1),s(1,2,3)],[c('1'),s('1','2','3')]). -~~~~ - - */ - - - -/** @pred maplist( 2:Pred, + _List1_,+ _List2_) - -Apply _Pred_ on all successive pairs of elements from - _List1_ and - _List2_. Fails if _Pred_ can not be applied to a -pair. See the example above. - - -*/ - -/** @pred maplist(3:Pred,+ List1,+ List2,+ List4) - -Apply _Pred_ on all successive triples of elements from _List1_, - _List2_ and _List3_. Fails if _Pred_ can not be applied to a -triple. See the example above. - - */ - :- meta_predicate selectlist(2,+,-), selectlist(3,+,+,-), @@ -161,6 +84,73 @@ triple. See the example above. :- use_module(library(charsio), [format_to_chars/3, read_from_chars/2]). :- use_module(library(occurs), [sub_term/2]). +/** + * @defgroup maplist Map List and Term Operations + * @ingroup library + * @{ + * + * This library provides a set of utilities for applying a predicate to + * all elements of a list. They allow one to easily perform the most common do-loop constructs in Prolog. + * To avoid performance degradation, each call creates an + * equivalent Prolog program, without meta-calls, which is executed by + * the Prolog engine instead. The library was based on code + * by Joachim Schimpf and on code from SWI-Prolog, and it is also inspired by the GHC + * libraries. + * + * The routines are available once included with the + * `use_module(library(maplist))` command. + * Examples: + * + * ~~~~ + * plus(X,Y,Z) :- Z is X + Y. + * + * plus_if_pos(X,Y,Z) :- Y > 0, Z is X + Y. + * + * vars(X, Y, [X|Y]) :- var(X), !. + * vars(_, Y, Y). + * + * trans(TermIn, TermOut) :- + * nonvar(TermIn), + * TermIn =.. [p|Args], + * TermOut =..[q|Args], !. + * trans(X,X). + * ~~~~ + * %success + * + * ?- maplist(plus(1), [1,2,3,4], [2,3,4,5]). + * + * ?- checklist(var, [X,Y,Z]). + * + * ?- selectlist(<(0), [-1,0,1], [1]). + * + * ?- convlist(plus_if_pos(1), [-1,0,1], [2]). + * + * ?- sumlist(plus, [1,2,3,4], 1, 11). + * + * ?- maplist(mapargs(number_atom),[c(1),s(1,2,3)],[c('1'),s('1','2','3')]). + * ~~~~ + * + **/ + +/** @pred maplist( 2:Pred, + _List1_,+ _List2_) + +Apply _Pred_ on all successive pairs of elements from + _List1_ and + _List2_. Fails if _Pred_ can not be applied to a +pair. See the example above. + + +*/ + +/** @pred maplist(3:Pred,+ List1,+ List2,+ List4) + +Apply _Pred_ on all successive triples of elements from _List1_, + _List2_ and _List3_. Fails if _Pred_ can not be applied to a +triple. See the example above. + + */ + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Definitions for Metacalls diff --git a/mkdocs/mkdocs.yml b/mkdocs/mkdocs.yml index 5c81daac7..5ba1e8850 100644 --- a/mkdocs/mkdocs.yml +++ b/mkdocs/mkdocs.yml @@ -1,8 +1,10 @@ site_name: 'YAP' theme: 'readthedocs' +markdown_extensions: +use_directory_urls: false plugins: - - search - - awesome-pages: - filename: .index - disable_auto_arrange_index: false - collapse_single_pages: true \ No newline at end of file + - search + - awesome-pages: + filename: .index + disable_auto_arrange_index: false + collapse_single_pages: true \ No newline at end of file diff --git a/packages/ProbLog/problog.yap b/packages/ProbLog/problog.yap index 0bce42b5f..3dece1c0a 100644 --- a/packages/ProbLog/problog.yap +++ b/packages/ProbLog/problog.yap @@ -287,7 +287,8 @@ Instead of probabilities every fact has a t( ) prefix. The t stands for tunable ~~~~ t(0.5)::heads(_). ~~~~ -* + +*/ /** @defgroup ProbLogPredicates ProbLog Predicates @ingroup ProbLog1 @@ -300,7 +301,6 @@ In the description of the arguments of functors the following notation will be u + a preceding minus sign will denote an "output argument" + an argument with no preceding symbol can be used in both ways -@{ /** * @pred problog_max(+G, -Prob, -FactsUsed) @@ -344,7 +344,6 @@ This predicate returns the lower and upper bound of the probability of achieving This predicate returns the lower bound of the probability of achieving the goal G obtained by cutting the sld tree at the given probability for each branch. */ -%% @} /** @defgroup ProbLogParameterLearning ProbLog Parameter Learning Predicates @@ -4188,3 +4187,4 @@ user:term_expansion(Term,ExpandedTerm) :- problog:term_expansion_intern(Term,Mod,ExpandedTerm). %% @} + diff --git a/packages/bdd/bdd.yap b/packages/bdd/bdd.yap index a2ed5bb1c..19b98fea7 100644 --- a/packages/bdd/bdd.yap +++ b/packages/bdd/bdd.yap @@ -1,6 +1,6 @@ /** - @file bdd.yap + @file bdd/bdd.yap @defgroup BDDsPL Binary Decision Diagrams and Friends @ingroup BDDs diff --git a/packages/chr/chr_runtime.pl b/packages/chr/chr_runtime.pl index 4f61926ca..bcb6d82b2 100644 --- a/packages/chr/chr_runtime.pl +++ b/packages/chr/chr_runtime.pl @@ -68,6 +68,15 @@ %% * Added initialization directives for saved-states %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% @file chr_runtime.pl +%% @brief CHR runtime + +%% @namespace locked +%% @brief internal CHR space + +%% @namespace error_locked +%% @brief internal CHR space + %% @addtogroup CHR_Rule_Types Rule Types %% @ingroup CHR % diff --git a/packages/chr/chr_swi.pl b/packages/chr/chr_swi.pl index bebbbfd51..4a7e51818 100644 --- a/packages/chr/chr_swi.pl +++ b/packages/chr/chr_swi.pl @@ -29,6 +29,12 @@ the GNU General Public License. */ +%% @file chr_swi.pl +%% @brief CHR SWI specific + +%% @namespace check +%% @brief internal space + %% SWI begin %% @addtogroup CHR chr %% @ingroup packages diff --git a/packages/gecode/gecode5_yap_hand_written.yap b/packages/gecode/gecode5_yap_hand_written.yap index 1ad38b8a5..b921b74e6 100644 --- a/packages/gecode/gecode5_yap_hand_written.yap +++ b/packages/gecode/gecode5_yap_hand_written.yap @@ -1341,3 +1341,6 @@ keep_list_(_, X) :- (Space += maximize(X,Y)) :- !, maximize(Space,X,Y). (Space += keep(X)) :- !, keep_(Space,X). + +%! @} + diff --git a/packages/gecode/gecode6_yap_hand_written.yap b/packages/gecode/gecode6_yap_hand_written.yap index e3e32b8ad..3eff8c69b 100644 --- a/packages/gecode/gecode6_yap_hand_written.yap +++ b/packages/gecode/gecode6_yap_hand_written.yap @@ -1341,3 +1341,5 @@ keep_list_(_, X) :- (Space += maximize(X,Y)) :- !, maximize(Space,X,Y). (Space += keep(X)) :- !, keep_(Space,X). + +%! @} diff --git a/packages/real/real.c b/packages/real/real.c index 2ddb7f37f..5a08e092d 100644 --- a/packages/real/real.c +++ b/packages/real/real.c @@ -1,3 +1,19 @@ + +/** + * @file real.c + * @date Sat May 19 13:44:04 2018 + * + * @brief Prolog to R interface + * + * + */ + +/** + * @defgroup realI Interface Prolog to R + * @ brief How to call R from YAP + * @ingroup realm + * @{ + */ #define CSTACK_DEFNS #include "rconfig.h" #if HAVE_R_H || !defined(_YAP_NOT_INSTALLED_) @@ -2210,3 +2226,5 @@ install_real(void) { /* FUNCTOR_dot2 = PL_new_functor(PL_new_atom("."), 2); */ } #endif /* R_H */ +/// @} + diff --git a/packages/real/real.md b/packages/real/real.md index 8b7045ec5..009cac360 100644 --- a/packages/real/real.md +++ b/packages/real/real.md @@ -1,5 +1,3 @@ -The R Prolog Programming Interface {#realxplxc} -=================================== @file real.md @author Nicos Angelopoulos @@ -7,6 +5,10 @@ The R Prolog Programming Interface {#realxplxc} @version 1:0:4, 2013/12/25, sinter_class @license Perl Artistic License +@defgroup realmd The R Prolog Programming Interface +@ingroup packages +@{ + + @ref realpl This library enables the communication with an R process started as a shared library. @@ -42,7 +44,10 @@ The main modes for utilising the interface are Pass Prolog data to R, pass R data to Prolog or assign an R expression to an assignable R expression. -### Testing Real {#TestingR} + +@defgroup TestingR Testing Real +@ingroup realmd +@{ There is a raft of examples packed in a single file that tests the library. @@ -53,7 +58,10 @@ There is a raft of examples packed in a single file that tests the library. ?- edit( pack(real/examples/for_real) ). ~~~~ -### Prolog and R Syntax {#RSyntax} +@} +@defgroup RSyntax Prolog and R Syntax +@ingroup realmd +@{ There are syntactic conventions in R that make unparsable prolog code. Notably function and variable names are allowed to contain dots, square brackets are used @@ -155,7 +163,11 @@ This is only advisable for short data structures. For instance, Through this interface it is more convenient to be explicit about R chars by Prolog prepending atoms or codes with + as in the above example. -### Examples {#RealExamples} + +@} +@defgroup RealExamples Examples +@ingroup realmd +@{ ~~~~ @@ -202,7 +214,12 @@ logical :- ~~~~ -#### Info + +@} +@defgroup RealInfo Real Information +@ingroup realmd +@{ + @see http://stoics.org.uk/~nicos/sware/real @see pack(real/examples/for_real) @@ -211,10 +228,233 @@ logical :- @see pack(real/doc/padl2013-real.pdf) @see http://www.r-project.org/ -Also @subpaage yap-real describes the YAP specfic details in real. +Also @ref yap-real describes the YAP specfic details in real. + +@file real.md +' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll@} +@defgroup yap_real Development of real in YAP +@ingroup realmd +@{ -*/Development of real in YAP (#yap_real) ---------------------------- YAP includes a development version of real, designed to experiment with the internals of the implementation of R. It includes major @@ -264,3 +504,6 @@ in~\cite{}. Their major differences: - Updates: Nicos Angelopoulos, Dec. 2013, March, 2014 - Updates: Vitor Santos Costa Dec. 2015 + +@} +@} diff --git a/packages/real/real.pl b/packages/real/real.pl index 9df15b237..17eea60bf 100755 --- a/packages/real/real.pl +++ b/packages/real/real.pl @@ -14,7 +14,7 @@ * @file real.pl * @brief Prolog component of r_interface * @defgroup realpl Prolog component of r_interface - * @ingroup real + * @ingroup realmd * @{ * Initialization code and key predicares for R-Prolog interface. * @@ -950,4 +950,5 @@ prolog:message( r_root ) --> :- initialization( set_prolog_flag( double_quotes, string) ). -%%% @} +%% @} + diff --git a/packages/yap-lbfgs/lbfgs.pl b/packages/yap-lbfgs/lbfgs.pl index 45b34debf..2965481c2 100644 --- a/packages/yap-lbfgs/lbfgs.pl +++ b/packages/yap-lbfgs/lbfgs.pl @@ -278,3 +278,4 @@ print_param(Name,Value,Text,Dom) :- format(user,'~w~10+~w~19+~w~15+~w~30+~n',[Dom,Name,Value,Text]). +%% @} diff --git a/pl/absf.yap b/pl/absf.yap index eab63a0fe..58d56817d 100755 --- a/pl/absf.yap +++ b/pl/absf.yap @@ -14,7 +14,7 @@ @author L.Damas, V.S.Costa @defgroup AbsoluteFileName File Name Resolution - @ingroup builtins + @ingroup load_files Support for file name resolution through absolute_file_name/3 and friends. These utility built-ins describe a list of directories that diff --git a/pl/dialect.yap b/pl/dialect.yap index bf9612b43..b1acc28e7 100644 --- a/pl/dialect.yap +++ b/pl/dialect.yap @@ -7,7 +7,9 @@ * @brief support Prolog dialects * * @defgroup Dialects Compatibilty with other Prolog dialects - * @ingroup builtins + * @ingroup extensions + * @{ + * @brief Prolog dialects * */ @@ -54,7 +56,7 @@ check_dialect(Dialect) :- check_dialect(Dialect) :- '$do_error'(domain_error(dialect,Dialect),(:- expects_dialect(Dialect))). -%% exists_source(+Source) is semidet. +%% @pred exists_source(+Source) is semidet. % % True if Source (a term valid for load_files/2) exists. Fails % without error if this is not the case. The predicate is intended @@ -77,8 +79,8 @@ exists_source(Source, Path) :- file_errors(fail) ]). -%% source_exports(+Source, +Export) is semidet. -%% source_exports(+Source, -Export) is nondet. +%% @pred source_exports(+Source, +Export) is semidet. +%% @pred source_exports(+Source, -Export) is nondet. % % True if Source exports Export. Fails without error if this is % not the case. See also exists_source/1. @@ -93,7 +95,7 @@ source_exports(Source, Export) :- ; lists:member(Export, Exports) ). -%% open_source(+Source, -In:stream) is semidet. +%% @pred open_source(+Source, -In:stream) is semidet. % % Open a source location. @@ -108,3 +110,5 @@ open_source(File, In) :- exports(In, Exports) :- read(In, Term), Term = (:- module(_Name, Exports)). + +@} diff --git a/pl/spy.yap b/pl/spy.yap index 0aeecbb75..d03331ce7 100644 --- a/pl/spy.yap +++ b/pl/spy.yap @@ -33,7 +33,7 @@ /** * @defgroup DebSet Debugger Control - * @ingroup builtins Deb_Interaction + * @ingroup Deb_Interaction @{ The diff --git a/pl/utils.yap b/pl/utils.yap index 80e7808da..875744e1c 100644 --- a/pl/utils.yap +++ b/pl/utils.yap @@ -16,7 +16,7 @@ *************************************************************************/ /** - * @file utils.yap + * @file pl/utils.yap * @author VITOR SANTOS COSTA * @date Thu Oct 19 12:21:01 2017 * diff --git a/pl/ypp.yap b/pl/ypp.yap index bf9cd6396..bbb648b3f 100644 --- a/pl/ypp.yap +++ b/pl/ypp.yap @@ -34,6 +34,12 @@ /** * @defgroup ypp Yap PreProcessing * @ingroup library + * + * This program_continuation can be used as a preprocessor in the + * style of the `C` language. Currently, it must be used through + * ypp_consult and or ypp_reconsult. + * + * Notice that ypp uses `#` commands. * */