Update of /cvsroot/xsb/XSB/emu
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv12743
Modified Files:
builtin.c builtin.h slgdelay.c slgdelay.h tr_utils.c
Added Files:
table_inspection_defs.h
Log Message:
Adding scratch code for table inspection functions that may, if they're good, grow up into answer_completion and the like.
--- NEW FILE: table_inspection_defs.h ---
/* File: table_inspection_defs.h
** Contact: xsb-contact@...
**
** Copyright (C) The Research Foundation of SUNY, 1986, 1993-1998
** Copyright (C) ECRC, Germany, 1990
**
** XSB is free software; you can redistribute it and/or modify it under the
** terms of the GNU Library General Public License as published by the Free
** Software Foundation; either version 2 of the License, or (at your option)
** any later version.
**
** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
** FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
** for more details.
**
** You should have received a copy of the GNU Library General Public License
** along with XSB; if not, write to the Free Software Foundation,
** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
**
*/
#define FIND_COMPONENTS 0
#define FIND_FORWARD_DEPENDENCIES 1
#define FIND_BACKWARD_DEPENDENCIES 2
Index: builtin.c
===================================================================
RCS file: /cvsroot/xsb/XSB/emu/builtin.c,v
retrieving revision 1.281
retrieving revision 1.282
diff -u -r1.281 -r1.282
--- builtin.c 28 Apr 2007 13:29:49 -0000 1.281
+++ builtin.c 1 May 2007 14:52:28 -0000 1.282
@@ -173,6 +173,7 @@
extern xsbBool db_build_prref(CTXTdecl), db_abolish0(CTXTdecl),
db_reclaim0(CTXTdecl), db_get_prref(CTXTdecl);
extern xsbBool dynamic_code_function(CTXTdecl);
+extern xsbBool table_inspection_function(CTXTdecl);
extern char *dirname_canonic(char *);
extern xsbBool almost_search_module(CTXTdeclc char *);
@@ -2505,7 +2506,6 @@
/* TLS: useful for power function -- see eval.P */
case XSB_POW: {
- Cell val = ptoc_tag(CTXTc 1);
if (isofloat(ptoc_tag(CTXTc 1))) {
if (isofloat(ptoc_tag(CTXTc 2)))
ctop_float(CTXTc 3,powf(ptoc_float(CTXTc 1),ptoc_float(CTXTc 2)));
@@ -2643,6 +2643,11 @@
break;
}
+ case TABLE_INSPECTION_FUNCTION: {
+ table_inspection_function(CTXT);
+ break;
+ }
+
case FINDALL_FREE:
findall_free(CTXTc ptoc_int(CTXTc 1));
return TRUE;
Index: builtin.h
===================================================================
RCS file: /cvsroot/xsb/XSB/emu/builtin.h,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -r1.76 -r1.77
--- builtin.h 5 Apr 2007 17:26:57 -0000 1.76
+++ builtin.h 1 May 2007 14:52:29 -0000 1.77
@@ -151,7 +151,6 @@
#define FILE_READ_CANONICAL 133
#define GEN_RETRACT_ALL 134
-
#define DB_GET_LAST_CLAUSE 135
#define DB_RETRACT0 136
#define DB_GET_CLAUSE 137
@@ -159,7 +158,6 @@
#define DB_ABOLISH0 139
#define DB_RECLAIM0 140
#define DB_GET_PRREF 141
-
#define FORMATTED_IO 142
#define TABLE_STATUS 143
#define GET_DELAY_LISTS 144
@@ -176,7 +174,6 @@
#define TRIE_RETRACT_SAFE 155
#define ABOLISH_MODULE_TABLES 156
#define TRIE_ASSERT_HDR_INFO 157
-
#define TRIMCORE 158
#define NEWTRIE 159
#define TRIE_INTERN 160
@@ -189,9 +186,7 @@
#define RECLAIM_UNINTERNED_NR 167
#define GLOBALVAR 168
#define CCALL_STORE_ERROR 169
-
#define SET_TABLED_EVAL 170
-
#define UNIFY_WITH_OCCURS_CHECK 171
#define PUT_ATTRIBUTES 172
#define GET_ATTRIBUTES 173
@@ -222,7 +217,6 @@
#define ARG 201
#define UNIV 202
#define IS_MOST_GENERAL_TERM 203
-
#define HiLog_ARG 204
#define HiLog_UNIV 205
@@ -239,7 +233,12 @@
#define KEYSORT 221
#define PARSORT 222
-#define DYNAMIC_CODE_FUNCTION 223
+/* This is the place to put new functions involving dynamic code
+ assertion and retraction -- e.g. gc */
+#define DYNAMIC_CODE_FUNCTION 223
+/* This is the place to put new functions that inspect tables, such as
+ answer completion */
+#define TABLE_INSPECTION_FUNCTION 224
#define FINDALL_FREE 229
@@ -250,7 +249,10 @@
#define UNWIND_STACK 233
#define CLEAN_UP_BLOCK 234
+/* This is the place to put new MT functions -- for thread_create,
+ user mutexes, message queues, etc. */
#define THREAD_REQUEST 235
+
#define MT_RANDOM_REQUEST 236
/* added by dsw to support profiling, and backtracing */
Index: slgdelay.c
===================================================================
RCS file: /cvsroot/xsb/XSB/emu/slgdelay.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- slgdelay.c 14 Dec 2006 19:38:07 -0000 1.55
+++ slgdelay.c 1 May 2007 14:52:29 -0000 1.56
@@ -175,6 +175,7 @@
asi_pdes(asi) = NULL; \
asi_subgoal(asi) = SUBG; \
asi_dl_list(asi) = NULL; \
+ asi_scratchpad(asi) = 0; \
}
/*
Index: slgdelay.h
===================================================================
RCS file: /cvsroot/xsb/XSB/emu/slgdelay.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- slgdelay.h 7 Dec 2006 00:26:45 -0000 1.27
+++ slgdelay.h 1 May 2007 14:52:29 -0000 1.28
@@ -93,24 +93,18 @@
PNDE pdes; /* pos DEs that refer to this answer substitution */
VariantSF subgoal; /* subgoal to which this answer substitution belongs */
DL dl_list; /* delay lists that this answer substitution has */
+ unsigned int scratchpad; /* to be used for answer completion and
+ other answer-oriented post-processing */
} *ASI;
typedef struct AS_info ASI_Node;
#define asi_pdes(X) (X) -> pdes
#define asi_subgoal(X) (X) -> subgoal
#define asi_dl_list(X) (X) -> dl_list
+#define asi_scratchpad(X) (X) -> scratchpad
#define ASIs_PER_BLOCK 256
-/*
-| #define create_as_info(ANS, SUBG) \
-| asi = (ASI) mem_alloc(sizeof(struct AS_info),TABLE_SPACE); \
-| Child(ANS) = (NODEptr) asi; \
-| asi_pdes(asi) = NULL; \
-| asi_subgoal(asi) = SUBG; \
-| asi_dl_list(asi) = NULL
-*/
-
/*--------------------------------------------------------------------*/
/* TLS: delay_elements may have some unnecessary information.
Index: tr_utils.c
===================================================================
RCS file: /cvsroot/xsb/XSB/emu/tr_utils.c,v
retrieving revision 1.140
retrieving revision 1.141
diff -u -r1.140 -r1.141
--- tr_utils.c 6 Apr 2007 11:41:48 -0000 1.140
+++ tr_utils.c 1 May 2007 14:52:29 -0000 1.141
@@ -66,6 +66,7 @@
#include "builtin.h"
#include "call_graph_xsb.h" /* incremental evaluation */
+#include "table_inspection_defs.h"
/*----------------------------------------------------------------------*/
@@ -2900,3 +2901,279 @@
* }
*/
+//----------------------------------------------------------------------
+// This code under development -- TLS
+
+#ifdef BITS64
+#define VISITED_MASK 0xf000000000000000
+#else
+#define VISITED_MASK 0xf0000000
+#endif
+
+#ifdef BITS64
+#define STACK_MASK 0xfffffffffffffff
+#else
+#define STACK_MASK 0xfffffff
+#endif
+
+#define VISITED(as_leaf) (asi_scratchpad((ASI) Child(as_leaf)) & VISITED_MASK)
+#define STACK_INDEX(as_leaf) (asi_scratchpad((ASI) Child(as_leaf)) & STACK_MASK)
+#define MARK_VISITED(as_leaf) {asi_scratchpad((ASI) Child(as_leaf)) = VISITED_MASK;}
+
+extern void print_subgoal(CTXTdeclc FILE *, VariantSF);
+
+static int dfn = 0;
+
+struct answer_dfn {
+ BTNptr answer;
+ int dfn;
+ int min_link;
+} ;
+typedef struct answer_dfn *answerDFN;
+
+#define component_stack_increment 1000
+
+int component_stack_top = 0;
+answerDFN component_stack = NULL;
+int component_stack_size = 0;
+
+#define push_comp_node(as_leaf,index) { \
+ if (component_stack_top >= component_stack_size) {\
+ unsigned long old_component_stack_size = component_stack_size; \
+ component_stack_size = component_stack_size + component_stack_increment;\
+ component_stack = (answerDFN)mem_realloc(component_stack, \
+ old_component_stack_size*sizeof(struct answer_dfn), \
+ component_stack_size*sizeof(struct answer_dfn), \
+ TABLE_SPACE); \
+ }\
+ component_stack[component_stack_top].dfn = dfn; \
+ component_stack[component_stack_top].min_link = dfn++; \
+ component_stack[component_stack_top].answer = as_leaf; \
+ index = component_stack_top; \
+ component_stack_top++;\
+ }
+
+/* for use when you don't need the index returned */
+#define push_comp_node_1(as_leaf) { \
+ int index; \
+ MARK_VISITED(as_leaf); \
+ push_comp_node(as_leaf,index); \
+ }
+
+#define pop_comp_node(node) { \
+ component_stack_top--; \
+ node = component_stack[component_stack_top]; \
+ }
+
+#define copy_pop_comp_node(node) { \
+ push_done_node((component_stack_top-1), \
+ (component_stack[component_stack_top-1].dfn)); \
+ component_stack_top--; \
+ node = component_stack[component_stack_top].answer; \
+ }
+
+void print_comp_stack(CTXTdecl) {
+ int frame = 0;
+ while (frame < component_stack_top) {
+ printf("comp_frame %d answer %p dfn %d min_link %d ",frame,component_stack[frame].answer,
+ component_stack[frame].dfn,component_stack[frame].min_link);
+ print_subgoal(CTXTc stddbg, asi_subgoal((ASI) Child(component_stack[frame].answer)));
+ printf("\n");
+ frame++;
+ }
+}
+
+//----------------------------------------------------------------------
+struct done_answer_dfn {
+ BTNptr answer;
+ int scc;
+} ;
+typedef struct done_answer_dfn *doneAnswerDFN;
+
+int done_stack_top = 0;
+doneAnswerDFN done_stack = NULL;
+int done_stack_size = 0;
+
+#define push_done_node(index,dfn_num) { \
+ if (done_stack_top >= done_stack_size) { \
+ unsigned long old_done_stack_size = done_stack_size; \
+ done_stack_size = done_stack_size + component_stack_increment; \
+ done_stack = (doneAnswerDFN) mem_realloc(done_stack, \
+ old_done_stack_size*sizeof(struct done_answer_dfn), \
+ done_stack_size*sizeof(struct done_answer_dfn), \
+ TABLE_SPACE); \
+ } \
+ done_stack[done_stack_top].scc = dfn_num; \
+ done_stack[done_stack_top].answer = component_stack[index].answer; \
+ done_stack_top++; \
+ }
+
+void print_done_stack(CTXTdecl) {
+ int frame = 0;
+ while (frame < done_stack_top) {
+ printf("done_frame %d answer %p scc %d ",frame,
+ done_stack[frame].answer,done_stack[frame].scc);
+ print_subgoal(CTXTc stddbg, asi_subgoal((ASI) Child(done_stack[frame].answer)));
+ printf("\n");
+ frame++;
+ }
+}
+
+// reset the scratchpad for each answer in done stack
+void reset_done_stack() {
+ int frame = 0;
+ while (frame < done_stack_top) {
+ asi_scratchpad((ASI) Child(done_stack[frame].answer)) = 0;
+ frame++;
+ }
+}
+
+//----------------------------------------------------------------------
+/* Returns -1 when no answer found (not 0, as 0 can be an index */
+int visited_answer(BTNptr as_leaf) {
+ int found = -1;
+ int cur_stack_frame = 0;
+
+ while (found < 0 && cur_stack_frame < done_stack_top) {
+ if (done_stack[cur_stack_frame].answer == as_leaf)
+ found = cur_stack_frame;
+ cur_stack_frame++;
+ }
+
+ cur_stack_frame = 0;
+ while (found < 0 && cur_stack_frame < component_stack_top) {
+ if (component_stack[cur_stack_frame].answer == as_leaf)
+ found = cur_stack_frame;
+ cur_stack_frame++;
+ }
+ return found;
+}
+
+BTNptr traverse_subgoal(VariantSF pSF) {
+ BTNptr cur_node = 0;
+
+ if ( subg_answers(pSF) == COND_ANSWERS && IsNonNULL(subg_ans_root_ptr(pSF))) {
+ cur_node = subg_ans_root_ptr(pSF);
+ while (!IsLeafNode(cur_node)) {
+ cur_node = BTN_Child(cur_node);
+ }
+ return cur_node;
+ }
+ return 0;
+}
+
+#define update_minlink_minlink(from_answer,to_answer) { \
+ if (component_stack[to_answer].min_link < component_stack[from_answer].min_link) \
+ component_stack[from_answer].min_link = component_stack[to_answer].min_link; \
+ } \
+
+#define update_minlink_dfn(from_answer,to_answer) { \
+ if (component_stack[to_answer].dfn < component_stack[from_answer].min_link) \
+ component_stack[from_answer].min_link = component_stack[to_answer].dfn; \
+ } \
+
+
+
+int table_component_check(CTXTdeclc NODEptr from_answer) {
+ DL delayList;
+ DE delayElement;
+ BTNptr to_answer;
+ int to_answer_idx, from_answer_idx, component_num;
+
+ // if (is_conditional_answer(from_answer)) {
+ push_comp_node(from_answer,from_answer_idx);
+ printf("starting: ");
+ print_subgoal(CTXTc stddbg, asi_subgoal((ASI) Child(from_answer)));printf("\n");
+ // print_comp_stack(CTXT);
+ delayList = asi_dl_list((ASI) Child(from_answer));
+ while (delayList) {
+ delayElement = dl_de_list(delayList);
+ while (delayElement) {
+ if (de_ans_subst(delayElement)) to_answer = de_ans_subst(delayElement);
+ else to_answer = traverse_subgoal(de_subgoal(delayElement));
+ if (0 > (to_answer_idx = visited_answer(to_answer))) {
+ to_answer_idx = table_component_check(CTXTc to_answer);
+ update_minlink_minlink(from_answer_idx,to_answer_idx);
+ } else update_minlink_dfn(from_answer_idx,to_answer_idx);
+ delayElement = de_next(delayElement);
+ }
+ delayList = de_next(delayList);
+ }
+ printf("checking: ");
+ print_subgoal(CTXTc stddbg, asi_subgoal((ASI) Child(from_answer)));printf("\n");
+
+ if (component_stack[from_answer_idx].dfn
+ == component_stack[from_answer_idx].min_link) {
+ component_num = component_stack[from_answer_idx].dfn;
+ while (from_answer_idx < component_stack_top) {
+ push_done_node(component_stack_top-1,component_num);
+ component_stack_top--;
+ }
+ }
+ print_comp_stack(CTXT); printf("\n");
+ return from_answer_idx;
+ // }
+}
+
+xsbBool table_inspection_function( CTXTdecl )
+{
+ switch (ptoc_int(CTXTc 1)) {
+
+ case FIND_COMPONENTS: {
+ table_component_check(CTXTc (NODEptr) ptoc_int(CTXTc 2));
+ print_done_stack(CTXT);
+ break;
+ }
+
+ case FIND_FORWARD_DEPENDENCIES: {
+ DL delayList;
+ DE delayElement;
+ BTNptr as_leaf, new_answer;
+ struct answer_dfn stack_node;
+
+ done_stack_top = 0; dfn = 0;
+ as_leaf = (NODEptr) ptoc_int(CTXTc 2);
+ if (is_conditional_answer(as_leaf)) {
+ push_comp_node_1(as_leaf);
+ while (component_stack_top != 0) {
+ // print_comp_stack(CTXT);
+ pop_comp_node(stack_node);
+ as_leaf = stack_node.answer;
+ push_done_node((component_stack_top),component_stack[component_stack_top].dfn);
+ // print_subgoal(CTXTc stddbg, asi_subgoal((ASI) Child(as_leaf)));printf("\n");
+ delayList = asi_dl_list((ASI) Child(as_leaf));
+ while (delayList) {
+ delayElement = dl_de_list(delayList);
+ while (delayElement) {
+ if (de_ans_subst(delayElement)) {
+ if (!VISITED(de_ans_subst(delayElement)))
+ push_comp_node_1(de_ans_subst(delayElement));
+ } else {
+ new_answer = traverse_subgoal(de_subgoal(delayElement));
+ if (!VISITED(new_answer))
+ push_comp_node_1(new_answer);
+ }
+ delayElement = de_next(delayElement);
+ }
+ delayList = de_next(delayList);
+ }
+ }
+ mem_dealloc(component_stack,component_stack_size*sizeof(struct answer_dfn),
+ TABLE_SPACE);
+ print_done_stack(CTXT);
+ // Don't deallocte done stack until done with its information.
+ reset_done_stack();
+ }
+ else printf("found unconditional answer %p\n",as_leaf);
+ break;
+ }
+
+ case FIND_BACKWARD_DEPENDENCIES: {
+ break;
+ }
+
+ }
+
+ return TRUE;
+ }
+
|