2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: init.c *
|
|
|
|
* Last rev: *
|
|
|
|
* mods: *
|
|
|
|
* comments: initializing a prolog session *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
#ifdef SCCS
|
|
|
|
static char SccsId[] = "%W% %G%";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The code from this file is used to initialize the environment for prolog
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-08-31 03:51:44 +01:00
|
|
|
#include <stdlib.h>
|
2001-04-09 20:54:03 +01:00
|
|
|
#include "Yap.h"
|
|
|
|
#include "yapio.h"
|
2004-01-23 02:23:51 +00:00
|
|
|
#include "alloc.h"
|
2001-04-09 20:54:03 +01:00
|
|
|
#include "clause.h"
|
2002-11-11 17:38:10 +00:00
|
|
|
#include "Foreign.h"
|
2010-05-03 14:26:56 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef LOW_LEVEL_TRACER
|
|
|
|
#include "tracer.h"
|
|
|
|
#endif
|
|
|
|
#ifdef YAPOR
|
|
|
|
#include "or.macros.h"
|
|
|
|
#endif /* YAPOR */
|
|
|
|
#if defined(YAPOR) || defined(TABLING)
|
|
|
|
#if HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
#endif /* YAPOR || TABLING */
|
|
|
|
#if HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2002-11-11 17:38:10 +00:00
|
|
|
|
|
|
|
#define LOGFILE "logfile"
|
|
|
|
|
2002-11-19 17:10:45 +00:00
|
|
|
int Yap_output_msg = FALSE;
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef MACC
|
|
|
|
STATIC_PROTO(void InTTYLine, (char *));
|
|
|
|
#endif
|
|
|
|
#endif
|
2005-10-21 17:09:03 +01:00
|
|
|
STATIC_PROTO(void SetOp, (int, int, char *, Term));
|
2001-04-09 20:54:03 +01:00
|
|
|
STATIC_PROTO(void InitOps, (void));
|
|
|
|
STATIC_PROTO(void InitDebug, (void));
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
STATIC_PROTO(void CleanBack, (PredEntry *, CPredicate, CPredicate, CPredicate));
|
|
|
|
#else
|
2001-04-09 20:54:03 +01:00
|
|
|
STATIC_PROTO(void CleanBack, (PredEntry *, CPredicate, CPredicate));
|
2005-11-18 18:52:41 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
STATIC_PROTO(void InitStdPreds,(void));
|
|
|
|
STATIC_PROTO(void InitFlags, (void));
|
|
|
|
STATIC_PROTO(void InitCodes, (void));
|
|
|
|
STATIC_PROTO(void InitVersion, (void));
|
|
|
|
|
2005-11-18 18:52:41 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
STD_PROTO(void exit, (int));
|
|
|
|
|
|
|
|
/************** YAP PROLOG GLOBAL VARIABLES *************************/
|
|
|
|
|
|
|
|
/************* variables related to memory allocation ***************/
|
|
|
|
|
2008-03-25 16:45:53 +00:00
|
|
|
#if defined(THREADS)
|
2004-01-23 02:23:51 +00:00
|
|
|
|
2009-10-30 23:59:00 +00:00
|
|
|
ADDR Yap_HeapBase;
|
|
|
|
|
2008-04-02 16:41:50 +01:00
|
|
|
struct restore_info rinfo[MAX_THREADS];
|
2005-01-04 02:50:23 +00:00
|
|
|
|
2008-04-02 16:41:50 +01:00
|
|
|
struct thread_globs Yap_thread_gl[MAX_THREADS];
|
2004-01-23 02:23:51 +00:00
|
|
|
|
2010-07-23 12:07:33 +01:00
|
|
|
pthread_t Yap_master_thread;
|
|
|
|
|
2004-01-23 02:23:51 +00:00
|
|
|
#else
|
2005-01-04 02:50:23 +00:00
|
|
|
|
|
|
|
struct restore_info rinfo;
|
|
|
|
|
2004-01-23 02:23:51 +00:00
|
|
|
ADDR Yap_HeapBase,
|
|
|
|
Yap_LocalBase,
|
|
|
|
Yap_GlobalBase,
|
|
|
|
Yap_TrailBase,
|
|
|
|
Yap_TrailTop;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
/************ variables concerned with Error Handling *************/
|
2002-11-18 18:18:05 +00:00
|
|
|
char *Yap_ErrorMessage; /* used to pass error messages */
|
|
|
|
Term Yap_Error_Term; /* used to pass error terms */
|
|
|
|
yap_error_number Yap_Error_TYPE; /* used to pass the error */
|
2003-05-19 14:04:09 +01:00
|
|
|
UInt Yap_Error_Size; /* used to pass a size associated with an error */
|
2002-11-11 17:38:10 +00:00
|
|
|
|
2004-01-23 02:23:51 +00:00
|
|
|
/******************* storing error messages ****************************/
|
|
|
|
char Yap_ErrorSay[MAX_ERROR_MSG_SIZE];
|
|
|
|
|
|
|
|
/* if we botched in a LongIO operation */
|
|
|
|
jmp_buf Yap_IOBotch;
|
|
|
|
|
|
|
|
/* if we botched in the compiler */
|
|
|
|
jmp_buf Yap_CompilerBotch;
|
|
|
|
|
|
|
|
/************ variables concerned with Error Handling *************/
|
|
|
|
sigjmp_buf Yap_RestartEnv; /* used to restart after an abort execution */
|
|
|
|
|
|
|
|
/********* IO support *****/
|
|
|
|
|
|
|
|
/********* parsing ********************************************/
|
|
|
|
|
|
|
|
TokEntry *Yap_tokptr, *Yap_toktide;
|
|
|
|
VarEntry *Yap_VarTable, *Yap_AnonVarTable;
|
|
|
|
int Yap_eot_before_eof = FALSE;
|
|
|
|
|
|
|
|
/******************* intermediate buffers **********************/
|
|
|
|
|
|
|
|
char Yap_FileNameBuf[YAP_FILENAME_MAX],
|
|
|
|
Yap_FileNameBuf2[YAP_FILENAME_MAX];
|
|
|
|
|
|
|
|
#endif /* THREADS */
|
|
|
|
|
2005-01-28 23:14:41 +00:00
|
|
|
/******** whether Yap is responsible for signal handling******************/
|
|
|
|
int Yap_PrologShouldHandleInterrupts;
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
/********* readline support *****/
|
|
|
|
#if HAVE_LIBREADLINE
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
char *_line = (char *) NULL;
|
|
|
|
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
#ifdef MPWSHELL
|
|
|
|
/********** informing if we are in the MPW shell ********************/
|
|
|
|
|
|
|
|
int mpwshell = FALSE;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EMACS
|
|
|
|
|
|
|
|
int emacs_mode = FALSE;
|
|
|
|
char emacs_tmp[256], emacs_tmp2[256];
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/********* Prolog State ********************************************/
|
|
|
|
|
2008-03-25 22:03:14 +00:00
|
|
|
Int Yap_PrologMode = BootMode;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
int Yap_CritLocks = 0;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
/********* streams ********************************************/
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
YP_FILE *Yap_stdin;
|
|
|
|
YP_FILE *Yap_stdout;
|
|
|
|
YP_FILE *Yap_stderr;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
/************** Access to yap initial arguments ***************************/
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
char **Yap_argv;
|
|
|
|
int Yap_argc;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
/************** Extensions to Terms ***************************************/
|
|
|
|
|
|
|
|
#ifdef COROUTINING
|
|
|
|
/* array with the ops for your favourite extensions */
|
|
|
|
ext_op attas[attvars_ext+1];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/************** declarations local to init.c ************************/
|
|
|
|
static char *optypes[] =
|
|
|
|
{"", "xfx", "xfy", "yfx", "xf", "yf", "fx", "fy"};
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
/* OS page size for memory allocation */
|
2002-11-18 18:18:05 +00:00
|
|
|
int Yap_page_size;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
#if USE_THREADED_CODE
|
|
|
|
/* easy access to instruction opcodes */
|
2002-11-18 18:18:05 +00:00
|
|
|
void **Yap_ABSMI_OPCODES;
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
#if USE_SOCKET
|
2002-11-18 18:18:05 +00:00
|
|
|
int Yap_sockets_io=0;
|
2002-11-11 17:38:10 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
#if DEBUG
|
|
|
|
#if COROUTINING
|
2002-11-18 18:18:05 +00:00
|
|
|
int Yap_Portray_delays = FALSE;
|
2002-11-11 17:38:10 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
#define xfx 1
|
|
|
|
#define xfy 2
|
|
|
|
#define yfx 3
|
|
|
|
#define xf 4
|
|
|
|
#define yf 5
|
|
|
|
#define fx 6
|
|
|
|
#define fy 7
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
int
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_IsOpType(char *type)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 1; i <= 7; ++i)
|
|
|
|
if (strcmp(type, optypes[i]) == 0)
|
|
|
|
break;
|
|
|
|
return (i <= 7);
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
static int
|
2005-10-21 17:09:03 +01:00
|
|
|
OpDec(int p, char *type, Atom a, Term m)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
AtomEntry *ae = RepAtom(a);
|
|
|
|
OpEntry *info;
|
|
|
|
|
2009-11-20 00:33:14 +00:00
|
|
|
if (m == TermProlog)
|
|
|
|
m = PROLOG_MODULE;
|
2009-11-25 00:38:29 +00:00
|
|
|
else if (m == USER_MODULE)
|
|
|
|
m = PROLOG_MODULE;
|
2001-04-09 20:54:03 +01:00
|
|
|
for (i = 1; i <= 7; ++i)
|
|
|
|
if (strcmp(type, optypes[i]) == 0)
|
|
|
|
break;
|
|
|
|
if (i > 7) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(DOMAIN_ERROR_OPERATOR_SPECIFIER,MkAtomTerm(Yap_LookupAtom(type)),"op/3");
|
2001-04-09 20:54:03 +01:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
if (p) {
|
|
|
|
if (i == 1 || i == 2 || i == 4)
|
|
|
|
p |= DcrlpFlag;
|
|
|
|
if (i == 1 || i == 3 || i == 6)
|
|
|
|
p |= DcrrpFlag;
|
|
|
|
}
|
|
|
|
WRITE_LOCK(ae->ARWLock);
|
2009-11-20 00:33:14 +00:00
|
|
|
info = Yap_GetOpPropForAModuleHavingALock(ae, m);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (EndOfPAEntr(info)) {
|
2002-11-18 18:18:05 +00:00
|
|
|
info = (OpEntry *) Yap_AllocAtomSpace(sizeof(OpEntry));
|
2001-04-09 20:54:03 +01:00
|
|
|
info->KindOfPE = Ord(OpProperty);
|
2001-10-30 16:42:05 +00:00
|
|
|
info->NextOfPE = RepAtom(a)->PropsOfAE;
|
2005-10-21 17:09:03 +01:00
|
|
|
info->OpModule = m;
|
2006-04-28 14:23:23 +01:00
|
|
|
info->OpName = a;
|
|
|
|
LOCK(OpListLock);
|
|
|
|
info->OpNext = OpList;
|
|
|
|
OpList = info;
|
|
|
|
UNLOCK(OpListLock);
|
2001-10-30 16:42:05 +00:00
|
|
|
RepAtom(a)->PropsOfAE = AbsOpProp(info);
|
2001-04-09 20:54:03 +01:00
|
|
|
INIT_RWLOCK(info->OpRWLock);
|
|
|
|
WRITE_LOCK(info->OpRWLock);
|
|
|
|
WRITE_UNLOCK(ae->ARWLock);
|
|
|
|
info->Prefix = info->Infix = info->Posfix = 0;
|
|
|
|
} else {
|
|
|
|
WRITE_LOCK(info->OpRWLock);
|
|
|
|
WRITE_UNLOCK(ae->ARWLock);
|
|
|
|
}
|
|
|
|
if (i <= 3) {
|
2007-02-18 00:26:36 +00:00
|
|
|
if (yap_flags[STRICT_ISO_FLAG] &&
|
|
|
|
info->Posfix != 0) /* there is a posfix operator */ {
|
2001-04-09 20:54:03 +01:00
|
|
|
/* ISO dictates */
|
|
|
|
WRITE_UNLOCK(info->OpRWLock);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(PERMISSION_ERROR_CREATE_OPERATOR,MkAtomTerm(a),"op/3");
|
2009-11-20 00:33:14 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
info->Infix = p;
|
|
|
|
} else if (i <= 5) {
|
2007-02-18 00:26:36 +00:00
|
|
|
if (yap_flags[STRICT_ISO_FLAG] &&
|
|
|
|
info->Infix != 0) /* there is an infix operator */ {
|
2001-04-09 20:54:03 +01:00
|
|
|
/* ISO dictates */
|
|
|
|
WRITE_UNLOCK(info->OpRWLock);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(PERMISSION_ERROR_CREATE_OPERATOR,MkAtomTerm(a),"op/3");
|
2009-11-20 00:33:14 +00:00
|
|
|
return FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
info->Posfix = p;
|
|
|
|
} else {
|
|
|
|
info->Prefix = p;
|
|
|
|
}
|
|
|
|
WRITE_UNLOCK(info->OpRWLock);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
int
|
2005-10-21 17:09:03 +01:00
|
|
|
Yap_OpDec(int p, char *type, Atom a, Term m)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
2005-10-21 17:09:03 +01:00
|
|
|
return(OpDec(p,type,a,m));
|
2002-11-11 17:38:10 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static void
|
2005-10-21 17:09:03 +01:00
|
|
|
SetOp(int p, int type, char *at, Term m)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2002-11-18 18:18:05 +00:00
|
|
|
if (Yap_Option[5])
|
2002-11-11 17:38:10 +00:00
|
|
|
fprintf(stderr,"[setop %d %s %s]\n", p, optypes[type], at);
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
2005-10-21 17:09:03 +01:00
|
|
|
OpDec(p, optypes[type], Yap_LookupAtom(at), m);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Gets the info about an operator in a prop */
|
|
|
|
Atom
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_GetOp(OpEntry *pp, int *prio, int fix)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
SMALLUNSGN p;
|
|
|
|
|
|
|
|
if (fix == 0) {
|
|
|
|
p = pp->Prefix;
|
|
|
|
if (p & DcrrpFlag)
|
|
|
|
n = 6, *prio = (p ^ DcrrpFlag);
|
|
|
|
else
|
|
|
|
n = 7, *prio = p;
|
|
|
|
} else if (fix == 1) {
|
|
|
|
p = pp->Posfix;
|
|
|
|
if (p & DcrlpFlag)
|
|
|
|
n = 4, *prio = (p ^ DcrlpFlag);
|
|
|
|
else
|
|
|
|
n = 5, *prio = p;
|
|
|
|
} else {
|
|
|
|
p = pp->Infix;
|
|
|
|
if ((p & DcrrpFlag) && (p & DcrlpFlag))
|
|
|
|
n = 1, *prio = (p ^ (DcrrpFlag | DcrlpFlag));
|
|
|
|
else if (p & DcrrpFlag)
|
|
|
|
n = 3, *prio = (p ^ DcrrpFlag);
|
|
|
|
else if (p & DcrlpFlag)
|
|
|
|
n = 2, *prio = (p ^ DcrlpFlag);
|
|
|
|
else
|
|
|
|
n = 4, *prio = p;
|
|
|
|
}
|
2008-02-13 10:15:36 +00:00
|
|
|
return Yap_LookupAtom(optypes[n]);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct OPSTRUCT {
|
|
|
|
char *opName;
|
|
|
|
short int opType, opPrio;
|
|
|
|
} Opdef;
|
|
|
|
|
|
|
|
static Opdef Ops[] = {
|
|
|
|
{":-", xfx, 1200},
|
|
|
|
{"-->", xfx, 1200},
|
|
|
|
{"?-", fx, 1200},
|
|
|
|
{":-", fx, 1200},
|
|
|
|
{"dynamic", fx, 1150},
|
2008-02-12 17:03:59 +00:00
|
|
|
{"thread_local", fx, 1150},
|
2001-04-09 20:54:03 +01:00
|
|
|
{"initialization", fx, 1150},
|
2009-12-04 18:24:22 +00:00
|
|
|
{"volatile", fx, 1150},
|
2001-04-09 20:54:03 +01:00
|
|
|
{"mode", fx, 1150},
|
|
|
|
{"public", fx, 1150},
|
|
|
|
{"multifile", fx, 1150},
|
|
|
|
{"meta_predicate", fx, 1150},
|
2008-02-12 17:03:59 +00:00
|
|
|
{"module_transparent", fx, 1150},
|
2001-04-09 20:54:03 +01:00
|
|
|
{"discontiguous", fx, 1150},
|
|
|
|
#ifdef YAPOR
|
|
|
|
{"sequential", fx, 1150},
|
|
|
|
#endif /* YAPOR */
|
|
|
|
#ifdef TABLING
|
|
|
|
{"table", fx, 1150},
|
|
|
|
#endif /* TABLING */
|
2002-10-03 14:54:35 +01:00
|
|
|
#ifndef UNCUTABLE
|
|
|
|
{"uncutable", fx, 1150},
|
|
|
|
#endif /*UNCUTABLE ceh:*/
|
2009-11-27 15:55:46 +00:00
|
|
|
{"|", xfy, 1105},
|
2001-04-09 20:54:03 +01:00
|
|
|
{";", xfy, 1100},
|
|
|
|
/* {";", yf, 1100}, not allowed in ISO */
|
|
|
|
{"->", xfy, 1050},
|
2008-02-12 17:03:59 +00:00
|
|
|
{"*->", xfy, 1050},
|
2001-04-09 20:54:03 +01:00
|
|
|
{",", xfy, 1000},
|
|
|
|
{".", xfy, 999},
|
|
|
|
{"\\+", fy, 900},
|
|
|
|
{"not", fy, 900},
|
|
|
|
{"=", xfx, 700},
|
|
|
|
{"\\=", xfx, 700},
|
|
|
|
{"is", xfx, 700},
|
|
|
|
{"=..", xfx, 700},
|
|
|
|
{"==", xfx, 700},
|
|
|
|
{"\\==", xfx, 700},
|
|
|
|
{"@<", xfx, 700},
|
|
|
|
{"@>", xfx, 700},
|
|
|
|
{"@=<", xfx, 700},
|
|
|
|
{"@>=", xfx, 700},
|
2008-02-12 17:03:59 +00:00
|
|
|
{"=@=", xfx, 700},
|
|
|
|
{"\\=@=", xfx, 700},
|
2001-04-09 20:54:03 +01:00
|
|
|
{"=:=", xfx, 700},
|
|
|
|
{"=\\=", xfx, 700},
|
|
|
|
{"<", xfx, 700},
|
|
|
|
{">", xfx, 700},
|
|
|
|
{"=<", xfx, 700},
|
|
|
|
{">=", xfx, 700},
|
2007-12-05 12:17:25 +00:00
|
|
|
{"as", xfx, 600},
|
2001-04-09 20:54:03 +01:00
|
|
|
{":", xfy, 600},
|
|
|
|
{"+", yfx, 500},
|
|
|
|
{"-", yfx, 500},
|
|
|
|
{"/\\", yfx, 500},
|
|
|
|
{"\\/", yfx, 500},
|
2009-07-23 20:31:04 +01:00
|
|
|
{"><", yfx, 500},
|
2001-04-09 20:54:03 +01:00
|
|
|
{"#", yfx, 500},
|
2008-03-13 17:16:47 +00:00
|
|
|
{"rdiv", yfx, 400},
|
2010-08-31 03:51:44 +01:00
|
|
|
{"div", yfx, 400},
|
2001-04-09 20:54:03 +01:00
|
|
|
{"*", yfx, 400},
|
|
|
|
{"/", yfx, 400},
|
2008-08-24 00:46:20 +01:00
|
|
|
{"//", yfx, 400},
|
2001-04-09 20:54:03 +01:00
|
|
|
{"<<", yfx, 400},
|
|
|
|
{">>", yfx, 400},
|
2002-01-02 00:34:44 +00:00
|
|
|
{"mod", yfx, 400},
|
|
|
|
{"rem", yfx, 400},
|
2009-11-11 10:54:38 +00:00
|
|
|
{"+", fx, 200},
|
|
|
|
{"-", fy, 200},
|
|
|
|
{"\\", fy, 200},
|
2001-04-09 20:54:03 +01:00
|
|
|
{"//", yfx, 400},
|
|
|
|
{"**", xfx, 200},
|
|
|
|
{"^", xfy, 200}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitOps(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < sizeof(Ops) / sizeof(*Ops); ++i)
|
2005-10-21 17:09:03 +01:00
|
|
|
SetOp(Ops[i].opPrio, Ops[i].opType, Ops[i].opName, PROLOG_MODULE);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
#ifdef HAVE_ISATTY
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static void
|
|
|
|
InitDebug(void)
|
|
|
|
{
|
|
|
|
Atom At;
|
|
|
|
#ifdef DEBUG
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 1; i < 20; ++i)
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Option[i] = 0;
|
2002-11-19 17:10:45 +00:00
|
|
|
if (Yap_output_msg) {
|
2001-04-09 20:54:03 +01:00
|
|
|
char ch;
|
2002-11-11 17:38:10 +00:00
|
|
|
|
|
|
|
#if HAVE_ISATTY
|
|
|
|
if (!isatty (0)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2002-11-18 18:18:05 +00:00
|
|
|
fprintf(stderr,"absmi address:%p\n", FunAdr(Yap_absmi));
|
2001-05-07 20:56:02 +01:00
|
|
|
fprintf(stderr,"Set Trace Options:\n");
|
|
|
|
fprintf(stderr,"a getch\t\tb token\t\tc Lookup\td LookupVar\ti Index\n");
|
|
|
|
fprintf(stderr,"e SetOp\t\tf compile\tg icode\t\th boot\t\tl log\n");
|
2005-11-16 01:55:03 +00:00
|
|
|
fprintf(stderr,"m Machine\t p parser\n");
|
2001-04-09 20:54:03 +01:00
|
|
|
while ((ch = YP_putchar(YP_getchar())) != '\n')
|
|
|
|
if (ch >= 'a' && ch <= 'z')
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Option[ch - 'a' + 1] = 1;
|
|
|
|
if (Yap_Option['l' - 96]) {
|
|
|
|
Yap_logfile = fopen(LOGFILE, "w");
|
|
|
|
if (Yap_logfile == NULL) {
|
2001-05-07 20:56:02 +01:00
|
|
|
fprintf(stderr,"can not open %s\n", LOGFILE);
|
|
|
|
getchar();
|
2001-04-09 20:54:03 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
2001-05-07 20:56:02 +01:00
|
|
|
fprintf(stderr,"logging session to file 'logfile'\n");
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef MAC
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_SetTextFile(LOGFILE);
|
2001-04-09 20:54:03 +01:00
|
|
|
lp = my_line;
|
|
|
|
curfile = Nill;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2002-01-18 04:24:10 +00:00
|
|
|
/* Set at full leash */
|
2008-12-23 01:53:52 +00:00
|
|
|
At = AtomLeash;
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_PutValue(At, MkIntTerm(15));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-06-01 21:32:07 +01:00
|
|
|
Yap_InitCPred(char *Name, unsigned long int Arity, CPredicate code, UInt flags)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2008-09-24 00:59:41 +01:00
|
|
|
Atom atom = NIL;
|
|
|
|
PredEntry *pe = NULL;
|
2004-11-18 22:32:40 +00:00
|
|
|
yamop *p_code;
|
2004-09-27 21:45:04 +01:00
|
|
|
StaticClause *cl = NULL;
|
2008-10-07 23:52:26 +01:00
|
|
|
Functor f = NULL;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2008-09-24 00:59:41 +01:00
|
|
|
while (atom == NIL) {
|
|
|
|
atom = Yap_FullLookupAtom(Name);
|
|
|
|
if (atom == NIL && !Yap_growheap(FALSE, 0L, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-10-07 23:52:26 +01:00
|
|
|
if (Arity) {
|
|
|
|
while (!f) {
|
|
|
|
f = Yap_MkFunctor(atom,Arity);
|
|
|
|
if (!f && !Yap_growheap(FALSE, 0L, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-24 00:59:41 +01:00
|
|
|
while (pe == NULL) {
|
|
|
|
if (Arity)
|
2008-10-07 23:52:26 +01:00
|
|
|
pe = RepPredProp(PredPropByFunc(f,CurrentModule));
|
2008-09-24 00:59:41 +01:00
|
|
|
else
|
|
|
|
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
|
|
|
|
if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-09-27 21:45:04 +01:00
|
|
|
if (pe->PredFlags & CPredFlag) {
|
|
|
|
/* already exists */
|
|
|
|
cl = ClauseCodeToStaticClause(pe->CodeOfPred);
|
2004-11-18 22:32:40 +00:00
|
|
|
if ((flags | StandardPredFlag | CPredFlag) != pe->PredFlags) {
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace -= cl->ClSize;
|
2004-09-27 21:45:04 +01:00
|
|
|
Yap_FreeCodeSpace((ADDR)cl);
|
|
|
|
cl = NULL;
|
|
|
|
}
|
|
|
|
}
|
2004-11-18 22:32:40 +00:00
|
|
|
p_code = cl->ClCode;
|
2004-09-27 21:45:04 +01:00
|
|
|
while (!cl) {
|
|
|
|
UInt sz;
|
|
|
|
|
|
|
|
if (flags & SafePredFlag) {
|
2008-09-05 05:22:19 +01:00
|
|
|
sz = (CELL)NEXTOP(NEXTOP(NEXTOP(p_code,Osbpp),p),l);
|
2004-09-27 21:45:04 +01:00
|
|
|
} else {
|
2009-05-05 03:57:08 +01:00
|
|
|
sz = (CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(NEXTOP(p_code,e),p),Osbpp),p),l);
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
|
|
|
cl = (StaticClause *)Yap_AllocCodeSpace(sz);
|
|
|
|
if (!cl) {
|
|
|
|
if (!Yap_growheap(FALSE, sz, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace += sz;
|
2005-12-23 00:20:14 +00:00
|
|
|
cl->ClFlags = StaticMask;
|
|
|
|
cl->ClNext = NULL;
|
2005-01-28 23:14:41 +00:00
|
|
|
cl->ClSize = sz;
|
2004-09-27 21:45:04 +01:00
|
|
|
cl->usc.ClPred = pe;
|
|
|
|
p_code = cl->ClCode;
|
|
|
|
}
|
2003-11-18 19:16:08 +00:00
|
|
|
}
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->CodeOfPred = p_code;
|
2001-04-09 20:54:03 +01:00
|
|
|
pe->PredFlags = flags | StandardPredFlag | CPredFlag;
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->cs.f_code = code;
|
2004-09-27 21:45:04 +01:00
|
|
|
if (!(flags & SafePredFlag)) {
|
2003-11-18 19:16:08 +00:00
|
|
|
p_code->opc = Yap_opcode(_allocate);
|
|
|
|
p_code = NEXTOP(p_code,e);
|
|
|
|
}
|
2001-10-30 16:42:05 +00:00
|
|
|
if (flags & UserCPredFlag)
|
2003-11-18 19:16:08 +00:00
|
|
|
p_code->opc = Yap_opcode(_call_usercpred);
|
2001-10-30 16:42:05 +00:00
|
|
|
else
|
2003-11-18 19:16:08 +00:00
|
|
|
p_code->opc = Yap_opcode(_call_cpred);
|
2008-09-05 05:22:19 +01:00
|
|
|
p_code->u.Osbpp.bmap = NULL;
|
|
|
|
p_code->u.Osbpp.s = -Signed(RealEnvSize);
|
|
|
|
p_code->u.Osbpp.p =
|
|
|
|
p_code->u.Osbpp.p0 =
|
2006-12-13 16:10:26 +00:00
|
|
|
pe;
|
2008-09-05 05:22:19 +01:00
|
|
|
p_code = NEXTOP(p_code,Osbpp);
|
2004-09-27 21:45:04 +01:00
|
|
|
if (!(flags & SafePredFlag)) {
|
2003-11-18 19:16:08 +00:00
|
|
|
p_code->opc = Yap_opcode(_deallocate);
|
2008-08-30 16:24:44 +01:00
|
|
|
p_code->u.p.p = pe;
|
|
|
|
p_code = NEXTOP(p_code,p);
|
2003-11-18 19:16:08 +00:00
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
p_code->opc = Yap_opcode(_procceed);
|
2005-12-17 03:25:39 +00:00
|
|
|
p_code->u.p.p = pe;
|
|
|
|
p_code = NEXTOP(p_code,p);
|
2004-09-27 21:45:04 +01:00
|
|
|
p_code->opc = Yap_opcode(_Ystop);
|
2005-12-17 03:25:39 +00:00
|
|
|
p_code->u.l.l = cl->ClCode;
|
2003-11-18 19:16:08 +00:00
|
|
|
pe->OpcodeOfPred = pe->CodeOfPred->opc;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-06-01 21:32:07 +01:00
|
|
|
Yap_InitCmpPred(char *Name, unsigned long int Arity, CmpPredicate cmp_code, UInt flags)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2008-09-24 00:59:41 +01:00
|
|
|
Atom atom = NIL;
|
|
|
|
PredEntry *pe = NULL;
|
2004-09-27 21:45:04 +01:00
|
|
|
yamop *p_code = NULL;
|
|
|
|
StaticClause *cl = NULL;
|
2008-10-07 23:52:26 +01:00
|
|
|
Functor f = NULL;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2008-09-24 00:59:41 +01:00
|
|
|
while (atom == NIL) {
|
|
|
|
atom = Yap_FullLookupAtom(Name);
|
|
|
|
if (atom == NIL && !Yap_growheap(FALSE, 0L, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
2004-09-27 21:45:04 +01:00
|
|
|
}
|
2008-10-07 23:52:26 +01:00
|
|
|
if (Arity) {
|
|
|
|
while (!f) {
|
|
|
|
f = Yap_MkFunctor(atom,Arity);
|
|
|
|
if (!f && !Yap_growheap(FALSE, 0L, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-24 00:59:41 +01:00
|
|
|
while (pe == NULL) {
|
|
|
|
if (Arity)
|
2008-10-07 23:52:26 +01:00
|
|
|
pe = RepPredProp(PredPropByFunc(f,CurrentModule));
|
2008-09-24 00:59:41 +01:00
|
|
|
else
|
|
|
|
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
|
|
|
|
if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-09-27 21:45:04 +01:00
|
|
|
if (pe->PredFlags & CPredFlag) {
|
|
|
|
p_code = pe->CodeOfPred;
|
|
|
|
/* already exists */
|
|
|
|
} else {
|
|
|
|
while (!cl) {
|
2008-08-21 13:38:25 +01:00
|
|
|
UInt sz = sizeof(StaticClause)+(CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)NULL),plxxs),p),l);
|
2004-09-27 21:45:04 +01:00
|
|
|
cl = (StaticClause *)Yap_AllocCodeSpace(sz);
|
|
|
|
if (!cl) {
|
|
|
|
if (!Yap_growheap(FALSE, sz, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2006-11-06 18:35:05 +00:00
|
|
|
Yap_ClauseSpace += sz;
|
2005-12-23 00:20:14 +00:00
|
|
|
cl->ClFlags = StaticMask;
|
|
|
|
cl->ClNext = NULL;
|
2005-01-28 23:14:41 +00:00
|
|
|
cl->ClSize = sz;
|
2004-09-27 21:45:04 +01:00
|
|
|
cl->usc.ClPred = pe;
|
|
|
|
p_code = cl->ClCode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
pe->PredFlags = flags | StandardPredFlag | CPredFlag;
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->CodeOfPred = p_code;
|
|
|
|
pe->cs.d_code = cmp_code;
|
2001-11-15 00:01:43 +00:00
|
|
|
pe->ModuleOfPred = CurrentModule;
|
2003-01-13 14:02:50 +00:00
|
|
|
p_code->opc = pe->OpcodeOfPred = Yap_opcode(_call_bfunc_xx);
|
2008-08-21 13:38:25 +01:00
|
|
|
p_code->u.plxxs.p = pe;
|
|
|
|
p_code->u.plxxs.f = FAILCODE;
|
|
|
|
p_code->u.plxxs.x1 = Yap_emit_x(1);
|
|
|
|
p_code->u.plxxs.x2 = Yap_emit_x(2);
|
|
|
|
p_code->u.plxxs.flags = Yap_compile_cmp_flags(pe);
|
|
|
|
p_code = NEXTOP(p_code,plxxs);
|
2002-11-18 18:18:05 +00:00
|
|
|
p_code->opc = Yap_opcode(_procceed);
|
2005-12-17 03:25:39 +00:00
|
|
|
p_code->u.p.p = pe;
|
|
|
|
p_code = NEXTOP(p_code,p);
|
2004-09-20 05:16:33 +01:00
|
|
|
p_code->opc = Yap_opcode(_Ystop);
|
2005-12-17 03:25:39 +00:00
|
|
|
p_code->u.l.l = cl->ClCode;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-06-01 21:32:07 +01:00
|
|
|
Yap_InitAsmPred(char *Name, unsigned long int Arity, int code, CPredicate def, UInt flags)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2008-09-24 00:59:41 +01:00
|
|
|
Atom atom = NIL;
|
|
|
|
PredEntry *pe = NULL;
|
2008-10-07 23:52:26 +01:00
|
|
|
Functor f = NULL;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2008-09-24 00:59:41 +01:00
|
|
|
while (atom == NIL) {
|
|
|
|
atom = Yap_FullLookupAtom(Name);
|
|
|
|
if (atom == NIL && !Yap_growheap(FALSE, 0L, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-10-07 23:52:26 +01:00
|
|
|
if (Arity) {
|
|
|
|
while (!f) {
|
|
|
|
f = Yap_MkFunctor(atom,Arity);
|
|
|
|
if (!f && !Yap_growheap(FALSE, 0L, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-24 00:59:41 +01:00
|
|
|
while (pe == NULL) {
|
|
|
|
if (Arity)
|
2008-10-07 23:52:26 +01:00
|
|
|
pe = RepPredProp(PredPropByFunc(f,CurrentModule));
|
2008-09-24 00:59:41 +01:00
|
|
|
else
|
|
|
|
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
|
|
|
|
if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-05-28 17:26:00 +01:00
|
|
|
pe->PredFlags = flags | AsmPredFlag | StandardPredFlag | (code);
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->cs.f_code = def;
|
|
|
|
pe->ModuleOfPred = CurrentModule;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (def != NULL) {
|
2003-04-30 18:46:05 +01:00
|
|
|
yamop *p_code = ((StaticClause *)NULL)->ClCode;
|
2008-04-01 15:09:43 +01:00
|
|
|
StaticClause *cl;
|
2001-10-30 16:42:05 +00:00
|
|
|
|
2008-04-01 15:09:43 +01:00
|
|
|
if (pe->CodeOfPred == (yamop *)(&(pe->OpcodeOfPred))) {
|
2009-05-05 03:57:08 +01:00
|
|
|
if (flags & SafePredFlag) {
|
|
|
|
cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),Osbpp),p),l));
|
|
|
|
} else {
|
|
|
|
cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),e),Osbpp),p),p),l));
|
|
|
|
}
|
2008-04-01 15:09:43 +01:00
|
|
|
if (!cl) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitAsmPred");
|
|
|
|
return;
|
|
|
|
}
|
2008-09-05 05:22:19 +01:00
|
|
|
Yap_ClauseSpace += (CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),Osbpp),p),l);
|
2008-04-01 15:09:43 +01:00
|
|
|
} else {
|
|
|
|
cl = ClauseCodeToStaticClause(pe->CodeOfPred);
|
2005-11-23 03:01:33 +00:00
|
|
|
}
|
2005-12-23 00:20:14 +00:00
|
|
|
cl->ClFlags = StaticMask;
|
|
|
|
cl->ClNext = NULL;
|
2009-05-05 03:57:08 +01:00
|
|
|
if (flags & SafePredFlag) {
|
|
|
|
cl->ClSize = (CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),Osbpp),e),e);
|
|
|
|
} else {
|
|
|
|
cl->ClSize = (CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),e),Osbpp),p),e),e);
|
|
|
|
}
|
2005-12-17 03:25:39 +00:00
|
|
|
cl->usc.ClPred = pe;
|
2002-05-28 17:26:00 +01:00
|
|
|
p_code = cl->ClCode;
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->CodeOfPred = p_code;
|
2009-05-05 03:57:08 +01:00
|
|
|
if (!(flags & SafePredFlag)) {
|
|
|
|
p_code->opc = Yap_opcode(_allocate);
|
|
|
|
p_code = NEXTOP(p_code,e);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
p_code->opc = pe->OpcodeOfPred = Yap_opcode(_call_cpred);
|
2008-09-05 05:22:19 +01:00
|
|
|
p_code->u.Osbpp.bmap = NULL;
|
|
|
|
p_code->u.Osbpp.s = -Signed(RealEnvSize);
|
|
|
|
p_code->u.Osbpp.p = p_code->u.Osbpp.p0 = pe;
|
|
|
|
p_code = NEXTOP(p_code,Osbpp);
|
2009-05-05 03:57:08 +01:00
|
|
|
if (!(flags & SafePredFlag)) {
|
|
|
|
p_code->opc = Yap_opcode(_deallocate);
|
|
|
|
p_code->u.p.p = pe;
|
|
|
|
p_code = NEXTOP(p_code,p);
|
|
|
|
}
|
2002-11-18 18:18:05 +00:00
|
|
|
p_code->opc = Yap_opcode(_procceed);
|
2005-12-17 03:25:39 +00:00
|
|
|
p_code->u.p.p = pe;
|
|
|
|
p_code = NEXTOP(p_code,p);
|
2004-12-28 22:20:37 +00:00
|
|
|
p_code->opc = Yap_opcode(_Ystop);
|
2005-12-17 03:25:39 +00:00
|
|
|
p_code->u.l.l = cl->ClCode;
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
pe->OpcodeOfPred = Yap_opcode(_undef_p);
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->CodeOfPred = (yamop *)(&(pe->OpcodeOfPred));
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont, CPredicate Cut)
|
|
|
|
#else
|
2001-04-09 20:54:03 +01:00
|
|
|
CleanBack(PredEntry *pe, CPredicate Start, CPredicate Cont)
|
2005-11-18 18:52:41 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
yamop *code;
|
2002-12-27 16:53:09 +00:00
|
|
|
if (pe->cs.p_code.FirstClause != pe->cs.p_code.LastClause ||
|
|
|
|
pe->cs.p_code.TrueCodeOfPred != pe->cs.p_code.FirstClause ||
|
|
|
|
pe->CodeOfPred != pe->cs.p_code.FirstClause) {
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_Error(SYSTEM_ERROR,TermNil,
|
2001-04-09 20:54:03 +01:00
|
|
|
"initiating a C Pred with backtracking");
|
|
|
|
return;
|
|
|
|
}
|
2002-12-27 16:53:09 +00:00
|
|
|
code = (yamop *)(pe->cs.p_code.FirstClause);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (pe->PredFlags & UserCPredFlag)
|
2002-11-18 18:18:05 +00:00
|
|
|
code->opc = Yap_opcode(_try_userc);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
code->opc = Yap_opcode(_try_c);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
|
|
|
INIT_YAMOP_LTT(code, 2);
|
|
|
|
PUT_YAMOP_SEQ(code);
|
|
|
|
#endif /* YAPOR */
|
2008-09-05 05:22:19 +01:00
|
|
|
code->u.OtapFs.f = Start;
|
|
|
|
code = NEXTOP(code,OtapFs);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (pe->PredFlags & UserCPredFlag)
|
2002-11-18 18:18:05 +00:00
|
|
|
code->opc = Yap_opcode(_retry_userc);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
code->opc = Yap_opcode(_retry_c);
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
|
|
|
INIT_YAMOP_LTT(code, 1);
|
|
|
|
PUT_YAMOP_SEQ(code);
|
|
|
|
#endif /* YAPOR */
|
2008-09-05 05:22:19 +01:00
|
|
|
code->u.OtapFs.f = Cont;
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
2008-09-05 05:22:19 +01:00
|
|
|
code = NEXTOP(code,OtapFs);
|
2005-11-18 18:52:41 +00:00
|
|
|
if (pe->PredFlags & UserCPredFlag)
|
|
|
|
code->opc = Yap_opcode(_cut_c);
|
|
|
|
else
|
|
|
|
code->opc = Yap_opcode(_cut_userc);
|
2008-09-05 05:22:19 +01:00
|
|
|
code->u.OtapFs.f = Cut;
|
2005-11-18 18:52:41 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
2001-04-09 20:54:03 +01:00
|
|
|
void
|
2005-11-18 18:52:41 +00:00
|
|
|
Yap_InitCPredBack(char *Name, unsigned long int Arity,
|
|
|
|
unsigned int Extra, CPredicate Start,
|
2009-06-01 21:32:07 +01:00
|
|
|
CPredicate Cont, UInt flags){
|
2005-11-18 18:52:41 +00:00
|
|
|
Yap_InitCPredBack_(Name,Arity,Extra,Start,Cont,NULL,flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Yap_InitCPredBackCut(char *Name, unsigned long int Arity,
|
|
|
|
unsigned int Extra, CPredicate Start,
|
2009-06-01 21:32:07 +01:00
|
|
|
CPredicate Cont,CPredicate Cut, UInt flags){
|
2005-11-18 18:52:41 +00:00
|
|
|
Yap_InitCPredBack_(Name,Arity,Extra,Start,Cont,Cut,flags);
|
|
|
|
}
|
2010-01-28 15:42:49 +00:00
|
|
|
#else
|
|
|
|
Yap_InitCPredBackCut(char *Name, unsigned long int Arity,
|
|
|
|
unsigned int Extra, CPredicate Start,
|
|
|
|
CPredicate Cont,CPredicate Cut, UInt flags){
|
|
|
|
Yap_InitCPredBack(Name,Arity,Extra,Start,Cont,flags);
|
|
|
|
}
|
2005-11-18 18:52:41 +00:00
|
|
|
#endif /* CUT_C */
|
|
|
|
|
|
|
|
void
|
|
|
|
#ifdef CUT_C
|
|
|
|
Yap_InitCPredBack_(char *Name, unsigned long int Arity,
|
|
|
|
unsigned int Extra, CPredicate Start,
|
2009-06-01 21:32:07 +01:00
|
|
|
CPredicate Cont, CPredicate Cut, UInt flags)
|
2005-11-18 18:52:41 +00:00
|
|
|
#else
|
|
|
|
Yap_InitCPredBack(char *Name, unsigned long int Arity,
|
|
|
|
unsigned int Extra, CPredicate Start,
|
2009-06-01 21:32:07 +01:00
|
|
|
CPredicate Cont, UInt flags)
|
2005-11-18 18:52:41 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2008-09-24 00:59:41 +01:00
|
|
|
PredEntry *pe = NULL;
|
|
|
|
Atom atom = NIL;
|
2008-10-07 23:52:26 +01:00
|
|
|
Functor f = NULL;
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2008-09-24 00:59:41 +01:00
|
|
|
while (atom == NIL) {
|
|
|
|
atom = Yap_FullLookupAtom(Name);
|
|
|
|
if (atom == NIL && !Yap_growheap(FALSE, 0L, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-10-07 23:52:26 +01:00
|
|
|
if (Arity) {
|
|
|
|
while (!f) {
|
|
|
|
f = Yap_MkFunctor(atom,Arity);
|
|
|
|
if (!f && !Yap_growheap(FALSE, 0L, NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-24 00:59:41 +01:00
|
|
|
while (pe == NULL) {
|
|
|
|
if (Arity)
|
2008-10-07 23:52:26 +01:00
|
|
|
pe = RepPredProp(PredPropByFunc(f,CurrentModule));
|
2008-09-24 00:59:41 +01:00
|
|
|
else
|
|
|
|
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
|
|
|
|
if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-12-27 16:53:09 +00:00
|
|
|
if (pe->cs.p_code.FirstClause != NIL)
|
2005-11-18 18:52:41 +00:00
|
|
|
{
|
|
|
|
#ifdef CUT_C
|
|
|
|
CleanBack(pe, Start, Cont, Cut);
|
|
|
|
#else
|
|
|
|
CleanBack(pe, Start, Cont);
|
|
|
|
#endif /*CUT_C*/
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
else {
|
2003-04-30 18:46:05 +01:00
|
|
|
StaticClause *cl;
|
|
|
|
yamop *code = ((StaticClause *)NULL)->ClCode;
|
2005-11-18 18:52:41 +00:00
|
|
|
if (flags & UserCPredFlag)
|
2009-06-01 21:32:07 +01:00
|
|
|
pe->PredFlags = UserCPredFlag | CompiledPredFlag | StandardPredFlag | flags;
|
2005-11-18 18:52:41 +00:00
|
|
|
else
|
|
|
|
pe->PredFlags = CompiledPredFlag | StandardPredFlag;
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
|
|
|
pe->PredFlags |= SequentialPredFlag;
|
|
|
|
#endif /* YAPOR */
|
2005-11-18 18:52:41 +00:00
|
|
|
|
|
|
|
#ifdef CUT_C
|
2008-09-05 05:22:19 +01:00
|
|
|
cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code,OtapFs),OtapFs),OtapFs),l));
|
2005-11-18 18:52:41 +00:00
|
|
|
#else
|
2008-09-05 05:22:19 +01:00
|
|
|
cl = (StaticClause *)Yap_AllocCodeSpace((CELL)NEXTOP(NEXTOP(NEXTOP(code,OtapFs),OtapFs),l));
|
2005-11-18 18:52:41 +00:00
|
|
|
#endif
|
|
|
|
|
2004-11-19 22:08:43 +00:00
|
|
|
if (cl == NULL) {
|
|
|
|
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitCPredBack");
|
2001-04-09 20:54:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2005-12-23 00:20:14 +00:00
|
|
|
cl->ClFlags = StaticMask;
|
|
|
|
cl->ClNext = NULL;
|
2005-12-17 03:25:39 +00:00
|
|
|
#ifdef CUT_C
|
2008-09-05 05:22:19 +01:00
|
|
|
Yap_ClauseSpace += (CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code,OtapFs),OtapFs),OtapFs),l);
|
2005-12-17 03:25:39 +00:00
|
|
|
cl->ClSize =
|
2008-09-05 05:22:19 +01:00
|
|
|
(CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code,OtapFs),OtapFs),OtapFs),e);
|
2005-12-17 03:25:39 +00:00
|
|
|
#else
|
2008-09-05 05:22:19 +01:00
|
|
|
Yap_ClauseSpace += (CELL)NEXTOP(NEXTOP(NEXTOP(code,OtapFs),OtapFs),l);
|
2005-12-17 03:25:39 +00:00
|
|
|
cl->ClSize =
|
2008-09-05 05:22:19 +01:00
|
|
|
(CELL)NEXTOP(NEXTOP(NEXTOP(code,OtapFs),OtapFs),e);
|
2005-12-17 03:25:39 +00:00
|
|
|
#endif
|
|
|
|
cl->usc.ClPred = pe;
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
code = cl->ClCode;
|
2002-12-27 16:53:09 +00:00
|
|
|
pe->cs.p_code.TrueCodeOfPred = pe->CodeOfPred =
|
|
|
|
pe->cs.p_code.FirstClause = pe->cs.p_code.LastClause = code;
|
2001-04-09 20:54:03 +01:00
|
|
|
if (flags & UserCPredFlag)
|
2002-11-18 18:18:05 +00:00
|
|
|
pe->OpcodeOfPred = code->opc = Yap_opcode(_try_userc);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
pe->OpcodeOfPred = code->opc = Yap_opcode(_try_c);
|
2008-09-05 05:22:19 +01:00
|
|
|
code->u.OtapFs.f = Start;
|
|
|
|
code->u.OtapFs.p = pe;
|
|
|
|
code->u.OtapFs.s = Arity;
|
|
|
|
code->u.OtapFs.extra = Extra;
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
|
|
|
INIT_YAMOP_LTT(code, 2);
|
|
|
|
PUT_YAMOP_SEQ(code);
|
|
|
|
#endif /* YAPOR */
|
2008-09-05 05:22:19 +01:00
|
|
|
code = NEXTOP(code,OtapFs);
|
2001-04-09 20:54:03 +01:00
|
|
|
if (flags & UserCPredFlag)
|
2002-11-18 18:18:05 +00:00
|
|
|
code->opc = Yap_opcode(_retry_userc);
|
2001-04-09 20:54:03 +01:00
|
|
|
else
|
2002-11-18 18:18:05 +00:00
|
|
|
code->opc = Yap_opcode(_retry_c);
|
2008-09-05 05:22:19 +01:00
|
|
|
code->u.OtapFs.f = Cont;
|
|
|
|
code->u.OtapFs.p = pe;
|
|
|
|
code->u.OtapFs.s = Arity;
|
|
|
|
code->u.OtapFs.extra = Extra;
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef YAPOR
|
|
|
|
INIT_YAMOP_LTT(code, 1);
|
|
|
|
PUT_YAMOP_SEQ(code);
|
|
|
|
#endif /* YAPOR */
|
2008-09-05 05:22:19 +01:00
|
|
|
code = NEXTOP(code,OtapFs);
|
2005-11-18 18:52:41 +00:00
|
|
|
#ifdef CUT_C
|
|
|
|
if (flags & UserCPredFlag)
|
|
|
|
code->opc = Yap_opcode(_cut_userc);
|
|
|
|
else
|
|
|
|
code->opc = Yap_opcode(_cut_c);
|
2008-09-05 05:22:19 +01:00
|
|
|
code->u.OtapFs.f = Cut;
|
|
|
|
code->u.OtapFs.p = pe;
|
|
|
|
code->u.OtapFs.s = Arity;
|
|
|
|
code->u.OtapFs.extra = Extra;
|
|
|
|
code = NEXTOP(code,OtapFs);
|
2005-11-18 18:52:41 +00:00
|
|
|
#endif /* CUT_C */
|
2002-11-18 18:18:05 +00:00
|
|
|
code->opc = Yap_opcode(_Ystop);
|
2005-12-17 03:25:39 +00:00
|
|
|
code->u.l.l = cl->ClCode;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitStdPreds(void)
|
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitCPreds();
|
|
|
|
Yap_InitBackCPreds();
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitFlags(void)
|
|
|
|
{
|
2004-12-02 06:06:47 +00:00
|
|
|
/* note that Yap_heap_regs must be set first */
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2001-04-16 17:41:04 +01:00
|
|
|
#if USE_GMP
|
|
|
|
yap_flags[YAP_INT_BOUNDED_FLAG] = 0;
|
|
|
|
#else
|
2001-04-09 20:54:03 +01:00
|
|
|
yap_flags[YAP_INT_BOUNDED_FLAG] = 1;
|
2001-04-16 17:41:04 +01:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
yap_flags[MAX_ARITY_FLAG] = -1;
|
|
|
|
yap_flags[INTEGER_ROUNDING_FLAG] = 0;
|
|
|
|
yap_flags[YAP_MAX_INTEGER_FLAG] = (Int)(~((CELL)1 << (sizeof(Int)*8-1)));
|
|
|
|
yap_flags[YAP_MIN_INTEGER_FLAG] = (Int)(((CELL)1 << (sizeof(Int)*8-1)));
|
|
|
|
yap_flags[CHAR_CONVERSION_FLAG] = 1;
|
|
|
|
yap_flags[YAP_DOUBLE_QUOTES_FLAG] = 1;
|
2010-02-26 10:04:08 +00:00
|
|
|
yap_flags[YAP_TO_CHARS_FLAG] = ISO_TO_CHARS;
|
2001-04-09 20:54:03 +01:00
|
|
|
yap_flags[LANGUAGE_MODE_FLAG] = 0;
|
|
|
|
yap_flags[STRICT_ISO_FLAG] = FALSE;
|
|
|
|
yap_flags[SOURCE_MODE_FLAG] = FALSE;
|
2008-10-24 00:23:45 +01:00
|
|
|
yap_flags[CHARACTER_ESCAPE_FLAG] = SICSTUS_CHARACTER_ESCAPES;
|
2001-04-09 20:54:03 +01:00
|
|
|
yap_flags[WRITE_QUOTED_STRING_FLAG] = FALSE;
|
2001-10-31 20:16:48 +00:00
|
|
|
#if (defined(YAPOR) || defined(THREADS)) && PUREe_YAPOR
|
2001-04-09 20:54:03 +01:00
|
|
|
yap_flags[ALLOW_ASSERTING_STATIC_FLAG] = FALSE;
|
|
|
|
#else
|
|
|
|
yap_flags[ALLOW_ASSERTING_STATIC_FLAG] = TRUE;
|
|
|
|
#endif
|
2007-02-26 10:41:40 +00:00
|
|
|
yap_flags[GENERATE_DEBUG_INFO_FLAG] = TRUE;
|
2003-06-06 12:54:02 +01:00
|
|
|
/* current default */
|
|
|
|
yap_flags[INDEXING_MODE_FLAG] = INDEX_MODE_MULTI;
|
2005-07-06 20:34:12 +01:00
|
|
|
yap_flags[TABLING_MODE_FLAG] = 0;
|
2008-03-13 18:41:52 +00:00
|
|
|
yap_flags[QUIET_MODE_FLAG] = FALSE;
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2009-10-28 13:11:35 +00:00
|
|
|
static void
|
|
|
|
InitPredHash(void)
|
|
|
|
{
|
|
|
|
UInt i;
|
|
|
|
|
|
|
|
PredHash = (PredEntry **)Yap_AllocAtomSpace(sizeof(PredEntry **) * PredHashInitialSize);
|
|
|
|
PredHashTableSize = PredHashInitialSize;
|
|
|
|
if (PredHash == NULL) {
|
|
|
|
Yap_Error(FATAL_ERROR,MkIntTerm(0),"allocating initial predicate hash table");
|
|
|
|
}
|
|
|
|
for (i = 0; i < PredHashTableSize; ++i) {
|
|
|
|
PredHash[i] = NULL;
|
|
|
|
}
|
|
|
|
INIT_RWLOCK(PredHashRWLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitEnvInst(yamop start[2], yamop **instp, op_numbers opc, PredEntry *pred)
|
|
|
|
{
|
|
|
|
yamop *ipc = start;
|
|
|
|
|
|
|
|
/* make it look like the instruction is preceeded by a call instruction */
|
|
|
|
ipc->opc = Yap_opcode(_call);
|
|
|
|
ipc->u.Osbpp.s = -Signed(RealEnvSize);
|
|
|
|
ipc->u.Osbpp.bmap = NULL;
|
|
|
|
ipc->u.Osbpp.p = pred;
|
|
|
|
ipc->u.Osbpp.p0 = pred;
|
|
|
|
ipc = NEXTOP(ipc, Osbpp);
|
|
|
|
ipc->opc = Yap_opcode(opc);
|
|
|
|
*instp = ipc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-10-30 23:59:00 +00:00
|
|
|
InitOtaplInst(yamop start[1], OPCODE opc, PredEntry *pe)
|
2009-10-28 13:11:35 +00:00
|
|
|
{
|
|
|
|
yamop *ipc = start;
|
|
|
|
|
|
|
|
/* this is a place holder, it should not really be used */
|
|
|
|
ipc->opc = Yap_opcode(opc);
|
|
|
|
ipc->u.Otapl.s = 0;
|
2009-10-30 23:59:00 +00:00
|
|
|
ipc->u.Otapl.p = pe;
|
2009-10-28 13:11:35 +00:00
|
|
|
ipc->u.Otapl.d = NULL;
|
|
|
|
#ifdef YAPOR
|
|
|
|
INIT_YAMOP_LTT(ipc, 1);
|
|
|
|
#endif /* YAPOR */
|
|
|
|
#ifdef TABLING
|
|
|
|
ipc->u.Otapl.te = NULL;
|
|
|
|
#endif /* TABLING */
|
|
|
|
}
|
|
|
|
|
2009-10-28 15:53:23 +00:00
|
|
|
static void
|
|
|
|
InitDBErasedMarker(void)
|
|
|
|
{
|
|
|
|
Yap_heap_regs->db_erased_marker =
|
|
|
|
(DBRef)Yap_AllocCodeSpace(sizeof(DBStruct));
|
|
|
|
Yap_LUClauseSpace += sizeof(DBStruct);
|
|
|
|
Yap_heap_regs->db_erased_marker->id = FunctorDBRef;
|
|
|
|
Yap_heap_regs->db_erased_marker->Flags = ErasedMask;
|
|
|
|
Yap_heap_regs->db_erased_marker->Code = NULL;
|
|
|
|
Yap_heap_regs->db_erased_marker->DBT.DBRefs = NULL;
|
|
|
|
Yap_heap_regs->db_erased_marker->Parent = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitLogDBErasedMarker(void)
|
|
|
|
{
|
|
|
|
Yap_heap_regs->logdb_erased_marker =
|
|
|
|
(LogUpdClause *)Yap_AllocCodeSpace(sizeof(LogUpdClause)+(UInt)NEXTOP((yamop*)NULL,e));
|
|
|
|
Yap_LUClauseSpace += sizeof(LogUpdClause)+(UInt)NEXTOP((yamop*)NULL,e);
|
|
|
|
Yap_heap_regs->logdb_erased_marker->Id = FunctorDBRef;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClFlags = ErasedMask|LogUpdMask;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClSource = NULL;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClRefCount = 0;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClPred = PredLogUpdClause;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClExt = NULL;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClPrev = NULL;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClNext = NULL;
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClSize = (UInt)NEXTOP(((LogUpdClause *)NULL)->ClCode,e);
|
|
|
|
Yap_heap_regs->logdb_erased_marker->ClCode->opc = Yap_opcode(_op_fail);
|
|
|
|
INIT_CLREF_COUNT(Yap_heap_regs->logdb_erased_marker);
|
|
|
|
}
|
|
|
|
|
2010-05-03 14:26:56 +01:00
|
|
|
#define SWIAtomToAtom(X) SWI_Atoms[(X)>>1]
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitSWIAtoms(void)
|
|
|
|
{
|
|
|
|
int i=0, j=0;
|
|
|
|
#include "iswiatoms.h"
|
|
|
|
Yap_InitSWIHash();
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static void
|
2009-10-30 23:59:00 +00:00
|
|
|
InitAtoms(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
AtomHashTableSize = MaxHash;
|
|
|
|
HashChain = (AtomHashEntry *)Yap_AllocAtomSpace(sizeof(AtomHashEntry) * MaxHash);
|
|
|
|
if (HashChain == NULL) {
|
|
|
|
Yap_Error(FATAL_ERROR,MkIntTerm(0),"allocating initial atom table");
|
|
|
|
}
|
|
|
|
for (i = 0; i < MaxHash; ++i) {
|
|
|
|
INIT_RWLOCK(HashChain[i].AERWLock);
|
|
|
|
HashChain[i].Entry = NIL;
|
|
|
|
}
|
|
|
|
NOfAtoms = 0;
|
|
|
|
#if THREADS
|
|
|
|
SF_STORE->AtFoundVar = Yap_LookupAtom("**");
|
|
|
|
Yap_ReleaseAtom(AtomFoundVar);
|
|
|
|
SF_STORE->AtFreeTerm = Yap_LookupAtom("?");
|
|
|
|
Yap_ReleaseAtom(AtomFreeTerm);
|
|
|
|
SF_STORE->AtNil = Yap_LookupAtom("[]");
|
|
|
|
SF_STORE->AtDot = Yap_LookupAtom(".");
|
|
|
|
#else
|
|
|
|
Yap_LookupAtomWithAddress("**",&(SF_STORE->AtFoundVar));
|
|
|
|
Yap_ReleaseAtom(AtomFoundVar);
|
|
|
|
Yap_LookupAtomWithAddress("?",&(SF_STORE->AtFreeTerm));
|
|
|
|
Yap_ReleaseAtom(AtomFreeTerm);
|
|
|
|
Yap_LookupAtomWithAddress("[]",&(SF_STORE->AtNil));
|
|
|
|
Yap_LookupAtomWithAddress(".",&(SF_STORE->AtDot));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitWideAtoms(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
WideAtomHashTableSize = MaxWideHash;
|
|
|
|
WideHashChain = (AtomHashEntry *)Yap_AllocAtomSpace(sizeof(AtomHashEntry) * MaxWideHash);
|
|
|
|
if (WideHashChain == NULL) {
|
|
|
|
Yap_Error(FATAL_ERROR,MkIntTerm(0),"allocating wide atom table");
|
|
|
|
}
|
|
|
|
for (i = 0; i < MaxWideHash; ++i) {
|
|
|
|
INIT_RWLOCK(WideHashChain[i].AERWLock);
|
|
|
|
WideHashChain[i].Entry = NIL;
|
|
|
|
}
|
|
|
|
NOfWideAtoms = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitInvisibleAtoms(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2009-03-24 13:27:36 +00:00
|
|
|
/* initialise invisible chain */
|
|
|
|
Yap_heap_regs->invisiblechain.Entry = NIL;
|
|
|
|
INIT_RWLOCK(Yap_heap_regs->invisiblechain.AERWLock);
|
2009-10-30 23:59:00 +00:00
|
|
|
}
|
|
|
|
|
2004-01-23 02:23:51 +00:00
|
|
|
#ifdef THREADS
|
2010-06-19 14:38:04 +01:00
|
|
|
static void
|
|
|
|
InitThreadHandle(int wid)
|
2009-10-30 23:59:00 +00:00
|
|
|
{
|
2010-03-21 22:12:42 +00:00
|
|
|
FOREIGN_ThreadHandle(wid).in_use = FALSE;
|
|
|
|
FOREIGN_ThreadHandle(wid).zombie = FALSE;
|
|
|
|
FOREIGN_ThreadHandle(wid).local_preds = NULL;
|
2008-05-11 00:24:13 +01:00
|
|
|
#ifdef LOW_LEVEL_TRACER
|
2010-03-21 22:12:42 +00:00
|
|
|
FOREIGN_ThreadHandle(wid).thread_inst_count = 0LL;
|
2008-05-11 00:24:13 +01:00
|
|
|
#endif
|
2010-03-21 22:12:42 +00:00
|
|
|
pthread_mutex_init(&(FOREIGN_ThreadHandle(wid).tlock), NULL);
|
2009-10-30 23:59:00 +00:00
|
|
|
}
|
2008-03-25 16:45:53 +00:00
|
|
|
#endif
|
2009-10-30 23:59:00 +00:00
|
|
|
|
2010-08-04 11:35:30 +01:00
|
|
|
static void
|
|
|
|
InitSWIBuffers(int wid)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
FOREIGN_WL(wid)->SWI_buffers_[0] = malloc(SWI_BUF_SIZE);
|
|
|
|
FOREIGN_WL(wid)->SWI_buffers_sz_[0] = SWI_BUF_SIZE;
|
|
|
|
for (i=1; i <= SWI_BUF_RINGS; i++) {
|
|
|
|
FOREIGN_WL(wid)->SWI_buffers_[i] = NULL;
|
|
|
|
FOREIGN_WL(wid)->SWI_buffers_sz_[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-30 23:59:00 +00:00
|
|
|
static void
|
2010-03-21 22:12:42 +00:00
|
|
|
InitFirstWorkerThreadHandle(void)
|
2009-10-30 23:59:00 +00:00
|
|
|
{
|
2010-03-21 22:12:42 +00:00
|
|
|
#ifdef THREADS
|
|
|
|
ThreadHandle.id = 0;
|
|
|
|
ThreadHandle.in_use = TRUE;
|
|
|
|
ThreadHandle.default_yaam_regs =
|
|
|
|
&Yap_standard_regs;
|
|
|
|
ThreadHandle.pthread_handle = pthread_self();
|
|
|
|
pthread_mutex_init(&FOREIGN_ThreadHandle(0).tlock, NULL);
|
|
|
|
pthread_mutex_init(&FOREIGN_ThreadHandle(0).tlock_status, NULL);
|
|
|
|
ThreadHandle.tdetach = MkAtomTerm(AtomFalse);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitScratchPad(int wid)
|
|
|
|
{
|
|
|
|
FOREIGN_WL(wid)->scratchpad.ptr = NULL;
|
|
|
|
FOREIGN_WL(wid)->scratchpad.sz = SCRATCH_START_SIZE;
|
|
|
|
FOREIGN_WL(wid)->scratchpad.msz = SCRATCH_START_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Yap_CloseScratchPad(void)
|
|
|
|
{
|
|
|
|
Yap_FreeCodeSpace(ScratchPad.ptr);
|
|
|
|
ScratchPad.sz = SCRATCH_START_SIZE;
|
|
|
|
ScratchPad.msz = SCRATCH_START_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "iglobals.h"
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
2010-08-04 11:35:30 +01:00
|
|
|
#define MAX_INITS MAX_WORKERS
|
2005-10-28 18:38:50 +01:00
|
|
|
#else
|
2010-03-21 22:12:42 +00:00
|
|
|
#define MAX_INITS 1
|
|
|
|
#endif
|
2009-10-30 23:59:00 +00:00
|
|
|
|
2010-03-21 22:12:42 +00:00
|
|
|
struct worker_shared Yap_Global;
|
|
|
|
|
|
|
|
#if defined(YAPOR) || defined(THREADS)
|
|
|
|
struct worker_local Yap_WLocal[MAX_WORKERS];
|
|
|
|
#else
|
|
|
|
struct worker_local Yap_WLocal;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
InitCodes(void)
|
|
|
|
{
|
|
|
|
int wid;
|
|
|
|
#include "ihstruct.h"
|
|
|
|
InitGlobal();
|
|
|
|
for (wid = 0; wid < MAX_INITS; wid++)
|
|
|
|
InitWorker(wid);
|
|
|
|
InitFirstWorkerThreadHandle();
|
2001-04-09 20:54:03 +01:00
|
|
|
/* make sure no one else can use these two atoms */
|
2001-11-15 00:01:43 +00:00
|
|
|
CurrentModule = 0;
|
2010-03-21 22:12:42 +00:00
|
|
|
Yap_ReleaseAtom(AtomOfTerm(TermReFoundVar));
|
2002-03-08 06:31:32 +00:00
|
|
|
/* make sure we have undefp defined */
|
2002-05-10 16:04:03 +01:00
|
|
|
/* predicates can only be defined after this point */
|
2001-11-15 00:01:43 +00:00
|
|
|
{
|
|
|
|
/* make sure we know about the module predicate */
|
2008-12-23 01:53:52 +00:00
|
|
|
PredEntry *modp = RepPredProp(PredPropByFunc(FunctorModule,PROLOG_MODULE));
|
2001-11-15 00:01:43 +00:00
|
|
|
modp->PredFlags |= MetaPredFlag;
|
|
|
|
}
|
2002-05-10 16:04:03 +01:00
|
|
|
#ifdef YAPOR
|
2010-01-14 15:58:19 +00:00
|
|
|
Yap_heap_regs->getwork_code->u.Otapl.p = RepPredProp(PredPropByAtom(AtomGetwork, PROLOG_MODULE));
|
|
|
|
Yap_heap_regs->getwork_seq_code->u.Otapl.p = RepPredProp(PredPropByAtom(AtomGetworkSeq, PROLOG_MODULE));
|
2005-07-06 20:34:12 +01:00
|
|
|
#endif /* YAPOR */
|
2009-10-28 15:53:23 +00:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-06-04 01:46:32 +01:00
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
static void
|
|
|
|
InitVersion(void)
|
|
|
|
{
|
2008-12-23 01:53:52 +00:00
|
|
|
Yap_PutValue(AtomVersionNumber,
|
2009-10-23 09:09:16 +01:00
|
|
|
MkAtomTerm(Yap_LookupAtom(YAP_SVERSION)));
|
2006-05-22 17:23:49 +01:00
|
|
|
#if defined MYDDAS_MYSQL || defined MYDDAS_ODBC
|
2008-12-23 01:53:52 +00:00
|
|
|
Yap_PutValue(AtomMyddasVersionName,
|
2006-05-22 17:23:49 +01:00
|
|
|
MkAtomTerm(Yap_LookupAtom(MYDDAS_VERSION)));
|
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-27 15:15:54 +00:00
|
|
|
Yap_InitWorkspace(UInt Heap, UInt Stack, UInt Trail, UInt Atts, UInt max_table_size,
|
2005-08-04 16:45:56 +01:00
|
|
|
int n_workers, int sch_loop, int delay_load)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* initialise system stuff */
|
|
|
|
|
|
|
|
#if PUSH_REGS
|
2004-01-23 02:23:51 +00:00
|
|
|
#ifdef THREADS
|
2004-02-06 17:22:24 +00:00
|
|
|
pthread_key_create(&Yap_yaamregs_key, NULL);
|
|
|
|
pthread_setspecific(Yap_yaamregs_key, (const void *)&Yap_standard_regs);
|
2010-07-23 12:07:33 +01:00
|
|
|
Yap_master_thread = pthread_self();
|
2004-01-23 02:23:51 +00:00
|
|
|
#else
|
|
|
|
/* In this case we need to initialise the abstract registers */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_regp = &Yap_standard_regs;
|
2001-04-09 20:54:03 +01:00
|
|
|
/* the emulator will eventually copy them to its own local
|
|
|
|
register array, but for now they exist */
|
2004-01-23 02:23:51 +00:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif /* PUSH_REGS */
|
|
|
|
|
2002-10-21 23:14:29 +01:00
|
|
|
#ifdef THREADS
|
2003-12-18 17:23:22 +00:00
|
|
|
Yap_regp->worker_id_ = 0;
|
2002-10-21 23:14:29 +01:00
|
|
|
#endif
|
2001-04-09 20:54:03 +01:00
|
|
|
/* Init signal handling and time */
|
|
|
|
/* also init memory page size, required by later functions */
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitSysbits ();
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2008-03-25 16:45:53 +00:00
|
|
|
if (Heap < MinHeapSpace)
|
|
|
|
Heap = MinHeapSpace;
|
|
|
|
Heap = AdjustPageSize(Heap * K);
|
|
|
|
/* sanity checking for data areas */
|
|
|
|
if (Trail < MinTrailSpace)
|
|
|
|
Trail = MinTrailSpace;
|
|
|
|
Trail = AdjustPageSize(Trail * K);
|
|
|
|
if (Stack < MinStackSpace)
|
|
|
|
Stack = MinStackSpace;
|
|
|
|
Stack = AdjustPageSize(Stack * K);
|
2009-05-01 18:11:52 +01:00
|
|
|
if (!Atts)
|
|
|
|
Atts = 2048*sizeof(CELL);
|
|
|
|
else
|
|
|
|
Atts = AdjustPageSize(Atts * K);
|
2010-01-14 15:58:19 +00:00
|
|
|
#if defined(YAPOR) && !defined(THREADS)
|
2005-03-04 20:30:14 +00:00
|
|
|
worker_id = 0;
|
2005-08-04 16:45:56 +01:00
|
|
|
if (n_workers > MAX_WORKERS)
|
2005-05-31 01:32:02 +01:00
|
|
|
Yap_Error(INTERNAL_ERROR, TermNil, "excessive number of workers (Yap_InitWorkspace)");
|
2005-03-04 20:30:14 +00:00
|
|
|
#ifdef ENV_COPY
|
2005-08-04 16:45:56 +01:00
|
|
|
INFORMATION_MESSAGE("YapOr: copy model with %d worker%s", n_workers, n_workers == 1 ? "":"s");
|
2005-03-04 20:30:14 +00:00
|
|
|
#elif ACOW
|
2005-08-04 16:45:56 +01:00
|
|
|
INFORMATION_MESSAGE("YapOr: acow model with %d worker%s", n_workers, n_workers == 1 ? "":"s");
|
2005-03-04 20:30:14 +00:00
|
|
|
#else /* SBA */
|
2005-08-04 16:45:56 +01:00
|
|
|
INFORMATION_MESSAGE("YapOr: sba model with %d worker%s", n_workers, n_workers == 1 ? "":"s");
|
2005-03-04 20:30:14 +00:00
|
|
|
#endif /* ENV_COPY - ACOW - SBA */
|
2009-03-27 15:15:54 +00:00
|
|
|
map_memory(Heap, Stack+Atts, Trail, n_workers);
|
2005-03-04 20:30:14 +00:00
|
|
|
#else
|
2009-03-27 15:15:54 +00:00
|
|
|
Yap_InitMemory (Trail, Heap, Stack+Atts);
|
2010-01-14 15:58:19 +00:00
|
|
|
#endif /* YAPOR && !THREADS */
|
2005-03-04 20:30:14 +00:00
|
|
|
#if defined(YAPOR) || defined(TABLING)
|
2005-11-04 01:17:17 +00:00
|
|
|
Yap_init_global(max_table_size, n_workers, sch_loop, delay_load);
|
2003-12-18 16:38:40 +00:00
|
|
|
#endif /* YAPOR || TABLING */
|
2009-10-30 23:59:00 +00:00
|
|
|
Yap_AttsSize = Atts;
|
2004-03-02 16:44:58 +00:00
|
|
|
|
2005-03-04 20:30:14 +00:00
|
|
|
Yap_InitTime ();
|
2001-04-09 20:54:03 +01:00
|
|
|
/* InitAbsmi must be done before InitCodes */
|
2007-02-18 00:26:36 +00:00
|
|
|
/* This must be done before initialising predicates */
|
2007-02-26 10:41:40 +00:00
|
|
|
for (i = 0; i <= LAST_FLAG; i++) {
|
2007-02-18 00:26:36 +00:00
|
|
|
yap_flags[i] = 0;
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
#ifdef MPW
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitAbsmi(REGS, FunctorList);
|
2001-04-09 20:54:03 +01:00
|
|
|
#else
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitAbsmi();
|
2001-04-09 20:54:03 +01:00
|
|
|
#endif
|
|
|
|
InitCodes();
|
|
|
|
InitOps();
|
|
|
|
InitDebug();
|
|
|
|
InitVersion();
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_InitSysPath();
|
2001-04-09 20:54:03 +01:00
|
|
|
InitStdPreds();
|
2004-01-23 02:23:51 +00:00
|
|
|
/* make sure tmp area is available */
|
|
|
|
{
|
|
|
|
Yap_ReleasePreAllocCodeSpace(Yap_PreAllocCodeSpace());
|
|
|
|
}
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2010-09-24 14:00:53 +01:00
|
|
|
int
|
|
|
|
Yap_HaltRegisterHook (HaltHookFunc f, void * env)
|
|
|
|
{
|
|
|
|
struct halt_hook *h;
|
|
|
|
|
|
|
|
if (!(h = (struct halt_hook *)Yap_AllocCodeSpace(sizeof(struct halt_hook))))
|
|
|
|
return FALSE;
|
|
|
|
h->environment = env;
|
|
|
|
h->hook = f;
|
|
|
|
LOCK(BGL);
|
|
|
|
h->next = Yap_HaltHooks;
|
|
|
|
Yap_HaltHooks = h;
|
|
|
|
UNLOCK(BGL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_halt_hooks(int code)
|
|
|
|
{
|
|
|
|
struct halt_hook *hooke = Yap_HaltHooks;
|
|
|
|
|
|
|
|
while (hooke) {
|
|
|
|
hooke->hook(code, hooke->environment);
|
|
|
|
hooke = hooke->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_exit (int value)
|
2002-11-11 17:38:10 +00:00
|
|
|
{
|
2010-01-14 15:58:19 +00:00
|
|
|
#if defined(YAPOR) && !defined(THREADS)
|
2002-11-11 17:38:10 +00:00
|
|
|
unmap_memory();
|
2003-11-07 16:31:08 +00:00
|
|
|
#endif /* YAPOR */
|
2004-02-25 19:06:31 +00:00
|
|
|
|
2010-09-24 14:00:53 +01:00
|
|
|
if (! (Yap_PrologMode & BootMode) ) {
|
2004-02-25 19:06:31 +00:00
|
|
|
#ifdef LOW_PROF
|
2010-09-24 14:00:53 +01:00
|
|
|
remove("PROFPREDS");
|
|
|
|
remove("PROFILING");
|
2004-02-25 19:06:31 +00:00
|
|
|
#endif
|
2005-12-19 13:52:35 +00:00
|
|
|
#if defined MYDDAS_MYSQL || defined MYDDAS_ODBC
|
2010-09-24 14:00:53 +01:00
|
|
|
Yap_MYDDAS_delete_all_myddas_structs();
|
2005-12-19 13:52:35 +00:00
|
|
|
#endif
|
2010-09-24 14:00:53 +01:00
|
|
|
run_halt_hooks(value);
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_ShutdownLoadForeign();
|
2010-09-24 14:00:53 +01:00
|
|
|
}
|
2002-11-11 17:38:10 +00:00
|
|
|
exit(value);
|
|
|
|
}
|
|
|
|
|