demand.h

00001 /* File:      demand.h
00002 ** Author(s): Luis Castro
00003 ** Contact:   xsb-contact@cs.sunysb.edu
00004 ** 
00005 ** Copyright (C) The Research Foundation of SUNY, 1986, 1993-1999
00006 ** Copyright (C) ECRC, Germany, 1990
00007 ** 
00008 ** XSB is free software; you can redistribute it and/or modify it under the
00009 ** terms of the GNU Library General Public License as published by the Free
00010 ** Software Foundation; either version 2 of the License, or (at your option)
00011 ** any later version.
00012 ** 
00013 ** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
00014 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00015 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00016 ** more details.
00017 ** 
00018 ** You should have received a copy of the GNU Library General Public License
00019 ** along with XSB; if not, write to the Free Software Foundation,
00020 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00021 **
00022 ** $Id: demand.h,v 1.3 2005/01/14 18:30:55 ruim Exp $
00023 ** 
00024 */
00025 
00026 #include "ptoc_tag_xsb_i.h"
00027 #include "celltags_xsb.h"
00028 #include "cut_xsb.h"
00029 
00030 /* debug-related macros */
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 /* CP_DEBUG */
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 /*CP_DEBUG */
00043 #else /* DEBUG */
00044 #define INSPECT_CP(Type,CP)
00045 #endif /* DEBUG */
00046             
00047 
00048 /* static code to be inlined */
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   /* extracting and validating argument */
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   /* traversing and analysing stack section */
00065   b = (Choice) breg;
00066   has_generator=0;
00067   while (b < cutpoint) {
00068     if (is_generator_choicepoint(b)) {
00069       INSPECT_CP("generator",b);
00070 /*       has_generator=1; */
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     /* invert chain */
00080     b = b->prev_top;
00081   }
00082   /* if there are only prolog & consumer CP's, we can throw them away */
00083   if (!has_generator) {
00084     /* perform cut */
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 }

Generated on Wed Jul 26 13:30:40 2006 for XSB by  doxygen 1.4.5