From 39f392be9c4240e1f57b54f1d1f9813c78bbfb02 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 1 Jun 2012 13:16:29 +0100 Subject: [PATCH] allow finer control over indexing sub-terms. improve flag code a bit. --- C/index.c | 7 ++++--- C/init.c | 3 ++- H/Yap.h | 5 ++--- docs/yap.tex | 7 ++++++- pl/flags.yap | 13 +++++++++++++ 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/C/index.c b/C/index.c index 8d4c05803..0922d5779 100644 --- a/C/index.c +++ b/C/index.c @@ -2545,12 +2545,13 @@ do_compound_index(ClauseDef *min0, ClauseDef* max0, Term* sreg, struct intermedi /* base case, just commit to the current code */ return emit_single_switch_case(min0, cint, first, clleft, fail_l); } - if (yap_flags[INDEXING_MODE_FLAG] == INDEX_MODE_SINGLE && ap->PredFlags & LogUpdatePredFlag) { + if ((yap_flags[INDEXING_MODE_FLAG] == INDEX_MODE_SINGLE && ap->PredFlags & LogUpdatePredFlag) || + (yap_flags[INDEXING_TERM_DEPTH_FLAG] && cint->term_depth - cint->last_index_new_depth > yap_flags[INDEXING_TERM_DEPTH_FLAG])) { *newlabp = do_var_clauses(min0, max0, FALSE, cint, first, clleft, fail_l, ap->ArityOfPE+1); - return ret_lab; + return ret_lab; } - if (sreg == NULL || cint->term_depth > 20) { + if (sreg == NULL) { return suspend_indexing(min0, max0, ap, cint); } cint->term_depth++; diff --git a/C/init.c b/C/init.c index ab764c9df..c9e4473ba 100644 --- a/C/init.c +++ b/C/init.c @@ -915,6 +915,7 @@ InitFlags(void) yap_flags[INDEXING_MODE_FLAG] = INDEX_MODE_MULTI; yap_flags[TABLING_MODE_FLAG] = 0; yap_flags[QUIET_MODE_FLAG] = FALSE; + yap_flags[INDEXING_TERM_DEPTH_FLAG] = 0L; } static void @@ -1316,7 +1317,7 @@ Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_s Yap_InitTime(); /* InitAbsmi must be done before InitCodes */ /* This must be done before initialising predicates */ - for (i = 0; i <= LAST_FLAG; i++) { + for (i = 0; i <= NUMBER_OF_YAP_FLAGS; i++) { yap_flags[i] = 0; } #ifdef MPW diff --git a/H/Yap.h b/H/Yap.h index 768906d2d..4005904a7 100755 --- a/H/Yap.h +++ b/H/Yap.h @@ -453,8 +453,9 @@ typedef enum TABLING_MODE_FLAG = 20, VARS_CAN_HAVE_QUOTE_FLAG = 21, QUIET_MODE_FLAG = 22, + INDEXING_TERM_DEPTH_FLAG = 23, /* let this be the last one */ - LAST_FLAG = 23 + NUMBER_OF_YAP_FLAGS = 24 } yap_flags; #define STRING_AS_CHARS 0 @@ -501,8 +502,6 @@ typedef enum YAP_FAIL_SIGNAL = 0x100000 /* P = FAILCODE */ } yap_signals; -#define NUMBER_OF_YAP_FLAGS LAST_FLAG - typedef enum { GPROF_NO_EVENT, diff --git a/docs/yap.tex b/docs/yap.tex index ada1ed178..0885ca694 100644 --- a/docs/yap.tex +++ b/docs/yap.tex @@ -8078,8 +8078,13 @@ for which YAP was compiled and Operating System information. @item index @findex index (yap_flag/2 option) +@* If @code{on} allow indexing (default), if @code{off} disable it, if +@code{single} allow on first argument only. + +@item index_sub_term_search_depth +@findex index (yap_flag/2 option) @* -If @code{on} allow indexing (default), if @code{off} disable it. +Maximum bound on searching sub-terms for indexing, if @code{0} (default) no bound. @item informational_messages @findex informational_messages (yap_flag/2 option) diff --git a/pl/flags.yap b/pl/flags.yap index da0ed4b14..e0593418e 100644 --- a/pl/flags.yap +++ b/pl/flags.yap @@ -236,6 +236,18 @@ yap_flag(index,X) :- yap_flag(index,X) :- '$do_error'(domain_error(flag_value,index+X),yap_flag(index,X)). +% do or do not indexation +yap_flag(index_sub_term_search_depth,X) :- var(X), + '$access_yap_flags'(23, X), !. +yap_flag(index_sub_term_search_depth,X,X) :- + integer(X), X > 0, + '$set_yap_flags'(23,X1). +yap_flag(index_sub_term_search_depth,X,X) :- + \+ integer(X), + '$do_error'(type_error(integer,X),yap_flag(index_sub_term_search_depth,X)). +yap_flag(index_sub_term_search_depth,X,X) :- + '$do_error'(domain_error(out_of_range,index_sub_term_search_depth+X),yap_flag(index_sub_term_search_depth,X)). + yap_flag(home,X) :- '$yap_home'(X). @@ -869,6 +881,7 @@ yap_flag(dialect,yap). '$yap_system_flag'(home ). '$yap_system_flag'(host_type ). '$yap_system_flag'(index). +'$yap_system_flag'(index_sub_term_search_depth). '$yap_system_flag'(tabling_mode). '$yap_system_flag'(informational_messages). '$yap_system_flag'(integer_rounding_function).