diff --git a/C/atomic.c b/C/atomic.c index 26c331754..fdc89aefa 100755 --- a/C/atomic.c +++ b/C/atomic.c @@ -700,7 +700,7 @@ restart_aux: if (IsNumTerm(t1)) { Term t2 = Deref(ARG2); Term t12 = Yap_NumberToListOfAtoms(t1 PASS_REGS); - if (t12) { + if (t12 && t2) { { pop_text_stack(l); return Yap_unify(t12, t2); diff --git a/C/errors.c b/C/errors.c index 40caa5fef..74dc66329 100755 --- a/C/errors.c +++ b/C/errors.c @@ -786,12 +786,14 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function, 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; - return P; -} -if (type == INTERRUPT_EVENT) { + if (LOCAL_ActiveError->errorNo == SYNTAX_ERROR) { + LOCAL_ActiveError->errorClass = SYNTAX_ERROR_CLASS; + return P; + } 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); diff --git a/C/exec.c b/C/exec.c index 00ab8ddda..0500d6857 100755 --- a/C/exec.c +++ b/C/exec.c @@ -1233,8 +1233,15 @@ static Int creep_step(USES_REGS1) { /* '$execute_nonstop'(Goal,Mod) return rc; } -static Int execute_nonstop(USES_REGS1) { /* '$execute_nonstop'(Goal,Mod) - */ + +/** + * @brief Two argument version of non-interruptible execution: this will + * ignore signals including debugging requests. + * + * @return Int succeeds if it can transfer control. + */ + +static Int execute_nonstop(USES_REGS1) { Term t = Deref(ARG1); Term mod = Deref(ARG2); unsigned int arity; @@ -1309,6 +1316,20 @@ static Int execute_nonstop(USES_REGS1) { /* '$execute_nonstop'(Goal,Mod) } } + +/** + * @brief One argument version of non-interruptible execution: this will + * ignore signals including debugging requests. + * + * @return Int succeeds if it can transfer control. + */ +static Int execute_nonstop1(USES_REGS1) +{ + ARG2 = CurrentModule; +return execute_nonstop( PASS_REGS1 ); +} + + static Int execute_0(USES_REGS1) { /* '$execute_0'(Goal) */ Term mod = CurrentModule; Term t = Yap_YapStripModule(Deref(ARG1), &mod); @@ -2233,6 +2254,7 @@ void Yap_InitExecFs(void) { #endif Yap_InitCPred("$execute0", 2, execute0, NoTracePredFlag); Yap_InitCPred("$execute_nonstop", 2, execute_nonstop, NoTracePredFlag); + Yap_InitCPred("$execute_nonstop", 1, execute_nonstop1, NoTracePredFlag); Yap_InitCPred("$creep_step", 2, creep_step, NoTracePredFlag); Yap_InitCPred("$execute_clause", 4, execute_clause, NoTracePredFlag); Yap_InitCPred("$current_choice_point", 1, current_choice_point, 0); diff --git a/C/text.c b/C/text.c index 627efd46a..47d442169 100644 --- a/C/text.c +++ b/C/text.c @@ -249,42 +249,62 @@ static void *codes2buf(Term t0, void *b0, bool *get_codes USES_REGS) { while (IsPairTerm(t)) { Term hd = HeadOfTerm(t); if (IsVarTerm(hd)) { - Yap_Error(INSTANTIATION_ERROR, t0, "scanning list of codes"); + Yap_ThrowError(INSTANTIATION_ERROR, hd, "scanning list of codes"); return NULL; } if (!IsIntegerTerm(hd)) { - Yap_Error(TYPE_ERROR_INTEGER, t0, "scanning list of codes"); + Yap_ThrowError(TYPE_ERROR_CHARACTER_CODE, hd, "scanning list of codes"); return NULL; } Int code = IntegerOfTerm(hd); if (code < 0) { - Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE, t0, + Yap_ThrowError(TYPE_ERROR_CHARACTER_CODE, hd, "scanning list of codes"); return NULL; } length += put_utf8(ar, code); t = TailOfTerm(t); + if (IsVarTerm(t)) { + Yap_ThrowError(INSTANTIATION_ERROR, t, "scanning list of codes"); + return NULL; + } + if (!IsPairTerm(t) && t != TermNil) { + Yap_ThrowError(TYPE_ERROR_LIST, t, "scanning list of codes"); + return NULL; + } } } else { while (IsPairTerm(t)) { Term hd = HeadOfTerm(t); + if (IsVarTerm(hd)) { + Yap_ThrowError(INSTANTIATION_ERROR, hd, "scanning list of codes"); + return NULL; + } if (!IsAtomTerm(hd)) { - Yap_Error(TYPE_ERROR_ATOM, t0, "scanning list of atoms"); + Yap_ThrowError(TYPE_ERROR_CHARACTER, hd, "scanning list of atoms"); return NULL; } const char *code = RepAtom(AtomOfTerm(hd))->StrOfAE; if (code < 0) { - Yap_Error(REPRESENTATION_ERROR_CHARACTER, t0, "scanning list of atoms"); + Yap_ThrowError(TYPE_ERROR_CHARACTER, hd, "scanning list of atoms"); return NULL; } length += strlen(code); t = TailOfTerm(t); + if (IsVarTerm(t)) { + Yap_ThrowError(INSTANTIATION_ERROR, t, "scanning list of codes"); + return NULL; + } + if (!IsPairTerm(t) && t != TermNil) { + Yap_ThrowError(TYPE_ERROR_LIST, t, "scanning list of codes"); + return NULL; + } } } if (!IsVarTerm(t)) { if (t != TermNil) { - Yap_Error(TYPE_ERROR_INTEGER, t0, "scanning list of codes"); + Yap_ThrowError(TYPE_ERROR_LIST, t0, "scanning list of codes"); return NULL; } } @@ -294,7 +314,6 @@ static void *codes2buf(Term t0, void *b0, bool *get_codes USES_REGS) { if (codes) { while (IsPairTerm(t)) { Term hd = HeadOfTerm(t); - Int code = IntegerOfTerm(hd); st = st + put_utf8(st, code); @@ -736,7 +755,18 @@ static size_t write_length(const unsigned char *s0, seq_tv_t *out USES_REGS) { static Term write_number(unsigned char *s, seq_tv_t *out, bool error_on USES_REGS) { Term t; - t = Yap_StringToNumberTerm((char *)s, &out->enc,true); + yap_error_descriptor_t new_error; + bool mdnew = true; + Yap_pushErrorContext(error_on, &new_error); + t = Yap_StringToNumberTerm((char *)s, &out->enc,error_on); + Yap_popErrorContext(mdnew, true); + if (error_on) { + if (t == 0 && LOCAL_ActiveError->errorNo != YAP_NO_ERROR) { + P = FAILCODE; + Yap_HandleError("scanningx"); + } + } + Yap_ResetException(LOCAL_ActiveError); return t; } diff --git a/H/YapFlags.h b/H/YapFlags.h index aaff6428f..88e6ddab3 100644 --- a/H/YapFlags.h +++ b/H/YapFlags.h @@ -17,7 +17,7 @@ /** @file YapFlags.h - @addtogroup Flags + @addtogroup YAPFlags */ #ifndef YAP_FLAGS_H diff --git a/H/YapLFlagInfo.h b/H/YapLFlagInfo.h index 7acb70172..da6bcda8b 100644 --- a/H/YapLFlagInfo.h +++ b/H/YapLFlagInfo.h @@ -18,10 +18,12 @@ /** @file YapLFlagInfo.h - @addtogroup Flags + @addtogroup YAPFlags */ +/** + `autoload`: set the system to look for undefined procedures */ YAP_FLAG( AUTOLOAD_FLAG, "autoload", true, booleanFlag, "false" , NULL ), +/** + `read-only flag, that tells if Prolog is in an inner top-level */ YAP_FLAG( BREAK_LEVEL_FLAG, "break_level", true, nat, "0" , NULL ), YAP_FLAG( CALL_COUNTING_FLAG, "call_counting", true, booleanFlag, "true" , NULL ), /** + `call_counting` diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 765680d56..17c5c8012 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -33,6 +33,8 @@ SET (CMAKE_HTML_EXTRA_ endforeach(i ${CMAKE_HTML_EXTRA_}) set(DOCS_EXCLUDE_ +${CMAKE_SOURCE_DIR}/build +${CMAKE_SOURCE_DIR}/Debug ${CMAKE_SOURCE_DIR}/packages/jpl ${CMAKE_SOURCE_DIR}/packages/swig ${CMAKE_SOURCE_DIR}/packages/myddas/sqlite3/src @@ -47,7 +49,6 @@ ${CMAKE_SOURCE_DIR}/packages/gecode/3.7.0 ${CMAKE_SOURCE_DIR}/packages/gecode/3.6.0 ${CMAKE_SOURCE_DIR}/packages/gecode/dev ${CMAKE_SOURCE_DIR}/C/traced_absmi_insts.h -${CMAKE_SOURCE_DIR}/H/locals.h ${CMAKE_SOURCE_DIR}/H/globals.h ${CMAKE_SOURCE_DIR}/packages/cplint ${CMAKE_SOURCE_DIR}/packages/CLPBN/examples diff --git a/docs/Doxyfile b/docs/Doxyfile index 35b3be2dc..b06c8b843 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -816,7 +816,7 @@ RECURSIVE = YES # Note that relative paths are relative to the directory from which doxygen is # run. -EXCLUDE = /home/vsc/github/yap-6.3/packages/jpl /home/vsc/github/yap-6.3/packages/swig /home/vsc/github/yap-6.3/packages/myddas/sqlite3/src /home/vsc/github/yap-6.3/packages/gecode/4.4.0 /home/vsc/github/yap-6.3/packages/gecode/4.2.1 /home/vsc/github/yap-6.3/packages/gecode/4.2.0 /home/vsc/github/yap-6.3/packages/gecode/4.0.0 /home/vsc/github/yap-6.3/packages/gecode/3.7.3 /home/vsc/github/yap-6.3/packages/gecode/3.7.2 /home/vsc/github/yap-6.3/packages/gecode/3.7.1 /home/vsc/github/yap-6.3/packages/gecode/3.7.0 /home/vsc/github/yap-6.3/packages/gecode/3.6.0 /home/vsc/github/yap-6.3/packages/gecode/dev /home/vsc/github/yap-6.3/C/traced_absmi_insts.h /home/vsc/github/yap-6.3/H/locals.h /home/vsc/github/yap-6.3/H/globals.h /home/vsc/github/yap-6.3/packages/cplint /home/vsc/github/yap-6.3/packages/CLPBN/examples /home/vsc/github/yap-6.3/packages/CLPBN/horus /home/vsc/github/yap-6.3/packages/prosqlite /home/vsc/github/yap-6.3/packages/pyswip /home/vsc/github/yap-6.3/packages/yap-lbfgs/liblbfgs-1.10 /home/vsc/github/yap-6.3/library/dialect/swi/os /home/vsc/github/yap-6.3/packages/gecode/gecode3_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode4_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode3.yap /home/vsc/github/yap-6.3/packages/gecode/gecode4.yap /home/vsc/github/yap-6.3/packages/gecode/gecode3_yap_hand_written.yap /home/vsc/github/yap-6.3/packages/gecode/gecode4_yap_hand_written.yap */CMakeFiles/* *~ */ +EXCLUDE = /home/vsc/github/yap-6.3/build /home/vsc/github/yap-6.3/Debug /home/vsc/github/yap-6.3/packages/jpl /home/vsc/github/yap-6.3/packages/swig /home/vsc/github/yap-6.3/packages/myddas/sqlite3/src /home/vsc/github/yap-6.3/packages/gecode/4.4.0 /home/vsc/github/yap-6.3/packages/gecode/4.2.1 /home/vsc/github/yap-6.3/packages/gecode/4.2.0 /home/vsc/github/yap-6.3/packages/gecode/4.0.0 /home/vsc/github/yap-6.3/packages/gecode/3.7.3 /home/vsc/github/yap-6.3/packages/gecode/3.7.2 /home/vsc/github/yap-6.3/packages/gecode/3.7.1 /home/vsc/github/yap-6.3/packages/gecode/3.7.0 /home/vsc/github/yap-6.3/packages/gecode/3.6.0 /home/vsc/github/yap-6.3/packages/gecode/dev /home/vsc/github/yap-6.3/C/traced_absmi_insts.h /home/vsc/github/yap-6.3/H/globals.h /home/vsc/github/yap-6.3/packages/cplint /home/vsc/github/yap-6.3/packages/CLPBN/examples /home/vsc/github/yap-6.3/packages/CLPBN/horus /home/vsc/github/yap-6.3/packages/prosqlite /home/vsc/github/yap-6.3/packages/pyswip /home/vsc/github/yap-6.3/packages/yap-lbfgs/liblbfgs-1.10 /home/vsc/github/yap-6.3/library/dialect/swi/os /home/vsc/github/yap-6.3/packages/gecode/gecode3_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode4_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode3.yap /home/vsc/github/yap-6.3/packages/gecode/gecode4.yap /home/vsc/github/yap-6.3/packages/gecode/gecode3_yap_hand_written.yap /home/vsc/github/yap-6.3/packages/gecode/gecode4_yap_hand_written.yap */CMakeFiles/* *~ */ # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded diff --git a/docs/checkpl.yap b/docs/checkpl.yap new file mode 100644 index 000000000..a07a1aa5d --- /dev/null +++ b/docs/checkpl.yap @@ -0,0 +1,65 @@ + +:- use_module(library(lists)). +:- use_module(library(lineutils)). + +:- initialization(main). + +main :- + %system('find . \( -name '*.pl' -o -name '*.yap' -o -name '*.c' -o -name '*.h' -o -name '*.cpp' -o -name '*.hh' \) -type f -print | xargs grep '@defgroup\|@ingroup\|@addtogroup\|@{|@}'). + + file_filter_with_start_end( docs, tmp, add2graph, initgraph, checkgraph). + +initgraph(_,_). + +:- dynamic node/3, edge/3, e_b_n/3. + +checkgraph(_,_) :- + e_b_n(F,KN,_C), + node(KF,KN,_), + add_edge(KF, F, KN), + fail. +checkgraph(_,_) :- + listing(node), + listing(edge). + + + add2graph(Line, _Out) :- + split( Line, "% \t/*:", [File, Job, Name|_]), + append( _, L, Line), + append(Name, R, L), + dispatch( Name, File, Job, R). + +dispatch( Name, File, "defgroup", Comment):- + atom_codes(KN, Name), + atom_codes(KF, File), + atom_codes(C, Comment), + add_node(KF, KN,C). +dispatch( Name, File, "addtogroup", Comment):- + atom_codes(KN, Name), + atom_codes(KF, File), + atom_codes(C, Comment), + add_node_edge(KF, KN,C). +dispatch( Name, File, "ingroup", Comment):- + atom_codes(KN, Name), + atom_codes(KF, File), + atom_codes(C, Comment), + add_edge(KF, KN,C). +add_node(F, K,_C) :- + node(_,K,_), + throw( repeat(F:K) ). +add_node(F, K,C) :- + assert(node(F,K,C)). + + add_node_edge(F, K,_C) :- + node(F1,K,_), + !, + assert(edge(F1,F,K)). + add_node_edge(F, K,C) :- + assert(node(F,K,C)). + + add_edge(F, K,_C) :- + node(F1,K,_), + !, + assert(edge(F1,F,K)). + add_edge(F, K,C) :- + assert(e_b_n(F,K,C)). diff --git a/docs/md/yap.md b/docs/md/yap.md index 894b0a0bb..b2aeb8d43 100644 --- a/docs/md/yap.md +++ b/docs/md/yap.md @@ -17,7 +17,7 @@ Porto. The manual is organised as follows: -+ @subpage install ++ @subpage INSTALL + @subpage run diff --git a/docs/my.yap b/docs/my.xxx similarity index 100% rename from docs/my.yap rename to docs/my.xxx diff --git a/docs/yapdocs.yap b/docs/yapdocs.xxx similarity index 100% rename from docs/yapdocs.yap rename to docs/yapdocs.xxx diff --git a/include/YapErrors.h b/include/YapErrors.h index 303f564e1..f2cdf62a2 100644 --- a/include/YapErrors.h +++ b/include/YapErrors.h @@ -141,6 +141,7 @@ E(RESOURCE_ERROR_TRAIL, RESOURCE_ERROR, "trail_space") E(RESOURCE_ERROR_STACK, RESOURCE_ERROR, "stack_space") E1(SYNTAX_ERROR, SYNTAX_ERROR_CLASS, "syntax_error") +E1(SYNTAX_ERROR_NUMBER, SYNTAX_ERROR_CLASS, "syntax_error") E(SYSTEM_ERROR_INTERNAL, SYSTEM_ERROR_CLASS, "internal") E(SYSTEM_ERROR_COMPILER, SYSTEM_ERROR_CLASS, "compiler") diff --git a/os/chartypes.c b/os/chartypes.c index 67d407a88..b85c6a7cd 100644 --- a/os/chartypes.c +++ b/os/chartypes.c @@ -82,8 +82,7 @@ Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, bool error_on) { CACHE_REGS int sno; Term t; - yap_error_descriptor_t new_error; - int i = push_text_stack(); + int i = push_text_stack(); sno = Yap_open_buf_read_stream(s, strlen(s), encp, MEM_BUF_USER); if (sno < 0) @@ -92,7 +91,6 @@ Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, bool error_on) { GLOBAL_Stream[sno].encoding = *encp; else GLOBAL_Stream[sno].encoding = LOCAL_encoding; - bool new_rec = Yap_pushErrorContext(error_on,&new_error); #ifdef __ANDROID__ while (*s && isblank(*s) && Yap_wide_chtype(*s) == BS) s++; @@ -101,7 +99,6 @@ Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, bool error_on) { Yap_CloseStream(sno); UNLOCK(GLOBAL_Stream[sno].streamlock); pop_text_stack(i); - Yap_popErrorContext(new_rec , error_on); return t; } diff --git a/packages/raptor/doc/Doxyfile b/packages/raptor/doc/Doxyfile index 651e67e6e..140da6681 100644 --- a/packages/raptor/doc/Doxyfile +++ b/packages/raptor/doc/Doxyfile @@ -816,7 +816,7 @@ RECURSIVE = YES # Note that relative paths are relative to the directory from which doxygen is # run. -EXCLUDE = /home/vsc/github/yap-6.3/packages/jpl /home/vsc/github/yap-6.3/packages/swig /home/vsc/github/yap-6.3/packages/myddas/sqlite3/src /home/vsc/github/yap-6.3/packages/gecode/4.4.0 /home/vsc/github/yap-6.3/packages/gecode/4.2.1 /home/vsc/github/yap-6.3/packages/gecode/4.2.0 /home/vsc/github/yap-6.3/packages/gecode/4.0.0 /home/vsc/github/yap-6.3/packages/gecode/3.7.3 /home/vsc/github/yap-6.3/packages/gecode/3.7.2 /home/vsc/github/yap-6.3/packages/gecode/3.7.1 /home/vsc/github/yap-6.3/packages/gecode/3.7.0 /home/vsc/github/yap-6.3/packages/gecode/3.6.0 /home/vsc/github/yap-6.3/packages/gecode/dev /home/vsc/github/yap-6.3/C/traced_absmi_insts.h /home/vsc/github/yap-6.3/H/locals.h /home/vsc/github/yap-6.3/H/globals.h /home/vsc/github/yap-6.3/packages/cplint /home/vsc/github/yap-6.3/packages/CLPBN/examples /home/vsc/github/yap-6.3/packages/CLPBN/horus /home/vsc/github/yap-6.3/packages/prosqlite /home/vsc/github/yap-6.3/packages/pyswip /home/vsc/github/yap-6.3/packages/yap-lbfgs/liblbfgs-1.10 /home/vsc/github/yap-6.3/library/dialect/swi/os /home/vsc/github/yap-6.3/packages/gecode/gecode3_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode4_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode3.yap /home/vsc/github/yap-6.3/packages/gecode/gecode4.yap /home/vsc/github/yap-6.3/packages/gecode/gecode3_yap_hand_written.yap /home/vsc/github/yap-6.3/packages/gecode/gecode4_yap_hand_written.yap */CMakeFiles/* *~ */ +EXCLUDE = /home/vsc/github/yap-6.3/build /home/vsc/github/yap-6.3/Debug /home/vsc/github/yap-6.3/packages/jpl /home/vsc/github/yap-6.3/packages/swig /home/vsc/github/yap-6.3/packages/myddas/sqlite3/src /home/vsc/github/yap-6.3/packages/gecode/4.4.0 /home/vsc/github/yap-6.3/packages/gecode/4.2.1 /home/vsc/github/yap-6.3/packages/gecode/4.2.0 /home/vsc/github/yap-6.3/packages/gecode/4.0.0 /home/vsc/github/yap-6.3/packages/gecode/3.7.3 /home/vsc/github/yap-6.3/packages/gecode/3.7.2 /home/vsc/github/yap-6.3/packages/gecode/3.7.1 /home/vsc/github/yap-6.3/packages/gecode/3.7.0 /home/vsc/github/yap-6.3/packages/gecode/3.6.0 /home/vsc/github/yap-6.3/packages/gecode/dev /home/vsc/github/yap-6.3/C/traced_absmi_insts.h /home/vsc/github/yap-6.3/H/globals.h /home/vsc/github/yap-6.3/packages/cplint /home/vsc/github/yap-6.3/packages/CLPBN/examples /home/vsc/github/yap-6.3/packages/CLPBN/horus /home/vsc/github/yap-6.3/packages/prosqlite /home/vsc/github/yap-6.3/packages/pyswip /home/vsc/github/yap-6.3/packages/yap-lbfgs/liblbfgs-1.10 /home/vsc/github/yap-6.3/library/dialect/swi/os /home/vsc/github/yap-6.3/packages/gecode/gecode3_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode4_yap.cc /home/vsc/github/yap-6.3/packages/gecode/gecode3.yap /home/vsc/github/yap-6.3/packages/gecode/gecode4.yap /home/vsc/github/yap-6.3/packages/gecode/gecode3_yap_hand_written.yap /home/vsc/github/yap-6.3/packages/gecode/gecode4_yap_hand_written.yap */CMakeFiles/* *~ */ # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded diff --git a/pl/arrays.yap b/pl/arrays.yap index 54c1be381..d14d6ed3c 100644 --- a/pl/arrays.yap +++ b/pl/arrays.yap @@ -15,10 +15,13 @@ * * *************************************************************************/ -%% @{ - /** + +@file arrays.yap + @addtogroup YAPArrays + +@{ */ % % These are the array built-in predicates. They will only work if diff --git a/pl/debug.yap b/pl/debug.yap index d7ae4a411..eeedbbfc5 100644 --- a/pl/debug.yap +++ b/pl/debug.yap @@ -284,28 +284,30 @@ be lost. /** * @pred $trace( +Goal ) * + * This launches a goal from the debugger with the call. It must: + * - disable user interaction; + * - verify whether debugging is still ok; + * - enter the debugger core. + * The top gated_call should set up creeping for the next call. * - * @param _Goal_ is the goal to be examined. + * @param _Mod_:_Goal_ is the goal to be examined. * @return `call(Goal)` */ -% handle suspended goals -% take care with hidden goals. -% -% $trace may be called from user code, so be careful. '$trace'([Mod|G]) :- - '$stop_creeping'(_), + '$stop_creeping'(_), current_prolog_flag(debug, false), !, '$execute_nonstop'(G,Mod). '$trace'([Mod|G]) :- CP is '$last_choice_pt', gated_call( - '$debugger_input', - '$trace_query'(G, Mod, CP, not_expanded), - E, - '$continue_debugging'(E) + '$debugger_input', + '$trace_query'(G, Mod, CP, not_expanded), + E, + '$continue_debugging'(E) ). + '$continue_debugging'(_) :- !, current_prolog_flag(debug, false). '$continue_debugging'(exit) :- !, '$creep'. @@ -361,10 +363,12 @@ be lost. /** * @pred debugger_input. - * name of stream used for debugging, - * must be always connected to a tty. * - * '$debugger_input': try to connect the debugger to an open terminal. + * set up the stream used for debugging, + * - must be interactive. + * - default is `user_input`, but /dev/tty and CONIN$ can be used directly if + * user_input is bound to a file. + * */ '$debugger_input' :- stream_property(_,alias(debugger_input)), @@ -388,10 +392,13 @@ be lost. %% @pred '$trace_query'( +G, +M, +CP, +Expanded) % -%% debug a complex query - +% debug a complex query +% +'$trace_query'(V, M, CP, _) :- + '$creep', + !, + '$call'(V,M,V,CP). '$trace_query'(V, M, CP, _) :- - '$stop_creeping'(_), var(V), !, '$trace_query'(call(V), M, CP, _). '$trace_query'(!, _, CP, _) :- @@ -459,7 +466,7 @@ be lost. %% @pred $trace_goal( +Goal, +Module, +CallId, +CallInfo) %% -%% Actually debugs a +%% Actuallb sy debugs a %% goal! '$trace_goal'(G, M, GoalNumber, _H) :- ( @@ -490,18 +497,18 @@ be lost. '$debugger_expand_meta_call'(M:G, [], G1), strip_module(G1, MF, NG), gated_call( - '$enter_trace'(GoalNumber, G, M, H, _What), + '$enter_trace'(GoalNumber, G, M, H), '$execute_nonstop'(NG,MF), Port, '$trace_port'(Port, GoalNumber, G, M, true, H) ). % system_ '$trace_goal'(G, M, GoalNumber, H) :- - ( - '$is_opaque_predicate'(G, M) - ; - 'strip_module'(M:G, prolog, _NG) - ), + ( + '$is_opaque_predicate'(G, M) + ; + 'strip_module'(M:G, prolog, _NG) + ), !, gated_call( '$enter_trace'(GoalNumber, G, M, H), @@ -510,12 +517,24 @@ be lost. '$trace_port'(Port, GoalNumber, G, M, true, H) ). '$trace_goal'(G, M, GoalNumber, H) :- - gated_call( - '$enter_trace'(GoalNumber, G, M, H), - '$debug'( GoalNumber, G, M, H), - Port, - '$trace_port'(Port, GoalNumber, G, M, true, H) - ). + gated_call( + '$enter_trace'(GoalNumber, G, M, H), + '$debug'( GoalNumber, G, M, H), + Port, + '$trace_port'(Port, GoalNumber, G, M, true, H) + ). + + +/** + * @pred '$enter_trace'(+L, 0:G, +Module, +Info) + * + * call goal: prelims + * + * @parameter _Module_:_G_ + * @parameter _L_ is the list of active goals + * @parameter _Info_ describes the goal + * + */ '$enter_trace'(L, G, Module, Info) :- /* get goal no. */ ( var(L) -> @@ -543,6 +562,19 @@ be lost. /* and save it globaly */ '__NB_setval__'('$spy_gn',L1). +/** + * @pred '$enter_trace'(+L, 0:G, +Module, +Info) + * + * call goal: setup the diferrent cases + * - zip, just run through + * - source, call an interpreter + * - compiled code: try black magic. + * + * @parameter _Module_:_G_ + * @parameter _GoalNumber_ identifies the active goal + * @parameter _Info_ describes the goal + * + */ '$debug'(_, G, M, _H) :- '__NB_getval__'('$debug_status',state(zip,_Border,_), fail), !, @@ -555,12 +587,24 @@ be lost. '$creep_step'(GoalNumber, G, M, Info). - +/** + * @pred '$trace_go'(+L, 0:G, +Module, +Info) + * + * It needs to run in two separate steps: + * 1. Select a clause; + * 2. Debug it. + * We use a marker to track who we are in gated_call. + * + * @parameter _Module_:_G_ + * @parameter _GoalNumber_ identifies the active goal + * @parameter _Info_ describes the goal + * + */ '$trace_go'(GoalNumber, G, M, Info) :- - X=marker(_,M,G), + X=marker(_,M,G), CP is '$last_choice_pt', clause(M:G, Cl, _), - '$retry_clause'(GoalNumber, G, M, Info, X), + '$retry_clause'(GoalNumber, G, M, Info, X), '$trace_query'(Cl, M, CP, expanded). '$creep_step'(GoalNumber, G, M, Info) :- @@ -592,7 +636,7 @@ be lost. GoalNumber =< G0, !, fail. -'$re_trace_query'(forward(redo,G0), G, M, GoalNumber, H) :- + '$re_trace_query'(forward(redo,G0), G, M, GoalNumber, H) :- GoalNumber > G0, !, catch( @@ -638,7 +682,7 @@ be lost. '$TraceError'(forward(redo,_G0), _, _, _, _). %%% - backtrack long distance '$TraceError'(forward(fail,_G0),GoalNumber, _, _, _) :- !, - throw(error(fail(GoalNumber))). + throw(debugger(fail,GoalNumber)). %%% %%% - forward through the debugger '$TraceError'(forward('$wrapper',Event), _, _, _, _) :- diff --git a/pl/flags.yap b/pl/flags.yap index 6ec93294e..298666c4f 100644 --- a/pl/flags.yap +++ b/pl/flags.yap @@ -17,8 +17,8 @@ /** * @file flagd.ysp * - * @defgroup Flags Yap Flags - * @{} + * @defgroup YAPFlags Yap Flags + * * @ingroup builtins * */ diff --git a/pl/top.yap b/pl/top.yap index 87ab54131..e79aea434 100644 --- a/pl/top.yap +++ b/pl/top.yap @@ -670,6 +670,7 @@ write_query_answer( Bindings ) :- ; '$call'(Z,CP,G0,M) ). + '$call'((X*->Y| Z),CP,G0,M) :- !, ( '$current_choice_point'(DCP), @@ -831,7 +832,7 @@ gated_call(Setup, Goal, Catcher, Cleanup) :- Task0 = cleanup( All, Catcher, Cleanup, Tag, true, CP0), TaskF = cleanup( All, Catcher, Cleanup, Tag, false, CP0), '$tag_cleanup'(CP0, Task0), - '$execute'( Goal ), + '$execute_nonstop'( Goal ), '$cleanup_on_exit'(CP0, TaskF). @@ -965,7 +966,7 @@ catch(G, C, A) :- ). '$catch'(_,C,A) :- '$get_exception'(C0), - ( C = C0 -> '$execute'(A) ; throw(C0) ). + ( C = C0 -> '$execute_nonstop'(A, prolog) ; throw(C0) ). % variable throws are user-handled. '$run_catch'(G,E) :-