2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
2017-08-21 12:29:58 +01:00
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: amiops.h *
|
|
|
|
* Last rev: *
|
|
|
|
* mods: *
|
|
|
|
* comments: Basic abstract machine operations, such as *
|
|
|
|
* dereferencing, binding, trailing, and unification. *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
2011-05-23 16:19:47 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef SCCS
|
2017-08-21 12:29:58 +01:00
|
|
|
static char SccsId[] = "%W% %G%";
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* SCCS */
|
|
|
|
|
2012-06-29 22:44:08 +01:00
|
|
|
#include "inline-only.h"
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define IsArrayReference(a) ((a)->array_access_func == FunctorArrayAccess)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
/* dereferencing macros */
|
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
|
|
|
|
Dereferencing macros
|
|
|
|
|
|
|
|
*************************************************************/
|
|
|
|
|
|
|
|
/* For DEREFD, D has both the input and the exit argument */
|
|
|
|
/* A is only used locally */
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define profiled_deref_head_TEST(D, Label) \
|
|
|
|
if (IsVarTerm(D)) { \
|
|
|
|
if (!strcmp(#D, "d0")) { \
|
|
|
|
EMIT_CONDITIONAL_SUCCESS("IsVarTerm(d0)"); \
|
|
|
|
} else if (!strcmp(#D, "d1")) { \
|
|
|
|
EMIT_CONDITIONAL_SUCCESS("IsVarTerm(d1)"); \
|
|
|
|
} \
|
|
|
|
goto Label; \
|
|
|
|
} \
|
|
|
|
if (!strcmp(#D, "d0")) { \
|
|
|
|
EMIT_CONDITIONAL_FAIL("IsVarTerm(d0)"); \
|
|
|
|
} else if (!strcmp(#D, "d1")) { \
|
|
|
|
EMIT_CONDITIONAL_FAIL("IsVarTerm(d1)"); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define deref_head(D, Label) \
|
|
|
|
if (IsVarTerm(D)) \
|
|
|
|
goto Label
|
|
|
|
|
|
|
|
#define profiled_deref_body(D, A, LabelUnk, LabelNonVar) \
|
|
|
|
do { \
|
|
|
|
if (!IsVarTerm(D)) \
|
|
|
|
goto LabelNonVar; \
|
|
|
|
LabelUnk: \
|
|
|
|
(A) = (CELL *)(D); \
|
|
|
|
(D) = *(CELL *)(D); \
|
|
|
|
if (!strcmp(#D, "d0") && !strcmp(#A, "pt0")) { \
|
|
|
|
EMIT_SIMPLE_BLOCK_TEST(YAAM_DEREF_BODY_D0PT0); \
|
|
|
|
} else if (!strcmp(#D, "d0") && !strcmp(#A, "pt1")) { \
|
|
|
|
EMIT_SIMPLE_BLOCK_TEST(YAAM_DEREF_BODY_D0PT1); \
|
|
|
|
} else if (!strcmp(#D, "d0") && !strcmp(#A, "S_SREG")) { \
|
|
|
|
EMIT_SIMPLE_BLOCK_TEST(YAAM_DEREF_BODY_D0S_SREG); \
|
|
|
|
} else if (!strcmp(#D, "d1") && !strcmp(#A, "pt0")) { \
|
|
|
|
EMIT_SIMPLE_BLOCK_TEST(YAAM_DEREF_BODY_D1PT0); \
|
|
|
|
} else if (!strcmp(#D, "d1") && !strcmp(#A, "pt1")) { \
|
|
|
|
EMIT_SIMPLE_BLOCK_TEST(YAAM_DEREF_BODY_D1PT1); \
|
|
|
|
} \
|
2015-01-20 03:00:42 +00:00
|
|
|
} while (Unsigned(A) != (D));
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define deref_body(D, A, LabelUnk, LabelNonVar) \
|
|
|
|
do { \
|
|
|
|
if (!IsVarTerm(D)) \
|
|
|
|
goto LabelNonVar; \
|
|
|
|
LabelUnk: \
|
|
|
|
(A) = (CELL *)(D); \
|
|
|
|
(D) = *(CELL *)(D); \
|
|
|
|
} while (Unsigned(A) != (D))
|
|
|
|
|
|
|
|
#define deref_body(D, A, LabelUnk, LabelNonVar) \
|
|
|
|
do { \
|
|
|
|
if (!IsVarTerm(D)) \
|
|
|
|
goto LabelNonVar; \
|
|
|
|
LabelUnk: \
|
|
|
|
(A) = (CELL *)(D); \
|
|
|
|
(D) = *(CELL *)(D); \
|
|
|
|
} while (Unsigned(A) != (D))
|
|
|
|
|
|
|
|
#define do_derefa(D, A, LabelUnk, LabelDone) \
|
|
|
|
(D) = *(CELL *)(A); \
|
|
|
|
if (IsNonVarTerm(D)) \
|
|
|
|
goto LabelDone; \
|
|
|
|
goto LabelUnk; \
|
|
|
|
do { \
|
|
|
|
(A) = (CELL *)(D); \
|
|
|
|
(D) = *(CELL *)(D); \
|
|
|
|
if (!IsVarTerm(D)) \
|
|
|
|
goto LabelDone; \
|
|
|
|
LabelUnk:; \
|
|
|
|
} while (Unsigned(A) != (D)); \
|
|
|
|
LabelDone:
|
|
|
|
|
|
|
|
#define profiled_derefa_body(D, A, LabelUnk, LabelNonVar) \
|
|
|
|
do { \
|
|
|
|
(A) = (CELL *)(D); \
|
|
|
|
(D) = *(CELL *)(D); \
|
|
|
|
if (!strcmp(#D, "d0") && !strcmp(#A, "pt0")) { \
|
|
|
|
EMIT_SIMPLE_BLOCK_TEST(YAAM_DEREF_BODY_D0PT0); \
|
|
|
|
} else if (!strcmp(#D, "d0") && !strcmp(#A, "pt1")) { \
|
|
|
|
EMIT_SIMPLE_BLOCK_TEST(YAAM_DEREF_BODY_D0PT1); \
|
|
|
|
} else if (!strcmp(#D, "d0") && !strcmp(#A, "S_SREG")) { \
|
|
|
|
EMIT_SIMPLE_BLOCK_TEST(YAAM_DEREF_BODY_D0S_SREG); \
|
|
|
|
} else if (!strcmp(#D, "d1") && !strcmp(#A, "pt0")) { \
|
|
|
|
EMIT_SIMPLE_BLOCK_TEST(YAAM_DEREF_BODY_D1PT0); \
|
|
|
|
} else if (!strcmp(#D, "d1") && !strcmp(#A, "pt1")) { \
|
|
|
|
EMIT_SIMPLE_BLOCK_TEST(YAAM_DEREF_BODY_D1PT1); \
|
|
|
|
} \
|
|
|
|
if (!IsVarTerm(D)) \
|
|
|
|
goto LabelNonVar; \
|
|
|
|
LabelUnk:; \
|
|
|
|
} while (Unsigned(A) != (D));
|
2015-01-20 03:00:42 +00:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define derefa_body(D, A, LabelUnk, LabelNonVar) \
|
|
|
|
do { \
|
|
|
|
(A) = (CELL *)(D); \
|
|
|
|
(D) = *(CELL *)(D); \
|
|
|
|
if (!IsVarTerm(D)) \
|
|
|
|
goto LabelNonVar; \
|
|
|
|
LabelUnk:; \
|
|
|
|
} while (Unsigned(A) != (D))
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#if UNIQUE_TAG_FOR_PAIRS
|
|
|
|
|
|
|
|
/* If you have an unique tag for pairs you can use these macros which will
|
|
|
|
speed up detection of dereferenced pairs, but will be slow
|
|
|
|
for the other cases.
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
The only instruction where this seems useful is
|
2001-04-09 20:54:03 +01:00
|
|
|
switch_list_nl
|
|
|
|
*/
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define deref_list_head(D, Label) \
|
|
|
|
if (!IsPairTerm(D)) \
|
|
|
|
goto Label
|
|
|
|
|
|
|
|
#define deref_list_body(D, A, LabelList, LabelNonVar) \
|
|
|
|
do { \
|
|
|
|
if (!IsVarTerm(D)) \
|
|
|
|
goto LabelNonVar; \
|
|
|
|
(A) = (CELL *)(D); \
|
|
|
|
(D) = *(A); \
|
|
|
|
if (Unsigned(A) == (D)) \
|
|
|
|
break; \
|
|
|
|
if (IsPairTerm(D)) \
|
|
|
|
goto LabelList; \
|
|
|
|
} while (TRUE);
|
|
|
|
|
|
|
|
INLINE_ONLY inline EXTERN CELL *deref_ptr(CELL *A);
|
|
|
|
|
|
|
|
INLINE_ONLY inline EXTERN CELL *deref_ptr(CELL *A) {
|
|
|
|
Term D = *A;
|
|
|
|
do {
|
|
|
|
if (!IsVarTerm(D))
|
|
|
|
return A;
|
|
|
|
(A) = (CELL *)(D);
|
|
|
|
(D) = *(A);
|
|
|
|
if (Unsigned(A) == (D))
|
|
|
|
return A;
|
|
|
|
} while (TRUE);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* UNIQUE_TAG_FOR_PAIRS */
|
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
|
|
|
|
TRAIL VARIABLE
|
|
|
|
|
|
|
|
A contains the address of the variable that is to be trailed
|
|
|
|
|
|
|
|
*************************************************************/
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define RESET_VARIABLE(V) (*(CELL *)(V) = Unsigned(V))
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#ifdef TABLING
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define DO_TRAIL(TERM, VAL) \
|
|
|
|
{ \
|
|
|
|
tr_fr_ptr r; \
|
|
|
|
r = TR; \
|
|
|
|
TR = r + 1; \
|
|
|
|
TrailTerm(r) = (Term)(TERM); \
|
|
|
|
TrailVal(r) = (CELL)(VAL); \
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#ifdef BFZ_TRAIL_SCHEME
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL(TERM, VAL) \
|
|
|
|
if (OUTSIDE(HBREG, TERM, B) || ((TERM) > (CELL *)B_FZ)) \
|
|
|
|
DO_TRAIL(TERM, VAL)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL_LOCAL(TERM, VAL) \
|
|
|
|
if ((TERM) > (CELL *)B || (TERM) > (CELL *)B_FZ) \
|
|
|
|
DO_TRAIL(TERM, VAL)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#else /* BBREG_TRAIL_SCHEME */
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL(TERM, VAL) \
|
|
|
|
if (OUTSIDE(HBREG, TERM, BBREG)) \
|
|
|
|
DO_TRAIL(TERM, VAL)
|
|
|
|
|
|
|
|
#define TRAIL_LOCAL(TERM, VAL) \
|
|
|
|
if ((TERM) > (CELL *)BBREG) \
|
|
|
|
DO_TRAIL(TERM, VAL)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#endif /* TRAIL_SCHEME */
|
|
|
|
|
|
|
|
/* ------------------------------------------------------ */
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL_GLOBAL(TERM, VAL) \
|
|
|
|
if ((TERM) < HBREG) \
|
|
|
|
DO_TRAIL(TERM, VAL)
|
|
|
|
|
|
|
|
#define DO_MATRAIL(TERM, OLDVAL, NEWVAL) \
|
|
|
|
{ \
|
|
|
|
register tr_fr_ptr r = TR; \
|
|
|
|
TR = r + 2; \
|
|
|
|
TrailVal(r) = (OLDVAL); \
|
|
|
|
TrailTerm(r) = TrailTerm(r + 1) = AbsAppl((CELL *)(TERM)); \
|
|
|
|
TrailVal(r + 1) = (NEWVAL); \
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define MATRAIL(TERM, OVAL, VAL) \
|
|
|
|
if (OUTSIDE(HBREG, TERM, B)) \
|
|
|
|
DO_MATRAIL(TERM, OVAL, VAL)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#else /* TABLING */
|
|
|
|
|
|
|
|
#if defined(i386) && !defined(TERM_EXTENSIONS)
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define DO_TRAIL(A, D) \
|
|
|
|
{ \
|
|
|
|
tr_fr_ptr r; \
|
|
|
|
r = TR; \
|
|
|
|
TR = r + 1; \
|
|
|
|
TrailTerm(r) = (CELL)(A); \
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL(A, D) \
|
|
|
|
if (OUTSIDE(HBREG, A, B)) \
|
|
|
|
DO_TRAIL(A, D);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL_GLOBAL(A, D) \
|
|
|
|
if ((A) < HBREG) \
|
|
|
|
DO_TRAIL(A, D);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL_LOCAL(A, D) \
|
|
|
|
if ((A) > (CELL *)B) \
|
|
|
|
DO_TRAIL(A, D);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2008-03-25 22:03:14 +00:00
|
|
|
#elif defined(__alpha) && !defined(TERM_EXTENSIONS)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
/* alpha machines have a move conditional instruction, which avoids a
|
|
|
|
branch when jumping */
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL(A, D) \
|
|
|
|
TrailTerm(TR) = (CELL)(A); \
|
|
|
|
if (OUTSIDE(HBREG, A, B)) \
|
|
|
|
TR++
|
|
|
|
|
|
|
|
#define TRAIL(A, D) \
|
|
|
|
TrailTerm(TR) = (CELL)(A); \
|
|
|
|
if (!OUTSIDE(HBREG, A, B)) \
|
|
|
|
GONext();
|
2009-03-03 10:04:13 +00:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL_GLOBAL(A, D) \
|
|
|
|
TR[0] = (CELL)(A); \
|
|
|
|
if ((A) < HBREG) \
|
|
|
|
TR++
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL_LOCAL(A, D) \
|
|
|
|
TR[0] = (CELL)(A); \
|
|
|
|
if ((A) > ((CELL *)(B))) \
|
|
|
|
TR++
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#elif !defined(TERM_EXTENSIONS)
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define DO_TRAIL(A, D) TrailTerm(TR++) = (CELL)(A)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL(A, D) \
|
|
|
|
if (OUTSIDE(HBREG, A, B)) \
|
|
|
|
DO_TRAIL(A, D)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL_AND_JUMP(A, D) \
|
|
|
|
if (IN_BETWEEN(HBREG, A, B)) \
|
|
|
|
GONext(); \
|
|
|
|
DO_TRAIL(A, D)
|
2009-03-03 10:04:13 +00:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL_GLOBAL(A, D) \
|
|
|
|
if ((A) < HBREG) \
|
|
|
|
DO_TRAIL(A, D)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL_LOCAL(A, D) \
|
|
|
|
if ((A) > ((CELL *)B)) \
|
|
|
|
DO_TRAIL(A, D)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define DO_TRAIL(A, D) TrailTerm(TR++) = (CELL)(A)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL(A, D) \
|
|
|
|
if (OUTSIDE(HBREG, A, B)) \
|
|
|
|
DO_TRAIL(A, D)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TrailAndJump(A, D) \
|
|
|
|
if (IN_BETWEEN(HBREG, A, B)) \
|
2009-03-03 10:04:13 +00:00
|
|
|
GONext();
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL_GLOBAL(A, D) \
|
|
|
|
if ((A) < HBREG) \
|
|
|
|
DO_TRAIL(A, D)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL_LOCAL(A, D) \
|
|
|
|
if ((A) > ((CELL *)B)) \
|
|
|
|
DO_TRAIL(A, D)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
|
|
|
|
Binding Macros for Multiple Assignment Variables.
|
|
|
|
|
|
|
|
************************************************************/
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define DO_MATRAIL(VP, OLDV, D) \
|
|
|
|
{ \
|
|
|
|
TrailTerm(TR + 1) = OLDV; \
|
|
|
|
TrailTerm(TR) = TrailTerm(TR + 2) = AbsAppl(VP); \
|
|
|
|
TR += 3; \
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define MATRAIL(VP, OLDV, D) \
|
|
|
|
if (OUTSIDE(HBREG, VP, B)) \
|
|
|
|
DO_MATRAIL(VP, OLDV, D)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#endif /* TABLING */
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define REF_TO_TRENTRY(REF) AbsPair(((CELL *)&((REF)->Flags)))
|
|
|
|
#define CLREF_TO_TRENTRY(REF) AbsPair(((CELL *)&((REF)->ClFlags)))
|
2001-06-08 15:52:54 +01:00
|
|
|
|
2011-04-14 18:51:11 +01:00
|
|
|
#if FROZEN_STACKS
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL_REF(REF) \
|
|
|
|
RESET_VARIABLE(&TrailVal(TR)), TrailTerm(TR++) = REF_TO_TRENTRY(REF)
|
|
|
|
#define TRAIL_CLREF(REF) \
|
|
|
|
RESET_VARIABLE(&TrailVal(TR)), TrailTerm(TR++) = CLREF_TO_TRENTRY(REF)
|
|
|
|
#define TRAIL_LINK(REF) \
|
|
|
|
RESET_VARIABLE(&TrailVal(TR)), TrailTerm(TR++) = AbsPair((CELL *)(REF))
|
2011-04-14 18:51:11 +01:00
|
|
|
#else
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL_REF(REF) TrailTerm(TR++) = REF_TO_TRENTRY(REF)
|
|
|
|
#define TRAIL_CLREF(REF) TrailTerm(TR++) = CLREF_TO_TRENTRY(REF)
|
|
|
|
#define TRAIL_LINK(REF) TrailTerm(TR++) = AbsPair((CELL *)(REF))
|
2011-04-14 18:51:11 +01:00
|
|
|
#endif
|
2017-08-21 12:29:58 +01:00
|
|
|
#define TRAIL_FRAME(FR) DO_TRAIL(AbsPair((CELL *)(LOCAL_TrailBase)), FR)
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
extern void Yap_WakeUp(CELL *v);
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define Bind_Local(A, D) \
|
|
|
|
{ \
|
|
|
|
TRAIL_LOCAL(A, D); \
|
|
|
|
*(A) = (D); \
|
|
|
|
}
|
|
|
|
#define Bind_Global(A, D) \
|
|
|
|
{ \
|
|
|
|
*(A) = (D); \
|
|
|
|
if (__builtin_expect(GlobalIsAttVar(A), 0)) \
|
|
|
|
Yap_WakeUp(A); \
|
|
|
|
else \
|
|
|
|
TRAIL_GLOBAL(A, D); \
|
|
|
|
}
|
|
|
|
#define YapBind(A, D) \
|
|
|
|
{ \
|
|
|
|
*(A) = (D); \
|
|
|
|
if (A < HR) { \
|
|
|
|
if (__builtin_expect(GlobalIsAttVar(A), 0)) \
|
|
|
|
Yap_WakeUp(A); \
|
|
|
|
else \
|
|
|
|
TRAIL_GLOBAL(A, D); \
|
|
|
|
} else { \
|
|
|
|
TRAIL_LOCAL(A, D); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define Bind_NonAtt(A, D) \
|
|
|
|
{ \
|
|
|
|
*(A) = (D); \
|
|
|
|
TRAIL(A, D); \
|
|
|
|
}
|
|
|
|
#define Bind_Global_NonAtt(A, D) \
|
|
|
|
{ \
|
|
|
|
*(A) = (D); \
|
|
|
|
TRAIL_GLOBAL(A, D); \
|
|
|
|
}
|
|
|
|
#define Bind_and_Trail(A, D) \
|
|
|
|
{ \
|
|
|
|
*(A) = (D); \
|
|
|
|
DO_TRAIL(A, D); \
|
|
|
|
}
|
2016-04-10 14:21:17 +01:00
|
|
|
// #define Bind(A,D) YapBind(A,D) conflicts with Windows headers
|
2004-03-19 11:35:42 +00:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
#define MaBind(VP, D) \
|
|
|
|
{ \
|
|
|
|
MATRAIL((VP), *(VP), (D)); \
|
|
|
|
*(VP) = (D); \
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
|
|
|
|
Unification Routines
|
|
|
|
|
|
|
|
*************************************************************/
|
|
|
|
|
2013-04-25 23:15:04 +01:00
|
|
|
INLINE_ONLY inline EXTERN void reset_trail(tr_fr_ptr TR0);
|
2004-10-28 21:12:23 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
INLINE_ONLY inline EXTERN void reset_trail(tr_fr_ptr TR0) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2017-08-21 12:29:58 +01:00
|
|
|
while (TR != TR0) {
|
2004-09-07 21:20:12 +01:00
|
|
|
CELL d1;
|
|
|
|
--TR;
|
|
|
|
d1 = TrailTerm(TR);
|
2002-05-21 05:18:15 +01:00
|
|
|
#ifdef MULTI_ASSIGNMENT_VARIABLES
|
2004-09-07 21:20:12 +01:00
|
|
|
if (IsVarTerm(d1)) {
|
2002-05-21 05:18:15 +01:00
|
|
|
#endif
|
2004-09-07 21:20:12 +01:00
|
|
|
CELL *pt = (CELL *)d1;
|
|
|
|
RESET_VARIABLE(pt);
|
2002-05-21 05:18:15 +01:00
|
|
|
#ifdef MULTI_ASSIGNMENT_VARIABLES
|
2004-09-07 21:20:12 +01:00
|
|
|
} else {
|
|
|
|
CELL *pt = RepAppl(d1);
|
2017-08-21 12:29:58 +01:00
|
|
|
/* AbsAppl means */
|
|
|
|
/* multi-assignment variable */
|
|
|
|
/* so the next cell is the old value */
|
2008-03-25 22:03:14 +00:00
|
|
|
#ifdef FROZEN_STACKS
|
2017-08-21 12:29:58 +01:00
|
|
|
pt[0] = TrailVal(TR - 1);
|
2005-04-07 18:56:58 +01:00
|
|
|
TR -= 1;
|
2002-05-21 05:18:15 +01:00
|
|
|
#else
|
2017-08-21 12:29:58 +01:00
|
|
|
pt[0] = TrailTerm(TR - 1);
|
2004-09-07 21:20:12 +01:00
|
|
|
TR -= 2;
|
2005-04-07 18:56:58 +01:00
|
|
|
#endif /* FROZEN_STACKS */
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2004-09-07 21:20:12 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-30 19:42:14 +01:00
|
|
|
INLINE_ONLY inline EXTERN void reset_attvars(CELL *dvarsmin, CELL *dvarsmax);
|
2010-03-22 15:01:54 +00:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
INLINE_ONLY inline EXTERN void reset_attvars(CELL *dvarsmin, CELL *dvarsmax) {
|
2010-03-15 14:19:45 +00:00
|
|
|
if (dvarsmin) {
|
|
|
|
dvarsmin += 1;
|
|
|
|
do {
|
|
|
|
CELL *newv;
|
|
|
|
newv = CellPtr(*dvarsmin);
|
2017-08-21 12:29:58 +01:00
|
|
|
RESET_VARIABLE(dvarsmin + 1);
|
2010-03-15 14:19:45 +00:00
|
|
|
if (IsUnboundVar(dvarsmin))
|
2017-08-21 12:29:58 +01:00
|
|
|
break;
|
2010-03-15 14:19:45 +00:00
|
|
|
RESET_VARIABLE(dvarsmin);
|
|
|
|
dvarsmin = newv;
|
|
|
|
} while (TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
INLINE_ONLY inline EXTERN void close_attvar_chain(CELL *dvarsmin,
|
|
|
|
CELL *dvarsmax);
|
2010-03-22 15:01:54 +00:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
INLINE_ONLY inline EXTERN void close_attvar_chain(CELL *dvarsmin,
|
|
|
|
CELL *dvarsmax) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2010-03-15 14:19:45 +00:00
|
|
|
if (dvarsmin) {
|
|
|
|
dvarsmin += 1;
|
|
|
|
do {
|
|
|
|
CELL *newv;
|
2017-08-21 12:29:58 +01:00
|
|
|
YapBind(dvarsmin + 1, dvarsmin[1]);
|
2010-03-15 14:19:45 +00:00
|
|
|
if (IsUnboundVar(dvarsmin))
|
2017-08-21 12:29:58 +01:00
|
|
|
break;
|
2010-03-15 14:19:45 +00:00
|
|
|
newv = CellPtr(*dvarsmin);
|
|
|
|
RESET_VARIABLE(dvarsmin);
|
|
|
|
dvarsmin = newv;
|
|
|
|
} while (TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
INLINE_ONLY EXTERN inline bool Yap_unify(Term t0, Term t1);
|
2012-06-29 22:44:08 +01:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
INLINE_ONLY EXTERN inline bool Yap_unify(Term t0, Term t1) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2004-09-07 21:20:12 +01:00
|
|
|
tr_fr_ptr TR0 = TR;
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
if (Yap_IUnify(t0, t1)) {
|
2017-06-18 11:14:55 +01:00
|
|
|
return true;
|
2004-09-07 21:20:12 +01:00
|
|
|
} else {
|
|
|
|
reset_trail(TR0);
|
2017-06-18 11:14:55 +01:00
|
|
|
return false;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
INLINE_ONLY EXTERN inline Int Yap_unify_constant(Term a, Term cons);
|
2002-11-11 17:38:10 +00:00
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
INLINE_ONLY EXTERN inline Int Yap_unify_constant(Term a, Term cons) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2001-04-09 20:54:03 +01:00
|
|
|
CELL *pt;
|
2017-08-21 12:29:58 +01:00
|
|
|
deref_head(a, unify_cons_unk);
|
|
|
|
unify_cons_nonvar : {
|
|
|
|
if (a == cons)
|
|
|
|
return (TRUE);
|
|
|
|
else if (IsApplTerm(a)) {
|
|
|
|
Functor f;
|
|
|
|
if (!IsApplTerm(cons))
|
|
|
|
return (FALSE);
|
|
|
|
f = FunctorOfTerm(a);
|
|
|
|
if (f != FunctorOfTerm(cons))
|
|
|
|
return (FALSE);
|
|
|
|
if (IsExtensionFunctor(f)) {
|
|
|
|
switch ((CELL)f) {
|
|
|
|
case db_ref_e:
|
|
|
|
return (a == cons);
|
|
|
|
case long_int_e: {
|
|
|
|
CELL d0 = RepAppl(a)[1];
|
|
|
|
CELL d1 = RepAppl(cons)[1];
|
|
|
|
return d0 == d1;
|
|
|
|
}
|
|
|
|
case double_e: {
|
|
|
|
Float d0 = FloatOfTerm(a);
|
|
|
|
Float d1 = FloatOfTerm(cons);
|
|
|
|
return d0 == d1;
|
|
|
|
}
|
|
|
|
case big_int_e:
|
2008-03-25 22:03:14 +00:00
|
|
|
#ifdef USE_GMP
|
2017-08-21 12:29:58 +01:00
|
|
|
return (Yap_gmp_tcmp_big_big(a, cons) == 0);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* USE_GMP */
|
2017-08-21 12:29:58 +01:00
|
|
|
default:
|
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
2017-08-21 12:29:58 +01:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
deref_body(a, pt, unify_cons_unk, unify_cons_nonvar);
|
|
|
|
YapBind(pt, cons);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#define EQ_OK_IN_CMP 1
|
|
|
|
#define LT_OK_IN_CMP 2
|
|
|
|
#define GT_OK_IN_CMP 4
|
|
|
|
|
2017-08-21 12:29:58 +01:00
|
|
|
static inline int do_cut(int i) {
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2011-02-15 13:54:19 +00:00
|
|
|
if (POP_CHOICE_POINT(B->cp_b)) {
|
2010-01-26 18:03:09 +00:00
|
|
|
cut_c_pop();
|
|
|
|
}
|
|
|
|
Yap_TrimTrail();
|
|
|
|
B = B->cp_b;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define cut_succeed() return do_cut(TRUE)
|
|
|
|
|
|
|
|
#define cut_fail() return do_cut(FALSE)
|