1 
2 
3 
4 
5 
6 
7 
8 /*************************************************************************
9 *									 *
10 *	 YAP Prolog 	%W% %G% 					 *
11 *	Yap Prolog was developed at NCCUP - Universidade do Porto	 *
12 *									 *
13 * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997	 *
14 *									 *
15 **************************************************************************
16 *									 *
17 * File:		Yap.h.m4						 *
18 * mods:									 *
19 * comments:	main header file for YAP				 *
20 * version:      $Id: Yap.h,v 1.9 2002-06-01 04:29:01 vsc Exp $	 *
21 *************************************************************************/
22 
23 #include "config.h"
24 
25 /*
26 
27 #define RATIONAL_TREES 1
28 
29 #define DEPTH_LIMIT 1
30 
31 #define COROUTINING 1
32 
33 #define YAPOR      1
34 
35 #define ANALYST 1
36 
37 */
38 
39 #define MULTI_ASSIGNMENT_VARIABLES 1
40 
41 #if defined(TABLING)
42 #error Do not explicitly define TABLING
43 #endif /* YAPOR */
44 
45 #if defined(TABLING_BATCHED_SCHEDULING) && defined(TABLING_LOCAL_SCHEDULING)
46 #error Do not define multiple tabling scheduling strategies
47 #endif /* TABLING_BATCHED_SCHEDULING || TABLING_LOCAL_SCHEDULING */
48 
49 #if defined(TABLING_BATCHED_SCHEDULING) || defined(TABLING_LOCAL_SCHEDULING)
50 #define TABLING 1
51 #endif /* TABLING_BATCHED_SCHEDULING || TABLING_LOCAL_SCHEDULING */
52 
53 #if defined(YAPOR)
54 #error Do not explicitly define YAPOR
55 #endif /* YAPOR */
56 
57 #if (defined(ENV_COPY) && (defined(ACOW) || defined(SBA))) || (defined(ACOW) && defined(SBA))
58 #error Do not define multiple or-parallel models
59 #endif /* (ENV_COPY && (ACOW || SBA)) || (ACOW && SBA) */
60 
61 #if defined(ENV_COPY) || defined(ACOW) || defined(SBA)
62 #define YAPOR 1
63 #endif /* ENV_COPY || ACOW || SBA */
64 
65 #if defined(TABLING) && (defined(ACOW) || defined(SBA))
66 #error Currently TABLING only works with ENV_COPY
67 #endif /* TABLING && (ACOW || SBA) */
68 
69 #ifdef YAPOR
70 #define FIXED_STACKS 1
71 #endif /* YAPOR */
72 
73 #if defined(YAPOR) || defined(TABLING)
74 #undef TRAILING_REQUIRES_BRANCH
75 #endif /* YAPOR || TABLING */
76 
77 #if ANALYST
78 #ifdef USE_THREADED_CODE
79 #undef USE_THREADED_CODE
80 #endif
81 #endif
82 
83 #ifdef  COROUTINING
84 #ifndef TERM_EXTENSIONS
85 #define TERM_EXTENSIONS 1
86 #endif
87 #endif
88 
89 #ifdef SBA
90 #ifdef YAPOR
91 #ifndef FROZEN_STACKS
92 #define FROZEN_STACKS 1
93 #endif
94 #endif
95 #endif
96 
97 #ifdef TABLING
98 #ifndef FROZEN_STACKS
99 #define FROZEN_STACKS 1
100 #endif
101 #endif
102 
103 #ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */
104 /* adjust a config.h from mingw32 to work with vc++ */
105 #ifdef HAVE_GCC
106 #undef  HAVE_GCC
107 #endif
108 #ifdef  USE_THREADED_CODE
109 #undef  USE_THREADED_CODE
110 #endif
111 #define inline __inline
112 #define YAP_VERSION "Yap-4.3.21"
113 #define BIN_DIR "c:\\Program Files\\Yap\\bin"
114 #define LIB_DIR "c:\\Program Files\\Yap\\lib\\Yap"
115 #define SHARE_DIR "c:\\Program Files\\Yap\\share\\Yap"
116 #ifdef  HOST_ALIAS
117 #undef  HOST_ALIAS
118 #endif
119 #define HOST_ALIAS "i386-pc-win32"
120 #ifdef  HAVE_IEEEFP_H
121 #undef  HAVE_IEEEFP_H
122 #endif
123 #ifdef  HAVE_UNISTD_H
124 #undef  HAVE_UNISTD_H
125 #endif
126 #ifdef  HAVE_SYS_TIME_H
127 #undef  HAVE_SYS_TIME_H
128 #endif
129 #endif
130 
131 #ifdef __MINGW32__
132 #ifndef _WIN32
133 #define _WIN32 1
134 #endif
135 #endif
136 
137 #if HAVE_GCC
138 #define MIN_ARRAY 0
139 #define DUMMY_FILLER_FOR_ABS_TYPE
140 #else
141 #define MIN_ARRAY 1
142 #define DUMMY_FILLER_FOR_ABS_TYPE int dummy;
143 #endif
144 
145 #ifndef ADTDEFS_C
146 #define EXTERN  static
147 #else
148 #define EXTERN
149 #endif
150 
151 /*  truth-values							*/
152 #define	 TRUE	1
153 #define	 FALSE	0
154 
155 /*  null pointer							*/
156 #define	 NIL	0
157 
158 /* Basic types */
159 
160 /* defines integer  types Int and UInt (unsigned) with the same size as a ptr
161 ** and integer types Short and UShort with half the size of a ptr
162 */
163 
164 #if SIZEOF_INT_P==4
165 
166 #if SIZEOF_INT==4
167 /*   */ typedef int Int;
168 /*   */ typedef unsigned int UInt;
169 
170 #elif SIZEOF_LONG_INT==4
171 /*   */ typedef long int Int;
172 /*   */ typedef unsigned long int UInt;
173 
174 #else
175 #	error Yap require integer types of the same size as a pointer
176 #endif
177 
178 #if SIZEOF_SHORT_INT==2
179 /*   */ typedef short int Short;
180 /*   */ typedef unsigned short int UShort;
181 
182 #else
183 #	error Yap requires integer types half the size of a pointer
184 #endif
185 
186 #elif SIZEOF_INT_P==8
187 
188 #   if SIZEOF_INT==8
189 /*   */ typedef int Int;
190 /*   */ typedef unsigned int UInt;
191 
192 #elif SIZEOF_LONG_INT==8
193 /*   */ typedef long int Int;
194 /*   */ typedef unsigned long int UInt;
195 
196 #   elif SIZEOF_LONG_LONG_INT==8
197 /*   */ typedef long long int Int;
198 /*   */ typedef unsigned long long int UInt;
199 
200 #   else
201 #	error Yap requires integer types of the same size as a pointer
202 #   endif
203 
204 #   if SIZEOF_SHORT_INT==4
205 /*   */ typedef short int Short;
206 /*   */ typedef unsigned short int UShort;
207 
208 #   elif SIZEOF_INT==4
209 /*   */ typedef int Short;
210 /*   */ typedef short int UShort;
211 
212 #   else
213 #	error Yap requires integer types half the size of a pointer
214 #   endif
215 
216 #else
217 
218 #  error Yap requires pointers of size 4 or 8
219 
220 #endif
221 
222 /*   */ typedef double  Float;
223 
224 #if SIZEOF_INT<SIZEOF_INT_P
225 #define SHORT_INTS 1
226 #else
227 #define SHORT_INTS 0
228 #endif
229 
230 #if DEBUG
231 extern char     Option[20];
232 #endif
233 
234 /* #define FORCE_SECOND_QUADRANT 1 */
235 
236 #if defined(FORCE_SECOND_QUADRANT)
237 #define IN_SECOND_QUADRANT 1
238 #define MMAP_ADDR 0x42000000
239 #endif
240 
241 #if !IN_SECOND_QUADRANT
242 #if __linux__ || __FreeBSD__ || __NetBSD__ || mips || __APPLE__
243 #if defined(YAPOR) && defined(__alpha)
244 #define MMAP_ADDR 0x40000000
245 #elif mips
246 #define MMAP_ADDR 0x02000000
247 #elif __APPLE__
248 #define MMAP_ADDR 0x01000000
249 #else
250 #define MMAP_ADDR 0x09000000
251 #endif
252 #elif __svr4__ || defined(__SVR4)
253 #define MMAP_ADDR 0x02000000
254 #elif defined(_WIN32) || defined(__CYGWIN__)
255 #define MMAP_ADDR 0x30000000L
256 #endif
257 #endif /* !IN_SECOND_QUADRANT */
258 
259 #if defined(MMAP_ADDR) && (USE_MMAP || USE_SHMAT || _WIN32) && !__simplescalar__
260 #define HEAP_INIT_BASE  (MMAP_ADDR)
261 #define AtomBase        ((char *)MMAP_ADDR)
262 #else
263 #define HEAP_INIT_BASE  ((CELL)HeapBase)
264 #define AtomBase        (HeapBase)
265 #endif
266 
267 
268 
269 #ifndef SHORT_ADDRESSES
270 #	define LONG_ADDRESSES	1
271 #else
272 #	define LONG_ADDRESSES	0
273 #endif
274 
275 #ifndef ALIGN_LONGS
276 #define ALIGN_LONGS 1
277 #endif
278 
279 /*  basic data types  */
280 
281 typedef UInt CELL;
282 typedef UShort BITS16;
283 typedef Short SBITS16;
284 typedef UInt BITS32;
285 
286 #if ALIGN_LONGS
287 typedef CELL SFLAGS;
288 #else
289 typedef BITS16 SFLAGS;
290 #endif
291 
292 typedef char   *ADDR;
293 typedef CELL OFFSET;
294 typedef unsigned char *CODEADDR;
295 
296 #define WordSize     sizeof(BITS16)
297 #define CellSize     sizeof(CELL)
298 #define SmallSize    sizeof(SMALLUNSGN)
299 
300 /* type	casting	macros		*/
301 
302 #define	Addr(V)		((ADDR) (V))
303 #define	Unsigned(V)	((CELL) (V))
304 #define	Signed(V)	((Int) (V))
305 
306 #define CodePtr(V)	((CODEADDR)(V))
307 #define	CellPtr(V) 	((CELL *)(V))
308 #define OpCodePtr(V)	((OPCODE *)(V))
309 #define OpRegPtr(V)	((OPREG *)(V))
310 #define SmallPtr(V)	((SMALLUNSGN *)(V))
311 #define	WordPtr(V)	((BITS16 *)(V))
312 #define DisplPtr(V)	((DISPREG *)(V))
313 #define TermPtr(V)	((Term *) (V))
314 
315 /*	Abstract Type Definitions for YAPProlog			       */
316 
317 typedef CELL Term;
318 
319 #if !defined(YAPOR) && !defined(THREADS)
320 #include <nolocks.h>
321 #else
322 #ifdef i386
323 #include <locks_x86.h>
324 #endif
325 #if defined(sparc) || defined(__sparc)
326 #include <locks_sparc.h>
327 #endif
328 #ifdef mips
329 #include <locks_mips.h>
330 #endif
331 #ifdef __alpha
332 #include <locks_alpha.h>
333 #endif
334 #endif
335 
336 /********************** use an auxiliary function for ranges ************/
337 
338 #ifdef __GNUC__
339 #define IN_BETWEEN(MIN,X,MAX) (Unsigned((Int)(X)-(Int)(MIN)) <=  \
340  			    Unsigned((Int)(MAX)-(Int)(MIN)) )
341 
342 #define OUTSIDE(MIN,X,MAX) (Unsigned((Int)(X)-(Int)(MIN)) >  \
343  			    Unsigned((Int)(MAX)-(Int)(MIN)) )
344 #else
345 #define IN_BETWEEN(MIN,X,MAX) ((void *)(X) >= (void *)(MIN) && (void *)(X) <= (void *)(MAX))
346 
347 #define OUTSIDE(MIN,X,MAX) ((void *)(X) < (void *)(MIN) || (void *)(X) > (void *)(MAX))
348 #endif
349 
350 /* ************************* Atoms  *************************************/
351 
352 #include "Atoms.h"
353 
354 /* ************************* Coroutining  **********************************/
355 
356 #ifdef COROUTINING
357 /* Support for co-routining */
358 #include "corout.h"
359 #endif
360 
361 /*********  abstract machine registers **********************************/
362 
363 
364 #include "amidefs.h"
365 
366 #include "Regs.h"
367 
368 #if defined(YAPOR) ||defined(THREADS)
369 #ifdef mips
370 #include <locks_mips_funcs.h>
371 #endif
372 #ifdef __alpha
373 #include <locks_alpha_funcs.h>
374 #endif
375 #endif
376 
377 /************ variables	concerned with Error Handling *************/
378 
379 #include <setjmp.h>
380 
381 #if defined(SIMICS) || !HAVE_SIGSETJMP
382 #define sigjmp_buf jmp_buf
383 #define sigsetjmp(Env, Arg) setjmp(Env)
384 #define siglongjmp(Env, Arg) longjmp(Env, Arg)
385 #endif
386 
387 extern sigjmp_buf    RestartEnv;   /* used to restart after an abort */
388 
389 /* Support for arrays */
390 #include "arrays.h"
391 
392 /************ variables	concerned with Error Handling	*************/
393 
394 /* Types of Errors */
395 typedef enum {
396   YAP_NO_ERROR,
397   FATAL_ERROR,
398   INTERNAL_ERROR,
399   PURE_ABORT,
400   /* ISO_ERRORS */
401   DOMAIN_ERROR_ARRAY_OVERFLOW,
402   DOMAIN_ERROR_ARRAY_TYPE,
403   DOMAIN_ERROR_IO_MODE,
404   DOMAIN_ERROR_MUTABLE,
405   DOMAIN_ERROR_NON_EMPTY_LIST,
406   DOMAIN_ERROR_NOT_LESS_THAN_ZERO,
407   DOMAIN_ERROR_NOT_NL,
408   DOMAIN_ERROR_NOT_ZERO,
409   DOMAIN_ERROR_OUT_OF_RANGE,
410   DOMAIN_ERROR_OPERATOR_PRIORITY,
411   DOMAIN_ERROR_OPERATOR_SPECIFIER,
412   DOMAIN_ERROR_RADIX,
413   DOMAIN_ERROR_SHIFT_COUNT_OVERFLOW,
414   DOMAIN_ERROR_SOURCE_SINK,
415   DOMAIN_ERROR_STREAM,
416   DOMAIN_ERROR_STREAM_OR_ALIAS,
417   DOMAIN_ERROR_STREAM_POSITION,
418   DOMAIN_ERROR_TIMEOUT_SPEC,
419   DOMAIN_ERROR_SYNTAX_ERROR_HANDLER,
420   EVALUATION_ERROR_FLOAT_OVERFLOW,
421   EVALUATION_ERROR_FLOAT_UNDERFLOW,
422   EVALUATION_ERROR_INT_OVERFLOW,
423   EVALUATION_ERROR_UNDEFINED,
424   EVALUATION_ERROR_UNDERFLOW,
425   EVALUATION_ERROR_ZERO_DIVISOR,
426   EXISTENCE_ERROR_ARRAY,
427   EXISTENCE_ERROR_SOURCE_SINK,
428   EXISTENCE_ERROR_STREAM,
429   INSTANTIATION_ERROR,
430   PERMISSION_ERROR_ACCESS_PRIVATE_PROCEDURE,
431   PERMISSION_ERROR_NEW_ALIAS_FOR_STREAM,
432   PERMISSION_ERROR_CREATE_ARRAY,
433   PERMISSION_ERROR_CREATE_OPERATOR,
434   PERMISSION_ERROR_INPUT_BINARY_STREAM,
435   PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,
436   PERMISSION_ERROR_INPUT_STREAM,
437   PERMISSION_ERROR_INPUT_TEXT_STREAM,
438   PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE,
439   PERMISSION_ERROR_OPEN_SOURCE_SINK,
440   PERMISSION_ERROR_OUTPUT_BINARY_STREAM,
441   PERMISSION_ERROR_OUTPUT_STREAM,
442   PERMISSION_ERROR_OUTPUT_TEXT_STREAM,
443   PERMISSION_ERROR_RESIZE_ARRAY,
444   PERMISSION_ERROR_REPOSITION_STREAM,
445   REPRESENTATION_ERROR_CHARACTER,
446   REPRESENTATION_ERROR_CHARACTER_CODE,
447   REPRESENTATION_ERROR_MAX_ARITY,
448   SYNTAX_ERROR,
449   SYSTEM_ERROR,
450   TYPE_ERROR_ARRAY,
451   TYPE_ERROR_ATOM,
452   TYPE_ERROR_ATOMIC,
453   TYPE_ERROR_BYTE,
454   TYPE_ERROR_CALLABLE,
455   TYPE_ERROR_CHARACTER,
456   TYPE_ERROR_COMPOUND,
457   TYPE_ERROR_DBREF,
458   TYPE_ERROR_DBTERM,
459   TYPE_ERROR_EVALUABLE,
460   TYPE_ERROR_FLOAT,
461   TYPE_ERROR_INTEGER,
462   TYPE_ERROR_KEY,
463   TYPE_ERROR_LIST,
464   TYPE_ERROR_NUMBER,
465   TYPE_ERROR_PREDICATE_INDICATOR,
466   TYPE_ERROR_PTR,
467   TYPE_ERROR_UBYTE,
468   TYPE_ERROR_VARIABLE,
469   UNKNOWN_ERROR
470 } yap_error_number;
471 
472 extern char    *ErrorMessage;	/* used to pass error messages		*/
473 extern Term     Error_Term;	/* used to pass error terms */
474 extern yap_error_number  Error_TYPE;	/* used to pass the error */
475 
476 typedef enum {
477   YAP_INT_BOUNDED_FLAG = 0,
478   MAX_ARITY_FLAG = 1,
479   INTEGER_ROUNDING_FLAG = 2,
480   YAP_MAX_INTEGER_FLAG = 3,
481   YAP_MIN_INTEGER_FLAG = 4,
482   CHAR_CONVERSION_FLAG = 5,
483   YAP_DOUBLE_QUOTES_FLAG = 6,
484   YAP_TO_CHARS_FLAG = 7,
485   LANGUAGE_MODE_FLAG = 8,
486   STRICT_ISO_FLAG = 9,
487   SPY_CREEP_FLAG = 10,
488   SOURCE_MODE_FLAG = 11,
489   CHARACTER_ESCAPE_FLAG = 12,
490   WRITE_QUOTED_STRING_FLAG = 13,
491   ALLOW_ASSERTING_STATIC_FLAG = 14,
492   HALT_AFTER_CONSULT_FLAG = 15,
493   FAST_BOOT_FLAG = 16
494 } yap_flags;
495 
496 #define STRING_AS_CHARS		0
497 #define STRING_AS_ATOM		2
498 
499 #define QUINTUS_TO_CHARS	0
500 #define ISO_TO_CHARS		1
501 
502 #define CPROLOG_CHARACTER_ESCAPES		0
503 #define ISO_CHARACTER_ESCAPES			1
504 #define SICSTUS_CHARACTER_ESCAPES		2
505 
506 #define NUMBER_OF_YAP_FLAGS     FAST_BOOT_FLAG+1
507 
508 /************************  prototypes **********************************/
509 
510 #include "Yapproto.h"
511 
512 /************************  OPTYap configuration ************************/
513 
514 /* These must be included before unification handlers */
515 #if defined(YAPOR) || defined(TABLING)
516 #include "opt.config.h"
517 #endif
518 
519 /***********************************************************************/
520 
521      /*
522 absrectype Term	= Int + Float +	Atom + Pair + Appl + Ref + Var
523 
524 with AbsAppl(t)	: *CELL	-> Term
525 and  RepAppl(t)	: Term -> *CELL
526 
527 and  AbsPair(t)	: *CELL	-> Term
528 and  RepPair(t)	: Term -> *CELL
529 
530 and  IsIntTerm(t) = ...
531 and  IsAtomTerm(t) = ...
532 and  IsVarTerm(t) = ...
533 and  IsPairTerm(t) = ...
534 and  IsApplTerm(t) = ...
535 and  IsFloatTerm(t) = ...
536 and  IsRefTerm(t) = ...
537 and  IsNonVarTerm(t) = ! IsVar(t)
538 and  IsNumterm(t) = IsIntTerm(t) || IsFloatTerm(t)
539 and  IsAtomicTerm(t) = IsNumTerm(t) || IsAtomTerm(t)
540 and  IsPrimitiveTerm(t) = IsAtomicTerm(t) || IsRefTerm(t)
541 
542 and  MkIntTerm(n) = ...
543 and  MkFloatTerm(f) = ...
544 and  MkAtomTerm(a) = ...
545 and  MkVarTerm(r) = ...
546 and  MkApplTerm(f,n,args) = ...
547 and  MkPairTerm(hd,tl) = ...
548 and  MkRefTerm(R) = ...
549 
550 and  PtrOfTerm(t) : Term -> CELL * = ...
551 and  IntOfTerm(t) : Term -> int	= ...
552 and  FloatOfTerm(t) : Term -> flt = ...
553 and  AtomOfTerm(t) : Term -> Atom = ...
554 and  VarOfTerm(t) : Term -> *Term = ....
555 and  HeadOfTerm(t) : Term -> Term = ...
556 and  TailOfTerm(t) : Term -> Term = ...
557 and  FunctorOfTerm(t) :	Term ->	Functor	= ...
558 and  ArgOfTerm(i,t)  : Term -> Term= ...
559 and  RefOfTerm(t) : Term -> DBRef = ...
560 
561 */
562 
563 /*
564    YAP can use several different tag schemes, according to the kind of
565    machine we are experimenting with.
566 */
567 
568 #if LONG_ADDRESSES && defined(OLD_TAG_SCHEME)
569 
570 #include "Tags_32bits.h"
571 
572 #endif /* LONG_ADDRESSES && defined(OLD_TAG_SCHEME) */
573 
574 /* AIX will by default place mmaped segments at 0x30000000. This is
575 	incompatible with the high tag scheme. Linux-ELF also does not like
576 	if you place things in the lower addresses (power to the libc people).
577 */
578 #if (defined(_AIX) || defined(_WIN32) || defined(sparc) || defined(__sparc) || defined(mips) || defined(__FreeBSD__) || defined(_POWER) || defined(__linux__) || defined(IN_SECOND_QUADRANT)) && !defined(TABLING)
579 #define USE_LOW32_TAGS 1
580 #endif
581 
582 #if LONG_ADDRESSES && SIZEOF_INT_P==4 && !defined(OLD_TAG_SCHEME) && !defined(USE_LOW32_TAGS)
583 
584 #include "Tags_32Ops.h"
585 
586 #endif /* LONG_ADDRESSES && !defined(OLD_TAG_SCHEME) && !defined(USE_LOW32_TAGS) */
587 
588 #if LONG_ADDRESSES && SIZEOF_INT_P==4 && !defined(OLD_TAG_SCHEME) && defined(USE_LOW32_TAGS)
589 
590 #include "Tags_32LowTag.h"
591 
592 #endif /* LONG_ADDRESSES && !defined(OLD_TAG_SCHEME) */
593 
594 #if LONG_ADDRESSES && SIZEOF_INT_P==8 && !defined(OLD_TAG_SCHEME)
595 
596 #include "Tags_64bits.h"
597 
598 #endif /* LONG_ADDRESSES && SIZEOF_INT_P==8 && !defined(OLD_TAG_SCHEME) */
599 
600 #if !LONG_ADDRESSES
601 
602 #include "Tags_24bits.h"
603 
604 #endif /* !LONG_ADDRESSES */
605 
606 #ifdef TAG_LOW_BITS_32
607 #define MBIT     0x80000000
608 #define RBIT     0x40000000
609 
610 #if IN_SECOND_QUADRANT
611 #define INVERT_RBIT 1 /* RBIT is 1 by default */
612 #endif
613 
614 #else
615 
616 #if defined(SBA) && defined(__linux__)
617 #define MBIT     /* 0x20000000 */ MKTAG(0x1,0)	/* mark bit */
618 #else
619 #define RBIT     /* 0x20000000 */ MKTAG(0x1,0)  /* relocation chain bit */
620 #define MBIT     /* 0x40000000 */ MKTAG(0x2,0)	/* mark bit */
621 #endif
622 #endif
623 
624 #define	TermSize    sizeof(Term)
625 
626 /************* variables related to memory allocation *******************/
627 /* must be before TermExt.h */
628 extern ADDR     HeapBase,
629 		     LocalBase,
630 		     GlobalBase,
631 		     TrailBase, TrailTop,
632 		     ForeignCodeBase, ForeignCodeTop, ForeignCodeMax;
633 
634 
635 /* applies to unbound variables */
636 
637 inline EXTERN Term * VarOfTerm(Term t);
638 
VarOfTerm(Term t)639 inline EXTERN Term * VarOfTerm(Term t)
640 {
641 	return (Term *) (t);
642 }
643 
644 
645 #if SBA
646 
647 inline EXTERN Term MkVarTerm(void);
648 
MkVarTerm()649 inline EXTERN Term MkVarTerm()
650 {
651 	return (Term) ((*H = 0, H++));
652 }
653 
654 
655 
656 inline EXTERN int IsUnboundVar(Term);
657 
IsUnboundVar(Term t)658 inline EXTERN int IsUnboundVar(Term t)
659 {
660 	return (int) (t == 0);
661 }
662 
663 
664 #else
665 
666 inline EXTERN Term MkVarTerm(void);
667 
MkVarTerm()668 inline EXTERN Term MkVarTerm()
669 {
670 	return (Term) ((*H = (CELL) H, H++));
671 }
672 
673 
674 
675 inline EXTERN int IsUnboundVar(Term);
676 
IsUnboundVar(Term t)677 inline EXTERN int IsUnboundVar(Term t)
678 {
679 	return (int) (*VarOfTerm(t) == (t));
680 }
681 
682 
683 #endif
684 
685 inline EXTERN CELL * PtrOfTerm(Term);
686 
PtrOfTerm(Term t)687 inline EXTERN CELL * PtrOfTerm(Term t)
688 {
689 	return (CELL *) (*(CELL *)(t));
690 }
691 
692 
693 
694 
695 inline EXTERN Functor FunctorOfTerm(Term);
696 
FunctorOfTerm(Term t)697 inline EXTERN Functor FunctorOfTerm(Term t)
698 {
699 	return (Functor) (*RepAppl(t));
700 }
701 
702 
703 
704 inline EXTERN Term MkAtomTerm(Atom);
705 
MkAtomTerm(Atom a)706 inline EXTERN Term MkAtomTerm(Atom a)
707 {
708 	return (Term) (TAGGEDA(AtomTag, (CELL)(a)-HEAP_INIT_BASE));
709 }
710 
711 
712 
713 inline EXTERN Atom AtomOfTerm(Term t);
714 
AtomOfTerm(Term t)715 inline EXTERN Atom AtomOfTerm(Term t)
716 {
717 	return (Atom) (HEAP_INIT_BASE+NonTagPart(t));
718 }
719 
720 
721 
722 inline EXTERN int IsAtomTerm(Term);
723 
IsAtomTerm(Term t)724 inline EXTERN int IsAtomTerm(Term t)
725 {
726 	return (int) (CHKTAG((t), AtomTag));
727 }
728 
729 
730 
731 
732 inline EXTERN Term MkIntTerm(Int);
733 
MkIntTerm(Int n)734 inline EXTERN Term MkIntTerm(Int n)
735 {
736 	return (Term) (TAGGED(NumberTag, (n)));
737 }
738 
739 
740 /*
741   A constant to subtract or add to a well-known term, we assume no
742   overflow problems are possible
743 */
744 
745 inline EXTERN Term MkIntConstant(Int);
746 
MkIntConstant(Int n)747 inline EXTERN Term MkIntConstant(Int n)
748 {
749 	return (Term) (NONTAGGED(NumberTag, (n)));
750 }
751 
752 
753 
754 inline EXTERN int IsIntTerm(Term);
755 
IsIntTerm(Term t)756 inline EXTERN int IsIntTerm(Term t)
757 {
758 	return (int) (CHKTAG((t), NumberTag));
759 }
760 
761 
762 
763 /* Needed to handle numbers:
764    	these two macros are fundamental in the integer/float conversions */
765 
766 #ifdef M_WILLIAMS
767 #define IntInBnd(X)	(TRUE)
768 #else
769 #ifdef TAGS_FAST_OPS
770 #define IntInBnd(X)	(Unsigned( ( (Int)(X) >> (32-7) ) + 1) <= 1)
771 #else
772 #define IntInBnd(X)	( (X) < MAX_ABS_INT && \
773                           (X) > -MAX_ABS_INT-1L )
774 #endif
775 #endif
776 #ifdef C_PROLOG
777 #define FlIsInt(X)	( (X) == (Int)(X) && IntInBnd((X)) )
778 #else
779 #define FlIsInt(X)	( FALSE )
780 #endif
781 
782 
783 /*
784   There are two types of functors:
785 
786   o Special functors mark special terms
787   on the heap that should be seen as constants.
788 
789   o Standard functors mark normal applications.
790 
791 */
792 
793 #include "TermExt.h"
794 
795 #define IsAccessFunc(func)		((func) == FunctorAccess)
796 
797 
798 inline EXTERN Term MkIntegerTerm(Int);
799 
MkIntegerTerm(Int n)800 inline EXTERN Term MkIntegerTerm(Int n)
801 {
802 	return (Term) (IntInBnd(n) ? MkIntTerm(n) : MkLongIntTerm(n));
803 }
804 
805 
806 
807 inline EXTERN int IsIntegerTerm(Term);
808 
IsIntegerTerm(Term t)809 inline EXTERN int IsIntegerTerm(Term t)
810 {
811 	return (int) (IsIntTerm(t) || IsLongIntTerm(t));
812 }
813 
814 
815 
816 inline EXTERN Int IntegerOfTerm(Term);
817 
IntegerOfTerm(Term t)818 inline EXTERN Int IntegerOfTerm(Term t)
819 {
820 	return (Int) (IsIntTerm(t) ? IntOfTerm(t) : LongIntOfTerm(t));
821 }
822 
823 
824 
825 
826 /*************** unification routines ***********************************/
827 
828 #if SBA
829 #include "or.sbaamiops.h"
830 #else
831 #include "amiops.h"
832 #endif
833 
834 /*************** High level macros to access arguments ******************/
835 
836 
837 inline EXTERN Term ArgOfTerm(int i, Term t);
838 
ArgOfTerm(int i,Term t)839 inline EXTERN Term ArgOfTerm(int i, Term t)
840 {
841 	return (Term) (Derefa(RepAppl(t) + (i)));
842 }
843 
844 
845 
846 inline EXTERN Term HeadOfTerm(Term);
847 
HeadOfTerm(Term t)848 inline EXTERN Term HeadOfTerm(Term t)
849 {
850 	return (Term) (Derefa(RepPair(t)));
851 }
852 
853 
854 
855 inline EXTERN Term TailOfTerm(Term);
856 
TailOfTerm(Term t)857 inline EXTERN Term TailOfTerm(Term t)
858 {
859 	return (Term) (Derefa(RepPair(t) + 1));
860 }
861 
862 
863 
864 
865 inline EXTERN Term ArgOfTermCell(int i, Term t);
866 
ArgOfTermCell(int i,Term t)867 inline EXTERN Term ArgOfTermCell(int i, Term t)
868 {
869 	return (Term) ((CELL)(RepAppl(t) + (i)));
870 }
871 
872 
873 
874 inline EXTERN Term HeadOfTermCell(Term);
875 
HeadOfTermCell(Term t)876 inline EXTERN Term HeadOfTermCell(Term t)
877 {
878 	return (Term) ((CELL)(RepPair(t)));
879 }
880 
881 
882 
883 inline EXTERN Term TailOfTermCell(Term);
884 
TailOfTermCell(Term t)885 inline EXTERN Term TailOfTermCell(Term t)
886 {
887 	return (Term) ((CELL)(RepPair(t) + 1));
888 }
889 
890 
891 
892 /*************** variables concerned with atoms	table *******************/
893 #define	MaxHash	    1001
894 
895 /************ variables	concerned with save and restore	*************/
896 extern int      splfild;
897 
898 #define FAIL_RESTORE  0
899 #define DO_EVERYTHING 1
900 #define DO_ONLY_CODE  2
901 
902 
903 #ifdef EMACS
904 
905 /******************** using Emacs mode ********************************/
906 
907 extern int      emacs_mode;
908 
909 #endif
910 
911 
912 /************ variable concerned with version number *****************/
913 extern char    version_number[];
914 
915 /********* common instructions codes*************************/
916 
917 #define MAX_PROMPT  256
918 
919 #if USE_THREADED_CODE
920 
921 /************ reverse lookup of instructions *****************/
922 typedef struct opcode_tab_entry {
923   OPCODE opc;
924   op_numbers opnum;
925 } opentry;
926 
927 #endif
928 
929 /******************* controlling the compiler ****************************/
930 extern int      optimizer_on;
931 
932 /******************* the line for the current parse **********************/
933 extern int      StartLine;
934 extern int      StartCh;
935 extern int      CurFileNo;
936 
937 /********************* how to write a Prolog term ***********************/
938 
939 /********* Prolog may be in several modes *******************************/
940 
941 typedef enum {
942   BootMode  =   1,		/* if booting or restoring */
943   UserMode  =   2,		/* Normal mode */
944   CritMode  =   4,		/* If we are meddling with the heap */
945   AbortMode =   8,		/* expecting to abort */
946   InterruptMode = 16,		/* under an interrupt */
947   InErrorMode = 32,		/* under an interrupt */
948   ConsoleGetcMode = 64		/* blocked reading from console */
949 } prolog_exec_mode;
950 
951 extern prolog_exec_mode      PrologMode;
952 extern int      CritLocks;
953 
954 /************** Access to yap initial arguments ***************************/
955 
956 extern char   **yap_args;
957 extern int      yap_argc;
958 
959 /******************* controlling debugging ****************************/
960 extern int      creep_on;
961 
962 #ifdef YAPOR
963 #define YAPEnterCriticalSection()                           \
964 	{                                                   \
965           if (worker_id != GLOBAL_LOCKS_who_locked_heap) {  \
966 	    LOCK(GLOBAL_LOCKS_heap_access);                 \
967 	    GLOBAL_LOCKS_who_locked_heap = worker_id;       \
968 	  }                                                 \
969           PrologMode |= CritMode;                           \
970           CritLocks++;                                      \
971         }
972 #define YAPLeaveCriticalSection()                                        \
973 	{                                                                \
974           CritLocks--;                                                   \
975           if (!CritLocks) {                                              \
976             PrologMode &= ~CritMode;                                     \
977             if (PrologMode & InterruptMode) {                            \
978 	      PrologMode &= ~InterruptMode;                              \
979 	      ProcessSIGINT();                                           \
980             }                                                            \
981             if (PrologMode & AbortMode) {                                \
982 	      PrologMode &= ~AbortMode;                                  \
983 	      Error(PURE_ABORT, 0, "");                            \
984             }                                                            \
985 	    GLOBAL_LOCKS_who_locked_heap = MAX_WORKERS;                  \
986             UNLOCK(GLOBAL_LOCKS_heap_access);                            \
987           }                                                              \
988         }
989 #else
990 #define YAPEnterCriticalSection()                           \
991 	{                                                   \
992           PrologMode |= CritMode;                           \
993           CritLocks++;                                      \
994         }
995 #define YAPLeaveCriticalSection()                                        \
996 	{                                                                \
997           CritLocks--;                                                   \
998           if (!CritLocks) {                                              \
999             PrologMode &= ~CritMode;                                     \
1000             if (PrologMode & InterruptMode) {                            \
1001 	      PrologMode &= ~InterruptMode;                              \
1002 	      ProcessSIGINT();                                           \
1003             }                                                            \
1004             if (PrologMode & AbortMode) {                                \
1005 	      PrologMode &= ~AbortMode;                                  \
1006 	      Error(PURE_ABORT, 0, "");                            \
1007             }                                                            \
1008           }                                                              \
1009         }
1010 #endif /* YAPOR */
1011 
1012 /* when we are calling the InitStaff procedures */
1013 #define AT_BOOT      0
1014 #define AT_RESTORE   1
1015 
1016 /********* whether we should try to compile array references ******************/
1017 
1018 extern int  compile_arrays;
1019 
1020 /********* mutable variables ******************/
1021 
1022 /* I assume that the size of this structure is a multiple of the size
1023    of CELL!!! */
1024 typedef struct TIMED_MAVAR{
1025   CELL value;
1026   CELL clock;
1027 } timed_var;
1028 
1029 /********* while debugging you may need some info ***********************/
1030 
1031 #if DEBUG
1032 extern int      output_msg;
1033 #endif
1034 
1035 #if EMACS
1036 extern char     emacs_tmp[], emacs_tmp2[];
1037 #endif
1038 
1039 #if HAVE_SIGNAL
1040 extern int      snoozing;
1041 #endif
1042 
1043 #if defined(YAPOR) || defined(TABLING)
1044 #include "opt.structs.h"
1045 #include "opt.macros.h"
1046 #include "opt.proto.h"
1047 #endif /* YAPOR || TABLING */
1048 
1049 #if SBA
1050 #include "or.sbaunify.h"
1051 #endif
1052 
1053