This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/H/pl-shared.h

354 lines
8.7 KiB
C
Raw Normal View History

2013-11-15 01:10:25 +00:00
#ifndef PL_SHARED_H
2013-11-15 01:10:25 +00:00
#define PL_SHARED_H
2013-11-16 16:58:07 +00:00
/* we are in YAP */
#ifndef __YAP_PROLOG__
#define __YAP_PROLOG__ 1
#endif
2013-11-16 00:27:02 +00:00
2013-11-25 11:15:25 +00:00
#include <assert.h>
2013-11-16 16:58:07 +00:00
// SWI stuff that is needed everywhere
2013-11-16 16:58:07 +00:00
#ifndef __unix__
#if defined(_AIX) || defined(__APPLE__) || defined(__unix) || defined(__BEOS__) || defined(__NetBSD__)
#define __unix__ 1
#endif
#endif
2013-11-16 16:58:07 +00:00
#ifndef PL_CONSOLE
#define PL_KERNEL 1
#endif
#ifndef __WINDOWS__
#if defined(_MSC_VER) || defined(__MINGW32__)
#define __WINDOWS__ 1
#endif
#endif
// SWI Options
#define O_STRING 1
#define O_QUASIQUOTATIONS 1
2014-02-27 16:31:20 +00:00
#if HAVE_LOCALE_H
2013-11-25 11:15:25 +00:00
#define O_LOCALE 1
2014-02-27 16:31:20 +00:00
#endif
2013-11-16 16:58:07 +00:00
//#define O_ATOMGC 1
//#define O_CLAUSEGC 1
#ifdef HAVE_GMP_H
#define O_GMP 1
#endif
#ifdef __WINDOWS__
#define NOTTYCONTROL TRUE
#define O_DDE 1
#define O_DLL 1
#define O_HASDRIVES 1
#define O_HASSHARES 1
#define O_XOS 1
#define O_RLC 1
2013-11-16 17:26:31 +00:00
#define EMULATE_DLOPEN 1
2013-11-16 16:58:07 +00:00
#endif
#ifdef THREADS
#define O_PLMT 1
#else
#ifdef _REENTRANT
#undef _REENTRANT
#endif
#endif
2014-02-16 13:03:09 +00:00
#include <SWI-Stream.h>
2013-11-16 16:58:07 +00:00
#include <SWI-Prolog.h>
#define COMMON(X) extern X
#if defined(__GNUC__) && !defined(MAY_ALIAS)
#define MAY_ALIAS __attribute__ ((__may_alias__))
#else
#define MAY_ALIAS
#endif
#ifndef PL_HAVE_TERM_T
#define PL_HAVE_TERM_T
typedef uintptr_t term_t;
#endif
#if _WIN32
#ifndef THREADS
typedef int pthread_t;
#endif
#endif
typedef uintptr_t word; /* Anonymous 4 byte object */
typedef int bool;
2013-11-16 16:58:07 +00:00
#define GLOBAL_LD (LOCAL_PL_local_data_p)
#if !defined(O_PLMT) && !defined(YAPOR)
2013-11-16 18:51:32 +00:00
2013-11-16 16:58:07 +00:00
#define LOCAL_LD (GLOBAL_LD)
#define LD (GLOBAL_LD)
#define ARG1_LD void
#define ARG_LD
#define GET_LD
#define PRED_LD
#define PASS_LD
#define PASS_LD1
#define IGNORE_LD
#define REGS_FROM_LD
#define LD_FROM_REGS
#else
#define LOCAL_LD (__PL_ld)
#define LD LOCAL_LD
#define GET_LD CACHE_REGS struct PL_local_data *__PL_ld = GLOBAL_LD;
#define ARG1_LD struct PL_local_data *__PL_ld
#define ARG_LD , ARG1_LD
#define PASS_LD1 LD
#define PASS_LD , LD
#define PRED_LD GET_LD
#define IGNORE_LD (void)__PL_ld;
#define REGS_FROM_LD struct regstore_t *regcache = __PL_ld->reg_cache;
#define LD_FROM_REGS struct PL_local_data *__PL_ld = LOCAL_PL_local_data_p;
#endif
/*******************************
* STREAM I/O *
*******************************/
#define REDIR_MAGIC 0x23a9bef3
typedef struct redir_context
{ int magic; /* REDIR_MAGIC */
2014-02-16 13:03:09 +00:00
struct io_stream *stream; /* temporary output */
int is_stream; /* redirect to stream */
int redirected; /* output is redirected */
term_t term; /* redirect target */
int out_format; /* output type */
int out_arity; /* 2 for difference-list versions */
size_t size; /* size of I/O buffer */
char *data; /* data written */
char buffer[1024]; /* fast temporary buffer */
} redir_context;
#include "pl-file.h"
#define EOS '\0'
/********************************
* HASH TABLES *
*********************************/
#include "pl-table.h"
/********************************
* BUFFERS *
*********************************/
#define BUFFER_RING_SIZE 16 /* foreign buffer ring (pl-fli.c) */
#include "pl-buffer.h"
typedef struct canonical_dir * CanonicalDir; /* pl-os.c */
typedef struct
{ char *state; /* system's boot file */
char *startup; /* default user startup file */
int local; /* default local stack size (K) */
int global; /* default global stack size (K) */
int trail; /* default trail stack size (K) */
char *goal; /* default initialisation goal */
char *toplevel; /* default top level goal */
bool notty; /* use tty? */
char *arch; /* machine/OS we are using */
char *home; /* systems home directory */
} pl_defaults_t;
typedef struct on_halt * OnHalt; /* pl-os.c */
typedef struct extension_cell * ExtensionCell; /* pl-ext.c */
typedef struct tempfile * TempFile; /* pl-os.c */
typedef struct initialise_handle * InitialiseHandle;
/********************************
* Operating System *
*********************************/
#include "pl-os.h"
/********************************
* Table *
*********************************/
#include "pl-table.h"
2013-11-16 16:58:07 +00:00
/********************************
* LOCALE *
*********************************/
#include "pl-locale.h" /* Locale objects */
/********************************
* GLOBALS *
*********************************/
/* vsc: global variables */
#include "pl-global.h"
// THIS HAS TO BE ABSTRACTED
#define true(s, a) ((s)->flags & (a))
#define false(s, a) (!true((s), (a)))
#define set(s, a) ((s)->flags |= (a))
#define clear(s, a) ((s)->flags &= ~(a))
2013-11-16 16:58:07 +00:00
#define P_QUASI_QUOTATION_SYNTAX (0x00000004) /* <![Type[Quasi Quote]]> */
#define PLFLAG_CHARESCAPE 0x000001 /* handle \ in atoms */
#define PLFLAG_GC 0x000002 /* do GC */
#define PLFLAG_TRACE_GC 0x000004 /* verbose gc */
#define PLFLAG_TTY_CONTROL 0x000008 /* allow for tty control */
#define PLFLAG_READLINE 0x000010 /* readline is loaded */
#define PLFLAG_DEBUG_ON_ERROR 0x000020 /* start tracer on error */
#define PLFLAG_REPORT_ERROR 0x000040 /* print error message */
#define PLFLAG_FILE_CASE 0x000080 /* file names are case sensitive */
#define PLFLAG_FILE_CASE_PRESERVING 0x000100 /* case preserving file names */
#define PLFLAG_DOS_FILE_NAMES 0x000200 /* dos (8+3) file names */
#define ALLOW_VARNAME_FUNCTOR 0x000400 /* Read Foo(x) as 'Foo'(x) */
#define PLFLAG_ISO 0x000800 /* Strict ISO compliance */
#define PLFLAG_OPTIMISE 0x001000 /* -O: optimised compilation */
#define PLFLAG_FILEVARS 0x002000 /* Expand $var and ~ in filename */
#define PLFLAG_AUTOLOAD 0x004000 /* do autoloading */
#define PLFLAG_CHARCONVERSION 0x008000 /* do character-conversion */
#define PLFLAG_LASTCALL 0x010000 /* Last call optimization enabled? */
#define PLFLAG_EX_ABORT 0x020000 /* abort with exception */
#define PLFLAG_BACKQUOTED_STRING 0x040000 /* `a string` */
#define PLFLAG_SIGNALS 0x080000 /* Handle signals */
#define PLFLAG_DEBUGINFO 0x100000 /* generate debug info */
#define PLFLAG_FILEERRORS 0x200000 /* Edinburgh file errors */
2013-11-16 16:58:07 +00:00
#define PLFLAG_WARN_OVERRIDE_IMPLICIT_IMPORT 0x200000 /* Warn overriding weak symbols */
#define PLFLAG_QUASI_QUOTES 0x400000 /* Support quasi quotes */
/* Flags on module. Most of these flags are copied to the read context
in pl-read.c.
*/
#define M_SYSTEM (0x0001) /* system module */
#define M_CHARESCAPE (0x0002) /* module */
#define DBLQ_CHARS (0x0004) /* "ab" --> ['a', 'b'] */
#define DBLQ_ATOM (0x0008) /* "ab" --> 'ab' */
#define DBLQ_STRING (0x0010) /* "ab" --> "ab" */
#define DBLQ_MASK (DBLQ_CHARS|DBLQ_ATOM|DBLQ_STRING)
#define UNKNOWN_FAIL (0x0020) /* module */
#define UNKNOWN_WARNING (0x0040) /* module */
#define UNKNOWN_ERROR (0x0080) /* module */
#define UNKNOWN_MASK (UNKNOWN_ERROR|UNKNOWN_WARNING|UNKNOWN_FAIL)
extern unsigned int
getUnknownModule(module_t m);
#define truePrologFlag(flag) true(&LD->prolog_flag.mask, flag)
#define setPrologFlagMask(flag) set(&LD->prolog_flag.mask, flag)
#define clearPrologFlagMask(flag) clear(&LD->prolog_flag.mask, flag)
2013-11-13 22:52:36 +00:00
COMMON(int) debugmode(debug_type new, debug_type *old);
COMMON(int) tracemode(debug_type new, debug_type *old);
2014-01-07 01:10:48 +00:00
COMMON(void) Yap_setCurrentSourceLocation( void *rd );
2013-11-15 15:45:55 +00:00
extern int raiseSignal(PL_local_data_t *ld, int sig);
#ifdef YATOM_H
static inline atom_t
AtomToSWIAtom(Atom at)
{
TranslationEntry *p;
if ((p = Yap_GetTranslationProp(at)) != NULL)
return (atom_t)(p->Translation*2+1);
return (atom_t)at;
}
#endif
static inline Atom
SWIAtomToAtom(atom_t at)
{
if ((CELL)at & 1)
return SWI_Atoms[at/2];
return (Atom)at;
}
2013-11-25 11:15:25 +00:00
Atom YAP_AtomFromSWIAtom(atom_t at);
atom_t YAP_SWIAtomFromAtom(Atom at);
/* This is silly, but let's keep it like that for now */
static inline Functor
SWIFunctorToFunctor(functor_t f)
{
2014-02-16 13:03:09 +00:00
if (((CELL)(f) & 2) && ((CELL)f) < N_SWI_FUNCTORS*4+2)
2013-11-25 11:15:25 +00:00
return SWI_Functors[((CELL)f)/4];
return (Functor)f;
}
2013-11-13 22:52:36 +00:00
2013-11-16 16:58:07 +00:00
static inline Term
OpenList(int n USES_REGS)
{
Term t;
BACKUP_H();
2014-01-19 21:15:05 +00:00
while (HR+2*n > ASP-1024) {
2013-11-16 16:58:07 +00:00
if (!Yap_dogc( 0, NULL PASS_REGS )) {
RECOVER_H();
return FALSE;
}
}
2014-01-19 21:15:05 +00:00
t = AbsPair(HR);
HR += 2*n;
2013-11-16 16:58:07 +00:00
RECOVER_H();
return t;
}
static inline Term
ExtendList(Term t0, Term inp)
{
Term t;
CELL *ptr = RepPair(t0);
BACKUP_H();
ptr[0] = inp;
ptr[1] = AbsPair(ptr+2);
t = AbsPair(ptr+2);
RECOVER_H();
return t;
}
static inline int
CloseList(Term t0, Term tail)
{
CELL *ptr = RepPair(t0);
RESET_VARIABLE(ptr-1);
if (!Yap_unify((Term)(ptr-1), tail))
return FALSE;
return TRUE;
}
#endif /* PL_SHARED_INCLUDE */