This file is indexed.

/usr/include/Yap/amiops.h is in yap 6.2.2-6+b2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
/*************************************************************************
*									 *
*	 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.       *
*									 *
*************************************************************************/
#ifdef SCCS
static char     SccsId[] = "%W% %G%";
#endif /* SCCS */

#define  IsArrayReference(a) ((a)->array_access_func == FunctorArrayAccess)


/* dereferencing macros */

/************************************************************

Dereferencing macros

*************************************************************/

/* For DEREFD, D has both the input and the exit argument */
/* A is only used locally */

#define deref_head(D,Label)  if (IsVarTerm(D)) goto Label

#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 derefa_body(D,A,LabelUnk,LabelNonVar)                \
		do {                                         \
                   (A) = (CELL *)(D);                        \
                   (D) = *(CELL *)(D);                       \
                   if(!IsVarTerm(D)) goto LabelNonVar;       \
		LabelUnk:      ;                             \
		} while (Unsigned(A) != (D))

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

   The only instruction where this seems useful is 
   switch_list_nl
*/

#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);

#endif /* UNIQUE_TAG_FOR_PAIRS */

EXTERN Term STD_PROTO(Deref,(Term));
EXTERN Term STD_PROTO(Derefa,(CELL *));

EXTERN inline Term Deref(Term a)
{
   while(IsVarTerm(a)) {
	Term *b = (Term *) a;
	a = *b;
	if(a==((Term) b)) return a;
   }
   return(a);
}

EXTERN inline Term
Derefa(CELL *b)
{
  Term a = *b;
 restart:
  if (!IsVarTerm(a)) {
    return(a);
  } else if (a == (CELL)b) {
    return(a);
  } else {
    b = (CELL *)a;
    a = *b;
    goto restart;
  }
}

/************************************************************

TRAIL VARIABLE

A contains the address of the variable that is to be trailed

*************************************************************/


#define RESET_VARIABLE(V)       (*(CELL *)(V) = Unsigned(V))

#if SIZEOF_DOUBLE == 2*SIZEOF_LONG_INT

EXTERN inline void
AlignGlobalForDouble(void)
{
  /* Force Alignment for floats. Note that garbage collector may
     break the alignment; */
  if (!DOUBLE_ALIGNED(H)) {
    RESET_VARIABLE(H);
    H++;
  }
}

#endif

#ifdef TABLING

#define DO_TRAIL(TERM, VAL)      \
{                                \
  register tr_fr_ptr r;          \
  r = TR;                        \
  TR = r + 1;                    \
  TrailTerm(r) = (Term) (TERM);  \
  TrailVal(r) = (CELL) (VAL);    \
}

#ifdef BFZ_TRAIL_SCHEME

#define TRAIL(TERM, VAL)                                  \
        if (OUTSIDE(HBREG,TERM,B) ||                      \
            ((TERM) > (CELL *)B_FZ))                      \
          DO_TRAIL(TERM, VAL)

#define TRAIL_LOCAL(TERM, VAL)                            \
 	if ((TERM) > (CELL *)B || (TERM) > (CELL *)B_FZ)  \
          DO_TRAIL(TERM, VAL)

#ifdef TERM_EXTENSIONS

#define Trail(TERM, VAL, LAB)                             \
        if (IN_BETWEEN(HBREG,TERM,B) &&                   \
            ((TERM) < (CELL *)B_FZ))                      \
          goto LAB

#define TrailAndJump(TERM, VAL)                             \
        if (IN_BETWEEN(HBREG,TERM,B) &&                   \
            ((TERM) < (CELL *)B_FZ))                      \
          GONext();

#else
#define Trail(TERM, VAL, LAB)                             \
          TRAIL(TERM, VAL)

#define Trail(TERM, VAL, LAB)                             \
          TRAIL_AND_JUMP(TERM, VAL)
#endif

#else /* BBREG_TRAIL_SCHEME */

#define TRAIL(TERM, VAL)                                  \
        if (OUTSIDE(HBREG,TERM,BBREG))                    \
          DO_TRAIL(TERM, VAL)

#ifdef TERM_EXTENSIONS
#define Trail(TERM, VAL, LAB)                             \
        if (IN_BETWEEN(HBREG,TERM,BBREG))                 \
          goto LAB

#define TrailAndJump(TERM, VAL)                             \
        if (IN_BETWEEN(HBREG,TERM,BBREG))                 \
          GONext();

#else
#define Trail(TERM, VAL, LAB)                             \
          TRAIL(TERM, VAL)

#define TrailAndJump(TERM, VAL)                             \
          TRAIL_AND_JUMP(TERM, VAL)

#endif

#define TRAIL_LOCAL(TERM, VAL)                            \
 	if ((TERM) > (CELL *)BBREG) DO_TRAIL(TERM, VAL)

#endif /* TRAIL_SCHEME */

/* ------------------------------------------------------ */

#define TRAIL_GLOBAL(TERM, VAL)                  \
 	if ((TERM) < HBREG) DO_TRAIL(TERM, VAL)

#ifdef TERM_EXTENSIONS
#define Trail_Global(TERM, VAL, LAB)              \
 	if ((TERM) >= HBREG) goto LAB
#else
#define Trail_Global(TERM, VAL, LAB)              \
          TRAIL_GLOBAL(TERM, VAL)
#endif

#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);                                 \
}

#define MATRAIL(TERM, OVAL, VAL)                  \
        if (OUTSIDE(HBREG,TERM,B))                \
          DO_MATRAIL(TERM, OVAL, VAL)

#else /* TABLING */

#if defined(i386) && !defined(TERM_EXTENSIONS)

#define DO_TRAIL(A,D)                   \
{					\
  register tr_fr_ptr r; 		\
  r = TR;				\
  TR = r+1;				\
  TrailTerm(r) = (CELL)(A);		\
}

#define TRAIL(A,D)        if (OUTSIDE(HBREG,A,B))             \
				DO_TRAIL(A,D);

#define TRAIL_AND_JUMP(A,D)        if (!OUTSIDE(HBREG,A,B)) GONext();	\
				DO_TRAIL(A,D);

#define Trail(A, D, LAB)   TRAIL(A,D)

#define TRAIL_GLOBAL(A,D)	if ((A) < HBREG) DO_TRAIL(A,D);

#define Trail_Global(A,D,LAB)	if ((A) < HBREG) DO_TRAIL(A,D);

#define TRAIL_LOCAL(A,D)	if ((A) > (CELL *)B) DO_TRAIL(A,D);


#elif defined(__alpha) && !defined(TERM_EXTENSIONS)

/* alpha machines have a move conditional instruction, which avoids a
   branch when jumping */
#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();

#define Trail(A,D,LAB)    TRAIL(A,D)

#define TRAIL_GLOBAL(A,D)	TR[0] = (CELL)(A); if ((A) < HBREG) TR++

#define Trail_Global(A,D,LAB)   TRAIL_GLOBAL(A,D)

#define TRAIL_LOCAL(A,D)	TR[0] = (CELL)(A); if ((A) > ((CELL *)(B)))  TR++

#elif !defined(TERM_EXTENSIONS)

#define DO_TRAIL(A,D)     TrailTerm(TR++) = (CELL)(A)

#define TRAIL(A,D)        if (OUTSIDE(HBREG,A,B))            \
                              DO_TRAIL(A,D)

#define TRAIL_AND_JUMP(A,D)        if (IN_BETWEEN(HBREG,A,B)) GONext();	\
                              DO_TRAIL(A,D)

#define Trail(A,D,LAB)    TRAIL(A,D)

#define TRAIL_GLOBAL(A,D)	if ((A) < HBREG) DO_TRAIL(A,D)

#define Trail_Global(A,D,LAB)  TRAIL_GLOBAL(A,D)

#define Trail_Global2(A,D,LAB)  TRAIL_GLOBAL(A,D)

#define TRAIL_LOCAL(A,D)	if ((A) > ((CELL *)B))  DO_TRAIL(A,D)

#else

#define DO_TRAIL(A,D)     TrailTerm(TR++) = (CELL)(A)

#define TRAIL(A,D)        if (OUTSIDE(HBREG,A,B))            \
                              DO_TRAIL(A,D)

#define Trail(A,D,LAB)    if (IN_BETWEEN(HBREG,A,B))            \
                              goto LAB

#define TrailAndJump(A,D)    if (IN_BETWEEN(HBREG,A,B))            \
    GONext();

#define TRAIL_GLOBAL(A,D)	if ((A) < HBREG) DO_TRAIL(A,D)

#define Trail_Global(A,D,LAB) if ((A) >= HBREG) goto LAB

#define Trail_Global2(A,D,LAB) if ((A) < HBREG) goto LAB

#define TRAIL_LOCAL(A,D)	if ((A) > ((CELL *)B))  DO_TRAIL(A,D)

#endif

/************************************************************

Binding Macros for Multiple Assignment Variables.

************************************************************/

#define DO_MATRAIL(VP, OLDV, D)                                  \
        { TrailTerm(TR+1) = OLDV;                                \
          TrailTerm(TR) = TrailTerm(TR+2) = AbsAppl(VP);         \
          TR += 3;                                               \
        }

#define MATRAIL(VP,OLDV,D)    if (OUTSIDE(HBREG,VP,B))          \
                           DO_MATRAIL(VP, OLDV, D)

#endif /* TABLING */


#define REF_TO_TRENTRY(REF)    AbsPair(((CELL *)&((REF)->Flags)))
#define CLREF_TO_TRENTRY(REF)  AbsPair(((CELL *)&((REF)->ClFlags)))

#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))
#define TRAIL_FRAME(FR)        DO_TRAIL(AbsPair((CELL *)(Yap_TrailBase)), FR)

#define Bind(A,D)              TRAIL(A,D); *(A) = (D)
#define Bind_Global(A,D)       TRAIL_GLOBAL(A,D); *(A) = (D)
#define Bind_and_Trail(A,D)    DO_TRAIL(A,D); *(A) = (D)
#define BIND(A,D,L)            *(A) = (D); Trail(A,D,L)
#define BIND_AND_JUMP(A,D)     *(A) = (D); TrailAndJump(A,D)
#define BIND_GLOBAL(A,D,L)     *(A) = (D); Trail_Global(A,D,L)

#ifdef COROUTINING
#define BIND_GLOBAL2(A,D,LAB,LAB1)   *(A) = (D); if ((A) < HBREG) goto LAB; goto LAB1

#define BIND_GLOBALCELL(A,D)    *(A) = (D); \
				if ((A) >= HBREG) continue; \
                                TRAIL_GLOBAL(A,D); if (!IsAttVar(A)) continue; \
                                Yap_WakeUp((A)); continue

#define BIND_GLOBALCELL_NONATT(A,D)    *(A) = (D); \
				if ((A) >= HBREG) continue; \
                                TRAIL_GLOBAL(A,D);
#else
#define BIND_GLOBAL2(A,D,LAB,LAB1)   BIND_GLOBAL(A,D,LAB)

#define BIND_GLOBALCELL(A,D)    BIND_GLOBAL(A,D,L); continue

#define BIND_GLOBALCELL_NONATT(A,D)    BIND_GLOBALCELL; continue
#endif

#define Bind_Local(A,D)	   { TRAIL_LOCAL(A,D); *(A) = (D); }


#define MaBind(VP,D)    { MATRAIL((VP),*(VP),(D)); *(VP) = (D); }

#if defined(__GNUC__) && defined(i386) && !defined(TERM_EXTENSIONS) && !defined(TABLING)
/* destroy d0 and pt0 */
#define DBIND(A,D,L)                                                    \
{ register CELL *t1=HBREG;                                              \
__asm__("movl %4,(%0)\n\t"                                              \
        "movl %2,%4\n\t"                                                \
	"subl %1,%2\n\t"                                                \
	"subl %0,%4\n\t"                                                \
	"cmpl %2,%4\n\t"                                                \
	"jae  1f\n\t"                                                   \
	"movl %3,%4\n\t"                                                \
	"movl %0,(%4)\n\t"                                              \
	"addl $4,%4\n\t"                                                \
	"movl %4,%3\n\t"                                                \
	"1:"                                                            \
	: /* no outputs */                                              \
	: "r" (A), "m" (B), "r" (t1), "m" (TR), "r" (D) );              \
}

#else
#define DBIND(A,D,L)  BIND(A,D,L)
#endif


/************************************************************

Unification Routines

*************************************************************/

EXTERN Int STD_PROTO(Yap_unify,(Term,Term));

inline EXTERN void STD_PROTO(reset_trail,(tr_fr_ptr));

inline EXTERN void
reset_trail(tr_fr_ptr TR0) {
  while(TR != TR0) {
    CELL d1;
    --TR;
    d1 = TrailTerm(TR);
#ifdef MULTI_ASSIGNMENT_VARIABLES
    if (IsVarTerm(d1)) {
#endif
      CELL *pt = (CELL *)d1;
      RESET_VARIABLE(pt);
#ifdef MULTI_ASSIGNMENT_VARIABLES
    } else {
      CELL *pt = RepAppl(d1);
      /* AbsAppl means */
      /* multi-assignment variable */
      /* so the next cell is the old value */ 
#ifdef FROZEN_STACKS
      pt[0] = TrailVal(TR-1);
      TR -= 1;
#else
      pt[0] = TrailTerm(TR-1);
      TR -= 2;
#endif /* FROZEN_STACKS */
    }
#endif
  }
}

inline EXTERN void reset_attvars(CELL *dvarsmin, CELL *dvarsmax);

inline EXTERN void
reset_attvars(CELL *dvarsmin, CELL *dvarsmax) {
  if (dvarsmin) {
    dvarsmin += 1;
    do {
      CELL *newv;
      newv = CellPtr(*dvarsmin);
      RESET_VARIABLE(dvarsmin+1);
      if (IsUnboundVar(dvarsmin))
	break;
      RESET_VARIABLE(dvarsmin);
      dvarsmin = newv;
    } while (TRUE);
  }
}

inline EXTERN void close_attvar_chain(CELL *dvarsmin, CELL *dvarsmax);

inline EXTERN void
close_attvar_chain(CELL *dvarsmin, CELL *dvarsmax) {
  if (dvarsmin) {
    dvarsmin += 1;
    do {
      CELL *newv;
      Bind(dvarsmin+1, dvarsmin[1]);
      if (IsUnboundVar(dvarsmin))
	break;
      newv = CellPtr(*dvarsmin);
      RESET_VARIABLE(dvarsmin);
      dvarsmin = newv;
    } while (TRUE);
  }
}

EXTERN inline
Int Yap_unify(Term t0, Term t1)
{
  tr_fr_ptr TR0 = TR;

  if (Yap_IUnify(t0,t1)) {
    return TRUE;
  } else {
    reset_trail(TR0);
    return FALSE;
  }
}

EXTERN Int STD_PROTO(Yap_unify_constant,(Term,Term));

EXTERN inline Int
Yap_unify_constant(register Term a, register Term cons)
{
  CELL *pt;
  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 (CELL)FunctorDBRef:
	  return(a == cons);
	case (CELL)FunctorLongInt:
	  {
	    CELL d0 = RepAppl(a)[1];
	    CELL d1 = RepAppl(cons)[1];
	    return d0 == d1;
	  }
	case (CELL)FunctorDouble:
	  {
	    Float d0 = FloatOfTerm(a);
	    Float d1 = FloatOfTerm(cons);
	    return d0 == d1;
	  }
	case (CELL)FunctorBigInt:
#ifdef USE_GMP
	  return (Yap_gmp_tcmp_big_big(a, cons) == 0);
#endif /* USE_GMP */
	default:
	  return FALSE;
	}
      }
    } else
      return FALSE;
  }

  deref_body(a,pt,unify_cons_unk,unify_cons_nonvar);
  BIND(pt,cons,wake_for_cons);
#ifdef COROUTINING
  DO_TRAIL(pt, cons);
  if (IsAttVar(pt)) Yap_WakeUp(pt);
 wake_for_cons:
#endif
  return(TRUE);
}


#define EQ_OK_IN_CMP 1
#define LT_OK_IN_CMP 2
#define GT_OK_IN_CMP 4

static inline int
do_cut(int i) {
#ifdef CUT_C
  while (POP_CHOICE_POINT(B->cp_b)) {
    cut_c_pop();
  }
#endif
  Yap_TrimTrail();
  B = B->cp_b;
  return i;
}

#define cut_succeed() return do_cut(TRUE)

#define cut_fail() return do_cut(FALSE)