This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/OPTYap/opt.mavar.h

93 lines
3.0 KiB
C
Raw Normal View History

/************************************************************************
** **
** The YapTab/YapOr/OPTYap systems **
** **
** YapTab extends the Yap Prolog engine to support sequential tabling **
** YapOr extends the Yap Prolog engine to support or-parallelism **
** OPTYap extends the Yap Prolog engine to support or-parallel tabling **
** **
** **
** Yap Prolog was developed at University of Porto, Portugal **
** **
************************************************************************/
#ifdef MULTI_ASSIGNMENT_VARIABLES
/*
Set of routines to allow restoring updatable variables when we go *up*
in the tree. Required by copying, SBA, and tabling. Not required by ACOW.
*/
#ifndef OPT_MAVAR_STATIC
#define OPT_MAVAR_STATIC inline static
2011-04-14 19:19:13 +01:00
#endif /* !OPT_MAVAR_STATIC */
OPT_MAVAR_STATIC unsigned int Yap_MAVAR_HASH(CELL *addr USES_REGS);
OPT_MAVAR_STATIC struct ma_h_entry * Yap_ALLOC_NEW_MASPACE(USES_REGS1);
OPT_MAVAR_STATIC int Yap_lookup_ma_var(CELL *addr USES_REGS);
OPT_MAVAR_STATIC UInt Yap_NEW_MAHASH(ma_h_inner_struct *top USES_REGS);
OPT_MAVAR_STATIC unsigned int
Yap_MAVAR_HASH(CELL *addr USES_REGS) {
#if SIZEOF_INT_P==8
return((((unsigned int)((CELL)(addr)))>>3)%MAVARS_HASH_SIZE);
#else
return((((unsigned int)((CELL)(addr)))>>2)%MAVARS_HASH_SIZE);
#endif
}
OPT_MAVAR_STATIC struct ma_h_entry *
Yap_ALLOC_NEW_MASPACE(USES_REGS1)
{
2015-01-20 03:00:42 +00:00
ma_h_inner_struct *newS = LOCAL_ma_h_top;
2011-04-14 19:19:13 +01:00
LOCAL_ma_h_top++;
2015-01-20 03:00:42 +00:00
return newS;
}
OPT_MAVAR_STATIC int
Yap_lookup_ma_var(CELL *addr USES_REGS) {
unsigned int i = Yap_MAVAR_HASH(addr PASS_REGS);
struct ma_h_entry *nptr, *optr;
2011-04-14 19:19:13 +01:00
if (LOCAL_ma_hash_table[i].timestmp != LOCAL_ma_timestamp) {
LOCAL_ma_hash_table[i].timestmp = LOCAL_ma_timestamp;
LOCAL_ma_hash_table[i].val.addr = addr;
LOCAL_ma_hash_table[i].val.next = NULL;
return FALSE;
}
2011-04-14 19:19:13 +01:00
if (LOCAL_ma_hash_table[i].val.addr == addr)
return TRUE;
2011-04-14 19:19:13 +01:00
optr = &(LOCAL_ma_hash_table[i].val);
nptr = LOCAL_ma_hash_table[i].val.next;
while (nptr != NULL) {
if (nptr->addr == addr) {
return TRUE;
}
optr = nptr;
nptr = nptr->next;
}
nptr = Yap_ALLOC_NEW_MASPACE(PASS_REGS1);
nptr->addr = addr;
nptr->next = optr;
return FALSE;
}
OPT_MAVAR_STATIC UInt
Yap_NEW_MAHASH(ma_h_inner_struct *top USES_REGS) {
2011-04-14 19:19:13 +01:00
UInt time = ++LOCAL_ma_timestamp;
if (time == 0) {
unsigned int i;
/* damn, we overflowed */
for (i = 0; i < MAVARS_HASH_SIZE; i++)
2011-04-14 19:19:13 +01:00
LOCAL_ma_hash_table[i].timestmp = 0;
time = ++LOCAL_ma_timestamp;
}
2011-04-14 19:19:13 +01:00
LOCAL_ma_h_top = top;
return time;
}
2011-04-18 14:59:17 +01:00
#else
#define Yap_MAVAR_HASH(addr)
#define Yap_ALLOC_NEW_MASPACE()
#define Yap_lookup_ma_var(addr)
#define Yap_NEW_MAHASH(top)
#endif /* MULTI_ASSIGNMENT_VARIABLES */