unify_xsb.h

00001 /* File:      unify_xsb.h
00002 ** Author(s): Bart Demoen (maintained & checked by Kostis Sagonas)
00003 ** Contact:   xsb-contact@cs.sunysb.edu
00004 ** Note: This file is an adaptation of unify_xsb_i.h, made by Luis Castro, 
00005 ** in order to define the unification code as a C macro.
00006 ** 
00007 ** Copyright (C) K.U. Leuven 1999-2000
00008 ** Copyright (C) The Research Foundation of SUNY, 1986, 1993-1998
00009 ** Copyright (C) ECRC, Germany, 1990
00010 ** 
00011 ** XSB is free software; you can redistribute it and/or modify it under the
00012 ** terms of the GNU Library General Public License as published by the Free
00013 ** Software Foundation; either version 2 of the License, or (at your option)
00014 ** any later version.
00015 ** 
00016 ** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
00017 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00019 ** more details.
00020 ** 
00021 ** You should have received a copy of the GNU Library General Public License
00022 ** along with XSB; if not, write to the Free Software Foundation,
00023 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 **
00025 ** $Id: unify_xsb.h,v 1.7 2005/11/17 21:46:57 dwarren Exp $
00026 ** 
00027 */
00028 
00029 #define IFTHEN_SUCCEED  XSB_Next_Instr()
00030 #define IFTHEN_FAILED   Fail1 ; XSB_Next_Instr();
00031 
00032 
00033 #define COND1      (CPtr)(op1) < hreg ||  (CPtr)(op1) < hfreg 
00034 #define COND2      (CPtr)(op2) < hreg ||  (CPtr)(op2) < hfreg 
00035 
00036 #define attv_dbgmsg(String) xsb_dbgmsg((LOG_ATTV,String))
00037 
00038 #define unify_xsb(loc)                                       \
00039  loc##_tail_recursion:                                       \
00040   XSB_Deref2(op1, goto loc##_label_op1_free);                \
00041   XSB_Deref2(op2, goto loc##_label_op2_free);                \
00042                                                              \
00043   if (isattv(op1)) goto loc##_label_op1_attv;                \
00044   if (isattv(op2)) goto loc##_label_op2_attv;                \
00045                                                              \
00046   if (isfloat(op2) && isboxedfloat(op1) ) {                  \
00047     if ( float_val(op2) == (float)boxedfloat_val(op1))       \
00048       {IFTHEN_SUCCEED;}                                      \
00049     else                                                     \
00050       {IFTHEN_FAILED;}                                       \
00051   }                                                          \
00052   if (isfloat(op1) && isboxedfloat(op2) ) {                  \
00053     if ( float_val(op1) == (float)boxedfloat_val(op2))       \
00054       {IFTHEN_SUCCEED;}                                      \
00055     else                                                     \
00056       {IFTHEN_FAILED;}                                       \
00057   }                                                          \
00058                                                              \
00059   if (cell_tag(op1) != cell_tag(op2))                        \
00060     {IFTHEN_FAILED;}                                         \
00061                                                              \
00062   if (isconstr(op1)) goto loc##_label_both_struct;           \
00063   if (islist(op1)) goto loc##_label_both_list;               \
00064   /* now they are both atomic */                             \
00065   if (op1 == op2) {IFTHEN_SUCCEED;}                          \
00066   IFTHEN_FAILED;                                             \
00067                                                              \
00068  loc##_label_op1_free:                                       \
00069   XSB_Deref2(op2, goto loc##_label_both_free);               \
00070   bind_copy((CPtr)(op1), op2);                               \
00071   IFTHEN_SUCCEED;                                            \
00072                                                              \
00073  loc##_label_op2_free:                                       \
00074   bind_copy((CPtr)(op2), op1);                               \
00075   IFTHEN_SUCCEED;                                            \
00076                                                              \
00077  loc##_label_both_free:                                      \
00078   if ( (CPtr)(op1) == (CPtr)(op2) ) {IFTHEN_SUCCEED;}        \
00079   if ( (CPtr)(op1) < (CPtr)(op2) )                           \
00080     {                                                        \
00081       if (COND1)                                             \
00082         /* op1 not in local stack */                         \
00083         { bind_ref((CPtr)(op2), (CPtr)(op1)); }              \
00084       else  /* op1 points to op2 */                          \
00085         { bind_ref((CPtr)(op1), (CPtr)(op2)); }              \
00086       }                                                      \
00087   else                                                       \
00088     { /* op1 > op2 */                                        \
00089       if (COND2)                                             \
00090         { bind_ref((CPtr)(op1), (CPtr)(op2)); }              \
00091       else                                                   \
00092         { bind_ref((CPtr)(op2), (CPtr)(op1)); }              \
00093     }                                                        \
00094   IFTHEN_SUCCEED;                                            \
00095                                                              \
00096  loc##_label_both_list:                                      \
00097   if (op1 == op2) {IFTHEN_SUCCEED;}                          \
00098                                                              \
00099   op1 = (Cell)(clref_val(op1));                              \
00100   op2 = (Cell)(clref_val(op2));                              \
00101   if ( !unify(CTXTc cell((CPtr)op1), cell((CPtr)op2)))       \
00102     { IFTHEN_FAILED; }                                       \
00103   op1 = (Cell)((CPtr)op1+1);                                 \
00104   op2 = (Cell)((CPtr)op2+1);                                 \
00105   goto loc##_tail_recursion;                                 \
00106                                                              \
00107  loc##_label_both_struct:                                    \
00108   if (op1 == op2) {IFTHEN_SUCCEED;}                          \
00109                                                              \
00110   /* a != b */                                               \
00111   op1 = (Cell)(clref_val(op1));                              \
00112   op2 = (Cell)(clref_val(op2));                              \
00113   if (((Pair)(CPtr)op1)->psc_ptr!=((Pair)(CPtr)op2)->psc_ptr)\
00114     {                                                        \
00115       /* 0(a) != 0(b) */                                     \
00116       IFTHEN_FAILED;                                         \
00117     }                                                        \
00118   {                                                          \
00119     int arity = get_arity(((Pair)(CPtr)op1)->psc_ptr);       \
00120     while (--arity)                                          \
00121       {                                                      \
00122         op1 = (Cell)((CPtr)op1+1); op2 = (Cell)((CPtr)op2+1);\
00123         if (!unify(CTXTc cell((CPtr)op1), cell((CPtr)op2)))  \
00124           {                                                  \
00125             IFTHEN_FAILED;                                   \
00126           }                                                  \
00127       }                                                      \
00128     op1 = (Cell)((CPtr)op1+1); op2 = (Cell)((CPtr)op2+1);    \
00129     goto loc##_tail_recursion;                               \
00130   }                                                          \
00131                                                              \
00132   /* if the order of the arguments in add_interrupt */       \
00133   /* is not important, the following three can actually */   \
00134   /* be collapsed into one; loosing some meaningful */       \
00135   /* attv_dbgmsg - they have been lost partially */          \
00136   /* already */                                              \
00137                                                              \
00138  loc##_label_op1_attv:                                       \
00139   if (isattv(op2)) goto loc##_label_both_attv;               \
00140   attv_dbgmsg(">>>> ATTV = something, interrupt needed\n");  \
00141   add_interrupt(CTXTc cell(((CPtr)dec_addr(op1) + 1)),op2);  \
00142   bind_copy((CPtr)dec_addr(op1), op2);                       \
00143   IFTHEN_SUCCEED;                                            \
00144                                                              \
00145  loc##_label_op2_attv:                                       \
00146   attv_dbgmsg(">>>> something = ATTV, interrupt needed\n");  \
00147   add_interrupt(CTXTc cell(((CPtr)dec_addr(op2) + 1)),op1);  \
00148   bind_copy((CPtr)dec_addr(op2), op1);                       \
00149   IFTHEN_SUCCEED;                                            \
00150                                                              \
00151  loc##_label_both_attv:                                      \
00152   if (op1 != op2)                                            \
00153     {                                                        \
00154       attv_dbgmsg(">>>> ATTV = ???, interrupt needed\n");    \
00155       add_interrupt(CTXTc cell(((CPtr)dec_addr(op1) + 1)),op2);    \
00156       bind_copy((CPtr)dec_addr(op1), op2);                   \
00157     }                                                        \
00158   IFTHEN_SUCCEED
00159 
00160 
00161 

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