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 #include "ptoc_tag_xsb_i.h"
00027 #include "celltags_xsb.h"
00028 #include "cut_xsb.h"
00029
00030
00031 #ifdef DEBUG_VERBOSE
00032 #ifdef CP_DEBUG
00033 #define INSPECT_CP(Type,CP) \
00034 fprintf(stddbg,\
00035 "choicepoint(type(%s),address(%p),pred(%s/%d),ptcp(%p)).\n", \
00036 Type, CP, ((Choice)CP)->psc->nameptr, ((Choice)CP)->psc->arity,\
00037 ((Choice)CP)->ptcp)
00038 #else
00039 #define INSPECT_CP(Type,CP) \
00040 fprintf(stddbg,"choicepoint(type(%s),address(%p),ptcp(%p)).\n",\
00041 Type,CP,((Choice)CP)->ptcp)
00042 #endif
00043 #else
00044 #define INSPECT_CP(Type,CP)
00045 #endif
00046
00047
00048
00049
00050 static inline void perform_once(void)
00051 {
00052 unsigned int arg1;
00053 int has_generator;
00054 CPtr cutpoint,cutto;
00055 Choice b;
00056
00057
00058 arg1 = ptoc_int(1);
00059 cutpoint = (CPtr) ((unsigned long) tcpstack.high - arg1);
00060 if (cutpoint < breg) {
00061 xsb_abort("demand_once/1 called with Breg greater than current.");
00062 }
00063
00064
00065 b = (Choice) breg;
00066 has_generator=0;
00067 while (b < cutpoint) {
00068 if (is_generator_choicepoint(b)) {
00069 INSPECT_CP("generator",b);
00070
00071 delete_table(b);
00072 } else if (is_consumer_choicepoint(b)) {
00073 INSPECT_CP("consumer",b);
00074 } else if (is_compl_susp_frame(b)) {
00075 INSPECT_CP("compl_susp_frame",b);
00076 } else {
00077 INSPECT_CP("prolog",b);
00078 }
00079
00080 b = b->prev_top;
00081 }
00082
00083 if (!has_generator) {
00084
00085 ebreg = cp_ebreg(cutpoint);
00086 hbreg = cp_hreg(cutpoint);
00087 if (breg != cutpoint) {
00088 CPtr xtemp1, xtemp2;
00089 unwind_trail(breg,xtemp1,xtemp2);
00090 breg = cutpoint;
00091 }
00092 }
00093 }
00094
00095 static inline void delete_table(TChoice choicepoint)
00096 {
00097 VariantSF subgoal;
00098 struct completion_stack_frame *csf;
00099 TIFptr tif;
00100
00101 subgoal = (VariantSF) choicepoint->subgoal_ptr;
00102 csf = subgoal->compl_stack_ptr;
00103 tif = subgoal->tif_ptr;
00104
00105 reclaim_incomplete_table_structs(subgoal);
00106 delete_predicate_table(tif);
00107
00108 }