File: opt.mavar.h

package info (click to toggle)
yap 5.1.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 16,124 kB
  • ctags: 14,650
  • sloc: ansic: 122,796; perl: 22,545; sh: 3,768; java: 1,277; makefile: 1,191; xml: 739; tcl: 624; lisp: 142; awk: 9
file content (104 lines) | stat: -rw-r--r-- 2,912 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**********************************************************************
                                                               
                       The OPTYap Prolog system                
  OPTYap extends the Yap Prolog system to support or-parallel tabling
                                                               
  Copyright:   R. Rocha and NCC - University of Porto, Portugal
  File:        opt.mavar.h  
  version:     $Id: opt.mavar.h,v 1.4 2005/08/05 14:55:03 vsc Exp $   
                                                                     
**********************************************************************/

#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
#endif

#define MAVARS_HASH_SIZE 512

typedef struct ma_h_entry {
  CELL* addr;
  struct ma_h_entry *next;
} ma_h_inner_struct;

typedef struct {
  UInt timestmp;
  struct ma_h_entry val;
} ma_hash_entry;

extern ma_hash_entry Yap_ma_hash_table[MAVARS_HASH_SIZE];

extern UInt Yap_timestamp;    /* an unsigned int */

OPT_MAVAR_STATIC unsigned int Yap_MAVAR_HASH(CELL *);
OPT_MAVAR_STATIC struct ma_h_entry *Yap_ALLOC_NEW_MASPACE(void);
OPT_MAVAR_STATIC int Yap_lookup_ma_var(CELL *);
OPT_MAVAR_STATIC UInt Yap_NEW_MAHASH(ma_h_inner_struct *);

OPT_MAVAR_STATIC unsigned int
Yap_MAVAR_HASH(CELL *addr) {
#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
}

extern ma_h_inner_struct *Yap_ma_h_top;

OPT_MAVAR_STATIC struct ma_h_entry *
Yap_ALLOC_NEW_MASPACE(void)
{
  ma_h_inner_struct *new = Yap_ma_h_top;
  Yap_ma_h_top++;
  return new;
}

OPT_MAVAR_STATIC int
Yap_lookup_ma_var(CELL *addr) {
  unsigned int i = Yap_MAVAR_HASH(addr);
  struct ma_h_entry *nptr, *optr;

  if (Yap_ma_hash_table[i].timestmp != Yap_timestamp) {
    Yap_ma_hash_table[i].timestmp = Yap_timestamp;
    Yap_ma_hash_table[i].val.addr = addr;
    Yap_ma_hash_table[i].val.next = NULL;
    return FALSE;
  }
  if (Yap_ma_hash_table[i].val.addr == addr) 
    return TRUE;
  optr = &(Yap_ma_hash_table[i].val);
  nptr = Yap_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();
  nptr->addr = addr;
  nptr->next = optr;
  return FALSE;
}

OPT_MAVAR_STATIC UInt
Yap_NEW_MAHASH(ma_h_inner_struct *top) {
  UInt time = ++Yap_timestamp;
  if (time == 0) {
    unsigned int i;
    /* damn, we overflowed */
    for (i = 0; i < MAVARS_HASH_SIZE; i++)
      Yap_ma_hash_table[i].timestmp = 0;
    time = ++Yap_timestamp;
  }
  Yap_ma_h_top = top;
  return time;
}

#endif /* MULTI_ASSIGNMENT_VARIABLES */