36#define USE_MYDDAS_SQLITE3 1
42#if (defined(YAPOR_COPY) && \
43 (defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_THREADS))) || \
44 (defined(YAPOR_COW) && (defined(YAPOR_SBA) || defined(YAPOR_THREADS))) || \
45 (defined(YAPOR_SBA) && defined(YAPOR_THREADS))
46#error Do not define multiple or-parallel models
51#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \
52 defined(YAPOR_THREADS)
57#if defined(TABLING) && \
58 (defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_THREADS))
59#error TABLING only works with YAPOR_COPY
62#if defined(THREADS) && \
63 (defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_COPY))
64#error THREADS only works with YAPOR_THREADS
73#define RATIONAL_TREES 1
82#include "inline-only.h"
83#if defined(YAPOR) || defined(TABLING)
84#include "opt.config.h"
99#define MULTI_ASSIGNMENT_VARIABLES 1
101#if defined(YAPOR) || defined(THREADS)
102#define MULTIPLE_STACKS 1
103#define PARALLEL_YAP 1
106#if defined(YAPOR) || defined(TABLING)
107#undef TRAILING_REQUIRES_BRANCH
110#if defined(TABLING) || defined(YAPOR_SBA)
111#define FROZEN_STACKS 1
114#if defined(THREADS) || defined(SUPPORT_CONDOR)
115#define USE_SYSTEM_MALLOC 1
118#if defined(ANALYST) && defined(USE_THREADED_CODE)
119#undef USE_THREADED_CODE
122#if defined(COROUTINING) && !defined(TERM_EXTENSIONS)
123#define TERM_EXTENSIONS 1
133#if !defined(nullptr) && !defined(HAVE_NULLPTR)
136#elif defined(__GNUC__)
137#define nullptr __null
152#if HAVE_GCC && !defined(__cplusplus)
154#define DUMMY_FILLER_FOR_ABS_TYPE
157#define DUMMY_FILLER_FOR_ABS_TYPE int dummy;
161typedef void *(*fptr_t)(void);
167extern const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR,
168 *Yap_PLDIR, *Yap_COMMONSDIR, *Yap_STARTUP,*Yap_INPUT_STARTUP,*Yap_OUTPUT_STARTUP,
169 *Yap_BOOTFILE, *Yap_INCLUDEDIR;
181#ifdef HAVE___BUILTIN_EXPECT
182#define likely(x) __builtin_expect((x), 1)
183#define unlikely(x) __builtin_expect((x), 0)
186#define unlikely(x) (x)
190#if USE_PTHREAD_LOCKING
192#define _XOPEN_SOURCE 600
202#if HAVE_SIGPROF && (defined(__linux__) || defined(__APPLE__))
206#if !defined(HAVE_STRNLEN)
207INLINE_ONLY EXTERN
size_t strnlen(
const char *s,
size_t maxlen);
209INLINE_ONLY EXTERN
size_t strnlen(
const char *s,
size_t maxlen) {
222#if defined(FORCE_SECOND_QUADRANT)
223#define IN_SECOND_QUADRANT 1
224#define MMAP_ADDR 0x42000000
227#if !defined(IN_SECOND_QUADRANT)
228#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
229 defined(mips) || defined(__mips64) || defined(__aarch64__) || \
231#if defined(YAPOR) && defined(__alpha)
233#define MMAP_ADDR 0x40000000
235#define MMAP_ADDR 0x02000000
236#elif defined(__mips64)
237#define MMAP_ADDR 0x02000000
238#elif defined(__aarch64__)
239#define MMAP_ADDR 0x02000000
240#elif defined(__powerpc__)
241#define MMAP_ADDR 0x20000000
243#define MMAP_ADDR 0x10000000
245#elif __svr4__ || defined(__SVR4)
246#define MMAP_ADDR 0x02000000
254extern size_t Yap_page_size;
256#ifdef USE_SYSTEM_MALLOC
257#define HEAP_INIT_BASE 0L
260#if defined(MMAP_ADDR) && (defined(USE_MMAP) || USE_SHMAT) && \
261 !defined(__simplescalar__) && !defined(RANDOMIZE_START_ADDRESS)
262#define HEAP_INIT_BASE (MMAP_ADDR)
263#define AtomBase ((char *)MMAP_ADDR)
266#define HEAP_INIT_BASE ((CELL)Yap_HeapBase)
267#define AtomBase (Yap_HeapBase)
276#define K1 ((CELL)1024)
277#define K16 ((CELL)(1024 * 64))
278#define K64 ((CELL)(1024 * 64))
279#define M1 ((CELL)(1024 * 1024))
280#define M2 ((CELL)(2048 * 1024))
285typedef BITS16 SFLAGS;
290typedef unsigned char *CODEADDR;
292#define TermPtr(V) ((Term *)(V))
293#define Addr(V) ((ADDR)(V))
295#define CodePtr(V) ((CODEADDR)(V))
296#define CellPtr(V) ((CELL *)(V))
297#define OpCodePtr(V) ((OPCODE *)(V))
298#define OpRegPtr(V) ((OPREG *)(V))
299#define SmallPtr(V) ((SMALLUNSGN *)(V))
300#define WordPtr(V) ((BITS16 *)(V))
301#define DisplPtr(V) ((DISPREG *)(V))
303#if !defined(YAPOR) && !defined(THREADS)
308#define _XOPEN_SOURCE 600
311#include <locks_pthread.h>
312typedef pthread_mutex_t lockvar;
332#define FUNC_READ_LOCK(X) READ_LOCK((X)->FRWLock)
333#define FUNC_READ_UNLOCK(X) READ_UNLOCK((X)->FRWLock)
334#define FUNC_WRITE_LOCK(X) WRITE_LOCK((X)->FRWLock)
335#define FUNC_WRITE_UNLOCK(X) WRITE_UNLOCK((X)->FRWLock)
342#define IN_BETWEEN(MIN, X, MAX) \
343 (Unsigned((Int)(X) - (Int)(MIN)) <= Unsigned((Int)(MAX) - (Int)(MIN)))
345#define OUTSIDE(MIN, X, MAX) \
346 (Unsigned((Int)(X) - (Int)(MIN)) > Unsigned((Int)(MAX) - (Int)(MIN)))
348#define IN_BETWEEN(MIN, X, MAX) \
349 ((void *)(X) >= (void *)(MIN) && (void *)(X) <= (void *)(MAX))
351#define OUTSIDE(MIN, X, MAX) \
352 ((void *)(X) < (void *)(MIN) || (void *)(X) > (void *)(MAX))
361#include "YapCompoundTerm.h"
363#define TermSize sizeof(Term)
397#include "or.sba_amiops.h"
398#include "or.sba_unify.h"
407#if defined(YAPOR) || defined(TABLING)
408#include "opt.structs.h"
410#include "opt.proto.h"
412#include "opt.macros.h"
423#define sigjmp_buf jmp_buf
424#define sigsetjmp(Env, Arg) setjmp(Env)
425#define siglongjmp(Env, Arg) longjmp(Env, Arg)
436#define MAX_EMPTY_WAKEUPS 16
443extern ADDR Yap_HeapBase;
454extern int Yap_output_msg;
459#include <android/asset_manager.h>
460#include <android/asset_manager_jni.h>
461#include <android/log.h>
464extern AAssetManager *Yap_assetManager(
void);
466extern void *Yap_openAssetFile(
const char *path);
467extern bool Yap_isAsset(
const char *path);
468extern bool Yap_AccessAsset(
const char *name,
int mode);
469extern bool Yap_AssetIsFile(
const char *name);
470extern bool Yap_AssetIsDir(
const char *name);
471extern int64_t Yap_AssetSize(
const char *name);
475#define __android_log_print(...)
484#define MaxWideHash (MaxHash / 10 + 1)
486typedef enum e_restore_t {
490 YAP_BOOT_FROM_PROLOG = 4
497#define MAX_PROMPT 256
503#define DefaultMaxModules 256
509#define YAPEnterCriticalSection() \
511 if (worker_id != GLOBAL_locks_who_locked_heap) { \
512 LOCK(GLOBAL_locks_heap_access); \
513 GLOBAL_locks_who_locked_heap = worker_id; \
515 LOCAL_PrologMode |= CritMode; \
518#define YAPLeaveCriticalSection() \
521 if (!LOCAL_CritLocks) { \
522 LOCAL_PrologMode &= ~CritMode; \
523 if (LOCAL_PrologMode & AbortMode) { \
524 LOCAL_PrologMode &= ~AbortMode; \
525 Yap_Error(ABORT_EVENT, 0, ""); \
527 GLOBAL_locks_who_locked_heap = MAX_WORKERS; \
528 UNLOCK(GLOBAL_locks_heap_access); \
531#elif defined(THREADS)
532#define YAPEnterCriticalSection() \
535 LOCAL_PrologMode |= CritMode; \
537#define YAPLeaveCriticalSection() \
539 LOCAL_PrologMode &= ~CritMode; \
540 if (LOCAL_PrologMode & AbortMode) { \
541 LOCAL_PrologMode &= ~AbortMode; \
542 Yap_Error(ABORT_EVENT, 0, ""); \
548#define YAPEnterCriticalSection() \
550 LOCAL_PrologMode |= \
555#define YAPLeaveCriticalSection() \
559 if (!LOCAL_CritLocks) { \
560 LOCAL_PrologMode &= ~CritMode; \
561 if (LOCAL_PrologMode & AbortMode) { \
562 LOCAL_PrologMode &= ~AbortMode; \
590 MIXED_MODE_USER = 0x2,
591 MIXED_MODE_ALL = 0x4,
596#define MIXED_MODE (MIXED_MODE_USER | MIXED_MODE_ALL)
598#define COMPILED (COMPILE_USER | COMPILE_ALL)
618void Yap_destroy_tqueue(
db_queue *dbq USES_REGS);
619bool Yap_enqueue_tqueue(
db_queue *father_key, Term t USES_REGS);
620bool Yap_dequeue_tqueue(
db_queue *father_key, Term t,
bool first,
621 bool release USES_REGS);
625typedef struct thread_mbox {
627 pthread_mutex_t mutex;
632 struct thread_mbox *next;
635typedef struct thandle {
643 Term cmod, texit_mod;
650 pthread_t pthread_handle;
653#ifdef LOW_LEVEL_TRACER
654 long long int thread_inst_count;
661 pthread_mutex_t tlock;
662 pthread_mutex_t tlock_status;
664 hrtime_t start_of_w_times;
665 hrtime_t last_w_time;
668 struct timeval *start_of_timesp;
669 struct timeval *last_timep;
670 struct timeval *start_of_times_sysp;
671 struct timeval *last_time_sysp;
673 win64_time_t *start_of_timesp;
674 win64_time_t *last_timep;
675 win64_time_t *start_of_times_sysp;
676 win64_time_t *last_time_sysp;
681#define GC_MAVARS_HASH_SIZE 512
692typedef int (*Agc_hook)(
Atom);
700#include "ScannerTypes.h"
706#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
708extern long Yap_worker_area_size;
711#define Yap_global (&Yap_Global)
716#define REMOTE(wid) (Yap_local[wid])
719#define REMOTE(wid) (Yap_local + wid)
722#define REMOTE(wid) (&Yap_local)
734#include "YapHandles.h"
738#include "YapSignals.h"
740#define must_be_variable(t) if (!IsVarTerm(t)) Yap_ThrowError(UNINSTANTIATION_ERROR, v, NULL)
742INLINE_ONLY Term must_be_module(Term t) {
744 if (IsVarTerm(t)) Yap_ThrowError(INSTANTIATION_ERROR, t, NULL);
745 if (!IsAtomTerm(t)) Yap_ThrowError(TYPE_ERROR_ATOM, t, NULL);
749INLINE_ONLY Term must_be_integer(Term t) {
751 if (IsVarTerm(t)) Yap_ThrowError(INSTANTIATION_ERROR, t, NULL);
752 if (!IsIntegerTerm(t)) Yap_ThrowError(TYPE_ERROR_INTEGER, t, NULL);
756 INLINE_ONLY Term must_be_unbound(Term t) {
758 if (!IsVarTerm(t)) Yap_ThrowError(UNINSTANTIATION_ERROR, t, NULL);
775inline static void LOG0(
const char *f,
int l,
const char *fmt, ...) {
779 __android_log_print(ANDROID_LOG_INFO,
"YAP ", fmt, ap);
782 fd = fopen(
"c:\\cygwin\\Log.txt",
"a");
783 vfprintf(fd, fmt, ap);
786 vfprintf(stderr, fmt, ap);
790#define LOG(...) LOG0(__FILE__, __LINE__, __VA_ARGS__)
792#define REGS_LOG(...) CACHE_REGS LOG0(__FILE__, __LINE__, __VA_ARGS__)
804extern bool Yap_Embedded, Yap_Server;