YAP 7.1.0
or.sba_unify.h
1/************************************************************************
2** **
3** The YapTab/YapOr/OPTYap systems **
4** **
5** YapTab extends the Yap Prolog engine to support sequential tabling **
6** YapOr extends the Yap Prolog engine to support or-parallelism **
7** OPTYap extends the Yap Prolog engine to support or-parallel tabling **
8** **
9** **
10** Yap Prolog was developed at University of Porto, Portugal **
11** **
12************************************************************************/
13
14#ifdef SCCS
15static char SccsId[] = "%W% %G%";
16#endif /* SCCS */
17
18/************************************************************
19
20Unification Routines
21
22*************************************************************/
23
24static inline
25Int bind_variable(Term t0, Term t1)
26{
27 tr_fr_ptr TR0 = TR;
28 if (Yap_IUnify(t0,t1)) {
29 return(TRUE);
30 } else {
31 while(TR != TR0) {
32 CELL *p = (CELL *)TrailTerm(--TR);
33 RESET_VARIABLE(p);
34 }
35 return(FALSE);
36 }
37}
38
39EXTERN inline
40Int unify(Term t0, Term t1)
41{
42 tr_fr_ptr TR0 = TR;
43 if (Yap_IUnify(t0,t1)) {
44 return(TRUE);
45 } else {
46 while(TR != TR0) {
47 CELL *p = (CELL *)TrailTerm(--TR);
48 RESET_VARIABLE(p);
49 }
50 return(FALSE);
51 }
52}
53
54EXTERN inline Int unify_constant(register Term a, register Term cons)
55{
56 CELL *pt;
57 CELL *pt0, *pt1;
58
59 deref_head(a,unify_cons_unk);
60 unify_cons_nonvar:
61 {
62 if (a == cons) return(TRUE);
63 else if (IsApplTerm(a) && IsExtensionFunctor(FunctorOfTerm(a))) {
64 Functor fun = FunctorOfTerm(a);
65 if (!IsApplTerm(cons) || FunctorOfTerm(cons) != fun)
66 return FALSE;
67 switch((CELL)fun) {
68 case (CELL)FunctorDBRef:
69 return(pt0 == pt1);
70 case (CELL)FunctorLongInt:
71 return(pt0[1] == pt1[1]);
72 case (CELL)FunctorString:
73 return(strcmp( (const char *)(pt0+2), (const char *)(pt1+2)) == 0);
74 case (CELL)FunctorDouble:
75 return(FloatOfTerm(AbsAppl(pt0)) == FloatOfTerm(AbsAppl(pt1)));
76#ifdef USE_GMP
77 case (CELL)FunctorBigInt:
78 return(Yap_gmp_tcmp_big_big(AbsAppl(pt0),AbsAppl(pt0)) == 0);
79#endif /* USE_GMP */
80 default:
81 return(FALSE);
82 }
83 }
84 /* no other factors are accepted as arguments */
85 return(FALSE);
86 }
87
88
89 deref_body(a,pt,unify_cons_unk,unify_cons_nonvar);
90 YapBind(pt,cons);
91 return(TRUE);
92}
93
94