2005-05-27 23:27:59 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog %W% %G% *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
2011-11-02 22:53:49 +00:00
|
|
|
* File: Yap.h *
|
2005-05-27 23:27:59 +01:00
|
|
|
* mods: *
|
|
|
|
* comments: main header file for YAP *
|
2008-06-18 11:02:27 +01:00
|
|
|
* version: $Id: Yap.h,v 1.38 2008-06-18 10:02:27 vsc Exp $ *
|
2005-05-27 23:27:59 +01:00
|
|
|
*************************************************************************/
|
|
|
|
|
2011-03-02 23:19:39 +00:00
|
|
|
#ifndef YAP_H
|
|
|
|
#define YAP_H 1
|
|
|
|
|
2011-04-14 19:19:13 +01:00
|
|
|
#if defined(YAPOR)
|
|
|
|
#error Do not explicitly define YAPOR
|
|
|
|
#endif /* YAPOR */
|
|
|
|
|
2011-04-14 20:00:35 +01:00
|
|
|
#if (defined(YAPOR_COPY) && (defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_THREADS))) || (defined(YAPOR_COW) && (defined(YAPOR_SBA) || defined(YAPOR_THREADS))) || (defined(YAPOR_SBA) && defined(YAPOR_THREADS))
|
2011-04-14 19:19:13 +01:00
|
|
|
#error Do not define multiple or-parallel models
|
2011-04-18 14:59:17 +01:00
|
|
|
#endif /* (YAPOR_COPY && (YAPOR_COW || YAPOR_SBA || YAPOR_THREADS)) || (YAPOR_COW && (YAPOR_SBA || YAPOR_THREADS)) || (YAPOR_SBA || YAPOR_THREADS) */
|
2011-04-14 19:19:13 +01:00
|
|
|
|
2011-04-14 20:00:35 +01:00
|
|
|
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_THREADS)
|
2011-04-14 19:19:13 +01:00
|
|
|
#define YAPOR 1
|
2011-04-18 14:59:17 +01:00
|
|
|
#define FIXED_STACKS 1
|
|
|
|
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA || YAPOR_THREADS */
|
2011-04-14 19:19:13 +01:00
|
|
|
|
2011-04-14 20:00:35 +01:00
|
|
|
#if defined(TABLING) && (defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_THREADS))
|
2011-04-18 14:59:17 +01:00
|
|
|
#error TABLING only works with YAPOR_COPY
|
2011-04-14 20:00:35 +01:00
|
|
|
#endif /* TABLING && (YAPOR_COW || YAPOR_SBA || YAPOR_THREADS) */
|
2011-04-14 19:19:13 +01:00
|
|
|
|
2011-04-18 14:59:17 +01:00
|
|
|
#if defined(THREADS) && (defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_COPY))
|
|
|
|
#error THREADS only works with YAPOR_THREADS
|
|
|
|
#endif /* THREADS && (YAPOR_COW || YAPOR_SBA || YAPOR_COPY) */
|
|
|
|
|
2005-05-27 23:27:59 +01:00
|
|
|
#include "config.h"
|
2011-04-18 14:59:17 +01:00
|
|
|
#if defined(YAPOR) || defined(TABLING)
|
2009-07-03 00:54:39 +01:00
|
|
|
#include "opt.config.h"
|
|
|
|
#endif /* YAPOR || TABLING */
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
#define RATIONAL_TREES 1
|
|
|
|
#define DEPTH_LIMIT 1
|
|
|
|
#define COROUTINING 1
|
|
|
|
#define ANALYST 1
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MULTI_ASSIGNMENT_VARIABLES 1
|
|
|
|
|
2011-04-15 10:48:24 +01:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2011-04-14 18:51:11 +01:00
|
|
|
#define MULTIPLE_STACKS 1
|
|
|
|
#define PARALLEL_YAP 1
|
2011-04-18 14:59:17 +01:00
|
|
|
#endif /* YAPOR || THREADS */
|
2011-04-14 18:51:11 +01:00
|
|
|
|
2005-05-27 23:27:59 +01:00
|
|
|
#if defined(YAPOR) || defined(TABLING)
|
|
|
|
#undef TRAILING_REQUIRES_BRANCH
|
|
|
|
#endif /* YAPOR || TABLING */
|
|
|
|
|
2011-04-18 14:59:17 +01:00
|
|
|
#if defined(TABLING) || defined(YAPOR_SBA)
|
|
|
|
#define FROZEN_STACKS 1
|
|
|
|
#endif /* TABLING || YAPOR_SBA */
|
|
|
|
|
|
|
|
#if defined(THREADS) || defined(SUPPORT_CONDOR)
|
|
|
|
#define USE_SYSTEM_MALLOC 1
|
|
|
|
#endif /* THREADS || SUPPORT_CONDOR */
|
|
|
|
|
2011-05-23 16:19:47 +01:00
|
|
|
#if defined(ANALYST) && defined(USE_THREADED_CODE)
|
2005-05-27 23:27:59 +01:00
|
|
|
#undef USE_THREADED_CODE
|
2011-05-23 16:19:47 +01:00
|
|
|
#endif /* ANALYST && USE_THREADED_CODE */
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2011-05-23 16:19:47 +01:00
|
|
|
#if defined(COROUTINING) && !defined(TERM_EXTENSIONS)
|
2005-05-27 23:27:59 +01:00
|
|
|
#define TERM_EXTENSIONS 1
|
2011-05-23 16:19:47 +01:00
|
|
|
#endif /* COROUTINING && !TERM_EXTENSIONS */
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2011-05-23 16:19:47 +01:00
|
|
|
/* Microsoft's Visual C++ Compiler */
|
|
|
|
#ifdef _MSC_VER /* adjust a config.h from mingw32 to work with vc++ */
|
2005-05-27 23:27:59 +01:00
|
|
|
#ifdef HAVE_GCC
|
2011-05-23 16:19:47 +01:00
|
|
|
#undef HAVE_GCC
|
|
|
|
#endif /* HAVE_GCC */
|
2005-05-27 23:27:59 +01:00
|
|
|
#ifdef USE_THREADED_CODE
|
|
|
|
#undef USE_THREADED_CODE
|
2011-05-23 16:19:47 +01:00
|
|
|
#endif /* USE_THREADED_CODE */
|
2005-05-27 23:27:59 +01:00
|
|
|
#define inline __inline
|
2012-02-13 19:30:00 +00:00
|
|
|
#define YAP_VERSION "YAP-6.3.2"
|
2005-08-23 19:11:55 +01:00
|
|
|
#define BIN_DIR "c:\\Yap\\bin"
|
|
|
|
#define LIB_DIR "c:\\Yap\\lib\\Yap"
|
|
|
|
#define SHARE_DIR "c:\\Yap\\share\\Yap"
|
2011-05-23 16:19:47 +01:00
|
|
|
#ifdef HOST_ALIAS
|
|
|
|
#undef HOST_ALIAS
|
|
|
|
#endif /* HOST_ALIAS */
|
2005-05-27 23:27:59 +01:00
|
|
|
#define HOST_ALIAS "i386-pc-win32"
|
2011-05-23 16:19:47 +01:00
|
|
|
#ifdef HAVE_IEEEFP_H
|
|
|
|
#undef HAVE_IEEEFP_H
|
|
|
|
#endif /* HAVE_IEEEFP_H */
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#undef HAVE_UNISTD_H
|
|
|
|
#endif /* HAVE_UNISTD_H */
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
#undef HAVE_SYS_TIME_H
|
|
|
|
#endif /* HAVE_SYS_TIME_H */
|
|
|
|
#endif /* _MSC_VER */
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
#ifdef __MINGW32__
|
|
|
|
#ifndef _WIN32
|
|
|
|
#define _WIN32 1
|
2011-05-25 16:40:36 +01:00
|
|
|
#endif /* _WIN32 */
|
|
|
|
#endif /* __MINGW32__ */
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
#if HAVE_GCC
|
|
|
|
#define MIN_ARRAY 0
|
|
|
|
#define DUMMY_FILLER_FOR_ABS_TYPE
|
|
|
|
#else
|
|
|
|
#define MIN_ARRAY 1
|
|
|
|
#define DUMMY_FILLER_FOR_ABS_TYPE int dummy;
|
2011-05-25 16:40:36 +01:00
|
|
|
#endif /* HAVE_GCC */
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2011-11-02 22:53:49 +00:00
|
|
|
#ifdef THREADS
|
|
|
|
#if USE_PTHREAD_LOCKING
|
|
|
|
#ifndef _XOPEN_SOURCE
|
|
|
|
#define _XOPEN_SOURCE 600
|
|
|
|
#endif /* !_XOPEN_SOURCE */
|
|
|
|
#endif /* USE_PTHREAD_LOCKING */
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif /* THREADS */
|
|
|
|
|
2005-05-27 23:27:59 +01:00
|
|
|
#ifndef ADTDEFS_C
|
|
|
|
#define EXTERN static
|
|
|
|
#else
|
|
|
|
#define EXTERN
|
2011-05-25 16:40:36 +01:00
|
|
|
#endif /* ADTDEFS_C */
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2011-05-23 16:19:47 +01:00
|
|
|
/* truth-values */
|
2005-05-27 23:27:59 +01:00
|
|
|
#define TRUE 1
|
|
|
|
#define FALSE 0
|
|
|
|
|
2011-05-23 16:19:47 +01:00
|
|
|
|
|
|
|
/* null pointer */
|
2005-05-27 23:27:59 +01:00
|
|
|
#define NIL 0
|
|
|
|
|
|
|
|
/* Basic types */
|
|
|
|
|
2011-11-02 22:53:49 +00:00
|
|
|
#include "YapTerm.h"
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2008-09-18 17:34:46 +01:00
|
|
|
#if HAVE_SIGPROF && (defined(__linux__) || defined(__APPLE__))
|
2005-05-27 23:27:59 +01:00
|
|
|
#define LOW_PROF 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* #define FORCE_SECOND_QUADRANT 1 */
|
|
|
|
|
|
|
|
#if defined(FORCE_SECOND_QUADRANT)
|
|
|
|
#define IN_SECOND_QUADRANT 1
|
|
|
|
#define MMAP_ADDR 0x42000000
|
2011-05-25 16:40:36 +01:00
|
|
|
#endif /* FORCE_SECOND_QUADRANT */
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2008-03-25 22:03:14 +00:00
|
|
|
#if !defined(IN_SECOND_QUADRANT)
|
2011-07-25 23:50:50 +01:00
|
|
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(mips) || (__DragonFly__)
|
2005-05-27 23:27:59 +01:00
|
|
|
#if defined(YAPOR) && defined(__alpha)
|
|
|
|
|
|
|
|
#define MMAP_ADDR 0x40000000
|
2008-03-25 22:03:14 +00:00
|
|
|
#elif defined(mips)
|
2005-05-27 23:27:59 +01:00
|
|
|
#define MMAP_ADDR 0x02000000
|
2010-12-31 04:14:45 +00:00
|
|
|
#elif defined(__powerpc__)
|
|
|
|
#define MMAP_ADDR 0x20000000
|
2005-05-27 23:27:59 +01:00
|
|
|
#else
|
2009-10-16 08:09:22 +01:00
|
|
|
#define MMAP_ADDR 0x10000000
|
2011-05-25 16:40:36 +01:00
|
|
|
#endif /* YAPOR && __alpha */
|
2005-05-27 23:27:59 +01:00
|
|
|
#elif __svr4__ || defined(__SVR4)
|
|
|
|
#define MMAP_ADDR 0x02000000
|
2011-05-25 16:40:36 +01:00
|
|
|
#endif /* __linux__ || __FreeBSD__ || __NetBSD__ || mips || __APPLE__ || __DragonFly__ */
|
2005-05-27 23:27:59 +01:00
|
|
|
#endif /* !IN_SECOND_QUADRANT */
|
|
|
|
|
2010-06-19 14:38:04 +01:00
|
|
|
/* #define RANDOMIZE_START_ADDRESS 1 */
|
2009-11-18 23:32:00 +00:00
|
|
|
|
2008-05-15 14:41:48 +01:00
|
|
|
#ifdef USE_SYSTEM_MALLOC
|
2005-05-27 23:27:59 +01:00
|
|
|
#define HEAP_INIT_BASE 0L
|
|
|
|
#define AtomBase NULL
|
2011-05-25 16:40:36 +01:00
|
|
|
#else /* !USE_SYSTEM_MALLOC */
|
2009-11-18 23:32:00 +00:00
|
|
|
#if defined(MMAP_ADDR) && (defined(USE_MMAP) || USE_SHMAT) && !defined(__simplescalar__) && !defined(RANDOMIZE_START_ADDRESS)
|
2005-05-27 23:27:59 +01:00
|
|
|
#define HEAP_INIT_BASE (MMAP_ADDR)
|
|
|
|
#define AtomBase ((char *)MMAP_ADDR)
|
2011-05-25 16:40:36 +01:00
|
|
|
#else /*! (MMAP_ADDR && (USE_MMAP || USE_SHMAT) && !__simplescalar__ && !RANDOMIZE_START_ADDRESS) */
|
2005-05-27 23:27:59 +01:00
|
|
|
#define HEAP_INIT_BASE ((CELL)Yap_HeapBase)
|
|
|
|
#define AtomBase (Yap_HeapBase)
|
2011-05-25 16:40:36 +01:00
|
|
|
#endif /* MMAP_ADDR && (USE_MMAP || USE_SHMAT) && !__simplescalar__ && !RANDOMIZE_START_ADDRESS */
|
|
|
|
#endif /* USE_SYSTEM_MALLOC */
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef ALIGN_LONGS
|
|
|
|
#define ALIGN_LONGS 1
|
|
|
|
#endif
|
|
|
|
|
2010-05-11 12:25:49 +01:00
|
|
|
#define K1 ((CELL)1024)
|
|
|
|
#define K16 ((CELL)(1024*64))
|
|
|
|
#define K64 ((CELL)(1024*64))
|
|
|
|
#define M1 ((CELL)(1024*1024))
|
|
|
|
#define M2 ((CELL)(2048*1024))
|
|
|
|
|
2005-05-27 23:27:59 +01:00
|
|
|
#if ALIGN_LONGS
|
|
|
|
typedef CELL SFLAGS;
|
|
|
|
#else
|
|
|
|
typedef BITS16 SFLAGS;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef char *ADDR;
|
|
|
|
typedef CELL OFFSET;
|
|
|
|
typedef unsigned char *CODEADDR;
|
|
|
|
|
2011-06-21 16:53:17 +01:00
|
|
|
#define ALIGN_YAPTYPE(X,TYPE) (((CELL)(X)+(sizeof(TYPE)-1)) & ~(sizeof(TYPE)-1))
|
|
|
|
|
2011-11-02 22:53:49 +00:00
|
|
|
#define TermPtr(V) ((Term *) (V))
|
2005-05-27 23:27:59 +01:00
|
|
|
#define Addr(V) ((ADDR) (V))
|
|
|
|
|
|
|
|
#define CodePtr(V) ((CODEADDR)(V))
|
|
|
|
#define CellPtr(V) ((CELL *)(V))
|
|
|
|
#define OpCodePtr(V) ((OPCODE *)(V))
|
|
|
|
#define OpRegPtr(V) ((OPREG *)(V))
|
|
|
|
#define SmallPtr(V) ((SMALLUNSGN *)(V))
|
|
|
|
#define WordPtr(V) ((BITS16 *)(V))
|
|
|
|
#define DisplPtr(V) ((DISPREG *)(V))
|
|
|
|
|
|
|
|
#if !defined(YAPOR) && !defined(THREADS)
|
|
|
|
#include <nolocks.h>
|
2010-10-15 13:14:24 +01:00
|
|
|
#elif USE_PTHREAD_LOCKING || defined(__CYGWIN__)
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
#ifndef _XOPEN_SOURCE
|
|
|
|
#define _XOPEN_SOURCE 600
|
|
|
|
#endif
|
|
|
|
|
2010-04-19 02:34:08 +01:00
|
|
|
#include <locks_pthread.h>
|
2005-05-27 23:27:59 +01:00
|
|
|
typedef pthread_mutex_t lockvar;
|
|
|
|
typedef pthread_rwlock_t rwlock_t;
|
2010-01-22 22:30:43 +00:00
|
|
|
|
2010-10-15 02:06:37 +01:00
|
|
|
#elif defined(i386)|| defined(__x86_64__)
|
2005-05-27 23:27:59 +01:00
|
|
|
typedef volatile int lockvar;
|
2010-04-19 02:34:08 +01:00
|
|
|
#include <locks_x86.h>
|
2005-05-27 23:27:59 +01:00
|
|
|
#elif defined(sparc) || defined(__sparc)
|
|
|
|
typedef volatile int lockvar;
|
2010-04-19 02:34:08 +01:00
|
|
|
#include <locks_sparc.h>
|
2005-05-27 23:27:59 +01:00
|
|
|
#elif defined(mips)
|
|
|
|
typedef volatile int lockvar;
|
2010-04-19 02:34:08 +01:00
|
|
|
#include <locks_mips.h>
|
2005-05-27 23:27:59 +01:00
|
|
|
#elif defined(__alpha)
|
|
|
|
typedef volatile int lockvar;
|
2010-04-19 02:34:08 +01:00
|
|
|
#include <locks_alpha.h>
|
2005-05-27 23:27:59 +01:00
|
|
|
#else
|
|
|
|
|
|
|
|
#ifndef _XOPEN_SOURCE
|
|
|
|
#define _XOPEN_SOURCE 600
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef pthread_mutex_t lockvar;
|
|
|
|
typedef pthread_rwlock_t rwlock_t;
|
2010-04-19 02:34:08 +01:00
|
|
|
#include <locks_pthread.h>
|
2005-05-27 23:27:59 +01:00
|
|
|
#endif
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
use an auxiliary function for ranges
|
|
|
|
*************************************************************************************************/
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define IN_BETWEEN(MIN,X,MAX) (Unsigned((Int)(X)-(Int)(MIN)) <= \
|
|
|
|
Unsigned((Int)(MAX)-(Int)(MIN)) )
|
|
|
|
|
|
|
|
#define OUTSIDE(MIN,X,MAX) (Unsigned((Int)(X)-(Int)(MIN)) > \
|
|
|
|
Unsigned((Int)(MAX)-(Int)(MIN)) )
|
|
|
|
#else
|
|
|
|
#define IN_BETWEEN(MIN,X,MAX) ((void *)(X) >= (void *)(MIN) && (void *)(X) <= (void *)(MAX))
|
|
|
|
|
|
|
|
#define OUTSIDE(MIN,X,MAX) ((void *)(X) < (void *)(MIN) || (void *)(X) > (void *)(MAX))
|
|
|
|
#endif
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
Atoms
|
|
|
|
*************************************************************************************************/
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
#include "Atoms.h"
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
Coroutining
|
|
|
|
*************************************************************************************************/
|
|
|
|
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
#ifdef COROUTINING
|
|
|
|
/* Support for co-routining */
|
|
|
|
#include "corout.h"
|
|
|
|
#endif
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
abstract machine registers
|
|
|
|
*************************************************************************************************/
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
#include "amidefs.h"
|
|
|
|
|
|
|
|
#include "Regs.h"
|
|
|
|
|
|
|
|
#if defined(YAPOR) ||defined(THREADS)
|
|
|
|
#ifdef mips
|
2010-04-19 02:34:08 +01:00
|
|
|
#include <locks_mips_funcs.h>
|
2005-05-27 23:27:59 +01:00
|
|
|
#endif
|
|
|
|
#ifdef __alpha
|
2010-04-19 02:34:08 +01:00
|
|
|
#include <locks_alpha_funcs.h>
|
2005-05-27 23:27:59 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
variables concerned with Error Handling
|
|
|
|
*************************************************************************************************/
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
#include <setjmp.h>
|
|
|
|
|
|
|
|
#if defined(SIMICS) || !HAVE_SIGSETJMP
|
|
|
|
#define sigjmp_buf jmp_buf
|
|
|
|
#define sigsetjmp(Env, Arg) setjmp(Env)
|
|
|
|
#define siglongjmp(Env, Arg) longjmp(Env, Arg)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Support for arrays */
|
|
|
|
#include "arrays.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Types of Errors */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
YAP_NO_ERROR,
|
|
|
|
FATAL_ERROR,
|
|
|
|
INTERNAL_ERROR,
|
|
|
|
INTERNAL_COMPILER_ERROR,
|
|
|
|
PURE_ABORT,
|
|
|
|
CALL_COUNTER_UNDERFLOW,
|
|
|
|
/* ISO_ERRORS */
|
|
|
|
CONSISTENCY_ERROR,
|
|
|
|
DOMAIN_ERROR_ARRAY_OVERFLOW,
|
|
|
|
DOMAIN_ERROR_ARRAY_TYPE,
|
|
|
|
DOMAIN_ERROR_IO_MODE,
|
|
|
|
DOMAIN_ERROR_MUTABLE,
|
|
|
|
DOMAIN_ERROR_NON_EMPTY_LIST,
|
|
|
|
DOMAIN_ERROR_NOT_LESS_THAN_ZERO,
|
|
|
|
DOMAIN_ERROR_NOT_NL,
|
|
|
|
DOMAIN_ERROR_NOT_ZERO,
|
|
|
|
DOMAIN_ERROR_OUT_OF_RANGE,
|
|
|
|
DOMAIN_ERROR_OPERATOR_PRIORITY,
|
|
|
|
DOMAIN_ERROR_OPERATOR_SPECIFIER,
|
|
|
|
DOMAIN_ERROR_RADIX,
|
|
|
|
DOMAIN_ERROR_SHIFT_COUNT_OVERFLOW,
|
|
|
|
DOMAIN_ERROR_SOURCE_SINK,
|
|
|
|
DOMAIN_ERROR_STREAM,
|
2010-10-27 14:49:27 +01:00
|
|
|
DOMAIN_ERROR_STREAM_ENCODING,
|
2005-05-27 23:27:59 +01:00
|
|
|
DOMAIN_ERROR_STREAM_OR_ALIAS,
|
|
|
|
DOMAIN_ERROR_STREAM_POSITION,
|
|
|
|
DOMAIN_ERROR_TIMEOUT_SPEC,
|
|
|
|
DOMAIN_ERROR_SYNTAX_ERROR_HANDLER,
|
|
|
|
EVALUATION_ERROR_FLOAT_OVERFLOW,
|
|
|
|
EVALUATION_ERROR_FLOAT_UNDERFLOW,
|
|
|
|
EVALUATION_ERROR_INT_OVERFLOW,
|
|
|
|
EVALUATION_ERROR_UNDEFINED,
|
|
|
|
EVALUATION_ERROR_UNDERFLOW,
|
|
|
|
EVALUATION_ERROR_ZERO_DIVISOR,
|
|
|
|
EXISTENCE_ERROR_ARRAY,
|
2008-03-27 00:41:33 +00:00
|
|
|
EXISTENCE_ERROR_KEY,
|
2005-05-27 23:27:59 +01:00
|
|
|
EXISTENCE_ERROR_SOURCE_SINK,
|
|
|
|
EXISTENCE_ERROR_STREAM,
|
2010-02-28 00:57:29 +00:00
|
|
|
EXISTENCE_ERROR_VARIABLE,
|
2005-05-27 23:27:59 +01:00
|
|
|
INSTANTIATION_ERROR,
|
|
|
|
INTERRUPT_ERROR,
|
2005-11-23 13:24:00 +00:00
|
|
|
OPERATING_SYSTEM_ERROR,
|
2005-05-27 23:27:59 +01:00
|
|
|
OUT_OF_HEAP_ERROR,
|
|
|
|
OUT_OF_STACK_ERROR,
|
|
|
|
OUT_OF_TRAIL_ERROR,
|
|
|
|
OUT_OF_ATTVARS_ERROR,
|
|
|
|
OUT_OF_AUXSPACE_ERROR,
|
|
|
|
PERMISSION_ERROR_ACCESS_PRIVATE_PROCEDURE,
|
|
|
|
PERMISSION_ERROR_NEW_ALIAS_FOR_STREAM,
|
|
|
|
PERMISSION_ERROR_CREATE_ARRAY,
|
|
|
|
PERMISSION_ERROR_CREATE_OPERATOR,
|
|
|
|
PERMISSION_ERROR_INPUT_BINARY_STREAM,
|
|
|
|
PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,
|
|
|
|
PERMISSION_ERROR_INPUT_STREAM,
|
|
|
|
PERMISSION_ERROR_INPUT_TEXT_STREAM,
|
|
|
|
PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE,
|
|
|
|
PERMISSION_ERROR_OPEN_SOURCE_SINK,
|
|
|
|
PERMISSION_ERROR_OUTPUT_BINARY_STREAM,
|
|
|
|
PERMISSION_ERROR_OUTPUT_STREAM,
|
|
|
|
PERMISSION_ERROR_OUTPUT_TEXT_STREAM,
|
|
|
|
PERMISSION_ERROR_RESIZE_ARRAY,
|
|
|
|
PERMISSION_ERROR_REPOSITION_STREAM,
|
|
|
|
PRED_ENTRY_COUNTER_UNDERFLOW,
|
|
|
|
REPRESENTATION_ERROR_CHARACTER,
|
|
|
|
REPRESENTATION_ERROR_CHARACTER_CODE,
|
|
|
|
REPRESENTATION_ERROR_MAX_ARITY,
|
2009-05-23 03:51:48 +01:00
|
|
|
REPRESENTATION_ERROR_VARIABLE,
|
2009-04-25 01:03:00 +01:00
|
|
|
RESOURCE_ERROR_HUGE_INT,
|
2009-05-23 01:55:18 +01:00
|
|
|
RESOURCE_ERROR_MAX_STREAMS,
|
2008-03-24 23:48:47 +00:00
|
|
|
RESOURCE_ERROR_MAX_THREADS,
|
2008-04-02 18:37:07 +01:00
|
|
|
RESOURCE_ERROR_MEMORY,
|
2009-04-25 17:01:33 +01:00
|
|
|
RESOURCE_ERROR_STACK,
|
2005-05-27 23:27:59 +01:00
|
|
|
RETRY_COUNTER_UNDERFLOW,
|
|
|
|
SYNTAX_ERROR,
|
|
|
|
SYSTEM_ERROR,
|
|
|
|
TYPE_ERROR_ARRAY,
|
|
|
|
TYPE_ERROR_ATOM,
|
|
|
|
TYPE_ERROR_ATOMIC,
|
|
|
|
TYPE_ERROR_BYTE,
|
|
|
|
TYPE_ERROR_CALLABLE,
|
|
|
|
TYPE_ERROR_CHAR,
|
|
|
|
TYPE_ERROR_CHARACTER,
|
|
|
|
TYPE_ERROR_COMPOUND,
|
|
|
|
TYPE_ERROR_DBREF,
|
|
|
|
TYPE_ERROR_DBTERM,
|
|
|
|
TYPE_ERROR_EVALUABLE,
|
|
|
|
TYPE_ERROR_FLOAT,
|
|
|
|
TYPE_ERROR_INTEGER,
|
|
|
|
TYPE_ERROR_KEY,
|
|
|
|
TYPE_ERROR_LIST,
|
|
|
|
TYPE_ERROR_NUMBER,
|
|
|
|
TYPE_ERROR_PREDICATE_INDICATOR,
|
|
|
|
TYPE_ERROR_PTR,
|
2011-06-13 01:42:32 +01:00
|
|
|
TYPE_ERROR_STRING,
|
2005-05-27 23:27:59 +01:00
|
|
|
TYPE_ERROR_UBYTE,
|
|
|
|
TYPE_ERROR_UCHAR,
|
|
|
|
TYPE_ERROR_VARIABLE,
|
|
|
|
UNKNOWN_ERROR
|
|
|
|
} yap_error_number;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
YAP_INT_BOUNDED_FLAG = 0,
|
|
|
|
MAX_ARITY_FLAG = 1,
|
|
|
|
INTEGER_ROUNDING_FLAG = 2,
|
|
|
|
YAP_MAX_INTEGER_FLAG = 3,
|
|
|
|
YAP_MIN_INTEGER_FLAG = 4,
|
|
|
|
CHAR_CONVERSION_FLAG = 5,
|
|
|
|
YAP_DOUBLE_QUOTES_FLAG = 6,
|
|
|
|
YAP_TO_CHARS_FLAG = 7,
|
|
|
|
LANGUAGE_MODE_FLAG = 8,
|
|
|
|
STRICT_ISO_FLAG = 9,
|
|
|
|
SOURCE_MODE_FLAG = 11,
|
|
|
|
CHARACTER_ESCAPE_FLAG = 12,
|
|
|
|
WRITE_QUOTED_STRING_FLAG = 13,
|
|
|
|
ALLOW_ASSERTING_STATIC_FLAG = 14,
|
|
|
|
HALT_AFTER_CONSULT_FLAG = 15,
|
|
|
|
FAST_BOOT_FLAG = 16,
|
|
|
|
STACK_DUMP_ON_ERROR_FLAG = 17,
|
2007-02-26 10:41:40 +00:00
|
|
|
GENERATE_DEBUG_INFO_FLAG = 18,
|
|
|
|
INDEXING_MODE_FLAG = 19,
|
|
|
|
TABLING_MODE_FLAG = 20,
|
2008-02-07 23:09:13 +00:00
|
|
|
VARS_CAN_HAVE_QUOTE_FLAG = 21,
|
2008-03-13 18:41:52 +00:00
|
|
|
QUIET_MODE_FLAG = 22,
|
2007-02-18 00:26:36 +00:00
|
|
|
/* let this be the last one */
|
2008-03-13 18:41:52 +00:00
|
|
|
LAST_FLAG = 23
|
2005-05-27 23:27:59 +01:00
|
|
|
} yap_flags;
|
|
|
|
|
|
|
|
#define STRING_AS_CHARS 0
|
|
|
|
#define STRING_AS_ATOM 2
|
|
|
|
|
|
|
|
#define QUINTUS_TO_CHARS 0
|
|
|
|
#define ISO_TO_CHARS 1
|
|
|
|
|
|
|
|
#define CPROLOG_CHARACTER_ESCAPES 0
|
|
|
|
#define ISO_CHARACTER_ESCAPES 1
|
|
|
|
#define SICSTUS_CHARACTER_ESCAPES 2
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
INDEX_MODE_OFF = 0,
|
|
|
|
INDEX_MODE_SINGLE = 1,
|
|
|
|
INDEX_MODE_COMPACT = 2,
|
|
|
|
INDEX_MODE_MULTI = 3,
|
|
|
|
INDEX_MODE_MAX = 4
|
|
|
|
} index_mode_options;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
YAP_CREEP_SIGNAL = 0x1, /* received a creep */
|
|
|
|
YAP_WAKEUP_SIGNAL = 0x2, /* goals to wake up */
|
|
|
|
YAP_ALARM_SIGNAL = 0x4, /* received an alarm */
|
|
|
|
YAP_HUP_SIGNAL = 0x8, /* received SIGHUP */
|
|
|
|
YAP_USR1_SIGNAL = 0x10, /* received SIGUSR1 */
|
|
|
|
YAP_USR2_SIGNAL = 0x20, /* received SIGUSR2 */
|
|
|
|
YAP_INT_SIGNAL = 0x40, /* received SIGINT (unused for now) */
|
|
|
|
YAP_ITI_SIGNAL = 0x80, /* received inter thread signal */
|
|
|
|
YAP_TROVF_SIGNAL = 0x100, /* received trail overflow */
|
|
|
|
YAP_CDOVF_SIGNAL = 0x200, /* received code overflow */
|
|
|
|
YAP_STOVF_SIGNAL = 0x400, /* received stack overflow */
|
|
|
|
YAP_TRACE_SIGNAL = 0x800, /* received start trace */
|
|
|
|
YAP_DEBUG_SIGNAL = 0x1000, /* received start debug */
|
|
|
|
YAP_BREAK_SIGNAL = 0x2000, /* received break signal */
|
|
|
|
YAP_STACK_DUMP_SIGNAL = 0x4000, /* received stack dump signal */
|
|
|
|
YAP_STATISTICS_SIGNAL = 0x8000, /* received statistics */
|
2007-02-18 00:26:36 +00:00
|
|
|
YAP_DELAY_CREEP_SIGNAL = 0x10000, /* received a creep but should not do it */
|
2008-05-23 11:02:13 +01:00
|
|
|
YAP_AGC_SIGNAL = 0x20000, /* call atom garbage collector asap */
|
2009-06-03 16:09:14 +01:00
|
|
|
YAP_PIPE_SIGNAL = 0x40000, /* call atom garbage collector asap */
|
2010-12-04 18:45:09 +00:00
|
|
|
YAP_VTALARM_SIGNAL = 0x80000, /* received SIGVTALARM */
|
|
|
|
YAP_FAIL_SIGNAL = 0x100000 /* P = FAILCODE */
|
2005-05-27 23:27:59 +01:00
|
|
|
} yap_signals;
|
|
|
|
|
2007-02-26 10:41:40 +00:00
|
|
|
#define NUMBER_OF_YAP_FLAGS LAST_FLAG
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
prototypes
|
|
|
|
*************************************************************************************************/
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
#include "Yapproto.h"
|
|
|
|
|
2011-11-02 22:53:49 +00:00
|
|
|
#include "YapTags.h"
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
#define TermSize sizeof(Term)
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
variables related to memory allocation
|
|
|
|
*************************************************************************************************/
|
2005-05-27 23:27:59 +01:00
|
|
|
/* must be before TermExt.h */
|
|
|
|
|
|
|
|
extern ADDR Yap_HeapBase;
|
|
|
|
|
|
|
|
/* This is ok for Linux, should be ok for everyone */
|
|
|
|
#define YAP_FILENAME_MAX 1024
|
|
|
|
|
|
|
|
#define MAX_ERROR_MSG_SIZE YAP_FILENAME_MAX
|
|
|
|
|
2011-06-20 14:49:24 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
Debugging Support
|
|
|
|
*************************************************************************************************/
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
extern int Yap_output_msg;
|
|
|
|
#endif
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
variables concerned with atoms table
|
|
|
|
*************************************************************************************************/
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2008-12-23 01:53:52 +00:00
|
|
|
#define MaxHash 3333
|
2006-11-27 17:42:03 +00:00
|
|
|
#define MaxWideHash (MaxHash/10+1)
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
#define FAIL_RESTORE 0
|
|
|
|
#define DO_EVERYTHING 1
|
|
|
|
#define DO_ONLY_CODE 2
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
common instructions codes
|
|
|
|
*************************************************************************************************/
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
#define MAX_PROMPT 256
|
|
|
|
|
|
|
|
#if USE_THREADED_CODE
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
reverse lookup of instructions
|
|
|
|
*************************************************************************************************/
|
2005-05-27 23:27:59 +01:00
|
|
|
typedef struct opcode_tab_entry
|
|
|
|
{
|
|
|
|
OPCODE opc;
|
|
|
|
op_numbers opnum;
|
|
|
|
} opentry;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
Prolog may be in several modes
|
|
|
|
*************************************************************************************************/
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
BootMode = 0x1, /* if booting or restoring */
|
|
|
|
UserMode = 0x2, /* Normal mode */
|
|
|
|
CritMode = 0x4, /* If we are meddling with the heap */
|
|
|
|
AbortMode = 0x8, /* expecting to abort */
|
|
|
|
InterruptMode = 0x10, /* under an interrupt */
|
|
|
|
InErrorMode = 0x20, /* under an interrupt */
|
|
|
|
ConsoleGetcMode = 0x40, /* blocked reading from console */
|
|
|
|
ExtendStackMode = 0x80, /* trying to extend stack */
|
|
|
|
GrowHeapMode = 0x100, /* extending Heap */
|
|
|
|
GrowStackMode = 0x200, /* extending Stack */
|
|
|
|
GCMode = 0x400, /* doing Garbage Collecting */
|
|
|
|
ErrorHandlingMode = 0x800, /* doing error handling */
|
|
|
|
CCallMode = 0x1000, /* In c Call */
|
|
|
|
UnifyMode = 0x2000, /* In Unify Code */
|
2005-12-17 03:25:39 +00:00
|
|
|
UserCCallMode = 0x4000, /* In User C-call Code */
|
2006-12-13 16:10:26 +00:00
|
|
|
MallocMode = 0x8000, /* Doing malloc, realloc, free */
|
|
|
|
SystemMode = 0x10000, /* in system mode */
|
2011-03-01 12:31:19 +00:00
|
|
|
AsyncIntMode = 0x20000, /* YAP has just been interrupted from the outside */
|
|
|
|
InReadlineMode = 0x40000 /* YAP has just been interrupted from the outside */
|
2005-05-27 23:27:59 +01:00
|
|
|
} prolog_exec_mode;
|
|
|
|
|
|
|
|
|
2011-05-23 16:19:47 +01:00
|
|
|
/*************************************************************************************************
|
2011-05-25 16:40:36 +01:00
|
|
|
number of modules
|
2011-05-23 16:19:47 +01:00
|
|
|
*************************************************************************************************/
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2007-04-10 23:13:21 +01:00
|
|
|
#define DefaultMaxModules 256
|
2005-05-27 23:27:59 +01:00
|
|
|
|
2011-05-23 16:19:47 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
Critical sections
|
|
|
|
*************************************************************************************************/
|
2008-03-25 22:03:14 +00:00
|
|
|
#ifdef YAPOR
|
2005-05-27 23:27:59 +01:00
|
|
|
#define YAPEnterCriticalSection() \
|
|
|
|
{ \
|
2011-05-10 11:47:18 +01:00
|
|
|
if (worker_id != GLOBAL_locks_who_locked_heap) { \
|
|
|
|
LOCK(GLOBAL_locks_heap_access); \
|
|
|
|
GLOBAL_locks_who_locked_heap = worker_id; \
|
2005-05-27 23:27:59 +01:00
|
|
|
} \
|
2011-05-25 16:40:36 +01:00
|
|
|
LOCAL_PrologMode |= CritMode; \
|
|
|
|
LOCAL_CritLocks++; \
|
2005-05-27 23:27:59 +01:00
|
|
|
}
|
|
|
|
#define YAPLeaveCriticalSection() \
|
|
|
|
{ \
|
2011-05-25 16:40:36 +01:00
|
|
|
LOCAL_CritLocks--; \
|
|
|
|
if (!LOCAL_CritLocks) { \
|
|
|
|
LOCAL_PrologMode &= ~CritMode; \
|
|
|
|
if (LOCAL_PrologMode & InterruptMode) { \
|
|
|
|
LOCAL_PrologMode &= ~InterruptMode; \
|
2005-05-27 23:27:59 +01:00
|
|
|
Yap_ProcessSIGINT(); \
|
|
|
|
} \
|
2011-05-25 16:40:36 +01:00
|
|
|
if (LOCAL_PrologMode & AbortMode) { \
|
|
|
|
LOCAL_PrologMode &= ~AbortMode; \
|
2005-05-27 23:27:59 +01:00
|
|
|
Yap_Error(PURE_ABORT, 0, ""); \
|
|
|
|
} \
|
2011-05-10 11:47:18 +01:00
|
|
|
GLOBAL_locks_who_locked_heap = MAX_WORKERS; \
|
|
|
|
UNLOCK(GLOBAL_locks_heap_access); \
|
2005-05-27 23:27:59 +01:00
|
|
|
} \
|
|
|
|
}
|
2008-03-25 22:03:14 +00:00
|
|
|
#elif defined(THREADS)
|
2005-05-27 23:27:59 +01:00
|
|
|
#define YAPEnterCriticalSection() \
|
|
|
|
{ \
|
2006-04-28 14:23:23 +01:00
|
|
|
/* LOCK(BGL); */ \
|
2011-05-25 16:40:36 +01:00
|
|
|
LOCAL_PrologMode |= CritMode; \
|
2005-05-27 23:27:59 +01:00
|
|
|
}
|
|
|
|
#define YAPLeaveCriticalSection() \
|
|
|
|
{ \
|
2011-05-25 16:40:36 +01:00
|
|
|
LOCAL_PrologMode &= ~CritMode; \
|
|
|
|
if (LOCAL_PrologMode & InterruptMode) { \
|
|
|
|
LOCAL_PrologMode &= ~InterruptMode; \
|
2005-05-27 23:27:59 +01:00
|
|
|
Yap_ProcessSIGINT(); \
|
|
|
|
} \
|
2011-05-25 16:40:36 +01:00
|
|
|
if (LOCAL_PrologMode & AbortMode) { \
|
|
|
|
LOCAL_PrologMode &= ~AbortMode; \
|
2005-05-27 23:27:59 +01:00
|
|
|
Yap_Error(PURE_ABORT, 0, ""); \
|
|
|
|
} \
|
2006-04-28 14:23:23 +01:00
|
|
|
/* UNLOCK(BGL); */ \
|
2005-05-27 23:27:59 +01:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define YAPEnterCriticalSection() \
|
|
|
|
{ \
|
2011-05-25 16:40:36 +01:00
|
|
|
LOCAL_PrologMode |= CritMode; \
|
|
|
|
LOCAL_CritLocks++; \
|
2005-05-27 23:27:59 +01:00
|
|
|
}
|
|
|
|
#define YAPLeaveCriticalSection() \
|
|
|
|
{ \
|
2011-05-25 16:40:36 +01:00
|
|
|
LOCAL_CritLocks--; \
|
|
|
|
if (!LOCAL_CritLocks) { \
|
|
|
|
LOCAL_PrologMode &= ~CritMode; \
|
|
|
|
if (LOCAL_PrologMode & InterruptMode) { \
|
|
|
|
LOCAL_PrologMode &= ~InterruptMode; \
|
2005-05-27 23:27:59 +01:00
|
|
|
Yap_ProcessSIGINT(); \
|
|
|
|
} \
|
2011-05-25 16:40:36 +01:00
|
|
|
if (LOCAL_PrologMode & AbortMode) { \
|
|
|
|
LOCAL_PrologMode &= ~AbortMode; \
|
2005-05-27 23:27:59 +01:00
|
|
|
Yap_Error(PURE_ABORT, 0, ""); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#endif /* YAPOR */
|
|
|
|
|
|
|
|
/* when we are calling the InitStaff procedures */
|
|
|
|
#define AT_BOOT 0
|
|
|
|
#define AT_RESTORE 1
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
|
|
|
|
/*************************************************************************************************
|
|
|
|
mutable variables
|
|
|
|
*************************************************************************************************/
|
2005-05-27 23:27:59 +01:00
|
|
|
|
|
|
|
/* I assume that the size of this structure is a multiple of the size
|
|
|
|
of CELL!!! */
|
|
|
|
typedef struct TIMED_MAVAR
|
|
|
|
{
|
|
|
|
CELL value;
|
|
|
|
CELL clock;
|
|
|
|
} timed_var;
|
|
|
|
|
2006-03-09 15:52:06 +00:00
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
execution mode
|
|
|
|
*************************************************************************************************/
|
2009-04-08 00:32:36 +01:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
INTERPRETED, /* interpreted */
|
|
|
|
MIXED_MODE_USER, /* mixed mode only for user predicates */
|
|
|
|
MIXED_MODE_ALL, /* mixed mode for all predicates */
|
|
|
|
COMPILE_USER, /* compile all user predicates*/
|
|
|
|
COMPILE_ALL /* compile all predicates */
|
|
|
|
} yap_exec_mode;
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
|
2011-05-23 16:19:47 +01:00
|
|
|
/************************/
|
|
|
|
#ifdef THREADS
|
|
|
|
typedef struct thandle {
|
|
|
|
int in_use;
|
|
|
|
int zombie;
|
|
|
|
UInt ssize;
|
|
|
|
UInt tsize;
|
|
|
|
UInt sysize;
|
|
|
|
void *stack_address;
|
|
|
|
Term tdetach;
|
|
|
|
Term cmod, texit_mod;
|
|
|
|
struct DB_TERM *tgoal, *texit;
|
|
|
|
int id;
|
|
|
|
int ret;
|
|
|
|
REGSTORE *default_yaam_regs;
|
|
|
|
REGSTORE *current_yaam_regs;
|
|
|
|
struct pred_entry *local_preds;
|
|
|
|
pthread_t pthread_handle;
|
|
|
|
int ref_count;
|
|
|
|
#ifdef LOW_LEVEL_TRACER
|
|
|
|
long long int thread_inst_count;
|
|
|
|
int been_here1;
|
|
|
|
int been_here2;
|
|
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
|
|
int been_here;
|
|
|
|
#endif
|
|
|
|
pthread_mutex_t tlock;
|
|
|
|
pthread_mutex_t tlock_status;
|
|
|
|
#if HAVE_GETRUSAGE||defined(_WIN32)
|
|
|
|
struct timeval *start_of_timesp;
|
|
|
|
struct timeval *last_timep;
|
|
|
|
#endif
|
|
|
|
} yap_thandle;
|
|
|
|
#endif /* THREADS */
|
|
|
|
|
|
|
|
#define GC_MAVARS_HASH_SIZE 512
|
|
|
|
typedef struct gc_ma_hash_entry_struct {
|
|
|
|
UInt timestmp;
|
|
|
|
#ifdef TABLING
|
|
|
|
tr_fr_ptr loc;
|
|
|
|
struct gc_ma_hash_entry_struct *more;
|
|
|
|
#endif
|
|
|
|
CELL* addr;
|
|
|
|
struct gc_ma_hash_entry_struct *next;
|
|
|
|
} gc_ma_hash_entry;
|
|
|
|
|
|
|
|
typedef int (*Agc_hook)(Atom);
|
|
|
|
|
|
|
|
typedef struct scratch_block_struct {
|
|
|
|
char *ptr;
|
|
|
|
UInt sz, msz;
|
|
|
|
} scratch_block;
|
|
|
|
|
|
|
|
|
|
|
|
/* scanner types */
|
|
|
|
#include "ScannerTypes.h"
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
OPTYAP includes
|
|
|
|
*************************************************************************************************/
|
2011-05-23 16:19:47 +01:00
|
|
|
|
|
|
|
#if defined(YAPOR) || defined(TABLING)
|
|
|
|
#include "opt.structs.h"
|
|
|
|
#include "opt.proto.h"
|
|
|
|
#include "opt.macros.h"
|
|
|
|
#endif /* YAPOR || TABLING */
|
|
|
|
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
|
|
|
|
/*************************************************************************************************
|
|
|
|
GLOBAL and LOCAL variables
|
|
|
|
*************************************************************************************************/
|
2011-05-23 16:19:47 +01:00
|
|
|
|
|
|
|
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
|
|
|
|
extern struct global_data *Yap_global;
|
|
|
|
extern long Yap_worker_area_size;
|
|
|
|
#else
|
|
|
|
extern struct global_data Yap_Global;
|
|
|
|
#define Yap_global (&Yap_Global)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(THREADS)
|
|
|
|
extern struct worker_local *Yap_local[MAX_THREADS];
|
|
|
|
#define REMOTE(wid) (Yap_local[wid])
|
|
|
|
#elif defined(YAPOR)
|
|
|
|
extern struct worker_local *Yap_local;
|
|
|
|
#define REMOTE(wid) (Yap_local + wid)
|
|
|
|
#else /* !THREADS && !YAPOR */
|
|
|
|
extern struct worker_local Yap_local;
|
|
|
|
#define REMOTE(wid) (&Yap_local)
|
|
|
|
#endif
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
#define YP_FILE FILE
|
2011-05-23 16:19:47 +01:00
|
|
|
#include "hglobals.h"
|
|
|
|
#include "dglobals.h"
|
|
|
|
#include "hlocals.h"
|
|
|
|
#include "dlocals.h"
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
|
|
|
|
/*************************************************************************************************
|
|
|
|
unification routines
|
|
|
|
*************************************************************************************************/
|
2011-05-23 16:19:47 +01:00
|
|
|
|
|
|
|
#ifdef YAPOR_SBA
|
|
|
|
#include "or.sba_amiops.h"
|
2011-06-02 17:01:00 +01:00
|
|
|
#include "or.sba_unify.h"
|
2011-05-23 16:19:47 +01:00
|
|
|
#else
|
|
|
|
#include "amiops.h"
|
|
|
|
#endif /* YAPOR_SBA */
|
|
|
|
|
2011-05-25 16:40:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************************************
|
|
|
|
High level macros to access arguments
|
|
|
|
*************************************************************************************************/
|
2011-05-23 16:19:47 +01:00
|
|
|
|
|
|
|
inline EXTERN Term ArgOfTerm (int i, Term t);
|
|
|
|
|
|
|
|
inline EXTERN Term
|
|
|
|
ArgOfTerm (int i, Term t)
|
|
|
|
{
|
|
|
|
return (Term) (Derefa (RepAppl (t) + (i)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline EXTERN Term HeadOfTerm (Term);
|
|
|
|
|
|
|
|
inline EXTERN Term
|
|
|
|
HeadOfTerm (Term t)
|
|
|
|
{
|
|
|
|
return (Term) (Derefa (RepPair (t)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline EXTERN Term TailOfTerm (Term);
|
|
|
|
|
|
|
|
inline EXTERN Term
|
|
|
|
TailOfTerm (Term t)
|
|
|
|
{
|
|
|
|
return (Term) (Derefa (RepPair (t) + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline EXTERN Term ArgOfTermCell (int i, Term t);
|
|
|
|
|
|
|
|
inline EXTERN Term
|
|
|
|
ArgOfTermCell (int i, Term t)
|
|
|
|
{
|
|
|
|
return (Term) ((CELL) (RepAppl (t) + (i)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline EXTERN Term HeadOfTermCell (Term);
|
|
|
|
|
|
|
|
inline EXTERN Term
|
|
|
|
HeadOfTermCell (Term t)
|
|
|
|
{
|
|
|
|
return (Term) ((CELL) (RepPair (t)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline EXTERN Term TailOfTermCell (Term);
|
|
|
|
|
|
|
|
inline EXTERN Term
|
|
|
|
TailOfTermCell (Term t)
|
|
|
|
{
|
|
|
|
return (Term) ((CELL) (RepPair (t) + 1));
|
|
|
|
}
|
|
|
|
|
2011-12-13 10:01:51 +00:00
|
|
|
|
2011-07-27 16:31:10 +01:00
|
|
|
/*************************************************************************************************
|
|
|
|
slots
|
|
|
|
*************************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
Yap_StartSlots( USES_REGS1 ) {
|
|
|
|
*--ASP = MkIntegerTerm(CurSlot);
|
|
|
|
*--ASP = MkIntTerm(0);
|
|
|
|
CurSlot = LCL0-ASP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
Yap_CloseSlots( USES_REGS1 ) {
|
|
|
|
Int old_slots;
|
2011-08-31 21:56:32 +01:00
|
|
|
if (CurSlot < LCL0-ASP)
|
|
|
|
return;
|
2011-07-27 16:31:10 +01:00
|
|
|
old_slots = IntOfTerm(ASP[0]);
|
|
|
|
ASP += (old_slots+1);
|
|
|
|
CurSlot = IntOfTerm(*ASP);
|
|
|
|
ASP++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline Int
|
|
|
|
Yap_CurrentSlot( USES_REGS1 ) {
|
|
|
|
return IntOfTerm(ASP[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pop slots when pruning */
|
|
|
|
static inline void
|
|
|
|
Yap_PopSlots( USES_REGS1 ) {
|
|
|
|
while (LCL0-CurSlot < ASP) {
|
|
|
|
Int old_slots;
|
|
|
|
CELL *ptr = LCL0-CurSlot;
|
|
|
|
old_slots = IntOfTerm(ptr[0]);
|
|
|
|
ptr += (old_slots+1);
|
|
|
|
CurSlot = IntOfTerm(*ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline Term
|
|
|
|
Yap_GetFromSlot(Int slot USES_REGS)
|
|
|
|
{
|
|
|
|
return(Deref(LCL0[slot]));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline Term
|
|
|
|
Yap_GetPtrFromSlot(Int slot USES_REGS)
|
|
|
|
{
|
|
|
|
return(LCL0[slot]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline Term *
|
|
|
|
Yap_AddressFromSlot(Int slot USES_REGS)
|
|
|
|
{
|
|
|
|
return(LCL0+slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
Yap_PutInSlot(Int slot, Term t USES_REGS)
|
|
|
|
{
|
|
|
|
LCL0[slot] = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-02 23:19:39 +00:00
|
|
|
#endif /* YAP_H */
|
2011-07-27 16:31:10 +01:00
|
|
|
|