YAP 7.1.0
terms.h
1#ifndef TERMS_H
2
3#define TERMS_H #include "amidefs.h"
4
5#include "Yap.h"
6
7typedef struct cp_frame {
8 CELL *pt0;
9 CELL *pt0_end;
10 CELL *ptf;
11 CELL *curp;
12 CELL* oldp;
13 CELL oldv;
14 tr_fr_ptr tr;
15 bool ground;
16 Term t;
18
19
20#define to_visit stt->pt
21#define to_visit0 stt->pt0
22#define to_visit_end stt->max
23
24
25 typedef struct {
26 size_t szW , arenaW;
27 CELL *hlow;
28 Int tr0;
29 Term t, *bindp, *arenap;
30 yap_error_number err;
31 int restarts_g;
32 copy_frame *pt0;
33 copy_frame *pt;
34 copy_frame *max;
35 } Ystack_t;
36
37
38#define IS_VISIT_MARKER(d0) (IsPairTerm(d0) && \
39 (copy_frame*)RepPair(d0) >= to_visit0 \
40&& (copy_frame*)RepPair(d0) <= to_visit)
41
42#define VISIT_MARK() AbsPair((CELL*)to_visit)
43
44#define VISIT_ENTRY(d0) (( copy_frame *)RepPair(d0))
45
46#define VISIT_TARGET(d0) ((( copy_frame *)RepPair(d0))->t)
47
48#define VISIT_REPLACED(d0) ((( copy_frame *)RepPair(d0))->oldv)
49
50
51#define VUNMARK(ptd0, d0) (*(ptd0) = (d0))
52
53
54#define VISITED(D0) IS_VISIT_MARKER(D0)
55
56
57#define VISIT_UNMARK(d0) (IS_VISIT_MARKER(d0)?(( copy_frame *)RepPair(d0))->oldv:d0)
58
59#define mderef_head(D, DM, Label) \
60 D = DM;\
61 while (IS_VISIT_MARKER(D)){\
62 D = VISIT_REPLACED(D); } \
63 if (IsVarTerm(D)) goto Label \
64
65static inline bool init_stack(Ystack_t *b)
66{
67
68 b->pt0 =(copy_frame*)LOCAL_aux;
69
70 b->szW = LOCAL_aux_sz/sizeof(copy_frame);
71 b->pt = b->pt0;
72 b->max = (copy_frame*)((char*)(b->pt0)+LOCAL_aux_sz);
73 b->hlow = HR;
74
75 b->tr0 = TR-B->cp_tr;
76 b->err = YAP_NO_ERROR;
77 return (b->pt0 != NULL);
78 }
79
80
81static inline size_t realloc_stack( Ystack_t *stt) {
82 size_t delta = (char*)stt->max-(char*)stt->pt0, n=stt->pt-stt->pt0;
83 size_t nsz = delta > 1024*1024 ? delta+1024+1024 : 2*delta;
84 stt->pt0 =(copy_frame*)(LOCAL_aux =realloc(LOCAL_aux,(nsz+1)*sizeof(copy_frame)));
85 stt->szW = LOCAL_aux_sz/sizeof(copy_frame);
86 stt->pt = stt->pt0;
87 stt->max = stt->pt0+nsz;
88 for (stt->pt = stt->pt0; stt->pt < stt->pt0+n; stt->pt++) {
89 stt->pt->oldp[0] = VISIT_MARK();
90 }
91 return nsz;
92}
93
94
95static inline void reset_stack( Ystack_t *b) {
96 b->pt = b->pt0;
97 b->hlow = HR;
98 b->tr0 = TR-B->cp_tr;
99
100}
101
102static inline void reset_stack_but_not_trail( Ystack_t *b) {
103 b->pt = b->pt0;
104 b->hlow = HR;
105}
106
107
108#define mderef_body(D, DM, A, LabelUnk, LabelNonVar) \
109 do {\
110 if (!IsVarTerm(D)) \
111 goto LabelNonVar; \
112 LabelUnk: \
113(A) = (CELL *)(D); \
114(DM) = *(A);\
115 while (IS_VISIT_MARKER(DM)){\
116 DM = VISIT_REPLACED(DM); } \
117 if (DM==D) break;\
118 D=DM;\
119} while (true )
120
121#define POP_VISIT(A, DD)\
122{ DD=*A;\
123if(IS_VISIT_MARKER(DD))\
124 {*A = (( copy_frame *)RepPair(dd))->oldv; }}
125
126#define PUSH_VISIT(A, DD, D)\
127{if(IS_VISIT_MARKER(DD)) {\
128 (( copy_frame *)RepPair(DD))->oldv = (D); *(A)=DD; }}
129
130#define TrailedMaBind(VP, D) \
131 { \
132 DO_MATRAIL((VP), *(VP), (D)); \
133 *(VP) = (D); \
134 }
135
136
137#define mSET(A,D) \
138 { Term dd; POP_VISIT(A, dd); *A=D; PUSH_VISIT(A,dd,D); }
139
140#define mBind(A,D) \
141 { Term dd; POP_VISIT(A, dd); YapBind(A,D); PUSH_VISIT(A,dd,D); }
142
143#define mBind_And_Trail(A,D) \
144 { Term dd; POP_VISIT(A, dd); Bind_and_Trail(A,D); PUSH_VISIT(A,dd,D); }
145
146#define mMaBind(A,D) \
147 { Term dd; POP_VISIT(A, dd); MaBind(A,D); PUSH_VISIT(A,dd,D); }
148
149
150#define mTrailedMaBind(A,D) \
151 { Term dd; POP_VISIT((A), dd); TrailedMaBind((A),(D)); PUSH_VISIT(A,dd,D); }
152
153
154#if 1
155#define COPY(t)
156#else
157extern
158unsigned long long vsc_cnt;
159#define COPY(t) if (!IsAtomOrIntTerm(t)){ fprintf(stderr,"+ %lld %s: ",vsc_count++,__FUNCTION__); Yap_DebugPlxWriteln(t);}
160#define OCOPY(t) { fprintf(stderr,"- %lld %s: ",vsc_count++,__FUNCTION__); Yap_DebugPlWriteln(t);if (vsc_count==12190) Yap_do_low_level_trace=1}
161#endif
162
163
164
165/* is val pointing to something bound to the heap? */
166
167
168#define GCIsPrimitiveTerm(X) (/* not really needed !IsVarTerm(X) && */ IsAtomOrIntTerm(X))
169
170/* Does X point to an object in the heap */
171#define HEAP_PTR(val) (!GCIsPrimitiveTerm(val) && ONHEAP(GET_NEXT(val)))
172
173/*
174 Heap_trail_entry must be very careful. We are looking at a valid
175 trail entry if: it was between H0 and HB or between B and LCLO
176 (that is, if it was covered by choicepoints at the time), and if it
177 was a heap pointer.
178
179 We can join the two conditions: (H0 =< val < HB || ((B < val < LCL0)
180 x && H0 <= *DETAG(val) < H))
181*/
182#define HEAP_TRAIL_ENTRY(val) ((IsVarTerm(val)) && \
183 ((H0 <= CellPtr(val) && CellPtr(val)\
184 < cp_H) || \
185 (CellPtr(B) < CellPtr(val) && CellPtr(val) <= \
186 LCL0 && HEAP_PTR(val))))
187
188
189#endif
Main definitions.
Definition: terms.h:25