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
15 static char SccsId[] = "%W% %G%";
16 #endif /* SCCS */
17
18 /************************************************************
19
20 Unification Routines
21
22 *************************************************************/
23
24 static inline
bind_variable(Term t0,Term t1)25 Int 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
39 EXTERN inline
40 /*
41 Int unify(Term t0, Term t1)
42 */
unify(Term t0,Term t1)43 Int unify(Term t0, Term t1)
44 {
45 tr_fr_ptr TR0 = TR;
46 if (Yap_IUnify(t0,t1)) {
47 return(TRUE);
48 } else {
49 while(TR != TR0) {
50 CELL *p = (CELL *)TrailTerm(--TR);
51 RESET_VARIABLE(p);
52 }
53 return(FALSE);
54 }
55 }
56
unify_constant(register Term a,register Term cons)57 EXTERN inline Int unify_constant(register Term a, register Term cons)
58 {
59 CELL *pt;
60 deref_head(a,unify_cons_unk);
61 unify_cons_nonvar:
62 {
63 if (a == cons) return(TRUE);
64 else if (IsApplTerm(a) && IsExtensionFunctor(FunctorOfTerm(a))) {
65 Functor fun = FunctorOfTerm(a);
66 if (fun == FunctorDouble)
67 return(IsFloatTerm(cons) && FloatOfTerm(a) == FloatOfTerm(cons));
68 else if (fun == FunctorLongInt) {
69 return(IsLongIntTerm(cons) && LongIntOfTerm(a) == LongIntOfTerm(cons));
70 #ifdef TERM_EXTENSIONS
71 } else if (IsAttachFunc(fun)) {
72 return(attas[ExtFromFunctor(fun)].bind_op(SBIND,a,cons));
73 #endif /* TERM_EXTENSIONS */
74 } else
75 return(FALSE);
76 /* no other factors are accepted as arguments */
77 } else return(FALSE);
78 }
79
80
81 deref_body(a,pt,unify_cons_unk,unify_cons_nonvar);
82 Bind(pt,cons);
83 return(TRUE);
84 }
85
86
87