00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __SLGDELAY_H__
00027 #define __SLGDELAY_H__
00028
00029
00030 #include "debugs/debug_delay.h"
00031
00032 #define NEG_DELAY 0
00033
00034
00035
00036
00037
00038
00039 #define delay_negatively(SUBGOAL) { \
00040 Cell new_delay_cons_cell; \
00041 \
00042 new_delay_cons_cell = makelist(hreg); \
00043 sreg = hreg+2; \
00044 follow(hreg++) = makecs(sreg); \
00045 follow(hreg++) = (delayreg == NULL) ? makenil : (Cell) delayreg; \
00046 new_heap_functor(sreg, delay_psc); \
00047 cell(sreg) = makeaddr(SUBGOAL); sreg++; \
00048 cell(sreg) = makeaddr(NEG_DELAY); sreg++; \
00049 cell(sreg) = makeaddr(NEG_DELAY); sreg++; \
00050 hreg = sreg; \
00051 delayreg = (CPtr) new_delay_cons_cell; \
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 #define delay_positively(SUBGOAL, ANSWER, MAKE_SUBSF) { \
00067 Cell new_delay_cons_cell; \
00068 \
00069 new_delay_cons_cell = makelist(hreg); \
00070 sreg = hreg + 2; \
00071 follow(hreg++) = makecs(sreg); \
00072 follow(hreg++) = (delayreg == NULL) ? makenil : (Cell) delayreg; \
00073 new_heap_functor(sreg, delay_psc); \
00074 cell(sreg++) = makeaddr(SUBGOAL); \
00075 cell(sreg++) = makeaddr(ANSWER); \
00076 follow(sreg++) = MAKE_SUBSF; \
00077 hreg = sreg; \
00078 delayreg = (CPtr) new_delay_cons_cell; \
00079 }
00080
00081
00082
00083 typedef struct delay_element *DE;
00084 typedef struct delay_list *DL;
00085 typedef struct pos_neg_de_list *PNDE;
00086
00087
00088
00089
00090
00091
00092 typedef struct AS_info {
00093 PNDE pdes;
00094 VariantSF subgoal;
00095 DL dl_list;
00096 } *ASI;
00097
00098 #define asi_pdes(X) (X) -> pdes
00099 #define asi_subgoal(X) (X) -> subgoal
00100 #define asi_dl_list(X) (X) -> dl_list
00101
00102 #define create_as_info(ANS, SUBG) \
00103 asi = (ASI) mem_alloc(sizeof(struct AS_info),TABLE_SPACE); \
00104 Child(ANS) = (NODEptr) asi; \
00105 asi_pdes(asi) = NULL; \
00106 asi_subgoal(asi) = SUBG; \
00107 asi_dl_list(asi) = NULL
00108
00109
00110
00111 struct delay_element {
00112 VariantSF subgoal;
00113 NODEptr ans_subst;
00114 DE next;
00115 PNDE pnde;
00116
00117
00118
00119 #ifdef DEBUG_DELAYVAR
00120 NODEptr subs_fact;
00121 #endif
00122 NODEptr subs_fact_leaf;
00123 } ;
00124
00125 #define de_subgoal(X) (X) -> subgoal
00126 #define de_ans_subst(X) (X) -> ans_subst
00127 #define de_next(X) (X) -> next
00128 #define de_pnde(X) (X) -> pnde
00129 #ifdef DEBUG_DELAYVAR
00130 #define de_subs_fact(X) (X) -> subs_fact
00131 #endif
00132 #define de_subs_fact_leaf(X) (X) -> subs_fact_leaf
00133
00134
00135
00136 struct delay_list {
00137 DE de_list;
00138 NODEptr asl;
00139 DL next;
00140 } ;
00141
00142 #define dl_de_list(X) (X) -> de_list
00143 #define dl_next(X) (X) -> next
00144 #define dl_asl(X) (X) -> asl
00145
00146
00147
00148 struct pos_neg_de_list {
00149 DL dl;
00150 DE de;
00151 PNDE prev, next;
00152 } ;
00153
00154 #define pnde_dl(X) (X) -> dl
00155 #define pnde_de(X) (X) -> de
00156 #define pnde_prev(X) (X) -> prev
00157 #define pnde_next(X) (X) -> next
00158
00159
00160
00161
00162
00163
00164 #define UNCONDITIONAL_MARK 0x3
00165
00166 #define Delay(X) (ASI) ((word) (TN_Child(X)) & ~UNCONDITIONAL_MARK)
00167
00168 #define is_conditional_answer(ANS) \
00169 (Child(ANS) && !((word) (Child(ANS)) & UNCONDITIONAL_MARK))
00170
00171 #define is_unconditional_answer(ANS) \
00172 (!Child(ANS) || ((word) (Child(ANS)) & UNCONDITIONAL_MARK))
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 #define was_simplifiable(SUBG, ANS) \
00184 ((ANS == NULL) ? (is_completed(SUBG) && subgoal_fails(SUBG)) \
00185 : (is_unconditional_answer(ANS)))
00186
00187 #define is_failing_delay_element(SUBG, ANS) \
00188 ((ANS == NULL) ? (is_completed(SUBG) && has_answer_code(SUBG) && \
00189 subgoal_unconditionally_succeeds(SUBG)) \
00190 : (IsDeletedNode(ANS)))
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 #define mark_conditional_answer(ANS, SUBG, NEW_DL) \
00202 if (Child(ANS) == NULL) { \
00203 create_as_info(ANS, SUBG); \
00204 } \
00205 else { \
00206 asi = Delay(ANS); \
00207 } \
00208 dl_next(NEW_DL) = asi_dl_list(asi); \
00209 asi_dl_list(asi) = NEW_DL; \
00210 dl_asl(NEW_DL) = ANS
00211
00212 #define unmark_conditional_answer(ANS) \
00213 Child(ANS) = (NODEptr) ((word) (Child(ANS)) | UNCONDITIONAL_MARK)
00214
00215 #define most_general_answer(ANS) IsEscapeNode(ANS)
00216
00217
00218
00219
00220
00221 extern xsbBool neg_delay;
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 extern xsbBool answer_is_junk(CPtr);
00234 #ifndef MULTI_THREAD
00235 extern void abolish_wfs_space(void);
00236 extern void simplify_neg_fails(VariantSF);
00237 extern void do_delay_stuff(NODEptr, VariantSF, xsbBool);
00238 #else
00239 struct th_context;
00240 extern void abolish_wfs_space(struct th_context *);
00241 extern void simplify_neg_fails(struct th_context *, VariantSF);
00242 extern void do_delay_stuff(struct th_context *, NODEptr, VariantSF, xsbBool);
00243 #endif
00244 extern unsigned long allocated_de_space(int * num_blocks);
00245 extern unsigned long unused_de_space(void);
00246 extern unsigned long allocated_dl_space(int * num_blocks);
00247 extern unsigned long unused_dl_space(void);
00248 #ifndef MULTI_THREAD
00249 extern void simplify_pos_unsupported(NODEptr);
00250 #else
00251 extern void simplify_pos_unsupported(struct th_context *, NODEptr);
00252 #endif
00253 extern void release_all_dls(ASI);
00254
00255
00256
00257
00258 #endif